deep-chat-dev 9.0.327 → 9.0.328

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,4 +1,4 @@
1
- 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",_="style",Jo="unset",Ko="html-wrapper",S=function S(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var Wo=/*#__PURE__*/function(){function Wo(){_classCallCheck(this,Wo);}return _createClass(Wo,null,[{key:"render",value:function render(e,t){var n=S();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var ws=/*#__PURE__*/function(){function ws(){_classCallCheck(this,ws);}return _createClass(ws,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=S();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=ws.createElements(),r={onSuccess:t,onFail:Wo.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:ws.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var Y="service",h="text",I="html",f="error",$="https://deepchat.dev/docs/",J="ai",U="user",bt="assistant",Cs="error-message-text",gs="deep-chat-outer-container-role-",pr="empty-message",li="deep-chat-top-message",fr="deep-chat-middle-message",di="deep-chat-bottom-message",A="src",T="type",Q="file",y="files",j="image",V="images",Re="camera",ln="gifs",P="audio",Ye="microphone",lo="mixedFiles",Gt="any",ho="file-message",Mt="start",uo="end",po="messages";function mr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function Xo(i){return i&&JSON.stringify(i);}function Bi(i,e,t,n){var s="\n".concat(mr(e)," message: ").concat(JSON.stringify(i)," \n"),r=t?"".concat(mr(e)," message after interceptor: ").concat(Xo(n)," \n"):"";return s+r;}function Zo(i,e,t,n){return"".concat(Bi(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat($,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat($,"interceptors#responseInterceptor");}function Yo(i,e,t){var n="response";return"".concat(Bi(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Qo(i,e){var t="request";return"".concat(Bi(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function ea(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var dn=Zo,ta=Qo,na=Yo,gr=ea,re="Invalid API Key",He="Failed to connect",Ie="Request settings have not been set up",Ys="No file was added",Di="Image was not found",fo="Multi-response arrays are not supported for streaming",mo="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat($,"interceptors#responseInterceptor"),sa="Cannot mix {text: string} and {html: string} responses.",ia="No valid stream events were sent.\n".concat(mo),ra="Readable Stream connection error.",Wt="Please define a `function_handler` property inside the service config.",un="Function tool response must be an array or contain a text property",go="Failed to fetch history",pn="inside-start",it="inside-end",xe="outside-start",he="outside-end",ze="dropup-menu",x="default",Te="hover",q="click";var ee=/*#__PURE__*/function(){function ee(){_classCallCheck(this,ee);}return _createClass(ee,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var n=Object.keys(t).reduce(function(s,r){return s[r]="",s;},{});Object.assign(e[_],n);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t[q]&&ee.unsetStyle(e,t[q]),t[Te]&&ee.unsetStyle(e,t[Te]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){ee.unsetActivityCSSMouseStates(e,t),t[x]&&ee.unsetStyle(e,t[x]);}// if you want to asdd default styling - use pure css classes
1
+ 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",_="style",Jo="unset",Ko="html-wrapper",S=function S(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var Wo=/*#__PURE__*/function(){function Wo(){_classCallCheck(this,Wo);}return _createClass(Wo,null,[{key:"render",value:function render(e,t){var n=S();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var ws=/*#__PURE__*/function(){function ws(){_classCallCheck(this,ws);}return _createClass(ws,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=S();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=ws.createElements(),r={onSuccess:t,onFail:Wo.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:ws.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var Y="service",h="text",M="html",f="error",$="https://deepchat.dev/docs/",J="ai",U="user",bt="assistant",Cs="error-message-text",gs="deep-chat-outer-container-role-",pr="empty-message",li="deep-chat-top-message",fr="deep-chat-middle-message",di="deep-chat-bottom-message",A="src",T="type",Q="file",y="files",j="image",V="images",Re="camera",ln="gifs",P="audio",Ye="microphone",lo="mixedFiles",Gt="any",ho="file-message",Mt="start",uo="end",po="messages";function mr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function Xo(i){return i&&JSON.stringify(i);}function Bi(i,e,t,n){var s="\n".concat(mr(e)," message: ").concat(JSON.stringify(i)," \n"),r=t?"".concat(mr(e)," message after interceptor: ").concat(Xo(n)," \n"):"";return s+r;}function Zo(i,e,t,n){return"".concat(Bi(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat($,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat($,"interceptors#responseInterceptor");}function Yo(i,e,t){var n="response";return"".concat(Bi(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Qo(i,e){var t="request";return"".concat(Bi(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function ea(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var dn=Zo,ta=Qo,na=Yo,gr=ea,re="Invalid API Key",He="Failed to connect",Ie="Request settings have not been set up",Ys="No file was added",Di="Image was not found",fo="Multi-response arrays are not supported for streaming",mo="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat($,"interceptors#responseInterceptor"),sa="Cannot mix {text: string} and {html: string} responses.",ia="No valid stream events were sent.\n".concat(mo),ra="Readable Stream connection error.",Wt="Please define a `function_handler` property inside the service config.",un="Function tool response must be an array or contain a text property",go="Failed to fetch history",pn="inside-start",it="inside-end",xe="outside-start",he="outside-end",ze="dropup-menu",x="default",Te="hover",q="click";var ee=/*#__PURE__*/function(){function ee(){_classCallCheck(this,ee);}return _createClass(ee,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var n=Object.keys(t).reduce(function(s,r){return s[r]="",s;},{});Object.assign(e[_],n);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t[q]&&ee.unsetStyle(e,t[q]),t[Te]&&ee.unsetStyle(e,t[Te]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){ee.unsetActivityCSSMouseStates(e,t),t[x]&&ee.unsetStyle(e,t[x]);}// if you want to asdd default styling - use pure css classes
2
2
  },{key:"processStateful",value:function processStateful(e){var t=e[x]||{},n=Object.assign(JSON.parse(JSON.stringify(t)),e==null?void 0:e[Te]),s=Object.assign(JSON.parse(JSON.stringify(n)),e==null?void 0:e[q]);return _defineProperty(_defineProperty(_defineProperty({},x,t),Te,n),q,s);}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t=_defineProperty(_defineProperty(_defineProperty({},x,{}),Te,{}),q,{});return e.forEach(function(n){t[x]=Object.assign(t[x],n[x]),t[Te]=Object.assign(t[Te],n[Te]),t[q]=Object.assign(t[q],n[q]);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e[x]||[]).forEach(function(n){var r;var s=n;t[_][s]&&(r=e[x])!=null&&r[s]&&(e[x][n]=t[_][s]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var n in t){var s=t[n];e[n]===""&&s&&(e[n]=s);}}}]);}();var Lt=/*#__PURE__*/function(){function Lt(){_classCallCheck(this,Lt);}return _createClass(Lt,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==Lt.DEFAULT_FONT_FAMILY)return;var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(s){return s.getAttribute("href")===Lt.FONT_URL;})){var s=S("link");s.rel="stylesheet",s.href=Lt.FONT_URL,t.appendChild(s);}}}]);}();Lt.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",Lt.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var Ts=Lt;var sn=/*#__PURE__*/function(){function sn(){_classCallCheck(this,sn);}return _createClass(sn,null,[{key:"apply",value:function apply(e,t){if(t)try{sn.applyStyleSheet(e,t);}catch(_unused){sn.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=S("style");n.innerHTML=e,t.appendChild(n);}},{key:"applyDefaultStyleToComponent",value:function applyDefaultStyleToComponent(e,t){t&&ee.applyToStyleIfNotDefined(e,t),ee.applyToStyleIfNotDefined(e,sn.DEFAULT_COMPONENT_STYLE);}}]);}();sn.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:Ts.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
@@ -12,10 +12,10 @@ function clear(){var t,n,s;var e=window.scrollY;this.inputElementRef[m].contains
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;}));}}]);}();At.TEXT_INPUT_ID="text-input";var Rs=At;var zt=/*#__PURE__*/function(){function zt(){_classCallCheck(this,zt);}return _createClass(zt,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),(Oe.IS_MOBILE||Oe.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(Rs.TEXT_INPUT_ID));t&&zt.focusEndOfInput(t);}}]);}();var yo="Authentication",oe="Authorization",aa="authorization",Fi="Unauthorized",Ui="Authorization header",kt="Invalid",ps="Incorrect",be="authentication_error",Ke="invalid_request_error",D="Content-Type",ca="content-type",K="application/json",B="object",Hi="completed",ye="Bearer ",ae="GET",le="POST",ji="Upload an audio file",xs="function_call",qt="input_audio",Ne="image_url",Ks=/*#__PURE__*/function(){function Ks(){_classCallCheck(this,Ks);}return _createClass(Ks,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=e.scrollHeight,n=e.clientHeight,s=e.scrollTop,r=t-n;return s>=r-Ks.CODE_SNIPPET_GENERATION_JUMP;}},{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.hiddenMessages&&e.hiddenMessages.hiddenElements.size>0&&e.hiddenMessages.clear(),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;}}]);}();Ks.CODE_SNIPPET_GENERATION_JUMP=0.5;var ce=Ks;var Ws=/*#__PURE__*/function(){function Ws(){_classCallCheck(this,Ws);}return _createClass(Ws,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);},Ws.LOAD_VOICES_MS);}}]);}();Ws.LOAD_VOICES_MS=200;var hn=Ws;var rn=/*#__PURE__*/function(){function rn(){_classCallCheck(this,rn);}return _createClass(rn,null,[{key:"colorToHex",value:function colorToHex(e){var t=S();return t[_].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=rn.colorToHex(t.styles.bubble.color);e[_].setProperty("--loading-message-color",r),e[_].setProperty("--loading-message-color-fade","".concat(r,"33"));}else e[_].setProperty("--loading-message-color","#848484"),e[_].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=rn.colorToHex(n);e[_].setProperty("--loading-history-color",c);}else e[_].setProperty("--loading-history-color","#dbdbdb");e[_].setProperty("--loading-history-height",r||"57px"),e[_].setProperty("--loading-history-width",s||"57px"),e[_].setProperty("--loading-history-margin",o||"7px"),e[_].setProperty("--loading-history-border",a||"6px solid");}}]);}();rn.BUBBLE_CLASS="deep-chat-loading-message-bubble",rn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var rt=rn;var te=/*#__PURE__*/function(){function te(){_classCallCheck(this,te);}return _createClass(te,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var n=e.containerStyle;n&&(Object.assign(t[_],n),console[f]("The containerStyle property".concat(qe,"1.3.14.")),console[f]("".concat(Ot,"the style property instead: ").concat($,"styles#style")));}// eslint-disable-next-line @typescript-eslint/no-explicit-any
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;}));}}]);}();At.TEXT_INPUT_ID="text-input";var Rs=At;var zt=/*#__PURE__*/function(){function zt(){_classCallCheck(this,zt);}return _createClass(zt,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),(Oe.IS_MOBILE||Oe.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(Rs.TEXT_INPUT_ID));t&&zt.focusEndOfInput(t);}}]);}();var yo="Authentication",ae="Authorization",aa="authorization",Fi="Unauthorized",Ui="Authorization header",kt="Invalid",ps="Incorrect",be="authentication_error",Ke="invalid_request_error",D="Content-Type",ca="content-type",K="application/json",B="object",Hi="completed",ye="Bearer ",ce="GET",le="POST",ji="Upload an audio file",xs="function_call",qt="input_audio",Ne="image_url",Ks=/*#__PURE__*/function(){function Ks(){_classCallCheck(this,Ks);}return _createClass(Ks,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]:Ks.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.clear(),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;}}]);}();Ks.CODE_SNIPPET_GENERATION_JUMP=1;var oe=Ks;var Ws=/*#__PURE__*/function(){function Ws(){_classCallCheck(this,Ws);}return _createClass(Ws,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);},Ws.LOAD_VOICES_MS);}}]);}();Ws.LOAD_VOICES_MS=200;var hn=Ws;var rn=/*#__PURE__*/function(){function rn(){_classCallCheck(this,rn);}return _createClass(rn,null,[{key:"colorToHex",value:function colorToHex(e){var t=S();return t[_].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=rn.colorToHex(t.styles.bubble.color);e[_].setProperty("--loading-message-color",r),e[_].setProperty("--loading-message-color-fade","".concat(r,"33"));}else e[_].setProperty("--loading-message-color","#848484"),e[_].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=rn.colorToHex(n);e[_].setProperty("--loading-history-color",c);}else e[_].setProperty("--loading-history-color","#dbdbdb");e[_].setProperty("--loading-history-height",r||"57px"),e[_].setProperty("--loading-history-width",s||"57px"),e[_].setProperty("--loading-history-margin",o||"7px"),e[_].setProperty("--loading-history-border",a||"6px solid");}}]);}();rn.BUBBLE_CLASS="deep-chat-loading-message-bubble",rn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var rt=rn;var te=/*#__PURE__*/function(){function te(){_classCallCheck(this,te);}return _createClass(te,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var n=e.containerStyle;n&&(Object.assign(t[_],n),console[f]("The containerStyle property".concat(qe,"1.3.14.")),console[f]("".concat(Ot,"the style property instead: ").concat($,"styles#style")));}// eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
  },{key:"handleResponseProperty",value:function handleResponseProperty(e){return console[f]("The {result: ....} response object type".concat(qe,"1.3.0.")),console[f]("".concat(Ot,"the new response object: ").concat($,"connect#Response")),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console[f]("The initialMessages property".concat(qe,"2.0.0.")),console[f]("".concat(Ot,"the history property instead: ").concat($,"messages/#history")),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e[Q];t&&(console[f]("The file property in MessageContent".concat(qe,"1.3.17.")),console[f]("".concat(Ot,"the files array property: ").concat($,"messages/#MessageContent")),e[y]=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console[f]("The validateMessageBeforeSending property".concat(qe,"1.3.24.")),console[f]("".concat(Ot,"validateInput: ").concat($,"interceptors#validateInput")),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console[f]("The submitUserMessage(text: string) argument string type".concat(qe,"1.4.4.")),console[f]("".concat(Ot,"the new argument type: ").concat($,"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(qe,"1.4.4.")),console[f]("".concat(Ot,"using {..., overwrite: true} object: ").concat($,"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(qe,"2.0.0.")),console[f]("".concat(ys,"connect object: ").concat($,"connect#connect-1")));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console[f]("The stream property".concat(br,"the connect object in version 2.0.0.")),console[f]("".concat(ys,"connect object: ").concat($,"connect#connect-1")),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var s;var n=e;n.onNewMessage&&(console[f]("The onNewMessage event".concat(qe,"2.0.0.")),console[f]("".concat(ys,"onMessage event: ").concat($,"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(qe,"2.0.0.")),console[f]("Please use the connect property instead: ".concat($,"files")),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=JSON.parse(JSON.stringify(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(tn,"2.1.0.")),console[f]("Check it out here: ".concat($,"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(qe,"2.1.0.")),console[f]("Please use displayLoading instead: ".concat($,"modes#demo")),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,n="".concat(ys,"official documentation: ").concat($,"directConnection/Cohere");return t.chat&&(console[f]("Cohere chat property".concat(qe,"2.2.3.")),console[f](n),delete t.chat),t.textGeneration?(console[f]("Cohere textGeneration".concat(yr,"2.2.3.")),console[f](n),delete t.textGeneration,!1):t.summarization?(console[f]("Cohere summarization".concat(yr,"2.2.3.")),console[f](n),delete t.summarization,!1):!0;}},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==B)return;var t=e.htmlWrappers;if(t)return console[f]("The htmlWrappers property".concat(br,"Deep Chat's base").concat(tn,"2.3.0.")),console[f]("Check it out here: ".concat($,"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(tn,"2.3.0.")),console[f]("Check it out here: ".concat($,"modes#focusMode")),e.smoothScroll=!0),e;}},{key:"processPosition",value:function processPosition(e){if(!e)return e;var t="Position names have been updated".concat(tn,"2.3.1.");return e==="inside-left"?(console[f](t),pn):e==="inside-right"?(console[f](t),it):e==="outside-left"?(console[f](t),xe):e==="outside-right"?(console[f](t),he):e;}},{key:"processBrowserStorage",value:function processBrowserStorage(e){var t=e.get();t&&Array.isArray(t)&&e.addMessages(t);}}]);}();var tn=" since version ",qe=" is deprecated ".concat(tn),Ot="Please change to using ",ys="Please see the ",yr=" is not supported ".concat(tn),br=" has been moved to ";var yt=/*#__PURE__*/function(){function yt(){_classCallCheck(this,yt);}return _createClass(yt,null,[{key:"mouseUp",value:function mouseUp(e,t){ee.unsetAllCSSMouseStates(e,t),Object.assign(e[_],t[x]),Object.assign(e[_],t[Te]);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e[_],t[q]);}},{key:"mouseLeave",value:function mouseLeave(e,t){ee.unsetAllCSSMouseStates(e,t),Object.assign(e[_],t[x]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e[_],t[Te]);}},{key:"add",value:function add(e,t){e.addEventListener("mouseenter",yt.mouseEnter.bind(this,e,t)),e.addEventListener("mouseleave",yt.mouseLeave.bind(this,e,t)),e.addEventListener("mousedown",yt.mouseDown.bind(this,e,t)),e.addEventListener("mouseup",yt.mouseUp.bind(this,e,t));}}]);}();var la="deep-chat-temporary-message",da="deep-chat-suggestion-button",yi={"deep-chat-button":{styles:_defineProperty(_defineProperty(_defineProperty({},x,{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"}),Te,{backgroundColor:"#fafafa"}),q,{backgroundColor:"#f1f1f1"})}},vr=Object.keys(yi);var ot=/*#__PURE__*/function(){function ot(){_classCallCheck(this,ot);}return _createClass(ot,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener(q,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(la):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return vr.find(function(t){return e[m].contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var n=yi[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=yi[n].styles;if(r){var a=JSON.parse(JSON.stringify(r));a[x]&&ee.overwriteDefaultWithAlreadyApplied(a,t),s.unshift(a);}var o=ee.mergeStatefulStyles(s);return ee.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,n){vr.forEach(function(r){var o=n.getElementsByClassName(r);Array.from(o||[]).forEach(function(a){var c=ot.getProcessedStyles(t,a,r);Z.applyStylesToElement(a,c),ot.applyEvents(a,r);});});var s=n.getElementsByClassName(da);Array.from(s).forEach(function(r){return ot.applySuggestionEvent(e,r);});}}]);}();var Z=/*#__PURE__*/function(){function Z(){_classCallCheck(this,Z);}return _createClass(Z,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var n=ee.processStateful(t);yt.add(e,n),Object.assign(e[_],n[x]);}},{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&&Z.applyEventsToElement(e,n),s&&!ot.doesElementContainDeepChatClass(e)&&Z.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]&&Z.applyClassUtilitiesToElement(r,e[n]);});});}},{key:"apply",value:function apply(e,t){ot.applyDeepChatUtilities(e,e.htmlClassUtilities,t),Z.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){Z.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){Z.traverseNodes(r,s);}),s;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=S();return t.innerHTML=e,ot.isElementTemporary({outerContainer:t,bubbleElement:t,innerContainer:t});}// useful for removing event listeners
17
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[x]);if(r)return e.innerHTML=r,{contentEl:Z.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(Ko)[0]||e;}}]);}();var wt=/*#__PURE__*/function(){function wt(){_classCallCheck(this,wt);}return _createClass(wt,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(wt.HTML_BUBBLE_CLASS);var _Z$tryAddWrapper=Z.tryAddWrapper(o.bubbleElement,t,e._customWrappers,n),a=_Z$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,n){n.bubbleElement.innerHTML=t,Z.apply(e,n.outerContainer),te.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,I,wt.HTML_BUBBLE_CLASS);return o&&wt.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=wt.createElements(e,t,n,s);return N.fillEmptyMessageElement(r.bubbleElement,t),Z.apply(e,r.outerContainer),te.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,n,!1,(o=e.messageStyles)==null?void 0:o[I]),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&&Z.isTemporaryBasedOnHTML(t))return;var o=wt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();wt.HTML_BUBBLE_CLASS="html-message";var at=wt;var ha=/*#__PURE__*/function(){function ha(){_classCallCheck(this,ha);}return _createClass(ha,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,v=p.bMarks[u]+p.tShift[u],E=p.eMarks[u];if(v+1>E)return!1;var C=p[A].charAt(v);if(C!==a)return!1;var H=v;v=p.skipChars(v,C);var W=v-H;if(W!==2)return!1;var X=u;for(;++X,!(X>=g||(v=H=p.bMarks[X]+p.tShift[X],E=p.eMarks[X],v<E&&p.tShift[X]<p.blkIndent));)if(p[A].charAt(v)===a&&!(p.tShift[X]-p.blkIndent>=4)&&(v=p.skipChars(v,C),!(v-H<W)&&(v=p.skipSpaces(v),!(v<E)))){b=!0;break;}W=p.tShift[u],p.line=X+(b?1:0);var ve=p.getLines(u+1,X,W,!0).replace(/[ \n]+/g," ").trim();return p.tokens.push({type:"katex",params:null,content:ve,lines:[u,p.line],level:p.level,block:!0}),!0;},d=function d(p,u){var g=p.pos,b=p.posMax;var v=g;if(p[A].charAt(v)!==a)return!1;for(++v;v<b&&p[A].charAt(v)===a;)++v;var E=p[A].slice(g,v);if(E.length>2)return!1;var C=v;var H=0;for(;v<b;){var W=p[A].charAt(v);if(W==="{"&&(v===0||p[A].charAt(v-1)!=="\\"))H+=1;else if(W==="}"&&(v===0||p[A].charAt(v-1)!=="\\")){if(H-=1,H<0)return!1;}else if(W===a&&H===0){var X=v;var ve=v+1;for(;ve<b&&p[A].charAt(ve)===a;)++ve;if(ve-X===E.length){if(!u){var St=p[A].slice(C,X).replace(/[ \n]+/g," ").trim();p.push({type:"katex",content:St,block:E.length>1,level:p.level});}return p.pos=ve,!0;}}v+=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 bs;function bo(i){return bs=bs||document.createElement("textarea"),bs.innerHTML="&"+i+";",bs.value;}var ua=Object.prototype.hasOwnProperty;function pa(i,e){return i?ua.call(i,e):!1;}function vo(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 fa=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function rs(i){return i.indexOf("\\")<0?i:i.replace(fa,"$1");}function _o(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 bi(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 ma=/&([a-z#][a-z0-9]{1,31});/gi,ga=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function ya(i,e){var t=0,n=bo(e);return e!==n?n:e.charCodeAt(0)===35&&ga.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),_o(t))?bi(t):i;}function Vt(i){return i.indexOf("&")<0?i:i.replace(ma,ya);}var ba=/[&<>"]/,va=/[&<>"]/g,_a={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function Ea(i){return _a[i];}function Le(i){return ba.test(i)?i.replace(va,Ea):i;}var w={};w.blockquote_open=function(){return"<blockquote>\n";};w.blockquote_close=function(i,e){return"</blockquote>"+Xt(i,e);};w.code=function(i,e){return i[e].block?"<pre><code>"+Le(i[e].content)+"</code></pre>"+Xt(i,e):"<code>"+Le(i[e].content)+"</code>";};w.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(" "),pa(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=Le(Vt(rs(d))),o=' class="'+a+c+'"';}return t.highlight?p=t.highlight.apply(t.highlight,[r.content].concat(l))||Le(r.content):p=Le(r.content),"<pre><code"+o+">"+p+"</code></pre>"+Xt(i,e);};w.fence_custom={};w.heading_open=function(i,e){return"<h"+i[e].hLevel+">";};w.heading_close=function(i,e){return"</h"+i[e].hLevel+">\n";};w.hr=function(i,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+Xt(i,e);};w.bullet_list_open=function(){return"<ul>\n";};w.bullet_list_close=function(i,e){return"</ul>"+Xt(i,e);};w.list_item_open=function(){return"<li>";};w.list_item_close=function(){return"</li>\n";};w.ordered_list_open=function(i,e){var t=i[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};w.ordered_list_close=function(i,e){return"</ol>"+Xt(i,e);};w.paragraph_open=function(i,e){return i[e].tight?"":"<p>";};w.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?Xt(i,e):"");};w.link_open=function(i,e,t){var n=i[e].title?' title="'+Le(Vt(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Le(i[e].href)+'"'+n+s+">";};w.link_close=function(){return"</a>";};w.image=function(i,e,t){var n=' src="'+Le(i[e].src)+'"',s=i[e].title?' title="'+Le(Vt(i[e].title))+'"':"",r=' alt="'+(i[e].alt?Le(Vt(rs(i[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+r+s+o+">";};w.table_open=function(){return"<table>\n";};w.table_close=function(){return"</table>\n";};w.thead_open=function(){return"<thead>\n";};w.thead_close=function(){return"</thead>\n";};w.tbody_open=function(){return"<tbody>\n";};w.tbody_close=function(){return"</tbody>\n";};w.tr_open=function(){return"<tr>";};w.tr_close=function(){return"</tr>\n";};w.th_open=function(i,e){var t=i[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};w.th_close=function(){return"</th>";};w.td_open=function(i,e){var t=i[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};w.td_close=function(){return"</td>";};w.strong_open=function(){return"<strong>";};w.strong_close=function(){return"</strong>";};w.em_open=function(){return"<em>";};w.em_close=function(){return"</em>";};w.del_open=function(){return"<del>";};w.del_close=function(){return"</del>";};w.ins_open=function(){return"<ins>";};w.ins_close=function(){return"</ins>";};w.mark_open=function(){return"<mark>";};w.mark_close=function(){return"</mark>";};w.sub=function(i,e){return"<sub>"+Le(i[e].content)+"</sub>";};w.sup=function(i,e){return"<sup>"+Le(i[e].content)+"</sup>";};w.hardbreak=function(i,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};w.softbreak=function(i,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};w.text=function(i,e){return Le(i[e].content);};w.htmlblock=function(i,e){return i[e].content;};w.htmltag=function(i,e){return i[e].content;};w.abbr_open=function(i,e){return'<abbr title="'+Le(Vt(i[e].title))+'">';};w.abbr_close=function(){return"</abbr>";};w.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>";};w.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";};w.footnote_block_close=function(){return"</ol>\n</section>\n";};w.footnote_open=function(i,e){var t=Number(i[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};w.footnote_close=function(){return"</li>\n";};w.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>';};w.dl_open=function(){return"<dl>\n";};w.dt_open=function(){return"<dt>";};w.dd_open=function(){return"<dd>";};w.dl_close=function(){return"</dl>\n";};w.dt_close=function(){return"</dt>\n";};w.dd_close=function(){return"</dd>\n";};function Eo(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?Eo(i,e+2):e;}var Xt=w.getBreak=function(e,t){return t=Eo(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function qi(){this.rules=vo({},w),this.getBreak=w.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 je(){this.__rules__=[],this.__cache__=null;}je.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};je.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));});});};je.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;};je.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;};je.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;};je.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};je.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;};je.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;};je.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function Sa(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 Zt(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;}Zt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};Zt.prototype.push=function(i){this.pending&&this.pushPending(),this.tokens.push(i),this.pendingLevel=this.level;};Zt.prototype.cacheSet=function(i,e){for(var t=this.cache.length;t<=i;t++)this.cache.push(0);this.cache[i]=e;};Zt.prototype.cacheGet=function(i){return i<this.cache.length?this.cache[i]:0;};function os(i,e){var t,n,s,r=-1,o=i.posMax,a=i.pos,c=i.isInLabel;if(i.isInLabel)return-1;if(i.labelUnmatchedScopes)return i.labelUnmatchedScopes--,-1;for(i.pos=e+1,i.isInLabel=!0,t=1;i.pos<o;){if(s=i.src.charCodeAt(i.pos),s===91)t++;else if(s===93&&(t--,t===0)){n=!0;break;}i.parser.skipToken(i);}return n?(r=i.pos,i.labelUnmatchedScopes=0):i.labelUnmatchedScopes=t-1,i.pos=a,i.isInLabel=c,r;}function xa(i,e,t,n){var s,r,o,a,c,l;if(i.charCodeAt(0)!==42||i.charCodeAt(1)!==91||i.indexOf("]:")===-1||(s=new Zt(i,e,t,n,[]),r=os(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 Aa(i){var e=i.tokens,t,n,s,r;if(!i.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(r=xa(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function vi(i){var e=Vt(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function So(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=vi(rs(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=rs(i.src.slice(r,e)),!i.parser.validateLink(s))?!1:(i.linkContent=s,i.pos=e,!0);}function xo(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=rs(i.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function Ao(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function wa(i,e,t,n){var s,r,o,a,c,l,d,p,u;if(i.charCodeAt(0)!==91||i.indexOf("]:")===-1||(s=new Zt(i,e,t,n,[]),r=os(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(!So(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&&xo(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=Ao(i.slice(1,r)),_typeof(n.references[u])>"u"&&(n.references[u]={title:p,href:d}),o);}function Ca(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=wa(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Ta(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 Ra(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 _r=" \n()[]'\".,!?-";function hi(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function Ia(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="(^|["+_r.split("").map(hi).join("")+"])("+Object.keys(i.env.abbreviations).map(function(b){return b.substr(1);}).sort(function(b,v){return v.length-b.length;}).map(hi).join("|")+")($|["+_r.split("").map(hi).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 Ma=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,ka=/\((c|tm|r|p)\)/ig,Oa={c:"©",r:"®",p:"§",tm:"™"};function Na(i){return i.indexOf("(")<0?i:i.replace(ka,function(e,t){return Oa[t.toLowerCase()];});}function La(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=Na(n),Ma.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 Pa=/['"]/,Er=/['"]/g,Ba=/[-\s()\[\]]/,Sr="’";function xr(i,e){return e<0||e>=i.length?!1:!Ba.test(i[e]);}function en(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function Da(i){var e,t,n,s,r,o,a,c,l,d,p,u,g,b,v,E,C;if(i.options.typographer){for(C=[],v=i.tokens.length-1;v>=0;v--)if(i.tokens[v].type==="inline"){for(E=i.tokens[v].children,C.length=0,e=0;e<E.length;e++)if(t=E[e],!(t.type!=="text"||Pa.test(t.text))){for(a=E[e].level,g=C.length-1;g>=0&&!(C[g].level<=a);g--);C.length=g+1,n=t.content,r=0,o=n.length;e:for(;r<o&&(Er.lastIndex=r,s=Er.exec(n),!!s);){if(c=!xr(n,s.index-1),r=s.index+1,b=s[0]==="'",l=!xr(n,r),!l&&!c){b&&(t.content=en(t.content,s.index,Sr));continue;}if(p=!l,u=!c,u){for(g=C.length-1;g>=0&&(d=C[g],!(C[g].level<a));g--)if(d.single===b&&C[g].level===a){d=C[g],b?(E[d.token].content=en(E[d.token].content,d.pos,i.options.quotes[2]),t.content=en(t.content,s.index,i.options.quotes[3])):(E[d.token].content=en(E[d.token].content,d.pos,i.options.quotes[0]),t.content=en(t.content,s.index,i.options.quotes[1])),C.length=g;continue e;}}p?C.push({token:e,pos:s.index,single:b,level:a}):u&&b&&(t.content=en(t.content,s.index,Sr));}}}}}var ui=[["block",Sa],["abbr",Aa],["references",Ca],["inline",Ta],["footnote_tail",Ra],["abbr2",Ia],["replacements",La],["smartquotes",Da]];function wo(){this.options={},this.ruler=new je();for(var i=0;i<ui.length;i++)this.ruler.push(ui[i][0],ui[i][1]);}wo.prototype.process=function(i){var e,t,n;for(n=this.ruler.getRules(""),e=0,t=n.length;e<t;e++)n[e](i);};function Yt(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;}Yt.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};Yt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};Yt.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};Yt.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};Yt.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;};Yt.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 Fa(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 Ua(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 Ha(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,v=i.bMarks[e]+i.tShift[e],E=i.eMarks[e];if(v>E||i.src.charCodeAt(v++)!==62||i.level>=i.options.maxNesting)return!1;if(n)return!0;for(i.src.charCodeAt(v)===32&&v++,c=i.blkIndent,i.blkIndent=0,a=[i.bMarks[e]],i.bMarks[e]=v,v=v<E?i.skipSpaces(v):v,r=v>=E,o=[i.tShift[e]],i.tShift[e]=v-i.bMarks[e],p=i.parser.ruler.getRules("blockquote"),s=e+1;s<t&&(v=i.bMarks[s]+i.tShift[s],E=i.eMarks[s],!(v>=E));s++){if(i.src.charCodeAt(v++)===62){i.src.charCodeAt(v)===32&&v++,a.push(i.bMarks[s]),i.bMarks[s]=v,v=v<E?i.skipSpaces(v):v,r=v>=E,o.push(i.tShift[s]),i.tShift[s]=v-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 ja(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 Ar(i,e){var t,n,s;return n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e],n>=s||(t=i.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<s&&i.src.charCodeAt(n)!==32?-1:n;}function wr(i,e){var t,n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e];if(n+1>=s||(t=i.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=s)return-1;if(t=i.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return n<s&&i.src.charCodeAt(n)!==32?-1:n;}function qa(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 $a(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,v,E,C,H,W,X,ve,St=!0,xt,Be,ur,ci;if((p=wr(i,e))>=0)E=!0;else if((p=Ar(i,e))>=0)E=!1;else return!1;if(i.level>=i.options.maxNesting)return!1;if(v=i.src.charCodeAt(p-1),n)return!0;for(H=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:X=[e,0],level:i.level++})):i.tokens.push({type:"bullet_list_open",lines:X=[e,0],level:i.level++}),s=e,W=!1,xt=i.parser.ruler.getRules("list");s<t&&(C=i.skipSpaces(p),u=i.eMarks[s],C>=u?g=1:g=C-p,g>4&&(g=1),g<1&&(g=1),r=p-i.bMarks[s]+g,i.tokens.push({type:"list_item_open",lines:ve=[e,0],level:i.level++}),a=i.blkIndent,c=i.tight,o=i.tShift[e],l=i.parentType,i.tShift[e]=C-i.bMarks[e],i.blkIndent=r,i.tight=!0,i.parentType="list",i.parser.tokenize(i,e,t,!0),(!i.tight||W)&&(St=!1),W=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,ve[1]=s,C=i.bMarks[e],!(s>=t||i.isEmpty(s)||i.tShift[s]<i.blkIndent));){for(ci=!1,Be=0,ur=xt.length;Be<ur;Be++)if(xt[Be](i,s,t,!0)){ci=!0;break;}if(ci)break;if(E){if(p=wr(i,s),p<0)break;}else if(p=Ar(i,s),p<0)break;if(v!==i.src.charCodeAt(p-1))break;}return i.tokens.push({type:E?"ordered_list_close":"bullet_list_close",level:--i.level}),X[1]=s,i.line=s,St&&qa(i,H),!0;}function Ga(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 za(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 Va(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 Co={};["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){Co[i]=!0;});var Ja=/^<([a-zA-Z]{1,15})[\s\/>]/,Ka=/^<\/([a-zA-Z]{1,15})[\s>]/;function Wa(i){var e=i|32;return e>=97&&e<=122;}function Xa(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||Wa(s)){if(s===47){if(r=i.src.slice(a,c).match(Ka),!r)return!1;}else if(r=i.src.slice(a,c).match(Ja),!r)return!1;if(Co[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 pi(i,e){var t=i.bMarks[e]+i.blkIndent,n=i.eMarks[e];return i.src.substr(t,n-t);}function Za(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=pi(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=pi(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=pi(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 vs(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 Ya(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 Qa(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,v,E,C;if(n)return i.ddIndent<0?!1:vs(i,e)>=0;if(d=e+1,i.isEmpty(d)&&++d>t||i.tShift[d]<i.blkIndent||(s=vs(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(C=!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++}),v=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)&&(C=!1),E=i.line-r>1&&i.isEmpty(i.line-1),i.tShift[r]=b,i.tight=v,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=vs(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=vs(i,r),s<0))break;}return i.tokens.push({type:"dl_close",level:--i.level}),c[1]=d,i.line=d,C&&Ya(i,l),!0;}function ec(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 _s=[["code",Fa],["fences",Ua,["paragraph","blockquote","list"]],["blockquote",Ha,["paragraph","blockquote","list"]],["hr",ja,["paragraph","blockquote","list"]],["list",$a,["paragraph","blockquote"]],["footnote",Ga,["paragraph"]],["heading",za,["paragraph","blockquote"]],["lheading",Va],["htmlblock",Xa,["paragraph","blockquote"]],["table",Za,["paragraph"]],["deflist",Qa,["paragraph"]],["paragraph",ec]];function $i(){this.ruler=new je();for(var i=0;i<_s.length;i++)this.ruler.push(_s[i][0],_s[i][1],{alt:(_s[i][2]||[]).slice()});}$i.prototype.tokenize=function(i,e,t){for(var n=this.ruler.getRules(""),s=n.length,r=e,o=!1,a,c;r<t&&(i.line=r=i.skipEmptyLines(r),!(r>=t||i.tShift[r]<i.blkIndent));){for(c=0;c<s&&(a=n[c](i,r,t,!1),!a);c++);if(i.tight=!o,i.isEmpty(i.line-1)&&(o=!0),r=i.line,r<t&&i.isEmpty(r)){if(o=!0,r++,r<t&&i.parentType==="list"&&i.isEmpty(r))break;i.line=r;}}};var tc=/[\n\t]/g,nc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,sc=/\u00a0/g;$i.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(sc," "),i=i.replace(nc,"\n"),i.indexOf(" ")>=0&&(i=i.replace(tc,function(a,c){var l;return i.charCodeAt(c)===10?(r=c+1,o=0,a):(l=" ".slice((c-r-o)%4),o=c-r+1,l);})),s=new Yt(i,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function ic(i){switch(i){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1;}}function rc(i,e){for(var t=i.pos;t<i.posMax&&!ic(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function oc(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 Gi=[];for(var Cr=0;Cr<256;Cr++)Gi.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){Gi[i.charCodeAt(0)]=1;});function ac(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&&Gi[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 cc(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 lc(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 dc(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 hc(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 Tr(i){return i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122;}function Rr(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&&(Tr(n)&&(o=!1),Tr(s)&&(a=!1))),{can_open:o,can_close:a,delims:r};}function uc(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=Rr(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=Rr(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 pc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function fc(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(pc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var mc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function gc(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(mc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function yc(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=os(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,So(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&&xo(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=os(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[Ao(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 bc(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=os(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 vc(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 _c=["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"],Ec=/^<([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])?)*)>/,Sc=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function xc(i,e){var t,n,s,r,o,a=i.pos;return i.src.charCodeAt(a)!==60||(t=i.src.slice(a),t.indexOf(">")<0)?!1:(n=t.match(Sc),n?_c.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=vi(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(Ec),s?(r=s[0].slice(1,-1),o=vi("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 Qs(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 Ac=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,wc=/[^"'=<>`\x00-\x20]+/,Cc=/'[^']*'/,Tc=/"[^"]*"/,Rc=Qs(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",wc)("single_quoted",Cc)("double_quoted",Tc)(),Ic=Qs(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Ac)("attr_value",Rc)(),Mc=Qs(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",Ic)(),kc=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Oc=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Nc=/<[?].*?[?]>/,Lc=/<![A-Z]+\s+[^>]*>/,Pc=/<!\[CDATA\[[\s\S]*?\]\]>/,Bc=Qs(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Mc)("close_tag",kc)("comment",Oc)("processing",Nc)("declaration",Lc)("cdata",Pc)();function Dc(i){var e=i|32;return e>=97&&e<=122;}function Fc(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&&!Dc(t))||(n=i.src.slice(r).match(Bc),!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 Uc=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Hc=/^&([a-z][a-z0-9]{1,31});/i;function jc(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(Uc),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=_o(n)?bi(n):bi(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match(Hc),s){var a=bo(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 fi=[["text",rc],["newline",oc],["escape",ac],["backticks",cc],["del",lc],["ins",dc],["mark",hc],["emphasis",uc],["sub",fc],["sup",gc],["links",yc],["footnote_inline",bc],["footnote_ref",vc],["autolink",xc],["htmltag",Fc],["entity",jc]];function ei(){this.ruler=new je();for(var i=0;i<fi.length;i++)this.ruler.push(fi[i][0],fi[i][1]);this.validateLink=qc;}ei.prototype.skipToken=function(i){var e=this.ruler.getRules(""),t=e.length,n=i.pos,s,r;if((r=i.cacheGet(n))>0){i.pos=r;return;}for(s=0;s<t;s++)if(e[s](i,!0)){i.cacheSet(n,i.pos);return;}i.pos++,i.cacheSet(n,i.pos);};ei.prototype.tokenize=function(i){for(var e=this.ruler.getRules(""),t=e.length,n=i.posMax,s,r;i.pos<n;){for(r=0;r<t&&(s=e[r](i,!1),!s);r++);if(s){if(i.pos>=n)break;continue;}i.pending+=i.src[i.pos++];}i.pending&&i.pushPending();};ei.prototype.parse=function(i,e,t,n){var s=new Zt(i,this,e,t,n);this.tokenize(s);};function qc(i){var e=["vbscript","javascript","file","data"],t=i.trim().toLowerCase();return t=Vt(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var $c={options:{html:!1,// Enable HTML tags in source
18
+ },{key:"overwrite",value:function overwrite(e,t,n,s){var r=e.messageToElements,o=N.overwriteMessage(r,s,t,n,M,wt.HTML_BUBBLE_CLASS);return o&&wt.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=wt.createElements(e,t,n,s);return N.fillEmptyMessageElement(r.bubbleElement,t),Z.apply(e,r.outerContainer),te.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,n,!1,(o=e.messageStyles)==null?void 0:o[M]),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&&Z.isTemporaryBasedOnHTML(t))return;var o=wt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();wt.HTML_BUBBLE_CLASS="html-message";var at=wt;var ha=/*#__PURE__*/function(){function ha(){_classCallCheck(this,ha);}return _createClass(ha,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,v=p.bMarks[u]+p.tShift[u],E=p.eMarks[u];if(v+1>E)return!1;var C=p[A].charAt(v);if(C!==a)return!1;var H=v;v=p.skipChars(v,C);var W=v-H;if(W!==2)return!1;var X=u;for(;++X,!(X>=g||(v=H=p.bMarks[X]+p.tShift[X],E=p.eMarks[X],v<E&&p.tShift[X]<p.blkIndent));)if(p[A].charAt(v)===a&&!(p.tShift[X]-p.blkIndent>=4)&&(v=p.skipChars(v,C),!(v-H<W)&&(v=p.skipSpaces(v),!(v<E)))){b=!0;break;}W=p.tShift[u],p.line=X+(b?1:0);var ve=p.getLines(u+1,X,W,!0).replace(/[ \n]+/g," ").trim();return p.tokens.push({type:"katex",params:null,content:ve,lines:[u,p.line],level:p.level,block:!0}),!0;},d=function d(p,u){var g=p.pos,b=p.posMax;var v=g;if(p[A].charAt(v)!==a)return!1;for(++v;v<b&&p[A].charAt(v)===a;)++v;var E=p[A].slice(g,v);if(E.length>2)return!1;var C=v;var H=0;for(;v<b;){var W=p[A].charAt(v);if(W==="{"&&(v===0||p[A].charAt(v-1)!=="\\"))H+=1;else if(W==="}"&&(v===0||p[A].charAt(v-1)!=="\\")){if(H-=1,H<0)return!1;}else if(W===a&&H===0){var X=v;var ve=v+1;for(;ve<b&&p[A].charAt(ve)===a;)++ve;if(ve-X===E.length){if(!u){var St=p[A].slice(C,X).replace(/[ \n]+/g," ").trim();p.push({type:"katex",content:St,block:E.length>1,level:p.level});}return p.pos=ve,!0;}}v+=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 bs;function bo(i){return bs=bs||document.createElement("textarea"),bs.innerHTML="&"+i+";",bs.value;}var ua=Object.prototype.hasOwnProperty;function pa(i,e){return i?ua.call(i,e):!1;}function vo(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 fa=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function rs(i){return i.indexOf("\\")<0?i:i.replace(fa,"$1");}function _o(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 bi(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 ma=/&([a-z#][a-z0-9]{1,31});/gi,ga=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function ya(i,e){var t=0,n=bo(e);return e!==n?n:e.charCodeAt(0)===35&&ga.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),_o(t))?bi(t):i;}function Vt(i){return i.indexOf("&")<0?i:i.replace(ma,ya);}var ba=/[&<>"]/,va=/[&<>"]/g,_a={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function Ea(i){return _a[i];}function Le(i){return ba.test(i)?i.replace(va,Ea):i;}var w={};w.blockquote_open=function(){return"<blockquote>\n";};w.blockquote_close=function(i,e){return"</blockquote>"+Xt(i,e);};w.code=function(i,e){return i[e].block?"<pre><code>"+Le(i[e].content)+"</code></pre>"+Xt(i,e):"<code>"+Le(i[e].content)+"</code>";};w.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(" "),pa(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=Le(Vt(rs(d))),o=' class="'+a+c+'"';}return t.highlight?p=t.highlight.apply(t.highlight,[r.content].concat(l))||Le(r.content):p=Le(r.content),"<pre><code"+o+">"+p+"</code></pre>"+Xt(i,e);};w.fence_custom={};w.heading_open=function(i,e){return"<h"+i[e].hLevel+">";};w.heading_close=function(i,e){return"</h"+i[e].hLevel+">\n";};w.hr=function(i,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+Xt(i,e);};w.bullet_list_open=function(){return"<ul>\n";};w.bullet_list_close=function(i,e){return"</ul>"+Xt(i,e);};w.list_item_open=function(){return"<li>";};w.list_item_close=function(){return"</li>\n";};w.ordered_list_open=function(i,e){var t=i[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};w.ordered_list_close=function(i,e){return"</ol>"+Xt(i,e);};w.paragraph_open=function(i,e){return i[e].tight?"":"<p>";};w.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?Xt(i,e):"");};w.link_open=function(i,e,t){var n=i[e].title?' title="'+Le(Vt(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Le(i[e].href)+'"'+n+s+">";};w.link_close=function(){return"</a>";};w.image=function(i,e,t){var n=' src="'+Le(i[e].src)+'"',s=i[e].title?' title="'+Le(Vt(i[e].title))+'"':"",r=' alt="'+(i[e].alt?Le(Vt(rs(i[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+r+s+o+">";};w.table_open=function(){return"<table>\n";};w.table_close=function(){return"</table>\n";};w.thead_open=function(){return"<thead>\n";};w.thead_close=function(){return"</thead>\n";};w.tbody_open=function(){return"<tbody>\n";};w.tbody_close=function(){return"</tbody>\n";};w.tr_open=function(){return"<tr>";};w.tr_close=function(){return"</tr>\n";};w.th_open=function(i,e){var t=i[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};w.th_close=function(){return"</th>";};w.td_open=function(i,e){var t=i[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};w.td_close=function(){return"</td>";};w.strong_open=function(){return"<strong>";};w.strong_close=function(){return"</strong>";};w.em_open=function(){return"<em>";};w.em_close=function(){return"</em>";};w.del_open=function(){return"<del>";};w.del_close=function(){return"</del>";};w.ins_open=function(){return"<ins>";};w.ins_close=function(){return"</ins>";};w.mark_open=function(){return"<mark>";};w.mark_close=function(){return"</mark>";};w.sub=function(i,e){return"<sub>"+Le(i[e].content)+"</sub>";};w.sup=function(i,e){return"<sup>"+Le(i[e].content)+"</sup>";};w.hardbreak=function(i,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};w.softbreak=function(i,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};w.text=function(i,e){return Le(i[e].content);};w.htmlblock=function(i,e){return i[e].content;};w.htmltag=function(i,e){return i[e].content;};w.abbr_open=function(i,e){return'<abbr title="'+Le(Vt(i[e].title))+'">';};w.abbr_close=function(){return"</abbr>";};w.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>";};w.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";};w.footnote_block_close=function(){return"</ol>\n</section>\n";};w.footnote_open=function(i,e){var t=Number(i[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};w.footnote_close=function(){return"</li>\n";};w.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>';};w.dl_open=function(){return"<dl>\n";};w.dt_open=function(){return"<dt>";};w.dd_open=function(){return"<dd>";};w.dl_close=function(){return"</dl>\n";};w.dt_close=function(){return"</dt>\n";};w.dd_close=function(){return"</dd>\n";};function Eo(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?Eo(i,e+2):e;}var Xt=w.getBreak=function(e,t){return t=Eo(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function qi(){this.rules=vo({},w),this.getBreak=w.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 je(){this.__rules__=[],this.__cache__=null;}je.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};je.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));});});};je.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;};je.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;};je.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;};je.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};je.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;};je.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;};je.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function Sa(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 Zt(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;}Zt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};Zt.prototype.push=function(i){this.pending&&this.pushPending(),this.tokens.push(i),this.pendingLevel=this.level;};Zt.prototype.cacheSet=function(i,e){for(var t=this.cache.length;t<=i;t++)this.cache.push(0);this.cache[i]=e;};Zt.prototype.cacheGet=function(i){return i<this.cache.length?this.cache[i]:0;};function os(i,e){var t,n,s,r=-1,o=i.posMax,a=i.pos,c=i.isInLabel;if(i.isInLabel)return-1;if(i.labelUnmatchedScopes)return i.labelUnmatchedScopes--,-1;for(i.pos=e+1,i.isInLabel=!0,t=1;i.pos<o;){if(s=i.src.charCodeAt(i.pos),s===91)t++;else if(s===93&&(t--,t===0)){n=!0;break;}i.parser.skipToken(i);}return n?(r=i.pos,i.labelUnmatchedScopes=0):i.labelUnmatchedScopes=t-1,i.pos=a,i.isInLabel=c,r;}function xa(i,e,t,n){var s,r,o,a,c,l;if(i.charCodeAt(0)!==42||i.charCodeAt(1)!==91||i.indexOf("]:")===-1||(s=new Zt(i,e,t,n,[]),r=os(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 Aa(i){var e=i.tokens,t,n,s,r;if(!i.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(r=xa(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function vi(i){var e=Vt(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function So(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=vi(rs(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=rs(i.src.slice(r,e)),!i.parser.validateLink(s))?!1:(i.linkContent=s,i.pos=e,!0);}function xo(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=rs(i.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function Ao(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function wa(i,e,t,n){var s,r,o,a,c,l,d,p,u;if(i.charCodeAt(0)!==91||i.indexOf("]:")===-1||(s=new Zt(i,e,t,n,[]),r=os(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(!So(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&&xo(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=Ao(i.slice(1,r)),_typeof(n.references[u])>"u"&&(n.references[u]={title:p,href:d}),o);}function Ca(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=wa(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Ta(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 Ra(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 _r=" \n()[]'\".,!?-";function hi(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function Ia(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="(^|["+_r.split("").map(hi).join("")+"])("+Object.keys(i.env.abbreviations).map(function(b){return b.substr(1);}).sort(function(b,v){return v.length-b.length;}).map(hi).join("|")+")($|["+_r.split("").map(hi).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 Ma=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,ka=/\((c|tm|r|p)\)/ig,Oa={c:"©",r:"®",p:"§",tm:"™"};function Na(i){return i.indexOf("(")<0?i:i.replace(ka,function(e,t){return Oa[t.toLowerCase()];});}function La(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=Na(n),Ma.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 Pa=/['"]/,Er=/['"]/g,Ba=/[-\s()\[\]]/,Sr="’";function xr(i,e){return e<0||e>=i.length?!1:!Ba.test(i[e]);}function en(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function Da(i){var e,t,n,s,r,o,a,c,l,d,p,u,g,b,v,E,C;if(i.options.typographer){for(C=[],v=i.tokens.length-1;v>=0;v--)if(i.tokens[v].type==="inline"){for(E=i.tokens[v].children,C.length=0,e=0;e<E.length;e++)if(t=E[e],!(t.type!=="text"||Pa.test(t.text))){for(a=E[e].level,g=C.length-1;g>=0&&!(C[g].level<=a);g--);C.length=g+1,n=t.content,r=0,o=n.length;e:for(;r<o&&(Er.lastIndex=r,s=Er.exec(n),!!s);){if(c=!xr(n,s.index-1),r=s.index+1,b=s[0]==="'",l=!xr(n,r),!l&&!c){b&&(t.content=en(t.content,s.index,Sr));continue;}if(p=!l,u=!c,u){for(g=C.length-1;g>=0&&(d=C[g],!(C[g].level<a));g--)if(d.single===b&&C[g].level===a){d=C[g],b?(E[d.token].content=en(E[d.token].content,d.pos,i.options.quotes[2]),t.content=en(t.content,s.index,i.options.quotes[3])):(E[d.token].content=en(E[d.token].content,d.pos,i.options.quotes[0]),t.content=en(t.content,s.index,i.options.quotes[1])),C.length=g;continue e;}}p?C.push({token:e,pos:s.index,single:b,level:a}):u&&b&&(t.content=en(t.content,s.index,Sr));}}}}}var ui=[["block",Sa],["abbr",Aa],["references",Ca],["inline",Ta],["footnote_tail",Ra],["abbr2",Ia],["replacements",La],["smartquotes",Da]];function wo(){this.options={},this.ruler=new je();for(var i=0;i<ui.length;i++)this.ruler.push(ui[i][0],ui[i][1]);}wo.prototype.process=function(i){var e,t,n;for(n=this.ruler.getRules(""),e=0,t=n.length;e<t;e++)n[e](i);};function Yt(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;}Yt.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};Yt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};Yt.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};Yt.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};Yt.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;};Yt.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 Fa(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 Ua(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 Ha(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,v=i.bMarks[e]+i.tShift[e],E=i.eMarks[e];if(v>E||i.src.charCodeAt(v++)!==62||i.level>=i.options.maxNesting)return!1;if(n)return!0;for(i.src.charCodeAt(v)===32&&v++,c=i.blkIndent,i.blkIndent=0,a=[i.bMarks[e]],i.bMarks[e]=v,v=v<E?i.skipSpaces(v):v,r=v>=E,o=[i.tShift[e]],i.tShift[e]=v-i.bMarks[e],p=i.parser.ruler.getRules("blockquote"),s=e+1;s<t&&(v=i.bMarks[s]+i.tShift[s],E=i.eMarks[s],!(v>=E));s++){if(i.src.charCodeAt(v++)===62){i.src.charCodeAt(v)===32&&v++,a.push(i.bMarks[s]),i.bMarks[s]=v,v=v<E?i.skipSpaces(v):v,r=v>=E,o.push(i.tShift[s]),i.tShift[s]=v-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 ja(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 Ar(i,e){var t,n,s;return n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e],n>=s||(t=i.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<s&&i.src.charCodeAt(n)!==32?-1:n;}function wr(i,e){var t,n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e];if(n+1>=s||(t=i.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=s)return-1;if(t=i.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return n<s&&i.src.charCodeAt(n)!==32?-1:n;}function qa(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 $a(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,v,E,C,H,W,X,ve,St=!0,xt,Be,ur,ci;if((p=wr(i,e))>=0)E=!0;else if((p=Ar(i,e))>=0)E=!1;else return!1;if(i.level>=i.options.maxNesting)return!1;if(v=i.src.charCodeAt(p-1),n)return!0;for(H=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:X=[e,0],level:i.level++})):i.tokens.push({type:"bullet_list_open",lines:X=[e,0],level:i.level++}),s=e,W=!1,xt=i.parser.ruler.getRules("list");s<t&&(C=i.skipSpaces(p),u=i.eMarks[s],C>=u?g=1:g=C-p,g>4&&(g=1),g<1&&(g=1),r=p-i.bMarks[s]+g,i.tokens.push({type:"list_item_open",lines:ve=[e,0],level:i.level++}),a=i.blkIndent,c=i.tight,o=i.tShift[e],l=i.parentType,i.tShift[e]=C-i.bMarks[e],i.blkIndent=r,i.tight=!0,i.parentType="list",i.parser.tokenize(i,e,t,!0),(!i.tight||W)&&(St=!1),W=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,ve[1]=s,C=i.bMarks[e],!(s>=t||i.isEmpty(s)||i.tShift[s]<i.blkIndent));){for(ci=!1,Be=0,ur=xt.length;Be<ur;Be++)if(xt[Be](i,s,t,!0)){ci=!0;break;}if(ci)break;if(E){if(p=wr(i,s),p<0)break;}else if(p=Ar(i,s),p<0)break;if(v!==i.src.charCodeAt(p-1))break;}return i.tokens.push({type:E?"ordered_list_close":"bullet_list_close",level:--i.level}),X[1]=s,i.line=s,St&&qa(i,H),!0;}function Ga(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 za(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 Va(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 Co={};["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){Co[i]=!0;});var Ja=/^<([a-zA-Z]{1,15})[\s\/>]/,Ka=/^<\/([a-zA-Z]{1,15})[\s>]/;function Wa(i){var e=i|32;return e>=97&&e<=122;}function Xa(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||Wa(s)){if(s===47){if(r=i.src.slice(a,c).match(Ka),!r)return!1;}else if(r=i.src.slice(a,c).match(Ja),!r)return!1;if(Co[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 pi(i,e){var t=i.bMarks[e]+i.blkIndent,n=i.eMarks[e];return i.src.substr(t,n-t);}function Za(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=pi(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=pi(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=pi(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 vs(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 Ya(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 Qa(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,b,v,E,C;if(n)return i.ddIndent<0?!1:vs(i,e)>=0;if(d=e+1,i.isEmpty(d)&&++d>t||i.tShift[d]<i.blkIndent||(s=vs(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(C=!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++}),v=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)&&(C=!1),E=i.line-r>1&&i.isEmpty(i.line-1),i.tShift[r]=b,i.tight=v,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=vs(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=vs(i,r),s<0))break;}return i.tokens.push({type:"dl_close",level:--i.level}),c[1]=d,i.line=d,C&&Ya(i,l),!0;}function ec(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 _s=[["code",Fa],["fences",Ua,["paragraph","blockquote","list"]],["blockquote",Ha,["paragraph","blockquote","list"]],["hr",ja,["paragraph","blockquote","list"]],["list",$a,["paragraph","blockquote"]],["footnote",Ga,["paragraph"]],["heading",za,["paragraph","blockquote"]],["lheading",Va],["htmlblock",Xa,["paragraph","blockquote"]],["table",Za,["paragraph"]],["deflist",Qa,["paragraph"]],["paragraph",ec]];function $i(){this.ruler=new je();for(var i=0;i<_s.length;i++)this.ruler.push(_s[i][0],_s[i][1],{alt:(_s[i][2]||[]).slice()});}$i.prototype.tokenize=function(i,e,t){for(var n=this.ruler.getRules(""),s=n.length,r=e,o=!1,a,c;r<t&&(i.line=r=i.skipEmptyLines(r),!(r>=t||i.tShift[r]<i.blkIndent));){for(c=0;c<s&&(a=n[c](i,r,t,!1),!a);c++);if(i.tight=!o,i.isEmpty(i.line-1)&&(o=!0),r=i.line,r<t&&i.isEmpty(r)){if(o=!0,r++,r<t&&i.parentType==="list"&&i.isEmpty(r))break;i.line=r;}}};var tc=/[\n\t]/g,nc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,sc=/\u00a0/g;$i.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(sc," "),i=i.replace(nc,"\n"),i.indexOf(" ")>=0&&(i=i.replace(tc,function(a,c){var l;return i.charCodeAt(c)===10?(r=c+1,o=0,a):(l=" ".slice((c-r-o)%4),o=c-r+1,l);})),s=new Yt(i,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function ic(i){switch(i){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1;}}function rc(i,e){for(var t=i.pos;t<i.posMax&&!ic(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function oc(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 Gi=[];for(var Cr=0;Cr<256;Cr++)Gi.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){Gi[i.charCodeAt(0)]=1;});function ac(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&&Gi[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 cc(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 lc(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 dc(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 hc(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 Tr(i){return i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122;}function Rr(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&&(Tr(n)&&(o=!1),Tr(s)&&(a=!1))),{can_open:o,can_close:a,delims:r};}function uc(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=Rr(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=Rr(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 pc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function fc(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(pc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var mc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function gc(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(mc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function yc(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=os(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,So(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&&xo(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=os(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[Ao(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 bc(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=os(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 vc(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 _c=["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"],Ec=/^<([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])?)*)>/,Sc=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function xc(i,e){var t,n,s,r,o,a=i.pos;return i.src.charCodeAt(a)!==60||(t=i.src.slice(a),t.indexOf(">")<0)?!1:(n=t.match(Sc),n?_c.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=vi(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(Ec),s?(r=s[0].slice(1,-1),o=vi("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 Qs(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 Ac=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,wc=/[^"'=<>`\x00-\x20]+/,Cc=/'[^']*'/,Tc=/"[^"]*"/,Rc=Qs(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",wc)("single_quoted",Cc)("double_quoted",Tc)(),Ic=Qs(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Ac)("attr_value",Rc)(),Mc=Qs(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",Ic)(),kc=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Oc=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Nc=/<[?].*?[?]>/,Lc=/<![A-Z]+\s+[^>]*>/,Pc=/<!\[CDATA\[[\s\S]*?\]\]>/,Bc=Qs(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Mc)("close_tag",kc)("comment",Oc)("processing",Nc)("declaration",Lc)("cdata",Pc)();function Dc(i){var e=i|32;return e>=97&&e<=122;}function Fc(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&&!Dc(t))||(n=i.src.slice(r).match(Bc),!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 Uc=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Hc=/^&([a-z][a-z0-9]{1,31});/i;function jc(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(Uc),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=_o(n)?bi(n):bi(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match(Hc),s){var a=bo(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 fi=[["text",rc],["newline",oc],["escape",ac],["backticks",cc],["del",lc],["ins",dc],["mark",hc],["emphasis",uc],["sub",fc],["sup",gc],["links",yc],["footnote_inline",bc],["footnote_ref",vc],["autolink",xc],["htmltag",Fc],["entity",jc]];function ei(){this.ruler=new je();for(var i=0;i<fi.length;i++)this.ruler.push(fi[i][0],fi[i][1]);this.validateLink=qc;}ei.prototype.skipToken=function(i){var e=this.ruler.getRules(""),t=e.length,n=i.pos,s,r;if((r=i.cacheGet(n))>0){i.pos=r;return;}for(s=0;s<t;s++)if(e[s](i,!0)){i.cacheSet(n,i.pos);return;}i.pos++,i.cacheSet(n,i.pos);};ei.prototype.tokenize=function(i){for(var e=this.ruler.getRules(""),t=e.length,n=i.posMax,s,r;i.pos<n;){for(r=0;r<t&&(s=e[r](i,!1),!s);r++);if(s){if(i.pos>=n)break;continue;}i.pending+=i.src[i.pos++];}i.pending&&i.pushPending();};ei.prototype.parse=function(i,e,t,n){var s=new Zt(i,this,e,t,n);this.tokenize(s);};function qc(i){var e=["vbscript","javascript","file","data"],t=i.trim().toLowerCase();return t=Vt(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var $c={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
@@ -73,7 +73,7 @@ function setElementProps(e,t,n,s){var r;n!=="loading"&&(e.applyCustomStyles(t,s,
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===P||(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===j||(n==null?void 0:n.startsWith("data:image"))||n&&ue.isImageFileExtension(n);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();var Jt=/*#__PURE__*/function(){function Jt(){_classCallCheck(this,Jt);}return _createClass(Jt,null,[{key:"onMessage",value:function onMessage(e,t,n){var r;var s=JSON.parse(JSON.stringify({message:t,isHistory:n,isInitial:n}));ue.reAddFileRefToObject(t,s.message),(r=e.onMessage)==null||r.call(e,s),e.dispatchEvent(new CustomEvent("message",{detail:s})),te.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=JSON.parse(JSON.stringify({content:t,isUser:n}));t[y]&&ue.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 me=/*#__PURE__*/function(){function me(){_classCallCheck(this,me);}return _createClass(me,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=S();return e[m].add("loading-history"),e.appendChild(S()),e.appendChild(S()),e.appendChild(S()),e.appendChild(S()),e;}},{key:"apply",value:function apply(e,t,n){rt.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=JSON.parse(JSON.stringify(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(me.CLASS);var s=n?me.FULL_VIEW_CLASS:me.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;me.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==po&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",J),n=t.bubbleElement,s=me.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[I],s=n?at.createElements(e,n,J,!0,!0):me.createDefaultElements(e);return me.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(me.FULL_VIEW_CLASS)){t.outerContainer[m].replace(me.FULL_VIEW_CLASS,me.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&&me.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[I];return u&&(t.bubbleElement.innerHTML=u),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];me.tryChangeViewToSmall(e,t)||me.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();me.CLASS="loading-history-message",me.FULL_VIEW_CLASS="loading-history-message-full-view",me.SMALL_CLASS="loading-history-message-small";var vt=me;var es=/*#__PURE__*/function(){function es(){_classCallCheck(this,es);}return _createClass(es,null,[{key:"setFade",value:function setFade(e,t){e[_].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(es.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[_].opacity="0";n=typeof t=="number"?t:es.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(s){setTimeout(function(){return s();},n);});case 1:e[_].opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();es.DEFAULT_FADE_MS=500;var Is=es;var Kc=/*#__PURE__*/function(){function Kc(e,t){_classCallCheck(this,Kc);this.hiddenElements=/* @__PURE__ */new Set(),_typeof(t)=="object"&&(this.config=t),this._messages=e,this.io=this.initIntersectionObserver(this._messages.elementRef),this.element=this.createElement(),this._messages.elementRef.appendChild(this.element);}return _createClass(Kc,[{key:"initIntersectionObserver",value:function initIntersectionObserver(e){var _this3=this;return new IntersectionObserver(function(t){t.forEach(function(n){n.isIntersecting&&_this3.hiddenElements.has(n.target)&&(_this3.hiddenElements["delete"](n.target),_this3.io.unobserve(n.target),_this3.updateElement());});},{root:e,threshold:0.1});}},{key:"createElement",value:function createElement(){var _this4=this;var n,s,r;var e=S();e.id="hidden-messages",e.onclick=function(){var o;if(((o=_this4.config)==null?void 0:o.clickScroll)==="last")ce.scrollToBottom(_this4._messages,!0);else{var a=_this4.hiddenElements.values().next().value;a&&_this4._messages.elementRef.scrollTo({left:0,top:a.offsetTop,behavior:"smooth"});}},Z.apply(this._messages,e),Object.assign(e[_],(s=(n=this.config)==null?void 0:n.styles)==null?void 0:s[x]);var t=ee.processStateful(((r=this.config)==null?void 0:r.styles)||{});return yt.add(e,t),e;}},{key:"update",value:function update(){var t;var e=(t=this._messages.getFirstMessageContentEl())==null?void 0:t.outerContainer;e&&!ce.isVisibleInParent(e,this._messages.elementRef)&&(this.hiddenElements.add(e),this.io.observe(e),this.updateElement());}},{key:"clear",value:function clear(){var _this5=this;this.hiddenElements.forEach(function(e){return _this5.io.unobserve(e);}),this.hiddenElements.clear(),this.updateElement();}},{key:"updateElement",value:function updateElement(){var e;if(this.element){var t=this.hiddenElements.size,n="".concat(t," new message").concat(t===1?"":"s");if((e=this.config)!=null&&e.onUpdate){var s=this.config.onUpdate(n,t);this.element.innerHTML=s,Z.apply(this._messages,this.element);}else this.element.innerHTML=n;this.element[_].display=t?"flex":"none";}}}]);}();var Ir="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",_i="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 Ro=/*#__PURE__*/function(){function Ro(e){_classCallCheck(this,Ro);this.className=e;}return _createClass(Ro,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e)[_]).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e)[_].visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e)[m].add("role-hidden");}}]);}();var dt=/*#__PURE__*/function(_Ro){function dt(e){var _this6;_classCallCheck(this,dt);_this6=_callSuper(this,dt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(dt,_Ro);return _createClass(dt,[{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===Mt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Mt?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var r,o,a,c,l;var n=S("img");e===U?(n[A]=((r=t==null?void 0:t[U])==null?void 0:r[A])||((o=t==null?void 0:t[x])==null?void 0:o[A])||_i,n.onerror=dt.errorFallback.bind(this,_i)):(n[A]=((a=t==null?void 0:t[e])==null?void 0:a[A])||((c=t==null?void 0:t[J])==null?void 0:c[A])||((l=t==null?void 0:t[x])==null?void 0:l[A])||Ir,n.onerror=dt.errorFallback.bind(this,Ir)),n[m].add("avatar"),n.alt="".concat(e," avatar");var s=S();return s[m].add(this.className),s.appendChild(n),t&&dt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,r,o,a,c,l;var n=te.processPosition((r=(s=t==null?void 0:t[e])==null?void 0:s.styles)==null?void 0:r.position);return e!==U&&(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[x])==null?void 0:c.styles)==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===U?uo:Mt,n;}}],[{key:"errorFallback",value:function errorFallback(e,t){var n=t.target;n.onerror=null,n[A]=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){Object.assign(e[_],n.container),Object.assign(t[_],n.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){var r,o,a,c;if((r=n[x])!=null&&r.styles&&dt.applyCustomStylesToElements(e,t,n[x].styles),s===U)(o=n.user)!=null&&o.styles&&dt.applyCustomStylesToElements(e,t,n.user.styles);else{(a=n.ai)!=null&&a.styles&&dt.applyCustomStylesToElements(e,t,n.ai.styles);var l=(c=n[s])==null?void 0:c.styles;l&&dt.applyCustomStylesToElements(e,t,l);}}}]);}(Ro);var Kn=/*#__PURE__*/function(_Ro2){function Kn(e){var _this7;_classCallCheck(this,Kn);_this7=_callSuper(this,Kn,["name"]),_this7._names=e;return _this7;}_inherits(Kn,_Ro2);return _createClass(Kn,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),r=Kn.getPosition(t,n);s[m].add(r===Mt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Mt?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=S();return n[m].add(this.className),n.textContent=Kn.getNameText(e,t),Kn.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,r,o;var n=te.processPosition((s=t==null?void 0:t[e])==null?void 0:s.position);return e!==U&&(n!==null&&n!==void 0?n:n=(r=t==null?void 0:t[J])==null?void 0:r.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[x])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===U?uo:Mt,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,r,o,a;Object.assign(e[_],(s=n[x])==null?void 0:s[_]),t===U?Object.assign(e[_],(r=n[U])==null?void 0:r[_]):(Object.assign(e[_],(o=n[J])==null?void 0:o[_]),Object.assign(e[_],(a=n[t])==null?void 0:a[_]));}},{key:"getNameText",value:function getNameText(e,t){var n,s,r,o,a,c;return e===U?((n=t[U])==null?void 0:n[h])||((s=t[x])==null?void 0:s[h])||"User":e===J?((r=t[J])==null?void 0:r[h])||((o=t[x])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[x])==null?void 0:c[h])||e;}}]);}(Ro);var Me=/*#__PURE__*/function(){function Me(e){var _this8=this;_classCallCheck(this,Me);var t,n,s,r;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=Me.createContainerElement(),this.messageStyles=te.processMessageStyles(e.messageStyles),this._remarkable=as.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new dt(e.avatars)),e.names&&(this.name=new Kn(e.names)),e.browserStorage&&(this.browserStorage=new Jc(e.browserStorage)),this._onMessage=Jt.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),e.hiddenMessages&&(this.hiddenMessages=new Kc(this,e.hiddenMessages)),this.focusMode=te.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=S(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Is.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||te.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(Me,[{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(Me.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===P||(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===j||(n==null?void 0:n.startsWith("data:image"))||n&&ue.isImageFileExtension(n);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();var Jt=/*#__PURE__*/function(){function Jt(){_classCallCheck(this,Jt);}return _createClass(Jt,null,[{key:"onMessage",value:function onMessage(e,t,n){var r;var s=JSON.parse(JSON.stringify({message:t,isHistory:n,isInitial:n}));ue.reAddFileRefToObject(t,s.message),(r=e.onMessage)==null||r.call(e,s),e.dispatchEvent(new CustomEvent("message",{detail:s})),te.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=JSON.parse(JSON.stringify({content:t,isUser:n}));t[y]&&ue.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 me=/*#__PURE__*/function(){function me(){_classCallCheck(this,me);}return _createClass(me,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=S();return e[m].add("loading-history"),e.appendChild(S()),e.appendChild(S()),e.appendChild(S()),e.appendChild(S()),e;}},{key:"apply",value:function apply(e,t,n){rt.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=JSON.parse(JSON.stringify(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(me.CLASS);var s=n?me.FULL_VIEW_CLASS:me.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;me.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==po&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",J),n=t.bubbleElement,s=me.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[M],s=n?at.createElements(e,n,J,!0,!0):me.createDefaultElements(e);return me.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(me.FULL_VIEW_CLASS)){t.outerContainer[m].replace(me.FULL_VIEW_CLASS,me.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&&me.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[M];return u&&(t.bubbleElement.innerHTML=u),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];me.tryChangeViewToSmall(e,t)||me.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();me.CLASS="loading-history-message",me.FULL_VIEW_CLASS="loading-history-message-full-view",me.SMALL_CLASS="loading-history-message-small";var vt=me;var es=/*#__PURE__*/function(){function es(){_classCallCheck(this,es);}return _createClass(es,null,[{key:"setFade",value:function setFade(e,t){e[_].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(es.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[_].opacity="0";n=typeof t=="number"?t:es.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(s){setTimeout(function(){return s();},n);});case 1:e[_].opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();es.DEFAULT_FADE_MS=500;var Is=es;var Kc=/*#__PURE__*/function(){function Kc(e,t,n){_classCallCheck(this,Kc);this.hiddenElements=/* @__PURE__ */new Set(),_typeof(t)=="object"&&(this.config=t),_typeof(n)=="object"&&(this.scrollButtonConfig=n),console.log(this.scrollButtonConfig),this._messages=e,this.io=this.initIntersectionObserver(this._messages.elementRef),this.element=this.createElement(),this._messages.elementRef.appendChild(this.element);}return _createClass(Kc,[{key:"initIntersectionObserver",value:function initIntersectionObserver(e){var _this3=this;return new IntersectionObserver(function(t){t.forEach(function(n){n.isIntersecting&&_this3.hiddenElements.has(n.target)&&(_this3.hiddenElements["delete"](n.target),_this3.io.unobserve(n.target),_this3.updateElement());});},{root:e,threshold:0.1});}},{key:"createElement",value:function createElement(){var _this4=this;var n,s,r;var e=S();e.id="scroll-button",e.onclick=function(){var o;if(((o=_this4.config)==null?void 0:o.clickScroll)==="last")oe.scrollToBottom(_this4._messages,!0);else{var a=_this4.hiddenElements.values().next().value;a&&_this4._messages.elementRef.scrollTo({left:0,top:a.offsetTop,behavior:"smooth"});}},Z.apply(this._messages,e),Object.assign(e[_],(s=(n=this.config)==null?void 0:n.styles)==null?void 0:s[x]);var t=ee.processStateful(((r=this.config)==null?void 0:r.styles)||{});return yt.add(e,t),e;}},{key:"update",value:function update(){var t;var e=(t=this._messages.getFirstMessageContentEl())==null?void 0:t.outerContainer;e&&!oe.isVisibleInParent(e,this._messages.elementRef)&&(this.hiddenElements.add(e),this.io.observe(e),this.updateElement());}},{key:"displayScrollElement",value:function displayScrollElement(){this.element&&(this.element[_].display="flex",this.element.innerHTML='<span style="font-size: 20px; cursor: pointer;">&darr;</span>',this.element[_].opacity="1");}},{key:"hideScrollElement",value:function hideScrollElement(){this.element&&(this.element[_].opacity="0");}},{key:"clear",value:function clear(){var _this5=this;this.hiddenElements.forEach(function(e){return _this5.io.unobserve(e);}),this.hiddenElements.clear(),this.updateElement();}},{key:"updateElement",value:function updateElement(){var e;if(this.element){var t=this.hiddenElements.size,n="".concat(t," new message").concat(t===1?"":"s");if((e=this.config)!=null&&e.onUpdate){var s=this.config.onUpdate(n,t);this.element.innerHTML=s,Z.apply(this._messages,this.element);}else this.element.innerHTML=n;this.element[_].opacity=t?"1":"0";}}}]);}();var Ir="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",_i="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 Ro=/*#__PURE__*/function(){function Ro(e){_classCallCheck(this,Ro);this.className=e;}return _createClass(Ro,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e)[_]).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e)[_].visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e)[m].add("role-hidden");}}]);}();var dt=/*#__PURE__*/function(_Ro){function dt(e){var _this6;_classCallCheck(this,dt);_this6=_callSuper(this,dt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(dt,_Ro);return _createClass(dt,[{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===Mt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Mt?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var r,o,a,c,l;var n=S("img");e===U?(n[A]=((r=t==null?void 0:t[U])==null?void 0:r[A])||((o=t==null?void 0:t[x])==null?void 0:o[A])||_i,n.onerror=dt.errorFallback.bind(this,_i)):(n[A]=((a=t==null?void 0:t[e])==null?void 0:a[A])||((c=t==null?void 0:t[J])==null?void 0:c[A])||((l=t==null?void 0:t[x])==null?void 0:l[A])||Ir,n.onerror=dt.errorFallback.bind(this,Ir)),n[m].add("avatar"),n.alt="".concat(e," avatar");var s=S();return s[m].add(this.className),s.appendChild(n),t&&dt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,r,o,a,c,l;var n=te.processPosition((r=(s=t==null?void 0:t[e])==null?void 0:s.styles)==null?void 0:r.position);return e!==U&&(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[x])==null?void 0:c.styles)==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===U?uo:Mt,n;}}],[{key:"errorFallback",value:function errorFallback(e,t){var n=t.target;n.onerror=null,n[A]=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){Object.assign(e[_],n.container),Object.assign(t[_],n.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){var r,o,a,c;if((r=n[x])!=null&&r.styles&&dt.applyCustomStylesToElements(e,t,n[x].styles),s===U)(o=n.user)!=null&&o.styles&&dt.applyCustomStylesToElements(e,t,n.user.styles);else{(a=n.ai)!=null&&a.styles&&dt.applyCustomStylesToElements(e,t,n.ai.styles);var l=(c=n[s])==null?void 0:c.styles;l&&dt.applyCustomStylesToElements(e,t,l);}}}]);}(Ro);var Kn=/*#__PURE__*/function(_Ro2){function Kn(e){var _this7;_classCallCheck(this,Kn);_this7=_callSuper(this,Kn,["name"]),_this7._names=e;return _this7;}_inherits(Kn,_Ro2);return _createClass(Kn,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),r=Kn.getPosition(t,n);s[m].add(r===Mt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Mt?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=S();return n[m].add(this.className),n.textContent=Kn.getNameText(e,t),Kn.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,r,o;var n=te.processPosition((s=t==null?void 0:t[e])==null?void 0:s.position);return e!==U&&(n!==null&&n!==void 0?n:n=(r=t==null?void 0:t[J])==null?void 0:r.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[x])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===U?uo:Mt,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,r,o,a;Object.assign(e[_],(s=n[x])==null?void 0:s[_]),t===U?Object.assign(e[_],(r=n[U])==null?void 0:r[_]):(Object.assign(e[_],(o=n[J])==null?void 0:o[_]),Object.assign(e[_],(a=n[t])==null?void 0:a[_]));}},{key:"getNameText",value:function getNameText(e,t){var n,s,r,o,a,c;return e===U?((n=t[U])==null?void 0:n[h])||((s=t[x])==null?void 0:s[h])||"User":e===J?((r=t[J])==null?void 0:r[h])||((o=t[x])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[x])==null?void 0:c[h])||e;}}]);}(Ro);var Me=/*#__PURE__*/function(){function Me(e){var _this8=this;_classCallCheck(this,Me);var t,n,s,r;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=Me.createContainerElement(),this.messageStyles=te.processMessageStyles(e.messageStyles),this._remarkable=as.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new dt(e.avatars)),e.names&&(this.name=new Kn(e.names)),e.browserStorage&&(this.browserStorage=new Jc(e.browserStorage)),this._onMessage=Jt.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),e.hiddenMessages&&(this.scrollButton=new Kc(this,e.hiddenMessages)),this.focusMode=te.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=S(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Is.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||te.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(Me,[{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(Me.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",Me.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(Me.LAST_GROUP_MESSAGES_ACTIVE);var e=S();(this.messageToElements.length>1||this.messageToElements.length===1&&this.messageToElements[0][0].role!==U)&&e[m].add(Me.LAST_GROUP_MESSAGES_ACTIVE),this._lastGroupMessagesElement=e;}},{key:"appendOuterContainerElemet",value:function appendOuterContainerElemet(e,t){var n;this.focusMode&&(t===U||!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(Me.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(rt.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 vt.changeFullViewToSmall(this),!n&&Me.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
@@ -81,33 +81,33 @@ function setElementProps(e,t,n,s){var r;n!=="loading"&&(e.applyCustomStyles(t,s,
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===U?"user-message-text":"ai-message-text"),this.renderText(e,t,n),N.addRoleElements(e,n,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
82
82
  },{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){e&&this.messageStyles&&Ce.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(Cs);}},{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 _Z$tryAddWrapper2=Z.tryAddWrapper(e,t,this._customWrappers,n),s=_Z$tryAddWrapper2.contentEl,r=_Z$tryAddWrapper2.wrapper;r&&Z.apply(this,e),s.innerHTML=this._remarkable.render(t),this._applyHTMLToRemarkable&&Z.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=as.createNew(e),this.messageToElements.forEach(function(t){t[1][h]&&t[0][h]&&_this0.renderText(t[1][h].bubbleElement,t[0][h],t[0].role);});}},{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===U){var s=typeof this.focusMode!="boolean"&&((n=this.focusMode)==null?void 0:n.smoothScroll);ce.scrollToBottom(this,s);}else if(t&&this.autoScrollAllowed){var _s2=this.getFirstMessageContentEl();ce.scrollToBottom(this,!1,_s2==null?void 0:_s2.outerContainer);}}}],[{key:"createContainerElement",value:function createContainerElement(){var e=S();return e.id=po,e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return Me.isLoadingMessage(e)||ot.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=S(),n=S();n[m].add("inner-message-container"),t.appendChild(n),t[m].add("outer-message-container"),t[m].add(N.buildRoleOuterContainerClass(e));var s=S();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={role:a||J};return t&&(c[h]=t),n&&(c[y]=n),s&&(c[I]=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(rt.BUBBLE_CLASS);}}]);}();Me.TEXT_BUBBLE_CLASS="text-message",Me.INTRO_CLASS="deep-chat-intro",Me.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var Je=Me;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].role===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=as.createNew(e),this.messageToElements.forEach(function(t){t[1][h]&&t[0][h]&&_this0.renderText(t[1][h].bubbleElement,t[0][h],t[0].role);});}},{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===U){var s=typeof this.focusMode!="boolean"&&((n=this.focusMode)==null?void 0:n.smoothScroll);oe.scrollToBottom(this,s);}else if(t&&this.autoScrollAllowed){var _s2=this.getFirstMessageContentEl();oe.scrollToBottom(this,!1,_s2==null?void 0:_s2.outerContainer);}}}],[{key:"createContainerElement",value:function createContainerElement(){var e=S();return e.id=po,e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return Me.isLoadingMessage(e)||ot.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=S(),n=S();n[m].add("inner-message-container"),t.appendChild(n),t[m].add("outer-message-container"),t[m].add(N.buildRoleOuterContainerClass(e));var s=S();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={role:a||J};return t&&(c[h]=t),n&&(c[y]=n),s&&(c[M]=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(rt.BUBBLE_CLASS);}}]);}();Me.TEXT_BUBBLE_CLASS="text-message",Me.INTRO_CLASS="deep-chat-intro",Me.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var Je=Me;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].role===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],[rt.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(pr),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e[m].contains(pr)&&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(gs).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$m;e.outerContainer[m].remove(li,fr,di),(_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[I]!==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,Je.TEXT_BUBBLE_CLASS)),e[I]&&(n[I]=N.findMessageElements(t,at.HTML_BUBBLE_CLASS)),e[y]&&(n[y]=N.filterdMessageElements(t,ho)),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
88
+ },{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e[m].add(pr),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e[m].contains(pr)&&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(gs).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$m;e.outerContainer[m].remove(li,fr,di),(_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[M]!==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,Je.TEXT_BUBBLE_CLASS)),e[M]&&(n[M]=N.findMessageElements(t,at.HTML_BUBBLE_CLASS)),e[y]&&(n[y]=N.filterdMessageElements(t,ho)),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
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(gs);})),!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,[li]):l&&d?N.addNewPositionClasses(r,[fr]):l&&!d?N.addNewPositionClasses(r,[di]):!l&&!d&&N.addNewPositionClasses(r,[li,di]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer[m]).find(function(s){return s.startsWith(gs);})===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(Cs)||N.revealRoleElements(r.innerContainer,t,n);var a=Array.from(r.outerContainer[m]).find(function(c){return c.startsWith(gs);});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)!==B)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)===B?t[n]=N.processMessageContent(s):t[n]=s;}),t;}}]);}();var ut=/*#__PURE__*/function(){function ut(e,t){_classCallCheck(this,ut);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialText="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(ut,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e[h])===void 0&&(e==null?void 0:e[I])===void 0)return console[f](mo);e!=null&&e.custom&&this._message&&(this._message.custom=e.custom);var t=(e==null?void 0:e[h])||(e==null?void 0:e[I])||"",n=ce.isScrollbarAtBottomOfElement(this._messages.elementRef),s=(e==null?void 0:e[h])!==void 0?h:I;if(!this._elements&&!this._message)this.setInitialState(s,t,e==null?void 0:e.role);else{if(this._streamType!==s)return console[f](sa);this.updateBasedOnType(t,s,e==null?void 0:e.overwrite);}e!=null&&e._sessionId&&(this._sessionId=e==null?void 0:e._sessionId),n&&ce.scrollToBottom(this._messages);}},{key:"setInitialState",value:function setInitialState(e,t,n){var o,a,c;this._streamType=e,n!==null&&n!==void 0?n:n=J;var s=((o=this._messages._customWrappers)==null?void 0:o[n])||((a=this._messages._customWrappers)==null?void 0:a[x]),r=s?"":t;this._elements=e===h?this._messages.addNewTextMessage(r,n):at.add(this._messages,r,n),this._elements&&(this._elements.bubbleElement[m].add(ut.MESSAGE_CLASS),this._activeMessageRole=n,this._message=_defineProperty({role: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.hiddenMessages)==null||c.update());}// 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=Z.getTargetWrapper(e.bubbleElement),this._elements&&Z.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.partialRenderBubbleUpdate(e):this._messages.renderText(t,this._message[h]));}},{key:"isNewPartialRenderParagraph",value:function isNewPartialRenderParagraph(e,t){var n;return t?(e.innerHTML="",!0):this._partialBubble?this._partialText&&this.shouldCreateNewParagraph(this._partialText):((n=this._message)==null?void 0:n[h])&&this.shouldCreateNewParagraph(this._message[h]);}},{key:"shouldCreateNewParagraph",value:function shouldCreateNewParagraph(e){var t=e.indexOf(ut.PARTIAL_RENDER_TEXT_MARK);return t===-1?!1:!e.substring(t+ut.PARTIAL_RENDER_TEXT_MARK.length).startsWith("---");}},{key:"partialRenderNewParagraph",value:function partialRenderNewParagraph(e){this._partialText="",this._partialBubble=S(),this._partialBubble[m].add("partial-render-message"),e.appendChild(this._partialBubble);}},{key:"partialRenderBubbleUpdate",value:function partialRenderBubbleUpdate(e){this._partialText+=e,this._messages.renderText(this._partialBubble,this._partialText);}},{key:"updateHTML",value:function updateHTML(e,t,n){if(this._message)if(n)this._message[I]=e,t.innerHTML=e;else{var s=S("span");s.innerHTML=e,t.appendChild(s),this._message[I]=(t==null?void 0:t.innerHTML)||"";}}},{key:"finaliseStreamedMessage",value:function finaliseStreamedMessage(){var e,t;if(!(this._endStreamAfterOperation||!this._message)&&!(this._fileAdded&&!this._elements)){if(!this._elements)throw Error(ia);(e=this._elements.bubbleElement)!=null&&e[m].contains(ut.MESSAGE_CLASS)&&(this._streamType===h?this._messages.textToSpeech&&hn.speak(this._message[h]||"",this._messages.textToSpeech):this._streamType===I&&this._elements&&Z.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement[m].remove(ut.MESSAGE_CLASS),this._message&&(this._sessionId&&(this._message._sessionId=this._sessionId),this._messages.sendClientUpdate(Je.createMessageContent(this._message),!1),(t=this._messages.browserStorage)==null||t.addMessages(this._messages.messageToElements.map(function(_ref9){var _ref0=_slicedToArray(_ref9,1),n=_ref0[0];return n;}))),this._hasStreamEnded=!0);}}},{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)!==B)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)===B?t[n]=N.processMessageContent(s):t[n]=s;}),t;}}]);}();var ut=/*#__PURE__*/function(){function ut(e,t){_classCallCheck(this,ut);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialText="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(ut,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e[h])===void 0&&(e==null?void 0:e[M])===void 0)return console[f](mo);e!=null&&e.custom&&this._message&&(this._message.custom=e.custom);var t=(e==null?void 0:e[h])||(e==null?void 0:e[M])||"",n=oe.isScrollbarAtBottomOfElement(this._messages.elementRef),s=(e==null?void 0:e[h])!==void 0?h:M;if(!this._elements&&!this._message)this.setInitialState(s,t,e==null?void 0:e.role);else{if(this._streamType!==s)return console[f](sa);this.updateBasedOnType(t,s,e==null?void 0:e.overwrite);}e!=null&&e._sessionId&&(this._sessionId=e==null?void 0:e._sessionId),n&&oe.scrollToBottom(this._messages);}},{key:"setInitialState",value:function setInitialState(e,t,n){var o,a,c;this._streamType=e,n!==null&&n!==void 0?n:n=J;var s=((o=this._messages._customWrappers)==null?void 0:o[n])||((a=this._messages._customWrappers)==null?void 0:a[x]),r=s?"":t;this._elements=e===h?this._messages.addNewTextMessage(r,n):at.add(this._messages,r,n),this._elements&&(this._elements.bubbleElement[m].add(ut.MESSAGE_CLASS),this._message=_defineProperty({role:n},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.update());}// 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=Z.getTargetWrapper(e.bubbleElement),this._elements&&Z.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.partialRenderBubbleUpdate(e):this._messages.renderText(t,this._message[h]));}},{key:"isNewPartialRenderParagraph",value:function isNewPartialRenderParagraph(e,t){var n;return t?(e.innerHTML="",!0):this._partialBubble?this._partialText&&this.shouldCreateNewParagraph(this._partialText):((n=this._message)==null?void 0:n[h])&&this.shouldCreateNewParagraph(this._message[h]);}},{key:"shouldCreateNewParagraph",value:function shouldCreateNewParagraph(e){var t=e.indexOf(ut.PARTIAL_RENDER_TEXT_MARK);return t===-1?!1:!e.substring(t+ut.PARTIAL_RENDER_TEXT_MARK.length).startsWith("---");}},{key:"partialRenderNewParagraph",value:function partialRenderNewParagraph(e){this._partialText="",this._partialBubble=S(),this._partialBubble[m].add("partial-render-message"),e.appendChild(this._partialBubble);}},{key:"partialRenderBubbleUpdate",value:function partialRenderBubbleUpdate(e){this._partialText+=e,this._messages.renderText(this._partialBubble,this._partialText);}},{key:"updateHTML",value:function updateHTML(e,t,n){if(this._message)if(n)this._message[M]=e,t.innerHTML=e;else{var s=S("span");s.innerHTML=e,t.appendChild(s),this._message[M]=(t==null?void 0:t.innerHTML)||"";}}},{key:"finaliseStreamedMessage",value:function finaliseStreamedMessage(){var e,t;if(!(this._endStreamAfterOperation||!this._message)&&!(this._fileAdded&&!this._elements)){if(!this._elements)throw Error(ia);(e=this._elements.bubbleElement)!=null&&e[m].contains(ut.MESSAGE_CLASS)&&(this._streamType===h?this._messages.textToSpeech&&hn.speak(this._message[h]||"",this._messages.textToSpeech):this._streamType===M&&this._elements&&Z.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement[m].remove(ut.MESSAGE_CLASS),this._message&&(this._sessionId&&(this._message._sessionId=this._sessionId),this._messages.sendClientUpdate(Je.createMessageContent(this._message),!1),(t=this._messages.browserStorage)==null||t.addMessages(this._messages.messageToElements.map(function(_ref9){var _ref0=_slicedToArray(_ref9,1),n=_ref0[0];return n;}))),this._hasStreamEnded=!0);}}},{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;}()}]);}();ut.MESSAGE_CLASS="streamed-message",ut.PARTIAL_RENDER_TEXT_MARK="\n\n";var et=ut;var L=/*#__PURE__*/function(){function L(){_classCallCheck(this,L);}return _createClass(L,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(Ie);case 1:s=e.headers[D];delete e.headers[D];_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[D]=s,_t3;case 5:return _context3.a(2,(e.headers[D]=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)===B)return t instanceof Error?e.addNewErrorMessage(Y,t.message):Array.isArray(t)||typeof t[f]=="string"?e.addNewErrorMessage(Y,t):Object.keys(t).length===0?e.addNewErrorMessage(Y,n):e.addNewErrorMessage(Y,JSON.stringify(t));e.addNewErrorMessage(Y,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)||le,headers:t};return r.method!==ae&&(r.body=n?JSON.stringify(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(K)?e.json():t!=null&&t.includes("text/plain")||!t?e:e.blob();}},{key:"processRequestInterceptor",value:function(){var _processRequestInterceptor=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(e,t){var o,n,s,r,_t4;return _regenerator().w(function(_context4){while(1)switch(_context4.n){case 0:_context4.n=1;return(o=e.requestInterceptor)==null?void 0:o.call(e,t);case 1:_t4=_context4.v;if(_t4){_context4.n=2;break;}_t4=t;case 2:n=_t4;s=n;r=n;return _context4.a(2,{body:s.body,headers:s.headers,error:r[f]});}},_callee4);}));function processRequestInterceptor(_x10,_x11){return _processRequestInterceptor.apply(this,arguments);}return processRequestInterceptor;}()},{key:"validateResponseFormat",value:function validateResponseFormat(e,t){if(!e)return!1;var n=Array.isArray(e)?e:[e];return t&&n.length>1?(console[f](fo),!1):!n.find(function(r){return _typeof(r)!="object"||!(typeof r[f]=="string"||typeof r[h]=="string"||typeof r[I]=="string"||Array.isArray(r[y]));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,n){e.addNewErrorMessage(Y,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=dn(t,"response",!!a,c);L.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 Wc(_x14,_x15){return _Wc.apply(this,arguments);}function _Wc(){_Wc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee189(i,e){var t,n;return _regenerator().w(function(_context189){while(1)switch(_context189.n){case 0:t=i.getReader();case 1:_context189.n=2;return t.read();case 2:if((n=_context189.v).done){_context189.n=4;break;}e(n.value);case 3:_context189.n=1;break;case 4:return _context189.a(2);}},_callee189);}));return _Wc.apply(this,arguments);}function Xc(i){var e,t,n,s=!1;return function(o){e===void 0?(e=o,t=0,n=-1):e=Yc(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 Zc(i,e,t){var n=Mr();var s=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(n),n=Mr();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 Yc(i,e){var t=new Uint8Array(i.length+e.length);return t.set(i),t.set(e,i.length),t;}function Mr(){return{data:"",event:"",id:"",retry:void 0};}var Qc=function Qc(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 Ei="text/event-stream",el=1e3,kr="last-event-id";function tl(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=Qc(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(p,u){var g=Object.assign({},n);g.accept||(g.accept=Ei);var b;function v(){b.abort(),document.hidden||ve();}c||document.addEventListener("visibilitychange",v);var E=el,C=0;function H(){document.removeEventListener("visibilitychange",v),window.clearTimeout(C),b.abort();}t==null||t.addEventListener("abort",function(){H(),p();});var W=l!==null&&l!==void 0?l:window.fetch,X=s!==null&&s!==void 0?s:nl;function ve(){return _ve.apply(this,arguments);}function _ve(){_ve=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var St,xt,Be,_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 W(i,Object.assign(Object.assign({},d),{headers:g,signal:b.signal}));case 2:xt=_context6.v;_context6.n=3;return X(xt);case 3:_context6.n=4;return Wc(xt.body,Xc(Zc(function(Be){Be?g[kr]=Be:delete g[kr];},function(Be){E=Be;},r)));case 4:o==null||o();H();p();_context6.n=6;break;case 5:_context6.p=5;_t6=_context6.v;if(!b.signal.aborted)try{Be=(St=a==null?void 0:a(_t6))!==null&&St!==void 0?St:E;window.clearTimeout(C),C=window.setTimeout(ve,Be);}catch(Be){H(),u(Be);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _ve.apply(this,arguments);}ve();});}function nl(i){var e=i.headers.get("content-type");if(!(e!=null&&e.startsWith(Ei)))throw new Error("Expected content-type to be ".concat(Ei,", Actual: ").concat(e));}var F=/*#__PURE__*/function(){function F(){_classCallCheck(this,F);}return _createClass(F,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)||le,headers:t};return r.method!==ce&&(r.body=n?JSON.stringify(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(K)?e.json():t!=null&&t.includes("text/plain")||!t?e:e.blob();}},{key:"processRequestInterceptor",value:function(){var _processRequestInterceptor=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(e,t){var o,n,s,r,_t4;return _regenerator().w(function(_context4){while(1)switch(_context4.n){case 0:_context4.n=1;return(o=e.requestInterceptor)==null?void 0:o.call(e,t);case 1:_t4=_context4.v;if(_t4){_context4.n=2;break;}_t4=t;case 2:n=_t4;s=n;r=n;return _context4.a(2,{body:s.body,headers:s.headers,error:r[f]});}},_callee4);}));function processRequestInterceptor(_x10,_x11){return _processRequestInterceptor.apply(this,arguments);}return processRequestInterceptor;}()},{key:"validateResponseFormat",value:function validateResponseFormat(e,t){if(!e)return!1;var n=Array.isArray(e)?e:[e];return t&&n.length>1?(console[f](fo),!1):!n.find(function(r){return _typeof(r)!="object"||!(typeof r[f]=="string"||typeof r[h]=="string"||typeof r[M]=="string"||Array.isArray(r[y]));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,n){e.addNewErrorMessage(Y,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=dn(t,"response",!!a,c);L.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 Wc(_x14,_x15){return _Wc.apply(this,arguments);}function _Wc(){_Wc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee190(i,e){var t,n;return _regenerator().w(function(_context190){while(1)switch(_context190.n){case 0:t=i.getReader();case 1:_context190.n=2;return t.read();case 2:if((n=_context190.v).done){_context190.n=4;break;}e(n.value);case 3:_context190.n=1;break;case 4:return _context190.a(2);}},_callee190);}));return _Wc.apply(this,arguments);}function Xc(i){var e,t,n,s=!1;return function(o){e===void 0?(e=o,t=0,n=-1):e=Yc(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 Zc(i,e,t){var n=Mr();var s=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(n),n=Mr();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 Yc(i,e){var t=new Uint8Array(i.length+e.length);return t.set(i),t.set(e,i.length),t;}function Mr(){return{data:"",event:"",id:"",retry:void 0};}var Qc=function Qc(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 Ei="text/event-stream",el=1e3,kr="last-event-id";function tl(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=Qc(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(p,u){var g=Object.assign({},n);g.accept||(g.accept=Ei);var b;function v(){b.abort(),document.hidden||ve();}c||document.addEventListener("visibilitychange",v);var E=el,C=0;function H(){document.removeEventListener("visibilitychange",v),window.clearTimeout(C),b.abort();}t==null||t.addEventListener("abort",function(){H(),p();});var W=l!==null&&l!==void 0?l:window.fetch,X=s!==null&&s!==void 0?s:nl;function ve(){return _ve.apply(this,arguments);}function _ve(){_ve=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var St,xt,Be,_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 W(i,Object.assign(Object.assign({},d),{headers:g,signal:b.signal}));case 2:xt=_context6.v;_context6.n=3;return X(xt);case 3:_context6.n=4;return Wc(xt.body,Xc(Zc(function(Be){Be?g[kr]=Be:delete g[kr];},function(Be){E=Be;},r)));case 4:o==null||o();H();p();_context6.n=6;break;case 5:_context6.p=5;_t6=_context6.v;if(!b.signal.aborted)try{Be=(St=a==null?void 0:a(_t6))!==null&&St!==void 0?St:E;window.clearTimeout(C),C=window.setTimeout(ve,Be);}catch(Be){H(),u(Be);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _ve.apply(this,arguments);}ve();});}function nl(i){var e=i.headers.get("content-type");if(!(e!=null&&e.startsWith(Ei)))throw new Error("Expected content-type to be ".concat(Ei,", Actual: ").concat(e));}var F=/*#__PURE__*/function(){function F(){_classCallCheck(this,F);}return _createClass(F,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,v,E,o,_yield$L$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 L.processRequestInterceptor(e.deepChat,o);case 1:_yield$L$processReque=_context7.v;a=_yield$L$processReque.body;c=_yield$L$processReque.headers;l=_yield$L$processReque.error;if(!l){_context7.n=2;break;}return _context7.a(2,L.onInterceptorError(n,l,e.streamHandlers.onClose));case 2:if(!((g=e.connectSettings)!=null&&g.handler)){_context7.n=3;break;}return _context7.a(2,Qe.stream(e,a,n));case 3:if(!(((b=e.connectSettings)==null?void 0:b.url)===nt.URL)){_context7.n=4;break;}return _context7.a(2,nt.requestStream(n,e));case 4:d=new et(n,e.stream),p={method:((v=e.connectSettings)==null?void 0:v.method)||le,headers:c,credentials:(E=e.connectSettings)==null?void 0:E.credentials,body:s?JSON.stringify(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?F.handleReadableStream(e,n,d,p,r,a):F.handleEventStream(e,n,d,p,r,a),d));}},_callee7);}));function request(_x16,_x17,_x18){return _request.apply(this,arguments);}return request;}()// prettier-ignore
100
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 v,E,u,g,b,_yield$u$read,C,H,W,X,ve,_t7;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(p.body){_context8.n=1;break;}throw new Error(ra);case 1:u=p.body.getReader(),g=new TextDecoder();a();b=!1;case 2:if(!(!b&&!l)){_context8.n=8;break;}_context8.n=3;return u.read();case 3:_yield$u$read=_context8.v;C=_yield$u$read.value;H=_yield$u$read.done;if(!(b=H,b)){_context8.n=4;break;}F.handleClose(e,n,c,r);_context8.n=7;break;case 4:W=g.decode(C,{stream:!0});_context8.n=5;return(E=(v=e.deepChat).responseInterceptor)==null?void 0:E.call(v,W);case 5:_t7=_context8.v;if(_t7){_context8.n=6;break;}_t7=W;case 6:X=_t7;ve=_typeof(X)=="object"?X:_defineProperty({},h,W);F.handleMessage(e,t,n,ve,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){F.handleError(e,t,p);}),e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l=!0;};}// prettier-ignore
101
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();},tl(((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 L.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,v,_t8;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(JSON.stringify(p.data)!==JSON.stringify("[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:v=_t8;F.handleMessage(e,t,n,v,o);case 3:return _context0.a(2);}},_callee0);}))();},onerror:function onerror(p){throw c(),p;},onclose:function onclose(){F.handleClose(e,n,c,r);},signal:l.signal}))["catch"](function(p){F.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){F.upsertContent(t,n.upsertStreamedMessage.bind(n),n,a),t.removeError();})["catch"](function(a){t.isLastMessageError()||L.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(){L.displayError(t,n);})["catch"](function(r){L.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
105
- },{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,n,s){var r,o,_r2,_r3,_o2;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:_context1.n=1;return L.basicResponseProcessing(e,n,{io:s,useRI:!1});case 1:if(_context1.v){_context1.n=2;break;}return _context1.a(2,t.onClose());case 2:if(Array.isArray(n)&&(n=n[0]),n[I]){t.onOpen();r=Z.splitHTML(n[I]);r.length===0&&(r=n[I].split(""));o=new et(e,s==null?void 0:s.stream);F.populateMessages(e,r,o,t,I,0,s);}if(!n[y]){_context1.n=4;break;}_context1.n=3;return L.basicResponseProcessing(e,_defineProperty({},y,n[y]),{io:s});case 3:_r2=_context1.v;e.addNewMessage(_objectSpread({sendUpdate:!1},_r2)),!n[I]&&!n[h]&&(new et(e,s==null?void 0:s.stream).finaliseStreamedMessage(),t.onClose());case 4:if(n[h]){t.onOpen();_r3=n[h].split(""),_o2=new et(e,s==null?void 0:s.stream);F.populateMessages(e,_r3,_o2,t,h,0,s);}n[f]&&(L.displayError(e,n[f]),t.onClose()),t.onAbort=function(){t.onClose();};case 5:return _context1.a(2);}},_callee1);}));function simulate(_x20,_x21,_x22,_x23){return _simulate.apply(this,arguments);}return simulate;}()// prettier-ignore
105
+ },{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,n,s){var r,o,_r2,_r3,_o2;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:_context1.n=1;return L.basicResponseProcessing(e,n,{io:s,useRI:!1});case 1:if(_context1.v){_context1.n=2;break;}return _context1.a(2,t.onClose());case 2:if(Array.isArray(n)&&(n=n[0]),n[M]){t.onOpen();r=Z.splitHTML(n[M]);r.length===0&&(r=n[M].split(""));o=new et(e,s==null?void 0:s.stream);F.populateMessages(e,r,o,t,M,0,s);}if(!n[y]){_context1.n=4;break;}_context1.n=3;return L.basicResponseProcessing(e,_defineProperty({},y,n[y]),{io:s});case 3:_r2=_context1.v;e.addNewMessage(_objectSpread({sendUpdate:!1},_r2)),!n[M]&&!n[h]&&(new et(e,s==null?void 0:s.stream).finaliseStreamedMessage(),t.onClose());case 4:if(n[h]){t.onOpen();_r3=n[h].split(""),_o2=new et(e,s==null?void 0:s.stream);F.populateMessages(e,_r3,_o2,t,h,0,s);}n[f]&&(L.displayError(e,n[f]),t.onClose()),t.onAbort=function(){t.onClose();};case 5:return _context1.a(2);}},_callee1);}));function simulate(_x20,_x21,_x22,_x23){return _simulate.apply(this,arguments);}return simulate;}()// prettier-ignore
106
106
  // io is only passed for demo to simulate a real stream
107
- },{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,n,s,r,o,a){var c,d,l,_t9;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:c=t[o];if(!c){_context10.n=5;break;}_context10.p=1;_context10.n=2;return L.basicResponseProcessing(e,_defineProperty({},r,c),{io:a});case 2:d=_context10.v;F.upsertContent(e,n.upsertStreamedMessage.bind(n),n,d),e.removeError();_context10.n=4;break;case 3:_context10.p=3;_t9=_context10.v;e.isLastMessageError()||L.displayError(e,_t9);case 4:l=setTimeout(function(){F.populateMessages(e,t,n,s,r,o+1,a);},s.simulationInterim||6);s.onAbort=function(){F.abort(l,n,s.onClose);};_context10.n=6;break;case 5:n.finaliseStreamedMessage(),s.onClose();case 6:return _context10.a(2);}},_callee10,null,[[1,3]]);}));function populateMessages(_x24,_x25,_x26,_x27,_x28,_x29,_x30){return _populateMessages.apply(this,arguments);}return populateMessages;}()},{key:"isSimulation",value:function isSimulation(e){return _typeof(e)=="object"&&!!e.simulation;}},{key:"isSimulatable",value:function isSimulatable(e,t){return F.isSimulation(e)&&t&&(t[h]||t[I]);}},{key:"abort",value:function abort(e,t,n){clearTimeout(e),t.finaliseStreamedMessage(),n();}},{key:"upsertContent",value:function upsertContent(e,t,n,s){if(s&&Array.isArray(s)&&(s=s[0]),s!=null&&s[h]||s!=null&&s[I]){var r=t(s);n!==null&&n!==void 0?n:n=r||void 0;}if(s!=null&&s[y]&&(e.addNewMessage(_defineProperty({},y,s[y])),n==null||n.markFileAdded()),s!=null&&s[f])throw s[f];}}]);}();var Ft=/*#__PURE__*/function(){function Ft(){_classCallCheck(this,Ft);}return _createClass(Ft,null,[{key:"generateResponse",value:function generateResponse(e){var t=e[e.length-1][0];if(t[y]&&t[y].length>0){if(t[y].length>1)return"These are interesting files!";var n=t[y][0];return n[A]&&n[A].startsWith("data:image/gif")?"That is a nice gif!":n.type===j?"That is a nice image!":n.type===P?"I like the sound of that!":"That is an interesting file!";}if(t[h]){if(t[h].charAt(t[h].length-1)==="?")return"I'm sorry but I can't answer that question...";if(t[h].includes("updog"))return"What's updog?";}return"Hi there! This is a demo response!";}},{key:"getCustomResponse",value:function getCustomResponse(e,t){return typeof e=="function"?e(t):e;}},{key:"getResponse",value:function getResponse(_ref11){var e=_ref11.customDemoResponse,t=_ref11.messageToElements;return e?Ft.getCustomResponse(e,t[t.length-1][0]):_defineProperty({},h,Ft.generateResponse(t));}// timeout is used to simulate a timeout for a response to come back
107
+ },{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,n,s,r,o,a){var c,d,l,_t9;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:c=t[o];if(!c){_context10.n=5;break;}_context10.p=1;_context10.n=2;return L.basicResponseProcessing(e,_defineProperty({},r,c),{io:a});case 2:d=_context10.v;F.upsertContent(e,n.upsertStreamedMessage.bind(n),n,d),e.removeError();_context10.n=4;break;case 3:_context10.p=3;_t9=_context10.v;e.isLastMessageError()||L.displayError(e,_t9);case 4:l=setTimeout(function(){F.populateMessages(e,t,n,s,r,o+1,a);},s.simulationInterim||6);s.onAbort=function(){F.abort(l,n,s.onClose);};_context10.n=6;break;case 5:n.finaliseStreamedMessage(),s.onClose();case 6:return _context10.a(2);}},_callee10,null,[[1,3]]);}));function populateMessages(_x24,_x25,_x26,_x27,_x28,_x29,_x30){return _populateMessages.apply(this,arguments);}return populateMessages;}()},{key:"isSimulation",value:function isSimulation(e){return _typeof(e)=="object"&&!!e.simulation;}},{key:"isSimulatable",value:function isSimulatable(e,t){return F.isSimulation(e)&&t&&(t[h]||t[M]);}},{key:"abort",value:function abort(e,t,n){clearTimeout(e),t.finaliseStreamedMessage(),n();}},{key:"upsertContent",value:function upsertContent(e,t,n,s){if(s&&Array.isArray(s)&&(s=s[0]),s!=null&&s[h]||s!=null&&s[M]){var r=t(s);n!==null&&n!==void 0?n:n=r||void 0;}if(s!=null&&s[y]&&(e.addNewMessage(_defineProperty({},y,s[y])),n==null||n.markFileAdded()),s!=null&&s[f])throw s[f];}}]);}();var Ft=/*#__PURE__*/function(){function Ft(){_classCallCheck(this,Ft);}return _createClass(Ft,null,[{key:"generateResponse",value:function generateResponse(e){var t=e[e.length-1][0];if(t[y]&&t[y].length>0){if(t[y].length>1)return"These are interesting files!";var n=t[y][0];return n[A]&&n[A].startsWith("data:image/gif")?"That is a nice gif!":n.type===j?"That is a nice image!":n.type===P?"I like the sound of that!":"That is an interesting file!";}if(t[h]){if(t[h].charAt(t[h].length-1)==="?")return"I'm sorry but I can't answer that question...";if(t[h].includes("updog"))return"What's updog?";}return"Hi there! This is a demo response!";}},{key:"getCustomResponse",value:function getCustomResponse(e,t){return typeof e=="function"?e(t):e;}},{key:"getResponse",value:function getResponse(_ref11){var e=_ref11.customDemoResponse,t=_ref11.messageToElements;return e?Ft.getCustomResponse(e,t[t.length-1][0]):_defineProperty({},h,Ft.generateResponse(t));}// timeout is used to simulate a timeout for a response to come back
108
108
  },{key:"request",value:function request(e,t){var n=Ft.getResponse(t);setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(){var s,r,o;return _regenerator().w(function(_context11){while(1)switch(_context11.n){case 0:_context11.n=1;return L.basicResponseProcessing(t,n,{io:e});case 1:s=_context11.v;if(s){_context11.n=2;break;}return _context11.a(2,e.completionsHandlers.onFinish());case 2:r=Array.isArray(s)?s:[s],o=r.find(function(a){return typeof a[f]=="string";});o?(t.addNewErrorMessage(Y,o[f]),e.completionsHandlers.onFinish()):F.isSimulatable(e.stream,s)?F.simulate(t,e.streamHandlers,s):(r.forEach(function(a){return t.addNewMessage(a);}),e.completionsHandlers.onFinish());case 3:return _context11.a(2);}},_callee11);})),400);}// timeout is used to simulate a timeout for a response to come back
109
109
  },{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var n=Ft.getResponse(e);F.simulate(e,t.streamHandlers,n,t);},400);}}]);}();Ft.URL="deep-chat-demo";var nt=Ft;var Ee=/*#__PURE__*/function(){function Ee(){_classCallCheck(this,Ee);}return _createClass(Ee,null,[{key:"setup",value:function setup(e){e.permittedErrorPrefixes=["Connection error","Error in server message"],e.websocket="pending";}},{key:"isElementPresentInDOM",value:function isElementPresentInDOM(e){return e.getRootNode({composed:!0})instanceof Document;}},{key:"createConnection",value:function createConnection(e,t){if(!Ee.isElementPresentInDOM(e.deepChat))return;var n=e.connectSettings.websocket;if(n){if(e.connectSettings.handler)return Qe.websocket(e,t);try{var s=typeof n!="boolean"?n:void 0,r=new WebSocket(e.connectSettings.url||"",s);e.websocket=r,e.websocket.onopen=function(){var o,a;t.removeError(),e.websocket&&_typeof(e.websocket)===B&&Ee.assignListeners(e,r,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console[f](o),Ee.retryConnection(e,t);};}catch(s){console[f](s),Ee.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var n,s;(s=(n=e.deepChat)._validationHandler)==null||s.call(n),Ee.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage(Y,"Connection error"),setTimeout(function(){Ee.createConnection(e,t);},5e3));}},{key:"assignListeners",value:function assignListeners(e,t,n){var _this1=this;var s={};t.onmessage=/*#__PURE__*/function(){var _ref14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(r){var o,a,c,l,_c2,_l2,_t0;return _regenerator().w(function(_context12){while(1)switch(_context12.p=_context12.n){case 0:if(!e.extractResultData){_context12.n=8;break;}_context12.p=1;o=JSON.parse(r.data);_context12.n=2;return L.basicResponseProcessing(n,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(dn(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!F.isSimulation(e.stream)){_context12.n=4;break;}c=Ee.stream.bind(_this1,e,n,s),l=s[o.role||J];F.upsertContent(n,c,l,a);_context12.n=6;break;case 4:_c2=Array.isArray(a)?a:[a],_l2=_c2.find(function(d){return typeof d[f]=="string";});if(!_l2){_context12.n=5;break;}throw _l2[f];case 5:_c2.forEach(function(d){return n.addNewMessage(d);});case 6:_context12.n=8;break;case 7:_context12.p=7;_t0=_context12.v;L.displayError(n,_t0,"Error in server message");case 8:return _context12.a(2);}},_callee12,null,[[1,7]]);}));return function(_x31){return _ref14.apply(this,arguments);};}(),t.onclose=function(){var r,o;console[f]("Connection closed"),n.isLastMessageError()||n.addNewErrorMessage(Y,"Connection error"),e.stream&&((o=(r=e.streamHandlers).onAbort)==null||o.call(r)),Ee.createConnection(e,n);};}},{key:"sendWebsocket",value:function(){var _sendWebsocket=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e,t,n){var s,d,p,r,o,_yield$L$processReque2,a,c,l,_args13=arguments;return _regenerator().w(function(_context13){while(1)switch(_context13.n){case 0:s=_args13.length>3&&_args13[3]!==undefined?_args13[3]:!0;if(!(((d=e.connectSettings)==null?void 0:d.url)===nt.URL)){_context13.n=1;break;}return _context13.a(2,nt.request(e,n));case 1:r=e.websocket;if(!(!r||r==="pending")){_context13.n=2;break;}return _context13.a(2);case 2:o={body:t,headers:(p=e.connectSettings)==null?void 0:p.headers};_context13.n=3;return L.processRequestInterceptor(e.deepChat,o);case 3:_yield$L$processReque2=_context13.v;a=_yield$L$processReque2.body;c=_yield$L$processReque2.error;if(!c){_context13.n=4;break;}return _context13.a(2,n.addNewErrorMessage(Y,c));case 4:if(Ee.isWebSocket(r)){_context13.n=5;break;}return _context13.a(2,r.newUserMessage.listener(a));case 5:l=s?JSON.stringify(a):a;r.readyState===void 0||r.readyState!==r.OPEN?(console[f]("Connection is not open"),n.isLastMessageError()||n.addNewErrorMessage(Y,"Connection error")):(r.send(JSON.stringify(l)),e.completionsHandlers.onFinish());case 6:return _context13.a(2);}},_callee13);}));function sendWebsocket(_x32,_x33,_x34){return _sendWebsocket.apply(this,arguments);}return sendWebsocket;}()},{key:"canSendMessage",value:function canSendMessage(e){return e?e==="pending"?!1:Ee.isWebSocket(e)?e.readyState!==void 0&&e.readyState===e.OPEN:e.isOpen:!0;}// if false then it is the internal websocket handler
110
- },{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,n,s){if(!s)return;var r=e.stream.simulation;if(typeof r=="string"){var _n$o;var o=s.role||J,a=n[o];s[h]===r||s[I]===r?(a==null||a.finaliseStreamedMessage(),delete n[o]):((_n$o=n[o])!==null&&_n$o!==void 0?_n$o:n[o]=new et(t,e.stream),n[o].upsertStreamedMessage(s));}else F.simulate(t,e.streamHandlers,s);}}]);}();var Qe=/*#__PURE__*/function(){function Qe(){_classCallCheck(this,Qe);}return _createClass(Qe,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(e,t,n){var a,c,s,r,o;return _regenerator().w(function(_context15){while(1)switch(_context15.n){case 0:s=!0;r=/*#__PURE__*/function(){var _ref15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(l){var d,p,u;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(s){_context14.n=1;break;}return _context14.a(2);case 1:s=!1;_context14.n=2;return L.basicResponseProcessing(n,l,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console[f](dn(l,"server",!!e.deepChat.responseInterceptor,d)),n.addNewErrorMessage(Y,"Error in server message"),e.completionsHandlers.onFinish();else{p=Array.isArray(d)?d:[d],u=p.find(function(g){return typeof g[f]=="string";});u?(console[f](u[f]),n.addNewErrorMessage(Y,u[f]),e.completionsHandlers.onFinish()):F.isSimulatable(e.stream,d)?F.simulate(n,e.streamHandlers,d):(p.forEach(function(g){return n.addNewMessage(g);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function r(_x38){return _ref15.apply(this,arguments);};}(),o=Qe.generateOptionalSignals();(c=(a=e.connectSettings).handler)==null||c.call(a,t,_objectSpread(_objectSpread({},o),{},{onResponse:r}));case 1:return _context15.a(2);}},_callee15);}));function request(_x35,_x36,_x37){return _request2.apply(this,arguments);}return request;}()},{key:"attemptToFinaliseStream",value:function attemptToFinaliseStream(e,t){try{var n=t.messageElementRefs[t.messageElementRefs.length-1];Je.isLoadingMessage(n)?t.removeLastMessage():e.finaliseStreamedMessage();}catch(n){console[f](n),t.addNewErrorMessage(Y,n);}}// prettier-ignore
110
+ },{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,n,s){if(!s)return;var r=e.stream.simulation;if(typeof r=="string"){var _n$o;var o=s.role||J,a=n[o];s[h]===r||s[M]===r?(a==null||a.finaliseStreamedMessage(),delete n[o]):((_n$o=n[o])!==null&&_n$o!==void 0?_n$o:n[o]=new et(t,e.stream),n[o].upsertStreamedMessage(s));}else F.simulate(t,e.streamHandlers,s);}}]);}();var Qe=/*#__PURE__*/function(){function Qe(){_classCallCheck(this,Qe);}return _createClass(Qe,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(e,t,n){var a,c,s,r,o;return _regenerator().w(function(_context15){while(1)switch(_context15.n){case 0:s=!0;r=/*#__PURE__*/function(){var _ref15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(l){var d,p,u;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(s){_context14.n=1;break;}return _context14.a(2);case 1:s=!1;_context14.n=2;return L.basicResponseProcessing(n,l,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console[f](dn(l,"server",!!e.deepChat.responseInterceptor,d)),n.addNewErrorMessage(Y,"Error in server message"),e.completionsHandlers.onFinish();else{p=Array.isArray(d)?d:[d],u=p.find(function(g){return typeof g[f]=="string";});u?(console[f](u[f]),n.addNewErrorMessage(Y,u[f]),e.completionsHandlers.onFinish()):F.isSimulatable(e.stream,d)?F.simulate(n,e.streamHandlers,d):(p.forEach(function(g){return n.addNewMessage(g);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function r(_x38){return _ref15.apply(this,arguments);};}(),o=Qe.generateOptionalSignals();(c=(a=e.connectSettings).handler)==null||c.call(a,t,_objectSpread(_objectSpread({},o),{},{onResponse:r}));case 1:return _context15.a(2);}},_callee15);}));function request(_x35,_x36,_x37){return _request2.apply(this,arguments);}return request;}()},{key:"attemptToFinaliseStream",value:function attemptToFinaliseStream(e,t){try{var n=t.messageElementRefs[t.messageElementRefs.length-1];Je.isLoadingMessage(n)?t.removeLastMessage():e.finaliseStreamedMessage();}catch(n){console[f](n),t.addNewErrorMessage(Y,n);}}// prettier-ignore
111
111
  },{key:"stream",value:function stream(e,t,n){var p,u;var s=!0,r=!1;var o=new et(n,e.stream),a=function a(){r||!s||(e.streamHandlers.onOpen(),r=!0);},c=function c(){s&&(Qe.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1);},l=/*#__PURE__*/function(){var _ref16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(g){var b,v;return _regenerator().w(function(_context16){while(1)switch(_context16.n){case 0:if(s){_context16.n=1;break;}return _context16.a(2);case 1:_context16.n=2;return L.basicResponseProcessing(n,g,{io:e,displayError:!1});case 2:b=_context16.v;if(b)b[f]?(Qe.streamError(b[f],o,e,n),s=!1):F.upsertContent(n,o.upsertStreamedMessage.bind(o),o,b);else{v=dn(g,"server",!!e.deepChat.responseInterceptor,b);Qe.streamError(v,o,e,n),s=!1;}case 3:return _context16.a(2);}},_callee16);}));return function l(_x39){return _ref16.apply(this,arguments);};}();e.streamHandlers.onAbort=function(){Qe.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1;};var d=Qe.generateOptionalSignals();(u=(p=e.connectSettings).handler)==null||u.call(p,t,_objectSpread(_objectSpread({},d),{},{onOpen:a,onResponse:l,onClose:c,stopClicked:e.streamHandlers.stopClicked}));}},{key:"streamError",value:function streamError(e,t,n,s){console[f](e),t.finaliseStreamedMessage(),s.addNewErrorMessage(Y,e),n.streamHandlers.onClose();}// prettier-ignore
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,v,E;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:_context17.n=1;return L.basicResponseProcessing(t,d,{io:e,displayError:!1});case 1:p=_context17.v;if(!p)console[f](dn(d,"server",!!e.deepChat.responseInterceptor,p)),t.addNewErrorMessage(Y,"Error in server message");else{u=Array.isArray(p)?p:[p],g=u.find(function(b){return typeof b[f]=="string";});if(g)console[f](g[f]),t.isLastMessageError()||t.addNewErrorMessage(Y,g[f]);else if(F.isSimulation(e.stream)){b=p,v=Ee.stream.bind(_this10,e,t,n.roleToStream),E=n.roleToStream[b.role||J];F.upsertContent(t,v,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=Qe.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 ie=/*#__PURE__*/function(){function ie(){_classCallCheck(this,ie);}return _createClass(ie,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$L$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 L.processRequestInterceptor(e.deepChat,r);case 1:_yield$L$processReque3=_context19.v;o=_yield$L$processReque3.body;a=_yield$L$processReque3.headers;c=_yield$L$processReque3.error;l=e.completionsHandlers.onFinish;if(!c){_context19.n=2;break;}return _context19.a(2,L.onInterceptorError(n,c,l));case 2:if(!((u=e.connectSettings)!=null&&u.handler)){_context19.n=3;break;}return _context19.a(2,Qe.request(e,o,n));case 3:if(!(((g=e.connectSettings)==null?void 0:g.url)===nt.URL)){_context19.n=4;break;}return _context19.a(2,nt.request(e,n));case 4:d=!0;L.fetch(e,a,s,o).then(function(b){return d=!!b.ok,b;}).then(function(b){return L.processResponseByType(b);}).then(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(b){var C,H,v,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(H=(C=e.deepChat).responseInterceptor)==null?void 0:H.call(C,b);case 2:_t1=_context18.v;if(_t1){_context18.n=3;break;}_t1=b;case 3:v=_t1;_context18.n=4;return e.extractResultData(v,o);case 4:E=_context18.v;if(d){_context18.n=5;break;}throw b;case 5:if(!(!E||_typeof(E)!==B&&!Array.isArray(E))){_context18.n=6;break;}throw Error(dn(b,"response",!!e.deepChat.responseInterceptor,v));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:F.isSimulatable(e.stream,E)?F.simulate(n,e.streamHandlers,E):((Array.isArray(E)?E:[E]).forEach(function(X){return n.addNewMessage(X);}),l());case 9:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref18.apply(this,arguments);};}())["catch"](function(b){L.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(){ie.executePollRequest(e,t,n,s);},a.timeoutMS):F.isSimulatable(e.stream,a)?F.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){L.displayError(s,o),r();});}// prettier-ignore
@@ -115,7 +115,7 @@ function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(functio
115
115
  },{key:"verifyKey",value:function verifyKey(e,t,n,s,r,o,a,c,l){if(e==="")return o(re);a(),fetch(t,{method:s,headers:n,body:l||null}).then(function(d){return L.processResponseByType(d);}).then(function(d){c(d,e,r,o);})["catch"](function(d){o(He),console[f](d);});}}]);}();var fn=/*#__PURE__*/function(){function fn(){_classCallCheck(this,fn);}return _createClass(fn,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=fn.getMaxMessages(e,t)):e=[e[e.length-1]],e=JSON.parse(JSON.stringify(e)),n===void 0?e:fn.getCharacterLimitMessages(e,n);}}]);}();var Ct=/*#__PURE__*/function(){function Ct(e,t,n){_classCallCheck(this,Ct);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,n.fetchHistory&&this.fetchHistory(n.fetchHistory),e.loadHistory&&this.setupLoadHistoryOnScroll(e.loadHistory),this.setupInitialHistory(e);}return _createClass(Ct,[{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=vt.addMessage(this._messages);_context22.n=1;return e();case 1:n=_context22.v;this._messages.removeMessage(t),Ct.displayIntroMessages(this._messages.messageElementRefs),n.forEach(function(s){return _this11._messages.addAnyMessage(s,!0);}),setTimeout(function(){return ce.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(Je.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:"setupLoadHistoryOnScroll",value:function(){var _setupLoadHistoryOnScroll=_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=vt.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(Y,Ct.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 setupLoadHistoryOnScroll(_x50){return _setupLoadHistoryOnScroll.apply(this,arguments);}return setupLoadHistoryOnScroll;}()},{key:"populateInitialHistory",value:function populateInitialHistory(e){var _this14=this;e.forEach(function(t){te.processHistoryFile(t),_this14._messages.addAnyMessage(t,!0);});}},{key:"loadInitialHistory",value:function(){var _loadInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(e){var _this15=this;var t,n,s,_t13;return _regenerator().w(function(_context25){while(1)switch(_context25.p=_context25.n){case 0:this._isLoading=!0;t=vt.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),s===0&&setTimeout(function(){return ce.scrollToBottom(_this15._messages);},0);_context25.n=4;break;case 3:_context25.p=3;_t13=_context25.v;this._messages.removeMessage(t),this._isPaginationComplete=!0,this._messages.addNewErrorMessage(Y,Ct.FAILED_ERROR_MESSAGE,!0),console[f](_t13);case 4:Ct.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 n,t;return _regenerator().w(function(_context26){while(1)switch(_context26.n){case 0:e.loadHistory&&this.loadInitialHistory(e.loadHistory);t=e.history||te.processHistory(e)||((n=this._messages.browserStorage)==null?void 0:n.get().messages);t&&(this.populateInitialHistory(t),this._index+=1);case 1:return _context26.a(2);}},_callee26,this);}));function setupInitialHistory(_x52){return _setupInitialHistory.apply(this,arguments);}return setupInitialHistory;}()}],[{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(Ct.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(Je.INTRO_CLASS))n.outerContainer[_].display="";else break;}}}]);}();Ct.FAILED_ERROR_MESSAGE="Failed to load history";var cs=Ct;var fe=/*#__PURE__*/function(){function fe(){_classCallCheck(this,fe);}return _createClass(fe,null,[{key:"parseConfig",value:function parseConfig(e,t,n){var r;var s={files:e};if(_typeof(n)=="object"){te.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=fe.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=fn.getMaxMessages(e,t)):e=[e[e.length-1]],e=JSON.parse(JSON.stringify(e)),n===void 0?e:fn.getCharacterLimitMessages(e,n);}}]);}();var Ct=/*#__PURE__*/function(){function Ct(e,t,n){_classCallCheck(this,Ct);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,n.fetchHistory&&this.fetchHistory(n.fetchHistory),e.loadHistory&&this.setupLoadHistoryOnScroll(e.loadHistory),this.setupInitialHistory(e);}return _createClass(Ct,[{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=vt.addMessage(this._messages);_context22.n=1;return e();case 1:n=_context22.v;this._messages.removeMessage(t),Ct.displayIntroMessages(this._messages.messageElementRefs),n.forEach(function(s){return _this11._messages.addAnyMessage(s,!0);}),setTimeout(function(){return oe.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(Je.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:"setupLoadHistoryOnScroll",value:function(){var _setupLoadHistoryOnScroll=_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=vt.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(Y,Ct.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 setupLoadHistoryOnScroll(_x50){return _setupLoadHistoryOnScroll.apply(this,arguments);}return setupLoadHistoryOnScroll;}()},{key:"populateInitialHistory",value:function populateInitialHistory(e){var _this14=this;e.forEach(function(t){te.processHistoryFile(t),_this14._messages.addAnyMessage(t,!0);});}},{key:"loadInitialHistory",value:function(){var _loadInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(e){var _this15=this;var t,n,s,_t13;return _regenerator().w(function(_context25){while(1)switch(_context25.p=_context25.n){case 0:this._isLoading=!0;t=vt.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),s===0&&setTimeout(function(){return oe.scrollToBottom(_this15._messages);},0);_context25.n=4;break;case 3:_context25.p=3;_t13=_context25.v;this._messages.removeMessage(t),this._isPaginationComplete=!0,this._messages.addNewErrorMessage(Y,Ct.FAILED_ERROR_MESSAGE,!0),console[f](_t13);case 4:Ct.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 n,t;return _regenerator().w(function(_context26){while(1)switch(_context26.n){case 0:e.loadHistory&&this.loadInitialHistory(e.loadHistory);t=e.history||te.processHistory(e)||((n=this._messages.browserStorage)==null?void 0:n.get().messages);t&&(this.populateInitialHistory(t),this._index+=1);case 1:return _context26.a(2);}},_callee26,this);}));function setupInitialHistory(_x52){return _setupInitialHistory.apply(this,arguments);}return setupInitialHistory;}()}],[{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(Ct.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(Je.INTRO_CLASS))n.outerContainer[_].display="";else break;}}}]);}();Ct.FAILED_ERROR_MESSAGE="Failed to load history";var cs=Ct;var fe=/*#__PURE__*/function(){function fe(){_classCallCheck(this,fe);}return _createClass(fe,null,[{key:"parseConfig",value:function parseConfig(e,t,n){var r;var s={files:e};if(_typeof(n)=="object"){te.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=fe.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[P])==null?void 0:a[y])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e.recordAudio=fe.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[P])!=null&&p[y]&&((_u$maxNumberOfFiles=(u=e.fileTypes[P][y]).maxNumberOfFiles)!==null&&_u$maxNumberOfFiles!==void 0?_u$maxNumberOfFiles:u.maxNumberOfFiles=n[y].maxNumberOfFiles))):s||(e.fileTypes[P]=fe.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[P]=fe.parseConfig(o,t,n);}// prettier-ignore
@@ -128,7 +128,7 @@ function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(functio
128
128
  function R(e,t,n,s,r){var _this16;_classCallCheck(this,R);var o;_this16=_callSuper(this,R,[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(R,_Kt);return _createClass(R,[{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
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;ie.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 fn.getCharacterLimitMessages(e,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this.systemMessage.length:-1);}},{key:"addSystemMessage",value:function addSystemMessage(e){this.systemMessage&&e.unshift({role:"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(Ie);case 1:o=n(this.rawBody,t),a=s?this.stream:!1;if(!(a&&(_typeof(a)!==B||!a.simulation)||o.stream)){_context33.n=2;break;}o.stream=!0,s!=null&&s.readable&&(this.stream={readable:!0}),F.request(this,o,e);_context33.n=4;break;case 2:_context33.n=3;return ie.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(un);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?F.request(this,e,t):ie.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(Wt);case 1:o=JSON.parse(JSON.stringify(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({role:"system",content:r.message})),o.messages.push({tool_calls:e.tool_calls,role:bt,content:null}),!c.find(function(_ref25){var d=_ref25.response;return typeof d!="string";})&&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({role:"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(un);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===U?U:bt;}},{key:"getRoleViaAI",value:function getRoleViaAI(e){return e===J?bt:U;}},{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type===j;}).map(function(t){return _defineProperty(_defineProperty({},T,Ne),Ne,{url:t[A]||""});}).filter(function(t){return t[Ne].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({},T,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({},T,h),h,e[h])),n;}return e[h]||"";}}]);}(Kt);var Ms=/*#__PURE__*/function(){function Ms(){_classCallCheck(this,Ms);}return _createClass(Ms,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?Ms.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,Ms.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var pt=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
130
130
  function pt(){var _this17;_classCallCheck(this,pt);_this17=_callSuper(this,pt),_this17._waitingToRender_=!1,_this17._propUpdated_=!1,Object.keys(pt._attributeToProperty_).forEach(function(e){var t=pt._attributeToProperty_[e];_this17.constructPropertyAccessors(t),_this17.hasOwnProperty(e)||_this17.constructPropertyAccessors(t,e);});return _this17;}_inherits(pt,_HTMLElement);return _createClass(pt,[{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:Ms.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,n){if(t===n)return;var s=pt._attributes_[e](n),r=pt._attributeToProperty_[e];this[r]=s;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(pt._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));pt._attributes_={},pt._attributeToProperty_={};var Si=pt;var sl="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path d=\"\n\t\t\tM669.727,273.516c-22.891-2.476-46.15-3.895-69.727-4.248c-103.025,0.457-209.823,25.517-310.913,73.536\n\t\t\tc-75.058,37.122-148.173,89.529-211.67,154.174C46.232,529.978,6.431,577.76,0,628.74c0.76,44.162,48.153,98.67,77.417,131.764\n\t\t\tc59.543,62.106,130.754,113.013,211.67,154.174c2.75,1.335,5.51,2.654,8.276,3.955l-75.072,131.102l102.005,60.286l551.416-960.033\n\t\t\tl-98.186-60.008L669.727,273.516z M902.563,338.995l-74.927,129.857c34.47,44.782,54.932,100.006,54.932,159.888\n\t\t\tc0,149.257-126.522,270.264-282.642,270.264c-6.749,0-13.29-0.728-19.922-1.172l-49.585,85.84c22.868,2.449,45.99,4.233,69.58,4.541\n\t\t\tc103.123-0.463,209.861-25.812,310.84-73.535c75.058-37.122,148.246-89.529,211.743-154.174\n\t\t\tc31.186-32.999,70.985-80.782,77.417-131.764c-0.76-44.161-48.153-98.669-77.417-131.763\n\t\t\tc-59.543-62.106-130.827-113.013-211.743-154.175C908.108,341.478,905.312,340.287,902.563,338.995L902.563,338.995z\n\t\t\tM599.927,358.478c6.846,0,13.638,0.274,20.361,0.732l-58.081,100.561c-81.514,16.526-142.676,85.88-142.676,168.897\n\t\t\tc0,20.854,3.841,40.819,10.913,59.325c0.008,0.021-0.008,0.053,0,0.074l-58.228,100.854\n\t\t\tc-34.551-44.823-54.932-100.229-54.932-160.182C317.285,479.484,443.808,358.477,599.927,358.478L599.927,358.478z M768.896,570.513\n\t\t\tL638.013,797.271c81.076-16.837,141.797-85.875,141.797-168.603C779.81,608.194,775.724,588.729,768.896,570.513L768.896,570.513z\"\n\t\t\t/>\n</svg>\n",il="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path id=\"path6686\" inkscape:connector-curvature=\"0\" d=\"M779.843,599.925c0,95.331-80.664,172.612-180.169,172.612\n\t\t\tc-99.504,0-180.168-77.281-180.168-172.612c0-95.332,80.664-172.612,180.168-172.612\n\t\t\tC699.179,427.312,779.843,504.594,779.843,599.925z M600,240.521c-103.025,0.457-209.814,25.538-310.904,73.557\n\t\t\tc-75.058,37.122-148.206,89.496-211.702,154.141C46.208,501.218,6.431,549,0,599.981c0.76,44.161,48.13,98.669,77.394,131.763\n\t\t\tc59.543,62.106,130.786,113.018,211.702,154.179c94.271,45.751,198.616,72.092,310.904,73.557\n\t\t\tc103.123-0.464,209.888-25.834,310.866-73.557c75.058-37.122,148.243-89.534,211.74-154.179\n\t\t\tc31.185-32.999,70.962-80.782,77.394-131.763c-0.76-44.161-48.13-98.671-77.394-131.764\n\t\t\tc-59.543-62.106-130.824-112.979-211.74-154.141C816.644,268.36,712.042,242.2,600,240.521z M599.924,329.769\n\t\t\tc156.119,0,282.675,120.994,282.675,270.251c0,149.256-126.556,270.25-282.675,270.25S317.249,749.275,317.249,600.02\n\t\t\tC317.249,450.763,443.805,329.769,599.924,329.769L599.924,329.769z\"/>\n</svg>\n";var _t=/*#__PURE__*/function(){function _t(){_classCallCheck(this,_t);}return _createClass(_t,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Tt=/*#__PURE__*/function(){function Tt(){_classCallCheck(this,Tt);}return _createClass(Tt,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:Ms.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,n){if(console.log("reference 1"),console.log(t),console.log("reference 2"),console.log(n),t===n)return;var s=pt._attributes_[e](n),r=pt._attributeToProperty_[e];this[r]=s;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(pt._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));pt._attributes_={},pt._attributeToProperty_={};var Si=pt;var sl="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path d=\"\n\t\t\tM669.727,273.516c-22.891-2.476-46.15-3.895-69.727-4.248c-103.025,0.457-209.823,25.517-310.913,73.536\n\t\t\tc-75.058,37.122-148.173,89.529-211.67,154.174C46.232,529.978,6.431,577.76,0,628.74c0.76,44.162,48.153,98.67,77.417,131.764\n\t\t\tc59.543,62.106,130.754,113.013,211.67,154.174c2.75,1.335,5.51,2.654,8.276,3.955l-75.072,131.102l102.005,60.286l551.416-960.033\n\t\t\tl-98.186-60.008L669.727,273.516z M902.563,338.995l-74.927,129.857c34.47,44.782,54.932,100.006,54.932,159.888\n\t\t\tc0,149.257-126.522,270.264-282.642,270.264c-6.749,0-13.29-0.728-19.922-1.172l-49.585,85.84c22.868,2.449,45.99,4.233,69.58,4.541\n\t\t\tc103.123-0.463,209.861-25.812,310.84-73.535c75.058-37.122,148.246-89.529,211.743-154.174\n\t\t\tc31.186-32.999,70.985-80.782,77.417-131.764c-0.76-44.161-48.153-98.669-77.417-131.763\n\t\t\tc-59.543-62.106-130.827-113.013-211.743-154.175C908.108,341.478,905.312,340.287,902.563,338.995L902.563,338.995z\n\t\t\tM599.927,358.478c6.846,0,13.638,0.274,20.361,0.732l-58.081,100.561c-81.514,16.526-142.676,85.88-142.676,168.897\n\t\t\tc0,20.854,3.841,40.819,10.913,59.325c0.008,0.021-0.008,0.053,0,0.074l-58.228,100.854\n\t\t\tc-34.551-44.823-54.932-100.229-54.932-160.182C317.285,479.484,443.808,358.477,599.927,358.478L599.927,358.478z M768.896,570.513\n\t\t\tL638.013,797.271c81.076-16.837,141.797-85.875,141.797-168.603C779.81,608.194,775.724,588.729,768.896,570.513L768.896,570.513z\"\n\t\t\t/>\n</svg>\n",il="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path id=\"path6686\" inkscape:connector-curvature=\"0\" d=\"M779.843,599.925c0,95.331-80.664,172.612-180.169,172.612\n\t\t\tc-99.504,0-180.168-77.281-180.168-172.612c0-95.332,80.664-172.612,180.168-172.612\n\t\t\tC699.179,427.312,779.843,504.594,779.843,599.925z M600,240.521c-103.025,0.457-209.814,25.538-310.904,73.557\n\t\t\tc-75.058,37.122-148.206,89.496-211.702,154.141C46.208,501.218,6.431,549,0,599.981c0.76,44.161,48.13,98.669,77.394,131.763\n\t\t\tc59.543,62.106,130.786,113.018,211.702,154.179c94.271,45.751,198.616,72.092,310.904,73.557\n\t\t\tc103.123-0.464,209.888-25.834,310.866-73.557c75.058-37.122,148.243-89.534,211.74-154.179\n\t\t\tc31.185-32.999,70.962-80.782,77.394-131.763c-0.76-44.161-48.13-98.671-77.394-131.764\n\t\t\tc-59.543-62.106-130.824-112.979-211.74-154.141C816.644,268.36,712.042,242.2,600,240.521z M599.924,329.769\n\t\t\tc156.119,0,282.675,120.994,282.675,270.251c0,149.256-126.556,270.25-282.675,270.25S317.249,749.275,317.249,600.02\n\t\t\tC317.249,450.763,443.805,329.769,599.924,329.769L599.924,329.769z\"/>\n</svg>\n";var _t=/*#__PURE__*/function(){function _t(){_classCallCheck(this,_t);}return _createClass(_t,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Tt=/*#__PURE__*/function(){function Tt(){_classCallCheck(this,Tt);}return _createClass(Tt,null,[{key:"changeVisibility",value:// prettier-ignore
132
132
  function changeVisibility(e,t,n,s){s.target.id===Tt.VISIBLE_ICON_ID?(t[_].display="none",n[_].display="block",e.type="password"):(t[_].display="block",n[_].display="none",e.type=h);}},{key:"createIconElement",value:function createIconElement(e,t){var n=_t.createSVGElement(e);return n.id=t,n[m].add("visibility-icon"),n;}// prettier-ignore
133
133
  },{key:"create",value:function create(e){var t=S();t.id="visibility-icon-container";var n=Tt.createIconElement(il,Tt.VISIBLE_ICON_ID);n[_].display="none",t.appendChild(n);var s=Tt.createIconElement(sl,"not-visible-icon");return t.appendChild(s),t.onclick=Tt.changeVisibility.bind(this,e,n,s),t;}}]);}();Tt.VISIBLE_ICON_ID="visible-icon";var xi=Tt;var Ae=/*#__PURE__*/function(){function Ae(){_classCallCheck(this,Ae);}return _createClass(Ae,null,[{key:"createCautionText",value:function createCautionText(){var e=S("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=S("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=S();return e.id="insert-key-input-invalid-text",e[_].display="none",e;}},{key:"createHelpTextContainer",value:function createHelpTextContainer(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var n=S();n.id="insert-key-help-text-container";var s=S();s.id="insert-key-help-text-contents";var r=Ae.createFailText();if(s.appendChild(r),e){var o=Ae.createHelpLink(e);s.appendChild(o);}if(t===!0){var _o3=Ae.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[_].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
@@ -140,20 +140,20 @@ function changeVisibility(e,t,n,s){s.target.id===Tt.VISIBLE_ICON_ID?(t[_].displa
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},G=/*#__PURE__*/function(_Kt2){function G(e){var _this18;_classCallCheck(this,G);var t,n;_this18=_callSuper(this,G,[e]),_this18._isModelLoaded=!1,_this18._isModelLoading=!1,_this18._loadOnFirstMessage=!1,_this18._webModel={},_this18.permittedErrorPrefixes=[G.MULTIPLE_MODELS_ERROR,G.WEB_LLM_NOT_FOUND_ERROR,G.GENERIC_ERROR],_this18._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this18._webModel=e.webModel),(t=_this18._webModel.load)!=null&&t.clearCache&&G.clearAllCache(),_this18.findModelInWindow(e),_this18.canSendMessage=_this18.canSubmit.bind(_assertThisInitialized(_this18)),_this18._chatEl=(n=e.shadowRoot)==null?void 0:n.children[0],e.history&&G.setUpHistory(_this18._conversationHistory,e.history);return _this18;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
143
- _inherits(G,_Kt2);return _createClass(G,[{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>G.MODULE_SEARCH_LIMIT_S?((n=this._messages)==null||n.addNewErrorMessage(Y,G.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&&ce.scrollToTop((s=_this21._messages)==null?void 0:s.elementRef);},e);}// prettier-ignore
143
+ _inherits(G,_Kt2);return _createClass(G,[{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>G.MODULE_SEARCH_LIMIT_S?((n=this._messages)==null||n.addNewErrorMessage(Y,G.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&&oe.scrollToTop((s=_this21._messages)==null?void 0:s.elementRef);},e);}// prettier-ignore
144
144
  },{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=ks.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:J,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(G.chat){(t=this._messages)==null||t.addNewErrorMessage(Y,G.MULTIPLE_MODELS_ERROR),console[f](G.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return Or.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var n;var e=G.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=JSON.parse(JSON.stringify(Or));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,v,_g,_t17;return _regenerator().w(function(_context39){while(1)switch(_context39.p=_context39.n){case 0:this.scrollToTop(),G.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 ce.scrollToBottom(_this22._messages);}),n=!1);};G.chat.setInitProgressCallback(s);_context39.p=1;_this$getConfig=this.getConfig(),g=_this$getConfig.model,b=_this$getConfig.appConfig,v={};this._webModel.instruction&&(v.conv_config={system:this._webModel.instruction});this._conversationHistory.length>0&&(v.conversation_history=this._conversationHistory);_context39.n=2;return G.chat.reload(g,v,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=ks.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(Y,G.GENERIC_ERROR);console[f](e);this._isModelLoaded=!1;this._isModelLoading=!1;_t18=G.chat;if(!_t18){_context40.n=2;break;}_context40.n=1;return G.chat.unload();case 1:G.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 G.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 et(e);_context43.n=1;return n.generate(t,/*#__PURE__*/function(){var _ref27=_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 G.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 _ref27.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(Y),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$L$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 L.processRequestInterceptor(this.deepChat,{body:_defineProperty({},h,s)});case 1:_yield$L$processReque5=_context45.v;r=_yield$L$processReque5.body;o=_yield$L$processReque5.error;a=!!this.stream;try{if(o)L.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!r||!r[h]){c=ta({body:r},!1);console[f](c);l=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;L.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:!G.chat||this._isModelLoading||((n=this._webModel.introMessage)!=null&&n.removeAfterMessage&&((s=this._removeIntro)==null||s.call(this)),e.addLoadingMessage(),this.generateResp(e,t,G.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.role===U&&n[h]){var r=t[s+1];r!=null&&r[h]&&r.role!==U&&e.push([n[h],r[h]]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e,t,n){var a,c,s,r,o,d,_t23;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:_context47.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,n);case 1:_t23=_context47.v;if(_t23){_context47.n=2;break;}_t23=n;case 2:s=_t23;if(!((c=e.connect)!=null&&c.stream&&Array.isArray(s)&&s.length>1)){_context47.n=3;break;}console[f](fo);return _context47.a(2);case 3:r=Array.isArray(s)?s:[s],o=r.find(function(l){return typeof l[f]=="string";});if(!o){_context47.n=4;break;}L.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=na(n,!!e.responseInterceptor,s);L.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(){G.clearCache("webllm/model"),G.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);});});});}}]);}(Kt);G.GENERIC_ERROR="Error, please check the [troubleshooting](".concat($,"webModel#troubleshooting) section of documentation for help."),G.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",G.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",G.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",G.MODULE_SEARCH_LIMIT_S=5;var ls=G;var de=function de(i,e,t,n){return{url:i,method:e,handleVerificationResult:t,augmentUrl:n};},rl=function rl(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},ol=function ol(i,e,t,n){var s=i;Array.isArray(s[f])&&s[f][0]==="Error in `parameters`: field required"?t(e):n(re);},al=function al(){return de("https://api-inference.huggingface.co/models/gpt2",le,ol);},ts=/*#__PURE__*/function(_R){// 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,v,_g,_t17;return _regenerator().w(function(_context39){while(1)switch(_context39.p=_context39.n){case 0:this.scrollToTop(),G.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 oe.scrollToBottom(_this22._messages);}),n=!1);};G.chat.setInitProgressCallback(s);_context39.p=1;_this$getConfig=this.getConfig(),g=_this$getConfig.model,b=_this$getConfig.appConfig,v={};this._webModel.instruction&&(v.conv_config={system:this._webModel.instruction});this._conversationHistory.length>0&&(v.conversation_history=this._conversationHistory);_context39.n=2;return G.chat.reload(g,v,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=ks.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(Y,G.GENERIC_ERROR);console[f](e);this._isModelLoaded=!1;this._isModelLoading=!1;_t18=G.chat;if(!_t18){_context40.n=2;break;}_context40.n=1;return G.chat.unload();case 1:G.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 G.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 et(e);_context43.n=1;return n.generate(t,/*#__PURE__*/function(){var _ref27=_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 G.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 _ref27.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(Y),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$L$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 L.processRequestInterceptor(this.deepChat,{body:_defineProperty({},h,s)});case 1:_yield$L$processReque5=_context45.v;r=_yield$L$processReque5.body;o=_yield$L$processReque5.error;a=!!this.stream;try{if(o)L.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!r||!r[h]){c=ta({body:r},!1);console[f](c);l=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;L.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:!G.chat||this._isModelLoading||((n=this._webModel.introMessage)!=null&&n.removeAfterMessage&&((s=this._removeIntro)==null||s.call(this)),e.addLoadingMessage(),this.generateResp(e,t,G.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.role===U&&n[h]){var r=t[s+1];r!=null&&r[h]&&r.role!==U&&e.push([n[h],r[h]]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e,t,n){var a,c,s,r,o,d,_t23;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:_context47.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,n);case 1:_t23=_context47.v;if(_t23){_context47.n=2;break;}_t23=n;case 2:s=_t23;if(!((c=e.connect)!=null&&c.stream&&Array.isArray(s)&&s.length>1)){_context47.n=3;break;}console[f](fo);return _context47.a(2);case 3:r=Array.isArray(s)?s:[s],o=r.find(function(l){return typeof l[f]=="string";});if(!o){_context47.n=4;break;}L.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=na(n,!!e.responseInterceptor,s);L.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(){G.clearCache("webllm/model"),G.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);});});});}}]);}(Kt);G.GENERIC_ERROR="Error, please check the [troubleshooting](".concat($,"webModel#troubleshooting) section of documentation for help."),G.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",G.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",G.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",G.MODULE_SEARCH_LIMIT_S=5;var ls=G;var de=function de(i,e,t,n){return{url:i,method:e,handleVerificationResult:t,augmentUrl:n};},rl=function rl(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},ol=function ol(i,e,t,n){var s=i;Array.isArray(s[f])&&s[f][0]==="Error in `parameters`: field required"?t(e):n(re);},al=function al(){return de("https://api-inference.huggingface.co/models/gpt2",le,ol);},ts=/*#__PURE__*/function(_R){// prettier-ignore
146
146
  function ts(e,t,n,s,r,o){var _this24;_classCallCheck(this,ts);_this24=_callSuper(this,ts,[e,al(),rl,r,o]),_this24.insertKeyPlaceholderText="Hugging Face Token",_this24.keyHelpUrl="https://huggingface.co/settings/tokens",_this24.permittedErrorPrefixes=[Ui],_this24.url="".concat(ts.URL_PREFIX).concat(n),_this24.textInputPlaceholderText=t,_typeof(s)=="object"&&(s.model&&(_this24.url="".concat(ts.URL_PREFIX).concat(s.model)),s.options&&(_this24.rawBody.options=s.options),s.parameters&&(_this24.rawBody.parameters=s.parameters));return _this24;}// prettier-ignore
147
147
  _inherits(ts,_R);return _createClass(ts,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var _s$options;var s=JSON.parse(JSON.stringify(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(Ie);case 1:s=this.preprocessBody(this.rawBody,t,n);ie.request(this,s,e);case 2:return _context48.a(2);}},_callee48,this);}));function callServiceAPI(_x108,_x109,_x110){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(R);ts.URL_PREFIX="https://api-inference.huggingface.co/models/";var Et=ts;var fs=/*#__PURE__*/function(_Et){// prettier-ignore
148
148
  function fs(e,t,n,s,r,o){var _this25;_classCallCheck(this,fs);_this25=_callSuper(this,fs,[e,t,n,s,r,o]),_this25.isTextInputDisabled=!0,_this25.canSendMessage=fs.canSendFile;return _this25;}_inherits(fs,_Et);return _createClass(fs,[{key:"preprocessBody",value:function preprocessBody(e,t,n){return n[0];}// prettier-ignore
149
149
  },{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(Ie);case 1:if(n!=null&&n[0]){_context49.n=2;break;}throw new Error(Ys);case 2:ie.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]);}}]);}(Et);var cl=/*#__PURE__*/function(_fs){// prettier-ignore
150
- 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.audioClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,cl,[e,"Attach an audio ".concat(Q),"ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,n,{audio:{}}]);}_inherits(cl,_fs);return _createClass(cl,[{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;}()}]);}(fs);var ll=/*#__PURE__*/function(_fs2){function ll(e){_classCallCheck(this,ll);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.imageClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ll,[e,"Attach an image ".concat(Q),"google/vit-base-patch16-224",t,n,{images:{}}]);}_inherits(ll,_fs2);return _createClass(ll,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e){var t;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(!e.estimated_time){_context51.n=1;break;}return _context51.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[f]){_context51.n=2;break;}throw e[f];case 2:return _context51.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee51);}));function extractPollResultData(_x115){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(fs);var ti=function ti(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},dl=function dl(i,e,t,n){i.message?n(re):t(e);},ni=function ni(){return de("https://api.stability.ai/v1/engines/list",ae,dl);},yn="data:image/png;base64,";var si=/*#__PURE__*/function(_R2){// prettier-ignore
150
+ 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.audioClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,cl,[e,"Attach an audio ".concat(Q),"ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,n,{audio:{}}]);}_inherits(cl,_fs);return _createClass(cl,[{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;}()}]);}(fs);var ll=/*#__PURE__*/function(_fs2){function ll(e){_classCallCheck(this,ll);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.imageClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ll,[e,"Attach an image ".concat(Q),"google/vit-base-patch16-224",t,n,{images:{}}]);}_inherits(ll,_fs2);return _createClass(ll,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e){var t;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(!e.estimated_time){_context51.n=1;break;}return _context51.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[f]){_context51.n=2;break;}throw e[f];case 2:return _context51.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee51);}));function extractPollResultData(_x115){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(fs);var ti=function ti(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},dl=function dl(i,e,t,n){i.message?n(re):t(e);},ni=function ni(){return de("https://api.stability.ai/v1/engines/list",ce,dl);},yn="data:image/png;base64,";var si=/*#__PURE__*/function(_R2){// prettier-ignore
151
151
  function si(e,t,n,s,r){var _this26;_classCallCheck(this,si);_this26=_callSuper(this,si,[e,t,n,s,r]),_this26.insertKeyPlaceholderText=_this26.genereteAPIKeyName("Stability AI"),_this26.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this26.permittedErrorPrefixes=[ps,"invalid_"];return _this26;}_inherits(si,_R2);return _createClass(si);}(R);var Os=/*#__PURE__*/function(_si){function Os(e){var _this27;_classCallCheck(this,Os);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t==null?void 0:t.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this27=_callSuper(this,Os,[e,ni(),ti,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")),Os.cleanConfig(r),Object.assign(_this27.rawBody,r)),_this27.canSendMessage=Os.canSendFileMessage;return _this27;}_inherits(Os,_si);return _createClass(Os,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(j,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}// prettier-ignore
152
152
  },{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(Ie);case 1:if(n){_context52.n=2;break;}throw new Error(Di);case 2:s=this.createFormDataBody(this.rawBody,n[0]);L.tempRemoveContentHeader(this.connectSettings,ie.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({},A,"".concat(yn).concat(n.base64)),T,j);});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]);}}]);}(si);var Ns=/*#__PURE__*/function(_si2){function Ns(e){var _this28;_classCallCheck(this,Ns);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t==null?void 0:t.stabilityAI,s=_defineProperty({},V,_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:2}));_this28=_callSuper(this,Ns,[e,ni(),ti,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),Ns.cleanConfig(r),Object.assign(_this28.rawBody,r)),_this28.canSendMessage=Ns.canSendFileTextMessage;return _this28;}_inherits(Ns,_si2);return _createClass(Ns,[{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
153
153
  },{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(Ie);case 1:if(!(!n||!n[0]||!n[1])){_context54.n=2;break;}throw new Error(Di);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);L.tempRemoveContentHeader(this.connectSettings,ie.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({},A,"".concat(yn).concat(n.base64)),T,j);});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()!=="");}}]);}(si);var hl=/*#__PURE__*/function(_fs3){function hl(e){_classCallCheck(this,hl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.audioSpeechRecognition,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,hl,[e,"Attach an audio ".concat(Q),"facebook/wav2vec2-large-960h-lv60-self",t,n,{audio:{}}]);}_inherits(hl,_fs3);return _createClass(hl,[{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;}()}]);}(fs);var ul=/*#__PURE__*/function(_Et2){function ul(e){_classCallCheck(this,ul);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.textGeneration,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ul,[e,"Once upon a time","gpt2",t,n]);}_inherits(ul,_Et2);return _createClass(ul,[{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;}()}]);}(Et);var pl=/*#__PURE__*/function(_Et3){function pl(e){var _this29;_classCallCheck(this,pl);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,pl,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,n]),_this29.permittedErrorPrefixes=[Ui,"Error in"],_this29._context=t.context;return _this29;}_inherits(pl,_Et3);return _createClass(pl,[{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;}()}]);}(Et);var fl=/*#__PURE__*/function(_Et4){function fl(e){_classCallCheck(this,fl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.summarization,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,fl,[e,"Insert text to summarize","facebook/bart-large-cnn",t,n]);}_inherits(fl,_Et4);return _createClass(fl,[{key:"extractResultData",value:function(){var _extractResultData6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){var t;return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e[f]){_context59.n=1;break;}throw e[f];case 1:return _context59.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.summary_text)||""));}},_callee59);}));function extractResultData(_x127){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(Et);var ml=/*#__PURE__*/function(_Et5){function ml(e){var _this30$maxMessages;var _this30;_classCallCheck(this,ml);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,ml,[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
154
154
  _inherits(ml,_Et5);return _createClass(ml,[{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.role===U;}).map(function(a){return a[h];}),o=s.filter(function(a){return a.role===J;}).map(function(a){return a[h];});return{past_user_inputs:r,generated_responses:o,mostRecentMessageText:n};}// prettier-ignore
155
155
  },{key:"preprocessBody",value:function preprocessBody(e,t){var _n$options;var n=JSON.parse(JSON.stringify(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;}()}]);}(Et);var Ls=/*#__PURE__*/function(_si3){function Ls(e){var _this31;_classCallCheck(this,Ls);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.stabilityAI,s=_defineProperty({},V,_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:1}));_this31=_callSuper(this,Ls,[e,ni(),ti,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),Ls.cleanConfig(r),Object.assign(_this31.rawBody,r)),_this31.canSendMessage=Ls.canSendFileTextMessage;return _this31;}_inherits(Ls,_si3);return _createClass(Ls,[{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
156
- },{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(Ie);case 1:if(n){_context61.n=2;break;}throw new Error(Di);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);L.tempRemoveContentHeader(this.connectSettings,ie.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({},A,"".concat(yn).concat(n.base64)),T,j);});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()!=="");}}]);}(si);var gl=/*#__PURE__*/function(_Et6){function gl(e){_classCallCheck(this,gl);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,gl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(gl,_Et6);return _createClass(gl,[{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;}()}]);}(Et);var Ps=/*#__PURE__*/function(_si4){function Ps(e){var _this32;_classCallCheck(this,Ps);var r;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.stabilityAI;_this32=_callSuper(this,Ps,[e,ni(),ti,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),Ps.cleanConfig(s),Object.assign(_this32.rawBody,s)),_this32.canSendMessage=Ps.canSendTextMessage;return _this32;}_inherits(Ps,_si4);return _createClass(Ps,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=JSON.parse(JSON.stringify(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({},A,"".concat(yn).concat(n.base64)),T,j);});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()!=="");}}]);}(si);var yl=/*#__PURE__*/function(_Et7){function yl(e){var _this33;_classCallCheck(this,yl);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,yl,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this33.permittedErrorPrefixes=[Ui,"No mask_token"];return _this33;}_inherits(yl,_Et7);return _createClass(yl,[{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;}()}]);}(Et);var zi=function zi(i){return _defineProperty(_defineProperty({},D,K),oe,"".concat(ye).concat(i));},bl=function bl(i,e,t,n){var s=i;s[f]?s[f].message===Fi?n(re):n(He):t(e);},Vi=function Vi(){return de("https://open.bigmodel.cn/api/paas/v4/models",ae,bl);};var vl=/*#__PURE__*/function(_R3){function vl(e){var _o$model,_a$voice;var _this34;_classCallCheck(this,vl);var r,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.bigModel;_this34=_callSuper(this,vl,[e,Vi(),zi,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=[oe,be];var s=(r=t.bigModel)==null?void 0:r.textToSpeech;_typeof(s)===B&&(_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(vl,_R3);return _createClass(vl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},T,"audio/mpeg")),n=URL.createObjectURL(t);return _context68.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},A,n),T,P)]));}},_callee68);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(R);var Ji=function Ji(i){return _defineProperty(_defineProperty({},D,K),oe,"".concat(ye).concat(i));},_l=function _l(i,e,t,n){var s=i;s[f]?s[f].message===Fi?n(re):n(He):t(e);},Ki=function Ki(){return de("https://api.together.xyz/v1/models",ae,_l);};var El=/*#__PURE__*/function(_R4){function El(e){var _o$model2,_a$voice2;var _this35;_classCallCheck(this,El);var r,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.together;_this35=_callSuper(this,El,[e,Ki(),Ji,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=[Ke,be];var s=(r=t.together)==null?void 0:r.textToSpeech;_typeof(s)===B&&_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(El,_R4);return _createClass(El,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},T,"audio/mpeg")),n=URL.createObjectURL(t);return _context70.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},A,n),T,P)]));}},_callee70);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(R);var Pe="https://api.openai.com/v1/",bn="https://platform.openai.com/account/api-keys",Ai="input_text",Nr="input_image",Lr="output_text",mi="image_generation_call",Io="function_call_output",Sn="response",vn=function vn(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},Mo=function Mo(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(re):n(He):t(e);},_n=function _n(){return de("".concat(Pe,"models"),ae,Mo);},It=/*#__PURE__*/function(){var _ref54=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(i,e,t){var n,s,r,o,a,c,_yield$L$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 L.processRequestInterceptor(r,c);case 1:_yield$L$processReque6=_context71.v;l=_yield$L$processReque6.body;d=_yield$L$processReque6.headers;p=_yield$L$processReque6.error;u=o.onFinish;if(!(p&&a)){_context71.n=2;break;}return _context71.a(2,L.onInterceptorError(a,p,u));case 2:_context71.n=3;return L.fetch(i,d,n,l).then(function(b){return L.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 It(_x144,_x145,_x146){return _ref54.apply(this,arguments);};}(),Fe=/*#__PURE__*/function(){function Fe(){_classCallCheck(this,Fe);}return _createClass(Fe,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[D];delete r[D];a=n.map(/*#__PURE__*/function(){var _ref55=_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(It(e,l,le,!1));})));}},_callee72);}));return function(_x151){return _ref55.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[D]=o,c));case 4:_context73.p=4;_t24=_context73.v;throw r[D]=o,L.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")?j:Gt;}},{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(_ref56){var c=_ref56.fileId;return e.url="".concat(n).concat(c).concat(s),new Promise(function(l){l(It(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({},A,u.target.result),"name",t[l].name),T,Fe.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
156
+ },{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(Ie);case 1:if(n){_context61.n=2;break;}throw new Error(Di);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);L.tempRemoveContentHeader(this.connectSettings,ie.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({},A,"".concat(yn).concat(n.base64)),T,j);});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()!=="");}}]);}(si);var gl=/*#__PURE__*/function(_Et6){function gl(e){_classCallCheck(this,gl);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,gl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(gl,_Et6);return _createClass(gl,[{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;}()}]);}(Et);var Ps=/*#__PURE__*/function(_si4){function Ps(e){var _this32;_classCallCheck(this,Ps);var r;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.stabilityAI;_this32=_callSuper(this,Ps,[e,ni(),ti,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),Ps.cleanConfig(s),Object.assign(_this32.rawBody,s)),_this32.canSendMessage=Ps.canSendTextMessage;return _this32;}_inherits(Ps,_si4);return _createClass(Ps,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=JSON.parse(JSON.stringify(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({},A,"".concat(yn).concat(n.base64)),T,j);});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()!=="");}}]);}(si);var yl=/*#__PURE__*/function(_Et7){function yl(e){var _this33;_classCallCheck(this,yl);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,yl,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this33.permittedErrorPrefixes=[Ui,"No mask_token"];return _this33;}_inherits(yl,_Et7);return _createClass(yl,[{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;}()}]);}(Et);var zi=function zi(i){return _defineProperty(_defineProperty({},D,K),ae,"".concat(ye).concat(i));},bl=function bl(i,e,t,n){var s=i;s[f]?s[f].message===Fi?n(re):n(He):t(e);},Vi=function Vi(){return de("https://open.bigmodel.cn/api/paas/v4/models",ce,bl);};var vl=/*#__PURE__*/function(_R3){function vl(e){var _o$model,_a$voice;var _this34;_classCallCheck(this,vl);var r,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.bigModel;_this34=_callSuper(this,vl,[e,Vi(),zi,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=[ae,be];var s=(r=t.bigModel)==null?void 0:r.textToSpeech;_typeof(s)===B&&(_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(vl,_R3);return _createClass(vl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},T,"audio/mpeg")),n=URL.createObjectURL(t);return _context68.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},A,n),T,P)]));}},_callee68);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(R);var Ji=function Ji(i){return _defineProperty(_defineProperty({},D,K),ae,"".concat(ye).concat(i));},_l=function _l(i,e,t,n){var s=i;s[f]?s[f].message===Fi?n(re):n(He):t(e);},Ki=function Ki(){return de("https://api.together.xyz/v1/models",ce,_l);};var El=/*#__PURE__*/function(_R4){function El(e){var _o$model2,_a$voice2;var _this35;_classCallCheck(this,El);var r,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.together;_this35=_callSuper(this,El,[e,Ki(),Ji,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=[Ke,be];var s=(r=t.together)==null?void 0:r.textToSpeech;_typeof(s)===B&&_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(El,_R4);return _createClass(El,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},T,"audio/mpeg")),n=URL.createObjectURL(t);return _context70.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},A,n),T,P)]));}},_callee70);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(R);var Pe="https://api.openai.com/v1/",bn="https://platform.openai.com/account/api-keys",Ai="input_text",Nr="input_image",Lr="output_text",mi="image_generation_call",Io="function_call_output",Sn="response",vn=function vn(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},Mo=function Mo(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(re):n(He):t(e);},_n=function _n(){return de("".concat(Pe,"models"),ce,Mo);},It=/*#__PURE__*/function(){var _ref54=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(i,e,t){var n,s,r,o,a,c,_yield$L$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 L.processRequestInterceptor(r,c);case 1:_yield$L$processReque6=_context71.v;l=_yield$L$processReque6.body;d=_yield$L$processReque6.headers;p=_yield$L$processReque6.error;u=o.onFinish;if(!(p&&a)){_context71.n=2;break;}return _context71.a(2,L.onInterceptorError(a,p,u));case 2:_context71.n=3;return L.fetch(i,d,n,l).then(function(b){return L.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 It(_x144,_x145,_x146){return _ref54.apply(this,arguments);};}(),Fe=/*#__PURE__*/function(){function Fe(){_classCallCheck(this,Fe);}return _createClass(Fe,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[D];delete r[D];a=n.map(/*#__PURE__*/function(){var _ref55=_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(It(e,l,le,!1));})));}},_callee72);}));return function(_x151){return _ref55.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[D]=o,c));case 4:_context73.p=4;_t24=_context73.v;throw r[D]=o,L.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")?j:Gt;}},{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(_ref56){var c=_ref56.fileId;return e.url="".concat(n).concat(c).concat(s),new Promise(function(l){l(It(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({},A,u.target.result),"name",t[l].name),T,Fe.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
157
157
  },{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 Fe.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[A])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[A]));});case 2:return _context75.a(2,(d=r==null?void 0:r[h])!=null&&d.value?_defineProperty(_defineProperty({},h,r[h].value),"role",s):_defineProperty(_defineProperty({},y,o),"role",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
158
158
  // To reproduce use the following text:
159
159
  // give example data for a csv and create a suitable bar chart for it with a link
@@ -164,31 +164,31 @@ _inherits(ml,_Et5);return _createClass(ml,[{key:"processMessagesI",value:functio
164
164
  // "give example data for a csv and create a suitable bar chart"
165
165
  },{key:"parseMessages",value:function parseMessages(e,t,n){var s=[];return t.forEach(/*#__PURE__*/function(){var _ref59=_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 _ref60=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(o){return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:s.push(Fe.getFilesAndText(e,r,n,o));case 1:return _context77.a(2);}},_callee77);}));return function(_x166){return _ref60.apply(this,arguments);};}());case 1:return _context78.a(2);}},_callee78);}));return function(_x165){return _ref59.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,Fe.parseMessages(e,[{content:t,role:bt}],n));}},_callee79);}));function processStreamMessages(_x167,_x168,_x169){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
166
166
  },{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=Fe.parseResult(t,n);return _context80.a(2,Fe.parseMessages(e,r,s));}},_callee80);}));function processAPIMessages(_x170,_x171,_x172,_x173){return _processAPIMessages.apply(this,arguments);}return processAPIMessages;}()}]);}();Fe.FILES_WITH_TEXT_ERROR="content with type `text` must have `text` values",Fe.FUNCTION_TOOL_RESP_ERROR="Response must contain an array of strings for each individual function/tool_call, see ".concat($,"directConnection/OpenAI/#assistant-functions.");var ht=Fe;var Rt=/*#__PURE__*/function(_R5){// prettier-ignore
167
- function Rt(e,t,n,s,r,o){var _this36;_classCallCheck(this,Rt);if(_this36=_callSuper(this,Rt,[e,s,r,o]),_this36.insertKeyPlaceholderText=_this36.genereteAPIKeyName("OpenAI"),_this36.keyHelpUrl=bn,_this36.url="",_this36.permittedErrorPrefixes=[ps,"Please send text",cs.FAILED_ERROR_MESSAGE],_this36.shouldFetchHistory=!1,_this36._searchedForThreadId=!1,_this36._config={},_this36._newAssistantDetails={model:"gpt-4"},_this36._waitingForStreamResponse=!1,_this36._isSSEStream=!1,_this36.urlSegments=n,_typeof(t)=="object"){_this36._config=t;var _this36$_config=_this36._config,a=_this36$_config.new_assistant,c=_this36$_config.thread_id,l=_this36$_config.load_thread_history;Object.assign(_this36._newAssistantDetails,a),c&&(_this36.sessionId=c),l&&(_this36.shouldFetchHistory=!0);}_this36.maxMessages=1,_this36._isSSEStream=!!(_this36.stream&&(_typeof(_this36.stream)!="object"||!_this36.stream.simulation));return _this36;}_inherits(Rt,_R5);return _createClass(Rt,[{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,go)]);}},_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=fn.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(_ref62){var c=_ref62.name;return c;}));a==="code_interpreter"||a==="file_search"||a===V?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 Rt.processAttachmentsMessage(s,t,"file_search");if(r==="code_interpreter")return Rt.processAttachmentsMessage(s,t,"code_interpreter");if(t.find(function(_ref63){var a=_ref63.name;return!ue.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=Rt.processImageMessage(s,t);if(_a3)return _a3;}}return{content:s[h]||"",role:U};}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,n){var s=JSON.parse(JSON.stringify(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);ie.request(this,s,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _s6=this.createNewThreadMessages(this.rawBody,t,n);this._isSSEStream?this.createStreamRun(_s6):ie.request(this,_s6,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(Ie);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 ht.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=le,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 It(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),le);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(_ref64){var _ref65=_slicedToArray(_ref64,1),n=_ref65[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(ht.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:ae,headers:(s=this.connectSettings)==null?void 0:s.headers};return _context84.a(2,(ie.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 It(this,JSON.parse(JSON.stringify(this.rawBody)),le);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 It(this,{},ae);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,ht.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:Rt.POLLING_TIMEOUT_MS});case 1:if(!(t===Hi&&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
167
+ function Rt(e,t,n,s,r,o){var _this36;_classCallCheck(this,Rt);if(_this36=_callSuper(this,Rt,[e,s,r,o]),_this36.insertKeyPlaceholderText=_this36.genereteAPIKeyName("OpenAI"),_this36.keyHelpUrl=bn,_this36.url="",_this36.permittedErrorPrefixes=[ps,"Please send text",cs.FAILED_ERROR_MESSAGE],_this36.shouldFetchHistory=!1,_this36._searchedForThreadId=!1,_this36._config={},_this36._newAssistantDetails={model:"gpt-4"},_this36._waitingForStreamResponse=!1,_this36._isSSEStream=!1,_this36.urlSegments=n,_typeof(t)=="object"){_this36._config=t;var _this36$_config=_this36._config,a=_this36$_config.new_assistant,c=_this36$_config.thread_id,l=_this36$_config.load_thread_history;Object.assign(_this36._newAssistantDetails,a),c&&(_this36.sessionId=c),l&&(_this36.shouldFetchHistory=!0);}_this36.maxMessages=1,_this36._isSSEStream=!!(_this36.stream&&(_typeof(_this36.stream)!="object"||!_this36.stream.simulation));return _this36;}_inherits(Rt,_R5);return _createClass(Rt,[{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,go)]);}},_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=fn.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(_ref62){var c=_ref62.name;return c;}));a==="code_interpreter"||a==="file_search"||a===V?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 Rt.processAttachmentsMessage(s,t,"file_search");if(r==="code_interpreter")return Rt.processAttachmentsMessage(s,t,"code_interpreter");if(t.find(function(_ref63){var a=_ref63.name;return!ue.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=Rt.processImageMessage(s,t);if(_a3)return _a3;}}return{content:s[h]||"",role:U};}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,n){var s=JSON.parse(JSON.stringify(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);ie.request(this,s,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _s6=this.createNewThreadMessages(this.rawBody,t,n);this._isSSEStream?this.createStreamRun(_s6):ie.request(this,_s6,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(Ie);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 ht.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=le,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 It(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),le);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(_ref64){var _ref65=_slicedToArray(_ref64,1),n=_ref65[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(ht.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:ce,headers:(s=this.connectSettings)==null?void 0:s.headers};return _context84.a(2,(ie.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 It(this,JSON.parse(JSON.stringify(this.rawBody)),le);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 It(this,{},ce);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,ht.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:Rt.POLLING_TIMEOUT_MS});case 1:if(!(t===Hi&&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
168
168
  },{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.functionHandler){_context88.n=1;break;}throw Error(Wt);case 1:t=e.map(function(c){return{name:c["function"].name,arguments:c["function"].arguments};});_context88.n=2;return this.functionHandler(t);case 2:n=_context88.v;if(!(!Array.isArray(n)||e.length!==n.length)){_context88.n=3;break;}throw Error(ht.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!="string";})){_context88.n=5;break;}throw Error(ht.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 It(this,{tool_outputs:r},le);case 8:return _context88.a(2,{timeoutMS:Rt.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=JSON.parse(JSON.stringify(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
169
169
  },{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var t,n,s,r,o,a,c,l,_a4,_c3;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=ht.getFilesAndText.bind(this,this,{role:bt,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 ht.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_c3=_context90.v;return _context90.a(2,_defineProperty(_defineProperty({},h,_c3[0][h]),y,_c3[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
170
170
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
- },{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 F.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 ue.isImageFileExtension(s.name);}).map(function(s){return _defineProperty(_defineProperty({},T,"image_file"),"image_file",{file_id:s.id});});if(n&&n.length>0)return e[h]&&e[h].length>0&&n.push(_defineProperty(_defineProperty({},T,h),h,e[h])),{content:n,role:U};}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,n){return{attachments:t.map(function(r){return{tools:[_defineProperty({},T,n)],file_id:r.id};}),content:[_defineProperty(_defineProperty({},T,h),h,e[h])],role:U};}}]);}(R);Rt.POLLING_TIMEOUT_MS=500;var Bs=Rt;var Wi=/*#__PURE__*/function(_Bs){function Wi(e){var _a$headers,_c$OpenAIBeta;var _this39;_classCallCheck(this,Wi);var o,a,c,l,d;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.openAI,s=(o=t.openAI)==null?void 0:o.assistant,r=Wi.buildUrlSegments(s);if(_this39=_callSuper(this,Wi,[e,s,r,_n(),vn,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)===B){var _ref76=(d=(l=e.directConnection)==null?void 0:l.openAI)==null?void 0:d.assistant,p=_ref76.function_handler,u=_ref76.files_tool_type;p&&(_this39._functionHandlerI=p),u&&(_this39.filesToolType=u);}return _this39;}_inherits(Wi,_Bs);return _createClass(Wi,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||Pe;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"};}}]);}(Bs);var Ds="Please define the Azure URL Details. [More Information](".concat($,"directConnection/Azure)"),ko=function ko(i){return _defineProperty({"api-key":i},D,K);},Oo=function Oo(i){return de("".concat(i.endpoint,"/openai/models?api-version=").concat(i.version),ae,Mo);},No=function No(i){var e=i.endpoint,t=i.version,n=i.deploymentId;return e&&t&&n;},on=/*#__PURE__*/function(_Bs2){function on(e){var _E$headers;var _this40;_classCallCheck(this,on);var l,d,p,u,g,b,v,E;var t=JSON.parse(JSON.stringify(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(on.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(on.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,on,[e,s==null?void 0:s.assistant,c,Oo(r),ko,n]),_this40.permittedErrorPrefixes=[Ds],_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)===B){var _ref78=(v=(b=(g=e.directConnection)==null?void 0:g.azure)==null?void 0:b.openAI)==null?void 0:v.assistant,C=_ref78.function_handler,H=_ref78.files_tool_type;C&&(_this40._functionHandlerI=C),H&&(_this40.filesToolType=H);}No(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,Ds));}));return _this40;}_inherits(on,_Bs2);return _createClass(on);}(Bs);on.THREAD_RESOURCE="threads",on.NEW_ASSISTANT_RESOURCE="assistants";var wi=on;var Sl="sts-session-started",xl="sts-session-stopped";var se=/*#__PURE__*/function(){function se(){_classCallCheck(this,se);}return _createClass(se,null,[{key:"addAttributes",value:function addAttributes(e){e.role="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-disabled","true");}},{key:"removeAriaDisabled",value:function removeAriaDisabled(e){e.removeAttribute("aria-disabled");}},{key:"removeAriaAttributes",value:function removeAriaAttributes(e){se.removeAriaBusy(e),se.removeAriaDisabled(e);}}]);}();var Lo="<?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",Ue=/*#__PURE__*/function(){function Ue(){_classCallCheck(this,Ue);}return _createClass(Ue,null,[{key:"createTextElement",value:function createTextElement(e){var t=S();return t[m].add(Ue.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,n,s){n?e.push(_t.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 Ue.tryAddSVGElement(a,t,o,r),r&&a.push(Ue.createTextElement(r)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e[m].remove(Ue.INPUT_BUTTON_SVG_CLASS,Ue.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(n){return n[m].contains(Ue.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e[m].add(Ue.INPUT_BUTTON_SVG_TEXT_CLASS):e[m].add(Ue.INPUT_BUTTON_SVG_CLASS);}}]);}();Ue.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",Ue.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",Ue.INPUT_BUTTON_SVG_CLASS="input-button-svg";var lt=Ue;var Wn=/*#__PURE__*/function(){function Wn(){_classCallCheck(this,Wn);}return _createClass(Wn,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 pe=/*#__PURE__*/function(){function pe(){_classCallCheck(this,pe);}return _createClass(pe,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var r,o;t.container&&ee.unsetAllCSSMouseStates(e,t.container);var _Wn$parseSVGTextEleme=Wn.parseSVGTextElements(Array.from(e.children)),n=_Wn$parseSVGTextEleme.svg,s=_Wn$parseSVGTextEleme.text;(r=t.svg)!=null&&r.styles&&n&&ee.unsetAllCSSMouseStates(n,t.svg.styles),(o=t[h])!=null&&o.styles&&s&&ee.unsetAllCSSMouseStates(s,t[h].styles);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var r,o;t.container&&ee.unsetActivityCSSMouseStates(e,t.container);var _Wn$parseSVGTextEleme2=Wn.parseSVGTextElements(Array.from(e.children)),n=_Wn$parseSVGTextEleme2.svg,s=_Wn$parseSVGTextEleme2.text;(r=t.svg)!=null&&r.styles&&n&&ee.unsetActivityCSSMouseStates(n,t.svg.styles),(o=t[h])!=null&&o.styles&&s&&ee.unsetActivityCSSMouseStates(s,t[h].styles);}},{key:"setElementsCSS",value:function setElementsCSS(e,t,n){var o,a,c,l,d;Object.assign(e[_],(o=t.container)==null?void 0:o[n]);var _Wn$parseSVGTextEleme3=Wn.parseSVGTextElements(Array.from(e.children)),s=_Wn$parseSVGTextEleme3.svg,r=_Wn$parseSVGTextEleme3.text;s&&Object.assign(s[_],(c=(a=t.svg)==null?void 0:a.styles)==null?void 0:c[n]),r&&Object.assign(r[_],(d=(l=t[h])==null?void 0:l.styles)==null?void 0:d[n]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,n){pe.setElementsCSS(e,t,x),n!==x&&(pe.setElementsCSS(e,t,Te),n!==Te&&pe.setElementsCSS(e,t,q));}}]);}();var Qt=/*#__PURE__*/function(){// prettier-ignore
171
+ },{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 F.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 ue.isImageFileExtension(s.name);}).map(function(s){return _defineProperty(_defineProperty({},T,"image_file"),"image_file",{file_id:s.id});});if(n&&n.length>0)return e[h]&&e[h].length>0&&n.push(_defineProperty(_defineProperty({},T,h),h,e[h])),{content:n,role:U};}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,n){return{attachments:t.map(function(r){return{tools:[_defineProperty({},T,n)],file_id:r.id};}),content:[_defineProperty(_defineProperty({},T,h),h,e[h])],role:U};}}]);}(R);Rt.POLLING_TIMEOUT_MS=500;var Bs=Rt;var Wi=/*#__PURE__*/function(_Bs){function Wi(e){var _a$headers,_c$OpenAIBeta;var _this39;_classCallCheck(this,Wi);var o,a,c,l,d;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.openAI,s=(o=t.openAI)==null?void 0:o.assistant,r=Wi.buildUrlSegments(s);if(_this39=_callSuper(this,Wi,[e,s,r,_n(),vn,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)===B){var _ref76=(d=(l=e.directConnection)==null?void 0:l.openAI)==null?void 0:d.assistant,p=_ref76.function_handler,u=_ref76.files_tool_type;p&&(_this39._functionHandlerI=p),u&&(_this39.filesToolType=u);}return _this39;}_inherits(Wi,_Bs);return _createClass(Wi,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||Pe;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"};}}]);}(Bs);var Ds="Please define the Azure URL Details. [More Information](".concat($,"directConnection/Azure)"),ko=function ko(i){return _defineProperty({"api-key":i},D,K);},Oo=function Oo(i){return de("".concat(i.endpoint,"/openai/models?api-version=").concat(i.version),ce,Mo);},No=function No(i){var e=i.endpoint,t=i.version,n=i.deploymentId;return e&&t&&n;},on=/*#__PURE__*/function(_Bs2){function on(e){var _E$headers;var _this40;_classCallCheck(this,on);var l,d,p,u,g,b,v,E;var t=JSON.parse(JSON.stringify(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(on.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(on.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,on,[e,s==null?void 0:s.assistant,c,Oo(r),ko,n]),_this40.permittedErrorPrefixes=[Ds],_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)===B){var _ref78=(v=(b=(g=e.directConnection)==null?void 0:g.azure)==null?void 0:b.openAI)==null?void 0:v.assistant,C=_ref78.function_handler,H=_ref78.files_tool_type;C&&(_this40._functionHandlerI=C),H&&(_this40.filesToolType=H);}No(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,Ds));}));return _this40;}_inherits(on,_Bs2);return _createClass(on);}(Bs);on.THREAD_RESOURCE="threads",on.NEW_ASSISTANT_RESOURCE="assistants";var wi=on;var Sl="sts-session-started",xl="sts-session-stopped";var se=/*#__PURE__*/function(){function se(){_classCallCheck(this,se);}return _createClass(se,null,[{key:"addAttributes",value:function addAttributes(e){e.role="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-disabled","true");}},{key:"removeAriaDisabled",value:function removeAriaDisabled(e){e.removeAttribute("aria-disabled");}},{key:"removeAriaAttributes",value:function removeAriaAttributes(e){se.removeAriaBusy(e),se.removeAriaDisabled(e);}}]);}();var Lo="<?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",Ue=/*#__PURE__*/function(){function Ue(){_classCallCheck(this,Ue);}return _createClass(Ue,null,[{key:"createTextElement",value:function createTextElement(e){var t=S();return t[m].add(Ue.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,n,s){n?e.push(_t.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 Ue.tryAddSVGElement(a,t,o,r),r&&a.push(Ue.createTextElement(r)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e[m].remove(Ue.INPUT_BUTTON_SVG_CLASS,Ue.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(n){return n[m].contains(Ue.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e[m].add(Ue.INPUT_BUTTON_SVG_TEXT_CLASS):e[m].add(Ue.INPUT_BUTTON_SVG_CLASS);}}]);}();Ue.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",Ue.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",Ue.INPUT_BUTTON_SVG_CLASS="input-button-svg";var lt=Ue;var Wn=/*#__PURE__*/function(){function Wn(){_classCallCheck(this,Wn);}return _createClass(Wn,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 pe=/*#__PURE__*/function(){function pe(){_classCallCheck(this,pe);}return _createClass(pe,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var r,o;t.container&&ee.unsetAllCSSMouseStates(e,t.container);var _Wn$parseSVGTextEleme=Wn.parseSVGTextElements(Array.from(e.children)),n=_Wn$parseSVGTextEleme.svg,s=_Wn$parseSVGTextEleme.text;(r=t.svg)!=null&&r.styles&&n&&ee.unsetAllCSSMouseStates(n,t.svg.styles),(o=t[h])!=null&&o.styles&&s&&ee.unsetAllCSSMouseStates(s,t[h].styles);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var r,o;t.container&&ee.unsetActivityCSSMouseStates(e,t.container);var _Wn$parseSVGTextEleme2=Wn.parseSVGTextElements(Array.from(e.children)),n=_Wn$parseSVGTextEleme2.svg,s=_Wn$parseSVGTextEleme2.text;(r=t.svg)!=null&&r.styles&&n&&ee.unsetActivityCSSMouseStates(n,t.svg.styles),(o=t[h])!=null&&o.styles&&s&&ee.unsetActivityCSSMouseStates(s,t[h].styles);}},{key:"setElementsCSS",value:function setElementsCSS(e,t,n){var o,a,c,l,d;Object.assign(e[_],(o=t.container)==null?void 0:o[n]);var _Wn$parseSVGTextEleme3=Wn.parseSVGTextElements(Array.from(e.children)),s=_Wn$parseSVGTextEleme3.svg,r=_Wn$parseSVGTextEleme3.text;s&&Object.assign(s[_],(c=(a=t.svg)==null?void 0:a.styles)==null?void 0:c[n]),r&&Object.assign(r[_],(d=(l=t[h])==null?void 0:l.styles)==null?void 0:d[n]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,n){pe.setElementsCSS(e,t,x),n!==x&&(pe.setElementsCSS(e,t,Te),n!==Te&&pe.setElementsCSS(e,t,q));}}]);}();var Qt=/*#__PURE__*/function(){// prettier-ignore
172
172
  function Qt(e,t,n,s,r,o){_classCallCheck(this,Qt);this._mouseState={state:"default"},this.isCustom=!1,se.addAttributes(e),this.elementRef=e,this.svg=_t.createSVGElement(t),this.customStyles=r,this.position=te.processPosition(n),this._tooltipSettings=s,this.dropupText=o;}return _createClass(Qt,[{key:"buttonMouseLeave",value:function buttonMouseLeave(e){var t;this._mouseState.state=x,((t=this._activeTooltip)==null?void 0:t.element[_].visibility)==="visible"&&this._tooltipSettings&&tt.hide(this._activeTooltip,this._tooltipSettings),e&&(pe.unsetAllCSS(this.elementRef,e),pe.setElementsCSS(this.elementRef,e,x));}},{key:"buttonMouseEnter",value:function buttonMouseEnter(e){var t;this._mouseState.state=Te,this._tooltipSettings&&(this._activeTooltip=tt.display(this.elementRef,this._tooltipSettings,(t=this._activeTooltip)==null?void 0:t.element)),e&&pe.setElementsCSS(this.elementRef,e,Te);}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&pe.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state=q,e&&pe.setElementsCSS(this.elementRef,e,q);}// be careful not to use onclick as that is used for button functionality
173
173
  },{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&&pe.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&&pe.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)),lt.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=lt.createCustomElements(t,this.svg,n);if(s&&s.length>0){if(this.position===ze){var r=this.svg.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 Xs=/*#__PURE__*/function(_Qt){function Xs(e){var _this41;_classCallCheck(this,Xs);var n,s;var t=((s=(n=e==null?void 0:e[x])==null?void 0:n.svg)==null?void 0:s.content)||Xs.EMPTY_SVG;_this41=_callSuper(this,Xs,[S(),t,void 0,void 0,e]),_this41.isActive=!1,_this41._innerElements=_this41.createInnerElementsForStates(_this41.customStyles),_this41.changeToDefault();return _this41;}_inherits(Xs,_Qt);return _createClass(Xs,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty(_defineProperty(_defineProperty({},x,this.createInnerButtonElements(x,e)),"active",this.createInnerButtonElements("active",e)),"unavailable",this.createInnerButtonElements("unavailable",e));}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return lt.createCustomElements(e,this.svg,t)||[this.svg];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef[m].replace(lt.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements.active),this.reapplyStateStyle("active",["unavailable",x]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,n,s;this.changeState(this._innerElements[x]),(e=this.customStyles)!=null&&e.active&&pe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(n=this.customStyles)!=null&&n.unavailable&&pe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s.unavailable),this.reapplyStateStyle(x,["active","unavailable"]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,n,s;this.changeState(this._innerElements.unavailable),(e=this.customStyles)!=null&&e.active&&pe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(n=this.customStyles)!=null&&n[x]&&pe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[x]),this.reapplyStateStyle("unavailable",[x,"active"]),this.isActive=!1;}}]);}(Qt);Xs.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var Fs=Xs;var Se=/*#__PURE__*/function(){function Se(){_classCallCheck(this,Se);}return _createClass(Se,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(),Se.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(),Se.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:Se.getObjectValue(s,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,n){var s=Se.getObjectValue(t,n);if(s){var r=_objectSpread(_objectSpread({},s),Se.getObjectValue(e,n)||{});Se.setPropertyValue(e,n,r);}}},{key:"isJson",value:function isJson(e){try{return JSON.stringify(e),!0;}catch(_unused8){return!1;}}// prettier-ignore
174
174
  },{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 Po="<?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>",Ci="<?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(_R6){function z(e){var _l$model;var _this42;_classCallCheck(this,z);var r,o,a,c,l;var t=JSON.parse(JSON.stringify(e.directConnection)),n=z.getKey(e);_this42=_callSuper(this,z,[e,_n(),vn,{key:n}]),_this42.insertKeyPlaceholderText=_this42.genereteAPIKeyName("OpenAI"),_this42.keyHelpUrl=bn,_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)===B){_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,_ref81=d.config||{},p=_ref81.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,_R6);return _createClass(z,[{key:"setInputAudioTranscribe",value:// https://community.openai.com/t/unable-to-access-user-audio-transcript-in-realtime-api/1001570/3
175
175
  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($,"directConnection/OpenAI/OpenAIRealtime#OpenAIRealtimeConfig")));}// called after API key was inserted
176
- },{key:"setUpView",value:function setUpView(e,t){e[_].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(Pe,"realtime/sessions"),{method:le,body:JSON.stringify(this.rawBody),headers:_defineProperty(_defineProperty({},D,K),oe,"".concat(ye).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(JSON.stringify(_defineProperty(_defineProperty({},T,"session.update"),"session",e)));},sendMessage:function sendMessage(e,t){var n=t||"system",s=[_defineProperty(_defineProperty({},T,n==="system"||n===U?Ai:h),"text",e)],r=_defineProperty(_defineProperty({role:n},T,"message"),"content",s);_this43.sendMessage(r);}};}},{key:"createContainer",value:function createContainer(){var e=S();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=S();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[_],(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=S();e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e[_],(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 Fs((t=this._buttonsConfig)==null?void 0:t[Ye]);return e.elementRef[m].add(z.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),e.elementRef.onclick=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),se.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 Fs((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[m].add(z.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),e.elementRef.onclick=/*#__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=S(P);n.autoplay=!0;s=new AudioContext(),r=s.createAnalyser();r.fftSize=256;o=new Uint8Array(r.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref84=_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 _ref84.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 _ref85=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(a){var l,d,p,c,g,b,v,_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&&(se.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(Sl)),_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)===xs)){_context97.n=5;break;}b=g.name,v=g.call_id;_context97.p=2;_context97.n=3;return _this46.handleTool(b,g.arguments,v);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===Ke?_this46.stopOnError(c.message):c.type==="response.audio_transcript.delta"||(c.type==="response.audio_transcript.done"?c.transcript&&Jt.onMessage(_this46._deepChat,_defineProperty({role:J},h,c.transcript),!1):c.type==="conversation.item.input_audio_transcription.completed"&&c.transcript&&Jt.onMessage(_this46._deepChat,_defineProperty({role:U},h,c.transcript),!1));case 7:return _context97.a(2);}},_callee97,null,[[2,4]]);}));return function(_x189){return _ref85.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(Pe,"realtime"),{method:le,body:a.sdp,headers:_defineProperty(_defineProperty({},oe,"".concat(ye).concat(e)),D,"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({},T,"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
176
+ },{key:"setUpView",value:function setUpView(e,t){e[_].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(Pe,"realtime/sessions"),{method:le,body:JSON.stringify(this.rawBody),headers:_defineProperty(_defineProperty({},D,K),ae,"".concat(ye).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(JSON.stringify(_defineProperty(_defineProperty({},T,"session.update"),"session",e)));},sendMessage:function sendMessage(e,t){var n=t||"system",s=[_defineProperty(_defineProperty({},T,n==="system"||n===U?Ai:h),"text",e)],r=_defineProperty(_defineProperty({role:n},T,"message"),"content",s);_this43.sendMessage(r);}};}},{key:"createContainer",value:function createContainer(){var e=S();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=S();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[_],(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=S();e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e[_],(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 Fs((t=this._buttonsConfig)==null?void 0:t[Ye]);return e.elementRef[m].add(z.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),e.elementRef.onclick=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),se.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 Fs((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[m].add(z.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),e.elementRef.onclick=/*#__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=S(P);n.autoplay=!0;s=new AudioContext(),r=s.createAnalyser();r.fftSize=256;o=new Uint8Array(r.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref84=_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 _ref84.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 _ref85=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(a){var l,d,p,c,g,b,v,_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&&(se.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(Sl)),_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)===xs)){_context97.n=5;break;}b=g.name,v=g.call_id;_context97.p=2;_context97.n=3;return _this46.handleTool(b,g.arguments,v);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===Ke?_this46.stopOnError(c.message):c.type==="response.audio_transcript.delta"||(c.type==="response.audio_transcript.done"?c.transcript&&Jt.onMessage(_this46._deepChat,_defineProperty({role:J},h,c.transcript),!1):c.type==="conversation.item.input_audio_transcription.completed"&&c.transcript&&Jt.onMessage(_this46._deepChat,_defineProperty({role:U},h,c.transcript),!1));case 7:return _context97.a(2);}},_callee97,null,[[2,4]]);}));return function(_x189){return _ref85.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(Pe,"realtime"),{method:le,body:a.sdp,headers:_defineProperty(_defineProperty({},ae,"".concat(ye).concat(e)),D,"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({},T,"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
177
177
  // in such instance please wait and refresh at a later time
178
- },{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[_].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(xl)),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=S();return e.id="deep-chat-openai-realtime-error",Object.assign(e[_],(t=this._errorConfig)==null?void 0:t[_]),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[_].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=S();return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t[I]&&(this._loadingElement.innerHTML=this._loadingConfig[I]),Object.assign(e[_],(n=this._loadingConfig)==null?void 0:n[_]),e[_].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),se.removeAriaDisabled(this._toggleButton.elementRef),se.addAriaBusy(this._toggleButton.elementRef)),(typeof((e=this._loadingConfig)==null?void 0:e.display)!="boolean"||this._loadingConfig.display)&&this._loadingElement&&(this._loadingElement[_].display="block",(t=this._loadingConfig)!=null&&t[I]||(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),se.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement[_].display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
178
+ },{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[_].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(xl)),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=S();return e.id="deep-chat-openai-realtime-error",Object.assign(e[_],(t=this._errorConfig)==null?void 0:t[_]),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[_].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=S();return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t[M]&&(this._loadingElement.innerHTML=this._loadingConfig[M]),Object.assign(e[_],(n=this._loadingConfig)==null?void 0:n[_]),e[_].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),se.removeAriaDisabled(this._toggleButton.elementRef),se.addAriaBusy(this._toggleButton.elementRef)),(typeof((e=this._loadingConfig)==null?void 0:e.display)!="boolean"||this._loadingConfig.display)&&this._loadingElement&&(this._loadingElement[_].display="block",(t=this._loadingConfig)!=null&&t[M]||(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),se.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement[_].display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
179
179
  },{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(Wt);case 1:_context99.n=2;return this._functionHandlerI({name:e,arguments:t});case 2:s=_context99.v;if(!(_typeof(s)!="object"||!Se.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({},T,Io),"call_id",n),"output",JSON.stringify(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
180
180
  },{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify(_defineProperty(_defineProperty({},T,"conversation.item.create"),"item",e));this._dc.send(t);var n=_defineProperty({},T,"response.create");this._dc.send(JSON.stringify(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?JSON.parse(JSON.stringify(e.avatar)):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$Ye,_o$x,_a$svg,_c$content,_t$toggle,_u$x,_g$svg,_b$content,_v$active,_E$svg,_C$content;var n,s,r,o,a,c,l,d,p,u,g,b,v,E,C;var t=_typeof(e)=="object"&&e.buttons?JSON.parse(JSON.stringify(e.buttons)):{};return(r=(s=(n=t[Ye])==null?void 0:n[x])==null?void 0:s[h])!=null&&r.content||((_t$Ye=t[Ye])!==null&&_t$Ye!==void 0?_t$Ye:t[Ye]={},(_o$x=(o=t[Ye])[x])!==null&&_o$x!==void 0?_o$x:o[x]={},(_a$svg=(a=t[Ye][x]).svg)!==null&&_a$svg!==void 0?_a$svg:a.svg={},(_c$content=(c=t[Ye][x].svg).content)!==null&&_c$content!==void 0?_c$content:c.content=Lo),(p=(d=(l=t.toggle)==null?void 0:l[x])==null?void 0:d[h])!=null&&p.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_u$x=(u=t.toggle)[x])!==null&&_u$x!==void 0?_u$x:u[x]={},(_g$svg=(g=t.toggle[x]).svg)!==null&&_g$svg!==void 0?_g$svg:g.svg={},(_b$content=(b=t.toggle[x].svg).content)!==null&&_b$content!==void 0?_b$content:b.content=Po,(_v$active=(v=t.toggle).active)!==null&&_v$active!==void 0?_v$active:v.active={},(_E$svg=(E=t.toggle.active).svg)!==null&&_E$svg!==void 0?_E$svg:E.svg={},(_C$content=(C=t.toggle.active.svg).content)!==null&&_C$content!==void 0?_C$content:C.content=Ci),t;}},{key:"createAvatar",value:function createAvatar(e){var n;var t=S("img");return t.id="deep-chat-openai-realtime-avatar",Object.assign(t[_],(n=e==null?void 0:e.styles)==null?void 0:n[j]),t[A]=(e==null?void 0:e[A])||_i,t;}},{key:"createButtonContainer",value:function createButtonContainer(e){var t=S();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),se.removeAriaBusy(e.elementRef),se.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){z.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){se.removeAriaDisabled(e.elementRef),e.elementRef[m].remove(z.UNAVAILABLE);}}]);}(R);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 Ti=z;var an=/*#__PURE__*/function(_R7){function an(e){var _o$model3,_a$voice3;var _this48;_classCallCheck(this,an);var r,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t==null?void 0:t.openAI;_this48=_callSuper(this,an,[e,_n(),vn,n]),_this48.insertKeyPlaceholderText=_this48.genereteAPIKeyName("OpenAI"),_this48.keyHelpUrl=bn,_this48.url="".concat(Pe,"audio/speech"),_this48.permittedErrorPrefixes=[kt];var s=(r=t==null?void 0:t.openAI)==null?void 0:r.textToSpeech;_typeof(s)===B&&Object.assign(_this48.rawBody,s),(_o$model3=(o=_this48.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=an.DEFAULT_MODEL,(_a$voice3=(a=_this48.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=an.DEFAULT_VOIDE,_this48.textInputPlaceholderText="Insert text to generate audio",_this48.rawBody.response_format="mp3";return _this48;}_inherits(an,_R7);return _createClass(an,[{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=JSON.parse(JSON.stringify(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({},A,s.target.result),T,P)]));};}));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;}()}]);}(R);an.DEFAULT_MODEL="tts-1",an.DEFAULT_VOIDE="alloy";var Ri=an;var We=/*#__PURE__*/function(_R8){function We(e){var _o$model4;var _this49;_classCallCheck(this,We);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t==null?void 0:t.openAI;_this49=_callSuper(this,We,[e,_n(),vn,n,{audio:{}}]),_this49.insertKeyPlaceholderText=_this49.genereteAPIKeyName("OpenAI"),_this49.keyHelpUrl=bn,_this49.url="",_this49.permittedErrorPrefixes=[kt],_this49.textInputPlaceholderText=ji,_this49._service_url=We.AUDIO_TRANSCRIPTIONS_URL;var s=(r=t==null?void 0:t.openAI)==null?void 0:r[P];_typeof(s)=="object"&&(_this49.processConfig(s),We.cleanConfig(s),Object.assign(_this49.rawBody,s)),(_o$model4=(o=_this49.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=We.DEFAULT_MODEL,_this49.rawBody.response_format="json",_this49.canSendMessage=We.canSendFileMessage;return _this49;}_inherits(We,_R8);return _createClass(We,[{key:"processConfig",value:function processConfig(e){e!=null&&e.type&&e.type==="translation"&&(this._service_url=We.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=JSON.parse(JSON.stringify(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
181
181
  },{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(Ie);case 1:if(n!=null&&n[0]){_context102.n=2;break;}throw new Error(Ys);case 2:this.url=this.connectSettings.url||this._service_url;s=this.preprocessBody(this.rawBody,t),r=We.createFormDataBody(s,n[0]);L.tempRemoveContentHeader(this.connectSettings,ie.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(Q,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}}]);}(R);We.AUDIO_TRANSCRIPTIONS_URL="".concat(Pe,"audio/transcriptions"),We.AUDIO_TRANSLATIONS_URL="".concat(Pe,"audio/translations"),We.DEFAULT_MODEL="whisper-1";var Ii=We;var En="Ocp-Apim-Subscription-Key",Bo=// eslint-disable-next-line max-len
182
182
  "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",Al=function Al(i,e){return _defineProperty(_defineProperty(_defineProperty({},En,e),D,"application/ssml+xml"),"X-Microsoft-OutputFormat",i);},wl=function wl(i){return _defineProperty(_defineProperty({},En,i),"Accept",K);},Cl=function Cl(i,e,t,n){i[f]?n(re):t(e);},Tl=function Tl(i){return{url:"https://".concat(i,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:le,createHeaders:function createHeaders(e){return _defineProperty({},En,"".concat(e));},handleVerificationResult:Cl};},Rl=function Rl(i){return _defineProperty(_defineProperty({},En,i),D,K);},Il=function Il(i,e,t,n){var r;((r=i[f])==null?void 0:r.code)==="401"?n(re):t(e);},Ml=function Ml(i){return{url:"".concat(i,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:le,createHeaders:function createHeaders(e){return _defineProperty({},En,"".concat(e));},handleVerificationResult:Il};},kl=function kl(i,e,t,n){i.json().then(function(r){!Array.isArray(r)&&r[f].code===401e3?n(re):t(e);});},Ol=function Ol(i){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:le,createHeaders:function createHeaders(e){return Do(i,e);},handleVerificationResult:kl};},Do=function Do(i,e){var t=_defineProperty(_defineProperty({},En,e),D,K);return i&&(t["Ocp-Apim-Subscription-Region"]=i),t;};var Nl=/*#__PURE__*/function(_R9){// prettier-ignore
183
- function Nl(e,t,n,s,r){var _this50;_classCallCheck(this,Nl);_this50=_callSuper(this,Nl,[e,Ml(n),t,s,r]),_this50.insertKeyPlaceholderText="Azure Language Subscription Key",_this50.keyHelpUrl=Bo,_this50.permittedErrorPrefixes=["Access"];return _this50;}_inherits(Nl,_R9);return _createClass(Nl);}(R);var ns=/*#__PURE__*/function(_Nl){function ns(e){var _a$language;var _this51;_classCallCheck(this,ns);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,ns,[e,Rl,t.endpoint,n]),_this51.permittedErrorPrefixes=[ns.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,ns.ENDPOINT_ERROR_MESSAGE));}));return _this51;}_inherits(ns,_Nl);return _createClass(ns,[{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:ae,headers:(t=this.connectSettings)==null?void 0:t.headers};ie.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;}()}]);}(Nl);ns.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
184
- "Please define the azure endpoint. [More Information](".concat($,"directConnection/Azure#Summarization)");var Mi=ns;var Ll=/*#__PURE__*/function(){var _ref97=_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({},aa,i),ca,K);_t46="https://api.assemblyai.com/v2/transcript/";_context107.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:le,body:JSON.stringify({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===Hi)){_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 Ll(_x204,_x205){return _ref97.apply(this,arguments);};}(),Pl=function Pl(i){return _defineProperty(_defineProperty({},oe,i),D,"application/octet-stream");},Bl=function Bl(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(re):n(He):t(e);},Dl=function Dl(){return de("https://api.assemblyai.com/v2/upload",le,Bl);};var Xi=/*#__PURE__*/function(_R0){function Xi(e){var _this52;_classCallCheck(this,Xi);var n;var t=(n=e.directConnection)==null?void 0:n.assemblyAI;_this52=_callSuper(this,Xi,[e,Dl(),Pl,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=[yo,kt],_this52.canSendMessage=Xi.canFileSendMessage;return _this52;}_inherits(Xi,_R0);return _createClass(Xi,[{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(Ie);case 1:if(n!=null&&n[0]){_context108.n=2;break;}throw new Error(Ys);case 2:ie.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[oe];_context109.n=2;return Ll(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]);}}]);}(R);var Us=/*#__PURE__*/function(_R1){// prettier-ignore
183
+ function Nl(e,t,n,s,r){var _this50;_classCallCheck(this,Nl);_this50=_callSuper(this,Nl,[e,Ml(n),t,s,r]),_this50.insertKeyPlaceholderText="Azure Language Subscription Key",_this50.keyHelpUrl=Bo,_this50.permittedErrorPrefixes=["Access"];return _this50;}_inherits(Nl,_R9);return _createClass(Nl);}(R);var ns=/*#__PURE__*/function(_Nl){function ns(e){var _a$language;var _this51;_classCallCheck(this,ns);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,ns,[e,Rl,t.endpoint,n]),_this51.permittedErrorPrefixes=[ns.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,ns.ENDPOINT_ERROR_MESSAGE));}));return _this51;}_inherits(ns,_Nl);return _createClass(ns,[{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:ce,headers:(t=this.connectSettings)==null?void 0:t.headers};ie.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;}()}]);}(Nl);ns.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
184
+ "Please define the azure endpoint. [More Information](".concat($,"directConnection/Azure#Summarization)");var Mi=ns;var Ll=/*#__PURE__*/function(){var _ref97=_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({},aa,i),ca,K);_t46="https://api.assemblyai.com/v2/transcript/";_context107.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:le,body:JSON.stringify({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===Hi)){_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 Ll(_x204,_x205){return _ref97.apply(this,arguments);};}(),Pl=function Pl(i){return _defineProperty(_defineProperty({},ae,i),D,"application/octet-stream");},Bl=function Bl(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(re):n(He):t(e);},Dl=function Dl(){return de("https://api.assemblyai.com/v2/upload",le,Bl);};var Xi=/*#__PURE__*/function(_R0){function Xi(e){var _this52;_classCallCheck(this,Xi);var n;var t=(n=e.directConnection)==null?void 0:n.assemblyAI;_this52=_callSuper(this,Xi,[e,Dl(),Pl,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=[yo,kt],_this52.canSendMessage=Xi.canFileSendMessage;return _this52;}_inherits(Xi,_R0);return _createClass(Xi,[{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(Ie);case 1:if(n!=null&&n[0]){_context108.n=2;break;}throw new Error(Ys);case 2:ie.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[ae];_context109.n=2;return Ll(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]);}}]);}(R);var Us=/*#__PURE__*/function(_R1){// prettier-ignore
185
185
  function Us(e,t,n,s,r){var _this53$maxMessages,_u$model;var _this53;_classCallCheck(this,Us);var p,u;var o=JSON.parse(JSON.stringify(e.directConnection)),a=t||_n(),c=n||vn,l=s||o.openAI;_this53=_callSuper(this,Us,[e,a,c,l]),_this53.insertKeyPlaceholderText=_this53.genereteAPIKeyName("OpenAI"),_this53.keyHelpUrl="https://platform.openai.com/account/api-keys",_this53.permittedErrorPrefixes=[ps,"Invalid value"];var d=r||((p=o.openAI)==null?void 0:p.chat);_typeof(d)===B&&_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(Us,_R1);return _createClass(Us,[{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===P){var o=(n=t[A])==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({},T,qt),qt,{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({},T,h),h,e[h])),s;}return e[h];}}]);}(R);var Hs=/*#__PURE__*/function(_Us){function Hs(){var _this54;_classCallCheck(this,Hs);_this54=_callSuper(this,Hs,arguments),_this54.url="".concat(Pe,"chat/completions");return _this54;}_inherits(Hs,_Us);return _createClass(Hs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:Hs.getContent(r),role:R.getRoleViaUser(r.role)};});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[P])){_context111.n=4;break;}l=this.deepChat.textToSpeech,d=_typeof(l)=="object"&&typeof((c=l==null?void 0:l[P])==null?void 0:c.displayText)=="boolean";return _context111.a(2,_defineProperty(_defineProperty({},y,[_defineProperty(_defineProperty({},A,"data:audio/wav;base64,".concat(e.choices[0].message[P].data)),T,P)]),h,d?e.choices[0].message[P].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 Us.getBaseFileContent(e).map(function(n){return n.type===qt?n:_defineProperty(_defineProperty({},T,Ne),Ne,{url:n[A]});});}},{key:"getContent",value:function getContent(e){if(e[y]&&e[y].length>0){var t=Hs.getFileContent(e[y]);return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},T,h),h,e[h])),t;}return e[h];}}]);}(Us);var dr=/*#__PURE__*/function(_R10){// prettier-ignore
186
186
  function dr(e,t,n,s,r){var _this55;_classCallCheck(this,dr);_this55=_callSuper(this,dr,[e,Tl(n),t,s,r]),_this55.insertKeyPlaceholderText="Azure Speech Subscription Key",_this55.keyHelpUrl=Bo;return _this55;}_inherits(dr,_R10);return _createClass(dr);}(R);dr.REGION_ERROR_PREFIX="Please define a region config property. [More Information](".concat($,"directConnection/Azure#");var mn=dr;var ss=/*#__PURE__*/function(_mn){// prettier-ignore
187
187
  function ss(e){var _a$lang,_c$name,_l$gender;var _this56;_classCallCheck(this,ss);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,ss,[e,Al.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,n]),_this56.permittedErrorPrefixes=[ss.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,ss.REGION_ERROR_MESSAGE));}));return _this56;}_inherits(ss,_mn);return _createClass(ss,[{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({},A,s.target.result),T,P)]));};}));}},_callee114);}));function extractResultData(_x218){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}]);}(mn);ss.REGION_ERROR_MESSAGE="".concat(mn.REGION_ERROR_PREFIX,"TextToSpeech)");var ki=ss;var cn=/*#__PURE__*/function(_mn2){function cn(e){var _this57;_classCallCheck(this,cn);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,cn,[e,wl,t.region,n,s]),_this57.permittedErrorPrefixes=[cn.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,cn.REGION_ERROR_MESSAGE));});else{_this57.canSendMessage=cn.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(cn,_mn2);return _createClass(cn,[{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(Ie);case 1:if(n!=null&&n[0]){_context115.n=2;break;}throw new Error(Ys);case 2:(r=this.connectSettings)!=null&&r.headers&&(this.connectSettings.headers[D]=n[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),ie.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]);}}]);}(mn);cn.REGION_ERROR_MESSAGE="".concat(mn.REGION_ERROR_PREFIX,"SpeechToText)");var Oi=cn;var Fl=/*#__PURE__*/function(_R11){// prettier-ignore
188
188
  function Fl(e){var _this58;_classCallCheck(this,Fl);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,Fl,[e,Ol(t.region),Do.bind({},t==null?void 0:t.region),n]),_this58.insertKeyPlaceholderText="Azure Translate Subscription Key",_this58.keyHelpUrl=// eslint-disable-next-line max-len
189
- "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(Fl,_R11);return _createClass(Fl,[{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;}()}]);}(R);var Ul=/*#__PURE__*/function(_R12){function Ul(e){var _o$model5;var _this59;_classCallCheck(this,Ul);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.bigModel;_this59=_callSuper(this,Ul,[e,Vi(),zi,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=[oe,be];var s=(r=t.bigModel)==null?void 0:r[V];_typeof(s)===B&&(_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(Ul,_R12);return _createClass(Ul,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},A,n.url),T,j):_defineProperty(_defineProperty({},A,""),T,j);});return _context120.a(2,_defineProperty({},y,t));}},_callee120);}));function extractResultData(_x228){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(R);var Fo=function Fo(i){return _defineProperty(_defineProperty({},D,K),oe,"".concat(ye).concat(i));},Hl=function Hl(i,e,t,n){var s=i;s[f]?s[f].message===Fi?n(re):n(He):t(e);},Uo=function Uo(){return de("https://api.groq.com/openai/v1/models",ae,Hl);};var jl=/*#__PURE__*/function(_R13){function jl(e){var _o$model6,_a$voice4,_c$response_format;var _this60;_classCallCheck(this,jl);var r,o,a,c;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.groq;_this60=_callSuper(this,jl,[e,Uo(),Fo,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=[kt,"property"];var s=(r=t.groq)==null?void 0:r.textToSpeech;_typeof(s)===B&&_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,_R13);return _createClass(jl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},T,"audio/".concat(t))),s=URL.createObjectURL(n);return _context122.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},A,s),T,P)]));}},_callee122,this);}));function extractResultData(_x231){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(R);var ql=/*#__PURE__*/function(_R14){function ql(e){var _o$model7;var _this61;_classCallCheck(this,ql);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.together;_this61=_callSuper(this,ql,[e,Ki(),Ji,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=[Ke,be];var s=(r=t.together)==null?void 0:r[V];_typeof(s)===B&&_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,_R14);return _createClass(ql,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},A,n.url),T,j):n!=null&&n.b64_json?_defineProperty(_defineProperty({},A,"data:image/png;base64,".concat(n.b64_json)),T,j):_defineProperty(_defineProperty({},A,""),T,j);});return _context124.a(2,_defineProperty({},y,t));}},_callee124);}));function extractResultData(_x234){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(R);var Ge=/*#__PURE__*/function(_Us2){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
189
+ "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(Fl,_R11);return _createClass(Fl,[{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;}()}]);}(R);var Ul=/*#__PURE__*/function(_R12){function Ul(e){var _o$model5;var _this59;_classCallCheck(this,Ul);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.bigModel;_this59=_callSuper(this,Ul,[e,Vi(),zi,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=[ae,be];var s=(r=t.bigModel)==null?void 0:r[V];_typeof(s)===B&&(_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(Ul,_R12);return _createClass(Ul,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},A,n.url),T,j):_defineProperty(_defineProperty({},A,""),T,j);});return _context120.a(2,_defineProperty({},y,t));}},_callee120);}));function extractResultData(_x228){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(R);var Fo=function Fo(i){return _defineProperty(_defineProperty({},D,K),ae,"".concat(ye).concat(i));},Hl=function Hl(i,e,t,n){var s=i;s[f]?s[f].message===Fi?n(re):n(He):t(e);},Uo=function Uo(){return de("https://api.groq.com/openai/v1/models",ce,Hl);};var jl=/*#__PURE__*/function(_R13){function jl(e){var _o$model6,_a$voice4,_c$response_format;var _this60;_classCallCheck(this,jl);var r,o,a,c;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.groq;_this60=_callSuper(this,jl,[e,Uo(),Fo,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=[kt,"property"];var s=(r=t.groq)==null?void 0:r.textToSpeech;_typeof(s)===B&&_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,_R13);return _createClass(jl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},T,"audio/".concat(t))),s=URL.createObjectURL(n);return _context122.a(2,_defineProperty({},y,[_defineProperty(_defineProperty({},A,s),T,P)]));}},_callee122,this);}));function extractResultData(_x231){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(R);var ql=/*#__PURE__*/function(_R14){function ql(e){var _o$model7;var _this61;_classCallCheck(this,ql);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.together;_this61=_callSuper(this,ql,[e,Ki(),Ji,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=[Ke,be];var s=(r=t.together)==null?void 0:r[V];_typeof(s)===B&&_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,_R14);return _createClass(ql,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(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({},A,n.url),T,j):n!=null&&n.b64_json?_defineProperty(_defineProperty({},A,"data:image/png;base64,".concat(n.b64_json)),T,j):_defineProperty(_defineProperty({},A,""),T,j);});return _context124.a(2,_defineProperty({},y,t));}},_callee124);}));function extractResultData(_x234){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(R);var Ge=/*#__PURE__*/function(_Us2){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
190
190
  // prettier-ignore
191
- function Ge(e,t,n,s,r){var _this62;_classCallCheck(this,Ge);var a,c;_this62=_callSuper(this,Ge,[e,t,n,s,r]),_this62.keyHelpUrl=bn,_this62.url="".concat(Pe,"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)===B&&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(Ge,_Us2);return _createClass(Ge,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Ge,"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(Pe,"conversations/").concat(this._conversationId,"/items?limit=").concat(this._conversationLoadLimit);_context125.n=2;return It(this,{},ae);case 2:t=_context125.v;return _context125.a(2,(this.connectSettings.method=le,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,go)]));}},_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(Ge.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===Ai||s.type===Lr)&&s[h]?t.push(_defineProperty({role:_n8.role},h,s[h])):s.type===Nr&&t.push(_defineProperty({role:_n8.role},y,Ge.generateImageFile(s[Ne]||"")));}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}else _n8.type===mi&&t.push(_defineProperty({role:J},y,Ge.generateImageFile(_n8.result)));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e));t=this.processMessages(t),t=this._useConversation?[t[t.length-1]]:t;var s=t.map(function(r){return{content:Ge.getContent(r),role:R.getRoleViaUser(r.role)};});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(Pe,"conversations");_context126.n=1;return It(this,{},le);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=Ge.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])=="string";}))==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)===xs&&e.type?this.handleStreamedResponsesFunctionCall(e,t):e.type==="".concat(Sn,".").concat(mi,".partial_image")&&e.partial_image_b64?_defineProperty({},y,[_defineProperty(_defineProperty({},A,"".concat(Ge.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),T,j)]):e.delta&&!this._functionStreamInProgress&&e.type==="".concat(Sn,".").concat(Lr,".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(Sn,".output_item.done"))){_context130.n=2;break;}if(!(this._functionStreamInProgress=!1,((n=e.item)==null?void 0:n.type)===xs)){_context130.n=1;break;}return _context130.a(2,this.handleResponsesFunctionCalls([e.item],t));case 1:_context130.n=3;break;case 2:e.type==="".concat(Sn,".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===mi;});return n?_defineProperty(_defineProperty({},y,Ge.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===xs;});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(Wt);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=JSON.parse(JSON.stringify(t));if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref128){var l=_ref128.response;return typeof l!="string";})&&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:Io,call_id:p.call_id,output:l[Sn]});}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(un);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 Us.getBaseFileContent(e).map(function(n){return n.type===qt?n:_defineProperty(_defineProperty({detail:"auto"},T,Nr),Ne,n[A]);});}},{key:"getContent",value:function getContent(e){if(e.role===U&&e[y]&&e[y].length>0){var _n9=Ge.getFileContent(e[y]);return e[h]&&e[h].trim().length>0&&_n9.unshift(_defineProperty(_defineProperty({},T,Ai),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===Hi;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},A,"".concat(Ge.IMAGE_BASE64_PREFIX).concat(e)),T,j)];}}]);}(Us);Ge.IMAGE_BASE64_PREFIX="data:image/png;base64,";var js=Ge;var Zi=/*#__PURE__*/function(_js){function Zi(e){var _this64;_classCallCheck(this,Zi);var o,a,c,l,d,p,u;var t=JSON.parse(JSON.stringify(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,Zi,[e,Oo(s),ko,n,r]),_this64.permittedErrorPrefixes=[Ds],_this64.isTextInputDisabled=!1,_typeof(r)===B){var _ref131=(u=(p=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:p.openAI)==null?void 0:u.chat,g=_ref131.function_handler;g&&(_this64.functionHandler=g);}No(s)?_this64.url=Zi.buildURL(s):(_this64.isTextInputDisabled=!0,_this64.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,Ds));}));return _this64;}_inherits(Zi,_js);return _createClass(Zi,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(_R15){function qs(e){var _this65$maxMessages,_l$model2;var _this65;_classCallCheck(this,qs);var r,o,a,c,l;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.bigModel;_this65=_callSuper(this,qs,[e,Vi(),zi,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=[oe,be];var s=(r=t.bigModel)==null?void 0:r.chat;_typeof(s)===B&&_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,_R15);return _createClass(qs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:qs.getTextWFilesContent(r,qs.getFileContent),role:R.getRoleViaAI(r.role)};});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].role)===J&&((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===j?_defineProperty(_defineProperty({},T,Ne),Ne,{url:t[A]||""}):_defineProperty(_defineProperty({},T,Q),"file_url",{url:t[A]||""});});}}]);}(R);var $l=/*#__PURE__*/function(_R16){function $l(e){var _this66$maxMessages,_o$model8;var _this66;_classCallCheck(this,$l);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.together;_this66=_callSuper(this,$l,[e,Ki(),Ji,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=[Ke,be];var s=(r=t.together)==null?void 0:r.chat;_typeof(s)===B&&_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($l,_R16);return _createClass($l,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:r.role===J?bt:r.role};});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;}()}]);}(R);var Xe=/*#__PURE__*/function(_R17){function Xe(e){var _this67;_classCallCheck(this,Xe);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:2})};_this67=_callSuper(this,Xe,[e,_n(),vn,n,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenAI"),_this67.keyHelpUrl=bn,_this67.url="",_this67.permittedErrorPrefixes=[ps,"Invalid input image"];var r=(o=t==null?void 0:t.openAI)==null?void 0:o[V];if(_this67[Re]){var a=_typeof(r)=="object"&&r.size?Number.parseInt(r.size):1024;_this67[Re][y]={dimensions:{width:a,height:a}};}_typeof(r)===B&&Object.assign(_this67.rawBody,r),_this67.canSendMessage=Xe.canFileSendMessage;return _this67;}_inherits(Xe,_R17);return _createClass(Xe,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e));return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
191
+ function Ge(e,t,n,s,r){var _this62;_classCallCheck(this,Ge);var a,c;_this62=_callSuper(this,Ge,[e,t,n,s,r]),_this62.keyHelpUrl=bn,_this62.url="".concat(Pe,"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)===B&&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(Ge,_Us2);return _createClass(Ge,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Ge,"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(Pe,"conversations/").concat(this._conversationId,"/items?limit=").concat(this._conversationLoadLimit);_context125.n=2;return It(this,{},ce);case 2:t=_context125.v;return _context125.a(2,(this.connectSettings.method=le,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,go)]));}},_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(Ge.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===Ai||s.type===Lr)&&s[h]?t.push(_defineProperty({role:_n8.role},h,s[h])):s.type===Nr&&t.push(_defineProperty({role:_n8.role},y,Ge.generateImageFile(s[Ne]||"")));}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}else _n8.type===mi&&t.push(_defineProperty({role:J},y,Ge.generateImageFile(_n8.result)));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e));t=this.processMessages(t),t=this._useConversation?[t[t.length-1]]:t;var s=t.map(function(r){return{content:Ge.getContent(r),role:R.getRoleViaUser(r.role)};});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(Pe,"conversations");_context126.n=1;return It(this,{},le);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=Ge.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])=="string";}))==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)===xs&&e.type?this.handleStreamedResponsesFunctionCall(e,t):e.type==="".concat(Sn,".").concat(mi,".partial_image")&&e.partial_image_b64?_defineProperty({},y,[_defineProperty(_defineProperty({},A,"".concat(Ge.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),T,j)]):e.delta&&!this._functionStreamInProgress&&e.type==="".concat(Sn,".").concat(Lr,".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(Sn,".output_item.done"))){_context130.n=2;break;}if(!(this._functionStreamInProgress=!1,((n=e.item)==null?void 0:n.type)===xs)){_context130.n=1;break;}return _context130.a(2,this.handleResponsesFunctionCalls([e.item],t));case 1:_context130.n=3;break;case 2:e.type==="".concat(Sn,".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===mi;});return n?_defineProperty(_defineProperty({},y,Ge.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===xs;});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(Wt);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=JSON.parse(JSON.stringify(t));if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref128){var l=_ref128.response;return typeof l!="string";})&&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:Io,call_id:p.call_id,output:l[Sn]});}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(un);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 Us.getBaseFileContent(e).map(function(n){return n.type===qt?n:_defineProperty(_defineProperty({detail:"auto"},T,Nr),Ne,n[A]);});}},{key:"getContent",value:function getContent(e){if(e.role===U&&e[y]&&e[y].length>0){var _n9=Ge.getFileContent(e[y]);return e[h]&&e[h].trim().length>0&&_n9.unshift(_defineProperty(_defineProperty({},T,Ai),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===Hi;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},A,"".concat(Ge.IMAGE_BASE64_PREFIX).concat(e)),T,j)];}}]);}(Us);Ge.IMAGE_BASE64_PREFIX="data:image/png;base64,";var js=Ge;var Zi=/*#__PURE__*/function(_js){function Zi(e){var _this64;_classCallCheck(this,Zi);var o,a,c,l,d,p,u;var t=JSON.parse(JSON.stringify(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,Zi,[e,Oo(s),ko,n,r]),_this64.permittedErrorPrefixes=[Ds],_this64.isTextInputDisabled=!1,_typeof(r)===B){var _ref131=(u=(p=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:p.openAI)==null?void 0:u.chat,g=_ref131.function_handler;g&&(_this64.functionHandler=g);}No(s)?_this64.url=Zi.buildURL(s):(_this64.isTextInputDisabled=!0,_this64.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,Ds));}));return _this64;}_inherits(Zi,_js);return _createClass(Zi,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(_R15){function qs(e){var _this65$maxMessages,_l$model2;var _this65;_classCallCheck(this,qs);var r,o,a,c,l;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.bigModel;_this65=_callSuper(this,qs,[e,Vi(),zi,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=[ae,be];var s=(r=t.bigModel)==null?void 0:r.chat;_typeof(s)===B&&_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,_R15);return _createClass(qs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:qs.getTextWFilesContent(r,qs.getFileContent),role:R.getRoleViaAI(r.role)};});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].role)===J&&((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===j?_defineProperty(_defineProperty({},T,Ne),Ne,{url:t[A]||""}):_defineProperty(_defineProperty({},T,Q),"file_url",{url:t[A]||""});});}}]);}(R);var $l=/*#__PURE__*/function(_R16){function $l(e){var _this66$maxMessages,_o$model8;var _this66;_classCallCheck(this,$l);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.together;_this66=_callSuper(this,$l,[e,Ki(),Ji,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=[Ke,be];var s=(r=t.together)==null?void 0:r.chat;_typeof(s)===B&&_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($l,_R16);return _createClass($l,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:r.role===J?bt:r.role};});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;}()}]);}(R);var Xe=/*#__PURE__*/function(_R17){function Xe(e){var _this67;_classCallCheck(this,Xe);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},y,{acceptedFormats:".png",maxNumberOfFiles:2})};_this67=_callSuper(this,Xe,[e,_n(),vn,n,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenAI"),_this67.keyHelpUrl=bn,_this67.url="",_this67.permittedErrorPrefixes=[ps,"Invalid input image"];var r=(o=t==null?void 0:t.openAI)==null?void 0:o[V];if(_this67[Re]){var a=_typeof(r)=="object"&&r.size?Number.parseInt(r.size):1024;_this67[Re][y]={dimensions:{width:a,height:a}};}_typeof(r)===B&&Object.assign(_this67.rawBody,r),_this67.canSendMessage=Xe.canFileSendMessage;return _this67;}_inherits(Xe,_R17);return _createClass(Xe,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e));return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
192
192
  },{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=Xe.IMAGE_EDIT_URL;var c=this.preprocessBody(this.rawBody,r);s=Xe.createFormDataBody(c,n[0],n[1]);}else this.url=Xe.IMAGE_VARIATIONS_URL,s=Xe.createFormDataBody(this.rawBody,n[0]);L.tempRemoveContentHeader(this.connectSettings,ie.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(Ie);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(Ie);case 3:this.url=Xe.IMAGE_GENERATION_URL;r=this.preprocessBody(this.rawBody,t[t.length-1][h]);ie.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({},A,n.url),T,j):_defineProperty(_defineProperty({},A,"".concat(yn).concat(n.b64_json)),T,j);});return _context138.a(2,_defineProperty({},y,t));}},_callee138);}));function extractResultData(_x258){return _extractResultData27.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
193
193
  // 1 image:
194
194
  // - With text - edits image based on the text
@@ -198,21 +198,21 @@ function Ge(e,t,n,s,r){var _this62;_classCallCheck(this,Ge);var a,c;_this62=_cal
198
198
  // Add text to describe the required modification.
199
199
  // Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
200
200
  // `;
201
- }],[{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(j,t),n&&s.append("mask",n),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s;}}]);}(R);Xe.IMAGE_GENERATION_URL="".concat(Pe,"images/generations"),Xe.IMAGE_VARIATIONS_URL="".concat(Pe,"images/variations"),Xe.IMAGE_EDIT_URL="".concat(Pe,"images/edits");var Ni=Xe;var Gl=function Gl(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},zl=function zl(i,e,t,n){var s=i;s[f]?s[f].type===be?n(re):n(He):t(e);},Vl=function Vl(){return de("https://openrouter.ai/api/v1/key",ae,zl);};var Xn=/*#__PURE__*/function(_R18){function Xn(e){var _this68$maxMessages,_o$model9,_a$max_tokens;var _this68;_classCallCheck(this,Xn);var s,r,o,a;var n=JSON.parse(JSON.stringify(e.directConnection)).openRouter;_this68=_callSuper(this,Xn,[e,Vl(),Gl,n]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("OpenRouter"),_this68.keyHelpUrl="https://openrouter.ai/keys",_this68.url="https://openrouter.ai/api/v1/chat/completions",_this68.permittedErrorPrefixes=[Ke,be],_typeof(n)===B&&_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(Xn,_R18);return _createClass(Xn,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(o){return{content:Xn.getContent(o),role:R.getRoleViaUser(o.role)};}),r=[];return this.systemMessage&&r.push({role:"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,_c4;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[V])){_context140.n=3;break;}c=e.message[V].map(function(l){return _defineProperty({},A,l[Ne].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:_c4=((o=_a5.message[V])==null?void 0:o.map(function(l){return _defineProperty({},A,l[Ne].url);}))||[];return _context140.a(2,_defineProperty(_defineProperty({},h,_a5.message.content||""),"files",_c4));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[V])){_context141.n=1;break;}s=n[V].map(function(r){return _defineProperty({},A,r[Ne].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===P;}).map(function(t){var r,o,a;var n=(r=t[A])==null?void 0:r.split(",")[1],s=(a=(o=t[A])==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return _defineProperty(_defineProperty({},T,qt),qt,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[qt].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[y]&&e[y].length>0){var t=[].concat(_toConsumableArray(Xn.getImageContent(e[y])),_toConsumableArray(Xn.getAudioContent(e[y])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},T,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(R);var Jl=function Jl(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},Kl=function Kl(i,e,t,n){i[f]?n(re):t(e);},Wl=function Wl(){return de("https://api.perplexity.ai/chat/completions",le,Kl);};var Xl=/*#__PURE__*/function(_R19){function Xl(e){var _this69$maxMessages,_s$model;var _this69;_classCallCheck(this,Xl);var s;var n=JSON.parse(JSON.stringify(e.directConnection)).perplexity;_this69=_callSuper(this,Xl,[e,Wl(),Jl,n]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Perplexity"),_this69.keyHelpUrl="https://www.perplexity.ai/settings/api",_this69.url="https://api.perplexity.ai/chat/completions",_this69.permittedErrorPrefixes=[kt,yo,"Permission denied"],_typeof(n)===B&&_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(Xl,_R19);return _createClass(Xl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:R.getRoleViaUser(r.role)};});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;}()}]);}(R);var Zl=function Zl(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},Yl=function Yl(i,e,t,n){var s=i;s[f]?s[f].type===be?n(re):n(He):t(e);},Ql=function Ql(){return de("https://api.deepseek.com/models",ae,Yl);};var ed=/*#__PURE__*/function(_R20){function ed(e){var _this70$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this70;_classCallCheck(this,ed);var s,r,o;var n=JSON.parse(JSON.stringify(e.directConnection)).deepSeek;_this70=_callSuper(this,ed,[e,Ql(),Zl,n]),_this70.insertKeyPlaceholderText=_this70.genereteAPIKeyName("DeepSeek"),_this70.keyHelpUrl="https://platform.deepseek.com/api_keys",_this70.url="https://api.deepseek.com/v1/chat/completions",_this70.permittedErrorPrefixes=[Ke,be],_typeof(n)===B&&_this70.completeConfig(n),(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_s$model2=(s=_this70.rawBody).model)!==null&&_s$model2!==void 0?_s$model2:s.model="deepseek-chat",(_r$temperature=(r=_this70.rawBody).temperature)!==null&&_r$temperature!==void 0?_r$temperature:r.temperature=1,(_o$max_tokens=(o=_this70.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this70;}_inherits(ed,_R20);return _createClass(ed,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});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){var t;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.choices&&e.choices.length>0)){_context145.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context145.n=2;break;}return _context145.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context145.n=3;break;}return _context145.a(2,_defineProperty({},h,t.message.content));case 3:return _context145.a(2,_defineProperty({},h,""));}},_callee145);}));function extractResultData(_x270){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(R);var td=function td(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},nd=function nd(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(re):t(e);},sd=function sd(){return de("https://api.minimax.io/v1/files/delete",le,nd);};var id=/*#__PURE__*/function(_R21){function id(e){var _this71$maxMessages,_s$model3;var _this71;_classCallCheck(this,id);var s;var n=JSON.parse(JSON.stringify(e.directConnection)).miniMax;_this71=_callSuper(this,id,[e,sd(),td,n]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("MiniMax"),_this71.keyHelpUrl="https://www.minimaxi.com",_this71.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this71.permittedErrorPrefixes=[Ke,be,"insufficient balance"],_typeof(n)===B&&_this71.completeConfig(n),(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_s$model3=(s=_this71.rawBody).model)!==null&&_s$model3!==void 0?_s$model3:s.model="MiniMax-M1";return _this71;}_inherits(id,_R21);return _createClass(id,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){return _regenerator().w(function(_context146){while(1)switch(_context146.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context146.a(2);}},_callee146,this);}));function callServiceAPI(_x271,_x272){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e){var t,_n1;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(!e[f]){_context147.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context147.n=3;break;}_n1=e.choices[0];if(!(_n1.delta&&_n1.delta.content)){_context147.n=2;break;}return _context147.a(2,_defineProperty({},h,_n1.delta.content));case 2:if(!(_n1.message&&_n1.message.content)){_context147.n=3;break;}return _context147.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)){_context147.n=4;break;}throw e.base_resp.status_msg;case 4:return _context147.a(2,_defineProperty({},h,""));}},_callee147);}));function extractResultData(_x273){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(R);var rd=function rd(i){return _defineProperty(_defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K),"accept",K);},od=function od(i,e,t,n){i.detail?n(re):t(e);},ad=function ad(){return de("https://api.mistral.ai/v1/models",ae,od);};var Yi=/*#__PURE__*/function(_R22){function Yi(e){var _this72$maxMessages,_o$model0;var _this72;_classCallCheck(this,Yi);var s,r,o;var n=JSON.parse(JSON.stringify(e.directConnection)).mistral;_this72=_callSuper(this,Yi,[e,ad(),rd,n]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("Mistral"),_this72.keyHelpUrl="https://console.mistral.ai/api-keys/",_this72.url="https://api.mistral.ai/v1/chat/completions",_this72.permittedErrorPrefixes=[kt],_typeof(n)===B&&_this72.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.mistral)==null?void 0:r.function_handler),(_this72$maxMessages=_this72.maxMessages)!==null&&_this72$maxMessages!==void 0?_this72$maxMessages:_this72.maxMessages=-1,(_o$model0=(o=_this72.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="mistral-small-latest";return _this72;}_inherits(Yi,_R22);return _createClass(Yi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{role:R.getRoleViaAI(r.role),content:R.getTextWFilesContent(r,Yi.getFileContent)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e,t){var _this$messages5;return _regenerator().w(function(_context148){while(1)switch(_context148.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),{});case 1:return _context148.a(2);}},_callee148,this);}));function callServiceAPI(_x274,_x275){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e,t){var _n10;return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:if(!e.message){_context149.n=1;break;}throw e.message;case 1:if(!e[f]){_context149.n=2;break;}throw e[f].message;case 2:if(!(e.choices&&e.choices.length>0)){_context149.n=4;break;}_n10=e.choices[0];if(!_n10.delta){_context149.n=3;break;}return _context149.a(2,this.extractStreamResult(_n10,t));case 3:if(!_n10.message){_context149.n=4;break;}return _context149.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 _context149.a(2,_defineProperty({},h,""));}},_callee149,this);}));function extractResultData(_x276,_x277){return _extractResultData32.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){var n,s,r;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:n=e.delta,s=e.finish_reason;if(!(s==="tool_calls"&&n!=null&&n.tool_calls)){_context150.n=1;break;}r={tool_calls:n.tool_calls};return _context150.a(2,this.handleToolsGeneric(r,this.functionHandler,this.messages,t));case 1:return _context150.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee150,this);}));function extractStreamResult(_x278,_x279){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t.type===j?_defineProperty(_defineProperty({},T,Ne),Ne,t[A]||""):_defineProperty(_defineProperty({},T,h),h,"[Unsupported ".concat(Q," type: ").concat(t.type,"]"));});}}]);}(R);var Qi=/*#__PURE__*/function(_R23){function Qi(e){var _this73$maxMessages,_l$model3;var _this73;_classCallCheck(this,Qi);var r,o,a,c,l;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.groq;_this73=_callSuper(this,Qi,[e,Uo(),Fo,n]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("Groq"),_this73.keyHelpUrl="https://console.groq.com/keys",_this73.url="https://api.groq.com/openai/v1/chat/completions",_this73.permittedErrorPrefixes=[kt,"property"];var s=(r=t.groq)==null?void 0:r.chat;_typeof(s)===B&&_this73.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.groq)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this73$maxMessages=_this73.maxMessages)!==null&&_this73$maxMessages!==void 0?_this73$maxMessages:_this73.maxMessages=-1,(_l$model3=(l=_this73.rawBody).model)!==null&&_l$model3!==void 0?_l$model3:l.model="llama-3.3-70b-versatile";return _this73;}_inherits(Qi,_R23);return _createClass(Qi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:Qi.getTextWImagesContent(r),role:r.role===J?bt:r.role};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e,t){var _this$messages6;return _regenerator().w(function(_context151){while(1)switch(_context151.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 _context151.a(2);}},_callee151,this);}));function callServiceAPI(_x280,_x281){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e,t){var n,s,r,o;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:if(!e[f]){_context152.n=1;break;}throw e[f].message;case 1:return _context152.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,""));}},_callee152,this);}));function extractResultData(_x282,_x283){return _extractResultData33.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
202
- },{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:return _context153.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee153,this);}));function extractStreamResult(_x284,_x285){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(R);var cd=function cd(i){return _defineProperty(_defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K),"accept",K);},ld=function ld(i,e,t,n){typeof i.message=="string"?n(re):t(e);},dd=function dd(){return de("https://api.cohere.ai/v1/models",ae,ld);};var $s=/*#__PURE__*/function(_R24){function $s(e){var _this74$maxMessages,_s$model4;var _this74;_classCallCheck(this,$s);var s;var n=JSON.parse(JSON.stringify(e.directConnection)).cohere;if(_this74=_callSuper(this,$s,[e,dd(),cd,n]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Cohere"),_this74.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this74.permittedErrorPrefixes=["invalid"],_this74.url="https://api.cohere.com/v2/chat",_typeof(n)===B){var r=te.processCohere(n);_this74.canSendMessage=function(){return r;},_this74.cleanConfig(n),Object.assign(_this74.rawBody,n);}(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_s$model4=(s=_this74.rawBody).model)!==null&&_s$model4!==void 0?_s$model4:s.model="command-a-03-2025";return _this74;}_inherits($s,_R24);return _createClass($s,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=t.filter(function(r){return r[h];});return n.messages=s.map(function(r){return{role:R.getRoleViaAI(r.role),content:r[h]};}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context154.a(2);}},_callee154,this);}));function callServiceAPI(_x286,_x287){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e){var t,n,s,r;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:if(!(typeof e.message=="string")){_context155.n=1;break;}throw e.message;case 1:if(!(this.stream&&e[h])){_context155.n=2;break;}r=$s.parseBundledEvents(e[h]);return _context155.a(2,{text:$s.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])){_context155.n=3;break;}return _context155.a(2,_defineProperty({},h,e.message.content[0][h]));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context155.a(2);}},_callee155,this);}));function extractResultData(_x288){return _extractResultData34.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),n=[];var _iterator4=_createForOfIteratorHelper(t),_step4;try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){var s=_step4.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){_iterator4.e(err);}finally{_iterator4.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("");}}]);}(R);var hd=function hd(){return _defineProperty({},D,K);},ud=function ud(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(re):n(He):t(e);},pd=function pd(){var i="https://generativelanguage.googleapis.com/v1beta/models?key=";return de(i,ae,ud,function(e){return"".concat(i).concat(e);});};var er=/*#__PURE__*/function(_R25){function er(e){var _this75$maxMessages;var _this75;_classCallCheck(this,er);var s,r;var n=JSON.parse(JSON.stringify(e.directConnection)).gemini;_this75=_callSuper(this,er,[e,pd(),hd,n]),_this75.insertKeyPlaceholderText=_this75.genereteAPIKeyName("Gemini"),_this75.keyHelpUrl="https://aistudio.google.com/app/apikey",_this75.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent",_this75.url="",_this75.permittedErrorPrefixes=["API_KEY_INVALID"],_typeof(n)===B&&(n.model&&(_this75.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(n.model,":generateContent")),_this75.cleanConfig(n),_this75.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.gemini)==null?void 0:r.function_handler)),(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1;return _this75;}_inherits(er,_R25);return _createClass(er,[{key:"cleanConfig",value:function cleanConfig(e){delete e.model;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return er.getContent(r);});return n.contents=s,this.systemMessage&&(n.systemInstruction={parts:[_defineProperty({},h,this.systemMessage)]}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var _this$messages7;var n,s;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(this.connectSettings){_context156.n=1;break;}throw new Error(Ie);case 1:(_this$messages7=this.messages)!==null&&_this$messages7!==void 0?_this$messages7:this.messages=e;n=this.preprocessBody(this.rawBody,t),s=this.stream;s&&(_typeof(s)!==B||!s.simulation)||n.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),F.request(this,n,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),ie.request(this,n,e));case 2:return _context156.a(2);}},_callee156,this);}));function callServiceAPI(_x289,_x290){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()// https://ai.google.dev/gemini-api/docs/function-calling?example=weather
203
- },{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(!e[f]){_context157.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)){_context157.n=3;break;}a=e.candidates[0].content.parts,c=a.find(function(p){return p.functionCall;});if(!(c!=null&&c.functionCall)){_context157.n=2;break;}return _context157.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 _context157.a(2,_defineProperty(_defineProperty({},h,(l==null?void 0:l[h])||""),y,(o=d==null?void 0:d.inlineData)!=null&&o.data?[_defineProperty({},A,"data:image/png;base64,".concat(d.inlineData.data))]:[]));case 3:return _context157.a(2,_defineProperty({},h,""));}},_callee157,this);}));function extractResultData(_x291,_x292){return _extractResultData35.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){var n,s,_yield$this$callToolF3,r,o,a,c;return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:if(!(!e||!t||!this.functionHandler)){_context158.n=1;break;}throw Error(Wt);case 1:n=JSON.parse(JSON.stringify(t));s=e.map(function(c){return{name:c.name,arguments:JSON.stringify(c.args)};});_context158.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF3=_context158.v;r=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context158.n=3;break;}return _context158.a(2,o);case 3:a={parts:e.map(function(c){return{functionCall:{name:c.name,args:c.args}};}),role:"model"};if(!(n.contents.push(a),!r.find(function(_ref181){var c=_ref181.response;return typeof c!="string";})&&s.length===r.length)){_context158.n=4;break;}c={parts:r.map(function(l,d){return{functionResponse:{name:e[d].name,response:{result:l.response}}};}),role:U};return _context158.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(un);case 5:return _context158.a(2);}},_callee158,this);}));function handleTools(_x293,_x294){return _handleTools2.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[A]&&n[A].includes("data:")){var _n$A$split=n[A].split(","),_n$A$split2=_slicedToArray(_n$A$split,2),s=_n$A$split2[0],r=_n$A$split2[1];t.push({inlineData:{mimeType:s.replace("data:","").replace(";base64",""),data:r}});}}),{parts:t,role:e.role===U?U:"model"};}}]);}(R);var fd=function fd(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},D,K),"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===be?n(re):n(He):t(e);},gd=function gd(){return de("https://api.anthropic.com/v1/models",ae,md);};var Gs=/*#__PURE__*/function(_R26){function Gs(e){var _this76$maxMessages,_o$model1,_a$max_tokens2;var _this76;_classCallCheck(this,Gs);var s,r,o,a;var n=JSON.parse(JSON.stringify(e.directConnection)).claude;_this76=_callSuper(this,Gs,[e,gd(),fd,n]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("Claude"),_this76.keyHelpUrl="https://console.anthropic.com/settings/keys",_this76.url="https://api.anthropic.com/v1/messages",_this76.permittedErrorPrefixes=[be,Ke],_this76._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},T,"tool_use"),"id",""),"name",""),"input",""),_typeof(n)===B&&_this76.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.claude)==null?void 0:r.function_handler),(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1,(_o$model1=(o=_this76.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="claude-sonnet-4-5-20250929",(_a$max_tokens2=(a=_this76.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this76;}_inherits(Gs,_R26);return _createClass(Gs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:Gs.getTextWFilesContent(r,Gs.getFileContent),role:R.getRoleViaUser(r.role)};});return n.messages=s,this.systemMessage&&(n.system=this.systemMessage),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e,t){var _this$messages8;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:(_this$messages8=this.messages)!==null&&_this$messages8!==void 0?_this$messages8:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context159.a(2);}},_callee159,this);}));function callServiceAPI(_x295,_x296){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e,t){var n,s,r,o,a;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if(!e[f]){_context160.n=1;break;}throw e[f].message;case 1:if(!(e.content&&e.content.length>0)){_context160.n=3;break;}o=e.content.find(function(c){return c.type==="tool_use";});if(!o){_context160.n=2;break;}return _context160.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(c){return c.type===h;});if(!a){_context160.n=3;break;}return _context160.a(2,_defineProperty({},h,a[h]));case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context160.n=4;break;}return _context160.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")){_context160.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context160.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((s=e.delta)==null?void 0:s.type)==="input_json_delta")){_context160.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context160.n=7;break;case 6:if(!(e.type==="message_delta"&&((r=e.delta)==null?void 0:r.stop_reason)==="tool_use")){_context160.n=7;break;}return _context160.a(2,(this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t)));case 7:return _context160.a(2,_defineProperty({},h,""));}},_callee160,this);}));function extractResultData(_x297,_x298){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var n,s,_yield$this$callToolF4,r,o,a,c;return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(!(!e||!t||!this.functionHandler)){_context161.n=1;break;}throw Error(Wt);case 1:n=JSON.parse(JSON.stringify(t));s=e.map(function(c){return{name:c.name,arguments:JSON.stringify(c.input)};});_context161.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF4=_context161.v;r=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context161.n=3;break;}return _context161.a(2,o);case 3:a=e.map(function(c){return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},T,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push({role:"assistant",content:a}),!r.find(function(_ref187){var c=_ref187.response;return typeof c!="string";})&&s.length===r.length)){_context161.n=4;break;}c=r.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},T,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context161.a(2,(n.messages.push({role:U,content:c}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(un);case 5:return _context161.a(2);}},_callee161,this);}));function handleTools(_x299,_x300){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var n,s,r;if(t.type===j){var o=(n=t[A])==null?void 0:n.split(",")[1],a=((r=(s=t[A])==null?void 0:s.match(/data:([^;]+)/))==null?void 0:r[1])||"image/jpeg";return _defineProperty(_defineProperty({},T,j),"source",_defineProperty(_defineProperty(_defineProperty({},T,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},T,h),h,"[Unsupported ".concat(Q," type: ").concat(t.type,"]"));});}}]);}(R);var yd=function yd(){return{};},bd=function bd(){},vd=function vd(){return de("",ae,bd);};var tr=/*#__PURE__*/function(_R27){function tr(e){var _this77$maxMessages,_o$model10,_a$stream;var _this77;_classCallCheck(this,tr);var s,r,o,a;var t=JSON.parse(JSON.stringify(e.directConnection));_this77=_callSuper(this,tr,[e,vd(),yd,{key:"placeholder"}]),_this77.insertKeyPlaceholderText="",_this77.keyHelpUrl="",_this77.validateKeyProperty=!1,_this77.url="http://localhost:11434/api/chat",_this77.permittedErrorPrefixes=["Error"];var n=t.ollama;_typeof(n)===B&&_this77.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.ollama)==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="llama3.2",(_a$stream=(a=_this77.rawBody).stream)!==null&&_a$stream!==void 0?_a$stream:a.stream=!1;return _this77;}_inherits(tr,_R27);return _createClass(tr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){var o={content:r[h]||"",role:R.getRoleViaUser(r.role)};if(r[y]&&r[y].length>0){var a=tr.getImageData(r[y]);a.length>0&&(o[V]=a);}return o;});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){var _this$messages9;return _regenerator().w(function(_context162){while(1)switch(_context162.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),{readable:!0});case 1:return _context162.a(2);}},_callee162,this);}));function callServiceAPI(_x301,_x302){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee163(e,t){var n,s,r;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:if(!e[f]){_context163.n=1;break;}throw e[f].message;case 1:if(!e[h]){_context163.n=2;break;}r=JSON.parse(e[h]);return _context163.a(2,(n=r.message)!=null&&n.tool_calls?this.handleTools({tool_calls:r.message.tool_calls},t):_defineProperty({},h,((s=r.message)==null?void 0:s.content)||""));case 2:return _context163.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},h,e.message.content||""):_defineProperty({},h,""));}},_callee163,this);}));function extractResultData(_x303,_x304){return _extractResultData37.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var n,s,_yield$this$callToolF5,r,o;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context164.n=1;break;}throw Error(Wt);case 1:n=JSON.parse(JSON.stringify(t));s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:JSON.stringify(a["function"].arguments)};});_context164.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF5=_context164.v;r=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context164.n=3;break;}return _context164.a(2,o);case 3:if(!(n.messages.push({tool_calls:e.tool_calls,role:bt,content:""}),!r.find(function(_ref194){var a=_ref194.response;return typeof a!="string";})&&s.length===r.length)){_context164.n=4;break;}return _context164.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({role:"tool",tool_name:l==null?void 0:l["function"].name,content:a.response});}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(un);case 5:return _context164.a(2);}},_callee164,this);}));function handleTools(_x305,_x306){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t.type===j;}).map(function(t){var s;return((s=t[A])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(R);var Ho=function Ho(i){return _defineProperty({Authorization:"".concat(ye).concat(i)},D,K);},_d=function _d(i,e,t,n){var s=i;s[f]?s[f].type===be||s[f].type===Ke?n(re):n(He):t(e);},jo=function jo(){return de("https://api.x.ai/v1/models",ae,_d);},Zs=/*#__PURE__*/function(_R28){function Zs(e){var _o$model11;var _this78;_classCallCheck(this,Zs);var r,o;var t=e.directConnection,n=t==null?void 0:t.x;_this78=_callSuper(this,Zs,[e,jo(),Ho,n]),_this78.insertKeyPlaceholderText=_this78.genereteAPIKeyName("X"),_this78.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this78.url=Zs.IMAGE_GENERATION_URL,_this78.permittedErrorPrefixes=[Ke,be];var s=(r=t==null?void 0:t.x)==null?void 0:r[V];_typeof(s)===B&&Object.assign(_this78.rawBody,s),(_o$model11=(o=_this78.rawBody).model)!==null&&_o$model11!==void 0?_o$model11:o.model="grok-2-image";return _this78;}_inherits(Zs,_R28);return _createClass(Zs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=JSON.parse(JSON.stringify(e));return n&&n!==""&&(s.prompt=n),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context165.a(2);}},_callee165,this);}));function callServiceAPI(_x307,_x308){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee166(e){var t;return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:if(!e[f]){_context166.n=1;break;}throw e[f].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},A,n.url),T,j):_defineProperty(_defineProperty({},A,"".concat(yn).concat(n.b64_json)),T,j);});return _context166.a(2,_defineProperty({},y,t));}},_callee166);}));function extractResultData(_x309){return _extractResultData38.apply(this,arguments);}return extractResultData;}()}]);}(R);Zs.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Li=Zs;var Ed=function Ed(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},Sd=function Sd(i,e,t,n){var s=i;s[f]?s[f].type===Ke?n(re):n(He):t(e);},xd=function xd(){return de("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",ae,Sd);};var nr=/*#__PURE__*/function(_R29){function nr(e){var _this79$maxMessages,_o$model12;var _this79;_classCallCheck(this,nr);var s,r,o;var n=JSON.parse(JSON.stringify(e.directConnection)).qwen;_this79=_callSuper(this,nr,[e,xd(),Ed,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("Qwen"),_this79.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this79.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this79.permittedErrorPrefixes=["No static","The model",ps],_typeof(n)===B&&_this79.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.qwen)==null?void 0:r.function_handler),(_this79$maxMessages=_this79.maxMessages)!==null&&_this79$maxMessages!==void 0?_this79$maxMessages:_this79.maxMessages=-1,(_o$model12=(o=_this79.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="qwen-plus";return _this79;}_inherits(nr,_R29);return _createClass(nr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:nr.getTextWImagesContent(r),role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e,t){var _this$messages0;return _regenerator().w(function(_context167){while(1)switch(_context167.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),{});case 1:return _context167.a(2);}},_callee167,this);}));function callServiceAPI(_x310,_x311){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){var _n11;return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:if(!e[f]){_context168.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context168.n=3;break;}_n11=e.choices[0];if(!_n11.delta){_context168.n=2;break;}return _context168.a(2,this.extractStreamResult(_n11,t));case 2:if(!_n11.message){_context168.n=3;break;}return _context168.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 _context168.a(2,_defineProperty({},h,""));}},_callee168,this);}));function extractResultData(_x312,_x313){return _extractResultData39.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e,t){return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:return _context169.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee169,this);}));function extractStreamResult(_x314,_x315){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()}]);}(R);var Ad=function Ad(i){return _defineProperty(_defineProperty({},oe,"".concat(ye).concat(i)),D,K);},wd=function wd(i,e,t,n){var s=i;s[f]?s[f].type===be?n(re):n(He):t(e);},Cd=function Cd(){return de("https://api.moonshot.ai/v1/models",ae,wd);};var sr=/*#__PURE__*/function(_R30){function sr(e){var _this80$maxMessages,_o$model13;var _this80;_classCallCheck(this,sr);var s,r,o;var n=JSON.parse(JSON.stringify(e.directConnection)).kimi;_this80=_callSuper(this,sr,[e,Cd(),Ad,n]),_this80.insertKeyPlaceholderText=_this80.genereteAPIKeyName("Kimi"),_this80.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this80.url="https://api.moonshot.ai/v1/chat/completions",_this80.permittedErrorPrefixes=[kt,"Not found"],_typeof(n)===B&&_this80.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.kimi)==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="moonshot-v1-8k";return _this80;}_inherits(sr,_R30);return _createClass(sr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:sr.getTextWImagesContent(r),role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e,t){var _this$messages1;return _regenerator().w(function(_context170){while(1)switch(_context170.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 _context170.a(2);}},_callee170,this);}));function callServiceAPI(_x316,_x317){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(e,t){var _n12;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:if(!e[f]){_context171.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context171.n=3;break;}_n12=e.choices[0];if(!_n12.delta){_context171.n=2;break;}return _context171.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context171.n=3;break;}return _context171.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 _context171.a(2,_defineProperty({},h,""));}},_callee171,this);}));function extractResultData(_x318,_x319){return _extractResultData40.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee172(e,t){return _regenerator().w(function(_context172){while(1)switch(_context172.n){case 0:return _context172.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee172,this);}));function extractStreamResult(_x320,_x321){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()}]);}(R);var Td=/*#__PURE__*/function(_R31){function Td(e){var _this81$maxMessages,_o$model14;var _this81;_classCallCheck(this,Td);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.x;_this81=_callSuper(this,Td,[e,jo(),Ho,n]),_this81.insertKeyPlaceholderText=_this81.genereteAPIKeyName("X"),_this81.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this81.url="https://api.x.ai/v1/chat/completions",_this81.permittedErrorPrefixes=[Ke,be];var s=(r=t.x)==null?void 0:r.chat;_typeof(s)===B&&_this81.completeConfig(s),(_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="grok-3-latest";return _this81;}_inherits(Td,_R31);return _createClass(Td,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e,t){return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context173.a(2);}},_callee173,this);}));function callServiceAPI(_x322,_x323){return _callServiceAPI38.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(e){var t,n,s,r,o;return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:if(!e[f]){_context174.n=1;break;}throw e[f].message;case 1:if(!(e.object==="chat.completion.chunk")){_context174.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context174.a(2,(n=o==null?void 0:o.delta)!=null&&n.content?_defineProperty({},h,o.delta.content):_defineProperty({},h,""));case 2:return _context174.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,""));}},_callee174);}));function extractResultData(_x324){return _extractResultData41.apply(this,arguments);}return extractResultData;}()}]);}(R);var Rd=/*#__PURE__*/function(){function Rd(){_classCallCheck(this,Rd);}return _createClass(Rd,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
201
+ }],[{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(j,t),n&&s.append("mask",n),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s;}}]);}(R);Xe.IMAGE_GENERATION_URL="".concat(Pe,"images/generations"),Xe.IMAGE_VARIATIONS_URL="".concat(Pe,"images/variations"),Xe.IMAGE_EDIT_URL="".concat(Pe,"images/edits");var Ni=Xe;var Gl=function Gl(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},zl=function zl(i,e,t,n){var s=i;s[f]?s[f].type===be?n(re):n(He):t(e);},Vl=function Vl(){return de("https://openrouter.ai/api/v1/key",ce,zl);};var Xn=/*#__PURE__*/function(_R18){function Xn(e){var _this68$maxMessages,_o$model9,_a$max_tokens;var _this68;_classCallCheck(this,Xn);var s,r,o,a;var n=JSON.parse(JSON.stringify(e.directConnection)).openRouter;_this68=_callSuper(this,Xn,[e,Vl(),Gl,n]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("OpenRouter"),_this68.keyHelpUrl="https://openrouter.ai/keys",_this68.url="https://openrouter.ai/api/v1/chat/completions",_this68.permittedErrorPrefixes=[Ke,be],_typeof(n)===B&&_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(Xn,_R18);return _createClass(Xn,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(o){return{content:Xn.getContent(o),role:R.getRoleViaUser(o.role)};}),r=[];return this.systemMessage&&r.push({role:"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,_c4;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[V])){_context140.n=3;break;}c=e.message[V].map(function(l){return _defineProperty({},A,l[Ne].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:_c4=((o=_a5.message[V])==null?void 0:o.map(function(l){return _defineProperty({},A,l[Ne].url);}))||[];return _context140.a(2,_defineProperty(_defineProperty({},h,_a5.message.content||""),"files",_c4));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[V])){_context141.n=1;break;}s=n[V].map(function(r){return _defineProperty({},A,r[Ne].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===P;}).map(function(t){var r,o,a;var n=(r=t[A])==null?void 0:r.split(",")[1],s=(a=(o=t[A])==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return _defineProperty(_defineProperty({},T,qt),qt,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[qt].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[y]&&e[y].length>0){var t=[].concat(_toConsumableArray(Xn.getImageContent(e[y])),_toConsumableArray(Xn.getAudioContent(e[y])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},T,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(R);var Jl=function Jl(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},Kl=function Kl(i,e,t,n){i[f]?n(re):t(e);},Wl=function Wl(){return de("https://api.perplexity.ai/chat/completions",le,Kl);};var Xl=/*#__PURE__*/function(_R19){function Xl(e){var _this69$maxMessages,_s$model;var _this69;_classCallCheck(this,Xl);var s;var n=JSON.parse(JSON.stringify(e.directConnection)).perplexity;_this69=_callSuper(this,Xl,[e,Wl(),Jl,n]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Perplexity"),_this69.keyHelpUrl="https://www.perplexity.ai/settings/api",_this69.url="https://api.perplexity.ai/chat/completions",_this69.permittedErrorPrefixes=[kt,yo,"Permission denied"],_typeof(n)===B&&_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(Xl,_R19);return _createClass(Xl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:R.getRoleViaUser(r.role)};});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;}()}]);}(R);var Zl=function Zl(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},Yl=function Yl(i,e,t,n){var s=i;s[f]?s[f].type===be?n(re):n(He):t(e);},Ql=function Ql(){return de("https://api.deepseek.com/models",ce,Yl);};var ed=/*#__PURE__*/function(_R20){function ed(e){var _this70$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this70;_classCallCheck(this,ed);var s,r,o;var n=JSON.parse(JSON.stringify(e.directConnection)).deepSeek;_this70=_callSuper(this,ed,[e,Ql(),Zl,n]),_this70.insertKeyPlaceholderText=_this70.genereteAPIKeyName("DeepSeek"),_this70.keyHelpUrl="https://platform.deepseek.com/api_keys",_this70.url="https://api.deepseek.com/v1/chat/completions",_this70.permittedErrorPrefixes=[Ke,be],_typeof(n)===B&&_this70.completeConfig(n),(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_s$model2=(s=_this70.rawBody).model)!==null&&_s$model2!==void 0?_s$model2:s.model="deepseek-chat",(_r$temperature=(r=_this70.rawBody).temperature)!==null&&_r$temperature!==void 0?_r$temperature:r.temperature=1,(_o$max_tokens=(o=_this70.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this70;}_inherits(ed,_R20);return _createClass(ed,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});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){var t;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.choices&&e.choices.length>0)){_context145.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context145.n=2;break;}return _context145.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context145.n=3;break;}return _context145.a(2,_defineProperty({},h,t.message.content));case 3:return _context145.a(2,_defineProperty({},h,""));}},_callee145);}));function extractResultData(_x270){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(R);var td=function td(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},nd=function nd(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(re):t(e);},sd=function sd(){return de("https://api.minimax.io/v1/files/delete",le,nd);};var id=/*#__PURE__*/function(_R21){function id(e){var _this71$maxMessages,_s$model3;var _this71;_classCallCheck(this,id);var s;var n=JSON.parse(JSON.stringify(e.directConnection)).miniMax;_this71=_callSuper(this,id,[e,sd(),td,n]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("MiniMax"),_this71.keyHelpUrl="https://www.minimaxi.com",_this71.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this71.permittedErrorPrefixes=[Ke,be,"insufficient balance"],_typeof(n)===B&&_this71.completeConfig(n),(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_s$model3=(s=_this71.rawBody).model)!==null&&_s$model3!==void 0?_s$model3:s.model="MiniMax-M1";return _this71;}_inherits(id,_R21);return _createClass(id,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){return _regenerator().w(function(_context146){while(1)switch(_context146.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context146.a(2);}},_callee146,this);}));function callServiceAPI(_x271,_x272){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e){var t,_n1;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(!e[f]){_context147.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context147.n=3;break;}_n1=e.choices[0];if(!(_n1.delta&&_n1.delta.content)){_context147.n=2;break;}return _context147.a(2,_defineProperty({},h,_n1.delta.content));case 2:if(!(_n1.message&&_n1.message.content)){_context147.n=3;break;}return _context147.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)){_context147.n=4;break;}throw e.base_resp.status_msg;case 4:return _context147.a(2,_defineProperty({},h,""));}},_callee147);}));function extractResultData(_x273){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(R);var rd=function rd(i){return _defineProperty(_defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K),"accept",K);},od=function od(i,e,t,n){i.detail?n(re):t(e);},ad=function ad(){return de("https://api.mistral.ai/v1/models",ce,od);};var Yi=/*#__PURE__*/function(_R22){function Yi(e){var _this72$maxMessages,_o$model0;var _this72;_classCallCheck(this,Yi);var s,r,o;var n=JSON.parse(JSON.stringify(e.directConnection)).mistral;_this72=_callSuper(this,Yi,[e,ad(),rd,n]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("Mistral"),_this72.keyHelpUrl="https://console.mistral.ai/api-keys/",_this72.url="https://api.mistral.ai/v1/chat/completions",_this72.permittedErrorPrefixes=[kt],_typeof(n)===B&&_this72.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.mistral)==null?void 0:r.function_handler),(_this72$maxMessages=_this72.maxMessages)!==null&&_this72$maxMessages!==void 0?_this72$maxMessages:_this72.maxMessages=-1,(_o$model0=(o=_this72.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="mistral-small-latest";return _this72;}_inherits(Yi,_R22);return _createClass(Yi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{role:R.getRoleViaAI(r.role),content:R.getTextWFilesContent(r,Yi.getFileContent)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e,t){var _this$messages5;return _regenerator().w(function(_context148){while(1)switch(_context148.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),{});case 1:return _context148.a(2);}},_callee148,this);}));function callServiceAPI(_x274,_x275){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e,t){var _n10;return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:if(!e.message){_context149.n=1;break;}throw e.message;case 1:if(!e[f]){_context149.n=2;break;}throw e[f].message;case 2:if(!(e.choices&&e.choices.length>0)){_context149.n=4;break;}_n10=e.choices[0];if(!_n10.delta){_context149.n=3;break;}return _context149.a(2,this.extractStreamResult(_n10,t));case 3:if(!_n10.message){_context149.n=4;break;}return _context149.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 _context149.a(2,_defineProperty({},h,""));}},_callee149,this);}));function extractResultData(_x276,_x277){return _extractResultData32.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){var n,s,r;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:n=e.delta,s=e.finish_reason;if(!(s==="tool_calls"&&n!=null&&n.tool_calls)){_context150.n=1;break;}r={tool_calls:n.tool_calls};return _context150.a(2,this.handleToolsGeneric(r,this.functionHandler,this.messages,t));case 1:return _context150.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee150,this);}));function extractStreamResult(_x278,_x279){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t.type===j?_defineProperty(_defineProperty({},T,Ne),Ne,t[A]||""):_defineProperty(_defineProperty({},T,h),h,"[Unsupported ".concat(Q," type: ").concat(t.type,"]"));});}}]);}(R);var Qi=/*#__PURE__*/function(_R23){function Qi(e){var _this73$maxMessages,_l$model3;var _this73;_classCallCheck(this,Qi);var r,o,a,c,l;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.groq;_this73=_callSuper(this,Qi,[e,Uo(),Fo,n]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("Groq"),_this73.keyHelpUrl="https://console.groq.com/keys",_this73.url="https://api.groq.com/openai/v1/chat/completions",_this73.permittedErrorPrefixes=[kt,"property"];var s=(r=t.groq)==null?void 0:r.chat;_typeof(s)===B&&_this73.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.groq)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this73$maxMessages=_this73.maxMessages)!==null&&_this73$maxMessages!==void 0?_this73$maxMessages:_this73.maxMessages=-1,(_l$model3=(l=_this73.rawBody).model)!==null&&_l$model3!==void 0?_l$model3:l.model="llama-3.3-70b-versatile";return _this73;}_inherits(Qi,_R23);return _createClass(Qi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:Qi.getTextWImagesContent(r),role:r.role===J?bt:r.role};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e,t){var _this$messages6;return _regenerator().w(function(_context151){while(1)switch(_context151.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 _context151.a(2);}},_callee151,this);}));function callServiceAPI(_x280,_x281){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e,t){var n,s,r,o;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:if(!e[f]){_context152.n=1;break;}throw e[f].message;case 1:return _context152.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,""));}},_callee152,this);}));function extractResultData(_x282,_x283){return _extractResultData33.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
202
+ },{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:return _context153.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee153,this);}));function extractStreamResult(_x284,_x285){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(R);var cd=function cd(i){return _defineProperty(_defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K),"accept",K);},ld=function ld(i,e,t,n){typeof i.message=="string"?n(re):t(e);},dd=function dd(){return de("https://api.cohere.ai/v1/models",ce,ld);};var $s=/*#__PURE__*/function(_R24){function $s(e){var _this74$maxMessages,_s$model4;var _this74;_classCallCheck(this,$s);var s;var n=JSON.parse(JSON.stringify(e.directConnection)).cohere;if(_this74=_callSuper(this,$s,[e,dd(),cd,n]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Cohere"),_this74.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this74.permittedErrorPrefixes=["invalid"],_this74.url="https://api.cohere.com/v2/chat",_typeof(n)===B){var r=te.processCohere(n);_this74.canSendMessage=function(){return r;},_this74.cleanConfig(n),Object.assign(_this74.rawBody,n);}(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_s$model4=(s=_this74.rawBody).model)!==null&&_s$model4!==void 0?_s$model4:s.model="command-a-03-2025";return _this74;}_inherits($s,_R24);return _createClass($s,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=t.filter(function(r){return r[h];});return n.messages=s.map(function(r){return{role:R.getRoleViaAI(r.role),content:r[h]};}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context154.a(2);}},_callee154,this);}));function callServiceAPI(_x286,_x287){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e){var t,n,s,r;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:if(!(typeof e.message=="string")){_context155.n=1;break;}throw e.message;case 1:if(!(this.stream&&e[h])){_context155.n=2;break;}r=$s.parseBundledEvents(e[h]);return _context155.a(2,{text:$s.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])){_context155.n=3;break;}return _context155.a(2,_defineProperty({},h,e.message.content[0][h]));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context155.a(2);}},_callee155,this);}));function extractResultData(_x288){return _extractResultData34.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),n=[];var _iterator4=_createForOfIteratorHelper(t),_step4;try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){var s=_step4.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){_iterator4.e(err);}finally{_iterator4.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("");}}]);}(R);var hd=function hd(){return _defineProperty({},D,K);},ud=function ud(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(re):n(He):t(e);},pd=function pd(){var i="https://generativelanguage.googleapis.com/v1beta/models?key=";return de(i,ce,ud,function(e){return"".concat(i).concat(e);});};var er=/*#__PURE__*/function(_R25){function er(e){var _this75$maxMessages;var _this75;_classCallCheck(this,er);var s,r;var n=JSON.parse(JSON.stringify(e.directConnection)).gemini;_this75=_callSuper(this,er,[e,pd(),hd,n]),_this75.insertKeyPlaceholderText=_this75.genereteAPIKeyName("Gemini"),_this75.keyHelpUrl="https://aistudio.google.com/app/apikey",_this75.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent",_this75.url="",_this75.permittedErrorPrefixes=["API_KEY_INVALID"],_typeof(n)===B&&(n.model&&(_this75.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(n.model,":generateContent")),_this75.cleanConfig(n),_this75.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.gemini)==null?void 0:r.function_handler)),(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1;return _this75;}_inherits(er,_R25);return _createClass(er,[{key:"cleanConfig",value:function cleanConfig(e){delete e.model;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return er.getContent(r);});return n.contents=s,this.systemMessage&&(n.systemInstruction={parts:[_defineProperty({},h,this.systemMessage)]}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var _this$messages7;var n,s;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(this.connectSettings){_context156.n=1;break;}throw new Error(Ie);case 1:(_this$messages7=this.messages)!==null&&_this$messages7!==void 0?_this$messages7:this.messages=e;n=this.preprocessBody(this.rawBody,t),s=this.stream;s&&(_typeof(s)!==B||!s.simulation)||n.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),F.request(this,n,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),ie.request(this,n,e));case 2:return _context156.a(2);}},_callee156,this);}));function callServiceAPI(_x289,_x290){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()// https://ai.google.dev/gemini-api/docs/function-calling?example=weather
203
+ },{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(!e[f]){_context157.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)){_context157.n=3;break;}a=e.candidates[0].content.parts,c=a.find(function(p){return p.functionCall;});if(!(c!=null&&c.functionCall)){_context157.n=2;break;}return _context157.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 _context157.a(2,_defineProperty(_defineProperty({},h,(l==null?void 0:l[h])||""),y,(o=d==null?void 0:d.inlineData)!=null&&o.data?[_defineProperty({},A,"data:image/png;base64,".concat(d.inlineData.data))]:[]));case 3:return _context157.a(2,_defineProperty({},h,""));}},_callee157,this);}));function extractResultData(_x291,_x292){return _extractResultData35.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){var n,s,_yield$this$callToolF3,r,o,a,c;return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:if(!(!e||!t||!this.functionHandler)){_context158.n=1;break;}throw Error(Wt);case 1:n=JSON.parse(JSON.stringify(t));s=e.map(function(c){return{name:c.name,arguments:JSON.stringify(c.args)};});_context158.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF3=_context158.v;r=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context158.n=3;break;}return _context158.a(2,o);case 3:a={parts:e.map(function(c){return{functionCall:{name:c.name,args:c.args}};}),role:"model"};if(!(n.contents.push(a),!r.find(function(_ref181){var c=_ref181.response;return typeof c!="string";})&&s.length===r.length)){_context158.n=4;break;}c={parts:r.map(function(l,d){return{functionResponse:{name:e[d].name,response:{result:l.response}}};}),role:U};return _context158.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(un);case 5:return _context158.a(2);}},_callee158,this);}));function handleTools(_x293,_x294){return _handleTools2.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[A]&&n[A].includes("data:")){var _n$A$split=n[A].split(","),_n$A$split2=_slicedToArray(_n$A$split,2),s=_n$A$split2[0],r=_n$A$split2[1];t.push({inlineData:{mimeType:s.replace("data:","").replace(";base64",""),data:r}});}}),{parts:t,role:e.role===U?U:"model"};}}]);}(R);var fd=function fd(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},D,K),"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===be?n(re):n(He):t(e);},gd=function gd(){return de("https://api.anthropic.com/v1/models",ce,md);};var Gs=/*#__PURE__*/function(_R26){function Gs(e){var _this76$maxMessages,_o$model1,_a$max_tokens2;var _this76;_classCallCheck(this,Gs);var s,r,o,a;var n=JSON.parse(JSON.stringify(e.directConnection)).claude;_this76=_callSuper(this,Gs,[e,gd(),fd,n]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("Claude"),_this76.keyHelpUrl="https://console.anthropic.com/settings/keys",_this76.url="https://api.anthropic.com/v1/messages",_this76.permittedErrorPrefixes=[be,Ke],_this76._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},T,"tool_use"),"id",""),"name",""),"input",""),_typeof(n)===B&&_this76.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.claude)==null?void 0:r.function_handler),(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1,(_o$model1=(o=_this76.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="claude-sonnet-4-5-20250929",(_a$max_tokens2=(a=_this76.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this76;}_inherits(Gs,_R26);return _createClass(Gs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:Gs.getTextWFilesContent(r,Gs.getFileContent),role:R.getRoleViaUser(r.role)};});return n.messages=s,this.systemMessage&&(n.system=this.systemMessage),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e,t){var _this$messages8;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:(_this$messages8=this.messages)!==null&&_this$messages8!==void 0?_this$messages8:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context159.a(2);}},_callee159,this);}));function callServiceAPI(_x295,_x296){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e,t){var n,s,r,o,a;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if(!e[f]){_context160.n=1;break;}throw e[f].message;case 1:if(!(e.content&&e.content.length>0)){_context160.n=3;break;}o=e.content.find(function(c){return c.type==="tool_use";});if(!o){_context160.n=2;break;}return _context160.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(c){return c.type===h;});if(!a){_context160.n=3;break;}return _context160.a(2,_defineProperty({},h,a[h]));case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context160.n=4;break;}return _context160.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")){_context160.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context160.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((s=e.delta)==null?void 0:s.type)==="input_json_delta")){_context160.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context160.n=7;break;case 6:if(!(e.type==="message_delta"&&((r=e.delta)==null?void 0:r.stop_reason)==="tool_use")){_context160.n=7;break;}return _context160.a(2,(this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t)));case 7:return _context160.a(2,_defineProperty({},h,""));}},_callee160,this);}));function extractResultData(_x297,_x298){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var n,s,_yield$this$callToolF4,r,o,a,c;return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(!(!e||!t||!this.functionHandler)){_context161.n=1;break;}throw Error(Wt);case 1:n=JSON.parse(JSON.stringify(t));s=e.map(function(c){return{name:c.name,arguments:JSON.stringify(c.input)};});_context161.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF4=_context161.v;r=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context161.n=3;break;}return _context161.a(2,o);case 3:a=e.map(function(c){return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},T,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push({role:"assistant",content:a}),!r.find(function(_ref187){var c=_ref187.response;return typeof c!="string";})&&s.length===r.length)){_context161.n=4;break;}c=r.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},T,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context161.a(2,(n.messages.push({role:U,content:c}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(un);case 5:return _context161.a(2);}},_callee161,this);}));function handleTools(_x299,_x300){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var n,s,r;if(t.type===j){var o=(n=t[A])==null?void 0:n.split(",")[1],a=((r=(s=t[A])==null?void 0:s.match(/data:([^;]+)/))==null?void 0:r[1])||"image/jpeg";return _defineProperty(_defineProperty({},T,j),"source",_defineProperty(_defineProperty(_defineProperty({},T,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},T,h),h,"[Unsupported ".concat(Q," type: ").concat(t.type,"]"));});}}]);}(R);var yd=function yd(){return{};},bd=function bd(){},vd=function vd(){return de("",ce,bd);};var tr=/*#__PURE__*/function(_R27){function tr(e){var _this77$maxMessages,_o$model10,_a$stream;var _this77;_classCallCheck(this,tr);var s,r,o,a;var t=JSON.parse(JSON.stringify(e.directConnection));_this77=_callSuper(this,tr,[e,vd(),yd,{key:"placeholder"}]),_this77.insertKeyPlaceholderText="",_this77.keyHelpUrl="",_this77.validateKeyProperty=!1,_this77.url="http://localhost:11434/api/chat",_this77.permittedErrorPrefixes=["Error"];var n=t.ollama;_typeof(n)===B&&_this77.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.ollama)==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="llama3.2",(_a$stream=(a=_this77.rawBody).stream)!==null&&_a$stream!==void 0?_a$stream:a.stream=!1;return _this77;}_inherits(tr,_R27);return _createClass(tr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){var o={content:r[h]||"",role:R.getRoleViaUser(r.role)};if(r[y]&&r[y].length>0){var a=tr.getImageData(r[y]);a.length>0&&(o[V]=a);}return o;});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){var _this$messages9;return _regenerator().w(function(_context162){while(1)switch(_context162.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),{readable:!0});case 1:return _context162.a(2);}},_callee162,this);}));function callServiceAPI(_x301,_x302){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee163(e,t){var n,s,r;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:if(!e[f]){_context163.n=1;break;}throw e[f].message;case 1:if(!e[h]){_context163.n=2;break;}r=JSON.parse(e[h]);return _context163.a(2,(n=r.message)!=null&&n.tool_calls?this.handleTools({tool_calls:r.message.tool_calls},t):_defineProperty({},h,((s=r.message)==null?void 0:s.content)||""));case 2:return _context163.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},h,e.message.content||""):_defineProperty({},h,""));}},_callee163,this);}));function extractResultData(_x303,_x304){return _extractResultData37.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var n,s,_yield$this$callToolF5,r,o;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context164.n=1;break;}throw Error(Wt);case 1:n=JSON.parse(JSON.stringify(t));s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:JSON.stringify(a["function"].arguments)};});_context164.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF5=_context164.v;r=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context164.n=3;break;}return _context164.a(2,o);case 3:if(!(n.messages.push({tool_calls:e.tool_calls,role:bt,content:""}),!r.find(function(_ref194){var a=_ref194.response;return typeof a!="string";})&&s.length===r.length)){_context164.n=4;break;}return _context164.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({role:"tool",tool_name:l==null?void 0:l["function"].name,content:a.response});}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(un);case 5:return _context164.a(2);}},_callee164,this);}));function handleTools(_x305,_x306){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t.type===j;}).map(function(t){var s;return((s=t[A])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(R);var Ho=function Ho(i){return _defineProperty({Authorization:"".concat(ye).concat(i)},D,K);},_d=function _d(i,e,t,n){var s=i;s[f]?s[f].type===be||s[f].type===Ke?n(re):n(He):t(e);},jo=function jo(){return de("https://api.x.ai/v1/models",ce,_d);},Zs=/*#__PURE__*/function(_R28){function Zs(e){var _o$model11;var _this78;_classCallCheck(this,Zs);var r,o;var t=e.directConnection,n=t==null?void 0:t.x;_this78=_callSuper(this,Zs,[e,jo(),Ho,n]),_this78.insertKeyPlaceholderText=_this78.genereteAPIKeyName("X"),_this78.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this78.url=Zs.IMAGE_GENERATION_URL,_this78.permittedErrorPrefixes=[Ke,be];var s=(r=t==null?void 0:t.x)==null?void 0:r[V];_typeof(s)===B&&Object.assign(_this78.rawBody,s),(_o$model11=(o=_this78.rawBody).model)!==null&&_o$model11!==void 0?_o$model11:o.model="grok-2-image";return _this78;}_inherits(Zs,_R28);return _createClass(Zs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=JSON.parse(JSON.stringify(e));return n&&n!==""&&(s.prompt=n),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context165.a(2);}},_callee165,this);}));function callServiceAPI(_x307,_x308){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee166(e){var t;return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:if(!e[f]){_context166.n=1;break;}throw e[f].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},A,n.url),T,j):_defineProperty(_defineProperty({},A,"".concat(yn).concat(n.b64_json)),T,j);});return _context166.a(2,_defineProperty({},y,t));}},_callee166);}));function extractResultData(_x309){return _extractResultData38.apply(this,arguments);}return extractResultData;}()}]);}(R);Zs.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Li=Zs;var Ed=function Ed(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},Sd=function Sd(i,e,t,n){var s=i;s[f]?s[f].type===Ke?n(re):n(He):t(e);},xd=function xd(){return de("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",ce,Sd);};var nr=/*#__PURE__*/function(_R29){function nr(e){var _this79$maxMessages,_o$model12;var _this79;_classCallCheck(this,nr);var s,r,o;var n=JSON.parse(JSON.stringify(e.directConnection)).qwen;_this79=_callSuper(this,nr,[e,xd(),Ed,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("Qwen"),_this79.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this79.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this79.permittedErrorPrefixes=["No static","The model",ps],_typeof(n)===B&&_this79.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.qwen)==null?void 0:r.function_handler),(_this79$maxMessages=_this79.maxMessages)!==null&&_this79$maxMessages!==void 0?_this79$maxMessages:_this79.maxMessages=-1,(_o$model12=(o=_this79.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="qwen-plus";return _this79;}_inherits(nr,_R29);return _createClass(nr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:nr.getTextWImagesContent(r),role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e,t){var _this$messages0;return _regenerator().w(function(_context167){while(1)switch(_context167.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),{});case 1:return _context167.a(2);}},_callee167,this);}));function callServiceAPI(_x310,_x311){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){var _n11;return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:if(!e[f]){_context168.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context168.n=3;break;}_n11=e.choices[0];if(!_n11.delta){_context168.n=2;break;}return _context168.a(2,this.extractStreamResult(_n11,t));case 2:if(!_n11.message){_context168.n=3;break;}return _context168.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 _context168.a(2,_defineProperty({},h,""));}},_callee168,this);}));function extractResultData(_x312,_x313){return _extractResultData39.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e,t){return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:return _context169.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee169,this);}));function extractStreamResult(_x314,_x315){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()}]);}(R);var Ad=function Ad(i){return _defineProperty(_defineProperty({},ae,"".concat(ye).concat(i)),D,K);},wd=function wd(i,e,t,n){var s=i;s[f]?s[f].type===be?n(re):n(He):t(e);},Cd=function Cd(){return de("https://api.moonshot.ai/v1/models",ce,wd);};var sr=/*#__PURE__*/function(_R30){function sr(e){var _this80$maxMessages,_o$model13;var _this80;_classCallCheck(this,sr);var s,r,o;var n=JSON.parse(JSON.stringify(e.directConnection)).kimi;_this80=_callSuper(this,sr,[e,Cd(),Ad,n]),_this80.insertKeyPlaceholderText=_this80.genereteAPIKeyName("Kimi"),_this80.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this80.url="https://api.moonshot.ai/v1/chat/completions",_this80.permittedErrorPrefixes=[kt,"Not found"],_typeof(n)===B&&_this80.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.kimi)==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="moonshot-v1-8k";return _this80;}_inherits(sr,_R30);return _createClass(sr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:sr.getTextWImagesContent(r),role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e,t){var _this$messages1;return _regenerator().w(function(_context170){while(1)switch(_context170.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 _context170.a(2);}},_callee170,this);}));function callServiceAPI(_x316,_x317){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(e,t){var _n12;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:if(!e[f]){_context171.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context171.n=3;break;}_n12=e.choices[0];if(!_n12.delta){_context171.n=2;break;}return _context171.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context171.n=3;break;}return _context171.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 _context171.a(2,_defineProperty({},h,""));}},_callee171,this);}));function extractResultData(_x318,_x319){return _extractResultData40.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee172(e,t){return _regenerator().w(function(_context172){while(1)switch(_context172.n){case 0:return _context172.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee172,this);}));function extractStreamResult(_x320,_x321){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()}]);}(R);var Td=/*#__PURE__*/function(_R31){function Td(e){var _this81$maxMessages,_o$model14;var _this81;_classCallCheck(this,Td);var r,o;var t=JSON.parse(JSON.stringify(e.directConnection)),n=t.x;_this81=_callSuper(this,Td,[e,jo(),Ho,n]),_this81.insertKeyPlaceholderText=_this81.genereteAPIKeyName("X"),_this81.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this81.url="https://api.x.ai/v1/chat/completions",_this81.permittedErrorPrefixes=[Ke,be];var s=(r=t.x)==null?void 0:r.chat;_typeof(s)===B&&_this81.completeConfig(s),(_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="grok-3-latest";return _this81;}_inherits(Td,_R31);return _createClass(Td,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=JSON.parse(JSON.stringify(e)),s=this.processMessages(t).map(function(r){return{content:r[h]||"",role:R.getRoleViaUser(r.role)};});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e,t){return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context173.a(2);}},_callee173,this);}));function callServiceAPI(_x322,_x323){return _callServiceAPI38.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(e){var t,n,s,r,o;return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:if(!e[f]){_context174.n=1;break;}throw e[f].message;case 1:if(!(e.object==="chat.completion.chunk")){_context174.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context174.a(2,(n=o==null?void 0:o.delta)!=null&&n.content?_defineProperty({},h,o.delta.content):_defineProperty({},h,""));case 2:return _context174.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,""));}},_callee174);}));function extractResultData(_x324){return _extractResultData41.apply(this,arguments);}return extractResultData;}()}]);}(R);var Rd=/*#__PURE__*/function(){function Rd(){_classCallCheck(this,Rd);}return _createClass(Rd,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
204
204
  function create(e){var t=e.directConnection,n=e.connect,s=e.demo,r=e.webModel;if(r)return new ls(e);if(t){if(t.openAI)return t.openAI[V]?new Ni(e):t.openAI.speechToText?new Ii(e):t.openAI.textToSpeech?new Ri(e):t.openAI.assistant?new Wi(e):t.openAI.realtime?new Ti(e):t.openAI.completions?new Hs(e):new js(e);if(t.assemblyAI)return new Xi(e);if(t.cohere)return new $s(e);if(t.huggingFace)return t.huggingFace.textGeneration?new ul(e):t.huggingFace.summarization?new fl(e):t.huggingFace.translation?new gl(e):t.huggingFace.fillMask?new yl(e):t.huggingFace.questionAnswer?new pl(e):t.huggingFace.audioSpeechRecognition?new hl(e):t.huggingFace.audioClassification?new cl(e):t.huggingFace.imageClassification?new ll(e):new ml(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new Zi(e);if(t.azure.openAI.assistant)return new wi(e);}if(t.azure.speechToText)return new Oi(e);if(t.azure.textToSpeech)return new ki(e);if(t.azure.summarization)return new Mi(e);if(t.azure.translation)return new Fl(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new Ls(e):t.stabilityAI.imageToImageUpscale?new Os(e):t.stabilityAI.imageToImageMasking?new Ns(e):new Ps(e);if(t.mistral)return new Yi(e);if(t.gemini)return new er(e);if(t.claude)return new Gs(e);if(t.deepSeek)return new ed(e);if(t.miniMax)return new id(e);if(t.openRouter)return new Xn(e);if(t.kimi)return new sr(e);if(t.x)return t.x[V]?new Li(e):new Td(e);if(t.qwen)return new nr(e);if(t.together)return t.together[V]?new ql(e):t.together.textToSpeech?new El(e):new $l(e);if(t.bigModel)return t.bigModel[V]?new Ul(e):t.bigModel.textToSpeech?new vl(e):new qs(e);if(t.groq)return t.groq.textToSpeech?new jl(e):new Qi(e);if(t.perplexity)return new Xl(e);if(t.ollama)return new tr(e);}return n&&Object.keys(n).length>0&&!s?new Kt(e):new Kt(e,void 0,s||!0);}}]);}();var hr=/*#__PURE__*/_createClass(function hr(){_classCallCheck(this,hr);});hr.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 Pi=hr;function k(i){return function(e,t){Object.defineProperty(e,t,{});var n=e.constructor,s=t.toLocaleLowerCase();n._attributes_[s]=Pi.attibutes[i],n._attributeToProperty_[s]=t;};}var Id="deep-chat-downwards-mode",Md="deep-chat-upwards-mode",xn="submit-button",Es="loading-button",An="disabled-button",Pr="text-input-container-start-adjustment",Br="text-input-container-end-adjustment",Dr="text-input-container-start-small-adjustment",Fr="text-input-container-end-small-adjustment";var ir=/*#__PURE__*/function(){function ir(e){_classCallCheck(this,ir);this._isDisplayed=!1,this._elementRef=this.createIntroPanelWithChild(e),this._isDisplayed=!0;}return _createClass(ir,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e){var t=ir.createIntroPanel();return e[_].display==="none"&&(e[_].display="block"),t.appendChild(e),t;}},{key:"hide",value:function hide(){this._isDisplayed&&(this._elementRef[_].display="none",this._isDisplayed=!1);}},{key:"display",value:function display(){this._isDisplayed||(this._elementRef[_].display="",this._isDisplayed=!0);}}],[{key:"createIntroPanel",value:function createIntroPanel(){var e=S();return e[m].add("intro-panel"),Object.assign(e[_]),e;}}]);}();var kd="<?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>",_e=/*#__PURE__*/function(){function _e(){_classCallCheck(this,_e);}return _createClass(_e,null,[{key:"createImage",value:function createImage(e,t){var n=new Image();return n[A]=e[A],t&&ue.scrollDownOnImageLoad(n[A],t),ue.processContent(j,n,n[A],e.name);}// WORK - image still does not scroll down when loaded
205
205
  },{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=_e.createImage(t,o);return r.bubbleElement.appendChild(a),r.bubbleElement[m].add(_e.IMAGE_BUBBLE_CLASS),{type:j,elements:r};}},{key:"createAudioElement",value:function createAudioElement(e,t){var n=S(P);return n[A]=e[A],n[m].add("audio-player"),n.controls=!0,Oe.IS_SAFARI&&(n[m].add("audio-player-safari"),n[m].add(t===U?"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=_e.createAudioElement(t,n),o=e.createMessageElementsOnOrientation("",n,s);return o.bubbleElement.appendChild(r),o.bubbleElement[m].add(_e.AUDIO_BUBBLE_CLASS),{type:P,elements:o,audioElement:r};}},{key:"createAnyFile",value:function createAnyFile(e){var t=S();t[m].add("any-file-message-contents");var n=S();n[m].add("any-file-message-icon-container");var s=_t.createSVGElement(kd);s[m].add("any-file-message-icon"),n.appendChild(s);var r=S();return r[m].add("any-file-message-text"),r.textContent=e.name||Q,t.appendChild(n),t.appendChild(r),ue.processContent(Gt,t,e[A],r.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,n,s){var r=e.createMessageElementsOnOrientation("",n,s),o=_e.createAnyFile(t);return r.bubbleElement[m].add(_e.ANY_FILE_BUBBLE_CLASS),r.bubbleElement.appendChild(o),{type:Q,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=ue.removeFileRef(o)),ue.isAudioFile(o)){var l=_e.createNewAudioMessage(e,o,n,r),d=(c=e.textToSpeech)==null?void 0:c.audio;return d&&(d.autoPlay&&_e.autoPlayAudio(l.audioElement),typeof d.displayAudio=="boolean"&&!d.displayAudio)?void 0:l;}return ue.isImageFile(o)?_e.createImageMessage(e,o,n,!r&&s&&a===0):_e.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
206
- },{key:"addMessages",value:function addMessages(e,t,n,s,r){_e.createMessages(e,t,n,s,r).filter(function(a){return a!==void 0;}).forEach(function(_ref209){var a=_ref209.type,c=_ref209.elements;ue.addMessage(e,c,a,n,r);});}}]);}();_e.IMAGE_BUBBLE_CLASS="image-message",_e.AUDIO_BUBBLE_CLASS="audio-message",_e.ANY_FILE_BUBBLE_CLASS="any-file-message";var zs=_e;var $e=/*#__PURE__*/function(){function $e(){_classCallCheck(this,$e);}return _createClass($e,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){$e.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];$e.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][I])at.overwriteElements(e,n,t[1][I]);else{var a=at.create(e,n,t[0].role),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][I]=a;}t[0][I]=n;}// finds beforeElement, creates new elements, remove old and adds new ones
207
- },{key:"updateFileMessages",value:function updateFileMessages(e,t,n){var p,u;var s=t[0].role,r=zs.createMessages(e,n,s,!1),o=t[1][I],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(_ref210,v){var g=_ref210.type,b=_ref210.elements;var E;ue.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+v,0,b);}),$e.removeFilesMessages(e,t),t[1][y]=r.map(function(_ref211){var g=_ref211.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].role);else{var o=e.createElements(n,t[0].role),a=((s=t[1][y])==null?void 0:s[0])||t[1][I];(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 Ve.isActiveElement((t=e[h])==null?void 0:t.bubbleElement[m])||Ve.isActiveElement((n=e[I])==null?void 0:n.bubbleElement[m]);}// note that overwrite and 'deep-chat-temporary-message' are used to remove a message
208
- },{key:"update",value:function update(e,t,n){var s=e.messageToElements[n];if(s){if($e.isElementActive(s[1]))return console[f]("Cannot update a message that is being streamed");t[h]&&$e.updateTextMessage(e,s,t[h]),t[y]?$e.updateFileMessages(e,s,t[y]):$e.removeFilesMessages(e,s),t[I]&&$e.updateHTMLMessage(e,s,t[I]),!t[h]&&s[1][h]&&$e.removeTextHTMLMessage(e,s,h),!t[I]&&s[1][I]&&$e.removeTextHTMLMessage(e,s,I);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 Od=/*#__PURE__*/function(){function Od(){_classCallCheck(this,Od);}return _createClass(Od,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($,"connect#connect-1) property or a popular service via [directConnection](").concat($,"directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](").concat($,"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($,"modes#demo) property to true.");if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](".concat($,"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($,"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($,"connect#connect-1) object.");return null;}}]);}();var Ve=/*#__PURE__*/function(_Je){function Ve(e,t,n){var _this82;_classCallCheck(this,Ve);var o,a;_this82=_callSuper(this,Ve,[e]);var s=t.permittedErrorPrefixes,r=t.demo;_this82._errorMessageOverrides=(o=e.errorMessages)==null?void 0:o.overrides,_this82._onClearMessages=Jt.onClearMessages.bind(_this82,e),_this82._onError=Jt.onError.bind(_this82,e),_this82._isLoadingMessageAllowed=Ve.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this82.setLoadingToggle.bind(_this82)),_this82._permittedErrorPrefixes=s,_this82.addSetupMessageIfNeeded(e,t)||_this82.populateIntroPanel(n),r&&_this82.prepareDemo(te.processDemo(r),e.loadHistory),_this82.addIntroductoryMessages(e,t),new cs(e,_this82,t),_this82._displayServiceErrorMessages=(a=e.errorMessages)==null?void 0:a.displayServiceErrorMessages,e.getMessages=function(){return N.deepCloneMessagesWithReferences(_this82.messageToElements.map(function(_ref212){var _ref213=_slicedToArray(_ref212,1),c=_ref213[0];return c;}));},e.clearMessages=_this82.clearMessages.bind(_this82,t),e.refreshMessages=_this82.refreshTextMessages.bind(_this82,e.remarkable),e.scrollToBottom=ce.scrollToBottom.bind(_this82,_this82),e.addMessage=function(c,l){_this82.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!!l}),!l);},e.updateMessage=function(c,l){return $e.update(_this82,c,l);},t.isWebModel()&&t.setUpMessages(_this82),e.textToSpeech&&hn.processConfig(e.textToSpeech,function(c){_this82.textToSpeech=c;});return _this82;}_inherits(Ve,_Je);return _createClass(Ve,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1],n=Je.isLoadingMessage(t);if(!e&&n)this.removeLastMessage(),delete this._activeLoadingConfig;else{if(this._activeLoadingConfig&&n){var s=Z.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&&vt.addMessage(this,!1),s!=null&&s.full&&vt.addMessage(this);}e.displayErrors&&(e.displayErrors[x]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage(Y,""),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=Od.getText(e,t);if(n){var s=this.createAndAppendNewMessageElement(n,J);this.applyCustomStyles(s,J,!1);}return!!n;}// WORK - const file for deep chat classes
209
- },{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this83=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=_this83.messageElementRefs[_this83.messageElementRefs.length-1].innerContainer;N.hideRoleElements(a,_this83.avatar,_this83.name);}_this83.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],J):e!=null&&e[I]&&(n=at.add(this,e[I],J)),n&&(this.applyCustomStyles(n,J,!1,(s=this.messageStyles)==null?void 0:s.intro),n.outerContainer[m].add(Je.INTRO_CLASS),t&&(n.outerContainer[_].display="none")),n;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer[m].contains(Je.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(Y,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.role,t,r),!s&&this.textToSpeech&&e.role!==U&&hn.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])&&zs.addMessages(this,e[y],e.role,t,n);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e[I]!==void 0&&e[I]!==null){var s=at.add(this,e[I],e.role,t,n);!n&&ot.isElementTemporary(s)&&delete e[I];}}// this should not be activated by streamed messages
210
- },{key:"addNewMessage",value:function addNewMessage(e){var _this84=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.role!==U&&((c=this._hiddenAttachments)==null||c.removeHiddenFiles());var s=Ve.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=ce.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 _this84.scrollToFirstElement(s.role,o);}),t||(p=this.browserStorage)==null||p.addMessages(this.messageToElements.map(function(_ref214){var _ref215=_slicedToArray(_ref214,1),u=_ref215[0];return u;})),this.hiddenMessages&&s.role!==U&&this.tryUpdateHiddenMessageCount(t,e)),this._activeLoadingConfig&&this.addLoadingMessage(!1),s;}},{key:"tryUpdateHiddenMessageCount",value:function tryUpdateHiddenMessageCount(e,t){var _this85=this;(!e||t.sendUpdate!==void 0)&&setTimeout(function(){var n,s;return(s=(n=_this85.hiddenMessages)==null?void 0:n.update)==null?void 0:s.call(n);});}},{key:"isValidMessageContent",value:function isValidMessageContent(e){return e[h]||e[I]||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
206
+ },{key:"addMessages",value:function addMessages(e,t,n,s,r){_e.createMessages(e,t,n,s,r).filter(function(a){return a!==void 0;}).forEach(function(_ref209){var a=_ref209.type,c=_ref209.elements;ue.addMessage(e,c,a,n,r);});}}]);}();_e.IMAGE_BUBBLE_CLASS="image-message",_e.AUDIO_BUBBLE_CLASS="audio-message",_e.ANY_FILE_BUBBLE_CLASS="any-file-message";var zs=_e;var $e=/*#__PURE__*/function(){function $e(){_classCallCheck(this,$e);}return _createClass($e,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){$e.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];$e.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][M])at.overwriteElements(e,n,t[1][M]);else{var a=at.create(e,n,t[0].role),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][M]=a;}t[0][M]=n;}// finds beforeElement, creates new elements, remove old and adds new ones
207
+ },{key:"updateFileMessages",value:function updateFileMessages(e,t,n){var p,u;var s=t[0].role,r=zs.createMessages(e,n,s,!1),o=t[1][M],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(_ref210,v){var g=_ref210.type,b=_ref210.elements;var E;ue.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+v,0,b);}),$e.removeFilesMessages(e,t),t[1][y]=r.map(function(_ref211){var g=_ref211.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].role);else{var o=e.createElements(n,t[0].role),a=((s=t[1][y])==null?void 0:s[0])||t[1][M];(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 Ve.isActiveElement((t=e[h])==null?void 0:t.bubbleElement[m])||Ve.isActiveElement((n=e[M])==null?void 0:n.bubbleElement[m]);}// note that overwrite and 'deep-chat-temporary-message' are used to remove a message
208
+ },{key:"update",value:function update(e,t,n){var s=e.messageToElements[n];if(s){if($e.isElementActive(s[1]))return console[f]("Cannot update a message that is being streamed");t[h]&&$e.updateTextMessage(e,s,t[h]),t[y]?$e.updateFileMessages(e,s,t[y]):$e.removeFilesMessages(e,s),t[M]&&$e.updateHTMLMessage(e,s,t[M]),!t[h]&&s[1][h]&&$e.removeTextHTMLMessage(e,s,h),!t[M]&&s[1][M]&&$e.removeTextHTMLMessage(e,s,M);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 Od=/*#__PURE__*/function(){function Od(){_classCallCheck(this,Od);}return _createClass(Od,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($,"connect#connect-1) property or a popular service via [directConnection](").concat($,"directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](").concat($,"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($,"modes#demo) property to true.");if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](".concat($,"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($,"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($,"connect#connect-1) object.");return null;}}]);}();var Ve=/*#__PURE__*/function(_Je){function Ve(e,t,n){var _this82;_classCallCheck(this,Ve);var o,a;_this82=_callSuper(this,Ve,[e]);var s=t.permittedErrorPrefixes,r=t.demo;_this82._errorMessageOverrides=(o=e.errorMessages)==null?void 0:o.overrides,_this82._onClearMessages=Jt.onClearMessages.bind(_this82,e),_this82._onError=Jt.onError.bind(_this82,e),_this82._isLoadingMessageAllowed=Ve.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this82.setLoadingToggle.bind(_this82)),_this82._permittedErrorPrefixes=s,_this82.addSetupMessageIfNeeded(e,t)||_this82.populateIntroPanel(n),r&&_this82.prepareDemo(te.processDemo(r),e.loadHistory),_this82.addIntroductoryMessages(e,t),new cs(e,_this82,t),_this82._displayServiceErrorMessages=(a=e.errorMessages)==null?void 0:a.displayServiceErrorMessages,e.getMessages=function(){return N.deepCloneMessagesWithReferences(_this82.messageToElements.map(function(_ref212){var _ref213=_slicedToArray(_ref212,1),c=_ref213[0];return c;}));},e.clearMessages=_this82.clearMessages.bind(_this82,t),e.refreshMessages=_this82.refreshTextMessages.bind(_this82,e.remarkable),e.scrollToBottom=oe.scrollToBottom.bind(_this82,_this82),e.addMessage=function(c,l){_this82.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!!l}),!l);},e.updateMessage=function(c,l){return $e.update(_this82,c,l);},t.isWebModel()&&t.setUpMessages(_this82),e.textToSpeech&&hn.processConfig(e.textToSpeech,function(c){_this82.textToSpeech=c;}),_this82.elementRef.onscroll=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(){var c,l;return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:oe.isScrollbarAtBottomOfElement(_this82.elementRef,60)?(c=_this82.scrollButton)==null||c.hideScrollElement():(l=_this82.scrollButton)==null||l.displayScrollElement();case 1:return _context175.a(2);}},_callee175);}));return _this82;}_inherits(Ve,_Je);return _createClass(Ve,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1],n=Je.isLoadingMessage(t);if(!e&&n)this.removeLastMessage(),delete this._activeLoadingConfig;else{if(this._activeLoadingConfig&&n){var s=Z.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&&vt.addMessage(this,!1),s!=null&&s.full&&vt.addMessage(this);}e.displayErrors&&(e.displayErrors[x]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage(Y,""),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=Od.getText(e,t);if(n){var s=this.createAndAppendNewMessageElement(n,J);this.applyCustomStyles(s,J,!1);}return!!n;}// WORK - const file for deep chat classes
209
+ },{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this83=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=_this83.messageElementRefs[_this83.messageElementRefs.length-1].innerContainer;N.hideRoleElements(a,_this83.avatar,_this83.name);}_this83.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],J):e!=null&&e[M]&&(n=at.add(this,e[M],J)),n&&(this.applyCustomStyles(n,J,!1,(s=this.messageStyles)==null?void 0:s.intro),n.outerContainer[m].add(Je.INTRO_CLASS),t&&(n.outerContainer[_].display="none")),n;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer[m].contains(Je.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(Y,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.role,t,r),!s&&this.textToSpeech&&e.role!==U&&hn.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])&&zs.addMessages(this,e[y],e.role,t,n);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e[M]!==void 0&&e[M]!==null){var s=at.add(this,e[M],e.role,t,n);!n&&ot.isElementTemporary(s)&&delete e[M];}}// this should not be activated by streamed messages
210
+ },{key:"addNewMessage",value:function addNewMessage(e){var _this84=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.role!==U&&((c=this._hiddenAttachments)==null||c.removeHiddenFiles());var s=Ve.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=oe.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 _this84.scrollToFirstElement(s.role,o);}),t||(p=this.browserStorage)==null||p.addMessages(this.messageToElements.map(function(_ref215){var _ref216=_slicedToArray(_ref215,1),u=_ref216[0];return u;})),this.scrollButton&&s.role!==U&&this.tryUpdateHiddenMessageCount(t,e)),this._activeLoadingConfig&&this.addLoadingMessage(!1),s;}},{key:"tryUpdateHiddenMessageCount",value:function tryUpdateHiddenMessageCount(e,t){var _this85=this;(!e||t.sendUpdate!==void 0)&&setTimeout(function(){var n,s;return(s=(n=_this85.scrollButton)==null?void 0:n.update)==null?void 0:s.call(n);});}},{key:"isValidMessageContent",value:function isValidMessageContent(e){return e[h]||e[M]||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
211
211
  },{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(et.MESSAGE_CLASS)&&t.textContent===""||Ve.isTemporaryElement(e))&&this.removeLastMessage();}// prettier-ignore
212
- },{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this86=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[x])||"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(Cs),this.renderText(o,s);var c=Ce.extractParticularSharedStyles(["fontSize","fontFamily"],(u=this.messageStyles)==null?void 0:u[x]);Ce.applyCustomStylesToElements(r,!1,c),Ce.applyCustomStylesToElements(r,!1,(g=this.messageStyles)==null?void 0:g[f]),n||this.appendOuterContainerElemet(a),this.textToSpeech&&hn.speak(s,this.textToSpeech),(b=this._onError)==null||b.call(this,s),setTimeout(function(){return ce.scrollToBottom(_this86);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=Ve.extractErrorMessages(e);for(var _n13=0;_n13<t.length;_n13+=1){var s=t[_n13];if(typeof s=="string"){if(this._displayServiceErrorMessages)return s;if(this._permittedErrorPrefixes){var r=Ve.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]:J;var n=this.createMessageElements("",t),s=n.bubbleElement;n.bubbleElement[m].add(rt.DOTS_CONTAINER_CLASS);var r=S();return r[m].add("loading-message-dots"),s.appendChild(r),rt.setDots(s,e),n;}// prettier-ignore
213
- },{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,c,l,d,p,u;if(Je.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((a=this._activeLoadingConfig)==null?void 0:a.role)||J,n=((c=this._activeLoadingConfig)==null?void 0:c[_])||((d=(l=this.messageStyles)==null?void 0:l.loading)==null?void 0:d.message),s=n==null?void 0:n[I],r=s?at.createElements(this,s,t,!1):this.addDefaultLoadingMessage(n,t);this.appendOuterContainerElemet(r.outerContainer),r.bubbleElement[m].add(rt.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&&ce.isScrollbarAtBottomOfElement(this.elementRef)&&ce.scrollToBottom(this);}// this is a special method not to constantly refresh loading animations
214
- },{key:"updateLoadingMessage",value:function updateLoadingMessage(e){var s;var t=(s=this._activeLoadingConfig)==null?void 0:s[_],n=t==null?void 0:t[I];e.innerHTML=n||"";}},{key:"populateIntroPanel",value:function populateIntroPanel(e){e&&(this._introPanel=new ir(e),Z.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(e,t){return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:return _context175.a(2,(this._hiddenAttachments=t,Promise.all((e||[]).map(function(n){return new Promise(function(s){if(!n.type||n.type===Gt){var r=n[Q].name||Q;s({name:r,type:Gt,ref:n[Q]});}else{var _r7=new FileReader();_r7.readAsDataURL(n[Q]),_r7.onload=function(){var o=n[Q].name;s(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},A,_r7.result),"name",o),"type",n.type),"ref",n[Q]));};}});}))));}},_callee175,this);}));function addMultipleFiles(_x325,_x326){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
215
- function clearMessages(e,t){var _this$messageToElemen2;var r,o,a,c;var n=[];this.messageElementRefs.forEach(function(l){Ve.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(Cs)&&l.remove();}),this.messageElementRefs=n;var s=this.messageToElements.filter(function(l){return l[1][h]&&Ve.isActiveElement(l[1][h].bubbleElement[m])||l[1][I]&&Ve.isActiveElement(l[1][I].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.hiddenMessages)==null||a.clear(),(c=this._onClearMessages)==null||c.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref216;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===B?!1:!!e.displayLoadingBubble:(_ref216=_typeof(e.displayLoadingBubble)===B||e.displayLoadingBubble)!==null&&_ref216!==void 0?_ref216:!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(rt.BUBBLE_CLASS)||e.contains(vt.CLASS)||e.contains(et.MESSAGE_CLASS):!1;}}]);}(Je);var Zn=/*#__PURE__*/function(){function Zn(){_classCallCheck(this,Zn);}return _createClass(Zn,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t[pn].length>0&&e[m].add("text-input-inner-start-adjustment"),t[it].length>0&&e[m].add("text-input-inner-end-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,n){n[he].length===0&&n[xe].length>0?(e[0][m].add(Dr),t[m].add(Dr)):n[xe].length===0&&n[he].length>0&&(e[3][m].add(Fr),t[m].add(Fr));}// when submit is the only button
212
+ },{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this86=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[x])||"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(Cs),this.renderText(o,s);var c=Ce.extractParticularSharedStyles(["fontSize","fontFamily"],(u=this.messageStyles)==null?void 0:u[x]);Ce.applyCustomStylesToElements(r,!1,c),Ce.applyCustomStylesToElements(r,!1,(g=this.messageStyles)==null?void 0:g[f]),n||this.appendOuterContainerElemet(a),this.textToSpeech&&hn.speak(s,this.textToSpeech),(b=this._onError)==null||b.call(this,s),setTimeout(function(){return oe.scrollToBottom(_this86);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=Ve.extractErrorMessages(e);for(var _n13=0;_n13<t.length;_n13+=1){var s=t[_n13];if(typeof s=="string"){if(this._displayServiceErrorMessages)return s;if(this._permittedErrorPrefixes){var r=Ve.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]:J;var n=this.createMessageElements("",t),s=n.bubbleElement;n.bubbleElement[m].add(rt.DOTS_CONTAINER_CLASS);var r=S();return r[m].add("loading-message-dots"),s.appendChild(r),rt.setDots(s,e),n;}// prettier-ignore
213
+ },{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,c,l,d,p,u;if(Je.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((a=this._activeLoadingConfig)==null?void 0:a.role)||J,n=((c=this._activeLoadingConfig)==null?void 0:c[_])||((d=(l=this.messageStyles)==null?void 0:l.loading)==null?void 0:d.message),s=n==null?void 0:n[M],r=s?at.createElements(this,s,t,!1):this.addDefaultLoadingMessage(n,t);this.appendOuterContainerElemet(r.outerContainer),r.bubbleElement[m].add(rt.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&&oe.isScrollbarAtBottomOfElement(this.elementRef)&&oe.scrollToBottom(this);}// this is a special method not to constantly refresh loading animations
214
+ },{key:"updateLoadingMessage",value:function updateLoadingMessage(e){var s;var t=(s=this._activeLoadingConfig)==null?void 0:s[_],n=t==null?void 0:t[M];e.innerHTML=n||"";}},{key:"populateIntroPanel",value:function populateIntroPanel(e){e&&(this._introPanel=new ir(e),Z.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_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._hiddenAttachments=t,Promise.all((e||[]).map(function(n){return new Promise(function(s){if(!n.type||n.type===Gt){var r=n[Q].name||Q;s({name:r,type:Gt,ref:n[Q]});}else{var _r7=new FileReader();_r7.readAsDataURL(n[Q]),_r7.onload=function(){var o=n[Q].name;s(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},A,_r7.result),"name",o),"type",n.type),"ref",n[Q]));};}});}))));}},_callee176,this);}));function addMultipleFiles(_x325,_x326){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
215
+ function clearMessages(e,t){var _this$messageToElemen2;var r,o,a,c;var n=[];this.messageElementRefs.forEach(function(l){Ve.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(Cs)&&l.remove();}),this.messageElementRefs=n;var s=this.messageToElements.filter(function(l){return l[1][h]&&Ve.isActiveElement(l[1][h].bubbleElement[m])||l[1][M]&&Ve.isActiveElement(l[1][M].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.clear(),(c=this._onClearMessages)==null||c.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref217;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===B?!1:!!e.displayLoadingBubble:(_ref217=_typeof(e.displayLoadingBubble)===B||e.displayLoadingBubble)!==null&&_ref217!==void 0?_ref217:!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(rt.BUBBLE_CLASS)||e.contains(vt.CLASS)||e.contains(et.MESSAGE_CLASS):!1;}}]);}(Je);var Zn=/*#__PURE__*/function(){function Zn(){_classCallCheck(this,Zn);}return _createClass(Zn,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t[pn].length>0&&e[m].add("text-input-inner-start-adjustment"),t[it].length>0&&e[m].add("text-input-inner-end-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,n){n[he].length===0&&n[xe].length>0?(e[0][m].add(Dr),t[m].add(Dr)):n[xe].length===0&&n[he].length>0&&(e[3][m].add(Fr),t[m].add(Fr));}// when submit is the only button
216
216
  // when submit button is outside by itself - we increase the height for a better look
217
217
  },{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,n){if(!(n[pn].length>0||n[it].length>0)){if(n[he].length===0&&n[xe].length>0)return e[0][m].add(Pr),t[m].add(Pr),n[xe].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});if(n[xe].length===0&&n[he].length>0)return e[3][m].add(Br),t[m].add(Br),n[he].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});}}// prettier-ignore
218
218
  },{key:"set",value:function set(e,t,n,s){!!Zn.adjustOutsideSubmit(t,n,s)||Zn.adjustForOutsideButton(t,n,s),Zn.adjustInputPadding(e,s);}}]);}();var gn=/*#__PURE__*/function(){function gn(){_classCallCheck(this,gn);}return _createClass(gn,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var n=S();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===xe?0:e===pn?1:e===it?2:3;}},{key:"addButton",value:function addButton(e,t,n){t[m].add(n);var s=gn.getContainerIndex(n);e[s].appendChild(t),s===3&&t[m].add(he);}}]);}();var Ur=["camera","gifs","images","audio","mixedFiles","submit","microphone"],Nd="<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",ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,null,[{key:"addItemEvents",value:function addItemEvents(e,t,n,s){yt.add(t,s),t.addEventListener(q,function(){n[q]();}),t.addEventListener("mouseenter",function(r){e.highlightedItem=r.target;}),t.addEventListener("mouseleave",function(){e.highlightedItem=void 0;});}},{key:"createItemText",value:function createItemText(e,t){var n=S();return Object.assign(n[_],t),n[m].add(ke.TEXT_CLASS),n.textContent=e||"File",n;}},{key:"createItemIcon",value:function createItemIcon(e,t){var n=S();return Object.assign(n[_],t),n[m].add(ke.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(lt.INPUT_BUTTON_INNER_TEXT_CLASS)?(l||t.appendChild(ke.createItemIcon(o,n==null?void 0:n.iconContainer)),t.appendChild(ke.createItemText(c.textContent,n==null?void 0:n[h]))):(l||t.appendChild(ke.createItemIcon(s.children[0],n==null?void 0:n.iconContainer)),t.appendChild(ke.createItemText(r,n==null?void 0:n[h])));}},{key:"createItem",value:function createItem(e,t,n){var o;var s=S();Object.assign(s[_],(o=n==null?void 0:n.item)==null?void 0:o[x]),ke.populateItem(t,s,n),s[m].add(ke.MENU_ITEM_CLASS);var r=t.elementRef;if(t.isCustom)t.setDropupItem(s);else{var a=ee.processStateful((n==null?void 0:n.item)||{});ke.addItemEvents(e,s,r,a);}return s;}}]);}();ke.MENU_ITEM_CLASS="dropup-menu-item",ke.TEXT_CLASS="dropup-menu-item-text",ke.ICON_CLASS="dropup-menu-item-icon";var st=ke;var ne=/*#__PURE__*/function(_Qt2){// prettier-ignore
@@ -222,7 +222,7 @@ function ne(e,t,n,s){var _this87;_classCallCheck(this,ne);var c,l,d,p,u,g;var r=
222
222
  },{key:"focusSiblingItem",value:function focusSiblingItem(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var r=s?e:e[n?"nextSibling":"previousSibling"];r?(e.dispatchEvent(new MouseEvent("mouseleave")),r.dispatchEvent(new MouseEvent("mouseenter"))):(e.dispatchEvent(new MouseEvent("mouseleave")),ds.focusItemWhenOnEdge(t,n));}}]);}();var rr=/*#__PURE__*/function(){function rr(e,t){var _this90=this;_classCallCheck(this,rr);var n;this._isOpen=!0,this._styles=t,this.elementRef=rr.createElement((n=this._styles)==null?void 0:n.container),this.close(),setTimeout(function(){return _this90.addWindowEvents(e);});}return _createClass(rr,[{key:"open",value:function open(){this.elementRef[_].display="block",this._isOpen=!0;}},{key:"close",value:function close(){this._isOpen&&(this.elementRef[_].display="none",this._isOpen=!1);}},{key:"toggle",value:function toggle(){this._isOpen?this.close():this.open();}},{key:"addItem",value:function addItem(e){var t=st.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
223
223
  },{key:"addWindowEvents",value:function addWindowEvents(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener(q,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(q,this.clickEvent):e.parentElement!==((n=t.target.shadowRoot)==null?void 0:n.children[0])&&this.close();}// prettier-ignore
224
224
  },{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[q](),(r=this.highlightedItem)==null||r.dispatchEvent(new MouseEvent("mouseleave"))):t.key===ge.ARROW_DOWN?ds.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===ge.ARROW_UP&&ds.focusSiblingItem(this.highlightedItem||this.elementRef.children[0],this.elementRef,!1));}}],[{key:"createElement",value:function createElement(e){var t=S();return t.id=ze,Object.assign(t[_],e),t;}}]);}();var Ut=/*#__PURE__*/function(_Qt3){function Ut(e,t){var _this91;_classCallCheck(this,Ut);var r,o;var n=tt.tryCreateConfig("Options",(r=t==null?void 0:t.button)==null?void 0:r.tooltip);_this91=_callSuper(this,Ut,[Ut.createButtonElement(),Ld,void 0,n,{styles:(o=t==null?void 0:t.button)==null?void 0:o.styles}]);var s=_this91.createInnerElementsForStates(_this91.customStyles);_this91._menu=new rr(e,t==null?void 0:t.menu),_this91.addClickEvent(),_this91.buttonContainer=Ut.createButtonContainer(),_this91.changeElementsByState(s.styles),_this91.buttonContainer.appendChild(_this91.elementRef),_this91.elementRef[m].add(Ut.BUTTON_ICON_CLASS),_this91.buttonContainer.appendChild(_this91._menu.elementRef),_this91.reapplyStateStyle("styles"),_this91.addContainerEvents(e);return _this91;}_inherits(Ut,_Qt3);return _createClass(Ut,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("dropup-icon","styles",e)};}},{key:"addClickEvent",value:function addClickEvent(){this.elementRef.onclick=this._menu.toggle.bind(this._menu);}},{key:"addItem",value:function addItem(e){this._menu.addItem(e);}},{key:"addContainerEvents",value:function addContainerEvents(e){var _this92=this;e.addEventListener(q,function(t){var n=t.target[m];!n.contains(Ut.BUTTON_ICON_CLASS)&&!n.contains($t.DISABLED_CONTAINER_CLASS)&&_this92._menu.close();});}}],[{key:"createButtonElement",value:function createButtonElement(){var e=S();return e[m].add("input-button"),e;}},{key:"createButtonContainer",value:function createButtonContainer(){var e=S();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?te.processPosition((s=t==null?void 0:t.button)==null?void 0:s.position):e[xe].length>0&&e[he].length===0?he:xe;}}]);}(Qt);Ut.BUTTON_ICON_CLASS="dropup-button";var Vs=Ut;var we=/*#__PURE__*/function(){function we(){_classCallCheck(this,we);}return _createClass(we,null,[{key:"addToDropup",value:// prettier-ignore
225
- function addToDropup(e,t,n,s){var r=new Vs(n,s);Ur.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(_ref218){var a=_ref218.button;return r.addItem(a);});var o=Vs.getPosition(t,s);gn.addButton(e,r.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){[pn,it,xe,he].forEach(function(s){var r=s;t[r].forEach(function(o){gn.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,[]),xe,[]),pn,[]),it,[]),he,[]);}// prettier-ignore
225
+ function addToDropup(e,t,n,s){var r=new Vs(n,s);Ur.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(_ref219){var a=_ref219.button;return r.addItem(a);});var o=Vs.getPosition(t,s);gn.addButton(e,r.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){[pn,it,xe,he].forEach(function(s){var r=s;t[r].forEach(function(o){gn.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,[]),xe,[]),pn,[]),it,[]),he,[]);}// prettier-ignore
226
226
  },{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=we.createPositionsToButtonsObj();Object.keys(e).forEach(function(s){var o;var r=(o=e[s])==null?void 0:o.button.position;r&&we.setPosition(e,s,t[r]);}),t[it].length===0&&e.submit&&we.setPosition(e,"submit",t[it]),t[he].length===0&&(e.submit?we.setPosition(e,"submit",t[he]):e.microphone?we.setPosition(e,Ye,t[he]):e.camera?we.setPosition(e,Re,t[he]):e["".concat($t.INDICATOR_PREFIX,"1")]&&we.setPosition(e,"".concat($t.INDICATOR_PREFIX,"1"),t[he])),e.submit&&we.setPosition(e,"submit",t[xe].length===0?t[xe]:t[it]),e.microphone&&we.setPosition(e,Ye,t[xe].length===0?t[xe]:t[it]);var n=Object.keys(e);return n.length>1||t[ze].length>0?(Ur.forEach(function(s){e[s]&&t[ze].push(_objectSpread(_objectSpread({},e[s]),{},{buttonType:s}));}),n.forEach(function(s){var r=s;r.startsWith($t.INDICATOR_PREFIX)&&e[r]&&t[ze].push(_objectSpread(_objectSpread({},e[r]),{},{customType:r}));})):n.length===1&&we.setPosition(e,n[0],t[he].length===0?t[he]:t[xe]),t;}// prettier-ignore
227
227
  },{key:"addButtons",value:function addButtons(e,t,n,s){var r=we.generatePositionToButtons(t);return we.addToSideContainer(e,r),r[ze].length>0&&we.addToDropup(e,r,n,s),r;}}]);}();var Pd="<?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>",Bd="<?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",Dd="<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>",Fd="<?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",Ud=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},V,{id:"upload-images-icon",svgString:Bd,dropupText:"Image"}),ln,{id:"upload-gifs-icon",svgString:Fd,dropupText:"GIF"}),P,{id:"upload-audio-icon",svgString:Dd,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:Pd,dropupText:"File"});var ii=/*#__PURE__*/function(_Qt4){function ii(e){var _this93;_classCallCheck(this,ii);(e==null?void 0:e.position)===ze&&(e.position=he);var t=tt.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this93=_callSuper(this,ii,[ii.createMicrophoneElement(),Lo,e==null?void 0:e.position,t,e]),_this93.isActive=!1,_this93._innerElements=_this93.createInnerElementsForStates(_this93.customStyles),_this93.changeToDefault();return _this93;}_inherits(ii,_Qt4);return _createClass(ii,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},x,this.createInnerElements(t,x,e)),"active",this.createInnerElements(t,"active",e)),"unsupported",this.createInnerElements(t,"unsupported",e)),"commandMode",this.createInnerElements(t,"commandMode",e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements.active),this.toggleIconFilter("active"),this.reapplyStateStyle("active",[x,"commandMode"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[x]),this.toggleIconFilter(x),this.reapplyStateStyle(x,["active","commandMode"]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements.commandMode),this.toggleIconFilter("command"),this.reapplyStateStyle("commandMode",["active"]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements.unsupported),this.elementRef[m].add("unsupported-microphone"),this.reapplyStateStyle("unsupported",["active"]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()==="svg")switch(e){case x:t[m].remove("active-microphone-icon","command-microphone-icon"),t[m].add("default-microphone-icon");break;case"active":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=S();return e.id="microphone-button",e[m].add("input-button"),e;}}]);}(Qt);function Hd(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i["default"]:i;}var Ss={},wn={},Cn={},Tn={},Rn={},Hr;function ri(){if(Hr)return Rn;Hr=1,Object.defineProperty(Rn,"__esModule",{value:!0}),Rn.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 Rn.Text=i,i.FIRST_CHAR_REGEX=/\S/,i.DOUBLE_LINE=/\n\n/g,i.ONE_LINE=/\n/g,Rn;}var jr;function qo(){if(jr)return Tn;jr=1,Object.defineProperty(Tn,"__esModule",{value:!0}),Tn.Translate=void 0;var i=ri();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 Tn.Translate=e,Tn;}var qr;function jd(){if(qr)return Cn;qr=1,Object.defineProperty(Cn,"__esModule",{value:!0}),Cn.WebSpeechTranscript=void 0;var i=qo();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 Cn.WebSpeechTranscript=e,Cn;}var In={},$r;function or(){if($r)return In;$r=1,Object.defineProperty(In,"__esModule",{value:!0}),In.Browser=void 0;var i=/*#__PURE__*/_createClass(function i(){_classCallCheck(this,i);});return In.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;},In;}var Mn={},kn={},Gr;function qd(){if(Gr)return kn;Gr=1,Object.defineProperty(kn,"__esModule",{value:!0}),kn.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 _this94=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,_this94.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 kn.EventListeners=i,i.KEY_DOWN_TIMEOUT=null,kn;}var On={},zr;function $d(){if(zr)return On;zr=1,Object.defineProperty(On,"__esModule",{value:!0}),On.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 On.PreResultUtils=i,On;}var Nn={},Ln={},Vr;function $o(){if(Vr)return Ln;Vr=1,Object.defineProperty(Ln,"__esModule",{value:!0}),Ln.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
228
228
  // they can only safely be scrolled to the end
@@ -251,25 +251,25 @@ function addToDropup(e,t,n,s){var r=new Vs(n,s);Ur.forEach(function(a){var c=t[z
251
251
  },{key:"resetRecording",value:function resetRecording(u){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(u,!0);}// prettier-ignore
252
252
  },{key:"updateElements",value:function updateElements(u,g,b){var v;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 C=this.commands&&t.CommandUtils.execCommand(this,b,this._options,this._primitiveElement||this._genericElement,this._originalText);if(C){if(C.doNotProcessTranscription)return;u="",b="";}if(this.isPaused||this.isWaitingForCommand)return;(v=this._onResult)===null||v===void 0||v.call(this,b,u===""),this.finalTranscript=E,this._displayInterimResults||(u="");var H=this.finalTranscript===""&&u==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,u,H):this._genericElement&&this.updateGenericElement(this._genericElement,u,H);}// prettier-ignore
253
253
  // remember that padding values here contain actual text left and right
254
- },{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 v=this.startPadding+this.finalTranscript+g;if(u.value=v+this.endPadding,!this.isTargetInShadow){var E=v.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 v=(b?"":this.startPadding)+l.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=v;var E=n.AutoScroll.isRequired(this.autoScroll,u);n.AutoScroll.changeStateIfNeeded(this,E);var C=l.Text.lineBreak(g)+(b?"":this.endPadding);this.interimSpan.innerHTML=C,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&c.Cursor.setOffsetForSafariGeneric(u,v.length+C.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 Mn.Speech=d,Mn;}var Qr;function Vd(){if(Qr)return wn;Qr=1,Object.defineProperty(wn,"__esModule",{value:!0}),wn.WebSpeech=void 0;var i=jd(),e=or(),t=zo();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 _this95=this;this._service&&(this._service.onstart=function(){_this95.setStateOnStart();},this._service.onerror=function(r){e.Browser.IS_SAFARI()&&r.message==="Another request is started"||r.error==="aborted"&&_this95.isRestarting||r.error!=="no-speech"&&_this95.error(r.message||r.error);},this._service.onaudioend=function(){_this95.setStateOnStop();},this._service.onend=function(){_this95._stopping=!1;},this._service.onresult=function(r){if(_typeof(r.results)>"u"&&_this95._service)_this95._service.onend=null,_this95._service.stop();else if(_this95._extractText&&!_this95._stopping){var _this95$_extractText=_this95._extractText(r,_this95.finalTranscript,_this95._translations),o=_this95$_extractText.interimTranscript,a=_this95$_extractText.finalTranscript,c=_this95$_extractText.newText;_this95.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 wn.WebSpeech=n,wn;}var Un={},eo;function Jd(){if(eo)return Un;eo=1,Object.defineProperty(Un,"__esModule",{value:!0}),Un.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 Un.GlobalState=i,i.doubleClickPending=!1,Un;}var Hn={},jn={},to;function Kd(){if(to)return jn;to=1,Object.defineProperty(jn,"__esModule",{value:!0}),jn.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 jn.PreventConnectionStop=i,jn;}var qn={},$n={},no;function Wd(){return no||(no=1,Object.defineProperty($n,"__esModule",{value:!0}),$n.README_URL=void 0,$n.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),$n;}var so;function Xd(){if(so)return qn;so=1,Object.defineProperty(qn,"__esModule",{value:!0}),qn.AzureSpeechConfig=void 0;var i=Wd();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 _callee176(n,s){return _regenerator().w(function(_context176){while(1)switch(_context176.n){case 0:if(!s.region){_context176.n=1;break;}return _context176.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 _context176.a(2);}},_callee176);}));function getNewSpeechConfig(_x327,_x328){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 _callee177(n,s){var r;return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:_context177.n=1;return e.getNewSpeechConfig(n,s);case 1:r=_context177.v;return _context177.a(2,(r&&e.process(r,s),r));}},_callee177);}));function get(_x329,_x330){return _get2.apply(this,arguments);}return get;}()}]);}();return qn.AzureSpeechConfig=e,qn;}var Gn={},io;function Zd(){if(io)return Gn;io=1,Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.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 Gn.StopTimeout=i,i.DEFAULT_MS=2e4,Gn;}var zn={},ro;function Yd(){if(ro)return zn;ro=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.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 zn.AzureAudioConfig=i,zn;}var Vn={},oo;function Qd(){if(oo)return Vn;oo=1,Object.defineProperty(Vn,"__esModule",{value:!0}),Vn.AzureTranscript=void 0;var i=qo();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
255
- 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 Vn.AzureTranscript=e,Vn;}var ao;function eh(){if(ao)return Hn;ao=1,Object.defineProperty(Hn,"__esModule",{value:!0}),Hn.Azure=void 0;var i=Kd(),e=Xd(),t=Zd(),n=Yd(),s=Qd(),r=zo();var o=/*#__PURE__*/function(_r$Speech){function o(){var _this96;_classCallCheck(this,o);_this96=_callSuper(this,o,arguments),_this96._newTextPadding="";return _this96;}_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 _callee178(c){var l,_t51;return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:_t51=this.validate(c);if(!_t51){_context178.n=2;break;}_context178.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 _context178.a(2);}},_callee178,this);}));function startAsync(_x331){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 _callee179(c){var l,d,p,u,_c$autoLanguage,g,b,v,E;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:l=o.getAPI();d=n.AzureAudioConfig.get(l.AudioConfig,c.deviceId);_context179.n=1;return e.AzureSpeechConfig.get(l.SpeechConfig,c);case 1:p=_context179.v;if(p){if(c.autoLanguage&&c.autoLanguage.languages.length>0){_c$autoLanguage=c.autoLanguage,g=_c$autoLanguage.type,b=_c$autoLanguage.languages,v=b.slice(0,g==="Continuous"?10:4),E=l.AutoDetectSourceLanguageConfig.fromLanguages(v);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 _context179.a(2);}},_callee179,this);}));function instantiateService(_x332){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
254
+ },{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 v=this.startPadding+this.finalTranscript+g;if(u.value=v+this.endPadding,!this.isTargetInShadow){var E=v.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 v=(b?"":this.startPadding)+l.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=v;var E=n.AutoScroll.isRequired(this.autoScroll,u);n.AutoScroll.changeStateIfNeeded(this,E);var C=l.Text.lineBreak(g)+(b?"":this.endPadding);this.interimSpan.innerHTML=C,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&c.Cursor.setOffsetForSafariGeneric(u,v.length+C.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 Mn.Speech=d,Mn;}var Qr;function Vd(){if(Qr)return wn;Qr=1,Object.defineProperty(wn,"__esModule",{value:!0}),wn.WebSpeech=void 0;var i=jd(),e=or(),t=zo();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 _this95=this;this._service&&(this._service.onstart=function(){_this95.setStateOnStart();},this._service.onerror=function(r){e.Browser.IS_SAFARI()&&r.message==="Another request is started"||r.error==="aborted"&&_this95.isRestarting||r.error!=="no-speech"&&_this95.error(r.message||r.error);},this._service.onaudioend=function(){_this95.setStateOnStop();},this._service.onend=function(){_this95._stopping=!1;},this._service.onresult=function(r){if(_typeof(r.results)>"u"&&_this95._service)_this95._service.onend=null,_this95._service.stop();else if(_this95._extractText&&!_this95._stopping){var _this95$_extractText=_this95._extractText(r,_this95.finalTranscript,_this95._translations),o=_this95$_extractText.interimTranscript,a=_this95$_extractText.finalTranscript,c=_this95$_extractText.newText;_this95.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 wn.WebSpeech=n,wn;}var Un={},eo;function Jd(){if(eo)return Un;eo=1,Object.defineProperty(Un,"__esModule",{value:!0}),Un.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 Un.GlobalState=i,i.doubleClickPending=!1,Un;}var Hn={},jn={},to;function Kd(){if(to)return jn;to=1,Object.defineProperty(jn,"__esModule",{value:!0}),jn.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 jn.PreventConnectionStop=i,jn;}var qn={},$n={},no;function Wd(){return no||(no=1,Object.defineProperty($n,"__esModule",{value:!0}),$n.README_URL=void 0,$n.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),$n;}var so;function Xd(){if(so)return qn;so=1,Object.defineProperty(qn,"__esModule",{value:!0}),qn.AzureSpeechConfig=void 0;var i=Wd();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 _callee177(n,s){return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:if(!s.region){_context177.n=1;break;}return _context177.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 _context177.a(2);}},_callee177);}));function getNewSpeechConfig(_x327,_x328){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 _callee178(n,s){var r;return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:_context178.n=1;return e.getNewSpeechConfig(n,s);case 1:r=_context178.v;return _context178.a(2,(r&&e.process(r,s),r));}},_callee178);}));function get(_x329,_x330){return _get2.apply(this,arguments);}return get;}()}]);}();return qn.AzureSpeechConfig=e,qn;}var Gn={},io;function Zd(){if(io)return Gn;io=1,Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.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 Gn.StopTimeout=i,i.DEFAULT_MS=2e4,Gn;}var zn={},ro;function Yd(){if(ro)return zn;ro=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.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 zn.AzureAudioConfig=i,zn;}var Vn={},oo;function Qd(){if(oo)return Vn;oo=1,Object.defineProperty(Vn,"__esModule",{value:!0}),Vn.AzureTranscript=void 0;var i=qo();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
255
+ 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 Vn.AzureTranscript=e,Vn;}var ao;function eh(){if(ao)return Hn;ao=1,Object.defineProperty(Hn,"__esModule",{value:!0}),Hn.Azure=void 0;var i=Kd(),e=Xd(),t=Zd(),n=Yd(),s=Qd(),r=zo();var o=/*#__PURE__*/function(_r$Speech){function o(){var _this96;_classCallCheck(this,o);_this96=_callSuper(this,o,arguments),_this96._newTextPadding="";return _this96;}_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 _callee179(c){var l,_t51;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:_t51=this.validate(c);if(!_t51){_context179.n=2;break;}_context179.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 _context179.a(2);}},_callee179,this);}));function startAsync(_x331){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 _callee180(c){var l,d,p,u,_c$autoLanguage,g,b,v,E;return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:l=o.getAPI();d=n.AzureAudioConfig.get(l.AudioConfig,c.deviceId);_context180.n=1;return e.AzureSpeechConfig.get(l.SpeechConfig,c);case 1:p=_context180.v;if(p){if(c.autoLanguage&&c.autoLanguage.languages.length>0){_c$autoLanguage=c.autoLanguage,g=_c$autoLanguage.type,b=_c$autoLanguage.languages,v=b.slice(0,g==="Continuous"?10:4),E=l.AutoDetectSourceLanguageConfig.fromLanguages(v);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 _context180.a(2);}},_callee180,this);}));function instantiateService(_x332){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
256
256
  },{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
257
257
  },{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 _this97=this;this._retrieveTokenInterval=setInterval(function(){c==null||c().then(function(l){_this97._service&&(_this97._service.authorizationToken=(l==null?void 0:l.trim())||"");})["catch"](function(l){_this97.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 Hn.Azure=o,Hn;}var co;function th(){if(co)return Ss;co=1,Object.defineProperty(Ss,"__esModule",{value:!0});var i=Vd(),e=Go(),t=Jd(),n=eh();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 Ss["default"]=s,Ss;}var nh=th();var As=/* @__PURE__ */Hd(nh);var sh=/*#__PURE__*/function(){function sh(e,t){_classCallCheck(this,sh);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(sh,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this98=this;this._silenceTimeout=setTimeout(function(){var n;(n=e.submit)==null||n.call(e),As.stop(),_this98._stop||setTimeout(t,hs.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 is=/*#__PURE__*/function(_ii){function is(e,t,n){var _this99;_classCallCheck(this,is);var s=_typeof(e.speechToText)=="object"?e.speechToText:{};_this99=_callSuper(this,is,[s==null?void 0:s.button]);var _this99$processConfig=_this99.processConfiguration(t,e.speechToText),r=_this99$processConfig.serviceName,o=_this99$processConfig.processedConfig;if(_this99._addErrorMessage=n,r==="webspeech"&&!As.isWebSpeechSupported())_this99.changeToUnsupported();else{var a=!e.textInput||!e.textInput.disabled;_this99.elementRef.onclick=_this99.buttonClick.bind(_this99,t,a,r,o);}setTimeout(function(){_this99._validationHandler=e._validationHandler;});return _this99;}// prettier-ignore
258
258
  _inherits(is,_ii);return _createClass(is,[{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);}),As.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),n.submitAfterSilence&&(this._silenceSubmit=new sh(n.submitAfterSilence,n.stopAfterSubmit)),{serviceName:is.getServiceName(n),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,n,s){var _this100=this;var r=s==null?void 0:s.events;e.removePlaceholderStyle(),As.toggle(n,_objectSpread({insertInCursorLocation:!1,element:t?e.inputElementRef:void 0,onError:function onError(){var o;_this100.onError(),(o=_this100._silenceSubmit)==null||o.clearSilenceTimeout();},onStart:function onStart(){var o;_this100.changeToActive(),(o=r==null?void 0:r.onStart)==null||o.call(r);},onStop:function onStop(){var o,a,c;(o=_this100._validationHandler)==null||o.call(_this100),(a=_this100._silenceSubmit)==null||a.clearSilenceTimeout(),_this100.changeToDefault(),(c=r==null?void 0:r.onStop)==null||c.call(r);},onPauseTrigger:function onPauseTrigger(o){var a,c;(a=_this100._silenceSubmit)==null||a.onPause(o,e,_this100.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=_this100._validationHandler)==null||c.call(_this100)),(l=_this100._silenceSubmit)==null||l.resetSilenceTimeout(e,_this100.elementRef.onclick),(d=r==null?void 0:r.onResult)==null||d.call(r,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this100.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[q](),t||setTimeout(function(){return e[q]();},is.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(ii);is.MICROPHONE_RESET_TIMEOUT_MS=300;var hs=is;var gt=/*#__PURE__*/function(){// prettier-ignore
259
259
  function gt(e,t,n,s,r){var _this101=this;_classCallCheck(this,gt);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(){_this101._validationHandler=e._validationHandler,_this101._onInput=t.onInput;});}return _createClass(gt,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var n;return gt.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=gt.getTypeFromBlob(e);if(s===j){var r=gt.createImageAttachment(t);this.addFileAttachment(e,j,r,n);}else if(s===P){var _r8=us.createAudioAttachment(t);this.addFileAttachment(e,P,_r8,n);}else{var _r9=gt.createAnyFileAttachment(e.name);this.addFileAttachment(e,Gt,_r9,n);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,n,s){var a;var r=gt.createContainer(n);if(this._attachments.length>=this._fileCountLimit){var c=this._attachments[this._attachments.length-1].removeButton;c==null||c[q]();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=S();t[m].add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var n=S();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),us.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({},Q,e[Q]),"type",e.fileType);});}},{key:"hideAttachments",value:function hideAttachments(){var _this102=this;this._hiddenAttachments.clear(),this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t[q]();}),_this102._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[q]();});}),this._hiddenAttachments.clear();}},{key:"readdAttachments",value:function readdAttachments(){var _this103=this;var e;Array.from(this._hiddenAttachments).forEach(function(t){_this103._fileAttachmentsContainerRef.appendChild(t.attachmentContainerElement),_this103._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(j)?j:t.startsWith(P)?P:Gt;}},{key:"createImageAttachment",value:function createImageAttachment(e){var t=new Image();return t[A]=e,t[m].add("image-attachment"),t;}},{key:"createAnyFileAttachment",value:function createAnyFileAttachment(e){var t=S();t[m].add("border-bound-attachment"),Oe.IS_SAFARI&&t[m].add("border-bound-attachment-safari");var n=S();n[m].add("any-file-attachment-text");var s=S();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=S();return t[m].add("file-attachment"),t.appendChild(e),t;}}]);}();var ft=/*#__PURE__*/function(_gt){// prettier-ignore
260
260
  function ft(e,t,n,s,r){_classCallCheck(this,ft);return _callSuper(this,ft,[e,t,n,s,r]);}_inherits(ft,_gt);return _createClass(ft,[{key:"createTimer",value:function createTimer(e,t){var _this104=this;var n=0;var s=t!==void 0&&t<ft.TIMER_LIMIT_S?t:ft.TIMER_LIMIT_S;return setInterval(function(){var a;n+=1,n===s&&((a=_this104.stopPlaceholderCallback)==null||a.call(_this104),_this104.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=ft.createAudioContainer(),n=S();n[m].add("audio-placeholder-text-3-digits");var s=S();s[m].add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),s.appendChild(n);var r=_t.createSVGElement(Ci);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 _this105=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=_this105.stopPlaceholderCallback)==null?void 0:a.call(_this105);};e.addEventListener(q,o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var n=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),P,n,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
261
- },{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[Q]=e,ft.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=S();return e[m].add("border-bound-attachment","audio-attachment-icon-container"),Oe.IS_SAFARI&&e[m].add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var n=e.parentElement?ce.cloneElement(e):e,s=S(P);s[A]=t;var r=_t.createSVGElement(Po);r[m].add("attachment-icon","play-icon");var o=_t.createSVGElement(Ci);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);},n.onclick=function(){s.paused?s.play():s.pause();};}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=ft.createAudioContainer();return ft.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][q]();}}]);}(gt);ft.TIMER_LIMIT_S=5999;var us=ft;var ih=/*#__PURE__*/function(){function ih(){_classCallCheck(this,ih);}return _createClass(ih,null,[{key:"create",value:// prettier-ignore
261
+ },{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[Q]=e,ft.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=S();return e[m].add("border-bound-attachment","audio-attachment-icon-container"),Oe.IS_SAFARI&&e[m].add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var n=e.parentElement?oe.cloneElement(e):e,s=S(P);s[A]=t;var r=_t.createSVGElement(Po);r[m].add("attachment-icon","play-icon");var o=_t.createSVGElement(Ci);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);},n.onclick=function(){s.paused?s.play():s.pause();};}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=ft.createAudioContainer();return ft.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][q]();}}]);}(gt);ft.TIMER_LIMIT_S=5999;var us=ft;var ih=/*#__PURE__*/function(){function ih(){_classCallCheck(this,ih);}return _createClass(ih,null,[{key:"create",value:// prettier-ignore
262
262
  function create(e,t,n,s,r,o){return o===P?new us(e,t,n,s,r):new gt(e,t,n,s,r);}}]);}();var ms=/*#__PURE__*/function(){function ms(e,t,n){_classCallCheck(this,ms);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[_],t);}// prettier-ignore
263
- return _createClass(ms,[{key:"addType",value:function addType(e,t,n,s){var r=ih.create(e,t,n,this.toggleContainerDisplay.bind(this),this.elementRef,s);return this._fileAttachmentsTypes.push(r),r;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=S();return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef[_].display="block":this.elementRef.children.length===0&&(this.elementRef[_].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 _callee181(){return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:_context181.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref222=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(e){var t;return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:return _context180.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee180);}));return function(_x333){return _ref222.apply(this,arguments);};}()));case 1:return _context181.a(2);}},_callee181,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){ms.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 Ze=/*#__PURE__*/function(){function Ze(e,t,n){_classCallCheck(this,Ze);this._isOpen=!1,this._contentRef=Ze.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=Ze.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=Ze.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=Ze.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(Ze,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this106=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){se.addAttributes(t),_this106._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this107=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(){_this107._elementRef[_].display="none",_this107._backgroundPanelRef[_].display="none";},Ze.MODAL_CLOSE_TIMEOUT_MS);}},{key:"displayModalElements",value:function displayModalElements(){this._elementRef[_].display="flex",this._elementRef[m].remove("hide-modal"),this._elementRef[m].add("show-modal"),this._backgroundPanelRef[_].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 _this108=this;var s=t?Ze.createSVGButton(e):Ze.createTextButton(e);return this.addButtons(s),s.onclick=function(){_this108.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=S();return n[m].add("modal"),n.appendChild(e),t&&delete t.backgroundColor,Object.assign(n[_],t),n;}},{key:"createModalContent",value:function createModalContent(e,t){var _n$m;var n=S();return(_n$m=n[m]).add.apply(_n$m,_toConsumableArray(e)),t&&(n[_].backgroundColor=t),S().appendChild(n),n;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=S();return t[m].add("modal-button-panel"),e&&(t[_].backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=S();return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=S();return t[m].add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=S();t[m].add("modal-button","modal-svg-button");var n=_t.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 Ze(e,["modal-content"],t[y].infoModal.containerStyle);return r.addCloseButton("OK",!1,n),r.openTextModal.bind(r,t.infoModalTextMarkUp||"");}}}]);}();Ze.MODAL_CLOSE_TIMEOUT_MS=190;var Ht=Ze;var Js=/*#__PURE__*/function(_Qt5){// prettier-ignore
263
+ return _createClass(ms,[{key:"addType",value:function addType(e,t,n,s){var r=ih.create(e,t,n,this.toggleContainerDisplay.bind(this),this.elementRef,s);return this._fileAttachmentsTypes.push(r),r;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=S();return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef[_].display="block":this.elementRef.children.length===0&&(this.elementRef[_].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 _callee182(){return _regenerator().w(function(_context182){while(1)switch(_context182.n){case 0:_context182.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref223=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee181(e){var t;return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:return _context181.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee181);}));return function(_x333){return _ref223.apply(this,arguments);};}()));case 1:return _context182.a(2);}},_callee182,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){ms.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 Ze=/*#__PURE__*/function(){function Ze(e,t,n){_classCallCheck(this,Ze);this._isOpen=!1,this._contentRef=Ze.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=Ze.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=Ze.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=Ze.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(Ze,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this106=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){se.addAttributes(t),_this106._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this107=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(){_this107._elementRef[_].display="none",_this107._backgroundPanelRef[_].display="none";},Ze.MODAL_CLOSE_TIMEOUT_MS);}},{key:"displayModalElements",value:function displayModalElements(){this._elementRef[_].display="flex",this._elementRef[m].remove("hide-modal"),this._elementRef[m].add("show-modal"),this._backgroundPanelRef[_].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 _this108=this;var s=t?Ze.createSVGButton(e):Ze.createTextButton(e);return this.addButtons(s),s.onclick=function(){_this108.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=S();return n[m].add("modal"),n.appendChild(e),t&&delete t.backgroundColor,Object.assign(n[_],t),n;}},{key:"createModalContent",value:function createModalContent(e,t){var _n$m;var n=S();return(_n$m=n[m]).add.apply(_n$m,_toConsumableArray(e)),t&&(n[_].backgroundColor=t),S().appendChild(n),n;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=S();return t[m].add("modal-button-panel"),e&&(t[_].backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=S();return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=S();return t[m].add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=S();t[m].add("modal-button","modal-svg-button");var n=_t.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 Ze(e,["modal-content"],t[y].infoModal.containerStyle);return r.addCloseButton("OK",!1,n),r.openTextModal.bind(r,t.infoModalTextMarkUp||"");}}}]);}();Ze.MODAL_CLOSE_TIMEOUT_MS=190;var Ht=Ze;var Js=/*#__PURE__*/function(_Qt5){// prettier-ignore
264
264
  function Js(e,t,n,s,r,o){var _this109;_classCallCheck(this,Js);var p,u,g,b,v,E,C,H,W,X;var a=te.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=tt.tryCreateConfig("Upload File",(v=n==null?void 0:n.button)==null?void 0:v.tooltip);_this109=_callSuper(this,Js,[Js.createButtonElement(),r,a,l,n.button,c]);var d=_this109.createInnerElementsForStates(s,_this109.customStyles);_this109._inputElement=Js.createInputElement((E=n==null?void 0:n[y])==null?void 0:E.acceptedFormats),_this109.addClickEvent(e,n),_this109.changeElementsByState(d.styles),_this109.reapplyStateStyle("styles"),_this109._fileAttachmentsType=t,_this109._openModalOnce=((H=(C=n[y])==null?void 0:C.infoModal)==null?void 0:H.openModalOnce)===!1||(X=(W=n[y])==null?void 0:W.infoModal)==null?void 0:X.openModalOnce;return _this109;}_inherits(Js,_Qt5);return _createClass(Js,[{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[q]();}},{key:"import",value:function _import(e){ms.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=Ht.createTextModalFunc(e,t,n);this.elementRef.onclick=this[q].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=S("input");return t.type=Q,t.accept=e||"",t.hidden=!0,t.multiple=!0,t;}},{key:"createButtonElement",value:function createButtonElement(){var e=S();return e[m].add("input-button"),e;}}]);}(Qt);var mt=/*#__PURE__*/function(){function mt(){_classCallCheck(this,mt);}return _createClass(mt,null,[{key:"create",value:function create(e,t,n){var s=mt.createElement(n);mt.addEvents(s,e,t),e.appendChild(s);}},{key:"createElement",value:function createElement(e){var t=S();return t.id="drag-and-drop",_typeof(e)===B&&Object.assign(t[_],e),t;}},{key:"addEvents",value:function addEvents(e,t,n){t.ondragenter=function(s){s.preventDefault(),mt.display(e);},e.ondragleave=function(s){s.preventDefault(),mt.hide(e);},e.ondragover=function(s){s.preventDefault();},e.ondrop=function(s){s.preventDefault(),mt.uploadFile(n,s),mt.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[_].display="block";}},{key:"hide",value:function hide(e){e[_].display="none";}},{key:"isEnabled",value:function isEnabled(e,t){return t!==void 0&&t===!1?!1:!!t||e.getNumberOfTypes()>0;}}]);}();var Nt=/*#__PURE__*/function(){function Nt(){_classCallCheck(this,Nt);}return _createClass(Nt,null,[{key:"validate",value:// prettier-ignore
265
265
  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
266
- },{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee182(e,t,n,s,r,o){var a,c,l;return _regenerator().w(function(_context182){while(1)switch(_context182.n){case 0:a=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context182.n=1;return n.completePlaceholders();case 1:c=n.getAllFileData(),l=c==null?void 0:c.map(function(d){return d[Q];});return _context182.a(2,Nt.validate(e,s,r,a,l,o));}},_callee182);}));function useValidationFunc(_x334,_x335,_x336,_x337,_x338,_x339){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
267
- },{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee183(e,t,n,s,r){var a,o;return _regenerator().w(function(_context183){while(1)switch(_context183.n){case 0:o=(a=t[y])==null?void 0:a.map(function(c){return c[Q];});return _context183.a(2,Nt.validate(e,n,s,t[h],o,r,!0));}},_callee183);}));function useValidationFuncProgrammatic(_x340,_x341,_x342,_x343,_x344){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!==nt.URL&&!Ee.canSendMessage(n)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
268
- },{key:"attach",value:function attach(e,t,n,s,r,o){var a=e.validateInput||te.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref223=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee184(c){var l;return _regenerator().w(function(_context184){while(1)switch(_context184.n){case 0:if(!(r.status.loadingActive||r.status.requestInProgress||!Nt.validateWebsocket(t,r))){_context184.n=1;break;}return _context184.a(2,!1);case 1:l=a||t.canSendMessage;return _context184.a(2,l?c?Nt.useValidationFuncProgrammatic(l,c,r,t,o):Nt.useValidationFunc(l,n,s,r,t,o):null);}},_callee184);}));return function(_x345){return _ref223.apply(this,arguments);};}();}}]);}();var Vo=/*#__PURE__*/function(){function Vo(){_classCallCheck(this,Vo);}return _createClass(Vo,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 rh=/*#__PURE__*/function(_ii2){function rh(e,t){var _this110;_classCallCheck(this,rh);var n,s;_this110=_callSuper(this,rh,[t.button]),_this110._waitingForBrowserApproval=!1,_this110._audioType=e,_this110._extension=((n=t[y])==null?void 0:n.format)||"mp3",_this110._maxDurationSeconds=(s=t[y])==null?void 0:s.maxDurationSeconds,_this110.elementRef.onclick=_this110.buttonClick.bind(_assertThisInitialized(_this110));return _this110;}_inherits(rh,_ii2);return _createClass(rh,[{key:"buttonClick",value:function buttonClick(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()));}},{key:"stop",value:function stop(){var _this111=this;return new Promise(function(e){var t,n;_this111.changeToDefault(),(t=_this111._mediaRecorder)==null||t.stop(),(n=_this111._mediaStream)==null||n.getTracks().forEach(function(s){return s.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this112=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this112.changeToActive(),_this112._mediaRecorder=new MediaRecorder(e),_this112._audioType.addPlaceholderAttachment(_this112.stop.bind(_this112),_this112._maxDurationSeconds),_this112._mediaStream=e,_this112._mediaRecorder.addEventListener("dataavailable",function(t){_this112.createFile(t);}),_this112._mediaRecorder[Mt]();})["catch"](function(e){console[f](e),_this112.stop();})["finally"](function(){_this112._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this113=this;var t=new Blob([e.data],{type:"audio/".concat(this._extension)}),n=Vo.getFileName(this._newFilePrefix||P,this._extension),s=new File([t],n,{type:t.type}),r=new FileReader();r.readAsDataURL(s),r.onload=function(o){_this113._audioType.completePlaceholderAttachment(s,o.target.result);};}}]);}(ii);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 jt=/*#__PURE__*/function(){function jt(){_classCallCheck(this,jt);}return _createClass(jt,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=JSON.parse(JSON.stringify(e[t]||{}));Se.overwritePropertyObjectFromAnother(n,e.submit,["container",x]),Se.overwritePropertyObjectFromAnother(n,e.submit,[h,"styles",x]),Se.overwritePropertyObjectFromAnother(n,e.submit,["svg","styles",x]),e[t]=n;}// prettier-ignore
266
+ },{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee183(e,t,n,s,r,o){var a,c,l;return _regenerator().w(function(_context183){while(1)switch(_context183.n){case 0:a=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context183.n=1;return n.completePlaceholders();case 1:c=n.getAllFileData(),l=c==null?void 0:c.map(function(d){return d[Q];});return _context183.a(2,Nt.validate(e,s,r,a,l,o));}},_callee183);}));function useValidationFunc(_x334,_x335,_x336,_x337,_x338,_x339){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
267
+ },{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee184(e,t,n,s,r){var a,o;return _regenerator().w(function(_context184){while(1)switch(_context184.n){case 0:o=(a=t[y])==null?void 0:a.map(function(c){return c[Q];});return _context184.a(2,Nt.validate(e,n,s,t[h],o,r,!0));}},_callee184);}));function useValidationFuncProgrammatic(_x340,_x341,_x342,_x343,_x344){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!==nt.URL&&!Ee.canSendMessage(n)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
268
+ },{key:"attach",value:function attach(e,t,n,s,r,o){var a=e.validateInput||te.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref224=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee185(c){var l;return _regenerator().w(function(_context185){while(1)switch(_context185.n){case 0:if(!(r.status.loadingActive||r.status.requestInProgress||!Nt.validateWebsocket(t,r))){_context185.n=1;break;}return _context185.a(2,!1);case 1:l=a||t.canSendMessage;return _context185.a(2,l?c?Nt.useValidationFuncProgrammatic(l,c,r,t,o):Nt.useValidationFunc(l,n,s,r,t,o):null);}},_callee185);}));return function(_x345){return _ref224.apply(this,arguments);};}();}}]);}();var Vo=/*#__PURE__*/function(){function Vo(){_classCallCheck(this,Vo);}return _createClass(Vo,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 rh=/*#__PURE__*/function(_ii2){function rh(e,t){var _this110;_classCallCheck(this,rh);var n,s;_this110=_callSuper(this,rh,[t.button]),_this110._waitingForBrowserApproval=!1,_this110._audioType=e,_this110._extension=((n=t[y])==null?void 0:n.format)||"mp3",_this110._maxDurationSeconds=(s=t[y])==null?void 0:s.maxDurationSeconds,_this110.elementRef.onclick=_this110.buttonClick.bind(_assertThisInitialized(_this110));return _this110;}_inherits(rh,_ii2);return _createClass(rh,[{key:"buttonClick",value:function buttonClick(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()));}},{key:"stop",value:function stop(){var _this111=this;return new Promise(function(e){var t,n;_this111.changeToDefault(),(t=_this111._mediaRecorder)==null||t.stop(),(n=_this111._mediaStream)==null||n.getTracks().forEach(function(s){return s.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this112=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this112.changeToActive(),_this112._mediaRecorder=new MediaRecorder(e),_this112._audioType.addPlaceholderAttachment(_this112.stop.bind(_this112),_this112._maxDurationSeconds),_this112._mediaStream=e,_this112._mediaRecorder.addEventListener("dataavailable",function(t){_this112.createFile(t);}),_this112._mediaRecorder[Mt]();})["catch"](function(e){console[f](e),_this112.stop();})["finally"](function(){_this112._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this113=this;var t=new Blob([e.data],{type:"audio/".concat(this._extension)}),n=Vo.getFileName(this._newFilePrefix||P,this._extension),s=new File([t],n,{type:t.type}),r=new FileReader();r.readAsDataURL(s),r.onload=function(o){_this113._audioType.completePlaceholderAttachment(s,o.target.result);};}}]);}(ii);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 jt=/*#__PURE__*/function(){function jt(){_classCallCheck(this,jt);}return _createClass(jt,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=JSON.parse(JSON.stringify(e[t]||{}));Se.overwritePropertyObjectFromAnother(n,e.submit,["container",x]),Se.overwritePropertyObjectFromAnother(n,e.submit,[h,"styles",x]),Se.overwritePropertyObjectFromAnother(n,e.submit,["svg","styles",x]),e[t]=n;}// prettier-ignore
269
269
  },{key:"setUpDisabledButton",value:function setUpDisabledButton(e){Se.setPropertyValueIfDoesNotExist(e,["submit","container",x,"backgroundColor"],""),Se.setPropertyValueIfDoesNotExist(e,["disabled","container",x,"backgroundColor"],Jo),Se.setPropertyValueIfDoesNotExist(e.submit,["svg","styles",x,"filter"],""),Se.setPropertyValueIfDoesNotExist(e.disabled,["svg","styles",x,"filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),Se.setPropertyValueIfDoesNotExist(e.disabled,[h,"styles",x,"color"],"grey"),jt.overwriteDefaultStyleWithSubmit(e,"disabled");}},{key:"process",value:function process(e){var t=JSON.parse(JSON.stringify(e||{}));return jt.overwriteDefaultStyleWithSubmit(t,"loading"),jt.overwriteDefaultStyleWithSubmit(t,"stop"),e!=null&&e.alwaysEnabled||jt.setUpDisabledButton(t),t;}}]);}();var Yn=/*#__PURE__*/function(_Qt6){// prettier-ignore
270
270
  function Yn(e,t,n,s,r,o){var _this114;_classCallCheck(this,Yn);var a=jt.process(e.submitButtonStyles),c=oh,l=tt.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this114=_callSuper(this,Yn,[Yn.createButtonContainerElement(),c,a==null?void 0:a.position,l,a]),_this114._isSVGLoadingIconOverriden=!1,_this114.status={requestInProgress:!1,loadingActive:!1},_this114._messages=n,_this114._textInput=t,_this114._fileAttachments=r,_this114._innerElements=_this114.createInnerElementsForStates(),_this114._stopClicked={listener:function listener(){}},_this114._serviceIO=s,_this114._alwaysEnabled=!!(a!=null&&a.alwaysEnabled),e.disableSubmitButton=_this114.disableSubmitButton.bind(_assertThisInitialized(_this114),s),_this114.attemptOverwriteLoadingStyle(e),o.microphone&&_this114.setUpSpeechToText(o.microphone.button,e.speechToText),setTimeout(function(){var d;_this114._validationHandler=e._validationHandler,_this114.assignHandlers(_this114._validationHandler),(d=_this114._validationHandler)==null||d.call(_assertThisInitialized(_this114));});return _this114;}_inherits(Yn,_Qt6);return _createClass(Yn,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(){var _this$createCustomEle=this.createCustomElements(),e=_this$createCustomEle.submit,t=_this$createCustomEle.loading,n=_this$createCustomEle.stop;return{submit:e,loading:t||[Yn.createLoadingIconElement()],stop:n||[Yn.createStopIconElement()],disabled:this.createDisabledIconElement(e)};}},{key:"createCustomElements",value:function createCustomElements(){var _this115=this;var e=lt.createCustomElements("submit",this.svg,this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(n){var s=n,r=lt.createCustomElements(s,_this115.svg,_this115.customStyles);r&&(t[s]=r);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return lt.createCustomElements("disabled",this.svg,this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
271
- },{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=S("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 _callee185(){var _this116=this;var e,t;return _regenerator().w(function(_context185){while(1)switch(_context185.n){case 0:_context185.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));}(Oe.IS_SAFARI||Oe.IS_MOBILE)&&setTimeout(function(){return zt.focusEndOfInput(_this116._textInput.inputElementRef);});case 2:return _context185.a(2);}},_callee185,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee186(e){var _this117=this;var t;return _regenerator().w(function(_context186){while(1)switch(_context186.n){case 0:typeof e=="string"&&(e=te.processSubmitUserMessage(e));t=_defineProperty({},h,e[h]);e[y]&&(t[y]=Array.from(e[y]).map(function(n){return{file:n,type:gt.getTypeFromBlob(n)};})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this117.attemptSubmit(t,!0);});case 1:return _context186.a(2);}},_callee186);}));function programmaticSubmit(_x346){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
272
- },{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee187(e){var _this118=this;var t,r,o,a,c,n,s,_args187=arguments,_t53,_t54,_t55;return _regenerator().w(function(_context187){while(1)switch(_context187.n){case 0:t=_args187.length>1&&_args187[1]!==undefined?_args187[1]:!1;_context187.n=1;return(r=this._validationHandler)==null?void 0:r.call(this,t?e:void 0);case 1:_t53=_context187.v;_t54=!1;if(!(_t53===_t54)){_context187.n=2;break;}return _context187.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();Oe.IS_MOBILE&&setTimeout(function(){return _this118._textInput.inputElementRef.focus();});_t55=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t55){_context187.n=3;break;}_context187.n=3;return Is.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context187.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[Q];}),s=_defineProperty(_defineProperty({},h,e[h]===""?void 0:e[h]),y,n);_context187.n=5;return this._serviceIO.callAPI(s,this._messages);case 5:(c=this._fileAttachments)==null||c.hideFiles();case 6:return _context187.a(2);}},_callee187,this);}));function attemptSubmit(_x347){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee188(_ref224){var e,t,n,s,_t56;return _regenerator().w(function(_context188){while(1)switch(_context188.n){case 0:e=_ref224.text,t=_ref224.files,n=_ref224.custom;s={role:U,custom:n};e&&(s[h]=e);_t56=t;if(!_t56){_context188.n=2;break;}_context188.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:s[y]=_context188.v;case 2:this._serviceIO.sessionId&&(s._sessionId=this._serviceIO.sessionId);Object.keys(s).length>0&&this._messages.addNewMessage(s);case 3:return _context188.a(2);}},_callee188,this);}));function addNewMessage(_x348){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(Es,An,xn),se.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle("stop",["loading","submit"]),this.elementRef.onclick=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(xn,An),se.removeAriaDisabled(this.elementRef),this.elementRef[m].add(Es),se.addAriaBusy(this.elementRef),this.reapplyStateStyle("loading",["submit"]),this.elementRef.onclick=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
271
+ },{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=S("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 _callee186(){var _this116=this;var e,t;return _regenerator().w(function(_context186){while(1)switch(_context186.n){case 0:_context186.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));}(Oe.IS_SAFARI||Oe.IS_MOBILE)&&setTimeout(function(){return zt.focusEndOfInput(_this116._textInput.inputElementRef);});case 2:return _context186.a(2);}},_callee186,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee187(e){var _this117=this;var t;return _regenerator().w(function(_context187){while(1)switch(_context187.n){case 0:typeof e=="string"&&(e=te.processSubmitUserMessage(e));t=_defineProperty({},h,e[h]);e[y]&&(t[y]=Array.from(e[y]).map(function(n){return{file:n,type:gt.getTypeFromBlob(n)};})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this117.attemptSubmit(t,!0);});case 1:return _context187.a(2);}},_callee187);}));function programmaticSubmit(_x346){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
272
+ },{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee188(e){var _this118=this;var t,r,o,a,c,n,s,_args188=arguments,_t53,_t54,_t55;return _regenerator().w(function(_context188){while(1)switch(_context188.n){case 0:t=_args188.length>1&&_args188[1]!==undefined?_args188[1]:!1;_context188.n=1;return(r=this._validationHandler)==null?void 0:r.call(this,t?e:void 0);case 1:_t53=_context188.v;_t54=!1;if(!(_t53===_t54)){_context188.n=2;break;}return _context188.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();Oe.IS_MOBILE&&setTimeout(function(){return _this118._textInput.inputElementRef.focus();});_t55=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t55){_context188.n=3;break;}_context188.n=3;return Is.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context188.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[Q];}),s=_defineProperty(_defineProperty({},h,e[h]===""?void 0:e[h]),y,n);_context188.n=5;return this._serviceIO.callAPI(s,this._messages);case 5:(c=this._fileAttachments)==null||c.hideFiles();case 6:return _context188.a(2);}},_callee188,this);}));function attemptSubmit(_x347){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee189(_ref225){var e,t,n,s,_t56;return _regenerator().w(function(_context189){while(1)switch(_context189.n){case 0:e=_ref225.text,t=_ref225.files,n=_ref225.custom;s={role:U,custom:n};e&&(s[h]=e);_t56=t;if(!_t56){_context189.n=2;break;}_context189.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:s[y]=_context189.v;case 2:this._serviceIO.sessionId&&(s._sessionId=this._serviceIO.sessionId);Object.keys(s).length>0&&this._messages.addNewMessage(s);case 3:return _context189.a(2);}},_callee189,this);}));function addNewMessage(_x348){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(Es,An,xn),se.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle("stop",["loading","submit"]),this.elementRef.onclick=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(xn,An),se.removeAriaDisabled(this.elementRef),this.elementRef[m].add(Es),se.addAriaBusy(this.elementRef),this.reapplyStateStyle("loading",["submit"]),this.elementRef.onclick=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
273
273
  },{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this119=this;this.elementRef[m].contains(xn)||(this.elementRef[m].remove(Es,An),se.removeAriaAttributes(this.elementRef),this.elementRef[m].add(xn),this.changeElementsByState(this._innerElements.submit),jt.resetSubmit(this,this.status.loadingActive),this.elementRef.onclick=function(){var e;_this119.submitFromInput(),(e=_this119._microphoneButton)!=null&&e.isActive&&hs.toggleSpeechAfterSubmit(_this119._microphoneButton.elementRef,!!_this119._stopSTTAfterSubmit),setTimeout(function(){return zt.focusEndOfInput(_this119._textInput.inputElementRef);});});}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
274
274
  },{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(An)||(this.elementRef[m].remove(Es,xn),se.removeAriaBusy(this.elementRef),this.elementRef[m].add(An),se.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements.disabled),this.reapplyStateStyle("disabled",["submit"]),this.elementRef.onclick=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=S();return e[m].add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=S();return e[m].add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=S();return e.id="stop-icon",e;}}]);}(Qt);var ah="<?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",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=\"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",lh="<?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>",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=\"M4.89163 13.2687L9.16582 17.5427L18.7085 8\" stroke=\"#000000\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>";var ar=/*#__PURE__*/function(_Ht){// prettier-ignore
275
275
  function ar(e,t,n,s){var _this120;_classCallCheck(this,ar);_this120=_callSuper(this,ar,[e,["modal-content","modal-camera-content"],n]),_this120._stopped=!1,_this120._format="image/png",_this120._canvas=S("canvas"),_this120._canvas[m].add("camera-modal-canvas");var _this120$addButtonsAn=_this120.addButtonsAndTheirEvents(t),r=_this120$addButtonsAn.captureButton,o=_this120$addButtonsAn.submitButton;_this120._captureButton=r,_this120._submitButton=o,_this120._captureIcon=_this120._captureButton.children[0],_this120._refreshIcon=_t.createSVGElement(ah),_this120._refreshIcon[m].add("modal-svg-button-icon","modal-svg-refresh-icon"),(s==null?void 0:s.format)==="jpeg"&&(_this120._format="image/jpeg"),s!=null&&s.dimensions&&(_this120._dimensions=s.dimensions),_this120._contentRef.appendChild(_this120._canvas),_this120.extensionCloseCallback=_this120.stop;return _this120;}_inherits(ar,_Ht);return _createClass(ar,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=Ht.createSVGButton(ch);t[m].add("modal-svg-camera-button"),t.children[0][m].add("modal-svg-camera-icon");var n=this.addCloseButton(lh,!0);n[m].add("modal-svg-close-button"),n.children[0][m].add("modal-svg-close-icon");var s=Ht.createSVGButton(dh);return s[m].add("modal-svg-submit-button"),this.addButtons(t,s),this.addButtonEvents(t,n,s,e),{captureButton:t,submitButton:s};}// prettier-ignore
@@ -278,5 +278,5 @@ function ar(e,t,n,s){var _this120;_classCallCheck(this,ar);_this120=_callSuper(t
278
278
  function addClickEvent(e,t,n,s){var r=ar.createCameraModalFunc(e,t,n,s);this.elementRef.onclick=r;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=S();return e[m].add("input-button"),e;}}]);}(Qt);var nn=/*#__PURE__*/function(){function nn(e,t,n,s){_classCallCheck(this,nn);this.elementRef=nn.createPanelElement(e.inputAreaStyle);var r={},o=this.createFileUploadComponents(e,n,s,r),a=new Rs(e,n,o,t.browserStorage);e.speechToText&&!r.microphone&&(r.microphone={button:new hs(e,a,t.addNewErrorMessage.bind(t))});var c=new Yn(e,a,t,n,o,r);a.submit=c.submitFromInput.bind(c),Nt.attach(e,n,a,o,c,t.browserStorage),e.submitUserMessage=c.programmaticSubmit.bind(c),r.submit={button:c},e.customButtons&&$t.add(e,r),nn.addElements(this.elementRef,a,r,s,o,e.dropupStyles),nn.assignOnInput(e,n,o,a);}return _createClass(nn,[{key:"createFileUploadComponents",value:// prettier-ignore
279
279
  function createFileUploadComponents(e,t,n,s){var o,a,c,l;var r=new ms(this.elementRef,e.attachmentContainerStyle,t.demo);if(nn.createUploadButtons(e,t,t.fileTypes||{},r,n,s),(o=t[Re])!=null&&o[y]){var d=((a=s[V])==null?void 0:a.fileType)||r.addType(e,t,t[Re][y],V);s[Re]={button:new cr(n,d,t[Re])};}if((c=t.recordAudio)!=null&&c[y]){var _d3=((l=s[P])==null?void 0:l.fileType)||r.addType(e,t,t.recordAudio[y],P);s.microphone={button:new rh(_d3,t.recordAudio)};}return mt.isEnabled(r,e.dragAndDrop)&&mt.create(n,r,e.dragAndDrop),r;}// prettier-ignore
280
280
  }],[{key:"createPanelElement",value:function createPanelElement(e){var t=S();return t.id="input",Object.assign(t[_],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),_Ud$c=Ud[c],p=_Ud$c.id,u=_Ud$c.svgString,g=_Ud$c.dropupText,b=new Js(r,d,l,p,u,g);o[c]={button:b,fileType:d};}});}// prettier-ignore
281
- },{key:"addElements",value:function addElements(e,t,n,s,r,o){ce.addElements(e,t.elementRef);var a=gn.create(),c=we.addButtons(a,n,s,o);Zn.set(t.inputElementRef,a,r.elementRef,c),gn.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[Q];})),Jt.onInput(e,c,r);});};}}]);}();var lr=/*#__PURE__*/function(){function lr(){_classCallCheck(this,lr);}return _createClass(lr,null,[{key:"createElements",value:function createElements(e,t,n){var s=S();s.id="chat-view";var r=!e.focusMode&&e.upwardsMode;s.classList.add(r?Md:Id);var o=new Ve(e,t,n);t.websocket&&Ee.createConnection(t,o);var a=new nn(e,o,t,s),c=r?o.elementRef.parentElement:o.elementRef;return ce.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=lr.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var uh="#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%}#hidden-messages{position:absolute;top:75%;left:50%;right:50%;transform:translate(-50%,-50%);padding:8px;width:fit-content;height:fit-content;background-color:#fff;border:.5px solid #000000;z-index:2;display:none;justify-content:center;align-items:center;border-radius:10px;white-space:nowrap;cursor:pointer}#hidden-messages: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 ph=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&&ph(e,t,s),s;};var M=/*#__PURE__*/function(_Si){function M(){var _this125;_classCallCheck(this,M);var e;_this125=_callSuper(this,M),_this125.getMessages=function(){return[];},_this125.submitUserMessage=function(){return console.warn(gr("submitUserMessage"));},_this125.addMessage=function(){return console.warn(gr("addMessage"));},_this125.updateMessage=function(){},_this125.clearMessages=function(){},_this125.focusInput=function(){return zt.focusFromParentElement(_this125._elementRef);},_this125.refreshMessages=function(){},_this125.scrollToBottom=function(){},_this125.disableSubmitButton=function(){},_this125.setPlaceholderText=function(){},_this125._hasBeenRendered=!1,_this125._auxiliaryStyleApplied=!1,_this125._elementRef=S(),_this125._elementRef.id="container",_this125.attachShadow({mode:"open"}).appendChild(_this125._elementRef),(e=_this125.shadowRoot)==null||e.appendChild(tt.buildElement()),Jn.apply(uh,_this125.shadowRoot),setTimeout(function(){_this125._hasBeenRendered||_this125.onRender();},20);return _this125;}_inherits(M,_Si);return _createClass(M,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
282
- },{key:"onRender",value:function onRender(){var _this$_childElement;Ts.attemptAppendStyleSheetToHead(this.style),te.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=Rd.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(Jn.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),Jn.applyDefaultStyleToComponent(this.style,this.chatStyle),te.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?ws.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof R)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],lr.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof R&&Ae.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||Jt.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){ls.chat=void 0;}}]);}(Si);O([k("object")],M.prototype,"connect");O([k("object")],M.prototype,"directConnection");O([k("object")],M.prototype,"webModel");O([k("object")],M.prototype,"requestBodyLimits");O([k("function")],M.prototype,"requestInterceptor");O([k("function")],M.prototype,"responseInterceptor");O([k("function")],M.prototype,"validateInput");O([k("function")],M.prototype,"loadHistory");O([k("object")],M.prototype,"chatStyle");O([k("object")],M.prototype,"attachmentContainerStyle");O([k("object")],M.prototype,"dropupStyles");O([k("object")],M.prototype,"inputAreaStyle");O([k("object")],M.prototype,"textInput");O([k("object")],M.prototype,"defaultInput");O([k("object")],M.prototype,"submitButtonStyles");O([k("object")],M.prototype,"customButtons");O([k("string")],M.prototype,"auxiliaryStyle");O([k("array")],M.prototype,"history");O([k("object")],M.prototype,"browserStorage");O([k("object")],M.prototype,"introMessage");O([k("object")],M.prototype,"avatars");O([k("object")],M.prototype,"names");O([k("object")],M.prototype,"displayLoadingBubble");O([k("object")],M.prototype,"errorMessages");O([k("object")],M.prototype,"messageStyles");O([k("object")],M.prototype,"textToSpeech");O([k("object")],M.prototype,"speechToText");O([k("object")],M.prototype,"images");O([k("object")],M.prototype,"gifs");O([k("object")],M.prototype,"camera");O([k("object")],M.prototype,"audio");O([k("object")],M.prototype,"microphone");O([k("object")],M.prototype,"mixedFiles");O([k("object")],M.prototype,"dragAndDrop");O([k("object")],M.prototype,"htmlWrappers");O([k("object")],M.prototype,"htmlClassUtilities");O([k("object")],M.prototype,"remarkable");O([k("object")],M.prototype,"focusMode");O([k("boolean")],M.prototype,"upwardsMode");O([k("object")],M.prototype,"hiddenMessages");O([k("number")],M.prototype,"maxVisibleMessages");O([k("function")],M.prototype,"onMessage");O([k("function")],M.prototype,"onClearMessages");O([k("function")],M.prototype,"onComponentRender");O([k("function")],M.prototype,"onInput");O([k("function")],M.prototype,"onError");O([k("object")],M.prototype,"demo");O([k("object")],M.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",M);export{M as DeepChat};
281
+ },{key:"addElements",value:function addElements(e,t,n,s,r,o){oe.addElements(e,t.elementRef);var a=gn.create(),c=we.addButtons(a,n,s,o);Zn.set(t.inputElementRef,a,r.elementRef,c),gn.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[Q];})),Jt.onInput(e,c,r);});};}}]);}();var lr=/*#__PURE__*/function(){function lr(){_classCallCheck(this,lr);}return _createClass(lr,null,[{key:"createElements",value:function createElements(e,t,n){var s=S();s.id="chat-view";var r=!e.focusMode&&e.upwardsMode;s.classList.add(r?Md:Id);var o=new Ve(e,t,n);t.websocket&&Ee.createConnection(t,o);var a=new nn(e,o,t,s),c=r?o.elementRef.parentElement:o.elementRef;return oe.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=lr.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var uh="#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;width:fit-content;height:fit-content;background-color:#fff;border:.5px solid #000000;z-index:2;justify-content:center;align-items:center;border-radius:10px;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 ph=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&&ph(e,t,s),s;};var I=/*#__PURE__*/function(_Si){function I(){var _this125;_classCallCheck(this,I);var e;_this125=_callSuper(this,I),_this125.getMessages=function(){return[];},_this125.submitUserMessage=function(){return console.warn(gr("submitUserMessage"));},_this125.addMessage=function(){return console.warn(gr("addMessage"));},_this125.updateMessage=function(){},_this125.clearMessages=function(){},_this125.focusInput=function(){return zt.focusFromParentElement(_this125._elementRef);},_this125.refreshMessages=function(){},_this125.scrollToBottom=function(){},_this125.disableSubmitButton=function(){},_this125.setPlaceholderText=function(){},_this125._hasBeenRendered=!1,_this125._auxiliaryStyleApplied=!1,_this125._elementRef=S(),_this125._elementRef.id="container",_this125.attachShadow({mode:"open"}).appendChild(_this125._elementRef),(e=_this125.shadowRoot)==null||e.appendChild(tt.buildElement()),Jn.apply(uh,_this125.shadowRoot),setTimeout(function(){_this125._hasBeenRendered||_this125.onRender();},20);return _this125;}_inherits(I,_Si);return _createClass(I,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
282
+ },{key:"onRender",value:function onRender(){var _this$_childElement;Ts.attemptAppendStyleSheetToHead(this.style),te.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=Rd.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(Jn.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),Jn.applyDefaultStyleToComponent(this.style,this.chatStyle),te.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?ws.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof R)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],lr.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof R&&Ae.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||Jt.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){ls.chat=void 0;}}]);}(Si);O([k("object")],I.prototype,"connect");O([k("object")],I.prototype,"directConnection");O([k("object")],I.prototype,"webModel");O([k("object")],I.prototype,"requestBodyLimits");O([k("function")],I.prototype,"requestInterceptor");O([k("function")],I.prototype,"responseInterceptor");O([k("function")],I.prototype,"validateInput");O([k("function")],I.prototype,"loadHistory");O([k("object")],I.prototype,"chatStyle");O([k("object")],I.prototype,"attachmentContainerStyle");O([k("object")],I.prototype,"dropupStyles");O([k("object")],I.prototype,"inputAreaStyle");O([k("object")],I.prototype,"textInput");O([k("object")],I.prototype,"defaultInput");O([k("object")],I.prototype,"submitButtonStyles");O([k("object")],I.prototype,"customButtons");O([k("string")],I.prototype,"auxiliaryStyle");O([k("array")],I.prototype,"history");O([k("object")],I.prototype,"browserStorage");O([k("object")],I.prototype,"introMessage");O([k("object")],I.prototype,"avatars");O([k("object")],I.prototype,"names");O([k("object")],I.prototype,"displayLoadingBubble");O([k("object")],I.prototype,"errorMessages");O([k("object")],I.prototype,"messageStyles");O([k("object")],I.prototype,"textToSpeech");O([k("object")],I.prototype,"speechToText");O([k("object")],I.prototype,"images");O([k("object")],I.prototype,"gifs");O([k("object")],I.prototype,"camera");O([k("object")],I.prototype,"audio");O([k("object")],I.prototype,"microphone");O([k("object")],I.prototype,"mixedFiles");O([k("object")],I.prototype,"dragAndDrop");O([k("object")],I.prototype,"htmlWrappers");O([k("object")],I.prototype,"htmlClassUtilities");O([k("object")],I.prototype,"remarkable");O([k("object")],I.prototype,"focusMode");O([k("boolean")],I.prototype,"upwardsMode");O([k("object")],I.prototype,"hiddenMessages");O([k("object")],I.prototype,"scrollButton");O([k("number")],I.prototype,"maxVisibleMessages");O([k("function")],I.prototype,"onMessage");O([k("function")],I.prototype,"onClearMessages");O([k("function")],I.prototype,"onComponentRender");O([k("function")],I.prototype,"onInput");O([k("function")],I.prototype,"onError");O([k("object")],I.prototype,"demo");O([k("object")],I.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",I);export{I as DeepChat};