deep-chat-dev 9.0.354 → 9.0.357

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,21 @@
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(_n19){function n(){return _n19.apply(this,arguments);}n.toString=function(){return _n19.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",ra="unset",oa="html-wrapper",x=function x(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var aa=/*#__PURE__*/function(){function aa(){_classCallCheck(this,aa);}return _createClass(aa,null,[{key:"render",value:function render(e,t){var n=x();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var Ns=/*#__PURE__*/function(){function Ns(){_classCallCheck(this,Ns);}return _createClass(Ns,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=x();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=Ns.createElements(),r={onSuccess:t,onFail:aa.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:Ns.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var ie="service",h="text",P="html",f="error",K="https://deepchat.dev/docs/",Q="ai",D="user",ut="assistant",Bs="error-message-text",ws="deep-chat-outer-container-role-",xr="empty-message",vi="deep-chat-top-message",Ar="deep-chat-middle-message",Ei="deep-chat-bottom-message",C="src",I="type",ee="file",y="files",V="image",Y="images",Ne="camera",bn="gifs",j="audio",it="microphone",So="mixedFiles",Jt="any",xo="file-message",Bt="start",Ao="end",wo="messages",wr="0",Cr="1",S="role",ye="string",oe=function oe(i){return JSON.stringify(i);},w=function w(i){return JSON.parse(oe(i));};function Tr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function ca(i){return i&&oe(i);}function Wi(i,e,t,n){var s="\n".concat(Tr(e)," message: ").concat(oe(i)," \n"),r=t?"".concat(Tr(e)," message after interceptor: ").concat(ca(n)," \n"):"";return s+r;}function la(i,e,t,n){return"".concat(Wi(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat(K,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat(K,"interceptors#responseInterceptor");}function da(i,e,t){var n="response";return"".concat(Wi(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function ha(i,e){var t="request";return"".concat(Wi(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function ua(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var _n=la,pa=ha,fa=da,Rr=ua,de="Invalid API Key",Be="Failed to connect",De="Request settings have not been set up",ci="No file was added",Xi="Image was not found",Co="Multi-response arrays are not supported for streaming",To="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat(K,"interceptors#responseInterceptor"),ma="Cannot mix {text: string} and {html: string} responses.",ga="No valid stream events were sent.\n".concat(To),ya="Readable Stream connection error.",Dt="Please define a `function_handler` property inside the service config.",Qt="Function tool response must be an array or contain a text property",Ro="Failed to fetch history",En="inside-start",dt="inside-end",Me="outside-start",be="outside-end",Ye="dropup-menu",A="default",Oe="hover",X="click",U="active",H="disabled";var re=/*#__PURE__*/function(){function re(){_classCallCheck(this,re);}return _createClass(re,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[X]&&re.unsetStyle(e,t[X]),t[Oe]&&re.unsetStyle(e,t[Oe]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){re.unsetActivityCSSMouseStates(e,t),t[A]&&re.unsetStyle(e,t[A]);}// if you want to asdd default styling - use pure css classes
2
- },{key:"processStateful",value:function processStateful(e){var t=e[A]||{},n=Object.assign(w(t),e==null?void 0:e[Oe]),s=Object.assign(w(n),e==null?void 0:e[X]);return _defineProperty(_defineProperty(_defineProperty({},A,t),Oe,n),X,s);}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t=_defineProperty(_defineProperty(_defineProperty({},A,{}),Oe,{}),X,{});return e.forEach(function(n){t[A]=Object.assign(t[A],n[A]),t[Oe]=Object.assign(t[Oe],n[Oe]),t[X]=Object.assign(t[X],n[X]);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e[A]||[]).forEach(function(n){var r;var s=n;t[v][s]&&(r=e[A])!=null&&r[s]&&(e[A][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 $t=/*#__PURE__*/function(){function $t(){_classCallCheck(this,$t);}return _createClass($t,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==$t.DEFAULT_FONT_FAMILY)return;var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(s){return s.getAttribute("href")===$t.FONT_URL;})){var s=x("link");s.rel="stylesheet",s.href=$t.FONT_URL,t.appendChild(s);}}}]);}();$t.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",$t.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var Ds=$t;var pn=/*#__PURE__*/function(){function pn(){_classCallCheck(this,pn);}return _createClass(pn,null,[{key:"apply",value:function apply(e,t){if(t)try{pn.applyStyleSheet(e,t);}catch(_unused){pn.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=x("style");n.innerHTML=e,t.appendChild(n);}},{key:"applyDefaultStyleToComponent",value:function applyDefaultStyleToComponent(e,t){t&&re.applyToStyleIfNotDefined(e,t),re.applyToStyleIfNotDefined(e,pn.DEFAULT_COMPONENT_STYLE);}}]);}();pn.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:Ds.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
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(_n19){function n(){return _n19.apply(this,arguments);}n.toString=function(){return _n19.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",oa="unset",aa="html-wrapper",x=function x(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var ca=/*#__PURE__*/function(){function ca(){_classCallCheck(this,ca);}return _createClass(ca,null,[{key:"render",value:function render(e,t){var n=x();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var Bs=/*#__PURE__*/function(){function Bs(){_classCallCheck(this,Bs);}return _createClass(Bs,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=x();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=Bs.createElements(),r={onSuccess:t,onFail:ca.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:Bs.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var ie="service",h="text",P="html",f="error",K="https://deepchat.dev/docs/",Q="ai",D="user",ut="assistant",Ds="error-message-text",Cs="deep-chat-outer-container-role-",Ar="empty-message",Ei="deep-chat-top-message",wr="deep-chat-middle-message",Si="deep-chat-bottom-message",C="src",I="type",ee="file",y="files",V="image",Z="images",Ne="camera",bn="gifs",j="audio",it="microphone",xo="mixedFiles",Jt="any",Ao="file-message",Bt="start",wo="end",Co="messages",Cr="0",Tr="1",S="role",ye="string",oe=function oe(i){return JSON.stringify(i);},w=function w(i){return JSON.parse(oe(i));};function Rr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function la(i){return i&&oe(i);}function Xi(i,e,t,n){var s="\n".concat(Rr(e)," message: ").concat(oe(i)," \n"),r=t?"".concat(Rr(e)," message after interceptor: ").concat(la(n)," \n"):"";return s+r;}function da(i,e,t,n){return"".concat(Xi(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat(K,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat(K,"interceptors#responseInterceptor");}function ha(i,e,t){var n="response";return"".concat(Xi(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function ua(i,e){var t="request";return"".concat(Xi(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function pa(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var _n=da,fa=ua,ma=ha,Ir=pa,de="Invalid API Key",Be="Failed to connect",De="Request settings have not been set up",li="No file was added",Yi="Image was not found",To="Multi-response arrays are not supported for streaming",Ro="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat(K,"interceptors#responseInterceptor"),ga="Cannot mix {text: string} and {html: string} responses.",ya="No valid stream events were sent.\n".concat(Ro),ba="Readable Stream connection error.",Dt="Please define a `function_handler` property inside the service config.",Qt="Function tool response must be an array or contain a text property",Io="Failed to fetch history",En="inside-start",dt="inside-end",Me="outside-start",be="outside-end",Ze="dropup-menu",A="default",Oe="hover",X="click",U="active",H="disabled";var re=/*#__PURE__*/function(){function re(){_classCallCheck(this,re);}return _createClass(re,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[X]&&re.unsetStyle(e,t[X]),t[Oe]&&re.unsetStyle(e,t[Oe]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){re.unsetActivityCSSMouseStates(e,t),t[A]&&re.unsetStyle(e,t[A]);}// if you want to asdd default styling - use pure css classes
2
+ },{key:"processStateful",value:function processStateful(e){var t=e[A]||{},n=Object.assign(w(t),e==null?void 0:e[Oe]),s=Object.assign(w(n),e==null?void 0:e[X]);return _defineProperty(_defineProperty(_defineProperty({},A,t),Oe,n),X,s);}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t=_defineProperty(_defineProperty(_defineProperty({},A,{}),Oe,{}),X,{});return e.forEach(function(n){t[A]=Object.assign(t[A],n[A]),t[Oe]=Object.assign(t[Oe],n[Oe]),t[X]=Object.assign(t[X],n[X]);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e[A]||[]).forEach(function(n){var r;var s=n;t[v][s]&&(r=e[A])!=null&&r[s]&&(e[A][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 $t=/*#__PURE__*/function(){function $t(){_classCallCheck(this,$t);}return _createClass($t,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==$t.DEFAULT_FONT_FAMILY)return;var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(s){return s.getAttribute("href")===$t.FONT_URL;})){var s=x("link");s.rel="stylesheet",s.href=$t.FONT_URL,t.appendChild(s);}}}]);}();$t.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",$t.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var Fs=$t;var pn=/*#__PURE__*/function(){function pn(){_classCallCheck(this,pn);}return _createClass(pn,null,[{key:"apply",value:function apply(e,t){if(t)try{pn.applyStyleSheet(e,t);}catch(_unused){pn.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=x("style");n.innerHTML=e,t.appendChild(n);}},{key:"applyDefaultStyleToComponent",value:function applyDefaultStyleToComponent(e,t){t&&re.applyToStyleIfNotDefined(e,t),re.applyToStyleIfNotDefined(e,pn.DEFAULT_COMPONENT_STYLE);}}]);}();pn.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:Fs.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
3
  // it will cause issues if there are elements that are meant to be outside of the chat component and in
4
4
  // that instance they should overwrite this
5
5
  // this is also causing the chat to squeeze when there is no space
6
- overflow:"hidden"};var ts=pn;var qt=/*#__PURE__*/function(){function qt(){_classCallCheck(this,qt);}return _createClass(qt,null,[{key:"buildElement",value:function buildElement(){var e=x();e[m].add("tooltip");var t=x("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(qt.OVERFLOW_NEW_POSITION_PX,"px"):l.right>s.right&&(t[v].left="".concat(s.width-l.width-qt.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,n){return n||(n=qt.traverseParentUntilContainer(e).nextSibling),t[h]&&(n.children[0].textContent=t[h]),{timeout:setTimeout(function(){n[v].visibility="visible",qt.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]&&re.unsetStyle(e.element,t[v]),e.element[v].left="",e.element[v].top="";}}]);}();qt.OVERFLOW_NEW_POSITION_PX=4;var ct=qt;var as=/*#__PURE__*/_createClass(function as(){_classCallCheck(this,as);});as.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),as.IS_CHROMIUM=window.chrome,as.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var Ue=as;var ge=/* @__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;}(ge||{});var Gt=/*#__PURE__*/function(){function Gt(){_classCallCheck(this,Gt);}return _createClass(Gt,null,[{key:"add",value:// prettier-ignore
6
+ overflow:"hidden"};var ns=pn;var qt=/*#__PURE__*/function(){function qt(){_classCallCheck(this,qt);}return _createClass(qt,null,[{key:"buildElement",value:function buildElement(){var e=x();e[m].add("tooltip");var t=x("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(qt.OVERFLOW_NEW_POSITION_PX,"px"):l.right>s.right&&(t[v].left="".concat(s.width-l.width-qt.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,n){return n||(n=qt.traverseParentUntilContainer(e).nextSibling),t[h]&&(n.children[0].textContent=t[h]),{timeout:setTimeout(function(){n[v].visibility="visible",qt.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]&&re.unsetStyle(e.element,t[v]),e.element[v].left="",e.element[v].top="";}}]);}();qt.OVERFLOW_NEW_POSITION_PX=4;var ct=qt;var cs=/*#__PURE__*/_createClass(function cs(){_classCallCheck(this,cs);});cs.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),cs.IS_CHROMIUM=window.chrome,cs.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var Ue=cs;var ge=/* @__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;}(ge||{});var Gt=/*#__PURE__*/function(){function Gt(){_classCallCheck(this,Gt);}return _createClass(Gt,null,[{key:"add",value:// prettier-ignore
7
7
  function add(e,t,n,s){n!==void 0&&e.addEventListener("keydown",Gt.onKeyDown.bind(this,n)),e.oninput=Gt.onInput.bind(this,n,s),e.addEventListener("paste",function(r){var o;r.preventDefault(),(o=r.clipboardData)!=null&&o[y].length&&t.addFilesToAnyType(Array.from(r.clipboardData[y]));});}// preventing insertion early for a nicer UX
8
8
  // prettier-ignore
9
- },{key:"onKeyDown",value:function onKeyDown(e,t){var s=t.target.textContent;s&&s.length>=e&&!Gt.PERMITTED_KEYS.has(t.key)&&!Gt.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),en.focusEndOfInput(s)),t==null||t();}}]);}();Gt.PERMITTED_KEYS=/* @__PURE__ */new Set([ge.BACKSPACE,ge.DELETE,ge.ARROW_RIGHT,ge.ARROW_LEFT,ge.ARROW_DOWN,ge.ARROW_UP,ge.META,ge.CONTROL,ge.ENTER]);var Ti=Gt;var ba=/*#__PURE__*/function(){function ba(){_classCallCheck(this,ba);}return _createClass(ba,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var n,s;e.preventDefault();var t=(n=e.clipboardData)==null?void 0:n.getData("text/plain");t&&((s=document.execCommand)==null||s.call(document,"insertText",!1,t));}}]);}();var Mt=/*#__PURE__*/function(){function Mt(e,t,n,s){var _this=this;_classCallCheck(this,Mt);var o,a,c,l;this._isComposing=!1;var r=Mt.processConfig(t,e.textInput);this.elementRef=Mt.createContainerElement((o=r==null?void 0:r.styles)==null?void 0:o.container),this._config=r,this.inputElementRef=this.createInputElement((a=e.defaultInput)==null?void 0:a[h],s),Mt.addFilesToAnyType(n,(c=e.defaultInput)==null?void 0:c[y]),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(){Ti.add(_this.inputElementRef,n,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(Mt,[{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(H))||(Object.assign(this.inputElementRef[v],(t=this._config.placeholder)==null?void 0:t[v]),this.inputElementRef.textContent="",en.focusEndOfInput(this.inputElementRef),(n=this._onInput)==null||n.call(this,!1),(s=this._browserStorage)==null||s.addInputText("")),Ue.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(e,t){var s,r,o,a;var n=x();return n.id=Mt.TEXT_INPUT_ID,n[m].add("text-input-styling"),n[S]="textbox",typeof e=="string"?n.innerText=e:t!=null&&t.trackInputText&&(n.innerText=t.get().inputText||""),Ue.IS_MOBILE&&n.setAttribute("tabindex","0"),Ue.IS_CHROMIUM&&Mt.preventAutomaticScrollUpOnNewLine(n),typeof this._config[H]=="boolean"&&this._config[H]===!0?(n.contentEditable="false",n[m].add("text-input-".concat(H)),n.setAttribute("aria-".concat(H),"true")):(n.contentEditable="true",n.removeAttribute("aria-".concat(H)),this.addEventListeners(n)),Object.assign(n[v],(s=this._config.styles)==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(H))&&(e=this._config.placeholder)!=null&&e[v]&&(re.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.styles)==null?void 0:s[h]));}},{key:"addEventListeners",value:function addEventListeners(e){var _this2=this;var t,n;(t=this._config.styles)!=null&&t.focus&&(e.onfocus=function(){var s;return Object.assign(_this2.elementRef[v],(s=_this2._config.styles)==null?void 0:s.focus);},e.onblur=this.onBlur.bind(this,this._config.styles.focus,(n=this._config.styles)==null?void 0:n.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",ba.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){re.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef[v],t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===ge.ENTER&&!Ue.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$H,_t$placeholder,_n$h;var n;return t!==null&&t!==void 0?t:t={},(_t$H=t[H])!==null&&_t$H!==void 0?_t$H:t[H]=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=x();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
9
+ },{key:"onKeyDown",value:function onKeyDown(e,t){var s=t.target.textContent;s&&s.length>=e&&!Gt.PERMITTED_KEYS.has(t.key)&&!Gt.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),en.focusEndOfInput(s)),t==null||t();}}]);}();Gt.PERMITTED_KEYS=/* @__PURE__ */new Set([ge.BACKSPACE,ge.DELETE,ge.ARROW_RIGHT,ge.ARROW_LEFT,ge.ARROW_DOWN,ge.ARROW_UP,ge.META,ge.CONTROL,ge.ENTER]);var Ri=Gt;var _a=/*#__PURE__*/function(){function _a(){_classCallCheck(this,_a);}return _createClass(_a,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var n,s;e.preventDefault();var t=(n=e.clipboardData)==null?void 0:n.getData("text/plain");t&&((s=document.execCommand)==null||s.call(document,"insertText",!1,t));}}]);}();var Mt=/*#__PURE__*/function(){function Mt(e,t,n,s){var _this=this;_classCallCheck(this,Mt);var o,a,c,l;this._isComposing=!1;var r=Mt.processConfig(t,e.textInput);this.elementRef=Mt.createContainerElement((o=r==null?void 0:r.styles)==null?void 0:o.container),this._config=r,this.inputElementRef=this.createInputElement((a=e.defaultInput)==null?void 0:a[h],s),Mt.addFilesToAnyType(n,(c=e.defaultInput)==null?void 0:c[y]),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(){Ri.add(_this.inputElementRef,n,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(Mt,[{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(H))||(Object.assign(this.inputElementRef[v],(t=this._config.placeholder)==null?void 0:t[v]),this.inputElementRef.textContent="",en.focusEndOfInput(this.inputElementRef),(n=this._onInput)==null||n.call(this,!1),(s=this._browserStorage)==null||s.addInputText("")),Ue.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(e,t){var s,r,o,a;var n=x();return n.id=Mt.TEXT_INPUT_ID,n[m].add("text-input-styling"),n[S]="textbox",typeof e=="string"?n.innerText=e:t!=null&&t.trackInputText&&(n.innerText=t.get().inputText||""),Ue.IS_MOBILE&&n.setAttribute("tabindex","0"),Ue.IS_CHROMIUM&&Mt.preventAutomaticScrollUpOnNewLine(n),typeof this._config[H]=="boolean"&&this._config[H]===!0?(n.contentEditable="false",n[m].add("text-input-".concat(H)),n.setAttribute("aria-".concat(H),"true")):(n.contentEditable="true",n.removeAttribute("aria-".concat(H)),this.addEventListeners(n)),Object.assign(n[v],(s=this._config.styles)==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(H))&&(e=this._config.placeholder)!=null&&e[v]&&(re.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.styles)==null?void 0:s[h]));}},{key:"addEventListeners",value:function addEventListeners(e){var _this2=this;var t,n;(t=this._config.styles)!=null&&t.focus&&(e.onfocus=function(){var s;return Object.assign(_this2.elementRef[v],(s=_this2._config.styles)==null?void 0:s.focus);},e.onblur=this.onBlur.bind(this,this._config.styles.focus,(n=this._config.styles)==null?void 0:n.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",_a.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){re.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef[v],t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===ge.ENTER&&!Ue.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$H,_t$placeholder,_n$h;var n;return t!==null&&t!==void 0?t:t={},(_t$H=t[H])!==null&&_t$H!==void 0?_t$H:t[H]=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=x();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
11
  // the browser scrollbar will move up which leads to undesirable UX.
12
12
  // More details in this Stack Overflow question:
13
13
  // https://stackoverflow.com/questions/76285135/prevent-automatic-scroll-when-text-is-inserted-into-contenteditable-div
14
14
  // 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;}));}}]);}();Mt.TEXT_INPUT_ID="text-input";var Fs=Mt;var en=/*#__PURE__*/function(){function en(){_classCallCheck(this,en);}return _createClass(en,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),(Ue.IS_MOBILE||Ue.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(Fs.TEXT_INPUT_ID));t&&en.focusEndOfInput(t);}}]);}();var Io="Authentication",ce="Authorization",_a="authorization",li="Unauthorized",Zi="Authorization header",Ft="Invalid",Ss="Incorrect",Ae="authentication_error",et="invalid_request_error",$="Content-Type",va="content-type",J="application/json",F="object",Yi="completed",xe="Bearer ",le="GET",me="POST",Ji="Upload an audio file",Ps="function_call",Zt="input_audio",He="image_url",ii=/*#__PURE__*/function(){function ii(){_classCallCheck(this,ii);}return _createClass(ii,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]:ii.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===ge.ENTER&&setTimeout(t);};}}]);}();ii.CODE_SNIPPET_GENERATION_JUMP=1;var q=ii;var ri=/*#__PURE__*/function(){function ri(){_classCallCheck(this,ri);}return _createClass(ri,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);},ri.LOAD_VOICES_MS);}}]);}();ri.LOAD_VOICES_MS=200;var vn=ri;var fn=/*#__PURE__*/function(){function fn(){_classCallCheck(this,fn);}return _createClass(fn,null,[{key:"colorToHex",value:function colorToHex(e){var t=x();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.styles)==null?void 0:n.bubble)!=null&&s.color){var r=fn.colorToHex(t.styles.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=fn.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");}}]);}();fn.BUBBLE_CLASS="deep-chat-loading-message-bubble",fn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var ht=fn;var ae=/*#__PURE__*/function(){function ae(){_classCallCheck(this,ae);}return _createClass(ae,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var n=e.containerStyle;n&&(Object.assign(t[v],n),console[f]("The containerStyle property".concat(We,"1.3.14.")),console[f]("".concat(Ut,"the style property instead: ").concat(K,"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(We,"1.3.0.")),console[f]("".concat(Ut,"the new response object: ").concat(K,"connect#Response")),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console[f]("The initialMessages property".concat(We,"2.0.0.")),console[f]("".concat(Ut,"the history property instead: ").concat(K,"messages/#history")),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e[ee];t&&(console[f]("The file property in MessageContent".concat(We,"1.3.17.")),console[f]("".concat(Ut,"the files array property: ").concat(K,"messages/#MessageContent")),e[y]=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console[f]("The validateMessageBeforeSending property".concat(We,"1.3.24.")),console[f]("".concat(Ut,"validateInput: ").concat(K,"interceptors#validateInput")),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console[f]("The submitUserMessage(text: string) argument string type".concat(We,"1.4.4.")),console[f]("".concat(Ut,"the new argument type: ").concat(K,"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(We,"1.4.4.")),console[f]("".concat(Ut,"using {..., overwrite: true} object: ").concat(K,"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(We,"2.0.0.")),console[f]("".concat(Cs,"connect object: ").concat(K,"connect#connect-1")));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console[f]("The stream property".concat(Mr,"the connect object in version 2.0.0.")),console[f]("".concat(Cs,"connect object: ").concat(K,"connect#connect-1")),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var s;var n=e;n.onNewMessage&&(console[f]("The onNewMessage event".concat(We,"2.0.0.")),console[f]("".concat(Cs,"onMessage event: ").concat(K,"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(We,"2.0.0.")),console[f]("Please use the connect property instead: ".concat(K,"files")),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=w(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(hn,"2.1.0.")),console[f]("Check it out here: ".concat(K,"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(We,"2.1.0.")),console[f]("Please use displayLoading instead: ".concat(K,"modes#demo")),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,n="".concat(Cs,"official documentation: ").concat(K,"directConnection/Cohere");return t.chat&&(console[f]("Cohere chat property".concat(We,"2.2.3.")),console[f](n),delete t.chat),t.textGeneration?(console[f]("Cohere textGeneration".concat(Ir,"2.2.3.")),console[f](n),delete t.textGeneration,!1):t.summarization?(console[f]("Cohere summarization".concat(Ir,"2.2.3.")),console[f](n),delete t.summarization,!1):!0;}},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==F)return;var t=e.htmlWrappers;if(t)return console[f]("The htmlWrappers property".concat(Mr,"Deep Chat's base").concat(hn,"2.3.0.")),console[f]("Check it out here: ".concat(K,"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(hn,"2.3.0.")),console[f]("Check it out here: ".concat(K,"modes#focusMode")),e.smoothScroll=!0),e;}},{key:"processPosition",value:function processPosition(e){if(!e)return e;var t="Position names have been updated".concat(hn,"2.3.1.");return e==="inside-left"?(console[f](t),En):e==="inside-right"?(console[f](t),dt):e==="outside-left"?(console[f](t),Me):e==="outside-right"?(console[f](t),be):e;}},{key:"processBrowserStorage",value:function processBrowserStorage(e){var t=e.get();t&&Array.isArray(t)&&e.addMessages(t);}}]);}();var hn=" since version ",We=" is deprecated ".concat(hn),Ut="Please change to using ",Cs="Please see the ",Ir=" is not supported ".concat(hn),Mr=" has been moved to ";var At=/*#__PURE__*/function(){function At(){_classCallCheck(this,At);}return _createClass(At,null,[{key:"mouseUp",value:function mouseUp(e,t){re.unsetAllCSSMouseStates(e,t),Object.assign(e[v],t[A]),Object.assign(e[v],t[Oe]);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e[v],t[X]);}},{key:"mouseLeave",value:function mouseLeave(e,t){re.unsetAllCSSMouseStates(e,t),Object.assign(e[v],t[A]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e[v],t[Oe]);}},{key:"add",value:function add(e,t){e.addEventListener("mouseenter",At.mouseEnter.bind(this,e,t)),e.addEventListener("mouseleave",At.mouseLeave.bind(this,e,t)),e.addEventListener("mousedown",At.mouseDown.bind(this,e,t)),e.addEventListener("mouseup",At.mouseUp.bind(this,e,t));}}]);}();var Ea="deep-chat-temporary-message",Sa="deep-chat-suggestion-button",Ri={"deep-chat-button":{styles:_defineProperty(_defineProperty(_defineProperty({},A,{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"}),Oe,{backgroundColor:"#fafafa"}),X,{backgroundColor:"#f1f1f1"})}},kr=Object.keys(Ri);var pt=/*#__PURE__*/function(){function pt(){_classCallCheck(this,pt);}return _createClass(pt,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener(X,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(Ea):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return kr.find(function(t){return e[m].contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var n=Ri[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.styles;return l&&e[c].styles&&a.push(l),a;},[]),r=Ri[n].styles;if(r){var a=w(r);a[A]&&re.overwriteDefaultWithAlreadyApplied(a,t),s.unshift(a);}var o=re.mergeStatefulStyles(s);return re.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,n){kr.forEach(function(r){var o=n.getElementsByClassName(r);Array.from(o||[]).forEach(function(a){var c=pt.getProcessedStyles(t,a,r);se.applyStylesToElement(a,c),pt.applyEvents(a,r);});});var s=n.getElementsByClassName(Sa);Array.from(s).forEach(function(r){return pt.applySuggestionEvent(e,r);});}}]);}();var se=/*#__PURE__*/function(){function se(){_classCallCheck(this,se);}return _createClass(se,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var n=re.processStateful(t);At.add(e,n),Object.assign(e[v],n[A]);}},{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&&se.applyEventsToElement(e,n),s&&!pt.doesElementContainDeepChatClass(e)&&se.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]&&se.applyClassUtilitiesToElement(r,e[n]);});});}},{key:"apply",value:function apply(e,t){pt.applyDeepChatUtilities(e,e.htmlClassUtilities,t),se.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){se.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){se.traverseNodes(r,s);}),s;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=x();return t.innerHTML=e,pt.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[A]);if(r)return e.innerHTML=r,{contentEl:se.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(oa)[0]||e;}}]);}();var kt=/*#__PURE__*/function(){function kt(){_classCallCheck(this,kt);}return _createClass(kt,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(kt.HTML_BUBBLE_CLASS);var _se$tryAddWrapper=se.tryAddWrapper(o.bubbleElement,t,e._customWrappers,n),a=_se$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,n){n.bubbleElement.innerHTML=t,se.apply(e,n.outerContainer),ae.flagHTMLUpdateClass(n.bubbleElement);}// prettier-ignore
18
- },{key:"overwrite",value:function overwrite(e,t,n,s){var r=e.messageToElements,o=N.overwriteMessage(r,s,t,n,P,kt.HTML_BUBBLE_CLASS);return o&&kt.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=kt.createElements(e,t,n,s);return N.fillEmptyMessageElement(r.bubbleElement,t),se.apply(e,r.outerContainer),ae.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,n,!1,(o=e.messageStyles)==null?void 0:o[P]),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&&se.isTemporaryBasedOnHTML(t))return;var o=kt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();kt.HTML_BUBBLE_CLASS="html-message";var ft=kt;var xa=/*#__PURE__*/function(){function xa(){_classCallCheck(this,xa);}return _createClass(xa,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 b=!1,_=p.bMarks[u]+p.tShift[u],E=p.eMarks[u];if(_+1>E)return!1;var R=p[C].charAt(_);if(R!==a)return!1;var z=_;_=p.skipChars(_,R);var te=_-z;if(te!==2)return!1;var ne=u;for(;++ne,!(ne>=g||(_=z=p.bMarks[ne]+p.tShift[ne],E=p.eMarks[ne],_<E&&p.tShift[ne]<p.blkIndent));)if(p[C].charAt(_)===a&&!(p.tShift[ne]-p.blkIndent>=4)&&(_=p.skipChars(_,R),!(_-z<te)&&(_=p.skipSpaces(_),!(_<E)))){b=!0;break;}te=p.tShift[u],p.line=ne+(b?1:0);var we=p.getLines(u+1,ne,te,!0).replace(/[ \n]+/g," ").trim();return p.tokens.push({type:"katex",params:null,content:we,lines:[u,p.line],level:p.level,block:!0}),!0;},d=function d(p,u){var g=p.pos,b=p.posMax;var _=g;if(p[C].charAt(_)!==a)return!1;for(++_;_<b&&p[C].charAt(_)===a;)++_;var E=p[C].slice(g,_);if(E.length>2)return!1;var R=_;var z=0;for(;_<b;){var te=p[C].charAt(_);if(te==="{"&&(_===0||p[C].charAt(_-1)!=="\\"))z+=1;else if(te==="}"&&(_===0||p[C].charAt(_-1)!=="\\")){if(z-=1,z<0)return!1;}else if(te===a&&z===0){var ne=_;var we=_+1;for(;we<b&&p[C].charAt(we)===a;)++we;if(we-ne===E.length){if(!u){var Rt=p[C].slice(R,ne).replace(/[ \n]+/g," ").trim();p.push({type:"katex",content:Rt,block:E.length>1,level:p.level});}return p.pos=we,!0;}}_+=1;}return u||(p.pending+=E),p.pos+=E.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 Ts;function Mo(i){return Ts=Ts||document.createElement("textarea"),Ts.innerHTML="&"+i+";",Ts.value;}var Aa=Object.prototype.hasOwnProperty;function wa(i,e){return i?Aa.call(i,e):!1;}function ko(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 Ca=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function fs(i){return i.indexOf("\\")<0?i:i.replace(Ca,"$1");}function Po(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 Ii(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 Ta=/&([a-z#][a-z0-9]{1,31});/gi,Ra=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function Ia(i,e){var t=0,n=Mo(e);return e!==n?n:e.charCodeAt(0)===35&&Ra.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),Po(t))?Ii(t):i;}function tn(i){return i.indexOf("&")<0?i:i.replace(Ta,Ia);}var Ma=/[&<>"]/,ka=/[&<>"]/g,Pa={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function La(i){return Pa[i];}function je(i){return Ma.test(i)?i.replace(ka,La):i;}var T={};T.blockquote_open=function(){return"<blockquote>\n";};T.blockquote_close=function(i,e){return"</blockquote>"+rn(i,e);};T.code=function(i,e){return i[e].block?"<pre><code>"+je(i[e].content)+"</code></pre>"+rn(i,e):"<code>"+je(i[e].content)+"</code>";};T.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(" "),wa(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=je(tn(fs(d))),o=' class="'+a+c+'"';}return t.highlight?p=t.highlight.apply(t.highlight,[r.content].concat(l))||je(r.content):p=je(r.content),"<pre><code"+o+">"+p+"</code></pre>"+rn(i,e);};T.fence_custom={};T.heading_open=function(i,e){return"<h"+i[e].hLevel+">";};T.heading_close=function(i,e){return"</h"+i[e].hLevel+">\n";};T.hr=function(i,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+rn(i,e);};T.bullet_list_open=function(){return"<ul>\n";};T.bullet_list_close=function(i,e){return"</ul>"+rn(i,e);};T.list_item_open=function(){return"<li>";};T.list_item_close=function(){return"</li>\n";};T.ordered_list_open=function(i,e){var t=i[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};T.ordered_list_close=function(i,e){return"</ol>"+rn(i,e);};T.paragraph_open=function(i,e){return i[e].tight?"":"<p>";};T.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?rn(i,e):"");};T.link_open=function(i,e,t){var n=i[e].title?' title="'+je(tn(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+je(i[e].href)+'"'+n+s+">";};T.link_close=function(){return"</a>";};T.image=function(i,e,t){var n=' src="'+je(i[e].src)+'"',s=i[e].title?' title="'+je(tn(i[e].title))+'"':"",r=' alt="'+(i[e].alt?je(tn(fs(i[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+r+s+o+">";};T.table_open=function(){return"<table>\n";};T.table_close=function(){return"</table>\n";};T.thead_open=function(){return"<thead>\n";};T.thead_close=function(){return"</thead>\n";};T.tbody_open=function(){return"<tbody>\n";};T.tbody_close=function(){return"</tbody>\n";};T.tr_open=function(){return"<tr>";};T.tr_close=function(){return"</tr>\n";};T.th_open=function(i,e){var t=i[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};T.th_close=function(){return"</th>";};T.td_open=function(i,e){var t=i[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};T.td_close=function(){return"</td>";};T.strong_open=function(){return"<strong>";};T.strong_close=function(){return"</strong>";};T.em_open=function(){return"<em>";};T.em_close=function(){return"</em>";};T.del_open=function(){return"<del>";};T.del_close=function(){return"</del>";};T.ins_open=function(){return"<ins>";};T.ins_close=function(){return"</ins>";};T.mark_open=function(){return"<mark>";};T.mark_close=function(){return"</mark>";};T.sub=function(i,e){return"<sub>"+je(i[e].content)+"</sub>";};T.sup=function(i,e){return"<sup>"+je(i[e].content)+"</sup>";};T.hardbreak=function(i,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};T.softbreak=function(i,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};T.text=function(i,e){return je(i[e].content);};T.htmlblock=function(i,e){return i[e].content;};T.htmltag=function(i,e){return i[e].content;};T.abbr_open=function(i,e){return'<abbr title="'+je(tn(i[e].title))+'">';};T.abbr_close=function(){return"</abbr>";};T.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>";};T.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";};T.footnote_block_close=function(){return"</ol>\n</section>\n";};T.footnote_open=function(i,e){var t=Number(i[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};T.footnote_close=function(){return"</li>\n";};T.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>';};T.dl_open=function(){return"<dl>\n";};T.dt_open=function(){return"<dt>";};T.dd_open=function(){return"<dd>";};T.dl_close=function(){return"</dl>\n";};T.dt_close=function(){return"</dt>\n";};T.dd_close=function(){return"</dd>\n";};function Lo(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?Lo(i,e+2):e;}var rn=T.getBreak=function(e,t){return t=Lo(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function Qi(){this.rules=ko({},T),this.getBreak=T.getBreak;}Qi.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;};Qi.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 Ke(){this.__rules__=[],this.__cache__=null;}Ke.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};Ke.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));});});};Ke.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;};Ke.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;};Ke.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;};Ke.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};Ke.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;};Ke.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;};Ke.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function Oa(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 on(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;}on.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};on.prototype.push=function(i){this.pending&&this.pushPending(),this.tokens.push(i),this.pendingLevel=this.level;};on.prototype.cacheSet=function(i,e){for(var t=this.cache.length;t<=i;t++)this.cache.push(0);this.cache[i]=e;};on.prototype.cacheGet=function(i){return i<this.cache.length?this.cache[i]:0;};function ms(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 Na(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 on(i,e,t,n,[]),r=ms(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 Ba(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=Na(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 Mi(i){var e=tn(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function Oo(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=Mi(fs(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=fs(i.src.slice(r,e)),!i.parser.validateLink(s))?!1:(i.linkContent=s,i.pos=e,!0);}function No(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=fs(i.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function Bo(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function Da(i,e,t,n){var s,r,o,a,c,l,d,p,u;if(i.charCodeAt(0)!==91||i.indexOf("]:")===-1||(s=new on(i,e,t,n,[]),r=ms(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(!Oo(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&&No(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=Bo(i.slice(1,r)),_typeof(n.references[u])>"u"&&(n.references[u]={title:p,href:d}),o);}function Fa(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=Da(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 Ua(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 Ha(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 Pr=" \n()[]'\".,!?-";function Si(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function ja(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="(^|["+Pr.split("").map(Si).join("")+"])("+Object.keys(i.env.abbreviations).map(function(b){return b.substr(1);}).sort(function(b,_){return _.length-b.length;}).map(Si).join("|")+")($|["+Pr.split("").map(Si).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 $a=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,qa=/\((c|tm|r|p)\)/ig,Ga={c:"©",r:"®",p:"§",tm:"™"};function za(i){return i.indexOf("(")<0?i:i.replace(qa,function(e,t){return Ga[t.toLowerCase()];});}function Va(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=za(n),$a.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 Ka=/['"]/,Lr=/['"]/g,Wa=/[-\s()\[\]]/,Or="’";function Nr(i,e){return e<0||e>=i.length?!1:!Wa.test(i[e]);}function ln(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function Xa(i){var e,t,n,s,r,o,a,c,l,d,p,u,g,b,_,E,R;if(i.options.typographer){for(R=[],_=i.tokens.length-1;_>=0;_--)if(i.tokens[_].type==="inline"){for(E=i.tokens[_].children,R.length=0,e=0;e<E.length;e++)if(t=E[e],!(t.type!=="text"||Ka.test(t.text))){for(a=E[e].level,g=R.length-1;g>=0&&!(R[g].level<=a);g--);R.length=g+1,n=t.content,r=0,o=n.length;e:for(;r<o&&(Lr.lastIndex=r,s=Lr.exec(n),!!s);){if(c=!Nr(n,s.index-1),r=s.index+1,b=s[0]==="'",l=!Nr(n,r),!l&&!c){b&&(t.content=ln(t.content,s.index,Or));continue;}if(p=!l,u=!c,u){for(g=R.length-1;g>=0&&(d=R[g],!(R[g].level<a));g--)if(d.single===b&&R[g].level===a){d=R[g],b?(E[d.token].content=ln(E[d.token].content,d.pos,i.options.quotes[2]),t.content=ln(t.content,s.index,i.options.quotes[3])):(E[d.token].content=ln(E[d.token].content,d.pos,i.options.quotes[0]),t.content=ln(t.content,s.index,i.options.quotes[1])),R.length=g;continue e;}}p?R.push({token:e,pos:s.index,single:b,level:a}):u&&b&&(t.content=ln(t.content,s.index,Or));}}}}}var xi=[["block",Oa],["abbr",Ba],["references",Fa],["inline",Ua],["footnote_tail",Ha],["abbr2",ja],["replacements",Va],["smartquotes",Xa]];function Do(){this.options={},this.ruler=new Ke();for(var i=0;i<xi.length;i++)this.ruler.push(xi[i][0],xi[i][1]);}Do.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 an(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;}an.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};an.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};an.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};an.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};an.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;};an.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 Za(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 Ya(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 Ja(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,_=i.bMarks[e]+i.tShift[e],E=i.eMarks[e];if(_>E||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]=_,_=_<E?i.skipSpaces(_):_,r=_>=E,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],E=i.eMarks[s],!(_>=E));s++){if(i.src.charCodeAt(_++)===62){i.src.charCodeAt(_)===32&&_++,a.push(i.bMarks[s]),i.bMarks[s]=_,_=_<E?i.skipSpaces(_):_,r=_>=E,o.push(i.tShift[s]),i.tShift[s]=_-i.bMarks[s];continue;}if(r)break;for(b=!1,u=0,g=p.length;u<g;u++)if(p[u](i,s,t,!0)){b=!0;break;}if(b)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 Qa(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 Br(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 Dr(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 ec(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 tc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,_,E,R,z,te,ne,we,Rt=!0,It,qe,Sr,_i;if((p=Dr(i,e))>=0)E=!0;else if((p=Br(i,e))>=0)E=!1;else return!1;if(i.level>=i.options.maxNesting)return!1;if(_=i.src.charCodeAt(p-1),n)return!0;for(z=i.tokens.length,E?(d=i.bMarks[e]+i.tShift[e],b=Number(i.src.substr(d,p-d-1)),i.tokens.push({type:"ordered_list_open",order:b,lines:ne=[e,0],level:i.level++})):i.tokens.push({type:"bullet_list_open",lines:ne=[e,0],level:i.level++}),s=e,te=!1,It=i.parser.ruler.getRules("list");s<t&&(R=i.skipSpaces(p),u=i.eMarks[s],R>=u?g=1:g=R-p,g>4&&(g=1),g<1&&(g=1),r=p-i.bMarks[s]+g,i.tokens.push({type:"list_item_open",lines:we=[e,0],level:i.level++}),a=i.blkIndent,c=i.tight,o=i.tShift[e],l=i.parentType,i.tShift[e]=R-i.bMarks[e],i.blkIndent=r,i.tight=!0,i.parentType="list",i.parser.tokenize(i,e,t,!0),(!i.tight||te)&&(Rt=!1),te=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,we[1]=s,R=i.bMarks[e],!(s>=t||i.isEmpty(s)||i.tShift[s]<i.blkIndent));){for(_i=!1,qe=0,Sr=It.length;qe<Sr;qe++)if(It[qe](i,s,t,!0)){_i=!0;break;}if(_i)break;if(E){if(p=Dr(i,s),p<0)break;}else if(p=Br(i,s),p<0)break;if(_!==i.src.charCodeAt(p-1))break;}return i.tokens.push({type:E?"ordered_list_close":"bullet_list_close",level:--i.level}),ne[1]=s,i.line=s,Rt&&ec(i,z),!0;}function nc(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 sc(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 ic(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 Fo={};["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){Fo[i]=!0;});var rc=/^<([a-zA-Z]{1,15})[\s\/>]/,oc=/^<\/([a-zA-Z]{1,15})[\s>]/;function ac(i){var e=i|32;return e>=97&&e<=122;}function cc(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||ac(s)){if(s===47){if(r=i.src.slice(a,c).match(oc),!r)return!1;}else if(r=i.src.slice(a,c).match(rc),!r)return!1;if(Fo[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 Ai(i,e){var t=i.bMarks[e]+i.blkIndent,n=i.eMarks[e];return i.src.substr(t,n-t);}function lc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b;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=Ai(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=Ai(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:b=[e+2,0],level:i.level++}),c=e+2;c<t&&!(i.tShift[c]<i.blkIndent||(r=Ai(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]=b[1]=c,i.line=c,!0;}function Rs(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 dc(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 hc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,_,E,R;if(n)return i.ddIndent<0?!1:Rs(i,e)>=0;if(d=e+1,i.isEmpty(d)&&++d>t||i.tShift[d]<i.blkIndent||(s=Rs(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(R=!0,E=!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,b=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||E)&&(R=!1),E=i.line-r>1&&i.isEmpty(i.line-1),i.tShift[r]=b,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=Rs(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=Rs(i,r),s<0))break;}return i.tokens.push({type:"dl_close",level:--i.level}),c[1]=d,i.line=d,R&&dc(i,l),!0;}function uc(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 Is=[["code",Za],["fences",Ya,["paragraph","blockquote","list"]],["blockquote",Ja,["paragraph","blockquote","list"]],["hr",Qa,["paragraph","blockquote","list"]],["list",tc,["paragraph","blockquote"]],["footnote",nc,["paragraph"]],["heading",sc,["paragraph","blockquote"]],["lheading",ic],["htmlblock",cc,["paragraph","blockquote"]],["table",lc,["paragraph"]],["deflist",hc,["paragraph"]],["paragraph",uc]];function er(){this.ruler=new Ke();for(var i=0;i<Is.length;i++)this.ruler.push(Is[i][0],Is[i][1],{alt:(Is[i][2]||[]).slice()});}er.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 pc=/[\n\t]/g,fc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,mc=/\u00a0/g;er.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(mc," "),i=i.replace(fc,"\n"),i.indexOf(" ")>=0&&(i=i.replace(pc,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 an(i,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function gc(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 yc(i,e){for(var t=i.pos;t<i.posMax&&!gc(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function bc(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 tr=[];for(var Fr=0;Fr<256;Fr++)tr.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){tr[i.charCodeAt(0)]=1;});function _c(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&&tr[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 vc(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 Ec(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 Sc(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 xc(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 Ur(i){return i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122;}function Hr(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&&(Ur(n)&&(o=!1),Ur(s)&&(a=!1))),{can_open:o,can_close:a,delims:r};}function Ac(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=Hr(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=Hr(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 wc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Cc(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(wc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var Tc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Rc(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(Tc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function Ic(i,e){var t,n,s,r,o,a,c,l,d=!1,p=i.pos,u=i.posMax,g=i.pos,b=i.src.charCodeAt(g);if(b===33&&(d=!0,b=i.src.charCodeAt(++g)),b!==91||i.level>=i.options.maxNesting||(t=g+1,n=ms(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,Oo(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&&No(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=ms(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[Bo(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 Mc(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=ms(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 kc(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 Pc=["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"],Lc=/^<([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])?)*)>/,Oc=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Nc(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(Oc),n?Pc.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=Mi(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(Lc),s?(r=s[0].slice(1,-1),o=Mi("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 di(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 Bc=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Dc=/[^"'=<>`\x00-\x20]+/,Fc=/'[^']*'/,Uc=/"[^"]*"/,Hc=di(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Dc)("single_quoted",Fc)("double_quoted",Uc)(),jc=di(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Bc)("attr_value",Hc)(),$c=di(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",jc)(),qc=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Gc=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,zc=/<[?].*?[?]>/,Vc=/<![A-Z]+\s+[^>]*>/,Kc=/<!\[CDATA\[[\s\S]*?\]\]>/,Wc=di(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",$c)("close_tag",qc)("comment",Gc)("processing",zc)("declaration",Vc)("cdata",Kc)();function Xc(i){var e=i|32;return e>=97&&e<=122;}function Zc(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&&!Xc(t))||(n=i.src.slice(r).match(Wc),!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 Yc=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Jc=/^&([a-z][a-z0-9]{1,31});/i;function Qc(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(Yc),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=Po(n)?Ii(n):Ii(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match(Jc),s){var a=Mo(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 wi=[["text",yc],["newline",bc],["escape",_c],["backticks",vc],["del",Ec],["ins",Sc],["mark",xc],["emphasis",Ac],["sub",Cc],["sup",Rc],["links",Ic],["footnote_inline",Mc],["footnote_ref",kc],["autolink",Nc],["htmltag",Zc],["entity",Qc]];function hi(){this.ruler=new Ke();for(var i=0;i<wi.length;i++)this.ruler.push(wi[i][0],wi[i][1]);this.validateLink=el;}hi.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);};hi.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();};hi.prototype.parse=function(i,e,t,n){var s=new on(i,this,e,t,n);this.tokenize(s);};function el(i){var e=["vbscript","javascript","file","data"],t=i.trim().toLowerCase();return t=tn(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var tl={options:{html:!1,// Enable HTML tags in source
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;}));}}]);}();Mt.TEXT_INPUT_ID="text-input";var Us=Mt;var en=/*#__PURE__*/function(){function en(){_classCallCheck(this,en);}return _createClass(en,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),(Ue.IS_MOBILE||Ue.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(Us.TEXT_INPUT_ID));t&&en.focusEndOfInput(t);}}]);}();var Mo="Authentication",ce="Authorization",va="authorization",di="Unauthorized",Zi="Authorization header",Ft="Invalid",xs="Incorrect",Ae="authentication_error",et="invalid_request_error",$="Content-Type",Ea="content-type",J="application/json",F="object",Ji="completed",xe="Bearer ",le="GET",me="POST",Qi="Upload an audio file",Ls="function_call",Yt="input_audio",He="image_url",Sn="system",ri=/*#__PURE__*/function(){function ri(){_classCallCheck(this,ri);}return _createClass(ri,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]:ri.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===ge.ENTER&&setTimeout(t);};}}]);}();ri.CODE_SNIPPET_GENERATION_JUMP=1;var q=ri;var oi=/*#__PURE__*/function(){function oi(){_classCallCheck(this,oi);}return _createClass(oi,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);},oi.LOAD_VOICES_MS);}}]);}();oi.LOAD_VOICES_MS=200;var vn=oi;var fn=/*#__PURE__*/function(){function fn(){_classCallCheck(this,fn);}return _createClass(fn,null,[{key:"colorToHex",value:function colorToHex(e){var t=x();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.styles)==null?void 0:n.bubble)!=null&&s.color){var r=fn.colorToHex(t.styles.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=fn.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");}}]);}();fn.BUBBLE_CLASS="deep-chat-loading-message-bubble",fn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var ht=fn;var ae=/*#__PURE__*/function(){function ae(){_classCallCheck(this,ae);}return _createClass(ae,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var n=e.containerStyle;n&&(Object.assign(t[v],n),console[f]("The containerStyle property".concat(We,"1.3.14.")),console[f]("".concat(Ut,"the style property instead: ").concat(K,"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(We,"1.3.0.")),console[f]("".concat(Ut,"the new response object: ").concat(K,"connect#Response")),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console[f]("The initialMessages property".concat(We,"2.0.0.")),console[f]("".concat(Ut,"the history property instead: ").concat(K,"messages/#history")),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e[ee];t&&(console[f]("The file property in MessageContent".concat(We,"1.3.17.")),console[f]("".concat(Ut,"the files array property: ").concat(K,"messages/#MessageContent")),e[y]=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console[f]("The validateMessageBeforeSending property".concat(We,"1.3.24.")),console[f]("".concat(Ut,"validateInput: ").concat(K,"interceptors#validateInput")),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console[f]("The submitUserMessage(text: string) argument string type".concat(We,"1.4.4.")),console[f]("".concat(Ut,"the new argument type: ").concat(K,"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(We,"1.4.4.")),console[f]("".concat(Ut,"using {..., overwrite: true} object: ").concat(K,"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(We,"2.0.0.")),console[f]("".concat(Ts,"connect object: ").concat(K,"connect#connect-1")));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console[f]("The stream property".concat(kr,"the connect object in version 2.0.0.")),console[f]("".concat(Ts,"connect object: ").concat(K,"connect#connect-1")),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var s;var n=e;n.onNewMessage&&(console[f]("The onNewMessage event".concat(We,"2.0.0.")),console[f]("".concat(Ts,"onMessage event: ").concat(K,"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(We,"2.0.0.")),console[f]("Please use the connect property instead: ".concat(K,"files")),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=w(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(hn,"2.1.0.")),console[f]("Check it out here: ".concat(K,"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(We,"2.1.0.")),console[f]("Please use displayLoading instead: ".concat(K,"modes#demo")),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,n="".concat(Ts,"official documentation: ").concat(K,"directConnection/Cohere");return t.chat&&(console[f]("Cohere chat property".concat(We,"2.2.3.")),console[f](n),delete t.chat),t.textGeneration?(console[f]("Cohere textGeneration".concat(Mr,"2.2.3.")),console[f](n),delete t.textGeneration,!1):t.summarization?(console[f]("Cohere summarization".concat(Mr,"2.2.3.")),console[f](n),delete t.summarization,!1):!0;}},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==F)return;var t=e.htmlWrappers;if(t)return console[f]("The htmlWrappers property".concat(kr,"Deep Chat's base").concat(hn,"2.3.0.")),console[f]("Check it out here: ".concat(K,"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(hn,"2.3.0.")),console[f]("Check it out here: ".concat(K,"modes#focusMode")),e.smoothScroll=!0),e;}},{key:"processPosition",value:function processPosition(e){if(!e)return e;var t="Position names have been updated".concat(hn,"2.3.1.");return e==="inside-left"?(console[f](t),En):e==="inside-right"?(console[f](t),dt):e==="outside-left"?(console[f](t),Me):e==="outside-right"?(console[f](t),be):e;}},{key:"processBrowserStorage",value:function processBrowserStorage(e){var t=e.get();t&&Array.isArray(t)&&e.addMessages(t);}}]);}();var hn=" since version ",We=" is deprecated ".concat(hn),Ut="Please change to using ",Ts="Please see the ",Mr=" is not supported ".concat(hn),kr=" has been moved to ";var At=/*#__PURE__*/function(){function At(){_classCallCheck(this,At);}return _createClass(At,null,[{key:"mouseUp",value:function mouseUp(e,t){re.unsetAllCSSMouseStates(e,t),Object.assign(e[v],t[A]),Object.assign(e[v],t[Oe]);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e[v],t[X]);}},{key:"mouseLeave",value:function mouseLeave(e,t){re.unsetAllCSSMouseStates(e,t),Object.assign(e[v],t[A]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e[v],t[Oe]);}},{key:"add",value:function add(e,t){e.addEventListener("mouseenter",At.mouseEnter.bind(this,e,t)),e.addEventListener("mouseleave",At.mouseLeave.bind(this,e,t)),e.addEventListener("mousedown",At.mouseDown.bind(this,e,t)),e.addEventListener("mouseup",At.mouseUp.bind(this,e,t));}}]);}();var Sa="deep-chat-temporary-message",xa="deep-chat-suggestion-button",Ii={"deep-chat-button":{styles:_defineProperty(_defineProperty(_defineProperty({},A,{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"}),Oe,{backgroundColor:"#fafafa"}),X,{backgroundColor:"#f1f1f1"})}},Pr=Object.keys(Ii);var pt=/*#__PURE__*/function(){function pt(){_classCallCheck(this,pt);}return _createClass(pt,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener(X,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(Sa):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return Pr.find(function(t){return e[m].contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var n=Ii[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.styles;return l&&e[c].styles&&a.push(l),a;},[]),r=Ii[n].styles;if(r){var a=w(r);a[A]&&re.overwriteDefaultWithAlreadyApplied(a,t),s.unshift(a);}var o=re.mergeStatefulStyles(s);return re.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,n){Pr.forEach(function(r){var o=n.getElementsByClassName(r);Array.from(o||[]).forEach(function(a){var c=pt.getProcessedStyles(t,a,r);se.applyStylesToElement(a,c),pt.applyEvents(a,r);});});var s=n.getElementsByClassName(xa);Array.from(s).forEach(function(r){return pt.applySuggestionEvent(e,r);});}}]);}();var se=/*#__PURE__*/function(){function se(){_classCallCheck(this,se);}return _createClass(se,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var n=re.processStateful(t);At.add(e,n),Object.assign(e[v],n[A]);}},{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&&se.applyEventsToElement(e,n),s&&!pt.doesElementContainDeepChatClass(e)&&se.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]&&se.applyClassUtilitiesToElement(r,e[n]);});});}},{key:"apply",value:function apply(e,t){pt.applyDeepChatUtilities(e,e.htmlClassUtilities,t),se.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){se.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){se.traverseNodes(r,s);}),s;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=x();return t.innerHTML=e,pt.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[A]);if(r)return e.innerHTML=r,{contentEl:se.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(aa)[0]||e;}}]);}();var kt=/*#__PURE__*/function(){function kt(){_classCallCheck(this,kt);}return _createClass(kt,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(kt.HTML_BUBBLE_CLASS);var _se$tryAddWrapper=se.tryAddWrapper(o.bubbleElement,t,e._customWrappers,n),a=_se$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,n){n.bubbleElement.innerHTML=t,se.apply(e,n.outerContainer),ae.flagHTMLUpdateClass(n.bubbleElement);}// prettier-ignore
18
+ },{key:"overwrite",value:function overwrite(e,t,n,s){var r=e.messageToElements,o=N.overwriteMessage(r,s,t,n,P,kt.HTML_BUBBLE_CLASS);return o&&kt.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=kt.createElements(e,t,n,s);return N.fillEmptyMessageElement(r.bubbleElement,t),se.apply(e,r.outerContainer),ae.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,n,!1,(o=e.messageStyles)==null?void 0:o[P]),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&&se.isTemporaryBasedOnHTML(t))return;var o=kt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();kt.HTML_BUBBLE_CLASS="html-message";var ft=kt;var Aa=/*#__PURE__*/function(){function Aa(){_classCallCheck(this,Aa);}return _createClass(Aa,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 b=!1,_=p.bMarks[u]+p.tShift[u],E=p.eMarks[u];if(_+1>E)return!1;var R=p[C].charAt(_);if(R!==a)return!1;var z=_;_=p.skipChars(_,R);var te=_-z;if(te!==2)return!1;var ne=u;for(;++ne,!(ne>=g||(_=z=p.bMarks[ne]+p.tShift[ne],E=p.eMarks[ne],_<E&&p.tShift[ne]<p.blkIndent));)if(p[C].charAt(_)===a&&!(p.tShift[ne]-p.blkIndent>=4)&&(_=p.skipChars(_,R),!(_-z<te)&&(_=p.skipSpaces(_),!(_<E)))){b=!0;break;}te=p.tShift[u],p.line=ne+(b?1:0);var we=p.getLines(u+1,ne,te,!0).replace(/[ \n]+/g," ").trim();return p.tokens.push({type:"katex",params:null,content:we,lines:[u,p.line],level:p.level,block:!0}),!0;},d=function d(p,u){var g=p.pos,b=p.posMax;var _=g;if(p[C].charAt(_)!==a)return!1;for(++_;_<b&&p[C].charAt(_)===a;)++_;var E=p[C].slice(g,_);if(E.length>2)return!1;var R=_;var z=0;for(;_<b;){var te=p[C].charAt(_);if(te==="{"&&(_===0||p[C].charAt(_-1)!=="\\"))z+=1;else if(te==="}"&&(_===0||p[C].charAt(_-1)!=="\\")){if(z-=1,z<0)return!1;}else if(te===a&&z===0){var ne=_;var we=_+1;for(;we<b&&p[C].charAt(we)===a;)++we;if(we-ne===E.length){if(!u){var Rt=p[C].slice(R,ne).replace(/[ \n]+/g," ").trim();p.push({type:"katex",content:Rt,block:E.length>1,level:p.level});}return p.pos=we,!0;}}_+=1;}return u||(p.pending+=E),p.pos+=E.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 Rs;function ko(i){return Rs=Rs||document.createElement("textarea"),Rs.innerHTML="&"+i+";",Rs.value;}var wa=Object.prototype.hasOwnProperty;function Ca(i,e){return i?wa.call(i,e):!1;}function Po(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 Ta=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ms(i){return i.indexOf("\\")<0?i:i.replace(Ta,"$1");}function Lo(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 Mi(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 Ra=/&([a-z#][a-z0-9]{1,31});/gi,Ia=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function Ma(i,e){var t=0,n=ko(e);return e!==n?n:e.charCodeAt(0)===35&&Ia.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),Lo(t))?Mi(t):i;}function tn(i){return i.indexOf("&")<0?i:i.replace(Ra,Ma);}var ka=/[&<>"]/,Pa=/[&<>"]/g,La={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function Oa(i){return La[i];}function je(i){return ka.test(i)?i.replace(Pa,Oa):i;}var T={};T.blockquote_open=function(){return"<blockquote>\n";};T.blockquote_close=function(i,e){return"</blockquote>"+rn(i,e);};T.code=function(i,e){return i[e].block?"<pre><code>"+je(i[e].content)+"</code></pre>"+rn(i,e):"<code>"+je(i[e].content)+"</code>";};T.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(" "),Ca(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=je(tn(ms(d))),o=' class="'+a+c+'"';}return t.highlight?p=t.highlight.apply(t.highlight,[r.content].concat(l))||je(r.content):p=je(r.content),"<pre><code"+o+">"+p+"</code></pre>"+rn(i,e);};T.fence_custom={};T.heading_open=function(i,e){return"<h"+i[e].hLevel+">";};T.heading_close=function(i,e){return"</h"+i[e].hLevel+">\n";};T.hr=function(i,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+rn(i,e);};T.bullet_list_open=function(){return"<ul>\n";};T.bullet_list_close=function(i,e){return"</ul>"+rn(i,e);};T.list_item_open=function(){return"<li>";};T.list_item_close=function(){return"</li>\n";};T.ordered_list_open=function(i,e){var t=i[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};T.ordered_list_close=function(i,e){return"</ol>"+rn(i,e);};T.paragraph_open=function(i,e){return i[e].tight?"":"<p>";};T.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?rn(i,e):"");};T.link_open=function(i,e,t){var n=i[e].title?' title="'+je(tn(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+je(i[e].href)+'"'+n+s+">";};T.link_close=function(){return"</a>";};T.image=function(i,e,t){var n=' src="'+je(i[e].src)+'"',s=i[e].title?' title="'+je(tn(i[e].title))+'"':"",r=' alt="'+(i[e].alt?je(tn(ms(i[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+r+s+o+">";};T.table_open=function(){return"<table>\n";};T.table_close=function(){return"</table>\n";};T.thead_open=function(){return"<thead>\n";};T.thead_close=function(){return"</thead>\n";};T.tbody_open=function(){return"<tbody>\n";};T.tbody_close=function(){return"</tbody>\n";};T.tr_open=function(){return"<tr>";};T.tr_close=function(){return"</tr>\n";};T.th_open=function(i,e){var t=i[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};T.th_close=function(){return"</th>";};T.td_open=function(i,e){var t=i[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};T.td_close=function(){return"</td>";};T.strong_open=function(){return"<strong>";};T.strong_close=function(){return"</strong>";};T.em_open=function(){return"<em>";};T.em_close=function(){return"</em>";};T.del_open=function(){return"<del>";};T.del_close=function(){return"</del>";};T.ins_open=function(){return"<ins>";};T.ins_close=function(){return"</ins>";};T.mark_open=function(){return"<mark>";};T.mark_close=function(){return"</mark>";};T.sub=function(i,e){return"<sub>"+je(i[e].content)+"</sub>";};T.sup=function(i,e){return"<sup>"+je(i[e].content)+"</sup>";};T.hardbreak=function(i,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};T.softbreak=function(i,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};T.text=function(i,e){return je(i[e].content);};T.htmlblock=function(i,e){return i[e].content;};T.htmltag=function(i,e){return i[e].content;};T.abbr_open=function(i,e){return'<abbr title="'+je(tn(i[e].title))+'">';};T.abbr_close=function(){return"</abbr>";};T.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>";};T.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";};T.footnote_block_close=function(){return"</ol>\n</section>\n";};T.footnote_open=function(i,e){var t=Number(i[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};T.footnote_close=function(){return"</li>\n";};T.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>';};T.dl_open=function(){return"<dl>\n";};T.dt_open=function(){return"<dt>";};T.dd_open=function(){return"<dd>";};T.dl_close=function(){return"</dl>\n";};T.dt_close=function(){return"</dt>\n";};T.dd_close=function(){return"</dd>\n";};function Oo(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?Oo(i,e+2):e;}var rn=T.getBreak=function(e,t){return t=Oo(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function er(){this.rules=Po({},T),this.getBreak=T.getBreak;}er.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;};er.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 Ke(){this.__rules__=[],this.__cache__=null;}Ke.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};Ke.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));});});};Ke.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;};Ke.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;};Ke.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;};Ke.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};Ke.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;};Ke.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;};Ke.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function Na(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 on(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;}on.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};on.prototype.push=function(i){this.pending&&this.pushPending(),this.tokens.push(i),this.pendingLevel=this.level;};on.prototype.cacheSet=function(i,e){for(var t=this.cache.length;t<=i;t++)this.cache.push(0);this.cache[i]=e;};on.prototype.cacheGet=function(i){return i<this.cache.length?this.cache[i]:0;};function gs(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 Ba(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 on(i,e,t,n,[]),r=gs(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 Da(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=Ba(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 ki(i){var e=tn(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function No(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=ki(ms(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=ms(i.src.slice(r,e)),!i.parser.validateLink(s))?!1:(i.linkContent=s,i.pos=e,!0);}function Bo(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=ms(i.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function Do(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function Fa(i,e,t,n){var s,r,o,a,c,l,d,p,u;if(i.charCodeAt(0)!==91||i.indexOf("]:")===-1||(s=new on(i,e,t,n,[]),r=gs(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(!No(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&&Bo(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=Do(i.slice(1,r)),_typeof(n.references[u])>"u"&&(n.references[u]={title:p,href:d}),o);}function Ua(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=Fa(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 Ha(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 ja(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 Lr=" \n()[]'\".,!?-";function xi(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function $a(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="(^|["+Lr.split("").map(xi).join("")+"])("+Object.keys(i.env.abbreviations).map(function(b){return b.substr(1);}).sort(function(b,_){return _.length-b.length;}).map(xi).join("|")+")($|["+Lr.split("").map(xi).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 qa=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Ga=/\((c|tm|r|p)\)/ig,za={c:"©",r:"®",p:"§",tm:"™"};function Va(i){return i.indexOf("(")<0?i:i.replace(Ga,function(e,t){return za[t.toLowerCase()];});}function Ka(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=Va(n),qa.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 Wa=/['"]/,Or=/['"]/g,Xa=/[-\s()\[\]]/,Nr="’";function Br(i,e){return e<0||e>=i.length?!1:!Xa.test(i[e]);}function ln(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function Ya(i){var e,t,n,s,r,o,a,c,l,d,p,u,g,b,_,E,R;if(i.options.typographer){for(R=[],_=i.tokens.length-1;_>=0;_--)if(i.tokens[_].type==="inline"){for(E=i.tokens[_].children,R.length=0,e=0;e<E.length;e++)if(t=E[e],!(t.type!=="text"||Wa.test(t.text))){for(a=E[e].level,g=R.length-1;g>=0&&!(R[g].level<=a);g--);R.length=g+1,n=t.content,r=0,o=n.length;e:for(;r<o&&(Or.lastIndex=r,s=Or.exec(n),!!s);){if(c=!Br(n,s.index-1),r=s.index+1,b=s[0]==="'",l=!Br(n,r),!l&&!c){b&&(t.content=ln(t.content,s.index,Nr));continue;}if(p=!l,u=!c,u){for(g=R.length-1;g>=0&&(d=R[g],!(R[g].level<a));g--)if(d.single===b&&R[g].level===a){d=R[g],b?(E[d.token].content=ln(E[d.token].content,d.pos,i.options.quotes[2]),t.content=ln(t.content,s.index,i.options.quotes[3])):(E[d.token].content=ln(E[d.token].content,d.pos,i.options.quotes[0]),t.content=ln(t.content,s.index,i.options.quotes[1])),R.length=g;continue e;}}p?R.push({token:e,pos:s.index,single:b,level:a}):u&&b&&(t.content=ln(t.content,s.index,Nr));}}}}}var Ai=[["block",Na],["abbr",Da],["references",Ua],["inline",Ha],["footnote_tail",ja],["abbr2",$a],["replacements",Ka],["smartquotes",Ya]];function Fo(){this.options={},this.ruler=new Ke();for(var i=0;i<Ai.length;i++)this.ruler.push(Ai[i][0],Ai[i][1]);}Fo.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 an(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;}an.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};an.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};an.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};an.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};an.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;};an.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 Za(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 Ja(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 Qa(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,_=i.bMarks[e]+i.tShift[e],E=i.eMarks[e];if(_>E||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]=_,_=_<E?i.skipSpaces(_):_,r=_>=E,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],E=i.eMarks[s],!(_>=E));s++){if(i.src.charCodeAt(_++)===62){i.src.charCodeAt(_)===32&&_++,a.push(i.bMarks[s]),i.bMarks[s]=_,_=_<E?i.skipSpaces(_):_,r=_>=E,o.push(i.tShift[s]),i.tShift[s]=_-i.bMarks[s];continue;}if(r)break;for(b=!1,u=0,g=p.length;u<g;u++)if(p[u](i,s,t,!0)){b=!0;break;}if(b)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 ec(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 Dr(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 Fr(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 tc(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 nc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,_,E,R,z,te,ne,we,Rt=!0,It,qe,xr,vi;if((p=Fr(i,e))>=0)E=!0;else if((p=Dr(i,e))>=0)E=!1;else return!1;if(i.level>=i.options.maxNesting)return!1;if(_=i.src.charCodeAt(p-1),n)return!0;for(z=i.tokens.length,E?(d=i.bMarks[e]+i.tShift[e],b=Number(i.src.substr(d,p-d-1)),i.tokens.push({type:"ordered_list_open",order:b,lines:ne=[e,0],level:i.level++})):i.tokens.push({type:"bullet_list_open",lines:ne=[e,0],level:i.level++}),s=e,te=!1,It=i.parser.ruler.getRules("list");s<t&&(R=i.skipSpaces(p),u=i.eMarks[s],R>=u?g=1:g=R-p,g>4&&(g=1),g<1&&(g=1),r=p-i.bMarks[s]+g,i.tokens.push({type:"list_item_open",lines:we=[e,0],level:i.level++}),a=i.blkIndent,c=i.tight,o=i.tShift[e],l=i.parentType,i.tShift[e]=R-i.bMarks[e],i.blkIndent=r,i.tight=!0,i.parentType="list",i.parser.tokenize(i,e,t,!0),(!i.tight||te)&&(Rt=!1),te=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,we[1]=s,R=i.bMarks[e],!(s>=t||i.isEmpty(s)||i.tShift[s]<i.blkIndent));){for(vi=!1,qe=0,xr=It.length;qe<xr;qe++)if(It[qe](i,s,t,!0)){vi=!0;break;}if(vi)break;if(E){if(p=Fr(i,s),p<0)break;}else if(p=Dr(i,s),p<0)break;if(_!==i.src.charCodeAt(p-1))break;}return i.tokens.push({type:E?"ordered_list_close":"bullet_list_close",level:--i.level}),ne[1]=s,i.line=s,Rt&&tc(i,z),!0;}function sc(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 ic(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 rc(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 Uo={};["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){Uo[i]=!0;});var oc=/^<([a-zA-Z]{1,15})[\s\/>]/,ac=/^<\/([a-zA-Z]{1,15})[\s>]/;function cc(i){var e=i|32;return e>=97&&e<=122;}function lc(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||cc(s)){if(s===47){if(r=i.src.slice(a,c).match(ac),!r)return!1;}else if(r=i.src.slice(a,c).match(oc),!r)return!1;if(Uo[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 wi(i,e){var t=i.bMarks[e]+i.blkIndent,n=i.eMarks[e];return i.src.substr(t,n-t);}function dc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b;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=wi(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=wi(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:b=[e+2,0],level:i.level++}),c=e+2;c<t&&!(i.tShift[c]<i.blkIndent||(r=wi(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]=b[1]=c,i.line=c,!0;}function Is(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 hc(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 uc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,_,E,R;if(n)return i.ddIndent<0?!1:Is(i,e)>=0;if(d=e+1,i.isEmpty(d)&&++d>t||i.tShift[d]<i.blkIndent||(s=Is(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(R=!0,E=!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,b=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||E)&&(R=!1),E=i.line-r>1&&i.isEmpty(i.line-1),i.tShift[r]=b,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=Is(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=Is(i,r),s<0))break;}return i.tokens.push({type:"dl_close",level:--i.level}),c[1]=d,i.line=d,R&&hc(i,l),!0;}function pc(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 Ms=[["code",Za],["fences",Ja,["paragraph","blockquote","list"]],["blockquote",Qa,["paragraph","blockquote","list"]],["hr",ec,["paragraph","blockquote","list"]],["list",nc,["paragraph","blockquote"]],["footnote",sc,["paragraph"]],["heading",ic,["paragraph","blockquote"]],["lheading",rc],["htmlblock",lc,["paragraph","blockquote"]],["table",dc,["paragraph"]],["deflist",uc,["paragraph"]],["paragraph",pc]];function tr(){this.ruler=new Ke();for(var i=0;i<Ms.length;i++)this.ruler.push(Ms[i][0],Ms[i][1],{alt:(Ms[i][2]||[]).slice()});}tr.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 fc=/[\n\t]/g,mc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,gc=/\u00a0/g;tr.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(gc," "),i=i.replace(mc,"\n"),i.indexOf(" ")>=0&&(i=i.replace(fc,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 an(i,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function yc(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 bc(i,e){for(var t=i.pos;t<i.posMax&&!yc(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function _c(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 nr=[];for(var Ur=0;Ur<256;Ur++)nr.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){nr[i.charCodeAt(0)]=1;});function vc(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&&nr[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 Ec(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 Sc(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 xc(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 Ac(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 Hr(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&&(Hr(n)&&(o=!1),Hr(s)&&(a=!1))),{can_open:o,can_close:a,delims:r};}function wc(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 Cc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Tc(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(Cc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var Rc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Ic(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(Rc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function Mc(i,e){var t,n,s,r,o,a,c,l,d=!1,p=i.pos,u=i.posMax,g=i.pos,b=i.src.charCodeAt(g);if(b===33&&(d=!0,b=i.src.charCodeAt(++g)),b!==91||i.level>=i.options.maxNesting||(t=g+1,n=gs(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,No(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&&Bo(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=gs(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[Do(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 kc(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=gs(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 Pc(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 Lc=["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"],Oc=/^<([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])?)*)>/,Nc=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Bc(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(Nc),n?Lc.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=ki(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(Oc),s?(r=s[0].slice(1,-1),o=ki("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 hi(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 Dc=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Fc=/[^"'=<>`\x00-\x20]+/,Uc=/'[^']*'/,Hc=/"[^"]*"/,jc=hi(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Fc)("single_quoted",Uc)("double_quoted",Hc)(),$c=hi(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Dc)("attr_value",jc)(),qc=hi(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",$c)(),Gc=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,zc=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Vc=/<[?].*?[?]>/,Kc=/<![A-Z]+\s+[^>]*>/,Wc=/<!\[CDATA\[[\s\S]*?\]\]>/,Xc=hi(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",qc)("close_tag",Gc)("comment",zc)("processing",Vc)("declaration",Kc)("cdata",Wc)();function Yc(i){var e=i|32;return e>=97&&e<=122;}function Zc(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&&!Yc(t))||(n=i.src.slice(r).match(Xc),!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 Jc=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Qc=/^&([a-z][a-z0-9]{1,31});/i;function el(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(Jc),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=Lo(n)?Mi(n):Mi(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match(Qc),s){var a=ko(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 Ci=[["text",bc],["newline",_c],["escape",vc],["backticks",Ec],["del",Sc],["ins",xc],["mark",Ac],["emphasis",wc],["sub",Tc],["sup",Ic],["links",Mc],["footnote_inline",kc],["footnote_ref",Pc],["autolink",Bc],["htmltag",Zc],["entity",el]];function ui(){this.ruler=new Ke();for(var i=0;i<Ci.length;i++)this.ruler.push(Ci[i][0],Ci[i][1]);this.validateLink=tl;}ui.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);};ui.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();};ui.prototype.parse=function(i,e,t,n){var s=new on(i,this,e,t,n);this.tokenize(s);};function tl(i){var e=["vbscript","javascript","file","data"],t=i.trim().toLowerCase();return t=tn(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var nl={options:{html:!1,// Enable HTML tags in source
19
19
  xhtmlOut:!1,// Use '/' to close single tags (<br />)
20
20
  breaks:!1,// Convert '\n' in paragraphs into <br>
21
21
  langPrefix:"language-",// CSS language prefix for fenced blocks
@@ -29,7 +29,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
29
29
  // function (/*str, lang*/) { return ''; }
30
30
  //
31
31
  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"]}}},nl={options:{html:!1,// Enable HTML tags in source
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"]}}},sl={options:{html:!1,// Enable HTML tags in source
33
33
  xhtmlOut:!1,// Use '/' to close single tags (<br />)
34
34
  breaks:!1,// Convert '\n' in paragraphs into <br>
35
35
  langPrefix:"language-",// CSS language prefix for fenced blocks
@@ -44,7 +44,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
44
44
  //
45
45
  highlight:null,maxNesting:20// Internal protection, recursion limit
46
46
  },components:{// Don't restrict core/block/inline rules
47
- core:{},block:{},inline:{}}},sl={options:{html:!0,// Enable HTML tags in source
47
+ core:{},block:{},inline:{}}},il={options:{html:!0,// Enable HTML tags in source
48
48
  xhtmlOut:!0,// Use '/' to close single tags (<br />)
49
49
  breaks:!1,// Convert '\n' in paragraphs into <br>
50
50
  langPrefix:"language-",// CSS language prefix for fenced blocks
@@ -58,47 +58,47 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
58
58
  // function (/*str, lang*/) { return ''; }
59
59
  //
60
60
  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"]}}},il={"default":tl,full:nl,commonmark:sl};function Uo(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 mt(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 hi(),this.block=new er(),this.core=new Do(),this.renderer=new Qi(),this.ruler=new Ke(),this.options={},this.configure(il[i]),this.set(e||{});}mt.prototype.set=function(i){ko(this.options,i);};mt.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);});};mt.prototype.use=function(i,e){return i(this,e),this;};mt.prototype.parse=function(i,e){var t=new Uo(this,i,e);return this.core.process(t),t.tokens;};mt.prototype.render=function(i,e){return e=e||{},this.renderer.render(this.parse(i,e),this.options,e);};mt.prototype.parseInline=function(i,e){var t=new Uo(this,i,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};mt.prototype.renderInline=function(i,e){return e=e||{},this.renderer.render(this.parseInline(i,e),this.options,e);};var zt=/*#__PURE__*/function(){function zt(){_classCallCheck(this,zt);}return _createClass(zt,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(xa.katex.bind(this,r),{delimiter:s});}}},{key:"instantiate",value:function instantiate(e){if(e)return new mt(_objectSpread(_objectSpread({},zt.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new mt({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
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"]}}},rl={"default":nl,full:sl,commonmark:il};function Ho(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 mt(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 ui(),this.block=new tr(),this.core=new Fo(),this.renderer=new er(),this.ruler=new Ke(),this.options={},this.configure(rl[i]),this.set(e||{});}mt.prototype.set=function(i){Po(this.options,i);};mt.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);});};mt.prototype.use=function(i,e){return i(this,e),this;};mt.prototype.parse=function(i,e){var t=new Ho(this,i,e);return this.core.process(t),t.tokens;};mt.prototype.render=function(i,e){return e=e||{},this.renderer.render(this.parse(i,e),this.options,e);};mt.prototype.parseInline=function(i,e){var t=new Ho(this,i,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};mt.prototype.renderInline=function(i,e){return e=e||{},this.renderer.render(this.parseInline(i,e),this.options,e);};var zt=/*#__PURE__*/function(){function zt(){_classCallCheck(this,zt);}return _createClass(zt,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(Aa.katex.bind(this,r),{delimiter:s});}}},{key:"instantiate",value:function instantiate(e){if(e)return new mt(_objectSpread(_objectSpread({},zt.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new mt({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
62
  xhtmlOut:!1,// Use '/' to close single tags (<br />)
63
63
  breaks:!0,// Convert '\n' in paragraphs into <br>
64
64
  langPrefix:"language-",// CSS language prefix for fenced blocks
65
65
  linkTarget:"_blank",// set target to open in a new tab
66
66
  typographer:!0// Enable smartypants and other sweet transforms
67
67
  });}else return new mt(zt.DEFAULT_PROPERTIES);}},{key:"createNew",value:function createNew(e){var t=zt.instantiate(e);return zt.addPlugins(t,e),t.inline.validateLink=function(){return!0;},t;}}]);}();zt.DEFAULT_PROPERTIES={breaks:!0,linkTarget:"_blank"// set target to open in a new tab
68
- };var gs=zt;var rl=/*#__PURE__*/function(){function rl(e){_classCallCheck(this,rl);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),ae.processBrowserStorage(this));}return _createClass(rl,[{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,oe(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 Le=/*#__PURE__*/function(){function Le(){_classCallCheck(this,Le);}return _createClass(Le,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&&(Le.applyCustomStylesToElements(e,n,s.shared),t===D?Le.applyCustomStylesToElements(e,n,s.user):(Le.applyCustomStylesToElements(e,n,s.ai),Le.applyCustomStylesToElements(e,n,s[t])));}},{key:"isElementsStyles",value:function isElementsStyles(e){return!!(e.outerContainer||e.innerContainer||e.bubble||e.media);}// prettier-ignore
68
+ };var ys=zt;var ol=/*#__PURE__*/function(){function ol(e){_classCallCheck(this,ol);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),ae.processBrowserStorage(this));}return _createClass(ol,[{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,oe(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 Le=/*#__PURE__*/function(){function Le(){_classCallCheck(this,Le);}return _createClass(Le,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&&(Le.applyCustomStylesToElements(e,n,s.shared),t===D?Le.applyCustomStylesToElements(e,n,s.user):(Le.applyCustomStylesToElements(e,n,s.ai),Le.applyCustomStylesToElements(e,n,s[t])));}},{key:"isElementsStyles",value:function isElementsStyles(e){return!!(e.outerContainer||e.innerContainer||e.bubble||e.media);}// prettier-ignore
69
69
  },{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s,r){var o;r&&e[A]!==r?Le.isElementsStyles(r)?(Le.applyCustomStylesToElements(t,s,(o=e[A])==null?void 0:o.shared),Le.applyCustomStylesToElements(t,s,r)):(Le.applySideStyles(t,n,s,e[A]),Le.applySideStyles(t,n,s,r)):Le.applySideStyles(t,n,s,e[A]);}// prettier-ignore
70
70
  },{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 _e=/*#__PURE__*/function(){function _e(){_classCallCheck(this,_e);}return _createClass(_e,null,[{key:"setElementProps",value:// prettier-ignore
71
- function setElementProps(e,t,n,s){var r;n!=="loading"&&(e.applyCustomStyles(t,s,!0,(r=e.messageStyles)==null?void 0:r[n]),t.bubbleElement[m].add(xo));}// prettier-ignore
71
+ function setElementProps(e,t,n,s){var r;n!=="loading"&&(e.applyCustomStyles(t,s,!0,(r=e.messageStyles)==null?void 0:r[n]),t.bubbleElement[m].add(Ao));}// prettier-ignore
72
72
  },{key:"addMessage",value:function addMessage(e,t,n,s,r){_e.setElementProps(e,t,n,s),r||e.appendOuterContainerElemet(t.outerContainer);}},{key:"wrapInLink",value:function wrapInLink(e,t,n){var s=x("a");return s.href=t,s.download=n||ee,s.target="_blank",s.appendChild(e),s;}},{key:"isNonLinkableDataUrl",value:function isNonLinkableDataUrl(e,t){return!t.startsWith("data")||e===V?!1:e===Jt&&t.startsWith("data:text/javascript")||!t.startsWith("data:image")&&!t.startsWith("data:application");}},{key:"processContent",value:function processContent(e,t,n,s){return!n||_e.isNonLinkableDataUrl(e,n)?t:_e.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"))_e.waitToLoadThenScroll(t);else try{fetch(e,{mode:"no-cors"})["catch"](function(){})["finally"](function(){_e.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
73
  // But it is not actually used by anything in the chat, hence it is removed when adding a message
74
74
  // after the body has been stringified and parsed - the file reference will disappear, hence this readds it
75
75
  },{key:"reAddFileRefToObject",value:function reAddFileRefToObject(e,t){var n;(n=e[y])==null||n.forEach(function(s,r){var o;s.ref&&(o=t[y])!=null&&o[r]&&(t[y][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===j||(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===V||(n==null?void 0:n.startsWith("data:image"))||n&&_e.isImageFileExtension(n);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();var nn=/*#__PURE__*/function(){function nn(){_classCallCheck(this,nn);}return _createClass(nn,null,[{key:"onMessage",value:function onMessage(e,t,n){var r;var s=w({message:t,isHistory:n,isInitial:n});_e.reAddFileRefToObject(t,s.message),(r=e.onMessage)==null||r.call(e,s),e.dispatchEvent(new CustomEvent("message",{detail:s})),ae.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=w({content:t,isUser:n});t[y]&&_e.reAddFileRefToObject(_defineProperty({},y,(r=t[y])==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 Se=/*#__PURE__*/function(){function Se(){_classCallCheck(this,Se);}return _createClass(Se,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=x();return e[m].add("loading-history"),e.appendChild(x()),e.appendChild(x()),e.appendChild(x()),e.appendChild(x()),e;}},{key:"apply",value:function apply(e,t,n){ht.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=w(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,b;e.bubbleElement[m].add(Se.CLASS);var s=n?Se.FULL_VIEW_CLASS:Se.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.styles:(b=(g=(u=(p=t.messageStyles)==null?void 0:p.loading)==null?void 0:u.history)==null?void 0:g.small)==null?void 0:b.styles;Se.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==wo&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",Q),n=t.bubbleElement,s=Se.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[P],s=n?ft.createElements(e,n,Q,!0,!0):Se.createDefaultElements(e);return Se.addLoadHistoryMessage(s,e,t),N.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(Se.FULL_VIEW_CLASS)){t.outerContainer[m].replace(Se.FULL_VIEW_CLASS,Se.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.styles;p&&Se.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[P];return u&&(t.bubbleElement.innerHTML=u),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];Se.tryChangeViewToSmall(e,t)||Se.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();Se.CLASS="loading-history-message",Se.FULL_VIEW_CLASS="loading-history-message-full-view",Se.SMALL_CLASS="loading-history-message-small";var wt=Se;var cs=/*#__PURE__*/function(){function cs(){_classCallCheck(this,cs);}return _createClass(cs,null,[{key:"setFade",value:function setFade(e,t){e[v].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(cs.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:cs.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;}()}]);}();cs.DEFAULT_FADE_MS=500;var Us=cs;var Ht=/*#__PURE__*/function(){function Ht(e,t,n){_classCallCheck(this,Ht);if(this.hiddenElements=/* @__PURE__ */new Set(),this.isScrollButton=!1,this.isScrollingToBottom=!1,this._messages=e,t){var _s$styles;var s={};_typeof(t)=="object"&&(s=w(t),s.onUpdate=t.onUpdate),(_s$styles=s.styles)!==null&&_s$styles!==void 0?_s$styles:s.styles={};var r="fit-content";s.styles["default"]=_objectSpread({borderRadius:"10px",width:r,height:r},s.styles["default"]),this.hiddenMessagesConfig=s,this.io=this.initIntersectionObserver(this._messages.elementRef);}if(n){var _s2$styles;var _s2=_typeof(n)=="object"?w(n):{};(_s2$styles=_s2.styles)!==null&&_s2$styles!==void 0?_s2$styles:_s2.styles={},_s2.styles["default"]=_objectSpread({borderRadius:"50%",width:"1.4rem",height:"1.4rem"},_s2.styles["default"]),this.scrollButtonConfig=_s2;}this.element=this.createElement(),this._messages.elementRef.appendChild(this.element);}return _createClass(Ht,[{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=x();return e.id="scroll-button",q.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")q.scrollToBottom(_this4._messages,n),n&&_this4.element&&(Ht.hideElement(_this4.element),_this4.isScrollingToBottom=!0,q.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"});}}),se.apply(this._messages,e),e;}},{key:"assignStyles",value:function assignStyles(e){if(!this.element)return;Object.assign(this.element[v],e[A]);var t=re.processStateful(e);At.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){Ht.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,se.apply(this._messages,this.element);}else this.element.innerHTML=s;(t=this.hiddenMessagesConfig)!=null&&t.styles&&this.assignStyles(this.hiddenMessagesConfig.styles),Ht.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&&!q.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!==Cr&&(Ht.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.styles&&this.assignStyles(this.scrollButtonConfig.styles));}},{key:"updateScroll",value:function updateScroll(){var e;this.isScrollingToBottom||!this.scrollButtonConfig||(q.isScrollbarAtBottomOfElement(this._messages.elementRef,((e=this.scrollButtonConfig)==null?void 0:e.scrollDelta)||80)?this.element&&this.element[v].opacity!==wr&&Ht.hideElement(this.element):(this.displayScroll(),this.isScrollButton=!0));}}],[{key:"displayElement",value:function displayElement(e){e[v].opacity=Cr,e[v].pointerEvents="auto";}},{key:"hideElement",value:function hideElement(e){e[v].opacity=wr,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",ki="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 Ho=/*#__PURE__*/function(){function Ho(e){_classCallCheck(this,Ho);this.className=e;}return _createClass(Ho,[{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 yt=/*#__PURE__*/function(_Ho){function yt(e){var _this6;_classCallCheck(this,yt);_this6=_callSuper(this,yt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(yt,_Ho);return _createClass(yt,[{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===Bt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Bt?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var r,o,a,c,l;var n=x("img");e===D?(n[C]=((r=t==null?void 0:t[D])==null?void 0:r[C])||((o=t==null?void 0:t[A])==null?void 0:o[C])||ki,n.onerror=yt.errorFallback.bind(this,ki)):(n[C]=((a=t==null?void 0:t[e])==null?void 0:a[C])||((c=t==null?void 0:t[Q])==null?void 0:c[C])||((l=t==null?void 0:t[A])==null?void 0:l[C])||jr,n.onerror=yt.errorFallback.bind(this,jr)),n[m].add("avatar"),n.alt="".concat(e," avatar");var s=x();return s[m].add(this.className),s.appendChild(n),t&&yt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,r,o,a,c,l;var n=ae.processPosition((r=(s=t==null?void 0:t[e])==null?void 0:s.styles)==null?void 0:r.position);return e!==D&&(n!==null&&n!==void 0?n:n=(a=(o=t==null?void 0:t.ai)==null?void 0:o.styles)==null?void 0:a.position),n!==null&&n!==void 0?n:n=(l=(c=t==null?void 0:t[A])==null?void 0:c.styles)==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===D?Ao:Bt,n;}}],[{key:"errorFallback",value:function errorFallback(e,t){var n=t.target;n.onerror=null,n[C]=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[A])!=null&&r.styles&&yt.applyCustomStylesToElements(e,t,n[A].styles),s===D)(o=n.user)!=null&&o.styles&&yt.applyCustomStylesToElements(e,t,n.user.styles);else{(a=n.ai)!=null&&a.styles&&yt.applyCustomStylesToElements(e,t,n.ai.styles);var l=(c=n[s])==null?void 0:c.styles;l&&yt.applyCustomStylesToElements(e,t,l);}}}]);}(Ho);var ns=/*#__PURE__*/function(_Ho2){function ns(e){var _this7;_classCallCheck(this,ns);_this7=_callSuper(this,ns,["name"]),_this7._names=e;return _this7;}_inherits(ns,_Ho2);return _createClass(ns,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),r=ns.getPosition(t,n);s[m].add(r===Bt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Bt?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=x();return n[m].add(this.className),n.textContent=ns.getNameText(e,t),ns.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,r,o;var n=ae.processPosition((s=t==null?void 0:t[e])==null?void 0:s.position);return e!==D&&(n!==null&&n!==void 0?n:n=(r=t==null?void 0:t[Q])==null?void 0:r.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[A])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===D?Ao:Bt,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,r,o,a;Object.assign(e[v],(s=n[A])==null?void 0:s[v]),t===D?Object.assign(e[v],(r=n[D])==null?void 0:r[v]):(Object.assign(e[v],(o=n[Q])==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===D?((n=t[D])==null?void 0:n[h])||((s=t[A])==null?void 0:s[h])||"User":e===Q?((r=t[Q])==null?void 0:r[h])||((o=t[A])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[A])==null?void 0:c[h])||e;}}]);}(Ho);var Fe=/*#__PURE__*/function(){function Fe(e){var _this8=this;_classCallCheck(this,Fe);var t,n,s,r;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=Fe.createContainerElement(),this.messageStyles=ae.processMessageStyles(e.messageStyles),this._remarkable=gs.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new yt(e.avatars)),e.names&&(this.name=new ns(e.names)),e.browserStorage&&(this.browserStorage=new rl(e.browserStorage)),this._onMessage=nn.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),(e.hiddenMessages||e.scrollButton)&&(this.scrollButton=new Ht(this,e.hiddenMessages,e.scrollButton)),this.focusMode=ae.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=x(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Us.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||ae.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(Fe,[{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(Fe.TEXT_BUBBLE_CLASS),this.applyCustomStyles(r,t,!1),N.fillEmptyMessageElement(r.bubbleElement,e),r;}// prettier-ignore
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===j||(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===V||(n==null?void 0:n.startsWith("data:image"))||n&&_e.isImageFileExtension(n);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();var nn=/*#__PURE__*/function(){function nn(){_classCallCheck(this,nn);}return _createClass(nn,null,[{key:"onMessage",value:function onMessage(e,t,n){var r;var s=w({message:t,isHistory:n,isInitial:n});_e.reAddFileRefToObject(t,s.message),(r=e.onMessage)==null||r.call(e,s),e.dispatchEvent(new CustomEvent("message",{detail:s})),ae.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=w({content:t,isUser:n});t[y]&&_e.reAddFileRefToObject(_defineProperty({},y,(r=t[y])==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 Se=/*#__PURE__*/function(){function Se(){_classCallCheck(this,Se);}return _createClass(Se,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=x();return e[m].add("loading-history"),e.appendChild(x()),e.appendChild(x()),e.appendChild(x()),e.appendChild(x()),e;}},{key:"apply",value:function apply(e,t,n){ht.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=w(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,b;e.bubbleElement[m].add(Se.CLASS);var s=n?Se.FULL_VIEW_CLASS:Se.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.styles:(b=(g=(u=(p=t.messageStyles)==null?void 0:p.loading)==null?void 0:u.history)==null?void 0:g.small)==null?void 0:b.styles;Se.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==Co&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",Q),n=t.bubbleElement,s=Se.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[P],s=n?ft.createElements(e,n,Q,!0,!0):Se.createDefaultElements(e);return Se.addLoadHistoryMessage(s,e,t),N.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(Se.FULL_VIEW_CLASS)){t.outerContainer[m].replace(Se.FULL_VIEW_CLASS,Se.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.styles;p&&Se.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[P];return u&&(t.bubbleElement.innerHTML=u),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];Se.tryChangeViewToSmall(e,t)||Se.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();Se.CLASS="loading-history-message",Se.FULL_VIEW_CLASS="loading-history-message-full-view",Se.SMALL_CLASS="loading-history-message-small";var wt=Se;var ls=/*#__PURE__*/function(){function ls(){_classCallCheck(this,ls);}return _createClass(ls,null,[{key:"setFade",value:function setFade(e,t){e[v].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(ls.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:ls.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;}()}]);}();ls.DEFAULT_FADE_MS=500;var Hs=ls;var Ht=/*#__PURE__*/function(){function Ht(e,t,n){_classCallCheck(this,Ht);if(this.hiddenElements=/* @__PURE__ */new Set(),this.isScrollButton=!1,this.isScrollingToBottom=!1,this._messages=e,t){var _s$styles;var s={};_typeof(t)=="object"&&(s=w(t),s.onUpdate=t.onUpdate),(_s$styles=s.styles)!==null&&_s$styles!==void 0?_s$styles:s.styles={};var r="fit-content";s.styles["default"]=_objectSpread({borderRadius:"10px",width:r,height:r},s.styles["default"]),this.hiddenMessagesConfig=s,this.io=this.initIntersectionObserver(this._messages.elementRef);}if(n){var _s2$styles;var _s2=_typeof(n)=="object"?w(n):{};(_s2$styles=_s2.styles)!==null&&_s2$styles!==void 0?_s2$styles:_s2.styles={},_s2.styles["default"]=_objectSpread({borderRadius:"50%",width:"1.4rem",height:"1.4rem"},_s2.styles["default"]),this.scrollButtonConfig=_s2;}this.element=this.createElement(),this._messages.elementRef.appendChild(this.element);}return _createClass(Ht,[{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=x();return e.id="scroll-button",q.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")q.scrollToBottom(_this4._messages,n),n&&_this4.element&&(Ht.hideElement(_this4.element),_this4.isScrollingToBottom=!0,q.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"});}}),se.apply(this._messages,e),e;}},{key:"assignStyles",value:function assignStyles(e){if(!this.element)return;Object.assign(this.element[v],e[A]);var t=re.processStateful(e);At.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){Ht.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,se.apply(this._messages,this.element);}else this.element.innerHTML=s;(t=this.hiddenMessagesConfig)!=null&&t.styles&&this.assignStyles(this.hiddenMessagesConfig.styles),Ht.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&&!q.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!==Tr&&(Ht.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.styles&&this.assignStyles(this.scrollButtonConfig.styles));}},{key:"updateScroll",value:function updateScroll(){var e;this.isScrollingToBottom||!this.scrollButtonConfig||(q.isScrollbarAtBottomOfElement(this._messages.elementRef,((e=this.scrollButtonConfig)==null?void 0:e.scrollDelta)||80)?this.element&&this.element[v].opacity!==Cr&&Ht.hideElement(this.element):(this.displayScroll(),this.isScrollButton=!0));}}],[{key:"displayElement",value:function displayElement(e){e[v].opacity=Tr,e[v].pointerEvents="auto";}},{key:"hideElement",value:function hideElement(e){e[v].opacity=Cr,e[v].pointerEvents="none";}}]);}();var $r="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",Pi="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 yt=/*#__PURE__*/function(_jo){function yt(e){var _this6;_classCallCheck(this,yt);_this6=_callSuper(this,yt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(yt,_jo);return _createClass(yt,[{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===Bt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Bt?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var r,o,a,c,l;var n=x("img");e===D?(n[C]=((r=t==null?void 0:t[D])==null?void 0:r[C])||((o=t==null?void 0:t[A])==null?void 0:o[C])||Pi,n.onerror=yt.errorFallback.bind(this,Pi)):(n[C]=((a=t==null?void 0:t[e])==null?void 0:a[C])||((c=t==null?void 0:t[Q])==null?void 0:c[C])||((l=t==null?void 0:t[A])==null?void 0:l[C])||$r,n.onerror=yt.errorFallback.bind(this,$r)),n[m].add("avatar"),n.alt="".concat(e," avatar");var s=x();return s[m].add(this.className),s.appendChild(n),t&&yt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,r,o,a,c,l;var n=ae.processPosition((r=(s=t==null?void 0:t[e])==null?void 0:s.styles)==null?void 0:r.position);return e!==D&&(n!==null&&n!==void 0?n:n=(a=(o=t==null?void 0:t.ai)==null?void 0:o.styles)==null?void 0:a.position),n!==null&&n!==void 0?n:n=(l=(c=t==null?void 0:t[A])==null?void 0:c.styles)==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===D?wo:Bt,n;}}],[{key:"errorFallback",value:function errorFallback(e,t){var n=t.target;n.onerror=null,n[C]=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[A])!=null&&r.styles&&yt.applyCustomStylesToElements(e,t,n[A].styles),s===D)(o=n.user)!=null&&o.styles&&yt.applyCustomStylesToElements(e,t,n.user.styles);else{(a=n.ai)!=null&&a.styles&&yt.applyCustomStylesToElements(e,t,n.ai.styles);var l=(c=n[s])==null?void 0:c.styles;l&&yt.applyCustomStylesToElements(e,t,l);}}}]);}(jo);var ss=/*#__PURE__*/function(_jo2){function ss(e){var _this7;_classCallCheck(this,ss);_this7=_callSuper(this,ss,["name"]),_this7._names=e;return _this7;}_inherits(ss,_jo2);return _createClass(ss,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),r=ss.getPosition(t,n);s[m].add(r===Bt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Bt?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=x();return n[m].add(this.className),n.textContent=ss.getNameText(e,t),ss.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,r,o;var n=ae.processPosition((s=t==null?void 0:t[e])==null?void 0:s.position);return e!==D&&(n!==null&&n!==void 0?n:n=(r=t==null?void 0:t[Q])==null?void 0:r.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[A])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===D?wo:Bt,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,r,o,a;Object.assign(e[v],(s=n[A])==null?void 0:s[v]),t===D?Object.assign(e[v],(r=n[D])==null?void 0:r[v]):(Object.assign(e[v],(o=n[Q])==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===D?((n=t[D])==null?void 0:n[h])||((s=t[A])==null?void 0:s[h])||"User":e===Q?((r=t[Q])==null?void 0:r[h])||((o=t[A])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[A])==null?void 0:c[h])||e;}}]);}(jo);var Fe=/*#__PURE__*/function(){function Fe(e){var _this8=this;_classCallCheck(this,Fe);var t,n,s,r;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=Fe.createContainerElement(),this.messageStyles=ae.processMessageStyles(e.messageStyles),this._remarkable=ys.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new yt(e.avatars)),e.names&&(this.name=new ss(e.names)),e.browserStorage&&(this.browserStorage=new ol(e.browserStorage)),this._onMessage=nn.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),(e.hiddenMessages||e.scrollButton)&&(this.scrollButton=new Ht(this,e.hiddenMessages,e.scrollButton)),this.focusMode=ae.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=x(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Hs.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||ae.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(Fe,[{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(Fe.TEXT_BUBBLE_CLASS),this.applyCustomStyles(r,t,!1),N.fillEmptyMessageElement(r.bubbleElement,e),r;}// prettier-ignore
77
77
  },{key:"overwriteText",value:function overwriteText(e,t,n){var s=N.overwriteMessage(this.messageToElements,n,t,e,"text",Fe.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(Fe.LAST_GROUP_MESSAGES_ACTIVE);var e=x();(this.messageToElements.length>1||this.messageToElements.length===1&&this.messageToElements[0][0][S]!==D)&&e[m].add(Fe.LAST_GROUP_MESSAGES_ACTIVE),this._lastGroupMessagesElement=e;}},{key:"appendOuterContainerElemet",value:function appendOuterContainerElemet(e,t){var n;this.focusMode&&(t===D||!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(Fe.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(ht.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 wt.changeFullViewToSmall(this),!n&&Fe.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
78
  // https://github.com/OvidijusParsiunas/deep-chat/issues/258
79
79
  // prettier-ignore
80
80
  },{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&pt.isElementTemporary(e)){var n=this.messageElementRefs[this.messageElementRefs.length-2];n&&this.messageToElements.length>0&&!e.bubbleElement[m].contains(N.getRoleClass(t))&&N.revealRoleElements(n.innerContainer,this.avatar,this.name);}}},{key:"createElements",value:function createElements(e,t){var n=Fe.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 N.updateRefArr(this.messageElementRefs,s,n),N.classifyRoleMessages(this.messageElementRefs,t),s;}},{key:"addInnerContainerElements",value:// prettier-ignore
81
81
  function addInnerContainerElements(e,t,n){var s=this.messageElementRefs[this.messageElementRefs.length-1];return N.areOuterContainerClassRolesSame(n,s)&&!this.isLastMessageError()&&N.hideRoleElements(s.innerContainer,this.avatar,this.name),e[m].add("message-bubble",N.getRoleClass(n),n===D?"user-message-text":"ai-message-text"),this.renderText(e,t,n),N.addRoleElements(e,n,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
82
- },{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){e&&this.messageStyles&&Le.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=N.getLastMessageBubbleElement(this.elementRef))==null?void 0:e[m].contains(Bs);}},{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
82
+ },{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){e&&this.messageStyles&&Le.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=N.getLastMessageBubbleElement(this.elementRef))==null?void 0:e[m].contains(Ds);}},{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
83
  },{key:"renderText",value:function renderText(e,t,n){var _se$tryAddWrapper2=se.tryAddWrapper(e,t,this._customWrappers,n),s=_se$tryAddWrapper2.contentEl,r=_se$tryAddWrapper2.wrapper;r&&se.apply(this,e),s.innerHTML=this._remarkable.render(t),this._applyHTMLToRemarkable&&se.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=gs.createNew(e),this.messageToElements.forEach(function(t){t[1][h]&&t[0][h]&&_this0.renderText(t[1][h].bubbleElement,t[0][h],t[0][S]);});}},{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===D){var s=typeof this.focusMode!="boolean"&&((n=this.focusMode)==null?void 0:n.smoothScroll);q.scrollToBottom(this,s);}else if(t&&this.autoScrollAllowed){var _s3=this.getFirstMessageContentEl();q.scrollToBottom(this,!1,_s3==null?void 0:_s3.outerContainer);}}}],[{key:"createContainerElement",value:function createContainerElement(){var e=x();return e.id=wo,e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return Fe.isLoadingMessage(e)||pt.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=x(),n=x();n[m].add("inner-message-container"),t.appendChild(n),t[m].add("outer-message-container"),t[m].add(N.buildRoleOuterContainerClass(e));var s=x();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({},S,a||Q);return t&&(c[h]=t),n&&(c[y]=n),s&&(c[P]=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(ht.BUBBLE_CLASS);}}]);}();Fe.TEXT_BUBBLE_CLASS="text-message",Fe.INTRO_CLASS="deep-chat-intro",Fe.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var Qe=Fe;var N=/*#__PURE__*/function(){function N(){_classCallCheck(this,N);}return _createClass(N,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][S]===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
84
+ },{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this0=this;this._remarkable=ys.createNew(e),this.messageToElements.forEach(function(t){t[1][h]&&t[0][h]&&_this0.renderText(t[1][h].bubbleElement,t[0][h],t[0][S]);});}},{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===D){var s=typeof this.focusMode!="boolean"&&((n=this.focusMode)==null?void 0:n.smoothScroll);q.scrollToBottom(this,s);}else if(t&&this.autoScrollAllowed){var _s3=this.getFirstMessageContentEl();q.scrollToBottom(this,!1,_s3==null?void 0:_s3.outerContainer);}}}],[{key:"createContainerElement",value:function createContainerElement(){var e=x();return e.id=Co,e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return Fe.isLoadingMessage(e)||pt.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=x(),n=x();n[m].add("inner-message-container"),t.appendChild(n),t[m].add("outer-message-container"),t[m].add(N.buildRoleOuterContainerClass(e));var s=x();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({},S,a||Q);return t&&(c[h]=t),n&&(c[y]=n),s&&(c[P]=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(ht.BUBBLE_CLASS);}}]);}();Fe.TEXT_BUBBLE_CLASS="text-message",Fe.INTRO_CLASS="deep-chat-intro",Fe.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var Qe=Fe;var N=/*#__PURE__*/function(){function N(){_classCallCheck(this,N);}return _createClass(N,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][S]===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
85
  // and if messages have custom roles, it will still look to update the last 'ai' role message
86
86
  // prettier-ignore
87
87
  },{key:"overwriteMessage",value:function overwriteMessage(e,t,n,s,r,o){var a=N.getLastElementsByClass(t,[N.getRoleClass(s),o],[ht.BUBBLE_CLASS]),c=N.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(xr),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e[m].contains(xr)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,n,s;return Array.from(((s=(n=(t=N.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(ws).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$m;e.outerContainer[m].remove(vi,Ar,Ei),(_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[P]!==void 0&&(t+=1),e[y]&&(t+=e[y].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]=N.findMessageElements(t,Qe.TEXT_BUBBLE_CLASS)),e[P]&&(n[P]=N.findMessageElements(t,ft.HTML_BUBBLE_CLASS)),e[y]&&(n[y]=N.filterdMessageElements(t,xo)),n;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=N.getNumberOfElements(e),r=n?t.slice(0,s):t.slice(t.length-s);return N.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?N.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(ws);})),!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?N.addNewPositionClasses(r,[vi]):l&&d?N.addNewPositionClasses(r,[Ar]):l&&!d?N.addNewPositionClasses(r,[Ei]):!l&&!d&&N.addNewPositionClasses(r,[vi,Ei]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer[m]).find(function(s){return s.startsWith(ws);})===N.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(Bs)||N.revealRoleElements(r.innerContainer,t,n);var a=Array.from(r.outerContainer[m]).find(function(c){return c.startsWith(ws);});s===a&&N.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
88
+ },{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e[m].add(Ar),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e[m].contains(Ar)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,n,s;return Array.from(((s=(n=(t=N.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(Cs).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$m;e.outerContainer[m].remove(Ei,wr,Si),(_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[P]!==void 0&&(t+=1),e[y]&&(t+=e[y].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]=N.findMessageElements(t,Qe.TEXT_BUBBLE_CLASS)),e[P]&&(n[P]=N.findMessageElements(t,ft.HTML_BUBBLE_CLASS)),e[y]&&(n[y]=N.filterdMessageElements(t,Ao)),n;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=N.getNumberOfElements(e),r=n?t.slice(0,s):t.slice(t.length-s);return N.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?N.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(Cs);})),!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?N.addNewPositionClasses(r,[Ei]):l&&d?N.addNewPositionClasses(r,[wr]):l&&!d?N.addNewPositionClasses(r,[Si]):!l&&!d&&N.addNewPositionClasses(r,[Ei,Si]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer[m]).find(function(s){return s.startsWith(Cs);})===N.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(Ds)||N.revealRoleElements(r.innerContainer,t,n);var a=Array.from(r.outerContainer[m]).find(function(c){return c.startsWith(Cs);});s===a&&N.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
90
  // and 'custom' property value if it is not shallow copyable
91
91
  // 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 N.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!==F)return e;if(Array.isArray(e))return e.map(function(n){return N.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)===F?t[n]=N.processMessageContent(s):t[n]=s;}),t;}}]);}();var _t=/*#__PURE__*/function(){function _t(e,t){_classCallCheck(this,_t);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialContent="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(_t,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e[h])===void 0&&(e==null?void 0:e[P])===void 0)return console[f](To);var t=(e==null?void 0:e[h])||(e==null?void 0:e[P])||"",n=q.isScrollbarAtBottomOfElement(this._messages.elementRef),s=(e==null?void 0:e[h])!==void 0?h:P;if(!this._elements&&!this._message)this.setInitialState(s,t,e==null?void 0:e[S]);else{if(this._streamType!==s)return console[f](ma);e!=null&&e[S]&&(e==null?void 0:e[S])!==this._activeMessageRole?(this.finaliseStreamedMessage(!1),this.setInitialState(s,t,e==null?void 0:e[S])):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&&q.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=Q;var s=((o=this._messages._customWrappers)==null?void 0:o[n])||((a=this._messages._customWrappers)==null?void 0:a[A]),r=s?"":t;this._elements=e===h?this._messages.addNewTextMessage(r,n):ft.add(this._messages,r,n),this._elements&&(this._elements.bubbleElement[m].add(_t.MESSAGE_CLASS),this._activeMessageRole=n,this._message=_defineProperty(_defineProperty({},S,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=se.getTargetWrapper(e.bubbleElement),this._elements&&se.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||N.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(_t.PARTIAL_RENDER_MARK);return t===-1?!1:!e.substring(t+_t.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=x(),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[P]=n?e:(this._message[P]||"")+e,this._partialRender&&this.isNewPartialRenderParagraph(t,n)&&this.partialRenderNewParagraph(t),this._partialBubble)this.updatePartialRenderBubble(e);else if(n)t.innerHTML=e;else{var s=x("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(ga);this._message&&(t=this._elements.bubbleElement)!=null&&t[m].contains(_t.MESSAGE_CLASS)&&(this._streamType===h?this._messages.textToSpeech&&vn.speak(this._message[h]||"",this._messages.textToSpeech):this._streamType===P&&this._elements&&se.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement[m].remove(_t.MESSAGE_CLASS),this._message&&(this._sessionId&&(this._message._sessionId=this._sessionId),this._messages.sendClientUpdate(Qe.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
92
+ },{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return N.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!==F)return e;if(Array.isArray(e))return e.map(function(n){return N.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)===F?t[n]=N.processMessageContent(s):t[n]=s;}),t;}}]);}();var _t=/*#__PURE__*/function(){function _t(e,t){_classCallCheck(this,_t);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialContent="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(_t,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e[h])===void 0&&(e==null?void 0:e[P])===void 0)return console[f](Ro);var t=(e==null?void 0:e[h])||(e==null?void 0:e[P])||"",n=q.isScrollbarAtBottomOfElement(this._messages.elementRef),s=(e==null?void 0:e[h])!==void 0?h:P;if(!this._elements&&!this._message)this.setInitialState(s,t,e==null?void 0:e[S]);else{if(this._streamType!==s)return console[f](ga);e!=null&&e[S]&&(e==null?void 0:e[S])!==this._activeMessageRole?(this.finaliseStreamedMessage(!1),this.setInitialState(s,t,e==null?void 0:e[S])):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&&q.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=Q;var s=((o=this._messages._customWrappers)==null?void 0:o[n])||((a=this._messages._customWrappers)==null?void 0:a[A]),r=s?"":t;this._elements=e===h?this._messages.addNewTextMessage(r,n):ft.add(this._messages,r,n),this._elements&&(this._elements.bubbleElement[m].add(_t.MESSAGE_CLASS),this._activeMessageRole=n,this._message=_defineProperty(_defineProperty({},S,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=se.getTargetWrapper(e.bubbleElement),this._elements&&se.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||N.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(_t.PARTIAL_RENDER_MARK);return t===-1?!1:!e.substring(t+_t.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=x(),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[P]=n?e:(this._message[P]||"")+e,this._partialRender&&this.isNewPartialRenderParagraph(t,n)&&this.partialRenderNewParagraph(t),this._partialBubble)this.updatePartialRenderBubble(e);else if(n)t.innerHTML=e;else{var s=x("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(ya);this._message&&(t=this._elements.bubbleElement)!=null&&t[m].contains(_t.MESSAGE_CLASS)&&(this._streamType===h?this._messages.textToSpeech&&vn.speak(this._message[h]||"",this._messages.textToSpeech):this._streamType===P&&this._elements&&se.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement[m].remove(_t.MESSAGE_CLASS),this._message&&(this._sessionId&&(this._message._sessionId=this._sessionId),this._messages.sendClientUpdate(Qe.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
94
94
  },{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({},y,s));case 2:return _context2.a(2);}},_callee2,this);}));function endStreamAfterFileDownloaded(_x3,_x4){return _endStreamAfterFileDownloaded.apply(this,arguments);}return endStreamAfterFileDownloaded;}()}]);}();_t.MESSAGE_CLASS="streamed-message",_t.PARTIAL_RENDER_MARK="\n\n";var at=_t;var B=/*#__PURE__*/function(){function B(){_classCallCheck(this,B);}return _createClass(B,null,[{key:"tempRemoveContentHeader",value:// need to pass stringifyBody boolean separately as binding is throwing an error for some reason
95
95
  // prettier-ignore
96
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(De);case 1:s=e.headers[$];delete e.headers[$];_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[$]=s,_t3;case 5:return _context3.a(2,(e.headers[$]=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)===F)return t instanceof Error?e.addNewErrorMessage(ie,t.message):Array.isArray(t)||_typeof(t[f])===ye?e.addNewErrorMessage(ie,t):Object.keys(t).length===0?e.addNewErrorMessage(ie,n):e.addNewErrorMessage(ie,oe(t));e.addNewErrorMessage(ie,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)||me,headers:t};return r.method!==le&&(r.body=n?oe(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(J)?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](Co),!1):!n.find(function(r){return _typeof(r)!="object"||!(_typeof(r[f])===ye||_typeof(r[h])===ye||_typeof(r[P])===ye||Array.isArray(r[y]));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,n){e.addNewErrorMessage(ie,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=_n(t,"response",!!a,c);B.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 ol(_x14,_x15){return _ol.apply(this,arguments);}function _ol(){_ol=_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 _ol.apply(this,arguments);}function al(i){var e,t,n,s=!1;return function(o){e===void 0?(e=o,t=0,n=-1):e=ll(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 cl(i,e,t){var n=$r();var s=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(n),n=$r();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 ll(i,e){var t=new Uint8Array(i.length+e.length);return t.set(i),t.set(e,i.length),t;}function $r(){return{data:"",event:"",id:"",retry:void 0};}var dl=function dl(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 Pi="text/event-stream",hl=1e3,qr="last-event-id";function ul(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=dl(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(p,u){var g=Object.assign({},n);g.accept||(g.accept=Pi);var b;function _(){b.abort(),document.hidden||we();}c||document.addEventListener("visibilitychange",_);var E=hl,R=0;function z(){document.removeEventListener("visibilitychange",_),window.clearTimeout(R),b.abort();}t==null||t.addEventListener("abort",function(){z(),p();});var te=l!==null&&l!==void 0?l:window.fetch,ne=s!==null&&s!==void 0?s:pl;function we(){return _we.apply(this,arguments);}function _we(){_we=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var Rt,It,qe,_t6;return _regenerator().w(function(_context6){while(1)switch(_context6.p=_context6.n){case 0:b=new AbortController();_context6.p=1;_context6.n=2;return te(i,Object.assign(Object.assign({},d),{headers:g,signal:b.signal}));case 2:It=_context6.v;_context6.n=3;return ne(It);case 3:_context6.n=4;return ol(It.body,al(cl(function(qe){qe?g[qr]=qe:delete g[qr];},function(qe){E=qe;},r)));case 4:o==null||o();z();p();_context6.n=6;break;case 5:_context6.p=5;_t6=_context6.v;if(!b.signal.aborted)try{qe=(Rt=a==null?void 0:a(_t6))!==null&&Rt!==void 0?Rt:E;window.clearTimeout(R),R=window.setTimeout(we,qe);}catch(qe){z(),u(qe);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _we.apply(this,arguments);}we();});}function pl(i){var e=i.headers.get("content-type");if(!(e!=null&&e.startsWith(Pi)))throw new Error("Expected content-type to be ".concat(Pi,", Actual: ").concat(e));}var G=/*#__PURE__*/function(){function G(){_classCallCheck(this,G);}return _createClass(G,null,[{key:"request",value:// prettier-ignore
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)||me,headers:t};return r.method!==le&&(r.body=n?oe(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(J)?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](To),!1):!n.find(function(r){return _typeof(r)!="object"||!(_typeof(r[f])===ye||_typeof(r[h])===ye||_typeof(r[P])===ye||Array.isArray(r[y]));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,n){e.addNewErrorMessage(ie,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=_n(t,"response",!!a,c);B.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 al(_x14,_x15){return _al.apply(this,arguments);}function _al(){_al=_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 _al.apply(this,arguments);}function cl(i){var e,t,n,s=!1;return function(o){e===void 0?(e=o,t=0,n=-1):e=dl(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 ll(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 dl(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 hl=function hl(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 Li="text/event-stream",ul=1e3,Gr="last-event-id";function pl(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=hl(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(p,u){var g=Object.assign({},n);g.accept||(g.accept=Li);var b;function _(){b.abort(),document.hidden||we();}c||document.addEventListener("visibilitychange",_);var E=ul,R=0;function z(){document.removeEventListener("visibilitychange",_),window.clearTimeout(R),b.abort();}t==null||t.addEventListener("abort",function(){z(),p();});var te=l!==null&&l!==void 0?l:window.fetch,ne=s!==null&&s!==void 0?s:fl;function we(){return _we.apply(this,arguments);}function _we(){_we=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var Rt,It,qe,_t6;return _regenerator().w(function(_context6){while(1)switch(_context6.p=_context6.n){case 0:b=new AbortController();_context6.p=1;_context6.n=2;return te(i,Object.assign(Object.assign({},d),{headers:g,signal:b.signal}));case 2:It=_context6.v;_context6.n=3;return ne(It);case 3:_context6.n=4;return al(It.body,cl(ll(function(qe){qe?g[Gr]=qe:delete g[Gr];},function(qe){E=qe;},r)));case 4:o==null||o();z();p();_context6.n=6;break;case 5:_context6.p=5;_t6=_context6.v;if(!b.signal.aborted)try{qe=(Rt=a==null?void 0:a(_t6))!==null&&Rt!==void 0?Rt:E;window.clearTimeout(R),R=window.setTimeout(we,qe);}catch(qe){z(),u(qe);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _we.apply(this,arguments);}we();});}function fl(i){var e=i.headers.get("content-type");if(!(e!=null&&e.startsWith(Li)))throw new Error("Expected content-type to be ".concat(Li,", Actual: ").concat(e));}var G=/*#__PURE__*/function(){function G(){_classCallCheck(this,G);}return _createClass(G,null,[{key:"request",value:// prettier-ignore
99
99
  function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,n){var s,r,u,g,b,_,E,o,_yield$B$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 B.processRequestInterceptor(e.deepChat,o);case 1:_yield$B$processReque=_context7.v;a=_yield$B$processReque.body;c=_yield$B$processReque.headers;l=_yield$B$processReque.error;if(!l){_context7.n=2;break;}return _context7.a(2,B.onInterceptorError(n,l,e.streamHandlers.onClose));case 2:if(!((g=e.connectSettings)!=null&&g.handler)){_context7.n=3;break;}return _context7.a(2,ot.stream(e,a,n));case 3:if(!(((b=e.connectSettings)==null?void 0:b.url)===lt.URL)){_context7.n=4;break;}return _context7.a(2,lt.requestStream(n,e));case 4:d=new at(n,e.stream),p={method:((_=e.connectSettings)==null?void 0:_.method)||me,headers:c,credentials:(E=e.connectSettings)==null?void 0:E.credentials,body:s?oe(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?G.handleReadableStream(e,n,d,p,r,a):G.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 _,E,u,g,b,_yield$u$read,R,z,te,ne,we,_t7;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(p.body){_context8.n=1;break;}throw new Error(ya);case 1:u=p.body.getReader(),g=new TextDecoder();a();b=!1;case 2:if(!(!b&&!l)){_context8.n=8;break;}_context8.n=3;return u.read();case 3:_yield$u$read=_context8.v;R=_yield$u$read.value;z=_yield$u$read.done;if(!(b=z,b)){_context8.n=4;break;}G.handleClose(e,n,c,r);_context8.n=7;break;case 4:te=g.decode(R,{stream:!0});_context8.n=5;return(E=(_=e.deepChat).responseInterceptor)==null?void 0:E.call(_,te);case 5:_t7=_context8.v;if(_t7){_context8.n=6;break;}_t7=te;case 6:ne=_t7;we=_typeof(ne)=="object"?ne:_defineProperty({},h,te);G.handleMessage(e,t,n,we,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){G.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();},ul(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",_objectSpread(_objectSpread({},s),{},{openWhenHidden:!0,// keep stream open when browser tab not open
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 _,E,u,g,b,_yield$u$read,R,z,te,ne,we,_t7;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(p.body){_context8.n=1;break;}throw new Error(ba);case 1:u=p.body.getReader(),g=new TextDecoder();a();b=!1;case 2:if(!(!b&&!l)){_context8.n=8;break;}_context8.n=3;return u.read();case 3:_yield$u$read=_context8.v;R=_yield$u$read.value;z=_yield$u$read.done;if(!(b=z,b)){_context8.n=4;break;}G.handleClose(e,n,c,r);_context8.n=7;break;case 4:te=g.decode(R,{stream:!0});_context8.n=5;return(E=(_=e.deepChat).responseInterceptor)==null?void 0:E.call(_,te);case 5:_t7=_context8.v;if(_t7){_context8.n=6;break;}_t7=te;case 6:ne=_t7;we=_typeof(ne)=="object"?ne:_defineProperty({},h,te);G.handleMessage(e,t,n,we,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){G.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();},pl(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",_objectSpread(_objectSpread({},s),{},{openWhenHidden:!0,// keep stream open when browser tab not open
102
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 B.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,b,_,_t8;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(oe(p.data)!==oe("[DONE]"))){_context0.n=3;break;}try{b=JSON.parse(p.data);}catch(_unused6){b={};}_context0.n=1;return(g=(u=e.deepChat).responseInterceptor)==null?void 0:g.call(u,b);case 1:_t8=_context0.v;if(_t8){_context0.n=2;break;}_t8=b;case 2:_=_t8;G.handleMessage(e,t,n,_,o);case 3:return _context0.a(2);}},_callee0);}))();},onerror:function onerror(p){throw c(),p;},onclose:function onclose(){G.handleClose(e,n,c,r);},signal:l.signal}))["catch"](function(p){G.handleError(e,t,p);});}//prettier-ignore
103
103
  },{key:"handleMessage",value:function handleMessage(e,t,n,s,r){var o;(o=e.extractResultData)==null||o.call(e,s,r).then(function(a){G.upsertContent(t,n.upsertStreamedMessage.bind(n),n,a),t.removeError();})["catch"](function(a){t.isLastMessageError()||B.displayError(t,a);});}// eslint-disable-next-line @typescript-eslint/no-explicit-any
104
104
  },{key:"handleError",value:function handleError(e,t,n){var s;t.isLastMessageError()||(s=e.extractResultData)==null||s.call(e,n).then(function(){B.displayError(t,n);})["catch"](function(r){B.displayError(t,r);});}},{key:"handleClose",value:function handleClose(e,t,n,s){if(e.asyncCallInProgress){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
@@ -112,46 +112,46 @@ onopen:function onopen(p){return _asyncToGenerator(/*#__PURE__*/_regenerator().m
112
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,b,_,E;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:_context17.n=1;return B.basicResponseProcessing(t,d,{io:e,displayError:!1});case 1:p=_context17.v;if(!p)console[f](_n(d,"server",!!e.deepChat.responseInterceptor,p)),t.addNewErrorMessage(ie,"Error in server message");else{u=Array.isArray(p)?p:[p],g=u.find(function(b){return _typeof(b[f])===ye;});if(g)console[f](g[f]),t.isLastMessageError()||t.addNewErrorMessage(ie,g[f]);else if(G.isSimulation(e.stream)){b=p,_=Re.stream.bind(_this10,e,t,n.roleToStream),E=n.roleToStream[b[S]||Q];G.upsertContent(t,_,E,b);}else u.forEach(function(b){return t.addNewMessage(b);});}case 2:return _context17.a(2);}},_callee17);}));return function o(_x40){return _ref17.apply(this,arguments);};}(),a=ot.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 pe=/*#__PURE__*/function(){function pe(){_classCallCheck(this,pe);}return _createClass(pe,null,[{key:"request",value:// prettier-ignore
113
113
  function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,n){var s,p,u,g,r,_yield$B$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 B.processRequestInterceptor(e.deepChat,r);case 1:_yield$B$processReque3=_context19.v;o=_yield$B$processReque3.body;a=_yield$B$processReque3.headers;c=_yield$B$processReque3.error;l=e.completionsHandlers.onFinish;if(!c){_context19.n=2;break;}return _context19.a(2,B.onInterceptorError(n,c,l));case 2:if(!((u=e.connectSettings)!=null&&u.handler)){_context19.n=3;break;}return _context19.a(2,ot.request(e,o,n));case 3:if(!(((g=e.connectSettings)==null?void 0:g.url)===lt.URL)){_context19.n=4;break;}return _context19.a(2,lt.request(e,n));case 4:d=!0;B.fetch(e,a,s,o).then(function(b){return d=!!b.ok,b;}).then(function(b){return B.processResponseByType(b);}).then(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(b){var R,z,_,E,_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(z=(R=e.deepChat).responseInterceptor)==null?void 0:z.call(R,b);case 2:_t1=_context18.v;if(_t1){_context18.n=3;break;}_t1=b;case 3:_=_t1;_context18.n=4;return e.extractResultData(_,o);case 4:E=_context18.v;if(d){_context18.n=5;break;}throw b;case 5:if(!(!E||_typeof(E)!==F&&!Array.isArray(E))){_context18.n=6;break;}throw Error(_n(b,"response",!!e.deepChat.responseInterceptor,_));case 6:if(!E[f]){_context18.n=7;break;}throw E[f];case 7:if(!e.asyncCallInProgress){_context18.n=8;break;}e.asyncCallInProgress=!1;return _context18.a(2);case 8:G.isSimulatable(e.stream,E)?G.simulate(n,e.streamHandlers,E):((Array.isArray(E)?E:[E]).forEach(function(ne){return n.addNewMessage(ne);}),l());case 9:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref18.apply(this,arguments);};}())["catch"](function(b){B.displayError(n,b),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(){pe.executePollRequest(e,t,n,s);},a.timeoutMS):G.isSimulatable(e.stream,a)?G.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){B.displayError(s,o),r();});}// prettier-ignore
114
114
  },{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,n){var s,g,b,_,r,_yield$B$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 B.processRequestInterceptor(e.deepChat,r);case 1:_yield$B$processReque4=_context21.v;o=_yield$B$processReque4.body;a=_yield$B$processReque4.headers;c=_yield$B$processReque4.error;if(!c){_context21.n=2;break;}return _context21.a(2,B.onInterceptorError(n,c));case 2:l=((b=e.connectSettings)==null?void 0:b.url)||e.url||"",d=((_=e.connectSettings)==null?void 0:_.method)||me,p=s?oe(o):o,u={method:d,body:p,headers:a};e.connectSettings.credentials&&(u.credentials=e.connectSettings.credentials),pe.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
- },{key:"verifyKey",value:function verifyKey(e,t,n,s,r,o,a,c,l){if(e==="")return o(de);a(),fetch(t,{method:s,headers:n,body:l||null}).then(function(d){return B.processResponseByType(d);}).then(function(d){c(d,e,r,o);})["catch"](function(d){o(Be),console[f](d);});}}]);}();var Sn=/*#__PURE__*/function(){function Sn(){_classCallCheck(this,Sn);}return _createClass(Sn,null,[{key:"getCharacterLimitMessages",value:function getCharacterLimitMessages(e,t){var r;if(t===-1)return e;var n=0,s=e.length-1;for(s;s>=0;s-=1){var o=(r=e[s])==null?void 0:r[h];if(o!==void 0&&(n+=o.length,n>t)){e[s][h]=o.substring(0,o.length-(n-t));break;}}return e.slice(Math.max(s,0));}},{key:"getMaxMessages",value:function getMaxMessages(e,t){return e.slice(Math.max(e.length-t,0));}// if maxMessages is not defined we send all messages
115
+ },{key:"verifyKey",value:function verifyKey(e,t,n,s,r,o,a,c,l){if(e==="")return o(de);a(),fetch(t,{method:s,headers:n,body:l||null}).then(function(d){return B.processResponseByType(d);}).then(function(d){c(d,e,r,o);})["catch"](function(d){o(Be),console[f](d);});}}]);}();var xn=/*#__PURE__*/function(){function xn(){_classCallCheck(this,xn);}return _createClass(xn,null,[{key:"getCharacterLimitMessages",value:function getCharacterLimitMessages(e,t){var r;if(t===-1)return e;var n=0,s=e.length-1;for(s;s>=0;s-=1){var o=(r=e[s])==null?void 0:r[h];if(o!==void 0&&(n+=o.length,n>t)){e[s][h]=o.substring(0,o.length-(n-t));break;}}return e.slice(Math.max(s,0));}},{key:"getMaxMessages",value:function getMaxMessages(e,t){return e.slice(Math.max(e.length-t,0));}// if maxMessages is not defined we send all messages
116
116
  // if maxMessages above 0 we send that number
117
117
  // 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=Sn.getMaxMessages(e,t)):e=[e[e.length-1]],e=w(e),n===void 0?e:Sn.getCharacterLimitMessages(e,n);}}]);}();var Pt=/*#__PURE__*/function(){function Pt(e,t,n){_classCallCheck(this,Pt);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,n.fetchHistory&&this.fetchHistory(n.fetchHistory),this.setupInitialHistory(e);}return _createClass(Pt,[{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=wt.addMessage(this._messages);_context22.n=1;return e();case 1:n=_context22.v;this._messages.removeMessage(t),Pt.displayIntroMessages(this._messages.messageElementRefs),n.forEach(function(s){return _this11._messages.addAnyMessage(s,!0);}),setTimeout(function(){return q.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(Qe.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=N.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;N.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=wt.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(ie,Pt.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){ae.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=wt.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(ie,Pt.FAILED_ERROR_MESSAGE,!0),console[f](_t13);case 4:Pt.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||ae.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 q.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(Pt.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(Qe.INTRO_CLASS))n.outerContainer[v].display="";else break;}}}]);}();Pt.FAILED_ERROR_MESSAGE="Failed to load history";var ys=Pt;var Ee=/*#__PURE__*/function(){function Ee(){_classCallCheck(this,Ee);}return _createClass(Ee,null,[{key:"parseConfig",value:function parseConfig(e,t,n){var r;var s={files:e};if(_typeof(n)=="object"){ae.processFileConfigConnect(n);var o=n.files,a=n.connect,c=n.button;o&&(o.infoModal&&(s[y].infoModal=o.infoModal,(r=o.infoModal)!=null&&r.textMarkDown&&(s.infoModalTextMarkUp=t.render(o.infoModal.textMarkDown))),o.acceptedFormats&&(s[y].acceptedFormats=o.acceptedFormats),o.maxNumberOfFiles&&(s[y].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=Ee.parseConfig(s,t,n);}}// needs to be set after audio to overwrite maxNumberOfFiles
118
+ },{key:"processMessages",value:function processMessages(e,t,n){return t!==void 0?t>0&&(e=xn.getMaxMessages(e,t)):e=[e[e.length-1]],e=w(e),n===void 0?e:xn.getCharacterLimitMessages(e,n);}}]);}();var Pt=/*#__PURE__*/function(){function Pt(e,t,n){_classCallCheck(this,Pt);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,n.fetchHistory&&this.fetchHistory(n.fetchHistory),this.setupInitialHistory(e);}return _createClass(Pt,[{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=wt.addMessage(this._messages);_context22.n=1;return e();case 1:n=_context22.v;this._messages.removeMessage(t),Pt.displayIntroMessages(this._messages.messageElementRefs),n.forEach(function(s){return _this11._messages.addAnyMessage(s,!0);}),setTimeout(function(){return q.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(Qe.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=N.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;N.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=wt.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(ie,Pt.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){ae.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=wt.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(ie,Pt.FAILED_ERROR_MESSAGE,!0),console[f](_t13);case 4:Pt.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||ae.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 q.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(Pt.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(Qe.INTRO_CLASS))n.outerContainer[v].display="";else break;}}}]);}();Pt.FAILED_ERROR_MESSAGE="Failed to load history";var bs=Pt;var Ee=/*#__PURE__*/function(){function Ee(){_classCallCheck(this,Ee);}return _createClass(Ee,null,[{key:"parseConfig",value:function parseConfig(e,t,n){var r;var s={files:e};if(_typeof(n)=="object"){ae.processFileConfigConnect(n);var o=n.files,a=n.connect,c=n.button;o&&(o.infoModal&&(s[y].infoModal=o.infoModal,(r=o.infoModal)!=null&&r.textMarkDown&&(s.infoModalTextMarkUp=t.render(o.infoModal.textMarkDown))),o.acceptedFormats&&(s[y].acceptedFormats=o.acceptedFormats),o.maxNumberOfFiles&&(s[y].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=Ee.parseConfig(s,t,n);}}// needs to be set after audio to overwrite maxNumberOfFiles
119
119
  // prettier-ignore
120
120
  },{key:"processMicrophone",value:function processMicrophone(e,t,n,s){var _c$y,_u$maxNumberOfFiles;var a,c,l,d,p,u;var o=_objectSpread({acceptedFormats:"audio/*"},((a=e.fileTypes[j])==null?void 0:a[y])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e.recordAudio=Ee.parseConfig(o,t,n),_typeof(n)=="object"&&n[y]&&((_c$y=(c=e.recordAudio)[y])!==null&&_c$y!==void 0?_c$y:c[y]={},e.recordAudio[y].format=(l=n[y])==null?void 0:l.format,e.recordAudio[y].maxDurationSeconds=(d=n[y])==null?void 0:d.maxDurationSeconds,(p=e.fileTypes[j])!=null&&p[y]&&((_u$maxNumberOfFiles=(u=e.fileTypes[j][y]).maxNumberOfFiles)!==null&&_u$maxNumberOfFiles!==void 0?_u$maxNumberOfFiles:u.maxNumberOfFiles=n[y].maxNumberOfFiles))):s||(e.fileTypes[j]=Ee.parseConfig(o,t,n)));}// prettier-ignore
121
121
  },{key:"processAudioConfig",value:function processAudioConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"audio/*"},(s==null?void 0:s[y])||{});e.fileTypes[j]=Ee.parseConfig(o,t,n);}// prettier-ignore
122
122
  },{key:"processGifConfig",value:function processGifConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/gif"},(s==null?void 0:s[y])||{});e.fileTypes[bn]=Ee.parseConfig(o,t,n);}// needs to be set after images to overwrite maxNumberOfFiles
123
123
  // prettier-ignore
124
- },{key:"processCamera",value:function processCamera(e,t,n,s){var _c$y2;var a,c,l,d;var o=_objectSpread({acceptedFormats:"image/*"},((a=e.fileTypes[Y])==null?void 0:a[y])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e[Ne]=Ee.parseConfig(o,t,n),_typeof(n)=="object"&&(e[Ne].modalContainerStyle=n.modalContainerStyle,n[y]&&((_c$y2=(c=e[Ne])[y])!==null&&_c$y2!==void 0?_c$y2:c[y]={},e[Ne][y].format=(l=n[y])==null?void 0:l.format,e[Ne][y].dimensions=(d=n[y])==null?void 0:d.dimensions))):s||(e.fileTypes[Y]=Ee.parseConfig(o,t,n)));}// prettier-ignore
125
- },{key:"processImagesConfig",value:function processImagesConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/*"},(s==null?void 0:s[y])||{});e.fileTypes[Y]=Ee.parseConfig(o,t,n);}// default for direct service
126
- },{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$y,_n$acceptedFormats,_s$maxNumberOfFiles;var n,s;e&&((_e$y=e[y])!==null&&_e$y!==void 0?_e$y:e[y]={},(_n$acceptedFormats=(n=e[y]).acceptedFormats)!==null&&_n$acceptedFormats!==void 0?_n$acceptedFormats:n.acceptedFormats=t,(_s$maxNumberOfFiles=(s=e[y]).maxNumberOfFiles)!==null&&_s$maxNumberOfFiles!==void 0?_s$maxNumberOfFiles:s.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,n){Ee.populateDefaultFileIO(n==null?void 0:n[j],".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),Ee.populateDefaultFileIO(n==null?void 0:n[Y],".png,.jpg");var s=gs.createNew(e.remarkable);Ee.processImagesConfig(t,s,e[Y],n==null?void 0:n[Y]),Ee.processCamera(t,s,e[Ne],e[Y]),Ee.processGifConfig(t,s,e[bn],n==null?void 0:n[bn]),Ee.processAudioConfig(t,s,e[j],n==null?void 0:n[j]),Ee.processMicrophone(t,s,e[it],e[j]),Ee.processMixedFiles(t,s,e[So]);}}]);}();var sn=/*#__PURE__*/function(){function sn(e,t,n){var _a$url;_classCallCheck(this,sn);var s,r,o,a,c;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=sn.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,Ee.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=lt.URL),this.connectSettings.websocket&&Re.setup(this),this.stream=((c=this.deepChat.connect)==null?void 0:c.stream)||ae.checkForStream(this.deepChat),e.loadHistory&&ys.addErrorPrefix(this);}return _createClass(sn,[{key:"verifyKey",value:function verifyKey(e,t){}},{key:"getServiceIOByType",value:function getServiceIOByType(e){if(e.type.startsWith(j)&&this.fileTypes[j])return this.fileTypes[j];if(e.type.startsWith(V)){if(this.fileTypes[bn]&&e.type.endsWith("/gif"))return this.fileTypes[bn];if(this.fileTypes[Y])return this.fileTypes[Y];if(this[Ne])return this[Ne];}return this.fileTypes[So];}},{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&&!G.isSimulation(this.stream)?G.request(this,e,t,n):pe.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$$;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[$]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$$=(a=this.connectSettings.headers)[$])!==null&&_a$$!==void 0?_a$$:a[$]=J,s=!0);_context28.n=1;return this.request(n,e);case 1:s&&((c=this.connectSettings.headers)==null||delete c[$]);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=sn.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(De);case 1:n=Sn.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!==lt.URL)){r=_objectSpread({messages:n},this.rawBody);e[y]&&(s=this.getServiceIOByType(e[y][0]))!=null&&s.connect?this.callApiWithFiles(t,n,e[y]):Re.sendWebsocket(this,r,t,!1);}else this.callServiceAPI(t,n,e[y]);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,ae.handleResponseProperty(e));case 1:if(!B.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.length>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.length-1).forEach(function(a){s.append("message".concat(r+=1),oe(a));});var o=t[t.length-1];return o[h]&&(delete o[y],s.append("message".concat(r+=1),oe(o))),s;}}]);}();var M=/*#__PURE__*/function(_sn){// prettier-ignore
124
+ },{key:"processCamera",value:function processCamera(e,t,n,s){var _c$y2;var a,c,l,d;var o=_objectSpread({acceptedFormats:"image/*"},((a=e.fileTypes[Z])==null?void 0:a[y])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e[Ne]=Ee.parseConfig(o,t,n),_typeof(n)=="object"&&(e[Ne].modalContainerStyle=n.modalContainerStyle,n[y]&&((_c$y2=(c=e[Ne])[y])!==null&&_c$y2!==void 0?_c$y2:c[y]={},e[Ne][y].format=(l=n[y])==null?void 0:l.format,e[Ne][y].dimensions=(d=n[y])==null?void 0:d.dimensions))):s||(e.fileTypes[Z]=Ee.parseConfig(o,t,n)));}// prettier-ignore
125
+ },{key:"processImagesConfig",value:function processImagesConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/*"},(s==null?void 0:s[y])||{});e.fileTypes[Z]=Ee.parseConfig(o,t,n);}// default for direct service
126
+ },{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$y,_n$acceptedFormats,_s$maxNumberOfFiles;var n,s;e&&((_e$y=e[y])!==null&&_e$y!==void 0?_e$y:e[y]={},(_n$acceptedFormats=(n=e[y]).acceptedFormats)!==null&&_n$acceptedFormats!==void 0?_n$acceptedFormats:n.acceptedFormats=t,(_s$maxNumberOfFiles=(s=e[y]).maxNumberOfFiles)!==null&&_s$maxNumberOfFiles!==void 0?_s$maxNumberOfFiles:s.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,n){Ee.populateDefaultFileIO(n==null?void 0:n[j],".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),Ee.populateDefaultFileIO(n==null?void 0:n[Z],".png,.jpg");var s=ys.createNew(e.remarkable);Ee.processImagesConfig(t,s,e[Z],n==null?void 0:n[Z]),Ee.processCamera(t,s,e[Ne],e[Z]),Ee.processGifConfig(t,s,e[bn],n==null?void 0:n[bn]),Ee.processAudioConfig(t,s,e[j],n==null?void 0:n[j]),Ee.processMicrophone(t,s,e[it],e[j]),Ee.processMixedFiles(t,s,e[xo]);}}]);}();var sn=/*#__PURE__*/function(){function sn(e,t,n){var _a$url;_classCallCheck(this,sn);var s,r,o,a,c;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=sn.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,Ee.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=lt.URL),this.connectSettings.websocket&&Re.setup(this),this.stream=((c=this.deepChat.connect)==null?void 0:c.stream)||ae.checkForStream(this.deepChat),e.loadHistory&&bs.addErrorPrefix(this);}return _createClass(sn,[{key:"verifyKey",value:function verifyKey(e,t){}},{key:"getServiceIOByType",value:function getServiceIOByType(e){if(e.type.startsWith(j)&&this.fileTypes[j])return this.fileTypes[j];if(e.type.startsWith(V)){if(this.fileTypes[bn]&&e.type.endsWith("/gif"))return this.fileTypes[bn];if(this.fileTypes[Z])return this.fileTypes[Z];if(this[Ne])return this[Ne];}return this.fileTypes[xo];}},{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&&!G.isSimulation(this.stream)?G.request(this,e,t,n):pe.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$$;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[$]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$$=(a=this.connectSettings.headers)[$])!==null&&_a$$!==void 0?_a$$:a[$]=J,s=!0);_context28.n=1;return this.request(n,e);case 1:s&&((c=this.connectSettings.headers)==null||delete c[$]);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=sn.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(De);case 1:n=xn.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!==lt.URL)){r=_objectSpread({messages:n},this.rawBody);e[y]&&(s=this.getServiceIOByType(e[y][0]))!=null&&s.connect?this.callApiWithFiles(t,n,e[y]):Re.sendWebsocket(this,r,t,!1);}else this.callServiceAPI(t,n,e[y]);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,ae.handleResponseProperty(e));case 1:if(!B.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.length>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.length-1).forEach(function(a){s.append("message".concat(r+=1),oe(a));});var o=t[t.length-1];return o[h]&&(delete o[y],s.append("message".concat(r+=1),oe(o))),s;}}]);}();var M=/*#__PURE__*/function(_sn){// prettier-ignore
128
128
  function M(e,t,n,s,r){var _this16;_classCallCheck(this,M);var o;_this16=_callSuper(this,M,[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(M,_sn);return _createClass(M,[{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;pe.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 Sn.getCharacterLimitMessages(e,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this.systemMessage.length:-1);}},{key:"addSystemMessage",value:function addSystemMessage(e){this.systemMessage&&e.unshift(_defineProperty(_defineProperty({},S,"system"),"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(De);case 1:o=n(this.rawBody,t),a=s?this.stream:!1;if(!(a&&(_typeof(a)!==F||!a.simulation)||o.stream)){_context33.n=2;break;}o.stream=!0,s!=null&&s.readable&&(this.stream={readable:!0}),G.request(this,o,e);_context33.n=4;break;case 2:_context33.n=3;return pe.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(Qt);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?G.request(this,e,t):pe.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(Dt);case 1:o=w(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.length-1),r.message&&o.messages.unshift(_defineProperty(_defineProperty({},S,"system"),"content",r.message))),o.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},S,ut),"content",null)),!c.find(function(_ref25){var d=_ref25.response;return _typeof(d)!==ye;})&&a.length===c.length)){_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({},S,"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(Qt);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.length>0&&(this.messages.messageToElements[this.messages.messageToElements.length-1][0]._sessionId=e);}}],[{key:"getRoleViaUser",value:function getRoleViaUser(e){return e===D?D:ut;}},{key:"getRoleViaAI",value:function getRoleViaAI(e){return e===Q?ut:D;}},{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type===V;}).map(function(t){return _defineProperty(_defineProperty({},I,He),He,{url:t[C]||""});}).filter(function(t){return t[He].url.length>0;});}},{key:"getTextWImagesContent",value:function getTextWImagesContent(e){if(e[y]&&e[y].length>0){var t=this.getImageContent(e[y]);return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}},{key:"getTextWFilesContent",value:function getTextWFilesContent(e,t){if(e[y]&&e[y].length>0){var n=t(e[y]);return e[h]&&e[h].trim().length>0&&n.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),n;}return e[h]||"";}}]);}(sn);var Hs=/*#__PURE__*/function(){function Hs(){_classCallCheck(this,Hs);}return _createClass(Hs,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?Hs.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,Hs.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var vt=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
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;pe.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 xn.getCharacterLimitMessages(e,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this.systemMessage.length:-1);}},{key:"addSystemMessage",value:function addSystemMessage(e){this.systemMessage&&e.unshift(_defineProperty(_defineProperty({},S,Sn),"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(De);case 1:o=n(this.rawBody,t),a=s?this.stream:!1;if(!(a&&(_typeof(a)!==F||!a.simulation)||o.stream)){_context33.n=2;break;}o.stream=!0,s!=null&&s.readable&&(this.stream={readable:!0}),G.request(this,o,e);_context33.n=4;break;case 2:_context33.n=3;return pe.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(Qt);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?G.request(this,e,t):pe.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(Dt);case 1:o=w(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.length-1),r.message&&o.messages.unshift(_defineProperty(_defineProperty({},S,Sn),"content",r.message))),o.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},S,ut),"content",null)),!c.find(function(_ref25){var d=_ref25.response;return _typeof(d)!==ye;})&&a.length===c.length)){_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({},S,"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(Qt);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.length>0&&(this.messages.messageToElements[this.messages.messageToElements.length-1][0]._sessionId=e);}}],[{key:"getRoleViaUser",value:function getRoleViaUser(e){return e===D?D:ut;}},{key:"getRoleViaAI",value:function getRoleViaAI(e){return e===Q?ut:D;}},{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type===V;}).map(function(t){return _defineProperty(_defineProperty({},I,He),He,{url:t[C]||""});}).filter(function(t){return t[He].url.length>0;});}},{key:"getTextWImagesContent",value:function getTextWImagesContent(e){if(e[y]&&e[y].length>0){var t=this.getImageContent(e[y]);return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}},{key:"getTextWFilesContent",value:function getTextWFilesContent(e,t){if(e[y]&&e[y].length>0){var n=t(e[y]);return e[h]&&e[h].trim().length>0&&n.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),n;}return e[h]||"";}}]);}(sn);var js=/*#__PURE__*/function(){function js(){_classCallCheck(this,js);}return _createClass(js,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?js.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,js.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var vt=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
130
130
  function vt(){var _this17;_classCallCheck(this,vt);_this17=_callSuper(this,vt),_this17._waitingToRender_=!1,_this17._propUpdated_=!1,Object.keys(vt._attributeToProperty_).forEach(function(e){var t=vt._attributeToProperty_[e];_this17.constructPropertyAccessors(t),_this17.hasOwnProperty(e)||_this17.constructPropertyAccessors(t,e);});return _this17;}_inherits(vt,_HTMLElement);return _createClass(vt,[{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:Hs.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,n){if(t===n)return;var s=vt._attributes_[e](n),r=vt._attributeToProperty_[e];this[r]=s;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(vt._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));vt._attributes_={},vt._attributeToProperty_={};var Li=vt;var fl="<?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",ml="<?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 Ct=/*#__PURE__*/function(){function Ct(){_classCallCheck(this,Ct);}return _createClass(Ct,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Lt=/*#__PURE__*/function(){function Lt(){_classCallCheck(this,Lt);}return _createClass(Lt,null,[{key:"changeVisibility",value:// prettier-ignore
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:js.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,n){if(t===n)return;var s=vt._attributes_[e](n),r=vt._attributeToProperty_[e];this[r]=s;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(vt._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));vt._attributes_={},vt._attributeToProperty_={};var Oi=vt;var ml="<?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",gl="<?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 Ct=/*#__PURE__*/function(){function Ct(){_classCallCheck(this,Ct);}return _createClass(Ct,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Lt=/*#__PURE__*/function(){function Lt(){_classCallCheck(this,Lt);}return _createClass(Lt,null,[{key:"changeVisibility",value:// prettier-ignore
132
132
  function changeVisibility(e,t,n,s){s.target.id===Lt.VISIBLE_ICON_ID?(t[v].display="none",n[v].display="block",e.type="password"):(t[v].display="block",n[v].display="none",e.type=h);}},{key:"createIconElement",value:function createIconElement(e,t){var n=Ct.createSVGElement(e);return n.id=t,n[m].add("visibility-icon"),n;}// prettier-ignore
133
- },{key:"create",value:function create(e){var t=x();t.id="visibility-icon-container";var n=Lt.createIconElement(ml,Lt.VISIBLE_ICON_ID);n[v].display="none",t.appendChild(n);var s=Lt.createIconElement(fl,"not-visible-icon");return t.appendChild(s),t.onclick=Lt.changeVisibility.bind(this,e,n,s),t;}}]);}();Lt.VISIBLE_ICON_ID="visible-icon";var Oi=Lt;var ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,null,[{key:"createCautionText",value:function createCautionText(){var e=x("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=x("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=x();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=x();n.id="insert-key-help-text-container";var s=x();s.id="insert-key-help-text-contents";var r=ke.createFailText();if(s.appendChild(r),e){var o=ke.createHelpLink(e);s.appendChild(o);}if(t===!0){var _o3=ke.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("loading");}},{key:"onLoad",value:function onLoad(e,t){e[m].add("loading"),t.innerHTML='<div id="loading-key"></div>';}// prettier-ignore
133
+ },{key:"create",value:function create(e){var t=x();t.id="visibility-icon-container";var n=Lt.createIconElement(gl,Lt.VISIBLE_ICON_ID);n[v].display="none",t.appendChild(n);var s=Lt.createIconElement(ml,"not-visible-icon");return t.appendChild(s),t.onclick=Lt.changeVisibility.bind(this,e,n,s),t;}}]);}();Lt.VISIBLE_ICON_ID="visible-icon";var Ni=Lt;var ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,null,[{key:"createCautionText",value:function createCautionText(){var e=x("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=x("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=x();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=x();n.id="insert-key-help-text-container";var s=x();s.id="insert-key-help-text-contents";var r=ke.createFailText();if(s.appendChild(r),e){var o=ke.createHelpLink(e);s.appendChild(o);}if(t===!0){var _o3=ke.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("loading");}},{key:"onLoad",value:function onLoad(e,t){e[m].add("loading"),t.innerHTML='<div id="loading-key"></div>';}// prettier-ignore
134
134
  },{key:"verifyKey",value:function verifyKey(e,t,n){var s=e.value.trim();n.verifyKey(s,t);}// prettier-ignore
135
135
  },{key:"addVerificationEvents",value:function addVerificationEvents(e,t,n,s,r){var o={onSuccess:s,onFail:ke.onFail.bind(this,e,t,n),onLoad:ke.onLoad.bind(this,e,t)},a=ke.verifyKey.bind(this,e,o,r);t.onclick=a,e.onkeydown=function(c){!e[m].contains("loading")&&c.key===ge.ENTER&&a();};}},{key:"createStartButton",value:function createStartButton(){var e=x();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=x();t.id="insert-key-input-container";var n=x("input");return n.id="insert-key-input",n.placeholder=e||"API Key",n.type="password",n[m].add("insert-key-input-valid"),n.onfocus=ke.onInputFocus,t.appendChild(n),t;}// prettier-ignore
136
- },{key:"createContents",value:function createContents(e,t){var d;var n=x();n.id="insert-key-contents";var s=ke.createInput(t.insertKeyPlaceholderText),r=s.children[0],o=Oi.create(r);s.appendChild(o),n.appendChild(s);var a=ke.createStartButton(),_ke$createHelpTextCon=ke.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),c=_ke$createHelpTextCon.helpTextContainerElement,l=_ke$createHelpTextCon.failTextElement;return n.appendChild(a),n.appendChild(c),ke.addVerificationEvents(r,a,l,e,t),n;}},{key:"createElements",value:function createElements(e,t){var n=x();n.id="insert-key-view";var s=ke.createContents(e,t);return n.appendChild(s),n;}},{key:"render",value:function render(e,t,n){var s=ke.createElements(t,n);e.replaceChildren(s);}}]);}();var Ge=/*#__PURE__*/function(){function Ge(){_classCallCheck(this,Ge);}return _createClass(Ge,null,[{key:"enableButtons",value:function enableButtons(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;window.webLLM?(e&&(e[H]=!1),t&&(t[H]=!1)):n<bs.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return Ge.enableButtons(e,t,n+1);},250);}// prettier-ignore
136
+ },{key:"createContents",value:function createContents(e,t){var d;var n=x();n.id="insert-key-contents";var s=ke.createInput(t.insertKeyPlaceholderText),r=s.children[0],o=Ni.create(r);s.appendChild(o),n.appendChild(s);var a=ke.createStartButton(),_ke$createHelpTextCon=ke.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),c=_ke$createHelpTextCon.helpTextContainerElement,l=_ke$createHelpTextCon.failTextElement;return n.appendChild(a),n.appendChild(c),ke.addVerificationEvents(r,a,l,e,t),n;}},{key:"createElements",value:function createElements(e,t){var n=x();n.id="insert-key-view";var s=ke.createContents(e,t);return n.appendChild(s),n;}},{key:"render",value:function render(e,t,n){var s=ke.createElements(t,n);e.replaceChildren(s);}}]);}();var Ge=/*#__PURE__*/function(){function Ge(){_classCallCheck(this,Ge);}return _createClass(Ge,null,[{key:"enableButtons",value:function enableButtons(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;window.webLLM?(e&&(e[H]=!1),t&&(t[H]=!1)):n<_s.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return Ge.enableButtons(e,t,n+1);},250);}// prettier-ignore
137
137
  },{key:"setUpInitial",value:function setUpInitial(e,t,n,s){var r=(t==null?void 0:t.downloadClass)||Ge.DOWNLOAD_BUTTON_CLASS,o=(t==null?void 0:t.uploadClass)||Ge.UPLOAD_BUTTON_CLASS,a=(t==null?void 0:t.fileInputClass)||Ge.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[y]&&l[y].length>0&&e(l[y]);}),d&&(d.onclick=function(){return l[X]();}),(c||d)&&Ge.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=x("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[X](),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)||Ge.EXPORT_BUTTON_CLASS;return setTimeout(function(){var o=n==null?void 0:n.getElementsByClassName(r)[0];o&&(o.onclick=function(){return Ge.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>");}}]);}();Ge.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",Ge.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",Ge.FILE_INPUT_CLASS="deep-chat-file-input",Ge.EXPORT_BUTTON_CLASS="deep-chat-export-button";var js=Ge;var Gr={model_list:[// Llama-2
138
+ },{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,n,s){var r=(t==null?void 0:t.exportFilesClass)||Ge.EXPORT_BUTTON_CLASS;return setTimeout(function(){var o=n==null?void 0:n.getElementsByClassName(r)[0];o&&(o.onclick=function(){return Ge.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>");}}]);}();Ge.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",Ge.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",Ge.FILE_INPUT_CLASS="deep-chat-file-input",Ge.EXPORT_BUTTON_CLASS="deep-chat-export-button";var $s=Ge;var zr={model_list:[// Llama-2
139
139
  {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
140
  {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
141
  {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
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},W=/*#__PURE__*/function(_sn2){function W(e){var _this18;_classCallCheck(this,W);var t,n;_this18=_callSuper(this,W,[e]),_this18._isModelLoaded=!1,_this18._isModelLoading=!1,_this18._loadOnFirstMessage=!1,_this18._webModel={},_this18.permittedErrorPrefixes=[W.MULTIPLE_MODELS_ERROR,W.WEB_LLM_NOT_FOUND_ERROR,W.GENERIC_ERROR],_this18._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this18._webModel=e.webModel),(t=_this18._webModel.load)!=null&&t.clearCache&&W.clearAllCache(),_this18.findModelInWindow(e),_this18.canSendMessage=_this18.canSubmit.bind(_assertThisInitialized(_this18)),_this18._chatEl=(n=e.shadowRoot)==null?void 0:n.children[0],e.history&&W.setUpHistory(_this18._conversationHistory,e.history);return _this18;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
143
143
  _inherits(W,_sn2);return _createClass(W,[{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>W.MODULE_SEARCH_LIMIT_S?((n=this._messages)==null||n.addNewErrorMessage(ie,W.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&&q.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({},S,Q),"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(W.chat){(t=this._messages)==null||t.addNewErrorMessage(ie,W.MULTIPLE_MODELS_ERROR),console[f](W.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return Gr.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var n;var e=W.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=w(Gr);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,b,_,_g,_t17;return _regenerator().w(function(_context39){while(1)switch(_context39.p=_context39.n){case 0:this.scrollToTop(),W.chat=e,this._isModelLoading=!0;n=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;s=function s(g){var b;(b=_this22._messages)==null||b.addNewMessage({html:"<div>".concat(g[h],"</div>"),overwrite:!0,sendUpdate:!1}),n&&(setTimeout(function(){return q.scrollToBottom(_this22._messages);}),n=!1);};W.chat.setInitProgressCallback(s);_context39.p=1;_this$getConfig=this.getConfig(),g=_this$getConfig.model,b=_this$getConfig.appConfig,_={};this._webModel.instruction&&(_.conv_config={system:this._webModel.instruction});this._conversationHistory.length>0&&(_.conversation_history=this._conversationHistory);_context39.n=2;return W.chat.reload(g,_,b,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(ie,W.GENERIC_ERROR);console[f](e);this._isModelLoaded=!1;this._isModelLoading=!1;_t18=W.chat;if(!_t18){_context40.n=2;break;}_context40.n=1;return W.chat.unload();case 1:W.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 W.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 at(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 W.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(ie),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$B$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 B.processRequestInterceptor(this.deepChat,{body:_defineProperty({},h,s)});case 1:_yield$B$processReque5=_context45.v;r=_yield$B$processReque5.body;o=_yield$B$processReque5.error;a=!!this.stream;try{if(o)B.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!r||!r[h]){c=pa({body:r},!1);console[f](c);l=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;B.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:!W.chat||this._isModelLoading||((n=this._webModel.introMessage)!=null&&n.removeAfterMessage&&((s=this._removeIntro)==null||s.call(this)),e.addLoadingMessage(),this.generateResp(e,t,W.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[S]===D&&n[h]){var r=t[s+1];r!=null&&r[h]&&r[S]!==D&&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](Co);return _context47.a(2);case 3:r=Array.isArray(s)?s:[s],o=r.find(function(l){return _typeof(l[f])===ye;});if(!o){_context47.n=4;break;}B.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=fa(n,!!e.responseInterceptor,s);B.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(){W.clearCache("webllm/model"),W.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);});});});}}]);}(sn);W.GENERIC_ERROR="Error, please check the [troubleshooting](".concat(K,"webModel#troubleshooting) section of documentation for help."),W.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",W.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",W.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",W.MODULE_SEARCH_LIMIT_S=5;var bs=W;var fe=function fe(i,e,t,n){return{url:i,method:e,handleVerificationResult:t,augmentUrl:n};},gl=function gl(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},yl=function yl(i,e,t,n){var s=i;Array.isArray(s[f])&&s[f][0]==="Error in `parameters`: field required"?t(e):n(de);},bl=function bl(){return fe("https://api-inference.huggingface.co/models/gpt2",me,yl);},ls=/*#__PURE__*/function(_M){// prettier-ignore
146
- function ls(e,t,n,s,r,o){var _this24;_classCallCheck(this,ls);_this24=_callSuper(this,ls,[e,bl(),gl,r,o]),_this24.insertKeyPlaceholderText="Hugging Face Token",_this24.keyHelpUrl="https://huggingface.co/settings/tokens",_this24.permittedErrorPrefixes=[Zi],_this24.url="".concat(ls.URL_PREFIX).concat(n),_this24.textInputPlaceholderText=t,_typeof(s)=="object"&&(s.model&&(_this24.url="".concat(ls.URL_PREFIX).concat(s.model)),s.options&&(_this24.rawBody.options=s.options),s.parameters&&(_this24.rawBody.parameters=s.parameters));return _this24;}_inherits(ls,_M);return _createClass(ls,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var _s$options;var s=w(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(De);case 1:s=this.preprocessBody(this.rawBody,t,n);pe.request(this,s,e);case 2:return _context48.a(2);}},_callee48,this);}));function callServiceAPI(_x108,_x109,_x110){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(M);ls.URL_PREFIX="https://api-inference.huggingface.co/models/";var Tt=ls;var xs=/*#__PURE__*/function(_Tt){// prettier-ignore
147
- function xs(e,t,n,s,r,o){var _this25;_classCallCheck(this,xs);_this25=_callSuper(this,xs,[e,t,n,s,r,o]),_this25.isTextInputDisabled=!0,_this25.canSendMessage=xs.canSendFile;return _this25;}_inherits(xs,_Tt);return _createClass(xs,[{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(De);case 1:if(n!=null&&n[0]){_context49.n=2;break;}throw new Error(ci);case 2:pe.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]);}}]);}(Tt);var _l=/*#__PURE__*/function(_xs){// prettier-ignore
149
- function _l(e){_classCallCheck(this,_l);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,_l,[e,"Attach an audio ".concat(ee),"ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,n,{audio:{}}]);}_inherits(_l,_xs);return _createClass(_l,[{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;}()}]);}(xs);var vl=/*#__PURE__*/function(_xs2){function vl(e){_classCallCheck(this,vl);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,vl,[e,"Attach an image ".concat(ee),"google/vit-base-patch16-224",t,n,{images:{}}]);}_inherits(vl,_xs2);return _createClass(vl,[{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;}()}]);}(xs);var ui=function ui(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},El=function El(i,e,t,n){i.message?n(de):t(e);},pi=function pi(){return fe("https://api.stability.ai/v1/engines/list",le,El);},wn="data:image/png;base64,";var fi=/*#__PURE__*/function(_M2){// prettier-ignore
150
- function fi(e,t,n,s,r){var _this26;_classCallCheck(this,fi);_this26=_callSuper(this,fi,[e,t,n,s,r]),_this26.insertKeyPlaceholderText=_this26.genereteAPIKeyName("Stability AI"),_this26.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this26.permittedErrorPrefixes=[Ss,"invalid_"];return _this26;}_inherits(fi,_M2);return _createClass(fi);}(M);var $s=/*#__PURE__*/function(_fi){function $s(e){var _this27;_classCallCheck(this,$s);var o;var t=w(e.directConnection),n=t==null?void 0:t.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this27=_callSuper(this,$s,[e,pi(),ui,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")),$s.cleanConfig(r),Object.assign(_this27.rawBody,r)),_this27.canSendMessage=$s.canSendFileMessage;return _this27;}_inherits($s,_fi);return _createClass($s,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(V,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(De);case 1:if(n){_context52.n=2;break;}throw new Error(Xi);case 2:s=this.createFormDataBody(this.rawBody,n[0]);B.tempRemoveContentHeader(this.connectSettings,pe.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({},C,"".concat(wn).concat(n.base64)),I,V);});return _context53.a(2,_defineProperty({},y,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]);}}]);}(fi);var qs=/*#__PURE__*/function(_fi2){function qs(e){var _this28;_classCallCheck(this,qs);var o;var t=w(e.directConnection),n=t==null?void 0:t.stabilityAI,s=_defineProperty({},Y,_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:2}));_this28=_callSuper(this,qs,[e,pi(),ui,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),qs.cleanConfig(r),Object.assign(_this28.rawBody,r)),_this28.canSendMessage=qs.canSendFileTextMessage;return _this28;}_inherits(qs,_fi2);return _createClass(qs,[{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(De);case 1:if(!(!n||!n[0]||!n[1])){_context54.n=2;break;}throw new Error(Xi);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);B.tempRemoveContentHeader(this.connectSettings,pe.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({},C,"".concat(wn).concat(n.base64)),I,V);});return _context55.a(2,_defineProperty({},y,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()!=="");}}]);}(fi);var Sl=/*#__PURE__*/function(_xs3){function Sl(e){_classCallCheck(this,Sl);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,Sl,[e,"Attach an audio ".concat(ee),"facebook/wav2vec2-large-960h-lv60-self",t,n,{audio:{}}]);}_inherits(Sl,_xs3);return _createClass(Sl,[{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;}()}]);}(xs);var xl=/*#__PURE__*/function(_Tt2){function xl(e){_classCallCheck(this,xl);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,xl,[e,"Once upon a time","gpt2",t,n]);}_inherits(xl,_Tt2);return _createClass(xl,[{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;}()}]);}(Tt);var Al=/*#__PURE__*/function(_Tt3){function Al(e){var _this29;_classCallCheck(this,Al);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,Al,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,n]),_this29.permittedErrorPrefixes=[Zi,"Error in"],_this29._context=t.context;return _this29;}_inherits(Al,_Tt3);return _createClass(Al,[{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;}()}]);}(Tt);var wl=/*#__PURE__*/function(_Tt4){function wl(e){_classCallCheck(this,wl);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,wl,[e,"Insert text to summarize","facebook/bart-large-cnn",t,n]);}_inherits(wl,_Tt4);return _createClass(wl,[{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;}()}]);}(Tt);var Cl=/*#__PURE__*/function(_Tt5){function Cl(e){var _this30$maxMessages;var _this30;_classCallCheck(this,Cl);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,Cl,[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(Cl,_Tt5);return _createClass(Cl,[{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[S]===D;}).map(function(a){return a[h];}),o=s.filter(function(a){return a[S]===Q;}).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=w(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;}()}]);}(Tt);var Gs=/*#__PURE__*/function(_fi3){function Gs(e){var _this31;_classCallCheck(this,Gs);var o;var t=w(e.directConnection),n=t.stabilityAI,s=_defineProperty({},Y,_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:1}));_this31=_callSuper(this,Gs,[e,pi(),ui,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),Gs.cleanConfig(r),Object.assign(_this31.rawBody,r)),_this31.canSendMessage=Gs.canSendFileTextMessage;return _this31;}_inherits(Gs,_fi3);return _createClass(Gs,[{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(De);case 1:if(n){_context61.n=2;break;}throw new Error(Xi);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);B.tempRemoveContentHeader(this.connectSettings,pe.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({},C,"".concat(wn).concat(n.base64)),I,V);});return _context62.a(2,_defineProperty({},y,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()!=="");}}]);}(fi);var Tl=/*#__PURE__*/function(_Tt6){function Tl(e){_classCallCheck(this,Tl);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,Tl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(Tl,_Tt6);return _createClass(Tl,[{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;}()}]);}(Tt);var zs=/*#__PURE__*/function(_fi4){function zs(e){var _this32;_classCallCheck(this,zs);var r;var t=w(e.directConnection),n=t.stabilityAI;_this32=_callSuper(this,zs,[e,pi(),ui,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),zs.cleanConfig(s),Object.assign(_this32.rawBody,s)),_this32.canSendMessage=zs.canSendTextMessage;return _this32;}_inherits(zs,_fi4);return _createClass(zs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=w(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({},C,"".concat(wn).concat(n.base64)),I,V);});return _context65.a(2,_defineProperty({},y,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()!=="");}}]);}(fi);var Rl=/*#__PURE__*/function(_Tt7){function Rl(e){var _this33;_classCallCheck(this,Rl);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,Rl,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this33.permittedErrorPrefixes=[Zi,"No mask_token"];return _this33;}_inherits(Rl,_Tt7);return _createClass(Rl,[{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;}()}]);}(Tt);var nr=function nr(i){return _defineProperty(_defineProperty({},$,J),ce,"".concat(xe).concat(i));},Il=function Il(i,e,t,n){var s=i;s[f]?s[f].message===li?n(de):n(Be):t(e);},sr=function sr(){return fe("https://open.bigmodel.cn/api/paas/v4/models",le,Il);};var Ml=/*#__PURE__*/function(_M3){function Ml(e){var _o$model,_a$voice;var _this34;_classCallCheck(this,Ml);var r,o,a;var t=w(e.directConnection),n=t.bigModel;_this34=_callSuper(this,Ml,[e,sr(),nr,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=[ce,Ae];var s=(r=t.bigModel)==null?void 0:r.textToSpeech;_typeof(s)===F&&(_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(Ml,_M3);return _createClass(Ml,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},I,"audio/mpeg")),n=URL.createObjectURL(t);return _context68.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},C,n),I,j)]));}},_callee68);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(M);var ir=function ir(i){return _defineProperty(_defineProperty({},$,J),ce,"".concat(xe).concat(i));},kl=function kl(i,e,t,n){var s=i;s[f]?s[f].message===li?n(de):n(Be):t(e);},rr=function rr(){return fe("https://api.together.xyz/v1/models",le,kl);};var Pl=/*#__PURE__*/function(_M4){function Pl(e){var _o$model2,_a$voice2;var _this35;_classCallCheck(this,Pl);var r,o,a;var t=w(e.directConnection),n=t.together;_this35=_callSuper(this,Pl,[e,rr(),ir,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=[et,Ae];var s=(r=t.together)==null?void 0:r.textToSpeech;_typeof(s)===F&&_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(Pl,_M4);return _createClass(Pl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},I,"audio/mpeg")),n=URL.createObjectURL(t);return _context70.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},C,n),I,j)]));}},_callee70);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(M);var $e="https://api.openai.com/v1/",Cn="https://platform.openai.com/account/api-keys",Ni="input_text",zr="input_image",Vr="output_text",Ci="image_generation_call",jo="function_call_output",Mn="response",Tn=function Tn(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},$o=function $o(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(de):n(Be):t(e);},Rn=function Rn(){return fe("".concat($e,"models"),le,$o);},Nt=/*#__PURE__*/function(){var _ref55=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(i,e,t){var n,s,r,o,a,c,_yield$B$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 B.processRequestInterceptor(r,c);case 1:_yield$B$processReque6=_context71.v;l=_yield$B$processReque6.body;d=_yield$B$processReque6.headers;p=_yield$B$processReque6.error;u=o.onFinish;if(!(p&&a)){_context71.n=2;break;}return _context71.a(2,B.onInterceptorError(a,p,u));case 2:_context71.n=3;return B.fetch(i,d,n,l).then(function(b){return B.processResponseByType(b);});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 Nt(_x144,_x145,_x146){return _ref55.apply(this,arguments);};}(),ze=/*#__PURE__*/function(){function ze(){_classCallCheck(this,ze);}return _createClass(ze,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[$];delete r[$];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(Nt(e,l,me,!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[$]=o,c));case 4:_context73.p=4;_t24=_context73.v;throw r[$]=o,B.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")?V:Jt;}},{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(Nt(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({},C,u.target.result),"name",t[l].name),I,ze.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
144
+ },{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=$s.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),_defineProperty(_defineProperty(_defineProperty({},S,Q),"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(W.chat){(t=this._messages)==null||t.addNewErrorMessage(ie,W.MULTIPLE_MODELS_ERROR),console[f](W.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return zr.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var n;var e=W.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=w(zr);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,b,_,_g,_t17;return _regenerator().w(function(_context39){while(1)switch(_context39.p=_context39.n){case 0:this.scrollToTop(),W.chat=e,this._isModelLoading=!0;n=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;s=function s(g){var b;(b=_this22._messages)==null||b.addNewMessage({html:"<div>".concat(g[h],"</div>"),overwrite:!0,sendUpdate:!1}),n&&(setTimeout(function(){return q.scrollToBottom(_this22._messages);}),n=!1);};W.chat.setInitProgressCallback(s);_context39.p=1;_this$getConfig=this.getConfig(),g=_this$getConfig.model,b=_this$getConfig.appConfig,_={};this._webModel.instruction&&(_.conv_config=_defineProperty({},Sn,this._webModel.instruction));this._conversationHistory.length>0&&(_.conversation_history=this._conversationHistory);_context39.n=2;return W.chat.reload(g,_,b,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=$s.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(ie,W.GENERIC_ERROR);console[f](e);this._isModelLoaded=!1;this._isModelLoading=!1;_t18=W.chat;if(!_t18){_context40.n=2;break;}_context40.n=1;return W.chat.unload();case 1:W.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 W.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 at(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 W.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(ie),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$B$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 B.processRequestInterceptor(this.deepChat,{body:_defineProperty({},h,s)});case 1:_yield$B$processReque5=_context45.v;r=_yield$B$processReque5.body;o=_yield$B$processReque5.error;a=!!this.stream;try{if(o)B.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!r||!r[h]){c=fa({body:r},!1);console[f](c);l=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;B.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:!W.chat||this._isModelLoading||((n=this._webModel.introMessage)!=null&&n.removeAfterMessage&&((s=this._removeIntro)==null||s.call(this)),e.addLoadingMessage(),this.generateResp(e,t,W.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[S]===D&&n[h]){var r=t[s+1];r!=null&&r[h]&&r[S]!==D&&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](To);return _context47.a(2);case 3:r=Array.isArray(s)?s:[s],o=r.find(function(l){return _typeof(l[f])===ye;});if(!o){_context47.n=4;break;}B.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=ma(n,!!e.responseInterceptor,s);B.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(){W.clearCache("webllm/model"),W.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);});});});}}]);}(sn);W.GENERIC_ERROR="Error, please check the [troubleshooting](".concat(K,"webModel#troubleshooting) section of documentation for help."),W.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",W.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",W.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",W.MODULE_SEARCH_LIMIT_S=5;var _s=W;var fe=function fe(i,e,t,n){return{url:i,method:e,handleVerificationResult:t,augmentUrl:n};},yl=function yl(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},bl=function bl(i,e,t,n){var s=i;Array.isArray(s[f])&&s[f][0]==="Error in `parameters`: field required"?t(e):n(de);},_l=function _l(){return fe("https://api-inference.huggingface.co/models/gpt2",me,bl);},ds=/*#__PURE__*/function(_M){// prettier-ignore
146
+ function ds(e,t,n,s,r,o){var _this24;_classCallCheck(this,ds);_this24=_callSuper(this,ds,[e,_l(),yl,r,o]),_this24.insertKeyPlaceholderText="Hugging Face Token",_this24.keyHelpUrl="https://huggingface.co/settings/tokens",_this24.permittedErrorPrefixes=[Zi],_this24.url="".concat(ds.URL_PREFIX).concat(n),_this24.textInputPlaceholderText=t,_typeof(s)=="object"&&(s.model&&(_this24.url="".concat(ds.URL_PREFIX).concat(s.model)),s.options&&(_this24.rawBody.options=s.options),s.parameters&&(_this24.rawBody.parameters=s.parameters));return _this24;}_inherits(ds,_M);return _createClass(ds,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var _s$options;var s=w(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(De);case 1:s=this.preprocessBody(this.rawBody,t,n);pe.request(this,s,e);case 2:return _context48.a(2);}},_callee48,this);}));function callServiceAPI(_x108,_x109,_x110){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(M);ds.URL_PREFIX="https://api-inference.huggingface.co/models/";var Tt=ds;var As=/*#__PURE__*/function(_Tt){// prettier-ignore
147
+ function As(e,t,n,s,r,o){var _this25;_classCallCheck(this,As);_this25=_callSuper(this,As,[e,t,n,s,r,o]),_this25.isTextInputDisabled=!0,_this25.canSendMessage=As.canSendFile;return _this25;}_inherits(As,_Tt);return _createClass(As,[{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(De);case 1:if(n!=null&&n[0]){_context49.n=2;break;}throw new Error(li);case 2:pe.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]);}}]);}(Tt);var vl=/*#__PURE__*/function(_As){// prettier-ignore
149
+ function vl(e){_classCallCheck(this,vl);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,vl,[e,"Attach an audio ".concat(ee),"ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,n,{audio:{}}]);}_inherits(vl,_As);return _createClass(vl,[{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;}()}]);}(As);var El=/*#__PURE__*/function(_As2){function El(e){_classCallCheck(this,El);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,El,[e,"Attach an image ".concat(ee),"google/vit-base-patch16-224",t,n,{images:{}}]);}_inherits(El,_As2);return _createClass(El,[{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;}()}]);}(As);var pi=function pi(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},Sl=function Sl(i,e,t,n){i.message?n(de):t(e);},fi=function fi(){return fe("https://api.stability.ai/v1/engines/list",le,Sl);},Cn="data:image/png;base64,";var mi=/*#__PURE__*/function(_M2){// prettier-ignore
150
+ function mi(e,t,n,s,r){var _this26;_classCallCheck(this,mi);_this26=_callSuper(this,mi,[e,t,n,s,r]),_this26.insertKeyPlaceholderText=_this26.genereteAPIKeyName("Stability AI"),_this26.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this26.permittedErrorPrefixes=[xs,"invalid_"];return _this26;}_inherits(mi,_M2);return _createClass(mi);}(M);var qs=/*#__PURE__*/function(_mi){function qs(e){var _this27;_classCallCheck(this,qs);var o;var t=w(e.directConnection),n=t==null?void 0:t.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this27=_callSuper(this,qs,[e,fi(),pi,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,_mi);return _createClass(qs,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(V,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(De);case 1:if(n){_context52.n=2;break;}throw new Error(Yi);case 2:s=this.createFormDataBody(this.rawBody,n[0]);B.tempRemoveContentHeader(this.connectSettings,pe.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({},C,"".concat(Cn).concat(n.base64)),I,V);});return _context53.a(2,_defineProperty({},y,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]);}}]);}(mi);var Gs=/*#__PURE__*/function(_mi2){function Gs(e){var _this28;_classCallCheck(this,Gs);var o;var t=w(e.directConnection),n=t==null?void 0:t.stabilityAI,s=_defineProperty({},Z,_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:2}));_this28=_callSuper(this,Gs,[e,fi(),pi,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),Gs.cleanConfig(r),Object.assign(_this28.rawBody,r)),_this28.canSendMessage=Gs.canSendFileTextMessage;return _this28;}_inherits(Gs,_mi2);return _createClass(Gs,[{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(De);case 1:if(!(!n||!n[0]||!n[1])){_context54.n=2;break;}throw new Error(Yi);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);B.tempRemoveContentHeader(this.connectSettings,pe.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({},C,"".concat(Cn).concat(n.base64)),I,V);});return _context55.a(2,_defineProperty({},y,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()!=="");}}]);}(mi);var xl=/*#__PURE__*/function(_As3){function xl(e){_classCallCheck(this,xl);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,xl,[e,"Attach an audio ".concat(ee),"facebook/wav2vec2-large-960h-lv60-self",t,n,{audio:{}}]);}_inherits(xl,_As3);return _createClass(xl,[{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;}()}]);}(As);var Al=/*#__PURE__*/function(_Tt2){function Al(e){_classCallCheck(this,Al);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,Al,[e,"Once upon a time","gpt2",t,n]);}_inherits(Al,_Tt2);return _createClass(Al,[{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;}()}]);}(Tt);var wl=/*#__PURE__*/function(_Tt3){function wl(e){var _this29;_classCallCheck(this,wl);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,wl,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,n]),_this29.permittedErrorPrefixes=[Zi,"Error in"],_this29._context=t.context;return _this29;}_inherits(wl,_Tt3);return _createClass(wl,[{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;}()}]);}(Tt);var Cl=/*#__PURE__*/function(_Tt4){function Cl(e){_classCallCheck(this,Cl);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,Cl,[e,"Insert text to summarize","facebook/bart-large-cnn",t,n]);}_inherits(Cl,_Tt4);return _createClass(Cl,[{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;}()}]);}(Tt);var Tl=/*#__PURE__*/function(_Tt5){function Tl(e){var _this30$maxMessages;var _this30;_classCallCheck(this,Tl);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,Tl,[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(Tl,_Tt5);return _createClass(Tl,[{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[S]===D;}).map(function(a){return a[h];}),o=s.filter(function(a){return a[S]===Q;}).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=w(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;}()}]);}(Tt);var zs=/*#__PURE__*/function(_mi3){function zs(e){var _this31;_classCallCheck(this,zs);var o;var t=w(e.directConnection),n=t.stabilityAI,s=_defineProperty({},Z,_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:1}));_this31=_callSuper(this,zs,[e,fi(),pi,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),zs.cleanConfig(r),Object.assign(_this31.rawBody,r)),_this31.canSendMessage=zs.canSendFileTextMessage;return _this31;}_inherits(zs,_mi3);return _createClass(zs,[{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(De);case 1:if(n){_context61.n=2;break;}throw new Error(Yi);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);B.tempRemoveContentHeader(this.connectSettings,pe.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({},C,"".concat(Cn).concat(n.base64)),I,V);});return _context62.a(2,_defineProperty({},y,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()!=="");}}]);}(mi);var Rl=/*#__PURE__*/function(_Tt6){function Rl(e){_classCallCheck(this,Rl);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,Rl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(Rl,_Tt6);return _createClass(Rl,[{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;}()}]);}(Tt);var Vs=/*#__PURE__*/function(_mi4){function Vs(e){var _this32;_classCallCheck(this,Vs);var r;var t=w(e.directConnection),n=t.stabilityAI;_this32=_callSuper(this,Vs,[e,fi(),pi,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),Vs.cleanConfig(s),Object.assign(_this32.rawBody,s)),_this32.canSendMessage=Vs.canSendTextMessage;return _this32;}_inherits(Vs,_mi4);return _createClass(Vs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=w(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({},C,"".concat(Cn).concat(n.base64)),I,V);});return _context65.a(2,_defineProperty({},y,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()!=="");}}]);}(mi);var Il=/*#__PURE__*/function(_Tt7){function Il(e){var _this33;_classCallCheck(this,Il);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,Il,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this33.permittedErrorPrefixes=[Zi,"No mask_token"];return _this33;}_inherits(Il,_Tt7);return _createClass(Il,[{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;}()}]);}(Tt);var sr=function sr(i){return _defineProperty(_defineProperty({},$,J),ce,"".concat(xe).concat(i));},Ml=function Ml(i,e,t,n){var s=i;s[f]?s[f].message===di?n(de):n(Be):t(e);},ir=function ir(){return fe("https://open.bigmodel.cn/api/paas/v4/models",le,Ml);};var kl=/*#__PURE__*/function(_M3){function kl(e){var _o$model,_a$voice;var _this34;_classCallCheck(this,kl);var r,o,a;var t=w(e.directConnection),n=t.bigModel;_this34=_callSuper(this,kl,[e,ir(),sr,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=[ce,Ae];var s=(r=t.bigModel)==null?void 0:r.textToSpeech;_typeof(s)===F&&(_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(kl,_M3);return _createClass(kl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},I,"audio/mpeg")),n=URL.createObjectURL(t);return _context68.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},C,n),I,j)]));}},_callee68);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(M);var rr=function rr(i){return _defineProperty(_defineProperty({},$,J),ce,"".concat(xe).concat(i));},Pl=function Pl(i,e,t,n){var s=i;s[f]?s[f].message===di?n(de):n(Be):t(e);},or=function or(){return fe("https://api.together.xyz/v1/models",le,Pl);};var Ll=/*#__PURE__*/function(_M4){function Ll(e){var _o$model2,_a$voice2;var _this35;_classCallCheck(this,Ll);var r,o,a;var t=w(e.directConnection),n=t.together;_this35=_callSuper(this,Ll,[e,or(),rr,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=[et,Ae];var s=(r=t.together)==null?void 0:r.textToSpeech;_typeof(s)===F&&_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(Ll,_M4);return _createClass(Ll,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},I,"audio/mpeg")),n=URL.createObjectURL(t);return _context70.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},C,n),I,j)]));}},_callee70);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(M);var $e="https://api.openai.com/v1/",Tn="https://platform.openai.com/account/api-keys",Bi="input_text",Vr="input_image",Kr="output_text",Ti="image_generation_call",$o="function_call_output",kn="response",Rn=function Rn(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},qo=function qo(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(de):n(Be):t(e);},In=function In(){return fe("".concat($e,"models"),le,qo);},Nt=/*#__PURE__*/function(){var _ref55=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(i,e,t){var n,s,r,o,a,c,_yield$B$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 B.processRequestInterceptor(r,c);case 1:_yield$B$processReque6=_context71.v;l=_yield$B$processReque6.body;d=_yield$B$processReque6.headers;p=_yield$B$processReque6.error;u=o.onFinish;if(!(p&&a)){_context71.n=2;break;}return _context71.a(2,B.onInterceptorError(a,p,u));case 2:_context71.n=3;return B.fetch(i,d,n,l).then(function(b){return B.processResponseByType(b);});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 Nt(_x144,_x145,_x146){return _ref55.apply(this,arguments);};}(),ze=/*#__PURE__*/function(){function ze(){_classCallCheck(this,ze);}return _createClass(ze,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[$];delete r[$];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(Nt(e,l,me,!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[$]=o,c));case 4:_context73.p=4;_t24=_context73.v;throw r[$]=o,B.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")?V:Jt;}},{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(Nt(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({},C,u.target.result),"name",t[l].name),I,ze.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
155
  },{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 ze.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 b;if(!p[C])return;var g=t[u].path;(b=r==null?void 0:r[h])!=null&&b.value&&g&&(r[h].value=r[h].value.replace(g,p[C]));});case 2:return _context75.a(2,(d=r==null?void 0:r[h])!=null&&d.value?_defineProperty(_defineProperty({},h,r[h].value),S,s):_defineProperty(_defineProperty({},y,o),S,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
156
  // To reproduce use the following text:
157
157
  // give example data for a csv and create a suitable bar chart for it with a link
@@ -162,32 +162,32 @@ _inherits(Cl,_Tt5);return _createClass(Cl,[{key:"processMessagesI",value:functio
162
162
  // "give example data for a csv and create a suitable bar chart"
163
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(ze.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,ze.parseMessages(e,[{content:t,role:ut}],n));}},_callee79);}));function processStreamMessages(_x167,_x168,_x169){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
164
164
  },{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=ze.parseResult(t,n);return _context80.a(2,ze.parseMessages(e,r,s));}},_callee80);}));function processAPIMessages(_x170,_x171,_x172,_x173){return _processAPIMessages.apply(this,arguments);}return processAPIMessages;}()}]);}();ze.FILES_WITH_TEXT_ERROR="content with type `text` must have `text` values",ze.FUNCTION_TOOL_RESP_ERROR="Response must contain an array of strings for each individual function/tool_call, see ".concat(K,"directConnection/OpenAI/#assistant-functions.");var bt=ze;var Ot=/*#__PURE__*/function(_M5){// prettier-ignore
165
- function Ot(e,t,n,s,r,o){var _this36;_classCallCheck(this,Ot);if(_this36=_callSuper(this,Ot,[e,s,r,o]),_this36.insertKeyPlaceholderText=_this36.genereteAPIKeyName("OpenAI"),_this36.keyHelpUrl=Cn,_this36.url="",_this36.permittedErrorPrefixes=[Ss,"Please send text",ys.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(Ot,_M5);return _createClass(Ot,[{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,Ro)]);}},_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=Sn.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===Y?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 Ot.processAttachmentsMessage(s,t,"file_search");if(r==="code_interpreter")return Ot.processAttachmentsMessage(s,t,"code_interpreter");if(t.find(function(_ref64){var a=_ref64.name;return!_e.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=Ot.processImageMessage(s,t);if(_a3)return _a3;}}return _defineProperty({content:s[h]||""},S,D);}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,n){var s=w(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);pe.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):pe.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(De);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 bt.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=me,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 Nt(this,w(this._newAssistantDetails),me);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(bt.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:le,headers:(s=this.connectSettings)==null?void 0:s.headers};return _context84.a(2,(pe.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 Nt(this,w(this.rawBody),me);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 Nt(this,{},le);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,bt.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:Ot.POLLING_TIMEOUT_MS});case 1:if(!(t===Yi&&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},y,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
165
+ function Ot(e,t,n,s,r,o){var _this36;_classCallCheck(this,Ot);if(_this36=_callSuper(this,Ot,[e,s,r,o]),_this36.insertKeyPlaceholderText=_this36.genereteAPIKeyName("OpenAI"),_this36.keyHelpUrl=Tn,_this36.url="",_this36.permittedErrorPrefixes=[xs,"Please send text",bs.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(Ot,_M5);return _createClass(Ot,[{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,Io)]);}},_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=xn.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===Z?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 Ot.processAttachmentsMessage(s,t,"file_search");if(r==="code_interpreter")return Ot.processAttachmentsMessage(s,t,"code_interpreter");if(t.find(function(_ref64){var a=_ref64.name;return!_e.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=Ot.processImageMessage(s,t);if(_a3)return _a3;}}return _defineProperty({content:s[h]||""},S,D);}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,n){var s=w(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);pe.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):pe.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(De);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 bt.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=me,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 Nt(this,w(this._newAssistantDetails),me);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(bt.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:le,headers:(s=this.connectSettings)==null?void 0:s.headers};return _context84.a(2,(pe.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 Nt(this,w(this.rawBody),me);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 Nt(this,{},le);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,bt.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:Ot.POLLING_TIMEOUT_MS});case 1:if(!(t===Ji&&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},y,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
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(Dt);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(bt.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)!==ye;})){_context88.n=5;break;}throw Error(bt.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 Nt(this,{tool_outputs:r},me);case 8:return _context88.a(2,{timeoutMS:Ot.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=w(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
167
  },{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=bt.getFilesAndText.bind(this,this,_defineProperty(_defineProperty({},S,ut),"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 bt.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_c4=_context90.v;return _context90.a(2,_defineProperty(_defineProperty({},h,_c4[0][h]),y,_c4[1][y]));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
168
  // 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 G.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 _e.isImageFileExtension(s.name);}).map(function(s){return _defineProperty(_defineProperty({},I,"image_file"),"image_file",{file_id:s.id});});if(n&&n.length>0)return e[h]&&e[h].length>0&&n.push(_defineProperty(_defineProperty({},I,h),h,e[h])),_defineProperty({content:n},S,D);}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,n){return _defineProperty({attachments:t.map(function(r){return{tools:[_defineProperty({},I,n)],file_id:r.id};}),content:[_defineProperty(_defineProperty({},I,h),h,e[h])]},S,D);}}]);}(M);Ot.POLLING_TIMEOUT_MS=500;var Vs=Ot;var or=/*#__PURE__*/function(_Vs){function or(e){var _a$headers,_c$OpenAIBeta;var _this39;_classCallCheck(this,or);var o,a,c,l,d;var t=w(e.directConnection),n=t.openAI,s=(o=t.openAI)==null?void 0:o.assistant,r=or.buildUrlSegments(s);if(_this39=_callSuper(this,or,[e,s,r,Rn(),Tn,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)===F){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(or,_Vs);return _createClass(or,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||$e;return{threadsPrefix:"".concat(t,"/threads"),threadsPosfix:"",newAssistantUrl:"".concat(t,"/assistants"),createMessagePostfix:"",listMessagesPostfix:"order=desc",storeFiles:"".concat(t,"/").concat(y),getFilesPrefix:"".concat(t,"/").concat(y,"/"),getFilesPostfix:"/content"};}}]);}(Vs);var Ks="Please define the Azure URL Details. [More Information](".concat(K,"directConnection/Azure)"),qo=function qo(i){return _defineProperty({"api-key":i},$,J);},Go=function Go(i){return fe("".concat(i.endpoint,"/openai/models?api-version=").concat(i.version),le,$o);},zo=function zo(i){var e=i.endpoint,t=i.version,n=i.deploymentId;return e&&t&&n;},mn=/*#__PURE__*/function(_Vs2){function mn(e){var _E$headers;var _this40;_classCallCheck(this,mn);var l,d,p,u,g,b,_,E;var t=w(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(mn.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(mn.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(y).concat(a),getFilesPrefix:"".concat(o).concat(y,"/"),getFilesPostfix:"/content".concat(a)};if(_this40=_callSuper(this,mn,[e,s==null?void 0:s.assistant,c,Go(r),qo,n]),_this40.permittedErrorPrefixes=[Ks],_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)===F){var _ref82=(_=(b=(g=e.directConnection)==null?void 0:g.azure)==null?void 0:b.openAI)==null?void 0:_.assistant,R=_ref82.function_handler,z=_ref82.files_tool_type;R&&(_this40._functionHandlerI=R),z&&(_this40.filesToolType=z);}zo(r)?(_E$headers=(E=_this40.connectSettings).headers)!==null&&_E$headers!==void 0?_E$headers:E.headers={}:(_this40.isTextInputDisabled=!0,_this40.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,Ks));}));return _this40;}_inherits(mn,_Vs2);return _createClass(mn);}(Vs);mn.THREAD_RESOURCE="threads",mn.NEW_ASSISTANT_RESOURCE="assistants";var Bi=mn;var Ll="sts-session-started",Ol="sts-session-stopped";var ue=/*#__PURE__*/function(){function ue(){_classCallCheck(this,ue);}return _createClass(ue,null,[{key:"addAttributes",value:function addAttributes(e){e[S]="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(H),"true");}},{key:"removeAriaDisabled",value:function removeAriaDisabled(e){e.removeAttribute("aria-".concat(H));}},{key:"removeAriaAttributes",value:function removeAriaAttributes(e){ue.removeAriaBusy(e),ue.removeAriaDisabled(e);}}]);}();var Vo="<?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",Ve=/*#__PURE__*/function(){function Ve(){_classCallCheck(this,Ve);}return _createClass(Ve,null,[{key:"createTextElement",value:function createTextElement(e){var t=x();return t[m].add(Ve.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,n,s){n?e.push(Ct.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];console.log(s);var r=(c=s==null?void 0:s[h])==null?void 0:c.content,o=(l=s==null?void 0:s.svg)==null?void 0:l.content,a=[];return Ve.tryAddSVGElement(a,t,o,r),r&&a.push(Ve.createTextElement(r)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e[m].remove(Ve.INPUT_BUTTON_SVG_CLASS,Ve.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(n){return n[m].contains(Ve.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e[m].add(Ve.INPUT_BUTTON_SVG_TEXT_CLASS):e[m].add(Ve.INPUT_BUTTON_SVG_CLASS);}}]);}();Ve.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",Ve.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",Ve.INPUT_BUTTON_SVG_CLASS="input-button-svg";var gt=Ve;var ss=/*#__PURE__*/function(){function ss(){_classCallCheck(this,ss);}return _createClass(ss,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return _defineProperty({svg:e.find(function(t){return t.tagName.toLowerCase()==="svg";})},h,e.find(function(t){return t.tagName.toLowerCase()==="div";}));}}]);}();var ve=/*#__PURE__*/function(){function ve(){_classCallCheck(this,ve);}return _createClass(ve,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var r,o;t.container&&re.unsetAllCSSMouseStates(e,t.container);var _ss$parseSVGTextEleme=ss.parseSVGTextElements(Array.from(e.children)),n=_ss$parseSVGTextEleme.svg,s=_ss$parseSVGTextEleme.text;(r=t.svg)!=null&&r.styles&&n&&re.unsetAllCSSMouseStates(n,t.svg.styles),(o=t[h])!=null&&o.styles&&s&&re.unsetAllCSSMouseStates(s,t[h].styles);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var r,o;t.container&&re.unsetActivityCSSMouseStates(e,t.container);var _ss$parseSVGTextEleme2=ss.parseSVGTextElements(Array.from(e.children)),n=_ss$parseSVGTextEleme2.svg,s=_ss$parseSVGTextEleme2.text;(r=t.svg)!=null&&r.styles&&n&&re.unsetActivityCSSMouseStates(n,t.svg.styles),(o=t[h])!=null&&o.styles&&s&&re.unsetActivityCSSMouseStates(s,t[h].styles);}},{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 _ss$parseSVGTextEleme3=ss.parseSVGTextElements(Array.from(e.children)),s=_ss$parseSVGTextEleme3.svg,r=_ss$parseSVGTextEleme3.text;s&&Object.assign(s[v],(c=(a=t.svg)==null?void 0:a.styles)==null?void 0:c[n]),r&&Object.assign(r[v],(d=(l=t[h])==null?void 0:l.styles)==null?void 0:d[n]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,n){ve.setElementsCSS(e,t,A),n!==A&&(ve.setElementsCSS(e,t,Oe),n!==Oe&&ve.setElementsCSS(e,t,X));}}]);}();var cn=/*#__PURE__*/function(){// prettier-ignore
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 G.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 _e.isImageFileExtension(s.name);}).map(function(s){return _defineProperty(_defineProperty({},I,"image_file"),"image_file",{file_id:s.id});});if(n&&n.length>0)return e[h]&&e[h].length>0&&n.push(_defineProperty(_defineProperty({},I,h),h,e[h])),_defineProperty({content:n},S,D);}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,n){return _defineProperty({attachments:t.map(function(r){return{tools:[_defineProperty({},I,n)],file_id:r.id};}),content:[_defineProperty(_defineProperty({},I,h),h,e[h])]},S,D);}}]);}(M);Ot.POLLING_TIMEOUT_MS=500;var Ks=Ot;var ar=/*#__PURE__*/function(_Ks){function ar(e){var _a$headers,_c$OpenAIBeta;var _this39;_classCallCheck(this,ar);var o,a,c,l,d;var t=w(e.directConnection),n=t.openAI,s=(o=t.openAI)==null?void 0:o.assistant,r=ar.buildUrlSegments(s);if(_this39=_callSuper(this,ar,[e,s,r,In(),Rn,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)===F){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(ar,_Ks);return _createClass(ar,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||$e;return{threadsPrefix:"".concat(t,"/threads"),threadsPosfix:"",newAssistantUrl:"".concat(t,"/assistants"),createMessagePostfix:"",listMessagesPostfix:"order=desc",storeFiles:"".concat(t,"/").concat(y),getFilesPrefix:"".concat(t,"/").concat(y,"/"),getFilesPostfix:"/content"};}}]);}(Ks);var Ws="Please define the Azure URL Details. [More Information](".concat(K,"directConnection/Azure)"),Go=function Go(i){return _defineProperty({"api-key":i},$,J);},zo=function zo(i){return fe("".concat(i.endpoint,"/openai/models?api-version=").concat(i.version),le,qo);},Vo=function Vo(i){var e=i.endpoint,t=i.version,n=i.deploymentId;return e&&t&&n;},mn=/*#__PURE__*/function(_Ks2){function mn(e){var _E$headers;var _this40;_classCallCheck(this,mn);var l,d,p,u,g,b,_,E;var t=w(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(mn.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(mn.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(y).concat(a),getFilesPrefix:"".concat(o).concat(y,"/"),getFilesPostfix:"/content".concat(a)};if(_this40=_callSuper(this,mn,[e,s==null?void 0:s.assistant,c,zo(r),Go,n]),_this40.permittedErrorPrefixes=[Ws],_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)===F){var _ref82=(_=(b=(g=e.directConnection)==null?void 0:g.azure)==null?void 0:b.openAI)==null?void 0:_.assistant,R=_ref82.function_handler,z=_ref82.files_tool_type;R&&(_this40._functionHandlerI=R),z&&(_this40.filesToolType=z);}Vo(r)?(_E$headers=(E=_this40.connectSettings).headers)!==null&&_E$headers!==void 0?_E$headers:E.headers={}:(_this40.isTextInputDisabled=!0,_this40.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,Ws));}));return _this40;}_inherits(mn,_Ks2);return _createClass(mn);}(Ks);mn.THREAD_RESOURCE="threads",mn.NEW_ASSISTANT_RESOURCE="assistants";var Di=mn;var Ol="sts-session-started",Nl="sts-session-stopped";var ue=/*#__PURE__*/function(){function ue(){_classCallCheck(this,ue);}return _createClass(ue,null,[{key:"addAttributes",value:function addAttributes(e){e[S]="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(H),"true");}},{key:"removeAriaDisabled",value:function removeAriaDisabled(e){e.removeAttribute("aria-".concat(H));}},{key:"removeAriaAttributes",value:function removeAriaAttributes(e){ue.removeAriaBusy(e),ue.removeAriaDisabled(e);}}]);}();var Ko="<?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",Ve=/*#__PURE__*/function(){function Ve(){_classCallCheck(this,Ve);}return _createClass(Ve,null,[{key:"createTextElement",value:function createTextElement(e){var t=x();return t[m].add(Ve.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,n,s){n?e.push(Ct.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.svg)==null?void 0:l.content,a=[];return Ve.tryAddSVGElement(a,t,o,r),r&&a.push(Ve.createTextElement(r)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e[m].remove(Ve.INPUT_BUTTON_SVG_CLASS,Ve.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(n){return n[m].contains(Ve.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e[m].add(Ve.INPUT_BUTTON_SVG_TEXT_CLASS):e[m].add(Ve.INPUT_BUTTON_SVG_CLASS);}}]);}();Ve.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",Ve.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",Ve.INPUT_BUTTON_SVG_CLASS="input-button-svg";var gt=Ve;var is=/*#__PURE__*/function(){function is(){_classCallCheck(this,is);}return _createClass(is,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return _defineProperty({svg:e.find(function(t){return t.tagName.toLowerCase()==="svg";})},h,e.find(function(t){return t.tagName.toLowerCase()==="div";}));}}]);}();var ve=/*#__PURE__*/function(){function ve(){_classCallCheck(this,ve);}return _createClass(ve,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var r,o;t.container&&re.unsetAllCSSMouseStates(e,t.container);var _is$parseSVGTextEleme=is.parseSVGTextElements(Array.from(e.children)),n=_is$parseSVGTextEleme.svg,s=_is$parseSVGTextEleme.text;(r=t.svg)!=null&&r.styles&&n&&re.unsetAllCSSMouseStates(n,t.svg.styles),(o=t[h])!=null&&o.styles&&s&&re.unsetAllCSSMouseStates(s,t[h].styles);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var r,o;t.container&&re.unsetActivityCSSMouseStates(e,t.container);var _is$parseSVGTextEleme2=is.parseSVGTextElements(Array.from(e.children)),n=_is$parseSVGTextEleme2.svg,s=_is$parseSVGTextEleme2.text;(r=t.svg)!=null&&r.styles&&n&&re.unsetActivityCSSMouseStates(n,t.svg.styles),(o=t[h])!=null&&o.styles&&s&&re.unsetActivityCSSMouseStates(s,t[h].styles);}},{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 _is$parseSVGTextEleme3=is.parseSVGTextElements(Array.from(e.children)),s=_is$parseSVGTextEleme3.svg,r=_is$parseSVGTextEleme3.text;s&&Object.assign(s[v],(c=(a=t.svg)==null?void 0:a.styles)==null?void 0:c[n]),r&&Object.assign(r[v],(d=(l=t[h])==null?void 0:l.styles)==null?void 0:d[n]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,n){ve.setElementsCSS(e,t,A),n!==A&&(ve.setElementsCSS(e,t,Oe),n!==Oe&&ve.setElementsCSS(e,t,X));}}]);}();var cn=/*#__PURE__*/function(){// prettier-ignore
170
170
  function cn(e,t,n,s,r,o){_classCallCheck(this,cn);this._mouseState={state:"default"},this.isCustom=!1,ue.addAttributes(e),this.elementRef=e,this.svg=Ct.createSVGElement(t),this.customStyles=r,this.position=ae.processPosition(n),this._tooltipSettings=s,this.dropupText=o;}return _createClass(cn,[{key:"buttonMouseLeave",value:function buttonMouseLeave(e){var t;this._mouseState.state=A,((t=this._activeTooltip)==null?void 0:t.element[v].visibility)==="visible"&&this._tooltipSettings&&ct.hide(this._activeTooltip,this._tooltipSettings),e&&(ve.unsetAllCSS(this.elementRef,e),ve.setElementsCSS(this.elementRef,e,A));}},{key:"buttonMouseEnter",value:function buttonMouseEnter(e){var t;this._mouseState.state=Oe,this._tooltipSettings&&(this._activeTooltip=ct.display(this.elementRef,this._tooltipSettings,(t=this._activeTooltip)==null?void 0:t.element)),e&&ve.setElementsCSS(this.elementRef,e,Oe);}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&ve.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state=X,e&&ve.setElementsCSS(this.elementRef,e,X);}// 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&&ve.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&&ve.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)),gt.reassignClassBasedOnChildren(this.elementRef,e);}},{key:"buildDefaultIconElement",value:function buildDefaultIconElement(e){var t=this.svg.cloneNode(!0);return t.id=e,[t];}},{key:"createInnerElements",value:function createInnerElements(e,t,n){var s=gt.createCustomElements(t,this.svg,n);if(s&&s.length>0){if(this.position===Ye){var r=s[0].cloneNode(!0);r.id=s[0]===this.svg?e:"dropup-menu-item-icon-element-custom",s[0]=r;}return s;}return this.buildDefaultIconElement(e);}}]);}();var oi=/*#__PURE__*/function(_cn){function oi(e){var _this41;_classCallCheck(this,oi);var n,s;var t=((s=(n=e==null?void 0:e[A])==null?void 0:n.svg)==null?void 0:s.content)||oi.EMPTY_SVG;_this41=_callSuper(this,oi,[x(),t,void 0,void 0,e]),_this41.isActive=!1,_this41._innerElements=_this41.createInnerElementsForStates(_this41.customStyles),_this41.changeToDefault();return _this41;}_inherits(oi,_cn);return _createClass(oi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty(_defineProperty(_defineProperty({},A,this.createInnerButtonElements(A,e)),U,this.createInnerButtonElements(U,e)),"unavailable",this.createInnerButtonElements("unavailable",e));}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return gt.createCustomElements(e,this.svg,t)||[this.svg];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef[m].replace(gt.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements[U]),this.reapplyStateStyle(U,["unavailable",A]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,n,s;this.changeState(this._innerElements[A]),(e=this.customStyles)!=null&&e[U]&&ve.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[U]),(n=this.customStyles)!=null&&n.unavailable&&ve.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s.unavailable),this.reapplyStateStyle(A,[U,"unavailable"]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,n,s;this.changeState(this._innerElements.unavailable),(e=this.customStyles)!=null&&e[U]&&ve.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[U]),(n=this.customStyles)!=null&&n[A]&&ve.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[A]),this.reapplyStateStyle("unavailable",[A,U]),this.isActive=!1;}}]);}(cn);oi.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var Ws=oi;var Ie=/*#__PURE__*/function(){function Ie(){_classCallCheck(this,Ie);}return _createClass(Ie,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(),Ie.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(),Ie.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:Ie.getObjectValue(s,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,n){var s=Ie.getObjectValue(t,n);if(s){var r=_objectSpread(_objectSpread({},s),Ie.getObjectValue(e,n)||{});Ie.setPropertyValue(e,n,r);}}},{key:"isJson",value:function isJson(e){try{return oe(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 Ko="<?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>",Di="<?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>",Z=/*#__PURE__*/function(_M6){function Z(e){var _l$model;var _this42;_classCallCheck(this,Z);var r,o,a,c,l;var t=w(e.directConnection),n=Z.getKey(e);_this42=_callSuper(this,Z,[e,Rn(),Tn,{key:n}]),_this42.insertKeyPlaceholderText=_this42.genereteAPIKeyName("OpenAI"),_this42.keyHelpUrl=Cn,_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)===F){_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=Z.buildAvatarConfig(s),_this42._buttonsConfig=Z.buildButtonsConfig(s),_this42._avatarEl=Z.createAvatar(_this42._avatarConfig),_this42._containerEl=_this42.createContainer(),_this42._deepChat=e;return _this42;}_inherits(Z,_M6);return _createClass(Z,[{key:"setInputAudioTranscribe",value:// https://community.openai.com/t/unable-to-access-user-audio-transcript-in-realtime-api/1001570/3
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&&ve.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&&ve.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)),gt.reassignClassBasedOnChildren(this.elementRef,e);}},{key:"buildDefaultIconElement",value:function buildDefaultIconElement(e){var t=this.svg.cloneNode(!0);return t.id=e,[t];}},{key:"createInnerElements",value:function createInnerElements(e,t,n){var s=gt.createCustomElements(t,this.svg,n);if(s&&s.length>0){if(this.position===Ze){var r=s[0].cloneNode(!0);r.id=s[0]===this.svg?e:"dropup-menu-item-icon-element-custom",s[0]=r;}return s;}return this.buildDefaultIconElement(e);}}]);}();var ai=/*#__PURE__*/function(_cn){function ai(e){var _this41;_classCallCheck(this,ai);var n,s;var t=((s=(n=e==null?void 0:e[A])==null?void 0:n.svg)==null?void 0:s.content)||ai.EMPTY_SVG;_this41=_callSuper(this,ai,[x(),t,void 0,void 0,e]),_this41.isActive=!1,_this41._innerElements=_this41.createInnerElementsForStates(_this41.customStyles),_this41.changeToDefault();return _this41;}_inherits(ai,_cn);return _createClass(ai,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty(_defineProperty(_defineProperty({},A,this.createInnerButtonElements(A,e)),U,this.createInnerButtonElements(U,e)),"unavailable",this.createInnerButtonElements("unavailable",e));}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return gt.createCustomElements(e,this.svg,t)||[this.svg];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef[m].replace(gt.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements[U]),this.reapplyStateStyle(U,["unavailable",A]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,n,s;this.changeState(this._innerElements[A]),(e=this.customStyles)!=null&&e[U]&&ve.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[U]),(n=this.customStyles)!=null&&n.unavailable&&ve.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s.unavailable),this.reapplyStateStyle(A,[U,"unavailable"]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,n,s;this.changeState(this._innerElements.unavailable),(e=this.customStyles)!=null&&e[U]&&ve.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[U]),(n=this.customStyles)!=null&&n[A]&&ve.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[A]),this.reapplyStateStyle("unavailable",[A,U]),this.isActive=!1;}}]);}(cn);ai.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var Xs=ai;var Ie=/*#__PURE__*/function(){function Ie(){_classCallCheck(this,Ie);}return _createClass(Ie,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(),Ie.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(),Ie.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:Ie.getObjectValue(s,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,n){var s=Ie.getObjectValue(t,n);if(s){var r=_objectSpread(_objectSpread({},s),Ie.getObjectValue(e,n)||{});Ie.setPropertyValue(e,n,r);}}},{key:"isJson",value:function isJson(e){try{return oe(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 Wo="<?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>",Fi="<?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>",Y=/*#__PURE__*/function(_M6){function Y(e){var _l$model;var _this42;_classCallCheck(this,Y);var r,o,a,c,l;var t=w(e.directConnection),n=Y.getKey(e);_this42=_callSuper(this,Y,[e,In(),Rn,{key:n}]),_this42.insertKeyPlaceholderText=_this42.genereteAPIKeyName("OpenAI"),_this42.keyHelpUrl=Tn,_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)===F){_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=Y.buildAvatarConfig(s),_this42._buttonsConfig=Y.buildButtonsConfig(s),_this42._avatarEl=Y.createAvatar(_this42._avatarConfig),_this42._containerEl=_this42.createContainer(),_this42._deepChat=e;return _this42;}_inherits(Y,_M6);return _createClass(Y,[{key:"setInputAudioTranscribe",value:// https://community.openai.com/t/unable-to-access-user-audio-transcript-in-realtime-api/1001570/3
173
173
  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(K,"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($e,"realtime/sessions"),{method:me,body:oe(this.rawBody),headers:_defineProperty(_defineProperty({},$,J),ce,"".concat(xe).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(oe(_defineProperty(_defineProperty({},I,"session.update"),"session",e)));},sendMessage:function sendMessage(e,t){var n=t||"system",s=[_defineProperty(_defineProperty({},I,n==="system"||n===D?Ni:h),"text",e)],r=_defineProperty(_defineProperty(_defineProperty({},S,n),I,"message"),"content",s);_this43.sendMessage(r);}};}},{key:"createContainer",value:function createContainer(){var e=x();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=x();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[v],(n=(t=this._avatarConfig)==null?void 0:t.styles)==null?void 0:n.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var s;var e=x();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=Z.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var n=Z.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 Ws((t=this._buttonsConfig)==null?void 0:t[it]);return e.elementRef[m].add(Z.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),q.assignButtonEvents(e.elementRef,function(){e.isActive?(_this44.toggleMicorphone(!0),e.elementRef[m].replace(Z.MICROPHONE_ACTIVE,Z.BUTTON_DEFAULT),e.changeToDefault(),_this44._isMuted=!1):(_this44.toggleMicorphone(!1),e.elementRef[m].replace(Z.BUTTON_DEFAULT,Z.MICROPHONE_ACTIVE),ue.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 Ws((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[m].add(Z.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),q.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=x(j);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,b,_,_t37;return _regenerator().w(function(_context97){while(1)switch(_context97.p=_context97.n){case 0:c=JSON.parse(a.data);if(!(c.type==="session.created")){_context97.n=1;break;}_this46.removeUnavailable(),_this46._toggleButton&&(ue.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(Ll)),_this46.hideLoading();_context97.n=7;break;case 1:if(!(c.type==="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.type)===Ps)){_context97.n=5;break;}b=g.name,_=g.call_id;_context97.p=2;_context97.n=3;return _this46.handleTool(b,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.type===f?_this46.stopOnError(c[f].message):c.type===et?_this46.stopOnError(c.message):c.type==="response.audio_transcript.delta"||(c.type==="response.audio_transcript.done"?c.transcript&&nn.onMessage(_this46._deepChat,_defineProperty(_defineProperty({},S,Q),h,c.transcript),!1):c.type==="conversation.item.input_audio_transcription.completed"&&c.transcript&&nn.onMessage(_this46._deepChat,_defineProperty(_defineProperty({},S,D),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($e,"realtime"),{method:me,body:a.sdp,headers:_defineProperty(_defineProperty({},ce,"".concat(xe).concat(e)),$,"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({},I,"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
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($e,"realtime/sessions"),{method:me,body:oe(this.rawBody),headers:_defineProperty(_defineProperty({},$,J),ce,"".concat(xe).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(oe(_defineProperty(_defineProperty({},I,"session.update"),"session",e)));},sendMessage:function sendMessage(e,t){var n=t||Sn,s=[_defineProperty(_defineProperty({},I,n===Sn||n===D?Bi:h),"text",e)],r=_defineProperty(_defineProperty(_defineProperty({},S,n),I,"message"),"content",s);_this43.sendMessage(r);}};}},{key:"createContainer",value:function createContainer(){var e=x();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=x();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[v],(n=(t=this._avatarConfig)==null?void 0:t.styles)==null?void 0:n.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var s;var e=x();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=Y.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var n=Y.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 Xs((t=this._buttonsConfig)==null?void 0:t[it]);return e.elementRef[m].add(Y.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),q.assignButtonEvents(e.elementRef,function(){e.isActive?(_this44.toggleMicorphone(!0),e.elementRef[m].replace(Y.MICROPHONE_ACTIVE,Y.BUTTON_DEFAULT),e.changeToDefault(),_this44._isMuted=!1):(_this44.toggleMicorphone(!1),e.elementRef[m].replace(Y.BUTTON_DEFAULT,Y.MICROPHONE_ACTIVE),ue.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 Xs((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[m].add(Y.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),q.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=x(j);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,b,_,_t37;return _regenerator().w(function(_context97){while(1)switch(_context97.p=_context97.n){case 0:c=JSON.parse(a.data);if(!(c.type==="session.created")){_context97.n=1;break;}_this46.removeUnavailable(),_this46._toggleButton&&(ue.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(Ol)),_this46.hideLoading();_context97.n=7;break;case 1:if(!(c.type==="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.type)===Ls)){_context97.n=5;break;}b=g.name,_=g.call_id;_context97.p=2;_context97.n=3;return _this46.handleTool(b,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.type===f?_this46.stopOnError(c[f].message):c.type===et?_this46.stopOnError(c.message):c.type==="response.audio_transcript.delta"||(c.type==="response.audio_transcript.done"?c.transcript&&nn.onMessage(_this46._deepChat,_defineProperty(_defineProperty({},S,Q),h,c.transcript),!1):c.type==="conversation.item.input_audio_transcription.completed"&&c.transcript&&nn.onMessage(_this46._deepChat,_defineProperty(_defineProperty({},S,D),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($e,"realtime"),{method:me,body:a.sdp,headers:_defineProperty(_defineProperty({},ce,"".concat(xe).concat(e)),$,"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({},I,"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
175
  // 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(Ol)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&Z.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&Z.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&Z.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&Z.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&Z.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&Z.removeButtonUnavailable(this._toggleButton);}},{key:"createError",value:function createError(){var t;var e=x();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=x();return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t[P]&&(this._loadingElement.innerHTML=this._loadingConfig[P]),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(Z.BUTTON_LOADING),ue.removeAriaDisabled(this._toggleButton.elementRef),ue.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[P]||(this._loadingElement.textContent=((n=this._loadingConfig)==null?void 0:n[h])||"Loading"));}},{key:"hideLoading",value:function hideLoading(){this._toggleButton&&(this._toggleButton.elementRef[m].remove(Z.BUTTON_LOADING),ue.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(Dt);case 1:_context99.n=2;return this._functionHandlerI({name:e,arguments:t});case 2:s=_context99.v;if(!(_typeof(s)!="object"||!Ie.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({},I,jo),"call_id",n),"output",oe(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=oe(_defineProperty(_defineProperty({},I,"conversation.item.create"),"item",e));this._dc.send(t);var n=_defineProperty({},I,"response.create");this._dc.send(oe(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?w(e.avatar):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$it,_o$A,_a$svg,_c$content,_t$toggle,_u$A,_g$svg,_b$content,_$U,_E$svg,_R$content;var n,s,r,o,a,c,l,d,p,u,g,b,_,E,R;var t=_typeof(e)=="object"&&e.buttons?w(e.buttons):{};return(r=(s=(n=t[it])==null?void 0:n[A])==null?void 0:s[h])!=null&&r.content||((_t$it=t[it])!==null&&_t$it!==void 0?_t$it:t[it]={},(_o$A=(o=t[it])[A])!==null&&_o$A!==void 0?_o$A:o[A]={},(_a$svg=(a=t[it][A]).svg)!==null&&_a$svg!==void 0?_a$svg:a.svg={},(_c$content=(c=t[it][A].svg).content)!==null&&_c$content!==void 0?_c$content:c.content=Vo),(p=(d=(l=t.toggle)==null?void 0:l[A])==null?void 0:d[h])!=null&&p.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_u$A=(u=t.toggle)[A])!==null&&_u$A!==void 0?_u$A:u[A]={},(_g$svg=(g=t.toggle[A]).svg)!==null&&_g$svg!==void 0?_g$svg:g.svg={},(_b$content=(b=t.toggle[A].svg).content)!==null&&_b$content!==void 0?_b$content:b.content=Ko,(_$U=(_=t.toggle)[U])!==null&&_$U!==void 0?_$U:_[U]={},(_E$svg=(E=t.toggle[U]).svg)!==null&&_E$svg!==void 0?_E$svg:E.svg={},(_R$content=(R=t.toggle[U].svg).content)!==null&&_R$content!==void 0?_R$content:R.content=Di),t;}},{key:"createAvatar",value:function createAvatar(e){var n;var t=x("img");return t.id="deep-chat-openai-realtime-avatar",Object.assign(t[v],(n=e==null?void 0:e.styles)==null?void 0:n[V]),t[C]=(e==null?void 0:e[C])||ki,t;}},{key:"createButtonContainer",value:function createButtonContainer(e){var t=x();return t[m].add("deep-chat-openai-realtime-button-container"),t.appendChild(e),t;}},{key:"changeButtonToUnavailable",value:function changeButtonToUnavailable(e){e.elementRef[m].add(Z.UNAVAILABLE),ue.removeAriaBusy(e.elementRef),ue.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){Z.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){ue.removeAriaDisabled(e.elementRef),e.elementRef[m].remove(Z.UNAVAILABLE);}}]);}(M);Z.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",Z.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",Z.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",Z.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var Fi=Z;var gn=/*#__PURE__*/function(_M7){function gn(e){var _o$model3,_a$voice3;var _this48;_classCallCheck(this,gn);var r,o,a;var t=w(e.directConnection),n=t==null?void 0:t.openAI;_this48=_callSuper(this,gn,[e,Rn(),Tn,n]),_this48.insertKeyPlaceholderText=_this48.genereteAPIKeyName("OpenAI"),_this48.keyHelpUrl=Cn,_this48.url="".concat($e,"audio/speech"),_this48.permittedErrorPrefixes=[Ft];var s=(r=t==null?void 0:t.openAI)==null?void 0:r.textToSpeech;_typeof(s)===F&&Object.assign(_this48.rawBody,s),(_o$model3=(o=_this48.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=gn.DEFAULT_MODEL,(_a$voice3=(a=_this48.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=gn.DEFAULT_VOIDE,_this48.textInputPlaceholderText="Insert text to generate audio",_this48.rawBody.response_format="mp3";return _this48;}_inherits(gn,_M7);return _createClass(gn,[{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=w(e),s=(o=(r=t[t.length-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({},y,[_defineProperty(_defineProperty({},C,s.target.result),I,j)]));};}));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;}()}]);}(M);gn.DEFAULT_MODEL="tts-1",gn.DEFAULT_VOIDE="alloy";var Ui=gn;var tt=/*#__PURE__*/function(_M8){function tt(e){var _o$model4;var _this49;_classCallCheck(this,tt);var r,o;var t=w(e.directConnection),n=t==null?void 0:t.openAI;_this49=_callSuper(this,tt,[e,Rn(),Tn,n,{audio:{}}]),_this49.insertKeyPlaceholderText=_this49.genereteAPIKeyName("OpenAI"),_this49.keyHelpUrl=Cn,_this49.url="",_this49.permittedErrorPrefixes=[Ft],_this49.textInputPlaceholderText=Ji,_this49._service_url=tt.AUDIO_TRANSCRIPTIONS_URL;var s=(r=t==null?void 0:t.openAI)==null?void 0:r[j];_typeof(s)=="object"&&(_this49.processConfig(s),tt.cleanConfig(s),Object.assign(_this49.rawBody,s)),(_o$model4=(o=_this49.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=tt.DEFAULT_MODEL,_this49.rawBody.response_format="json",_this49.canSendMessage=tt.canSendFileMessage;return _this49;}_inherits(tt,_M8);return _createClass(tt,[{key:"processConfig",value:function processConfig(e){e!=null&&e.type&&e.type==="translation"&&(this._service_url=tt.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=w(e),s=(o=(r=t[t.length-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(De);case 1:if(n!=null&&n[0]){_context102.n=2;break;}throw new Error(ci);case 2:this.url=this.connectSettings.url||this._service_url;s=this.preprocessBody(this.rawBody,t),r=tt.createFormDataBody(s,n[0]);B.tempRemoveContentHeader(this.connectSettings,pe.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.type;}},{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(ee,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}}]);}(M);tt.AUDIO_TRANSCRIPTIONS_URL="".concat($e,"audio/transcriptions"),tt.AUDIO_TRANSLATIONS_URL="".concat($e,"audio/translations"),tt.DEFAULT_MODEL="whisper-1";var Hi=tt;var In="Ocp-Apim-Subscription-Key",Wo=// 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",Nl=function Nl(i,e){return _defineProperty(_defineProperty(_defineProperty({},In,e),$,"application/ssml+xml"),"X-Microsoft-OutputFormat",i);},Bl=function Bl(i){return _defineProperty(_defineProperty({},In,i),"Accept",J);},Dl=function Dl(i,e,t,n){i[f]?n(de):t(e);},Fl=function Fl(i){return{url:"https://".concat(i,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:me,createHeaders:function createHeaders(e){return _defineProperty({},In,"".concat(e));},handleVerificationResult:Dl};},Ul=function Ul(i){return _defineProperty(_defineProperty({},In,i),$,J);},Hl=function Hl(i,e,t,n){var r;((r=i[f])==null?void 0:r.code)==="401"?n(de):t(e);},jl=function jl(i){return{url:"".concat(i,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:me,createHeaders:function createHeaders(e){return _defineProperty({},In,"".concat(e));},handleVerificationResult:Hl};},$l=function $l(i,e,t,n){i.json().then(function(r){!Array.isArray(r)&&r[f].code===401e3?n(de):t(e);});},ql=function ql(i){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:me,createHeaders:function createHeaders(e){return Xo(i,e);},handleVerificationResult:$l};},Xo=function Xo(i,e){var t=_defineProperty(_defineProperty({},In,e),$,J);return i&&(t["Ocp-Apim-Subscription-Region"]=i),t;};var Gl=/*#__PURE__*/function(_M9){// prettier-ignore
181
- function Gl(e,t,n,s,r){var _this50;_classCallCheck(this,Gl);_this50=_callSuper(this,Gl,[e,jl(n),t,s,r]),_this50.insertKeyPlaceholderText="Azure Language Subscription Key",_this50.keyHelpUrl=Wo,_this50.permittedErrorPrefixes=["Access"];return _this50;}_inherits(Gl,_M9);return _createClass(Gl);}(M);var ds=/*#__PURE__*/function(_Gl){function ds(e){var _a$language;var _this51;_classCallCheck(this,ds);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,ds,[e,Ul,t.endpoint,n]),_this51.permittedErrorPrefixes=[ds.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,ds.ENDPOINT_ERROR_MESSAGE));}));return _this51;}_inherits(ds,_Gl);return _createClass(ds,[{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:le,headers:(t=this.connectSettings)==null?void 0:t.headers};pe.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;}()}]);}(Gl);ds.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
182
- "Please define the azure endpoint. [More Information](".concat(K,"directConnection/Azure#Summarization)");var ji=ds;var zl=/*#__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({},_a,i),va,J);_t46="https://api.assemblyai.com/v2/transcript/";_context107.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:me,body:oe({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===Yi)){_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 zl(_x204,_x205){return _ref101.apply(this,arguments);};}(),Vl=function Vl(i){return _defineProperty(_defineProperty({},ce,i),$,"application/octet-stream");},Kl=function Kl(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(de):n(Be):t(e);},Wl=function Wl(){return fe("https://api.assemblyai.com/v2/upload",me,Kl);};var ar=/*#__PURE__*/function(_M0){function ar(e){var _this52;_classCallCheck(this,ar);var n;var t=(n=e.directConnection)==null?void 0:n.assemblyAI;_this52=_callSuper(this,ar,[e,Wl(),Vl,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=Ji,_this52.permittedErrorPrefixes=[Io,Ft],_this52.canSendMessage=ar.canFileSendMessage;return _this52;}_inherits(ar,_M0);return _createClass(ar,[{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(De);case 1:if(n!=null&&n[0]){_context108.n=2;break;}throw new Error(ci);case 2:pe.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[ce];_context109.n=2;return zl(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]);}}]);}(M);var Xs=/*#__PURE__*/function(_M1){// prettier-ignore
183
- function Xs(e,t,n,s,r){var _this53$maxMessages,_u$model;var _this53;_classCallCheck(this,Xs);var p,u;var o=w(e.directConnection),a=t||Rn(),c=n||Tn,l=s||o.openAI;_this53=_callSuper(this,Xs,[e,a,c,l]),_this53.insertKeyPlaceholderText=_this53.genereteAPIKeyName("OpenAI"),_this53.keyHelpUrl="https://platform.openai.com/account/api-keys",_this53.permittedErrorPrefixes=[Ss,"Invalid value"];var d=r||((p=o.openAI)==null?void 0:p.chat);_typeof(d)===F&&_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(Xs,_M1);return _createClass(Xs,[{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.type===j){var o=(n=t[C])==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({},I,Zt),Zt,{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[y]&&e[y].length>0){var s=this.getBaseFileContent(e[y]);return e[h]&&e[h].trim().length>0&&s.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),s;}return e[h];}}]);}(M);var Zs=/*#__PURE__*/function(_Xs){function Zs(){var _this54;_classCallCheck(this,Zs);_this54=_callSuper(this,Zs,arguments),_this54.url="".concat($e,"chat/completions");return _this54;}_inherits(Zs,_Xs);return _createClass(Zs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Zs.getContent(r)},S,M.getRoleViaUser(r[S]));});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[j])){_context111.n=4;break;}l=this.deepChat.textToSpeech,d=_typeof(l)=="object"&&typeof((c=l==null?void 0:l[j])==null?void 0:c.displayText)=="boolean";return _context111.a(2,_defineProperty(_defineProperty({},y,[_defineProperty(_defineProperty({},C,"data:audio/wav;base64,".concat(e.choices[0].message[j].data)),I,j)]),h,d?e.choices[0].message[j].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 Xs.getBaseFileContent(e).map(function(n){return n.type===Zt?n:_defineProperty(_defineProperty({},I,He),He,{url:n[C]});});}},{key:"getContent",value:function getContent(e){if(e[y]&&e[y].length>0){var t=Zs.getFileContent(e[y]);return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),t;}return e[h];}}]);}(Xs);var vr=/*#__PURE__*/function(_M10){// prettier-ignore
184
- function vr(e,t,n,s,r){var _this55;_classCallCheck(this,vr);_this55=_callSuper(this,vr,[e,Fl(n),t,s,r]),_this55.insertKeyPlaceholderText="Azure Speech Subscription Key",_this55.keyHelpUrl=Wo;return _this55;}_inherits(vr,_M10);return _createClass(vr);}(M);vr.REGION_ERROR_PREFIX="Please define a region config property. [More Information](".concat(K,"directConnection/Azure#");var xn=vr;var hs=/*#__PURE__*/function(_xn){// prettier-ignore
185
- function hs(e){var _a$lang,_c$name,_l$gender;var _this56;_classCallCheck(this,hs);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,hs,[e,Nl.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,n]),_this56.permittedErrorPrefixes=[hs.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,hs.REGION_ERROR_MESSAGE));}));return _this56;}_inherits(hs,_xn);return _createClass(hs,[{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({},y,[_defineProperty(_defineProperty({},C,s.target.result),I,j)]));};}));}},_callee114);}));function extractResultData(_x218){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}]);}(xn);hs.REGION_ERROR_MESSAGE="".concat(xn.REGION_ERROR_PREFIX,"TextToSpeech)");var $i=hs;var yn=/*#__PURE__*/function(_xn2){function yn(e){var _this57;_classCallCheck(this,yn);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({},y,{acceptedFormats:".wav,.ogg"})};if(_this57=_callSuper(this,yn,[e,Bl,t.region,n,s]),_this57.permittedErrorPrefixes=[yn.REGION_ERROR_MESSAGE],_this57.url="",_this57.isTextInputDisabled=!0,_this57.textInputPlaceholderText=Ji,!t.region)_this57.isTextInputDisabled=!0,_this57.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,yn.REGION_ERROR_MESSAGE));});else{_this57.canSendMessage=yn.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(yn,_xn2);return _createClass(yn,[{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(De);case 1:if(n!=null&&n[0]){_context115.n=2;break;}throw new Error(ci);case 2:(r=this.connectSettings)!=null&&r.headers&&(this.connectSettings.headers[$]=n[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),pe.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]);}}]);}(xn);yn.REGION_ERROR_MESSAGE="".concat(xn.REGION_ERROR_PREFIX,"SpeechToText)");var qi=yn;var Xl=/*#__PURE__*/function(_M11){// prettier-ignore
186
- function Xl(e){var _this58;_classCallCheck(this,Xl);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,Xl,[e,ql(t.region),Xo.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(Xl,_M11);return _createClass(Xl,[{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;}()}]);}(M);var Zl=/*#__PURE__*/function(_M12){function Zl(e){var _o$model5;var _this59;_classCallCheck(this,Zl);var r,o;var t=w(e.directConnection),n=t.bigModel;_this59=_callSuper(this,Zl,[e,sr(),nr,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=[ce,Ae];var s=(r=t.bigModel)==null?void 0:r[Y];_typeof(s)===F&&(_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(Zl,_M12);return _createClass(Zl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},C,n.url),I,V):_defineProperty(_defineProperty({},C,""),I,V);});return _context120.a(2,_defineProperty({},y,t));}},_callee120);}));function extractResultData(_x228){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(M);var Zo=function Zo(i){return _defineProperty(_defineProperty({},$,J),ce,"".concat(xe).concat(i));},Yl=function Yl(i,e,t,n){var s=i;s[f]?s[f].message===li?n(de):n(Be):t(e);},Yo=function Yo(){return fe("https://api.groq.com/openai/v1/models",le,Yl);};var Jl=/*#__PURE__*/function(_M13){function Jl(e){var _o$model6,_a$voice4,_c$response_format;var _this60;_classCallCheck(this,Jl);var r,o,a,c;var t=w(e.directConnection),n=t.groq;_this60=_callSuper(this,Jl,[e,Yo(),Zo,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=[Ft,"property"];var s=(r=t.groq)==null?void 0:r.textToSpeech;_typeof(s)===F&&_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(Jl,_M13);return _createClass(Jl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},I,"audio/".concat(t))),s=URL.createObjectURL(n);return _context122.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},C,s),I,j)]));}},_callee122,this);}));function extractResultData(_x231){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ql=/*#__PURE__*/function(_M14){function Ql(e){var _o$model7;var _this61;_classCallCheck(this,Ql);var r,o;var t=w(e.directConnection),n=t.together;_this61=_callSuper(this,Ql,[e,rr(),ir,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=[et,Ae];var s=(r=t.together)==null?void 0:r[Y];_typeof(s)===F&&_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(Ql,_M14);return _createClass(Ql,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},C,n.url),I,V):n!=null&&n.b64_json?_defineProperty(_defineProperty({},C,"data:image/png;base64,".concat(n.b64_json)),I,V):_defineProperty(_defineProperty({},C,""),I,V);});return _context124.a(2,_defineProperty({},y,t));}},_callee124);}));function extractResultData(_x234){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ze=/*#__PURE__*/function(_Xs2){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
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(Nl)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&Y.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&Y.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&Y.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&Y.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&Y.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&Y.removeButtonUnavailable(this._toggleButton);}},{key:"createError",value:function createError(){var t;var e=x();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=x();return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t[P]&&(this._loadingElement.innerHTML=this._loadingConfig[P]),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(Y.BUTTON_LOADING),ue.removeAriaDisabled(this._toggleButton.elementRef),ue.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[P]||(this._loadingElement.textContent=((n=this._loadingConfig)==null?void 0:n[h])||"Loading"));}},{key:"hideLoading",value:function hideLoading(){this._toggleButton&&(this._toggleButton.elementRef[m].remove(Y.BUTTON_LOADING),ue.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(Dt);case 1:_context99.n=2;return this._functionHandlerI({name:e,arguments:t});case 2:s=_context99.v;if(!(_typeof(s)!="object"||!Ie.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({},I,$o),"call_id",n),"output",oe(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=oe(_defineProperty(_defineProperty({},I,"conversation.item.create"),"item",e));this._dc.send(t);var n=_defineProperty({},I,"response.create");this._dc.send(oe(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?w(e.avatar):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$it,_o$A,_a$svg,_c$content,_t$toggle,_u$A,_g$svg,_b$content,_$U,_E$svg,_R$content;var n,s,r,o,a,c,l,d,p,u,g,b,_,E,R;var t=_typeof(e)=="object"&&e.buttons?w(e.buttons):{};return(r=(s=(n=t[it])==null?void 0:n[A])==null?void 0:s[h])!=null&&r.content||((_t$it=t[it])!==null&&_t$it!==void 0?_t$it:t[it]={},(_o$A=(o=t[it])[A])!==null&&_o$A!==void 0?_o$A:o[A]={},(_a$svg=(a=t[it][A]).svg)!==null&&_a$svg!==void 0?_a$svg:a.svg={},(_c$content=(c=t[it][A].svg).content)!==null&&_c$content!==void 0?_c$content:c.content=Ko),(p=(d=(l=t.toggle)==null?void 0:l[A])==null?void 0:d[h])!=null&&p.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_u$A=(u=t.toggle)[A])!==null&&_u$A!==void 0?_u$A:u[A]={},(_g$svg=(g=t.toggle[A]).svg)!==null&&_g$svg!==void 0?_g$svg:g.svg={},(_b$content=(b=t.toggle[A].svg).content)!==null&&_b$content!==void 0?_b$content:b.content=Wo,(_$U=(_=t.toggle)[U])!==null&&_$U!==void 0?_$U:_[U]={},(_E$svg=(E=t.toggle[U]).svg)!==null&&_E$svg!==void 0?_E$svg:E.svg={},(_R$content=(R=t.toggle[U].svg).content)!==null&&_R$content!==void 0?_R$content:R.content=Fi),t;}},{key:"createAvatar",value:function createAvatar(e){var n;var t=x("img");return t.id="deep-chat-openai-realtime-avatar",Object.assign(t[v],(n=e==null?void 0:e.styles)==null?void 0:n[V]),t[C]=(e==null?void 0:e[C])||Pi,t;}},{key:"createButtonContainer",value:function createButtonContainer(e){var t=x();return t[m].add("deep-chat-openai-realtime-button-container"),t.appendChild(e),t;}},{key:"changeButtonToUnavailable",value:function changeButtonToUnavailable(e){e.elementRef[m].add(Y.UNAVAILABLE),ue.removeAriaBusy(e.elementRef),ue.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){Y.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){ue.removeAriaDisabled(e.elementRef),e.elementRef[m].remove(Y.UNAVAILABLE);}}]);}(M);Y.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",Y.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",Y.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",Y.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var Ui=Y;var gn=/*#__PURE__*/function(_M7){function gn(e){var _o$model3,_a$voice3;var _this48;_classCallCheck(this,gn);var r,o,a;var t=w(e.directConnection),n=t==null?void 0:t.openAI;_this48=_callSuper(this,gn,[e,In(),Rn,n]),_this48.insertKeyPlaceholderText=_this48.genereteAPIKeyName("OpenAI"),_this48.keyHelpUrl=Tn,_this48.url="".concat($e,"audio/speech"),_this48.permittedErrorPrefixes=[Ft];var s=(r=t==null?void 0:t.openAI)==null?void 0:r.textToSpeech;_typeof(s)===F&&Object.assign(_this48.rawBody,s),(_o$model3=(o=_this48.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=gn.DEFAULT_MODEL,(_a$voice3=(a=_this48.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=gn.DEFAULT_VOIDE,_this48.textInputPlaceholderText="Insert text to generate audio",_this48.rawBody.response_format="mp3";return _this48;}_inherits(gn,_M7);return _createClass(gn,[{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=w(e),s=(o=(r=t[t.length-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({},y,[_defineProperty(_defineProperty({},C,s.target.result),I,j)]));};}));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;}()}]);}(M);gn.DEFAULT_MODEL="tts-1",gn.DEFAULT_VOIDE="alloy";var Hi=gn;var tt=/*#__PURE__*/function(_M8){function tt(e){var _o$model4;var _this49;_classCallCheck(this,tt);var r,o;var t=w(e.directConnection),n=t==null?void 0:t.openAI;_this49=_callSuper(this,tt,[e,In(),Rn,n,{audio:{}}]),_this49.insertKeyPlaceholderText=_this49.genereteAPIKeyName("OpenAI"),_this49.keyHelpUrl=Tn,_this49.url="",_this49.permittedErrorPrefixes=[Ft],_this49.textInputPlaceholderText=Qi,_this49._service_url=tt.AUDIO_TRANSCRIPTIONS_URL;var s=(r=t==null?void 0:t.openAI)==null?void 0:r[j];_typeof(s)=="object"&&(_this49.processConfig(s),tt.cleanConfig(s),Object.assign(_this49.rawBody,s)),(_o$model4=(o=_this49.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=tt.DEFAULT_MODEL,_this49.rawBody.response_format="json",_this49.canSendMessage=tt.canSendFileMessage;return _this49;}_inherits(tt,_M8);return _createClass(tt,[{key:"processConfig",value:function processConfig(e){e!=null&&e.type&&e.type==="translation"&&(this._service_url=tt.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=w(e),s=(o=(r=t[t.length-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(De);case 1:if(n!=null&&n[0]){_context102.n=2;break;}throw new Error(li);case 2:this.url=this.connectSettings.url||this._service_url;s=this.preprocessBody(this.rawBody,t),r=tt.createFormDataBody(s,n[0]);B.tempRemoveContentHeader(this.connectSettings,pe.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.type;}},{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(ee,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}}]);}(M);tt.AUDIO_TRANSCRIPTIONS_URL="".concat($e,"audio/transcriptions"),tt.AUDIO_TRANSLATIONS_URL="".concat($e,"audio/translations"),tt.DEFAULT_MODEL="whisper-1";var ji=tt;var Mn="Ocp-Apim-Subscription-Key",Xo=// 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",Bl=function Bl(i,e){return _defineProperty(_defineProperty(_defineProperty({},Mn,e),$,"application/ssml+xml"),"X-Microsoft-OutputFormat",i);},Dl=function Dl(i){return _defineProperty(_defineProperty({},Mn,i),"Accept",J);},Fl=function Fl(i,e,t,n){i[f]?n(de):t(e);},Ul=function Ul(i){return{url:"https://".concat(i,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:me,createHeaders:function createHeaders(e){return _defineProperty({},Mn,"".concat(e));},handleVerificationResult:Fl};},Hl=function Hl(i){return _defineProperty(_defineProperty({},Mn,i),$,J);},jl=function jl(i,e,t,n){var r;((r=i[f])==null?void 0:r.code)==="401"?n(de):t(e);},$l=function $l(i){return{url:"".concat(i,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:me,createHeaders:function createHeaders(e){return _defineProperty({},Mn,"".concat(e));},handleVerificationResult:jl};},ql=function ql(i,e,t,n){i.json().then(function(r){!Array.isArray(r)&&r[f].code===401e3?n(de):t(e);});},Gl=function Gl(i){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:me,createHeaders:function createHeaders(e){return Yo(i,e);},handleVerificationResult:ql};},Yo=function Yo(i,e){var t=_defineProperty(_defineProperty({},Mn,e),$,J);return i&&(t["Ocp-Apim-Subscription-Region"]=i),t;};var zl=/*#__PURE__*/function(_M9){// prettier-ignore
181
+ function zl(e,t,n,s,r){var _this50;_classCallCheck(this,zl);_this50=_callSuper(this,zl,[e,$l(n),t,s,r]),_this50.insertKeyPlaceholderText="Azure Language Subscription Key",_this50.keyHelpUrl=Xo,_this50.permittedErrorPrefixes=["Access"];return _this50;}_inherits(zl,_M9);return _createClass(zl);}(M);var hs=/*#__PURE__*/function(_zl){function hs(e){var _a$language;var _this51;_classCallCheck(this,hs);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,hs,[e,Hl,t.endpoint,n]),_this51.permittedErrorPrefixes=[hs.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,hs.ENDPOINT_ERROR_MESSAGE));}));return _this51;}_inherits(hs,_zl);return _createClass(hs,[{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:le,headers:(t=this.connectSettings)==null?void 0:t.headers};pe.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;}()}]);}(zl);hs.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
182
+ "Please define the azure endpoint. [More Information](".concat(K,"directConnection/Azure#Summarization)");var $i=hs;var Vl=/*#__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({},va,i),Ea,J);_t46="https://api.assemblyai.com/v2/transcript/";_context107.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:me,body:oe({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===Ji)){_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 Vl(_x204,_x205){return _ref101.apply(this,arguments);};}(),Kl=function Kl(i){return _defineProperty(_defineProperty({},ce,i),$,"application/octet-stream");},Wl=function Wl(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(de):n(Be):t(e);},Xl=function Xl(){return fe("https://api.assemblyai.com/v2/upload",me,Wl);};var cr=/*#__PURE__*/function(_M0){function cr(e){var _this52;_classCallCheck(this,cr);var n;var t=(n=e.directConnection)==null?void 0:n.assemblyAI;_this52=_callSuper(this,cr,[e,Xl(),Kl,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=Qi,_this52.permittedErrorPrefixes=[Mo,Ft],_this52.canSendMessage=cr.canFileSendMessage;return _this52;}_inherits(cr,_M0);return _createClass(cr,[{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(De);case 1:if(n!=null&&n[0]){_context108.n=2;break;}throw new Error(li);case 2:pe.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[ce];_context109.n=2;return Vl(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]);}}]);}(M);var Ys=/*#__PURE__*/function(_M1){// prettier-ignore
183
+ function Ys(e,t,n,s,r){var _this53$maxMessages,_u$model;var _this53;_classCallCheck(this,Ys);var p,u;var o=w(e.directConnection),a=t||In(),c=n||Rn,l=s||o.openAI;_this53=_callSuper(this,Ys,[e,a,c,l]),_this53.insertKeyPlaceholderText=_this53.genereteAPIKeyName("OpenAI"),_this53.keyHelpUrl="https://platform.openai.com/account/api-keys",_this53.permittedErrorPrefixes=[xs,"Invalid value"];var d=r||((p=o.openAI)==null?void 0:p.chat);_typeof(d)===F&&_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(Ys,_M1);return _createClass(Ys,[{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.type===j){var o=(n=t[C])==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({},I,Yt),Yt,{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[y]&&e[y].length>0){var s=this.getBaseFileContent(e[y]);return e[h]&&e[h].trim().length>0&&s.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),s;}return e[h];}}]);}(M);var Zs=/*#__PURE__*/function(_Ys){function Zs(){var _this54;_classCallCheck(this,Zs);_this54=_callSuper(this,Zs,arguments),_this54.url="".concat($e,"chat/completions");return _this54;}_inherits(Zs,_Ys);return _createClass(Zs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Zs.getContent(r)},S,M.getRoleViaUser(r[S]));});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[j])){_context111.n=4;break;}l=this.deepChat.textToSpeech,d=_typeof(l)=="object"&&typeof((c=l==null?void 0:l[j])==null?void 0:c.displayText)=="boolean";return _context111.a(2,_defineProperty(_defineProperty({},y,[_defineProperty(_defineProperty({},C,"data:audio/wav;base64,".concat(e.choices[0].message[j].data)),I,j)]),h,d?e.choices[0].message[j].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 Ys.getBaseFileContent(e).map(function(n){return n.type===Yt?n:_defineProperty(_defineProperty({},I,He),He,{url:n[C]});});}},{key:"getContent",value:function getContent(e){if(e[y]&&e[y].length>0){var t=Zs.getFileContent(e[y]);return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),t;}return e[h];}}]);}(Ys);var Er=/*#__PURE__*/function(_M10){// prettier-ignore
184
+ function Er(e,t,n,s,r){var _this55;_classCallCheck(this,Er);_this55=_callSuper(this,Er,[e,Ul(n),t,s,r]),_this55.insertKeyPlaceholderText="Azure Speech Subscription Key",_this55.keyHelpUrl=Xo;return _this55;}_inherits(Er,_M10);return _createClass(Er);}(M);Er.REGION_ERROR_PREFIX="Please define a region config property. [More Information](".concat(K,"directConnection/Azure#");var An=Er;var us=/*#__PURE__*/function(_An){// prettier-ignore
185
+ function us(e){var _a$lang,_c$name,_l$gender;var _this56;_classCallCheck(this,us);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,us,[e,Bl.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,n]),_this56.permittedErrorPrefixes=[us.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,us.REGION_ERROR_MESSAGE));}));return _this56;}_inherits(us,_An);return _createClass(us,[{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({},y,[_defineProperty(_defineProperty({},C,s.target.result),I,j)]));};}));}},_callee114);}));function extractResultData(_x218){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}]);}(An);us.REGION_ERROR_MESSAGE="".concat(An.REGION_ERROR_PREFIX,"TextToSpeech)");var qi=us;var yn=/*#__PURE__*/function(_An2){function yn(e){var _this57;_classCallCheck(this,yn);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({},y,{acceptedFormats:".wav,.ogg"})};if(_this57=_callSuper(this,yn,[e,Dl,t.region,n,s]),_this57.permittedErrorPrefixes=[yn.REGION_ERROR_MESSAGE],_this57.url="",_this57.isTextInputDisabled=!0,_this57.textInputPlaceholderText=Qi,!t.region)_this57.isTextInputDisabled=!0,_this57.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,yn.REGION_ERROR_MESSAGE));});else{_this57.canSendMessage=yn.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(yn,_An2);return _createClass(yn,[{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(De);case 1:if(n!=null&&n[0]){_context115.n=2;break;}throw new Error(li);case 2:(r=this.connectSettings)!=null&&r.headers&&(this.connectSettings.headers[$]=n[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),pe.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]);}}]);}(An);yn.REGION_ERROR_MESSAGE="".concat(An.REGION_ERROR_PREFIX,"SpeechToText)");var Gi=yn;var Yl=/*#__PURE__*/function(_M11){// prettier-ignore
186
+ function Yl(e){var _this58;_classCallCheck(this,Yl);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,Yl,[e,Gl(t.region),Yo.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(Yl,_M11);return _createClass(Yl,[{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;}()}]);}(M);var Zl=/*#__PURE__*/function(_M12){function Zl(e){var _o$model5;var _this59;_classCallCheck(this,Zl);var r,o;var t=w(e.directConnection),n=t.bigModel;_this59=_callSuper(this,Zl,[e,ir(),sr,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=[ce,Ae];var s=(r=t.bigModel)==null?void 0:r[Z];_typeof(s)===F&&(_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(Zl,_M12);return _createClass(Zl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},C,n.url),I,V):_defineProperty(_defineProperty({},C,""),I,V);});return _context120.a(2,_defineProperty({},y,t));}},_callee120);}));function extractResultData(_x228){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(M);var Zo=function Zo(i){return _defineProperty(_defineProperty({},$,J),ce,"".concat(xe).concat(i));},Jl=function Jl(i,e,t,n){var s=i;s[f]?s[f].message===di?n(de):n(Be):t(e);},Jo=function Jo(){return fe("https://api.groq.com/openai/v1/models",le,Jl);};var Ql=/*#__PURE__*/function(_M13){function Ql(e){var _o$model6,_a$voice4,_c$response_format;var _this60;_classCallCheck(this,Ql);var r,o,a,c;var t=w(e.directConnection),n=t.groq;_this60=_callSuper(this,Ql,[e,Jo(),Zo,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=[Ft,"property"];var s=(r=t.groq)==null?void 0:r.textToSpeech;_typeof(s)===F&&_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(Ql,_M13);return _createClass(Ql,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},I,"audio/".concat(t))),s=URL.createObjectURL(n);return _context122.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},C,s),I,j)]));}},_callee122,this);}));function extractResultData(_x231){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(M);var ed=/*#__PURE__*/function(_M14){function ed(e){var _o$model7;var _this61;_classCallCheck(this,ed);var r,o;var t=w(e.directConnection),n=t.together;_this61=_callSuper(this,ed,[e,or(),rr,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=[et,Ae];var s=(r=t.together)==null?void 0:r[Z];_typeof(s)===F&&_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(ed,_M14);return _createClass(ed,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(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({},C,n.url),I,V):n!=null&&n.b64_json?_defineProperty(_defineProperty({},C,"data:image/png;base64,".concat(n.b64_json)),I,V):_defineProperty(_defineProperty({},C,""),I,V);});return _context124.a(2,_defineProperty({},y,t));}},_callee124);}));function extractResultData(_x234){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ye=/*#__PURE__*/function(_Ys2){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
188
188
  // prettier-ignore
189
- function Ze(e,t,n,s,r){var _this62;_classCallCheck(this,Ze);var a,c;_this62=_callSuper(this,Ze,[e,t,n,s,r]),_this62.keyHelpUrl=Cn,_this62.url="".concat($e,"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);_typeof(o)===F&&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(Ze,_Xs2);return _createClass(Ze,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Ze,"processConfig",this,3)([e,t]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.conversation,delete e.conversationLoadLimit;}},{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(){var _this63=this;var e,t,_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;this.url="".concat($e,"conversations/").concat(this._conversationId,"/items?limit=").concat(this._conversationLoadLimit);_context125.n=2;return Nt(this,{},le);case 2:t=_context125.v;return _context125.a(2,(this.connectSettings.method=me,this.url=e,this.deepChat.disableSubmitButton(!1),this.processConversationHistory(t)));case 3:_context125.p=3;_t48=_context125.v;return _context125.a(2,(this.deepChat.disableSubmitButton(!1),[_defineProperty({},f,Ro)]));}},_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(Ze.filterCompleted(e.data.reverse())),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _n8=_step2.value;if(_n8.type==="message"&&_n8.content&&Array.isArray(_n8.content)){var _iterator3=_createForOfIteratorHelper(_n8.content),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var s=_step3.value;(s.type===Ni||s.type===Vr)&&s[h]?t.push(_defineProperty(_defineProperty({},S,_n8[S]),h,s[h])):s.type===zr&&t.push(_defineProperty(_defineProperty({},S,_n8[S]),y,Ze.generateImageFile(s[He]||"")));}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}else _n8.type===Ci&&t.push(_defineProperty(_defineProperty({},S,Q),y,Ze.generateImageFile(_n8.result)));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e);t=this.processMessages(t),t=this._useConversation?[t[t.length-1]]:t;var s=t.map(function(r){return _defineProperty({content:Ze.getContent(r)},S,M.getRoleViaUser(r[S]));});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="".concat($e,"conversations");_context126.n=1;return Nt(this,{},me);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=Ze.filterCompleted(e.output);if(!(a.length>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])===ye;}))==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.type)===Ps&&e.type?this.handleStreamedResponsesFunctionCall(e,t):e.type==="".concat(Mn,".").concat(Ci,".partial_image")&&e.partial_image_b64?_defineProperty({},y,[_defineProperty(_defineProperty({},C,"".concat(Ze.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),I,V)]):e.delta&&!this._functionStreamInProgress&&e.type==="".concat(Mn,".").concat(Vr,".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.type==="".concat(Mn,".output_item.done"))){_context130.n=2;break;}if(!(this._functionStreamInProgress=!1,((n=e.item)==null?void 0:n.type)===Ps)){_context130.n=1;break;}return _context130.a(2,this.handleResponsesFunctionCalls([e.item],t));case 1:_context130.n=3;break;case 2:e.type==="".concat(Mn,".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.type===Ci;});return n?_defineProperty(_defineProperty({},y,Ze.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.type===Ps;});if(!(s.length===0)){_context131.n=1;break;}return _context131.a(2,null);case 1:if(!(!t||!this.functionHandler)){_context131.n=2;break;}throw Error(Dt);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=w(t);if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref134){var l=_ref134.response;return _typeof(l)!==ye;})&&r.length===o.length))){_context131.n=5;break;}return _context131.a(2,(o.forEach(function(l,d){var p=s[d];c.input.push({type:jo,call_id:p.call_id,output:l[Mn]});}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(Qt);case 6:return _context131.a(2);}},_callee131,this);}));function handleResponsesFunctionCalls(_x243,_x244,_x245){return _handleResponsesFunctionCalls.apply(this,arguments);}return handleResponsesFunctionCalls;}()}],[{key:"getFileContent",value:function getFileContent(e){return Xs.getBaseFileContent(e).map(function(n){return n.type===Zt?n:_defineProperty(_defineProperty({detail:"auto"},I,zr),He,n[C]);});}},{key:"getContent",value:function getContent(e){if(e[S]===D&&e[y]&&e[y].length>0){var _n9=Ze.getFileContent(e[y]);return e[h]&&e[h].trim().length>0&&_n9.unshift(_defineProperty(_defineProperty({},I,Ni),h,e[h])),_n9;}return e[h];}},{key:"filterCompleted",value:function filterCompleted(e){return(e==null?void 0:e.filter(function(t){return t.status===Yi;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},C,"".concat(Ze.IMAGE_BASE64_PREFIX).concat(e)),I,V)];}}]);}(Xs);Ze.IMAGE_BASE64_PREFIX="data:image/png;base64,";var Ys=Ze;var cr=/*#__PURE__*/function(_Ys){function cr(e){var _this64;_classCallCheck(this,cr);var o,a,c,l,d,p,u;var t=w(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,cr,[e,Go(s),qo,n,r]),_this64.permittedErrorPrefixes=[Ks],_this64.isTextInputDisabled=!1,_typeof(r)===F){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);}zo(s)?_this64.url=cr.buildURL(s):(_this64.isTextInputDisabled=!0,_this64.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,Ks));}));return _this64;}_inherits(cr,_Ys);return _createClass(cr,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);}}]);}(Ys);var Js=/*#__PURE__*/function(_M15){function Js(e){var _this65$maxMessages,_l$model2;var _this65;_classCallCheck(this,Js);var r,o,a,c,l;var t=w(e.directConnection),n=t.bigModel;_this65=_callSuper(this,Js,[e,sr(),nr,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=[ce,Ae];var s=(r=t.bigModel)==null?void 0:r.chat;_typeof(s)===F&&_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(Js,_M15);return _createClass(Js,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Js.getTextWFilesContent(r,Js.getFileContent)},S,M.getRoleViaAI(r[S]));});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 _n0;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;}_n0=e.choices[0].message;return _context133.a(2,_n0.tool_calls?this.handleToolsGeneric({tool_calls:_n0.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n0.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][S])===Q&&((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.type===V?_defineProperty(_defineProperty({},I,He),He,{url:t[C]||""}):_defineProperty(_defineProperty({},I,ee),"file_url",{url:t[C]||""});});}}]);}(M);var ed=/*#__PURE__*/function(_M16){function ed(e){var _this66$maxMessages,_o$model8;var _this66;_classCallCheck(this,ed);var r,o;var t=w(e.directConnection),n=t.together;_this66=_callSuper(this,ed,[e,rr(),ir,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=[et,Ae];var s=(r=t.together)==null?void 0:r.chat;_typeof(s)===F&&_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(ed,_M16);return _createClass(ed,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,r[S]===Q?ut:r[S]);});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;}()}]);}(M);var nt=/*#__PURE__*/function(_M17){function nt(e){var _this67;_classCallCheck(this,nt);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:2})};_this67=_callSuper(this,nt,[e,Rn(),Tn,n,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenAI"),_this67.keyHelpUrl=Cn,_this67.url="",_this67.permittedErrorPrefixes=[Ss,"Invalid input image"];var r=(o=t==null?void 0:t.openAI)==null?void 0:o[Y];if(_this67[Ne]){var a=_typeof(r)=="object"&&r.size?Number.parseInt(r.size):1024;_this67[Ne][y]={dimensions:{width:a,height:a}};}_typeof(r)===F&&Object.assign(_this67.rawBody,r),_this67.canSendMessage=nt.canFileSendMessage;return _this67;}_inherits(nt,_M17);return _createClass(nt,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e);return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
190
- },{key:"callApiWithImage",value:function callApiWithImage(e,t,n){var o,a;var s;var r=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim();if(n[1]||r&&r!==""){this.url=nt.IMAGE_EDIT_URL;var c=this.preprocessBody(this.rawBody,r);s=nt.createFormDataBody(c,n[0],n[1]);}else this.url=nt.IMAGE_VARIATIONS_URL,s=nt.createFormDataBody(this.rawBody,n[0]);B.tempRemoveContentHeader(this.connectSettings,pe.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(De);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(De);case 3:this.url=nt.IMAGE_GENERATION_URL;r=this.preprocessBody(this.rawBody,t[t.length-1][h]);pe.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({},C,n.url),I,V):_defineProperty(_defineProperty({},C,"".concat(wn).concat(n.b64_json)),I,V);});return _context138.a(2,_defineProperty({},y,t));}},_callee138);}));function extractResultData(_x258){return _extractResultData27.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
189
+ function Ye(e,t,n,s,r){var _this62;_classCallCheck(this,Ye);var a,c;_this62=_callSuper(this,Ye,[e,t,n,s,r]),_this62.keyHelpUrl=Tn,_this62.url="".concat($e,"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);_typeof(o)===F&&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(Ye,_Ys2);return _createClass(Ye,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Ye,"processConfig",this,3)([e,t]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.conversation,delete e.conversationLoadLimit;}},{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(){var _this63=this;var e,t,_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;this.url="".concat($e,"conversations/").concat(this._conversationId,"/items?limit=").concat(this._conversationLoadLimit);_context125.n=2;return Nt(this,{},le);case 2:t=_context125.v;return _context125.a(2,(this.connectSettings.method=me,this.url=e,this.deepChat.disableSubmitButton(!1),this.processConversationHistory(t)));case 3:_context125.p=3;_t48=_context125.v;return _context125.a(2,(this.deepChat.disableSubmitButton(!1),[_defineProperty({},f,Io)]));}},_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(Ye.filterCompleted(e.data.reverse())),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _n8=_step2.value;if(_n8.type==="message"&&_n8.content&&Array.isArray(_n8.content)){var _iterator3=_createForOfIteratorHelper(_n8.content),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var s=_step3.value;(s.type===Bi||s.type===Kr)&&s[h]?t.push(_defineProperty(_defineProperty({},S,_n8[S]),h,s[h])):s.type===Vr&&t.push(_defineProperty(_defineProperty({},S,_n8[S]),y,Ye.generateImageFile(s[He]||"")));}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}else _n8.type===Ti&&t.push(_defineProperty(_defineProperty({},S,Q),y,Ye.generateImageFile(_n8.result)));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e);t=this.processMessages(t),t=this._useConversation?[t[t.length-1]]:t;var s=t.map(function(r){return _defineProperty({content:Ye.getContent(r)},S,M.getRoleViaUser(r[S]));});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="".concat($e,"conversations");_context126.n=1;return Nt(this,{},me);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=Ye.filterCompleted(e.output);if(!(a.length>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])===ye;}))==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.type)===Ls&&e.type?this.handleStreamedResponsesFunctionCall(e,t):e.type==="".concat(kn,".").concat(Ti,".partial_image")&&e.partial_image_b64?_defineProperty({},y,[_defineProperty(_defineProperty({},C,"".concat(Ye.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),I,V)]):e.delta&&!this._functionStreamInProgress&&e.type==="".concat(kn,".").concat(Kr,".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.type==="".concat(kn,".output_item.done"))){_context130.n=2;break;}if(!(this._functionStreamInProgress=!1,((n=e.item)==null?void 0:n.type)===Ls)){_context130.n=1;break;}return _context130.a(2,this.handleResponsesFunctionCalls([e.item],t));case 1:_context130.n=3;break;case 2:e.type==="".concat(kn,".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.type===Ti;});return n?_defineProperty(_defineProperty({},y,Ye.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.type===Ls;});if(!(s.length===0)){_context131.n=1;break;}return _context131.a(2,null);case 1:if(!(!t||!this.functionHandler)){_context131.n=2;break;}throw Error(Dt);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=w(t);if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref134){var l=_ref134.response;return _typeof(l)!==ye;})&&r.length===o.length))){_context131.n=5;break;}return _context131.a(2,(o.forEach(function(l,d){var p=s[d];c.input.push({type:$o,call_id:p.call_id,output:l[kn]});}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(Qt);case 6:return _context131.a(2);}},_callee131,this);}));function handleResponsesFunctionCalls(_x243,_x244,_x245){return _handleResponsesFunctionCalls.apply(this,arguments);}return handleResponsesFunctionCalls;}()}],[{key:"getFileContent",value:function getFileContent(e){return Ys.getBaseFileContent(e).map(function(n){return n.type===Yt?n:_defineProperty(_defineProperty({detail:"auto"},I,Vr),He,n[C]);});}},{key:"getContent",value:function getContent(e){if(e[S]===D&&e[y]&&e[y].length>0){var _n9=Ye.getFileContent(e[y]);return e[h]&&e[h].trim().length>0&&_n9.unshift(_defineProperty(_defineProperty({},I,Bi),h,e[h])),_n9;}return e[h];}},{key:"filterCompleted",value:function filterCompleted(e){return(e==null?void 0:e.filter(function(t){return t.status===Ji;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},C,"".concat(Ye.IMAGE_BASE64_PREFIX).concat(e)),I,V)];}}]);}(Ys);Ye.IMAGE_BASE64_PREFIX="data:image/png;base64,";var Js=Ye;var lr=/*#__PURE__*/function(_Js){function lr(e){var _this64;_classCallCheck(this,lr);var o,a,c,l,d,p,u;var t=w(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,lr,[e,zo(s),Go,n,r]),_this64.permittedErrorPrefixes=[Ws],_this64.isTextInputDisabled=!1,_typeof(r)===F){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);}Vo(s)?_this64.url=lr.buildURL(s):(_this64.isTextInputDisabled=!0,_this64.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,Ws));}));return _this64;}_inherits(lr,_Js);return _createClass(lr,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);}}]);}(Js);var Qs=/*#__PURE__*/function(_M15){function Qs(e){var _this65$maxMessages,_l$model2;var _this65;_classCallCheck(this,Qs);var r,o,a,c,l;var t=w(e.directConnection),n=t.bigModel;_this65=_callSuper(this,Qs,[e,ir(),sr,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=[ce,Ae];var s=(r=t.bigModel)==null?void 0:r.chat;_typeof(s)===F&&_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(Qs,_M15);return _createClass(Qs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Qs.getTextWFilesContent(r,Qs.getFileContent)},S,M.getRoleViaAI(r[S]));});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 _n0;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;}_n0=e.choices[0].message;return _context133.a(2,_n0.tool_calls?this.handleToolsGeneric({tool_calls:_n0.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n0.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][S])===Q&&((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.type===V?_defineProperty(_defineProperty({},I,He),He,{url:t[C]||""}):_defineProperty(_defineProperty({},I,ee),"file_url",{url:t[C]||""});});}}]);}(M);var td=/*#__PURE__*/function(_M16){function td(e){var _this66$maxMessages,_o$model8;var _this66;_classCallCheck(this,td);var r,o;var t=w(e.directConnection),n=t.together;_this66=_callSuper(this,td,[e,or(),rr,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=[et,Ae];var s=(r=t.together)==null?void 0:r.chat;_typeof(s)===F&&_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(td,_M16);return _createClass(td,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,r[S]===Q?ut:r[S]);});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;}()}]);}(M);var nt=/*#__PURE__*/function(_M17){function nt(e){var _this67;_classCallCheck(this,nt);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:2})};_this67=_callSuper(this,nt,[e,In(),Rn,n,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenAI"),_this67.keyHelpUrl=Tn,_this67.url="",_this67.permittedErrorPrefixes=[xs,"Invalid input image"];var r=(o=t==null?void 0:t.openAI)==null?void 0:o[Z];if(_this67[Ne]){var a=_typeof(r)=="object"&&r.size?Number.parseInt(r.size):1024;_this67[Ne][y]={dimensions:{width:a,height:a}};}_typeof(r)===F&&Object.assign(_this67.rawBody,r),_this67.canSendMessage=nt.canFileSendMessage;return _this67;}_inherits(nt,_M17);return _createClass(nt,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e);return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
190
+ },{key:"callApiWithImage",value:function callApiWithImage(e,t,n){var o,a;var s;var r=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim();if(n[1]||r&&r!==""){this.url=nt.IMAGE_EDIT_URL;var c=this.preprocessBody(this.rawBody,r);s=nt.createFormDataBody(c,n[0],n[1]);}else this.url=nt.IMAGE_VARIATIONS_URL,s=nt.createFormDataBody(this.rawBody,n[0]);B.tempRemoveContentHeader(this.connectSettings,pe.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(De);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(De);case 3:this.url=nt.IMAGE_GENERATION_URL;r=this.preprocessBody(this.rawBody,t[t.length-1][h]);pe.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({},C,n.url),I,V):_defineProperty(_defineProperty({},C,"".concat(Cn).concat(n.b64_json)),I,V);});return _context138.a(2,_defineProperty({},y,t));}},_callee138);}));function extractResultData(_x258){return _extractResultData27.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
191
191
  // 1 image:
192
192
  // - With text - edits image based on the text
193
193
  // - No text - creates a variation of the image
@@ -196,34 +196,34 @@ function Ze(e,t,n,s,r){var _this62;_classCallCheck(this,Ze);var a,c;_this62=_cal
196
196
  // Add text to describe the required modification.
197
197
  // Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
198
198
  // `;
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(V,t),n&&s.append("mask",n),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s;}}]);}(M);nt.IMAGE_GENERATION_URL="".concat($e,"images/generations"),nt.IMAGE_VARIATIONS_URL="".concat($e,"images/variations"),nt.IMAGE_EDIT_URL="".concat($e,"images/edits");var Gi=nt;var td=function td(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},nd=function nd(i,e,t,n){var s=i;s[f]?s[f].type===Ae?n(de):n(Be):t(e);},sd=function sd(){return fe("https://openrouter.ai/api/v1/key",le,nd);};var is=/*#__PURE__*/function(_M18){function is(e){var _this68$maxMessages,_o$model9,_a$max_tokens;var _this68;_classCallCheck(this,is);var s,r,o,a;var n=w(e.directConnection).openRouter;_this68=_callSuper(this,is,[e,sd(),td,n]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("OpenRouter"),_this68.keyHelpUrl="https://openrouter.ai/keys",_this68.url="https://openrouter.ai/api/v1/chat/completions",_this68.permittedErrorPrefixes=[et,Ae],_typeof(n)===F&&_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(is,_M18);return _createClass(is,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(o){return _defineProperty({content:is.getContent(o)},S,M.getRoleViaUser(o[S]));}),r=[];return this.systemMessage&&r.push(_defineProperty(_defineProperty({},S,"system"),"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[Y])){_context140.n=3;break;}c=e.message[Y].map(function(l){return _defineProperty({},C,l[He].url);});return _context140.a(2,_defineProperty(_defineProperty({},h,e.message.content||""),y,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[Y])==null?void 0:o.map(function(l){return _defineProperty({},C,l[He].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[Y])){_context141.n=1;break;}s=n[Y].map(function(r){return _defineProperty({},C,r[He].url);});return _context141.a(2,_defineProperty(_defineProperty({},h,n.content||""),y,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.type===j;}).map(function(t){var r,o,a;var n=(r=t[C])==null?void 0:r.split(",")[1],s=(a=(o=t[C])==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return _defineProperty(_defineProperty({},I,Zt),Zt,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[Zt].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[y]&&e[y].length>0){var t=[].concat(_toConsumableArray(is.getImageContent(e[y])),_toConsumableArray(is.getAudioContent(e[y])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(M);var id=function id(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},rd=function rd(i,e,t,n){i[f]?n(de):t(e);},od=function od(){return fe("https://api.perplexity.ai/chat/completions",me,rd);};var ad=/*#__PURE__*/function(_M19){function ad(e){var _this69$maxMessages,_s$model;var _this69;_classCallCheck(this,ad);var s;var n=w(e.directConnection).perplexity;_this69=_callSuper(this,ad,[e,od(),id,n]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Perplexity"),_this69.keyHelpUrl="https://www.perplexity.ai/settings/api",_this69.url="https://api.perplexity.ai/chat/completions",_this69.permittedErrorPrefixes=[Ft,Io,"Permission denied"],_typeof(n)===F&&_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(ad,_M19);return _createClass(ad,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});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;}()}]);}(M);var cd=function cd(i){return _defineProperty(_defineProperty({},ce,"Bearer ".concat(i)),$,J);},ld=function ld(i,e,t,n){var s=i;s.detail?n(s.detail):t(e);},dd=function dd(){return fe("http://localhost:3000/api/v1/models",le,ld);};var hd=/*#__PURE__*/function(_M20){function hd(e){var _this70$maxMessages,_o$model0,_a$stream;var _this70;_classCallCheck(this,hd);var s,r,o,a;var n=w(e.directConnection).openWebUI;_this70=_callSuper(this,hd,[e,dd(),cd,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)===F&&(_this70.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.openWebUI)==null?void 0:r.function_handler),n[y]&&n[y].length>0&&(_this70.rawBody[y]=n[y])),(_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(hd,_M20);return _createClass(hd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:M.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});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(Dt);case 1:n=w(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},S,ut),"content","")),!r.find(function(_ref173){var a=_ref173.response;return _typeof(a)!==ye;})&&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({},S,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(Qt);case 5:return _context147.a(2);}},_callee147,this);}));function handleTools(_x274,_x275){return _handleTools2.apply(this,arguments);}return handleTools;}()}]);}(M);var ud=function ud(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},pd=function pd(i,e,t,n){var s=i;s[f]?s[f].type===Ae?n(de):n(Be):t(e);},fd=function fd(){return fe("https://api.deepseek.com/models",le,pd);};var md=/*#__PURE__*/function(_M21){function md(e){var _this71$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this71;_classCallCheck(this,md);var s,r,o;var n=w(e.directConnection).deepSeek;_this71=_callSuper(this,md,[e,fd(),ud,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=[et,Ae],_typeof(n)===F&&_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(md,_M21);return _createClass(md,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});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;}()}]);}(M);var gd=function gd(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},yd=function yd(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(de):t(e);},bd=function bd(){return fe("https://api.minimax.io/v1/files/delete",me,yd);};var _d=/*#__PURE__*/function(_M22){function _d(e){var _this72$maxMessages,_s$model3;var _this72;_classCallCheck(this,_d);var s;var n=w(e.directConnection).miniMax;_this72=_callSuper(this,_d,[e,bd(),gd,n]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("MiniMax"),_this72.keyHelpUrl="https://www.minimaxi.com",_this72.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this72.permittedErrorPrefixes=[et,Ae,"insufficient balance"],_typeof(n)===F&&_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(_d,_M22);return _createClass(_d,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});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,_n1;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;}_n1=e.choices[0];if(!(_n1.delta&&_n1.delta.content)){_context151.n=2;break;}return _context151.a(2,_defineProperty({},h,_n1.delta.content));case 2:if(!(_n1.message&&_n1.message.content)){_context151.n=3;break;}return _context151.a(2,_defineProperty({},h,_n1.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;}()}]);}(M);var vd=function vd(i){return _defineProperty(_defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J),"accept",J);},Ed=function Ed(i,e,t,n){i.detail?n(de):t(e);},Sd=function Sd(){return fe("https://api.mistral.ai/v1/models",le,Ed);};var lr=/*#__PURE__*/function(_M23){function lr(e){var _this73$maxMessages,_o$model1;var _this73;_classCallCheck(this,lr);var s,r,o;var n=w(e.directConnection).mistral;_this73=_callSuper(this,lr,[e,Sd(),vd,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=[Ft],_typeof(n)===F&&_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(lr,_M23);return _createClass(lr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty(_defineProperty({},S,M.getRoleViaAI(r[S])),"content",M.getTextWFilesContent(r,lr.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 _n10;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;}_n10=e.choices[0];if(!_n10.delta){_context153.n=3;break;}return _context153.a(2,this.extractStreamResult(_n10,t));case 3:if(!_n10.message){_context153.n=4;break;}return _context153.a(2,_n10.message.tool_calls?this.handleToolsGeneric({tool_calls:_n10.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n10.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.type===V?_defineProperty(_defineProperty({},I,He),He,t[C]||""):_defineProperty(_defineProperty({},I,h),h,"[Unsupported ".concat(ee," type: ").concat(t.type,"]"));});}}]);}(M);var dr=/*#__PURE__*/function(_M24){function dr(e){var _this74$maxMessages,_l$model3;var _this74;_classCallCheck(this,dr);var r,o,a,c,l;var t=w(e.directConnection),n=t.groq;_this74=_callSuper(this,dr,[e,Yo(),Zo,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=[Ft,"property"];var s=(r=t.groq)==null?void 0:r.chat;_typeof(s)===F&&_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(dr,_M24);return _createClass(dr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:dr.getTextWImagesContent(r)},S,r[S]===Q?ut:r[S]);});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;}()}]);}(M);var xd=function xd(i){return _defineProperty(_defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J),"accept",J);},Ad=function Ad(i,e,t,n){_typeof(i.message)===ye?n(de):t(e);},wd=function wd(){return fe("https://api.cohere.ai/v1/models",le,Ad);};var Qs=/*#__PURE__*/function(_M25){function Qs(e){var _this75$maxMessages,_s$model4;var _this75;_classCallCheck(this,Qs);var s;var n=w(e.directConnection).cohere;if(_this75=_callSuper(this,Qs,[e,wd(),xd,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)===F){var r=ae.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(Qs,_M25);return _createClass(Qs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t.filter(function(r){return r[h];});return n.messages=s.map(function(r){return _defineProperty(_defineProperty({},S,M.getRoleViaAI(r[S])),"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=Qs.parseBundledEvents(e[h]);return _context159.a(2,{text:Qs.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.type==="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("");}}]);}(M);var Cd=function Cd(){return _defineProperty({},$,J);},Td=function Td(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(de):n(Be):t(e);},Rd=function Rd(){var i="https://generativelanguage.googleapis.com/v1beta/models?key=";return fe(i,le,Td,function(e){return"".concat(i).concat(e);});};var hr=/*#__PURE__*/function(_M26){function hr(e){var _this76$maxMessages;var _this76;_classCallCheck(this,hr);var s,r;var n=w(e.directConnection).gemini;if(_this76=_callSuper(this,hr,[e,Rd(),Cd,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)===F){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(hr,_M26);return _createClass(hr,[{key:"cleanConfig",value:function cleanConfig(e){delete e.model;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return hr.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(De);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)!==F||!s.simulation)||n.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),G.request(this,n,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),pe.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])||""),y,(o=d==null?void 0:d.inlineData)!=null&&o.data?[_defineProperty({},C,"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(Dt);case 1:n=w(t);s=e.map(function(c){return{name:c.name,arguments:oe(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}};})},S,"model");if(!(n.contents.push(a),!r.find(function(_ref202){var c=_ref202.response;return _typeof(c)!==ye;})&&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}}};})},S,D);return _context162.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(Qt);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[y]&&e[y].length>0&&e[y].forEach(function(n){if(n[C]&&n[C].includes("data:")){var _n$C$split=n[C].split(","),_n$C$split2=_slicedToArray(_n$C$split,2),s=_n$C$split2[0],r=_n$C$split2[1];t.push({inlineData:{mimeType:s.replace("data:","").replace(";base64",""),data:r}});}}),_defineProperty({parts:t},S,e[S]===D?D:"model");}}]);}(M);var Id=function Id(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},$,J),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");},Md=function Md(i,e,t,n){var s=i;s[f]?s[f].type===Ae?n(de):n(Be):t(e);},kd=function kd(){return fe("https://api.anthropic.com/v1/models",le,Md);};var ei=/*#__PURE__*/function(_M27){function ei(e){var _this77$maxMessages,_o$model10,_a$max_tokens2;var _this77;_classCallCheck(this,ei);var s,r,o,a;var n=w(e.directConnection).claude;_this77=_callSuper(this,ei,[e,kd(),Id,n]),_this77.insertKeyPlaceholderText=_this77.genereteAPIKeyName("Claude"),_this77.keyHelpUrl="https://console.anthropic.com/settings/keys",_this77.url="https://api.anthropic.com/v1/messages",_this77.permittedErrorPrefixes=[Ae,et],_this77._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},I,"tool_use"),"id",""),"name",""),"input",""),_typeof(n)===F&&_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(ei,_M27);return _createClass(ei,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:ei.getTextWFilesContent(r,ei.getFileContent)},S,M.getRoleViaUser(r[S]));});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.type==="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.type===h;});if(!a){_context164.n=3;break;}return _context164.a(2,_defineProperty({},h,a[h]));case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context164.n=4;break;}return _context164.a(2,_defineProperty({},h,e.delta[h]||""));case 4:if(!(e.type==="content_block_start"&&((n=e.content_block)==null?void 0:n.type)==="tool_use")){_context164.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context164.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((s=e.delta)==null?void 0:s.type)==="input_json_delta")){_context164.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context164.n=7;break;case 6:if(!(e.type==="message_delta"&&((r=e.delta)==null?void 0:r.stop_reason)==="tool_use")){_context164.n=7;break;}return _context164.a(2,(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(Dt);case 1:n=w(t);s=e.map(function(c){return{name:c.name,arguments:oe(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({},I,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push(_defineProperty(_defineProperty({},S,"assistant"),"content",a)),!r.find(function(_ref210){var c=_ref210.response;return _typeof(c)!==ye;})&&s.length===r.length)){_context165.n=4;break;}c=r.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},I,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context165.a(2,(n.messages.push(_defineProperty(_defineProperty({},S,D),"content",c)),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(Qt);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.type===V){var o=(n=t[C])==null?void 0:n.split(",")[1],a=((r=(s=t[C])==null?void 0:s.match(/data:([^;]+)/))==null?void 0:r[1])||"image/jpeg";return _defineProperty(_defineProperty({},I,V),"source",_defineProperty(_defineProperty(_defineProperty({},I,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},I,h),h,"[Unsupported ".concat(ee," type: ").concat(t.type,"]"));});}}]);}(M);var Pd=function Pd(){return{};},Ld=function Ld(){},Od=function Od(){return fe("",le,Ld);},us=/*#__PURE__*/function(_M28){function us(e){var _this78$maxMessages,_o$model11,_a$stream2;var _this78;_classCallCheck(this,us);var s,r,o,a;var t=w(e.directConnection);_this78=_callSuper(this,us,[e,Od(),Pd,{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)===F&&_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(us,_M28);return _createClass(us,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){var o=_defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));if(r[y]&&r[y].length>0){var a=us.getImageData(r[y]);a.length>0&&(o[Y]=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(us.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(Dt);case 1:n=w(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:oe(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},S,ut),"content","")),!r.find(function(_ref218){var a=_ref218.response;return _typeof(a)!==ye;})&&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({},S,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(Qt);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.type===V;}).map(function(t){var s;return((s=t[C])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(M);us.THINK_END="</think>";var zi=us;var Jo=function Jo(i){return _defineProperty({Authorization:"".concat(xe).concat(i)},$,J);},Nd=function Nd(i,e,t,n){var s=i;s[f]?s[f].type===Ae||s[f].type===et?n(de):n(Be):t(e);},Qo=function Qo(){return fe("https://api.x.ai/v1/models",le,Nd);},ai=/*#__PURE__*/function(_M29){function ai(e){var _o$model12;var _this79;_classCallCheck(this,ai);var r,o;var t=e.directConnection,n=t==null?void 0:t.x;_this79=_callSuper(this,ai,[e,Qo(),Jo,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("X"),_this79.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this79.url=ai.IMAGE_GENERATION_URL,_this79.permittedErrorPrefixes=[et,Ae];var s=(r=t==null?void 0:t.x)==null?void 0:r[Y];_typeof(s)===F&&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(ai,_M29);return _createClass(ai,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=w(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({},C,n.url),I,V):_defineProperty(_defineProperty({},C,"".concat(wn).concat(n.b64_json)),I,V);});return _context170.a(2,_defineProperty({},y,t));}},_callee170);}));function extractResultData(_x317){return _extractResultData39.apply(this,arguments);}return extractResultData;}()}]);}(M);ai.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Vi=ai;var Bd=function Bd(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},Dd=function Dd(i,e,t,n){var s=i;s[f]?s[f].type===et?n(de):n(Be):t(e);},Fd=function Fd(){return fe("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",le,Dd);};var ur=/*#__PURE__*/function(_M30){function ur(e){var _this80$maxMessages,_o$model13;var _this80;_classCallCheck(this,ur);var s,r,o;var n=w(e.directConnection).qwen;_this80=_callSuper(this,ur,[e,Fd(),Bd,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",Ss],_typeof(n)===F&&_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(ur,_M30);return _createClass(ur,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:ur.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});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 _n11;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;}_n11=e.choices[0];if(!_n11.delta){_context172.n=2;break;}return _context172.a(2,this.extractStreamResult(_n11,t));case 2:if(!_n11.message){_context172.n=3;break;}return _context172.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 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;}()}]);}(M);var Ud=function Ud(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},Hd=function Hd(i,e,t,n){var s=i;s[f]?s[f].type===Ae?n(de):n(Be):t(e);},jd=function jd(){return fe("https://api.moonshot.ai/v1/models",le,Hd);};var pr=/*#__PURE__*/function(_M31){function pr(e){var _this81$maxMessages,_o$model14;var _this81;_classCallCheck(this,pr);var s,r,o;var n=w(e.directConnection).kimi;_this81=_callSuper(this,pr,[e,jd(),Ud,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=[Ft,"Not found"],_typeof(n)===F&&_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(pr,_M31);return _createClass(pr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:pr.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});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 _n12;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;}_n12=e.choices[0];if(!_n12.delta){_context175.n=2;break;}return _context175.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context175.n=3;break;}return _context175.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 _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;}()}]);}(M);var $d=/*#__PURE__*/function(_M32){function $d(e){var _this82$maxMessages,_o$model15;var _this82;_classCallCheck(this,$d);var r,o;var t=w(e.directConnection),n=t.x;_this82=_callSuper(this,$d,[e,Qo(),Jo,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=[et,Ae];var s=(r=t.x)==null?void 0:r.chat;_typeof(s)===F&&_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($d,_M32);return _createClass($d,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});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;}()}]);}(M);var Ls=/* @__PURE__ */function(i){return i.BLOCKING="blocking",i.STREAMING="streaming",i;}(Ls||{}),dn=/* @__PURE__ */function(i){return i.MESSAGE="message",i.AGENT_MESSAGE="agent_message",i.WORKFLOW_FINISHED="workflow_finished",i.ERROR="error",i;}(dn||{});var qd="image/",Gd="data:",zd=function zd(i,e){return{type:e,transfer_method:"local_file",upload_file_id:i};},Vd=function Vd(i){var e=i.trim();if(!e.startsWith(Gd))return null;var t=e.replace(/^data:\s*/,"").trim();return t?JSON.parse(t):null;};function Kd(_x333,_x334){return _Kd.apply(this,arguments);}function _Kd(){_Kd=_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(ee,i),t.append(D,e[D]);_e$headers=e.headers;n=_e$headers[$];s=_objectWithoutProperties(_e$headers,[$].map(_toPropertyKey));_context197.n=1;return fetch(e.url,{method:me,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 _Kd.apply(this,arguments);}function Wd(_x335,_x336){return _Wd.apply(this,arguments);}function _Wd(){_Wd=_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 _ref258=_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 Kd(s,e);case 1:r=_context198.v;o=s.type.startsWith(qd)?V:ee;return _context198.a(2,zd(r,o));}},_callee198);}));return function(_x367){return _ref258.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 _Wd.apply(this,arguments);}function Xd(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 Zd=function Zd(i,e,t){var n,s;switch(!e.conversationIdSet&&i.conversation_id&&(t(i.conversation_id),e.conversationIdSet=!0),i.event){case dn.MESSAGE:case dn.AGENT_MESSAGE:e.fullAnswer+=i.answer||"";break;case dn.WORKFLOW_FINISHED:!e.fullAnswer&&(s=(n=i.data)==null?void 0:n.outputs)!=null&&s.answer&&(e.fullAnswer=i.data.outputs.answer);break;case dn.ERROR:e.errorMessage=i.message||dn.ERROR;break;}};function Yd(_x337,_x338){return _Yd.apply(this,arguments);}function _Yd(){_Yd=_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=Vd(r);o&&Zd(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 _Yd.apply(this,arguments);}var Jd=function Jd(i){return _defineProperty(_defineProperty({},$,J),ce,"".concat(xe).concat(i));},Qd=function Qd(i,e,t,n){var s=i;s[f]?s[f].message===li?n(de):n(Be):"user_input_form"in i||"opening_statement"in i||"file_upload"in i?t(e):n(Be);},eh=function eh(i){return fe("".concat(i,"/parameters"),le,Qd);};var th=/*#__PURE__*/function(_M33){function th(e){var _ref239,_this83$maxMessages;var _this83;_classCallCheck(this,th);var r;var t=w(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,th,[e,eh(s),Jd,n]),_this83.insertKeyPlaceholderText=_this83.genereteAPIKeyName("Dify"),_this83.keyHelpUrl="https://docs.dify.ai/en/use-dify/publish/developing-with-apis",_this83.permittedErrorPrefixes=[Ae],_this83._conversationId="",_this83._user=D,_this83._inputs={},_this83.url="".concat(s,"/chat-messages"),_this83._uploadUrl="".concat(s,"/").concat(y,"/upload"),_typeof(n)===F&&(n[D]&&(_this83._user=n[D]),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?Ls.STREAMING:Ls.BLOCKING;return _this83;}_inherits(th,_M33);return _createClass(th,[{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},D,this._user);return this._conversationId&&(a.conversation_id=this._conversationId),n&&n.length>0&&(a[y]=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 Wd(n,_defineProperty(_defineProperty({url:this._uploadUrl},D,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===Ls.BLOCKING&&!this.stream?Xd(e,t):Yd(e,t));}},_callee180,this);}));function extractResultData(_x342){return _extractResultData43.apply(this,arguments);}return extractResultData;}()}]);}(M);var nh=/*#__PURE__*/function(){function nh(){_classCallCheck(this,nh);}return _createClass(nh,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 bs(e);if(t){if(t.openAI)return t.openAI[Y]?new Gi(e):t.openAI.speechToText?new Hi(e):t.openAI.textToSpeech?new Ui(e):t.openAI.assistant?new or(e):t.openAI.realtime?new Fi(e):t.openAI.completions?new Zs(e):new Ys(e);if(t.assemblyAI)return new ar(e);if(t.cohere)return new Qs(e);if(t.huggingFace)return t.huggingFace.textGeneration?new xl(e):t.huggingFace.summarization?new wl(e):t.huggingFace.translation?new Tl(e):t.huggingFace.fillMask?new Rl(e):t.huggingFace.questionAnswer?new Al(e):t.huggingFace.audioSpeechRecognition?new Sl(e):t.huggingFace.audioClassification?new _l(e):t.huggingFace.imageClassification?new vl(e):new Cl(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new cr(e);if(t.azure.openAI.assistant)return new Bi(e);}if(t.azure.speechToText)return new qi(e);if(t.azure.textToSpeech)return new $i(e);if(t.azure.summarization)return new ji(e);if(t.azure.translation)return new Xl(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new Gs(e):t.stabilityAI.imageToImageUpscale?new $s(e):t.stabilityAI.imageToImageMasking?new qs(e):new zs(e);if(t.mistral)return new lr(e);if(t.gemini)return new hr(e);if(t.claude)return new ei(e);if(t.deepSeek)return new md(e);if(t.miniMax)return new _d(e);if(t.openRouter)return new is(e);if(t.kimi)return new pr(e);if(t.x)return t.x[Y]?new Vi(e):new $d(e);if(t.qwen)return new ur(e);if(t.together)return t.together[Y]?new Ql(e):t.together.textToSpeech?new Pl(e):new ed(e);if(t.bigModel)return t.bigModel[Y]?new Zl(e):t.bigModel.textToSpeech?new Ml(e):new Js(e);if(t.groq)return t.groq.textToSpeech?new Jl(e):new dr(e);if(t.perplexity)return new ad(e);if(t.ollama)return new zi(e);if(t.openWebUI)return new hd(e);if(t.dify)return new th(e);}return n&&Object.keys(n).length>0&&!s?new sn(e):new sn(e,void 0,s||!0);}}]);}();var Er=/*#__PURE__*/_createClass(function Er(){_classCallCheck(this,Er);});Er.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 Ki=Er;function L(i){return function(e,t){Object.defineProperty(e,t,{});var n=e.constructor,s=t.toLocaleLowerCase();n._attributes_[s]=Ki.attibutes[i],n._attributeToProperty_[s]=t;};}var sh="deep-chat-downwards-mode",ih="deep-chat-upwards-mode",kn="submit-button",Ms="loading-button",Pn="disabled-button",Kr="text-input-container-start-adjustment",Wr="text-input-container-end-adjustment",Xr="text-input-container-start-small-adjustment",Zr="text-input-container-end-small-adjustment";var fr=/*#__PURE__*/function(){function fr(e){_classCallCheck(this,fr);this._isDisplayed=!1,this._elementRef=this.createIntroPanelWithChild(e),this._isDisplayed=!0;}return _createClass(fr,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e){var t=fr.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=x();return e[m].add("intro-panel"),Object.assign(e[v]),e;}}]);}();var rh="<?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>",Ce=/*#__PURE__*/function(){function Ce(){_classCallCheck(this,Ce);}return _createClass(Ce,null,[{key:"createImage",value:function createImage(e,t){var n=new Image();return n[C]=e[C],t&&_e.scrollDownOnImageLoad(n[C],t),_e.processContent(V,n,n[C],e.name);}// WORK - image still does not scroll down when loaded
203
- },{key:"createImageMessage",value:function createImageMessage(e,t,n,s){var r=e.createNewMessageElement("",n),o=s?e.scrollToFirstElement.bind(e,n,s):void 0,a=Ce.createImage(t,o);return r.bubbleElement.appendChild(a),r.bubbleElement[m].add(Ce.IMAGE_BUBBLE_CLASS),{type:V,elements:r};}},{key:"createAudioElement",value:function createAudioElement(e,t){var n=x(j);return n[C]=e[C],n[m].add("audio-player"),n.controls=!0,Ue.IS_SAFARI&&(n[m].add("audio-player-safari"),n[m].add(t===D?"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=Ce.createAudioElement(t,n),o=e.createMessageElementsOnOrientation("",n,s);return o.bubbleElement.appendChild(r),o.bubbleElement[m].add(Ce.AUDIO_BUBBLE_CLASS),{type:j,elements:o,audioElement:r};}},{key:"createAnyFile",value:function createAnyFile(e){var t=x();t[m].add("any-file-message-contents");var n=x();n[m].add("any-file-message-icon-container");var s=Ct.createSVGElement(rh);s[m].add("any-file-message-icon"),n.appendChild(s);var r=x();return r[m].add("any-file-message-text"),r.textContent=e.name||ee,t.appendChild(n),t.appendChild(r),_e.processContent(Jt,t,e[C],r.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,n,s){var r=e.createMessageElementsOnOrientation("",n,s),o=Ce.createAnyFile(t);return r.bubbleElement[m].add(Ce.ANY_FILE_BUBBLE_CLASS),r.bubbleElement.appendChild(o),{type:ee,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=_e.removeFileRef(o)),_e.isAudioFile(o)){var l=Ce.createNewAudioMessage(e,o,n,r),d=(c=e.textToSpeech)==null?void 0:c.audio;return d&&(d.autoPlay&&Ce.autoPlayAudio(l.audioElement),typeof d.displayAudio=="boolean"&&!d.displayAudio)?void 0:l;}return _e.isImageFile(o)?Ce.createImageMessage(e,o,n,!r&&s&&a===0):Ce.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){Ce.createMessages(e,t,n,s,r).filter(function(a){return a!==void 0;}).forEach(function(_ref240){var a=_ref240.type,c=_ref240.elements;_e.addMessage(e,c,a,n,r);});}}]);}();Ce.IMAGE_BUBBLE_CLASS="image-message",Ce.AUDIO_BUBBLE_CLASS="audio-message",Ce.ANY_FILE_BUBBLE_CLASS="any-file-message";var ti=Ce;var Xe=/*#__PURE__*/function(){function Xe(){_classCallCheck(this,Xe);}return _createClass(Xe,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][y])==null||n.forEach(function(s){Xe.removeElements(e.messageElementRefs,s);}),delete t[0][y],delete t[1][y];}},{key:"removeTextHTMLMessage",value:function removeTextHTMLMessage(e,t,n){var s=t[1][n];Xe.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][P])ft.overwriteElements(e,n,t[1][P]);else{var a=ft.create(e,n,t[0][S]),c=((r=t[1][y])==null?void 0:r[((s=t[1][y])==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][P]=a;}t[0][P]=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][S],r=ti.createMessages(e,n,s,!1),o=t[1][P],a=((u=t[1][y])==null?void 0:u[((p=t[1][y])==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(_ref241,_){var g=_ref241.type,b=_ref241.elements;var E;_e.setElementProps(e,b,g,s),(E=d.parentElement)==null||E.insertBefore(b.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(l+_,0,b);}),Xe.removeFilesMessages(e,t),t[1][y]=r.map(function(_ref242){var g=_ref242.elements;return g;}),t[0][y]=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][S]);else{var o=e.createElements(n,t[0][S]),a=((s=t[1][y])==null?void 0:s[0])||t[1][P];(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 Je.isActiveElement((t=e[h])==null?void 0:t.bubbleElement[m])||Je.isActiveElement((n=e[P])==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(Xe.isElementActive(s[1]))return console[f]("Cannot update a message that is being streamed");t[h]&&Xe.updateTextMessage(e,s,t[h]),t[y]?Xe.updateFileMessages(e,s,t[y]):Xe.removeFilesMessages(e,s),t[P]&&Xe.updateHTMLMessage(e,s,t[P]),!t[h]&&s[1][h]&&Xe.removeTextHTMLMessage(e,s,h),!t[P]&&s[1][P]&&Xe.removeTextHTMLMessage(e,s,P);var r=e.messageElementRefs,o=e.avatar,a=e.name;N.classifyRoleMessages(r),N.resetAllRoleElements(r,o,a);}else console[f]("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var oh=/*#__PURE__*/function(){function oh(){_classCallCheck(this,oh);}return _createClass(oh,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(K,"connect#connect-1) property or a popular service via [directConnection](").concat(K,"directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](").concat(K,"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(K,"modes#demo) property to true.");if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](".concat(K,"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.type==="function";})&&!r.function_handler)return"Please define the `function_handler` property inside the openAI [chat](".concat(K,"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(K,"connect#connect-1) object.");return null;}}]);}();var Je=/*#__PURE__*/function(_Qe){function Je(e,t,n){var _this86;_classCallCheck(this,Je);var a,c;_this86=_callSuper(this,Je,[e]);var s=t.permittedErrorPrefixes,r=t.demo;_this86._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this86._onClearMessages=nn.onClearMessages.bind(_this86,e),_this86._onError=nn.onError.bind(_this86,e),_this86._isLoadingMessageAllowed=Je.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(ae.processDemo(r),e.loadHistory),_this86.addIntroductoryMessages(e,t);var o=new ys(e,_this86,t);_this86._displayServiceErrorMessages=(c=e.errorMessages)==null?void 0:c.displayServiceErrorMessages,e.getMessages=function(){return N.deepCloneMessagesWithReferences(_this86.messageToElements.map(function(_ref243){var _ref244=_slicedToArray(_ref243,1),l=_ref244[0];return l;}));},e.clearMessages=_this86.clearMessages.bind(_this86,t),e.refreshMessages=_this86.refreshTextMessages.bind(_this86,e.remarkable),e.scrollToBottom=q.scrollToBottom.bind(_this86,_this86),e.addMessage=function(l,d){_this86.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(l,d){return Xe.update(_this86,l,d);},t.isWebModel()&&t.setUpMessages(_this86),e.textToSpeech&&vn.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(Je,_Qe);return _createClass(Je,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1],n=Qe.isLoadingMessage(t);if(!e&&n)this.removeLastMessage(),delete this._activeLoadingConfig;else{if(this._activeLoadingConfig&&n){var s=se.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&&wt.addMessage(this,!1),s!=null&&s.full&&wt.addMessage(this);}e.displayErrors&&(e.displayErrors[A]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage(ie,""),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=oh.getText(e,t);if(n){var s=this.createAndAppendNewMessageElement(n,Q);this.applyCustomStyles(s,Q,!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;N.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],Q):e!=null&&e[P]&&(n=ft.add(this,e[P],Q)),n&&(this.applyCustomStyles(n,Q,!1,(s=this.messageStyles)==null?void 0:s.intro),n.outerContainer[m].add(Qe.INTRO_CLASS),t&&(n.outerContainer[v].display="none")),n;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer[m].contains(Qe.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(ie,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[S],t,r),!s&&this.textToSpeech&&e[S]!==D&&vn.speak(e[h],this.textToSpeech));}},{key:"tryAddFileMessages",value:function tryAddFileMessages(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;e[y]&&Array.isArray(e[y])&&ti.addMessages(this,e[y],e[S],t,n);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e[P]!==void 0&&e[P]!==null){var s=ft.add(this,e[P],e[S],t,n);!n&&pt.isElementTemporary(s)&&delete e[P];}}// this should not be activated by streamed messages
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(V,t),n&&s.append("mask",n),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s;}}]);}(M);nt.IMAGE_GENERATION_URL="".concat($e,"images/generations"),nt.IMAGE_VARIATIONS_URL="".concat($e,"images/variations"),nt.IMAGE_EDIT_URL="".concat($e,"images/edits");var zi=nt;var nd=function nd(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},sd=function sd(i,e,t,n){var s=i;s[f]?s[f].type===Ae?n(de):n(Be):t(e);},id=function id(){return fe("https://openrouter.ai/api/v1/key",le,sd);};var rs=/*#__PURE__*/function(_M18){function rs(e){var _this68$maxMessages,_o$model9,_a$max_tokens;var _this68;_classCallCheck(this,rs);var s,r,o,a;var n=w(e.directConnection).openRouter;_this68=_callSuper(this,rs,[e,id(),nd,n]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("OpenRouter"),_this68.keyHelpUrl="https://openrouter.ai/keys",_this68.url="https://openrouter.ai/api/v1/chat/completions",_this68.permittedErrorPrefixes=[et,Ae],_typeof(n)===F&&_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(rs,_M18);return _createClass(rs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(o){return _defineProperty({content:rs.getContent(o)},S,M.getRoleViaUser(o[S]));}),r=[];return this.systemMessage&&r.push(_defineProperty(_defineProperty({},S,Sn),"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[Z])){_context140.n=3;break;}c=e.message[Z].map(function(l){return _defineProperty({},C,l[He].url);});return _context140.a(2,_defineProperty(_defineProperty({},h,e.message.content||""),y,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[Z])==null?void 0:o.map(function(l){return _defineProperty({},C,l[He].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[Z])){_context141.n=1;break;}s=n[Z].map(function(r){return _defineProperty({},C,r[He].url);});return _context141.a(2,_defineProperty(_defineProperty({},h,n.content||""),y,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.type===j;}).map(function(t){var r,o,a;var n=(r=t[C])==null?void 0:r.split(",")[1],s=(a=(o=t[C])==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return _defineProperty(_defineProperty({},I,Yt),Yt,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[Yt].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[y]&&e[y].length>0){var t=[].concat(_toConsumableArray(rs.getImageContent(e[y])),_toConsumableArray(rs.getAudioContent(e[y])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},I,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(M);var rd=function rd(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},od=function od(i,e,t,n){i[f]?n(de):t(e);},ad=function ad(){return fe("https://api.perplexity.ai/chat/completions",me,od);};var cd=/*#__PURE__*/function(_M19){function cd(e){var _this69$maxMessages,_s$model;var _this69;_classCallCheck(this,cd);var s;var n=w(e.directConnection).perplexity;_this69=_callSuper(this,cd,[e,ad(),rd,n]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Perplexity"),_this69.keyHelpUrl="https://www.perplexity.ai/settings/api",_this69.url="https://api.perplexity.ai/chat/completions",_this69.permittedErrorPrefixes=[Ft,Mo,"Permission denied"],_typeof(n)===F&&_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(cd,_M19);return _createClass(cd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});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;}()}]);}(M);var ld=function ld(i){return _defineProperty(_defineProperty({},ce,"Bearer ".concat(i)),$,J);},dd=function dd(i,e,t,n){var s=i;s.detail?n(s.detail):t(e);},hd=function hd(){return fe("http://localhost:3000/api/v1/models",le,dd);};var ud=/*#__PURE__*/function(_M20){function ud(e){var _this70$maxMessages,_o$model0,_a$stream;var _this70;_classCallCheck(this,ud);var s,r,o,a;var n=w(e.directConnection).openWebUI;_this70=_callSuper(this,ud,[e,hd(),ld,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)===F&&(_this70.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.openWebUI)==null?void 0:r.function_handler),n[y]&&n[y].length>0&&(_this70.rawBody[y]=n[y])),(_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(ud,_M20);return _createClass(ud,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:M.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});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(Dt);case 1:n=w(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},S,ut),"content","")),!r.find(function(_ref173){var a=_ref173.response;return _typeof(a)!==ye;})&&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({},S,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(Qt);case 5:return _context147.a(2);}},_callee147,this);}));function handleTools(_x274,_x275){return _handleTools2.apply(this,arguments);}return handleTools;}()}]);}(M);var pd=function pd(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},fd=function fd(i,e,t,n){var s=i;s[f]?s[f].type===Ae?n(de):n(Be):t(e);},md=function md(){return fe("https://api.deepseek.com/models",le,fd);};var gd=/*#__PURE__*/function(_M21){function gd(e){var _this71$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this71;_classCallCheck(this,gd);var s,r,o;var n=w(e.directConnection).deepSeek;_this71=_callSuper(this,gd,[e,md(),pd,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=[et,Ae],_typeof(n)===F&&_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(gd,_M21);return _createClass(gd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});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;}()}]);}(M);var yd=function yd(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},bd=function bd(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(de):t(e);},_d=function _d(){return fe("https://api.minimax.io/v1/files/delete",me,bd);};var vd=/*#__PURE__*/function(_M22){function vd(e){var _this72$maxMessages,_s$model3;var _this72;_classCallCheck(this,vd);var s;var n=w(e.directConnection).miniMax;_this72=_callSuper(this,vd,[e,_d(),yd,n]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("MiniMax"),_this72.keyHelpUrl="https://www.minimaxi.com",_this72.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this72.permittedErrorPrefixes=[et,Ae,"insufficient balance"],_typeof(n)===F&&_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(vd,_M22);return _createClass(vd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});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,_n1;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;}_n1=e.choices[0];if(!(_n1.delta&&_n1.delta.content)){_context151.n=2;break;}return _context151.a(2,_defineProperty({},h,_n1.delta.content));case 2:if(!(_n1.message&&_n1.message.content)){_context151.n=3;break;}return _context151.a(2,_defineProperty({},h,_n1.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;}()}]);}(M);var Ed=function Ed(i){return _defineProperty(_defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J),"accept",J);},Sd=function Sd(i,e,t,n){i.detail?n(de):t(e);},xd=function xd(){return fe("https://api.mistral.ai/v1/models",le,Sd);};var dr=/*#__PURE__*/function(_M23){function dr(e){var _this73$maxMessages,_o$model1;var _this73;_classCallCheck(this,dr);var s,r,o;var n=w(e.directConnection).mistral;_this73=_callSuper(this,dr,[e,xd(),Ed,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=[Ft],_typeof(n)===F&&_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(dr,_M23);return _createClass(dr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty(_defineProperty({},S,M.getRoleViaAI(r[S])),"content",M.getTextWFilesContent(r,dr.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 _n10;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;}_n10=e.choices[0];if(!_n10.delta){_context153.n=3;break;}return _context153.a(2,this.extractStreamResult(_n10,t));case 3:if(!_n10.message){_context153.n=4;break;}return _context153.a(2,_n10.message.tool_calls?this.handleToolsGeneric({tool_calls:_n10.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n10.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.type===V?_defineProperty(_defineProperty({},I,He),He,t[C]||""):_defineProperty(_defineProperty({},I,h),h,"[Unsupported ".concat(ee," type: ").concat(t.type,"]"));});}}]);}(M);var hr=/*#__PURE__*/function(_M24){function hr(e){var _this74$maxMessages,_l$model3;var _this74;_classCallCheck(this,hr);var r,o,a,c,l;var t=w(e.directConnection),n=t.groq;_this74=_callSuper(this,hr,[e,Jo(),Zo,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=[Ft,"property"];var s=(r=t.groq)==null?void 0:r.chat;_typeof(s)===F&&_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(hr,_M24);return _createClass(hr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:hr.getTextWImagesContent(r)},S,r[S]===Q?ut:r[S]);});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;}()}]);}(M);var Ad=function Ad(i){return _defineProperty(_defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J),"accept",J);},wd=function wd(i,e,t,n){_typeof(i.message)===ye?n(de):t(e);},Cd=function Cd(){return fe("https://api.cohere.ai/v1/models",le,wd);};var ei=/*#__PURE__*/function(_M25){function ei(e){var _this75$maxMessages,_s$model4;var _this75;_classCallCheck(this,ei);var s;var n=w(e.directConnection).cohere;if(_this75=_callSuper(this,ei,[e,Cd(),Ad,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)===F){var r=ae.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(ei,_M25);return _createClass(ei,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t.filter(function(r){return r[h];});return n.messages=s.map(function(r){return _defineProperty(_defineProperty({},S,M.getRoleViaAI(r[S])),"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=ei.parseBundledEvents(e[h]);return _context159.a(2,{text:ei.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.type==="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("");}}]);}(M);var Td=function Td(){return _defineProperty({},$,J);},Rd=function Rd(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(de):n(Be):t(e);},Id=function Id(){var i="https://generativelanguage.googleapis.com/v1beta/models?key=";return fe(i,le,Rd,function(e){return"".concat(i).concat(e);});};var ur=/*#__PURE__*/function(_M26){function ur(e){var _this76$maxMessages;var _this76;_classCallCheck(this,ur);var s,r;var n=w(e.directConnection).gemini;if(_this76=_callSuper(this,ur,[e,Id(),Td,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)===F){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(ur,_M26);return _createClass(ur,[{key:"cleanConfig",value:function cleanConfig(e){delete e.model;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return ur.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(De);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)!==F||!s.simulation)||n.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),G.request(this,n,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),pe.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])||""),y,(o=d==null?void 0:d.inlineData)!=null&&o.data?[_defineProperty({},C,"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(Dt);case 1:n=w(t);s=e.map(function(c){return{name:c.name,arguments:oe(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}};})},S,"model");if(!(n.contents.push(a),!r.find(function(_ref202){var c=_ref202.response;return _typeof(c)!==ye;})&&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}}};})},S,D);return _context162.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(Qt);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[y]&&e[y].length>0&&e[y].forEach(function(n){if(n[C]&&n[C].includes("data:")){var _n$C$split=n[C].split(","),_n$C$split2=_slicedToArray(_n$C$split,2),s=_n$C$split2[0],r=_n$C$split2[1];t.push({inlineData:{mimeType:s.replace("data:","").replace(";base64",""),data:r}});}}),_defineProperty({parts:t},S,e[S]===D?D:"model");}}]);}(M);var Md=function Md(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},$,J),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");},kd=function kd(i,e,t,n){var s=i;s[f]?s[f].type===Ae?n(de):n(Be):t(e);},Pd=function Pd(){return fe("https://api.anthropic.com/v1/models",le,kd);};var ti=/*#__PURE__*/function(_M27){function ti(e){var _this77$maxMessages,_o$model10,_a$max_tokens2;var _this77;_classCallCheck(this,ti);var s,r,o,a;var n=w(e.directConnection).claude;_this77=_callSuper(this,ti,[e,Pd(),Md,n]),_this77.insertKeyPlaceholderText=_this77.genereteAPIKeyName("Claude"),_this77.keyHelpUrl="https://console.anthropic.com/settings/keys",_this77.url="https://api.anthropic.com/v1/messages",_this77.permittedErrorPrefixes=[Ae,et],_this77._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},I,"tool_use"),"id",""),"name",""),"input",""),_typeof(n)===F&&_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(ti,_M27);return _createClass(ti,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:ti.getTextWFilesContent(r,ti.getFileContent)},S,M.getRoleViaUser(r[S]));});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.type==="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.type===h;});if(!a){_context164.n=3;break;}return _context164.a(2,_defineProperty({},h,a[h]));case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context164.n=4;break;}return _context164.a(2,_defineProperty({},h,e.delta[h]||""));case 4:if(!(e.type==="content_block_start"&&((n=e.content_block)==null?void 0:n.type)==="tool_use")){_context164.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context164.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((s=e.delta)==null?void 0:s.type)==="input_json_delta")){_context164.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context164.n=7;break;case 6:if(!(e.type==="message_delta"&&((r=e.delta)==null?void 0:r.stop_reason)==="tool_use")){_context164.n=7;break;}return _context164.a(2,(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(Dt);case 1:n=w(t);s=e.map(function(c){return{name:c.name,arguments:oe(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({},I,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push(_defineProperty(_defineProperty({},S,"assistant"),"content",a)),!r.find(function(_ref210){var c=_ref210.response;return _typeof(c)!==ye;})&&s.length===r.length)){_context165.n=4;break;}c=r.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},I,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context165.a(2,(n.messages.push(_defineProperty(_defineProperty({},S,D),"content",c)),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(Qt);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.type===V){var o=(n=t[C])==null?void 0:n.split(",")[1],a=((r=(s=t[C])==null?void 0:s.match(/data:([^;]+)/))==null?void 0:r[1])||"image/jpeg";return _defineProperty(_defineProperty({},I,V),"source",_defineProperty(_defineProperty(_defineProperty({},I,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},I,h),h,"[Unsupported ".concat(ee," type: ").concat(t.type,"]"));});}}]);}(M);var Ld=function Ld(){return{};},Od=function Od(){},Nd=function Nd(){return fe("",le,Od);},ps=/*#__PURE__*/function(_M28){function ps(e){var _this78$maxMessages,_o$model11,_a$stream2;var _this78;_classCallCheck(this,ps);var s,r,o,a;var t=w(e.directConnection);_this78=_callSuper(this,ps,[e,Nd(),Ld,{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)===F&&_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(ps,_M28);return _createClass(ps,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){var o=_defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));if(r[y]&&r[y].length>0){var a=ps.getImageData(r[y]);a.length>0&&(o[Z]=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(ps.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(Dt);case 1:n=w(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:oe(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},S,ut),"content","")),!r.find(function(_ref218){var a=_ref218.response;return _typeof(a)!==ye;})&&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({},S,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(Qt);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.type===V;}).map(function(t){var s;return((s=t[C])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(M);ps.THINK_END="</think>";var Vi=ps;var Qo=function Qo(i){return _defineProperty({Authorization:"".concat(xe).concat(i)},$,J);},Bd=function Bd(i,e,t,n){var s=i;s[f]?s[f].type===Ae||s[f].type===et?n(de):n(Be):t(e);},ea=function ea(){return fe("https://api.x.ai/v1/models",le,Bd);},ci=/*#__PURE__*/function(_M29){function ci(e){var _o$model12;var _this79;_classCallCheck(this,ci);var r,o;var t=e.directConnection,n=t==null?void 0:t.x;_this79=_callSuper(this,ci,[e,ea(),Qo,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("X"),_this79.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this79.url=ci.IMAGE_GENERATION_URL,_this79.permittedErrorPrefixes=[et,Ae];var s=(r=t==null?void 0:t.x)==null?void 0:r[Z];_typeof(s)===F&&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(ci,_M29);return _createClass(ci,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=w(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({},C,n.url),I,V):_defineProperty(_defineProperty({},C,"".concat(Cn).concat(n.b64_json)),I,V);});return _context170.a(2,_defineProperty({},y,t));}},_callee170);}));function extractResultData(_x317){return _extractResultData39.apply(this,arguments);}return extractResultData;}()}]);}(M);ci.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Ki=ci;var Dd=function Dd(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},Fd=function Fd(i,e,t,n){var s=i;s[f]?s[f].type===et?n(de):n(Be):t(e);},Ud=function Ud(){return fe("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",le,Fd);};var pr=/*#__PURE__*/function(_M30){function pr(e){var _this80$maxMessages,_o$model13;var _this80;_classCallCheck(this,pr);var s,r,o;var n=w(e.directConnection).qwen;_this80=_callSuper(this,pr,[e,Ud(),Dd,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",xs],_typeof(n)===F&&_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(pr,_M30);return _createClass(pr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:pr.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});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 _n11;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;}_n11=e.choices[0];if(!_n11.delta){_context172.n=2;break;}return _context172.a(2,this.extractStreamResult(_n11,t));case 2:if(!_n11.message){_context172.n=3;break;}return _context172.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 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;}()}]);}(M);var Hd=function Hd(i){return _defineProperty(_defineProperty({},ce,"".concat(xe).concat(i)),$,J);},jd=function jd(i,e,t,n){var s=i;s[f]?s[f].type===Ae?n(de):n(Be):t(e);},$d=function $d(){return fe("https://api.moonshot.ai/v1/models",le,jd);};var fr=/*#__PURE__*/function(_M31){function fr(e){var _this81$maxMessages,_o$model14;var _this81;_classCallCheck(this,fr);var s,r,o;var n=w(e.directConnection).kimi;_this81=_callSuper(this,fr,[e,$d(),Hd,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=[Ft,"Not found"],_typeof(n)===F&&_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(fr,_M31);return _createClass(fr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:fr.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});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 _n12;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;}_n12=e.choices[0];if(!_n12.delta){_context175.n=2;break;}return _context175.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context175.n=3;break;}return _context175.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 _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;}()}]);}(M);var qd=/*#__PURE__*/function(_M32){function qd(e){var _this82$maxMessages,_o$model15;var _this82;_classCallCheck(this,qd);var r,o;var t=w(e.directConnection),n=t.x;_this82=_callSuper(this,qd,[e,ea(),Qo,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=[et,Ae];var s=(r=t.x)==null?void 0:r.chat;_typeof(s)===F&&_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(qd,_M32);return _createClass(qd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});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;}()}]);}(M);var Os=/* @__PURE__ */function(i){return i.BLOCKING="blocking",i.STREAMING="streaming",i;}(Os||{}),dn=/* @__PURE__ */function(i){return i.MESSAGE="message",i.AGENT_MESSAGE="agent_message",i.WORKFLOW_FINISHED="workflow_finished",i.ERROR="error",i;}(dn||{});var Gd="image/",zd="data:",Vd=function Vd(i,e){return{type:e,transfer_method:"local_file",upload_file_id:i};},Kd=function Kd(i){var e=i.trim();if(!e.startsWith(zd))return null;var t=e.replace(/^data:\s*/,"").trim();return t?JSON.parse(t):null;};function Wd(_x333,_x334){return _Wd.apply(this,arguments);}function _Wd(){_Wd=_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(ee,i),t.append(D,e[D]);_e$headers=e.headers;n=_e$headers[$];s=_objectWithoutProperties(_e$headers,[$].map(_toPropertyKey));_context197.n=1;return fetch(e.url,{method:me,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 _Wd.apply(this,arguments);}function Xd(_x335,_x336){return _Xd.apply(this,arguments);}function _Xd(){_Xd=_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 _ref258=_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 Wd(s,e);case 1:r=_context198.v;o=s.type.startsWith(Gd)?V:ee;return _context198.a(2,Vd(r,o));}},_callee198);}));return function(_x367){return _ref258.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 _Xd.apply(this,arguments);}function Yd(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 Zd=function Zd(i,e,t){var n,s;switch(!e.conversationIdSet&&i.conversation_id&&(t(i.conversation_id),e.conversationIdSet=!0),i.event){case dn.MESSAGE:case dn.AGENT_MESSAGE:e.fullAnswer+=i.answer||"";break;case dn.WORKFLOW_FINISHED:!e.fullAnswer&&(s=(n=i.data)==null?void 0:n.outputs)!=null&&s.answer&&(e.fullAnswer=i.data.outputs.answer);break;case dn.ERROR:e.errorMessage=i.message||dn.ERROR;break;}};function Jd(_x337,_x338){return _Jd.apply(this,arguments);}function _Jd(){_Jd=_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=Kd(r);o&&Zd(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 _Jd.apply(this,arguments);}var Qd=function Qd(i){return _defineProperty(_defineProperty({},$,J),ce,"".concat(xe).concat(i));},eh=function eh(i,e,t,n){var s=i;s[f]?s[f].message===di?n(de):n(Be):"user_input_form"in i||"opening_statement"in i||"file_upload"in i?t(e):n(Be);},th=function th(i){return fe("".concat(i,"/parameters"),le,eh);};var nh=/*#__PURE__*/function(_M33){function nh(e){var _ref239,_this83$maxMessages;var _this83;_classCallCheck(this,nh);var r;var t=w(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,nh,[e,th(s),Qd,n]),_this83.insertKeyPlaceholderText=_this83.genereteAPIKeyName("Dify"),_this83.keyHelpUrl="https://docs.dify.ai/en/use-dify/publish/developing-with-apis",_this83.permittedErrorPrefixes=[Ae],_this83._conversationId="",_this83._user=D,_this83._inputs={},_this83.url="".concat(s,"/chat-messages"),_this83._uploadUrl="".concat(s,"/").concat(y,"/upload"),_typeof(n)===F&&(n[D]&&(_this83._user=n[D]),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?Os.STREAMING:Os.BLOCKING;return _this83;}_inherits(nh,_M33);return _createClass(nh,[{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},D,this._user);return this._conversationId&&(a.conversation_id=this._conversationId),n&&n.length>0&&(a[y]=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 Xd(n,_defineProperty(_defineProperty({url:this._uploadUrl},D,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===Os.BLOCKING&&!this.stream?Yd(e,t):Jd(e,t));}},_callee180,this);}));function extractResultData(_x342){return _extractResultData43.apply(this,arguments);}return extractResultData;}()}]);}(M);var sh=/*#__PURE__*/function(){function sh(){_classCallCheck(this,sh);}return _createClass(sh,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 _s(e);if(t){if(t.openAI)return t.openAI[Z]?new zi(e):t.openAI.speechToText?new ji(e):t.openAI.textToSpeech?new Hi(e):t.openAI.assistant?new ar(e):t.openAI.realtime?new Ui(e):t.openAI.completions?new Zs(e):new Js(e);if(t.assemblyAI)return new cr(e);if(t.cohere)return new ei(e);if(t.huggingFace)return t.huggingFace.textGeneration?new Al(e):t.huggingFace.summarization?new Cl(e):t.huggingFace.translation?new Rl(e):t.huggingFace.fillMask?new Il(e):t.huggingFace.questionAnswer?new wl(e):t.huggingFace.audioSpeechRecognition?new xl(e):t.huggingFace.audioClassification?new vl(e):t.huggingFace.imageClassification?new El(e):new Tl(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new lr(e);if(t.azure.openAI.assistant)return new Di(e);}if(t.azure.speechToText)return new Gi(e);if(t.azure.textToSpeech)return new qi(e);if(t.azure.summarization)return new $i(e);if(t.azure.translation)return new Yl(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new zs(e):t.stabilityAI.imageToImageUpscale?new qs(e):t.stabilityAI.imageToImageMasking?new Gs(e):new Vs(e);if(t.mistral)return new dr(e);if(t.gemini)return new ur(e);if(t.claude)return new ti(e);if(t.deepSeek)return new gd(e);if(t.miniMax)return new vd(e);if(t.openRouter)return new rs(e);if(t.kimi)return new fr(e);if(t.x)return t.x[Z]?new Ki(e):new qd(e);if(t.qwen)return new pr(e);if(t.together)return t.together[Z]?new ed(e):t.together.textToSpeech?new Ll(e):new td(e);if(t.bigModel)return t.bigModel[Z]?new Zl(e):t.bigModel.textToSpeech?new kl(e):new Qs(e);if(t.groq)return t.groq.textToSpeech?new Ql(e):new hr(e);if(t.perplexity)return new cd(e);if(t.ollama)return new Vi(e);if(t.openWebUI)return new ud(e);if(t.dify)return new nh(e);}return n&&Object.keys(n).length>0&&!s?new sn(e):new sn(e,void 0,s||!0);}}]);}();var Sr=/*#__PURE__*/_createClass(function Sr(){_classCallCheck(this,Sr);});Sr.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 Wi=Sr;function L(i){return function(e,t){Object.defineProperty(e,t,{});var n=e.constructor,s=t.toLocaleLowerCase();n._attributes_[s]=Wi.attibutes[i],n._attributeToProperty_[s]=t;};}var ih="deep-chat-downwards-mode",rh="deep-chat-upwards-mode",Pn="submit-button",ks="loading-button",Ln="disabled-button",Wr="text-input-container-start-adjustment",Xr="text-input-container-end-adjustment",Yr="text-input-container-start-small-adjustment",Zr="text-input-container-end-small-adjustment";var mr=/*#__PURE__*/function(){function mr(e){_classCallCheck(this,mr);this._isDisplayed=!1,this._elementRef=this.createIntroPanelWithChild(e),this._isDisplayed=!0;}return _createClass(mr,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e){var t=mr.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=x();return e[m].add("intro-panel"),Object.assign(e[v]),e;}}]);}();var oh="<?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>",Ce=/*#__PURE__*/function(){function Ce(){_classCallCheck(this,Ce);}return _createClass(Ce,null,[{key:"createImage",value:function createImage(e,t){var n=new Image();return n[C]=e[C],t&&_e.scrollDownOnImageLoad(n[C],t),_e.processContent(V,n,n[C],e.name);}// WORK - image still does not scroll down when loaded
203
+ },{key:"createImageMessage",value:function createImageMessage(e,t,n,s){var r=e.createNewMessageElement("",n),o=s?e.scrollToFirstElement.bind(e,n,s):void 0,a=Ce.createImage(t,o);return r.bubbleElement.appendChild(a),r.bubbleElement[m].add(Ce.IMAGE_BUBBLE_CLASS),{type:V,elements:r};}},{key:"createAudioElement",value:function createAudioElement(e,t){var n=x(j);return n[C]=e[C],n[m].add("audio-player"),n.controls=!0,Ue.IS_SAFARI&&(n[m].add("audio-player-safari"),n[m].add(t===D?"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=Ce.createAudioElement(t,n),o=e.createMessageElementsOnOrientation("",n,s);return o.bubbleElement.appendChild(r),o.bubbleElement[m].add(Ce.AUDIO_BUBBLE_CLASS),{type:j,elements:o,audioElement:r};}},{key:"createAnyFile",value:function createAnyFile(e){var t=x();t[m].add("any-file-message-contents");var n=x();n[m].add("any-file-message-icon-container");var s=Ct.createSVGElement(oh);s[m].add("any-file-message-icon"),n.appendChild(s);var r=x();return r[m].add("any-file-message-text"),r.textContent=e.name||ee,t.appendChild(n),t.appendChild(r),_e.processContent(Jt,t,e[C],r.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,n,s){var r=e.createMessageElementsOnOrientation("",n,s),o=Ce.createAnyFile(t);return r.bubbleElement[m].add(Ce.ANY_FILE_BUBBLE_CLASS),r.bubbleElement.appendChild(o),{type:ee,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=_e.removeFileRef(o)),_e.isAudioFile(o)){var l=Ce.createNewAudioMessage(e,o,n,r),d=(c=e.textToSpeech)==null?void 0:c.audio;return d&&(d.autoPlay&&Ce.autoPlayAudio(l.audioElement),typeof d.displayAudio=="boolean"&&!d.displayAudio)?void 0:l;}return _e.isImageFile(o)?Ce.createImageMessage(e,o,n,!r&&s&&a===0):Ce.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){Ce.createMessages(e,t,n,s,r).filter(function(a){return a!==void 0;}).forEach(function(_ref240){var a=_ref240.type,c=_ref240.elements;_e.addMessage(e,c,a,n,r);});}}]);}();Ce.IMAGE_BUBBLE_CLASS="image-message",Ce.AUDIO_BUBBLE_CLASS="audio-message",Ce.ANY_FILE_BUBBLE_CLASS="any-file-message";var ni=Ce;var Xe=/*#__PURE__*/function(){function Xe(){_classCallCheck(this,Xe);}return _createClass(Xe,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][y])==null||n.forEach(function(s){Xe.removeElements(e.messageElementRefs,s);}),delete t[0][y],delete t[1][y];}},{key:"removeTextHTMLMessage",value:function removeTextHTMLMessage(e,t,n){var s=t[1][n];Xe.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][P])ft.overwriteElements(e,n,t[1][P]);else{var a=ft.create(e,n,t[0][S]),c=((r=t[1][y])==null?void 0:r[((s=t[1][y])==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][P]=a;}t[0][P]=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][S],r=ni.createMessages(e,n,s,!1),o=t[1][P],a=((u=t[1][y])==null?void 0:u[((p=t[1][y])==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(_ref241,_){var g=_ref241.type,b=_ref241.elements;var E;_e.setElementProps(e,b,g,s),(E=d.parentElement)==null||E.insertBefore(b.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(l+_,0,b);}),Xe.removeFilesMessages(e,t),t[1][y]=r.map(function(_ref242){var g=_ref242.elements;return g;}),t[0][y]=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][S]);else{var o=e.createElements(n,t[0][S]),a=((s=t[1][y])==null?void 0:s[0])||t[1][P];(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 Je.isActiveElement((t=e[h])==null?void 0:t.bubbleElement[m])||Je.isActiveElement((n=e[P])==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(Xe.isElementActive(s[1]))return console[f]("Cannot update a message that is being streamed");t[h]&&Xe.updateTextMessage(e,s,t[h]),t[y]?Xe.updateFileMessages(e,s,t[y]):Xe.removeFilesMessages(e,s),t[P]&&Xe.updateHTMLMessage(e,s,t[P]),!t[h]&&s[1][h]&&Xe.removeTextHTMLMessage(e,s,h),!t[P]&&s[1][P]&&Xe.removeTextHTMLMessage(e,s,P);var r=e.messageElementRefs,o=e.avatar,a=e.name;N.classifyRoleMessages(r),N.resetAllRoleElements(r,o,a);}else console[f]("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var ah=/*#__PURE__*/function(){function ah(){_classCallCheck(this,ah);}return _createClass(ah,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(K,"connect#connect-1) property or a popular service via [directConnection](").concat(K,"directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](").concat(K,"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(K,"modes#demo) property to true.");if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](".concat(K,"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.type==="function";})&&!r.function_handler)return"Please define the `function_handler` property inside the openAI [chat](".concat(K,"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(K,"connect#connect-1) object.");return null;}}]);}();var Je=/*#__PURE__*/function(_Qe){function Je(e,t,n){var _this86;_classCallCheck(this,Je);var a,c;_this86=_callSuper(this,Je,[e]);var s=t.permittedErrorPrefixes,r=t.demo;_this86._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this86._onClearMessages=nn.onClearMessages.bind(_this86,e),_this86._onError=nn.onError.bind(_this86,e),_this86._isLoadingMessageAllowed=Je.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(ae.processDemo(r),e.loadHistory),_this86.addIntroductoryMessages(e,t);var o=new bs(e,_this86,t);_this86._displayServiceErrorMessages=(c=e.errorMessages)==null?void 0:c.displayServiceErrorMessages,e.getMessages=function(){return N.deepCloneMessagesWithReferences(_this86.messageToElements.map(function(_ref243){var _ref244=_slicedToArray(_ref243,1),l=_ref244[0];return l;}));},e.clearMessages=_this86.clearMessages.bind(_this86,t),e.refreshMessages=_this86.refreshTextMessages.bind(_this86,e.remarkable),e.scrollToBottom=q.scrollToBottom.bind(_this86,_this86),e.addMessage=function(l,d){_this86.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(l,d){return Xe.update(_this86,l,d);},t.isWebModel()&&t.setUpMessages(_this86),e.textToSpeech&&vn.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(Je,_Qe);return _createClass(Je,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1],n=Qe.isLoadingMessage(t);if(!e&&n)this.removeLastMessage(),delete this._activeLoadingConfig;else{if(this._activeLoadingConfig&&n){var s=se.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&&wt.addMessage(this,!1),s!=null&&s.full&&wt.addMessage(this);}e.displayErrors&&(e.displayErrors[A]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage(ie,""),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=ah.getText(e,t);if(n){var s=this.createAndAppendNewMessageElement(n,Q);this.applyCustomStyles(s,Q,!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;N.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],Q):e!=null&&e[P]&&(n=ft.add(this,e[P],Q)),n&&(this.applyCustomStyles(n,Q,!1,(s=this.messageStyles)==null?void 0:s.intro),n.outerContainer[m].add(Qe.INTRO_CLASS),t&&(n.outerContainer[v].display="none")),n;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer[m].contains(Qe.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(ie,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[S],t,r),!s&&this.textToSpeech&&e[S]!==D&&vn.speak(e[h],this.textToSpeech));}},{key:"tryAddFileMessages",value:function tryAddFileMessages(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;e[y]&&Array.isArray(e[y])&&ni.addMessages(this,e[y],e[S],t,n);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e[P]!==void 0&&e[P]!==null){var s=ft.add(this,e[P],e[S],t,n);!n&&pt.isElementTemporary(s)&&delete e[P];}}// this should not be activated by streamed messages
208
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[S]!==D&&((c=this._hiddenAttachments)==null||c.removeHiddenFiles());var s=Je.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=q.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[S],o);}),t||(p=this.browserStorage)==null||p.addMessages(this.messageToElements.map(function(_ref246){var _ref247=_slicedToArray(_ref246,1),u=_ref247[0];return u;})),this.scrollButton&&s[S]!==D&&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[P]||e[y]&&e[y].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=N.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,r]);}n&&this.sendClientUpdate(e,s);}// prettier-ignore
209
209
  },{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(at.MESSAGE_CLASS)&&t.textContent===""||Je.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,b;(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[A])||"Error, please try again.",r=this.createMessageElementsOnOrientation(s,f,n);N.hideRoleElements(r.innerContainer,this.avatar,this.name);var o=r.bubbleElement,a=r.outerContainer;o[m].add(Bs),this.renderText(o,s);var c=Le.extractParticularSharedStyles(["fontSize","fontFamily"],(u=this.messageStyles)==null?void 0:u[A]);Le.applyCustomStylesToElements(r,!1,c),Le.applyCustomStylesToElements(r,!1,(g=this.messageStyles)==null?void 0:g[f]),n||this.appendOuterContainerElemet(a),this.textToSpeech&&vn.speak(s,this.textToSpeech),(b=this._onError)==null||b.call(this,s),setTimeout(function(){return q.scrollToBottom(_this90);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=Je.extractErrorMessages(e);for(var _n13=0;_n13<t.length;_n13+=1){var s=t[_n13];if(_typeof(s)===ye){if(this._displayServiceErrorMessages)return s;if(this._permittedErrorPrefixes){var r=Je.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,s);if(r)return r;}}}}}},{key:"removeError",value:function removeError(){this.isLastMessageError()&&N.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:Q;var n=this.createMessageElements("",t),s=n.bubbleElement;n.bubbleElement[m].add(ht.DOTS_CONTAINER_CLASS);var r=x();return r[m].add("loading-message-dots"),s.appendChild(r),ht.setDots(s,e),n;}// 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,b;(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[A])||"Error, please try again.",r=this.createMessageElementsOnOrientation(s,f,n);N.hideRoleElements(r.innerContainer,this.avatar,this.name);var o=r.bubbleElement,a=r.outerContainer;o[m].add(Ds),this.renderText(o,s);var c=Le.extractParticularSharedStyles(["fontSize","fontFamily"],(u=this.messageStyles)==null?void 0:u[A]);Le.applyCustomStylesToElements(r,!1,c),Le.applyCustomStylesToElements(r,!1,(g=this.messageStyles)==null?void 0:g[f]),n||this.appendOuterContainerElemet(a),this.textToSpeech&&vn.speak(s,this.textToSpeech),(b=this._onError)==null||b.call(this,s),setTimeout(function(){return q.scrollToBottom(_this90);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=Je.extractErrorMessages(e);for(var _n13=0;_n13<t.length;_n13+=1){var s=t[_n13];if(_typeof(s)===ye){if(this._displayServiceErrorMessages)return s;if(this._permittedErrorPrefixes){var r=Je.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,s);if(r)return r;}}}}}},{key:"removeError",value:function removeError(){this.isLastMessageError()&&N.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:Q;var n=this.createMessageElements("",t),s=n.bubbleElement;n.bubbleElement[m].add(ht.DOTS_CONTAINER_CLASS);var r=x();return r[m].add("loading-message-dots"),s.appendChild(r),ht.setDots(s,e),n;}// prettier-ignore
211
211
  },{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,c,l,d,p,u;if(Qe.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((a=this._activeLoadingConfig)==null?void 0:a[S])||Q,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[P],r=s?ft.createElements(this,s,t,!1):this.addDefaultLoadingMessage(n,t);this.appendOuterContainerElemet(r.outerContainer),r.bubbleElement[m].add(ht.BUBBLE_CLASS),this.applyCustomStyles(r,t,!1,n==null?void 0:n.styles),(u=(p=this.avatar)==null?void 0:p.getAvatarContainer(r.innerContainer))==null||u[m].add("loading-avatar-container"),!this.focusMode&&q.isScrollbarAtBottomOfElement(this.elementRef)&&q.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[P];e.innerHTML=n||"";}},{key:"populateIntroPanel",value:function populateIntroPanel(e){e&&(this._introPanel=new fr(e),se.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.type||n.type===Jt){var r=n[ee].name||ee;s({name:r,type:Jt,ref:n[ee]});}else{var _r8=new FileReader();_r8.readAsDataURL(n[ee]),_r8.onload=function(){var o=n[ee].name;s(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},C,_r8.result),"name",o),"type",n.type),"ref",n[ee]));};}});}))));}},_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){Je.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(Bs)&&l.remove();}),this.messageElementRefs=n;var s=this.messageToElements.filter(function(l){return l[1][h]&&Je.isActiveElement(l[1][h].bubbleElement[m])||l[1][P]&&Je.isActiveElement(l[1][P].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 _ref248;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===F?!1:!!e.displayLoadingBubble:(_ref248=_typeof(e.displayLoadingBubble)===F||e.displayLoadingBubble)!==null&&_ref248!==void 0?_ref248:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _n14=0;_n14<e.length;_n14+=1)if(t.startsWith(e[_n14]))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(ht.BUBBLE_CLASS)||e.contains(wt.CLASS)||e.contains(at.MESSAGE_CLASS):!1;}}]);}(Qe);var rs=/*#__PURE__*/function(){function rs(){_classCallCheck(this,rs);}return _createClass(rs,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t[En].length>0&&e[m].add("text-input-inner-start-adjustment"),t[dt].length>0&&e[m].add("text-input-inner-end-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,n){n[be].length===0&&n[Me].length>0?(e[0][m].add(Xr),t[m].add(Xr)):n[Me].length===0&&n[be].length>0&&(e[3][m].add(Zr),t[m].add(Zr));}// when submit is the only button
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[P];e.innerHTML=n||"";}},{key:"populateIntroPanel",value:function populateIntroPanel(e){e&&(this._introPanel=new mr(e),se.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.type||n.type===Jt){var r=n[ee].name||ee;s({name:r,type:Jt,ref:n[ee]});}else{var _r8=new FileReader();_r8.readAsDataURL(n[ee]),_r8.onload=function(){var o=n[ee].name;s(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},C,_r8.result),"name",o),"type",n.type),"ref",n[ee]));};}});}))));}},_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){Je.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(Ds)&&l.remove();}),this.messageElementRefs=n;var s=this.messageToElements.filter(function(l){return l[1][h]&&Je.isActiveElement(l[1][h].bubbleElement[m])||l[1][P]&&Je.isActiveElement(l[1][P].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 _ref248;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===F?!1:!!e.displayLoadingBubble:(_ref248=_typeof(e.displayLoadingBubble)===F||e.displayLoadingBubble)!==null&&_ref248!==void 0?_ref248:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _n14=0;_n14<e.length;_n14+=1)if(t.startsWith(e[_n14]))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(ht.BUBBLE_CLASS)||e.contains(wt.CLASS)||e.contains(at.MESSAGE_CLASS):!1;}}]);}(Qe);var os=/*#__PURE__*/function(){function os(){_classCallCheck(this,os);}return _createClass(os,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t[En].length>0&&e[m].add("text-input-inner-start-adjustment"),t[dt].length>0&&e[m].add("text-input-inner-end-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,n){n[be].length===0&&n[Me].length>0?(e[0][m].add(Yr),t[m].add(Yr)):n[Me].length===0&&n[be].length>0&&(e[3][m].add(Zr),t[m].add(Zr));}// when submit is the only button
214
214
  // 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[En].length>0||n[dt].length>0)){if(n[be].length===0&&n[Me].length>0)return e[0][m].add(Kr),t[m].add(Kr),n[Me].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});if(n[Me].length===0&&n[be].length>0)return e[3][m].add(Wr),t[m].add(Wr),n[be].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});}}// prettier-ignore
216
- },{key:"set",value:function set(e,t,n,s){!!rs.adjustOutsideSubmit(t,n,s)||rs.adjustForOutsideButton(t,n,s),rs.adjustInputPadding(e,s);}}]);}();var An=/*#__PURE__*/function(){function An(){_classCallCheck(this,An);}return _createClass(An,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var n=x();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===Me?0:e===En?1:e===dt?2:3;}},{key:"addButton",value:function addButton(e,t,n){t[m].add(n);var s=An.getContainerIndex(n);e[s].appendChild(t),s===3&&t[m].add(be);}}]);}();var Yr=["camera","gifs","images","audio","mixedFiles","submit","microphone"],ah="<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",Te=/*#__PURE__*/function(){function Te(){_classCallCheck(this,Te);}return _createClass(Te,null,[{key:"addHighlightEvents",value:function addHighlightEvents(e,t){t.addEventListener("mouseenter",function(n){e.highlightedItem=n.target;}),t.addEventListener("mouseleave",function(){e.highlightedItem=void 0;});}},{key:"addItemEvents",value:function addItemEvents(e,t,n,s){At.add(t,s),t.addEventListener(X,function(){n[X]();}),Te.addHighlightEvents(e,t);}},{key:"createItemText",value:function createItemText(e,t){var n=x();return Object.assign(n[v],t),n[m].add(Te.TEXT_CLASS),n.textContent=e||"File",n;}},{key:"createItemIcon",value:function createItemIcon(e,t){var n=x();return Object.assign(n[v],t),n[m].add(Te.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.svg)==null?void 0:p.content)==="";});c[m].contains(gt.INPUT_BUTTON_INNER_TEXT_CLASS)?(l||t.appendChild(Te.createItemIcon(o,n==null?void 0:n.iconContainer)),t.appendChild(Te.createItemText(c.textContent,n==null?void 0:n[h]))):(l||t.appendChild(Te.createItemIcon(s.children[0],n==null?void 0:n.iconContainer)),t.appendChild(Te.createItemText(r,n==null?void 0:n[h])));}},{key:"createItem",value:function createItem(e,t,n){var o;var s=x();Object.assign(s[v],(o=n==null?void 0:n.item)==null?void 0:o[A]),Te.populateItem(t,s,n),s[m].add(Te.MENU_ITEM_CLASS),s.tabIndex=0;var r=t.elementRef;if(t.isCustom)t.setDropupItem(e,s);else{var a=re.processStateful((n==null?void 0:n.item)||{});Te.addItemEvents(e,s,r,a);}return s;}}]);}();Te.MENU_ITEM_CLASS="dropup-menu-item",Te.CUSTOM_BUTTON_ITEM_CLASS="dropup-menu-item-custom-button",Te.TEXT_CLASS="dropup-menu-item-text",Te.ICON_CLASS="dropup-menu-item-icon";var rt=Te;var he=/*#__PURE__*/function(_cn2){// prettier-ignore
217
- function he(e,t,n,s){var _this91;_classCallCheck(this,he);var c,l,d,p,u,g;var r=((p=(d=(l=(c=e==null?void 0:e.styles)==null?void 0:c.button)==null?void 0:l[A])==null?void 0:d[h])==null?void 0:p.content)||"Custom ".concat(t),o=ah,a=ct.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this91=_callSuper(this,he,[he.createButtonElement(),o,e==null?void 0:e.position,a,((u=e==null?void 0:e.styles)==null?void 0:u.button)||a&&{},r]),_this91._state=A,_this91.isCustom=!0,_this91._innerElements=_this91.createInnerElementsForStates(_this91.customStyles),_this91._menuStyles=s,_this91._onClick=e.onClick,_this91._dropupStyles=(g=e.styles)==null?void 0:g.dropup,_this91.setSetState(e),_this91.addClickListener(n),_this91.changeState(e.initialState,!0);return _this91;}_inherits(he,_cn2);return _createClass(he,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="custom-icon",n=this.createInnerElements(t,A,e);return _defineProperty(_defineProperty(_defineProperty({},A,n),U,this.genStateInnerElements(t,U,n,e)),H,this.genStateInnerElements(t,H,n,e));}},{key:"setSetState",value:function setSetState(e){var _this92=this;e.setState=function(t){t===A&&_this92.changeToDefault(),t===U&&_this92.changeToActive(),t===H&&_this92.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this93=this;q.assignButtonEvents(this.elementRef,function(){var n;var t=(n=_this93._onClick)==null?void 0:n.call(_this93,_this93._state);e==null||e(),(t===A||t===U||t===H)&&_this93.changeState(t);});}},{key:"changeState",value:function changeState(e,t){e===H?this.changeToDisabled(t):e===U?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 _n15=t.find(function(s){return s[m].contains(rt.TEXT_CLASS);});_n15&&Object.assign(_n15[v],e[h]);}if(e!=null&&e.iconContainer){var _n16=t.find(function(s){return s[m].contains(rt.ICON_CLASS);});_n16&&Object.assign(_n16[v],e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var n,s,r;this.elementRef=se.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((n=e==null?void 0:e.svg)==null?void 0:n.content)===""||this.elementRef.appendChild(rt.createItemIcon(this.svg,(s=this._menuStyles)==null?void 0:s.iconContainer)),this.elementRef.appendChild(rt.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),rt.addHighlightEvents(this._menu,this.elementRef),this.applyDropupContentStyles(e),Object.assign(this.elementRef[v],(s=e==null?void 0:e.item)==null?void 0:s[A]);var n=re.processStateful((e==null?void 0:e.item)||{});At.add(this.elementRef,n),this.addClickListener();}},{key:"changeToDefault",value:function changeToDefault(e){var t,n,s,r,o,a;!e&&this._state===A||(this.elementRef[m].contains(rt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[A],(n=this.customStyles)==null?void 0:n[A]):(this.changeElementsByState(this._innerElements[A]),(s=this.customStyles)!=null&&s[U]&&ve.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[U]),(o=this.customStyles)!=null&&o[H]&&ve.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[H]),this.reapplyStateStyle(A,[U,H])),this.elementRef[m].remove(he.DISABLED_CONTAINER_CLASS,he.ACTIVE_CONTAINER_CLASS),this.elementRef[m].add(he.DEFAULT_CONTAINER_CLASS),ue.removeAriaDisabled(this.elementRef),this._state=A);}},{key:"changeToActive",value:function changeToActive(e){var t,n;!e&&this._state===U||(this.elementRef[m].contains(rt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[U],(n=this.customStyles)==null?void 0:n[U]):(this.changeElementsByState(this._innerElements[U]),this.reapplyStateStyle(U,[H,A])),this.elementRef[m].remove(he.DISABLED_CONTAINER_CLASS,he.DEFAULT_CONTAINER_CLASS),this.elementRef[m].add(he.ACTIVE_CONTAINER_CLASS),ue.removeAriaDisabled(this.elementRef),this._state=U);}},{key:"changeToDisabled",value:function changeToDisabled(e){var t,n,s,r,o,a;!e&&this._state===H||(this.elementRef[m].contains(rt.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]),(s=this.customStyles)!=null&&s[U]&&ve.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[U]),(o=this.customStyles)!=null&&o[A]&&ve.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[A]),this.reapplyStateStyle(H,[A,U])),this.elementRef[m].remove(he.ACTIVE_CONTAINER_CLASS,he.DEFAULT_CONTAINER_CLASS),this.elementRef[m].add(he.DISABLED_CONTAINER_CLASS),ue.addAriaDisabled(this.elementRef),this._state=H);}// 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.svg)==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 _ss$parseSVGTextEleme4=ss.parseSVGTextElements(n),u=_ss$parseSVGTextEleme4.svg,g=_ss$parseSVGTextEleme4[h],_ss$parseSVGTextEleme5=ss.parseSVGTextElements(r),b=_ss$parseSVGTextEleme5.svg,_=_ss$parseSVGTextEleme5[h],E=[];he.addToInnerElements(E,o,u,b),he.addToInnerElements(E,a,g,_),r=E;}return r;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[m].add("input-button",he.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 he(o,a+1,s,r==null?void 0:r.menu)};t["".concat(he.INDICATOR_PREFIX).concat(a+1)]=c;});}}]);}(cn);he.INDICATOR_PREFIX="custom",he.BUTTON_CLASS="custom-button",he.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",he.DEFAULT_CONTAINER_CLASS="custom-button-container-default",he.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var Yt=he;var ch="<?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 _s=/*#__PURE__*/function(){function _s(){_classCallCheck(this,_s);}return _createClass(_s,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var n=e.elementRef,s=t?n.children[0]:n.children[n.children.length-1];_s.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("mouseleave")),r.dispatchEvent(new MouseEvent("mouseenter")),r.focus()):(t.dispatchEvent(new MouseEvent("mouseleave")),_s.focusItemWhenOnEdge(e,n));}}]);}();var mr=/*#__PURE__*/function(){function mr(e,t){var _this94=this;_classCallCheck(this,mr);var n;this._isOpen=!0,this._styles=t,this.elementRef=mr.createElement((n=this._styles)==null?void 0:n.container),this.close(),setTimeout(function(){return _this94.addWindowEvents(e);});}return _createClass(mr,[{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=rt.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
215
+ },{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,n){if(!(n[En].length>0||n[dt].length>0)){if(n[be].length===0&&n[Me].length>0)return e[0][m].add(Wr),t[m].add(Wr),n[Me].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});if(n[Me].length===0&&n[be].length>0)return e[3][m].add(Xr),t[m].add(Xr),n[be].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});}}// prettier-ignore
216
+ },{key:"set",value:function set(e,t,n,s){!!os.adjustOutsideSubmit(t,n,s)||os.adjustForOutsideButton(t,n,s),os.adjustInputPadding(e,s);}}]);}();var wn=/*#__PURE__*/function(){function wn(){_classCallCheck(this,wn);}return _createClass(wn,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var n=x();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===Me?0:e===En?1:e===dt?2:3;}},{key:"addButton",value:function addButton(e,t,n){t[m].add(n);var s=wn.getContainerIndex(n);e[s].appendChild(t),s===3&&t[m].add(be);}}]);}();var Jr=["camera","gifs","images","audio","mixedFiles","submit","microphone"],ch="<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",Te=/*#__PURE__*/function(){function Te(){_classCallCheck(this,Te);}return _createClass(Te,null,[{key:"addHighlightEvents",value:function addHighlightEvents(e,t){t.addEventListener("mouseenter",function(n){e.highlightedItem=n.target;}),t.addEventListener("mouseleave",function(){e.highlightedItem=void 0;});}},{key:"addItemEvents",value:function addItemEvents(e,t,n,s){At.add(t,s),t.addEventListener(X,function(){n[X]();}),Te.addHighlightEvents(e,t);}},{key:"createItemText",value:function createItemText(e,t){var n=x();return Object.assign(n[v],t),n[m].add(Te.TEXT_CLASS),n.textContent=e||"File",n;}},{key:"createItemIcon",value:function createItemIcon(e,t){var n=x();return Object.assign(n[v],t),n[m].add(Te.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.svg)==null?void 0:p.content)==="";});c[m].contains(gt.INPUT_BUTTON_INNER_TEXT_CLASS)?(l||t.appendChild(Te.createItemIcon(o,n==null?void 0:n.iconContainer)),t.appendChild(Te.createItemText(c.textContent,n==null?void 0:n[h]))):(l||t.appendChild(Te.createItemIcon(s.children[0],n==null?void 0:n.iconContainer)),t.appendChild(Te.createItemText(r,n==null?void 0:n[h])));}},{key:"createItem",value:function createItem(e,t,n){var o;var s=x();Object.assign(s[v],(o=n==null?void 0:n.item)==null?void 0:o[A]),Te.populateItem(t,s,n),s[m].add(Te.MENU_ITEM_CLASS),s.tabIndex=0;var r=t.elementRef;if(t.isCustom)t.setDropupItem(e,s);else{var a=re.processStateful((n==null?void 0:n.item)||{});Te.addItemEvents(e,s,r,a);}return s;}}]);}();Te.MENU_ITEM_CLASS="dropup-menu-item",Te.CUSTOM_BUTTON_ITEM_CLASS="dropup-menu-item-custom-button",Te.TEXT_CLASS="dropup-menu-item-text",Te.ICON_CLASS="dropup-menu-item-icon";var rt=Te;var he=/*#__PURE__*/function(_cn2){// prettier-ignore
217
+ function he(e,t,n,s){var _this91;_classCallCheck(this,he);var c,l,d,p,u,g;var r=((p=(d=(l=(c=e==null?void 0:e.styles)==null?void 0:c.button)==null?void 0:l[A])==null?void 0:d[h])==null?void 0:p.content)||"Custom ".concat(t),o=ch,a=ct.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this91=_callSuper(this,he,[he.createButtonElement(),o,e==null?void 0:e.position,a,((u=e==null?void 0:e.styles)==null?void 0:u.button)||a&&{},r]),_this91._state=A,_this91.isCustom=!0,_this91._innerElements=_this91.createInnerElementsForStates(_this91.customStyles),_this91._menuStyles=s,_this91._onClick=e.onClick,_this91._dropupStyles=(g=e.styles)==null?void 0:g.dropup,_this91.setSetState(e),_this91.addClickListener(n),_this91.changeState(e.initialState,!0);return _this91;}_inherits(he,_cn2);return _createClass(he,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="custom-icon",n=this.createInnerElements(t,A,e);return _defineProperty(_defineProperty(_defineProperty({},A,n),U,this.genStateInnerElements(t,U,n,e)),H,this.genStateInnerElements(t,H,n,e));}},{key:"setSetState",value:function setSetState(e){var _this92=this;e.setState=function(t){t===A&&_this92.changeToDefault(),t===U&&_this92.changeToActive(),t===H&&_this92.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this93=this;q.assignButtonEvents(this.elementRef,function(){var n;var t=(n=_this93._onClick)==null?void 0:n.call(_this93,_this93._state);e==null||e(),(t===A||t===U||t===H)&&_this93.changeState(t);});}},{key:"changeState",value:function changeState(e,t){e===H?this.changeToDisabled(t):e===U?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 _n15=t.find(function(s){return s[m].contains(rt.TEXT_CLASS);});_n15&&Object.assign(_n15[v],e[h]);}if(e!=null&&e.iconContainer){var _n16=t.find(function(s){return s[m].contains(rt.ICON_CLASS);});_n16&&Object.assign(_n16[v],e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var n,s,r;this.elementRef=se.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((n=e==null?void 0:e.svg)==null?void 0:n.content)===""||this.elementRef.appendChild(rt.createItemIcon(this.svg,(s=this._menuStyles)==null?void 0:s.iconContainer)),this.elementRef.appendChild(rt.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),rt.addHighlightEvents(this._menu,this.elementRef),this.applyDropupContentStyles(e),Object.assign(this.elementRef[v],(s=e==null?void 0:e.item)==null?void 0:s[A]);var n=re.processStateful((e==null?void 0:e.item)||{});At.add(this.elementRef,n),this.addClickListener();}},{key:"changeToDefault",value:function changeToDefault(e){var t,n,s,r,o,a;!e&&this._state===A||(this.elementRef[m].contains(rt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[A],(n=this.customStyles)==null?void 0:n[A]):(this.changeElementsByState(this._innerElements[A]),(s=this.customStyles)!=null&&s[U]&&ve.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[U]),(o=this.customStyles)!=null&&o[H]&&ve.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[H]),this.reapplyStateStyle(A,[U,H])),this.elementRef[m].remove(he.DISABLED_CONTAINER_CLASS,he.ACTIVE_CONTAINER_CLASS),this.elementRef[m].add(he.DEFAULT_CONTAINER_CLASS),ue.removeAriaDisabled(this.elementRef),this._state=A);}},{key:"changeToActive",value:function changeToActive(e){var t,n;!e&&this._state===U||(this.elementRef[m].contains(rt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[U],(n=this.customStyles)==null?void 0:n[U]):(this.changeElementsByState(this._innerElements[U]),this.reapplyStateStyle(U,[H,A])),this.elementRef[m].remove(he.DISABLED_CONTAINER_CLASS,he.DEFAULT_CONTAINER_CLASS),this.elementRef[m].add(he.ACTIVE_CONTAINER_CLASS),ue.removeAriaDisabled(this.elementRef),this._state=U);}},{key:"changeToDisabled",value:function changeToDisabled(e){var t,n,s,r,o,a;!e&&this._state===H||(this.elementRef[m].contains(rt.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]),(s=this.customStyles)!=null&&s[U]&&ve.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[U]),(o=this.customStyles)!=null&&o[A]&&ve.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[A]),this.reapplyStateStyle(H,[A,U])),this.elementRef[m].remove(he.ACTIVE_CONTAINER_CLASS,he.DEFAULT_CONTAINER_CLASS),this.elementRef[m].add(he.DISABLED_CONTAINER_CLASS),ue.addAriaDisabled(this.elementRef),this._state=H);}// 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.svg)==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 _is$parseSVGTextEleme4=is.parseSVGTextElements(n),u=_is$parseSVGTextEleme4.svg,g=_is$parseSVGTextEleme4[h],_is$parseSVGTextEleme5=is.parseSVGTextElements(r),b=_is$parseSVGTextEleme5.svg,_=_is$parseSVGTextEleme5[h],E=[];he.addToInnerElements(E,o,u,b),he.addToInnerElements(E,a,g,_),r=E;}return r;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[m].add("input-button",he.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 he(o,a+1,s,r==null?void 0:r.menu)};t["".concat(he.INDICATOR_PREFIX).concat(a+1)]=c;});}}]);}(cn);he.INDICATOR_PREFIX="custom",he.BUTTON_CLASS="custom-button",he.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",he.DEFAULT_CONTAINER_CLASS="custom-button-container-default",he.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var Zt=he;var lh="<?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 vs=/*#__PURE__*/function(){function vs(){_classCallCheck(this,vs);}return _createClass(vs,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var n=e.elementRef,s=t?n.children[0]:n.children[n.children.length-1];vs.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("mouseleave")),r.dispatchEvent(new MouseEvent("mouseenter")),r.focus()):(t.dispatchEvent(new MouseEvent("mouseleave")),vs.focusItemWhenOnEdge(e,n));}}]);}();var gr=/*#__PURE__*/function(){function gr(e,t){var _this94=this;_classCallCheck(this,gr);var n;this._isOpen=!0,this._styles=t,this.elementRef=gr.createElement((n=this._styles)==null?void 0:n.container),this.close(),setTimeout(function(){return _this94.addWindowEvents(e);});}return _createClass(gr,[{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=rt.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
220
220
  },{key:"addWindowEvents",value:function addWindowEvents(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener(X,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(X,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===ge.ESCAPE?(this.close(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===ge.ENTER?((s=this.highlightedItem)==null||s[X](),(r=this.highlightedItem)==null||r.dispatchEvent(new MouseEvent("mouseleave"))):t.key===ge.ARROW_DOWN?_s.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],!0):t.key===ge.ARROW_UP&&_s.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[0],!1));}}],[{key:"createElement",value:function createElement(e){var t=x();return t.id=Ye,Object.assign(t[v],e),t;}}]);}();var Kt=/*#__PURE__*/function(_cn3){function Kt(e,t){var _this95;_classCallCheck(this,Kt);var r,o;var n=ct.tryCreateConfig("Options",(r=t==null?void 0:t.button)==null?void 0:r.tooltip);_this95=_callSuper(this,Kt,[Kt.createButtonElement(),ch,void 0,n,{styles:(o=t==null?void 0:t.button)==null?void 0:o.styles}]);var s=_this95.createInnerElementsForStates(_this95.customStyles);_this95._menu=new mr(e,t==null?void 0:t.menu),_this95.addClickEvent(),_this95.buttonContainer=Kt.createButtonContainer(),_this95.changeElementsByState(s.styles),_this95.buttonContainer.appendChild(_this95.elementRef),_this95.elementRef[m].add(Kt.BUTTON_ICON_CLASS),_this95.buttonContainer.appendChild(_this95._menu.elementRef),_this95.reapplyStateStyle("styles"),_this95.addContainerEvents(e);return _this95;}_inherits(Kt,_cn3);return _createClass(Kt,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("dropup-icon","styles",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===ge.ENTER&&setTimeout(function(){_this96._menu.toggle();var t=_this96._menu.elementRef.children[0];t.focus(),t.dispatchEvent(new MouseEvent("mouseenter"));});};}},{key:"addItem",value:function addItem(e){this._menu.addItem(e);}},{key:"addContainerEvents",value:function addContainerEvents(e){var _this97=this;e.addEventListener(X,function(t){var n=t.target[m];!n.contains(Kt.BUTTON_ICON_CLASS)&&!n.contains(Yt.DISABLED_CONTAINER_CLASS)&&_this97._menu.close();});}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[m].add("input-button"),e;}},{key:"createButtonContainer",value:function createButtonContainer(){var e=x();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?ae.processPosition((s=t==null?void 0:t.button)==null?void 0:s.position):e[Me].length>0&&e[be].length===0?be:Me;}}]);}(cn);Kt.BUTTON_ICON_CLASS="dropup-button";var ni=Kt;var Pe=/*#__PURE__*/function(){function Pe(){_classCallCheck(this,Pe);}return _createClass(Pe,null,[{key:"addToDropup",value:// prettier-ignore
222
- function addToDropup(e,t,n,s){var r=new ni(n,s);Yr.forEach(function(a){var c=t[Ye].findIndex(function(d){return d.buttonType===a;}),l=t[Ye][c];l&&(r.addItem(l.button),t[Ye].splice(c,1));}),t[Ye].forEach(function(_ref250){var a=_ref250.button;return r.addItem(a);});var o=ni.getPosition(t,s);An.addButton(e,r.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){[En,dt,Me,be].forEach(function(s){var r=s;t[r].forEach(function(o){An.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({},Ye,[]),Me,[]),En,[]),dt,[]),be,[]);}// prettier-ignore
223
- },{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Pe.createPositionsToButtonsObj();Object.keys(e).forEach(function(s){var o;var r=(o=e[s])==null?void 0:o.button.position;r&&Pe.setPosition(e,s,t[r]);}),t[dt].length===0&&e.submit&&Pe.setPosition(e,"submit",t[dt]),t[be].length===0&&(e.submit?Pe.setPosition(e,"submit",t[be]):e.microphone?Pe.setPosition(e,it,t[be]):e.camera?Pe.setPosition(e,Ne,t[be]):e["".concat(Yt.INDICATOR_PREFIX,"1")]&&Pe.setPosition(e,"".concat(Yt.INDICATOR_PREFIX,"1"),t[be])),e.submit&&Pe.setPosition(e,"submit",t[Me].length===0?t[Me]:t[dt]),e.microphone&&Pe.setPosition(e,it,t[Me].length===0?t[Me]:t[dt]);var n=Object.keys(e);return n.length>1||t[Ye].length>0?(Yr.forEach(function(s){e[s]&&t[Ye].push(_objectSpread(_objectSpread({},e[s]),{},{buttonType:s}));}),n.forEach(function(s){var r=s;r.startsWith(Yt.INDICATOR_PREFIX)&&e[r]&&t[Ye].push(_objectSpread(_objectSpread({},e[r]),{},{customType:r}));})):n.length===1&&Pe.setPosition(e,n[0],t[be].length===0?t[be]:t[Me]),t;}// prettier-ignore
224
- },{key:"addButtons",value:function addButtons(e,t,n,s){var r=Pe.generatePositionToButtons(t);return Pe.addToSideContainer(e,r),r[Ye].length>0&&Pe.addToDropup(e,r,n,s),r;}}]);}();var lh="<?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>",dh="<?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",hh="<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>",uh="<?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",ph=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},Y,{id:"upload-images-icon",svgString:dh,dropupText:"Image"}),bn,{id:"upload-gifs-icon",svgString:uh,dropupText:"GIF"}),j,{id:"upload-audio-icon",svgString:hh,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:lh,dropupText:"File"});var mi=/*#__PURE__*/function(_cn4){function mi(e){var _this98;_classCallCheck(this,mi);(e==null?void 0:e.position)===Ye&&(e.position=be);var t=ct.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this98=_callSuper(this,mi,[mi.createMicrophoneElement(),Vo,e==null?void 0:e.position,t,e]),_this98.isActive=!1,_this98._innerElements=_this98.createInnerElementsForStates(_this98.customStyles),_this98.changeToDefault();return _this98;}_inherits(mi,_cn4);return _createClass(mi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},A,this.createInnerElements(t,A,e)),U,this.createInnerElements(t,U,e)),"unsupported",this.createInnerElements(t,"unsupported",e)),"commandMode",this.createInnerElements(t,"commandMode",e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements[U]),this.toggleIconFilter(U),this.reapplyStateStyle(U,[A,"commandMode"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[A]),this.toggleIconFilter(A),this.reapplyStateStyle(A,[U,"commandMode"]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements.commandMode),this.toggleIconFilter("command"),this.reapplyStateStyle("commandMode",[U]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements.unsupported),this.elementRef[m].add("unsupported-microphone"),this.reapplyStateStyle("unsupported",[U]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()==="svg")switch(e){case A:t[m].remove("active-microphone-icon","command-microphone-icon"),t[m].add("default-microphone-icon");break;case U: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=x();return e.id="microphone-button",e[m].add("input-button"),e;}}]);}(cn);function fh(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i["default"]:i;}var ks={},Ln={},On={},Nn={},Bn={},Jr;function gi(){if(Jr)return Bn;Jr=1,Object.defineProperty(Bn,"__esModule",{value:!0}),Bn.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 Bn.Text=i,i.FIRST_CHAR_REGEX=/\S/,i.DOUBLE_LINE=/\n\n/g,i.ONE_LINE=/\n/g,Bn;}var Qr;function ea(){if(Qr)return Nn;Qr=1,Object.defineProperty(Nn,"__esModule",{value:!0}),Nn.Translate=void 0;var i=gi();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 Nn.Translate=e,Nn;}var eo;function mh(){if(eo)return On;eo=1,Object.defineProperty(On,"__esModule",{value:!0}),On.WebSpeechTranscript=void 0;var i=ea();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 On.WebSpeechTranscript=e,On;}var Dn={},to;function gr(){if(to)return Dn;to=1,Object.defineProperty(Dn,"__esModule",{value:!0}),Dn.Browser=void 0;var i=/*#__PURE__*/_createClass(function i(){_classCallCheck(this,i);});return Dn.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;},Dn;}var Fn={},Un={},no;function gh(){if(no)return Un;no=1,Object.defineProperty(Un,"__esModule",{value:!0}),Un.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 Un.EventListeners=i,i.KEY_DOWN_TIMEOUT=null,Un;}var Hn={},so;function yh(){if(so)return Hn;so=1,Object.defineProperty(Hn,"__esModule",{value:!0}),Hn.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 Hn.PreResultUtils=i,Hn;}var jn={},$n={},io;function ta(){if(io)return $n;io=1,Object.defineProperty($n,"__esModule",{value:!0}),$n.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
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===ge.ESCAPE?(this.close(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===ge.ENTER?((s=this.highlightedItem)==null||s[X](),(r=this.highlightedItem)==null||r.dispatchEvent(new MouseEvent("mouseleave"))):t.key===ge.ARROW_DOWN?vs.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],!0):t.key===ge.ARROW_UP&&vs.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[0],!1));}}],[{key:"createElement",value:function createElement(e){var t=x();return t.id=Ze,Object.assign(t[v],e),t;}}]);}();var Kt=/*#__PURE__*/function(_cn3){function Kt(e,t){var _this95;_classCallCheck(this,Kt);var r,o;var n=ct.tryCreateConfig("Options",(r=t==null?void 0:t.button)==null?void 0:r.tooltip);_this95=_callSuper(this,Kt,[Kt.createButtonElement(),lh,void 0,n,{styles:(o=t==null?void 0:t.button)==null?void 0:o.styles}]);var s=_this95.createInnerElementsForStates(_this95.customStyles);_this95._menu=new gr(e,t==null?void 0:t.menu),_this95.addClickEvent(),_this95.buttonContainer=Kt.createButtonContainer(),_this95.changeElementsByState(s.styles),_this95.buttonContainer.appendChild(_this95.elementRef),_this95.elementRef[m].add(Kt.BUTTON_ICON_CLASS),_this95.buttonContainer.appendChild(_this95._menu.elementRef),_this95.reapplyStateStyle("styles"),_this95.addContainerEvents(e);return _this95;}_inherits(Kt,_cn3);return _createClass(Kt,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("dropup-icon","styles",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===ge.ENTER&&setTimeout(function(){_this96._menu.toggle();var t=_this96._menu.elementRef.children[0];t.focus(),t.dispatchEvent(new MouseEvent("mouseenter"));});};}},{key:"addItem",value:function addItem(e){this._menu.addItem(e);}},{key:"addContainerEvents",value:function addContainerEvents(e){var _this97=this;e.addEventListener(X,function(t){var n=t.target[m];!n.contains(Kt.BUTTON_ICON_CLASS)&&!n.contains(Zt.DISABLED_CONTAINER_CLASS)&&_this97._menu.close();});}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[m].add("input-button"),e;}},{key:"createButtonContainer",value:function createButtonContainer(){var e=x();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?ae.processPosition((s=t==null?void 0:t.button)==null?void 0:s.position):e[Me].length>0&&e[be].length===0?be:Me;}}]);}(cn);Kt.BUTTON_ICON_CLASS="dropup-button";var si=Kt;var Pe=/*#__PURE__*/function(){function Pe(){_classCallCheck(this,Pe);}return _createClass(Pe,null,[{key:"addToDropup",value:// prettier-ignore
222
+ function addToDropup(e,t,n,s){var r=new si(n,s);Jr.forEach(function(a){var c=t[Ze].findIndex(function(d){return d.buttonType===a;}),l=t[Ze][c];l&&(r.addItem(l.button),t[Ze].splice(c,1));}),t[Ze].forEach(function(_ref250){var a=_ref250.button;return r.addItem(a);});var o=si.getPosition(t,s);wn.addButton(e,r.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){[En,dt,Me,be].forEach(function(s){var r=s;t[r].forEach(function(o){wn.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({},Ze,[]),Me,[]),En,[]),dt,[]),be,[]);}// prettier-ignore
223
+ },{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Pe.createPositionsToButtonsObj();Object.keys(e).forEach(function(s){var o;var r=(o=e[s])==null?void 0:o.button.position;r&&Pe.setPosition(e,s,t[r]);}),t[dt].length===0&&e.submit&&Pe.setPosition(e,"submit",t[dt]),t[be].length===0&&(e.submit?Pe.setPosition(e,"submit",t[be]):e.microphone?Pe.setPosition(e,it,t[be]):e.camera?Pe.setPosition(e,Ne,t[be]):e["".concat(Zt.INDICATOR_PREFIX,"1")]&&Pe.setPosition(e,"".concat(Zt.INDICATOR_PREFIX,"1"),t[be])),e.submit&&Pe.setPosition(e,"submit",t[Me].length===0?t[Me]:t[dt]),e.microphone&&Pe.setPosition(e,it,t[Me].length===0?t[Me]:t[dt]);var n=Object.keys(e);return n.length>1||t[Ze].length>0?(Jr.forEach(function(s){e[s]&&t[Ze].push(_objectSpread(_objectSpread({},e[s]),{},{buttonType:s}));}),n.forEach(function(s){var r=s;r.startsWith(Zt.INDICATOR_PREFIX)&&e[r]&&t[Ze].push(_objectSpread(_objectSpread({},e[r]),{},{customType:r}));})):n.length===1&&Pe.setPosition(e,n[0],t[be].length===0?t[be]:t[Me]),t;}// prettier-ignore
224
+ },{key:"addButtons",value:function addButtons(e,t,n,s){var r=Pe.generatePositionToButtons(t);return Pe.addToSideContainer(e,r),r[Ze].length>0&&Pe.addToDropup(e,r,n,s),r;}}]);}();var dh="<?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>",hh="<?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",uh="<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>",ph="<?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",fh=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},Z,{id:"upload-images-icon",svgString:hh,dropupText:"Image"}),bn,{id:"upload-gifs-icon",svgString:ph,dropupText:"GIF"}),j,{id:"upload-audio-icon",svgString:uh,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:dh,dropupText:"File"});var gi=/*#__PURE__*/function(_cn4){function gi(e){var _this98;_classCallCheck(this,gi);(e==null?void 0:e.position)===Ze&&(e.position=be);var t=ct.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this98=_callSuper(this,gi,[gi.createMicrophoneElement(),Ko,e==null?void 0:e.position,t,e]),_this98.isActive=!1,_this98._innerElements=_this98.createInnerElementsForStates(_this98.customStyles),_this98.changeToDefault();return _this98;}_inherits(gi,_cn4);return _createClass(gi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},A,this.createInnerElements(t,A,e)),U,this.createInnerElements(t,U,e)),"unsupported",this.createInnerElements(t,"unsupported",e)),"commandMode",this.createInnerElements(t,"commandMode",e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements[U]),this.toggleIconFilter(U),this.reapplyStateStyle(U,[A,"commandMode"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[A]),this.toggleIconFilter(A),this.reapplyStateStyle(A,[U,"commandMode"]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements.commandMode),this.toggleIconFilter("command"),this.reapplyStateStyle("commandMode",[U]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements.unsupported),this.elementRef[m].add("unsupported-microphone"),this.reapplyStateStyle("unsupported",[U]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()==="svg")switch(e){case A:t[m].remove("active-microphone-icon","command-microphone-icon"),t[m].add("default-microphone-icon");break;case U: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=x();return e.id="microphone-button",e[m].add("input-button"),e;}}]);}(cn);function mh(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i["default"]:i;}var Ps={},On={},Nn={},Bn={},Dn={},Qr;function yi(){if(Qr)return Dn;Qr=1,Object.defineProperty(Dn,"__esModule",{value:!0}),Dn.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 Dn.Text=i,i.FIRST_CHAR_REGEX=/\S/,i.DOUBLE_LINE=/\n\n/g,i.ONE_LINE=/\n/g,Dn;}var eo;function ta(){if(eo)return Bn;eo=1,Object.defineProperty(Bn,"__esModule",{value:!0}),Bn.Translate=void 0;var i=yi();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 Bn.Translate=e,Bn;}var to;function gh(){if(to)return Nn;to=1,Object.defineProperty(Nn,"__esModule",{value:!0}),Nn.WebSpeechTranscript=void 0;var i=ta();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 Nn.WebSpeechTranscript=e,Nn;}var Fn={},no;function yr(){if(no)return Fn;no=1,Object.defineProperty(Fn,"__esModule",{value:!0}),Fn.Browser=void 0;var i=/*#__PURE__*/_createClass(function i(){_classCallCheck(this,i);});return Fn.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;},Fn;}var Un={},Hn={},so;function yh(){if(so)return Hn;so=1,Object.defineProperty(Hn,"__esModule",{value:!0}),Hn.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 Hn.EventListeners=i,i.KEY_DOWN_TIMEOUT=null,Hn;}var jn={},io;function bh(){if(io)return jn;io=1,Object.defineProperty(jn,"__esModule",{value:!0}),jn.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 jn.PreResultUtils=i,jn;}var $n={},qn={},ro;function na(){if(ro)return qn;ro=1,Object.defineProperty(qn,"__esModule",{value:!0}),qn.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
225
  // 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 $n.AutoScroll=i,$n;}var qn={},ro;function yi(){if(ro)return qn;ro=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 Gn={},oo;function bi(){if(oo)return Gn;oo=1,Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.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)
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 qn.AutoScroll=i,qn;}var Gn={},oo;function bi(){if(oo)return Gn;oo=1,Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.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 Gn.Elements=i,Gn;}var zn={},ao;function _i(){if(ao)return zn;ao=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.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
227
  },{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
228
  // private static getCursorOffsetFromLeft(inputElement: HTMLInputElement, position: number) {
229
229
  // // Get the value of the input element up to the cursor position
@@ -241,39 +241,39 @@ function addToDropup(e,t,n,s){var r=new ni(n,s);Yr.forEach(function(a){var c=t[Y
241
241
  // document.body.removeChild(tempSpan);
242
242
  // return {left: offsetWidth, top: offsetHeight};
243
243
  // }
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 Gn.Cursor=i,Gn;}var ao;function na(){if(ao)return jn;ao=1,Object.defineProperty(jn,"__esModule",{value:!0}),jn.CommandUtils=void 0;var i=ta(),e=yi(),t=gr(),n=bi(),s=gi();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,b;var _=a.commands;if(!_||!d||!l)return;var E=((u=_.settings)===null||u===void 0?void 0:u.caseSensitive)===!0?c:c.toLowerCase(),R=s.Text.breakupIntoWordsArr(E),z=((g=_.settings)===null||g===void 0?void 0:g.substrings)===!1?r.checkIfMatchesWord:r.checkIfMatchesSubstring;if(_.commandMode&&z(_.commandMode,E,R))return a.setInterimColorToFinal(),setTimeout(function(){return r.toggleCommandModeOn(a);}),{doNotProcessTranscription:!1};if(!(_.commandMode&&!a.isWaitingForCommand)){if(_.stop&&z(_.stop,E,R))return r.toggleCommandModeOff(a),setTimeout(function(){return a.stop();}),{doNotProcessTranscription:!1};if(_.pause&&z(_.pause,E,R))return r.toggleCommandModeOff(a),a.setInterimColorToFinal(),setTimeout(function(){var te;a.isPaused=!0,(te=a.onPauseTrigger)===null||te===void 0||te.call(a,!0);}),{doNotProcessTranscription:!1};if(_.resume&&z(_.resume,E,R))return a.isPaused=!1,(b=a.onPauseTrigger)===null||b===void 0||b.call(a,!1),r.toggleCommandModeOff(a),a.resetRecording(l),{doNotProcessTranscription:!0};if(_.reset&&z(_.reset,E,R))return p!==void 0&&r.setText(a,l,p,d),{doNotProcessTranscription:!0};if(_.removeAllText&&z(_.removeAllText,E,R))return r.setText(a,l,"",d),{doNotProcessTranscription:!0};}}}]);}();return jn.CommandUtils=r,jn;}var zn={},co;function bh(){if(co)return zn;co=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.Highlight=void 0;var i=yi(),e=bi();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 zn.Highlight=t,zn;}var Vn={},lo;function _h(){if(lo)return Vn;lo=1,Object.defineProperty(Vn,"__esModule",{value:!0}),Vn.Padding=void 0;var i=yi(),e=bi(),t=gi();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],b=e.Cursor.getGenericElementCursorOffset(o,p,!1),_=(c=o.textContent)===null||c===void 0?void 0:c[b];t.Text.isCharDefined(g)&&(r.startPadding=" "),t.Text.isCharDefined(_)&&(r.endPadding=" "),r.isCursorAtEnd=((l=o.textContent)===null||l===void 0?void 0:l.length)===b;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 Vn.Padding=n,Vn;}var ho;function sa(){if(ho)return Fn;ho=1,Object.defineProperty(Fn,"__esModule",{value:!0}),Fn.Speech=void 0;var i=gh(),e=yh(),t=na(),n=ta(),s=bh(),r=yi(),o=_h(),a=gr(),c=bi(),l=gi();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,b;if(u!=null&&u.element)if(i.EventListeners.add(this,u),Array.isArray(u.element)){var E=u.element.find(function(R){return R===document.activeElement;})||u.element[0];if(!E)return;this.prepare(E);}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,!((b=this._options)===null||b===void 0)&&b.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:
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 zn.Cursor=i,zn;}var co;function sa(){if(co)return $n;co=1,Object.defineProperty($n,"__esModule",{value:!0}),$n.CommandUtils=void 0;var i=na(),e=bi(),t=yr(),n=_i(),s=yi();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,b;var _=a.commands;if(!_||!d||!l)return;var E=((u=_.settings)===null||u===void 0?void 0:u.caseSensitive)===!0?c:c.toLowerCase(),R=s.Text.breakupIntoWordsArr(E),z=((g=_.settings)===null||g===void 0?void 0:g.substrings)===!1?r.checkIfMatchesWord:r.checkIfMatchesSubstring;if(_.commandMode&&z(_.commandMode,E,R))return a.setInterimColorToFinal(),setTimeout(function(){return r.toggleCommandModeOn(a);}),{doNotProcessTranscription:!1};if(!(_.commandMode&&!a.isWaitingForCommand)){if(_.stop&&z(_.stop,E,R))return r.toggleCommandModeOff(a),setTimeout(function(){return a.stop();}),{doNotProcessTranscription:!1};if(_.pause&&z(_.pause,E,R))return r.toggleCommandModeOff(a),a.setInterimColorToFinal(),setTimeout(function(){var te;a.isPaused=!0,(te=a.onPauseTrigger)===null||te===void 0||te.call(a,!0);}),{doNotProcessTranscription:!1};if(_.resume&&z(_.resume,E,R))return a.isPaused=!1,(b=a.onPauseTrigger)===null||b===void 0||b.call(a,!1),r.toggleCommandModeOff(a),a.resetRecording(l),{doNotProcessTranscription:!0};if(_.reset&&z(_.reset,E,R))return p!==void 0&&r.setText(a,l,p,d),{doNotProcessTranscription:!0};if(_.removeAllText&&z(_.removeAllText,E,R))return r.setText(a,l,"",d),{doNotProcessTranscription:!0};}}}]);}();return $n.CommandUtils=r,$n;}var Vn={},lo;function _h(){if(lo)return Vn;lo=1,Object.defineProperty(Vn,"__esModule",{value:!0}),Vn.Highlight=void 0;var i=bi(),e=_i();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 Vn.Highlight=t,Vn;}var Kn={},ho;function vh(){if(ho)return Kn;ho=1,Object.defineProperty(Kn,"__esModule",{value:!0}),Kn.Padding=void 0;var i=bi(),e=_i(),t=yi();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],b=e.Cursor.getGenericElementCursorOffset(o,p,!1),_=(c=o.textContent)===null||c===void 0?void 0:c[b];t.Text.isCharDefined(g)&&(r.startPadding=" "),t.Text.isCharDefined(_)&&(r.endPadding=" "),r.isCursorAtEnd=((l=o.textContent)===null||l===void 0?void 0:l.length)===b;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 Kn.Padding=n,Kn;}var uo;function ia(){if(uo)return Un;uo=1,Object.defineProperty(Un,"__esModule",{value:!0}),Un.Speech=void 0;var i=yh(),e=bh(),t=sa(),n=na(),s=_h(),r=bi(),o=vh(),a=yr(),c=_i(),l=yi();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,b;if(u!=null&&u.element)if(i.EventListeners.add(this,u),Array.isArray(u.element)){var E=u.element.find(function(R){return R===document.activeElement;})||u.element[0];if(!E)return;this.prepare(E);}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,!((b=this._options)===null||b===void 0)&&b.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
246
  // unfortunately it did not work because the service would still continue firing the intermediate and final results
247
247
  // into the new position
248
248
  },{key:"resetRecording",value:function resetRecording(u){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(u,!0);}// prettier-ignore
249
249
  },{key:"updateElements",value:function updateElements(u,g,b){var _;var E=l.Text.capitalize(g);if(this.finalTranscript===E&&u==="")return;e.PreResultUtils.process(this,b,u==="",this._onPreResult,this._options)&&(u="",b="");var R=this.commands&&t.CommandUtils.execCommand(this,b,this._options,this._primitiveElement||this._genericElement,this._originalText);if(R){if(R.doNotProcessTranscription)return;u="",b="";}if(this.isPaused||this.isWaitingForCommand)return;(_=this._onResult)===null||_===void 0||_.call(this,b,u===""),this.finalTranscript=E,this._displayInterimResults||(u="");var z=this.finalTranscript===""&&u==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,u,z):this._genericElement&&this.updateGenericElement(this._genericElement,u,z);}// prettier-ignore
250
250
  // remember that padding values here contain actual text left and right
251
- },{key:"updatePrimitiveElement",value:function updatePrimitiveElement(u,g,b){this.isHighlighted&&s.Highlight.removeForPrimitive(this,u),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,u),b&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var _=this.startPadding+this.finalTranscript+g;if(u.value=_+this.endPadding,!this.isTargetInShadow){var E=_.length+this.numberOfSpacesAfterNewText;c.Cursor.setOffsetForPrimitive(u,E,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&n.AutoScroll.scrollSafariPrimitiveToEnd(u);}},{key:"updateGenericElement",value:function updateGenericElement(u,g,b){this.isHighlighted&&s.Highlight.removeForGeneric(this,u),this.spansPopulated||r.Elements.appendSpans(this,u);var _=(b?"":this.startPadding)+l.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=_;var E=n.AutoScroll.isRequired(this.autoScroll,u);n.AutoScroll.changeStateIfNeeded(this,E);var R=l.Text.lineBreak(g)+(b?"":this.endPadding);this.interimSpan.innerHTML=R,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&c.Cursor.setOffsetForSafariGeneric(u,_.length+R.length),E&&n.AutoScroll.scrollGeneric(this,u),b&&(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 Fn.Speech=d,Fn;}var uo;function vh(){if(uo)return Ln;uo=1,Object.defineProperty(Ln,"__esModule",{value:!0}),Ln.WebSpeech=void 0;var i=mh(),e=gr(),t=sa();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 Ln.WebSpeech=n,Ln;}var Kn={},po;function Eh(){if(po)return Kn;po=1,Object.defineProperty(Kn,"__esModule",{value:!0}),Kn.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 Kn.GlobalState=i,i.doubleClickPending=!1,Kn;}var Wn={},Xn={},fo;function Sh(){if(fo)return Xn;fo=1,Object.defineProperty(Xn,"__esModule",{value:!0}),Xn.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 Xn.PreventConnectionStop=i,Xn;}var Zn={},Yn={},mo;function xh(){return mo||(mo=1,Object.defineProperty(Yn,"__esModule",{value:!0}),Yn.README_URL=void 0,Yn.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),Yn;}var go;function Ah(){if(go)return Zn;go=1,Object.defineProperty(Zn,"__esModule",{value:!0}),Zn.AzureSpeechConfig=void 0;var i=xh();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 Zn.AzureSpeechConfig=e,Zn;}var Jn={},yo;function wh(){if(yo)return Jn;yo=1,Object.defineProperty(Jn,"__esModule",{value:!0}),Jn.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 Jn.StopTimeout=i,i.DEFAULT_MS=2e4,Jn;}var Qn={},bo;function Ch(){if(bo)return Qn;bo=1,Object.defineProperty(Qn,"__esModule",{value:!0}),Qn.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 Qn.AzureAudioConfig=i,Qn;}var es={},_o;function Th(){if(_o)return es;_o=1,Object.defineProperty(es,"__esModule",{value:!0}),es.AzureTranscript=void 0;var i=ea();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 es.AzureTranscript=e,es;}var vo;function Rh(){if(vo)return Wn;vo=1,Object.defineProperty(Wn,"__esModule",{value:!0}),Wn.Azure=void 0;var i=Sh(),e=Ah(),t=wh(),n=Ch(),s=Th(),r=sa();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,b,_,E;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,b=_c$autoLanguage.languages,_=b.slice(0,g==="Continuous"?10:4),E=l.AutoDetectSourceLanguageConfig.fromLanguages(_);g==="Continuous"&&(E.mode=1),u=l.SpeechRecognizer.FromConfig(p,E,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
251
+ },{key:"updatePrimitiveElement",value:function updatePrimitiveElement(u,g,b){this.isHighlighted&&s.Highlight.removeForPrimitive(this,u),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,u),b&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var _=this.startPadding+this.finalTranscript+g;if(u.value=_+this.endPadding,!this.isTargetInShadow){var E=_.length+this.numberOfSpacesAfterNewText;c.Cursor.setOffsetForPrimitive(u,E,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&n.AutoScroll.scrollSafariPrimitiveToEnd(u);}},{key:"updateGenericElement",value:function updateGenericElement(u,g,b){this.isHighlighted&&s.Highlight.removeForGeneric(this,u),this.spansPopulated||r.Elements.appendSpans(this,u);var _=(b?"":this.startPadding)+l.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=_;var E=n.AutoScroll.isRequired(this.autoScroll,u);n.AutoScroll.changeStateIfNeeded(this,E);var R=l.Text.lineBreak(g)+(b?"":this.endPadding);this.interimSpan.innerHTML=R,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&c.Cursor.setOffsetForSafariGeneric(u,_.length+R.length),E&&n.AutoScroll.scrollGeneric(this,u),b&&(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 Un.Speech=d,Un;}var po;function Eh(){if(po)return On;po=1,Object.defineProperty(On,"__esModule",{value:!0}),On.WebSpeech=void 0;var i=gh(),e=yr(),t=ia();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 On.WebSpeech=n,On;}var Wn={},fo;function Sh(){if(fo)return Wn;fo=1,Object.defineProperty(Wn,"__esModule",{value:!0}),Wn.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 Wn.GlobalState=i,i.doubleClickPending=!1,Wn;}var Xn={},Yn={},mo;function xh(){if(mo)return Yn;mo=1,Object.defineProperty(Yn,"__esModule",{value:!0}),Yn.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 Yn.PreventConnectionStop=i,Yn;}var Zn={},Jn={},go;function Ah(){return go||(go=1,Object.defineProperty(Jn,"__esModule",{value:!0}),Jn.README_URL=void 0,Jn.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),Jn;}var yo;function wh(){if(yo)return Zn;yo=1,Object.defineProperty(Zn,"__esModule",{value:!0}),Zn.AzureSpeechConfig=void 0;var i=Ah();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 Zn.AzureSpeechConfig=e,Zn;}var Qn={},bo;function Ch(){if(bo)return Qn;bo=1,Object.defineProperty(Qn,"__esModule",{value:!0}),Qn.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 Qn.StopTimeout=i,i.DEFAULT_MS=2e4,Qn;}var es={},_o;function Th(){if(_o)return es;_o=1,Object.defineProperty(es,"__esModule",{value:!0}),es.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 es.AzureAudioConfig=i,es;}var ts={},vo;function Rh(){if(vo)return ts;vo=1,Object.defineProperty(ts,"__esModule",{value:!0}),ts.AzureTranscript=void 0;var i=ta();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 ts.AzureTranscript=e,ts;}var Eo;function Ih(){if(Eo)return Xn;Eo=1,Object.defineProperty(Xn,"__esModule",{value:!0}),Xn.Azure=void 0;var i=xh(),e=wh(),t=Ch(),n=Th(),s=Rh(),r=ia();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,b,_,E;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,b=_c$autoLanguage.languages,_=b.slice(0,g==="Continuous"?10:4),E=l.AutoDetectSourceLanguageConfig.fromLanguages(_);g==="Continuous"&&(E.mode=1),u=l.SpeechRecognizer.FromConfig(p,E,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
253
  },{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 Wn.Azure=o,Wn;}var Eo;function Ih(){if(Eo)return ks;Eo=1,Object.defineProperty(ks,"__esModule",{value:!0});var i=vh(),e=na(),t=Eh(),n=Rh();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 ks["default"]=s,ks;}var Mh=Ih();var Os=/* @__PURE__ */fh(Mh);var kh=/*#__PURE__*/function(){function kh(e,t){_classCallCheck(this,kh);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(kh,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this103=this;this._silenceTimeout=setTimeout(function(){var n;(n=e.submit)==null||n.call(e),Os.stop(),_this103._stop||setTimeout(t,vs.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 ps=/*#__PURE__*/function(_mi){function ps(e,t,n){var _this104;_classCallCheck(this,ps);var s=_typeof(e.speechToText)=="object"?e.speechToText:{};_this104=_callSuper(this,ps,[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"&&!Os.isWebSpeechSupported())_this104.changeToUnsupported();else{var a=!e.textInput||!e.textInput[H];q.assignButtonEvents(_this104.elementRef,_this104.buttonClick.bind(_this104,t,a,r,o));}setTimeout(function(){_this104._validationHandler=e._validationHandler;});return _this104;}// prettier-ignore
255
- _inherits(ps,_mi);return _createClass(ps,[{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);}),Os.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),n.submitAfterSilence&&(this._silenceSubmit=new kh(n.submitAfterSilence,n.stopAfterSubmit)),{serviceName:ps.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(),Os.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[X](),t||setTimeout(function(){return e[X]();},ps.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(mi);ps.MICROPHONE_RESET_TIMEOUT_MS=300;var vs=ps;var xt=/*#__PURE__*/function(){// prettier-ignore
256
- function xt(e,t,n,s,r){var _this106=this;_classCallCheck(this,xt);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(xt,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var n;return xt.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=xt.getTypeFromBlob(e);if(s===V){var r=xt.createImageAttachment(t);this.addFileAttachment(e,V,r,n);}else if(s===j){var _r9=Es.createAudioAttachment(t);this.addFileAttachment(e,j,_r9,n);}else{var _r0=xt.createAnyFileAttachment(e.name);this.addFileAttachment(e,Jt,_r0,n);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,n,s){var a;var r=xt.createContainer(n);if(this._attachments.length>=this._fileCountLimit){var c=this._attachments[this._attachments.length-1].removeButton;c==null||c[X]();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=x();t[m].add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var n=x();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),Es.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({},ee,e[ee]),"type",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[X]();}),_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[X]();});}),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.type===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.type.startsWith(r.slice(0,-2)))return!0;}}return!1;}},{key:"getTypeFromBlob",value:function getTypeFromBlob(e){var t=e.type;return t.startsWith(V)?V:t.startsWith(j)?j:Jt;}},{key:"createImageAttachment",value:function createImageAttachment(e){var t=new Image();return t[C]=e,t[m].add("image-attachment"),t;}},{key:"createAnyFileAttachment",value:function createAnyFileAttachment(e){var t=x();t[m].add("border-bound-attachment"),Ue.IS_SAFARI&&t[m].add("border-bound-attachment-safari");var n=x();n[m].add("any-file-attachment-text");var s=x();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=x();return t[m].add("file-attachment"),t.appendChild(e),t;}}]);}();var Et=/*#__PURE__*/function(_xt){// prettier-ignore
257
- function Et(e,t,n,s,r){_classCallCheck(this,Et);return _callSuper(this,Et,[e,t,n,s,r]);}_inherits(Et,_xt);return _createClass(Et,[{key:"createTimer",value:function createTimer(e,t){var _this109=this;var n=0;var s=t!==void 0&&t<Et.TIMER_LIMIT_S?t:Et.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=Et.createAudioContainer(),n=x();n[m].add("audio-placeholder-text-3-digits");var s=x();s[m].add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),s.appendChild(n);var r=Ct.createSVGElement(Di);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("mouseenter",s);var r=function r(){return e.replaceChildren(n);};e.addEventListener("mouseleave",r);var o=function o(){var a;return(a=_this110.stopPlaceholderCallback)==null?void 0:a.call(_this110);};e.addEventListener(X,o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var n=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),j,n,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
258
- },{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[ee]=e,Et.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=x();return e[m].add("border-bound-attachment","audio-attachment-icon-container"),Ue.IS_SAFARI&&e[m].add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var n=e.parentElement?q.cloneElement(e):e,s=x(j);s[C]=t;var r=Ct.createSVGElement(Ko);r[m].add("attachment-icon","play-icon");var o=Ct.createSVGElement(Di);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);},q.assignButtonEvents(n,function(){s.paused?s.play():s.pause();});}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=Et.createAudioContainer();return Et.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][X]();}}]);}(xt);Et.TIMER_LIMIT_S=5999;var Es=Et;var Ph=/*#__PURE__*/function(){function Ph(){_classCallCheck(this,Ph);}return _createClass(Ph,null,[{key:"create",value:// prettier-ignore
259
- function create(e,t,n,s,r,o){return o===j?new Es(e,t,n,s,r):new xt(e,t,n,s,r);}}]);}();var As=/*#__PURE__*/function(){function As(e,t,n){_classCallCheck(this,As);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(As,[{key:"addType",value:function addType(e,t,n,s){var r=Ph.create(e,t,n,this.toggleContainerDisplay.bind(this),this.elementRef,s);return this._fileAttachmentsTypes.push(r),r;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=x();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 _ref254=_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 _ref254.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){As.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 st=/*#__PURE__*/function(){function st(e,t,n){_classCallCheck(this,st);this._isOpen=!1,this._contentRef=st.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=st.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=st.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=st.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(st,[{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){ue.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";},st.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?st.createSVGButton(e):st.createTextButton(e);return this.addButtons(s),q.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===ge.ESCAPE?(this.close(),(n=this.extensionCloseCallback)==null||n.call(this)):t.key===ge.ENTER&&(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)));}}],[{key:"createContainer",value:function createContainer(e,t){var n=x();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=x();return(_n$m=n[m]).add.apply(_n$m,_toConsumableArray(e)),t&&(n[v].backgroundColor=t),x().appendChild(n),n;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=x();return t[m].add("modal-button-panel"),e&&(t[v].backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=x();return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=x();return t[m].add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=x();t[m].add("modal-button","modal-svg-button");var n=Ct.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[y])!=null&&s.infoModal){var r=new st(e,["modal-content"],t[y].infoModal.containerStyle);return r.addCloseButton("OK",!1,n),r.openTextModal.bind(r,t.infoModalTextMarkUp||"");}}}]);}();st.MODAL_CLOSE_TIMEOUT_MS=190;var Wt=st;var si=/*#__PURE__*/function(_cn5){// prettier-ignore
261
- function si(e,t,n,s,r,o){var _this114;_classCallCheck(this,si);var p,u,g,b,_,E,R,z,te,ne;var a=ae.processPosition((p=n==null?void 0:n.button)==null?void 0:p.position),c=((b=(g=(u=n==null?void 0:n.button)==null?void 0:u.styles)==null?void 0:g[h])==null?void 0:b.content)||o,l=ct.tryCreateConfig("Upload File",(_=n==null?void 0:n.button)==null?void 0:_.tooltip);_this114=_callSuper(this,si,[si.createButtonElement(),r,a,l,n.button,c]);var d=_this114.createInnerElementsForStates(s,_this114.customStyles);_this114._inputElement=si.createInputElement((E=n==null?void 0:n[y])==null?void 0:E.acceptedFormats),_this114.addClickEvent(e,n),_this114.changeElementsByState(d.styles),_this114.reapplyStateStyle("styles"),_this114._fileAttachmentsType=t,_this114._openModalOnce=((z=(R=n[y])==null?void 0:R.infoModal)==null?void 0:z.openModalOnce)===!1||(ne=(te=n[y])==null?void 0:te.infoModal)==null?void 0:ne.openModalOnce;return _this114;}_inherits(si,_cn5);return _createClass(si,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e,t){return{styles:this.createInnerElements(e,"styles",t)};}},{key:"triggerImportPrompt",value:function triggerImportPrompt(e){e.onchange=this["import"].bind(this,e),e[X]();}},{key:"import",value:function _import(e){As.addFilesToType(Array.from(e[y]||[]),[this._fileAttachmentsType]),e.value="";}},{key:"addClickEvent",value:function addClickEvent(e,t){var n=this.triggerImportPrompt.bind(this,this._inputElement),s=Wt.createTextModalFunc(e,t,n);this.elementRef.onclick=this[X].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=x("input");return t.type=ee,t.accept=e||"",t.hidden=!0,t.multiple=!0,t;}},{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[m].add("input-button"),e;}}]);}(cn);var St=/*#__PURE__*/function(){function St(){_classCallCheck(this,St);}return _createClass(St,null,[{key:"create",value:function create(e,t,n){var s=St.createElement(n);St.addEvents(s,e,t),e.appendChild(s);}},{key:"createElement",value:function createElement(e){var t=x();return t.id="drag-and-drop",_typeof(e)===F&&Object.assign(t[v],e),t;}},{key:"addEvents",value:function addEvents(e,t,n){t.ondragenter=function(s){s.preventDefault(),St.display(e);},e.ondragleave=function(s){s.preventDefault(),St.hide(e);},e.ondragover=function(s){s.preventDefault();},e.ondrop=function(s){s.preventDefault(),St.uploadFile(n,s),St.hide(e);};}},{key:"uploadFile",value:function uploadFile(e,t){var s;var n=(s=t.dataTransfer)==null?void 0:s[y];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 jt=/*#__PURE__*/function(){function jt(){_classCallCheck(this,jt);}return _createClass(jt,null,[{key:"validate",value:// 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 Xn.Azure=o,Xn;}var So;function Mh(){if(So)return Ps;So=1,Object.defineProperty(Ps,"__esModule",{value:!0});var i=Eh(),e=sa(),t=Sh(),n=Ih();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 Ps["default"]=s,Ps;}var kh=Mh();var Ns=/* @__PURE__ */mh(kh);var Ph=/*#__PURE__*/function(){function Ph(e,t){_classCallCheck(this,Ph);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(Ph,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this103=this;this._silenceTimeout=setTimeout(function(){var n;(n=e.submit)==null||n.call(e),Ns.stop(),_this103._stop||setTimeout(t,Es.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 fs=/*#__PURE__*/function(_gi){function fs(e,t,n){var _this104;_classCallCheck(this,fs);var s=_typeof(e.speechToText)=="object"?e.speechToText:{};_this104=_callSuper(this,fs,[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"&&!Ns.isWebSpeechSupported())_this104.changeToUnsupported();else{var a=!e.textInput||!e.textInput[H];q.assignButtonEvents(_this104.elementRef,_this104.buttonClick.bind(_this104,t,a,r,o));}setTimeout(function(){_this104._validationHandler=e._validationHandler;});return _this104;}// prettier-ignore
255
+ _inherits(fs,_gi);return _createClass(fs,[{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);}),Ns.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),n.submitAfterSilence&&(this._silenceSubmit=new Ph(n.submitAfterSilence,n.stopAfterSubmit)),{serviceName:fs.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(),Ns.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[X](),t||setTimeout(function(){return e[X]();},fs.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(gi);fs.MICROPHONE_RESET_TIMEOUT_MS=300;var Es=fs;var xt=/*#__PURE__*/function(){// prettier-ignore
256
+ function xt(e,t,n,s,r){var _this106=this;_classCallCheck(this,xt);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(xt,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var n;return xt.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=xt.getTypeFromBlob(e);if(s===V){var r=xt.createImageAttachment(t);this.addFileAttachment(e,V,r,n);}else if(s===j){var _r9=Ss.createAudioAttachment(t);this.addFileAttachment(e,j,_r9,n);}else{var _r0=xt.createAnyFileAttachment(e.name);this.addFileAttachment(e,Jt,_r0,n);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,n,s){var a;var r=xt.createContainer(n);if(this._attachments.length>=this._fileCountLimit){var c=this._attachments[this._attachments.length-1].removeButton;c==null||c[X]();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=x();t[m].add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var n=x();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),Ss.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({},ee,e[ee]),"type",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[X]();}),_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[X]();});}),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.type===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.type.startsWith(r.slice(0,-2)))return!0;}}return!1;}},{key:"getTypeFromBlob",value:function getTypeFromBlob(e){var t=e.type;return t.startsWith(V)?V:t.startsWith(j)?j:Jt;}},{key:"createImageAttachment",value:function createImageAttachment(e){var t=new Image();return t[C]=e,t[m].add("image-attachment"),t;}},{key:"createAnyFileAttachment",value:function createAnyFileAttachment(e){var t=x();t[m].add("border-bound-attachment"),Ue.IS_SAFARI&&t[m].add("border-bound-attachment-safari");var n=x();n[m].add("any-file-attachment-text");var s=x();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=x();return t[m].add("file-attachment"),t.appendChild(e),t;}}]);}();var Et=/*#__PURE__*/function(_xt){// prettier-ignore
257
+ function Et(e,t,n,s,r){_classCallCheck(this,Et);return _callSuper(this,Et,[e,t,n,s,r]);}_inherits(Et,_xt);return _createClass(Et,[{key:"createTimer",value:function createTimer(e,t){var _this109=this;var n=0;var s=t!==void 0&&t<Et.TIMER_LIMIT_S?t:Et.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=Et.createAudioContainer(),n=x();n[m].add("audio-placeholder-text-3-digits");var s=x();s[m].add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),s.appendChild(n);var r=Ct.createSVGElement(Fi);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("mouseenter",s);var r=function r(){return e.replaceChildren(n);};e.addEventListener("mouseleave",r);var o=function o(){var a;return(a=_this110.stopPlaceholderCallback)==null?void 0:a.call(_this110);};e.addEventListener(X,o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var n=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),j,n,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
258
+ },{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[ee]=e,Et.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=x();return e[m].add("border-bound-attachment","audio-attachment-icon-container"),Ue.IS_SAFARI&&e[m].add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var n=e.parentElement?q.cloneElement(e):e,s=x(j);s[C]=t;var r=Ct.createSVGElement(Wo);r[m].add("attachment-icon","play-icon");var o=Ct.createSVGElement(Fi);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);},q.assignButtonEvents(n,function(){s.paused?s.play():s.pause();});}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=Et.createAudioContainer();return Et.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][X]();}}]);}(xt);Et.TIMER_LIMIT_S=5999;var Ss=Et;var Lh=/*#__PURE__*/function(){function Lh(){_classCallCheck(this,Lh);}return _createClass(Lh,null,[{key:"create",value:// prettier-ignore
259
+ function create(e,t,n,s,r,o){return o===j?new Ss(e,t,n,s,r):new xt(e,t,n,s,r);}}]);}();var ws=/*#__PURE__*/function(){function ws(e,t,n){_classCallCheck(this,ws);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(ws,[{key:"addType",value:function addType(e,t,n,s){var r=Lh.create(e,t,n,this.toggleContainerDisplay.bind(this),this.elementRef,s);return this._fileAttachmentsTypes.push(r),r;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=x();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 _ref254=_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 _ref254.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){ws.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 st=/*#__PURE__*/function(){function st(e,t,n){_classCallCheck(this,st);this._isOpen=!1,this._contentRef=st.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=st.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=st.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=st.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(st,[{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){ue.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";},st.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?st.createSVGButton(e):st.createTextButton(e);return this.addButtons(s),q.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===ge.ESCAPE?(this.close(),(n=this.extensionCloseCallback)==null||n.call(this)):t.key===ge.ENTER&&(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)));}}],[{key:"createContainer",value:function createContainer(e,t){var n=x();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=x();return(_n$m=n[m]).add.apply(_n$m,_toConsumableArray(e)),t&&(n[v].backgroundColor=t),x().appendChild(n),n;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=x();return t[m].add("modal-button-panel"),e&&(t[v].backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=x();return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=x();return t[m].add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=x();t[m].add("modal-button","modal-svg-button");var n=Ct.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[y])!=null&&s.infoModal){var r=new st(e,["modal-content"],t[y].infoModal.containerStyle);return r.addCloseButton("OK",!1,n),r.openTextModal.bind(r,t.infoModalTextMarkUp||"");}}}]);}();st.MODAL_CLOSE_TIMEOUT_MS=190;var Wt=st;var ii=/*#__PURE__*/function(_cn5){// prettier-ignore
261
+ function ii(e,t,n,s,r,o){var _this114;_classCallCheck(this,ii);var p,u,g,b,_,E,R,z,te,ne;var a=ae.processPosition((p=n==null?void 0:n.button)==null?void 0:p.position),c=((b=(g=(u=n==null?void 0:n.button)==null?void 0:u.styles)==null?void 0:g[h])==null?void 0:b.content)||o,l=ct.tryCreateConfig("Upload File",(_=n==null?void 0:n.button)==null?void 0:_.tooltip);_this114=_callSuper(this,ii,[ii.createButtonElement(),r,a,l,n.button,c]);var d=_this114.createInnerElementsForStates(s,_this114.customStyles);_this114._inputElement=ii.createInputElement((E=n==null?void 0:n[y])==null?void 0:E.acceptedFormats),_this114.addClickEvent(e,n),_this114.changeElementsByState(d.styles),_this114.reapplyStateStyle("styles"),_this114._fileAttachmentsType=t,_this114._openModalOnce=((z=(R=n[y])==null?void 0:R.infoModal)==null?void 0:z.openModalOnce)===!1||(ne=(te=n[y])==null?void 0:te.infoModal)==null?void 0:ne.openModalOnce;return _this114;}_inherits(ii,_cn5);return _createClass(ii,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e,t){return{styles:this.createInnerElements(e,"styles",t)};}},{key:"triggerImportPrompt",value:function triggerImportPrompt(e){e.onchange=this["import"].bind(this,e),e[X]();}},{key:"import",value:function _import(e){ws.addFilesToType(Array.from(e[y]||[]),[this._fileAttachmentsType]),e.value="";}},{key:"addClickEvent",value:function addClickEvent(e,t){var n=this.triggerImportPrompt.bind(this,this._inputElement),s=Wt.createTextModalFunc(e,t,n);this.elementRef.onclick=this[X].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=x("input");return t.type=ee,t.accept=e||"",t.hidden=!0,t.multiple=!0,t;}},{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[m].add("input-button"),e;}}]);}(cn);var St=/*#__PURE__*/function(){function St(){_classCallCheck(this,St);}return _createClass(St,null,[{key:"create",value:function create(e,t,n){var s=St.createElement(n);St.addEvents(s,e,t),e.appendChild(s);}},{key:"createElement",value:function createElement(e){var t=x();return t.id="drag-and-drop",_typeof(e)===F&&Object.assign(t[v],e),t;}},{key:"addEvents",value:function addEvents(e,t,n){t.ondragenter=function(s){s.preventDefault(),St.display(e);},e.ondragleave=function(s){s.preventDefault(),St.hide(e);},e.ondragover=function(s){s.preventDefault();},e.ondrop=function(s){s.preventDefault(),St.uploadFile(n,s),St.hide(e);};}},{key:"uploadFile",value:function uploadFile(e,t){var s;var n=(s=t.dataTransfer)==null?void 0:s[y];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 jt=/*#__PURE__*/function(){function jt(){_classCallCheck(this,jt);}return _createClass(jt,null,[{key:"validate",value:// prettier-ignore
262
262
  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
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[ee];});return _context189.a(2,jt.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
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[y])==null?void 0:a.map(function(c){return c[ee];});return _context190.a(2,jt.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!==lt.URL&&!Re.canSendMessage(n)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
265
- },{key:"attach",value:function attach(e,t,n,s,r,o){var a=e.validateInput||ae.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref255=_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||!jt.validateWebsocket(t,r))){_context191.n=1;break;}return _context191.a(2,!1);case 1:l=a||t.canSendMessage;return _context191.a(2,l?c?jt.useValidationFuncProgrammatic(l,c,r,t,o):jt.useValidationFunc(l,n,s,r,t,o):null);}},_callee191);}));return function(_x363){return _ref255.apply(this,arguments);};}();}}]);}();var ia=/*#__PURE__*/function(){function ia(){_classCallCheck(this,ia);}return _createClass(ia,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 Lh=/*#__PURE__*/function(_mi2){function Lh(e,t){var _this115;_classCallCheck(this,Lh);var n,s;_this115=_callSuper(this,Lh,[t.button]),_this115._waitingForBrowserApproval=!1,_this115._audioType=e,_this115._extension=((n=t[y])==null?void 0:n.format)||"mp3",_this115._maxDurationSeconds=(s=t[y])==null?void 0:s.maxDurationSeconds,q.assignButtonEvents(_this115.elementRef,_this115.buttonClick.bind(_assertThisInitialized(_this115)));return _this115;}_inherits(Lh,_mi2);return _createClass(Lh,[{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[Bt]();})["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=ia.getFileName(this._newFilePrefix||j,this._extension),s=new File([t],n,{type:t.type}),r=new FileReader();r.readAsDataURL(s),r.onload=function(o){_this118._audioType.completePlaceholderAttachment(s,o.target.result);};}}]);}(mi);var Oh="<?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 Xt=/*#__PURE__*/function(){function Xt(){_classCallCheck(this,Xt);}return _createClass(Xt,null,[{key:"resetSubmit",value:function resetSubmit(e,t){t?e.unsetCustomStateStyles(["loading","submit"]):e.unsetCustomStateStyles(["stop","loading","submit"]),e.reapplyStateStyle("submit");}},{key:"overwriteDefaultStyleWithSubmit",value:function overwriteDefaultStyleWithSubmit(e,t){if(!e.submit)return;var n=w(e[t]||{});Ie.overwritePropertyObjectFromAnother(n,e.submit,["container",A]),Ie.overwritePropertyObjectFromAnother(n,e.submit,[h,"styles",A]),Ie.overwritePropertyObjectFromAnother(n,e.submit,["svg","styles",A]),e[t]=n;}// prettier-ignore
266
- },{key:"setUpDisabledButton",value:function setUpDisabledButton(e){Ie.setPropertyValueIfDoesNotExist(e,["submit","container",A,"backgroundColor"],""),Ie.setPropertyValueIfDoesNotExist(e,[H,"container",A,"backgroundColor"],ra),Ie.setPropertyValueIfDoesNotExist(e.submit,["svg","styles",A,"filter"],""),Ie.setPropertyValueIfDoesNotExist(e[H],["svg","styles",A,"filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),Ie.setPropertyValueIfDoesNotExist(e[H],[h,"styles",A,"color"],"grey"),Xt.overwriteDefaultStyleWithSubmit(e,H);}},{key:"process",value:function process(e){var t=w(e||{});return Xt.overwriteDefaultStyleWithSubmit(t,"loading"),Xt.overwriteDefaultStyleWithSubmit(t,"stop"),e!=null&&e.alwaysEnabled||Xt.setUpDisabledButton(t),t;}}]);}();var os=/*#__PURE__*/function(_cn6){// prettier-ignore
267
- function os(e,t,n,s,r,o){var _this119;_classCallCheck(this,os);var a=Xt.process(e.submitButtonStyles),c=Oh,l=ct.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this119=_callSuper(this,os,[os.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(os,_cn6);return _createClass(os,[{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||[os.createLoadingIconElement()],stop:n||[os.createStopIconElement()]},H,this.createDisabledIconElement(e));}},{key:"createCustomElements",value:function createCustomElements(){var _this120=this;var e=gt.createCustomElements("submit",this.svg,this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(n){var s=n,r=gt.createCustomElements(s,_this120.svg,_this120.customStyles);r&&(t[s]=r);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return gt.createCustomElements(H,this.svg,this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
265
+ },{key:"attach",value:function attach(e,t,n,s,r,o){var a=e.validateInput||ae.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref255=_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||!jt.validateWebsocket(t,r))){_context191.n=1;break;}return _context191.a(2,!1);case 1:l=a||t.canSendMessage;return _context191.a(2,l?c?jt.useValidationFuncProgrammatic(l,c,r,t,o):jt.useValidationFunc(l,n,s,r,t,o):null);}},_callee191);}));return function(_x363){return _ref255.apply(this,arguments);};}();}}]);}();var ra=/*#__PURE__*/function(){function ra(){_classCallCheck(this,ra);}return _createClass(ra,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 Oh=/*#__PURE__*/function(_gi2){function Oh(e,t){var _this115;_classCallCheck(this,Oh);var n,s;_this115=_callSuper(this,Oh,[t.button]),_this115._waitingForBrowserApproval=!1,_this115._audioType=e,_this115._extension=((n=t[y])==null?void 0:n.format)||"mp3",_this115._maxDurationSeconds=(s=t[y])==null?void 0:s.maxDurationSeconds,q.assignButtonEvents(_this115.elementRef,_this115.buttonClick.bind(_assertThisInitialized(_this115)));return _this115;}_inherits(Oh,_gi2);return _createClass(Oh,[{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[Bt]();})["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=ra.getFileName(this._newFilePrefix||j,this._extension),s=new File([t],n,{type:t.type}),r=new FileReader();r.readAsDataURL(s),r.onload=function(o){_this118._audioType.completePlaceholderAttachment(s,o.target.result);};}}]);}(gi);var Nh="<?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 Xt=/*#__PURE__*/function(){function Xt(){_classCallCheck(this,Xt);}return _createClass(Xt,null,[{key:"resetSubmit",value:function resetSubmit(e,t){t?e.unsetCustomStateStyles(["loading","submit"]):e.unsetCustomStateStyles(["stop","loading","submit"]),e.reapplyStateStyle("submit");}},{key:"overwriteDefaultStyleWithSubmit",value:function overwriteDefaultStyleWithSubmit(e,t){if(!e.submit)return;var n=w(e[t]||{});Ie.overwritePropertyObjectFromAnother(n,e.submit,["container",A]),Ie.overwritePropertyObjectFromAnother(n,e.submit,[h,"styles",A]),Ie.overwritePropertyObjectFromAnother(n,e.submit,["svg","styles",A]),e[t]=n;}// prettier-ignore
266
+ },{key:"setUpDisabledButton",value:function setUpDisabledButton(e){Ie.setPropertyValueIfDoesNotExist(e,["submit","container",A,"backgroundColor"],""),Ie.setPropertyValueIfDoesNotExist(e,[H,"container",A,"backgroundColor"],oa),Ie.setPropertyValueIfDoesNotExist(e.submit,["svg","styles",A,"filter"],""),Ie.setPropertyValueIfDoesNotExist(e[H],["svg","styles",A,"filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),Ie.setPropertyValueIfDoesNotExist(e[H],[h,"styles",A,"color"],"grey"),Xt.overwriteDefaultStyleWithSubmit(e,H);}},{key:"process",value:function process(e){var t=w(e||{});return Xt.overwriteDefaultStyleWithSubmit(t,"loading"),Xt.overwriteDefaultStyleWithSubmit(t,"stop"),e!=null&&e.alwaysEnabled||Xt.setUpDisabledButton(t),t;}}]);}();var as=/*#__PURE__*/function(_cn6){// prettier-ignore
267
+ function as(e,t,n,s,r,o){var _this119;_classCallCheck(this,as);var a=Xt.process(e.submitButtonStyles),c=Nh,l=ct.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this119=_callSuper(this,as,[as.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(as,_cn6);return _createClass(as,[{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||[as.createLoadingIconElement()],stop:n||[as.createStopIconElement()]},H,this.createDisabledIconElement(e));}},{key:"createCustomElements",value:function createCustomElements(){var _this120=this;var e=gt.createCustomElements("submit",this.svg,this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(n){var s=n,r=gt.createCustomElements(s,_this120.svg,_this120.customStyles);r&&(t[s]=r);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return gt.createCustomElements(H,this.svg,this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
268
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.svg||(o=(r=(s=this.customStyles)==null?void 0:s.loading)==null?void 0:r.svg)!=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=x("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,""),y,e));else{t=this._textInput.inputElementRef.innerText.trim();this.attemptSubmit(_defineProperty(_defineProperty({},h,t),y,e));}(Ue.IS_SAFARI||Ue.IS_MOBILE)&&setTimeout(function(){return en.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=ae.processSubmitUserMessage(e));t=_defineProperty({},h,e[h]);e[y]&&(t[y]=Array.from(e[y]).map(function(n){return{file:n,type:xt.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();Ue.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 Us.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[y])==null?void 0:a.map(function(l){return l[ee];}),s=_defineProperty(_defineProperty({},h,e[h]===""?void 0:e[h]),y,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(_ref257){var e,t,n,s,_t62;return _regenerator().w(function(_context195){while(1)switch(_context195.n){case 0:e=_ref257.text,t=_ref257.files,n=_ref257.custom;s=_defineProperty(_defineProperty({},S,D),"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[y]=_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(Ms,Pn,kn),ue.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle("stop",["loading","submit"]),q.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(kn,Pn),ue.removeAriaDisabled(this.elementRef),this.elementRef[m].add(Ms),ue.addAriaBusy(this.elementRef),this.reapplyStateStyle("loading",["submit"]),q.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(kn)||(this.elementRef[m].remove(Ms,Pn),ue.removeAriaAttributes(this.elementRef),this.elementRef[m].add(kn),this.changeElementsByState(this._innerElements.submit),Xt.resetSubmit(this,this.status.loadingActive),q.assignButtonEvents(this.elementRef,function(){var e;_this124.submitFromInput(),(e=_this124._microphoneButton)!=null&&e.isActive&&vs.toggleSpeechAfterSubmit(_this124._microphoneButton.elementRef,!!_this124._stopSTTAfterSubmit),setTimeout(function(){return en.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(Pn)||(this.elementRef[m].remove(Ms,kn),ue.removeAriaBusy(this.elementRef),this.elementRef[m].add(Pn),ue.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements[H]),this.reapplyStateStyle(H,["submit"]),q.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=x();return e[m].add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=x();return e[m].add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=x();return e.id="stop-icon",e;}}]);}(cn);var Nh="<?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",Bh="<?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",Dh="<?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>",Fh="<?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 yr=/*#__PURE__*/function(_Wt){// prettier-ignore
272
- function yr(e,t,n,s){var _this125;_classCallCheck(this,yr);_this125=_callSuper(this,yr,[e,["modal-content","modal-camera-content"],n]),_this125._stopped=!1,_this125._format="image/png",_this125._canvas=x("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=Ct.createSVGElement(Nh),_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(yr,_Wt);return _createClass(yr,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=Wt.createSVGButton(Bh);t[m].add("modal-svg-camera-button"),t.children[0][m].add("modal-svg-camera-icon");var n=this.addCloseButton(Dh,!0);n[m].add("modal-svg-close-button"),n.children[0][m].add("modal-svg-close-icon");var s=Wt.createSVGButton(Fh);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;q.assignButtonEvents(e,this.capture.bind(this)),q.assignButtonEvents(t,this.stop.bind(this)),q.assignButtonEvents(n,function(){var r=_this126.getFile();r&&As.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);},Wt.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this128=this;this._dataURL=void 0,this._submitButton[m].add("modal-svg-submit-".concat(H)),this._stopped=!1,navigator.mediaDevices.getUserMedia({video:this._dimensions||!0}).then(function(e){if(_this128._mediaStream=e,!_this128.isOpen())return _this128.stop();var t=x("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(H)),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(H)),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 _n17=new Uint8Array(t),s=new Blob([_n17],{type:this._format}),r=this._format==="image/jpeg"?"jpeg":"png",o=ia.getFileName(this._newFilePrefix||"photo",r);return new File([s],o,{type:s.type});}}},{key:"updateCanvas",value:function updateCanvas(e,t){if(!this._stopped){if(!this._dataURL){t.width=e.videoWidth,t.height=e.videoHeight;var _n18=t.getContext("2d");_n18==null||_n18.drawImage(e,0,0,t.width,t.height);}requestAnimationFrame(this.updateCanvas.bind(this,e,t));}}},{key:"openCameraModal",value:function openCameraModal(e){this.displayModalElements(),e[Bt]();}// prettier-ignore
274
- }],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,n,s){var r=new yr(e,t,n,s);return r.openCameraModal.bind(r,r);}}]);}(Wt);var Uh="<?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 br=/*#__PURE__*/function(_cn7){function br(e,t,n){var _this129;_classCallCheck(this,br);var l,d,p,u,g,b;var s=ae.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.styles)==null?void 0:p[h])==null?void 0:u.content)||"Photo",o=ct.tryCreateConfig("Camera",(g=n==null?void 0:n.button)==null?void 0:g.tooltip),a=((b=n==null?void 0:n.button)==null?void 0:b.styles)||{};_this129=_callSuper(this,br,[br.createButtonElement(),Uh,s,o,a,r]);var c=_this129.createInnerElementsForStates(_this129.customStyles);n&&_this129.addClickEvent(e,t,n.modalContainerStyle,n[y]),_this129.changeElementsByState(c.styles),_this129.reapplyStateStyle("styles");return _this129;}_inherits(br,_cn7);return _createClass(br,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("camera-icon","styles",e)};}},{key:"addClickEvent",value:// prettier-ignore
275
- function addClickEvent(e,t,n,s){var r=yr.createCameraModalFunc(e,t,n,s);q.assignButtonEvents(this.elementRef,r);}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[m].add("input-button"),e;}}]);}(cn);var un=/*#__PURE__*/function(){function un(e,t,n,s){_classCallCheck(this,un);this.elementRef=un.createPanelElement(e.inputAreaStyle);var r={},o=this.createFileUploadComponents(e,n,s,r),a=new Fs(e,n,o,t.browserStorage);e.speechToText&&!r.microphone&&(r.microphone={button:new vs(e,a,t.addNewErrorMessage.bind(t))});var c=new os(e,a,t,n,o,r);a.submit=c.submitFromInput.bind(c),jt.attach(e,n,a,o,c,t.browserStorage),e.submitUserMessage=c.programmaticSubmit.bind(c),r.submit={button:c},e.customButtons&&Yt.add(e,r),un.addElements(this.elementRef,a,r,s,o,e.dropupStyles),un.assignOnInput(e,n,o,a);}return _createClass(un,[{key:"createFileUploadComponents",value:// prettier-ignore
276
- function createFileUploadComponents(e,t,n,s){var o,a,c,l;var r=new As(this.elementRef,e.attachmentContainerStyle,t.demo);if(un.createUploadButtons(e,t,t.fileTypes||{},r,n,s),(o=t[Ne])!=null&&o[y]){var d=((a=s[Y])==null?void 0:a.fileType)||r.addType(e,t,t[Ne][y],Y);s[Ne]={button:new br(n,d,t[Ne])};}if((c=t.recordAudio)!=null&&c[y]){var _d3=((l=s[j])==null?void 0:l.fileType)||r.addType(e,t,t.recordAudio[y],j);s.microphone={button:new Lh(_d3,t.recordAudio)};}return St.isEnabled(r,e.dragAndDrop)&&St.create(n,r,e.dragAndDrop),r;}// prettier-ignore
277
- }],[{key:"createPanelElement",value:function createPanelElement(e){var t=x();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[y]){var d=s.addType(e,t,l[y],c),_ph$c=ph[c],p=_ph$c.id,u=_ph$c.svgString,g=_ph$c.dropupText,b=new si(r,d,l,p,u,g);o[c]={button:b,fileType:d};}});}// prettier-ignore
278
- },{key:"addElements",value:function addElements(e,t,n,s,r,o){q.addElements(e,t.elementRef);var a=An.create(),c=Pe.addButtons(a,n,s,o);rs.set(t.inputElementRef,a,r.elementRef,c),An.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[y]=o.map(function(l){return l[ee];})),nn.onInput(e,c,r);});};}}]);}();var _r=/*#__PURE__*/function(){function _r(){_classCallCheck(this,_r);}return _createClass(_r,null,[{key:"createElements",value:function createElements(e,t,n){var s=x();s.id="chat-view";var r=!e.focusMode&&e.upwardsMode;s.classList.add(r?ih:sh);var o=new Je(e,t,n);t.websocket&&Re.createConnection(t,o);var a=new un(e,o,t,s),c=r?o.elementRef.parentElement:o.elementRef;return q.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=_r.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var Hh="#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.26em}.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 jh=Object.defineProperty,O=function O(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&&jh(e,t,s),s;};var k=/*#__PURE__*/function(_Li){function k(){var _this130;_classCallCheck(this,k);var e;_this130=_callSuper(this,k),_this130.getMessages=function(){return[];},_this130.submitUserMessage=function(){return console.warn(Rr("submitUserMessage"));},_this130.addMessage=function(){return console.warn(Rr("addMessage"));},_this130.updateMessage=function(){},_this130.clearMessages=function(){},_this130.focusInput=function(){return en.focusFromParentElement(_this130._elementRef);},_this130.refreshMessages=function(){},_this130.scrollToBottom=function(){},_this130.disableSubmitButton=function(){},_this130.setPlaceholderText=function(){},_this130._hasBeenRendered=!1,_this130._auxiliaryStyleApplied=!1,_this130._elementRef=x(),_this130._elementRef.id="container",_this130.attachShadow({mode:"open"}).appendChild(_this130._elementRef),(e=_this130.shadowRoot)==null||e.appendChild(ct.buildElement()),ts.apply(Hh,_this130.shadowRoot),setTimeout(function(){_this130._hasBeenRendered||_this130.onRender();},20);return _this130;}_inherits(k,_Li);return _createClass(k,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
279
- },{key:"onRender",value:function onRender(){var _this$_childElement;Ds.attemptAppendStyleSheetToHead(this.style),ae.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=nh.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(ts.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),ts.applyDefaultStyleToComponent(this.style,this.chatStyle),ae.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?Ns.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof M)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],_r.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof M&&ke.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||nn.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){bs.chat=void 0;}}]);}(Li);O([L("object")],k.prototype,"connect");O([L("object")],k.prototype,"directConnection");O([L("object")],k.prototype,"webModel");O([L("object")],k.prototype,"requestBodyLimits");O([L("function")],k.prototype,"requestInterceptor");O([L("function")],k.prototype,"responseInterceptor");O([L("function")],k.prototype,"validateInput");O([L("function")],k.prototype,"loadHistory");O([L("object")],k.prototype,"chatStyle");O([L("object")],k.prototype,"attachmentContainerStyle");O([L("object")],k.prototype,"dropupStyles");O([L("object")],k.prototype,"inputAreaStyle");O([L("object")],k.prototype,"textInput");O([L("object")],k.prototype,"defaultInput");O([L("object")],k.prototype,"submitButtonStyles");O([L("object")],k.prototype,"customButtons");O([L("string")],k.prototype,"auxiliaryStyle");O([L("array")],k.prototype,"history");O([L("object")],k.prototype,"browserStorage");O([L("object")],k.prototype,"introMessage");O([L("object")],k.prototype,"avatars");O([L("object")],k.prototype,"names");O([L("object")],k.prototype,"displayLoadingBubble");O([L("object")],k.prototype,"errorMessages");O([L("object")],k.prototype,"messageStyles");O([L("object")],k.prototype,"textToSpeech");O([L("object")],k.prototype,"speechToText");O([L("object")],k.prototype,"images");O([L("object")],k.prototype,"gifs");O([L("object")],k.prototype,"camera");O([L("object")],k.prototype,"audio");O([L("object")],k.prototype,"microphone");O([L("object")],k.prototype,"mixedFiles");O([L("object")],k.prototype,"dragAndDrop");O([L("object")],k.prototype,"htmlWrappers");O([L("object")],k.prototype,"htmlClassUtilities");O([L("object")],k.prototype,"remarkable");O([L("object")],k.prototype,"focusMode");O([L("boolean")],k.prototype,"upwardsMode");O([L("object")],k.prototype,"scrollButton");O([L("object")],k.prototype,"hiddenMessages");O([L("number")],k.prototype,"maxVisibleMessages");O([L("function")],k.prototype,"onMessage");O([L("function")],k.prototype,"onClearMessages");O([L("function")],k.prototype,"onComponentRender");O([L("function")],k.prototype,"onInput");O([L("function")],k.prototype,"onError");O([L("object")],k.prototype,"demo");O([L("object")],k.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",k);export{k as DeepChat};
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();Ue.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 Hs.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[y])==null?void 0:a.map(function(l){return l[ee];}),s=_defineProperty(_defineProperty({},h,e[h]===""?void 0:e[h]),y,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(_ref257){var e,t,n,s,_t62;return _regenerator().w(function(_context195){while(1)switch(_context195.n){case 0:e=_ref257.text,t=_ref257.files,n=_ref257.custom;s=_defineProperty(_defineProperty({},S,D),"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[y]=_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(ks,Ln,Pn),ue.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle("stop",["loading","submit"]),q.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(Pn,Ln),ue.removeAriaDisabled(this.elementRef),this.elementRef[m].add(ks),ue.addAriaBusy(this.elementRef),this.reapplyStateStyle("loading",["submit"]),q.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(Pn)||(this.elementRef[m].remove(ks,Ln),ue.removeAriaAttributes(this.elementRef),this.elementRef[m].add(Pn),this.changeElementsByState(this._innerElements.submit),Xt.resetSubmit(this,this.status.loadingActive),q.assignButtonEvents(this.elementRef,function(){var e;_this124.submitFromInput(),(e=_this124._microphoneButton)!=null&&e.isActive&&Es.toggleSpeechAfterSubmit(_this124._microphoneButton.elementRef,!!_this124._stopSTTAfterSubmit),setTimeout(function(){return en.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(Ln)||(this.elementRef[m].remove(ks,Pn),ue.removeAriaBusy(this.elementRef),this.elementRef[m].add(Ln),ue.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements[H]),this.reapplyStateStyle(H,["submit"]),q.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=x();return e[m].add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=x();return e[m].add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=x();return e.id="stop-icon",e;}}]);}(cn);var Bh="<?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",Dh="<?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",Fh="<?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>",Uh="<?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 br=/*#__PURE__*/function(_Wt){// prettier-ignore
272
+ function br(e,t,n,s){var _this125;_classCallCheck(this,br);_this125=_callSuper(this,br,[e,["modal-content","modal-camera-content"],n]),_this125._stopped=!1,_this125._format="image/png",_this125._canvas=x("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=Ct.createSVGElement(Bh),_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(br,_Wt);return _createClass(br,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=Wt.createSVGButton(Dh);t[m].add("modal-svg-camera-button"),t.children[0][m].add("modal-svg-camera-icon");var n=this.addCloseButton(Fh,!0);n[m].add("modal-svg-close-button"),n.children[0][m].add("modal-svg-close-icon");var s=Wt.createSVGButton(Uh);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;q.assignButtonEvents(e,this.capture.bind(this)),q.assignButtonEvents(t,this.stop.bind(this)),q.assignButtonEvents(n,function(){var r=_this126.getFile();r&&ws.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);},Wt.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this128=this;this._dataURL=void 0,this._submitButton[m].add("modal-svg-submit-".concat(H)),this._stopped=!1,navigator.mediaDevices.getUserMedia({video:this._dimensions||!0}).then(function(e){if(_this128._mediaStream=e,!_this128.isOpen())return _this128.stop();var t=x("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(H)),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(H)),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 _n17=new Uint8Array(t),s=new Blob([_n17],{type:this._format}),r=this._format==="image/jpeg"?"jpeg":"png",o=ra.getFileName(this._newFilePrefix||"photo",r);return new File([s],o,{type:s.type});}}},{key:"updateCanvas",value:function updateCanvas(e,t){if(!this._stopped){if(!this._dataURL){t.width=e.videoWidth,t.height=e.videoHeight;var _n18=t.getContext("2d");_n18==null||_n18.drawImage(e,0,0,t.width,t.height);}requestAnimationFrame(this.updateCanvas.bind(this,e,t));}}},{key:"openCameraModal",value:function openCameraModal(e){this.displayModalElements(),e[Bt]();}// prettier-ignore
274
+ }],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,n,s){var r=new br(e,t,n,s);return r.openCameraModal.bind(r,r);}}]);}(Wt);var Hh="<?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 _r=/*#__PURE__*/function(_cn7){function _r(e,t,n){var _this129;_classCallCheck(this,_r);var l,d,p,u,g,b;var s=ae.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.styles)==null?void 0:p[h])==null?void 0:u.content)||"Photo",o=ct.tryCreateConfig("Camera",(g=n==null?void 0:n.button)==null?void 0:g.tooltip),a=((b=n==null?void 0:n.button)==null?void 0:b.styles)||{};_this129=_callSuper(this,_r,[_r.createButtonElement(),Hh,s,o,a,r]);var c=_this129.createInnerElementsForStates(_this129.customStyles);n&&_this129.addClickEvent(e,t,n.modalContainerStyle,n[y]),_this129.changeElementsByState(c.styles),_this129.reapplyStateStyle("styles");return _this129;}_inherits(_r,_cn7);return _createClass(_r,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("camera-icon","styles",e)};}},{key:"addClickEvent",value:// prettier-ignore
275
+ function addClickEvent(e,t,n,s){var r=br.createCameraModalFunc(e,t,n,s);q.assignButtonEvents(this.elementRef,r);}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[m].add("input-button"),e;}}]);}(cn);var un=/*#__PURE__*/function(){function un(e,t,n,s){_classCallCheck(this,un);this.elementRef=un.createPanelElement(e.inputAreaStyle);var r={},o=this.createFileUploadComponents(e,n,s,r),a=new Us(e,n,o,t.browserStorage);e.speechToText&&!r.microphone&&(r.microphone={button:new Es(e,a,t.addNewErrorMessage.bind(t))});var c=new as(e,a,t,n,o,r);a.submit=c.submitFromInput.bind(c),jt.attach(e,n,a,o,c,t.browserStorage),e.submitUserMessage=c.programmaticSubmit.bind(c),r.submit={button:c},e.customButtons&&Zt.add(e,r),un.addElements(this.elementRef,a,r,s,o,e.dropupStyles),un.assignOnInput(e,n,o,a);}return _createClass(un,[{key:"createFileUploadComponents",value:// prettier-ignore
276
+ function createFileUploadComponents(e,t,n,s){var o,a,c,l;var r=new ws(this.elementRef,e.attachmentContainerStyle,t.demo);if(un.createUploadButtons(e,t,t.fileTypes||{},r,n,s),(o=t[Ne])!=null&&o[y]){var d=((a=s[Z])==null?void 0:a.fileType)||r.addType(e,t,t[Ne][y],Z);s[Ne]={button:new _r(n,d,t[Ne])};}if((c=t.recordAudio)!=null&&c[y]){var _d3=((l=s[j])==null?void 0:l.fileType)||r.addType(e,t,t.recordAudio[y],j);s.microphone={button:new Oh(_d3,t.recordAudio)};}return St.isEnabled(r,e.dragAndDrop)&&St.create(n,r,e.dragAndDrop),r;}// prettier-ignore
277
+ }],[{key:"createPanelElement",value:function createPanelElement(e){var t=x();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[y]){var d=s.addType(e,t,l[y],c),_fh$c=fh[c],p=_fh$c.id,u=_fh$c.svgString,g=_fh$c.dropupText,b=new ii(r,d,l,p,u,g);o[c]={button:b,fileType:d};}});}// prettier-ignore
278
+ },{key:"addElements",value:function addElements(e,t,n,s,r,o){q.addElements(e,t.elementRef);var a=wn.create(),c=Pe.addButtons(a,n,s,o);os.set(t.inputElementRef,a,r.elementRef,c),wn.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[y]=o.map(function(l){return l[ee];})),nn.onInput(e,c,r);});};}}]);}();var vr=/*#__PURE__*/function(){function vr(){_classCallCheck(this,vr);}return _createClass(vr,null,[{key:"createElements",value:function createElements(e,t,n){var s=x();s.id="chat-view";var r=!e.focusMode&&e.upwardsMode;s.classList.add(r?rh:ih);var o=new Je(e,t,n);t.websocket&&Re.createConnection(t,o);var a=new un(e,o,t,s),c=r?o.elementRef.parentElement:o.elementRef;return q.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=vr.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var jh="#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 $h=Object.defineProperty,O=function O(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&&$h(e,t,s),s;};var k=/*#__PURE__*/function(_Oi){function k(){var _this130;_classCallCheck(this,k);var e;_this130=_callSuper(this,k),_this130.getMessages=function(){return[];},_this130.submitUserMessage=function(){return console.warn(Ir("submitUserMessage"));},_this130.addMessage=function(){return console.warn(Ir("addMessage"));},_this130.updateMessage=function(){},_this130.clearMessages=function(){},_this130.focusInput=function(){return en.focusFromParentElement(_this130._elementRef);},_this130.refreshMessages=function(){},_this130.scrollToBottom=function(){},_this130.disableSubmitButton=function(){},_this130.setPlaceholderText=function(){},_this130._hasBeenRendered=!1,_this130._auxiliaryStyleApplied=!1,_this130._elementRef=x(),_this130._elementRef.id="container",_this130.attachShadow({mode:"open"}).appendChild(_this130._elementRef),(e=_this130.shadowRoot)==null||e.appendChild(ct.buildElement()),ns.apply(jh,_this130.shadowRoot),setTimeout(function(){_this130._hasBeenRendered||_this130.onRender();},20);return _this130;}_inherits(k,_Oi);return _createClass(k,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
279
+ },{key:"onRender",value:function onRender(){var _this$_childElement;Fs.attemptAppendStyleSheetToHead(this.style),ae.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=sh.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(ns.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),ns.applyDefaultStyleToComponent(this.style,this.chatStyle),ae.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?Bs.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof M)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],vr.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof M&&ke.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||nn.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){_s.chat=void 0;}}]);}(Oi);O([L("object")],k.prototype,"connect");O([L("object")],k.prototype,"directConnection");O([L("object")],k.prototype,"webModel");O([L("object")],k.prototype,"requestBodyLimits");O([L("function")],k.prototype,"requestInterceptor");O([L("function")],k.prototype,"responseInterceptor");O([L("function")],k.prototype,"validateInput");O([L("function")],k.prototype,"loadHistory");O([L("object")],k.prototype,"chatStyle");O([L("object")],k.prototype,"attachmentContainerStyle");O([L("object")],k.prototype,"dropupStyles");O([L("object")],k.prototype,"inputAreaStyle");O([L("object")],k.prototype,"textInput");O([L("object")],k.prototype,"defaultInput");O([L("object")],k.prototype,"submitButtonStyles");O([L("object")],k.prototype,"customButtons");O([L("string")],k.prototype,"auxiliaryStyle");O([L("array")],k.prototype,"history");O([L("object")],k.prototype,"browserStorage");O([L("object")],k.prototype,"introMessage");O([L("object")],k.prototype,"avatars");O([L("object")],k.prototype,"names");O([L("object")],k.prototype,"displayLoadingBubble");O([L("object")],k.prototype,"errorMessages");O([L("object")],k.prototype,"messageStyles");O([L("object")],k.prototype,"textToSpeech");O([L("object")],k.prototype,"speechToText");O([L("object")],k.prototype,"images");O([L("object")],k.prototype,"gifs");O([L("object")],k.prototype,"camera");O([L("object")],k.prototype,"audio");O([L("object")],k.prototype,"microphone");O([L("object")],k.prototype,"mixedFiles");O([L("object")],k.prototype,"dragAndDrop");O([L("object")],k.prototype,"htmlWrappers");O([L("object")],k.prototype,"htmlClassUtilities");O([L("object")],k.prototype,"remarkable");O([L("object")],k.prototype,"focusMode");O([L("boolean")],k.prototype,"upwardsMode");O([L("object")],k.prototype,"scrollButton");O([L("object")],k.prototype,"hiddenMessages");O([L("number")],k.prototype,"maxVisibleMessages");O([L("function")],k.prototype,"onMessage");O([L("function")],k.prototype,"onClearMessages");O([L("function")],k.prototype,"onComponentRender");O([L("function")],k.prototype,"onInput");O([L("function")],k.prototype,"onError");O([L("object")],k.prototype,"demo");O([L("object")],k.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",k);export{k as DeepChat};