deep-chat-dev 9.0.292 → 9.0.294
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/custom-elements.json +15708 -16351
- package/dist/deepChat.bundle.js +1 -1
- package/dist/deepChat.d.ts +2 -0
- package/dist/deepChat.d.ts.map +1 -1
- package/dist/deepChat.js +157 -154
- package/dist/services/assemblyAI/assemblyAIAudioIO.d.ts.map +1 -1
- package/dist/services/grok/grokImagesIO.d.ts.map +1 -1
- package/dist/services/openAI/openAIImagesIO.d.ts.map +1 -1
- package/dist/services/openAI/openAISpeechToTextIO.d.ts.map +1 -1
- package/dist/services/openAI/openAITextToSpeechIO.d.ts.map +1 -1
- package/dist/services/serviceIOFactory.d.ts.map +1 -1
- package/dist/services/stabilityAI/stabilityAIImageToImageIO.d.ts.map +1 -1
- package/dist/services/stabilityAI/stabilityAIImageToImageMaskingIO.d.ts.map +1 -1
- package/dist/services/stabilityAI/stabilityAIImageToImageUpscaleIO.d.ts.map +1 -1
- package/dist/services/stabilityAI/stabilityAITextToImageIO.d.ts.map +1 -1
- package/dist/types/directConnection.d.ts +1 -3
- package/dist/types/directConnection.d.ts.map +1 -1
- package/dist/types/stream.d.ts +0 -1
- package/dist/types/stream.d.ts.map +1 -1
- package/dist/utils/legacy/legacy.d.ts +2 -0
- package/dist/utils/legacy/legacy.d.ts.map +1 -1
- package/dist/views/chat/messages/html/htmlMessages.d.ts.map +1 -1
- package/dist/views/chat/messages/html/htmlUtils.d.ts +7 -0
- package/dist/views/chat/messages/html/htmlUtils.d.ts.map +1 -1
- package/dist/views/chat/messages/messagesBase.d.ts +3 -1
- package/dist/views/chat/messages/messagesBase.d.ts.map +1 -1
- package/dist/views/chat/messages/stream/messageStream.d.ts +1 -3
- package/dist/views/chat/messages/stream/messageStream.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/services/elevenlabs/elevenLabsTextToSpeechIO.d.ts +0 -22
- package/dist/services/elevenlabs/elevenLabsTextToSpeechIO.d.ts.map +0 -1
- package/dist/services/elevenlabs/utils/elevenLabsUtils.d.ts +0 -9
- package/dist/services/elevenlabs/utils/elevenLabsUtils.d.ts.map +0 -1
- package/dist/types/elevenLabsResult.d.ts +0 -6
- package/dist/types/elevenLabsResult.d.ts.map +0 -1
- package/dist/types/elevenlabs.d.ts +0 -17
- package/dist/types/elevenlabs.d.ts.map +0 -1
package/dist/deepChat.js
CHANGED
@@ -1,27 +1,28 @@
|
|
1
|
-
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 _n5=0,F=function F(){};return{s:F,n:function n(){return _n5>=r.length?{done:!0}:{done:!1,value:r[_n5++]};},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 _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */_regeneratorRuntime=function _regeneratorRuntime(){return r;};var t,r={},e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,r,e,n){return Object.defineProperty(t,r,{value:e,enumerable:!n,configurable:!n,writable:!n});}try{c({},"");}catch(t){c=function c(t,r,e){return t[r]=e;};}function h(r,e,n,o){var i=e&&e.prototype instanceof Generator?e:Generator,a=Object.create(i.prototype);return c(a,"_invoke",function(r,e,n){var o=1;return function(i,a){if(3===o)throw Error("Generator is already running");if(4===o){if("throw"===i)throw a;return{value:t,done:!0};}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=d(u,n);if(c){if(c===f)continue;return c;}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(1===o)throw o=4,n.arg;n.dispatchException(n.arg);}else"return"===n.method&&n.abrupt("return",n.arg);o=3;var h=s(r,e,n);if("normal"===h.type){if(o=n.done?4:2,h.arg===f)continue;return{value:h.arg,done:n.done};}"throw"===h.type&&(o=4,n.method="throw",n.arg=h.arg);}};}(r,n,new Context(o||[])),!0),a;}function s(t,r,e){try{return{type:"normal",arg:t.call(r,e)};}catch(t){return{type:"throw",arg:t};}}r.wrap=h;var f={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}var l={};c(l,i,function(){return this;});var p=Object.getPrototypeOf,y=p&&p(p(x([])));y&&y!==e&&n.call(y,i)&&(l=y);var v=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(l);function g(t){["next","throw","return"].forEach(function(r){c(t,r,function(t){return this._invoke(r,t);});});}function AsyncIterator(t,r){function e(o,i,a,u){var c=s(t[o],t,i);if("throw"!==c.type){var h=c.arg,f=h.value;return f&&"object"==_typeof(f)&&n.call(f,"__await")?r.resolve(f.__await).then(function(t){e("next",t,a,u);},function(t){e("throw",t,a,u);}):r.resolve(f).then(function(t){h.value=t,a(h);},function(t){return e("throw",t,a,u);});}u(c.arg);}var o;c(this,"_invoke",function(t,n){function i(){return new r(function(r,o){e(t,n,r,o);});}return o=o?o.then(i,i):i();},!0);}function d(r,e){var n=e.method,o=r.i[n];if(o===t)return e.delegate=null,"throw"===n&&r.i["return"]&&(e.method="return",e.arg=t,d(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),f;var i=s(o,r.i,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,f;var a=i.arg;return a?a.done?(e[r.r]=a.value,e.next=r.n,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,f):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f);}function w(t){this.tryEntries.push(t);}function m(r){var e=r[4]||{};e.type="normal",e.arg=t,r[4]=e;}function Context(t){this.tryEntries=[[-1]],t.forEach(w,this),this.reset(!0);}function x(r){if(null!=r){var e=r[i];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,a=function e(){for(;++o<r.length;)if(n.call(r,o))return e.value=r[o],e.done=!1,e;return e.value=t,e.done=!0,e;};return a.next=a;}}throw new TypeError(_typeof(r)+" is not iterable");}return GeneratorFunction.prototype=GeneratorFunctionPrototype,c(v,"constructor",GeneratorFunctionPrototype),c(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName=c(GeneratorFunctionPrototype,u,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===GeneratorFunction||"GeneratorFunction"===(r.displayName||r.name));},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,GeneratorFunctionPrototype):(t.__proto__=GeneratorFunctionPrototype,c(t,u,"GeneratorFunction")),t.prototype=Object.create(v),t;},r.awrap=function(t){return{__await:t};},g(AsyncIterator.prototype),c(AsyncIterator.prototype,a,function(){return this;}),r.AsyncIterator=AsyncIterator,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new AsyncIterator(h(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then(function(t){return t.done?t.value:a.next();});},g(v),c(v,u,"Generator"),c(v,i,function(){return this;}),c(v,"toString",function(){return"[object Generator]";}),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.unshift(n);return function t(){for(;e.length;)if((n=e.pop())in r)return t.value=n,t.done=!1,t;return t.done=!0,t;};},r.values=x,Context.prototype={constructor:Context,reset:function reset(r){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(m),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t);},stop:function stop(){this.done=!0;var t=this.tryEntries[0][4];if("throw"===t.type)throw t.arg;return this.rval;},dispatchException:function dispatchException(r){if(this.done)throw r;var e=this;function n(t){a.type="throw",a.arg=r,e.next=t;}for(var o=e.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i[4],u=this.prev,c=i[1],h=i[2];if(-1===i[0])return n("end"),!1;if(!c&&!h)throw Error("try statement without catch or finally");if(null!=i[0]&&i[0]<=u){if(u<c)return this.method="next",this.arg=t,n(c),!0;if(u<h)return n(h),!1;}}},abrupt:function abrupt(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n[0]>-1&&n[0]<=this.prev&&this.prev<n[2]){var o=n;break;}}o&&("break"===t||"continue"===t)&&o[0]<=r&&r<=o[2]&&(o=null);var i=o?o[4]:{};return i.type=t,i.arg=r,o?(this.method="next",this.next=o[2],f):this.complete(i);},complete:function complete(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),f;},finish:function finish(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e[2]===t)return this.complete(e[4],e[3]),m(e),f;}},"catch":function _catch(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e[0]===t){var n=e[4];if("throw"===n.type){var o=n.arg;m(e);}return o;}}throw Error("illegal catch attempt");},delegateYield:function delegateYield(r,e,n){return this.delegate={i:x(r),r:e,n:n},"next"===this.method&&(this.arg=t),f;}},r;}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 rr=/*#__PURE__*/function(){function rr(){_classCallCheck(this,rr);}return _createClass(rr,null,[{key:"render",value:function render(e,t){var s=document.createElement("div");s.id="error-view",s.innerText=t,e.replaceChildren(s);}}]);}();var _s=/*#__PURE__*/function(){function _s(){_classCallCheck(this,_s);}return _createClass(_s,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=document.createElement("div");return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,s){var i=_s.createElements(),n={onSuccess:t,onFail:rr.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:_s.onLoad.bind(this,i)};s.key&&s.verifyKey(s.key,n),e.replaceChildren(i);}}]);}();var P=/*#__PURE__*/function(){function P(){_classCallCheck(this,P);}return _createClass(P,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var s=Object.keys(t).reduce(function(i,n){return i[n]="",i;},{});Object.assign(e.style,s);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t.click&&P.unsetStyle(e,t.click),t.hover&&P.unsetStyle(e,t.hover);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){P.unsetActivityCSSMouseStates(e,t),t["default"]&&P.unsetStyle(e,t["default"]);}// if you want to asdd default styling - use pure css classes
|
2
|
-
},{key:"processStateful",value:function processStateful(e){var t=e["default"]||{},s=Object.assign(JSON.parse(JSON.stringify(t)),e==null?void 0:e.hover),i=Object.assign(JSON.parse(JSON.stringify(s)),e==null?void 0:e.click);return{"default":t,hover:s,click:i};}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t={"default":{},hover:{},click:{}};return e.forEach(function(s){t["default"]=Object.assign(t["default"],s["default"]),t.hover=Object.assign(t.hover,s.hover),t.click=Object.assign(t.click,s.click);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e["default"]||[]).forEach(function(s){var n;var i=s;t.style[i]&&(n=e["default"])!=null&&n[i]&&(e["default"][s]=t.style[i]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var s in t){var i=t[s];e[s]===""&&i&&(e[s]=i);}}}]);}();var
|
1
|
+
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 _n5=0,F=function F(){};return{s:F,n:function n(){return _n5>=r.length?{done:!0}:{done:!1,value:r[_n5++]};},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 ir=/*#__PURE__*/function(){function ir(){_classCallCheck(this,ir);}return _createClass(ir,null,[{key:"render",value:function render(e,t){var s=document.createElement("div");s.id="error-view",s.innerText=t,e.replaceChildren(s);}}]);}();var _s=/*#__PURE__*/function(){function _s(){_classCallCheck(this,_s);}return _createClass(_s,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=document.createElement("div");return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,s){var i=_s.createElements(),n={onSuccess:t,onFail:ir.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:_s.onLoad.bind(this,i)};s.key&&s.verifyKey(s.key,n),e.replaceChildren(i);}}]);}();var N=/*#__PURE__*/function(){function N(){_classCallCheck(this,N);}return _createClass(N,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var s=Object.keys(t).reduce(function(i,n){return i[n]="",i;},{});Object.assign(e.style,s);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t.click&&N.unsetStyle(e,t.click),t.hover&&N.unsetStyle(e,t.hover);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){N.unsetActivityCSSMouseStates(e,t),t["default"]&&N.unsetStyle(e,t["default"]);}// if you want to asdd default styling - use pure css classes
|
2
|
+
},{key:"processStateful",value:function processStateful(e){var t=e["default"]||{},s=Object.assign(JSON.parse(JSON.stringify(t)),e==null?void 0:e.hover),i=Object.assign(JSON.parse(JSON.stringify(s)),e==null?void 0:e.click);return{"default":t,hover:s,click:i};}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t={"default":{},hover:{},click:{}};return e.forEach(function(s){t["default"]=Object.assign(t["default"],s["default"]),t.hover=Object.assign(t.hover,s.hover),t.click=Object.assign(t.click,s.click);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e["default"]||[]).forEach(function(s){var n;var i=s;t.style[i]&&(n=e["default"])!=null&&n[i]&&(e["default"][s]=t.style[i]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var s in t){var i=t[s];e[s]===""&&i&&(e[s]=i);}}}]);}();var Ze=/*#__PURE__*/function(){function Ze(){_classCallCheck(this,Ze);}return _createClass(Ze,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==Ze.DEFAULT_FONT_FAMILY)return;var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(i){return i.getAttribute("href")===Ze.FONT_URL;})){var i=document.createElement("link");i.rel="stylesheet",i.href=Ze.FONT_URL,t.appendChild(i);}}}]);}();Ze.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",Ze.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var Ss=Ze;var bt=/*#__PURE__*/function(){function bt(){_classCallCheck(this,bt);}return _createClass(bt,null,[{key:"apply",value:function apply(e,t){if(t)try{bt.applyStyleSheet(e,t);}catch(_unused){bt.addStyleElement(e,t);}}},{key:"applyStyleSheet",value:function applyStyleSheet(e,t){var s=new CSSStyleSheet();s.replaceSync(e),t.adoptedStyleSheets.push(s);}},{key:"addStyleElement",value:function addStyleElement(e,t){var s=document.createElement("style");s.innerHTML=e,t.appendChild(s);}},{key:"applyDefaultStyleToComponent",value:function applyDefaultStyleToComponent(e,t){t&&N.applyToStyleIfNotDefined(e,t),N.applyToStyleIfNotDefined(e,bt.DEFAULT_COMPONENT_STYLE);}}]);}();bt.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:Ss.DEFAULT_FONT_FAMILY,fontSize:"0.9rem",backgroundColor:"white",position:"relative",// this is used to prevent inputAreaStyle background color from going beyond the container's rounded border
|
3
3
|
// it will cause issues if there are elements that are meant to be outside of the chat component and in
|
4
4
|
// that instance they should overwrite this
|
5
5
|
// this is also causing the chat to squeeze when there is no space
|
6
|
-
overflow:"hidden"};var
|
7
|
-
function add(e,t,s,i){s!==void 0&&e.addEventListener("keydown",
|
6
|
+
overflow:"hidden"};var $t=bt;var Qe=/*#__PURE__*/function(){function Qe(){_classCallCheck(this,Qe);}return _createClass(Qe,null,[{key:"buildElement",value:function buildElement(){var e=document.createElement("div");e.classList.add("tooltip");var t=document.createElement("span");return t.classList.add("tooltip-text"),e.appendChild(t),e;}},{key:"tryCreateConfig",value:function tryCreateConfig(e,t){if(t)return typeof t=="boolean"?{text:e}:{text:t.text||e,timeout:t.timeout||0,style:t.style};}},{key:"traverseParentUntilContainer",value:function traverseParentUntilContainer(e){var t=e;for(;t.parentElement;)t=t.parentElement;return t;}},{key:"setPosition",value:function setPosition(e,t){var i=t.getRootNode().host.getBoundingClientRect(),n=e.getBoundingClientRect(),a=t.getBoundingClientRect().width/2,l=n.left+n.width/2;t.style.left="".concat(l-a-i.left,"px"),t.style.top="".concat(n.top-36-i.top,"px");var c=t.getBoundingClientRect();c.left<i.left?t.style.left="".concat(Qe.OVERFLOW_NEW_POSITION_PX,"px"):c.right>i.right&&(t.style.left="".concat(i.width-c.width-Qe.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,s){return s||(s=Qe.traverseParentUntilContainer(e).nextSibling),t.text&&(s.children[0].textContent=t.text),{timeout:setTimeout(function(){s.style.visibility="visible",Qe.setPosition(e,s),t.style&&Object.assign(s.style,t.style);},t.timeout||0),element:s};}},{key:"hide",value:function hide(e,t){clearTimeout(e.timeout),e.element.style.visibility="hidden",t.style&&N.unsetStyle(e.element,t.style),e.element.style.left="",e.element.style.top="";}}]);}();Qe.OVERFLOW_NEW_POSITION_PX=4;var Se=Qe;var Zt=/*#__PURE__*/_createClass(function Zt(){_classCallCheck(this,Zt);});Zt.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Zt.IS_CHROMIUM=window.chrome,Zt.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var He=Zt;var V=/* @__PURE__ */function(r){return r.ESCAPE="Escape",r.ENTER="Enter",r.TAB="Tab",r.ARROW_UP="ArrowUp",r.ARROW_DOWN="ArrowDown",r.ARROW_RIGHT="ArrowRight",r.ARROW_LEFT="ArrowLeft",r.BACKSPACE="Backspace",r.DELETE="Delete",r.META="Meta",r.CONTROL="Control",r;}(V||{});var et=/*#__PURE__*/function(){function et(){_classCallCheck(this,et);}return _createClass(et,null,[{key:"add",value:// prettier-ignore
|
7
|
+
function add(e,t,s,i){s!==void 0&&e.addEventListener("keydown",et.onKeyDown.bind(this,s)),e.oninput=et.onInput.bind(this,s,i),e.addEventListener("paste",function(n){var o;n.preventDefault(),(o=n.clipboardData)!=null&&o.files.length&&t.addFilesToAnyType(Array.from(n.clipboardData.files));});}// preventing insertion early for a nicer UX
|
8
8
|
// prettier-ignore
|
9
|
-
},{key:"onKeyDown",value:function onKeyDown(e,t){var i=t.target.textContent;i&&i.length>=e&&!
|
10
|
-
function clear(){var t,s;var e=window.scrollY;this.inputElementRef.classList.contains("text-input-disabled")||(Object.assign(this.inputElementRef.style,(t=this._config.placeholder)==null?void 0:t.style),this.inputElementRef.textContent="",ps.focusEndOfInput(this.inputElementRef),(s=this._onInput)==null||s.call(this,!1)),
|
9
|
+
},{key:"onKeyDown",value:function onKeyDown(e,t){var i=t.target.textContent;i&&i.length>=e&&!et.PERMITTED_KEYS.has(t.key)&&!et.isKeyCombinationPermitted(t)&&t.preventDefault();}},{key:"isKeyCombinationPermitted",value:function isKeyCombinationPermitted(e){return e.key==="a"?e.ctrlKey||e.metaKey:!1;}},{key:"onInput",value:function onInput(e,t,s){var i=s.target,n=i.textContent||"";e!==void 0&&n.length>e&&(i.textContent=n.substring(0,e),ps.focusEndOfInput(i)),t==null||t();}}]);}();et.PERMITTED_KEYS=/* @__PURE__ */new Set([V.BACKSPACE,V.DELETE,V.ARROW_RIGHT,V.ARROW_LEFT,V.ARROW_DOWN,V.ARROW_UP,V.META,V.CONTROL,V.ENTER]);var pi=et;var nr=/*#__PURE__*/function(){function nr(){_classCallCheck(this,nr);}return _createClass(nr,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var s,i;e.preventDefault();var t=(s=e.clipboardData)==null?void 0:s.getData("text/plain");t&&((i=document.execCommand)==null||i.call(document,"insertText",!1,t));}}]);}();var tt=/*#__PURE__*/function(){function tt(e,t,s){var _this=this;_classCallCheck(this,tt);var n,o;this._isComposing=!1;var i=tt.processConfig(t,e.textInput);this.elementRef=tt.createContainerElement((n=i==null?void 0:i.styles)==null?void 0:n.container),this._config=i,this.inputElementRef=this.createInputElement(),this.elementRef.appendChild(this.inputElementRef),e.setPlaceholderText=this.setPlaceholderText.bind(this),e.setPlaceholderText(((o=this._config.placeholder)==null?void 0:o.text)||"Ask me anything!"),setTimeout(function(){pi.add(_this.inputElementRef,s,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(tt,[{key:"clear",value:// this also similarly prevents scroll up
|
10
|
+
function clear(){var t,s;var e=window.scrollY;this.inputElementRef.classList.contains("text-input-disabled")||(Object.assign(this.inputElementRef.style,(t=this._config.placeholder)==null?void 0:t.style),this.inputElementRef.textContent="",ps.focusEndOfInput(this.inputElementRef),(s=this._onInput)==null||s.call(this,!1)),He.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(){var t,s,i,n;var e=document.createElement("div");return e.id=tt.TEXT_INPUT_ID,e.classList.add("text-input-styling"),e.role="textbox",He.IS_CHROMIUM&&tt.preventAutomaticScrollUpOnNewLine(e),typeof this._config.disabled=="boolean"&&this._config.disabled===!0?(e.contentEditable="false",e.classList.add("text-input-disabled"),e.setAttribute("aria-disabled","true")):(e.contentEditable="true",e.removeAttribute("aria-disabled"),this.addEventListeners(e)),Object.assign(e.style,(t=this._config.styles)==null?void 0:t.text),Object.assign(e.style,(s=this._config.placeholder)==null?void 0:s.style),(n=(i=this._config.placeholder)==null?void 0:i.style)!=null&&n.color||e.setAttribute("textcolor",""),e;}},{key:"removePlaceholderStyle",value:function removePlaceholderStyle(){var e,t,s,i;!this.inputElementRef.classList.contains("text-input-disabled")&&(e=this._config.placeholder)!=null&&e.style&&(N.unsetStyle(this.inputElementRef,(t=this._config.placeholder)==null?void 0:t.style),Object.assign(this.inputElementRef.style,(i=(s=this._config)==null?void 0:s.styles)==null?void 0:i.text));}},{key:"addEventListeners",value:function addEventListeners(e){var _this2=this;var t,s;(t=this._config.styles)!=null&&t.focus&&(e.onfocus=function(){var i;return Object.assign(_this2.elementRef.style,(i=_this2._config.styles)==null?void 0:i.focus);},e.onblur=this.onBlur.bind(this,this._config.styles.focus,(s=this._config.styles)==null?void 0:s.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",nr.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){N.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef.style,t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===V.ENTER&&!He.IS_MOBILE&&!this._isComposing&&!e.ctrlKey&&!e.shiftKey&&(e.preventDefault(),(t=this.submit)==null||t.call(this));}},{key:"onInput",value:function onInput(){var e,t;this.isTextInputEmpty()?Object.assign(this.inputElementRef.style,(e=this._config.placeholder)==null?void 0:e.style):this.removePlaceholderStyle(),(t=this._onInput)==null||t.call(this,!0);}},{key:"setPlaceholderText",value:function setPlaceholderText(e){this.inputElementRef.setAttribute("deep-chat-placeholder-text",e),this.inputElementRef.setAttribute("aria-label",e);}},{key:"isTextInputEmpty",value:function isTextInputEmpty(){return this.inputElementRef.textContent==="";}}],[{key:"processConfig",value:function processConfig(e,t){var _t$disabled,_t$placeholder,_s$text;var s;return t!==null&&t!==void 0?t:t={},(_t$disabled=t.disabled)!==null&&_t$disabled!==void 0?_t$disabled:t.disabled=e.isTextInputDisabled,(_t$placeholder=t.placeholder)!==null&&_t$placeholder!==void 0?_t$placeholder:t.placeholder={},(_s$text=(s=t.placeholder).text)!==null&&_s$text!==void 0?_s$text:s.text=e.textInputPlaceholderText,t;}},{key:"createContainerElement",value:function createContainerElement(e){var t=document.createElement("div");return t.id="text-input-container",Object.assign(t.style,e),t;}// this is is a bug fix where if the browser is scrolled down and the user types in text that creates new line
|
11
11
|
// the browser scrollbar will move up which leads to undesirable UX.
|
12
12
|
// More details in this Stack Overflow question:
|
13
13
|
// https://stackoverflow.com/questions/76285135/prevent-automatic-scroll-when-text-is-inserted-into-contenteditable-div
|
14
14
|
// prettier-ignore
|
15
|
-
},{key:"preventAutomaticScrollUpOnNewLine",value:function preventAutomaticScrollUpOnNewLine(e){var t;e.addEventListener("keydown",function(){t=window.scrollY;}),e.addEventListener("input",function(){t!==window.scrollY&&window.scrollTo({top:t});});}}]);}();
|
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});});}}]);}();tt.TEXT_INPUT_ID="text-input";var xs=tt;var ps=/*#__PURE__*/function(){function ps(){_classCallCheck(this,ps);}return _createClass(ps,null,[{key:"focusEndOfInput",value:function focusEndOfInput(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(t);}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(xs.TEXT_INPUT_ID));t&&(He.IS_SAFARI&&t.focus(),ps.focusEndOfInput(t));}}]);}();function Xi(r){return r.charAt(0).toUpperCase()+r.slice(1);}function rr(r){return r&&JSON.stringify(r);}function Ni(r,e,t,s){var i="\n".concat(Xi(e)," message: ").concat(JSON.stringify(r)," \n"),n=t?"".concat(Xi(e)," message after interceptor: ").concat(rr(s)," \n"):"";return i+n;}function or(r,e,t,s){return"".concat(Ni(r,e,t,s),"Make sure the ").concat(e," message is using the Response format: https://deepchat.dev/docs/connect/#Response \nYou can also augment it using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor");}function ar(r,e,t){var s="response";return"".concat(Ni(r,s,e,t),"Make sure the ").concat(s," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function lr(r,e){var t="request";return"".concat(Ni(r,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}var Yi="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor",C={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",INVALID_RESPONSE:or,INVALID_MODEL_REQUEST:lr,INVALID_MODEL_RESPONSE:ar,INVALID_STREAM_ARRAY_RESPONSE:"Multi-response arrays are not supported for streaming",INVALID_STREAM_EVENT:Yi,INVALID_STREAM_EVENT_MIX:"Cannot mix {text: string} and {html: string} responses.",NO_VALID_STREAM_EVENTS_SENT:"No valid stream events were sent.\n".concat(Yi),READABLE_STREAM_CONNECTION_ERROR:"Readable Stream connection error."},Xs=/*#__PURE__*/function(){function Xs(){_classCallCheck(this,Xs);}return _createClass(Xs,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(s){return e.appendChild(s);});}},{key:"isScrollbarAtBottomOfElement",value:function isScrollbarAtBottomOfElement(e){var t=e.scrollHeight,s=e.clientHeight,i=e.scrollTop,n=t-s;return i>=n-Xs.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;t?e.scrollTo({left:0,top:e.scrollHeight,behavior:"smooth"}):e.scrollTop=e.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}}]);}();Xs.CODE_SNIPPET_GENERATION_JUMP=0.5;var J=Xs;var Ys=/*#__PURE__*/function(){function Ys(){_classCallCheck(this,Ys);}return _createClass(Ys,null,[{key:"speak",value:function speak(e,t){if(!t.service&&window.SpeechSynthesisUtterance){var s=new SpeechSynthesisUtterance(e);Object.assign(s,t),speechSynthesis.speak(s);}}},{key:"processConfig",value:function processConfig(e,t){var s={};setTimeout(function(){if(_typeof(e)=="object"&&(e.service&&(s.service=e.service),e.lang&&(s.lang=e.lang),e.pitch&&(s.pitch=e.pitch),e.rate&&(s.rate=e.rate),e.volume&&(s.volume=e.volume),e.voiceName)){var i=window.speechSynthesis.getVoices().find(function(n){var o;return n.name.toLocaleLowerCase()===((o=e.voiceName)==null?void 0:o.toLocaleLowerCase());});i&&(s.voice=i);}t(s);},Ys.LOAD_VOICES_MS);}}]);}();Ys.LOAD_VOICES_MS=200;var St=Ys;var vt=/*#__PURE__*/function(){function vt(){_classCallCheck(this,vt);}return _createClass(vt,null,[{key:"colorToHex",value:function colorToHex(e){var t=document.createElement("div");return t.style.color=e,document.body.appendChild(t),"#".concat(window.getComputedStyle(t).color.match(/\d+/g).map(function(n){return parseInt(n).toString(16).padStart(2,"0");}).join(""));}},{key:"setDots",value:function setDots(e,t){var s,i,n,o;if((o=(n=(i=(s=t==null?void 0:t.loading)==null?void 0:s.message)==null?void 0:i.styles)==null?void 0:n.bubble)!=null&&o.color){var a=vt.colorToHex(t.loading.message.styles.bubble.color);e.style.setProperty("--loading-message-color",a),e.style.setProperty("--loading-message-color-fade","".concat(a,"33"));}else e.style.setProperty("--loading-message-color","#848484"),e.style.setProperty("--loading-message-color-fade","#55555533");}},{key:"setRing",value:function setRing(e,t){var _ref=t||{},s=_ref.color,i=_ref.width,n=_ref.height,o=_ref.margin,a=_ref.border;if(s){var l=vt.colorToHex(s);e.style.setProperty("--loading-history-color",l);}else e.style.setProperty("--loading-history-color","#dbdbdb");e.style.setProperty("--loading-history-height",n||"57px"),e.style.setProperty("--loading-history-width",i||"57px"),e.style.setProperty("--loading-history-margin",o||"7px"),e.style.setProperty("--loading-history-border",a||"6px solid");}}]);}();vt.BUBBLE_CLASS="deep-chat-loading-message-bubble",vt.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var je=vt;var he=/*#__PURE__*/function(){function he(){_classCallCheck(this,he);}return _createClass(he,null,[{key:"setElementProps",value:// prettier-ignore
|
16
16
|
function setElementProps(e,t,s,i){var n;s!=="loading"&&(e.applyCustomStyles(t,i,!0,(n=e.messageStyles)==null?void 0:n[s]),t.bubbleElement.classList.add(he.FILE_BUBBLE_CLASS));}// prettier-ignore
|
17
17
|
},{key:"addMessage",value:function addMessage(e,t,s,i,n){he.setElementProps(e,t,s,i),n||(e.appendOuterContainerElemet(t.outerContainer),e.focusMode||(e.elementRef.scrollTop=e.elementRef.scrollHeight));}},{key:"wrapInLink",value:function wrapInLink(e,t,s){var i=document.createElement("a");return i.href=t,i.download=s||he.DEFAULT_FILE_NAME,i.target="_blank",i.appendChild(e),i;}},{key:"isNonLinkableDataUrl",value:function isNonLinkableDataUrl(e,t){return!t.startsWith("data")||e==="image"?!1:e==="any"&&t.startsWith("data:text/javascript")||!t.startsWith("data:image")&&!t.startsWith("data:application");}},{key:"processContent",value:function processContent(e,t,s,i){return!s||he.isNonLinkableDataUrl(e,s)?t:he.wrapInLink(t,s,i);}},{key:"waitToLoadThenScroll",value:function waitToLoadThenScroll(e){setTimeout(function(){e.scrollTop=e.scrollHeight;},60);}},{key:"scrollDownOnImageLoad",value:function scrollDownOnImageLoad(e,t){if(e.startsWith("data"))he.waitToLoadThenScroll(t);else try{fetch(e,{mode:"no-cors"})["catch"](function(){})["finally"](function(){he.waitToLoadThenScroll(t);});}catch(_unused2){t.scrollTop=t.scrollHeight;}}// The strategy is to emit the actual file reference in the `onMessage` event for the user to inspect it
|
18
18
|
// But it is not actually used by anything in the chat, hence it is removed when adding a message
|
19
19
|
// after the body has been stringified and parsed - the file reference will disappear, hence this readds it
|
20
20
|
},{key:"reAddFileRefToObject",value:function reAddFileRefToObject(e,t){var s;(s=e.files)==null||s.forEach(function(i,n){var o;i.ref&&(o=t.files)!=null&&o[n]&&(t.files[n].ref=i.ref);});}// the chat does not use the actual file
|
21
|
-
},{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,s=e.type,i=e.src;return s==="audio"||(i==null?void 0:i.startsWith("data:audio"))||i&&t.test(i);}},{key:"isImageFile",value:function isImageFile(e){var t=e.type,s=e.src;return t==="image"||(s==null?void 0:s.startsWith("data:image"))||s&&he.isImageFileExtension(s);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();he.DEFAULT_FILE_NAME="file",he.FILE_BUBBLE_CLASS="file-message";var z=he;var
|
22
|
-
},{key:"handleResponseProperty",value:function handleResponseProperty(e){return console.error("The {result: ....} response object type is deprecated since version 1.3.0."),console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console.error("The initialMessages property is deprecated since version 2.0.0."),console.error("Please change to using the history property instead: https://deepchat.dev/docs/messages/#history"),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e.file;t&&(console.error("The file property in MessageContent is deprecated since version 1.3.17."),console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"),e.files=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console.error("The validateMessageBeforeSending property is deprecated since version 1.3.24."),console.error("Please change to using validateInput: https://deepchat.dev/docs/interceptors#validateInput"),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."),console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"),{text:e};}},{key:"flagHTMLUpdateClass",value:function flagHTMLUpdateClass(e){var t;(t=e.children[0])!=null&&t.classList.contains("deep-chat-update-message")&&(console.error('The "deep-chat-update-message" html class is deprecated since version 1.4.4.'),console.error("Please change to using {..., overwrite: true} object: https://deepchat.dev/docs/connect#Response"));}},{key:"processConnect",value:function processConnect(e){var t=e;t.request&&(t.connect?Object.assign(t.connect,t.request):t.connect=t.request,console.error("The request property is deprecated since version 2.0.0."),console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console.error("The stream property has been moved to the connect object in version 2.0.0."),console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var i;var s=e;s.onNewMessage&&(console.error("The onNewMessage event has been deprecated since version 2.0.0."),console.error("Please see the onMessage event: https://deepchat.dev/docs/events#onMessage"),(i=s.onNewMessage)==null||i.call(s,t)),e.dispatchEvent(new CustomEvent("new-message",{detail:t}));}},{key:"processFileConfigConnect",value:function processFileConfigConnect(e){var t=e;t.request&&(console.error("The request property in file configuration is deprecated since version 2.0.0."),console.error("Please use the connect property instead: https://deepchat.dev/docs/files"),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=JSON.parse(JSON.stringify(e)),s=t.loading;return s&&(s.outerContainer||s.innerContainer||s.bubble||s.media)&&(console.error("The loading message styles are defined using LoadingMessageStyles interface since version 2.1.0."),console.error("Check it out here: https://deepchat.dev/docs/messages/styles#LoadingMessageStyles"),t.loading={message:{styles:s}}),t;}},{key:"processDemo",value:function processDemo(e){return typeof e=="boolean"||e.displayLoadingBubble&&(console.error("The demo displayLoadingBubble property is deprecated since version 2.1.0."),console.error("Please use displayLoading instead: https://deepchat.dev/docs/modes#demo"),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,s="Please see the official documentation: https://deepchat.dev/docs/directConnection/Cohere";return t.chat&&(console.error("Cohere chat property is deprecated since version 2.2.3."),console.error(s),delete t.chat),t.textGeneration?(console.error("Cohere textGeneration is not supported since version 2.2.3."),console.error(s),delete t.textGeneration,!1):t.summarization?(console.error("Cohere summarization is not supported since version 2.2.3."),console.error(s),delete t.summarization,!1):!0;}
|
23
|
-
},{key:"
|
24
|
-
},{key:"overwrite",value:function overwrite(e,t,s,i){var n=e.messageToElements,o=b.overwriteMessage(n,i,t,s,"html",Pe.HTML_BUBBLE_CLASS);return o&&Pe.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var n=Pe.createElements(e,t,s,i);return b.fillEmptyMessageElement(n.bubbleElement,t),W.apply(e,n.outerContainer),ee.flagHTMLUpdateClass(n.bubbleElement),e.applyCustomStyles(n,s,!1,(o=e.messageStyles)==null?void 0:o.html),n;}},{key:"add",value:function add(e,t,s,i){var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(i!=null&&i.status){var a=this.overwrite(e,t,s,e.messageElementRefs);if(a)return a;i.status=!1;}if(n&&e.messageElementRefs.length>0&&W.isTemporaryBasedOnHTML(t))return;var o=Pe.create(e,t,s,n);return n||Pe.addElement(e,o.outerContainer),o;}}]);}();Pe.HTML_BUBBLE_CLASS="html-message";var Te=Pe;var pr=/*#__PURE__*/function(){function pr(){_classCallCheck(this,pr);}return _createClass(pr,null,[{key:"katex",value:function katex(e,t,s){var i="\\",a=(s||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var l=function l(u,h){var p;return((p=window.katex)==null?void 0:p.renderToString(u,_objectSpread({displayMode:h,throwOnError:!1,output:"mathml"},e)))||"";},c=function c(u,h,p){var m=!1,f=u.bMarks[h]+u.tShift[h],g=u.eMarks[h];if(f+1>g)return!1;var y=u.src.charAt(f);if(y!==a)return!1;var T=f;f=u.skipChars(f,y);var L=f-T;if(L!==2)return!1;var O=h;for(;++O,!(O>=p||(f=T=u.bMarks[O]+u.tShift[O],g=u.eMarks[O],f<g&&u.tShift[O]<u.blkIndent));)if(u.src.charAt(f)===a&&!(u.tShift[O]-u.blkIndent>=4)&&(f=u.skipChars(f,y),!(f-T<L)&&(f=u.skipSpaces(f),!(f<g)))){m=!0;break;}L=u.tShift[h],u.line=O+(m?1:0);var U=u.getLines(h+1,O,L,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:U,lines:[h,u.line],level:u.level,block:!0}),!0;},d=function d(u,h){var p=u.pos,m=u.posMax;var f=p;if(u.src.charAt(f)!==a)return!1;for(++f;f<m&&u.src.charAt(f)===a;)++f;var g=u.src.slice(p,f);if(g.length>2)return!1;var y=f;var T=0;for(;f<m;){var L=u.src.charAt(f);if(L==="{"&&(f===0||u.src.charAt(f-1)!==i))T+=1;else if(L==="}"&&(f===0||u.src.charAt(f-1)!==i)){if(T-=1,T<0)return!1;}else if(L===a&&T===0){var O=f;var U=f+1;for(;U<m&&u.src.charAt(U)===a;)++U;if(U-O===g.length){if(!h){var ge=u.src.slice(y,O).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:ge,block:g.length>1,level:u.level});}return u.pos=U,!0;}}f+=1;}return h||(u.pending+=g),u.pos+=g.length,!0;};t.inline.ruler.push("katex",d,s),t.block.ruler.push("katex",c,s),t.renderer.rules.katex=function(u,h){return l(u[h].content,u[h].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var gs;function jn(r){return gs=gs||document.createElement("textarea"),gs.innerHTML="&"+r+";",gs.value;}var fr=Object.prototype.hasOwnProperty;function mr(r,e){return r?fr.call(r,e):!1;}function Hn(r){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(s){r[s]=t[s];});}}),r;}var gr=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ns(r){return r.indexOf("\\")<0?r:r.replace(gr,"$1");}function qn(r){return!(r>=55296&&r<=57343||r>=64976&&r<=65007||(r&65535)===65535||(r&65535)===65534||r>=0&&r<=8||r===11||r>=14&&r<=31||r>=127&&r<=159||r>1114111);}function mi(r){if(r>65535){r-=65536;var e=55296+(r>>10),t=56320+(r&1023);return String.fromCharCode(e,t);}return String.fromCharCode(r);}var yr=/&([a-z#][a-z0-9]{1,31});/gi,br=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function vr(r,e){var t=0,s=jn(e);return e!==s?s:e.charCodeAt(0)===35&&br.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),qn(t))?mi(t):r;}function ct(r){return r.indexOf("&")<0?r:r.replace(yr,vr);}var Er=/[&<>"]/,_r=/[&<>"]/g,Sr={"&":"&","<":"<",">":">",'"':"""};function xr(r){return Sr[r];}function ie(r){return Er.test(r)?r.replace(_r,xr):r;}var v={};v.blockquote_open=function(){return"<blockquote>\n";};v.blockquote_close=function(r,e){return"</blockquote>"+ht(r,e);};v.code=function(r,e){return r[e].block?"<pre><code>"+ie(r[e].content)+"</code></pre>"+ht(r,e):"<code>"+ie(r[e].content)+"</code>";};v.fence=function(r,e,t,s,i){var n=r[e],o="",a=t.langPrefix,l="",c,d,u;if(n.params){if(c=n.params.split(/\s+/g),d=c.join(" "),mr(i.rules.fence_custom,c[0]))return i.rules.fence_custom[c[0]](r,e,t,s,i);l=ie(ct(ns(d))),o=' class="'+a+l+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[n.content].concat(c))||ie(n.content):u=ie(n.content),"<pre><code"+o+">"+u+"</code></pre>"+ht(r,e);};v.fence_custom={};v.heading_open=function(r,e){return"<h"+r[e].hLevel+">";};v.heading_close=function(r,e){return"</h"+r[e].hLevel+">\n";};v.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+ht(r,e);};v.bullet_list_open=function(){return"<ul>\n";};v.bullet_list_close=function(r,e){return"</ul>"+ht(r,e);};v.list_item_open=function(){return"<li>";};v.list_item_close=function(){return"</li>\n";};v.ordered_list_open=function(r,e){var t=r[e],s=t.order>1?' start="'+t.order+'"':"";return"<ol"+s+">\n";};v.ordered_list_close=function(r,e){return"</ol>"+ht(r,e);};v.paragraph_open=function(r,e){return r[e].tight?"":"<p>";};v.paragraph_close=function(r,e){var t=!(r[e].tight&&e&&r[e-1].type==="inline"&&!r[e-1].content);return(r[e].tight?"":"</p>")+(t?ht(r,e):"");};v.link_open=function(r,e,t){var s=r[e].title?' title="'+ie(ct(r[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+ie(r[e].href)+'"'+s+i+">";};v.link_close=function(){return"</a>";};v.image=function(r,e,t){var s=' src="'+ie(r[e].src)+'"',i=r[e].title?' title="'+ie(ct(r[e].title))+'"':"",n=' alt="'+(r[e].alt?ie(ct(ns(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+s+n+i+o+">";};v.table_open=function(){return"<table>\n";};v.table_close=function(){return"</table>\n";};v.thead_open=function(){return"<thead>\n";};v.thead_close=function(){return"</thead>\n";};v.tbody_open=function(){return"<tbody>\n";};v.tbody_close=function(){return"</tbody>\n";};v.tr_open=function(){return"<tr>";};v.tr_close=function(){return"</tr>\n";};v.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};v.th_close=function(){return"</th>";};v.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};v.td_close=function(){return"</td>";};v.strong_open=function(){return"<strong>";};v.strong_close=function(){return"</strong>";};v.em_open=function(){return"<em>";};v.em_close=function(){return"</em>";};v.del_open=function(){return"<del>";};v.del_close=function(){return"</del>";};v.ins_open=function(){return"<ins>";};v.ins_close=function(){return"</ins>";};v.mark_open=function(){return"<mark>";};v.mark_close=function(){return"</mark>";};v.sub=function(r,e){return"<sub>"+ie(r[e].content)+"</sub>";};v.sup=function(r,e){return"<sup>"+ie(r[e].content)+"</sup>";};v.hardbreak=function(r,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};v.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};v.text=function(r,e){return ie(r[e].content);};v.htmlblock=function(r,e){return r[e].content;};v.htmltag=function(r,e){return r[e].content;};v.abbr_open=function(r,e){return'<abbr title="'+ie(ct(r[e].title))+'">';};v.abbr_close=function(){return"</abbr>";};v.footnote_ref=function(r,e){var t=Number(r[e].id+1).toString(),s="fnref"+t;return r[e].subId>0&&(s+=":"+r[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+s+'">['+t+"]</a></sup>";};v.footnote_block_open=function(r,e,t){var s=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return s+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};v.footnote_block_close=function(){return"</ol>\n</section>\n";};v.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};v.footnote_close=function(){return"</li>\n";};v.footnote_anchor=function(r,e){var t=Number(r[e].id+1).toString(),s="fnref"+t;return r[e].subId>0&&(s+=":"+r[e].subId),' <a href="#'+s+'" class="footnote-backref">↩</a>';};v.dl_open=function(){return"<dl>\n";};v.dt_open=function(){return"<dt>";};v.dd_open=function(){return"<dd>";};v.dl_close=function(){return"</dl>\n";};v.dt_close=function(){return"</dt>\n";};v.dd_close=function(){return"</dd>\n";};function Vn(r,e){return++e>=r.length-2?e:r[e].type==="paragraph_open"&&r[e].tight&&r[e+1].type==="inline"&&r[e+1].content.length===0&&r[e+2].type==="paragraph_close"&&r[e+2].tight?Vn(r,e+2):e;}var ht=v.getBreak=function(e,t){return t=Vn(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function Di(){this.rules=Hn({},v),this.getBreak=v.getBreak;}Di.prototype.renderInline=function(r,e,t){for(var s=this.rules,i=r.length,n=0,o="";i--;)o+=s[r[n].type](r,n++,e,t,this);return o;};Di.prototype.render=function(r,e,t){for(var s=this.rules,i=r.length,n=-1,o="";++n<i;)r[n].type==="inline"?o+=this.renderInline(r[n].children,e,t):o+=s[r[n].type](r,n,e,t,this);return o;};function ce(){this.__rules__=[],this.__cache__=null;}ce.prototype.__find__=function(r){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===r)return t;return-1;};ce.prototype.__compile__=function(){var r=this,e=[""];r.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(s){e.indexOf(s)<0&&e.push(s);});}),r.__cache__={},e.forEach(function(t){r.__cache__[t]=[],r.__rules__.forEach(function(s){s.enabled&&(t&&s.alt.indexOf(t)<0||r.__cache__[t].push(s.fn));});});};ce.prototype.at=function(r,e,t){var s=this.__find__(r),i=t||{};if(s===-1)throw new Error("Parser rule not found: "+r);this.__rules__[s].fn=e,this.__rules__[s].alt=i.alt||[],this.__cache__=null;};ce.prototype.before=function(r,e,t,s){var i=this.__find__(r),n=s||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i,0,{name:e,enabled:!0,fn:t,alt:n.alt||[]}),this.__cache__=null;};ce.prototype.after=function(r,e,t,s){var i=this.__find__(r),n=s||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i+1,0,{name:e,enabled:!0,fn:t,alt:n.alt||[]}),this.__cache__=null;};ce.prototype.push=function(r,e,t){var s=t||{};this.__rules__.push({name:r,enabled:!0,fn:e,alt:s.alt||[]}),this.__cache__=null;};ce.prototype.enable=function(r,e){r=Array.isArray(r)?r:[r],e&&this.__rules__.forEach(function(t){t.enabled=!1;}),r.forEach(function(t){var s=this.__find__(t);if(s<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[s].enabled=!0;},this),this.__cache__=null;};ce.prototype.disable=function(r){r=Array.isArray(r)?r:[r],r.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;};ce.prototype.getRules=function(r){return this.__cache__===null&&this.__compile__(),this.__cache__[r]||[];};function wr(r){r.inlineMode?r.tokens.push({type:"inline",content:r.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):r.block.parse(r.src,r.options,r.env,r.tokens);}function ut(r,e,t,s,i){this.src=r,this.env=s,this.options=t,this.parser=e,this.tokens=i,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;}ut.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};ut.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level;};ut.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e;};ut.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0;};function rs(r,e){var t,s,i,n=-1,o=r.posMax,a=r.pos,l=r.isInLabel;if(r.isInLabel)return-1;if(r.labelUnmatchedScopes)return r.labelUnmatchedScopes--,-1;for(r.pos=e+1,r.isInLabel=!0,t=1;r.pos<o;){if(i=r.src.charCodeAt(r.pos),i===91)t++;else if(i===93&&(t--,t===0)){s=!0;break;}r.parser.skipToken(r);}return s?(n=r.pos,r.labelUnmatchedScopes=0):r.labelUnmatchedScopes=t-1,r.pos=a,r.isInLabel=l,n;}function Ar(r,e,t,s){var i,n,o,a,l,c;if(r.charCodeAt(0)!==42||r.charCodeAt(1)!==91||r.indexOf("]:")===-1||(i=new ut(r,e,t,s,[]),n=rs(i,1),n<0||r.charCodeAt(n+1)!==58))return-1;for(a=i.posMax,o=n+2;o<a&&i.src.charCodeAt(o)!==10;o++);return l=r.slice(2,n),c=r.slice(n+2,o).trim(),c.length===0?-1:(s.abbreviations||(s.abbreviations={}),_typeof(s.abbreviations[":"+l])>"u"&&(s.abbreviations[":"+l]=c),o);}function Cr(r){var e=r.tokens,t,s,i,n;if(!r.inlineMode){for(t=1,s=e.length-1;t<s;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(n=Ar(i,r.inline,r.options,r.env),!(n<0));)i=i.slice(n).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function gi(r){var e=ct(r);try{e=decodeURI(e);}catch(_unused3){}return encodeURI(e);}function Gn(r,e){var t,s,i,n=e,o=r.posMax;if(r.src.charCodeAt(e)===60){for(e++;e<o;){if(t=r.src.charCodeAt(e),t===10)return!1;if(t===62)return i=gi(ns(r.src.slice(n+1,e))),r.parser.validateLink(i)?(r.pos=e+1,r.linkContent=i,!0):!1;if(t===92&&e+1<o){e+=2;continue;}e++;}return!1;}for(s=0;e<o&&(t=r.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue;}if(t===40&&(s++,s>1)||t===41&&(s--,s<0))break;e++;}return n===e||(i=ns(r.src.slice(n,e)),!r.parser.validateLink(i))?!1:(r.linkContent=i,r.pos=e,!0);}function zn(r,e){var t,s=e,i=r.posMax,n=r.src.charCodeAt(e);if(n!==34&&n!==39&&n!==40)return!1;for(e++,n===40&&(n=41);e<i;){if(t=r.src.charCodeAt(e),t===n)return r.pos=e+1,r.linkContent=ns(r.src.slice(s+1,e)),!0;if(t===92&&e+1<i){e+=2;continue;}e++;}return!1;}function Kn(r){return r.trim().replace(/\s+/g," ").toUpperCase();}function Tr(r,e,t,s){var i,n,o,a,l,c,d,u,h;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(i=new ut(r,e,t,s,[]),n=rs(i,0),n<0||r.charCodeAt(n+1)!==58))return-1;for(a=i.posMax,o=n+2;o<a&&(l=i.src.charCodeAt(o),!(l!==32&&l!==10));o++);if(!Gn(i,o))return-1;for(d=i.linkContent,o=i.pos,c=o,o=o+1;o<a&&(l=i.src.charCodeAt(o),!(l!==32&&l!==10));o++);for(o<a&&c!==o&&zn(i,o)?(u=i.linkContent,o=i.pos):(u="",o=c);o<a&&i.src.charCodeAt(o)===32;)o++;return o<a&&i.src.charCodeAt(o)!==10?-1:(h=Kn(r.slice(1,n)),_typeof(s.references[h])>"u"&&(s.references[h]={title:u,href:d}),o);}function Rr(r){var e=r.tokens,t,s,i,n;if(r.env.references=r.env.references||{},!r.inlineMode){for(t=1,s=e.length-1;t<s;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(n=Tr(i,r.inline,r.options,r.env),!(n<0));)i=i.slice(n).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Mr(r){var e=r.tokens,t,s,i;for(s=0,i=e.length;s<i;s++)t=e[s],t.type==="inline"&&r.inline.parse(t.content,r.options,r.env,t.children);}function kr(r){var e,t,s,i,n,o,a,l,c,d=0,u=!1,h={};if(r.env.footnotes&&(r.tokens=r.tokens.filter(function(p){return p.type==="footnote_reference_open"?(u=!0,l=[],c=p.label,!1):p.type==="footnote_reference_close"?(u=!1,h[":"+c]=l,!1):(u&&l.push(p),!u);}),!!r.env.footnotes.list)){for(o=r.env.footnotes.list,r.tokens.push({type:"footnote_block_open",level:d++}),e=0,t=o.length;e<t;e++){for(r.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=h[":"+o[e].label]),r.tokens=r.tokens.concat(a),r.tokens[r.tokens.length-1].type==="paragraph_close"?n=r.tokens.pop():n=null,i=o[e].count>0?o[e].count:1,s=0;s<i;s++)r.tokens.push({type:"footnote_anchor",id:e,subId:s,level:d});n&&r.tokens.push(n),r.tokens.push({type:"footnote_close",level:--d});}r.tokens.push({type:"footnote_block_close",level:--d});}}var en=" \n()[]'\".,!?-";function ci(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function Lr(r){var e,t,s,i,n,o,a,l,c,d,u,h,p=r.tokens;if(r.env.abbreviations){for(r.env.abbrRegExp||(h="(^|["+en.split("").map(ci).join("")+"])("+Object.keys(r.env.abbreviations).map(function(m){return m.substr(1);}).sort(function(m,f){return f.length-m.length;}).map(ci).join("|")+")($|["+en.split("").map(ci).join("")+"])",r.env.abbrRegExp=new RegExp(h,"g")),d=r.env.abbrRegExp,t=0,s=p.length;t<s;t++)if(p[t].type==="inline"){for(i=p[t].children,e=i.length-1;e>=0;e--)if(n=i[e],n.type==="text"){for(l=0,o=n.content,d.lastIndex=0,c=n.level,a=[];u=d.exec(o);)d.lastIndex>l&&a.push({type:"text",content:o.slice(l,u.index+u[1].length),level:c}),a.push({type:"abbr_open",title:r.env.abbreviations[":"+u[2]],level:c++}),a.push({type:"text",content:u[2],level:c}),a.push({type:"abbr_close",level:--c}),l=d.lastIndex-u[3].length;a.length&&(l<o.length&&a.push({type:"text",content:o.slice(l),level:c}),p[t].children=i=[].concat(i.slice(0,e),a,i.slice(e+1)));}}}}var Ir=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Or=/\((c|tm|r|p)\)/ig,Pr={c:"©",r:"®",p:"§",tm:"™"};function Nr(r){return r.indexOf("(")<0?r:r.replace(Or,function(e,t){return Pr[t.toLowerCase()];});}function Dr(r){var e,t,s,i,n;if(r.options.typographer){for(n=r.tokens.length-1;n>=0;n--)if(r.tokens[n].type==="inline")for(i=r.tokens[n].children,e=i.length-1;e>=0;e--)t=i[e],t.type==="text"&&(s=t.content,s=Nr(s),Ir.test(s)&&(s=s.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=s);}}var Br=/['"]/,tn=/['"]/g,Fr=/[-\s()\[\]]/,sn="’";function nn(r,e){return e<0||e>=r.length?!1:!Fr.test(r[e]);}function mt(r,e,t){return r.substr(0,e)+t+r.substr(e+1);}function Ur(r){var e,t,s,i,n,o,a,l,c,d,u,h,p,m,f,g,y;if(r.options.typographer){for(y=[],f=r.tokens.length-1;f>=0;f--)if(r.tokens[f].type==="inline"){for(g=r.tokens[f].children,y.length=0,e=0;e<g.length;e++)if(t=g[e],!(t.type!=="text"||Br.test(t.text))){for(a=g[e].level,p=y.length-1;p>=0&&!(y[p].level<=a);p--);y.length=p+1,s=t.content,n=0,o=s.length;e:for(;n<o&&(tn.lastIndex=n,i=tn.exec(s),!!i);){if(l=!nn(s,i.index-1),n=i.index+1,m=i[0]==="'",c=!nn(s,n),!c&&!l){m&&(t.content=mt(t.content,i.index,sn));continue;}if(u=!c,h=!l,h){for(p=y.length-1;p>=0&&(d=y[p],!(y[p].level<a));p--)if(d.single===m&&y[p].level===a){d=y[p],m?(g[d.token].content=mt(g[d.token].content,d.pos,r.options.quotes[2]),t.content=mt(t.content,i.index,r.options.quotes[3])):(g[d.token].content=mt(g[d.token].content,d.pos,r.options.quotes[0]),t.content=mt(t.content,i.index,r.options.quotes[1])),y.length=p;continue e;}}u?y.push({token:e,pos:i.index,single:m,level:a}):h&&m&&(t.content=mt(t.content,i.index,sn));}}}}}var di=[["block",wr],["abbr",Cr],["references",Rr],["inline",Mr],["footnote_tail",kr],["abbr2",Lr],["replacements",Dr],["smartquotes",Ur]];function $n(){this.options={},this.ruler=new ce();for(var r=0;r<di.length;r++)this.ruler.push(di[r][0],di[r][1]);}$n.prototype.process=function(r){var e,t,s;for(s=this.ruler.getRules(""),e=0,t=s.length;e<t;e++)s[e](r);};function pt(r,e,t,s,i){var n,o,a,l,c,d,u;for(this.src=r,this.parser=e,this.options=t,this.env=s,this.tokens=i,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,u=!1,a=l=d=0,c=o.length;l<c;l++){if(n=o.charCodeAt(l),!u)if(n===32){d++;continue;}else u=!0;(n===10||l===c-1)&&(n!==10&&l++,this.bMarks.push(a),this.eMarks.push(l),this.tShift.push(d),u=!1,d=0,a=l+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}pt.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};pt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};pt.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};pt.prototype.skipChars=function(e,t){for(var s=this.src.length;e<s&&this.src.charCodeAt(e)===t;e++);return e;};pt.prototype.skipCharsBack=function(e,t,s){if(e<=s)return e;for(;e>s;)if(t!==this.src.charCodeAt(--e))return e+1;return e;};pt.prototype.getLines=function(e,t,s,i){var n,o,a,l,c,d=e;if(e>=t)return"";if(d+1===t)return o=this.bMarks[d]+Math.min(this.tShift[d],s),a=i?this.eMarks[d]+1:this.eMarks[d],this.src.slice(o,a);for(l=new Array(t-e),n=0;d<t;d++,n++)c=this.tShift[d],c>s&&(c=s),c<0&&(c=0),o=this.bMarks[d]+c,d+1<t||i?a=this.eMarks[d]+1:a=this.eMarks[d],l[n]=this.src.slice(o,a);return l.join("");};function jr(r,e,t){var s,i;if(r.tShift[e]-r.blkIndent<4)return!1;for(i=s=e+1;s<t;){if(r.isEmpty(s)){s++;continue;}if(r.tShift[s]-r.blkIndent>=4){s++,i=s;continue;}break;}return r.line=s,r.tokens.push({type:"code",content:r.getLines(e,i,4+r.blkIndent,!0),block:!0,lines:[e,r.line],level:r.level}),!0;}function Hr(r,e,t,s){var i,n,o,a,l,c=!1,d=r.bMarks[e]+r.tShift[e],u=r.eMarks[e];if(d+3>u||(i=r.src.charCodeAt(d),i!==126&&i!==96)||(l=d,d=r.skipChars(d,i),n=d-l,n<3)||(o=r.src.slice(d,u).trim(),o.indexOf("`")>=0))return!1;if(s)return!0;for(a=e;a++,!(a>=t||(d=l=r.bMarks[a]+r.tShift[a],u=r.eMarks[a],d<u&&r.tShift[a]<r.blkIndent));)if(r.src.charCodeAt(d)===i&&!(r.tShift[a]-r.blkIndent>=4)&&(d=r.skipChars(d,i),!(d-l<n)&&(d=r.skipSpaces(d),!(d<u)))){c=!0;break;}return n=r.tShift[e],r.line=a+(c?1:0),r.tokens.push({type:"fence",params:o,content:r.getLines(e+1,a,n,!0),lines:[e,r.line],level:r.level}),!0;}function qr(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m,f=r.bMarks[e]+r.tShift[e],g=r.eMarks[e];if(f>g||r.src.charCodeAt(f++)!==62||r.level>=r.options.maxNesting)return!1;if(s)return!0;for(r.src.charCodeAt(f)===32&&f++,l=r.blkIndent,r.blkIndent=0,a=[r.bMarks[e]],r.bMarks[e]=f,f=f<g?r.skipSpaces(f):f,n=f>=g,o=[r.tShift[e]],r.tShift[e]=f-r.bMarks[e],u=r.parser.ruler.getRules("blockquote"),i=e+1;i<t&&(f=r.bMarks[i]+r.tShift[i],g=r.eMarks[i],!(f>=g));i++){if(r.src.charCodeAt(f++)===62){r.src.charCodeAt(f)===32&&f++,a.push(r.bMarks[i]),r.bMarks[i]=f,f=f<g?r.skipSpaces(f):f,n=f>=g,o.push(r.tShift[i]),r.tShift[i]=f-r.bMarks[i];continue;}if(n)break;for(m=!1,h=0,p=u.length;h<p;h++)if(u[h](r,i,t,!0)){m=!0;break;}if(m)break;a.push(r.bMarks[i]),o.push(r.tShift[i]),r.tShift[i]=-1337;}for(c=r.parentType,r.parentType="blockquote",r.tokens.push({type:"blockquote_open",lines:d=[e,0],level:r.level++}),r.parser.tokenize(r,e,i),r.tokens.push({type:"blockquote_close",level:--r.level}),r.parentType=c,d[1]=r.line,h=0;h<o.length;h++)r.bMarks[h+e]=a[h],r.tShift[h+e]=o[h];return r.blkIndent=l,!0;}function Vr(r,e,t,s){var i,n,o,a=r.bMarks[e],l=r.eMarks[e];if(a+=r.tShift[e],a>l||(i=r.src.charCodeAt(a++),i!==42&&i!==45&&i!==95))return!1;for(n=1;a<l;){if(o=r.src.charCodeAt(a++),o!==i&&o!==32)return!1;o===i&&n++;}return n<3?!1:(s||(r.line=e+1,r.tokens.push({type:"hr",lines:[e,r.line],level:r.level})),!0);}function rn(r,e){var t,s,i;return s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e],s>=i||(t=r.src.charCodeAt(s++),t!==42&&t!==45&&t!==43)||s<i&&r.src.charCodeAt(s)!==32?-1:s;}function on(r,e){var t,s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e];if(s+1>=i||(t=r.src.charCodeAt(s++),t<48||t>57))return-1;for(;;){if(s>=i)return-1;if(t=r.src.charCodeAt(s++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return s<i&&r.src.charCodeAt(s)!==32?-1:s;}function Gr(r,e){var t,s,i=r.level+2;for(t=e+2,s=r.tokens.length-2;t<s;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function zr(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m,f,g,y,T,L,O,U,ge=!0,we,re,Xi,li;if((u=on(r,e))>=0)g=!0;else if((u=rn(r,e))>=0)g=!1;else return!1;if(r.level>=r.options.maxNesting)return!1;if(f=r.src.charCodeAt(u-1),s)return!0;for(T=r.tokens.length,g?(d=r.bMarks[e]+r.tShift[e],m=Number(r.src.substr(d,u-d-1)),r.tokens.push({type:"ordered_list_open",order:m,lines:O=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:O=[e,0],level:r.level++}),i=e,L=!1,we=r.parser.ruler.getRules("list");i<t&&(y=r.skipSpaces(u),h=r.eMarks[i],y>=h?p=1:p=y-u,p>4&&(p=1),p<1&&(p=1),n=u-r.bMarks[i]+p,r.tokens.push({type:"list_item_open",lines:U=[e,0],level:r.level++}),a=r.blkIndent,l=r.tight,o=r.tShift[e],c=r.parentType,r.tShift[e]=y-r.bMarks[e],r.blkIndent=n,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||L)&&(ge=!1),L=r.line-e>1&&r.isEmpty(r.line-1),r.blkIndent=a,r.tShift[e]=o,r.tight=l,r.parentType=c,r.tokens.push({type:"list_item_close",level:--r.level}),i=e=r.line,U[1]=i,y=r.bMarks[e],!(i>=t||r.isEmpty(i)||r.tShift[i]<r.blkIndent));){for(li=!1,re=0,Xi=we.length;re<Xi;re++)if(we[re](r,i,t,!0)){li=!0;break;}if(li)break;if(g){if(u=on(r,i),u<0)break;}else if(u=rn(r,i),u<0)break;if(f!==r.src.charCodeAt(u-1))break;}return r.tokens.push({type:g?"ordered_list_close":"bullet_list_close",level:--r.level}),O[1]=i,r.line=i,ge&&Gr(r,T),!0;}function Kr(r,e,t,s){var i,n,o,a,l,c=r.bMarks[e]+r.tShift[e],d=r.eMarks[e];if(c+4>d||r.src.charCodeAt(c)!==91||r.src.charCodeAt(c+1)!==94||r.level>=r.options.maxNesting)return!1;for(a=c+2;a<d;a++){if(r.src.charCodeAt(a)===32)return!1;if(r.src.charCodeAt(a)===93)break;}return a===c+2||a+1>=d||r.src.charCodeAt(++a)!==58?!1:(s||(a++,r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.refs||(r.env.footnotes.refs={}),l=r.src.slice(c+2,a-2),r.env.footnotes.refs[":"+l]=-1,r.tokens.push({type:"footnote_reference_open",label:l,level:r.level++}),i=r.bMarks[e],n=r.tShift[e],o=r.parentType,r.tShift[e]=r.skipSpaces(a)-a,r.bMarks[e]=a,r.blkIndent+=4,r.parentType="footnote",r.tShift[e]<r.blkIndent&&(r.tShift[e]+=r.blkIndent,r.bMarks[e]-=r.blkIndent),r.parser.tokenize(r,e,t,!0),r.parentType=o,r.blkIndent-=4,r.tShift[e]=n,r.bMarks[e]=i,r.tokens.push({type:"footnote_reference_close",level:--r.level})),!0);}function $r(r,e,t,s){var i,n,o,a=r.bMarks[e]+r.tShift[e],l=r.eMarks[e];if(a>=l||(i=r.src.charCodeAt(a),i!==35||a>=l))return!1;for(n=1,i=r.src.charCodeAt(++a);i===35&&a<l&&n<=6;)n++,i=r.src.charCodeAt(++a);return n>6||a<l&&i!==32?!1:(s||(l=r.skipCharsBack(l,32,a),o=r.skipCharsBack(l,35,a),o>a&&r.src.charCodeAt(o-1)===32&&(l=o),r.line=e+1,r.tokens.push({type:"heading_open",hLevel:n,lines:[e,r.line],level:r.level}),a<l&&r.tokens.push({type:"inline",content:r.src.slice(a,l).trim(),level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"heading_close",hLevel:n,level:r.level})),!0);}function Jr(r,e,t){var s,i,n,o=e+1;return o>=t||r.tShift[o]<r.blkIndent||r.tShift[o]-r.blkIndent>3||(i=r.bMarks[o]+r.tShift[o],n=r.eMarks[o],i>=n)||(s=r.src.charCodeAt(i),s!==45&&s!==61)||(i=r.skipChars(i,s),i=r.skipSpaces(i),i<n)?!1:(i=r.bMarks[e]+r.tShift[e],r.line=o+1,r.tokens.push({type:"heading_open",hLevel:s===61?1:2,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:r.src.slice(i,r.eMarks[e]).trim(),level:r.level+1,lines:[e,r.line-1],children:[]}),r.tokens.push({type:"heading_close",hLevel:s===61?1:2,level:r.level}),!0);}var Jn={};["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(r){Jn[r]=!0;});var Wr=/^<([a-zA-Z]{1,15})[\s\/>]/,Xr=/^<\/([a-zA-Z]{1,15})[\s>]/;function Yr(r){var e=r|32;return e>=97&&e<=122;}function Zr(r,e,t,s){var i,n,o,a=r.bMarks[e],l=r.eMarks[e],c=r.tShift[e];if(a+=c,!r.options.html||c>3||a+2>=l||r.src.charCodeAt(a)!==60)return!1;if(i=r.src.charCodeAt(a+1),i===33||i===63){if(s)return!0;}else if(i===47||Yr(i)){if(i===47){if(n=r.src.slice(a,l).match(Xr),!n)return!1;}else if(n=r.src.slice(a,l).match(Wr),!n)return!1;if(Jn[n[1].toLowerCase()]!==!0)return!1;if(s)return!0;}else return!1;for(o=e+1;o<r.lineMax&&!r.isEmpty(o);)o++;return r.line=o,r.tokens.push({type:"htmlblock",level:r.level,lines:[e,r.line],content:r.getLines(e,o,0,!0)}),!0;}function hi(r,e){var t=r.bMarks[e]+r.blkIndent,s=r.eMarks[e];return r.src.substr(t,s-t);}function Qr(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m;if(e+2>t||(l=e+1,r.tShift[l]<r.blkIndent)||(o=r.bMarks[l]+r.tShift[l],o>=r.eMarks[l])||(i=r.src.charCodeAt(o),i!==124&&i!==45&&i!==58)||(n=hi(r,e+1),!/^[-:| ]+$/.test(n))||(c=n.split("|"),c<=2))return!1;for(u=[],a=0;a<c.length;a++){if(h=c[a].trim(),!h){if(a===0||a===c.length-1)continue;return!1;}if(!/^:?-+:?$/.test(h))return!1;h.charCodeAt(h.length-1)===58?u.push(h.charCodeAt(0)===58?"center":"right"):h.charCodeAt(0)===58?u.push("left"):u.push("");}if(n=hi(r,e).trim(),n.indexOf("|")===-1||(c=n.replace(/^\||\|$/g,"").split("|"),u.length!==c.length))return!1;if(s)return!0;for(r.tokens.push({type:"table_open",lines:p=[e,0],level:r.level++}),r.tokens.push({type:"thead_open",lines:[e,e+1],level:r.level++}),r.tokens.push({type:"tr_open",lines:[e,e+1],level:r.level++}),a=0;a<c.length;a++)r.tokens.push({type:"th_open",align:u[a],lines:[e,e+1],level:r.level++}),r.tokens.push({type:"inline",content:c[a].trim(),lines:[e,e+1],level:r.level,children:[]}),r.tokens.push({type:"th_close",level:--r.level});for(r.tokens.push({type:"tr_close",level:--r.level}),r.tokens.push({type:"thead_close",level:--r.level}),r.tokens.push({type:"tbody_open",lines:m=[e+2,0],level:r.level++}),l=e+2;l<t&&!(r.tShift[l]<r.blkIndent||(n=hi(r,l).trim(),n.indexOf("|")===-1));l++){for(c=n.replace(/^\||\|$/g,"").split("|"),r.tokens.push({type:"tr_open",level:r.level++}),a=0;a<c.length;a++)r.tokens.push({type:"td_open",align:u[a],level:r.level++}),d=c[a].substring(c[a].charCodeAt(0)===124?1:0,c[a].charCodeAt(c[a].length-1)===124?c[a].length-1:c[a].length).trim(),r.tokens.push({type:"inline",content:d,level:r.level,children:[]}),r.tokens.push({type:"td_close",level:--r.level});r.tokens.push({type:"tr_close",level:--r.level});}return r.tokens.push({type:"tbody_close",level:--r.level}),r.tokens.push({type:"table_close",level:--r.level}),p[1]=m[1]=l,r.line=l,!0;}function ys(r,e){var t,s,i=r.bMarks[e]+r.tShift[e],n=r.eMarks[e];return i>=n||(s=r.src.charCodeAt(i++),s!==126&&s!==58)||(t=r.skipSpaces(i),i===t)||t>=n?-1:t;}function eo(r,e){var t,s,i=r.level+2;for(t=e+2,s=r.tokens.length-2;t<s;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function to(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m,f,g,y;if(s)return r.ddIndent<0?!1:ys(r,e)>=0;if(d=e+1,r.isEmpty(d)&&++d>t||r.tShift[d]<r.blkIndent||(i=ys(r,d),i<0)||r.level>=r.options.maxNesting)return!1;c=r.tokens.length,r.tokens.push({type:"dl_open",lines:l=[e,0],level:r.level++}),o=e,n=d;e:for(;;){for(y=!0,g=!1,r.tokens.push({type:"dt_open",lines:[o,o],level:r.level++}),r.tokens.push({type:"inline",content:r.getLines(o,o+1,r.blkIndent,!1).trim(),level:r.level+1,lines:[o,o],children:[]}),r.tokens.push({type:"dt_close",level:--r.level});;){if(r.tokens.push({type:"dd_open",lines:a=[d,0],level:r.level++}),f=r.tight,h=r.ddIndent,u=r.blkIndent,m=r.tShift[n],p=r.parentType,r.blkIndent=r.ddIndent=r.tShift[n]+2,r.tShift[n]=i-r.bMarks[n],r.tight=!0,r.parentType="deflist",r.parser.tokenize(r,n,t,!0),(!r.tight||g)&&(y=!1),g=r.line-n>1&&r.isEmpty(r.line-1),r.tShift[n]=m,r.tight=f,r.parentType=p,r.blkIndent=u,r.ddIndent=h,r.tokens.push({type:"dd_close",level:--r.level}),a[1]=d=r.line,d>=t||r.tShift[d]<r.blkIndent)break e;if(i=ys(r,d),i<0)break;n=d;}if(d>=t||(o=d,r.isEmpty(o))||r.tShift[o]<r.blkIndent||(n=o+1,n>=t)||(r.isEmpty(n)&&n++,n>=t)||r.tShift[n]<r.blkIndent||(i=ys(r,n),i<0))break;}return r.tokens.push({type:"dl_close",level:--r.level}),l[1]=d,r.line=d,y&&eo(r,c),!0;}function so(r,e){var t,s,i,n,o,a=e+1,l;if(t=r.lineMax,a<t&&!r.isEmpty(a)){for(l=r.parser.ruler.getRules("paragraph");a<t&&!r.isEmpty(a);a++)if(!(r.tShift[a]-r.blkIndent>3)){for(i=!1,n=0,o=l.length;n<o;n++)if(l[n](r,a,t,!0)){i=!0;break;}if(i)break;}}return s=r.getLines(e,a,r.blkIndent,!1).trim(),r.line=a,s.length&&(r.tokens.push({type:"paragraph_open",tight:!1,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:s,level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"paragraph_close",tight:!1,level:r.level})),!0;}var bs=[["code",jr],["fences",Hr,["paragraph","blockquote","list"]],["blockquote",qr,["paragraph","blockquote","list"]],["hr",Vr,["paragraph","blockquote","list"]],["list",zr,["paragraph","blockquote"]],["footnote",Kr,["paragraph"]],["heading",$r,["paragraph","blockquote"]],["lheading",Jr],["htmlblock",Zr,["paragraph","blockquote"]],["table",Qr,["paragraph"]],["deflist",to,["paragraph"]],["paragraph",so]];function Bi(){this.ruler=new ce();for(var r=0;r<bs.length;r++)this.ruler.push(bs[r][0],bs[r][1],{alt:(bs[r][2]||[]).slice()});}Bi.prototype.tokenize=function(r,e,t){for(var s=this.ruler.getRules(""),i=s.length,n=e,o=!1,a,l;n<t&&(r.line=n=r.skipEmptyLines(n),!(n>=t||r.tShift[n]<r.blkIndent));){for(l=0;l<i&&(a=s[l](r,n,t,!1),!a);l++);if(r.tight=!o,r.isEmpty(r.line-1)&&(o=!0),n=r.line,n<t&&r.isEmpty(n)){if(o=!0,n++,n<t&&r.parentType==="list"&&r.isEmpty(n))break;r.line=n;}}};var io=/[\n\t]/g,no=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,ro=/\u00a0/g;Bi.prototype.parse=function(r,e,t,s){var i,n=0,o=0;if(!r)return[];r=r.replace(ro," "),r=r.replace(no,"\n"),r.indexOf(" ")>=0&&(r=r.replace(io,function(a,l){var c;return r.charCodeAt(l)===10?(n=l+1,o=0,a):(c=" ".slice((l-n-o)%4),o=l-n+1,c);})),i=new pt(r,this,e,t,s),this.tokenize(i,i.line,i.lineMax);};function oo(r){switch(r){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 ao(r,e){for(var t=r.pos;t<r.posMax&&!oo(r.src.charCodeAt(t));)t++;return t===r.pos?!1:(e||(r.pending+=r.src.slice(r.pos,t)),r.pos=t,!0);}function lo(r,e){var t,s,i=r.pos;if(r.src.charCodeAt(i)!==10)return!1;if(t=r.pending.length-1,s=r.posMax,!e)if(t>=0&&r.pending.charCodeAt(t)===32){if(t>=1&&r.pending.charCodeAt(t-1)===32){for(var n=t-2;n>=0;n--)if(r.pending.charCodeAt(n)!==32){r.pending=r.pending.substring(0,n+1);break;}r.push({type:"hardbreak",level:r.level});}else r.pending=r.pending.slice(0,-1),r.push({type:"softbreak",level:r.level});}else r.push({type:"softbreak",level:r.level});for(i++;i<s&&r.src.charCodeAt(i)===32;)i++;return r.pos=i,!0;}var Fi=[];for(var an=0;an<256;an++)Fi.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){Fi[r.charCodeAt(0)]=1;});function co(r,e){var t,s=r.pos,i=r.posMax;if(r.src.charCodeAt(s)!==92)return!1;if(s++,s<i){if(t=r.src.charCodeAt(s),t<256&&Fi[t]!==0)return e||(r.pending+=r.src[s]),r.pos+=2,!0;if(t===10){for(e||r.push({type:"hardbreak",level:r.level}),s++;s<i&&r.src.charCodeAt(s)===32;)s++;return r.pos=s,!0;}}return e||(r.pending+="\\"),r.pos++,!0;}function ho(r,e){var t,s,i,n,o,a=r.pos,l=r.src.charCodeAt(a);if(l!==96)return!1;for(t=a,a++,s=r.posMax;a<s&&r.src.charCodeAt(a)===96;)a++;for(i=r.src.slice(t,a),n=o=a;(n=r.src.indexOf("`",o))!==-1;){for(o=n+1;o<s&&r.src.charCodeAt(o)===96;)o++;if(o-n===i.length)return e||r.push({type:"code",content:r.src.slice(a,n).replace(/[ \n]+/g," ").trim(),block:!1,level:r.level}),r.pos=o,!0;}return e||(r.pending+=i),r.pos+=i.length,!0;}function uo(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==126||e||o+4>=n||r.src.charCodeAt(o+1)!==126||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===126)||l===126||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===126;)s++;if(s>o+3)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===126&&r.src.charCodeAt(r.pos+1)===126&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==126&&a!==126&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"del_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"del_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function po(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==43||e||o+4>=n||r.src.charCodeAt(o+1)!==43||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===43)||l===43||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===43;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===43&&r.src.charCodeAt(r.pos+1)===43&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==43&&a!==43&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"ins_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"ins_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function fo(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==61||e||o+4>=n||r.src.charCodeAt(o+1)!==61||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===61)||l===61||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===61;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===61&&r.src.charCodeAt(r.pos+1)===61&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==61&&a!==61&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"mark_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"mark_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function ln(r){return r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122;}function cn(r,e){var t=e,s,i,n,o=!0,a=!0,l=r.posMax,c=r.src.charCodeAt(e);for(s=e>0?r.src.charCodeAt(e-1):-1;t<l&&r.src.charCodeAt(t)===c;)t++;return t>=l&&(o=!1),n=t-e,n>=4?o=a=!1:(i=t<l?r.src.charCodeAt(t):-1,(i===32||i===10)&&(o=!1),(s===32||s===10)&&(a=!1),c===95&&(ln(s)&&(o=!1),ln(i)&&(a=!1))),{can_open:o,can_close:a,delims:n};}function mo(r,e){var t,s,i,n,o,a,l,c=r.posMax,d=r.pos,u=r.src.charCodeAt(d);if(u!==95&&u!==42||e)return!1;if(l=cn(r,d),t=l.delims,!l.can_open)return r.pos+=t,e||(r.pending+=r.src.slice(d,r.pos)),!0;if(r.level>=r.options.maxNesting)return!1;for(r.pos=d+t,a=[t];r.pos<c;){if(r.src.charCodeAt(r.pos)===u){if(l=cn(r,r.pos),s=l.delims,l.can_close){for(n=a.pop(),o=s;n!==o;){if(o<n){a.push(n-o);break;}if(o-=n,a.length===0)break;r.pos+=n,n=a.pop();}if(a.length===0){t=n,i=!0;break;}r.pos+=s;continue;}l.can_open&&a.push(s),r.pos+=s;continue;}r.parser.skipToken(r);}return i?(r.posMax=r.pos,r.pos=d+t,e||((t===2||t===3)&&r.push({type:"strong_open",level:r.level++}),(t===1||t===3)&&r.push({type:"em_open",level:r.level++}),r.parser.tokenize(r),(t===1||t===3)&&r.push({type:"em_close",level:--r.level}),(t===2||t===3)&&r.push({type:"strong_close",level:--r.level})),r.pos=r.posMax+t,r.posMax=c,!0):(r.pos=d,!1);}var go=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function yo(r,e){var t,s,i=r.posMax,n=r.pos;if(r.src.charCodeAt(n)!==126||e||n+2>=i||r.level>=r.options.maxNesting)return!1;for(r.pos=n+1;r.pos<i;){if(r.src.charCodeAt(r.pos)===126){t=!0;break;}r.parser.skipToken(r);}return!t||n+1===r.pos||(s=r.src.slice(n+1,r.pos),s.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=n,!1):(r.posMax=r.pos,r.pos=n+1,e||r.push({type:"sub",level:r.level,content:s.replace(go,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}var bo=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function vo(r,e){var t,s,i=r.posMax,n=r.pos;if(r.src.charCodeAt(n)!==94||e||n+2>=i||r.level>=r.options.maxNesting)return!1;for(r.pos=n+1;r.pos<i;){if(r.src.charCodeAt(r.pos)===94){t=!0;break;}r.parser.skipToken(r);}return!t||n+1===r.pos||(s=r.src.slice(n+1,r.pos),s.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=n,!1):(r.posMax=r.pos,r.pos=n+1,e||r.push({type:"sup",level:r.level,content:s.replace(bo,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}function Eo(r,e){var t,s,i,n,o,a,l,c,d=!1,u=r.pos,h=r.posMax,p=r.pos,m=r.src.charCodeAt(p);if(m===33&&(d=!0,m=r.src.charCodeAt(++p)),m!==91||r.level>=r.options.maxNesting||(t=p+1,s=rs(r,p),s<0))return!1;if(a=s+1,a<h&&r.src.charCodeAt(a)===40){for(a++;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a>=h)return!1;for(p=a,Gn(r,a)?(n=r.linkContent,a=r.pos):n="",p=a;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<h&&p!==a&&zn(r,a))for(o=r.linkContent,a=r.pos;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);else o="";if(a>=h||r.src.charCodeAt(a)!==41)return r.pos=u,!1;a++;}else{if(r.linkLevel>0)return!1;for(;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<h&&r.src.charCodeAt(a)===91&&(p=a+1,a=rs(r,a),a>=0?i=r.src.slice(p,a++):a=p-1),i||(_typeof(i)>"u"&&(a=s+1),i=r.src.slice(t,s)),l=r.env.references[Kn(i)],!l)return r.pos=u,!1;n=l.href,o=l.title;}return e||(r.pos=t,r.posMax=s,d?r.push({type:"image",src:n,title:o,alt:r.src.substr(t,s-t),level:r.level}):(r.push({type:"link_open",href:n,title:o,level:r.level++}),r.linkLevel++,r.parser.tokenize(r),r.linkLevel--,r.push({type:"link_close",level:--r.level}))),r.pos=a,r.posMax=h,!0;}function _o(r,e){var t,s,i,n,o=r.posMax,a=r.pos;return a+2>=o||r.src.charCodeAt(a)!==94||r.src.charCodeAt(a+1)!==91||r.level>=r.options.maxNesting||(t=a+2,s=rs(r,a+1),s<0)?!1:(e||(r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.list||(r.env.footnotes.list=[]),i=r.env.footnotes.list.length,r.pos=t,r.posMax=s,r.push({type:"footnote_ref",id:i,level:r.level}),r.linkLevel++,n=r.tokens.length,r.parser.tokenize(r),r.env.footnotes.list[i]={tokens:r.tokens.splice(n)},r.linkLevel--),r.pos=s+1,r.posMax=o,!0);}function So(r,e){var t,s,i,n,o=r.posMax,a=r.pos;if(a+3>o||!r.env.footnotes||!r.env.footnotes.refs||r.src.charCodeAt(a)!==91||r.src.charCodeAt(a+1)!==94||r.level>=r.options.maxNesting)return!1;for(s=a+2;s<o;s++){if(r.src.charCodeAt(s)===32||r.src.charCodeAt(s)===10)return!1;if(r.src.charCodeAt(s)===93)break;}return s===a+2||s>=o||(s++,t=r.src.slice(a+2,s-1),_typeof(r.env.footnotes.refs[":"+t])>"u")?!1:(e||(r.env.footnotes.list||(r.env.footnotes.list=[]),r.env.footnotes.refs[":"+t]<0?(i=r.env.footnotes.list.length,r.env.footnotes.list[i]={label:t,count:0},r.env.footnotes.refs[":"+t]=i):i=r.env.footnotes.refs[":"+t],n=r.env.footnotes.list[i].count,r.env.footnotes.list[i].count++,r.push({type:"footnote_ref",id:i,subId:n,level:r.level})),r.pos=s,r.posMax=o,!0);}var xo=["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"],wo=/^<([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])?)*)>/,Ao=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Co(r,e){var t,s,i,n,o,a=r.pos;return r.src.charCodeAt(a)!==60||(t=r.src.slice(a),t.indexOf(">")<0)?!1:(s=t.match(Ao),s?xo.indexOf(s[1].toLowerCase())<0||(n=s[0].slice(1,-1),o=gi(n),!r.parser.validateLink(n))?!1:(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:n,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=s[0].length,!0):(i=t.match(wo),i?(n=i[0].slice(1,-1),o=gi("mailto:"+n),r.parser.validateLink(o)?(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:n,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=i[0].length,!0):!1):!1));}function ti(r,e){return r=r.source,e=e||"",function t(s,i){return s?(i=i.source||i,r=r.replace(s,i),t):new RegExp(r,e);};}var To=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Ro=/[^"'=<>`\x00-\x20]+/,Mo=/'[^']*'/,ko=/"[^"]*"/,Lo=ti(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Ro)("single_quoted",Mo)("double_quoted",ko)(),Io=ti(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",To)("attr_value",Lo)(),Oo=ti(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",Io)(),Po=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,No=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Do=/<[?].*?[?]>/,Bo=/<![A-Z]+\s+[^>]*>/,Fo=/<!\[CDATA\[[\s\S]*?\]\]>/,Uo=ti(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Oo)("close_tag",Po)("comment",No)("processing",Do)("declaration",Bo)("cdata",Fo)();function jo(r){var e=r|32;return e>=97&&e<=122;}function Ho(r,e){var t,s,i,n=r.pos;return!r.options.html||(i=r.posMax,r.src.charCodeAt(n)!==60||n+2>=i)||(t=r.src.charCodeAt(n+1),t!==33&&t!==63&&t!==47&&!jo(t))||(s=r.src.slice(n).match(Uo),!s)?!1:(e||r.push({type:"htmltag",content:r.src.slice(n,n+s[0].length),level:r.level}),r.pos+=s[0].length,!0);}var qo=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Vo=/^&([a-z][a-z0-9]{1,31});/i;function Go(r,e){var t,s,i,n=r.pos,o=r.posMax;if(r.src.charCodeAt(n)!==38)return!1;if(n+1<o){if(t=r.src.charCodeAt(n+1),t===35){if(i=r.src.slice(n).match(qo),i)return e||(s=i[1][0].toLowerCase()==="x"?parseInt(i[1].slice(1),16):parseInt(i[1],10),r.pending+=qn(s)?mi(s):mi(65533)),r.pos+=i[0].length,!0;}else if(i=r.src.slice(n).match(Vo),i){var a=jn(i[1]);if(i[1]!==a)return e||(r.pending+=a),r.pos+=i[0].length,!0;}}return e||(r.pending+="&"),r.pos++,!0;}var ui=[["text",ao],["newline",lo],["escape",co],["backticks",ho],["del",uo],["ins",po],["mark",fo],["emphasis",mo],["sub",yo],["sup",vo],["links",Eo],["footnote_inline",_o],["footnote_ref",So],["autolink",Co],["htmltag",Ho],["entity",Go]];function si(){this.ruler=new ce();for(var r=0;r<ui.length;r++)this.ruler.push(ui[r][0],ui[r][1]);this.validateLink=zo;}si.prototype.skipToken=function(r){var e=this.ruler.getRules(""),t=e.length,s=r.pos,i,n;if((n=r.cacheGet(s))>0){r.pos=n;return;}for(i=0;i<t;i++)if(e[i](r,!0)){r.cacheSet(s,r.pos);return;}r.pos++,r.cacheSet(s,r.pos);};si.prototype.tokenize=function(r){for(var e=this.ruler.getRules(""),t=e.length,s=r.posMax,i,n;r.pos<s;){for(n=0;n<t&&(i=e[n](r,!1),!i);n++);if(i){if(r.pos>=s)break;continue;}r.pending+=r.src[r.pos++];}r.pending&&r.pushPending();};si.prototype.parse=function(r,e,t,s){var i=new ut(r,this,e,t,s);this.tokenize(i);};function zo(r){var e=["vbscript","javascript","file","data"],t=r.trim().toLowerCase();return t=ct(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var Ko={options:{html:!1,// Enable HTML tags in source
|
21
|
+
},{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,s=e.type,i=e.src;return s==="audio"||(i==null?void 0:i.startsWith("data:audio"))||i&&t.test(i);}},{key:"isImageFile",value:function isImageFile(e){var t=e.type,s=e.src;return t==="image"||(s==null?void 0:s.startsWith("data:image"))||s&&he.isImageFileExtension(s);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();he.DEFAULT_FILE_NAME="file",he.FILE_BUBBLE_CLASS="file-message";var z=he;var X=/*#__PURE__*/function(){function X(){_classCallCheck(this,X);}return _createClass(X,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var s=e.containerStyle;s&&(Object.assign(t.style,s),console.error("The containerStyle property is deprecated since version 1.3.14."),console.error("Please change to using the style property instead: https://deepchat.dev/docs/styles#style"));}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
22
|
+
},{key:"handleResponseProperty",value:function handleResponseProperty(e){return console.error("The {result: ....} response object type is deprecated since version 1.3.0."),console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console.error("The initialMessages property is deprecated since version 2.0.0."),console.error("Please change to using the history property instead: https://deepchat.dev/docs/messages/#history"),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e.file;t&&(console.error("The file property in MessageContent is deprecated since version 1.3.17."),console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"),e.files=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console.error("The validateMessageBeforeSending property is deprecated since version 1.3.24."),console.error("Please change to using validateInput: https://deepchat.dev/docs/interceptors#validateInput"),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."),console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"),{text:e};}},{key:"flagHTMLUpdateClass",value:function flagHTMLUpdateClass(e){var t;(t=e.children[0])!=null&&t.classList.contains("deep-chat-update-message")&&(console.error('The "deep-chat-update-message" html class is deprecated since version 1.4.4.'),console.error("Please change to using {..., overwrite: true} object: https://deepchat.dev/docs/connect#Response"));}},{key:"processConnect",value:function processConnect(e){var t=e;t.request&&(t.connect?Object.assign(t.connect,t.request):t.connect=t.request,console.error("The request property is deprecated since version 2.0.0."),console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console.error("The stream property has been moved to the connect object in version 2.0.0."),console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var i;var s=e;s.onNewMessage&&(console.error("The onNewMessage event has been deprecated since version 2.0.0."),console.error("Please see the onMessage event: https://deepchat.dev/docs/events#onMessage"),(i=s.onNewMessage)==null||i.call(s,t)),e.dispatchEvent(new CustomEvent("new-message",{detail:t}));}},{key:"processFileConfigConnect",value:function processFileConfigConnect(e){var t=e;t.request&&(console.error("The request property in file configuration is deprecated since version 2.0.0."),console.error("Please use the connect property instead: https://deepchat.dev/docs/files"),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=JSON.parse(JSON.stringify(e)),s=t.loading;return s&&(s.outerContainer||s.innerContainer||s.bubble||s.media)&&(console.error("The loading message styles are defined using LoadingMessageStyles interface since version 2.1.0."),console.error("Check it out here: https://deepchat.dev/docs/messages/styles#LoadingMessageStyles"),t.loading={message:{styles:s}}),t;}},{key:"processDemo",value:function processDemo(e){return typeof e=="boolean"||e.displayLoadingBubble&&(console.error("The demo displayLoadingBubble property is deprecated since version 2.1.0."),console.error("Please use displayLoading instead: https://deepchat.dev/docs/modes#demo"),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,s="Please see the official documentation: https://deepchat.dev/docs/directConnection/Cohere";return t.chat&&(console.error("Cohere chat property is deprecated since version 2.2.3."),console.error(s),delete t.chat),t.textGeneration?(console.error("Cohere textGeneration is not supported since version 2.2.3."),console.error(s),delete t.textGeneration,!1):t.summarization?(console.error("Cohere summarization is not supported since version 2.2.3."),console.error(s),delete t.summarization,!1):!0;}// WORK - update link
|
23
|
+
},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!="object")return;var t=e.htmlWrappers;if(t)return console.error("The htmlWrappers property has been moved to Deep Chat's base since version 2.3.0."),console.error("Check it out here: https://deepchat.dev/docs/messages/HTML#htmlWrappers"),t;}}]);}();var Xe=/*#__PURE__*/function(){function Xe(){_classCallCheck(this,Xe);}return _createClass(Xe,null,[{key:"mouseUp",value:function mouseUp(e,t){N.unsetAllCSSMouseStates(e,t),Object.assign(e.style,t["default"]),Object.assign(e.style,t.hover);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e.style,t.click);}},{key:"mouseLeave",value:function mouseLeave(e,t){N.unsetAllCSSMouseStates(e,t),Object.assign(e.style,t["default"]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e.style,t.hover);}},{key:"add",value:function add(e,t){e.addEventListener("mouseenter",Xe.mouseEnter.bind(this,e,t)),e.addEventListener("mouseleave",Xe.mouseLeave.bind(this,e,t)),e.addEventListener("mousedown",Xe.mouseDown.bind(this,e,t)),e.addEventListener("mouseup",Xe.mouseUp.bind(this,e,t));}}]);}();var cr="deep-chat-temporary-message",dr="deep-chat-suggestion-button",fi={"deep-chat-button":{styles:{"default":{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"},hover:{backgroundColor:"#fafafa"},click:{backgroundColor:"#f1f1f1"}}}},Zi=Object.keys(fi);var Ce=/*#__PURE__*/function(){function Ce(){_classCallCheck(this,Ce);}return _createClass(Ce,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener("click",function(){var s,i;(i=e.submitUserMessage)==null||i.call(e,{text:((s=t.textContent)==null?void 0:s.trim())||""});});});}},{key:"isElementTemporary",value:function isElementTemporary(e){var t;return e?(t=e.bubbleElement.children[0])==null?void 0:t.classList.contains(cr):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return Zi.find(function(t){return e.classList.contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var s=fi[t].events;Object.keys(s||[]).forEach(function(i){e.addEventListener(i,s==null?void 0:s[i]);});}},{key:"getProcessedStyles",value:function getProcessedStyles(e,t,s){var i=Array.from(t.classList).reduce(function(a,l){var d;var c=(d=e[l])==null?void 0:d.styles;return c&&e[l].styles&&a.push(c),a;},[]),n=fi[s].styles;if(n){var a=JSON.parse(JSON.stringify(n));a["default"]&&N.overwriteDefaultWithAlreadyApplied(a,t),i.unshift(a);}var o=N.mergeStatefulStyles(i);return N.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,s){Zi.forEach(function(n){var o=s.getElementsByClassName(n);Array.from(o||[]).forEach(function(a){var l=Ce.getProcessedStyles(t,a,n);ee.applyStylesToElement(a,l),Ce.applyEvents(a,n);});});var i=s.getElementsByClassName(dr);Array.from(i).forEach(function(n){return Ce.applySuggestionEvent(e,n);});}}]);}();var ye=/*#__PURE__*/function(){function ye(){_classCallCheck(this,ye);}return _createClass(ye,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var s=N.processStateful(t);Xe.add(e,s),Object.assign(e.style,s["default"]);}},{key:"applyEventsToElement",value:function applyEventsToElement(e,t){Object.keys(t).forEach(function(s){var i=t[s];i&&e.addEventListener(s,i);});}},{key:"applyClassUtilitiesToElement",value:function applyClassUtilitiesToElement(e,t){var s=t.events,i=t.styles;s&&ye.applyEventsToElement(e,s),i&&!Ce.doesElementContainDeepChatClass(e)&&ye.applyStylesToElement(e,i);}},{key:"applyCustomClassUtilities",value:function applyCustomClassUtilities(e,t){Object.keys(e).forEach(function(s){var i=t.getElementsByClassName(s);Array.from(i).forEach(function(n){e[s]&&ye.applyClassUtilitiesToElement(n,e[s]);});});}},{key:"apply",value:function apply(e,t){Ce.applyDeepChatUtilities(e,e.htmlClassUtilities,t),ye.applyCustomClassUtilities(e.htmlClassUtilities,t);}},{key:"traverseNodes",value:function traverseNodes(e,t){e.nodeType===Node.ELEMENT_NODE&&t.push(e.outerHTML),e.childNodes.forEach(function(s){ye.traverseNodes(s,t);});}},{key:"splitHTML",value:function splitHTML(e){var s=new DOMParser().parseFromString(e,"text/html"),i=[];return s.body.childNodes.forEach(function(n){ye.traverseNodes(n,i);}),i;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=document.createElement("div");return t.innerHTML=e,Ce.isElementTemporary({outerContainer:t,bubbleElement:t,innerContainer:t});}// useful for removing event listeners
|
24
|
+
},{key:"replaceElementWithNewClone",value:function replaceElementWithNewClone(e,t){var i;var s=(t||e).cloneNode(!0);return(i=e.parentNode)==null||i.replaceChild(s,e),s;}},{key:"tryAddWrapper",value:function tryAddWrapper(e,t,s,i){if(t&&i){var n=(s==null?void 0:s[i])||(s==null?void 0:s["default"]);if(n)return e.innerHTML=n,{contentEl:ye.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(ye.TARGET_WRAPPER_CLASS)[0]||e;}}]);}();ye.TARGET_WRAPPER_CLASS="html-wrapper";var ee=ye;var Ne=/*#__PURE__*/function(){function Ne(){_classCallCheck(this,Ne);}return _createClass(Ne,null,[{key:"addElement",value:function addElement(e,t){e.appendOuterContainerElemet(t),e.focusMode||(e.elementRef.scrollTop=e.elementRef.scrollHeight);}},{key:"createElements",value:function createElements(e,t,s,i){var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;var o=e.createMessageElementsOnOrientation("",s,i,n);o.bubbleElement.classList.add(Ne.HTML_BUBBLE_CLASS);var _ee$tryAddWrapper=ee.tryAddWrapper(o.bubbleElement,t,e._customWrappers,s),a=_ee$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,s){s.bubbleElement.innerHTML=t,ee.apply(e,s.outerContainer),X.flagHTMLUpdateClass(s.bubbleElement);}// prettier-ignore
|
25
|
+
},{key:"overwrite",value:function overwrite(e,t,s,i){var n=e.messageToElements,o=b.overwriteMessage(n,i,t,s,"html",Ne.HTML_BUBBLE_CLASS);return o&&Ne.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var n=Ne.createElements(e,t,s,i);return b.fillEmptyMessageElement(n.bubbleElement,t),ee.apply(e,n.outerContainer),X.flagHTMLUpdateClass(n.bubbleElement),e.applyCustomStyles(n,s,!1,(o=e.messageStyles)==null?void 0:o.html),n;}},{key:"add",value:function add(e,t,s,i){var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(i!=null&&i.status){var a=this.overwrite(e,t,s,e.messageElementRefs);if(a)return a;i.status=!1;}if(n&&e.messageElementRefs.length>0&&ee.isTemporaryBasedOnHTML(t))return;var o=Ne.create(e,t,s,n);return n||Ne.addElement(e,o.outerContainer),o;}}]);}();Ne.HTML_BUBBLE_CLASS="html-message";var Te=Ne;var hr=/*#__PURE__*/function(){function hr(){_classCallCheck(this,hr);}return _createClass(hr,null,[{key:"katex",value:function katex(e,t,s){var a=(s||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var l=function l(u,h){var p;return((p=window.katex)==null?void 0:p.renderToString(u,_objectSpread({displayMode:h,throwOnError:!1,output:"mathml"},e)))||"";},c=function c(u,h,p){var m=!1,f=u.bMarks[h]+u.tShift[h],g=u.eMarks[h];if(f+1>g)return!1;var y=u.src.charAt(f);if(y!==a)return!1;var T=f;f=u.skipChars(f,y);var L=f-T;if(L!==2)return!1;var O=h;for(;++O,!(O>=p||(f=T=u.bMarks[O]+u.tShift[O],g=u.eMarks[O],f<g&&u.tShift[O]<u.blkIndent));)if(u.src.charAt(f)===a&&!(u.tShift[O]-u.blkIndent>=4)&&(f=u.skipChars(f,y),!(f-T<L)&&(f=u.skipSpaces(f),!(f<g)))){m=!0;break;}L=u.tShift[h],u.line=O+(m?1:0);var U=u.getLines(h+1,O,L,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:U,lines:[h,u.line],level:u.level,block:!0}),!0;},d=function d(u,h){var p=u.pos,m=u.posMax;var f=p;if(u.src.charAt(f)!==a)return!1;for(++f;f<m&&u.src.charAt(f)===a;)++f;var g=u.src.slice(p,f);if(g.length>2)return!1;var y=f;var T=0;for(;f<m;){var L=u.src.charAt(f);if(L==="{"&&(f===0||u.src.charAt(f-1)!=="\\"))T+=1;else if(L==="}"&&(f===0||u.src.charAt(f-1)!=="\\")){if(T-=1,T<0)return!1;}else if(L===a&&T===0){var O=f;var U=f+1;for(;U<m&&u.src.charAt(U)===a;)++U;if(U-O===g.length){if(!h){var ge=u.src.slice(y,O).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:ge,block:g.length>1,level:u.level});}return u.pos=U,!0;}}f+=1;}return h||(u.pending+=g),u.pos+=g.length,!0;};t.inline.ruler.push("katex",d,s),t.block.ruler.push("katex",c,s),t.renderer.rules.katex=function(u,h){return l(u[h].content,u[h].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var gs;function Fn(r){return gs=gs||document.createElement("textarea"),gs.innerHTML="&"+r+";",gs.value;}var ur=Object.prototype.hasOwnProperty;function pr(r,e){return r?ur.call(r,e):!1;}function Un(r){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(s){r[s]=t[s];});}}),r;}var fr=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ns(r){return r.indexOf("\\")<0?r:r.replace(fr,"$1");}function jn(r){return!(r>=55296&&r<=57343||r>=64976&&r<=65007||(r&65535)===65535||(r&65535)===65534||r>=0&&r<=8||r===11||r>=14&&r<=31||r>=127&&r<=159||r>1114111);}function mi(r){if(r>65535){r-=65536;var e=55296+(r>>10),t=56320+(r&1023);return String.fromCharCode(e,t);}return String.fromCharCode(r);}var mr=/&([a-z#][a-z0-9]{1,31});/gi,gr=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function yr(r,e){var t=0,s=Fn(e);return e!==s?s:e.charCodeAt(0)===35&&gr.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),jn(t))?mi(t):r;}function dt(r){return r.indexOf("&")<0?r:r.replace(mr,yr);}var br=/[&<>"]/,vr=/[&<>"]/g,Er={"&":"&","<":"<",">":">",'"':"""};function _r(r){return Er[r];}function ie(r){return br.test(r)?r.replace(vr,_r):r;}var v={};v.blockquote_open=function(){return"<blockquote>\n";};v.blockquote_close=function(r,e){return"</blockquote>"+ut(r,e);};v.code=function(r,e){return r[e].block?"<pre><code>"+ie(r[e].content)+"</code></pre>"+ut(r,e):"<code>"+ie(r[e].content)+"</code>";};v.fence=function(r,e,t,s,i){var n=r[e],o="",a=t.langPrefix,l="",c,d,u;if(n.params){if(c=n.params.split(/\s+/g),d=c.join(" "),pr(i.rules.fence_custom,c[0]))return i.rules.fence_custom[c[0]](r,e,t,s,i);l=ie(dt(ns(d))),o=' class="'+a+l+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[n.content].concat(c))||ie(n.content):u=ie(n.content),"<pre><code"+o+">"+u+"</code></pre>"+ut(r,e);};v.fence_custom={};v.heading_open=function(r,e){return"<h"+r[e].hLevel+">";};v.heading_close=function(r,e){return"</h"+r[e].hLevel+">\n";};v.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+ut(r,e);};v.bullet_list_open=function(){return"<ul>\n";};v.bullet_list_close=function(r,e){return"</ul>"+ut(r,e);};v.list_item_open=function(){return"<li>";};v.list_item_close=function(){return"</li>\n";};v.ordered_list_open=function(r,e){var t=r[e],s=t.order>1?' start="'+t.order+'"':"";return"<ol"+s+">\n";};v.ordered_list_close=function(r,e){return"</ol>"+ut(r,e);};v.paragraph_open=function(r,e){return r[e].tight?"":"<p>";};v.paragraph_close=function(r,e){var t=!(r[e].tight&&e&&r[e-1].type==="inline"&&!r[e-1].content);return(r[e].tight?"":"</p>")+(t?ut(r,e):"");};v.link_open=function(r,e,t){var s=r[e].title?' title="'+ie(dt(r[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+ie(r[e].href)+'"'+s+i+">";};v.link_close=function(){return"</a>";};v.image=function(r,e,t){var s=' src="'+ie(r[e].src)+'"',i=r[e].title?' title="'+ie(dt(r[e].title))+'"':"",n=' alt="'+(r[e].alt?ie(dt(ns(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+s+n+i+o+">";};v.table_open=function(){return"<table>\n";};v.table_close=function(){return"</table>\n";};v.thead_open=function(){return"<thead>\n";};v.thead_close=function(){return"</thead>\n";};v.tbody_open=function(){return"<tbody>\n";};v.tbody_close=function(){return"</tbody>\n";};v.tr_open=function(){return"<tr>";};v.tr_close=function(){return"</tr>\n";};v.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};v.th_close=function(){return"</th>";};v.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};v.td_close=function(){return"</td>";};v.strong_open=function(){return"<strong>";};v.strong_close=function(){return"</strong>";};v.em_open=function(){return"<em>";};v.em_close=function(){return"</em>";};v.del_open=function(){return"<del>";};v.del_close=function(){return"</del>";};v.ins_open=function(){return"<ins>";};v.ins_close=function(){return"</ins>";};v.mark_open=function(){return"<mark>";};v.mark_close=function(){return"</mark>";};v.sub=function(r,e){return"<sub>"+ie(r[e].content)+"</sub>";};v.sup=function(r,e){return"<sup>"+ie(r[e].content)+"</sup>";};v.hardbreak=function(r,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};v.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};v.text=function(r,e){return ie(r[e].content);};v.htmlblock=function(r,e){return r[e].content;};v.htmltag=function(r,e){return r[e].content;};v.abbr_open=function(r,e){return'<abbr title="'+ie(dt(r[e].title))+'">';};v.abbr_close=function(){return"</abbr>";};v.footnote_ref=function(r,e){var t=Number(r[e].id+1).toString(),s="fnref"+t;return r[e].subId>0&&(s+=":"+r[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+s+'">['+t+"]</a></sup>";};v.footnote_block_open=function(r,e,t){var s=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return s+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};v.footnote_block_close=function(){return"</ol>\n</section>\n";};v.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};v.footnote_close=function(){return"</li>\n";};v.footnote_anchor=function(r,e){var t=Number(r[e].id+1).toString(),s="fnref"+t;return r[e].subId>0&&(s+=":"+r[e].subId),' <a href="#'+s+'" class="footnote-backref">↩</a>';};v.dl_open=function(){return"<dl>\n";};v.dt_open=function(){return"<dt>";};v.dd_open=function(){return"<dd>";};v.dl_close=function(){return"</dl>\n";};v.dt_close=function(){return"</dt>\n";};v.dd_close=function(){return"</dd>\n";};function Hn(r,e){return++e>=r.length-2?e:r[e].type==="paragraph_open"&&r[e].tight&&r[e+1].type==="inline"&&r[e+1].content.length===0&&r[e+2].type==="paragraph_close"&&r[e+2].tight?Hn(r,e+2):e;}var ut=v.getBreak=function(e,t){return t=Hn(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function Pi(){this.rules=Un({},v),this.getBreak=v.getBreak;}Pi.prototype.renderInline=function(r,e,t){for(var s=this.rules,i=r.length,n=0,o="";i--;)o+=s[r[n].type](r,n++,e,t,this);return o;};Pi.prototype.render=function(r,e,t){for(var s=this.rules,i=r.length,n=-1,o="";++n<i;)r[n].type==="inline"?o+=this.renderInline(r[n].children,e,t):o+=s[r[n].type](r,n,e,t,this);return o;};function ce(){this.__rules__=[],this.__cache__=null;}ce.prototype.__find__=function(r){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===r)return t;return-1;};ce.prototype.__compile__=function(){var r=this,e=[""];r.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(s){e.indexOf(s)<0&&e.push(s);});}),r.__cache__={},e.forEach(function(t){r.__cache__[t]=[],r.__rules__.forEach(function(s){s.enabled&&(t&&s.alt.indexOf(t)<0||r.__cache__[t].push(s.fn));});});};ce.prototype.at=function(r,e,t){var s=this.__find__(r),i=t||{};if(s===-1)throw new Error("Parser rule not found: "+r);this.__rules__[s].fn=e,this.__rules__[s].alt=i.alt||[],this.__cache__=null;};ce.prototype.before=function(r,e,t,s){var i=this.__find__(r),n=s||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i,0,{name:e,enabled:!0,fn:t,alt:n.alt||[]}),this.__cache__=null;};ce.prototype.after=function(r,e,t,s){var i=this.__find__(r),n=s||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i+1,0,{name:e,enabled:!0,fn:t,alt:n.alt||[]}),this.__cache__=null;};ce.prototype.push=function(r,e,t){var s=t||{};this.__rules__.push({name:r,enabled:!0,fn:e,alt:s.alt||[]}),this.__cache__=null;};ce.prototype.enable=function(r,e){r=Array.isArray(r)?r:[r],e&&this.__rules__.forEach(function(t){t.enabled=!1;}),r.forEach(function(t){var s=this.__find__(t);if(s<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[s].enabled=!0;},this),this.__cache__=null;};ce.prototype.disable=function(r){r=Array.isArray(r)?r:[r],r.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;};ce.prototype.getRules=function(r){return this.__cache__===null&&this.__compile__(),this.__cache__[r]||[];};function Sr(r){r.inlineMode?r.tokens.push({type:"inline",content:r.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):r.block.parse(r.src,r.options,r.env,r.tokens);}function pt(r,e,t,s,i){this.src=r,this.env=s,this.options=t,this.parser=e,this.tokens=i,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;}pt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};pt.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level;};pt.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e;};pt.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0;};function rs(r,e){var t,s,i,n=-1,o=r.posMax,a=r.pos,l=r.isInLabel;if(r.isInLabel)return-1;if(r.labelUnmatchedScopes)return r.labelUnmatchedScopes--,-1;for(r.pos=e+1,r.isInLabel=!0,t=1;r.pos<o;){if(i=r.src.charCodeAt(r.pos),i===91)t++;else if(i===93&&(t--,t===0)){s=!0;break;}r.parser.skipToken(r);}return s?(n=r.pos,r.labelUnmatchedScopes=0):r.labelUnmatchedScopes=t-1,r.pos=a,r.isInLabel=l,n;}function xr(r,e,t,s){var i,n,o,a,l,c;if(r.charCodeAt(0)!==42||r.charCodeAt(1)!==91||r.indexOf("]:")===-1||(i=new pt(r,e,t,s,[]),n=rs(i,1),n<0||r.charCodeAt(n+1)!==58))return-1;for(a=i.posMax,o=n+2;o<a&&i.src.charCodeAt(o)!==10;o++);return l=r.slice(2,n),c=r.slice(n+2,o).trim(),c.length===0?-1:(s.abbreviations||(s.abbreviations={}),_typeof(s.abbreviations[":"+l])>"u"&&(s.abbreviations[":"+l]=c),o);}function wr(r){var e=r.tokens,t,s,i,n;if(!r.inlineMode){for(t=1,s=e.length-1;t<s;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(n=xr(i,r.inline,r.options,r.env),!(n<0));)i=i.slice(n).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function gi(r){var e=dt(r);try{e=decodeURI(e);}catch(_unused3){}return encodeURI(e);}function qn(r,e){var t,s,i,n=e,o=r.posMax;if(r.src.charCodeAt(e)===60){for(e++;e<o;){if(t=r.src.charCodeAt(e),t===10)return!1;if(t===62)return i=gi(ns(r.src.slice(n+1,e))),r.parser.validateLink(i)?(r.pos=e+1,r.linkContent=i,!0):!1;if(t===92&&e+1<o){e+=2;continue;}e++;}return!1;}for(s=0;e<o&&(t=r.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue;}if(t===40&&(s++,s>1)||t===41&&(s--,s<0))break;e++;}return n===e||(i=ns(r.src.slice(n,e)),!r.parser.validateLink(i))?!1:(r.linkContent=i,r.pos=e,!0);}function Vn(r,e){var t,s=e,i=r.posMax,n=r.src.charCodeAt(e);if(n!==34&&n!==39&&n!==40)return!1;for(e++,n===40&&(n=41);e<i;){if(t=r.src.charCodeAt(e),t===n)return r.pos=e+1,r.linkContent=ns(r.src.slice(s+1,e)),!0;if(t===92&&e+1<i){e+=2;continue;}e++;}return!1;}function Gn(r){return r.trim().replace(/\s+/g," ").toUpperCase();}function Ar(r,e,t,s){var i,n,o,a,l,c,d,u,h;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(i=new pt(r,e,t,s,[]),n=rs(i,0),n<0||r.charCodeAt(n+1)!==58))return-1;for(a=i.posMax,o=n+2;o<a&&(l=i.src.charCodeAt(o),!(l!==32&&l!==10));o++);if(!qn(i,o))return-1;for(d=i.linkContent,o=i.pos,c=o,o=o+1;o<a&&(l=i.src.charCodeAt(o),!(l!==32&&l!==10));o++);for(o<a&&c!==o&&Vn(i,o)?(u=i.linkContent,o=i.pos):(u="",o=c);o<a&&i.src.charCodeAt(o)===32;)o++;return o<a&&i.src.charCodeAt(o)!==10?-1:(h=Gn(r.slice(1,n)),_typeof(s.references[h])>"u"&&(s.references[h]={title:u,href:d}),o);}function Cr(r){var e=r.tokens,t,s,i,n;if(r.env.references=r.env.references||{},!r.inlineMode){for(t=1,s=e.length-1;t<s;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(n=Ar(i,r.inline,r.options,r.env),!(n<0));)i=i.slice(n).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Tr(r){var e=r.tokens,t,s,i;for(s=0,i=e.length;s<i;s++)t=e[s],t.type==="inline"&&r.inline.parse(t.content,r.options,r.env,t.children);}function Rr(r){var e,t,s,i,n,o,a,l,c,d=0,u=!1,h={};if(r.env.footnotes&&(r.tokens=r.tokens.filter(function(p){return p.type==="footnote_reference_open"?(u=!0,l=[],c=p.label,!1):p.type==="footnote_reference_close"?(u=!1,h[":"+c]=l,!1):(u&&l.push(p),!u);}),!!r.env.footnotes.list)){for(o=r.env.footnotes.list,r.tokens.push({type:"footnote_block_open",level:d++}),e=0,t=o.length;e<t;e++){for(r.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=h[":"+o[e].label]),r.tokens=r.tokens.concat(a),r.tokens[r.tokens.length-1].type==="paragraph_close"?n=r.tokens.pop():n=null,i=o[e].count>0?o[e].count:1,s=0;s<i;s++)r.tokens.push({type:"footnote_anchor",id:e,subId:s,level:d});n&&r.tokens.push(n),r.tokens.push({type:"footnote_close",level:--d});}r.tokens.push({type:"footnote_block_close",level:--d});}}var Qi=" \n()[]'\".,!?-";function ci(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function Mr(r){var e,t,s,i,n,o,a,l,c,d,u,h,p=r.tokens;if(r.env.abbreviations){for(r.env.abbrRegExp||(h="(^|["+Qi.split("").map(ci).join("")+"])("+Object.keys(r.env.abbreviations).map(function(m){return m.substr(1);}).sort(function(m,f){return f.length-m.length;}).map(ci).join("|")+")($|["+Qi.split("").map(ci).join("")+"])",r.env.abbrRegExp=new RegExp(h,"g")),d=r.env.abbrRegExp,t=0,s=p.length;t<s;t++)if(p[t].type==="inline"){for(i=p[t].children,e=i.length-1;e>=0;e--)if(n=i[e],n.type==="text"){for(l=0,o=n.content,d.lastIndex=0,c=n.level,a=[];u=d.exec(o);)d.lastIndex>l&&a.push({type:"text",content:o.slice(l,u.index+u[1].length),level:c}),a.push({type:"abbr_open",title:r.env.abbreviations[":"+u[2]],level:c++}),a.push({type:"text",content:u[2],level:c}),a.push({type:"abbr_close",level:--c}),l=d.lastIndex-u[3].length;a.length&&(l<o.length&&a.push({type:"text",content:o.slice(l),level:c}),p[t].children=i=[].concat(i.slice(0,e),a,i.slice(e+1)));}}}}var kr=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Lr=/\((c|tm|r|p)\)/ig,Ir={c:"©",r:"®",p:"§",tm:"™"};function Or(r){return r.indexOf("(")<0?r:r.replace(Lr,function(e,t){return Ir[t.toLowerCase()];});}function Nr(r){var e,t,s,i,n;if(r.options.typographer){for(n=r.tokens.length-1;n>=0;n--)if(r.tokens[n].type==="inline")for(i=r.tokens[n].children,e=i.length-1;e>=0;e--)t=i[e],t.type==="text"&&(s=t.content,s=Or(s),kr.test(s)&&(s=s.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=s);}}var Pr=/['"]/,en=/['"]/g,Dr=/[-\s()\[\]]/,tn="’";function sn(r,e){return e<0||e>=r.length?!1:!Dr.test(r[e]);}function gt(r,e,t){return r.substr(0,e)+t+r.substr(e+1);}function Br(r){var e,t,s,i,n,o,a,l,c,d,u,h,p,m,f,g,y;if(r.options.typographer){for(y=[],f=r.tokens.length-1;f>=0;f--)if(r.tokens[f].type==="inline"){for(g=r.tokens[f].children,y.length=0,e=0;e<g.length;e++)if(t=g[e],!(t.type!=="text"||Pr.test(t.text))){for(a=g[e].level,p=y.length-1;p>=0&&!(y[p].level<=a);p--);y.length=p+1,s=t.content,n=0,o=s.length;e:for(;n<o&&(en.lastIndex=n,i=en.exec(s),!!i);){if(l=!sn(s,i.index-1),n=i.index+1,m=i[0]==="'",c=!sn(s,n),!c&&!l){m&&(t.content=gt(t.content,i.index,tn));continue;}if(u=!c,h=!l,h){for(p=y.length-1;p>=0&&(d=y[p],!(y[p].level<a));p--)if(d.single===m&&y[p].level===a){d=y[p],m?(g[d.token].content=gt(g[d.token].content,d.pos,r.options.quotes[2]),t.content=gt(t.content,i.index,r.options.quotes[3])):(g[d.token].content=gt(g[d.token].content,d.pos,r.options.quotes[0]),t.content=gt(t.content,i.index,r.options.quotes[1])),y.length=p;continue e;}}u?y.push({token:e,pos:i.index,single:m,level:a}):h&&m&&(t.content=gt(t.content,i.index,tn));}}}}}var di=[["block",Sr],["abbr",wr],["references",Cr],["inline",Tr],["footnote_tail",Rr],["abbr2",Mr],["replacements",Nr],["smartquotes",Br]];function zn(){this.options={},this.ruler=new ce();for(var r=0;r<di.length;r++)this.ruler.push(di[r][0],di[r][1]);}zn.prototype.process=function(r){var e,t,s;for(s=this.ruler.getRules(""),e=0,t=s.length;e<t;e++)s[e](r);};function ft(r,e,t,s,i){var n,o,a,l,c,d,u;for(this.src=r,this.parser=e,this.options=t,this.env=s,this.tokens=i,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,u=!1,a=l=d=0,c=o.length;l<c;l++){if(n=o.charCodeAt(l),!u)if(n===32){d++;continue;}else u=!0;(n===10||l===c-1)&&(n!==10&&l++,this.bMarks.push(a),this.eMarks.push(l),this.tShift.push(d),u=!1,d=0,a=l+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}ft.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};ft.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};ft.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};ft.prototype.skipChars=function(e,t){for(var s=this.src.length;e<s&&this.src.charCodeAt(e)===t;e++);return e;};ft.prototype.skipCharsBack=function(e,t,s){if(e<=s)return e;for(;e>s;)if(t!==this.src.charCodeAt(--e))return e+1;return e;};ft.prototype.getLines=function(e,t,s,i){var n,o,a,l,c,d=e;if(e>=t)return"";if(d+1===t)return o=this.bMarks[d]+Math.min(this.tShift[d],s),a=i?this.eMarks[d]+1:this.eMarks[d],this.src.slice(o,a);for(l=new Array(t-e),n=0;d<t;d++,n++)c=this.tShift[d],c>s&&(c=s),c<0&&(c=0),o=this.bMarks[d]+c,d+1<t||i?a=this.eMarks[d]+1:a=this.eMarks[d],l[n]=this.src.slice(o,a);return l.join("");};function Fr(r,e,t){var s,i;if(r.tShift[e]-r.blkIndent<4)return!1;for(i=s=e+1;s<t;){if(r.isEmpty(s)){s++;continue;}if(r.tShift[s]-r.blkIndent>=4){s++,i=s;continue;}break;}return r.line=s,r.tokens.push({type:"code",content:r.getLines(e,i,4+r.blkIndent,!0),block:!0,lines:[e,r.line],level:r.level}),!0;}function Ur(r,e,t,s){var i,n,o,a,l,c=!1,d=r.bMarks[e]+r.tShift[e],u=r.eMarks[e];if(d+3>u||(i=r.src.charCodeAt(d),i!==126&&i!==96)||(l=d,d=r.skipChars(d,i),n=d-l,n<3)||(o=r.src.slice(d,u).trim(),o.indexOf("`")>=0))return!1;if(s)return!0;for(a=e;a++,!(a>=t||(d=l=r.bMarks[a]+r.tShift[a],u=r.eMarks[a],d<u&&r.tShift[a]<r.blkIndent));)if(r.src.charCodeAt(d)===i&&!(r.tShift[a]-r.blkIndent>=4)&&(d=r.skipChars(d,i),!(d-l<n)&&(d=r.skipSpaces(d),!(d<u)))){c=!0;break;}return n=r.tShift[e],r.line=a+(c?1:0),r.tokens.push({type:"fence",params:o,content:r.getLines(e+1,a,n,!0),lines:[e,r.line],level:r.level}),!0;}function jr(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m,f=r.bMarks[e]+r.tShift[e],g=r.eMarks[e];if(f>g||r.src.charCodeAt(f++)!==62||r.level>=r.options.maxNesting)return!1;if(s)return!0;for(r.src.charCodeAt(f)===32&&f++,l=r.blkIndent,r.blkIndent=0,a=[r.bMarks[e]],r.bMarks[e]=f,f=f<g?r.skipSpaces(f):f,n=f>=g,o=[r.tShift[e]],r.tShift[e]=f-r.bMarks[e],u=r.parser.ruler.getRules("blockquote"),i=e+1;i<t&&(f=r.bMarks[i]+r.tShift[i],g=r.eMarks[i],!(f>=g));i++){if(r.src.charCodeAt(f++)===62){r.src.charCodeAt(f)===32&&f++,a.push(r.bMarks[i]),r.bMarks[i]=f,f=f<g?r.skipSpaces(f):f,n=f>=g,o.push(r.tShift[i]),r.tShift[i]=f-r.bMarks[i];continue;}if(n)break;for(m=!1,h=0,p=u.length;h<p;h++)if(u[h](r,i,t,!0)){m=!0;break;}if(m)break;a.push(r.bMarks[i]),o.push(r.tShift[i]),r.tShift[i]=-1337;}for(c=r.parentType,r.parentType="blockquote",r.tokens.push({type:"blockquote_open",lines:d=[e,0],level:r.level++}),r.parser.tokenize(r,e,i),r.tokens.push({type:"blockquote_close",level:--r.level}),r.parentType=c,d[1]=r.line,h=0;h<o.length;h++)r.bMarks[h+e]=a[h],r.tShift[h+e]=o[h];return r.blkIndent=l,!0;}function Hr(r,e,t,s){var i,n,o,a=r.bMarks[e],l=r.eMarks[e];if(a+=r.tShift[e],a>l||(i=r.src.charCodeAt(a++),i!==42&&i!==45&&i!==95))return!1;for(n=1;a<l;){if(o=r.src.charCodeAt(a++),o!==i&&o!==32)return!1;o===i&&n++;}return n<3?!1:(s||(r.line=e+1,r.tokens.push({type:"hr",lines:[e,r.line],level:r.level})),!0);}function nn(r,e){var t,s,i;return s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e],s>=i||(t=r.src.charCodeAt(s++),t!==42&&t!==45&&t!==43)||s<i&&r.src.charCodeAt(s)!==32?-1:s;}function rn(r,e){var t,s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e];if(s+1>=i||(t=r.src.charCodeAt(s++),t<48||t>57))return-1;for(;;){if(s>=i)return-1;if(t=r.src.charCodeAt(s++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return s<i&&r.src.charCodeAt(s)!==32?-1:s;}function qr(r,e){var t,s,i=r.level+2;for(t=e+2,s=r.tokens.length-2;t<s;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function Vr(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m,f,g,y,T,L,O,U,ge=!0,we,re,Ji,li;if((u=rn(r,e))>=0)g=!0;else if((u=nn(r,e))>=0)g=!1;else return!1;if(r.level>=r.options.maxNesting)return!1;if(f=r.src.charCodeAt(u-1),s)return!0;for(T=r.tokens.length,g?(d=r.bMarks[e]+r.tShift[e],m=Number(r.src.substr(d,u-d-1)),r.tokens.push({type:"ordered_list_open",order:m,lines:O=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:O=[e,0],level:r.level++}),i=e,L=!1,we=r.parser.ruler.getRules("list");i<t&&(y=r.skipSpaces(u),h=r.eMarks[i],y>=h?p=1:p=y-u,p>4&&(p=1),p<1&&(p=1),n=u-r.bMarks[i]+p,r.tokens.push({type:"list_item_open",lines:U=[e,0],level:r.level++}),a=r.blkIndent,l=r.tight,o=r.tShift[e],c=r.parentType,r.tShift[e]=y-r.bMarks[e],r.blkIndent=n,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||L)&&(ge=!1),L=r.line-e>1&&r.isEmpty(r.line-1),r.blkIndent=a,r.tShift[e]=o,r.tight=l,r.parentType=c,r.tokens.push({type:"list_item_close",level:--r.level}),i=e=r.line,U[1]=i,y=r.bMarks[e],!(i>=t||r.isEmpty(i)||r.tShift[i]<r.blkIndent));){for(li=!1,re=0,Ji=we.length;re<Ji;re++)if(we[re](r,i,t,!0)){li=!0;break;}if(li)break;if(g){if(u=rn(r,i),u<0)break;}else if(u=nn(r,i),u<0)break;if(f!==r.src.charCodeAt(u-1))break;}return r.tokens.push({type:g?"ordered_list_close":"bullet_list_close",level:--r.level}),O[1]=i,r.line=i,ge&&qr(r,T),!0;}function Gr(r,e,t,s){var i,n,o,a,l,c=r.bMarks[e]+r.tShift[e],d=r.eMarks[e];if(c+4>d||r.src.charCodeAt(c)!==91||r.src.charCodeAt(c+1)!==94||r.level>=r.options.maxNesting)return!1;for(a=c+2;a<d;a++){if(r.src.charCodeAt(a)===32)return!1;if(r.src.charCodeAt(a)===93)break;}return a===c+2||a+1>=d||r.src.charCodeAt(++a)!==58?!1:(s||(a++,r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.refs||(r.env.footnotes.refs={}),l=r.src.slice(c+2,a-2),r.env.footnotes.refs[":"+l]=-1,r.tokens.push({type:"footnote_reference_open",label:l,level:r.level++}),i=r.bMarks[e],n=r.tShift[e],o=r.parentType,r.tShift[e]=r.skipSpaces(a)-a,r.bMarks[e]=a,r.blkIndent+=4,r.parentType="footnote",r.tShift[e]<r.blkIndent&&(r.tShift[e]+=r.blkIndent,r.bMarks[e]-=r.blkIndent),r.parser.tokenize(r,e,t,!0),r.parentType=o,r.blkIndent-=4,r.tShift[e]=n,r.bMarks[e]=i,r.tokens.push({type:"footnote_reference_close",level:--r.level})),!0);}function zr(r,e,t,s){var i,n,o,a=r.bMarks[e]+r.tShift[e],l=r.eMarks[e];if(a>=l||(i=r.src.charCodeAt(a),i!==35||a>=l))return!1;for(n=1,i=r.src.charCodeAt(++a);i===35&&a<l&&n<=6;)n++,i=r.src.charCodeAt(++a);return n>6||a<l&&i!==32?!1:(s||(l=r.skipCharsBack(l,32,a),o=r.skipCharsBack(l,35,a),o>a&&r.src.charCodeAt(o-1)===32&&(l=o),r.line=e+1,r.tokens.push({type:"heading_open",hLevel:n,lines:[e,r.line],level:r.level}),a<l&&r.tokens.push({type:"inline",content:r.src.slice(a,l).trim(),level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"heading_close",hLevel:n,level:r.level})),!0);}function Kr(r,e,t){var s,i,n,o=e+1;return o>=t||r.tShift[o]<r.blkIndent||r.tShift[o]-r.blkIndent>3||(i=r.bMarks[o]+r.tShift[o],n=r.eMarks[o],i>=n)||(s=r.src.charCodeAt(i),s!==45&&s!==61)||(i=r.skipChars(i,s),i=r.skipSpaces(i),i<n)?!1:(i=r.bMarks[e]+r.tShift[e],r.line=o+1,r.tokens.push({type:"heading_open",hLevel:s===61?1:2,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:r.src.slice(i,r.eMarks[e]).trim(),level:r.level+1,lines:[e,r.line-1],children:[]}),r.tokens.push({type:"heading_close",hLevel:s===61?1:2,level:r.level}),!0);}var Kn={};["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(r){Kn[r]=!0;});var Wr=/^<([a-zA-Z]{1,15})[\s\/>]/,$r=/^<\/([a-zA-Z]{1,15})[\s>]/;function Jr(r){var e=r|32;return e>=97&&e<=122;}function Xr(r,e,t,s){var i,n,o,a=r.bMarks[e],l=r.eMarks[e],c=r.tShift[e];if(a+=c,!r.options.html||c>3||a+2>=l||r.src.charCodeAt(a)!==60)return!1;if(i=r.src.charCodeAt(a+1),i===33||i===63){if(s)return!0;}else if(i===47||Jr(i)){if(i===47){if(n=r.src.slice(a,l).match($r),!n)return!1;}else if(n=r.src.slice(a,l).match(Wr),!n)return!1;if(Kn[n[1].toLowerCase()]!==!0)return!1;if(s)return!0;}else return!1;for(o=e+1;o<r.lineMax&&!r.isEmpty(o);)o++;return r.line=o,r.tokens.push({type:"htmlblock",level:r.level,lines:[e,r.line],content:r.getLines(e,o,0,!0)}),!0;}function hi(r,e){var t=r.bMarks[e]+r.blkIndent,s=r.eMarks[e];return r.src.substr(t,s-t);}function Yr(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m;if(e+2>t||(l=e+1,r.tShift[l]<r.blkIndent)||(o=r.bMarks[l]+r.tShift[l],o>=r.eMarks[l])||(i=r.src.charCodeAt(o),i!==124&&i!==45&&i!==58)||(n=hi(r,e+1),!/^[-:| ]+$/.test(n))||(c=n.split("|"),c<=2))return!1;for(u=[],a=0;a<c.length;a++){if(h=c[a].trim(),!h){if(a===0||a===c.length-1)continue;return!1;}if(!/^:?-+:?$/.test(h))return!1;h.charCodeAt(h.length-1)===58?u.push(h.charCodeAt(0)===58?"center":"right"):h.charCodeAt(0)===58?u.push("left"):u.push("");}if(n=hi(r,e).trim(),n.indexOf("|")===-1||(c=n.replace(/^\||\|$/g,"").split("|"),u.length!==c.length))return!1;if(s)return!0;for(r.tokens.push({type:"table_open",lines:p=[e,0],level:r.level++}),r.tokens.push({type:"thead_open",lines:[e,e+1],level:r.level++}),r.tokens.push({type:"tr_open",lines:[e,e+1],level:r.level++}),a=0;a<c.length;a++)r.tokens.push({type:"th_open",align:u[a],lines:[e,e+1],level:r.level++}),r.tokens.push({type:"inline",content:c[a].trim(),lines:[e,e+1],level:r.level,children:[]}),r.tokens.push({type:"th_close",level:--r.level});for(r.tokens.push({type:"tr_close",level:--r.level}),r.tokens.push({type:"thead_close",level:--r.level}),r.tokens.push({type:"tbody_open",lines:m=[e+2,0],level:r.level++}),l=e+2;l<t&&!(r.tShift[l]<r.blkIndent||(n=hi(r,l).trim(),n.indexOf("|")===-1));l++){for(c=n.replace(/^\||\|$/g,"").split("|"),r.tokens.push({type:"tr_open",level:r.level++}),a=0;a<c.length;a++)r.tokens.push({type:"td_open",align:u[a],level:r.level++}),d=c[a].substring(c[a].charCodeAt(0)===124?1:0,c[a].charCodeAt(c[a].length-1)===124?c[a].length-1:c[a].length).trim(),r.tokens.push({type:"inline",content:d,level:r.level,children:[]}),r.tokens.push({type:"td_close",level:--r.level});r.tokens.push({type:"tr_close",level:--r.level});}return r.tokens.push({type:"tbody_close",level:--r.level}),r.tokens.push({type:"table_close",level:--r.level}),p[1]=m[1]=l,r.line=l,!0;}function ys(r,e){var t,s,i=r.bMarks[e]+r.tShift[e],n=r.eMarks[e];return i>=n||(s=r.src.charCodeAt(i++),s!==126&&s!==58)||(t=r.skipSpaces(i),i===t)||t>=n?-1:t;}function Zr(r,e){var t,s,i=r.level+2;for(t=e+2,s=r.tokens.length-2;t<s;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function Qr(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m,f,g,y;if(s)return r.ddIndent<0?!1:ys(r,e)>=0;if(d=e+1,r.isEmpty(d)&&++d>t||r.tShift[d]<r.blkIndent||(i=ys(r,d),i<0)||r.level>=r.options.maxNesting)return!1;c=r.tokens.length,r.tokens.push({type:"dl_open",lines:l=[e,0],level:r.level++}),o=e,n=d;e:for(;;){for(y=!0,g=!1,r.tokens.push({type:"dt_open",lines:[o,o],level:r.level++}),r.tokens.push({type:"inline",content:r.getLines(o,o+1,r.blkIndent,!1).trim(),level:r.level+1,lines:[o,o],children:[]}),r.tokens.push({type:"dt_close",level:--r.level});;){if(r.tokens.push({type:"dd_open",lines:a=[d,0],level:r.level++}),f=r.tight,h=r.ddIndent,u=r.blkIndent,m=r.tShift[n],p=r.parentType,r.blkIndent=r.ddIndent=r.tShift[n]+2,r.tShift[n]=i-r.bMarks[n],r.tight=!0,r.parentType="deflist",r.parser.tokenize(r,n,t,!0),(!r.tight||g)&&(y=!1),g=r.line-n>1&&r.isEmpty(r.line-1),r.tShift[n]=m,r.tight=f,r.parentType=p,r.blkIndent=u,r.ddIndent=h,r.tokens.push({type:"dd_close",level:--r.level}),a[1]=d=r.line,d>=t||r.tShift[d]<r.blkIndent)break e;if(i=ys(r,d),i<0)break;n=d;}if(d>=t||(o=d,r.isEmpty(o))||r.tShift[o]<r.blkIndent||(n=o+1,n>=t)||(r.isEmpty(n)&&n++,n>=t)||r.tShift[n]<r.blkIndent||(i=ys(r,n),i<0))break;}return r.tokens.push({type:"dl_close",level:--r.level}),l[1]=d,r.line=d,y&&Zr(r,c),!0;}function eo(r,e){var t,s,i,n,o,a=e+1,l;if(t=r.lineMax,a<t&&!r.isEmpty(a)){for(l=r.parser.ruler.getRules("paragraph");a<t&&!r.isEmpty(a);a++)if(!(r.tShift[a]-r.blkIndent>3)){for(i=!1,n=0,o=l.length;n<o;n++)if(l[n](r,a,t,!0)){i=!0;break;}if(i)break;}}return s=r.getLines(e,a,r.blkIndent,!1).trim(),r.line=a,s.length&&(r.tokens.push({type:"paragraph_open",tight:!1,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:s,level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"paragraph_close",tight:!1,level:r.level})),!0;}var bs=[["code",Fr],["fences",Ur,["paragraph","blockquote","list"]],["blockquote",jr,["paragraph","blockquote","list"]],["hr",Hr,["paragraph","blockquote","list"]],["list",Vr,["paragraph","blockquote"]],["footnote",Gr,["paragraph"]],["heading",zr,["paragraph","blockquote"]],["lheading",Kr],["htmlblock",Xr,["paragraph","blockquote"]],["table",Yr,["paragraph"]],["deflist",Qr,["paragraph"]],["paragraph",eo]];function Di(){this.ruler=new ce();for(var r=0;r<bs.length;r++)this.ruler.push(bs[r][0],bs[r][1],{alt:(bs[r][2]||[]).slice()});}Di.prototype.tokenize=function(r,e,t){for(var s=this.ruler.getRules(""),i=s.length,n=e,o=!1,a,l;n<t&&(r.line=n=r.skipEmptyLines(n),!(n>=t||r.tShift[n]<r.blkIndent));){for(l=0;l<i&&(a=s[l](r,n,t,!1),!a);l++);if(r.tight=!o,r.isEmpty(r.line-1)&&(o=!0),n=r.line,n<t&&r.isEmpty(n)){if(o=!0,n++,n<t&&r.parentType==="list"&&r.isEmpty(n))break;r.line=n;}}};var to=/[\n\t]/g,so=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,io=/\u00a0/g;Di.prototype.parse=function(r,e,t,s){var i,n=0,o=0;if(!r)return[];r=r.replace(io," "),r=r.replace(so,"\n"),r.indexOf(" ")>=0&&(r=r.replace(to,function(a,l){var c;return r.charCodeAt(l)===10?(n=l+1,o=0,a):(c=" ".slice((l-n-o)%4),o=l-n+1,c);})),i=new ft(r,this,e,t,s),this.tokenize(i,i.line,i.lineMax);};function no(r){switch(r){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 ro(r,e){for(var t=r.pos;t<r.posMax&&!no(r.src.charCodeAt(t));)t++;return t===r.pos?!1:(e||(r.pending+=r.src.slice(r.pos,t)),r.pos=t,!0);}function oo(r,e){var t,s,i=r.pos;if(r.src.charCodeAt(i)!==10)return!1;if(t=r.pending.length-1,s=r.posMax,!e)if(t>=0&&r.pending.charCodeAt(t)===32){if(t>=1&&r.pending.charCodeAt(t-1)===32){for(var n=t-2;n>=0;n--)if(r.pending.charCodeAt(n)!==32){r.pending=r.pending.substring(0,n+1);break;}r.push({type:"hardbreak",level:r.level});}else r.pending=r.pending.slice(0,-1),r.push({type:"softbreak",level:r.level});}else r.push({type:"softbreak",level:r.level});for(i++;i<s&&r.src.charCodeAt(i)===32;)i++;return r.pos=i,!0;}var Bi=[];for(var on=0;on<256;on++)Bi.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){Bi[r.charCodeAt(0)]=1;});function ao(r,e){var t,s=r.pos,i=r.posMax;if(r.src.charCodeAt(s)!==92)return!1;if(s++,s<i){if(t=r.src.charCodeAt(s),t<256&&Bi[t]!==0)return e||(r.pending+=r.src[s]),r.pos+=2,!0;if(t===10){for(e||r.push({type:"hardbreak",level:r.level}),s++;s<i&&r.src.charCodeAt(s)===32;)s++;return r.pos=s,!0;}}return e||(r.pending+="\\"),r.pos++,!0;}function lo(r,e){var t,s,i,n,o,a=r.pos,l=r.src.charCodeAt(a);if(l!==96)return!1;for(t=a,a++,s=r.posMax;a<s&&r.src.charCodeAt(a)===96;)a++;for(i=r.src.slice(t,a),n=o=a;(n=r.src.indexOf("`",o))!==-1;){for(o=n+1;o<s&&r.src.charCodeAt(o)===96;)o++;if(o-n===i.length)return e||r.push({type:"code",content:r.src.slice(a,n).replace(/[ \n]+/g," ").trim(),block:!1,level:r.level}),r.pos=o,!0;}return e||(r.pending+=i),r.pos+=i.length,!0;}function co(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==126||e||o+4>=n||r.src.charCodeAt(o+1)!==126||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===126)||l===126||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===126;)s++;if(s>o+3)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===126&&r.src.charCodeAt(r.pos+1)===126&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==126&&a!==126&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"del_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"del_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function ho(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==43||e||o+4>=n||r.src.charCodeAt(o+1)!==43||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===43)||l===43||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===43;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===43&&r.src.charCodeAt(r.pos+1)===43&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==43&&a!==43&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"ins_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"ins_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function uo(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==61||e||o+4>=n||r.src.charCodeAt(o+1)!==61||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===61)||l===61||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===61;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===61&&r.src.charCodeAt(r.pos+1)===61&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==61&&a!==61&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"mark_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"mark_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function an(r){return r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122;}function ln(r,e){var t=e,s,i,n,o=!0,a=!0,l=r.posMax,c=r.src.charCodeAt(e);for(s=e>0?r.src.charCodeAt(e-1):-1;t<l&&r.src.charCodeAt(t)===c;)t++;return t>=l&&(o=!1),n=t-e,n>=4?o=a=!1:(i=t<l?r.src.charCodeAt(t):-1,(i===32||i===10)&&(o=!1),(s===32||s===10)&&(a=!1),c===95&&(an(s)&&(o=!1),an(i)&&(a=!1))),{can_open:o,can_close:a,delims:n};}function po(r,e){var t,s,i,n,o,a,l,c=r.posMax,d=r.pos,u=r.src.charCodeAt(d);if(u!==95&&u!==42||e)return!1;if(l=ln(r,d),t=l.delims,!l.can_open)return r.pos+=t,e||(r.pending+=r.src.slice(d,r.pos)),!0;if(r.level>=r.options.maxNesting)return!1;for(r.pos=d+t,a=[t];r.pos<c;){if(r.src.charCodeAt(r.pos)===u){if(l=ln(r,r.pos),s=l.delims,l.can_close){for(n=a.pop(),o=s;n!==o;){if(o<n){a.push(n-o);break;}if(o-=n,a.length===0)break;r.pos+=n,n=a.pop();}if(a.length===0){t=n,i=!0;break;}r.pos+=s;continue;}l.can_open&&a.push(s),r.pos+=s;continue;}r.parser.skipToken(r);}return i?(r.posMax=r.pos,r.pos=d+t,e||((t===2||t===3)&&r.push({type:"strong_open",level:r.level++}),(t===1||t===3)&&r.push({type:"em_open",level:r.level++}),r.parser.tokenize(r),(t===1||t===3)&&r.push({type:"em_close",level:--r.level}),(t===2||t===3)&&r.push({type:"strong_close",level:--r.level})),r.pos=r.posMax+t,r.posMax=c,!0):(r.pos=d,!1);}var fo=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function mo(r,e){var t,s,i=r.posMax,n=r.pos;if(r.src.charCodeAt(n)!==126||e||n+2>=i||r.level>=r.options.maxNesting)return!1;for(r.pos=n+1;r.pos<i;){if(r.src.charCodeAt(r.pos)===126){t=!0;break;}r.parser.skipToken(r);}return!t||n+1===r.pos||(s=r.src.slice(n+1,r.pos),s.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=n,!1):(r.posMax=r.pos,r.pos=n+1,e||r.push({type:"sub",level:r.level,content:s.replace(fo,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}var go=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function yo(r,e){var t,s,i=r.posMax,n=r.pos;if(r.src.charCodeAt(n)!==94||e||n+2>=i||r.level>=r.options.maxNesting)return!1;for(r.pos=n+1;r.pos<i;){if(r.src.charCodeAt(r.pos)===94){t=!0;break;}r.parser.skipToken(r);}return!t||n+1===r.pos||(s=r.src.slice(n+1,r.pos),s.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=n,!1):(r.posMax=r.pos,r.pos=n+1,e||r.push({type:"sup",level:r.level,content:s.replace(go,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}function bo(r,e){var t,s,i,n,o,a,l,c,d=!1,u=r.pos,h=r.posMax,p=r.pos,m=r.src.charCodeAt(p);if(m===33&&(d=!0,m=r.src.charCodeAt(++p)),m!==91||r.level>=r.options.maxNesting||(t=p+1,s=rs(r,p),s<0))return!1;if(a=s+1,a<h&&r.src.charCodeAt(a)===40){for(a++;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a>=h)return!1;for(p=a,qn(r,a)?(n=r.linkContent,a=r.pos):n="",p=a;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<h&&p!==a&&Vn(r,a))for(o=r.linkContent,a=r.pos;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);else o="";if(a>=h||r.src.charCodeAt(a)!==41)return r.pos=u,!1;a++;}else{if(r.linkLevel>0)return!1;for(;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<h&&r.src.charCodeAt(a)===91&&(p=a+1,a=rs(r,a),a>=0?i=r.src.slice(p,a++):a=p-1),i||(_typeof(i)>"u"&&(a=s+1),i=r.src.slice(t,s)),l=r.env.references[Gn(i)],!l)return r.pos=u,!1;n=l.href,o=l.title;}return e||(r.pos=t,r.posMax=s,d?r.push({type:"image",src:n,title:o,alt:r.src.substr(t,s-t),level:r.level}):(r.push({type:"link_open",href:n,title:o,level:r.level++}),r.linkLevel++,r.parser.tokenize(r),r.linkLevel--,r.push({type:"link_close",level:--r.level}))),r.pos=a,r.posMax=h,!0;}function vo(r,e){var t,s,i,n,o=r.posMax,a=r.pos;return a+2>=o||r.src.charCodeAt(a)!==94||r.src.charCodeAt(a+1)!==91||r.level>=r.options.maxNesting||(t=a+2,s=rs(r,a+1),s<0)?!1:(e||(r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.list||(r.env.footnotes.list=[]),i=r.env.footnotes.list.length,r.pos=t,r.posMax=s,r.push({type:"footnote_ref",id:i,level:r.level}),r.linkLevel++,n=r.tokens.length,r.parser.tokenize(r),r.env.footnotes.list[i]={tokens:r.tokens.splice(n)},r.linkLevel--),r.pos=s+1,r.posMax=o,!0);}function Eo(r,e){var t,s,i,n,o=r.posMax,a=r.pos;if(a+3>o||!r.env.footnotes||!r.env.footnotes.refs||r.src.charCodeAt(a)!==91||r.src.charCodeAt(a+1)!==94||r.level>=r.options.maxNesting)return!1;for(s=a+2;s<o;s++){if(r.src.charCodeAt(s)===32||r.src.charCodeAt(s)===10)return!1;if(r.src.charCodeAt(s)===93)break;}return s===a+2||s>=o||(s++,t=r.src.slice(a+2,s-1),_typeof(r.env.footnotes.refs[":"+t])>"u")?!1:(e||(r.env.footnotes.list||(r.env.footnotes.list=[]),r.env.footnotes.refs[":"+t]<0?(i=r.env.footnotes.list.length,r.env.footnotes.list[i]={label:t,count:0},r.env.footnotes.refs[":"+t]=i):i=r.env.footnotes.refs[":"+t],n=r.env.footnotes.list[i].count,r.env.footnotes.list[i].count++,r.push({type:"footnote_ref",id:i,subId:n,level:r.level})),r.pos=s,r.posMax=o,!0);}var _o=["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"],So=/^<([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])?)*)>/,xo=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function wo(r,e){var t,s,i,n,o,a=r.pos;return r.src.charCodeAt(a)!==60||(t=r.src.slice(a),t.indexOf(">")<0)?!1:(s=t.match(xo),s?_o.indexOf(s[1].toLowerCase())<0||(n=s[0].slice(1,-1),o=gi(n),!r.parser.validateLink(n))?!1:(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:n,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=s[0].length,!0):(i=t.match(So),i?(n=i[0].slice(1,-1),o=gi("mailto:"+n),r.parser.validateLink(o)?(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:n,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=i[0].length,!0):!1):!1));}function ti(r,e){return r=r.source,e=e||"",function t(s,i){return s?(i=i.source||i,r=r.replace(s,i),t):new RegExp(r,e);};}var Ao=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Co=/[^"'=<>`\x00-\x20]+/,To=/'[^']*'/,Ro=/"[^"]*"/,Mo=ti(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Co)("single_quoted",To)("double_quoted",Ro)(),ko=ti(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Ao)("attr_value",Mo)(),Lo=ti(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",ko)(),Io=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Oo=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,No=/<[?].*?[?]>/,Po=/<![A-Z]+\s+[^>]*>/,Do=/<!\[CDATA\[[\s\S]*?\]\]>/,Bo=ti(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Lo)("close_tag",Io)("comment",Oo)("processing",No)("declaration",Po)("cdata",Do)();function Fo(r){var e=r|32;return e>=97&&e<=122;}function Uo(r,e){var t,s,i,n=r.pos;return!r.options.html||(i=r.posMax,r.src.charCodeAt(n)!==60||n+2>=i)||(t=r.src.charCodeAt(n+1),t!==33&&t!==63&&t!==47&&!Fo(t))||(s=r.src.slice(n).match(Bo),!s)?!1:(e||r.push({type:"htmltag",content:r.src.slice(n,n+s[0].length),level:r.level}),r.pos+=s[0].length,!0);}var jo=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Ho=/^&([a-z][a-z0-9]{1,31});/i;function qo(r,e){var t,s,i,n=r.pos,o=r.posMax;if(r.src.charCodeAt(n)!==38)return!1;if(n+1<o){if(t=r.src.charCodeAt(n+1),t===35){if(i=r.src.slice(n).match(jo),i)return e||(s=i[1][0].toLowerCase()==="x"?parseInt(i[1].slice(1),16):parseInt(i[1],10),r.pending+=jn(s)?mi(s):mi(65533)),r.pos+=i[0].length,!0;}else if(i=r.src.slice(n).match(Ho),i){var a=Fn(i[1]);if(i[1]!==a)return e||(r.pending+=a),r.pos+=i[0].length,!0;}}return e||(r.pending+="&"),r.pos++,!0;}var ui=[["text",ro],["newline",oo],["escape",ao],["backticks",lo],["del",co],["ins",ho],["mark",uo],["emphasis",po],["sub",mo],["sup",yo],["links",bo],["footnote_inline",vo],["footnote_ref",Eo],["autolink",wo],["htmltag",Uo],["entity",qo]];function si(){this.ruler=new ce();for(var r=0;r<ui.length;r++)this.ruler.push(ui[r][0],ui[r][1]);this.validateLink=Vo;}si.prototype.skipToken=function(r){var e=this.ruler.getRules(""),t=e.length,s=r.pos,i,n;if((n=r.cacheGet(s))>0){r.pos=n;return;}for(i=0;i<t;i++)if(e[i](r,!0)){r.cacheSet(s,r.pos);return;}r.pos++,r.cacheSet(s,r.pos);};si.prototype.tokenize=function(r){for(var e=this.ruler.getRules(""),t=e.length,s=r.posMax,i,n;r.pos<s;){for(n=0;n<t&&(i=e[n](r,!1),!i);n++);if(i){if(r.pos>=s)break;continue;}r.pending+=r.src[r.pos++];}r.pending&&r.pushPending();};si.prototype.parse=function(r,e,t,s){var i=new pt(r,this,e,t,s);this.tokenize(i);};function Vo(r){var e=["vbscript","javascript","file","data"],t=r.trim().toLowerCase();return t=dt(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var Go={options:{html:!1,// Enable HTML tags in source
|
25
26
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
26
27
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
27
28
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
@@ -35,7 +36,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
35
36
|
// function (/*str, lang*/) { return ''; }
|
36
37
|
//
|
37
38
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
38
|
-
},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}}
|
39
|
+
},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}},zo={options:{html:!1,// Enable HTML tags in source
|
39
40
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
40
41
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
41
42
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
@@ -50,7 +51,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
50
51
|
//
|
51
52
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
52
53
|
},components:{// Don't restrict core/block/inline rules
|
53
|
-
core:{},block:{},inline:{}}},
|
54
|
+
core:{},block:{},inline:{}}},Ko={options:{html:!0,// Enable HTML tags in source
|
54
55
|
xhtmlOut:!0,// Use '/' to close single tags (<br />)
|
55
56
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
56
57
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
@@ -64,57 +65,59 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
64
65
|
// function (/*str, lang*/) { return ''; }
|
65
66
|
//
|
66
67
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
67
|
-
},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}},Wo={"default":
|
68
|
+
},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}},Wo={"default":Go,full:zo,commonmark:Ko};function Wn(r,e,t){this.src=e,this.env=t,this.options=r.options,this.tokens=[],this.inlineMode=!1,this.inline=r.inline,this.block=r.block,this.renderer=r.renderer,this.typographer=r.typographer;}function Re(r,e){typeof r!="string"&&(e=r,r="default"),e&&e.linkify!=null&&console.warn("linkify option is removed. Use linkify plugin instead:\n\nimport Remarkable from 'remarkable';\nimport linkify from 'remarkable/linkify';\nnew Remarkable().use(linkify)\n"),this.inline=new si(),this.block=new Di(),this.core=new zn(),this.renderer=new Pi(),this.ruler=new ce(),this.options={},this.configure(Wo[r]),this.set(e||{});}Re.prototype.set=function(r){Un(this.options,r);};Re.prototype.configure=function(r){var e=this;if(!r)throw new Error("Wrong `remarkable` preset, check name/content");r.options&&e.set(r.options),r.components&&Object.keys(r.components).forEach(function(t){r.components[t].rules&&e[t].ruler.enable(r.components[t].rules,!0);});};Re.prototype.use=function(r,e){return r(this,e),this;};Re.prototype.parse=function(r,e){var t=new Wn(this,r,e);return this.core.process(t),t.tokens;};Re.prototype.render=function(r,e){return e=e||{},this.renderer.render(this.parse(r,e),this.options,e);};Re.prototype.parseInline=function(r,e){var t=new Wn(this,r,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};Re.prototype.renderInline=function(r,e){return e=e||{},this.renderer.render(this.parseInline(r,e),this.options,e);};var st=/*#__PURE__*/function(){function st(){_classCallCheck(this,st);}return _createClass(st,null,[{key:"addPlugins",value:function addPlugins(e,t){var s=window.remarkable_plugins;if(s&&s.forEach(function(i){e.use(i.plugin,i.options);}),t!=null&&t.math){window.katex||console.warn("window.katex not found, use chatElementRef.refreshMessages to re-render messages");var i=_typeof(t.math)=="object"?t.math.delimiter:"",n=_typeof(t.math)=="object"&&t.math.options?t.math.options:{};e.use(hr.katex.bind(this,n),{delimiter:i});}}},{key:"instantiate",value:function instantiate(e){if(e)return new Re(_objectSpread(_objectSpread({},st.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new Re({highlight:function highlight(s,i){if(i&&t.getLanguage(i))try{return t.highlight(s,{language:i}).value;}catch(_unused4){console.error("failed to setup the highlight dependency");}try{return t.highlightAuto(s).value;}catch(_unused5){console.error("failed to automatically highlight messages");}return"";},html:!1,// Enable HTML tags in source
|
68
69
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
69
70
|
breaks:!0,// Convert '\n' in paragraphs into <br>
|
70
71
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
71
72
|
linkTarget:"_blank",// set target to open in a new tab
|
72
73
|
typographer:!0// Enable smartypants and other sweet transforms
|
73
|
-
});}else return new Re(
|
74
|
-
};var os=
|
74
|
+
});}else return new Re(st.DEFAULT_PROPERTIES);}},{key:"createNew",value:function createNew(e){var t=st.instantiate(e);return st.addPlugins(t,e),t.inline.validateLink=function(){return!0;},t;}}]);}();st.DEFAULT_PROPERTIES={breaks:!0,linkTarget:"_blank"// set target to open in a new tab
|
75
|
+
};var os=st;var $o=/*#__PURE__*/function(){function $o(e){_classCallCheck(this,$o);this.storageKey="deep-chat-storage",this.maxMessages=1e3,_typeof(e)=="object"&&(e.key&&(this.storageKey=e.key),e.maxMessages&&(this.maxMessages=e.maxMessages),e.clear=this.clear.bind(this));}return _createClass($o,[{key:"get",value:function get(){var e=localStorage.getItem(this.storageKey);return e?JSON.parse(e):[];}},{key:"addMessages",value:function addMessages(e){var t=e.length-this.maxMessages;t<0&&(t=0);var s=e.slice(t,e.length);localStorage.setItem(this.storageKey,JSON.stringify(s));}},{key:"clear",value:function clear(){localStorage.removeItem(this.storageKey);}}]);}();var Q=/*#__PURE__*/function(){function Q(){_classCallCheck(this,Q);}return _createClass(Q,null,[{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,s){if(s&&(Object.assign(e.outerContainer.style,s.outerContainer),Object.assign(e.innerContainer.style,s.innerContainer),Object.assign(e.bubbleElement.style,s.bubble),t)){var i=e.bubbleElement.children[0],n=i.tagName.toLocaleLowerCase()!=="a"?i:i.children[0];Object.assign(n.style,s.media);}}},{key:"applySideStyles",value:function applySideStyles(e,t,s,i){i&&(Q.applyCustomStylesToElements(e,s,i.shared),t===b.USER_ROLE?Q.applyCustomStylesToElements(e,s,i.user):(Q.applyCustomStylesToElements(e,s,i.ai),Q.applyCustomStylesToElements(e,s,i[t])));}},{key:"isElementsStyles",value:function isElementsStyles(e){return!!(e.outerContainer||e.innerContainer||e.bubble||e.media);}// prettier-ignore
|
75
76
|
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i,n){var o;n&&e["default"]!==n?Q.isElementsStyles(n)?(Q.applyCustomStylesToElements(t,i,(o=e["default"])==null?void 0:o.shared),Q.applyCustomStylesToElements(t,i,n)):(Q.applySideStyles(t,s,i,e["default"]),Q.applySideStyles(t,s,i,n)):Q.applySideStyles(t,s,i,e["default"]);}// prettier-ignore
|
76
|
-
},{key:"extractParticularSharedStyles",value:function extractParticularSharedStyles(e,t){if(!(t!=null&&t.shared))return;var s=t.shared,i={outerContainer:{},innerContainer:{},bubble:{},media:{}};return e.forEach(function(n){var o,a,l,c;i.outerContainer[n]=((o=s.outerContainer)==null?void 0:o[n])||"",i.innerContainer[n]=((a=s.innerContainer)==null?void 0:a[n])||"",i.bubble[n]=((l=s.bubble)==null?void 0:l[n])||"",i.media[n]=((c=s.media)==null?void 0:c[n])||"";}),i;}}]);}();var as=/*#__PURE__*/function(){function as(){_classCallCheck(this,as);}return _createClass(as,null,[{key:"onMessage",value:function onMessage(e,t,s){var n;var i=JSON.parse(JSON.stringify({message:t,isHistory:s,isInitial:s}));z.reAddFileRefToObject(t,i.message),(n=e.onMessage)==null||n.call(e,i),e.dispatchEvent(new CustomEvent("message",{detail:i})),ee.fireOnNewMessage(e,i);}},{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,s){var n,o;var i=JSON.parse(JSON.stringify({content:t,isUser:s}));t.files&&z.reAddFileRefToObject({files:(n=t.files)==null?void 0:n.map(function(a){return{ref:a};})},i.content),(o=e.onInput)==null||o.call(e,i),e.dispatchEvent(new CustomEvent("input",{detail:i}));}},{key:"onError",value:function onError(e,t){var s;(s=e.onError)==null||s.call(e,t),e.dispatchEvent(new CustomEvent("error",{detail:t}));}}]);}();var q=/*#__PURE__*/function(){function q(){_classCallCheck(this,q);}return _createClass(q,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=document.createElement("div");return e.classList.add("loading-history"),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e;}},{key:"apply",value:function apply(e,t,s){Ue.setRing(t.bubbleElement,s==null?void 0:s.bubble),s!=null&&s.bubble&&(s=JSON.parse(JSON.stringify(s)),delete s.bubble),e.applyCustomStyles(t,"history",!1,s);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var o,a,l,c,d,u,h,p;e.bubbleElement.classList.add(q.CLASS);var i=s?q.FULL_VIEW_CLASS:q.SMALL_CLASS;e.outerContainer.classList.add(i);var n=s?(c=(l=(a=(o=t.messageStyles)==null?void 0:o.loading)==null?void 0:a.history)==null?void 0:l.full)==null?void 0:c.styles:(p=(h=(u=(d=t.messageStyles)==null?void 0:d.loading)==null?void 0:u.history)==null?void 0:h.small)==null?void 0:p.styles;q.apply(t,e,n),t.elementRef.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",b.AI_ROLE),s=t.bubbleElement,i=q.generateLoadingRingElement();return s.appendChild(i),t;}},{key:"addMessage",value:function addMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var n,o,a,l;var s=(l=(a=(o=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:o.history)==null?void 0:a.full)==null?void 0:l.html,i=s?Te.createElements(e,s,b.AI_ROLE,!0,!0):q.createDefaultElements(e);return q.addLoadHistoryMessage(i,e,t),b.softRemRoleElements(i.innerContainer,e.avatar,e.name),i;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var s,i,n,o,a,l,c,d;if(t!=null&&t.outerContainer.classList.contains(q.FULL_VIEW_CLASS)){t.outerContainer.classList.replace(q.FULL_VIEW_CLASS,q.SMALL_CLASS);var u=(o=(n=(i=(s=e.messageStyles)==null?void 0:s.loading)==null?void 0:i.history)==null?void 0:n.small)==null?void 0:o.styles;u&&q.apply(e,t,u);var h=(d=(c=(l=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:l.history)==null?void 0:c.small)==null?void 0:d.html;return h&&(t.bubbleElement.innerHTML=h),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];q.tryChangeViewToSmall(e,t)||q.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();q.CLASS="loading-history-message",q.FULL_VIEW_CLASS="loading-history-message-full-view",q.SMALL_CLASS="loading-history-message-small";var He=q;var Qt=/*#__PURE__*/function(){function Qt(){_classCallCheck(this,Qt);}return _createClass(Qt,null,[{key:"setFade",value:function setFade(e,t){e.style.transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(Qt.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(e,t){var s;return _regeneratorRuntime().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:e.style.opacity="0";s=typeof t=="number"?t:Qt.DEFAULT_FADE_MS;_context.next=4;return new Promise(function(i){setTimeout(function(){return i();},s);});case 4:e.style.opacity="1";case 5:case"end":return _context.stop();}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();Qt.DEFAULT_FADE_MS=500;var ws=Qt;var dn="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",yi="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 Xn=/*#__PURE__*/function(){function Xn(e){_classCallCheck(this,Xn);this.className=e;}return _createClass(Xn,[{key:"tryHide",value:function tryHide(e){var t;(t=e.getElementsByClassName(this.className)[0].style).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){e.getElementsByClassName(this.className)[0].style.visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){e.getElementsByClassName(this.className)[0].classList.add("role-hidden");}}]);}();var Ie=/*#__PURE__*/function(_Xn){function Ie(e){var _this3;_classCallCheck(this,Ie);_this3=_callSuper(this,Ie,["avatar-container"]),_this3._avatars=e;return _this3;}_inherits(Ie,_Xn);return _createClass(Ie,[{key:"addBesideMsg",value:function addBesideMsg(e,t){var s=typeof this._avatars=="boolean"?void 0:this._avatars,i=this.createAvatar(t,s),n=this.getPosition(t,s);i.classList.add(n==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(n==="left"?"beforebegin":"afterend",i);}},{key:"createAvatar",value:function createAvatar(e,t){var n,o,a,l,c;var s=document.createElement("img");e===b.USER_ROLE?(s.src=((n=t==null?void 0:t.user)==null?void 0:n.src)||((o=t==null?void 0:t["default"])==null?void 0:o.src)||yi,s.onerror=Ie.errorFallback.bind(this,yi)):(s.src=((a=t==null?void 0:t[e])==null?void 0:a.src)||((l=t==null?void 0:t.ai)==null?void 0:l.src)||((c=t==null?void 0:t["default"])==null?void 0:c.src)||dn,s.onerror=Ie.errorFallback.bind(this,dn)),s.classList.add("avatar"),s.alt="".concat(e," avatar");var i=document.createElement("div");return i.classList.add(this.className),i.appendChild(s),t&&Ie.applyCustomStyles(i,s,t,e),i;}},{key:"getPosition",value:function getPosition(e,t){var i,n,o,a,l,c;var s=(n=(i=t==null?void 0:t[e])==null?void 0:i.styles)==null?void 0:n.position;return e!==b.USER_ROLE&&(s!==null&&s!==void 0?s:s=(a=(o=t==null?void 0:t.ai)==null?void 0:o.styles)==null?void 0:a.position),s!==null&&s!==void 0?s:s=(c=(l=t==null?void 0:t["default"])==null?void 0:l.styles)==null?void 0:c.position,s!==null&&s!==void 0?s:s=e===b.USER_ROLE?"right":"left",s;}}],[{key:"errorFallback",value:function errorFallback(e,t){var s=t.target;s.onerror=null,s.src=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,s){Object.assign(e.style,s.container),Object.assign(t.style,s.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){var n,o,a,l;if((n=s["default"])!=null&&n.styles&&Ie.applyCustomStylesToElements(e,t,s["default"].styles),i===b.USER_ROLE)(o=s.user)!=null&&o.styles&&Ie.applyCustomStylesToElements(e,t,s.user.styles);else{(a=s.ai)!=null&&a.styles&&Ie.applyCustomStylesToElements(e,t,s.ai.styles);var c=(l=s[i])==null?void 0:l.styles;c&&Ie.applyCustomStylesToElements(e,t,c);}}}]);}(Xn);var Wt=/*#__PURE__*/function(_Xn2){function Wt(e){var _this4;_classCallCheck(this,Wt);_this4=_callSuper(this,Wt,["name"]),_this4._names=e;return _this4;}_inherits(Wt,_Xn2);return _createClass(Wt,[{key:"addBesideMsg",value:function addBesideMsg(e,t){var s=typeof this._names=="boolean"?{}:this._names,i=this.createName(t,s),n=Wt.getPosition(t,s);i.classList.add(n==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(n==="left"?"beforebegin":"afterend",i);}},{key:"createName",value:function createName(e,t){var s=document.createElement("div");return s.classList.add(this.className),s.textContent=Wt.getNameText(e,t),Wt.applyStyle(s,e,t),s;}}],[{key:"getPosition",value:function getPosition(e,t){var i,n,o;var s=(i=t==null?void 0:t[e])==null?void 0:i.position;return e!==b.USER_ROLE&&(s!==null&&s!==void 0?s:s=(n=t==null?void 0:t.ai)==null?void 0:n.position),s!==null&&s!==void 0?s:s=(o=t==null?void 0:t["default"])==null?void 0:o.position,s!==null&&s!==void 0?s:s=e===b.USER_ROLE?"right":"left",s;}},{key:"applyStyle",value:function applyStyle(e,t,s){var i,n,o,a;Object.assign(e.style,(i=s["default"])==null?void 0:i.style),t===b.USER_ROLE?Object.assign(e.style,(n=s.user)==null?void 0:n.style):(Object.assign(e.style,(o=s.ai)==null?void 0:o.style),Object.assign(e.style,(a=s[t])==null?void 0:a.style));}},{key:"getNameText",value:function getNameText(e,t){var s,i,n,o,a,l;return e===b.USER_ROLE?((s=t.user)==null?void 0:s.text)||((i=t["default"])==null?void 0:i.text)||"User":e===b.AI_ROLE?((n=t.ai)==null?void 0:n.text)||((o=t["default"])==null?void 0:o.text)||"AI":((a=t[e])==null?void 0:a.text)||((l=t["default"])==null?void 0:l.text)||e;}}]);}(Xn);var te=/*#__PURE__*/function(){function te(e){var _this5=this;_classCallCheck(this,te);var t;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.elementRef=te.createContainerElement(),this.messageStyles=ee.processMessageStyles(e.messageStyles),this._remarkable=os.createNew(e.remarkable),e.avatars&&(this.avatar=new Ie(e.avatars)),e.names&&(this.name=new Wt(e.names)),e.browserStorage&&(this.browserStorage=new Xo(e.browserStorage)),this._onMessage=as.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),this.focusMode=e.focusMode,this.focusMode||(this._lastGroupMessagesElement=document.createElement("div")),typeof this.focusMode!="boolean"&&(t=this.focusMode)!=null&&t.fade&&ws.setFade(this.elementRef,this.focusMode.fade),setTimeout(function(){_this5.submitUserMessage=e.submitUserMessage;});}return _createClass(te,[{key:"addNewTextMessage",value:function addNewTextMessage(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(s!=null&&s.status){var o=this.overwriteText(t,e,this.messageElementRefs);if(o)return o;s.status=!1;}var n=i?this.createAndPrependNewMessageElement(e,t,i):this.createAndAppendNewMessageElement(e,t);return n.bubbleElement.classList.add(te.TEXT_BUBBLE_CLASS),this.applyCustomStyles(n,t,!1),b.fillEmptyMessageElement(n.bubbleElement,e),n;}// prettier-ignore
|
77
|
-
},{key:"overwriteText",value:function overwriteText(e,t,s){var i=b.overwriteMessage(this.messageToElements,s,t,e,"text",te.TEXT_BUBBLE_CLASS);return i&&this.renderText(i.bubbleElement,t),i;}},{key:"createAndAppendNewMessageElement",value:function createAndAppendNewMessageElement(e,t){return this.focusMode?this.appendNewMessageElementFocusMode(e,t):this.createAndAppendNewMessageElementDefault(e,t);}},{key:"appendNewMessageElementFocusMode",value:function appendNewMessageElementFocusMode(e,t){var i;var s=this.createNewMessageElement(e,t);if(this.appendOuterContainerElemet(s.outerContainer,t),t==="user"){var n=typeof this.focusMode!="boolean"&&((i=this.focusMode)==null?void 0:i.scroll);
|
77
|
+
},{key:"extractParticularSharedStyles",value:function extractParticularSharedStyles(e,t){if(!(t!=null&&t.shared))return;var s=t.shared,i={outerContainer:{},innerContainer:{},bubble:{},media:{}};return e.forEach(function(n){var o,a,l,c;i.outerContainer[n]=((o=s.outerContainer)==null?void 0:o[n])||"",i.innerContainer[n]=((a=s.innerContainer)==null?void 0:a[n])||"",i.bubble[n]=((l=s.bubble)==null?void 0:l[n])||"",i.media[n]=((c=s.media)==null?void 0:c[n])||"";}),i;}}]);}();var as=/*#__PURE__*/function(){function as(){_classCallCheck(this,as);}return _createClass(as,null,[{key:"onMessage",value:function onMessage(e,t,s){var n;var i=JSON.parse(JSON.stringify({message:t,isHistory:s,isInitial:s}));z.reAddFileRefToObject(t,i.message),(n=e.onMessage)==null||n.call(e,i),e.dispatchEvent(new CustomEvent("message",{detail:i})),X.fireOnNewMessage(e,i);}},{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,s){var n,o;var i=JSON.parse(JSON.stringify({content:t,isUser:s}));t.files&&z.reAddFileRefToObject({files:(n=t.files)==null?void 0:n.map(function(a){return{ref:a};})},i.content),(o=e.onInput)==null||o.call(e,i),e.dispatchEvent(new CustomEvent("input",{detail:i}));}},{key:"onError",value:function onError(e,t){var s;(s=e.onError)==null||s.call(e,t),e.dispatchEvent(new CustomEvent("error",{detail:t}));}}]);}();var q=/*#__PURE__*/function(){function q(){_classCallCheck(this,q);}return _createClass(q,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=document.createElement("div");return e.classList.add("loading-history"),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e;}},{key:"apply",value:function apply(e,t,s){je.setRing(t.bubbleElement,s==null?void 0:s.bubble),s!=null&&s.bubble&&(s=JSON.parse(JSON.stringify(s)),delete s.bubble),e.applyCustomStyles(t,"history",!1,s);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var o,a,l,c,d,u,h,p;e.bubbleElement.classList.add(q.CLASS);var i=s?q.FULL_VIEW_CLASS:q.SMALL_CLASS;e.outerContainer.classList.add(i);var n=s?(c=(l=(a=(o=t.messageStyles)==null?void 0:o.loading)==null?void 0:a.history)==null?void 0:l.full)==null?void 0:c.styles:(p=(h=(u=(d=t.messageStyles)==null?void 0:d.loading)==null?void 0:u.history)==null?void 0:h.small)==null?void 0:p.styles;q.apply(t,e,n),t.elementRef.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",b.AI_ROLE),s=t.bubbleElement,i=q.generateLoadingRingElement();return s.appendChild(i),t;}},{key:"addMessage",value:function addMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var n,o,a,l;var s=(l=(a=(o=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:o.history)==null?void 0:a.full)==null?void 0:l.html,i=s?Te.createElements(e,s,b.AI_ROLE,!0,!0):q.createDefaultElements(e);return q.addLoadHistoryMessage(i,e,t),b.softRemRoleElements(i.innerContainer,e.avatar,e.name),i;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var s,i,n,o,a,l,c,d;if(t!=null&&t.outerContainer.classList.contains(q.FULL_VIEW_CLASS)){t.outerContainer.classList.replace(q.FULL_VIEW_CLASS,q.SMALL_CLASS);var u=(o=(n=(i=(s=e.messageStyles)==null?void 0:s.loading)==null?void 0:i.history)==null?void 0:n.small)==null?void 0:o.styles;u&&q.apply(e,t,u);var h=(d=(c=(l=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:l.history)==null?void 0:c.small)==null?void 0:d.html;return h&&(t.bubbleElement.innerHTML=h),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];q.tryChangeViewToSmall(e,t)||q.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();q.CLASS="loading-history-message",q.FULL_VIEW_CLASS="loading-history-message-full-view",q.SMALL_CLASS="loading-history-message-small";var qe=q;var Qt=/*#__PURE__*/function(){function Qt(){_classCallCheck(this,Qt);}return _createClass(Qt,null,[{key:"setFade",value:function setFade(e,t){e.style.transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(Qt.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e,t){var s;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:e.style.opacity="0";s=typeof t=="number"?t:Qt.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(i){setTimeout(function(){return i();},s);});case 1:e.style.opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();Qt.DEFAULT_FADE_MS=500;var ws=Qt;var cn="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",yi="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 $n=/*#__PURE__*/function(){function $n(e){_classCallCheck(this,$n);this.className=e;}return _createClass($n,[{key:"tryHide",value:function tryHide(e){var t;(t=e.getElementsByClassName(this.className)[0].style).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){e.getElementsByClassName(this.className)[0].style.visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){e.getElementsByClassName(this.className)[0].classList.add("role-hidden");}}]);}();var Ie=/*#__PURE__*/function(_$n){function Ie(e){var _this3;_classCallCheck(this,Ie);_this3=_callSuper(this,Ie,["avatar-container"]),_this3._avatars=e;return _this3;}_inherits(Ie,_$n);return _createClass(Ie,[{key:"addBesideMsg",value:function addBesideMsg(e,t){var s=typeof this._avatars=="boolean"?void 0:this._avatars,i=this.createAvatar(t,s),n=this.getPosition(t,s);i.classList.add(n==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(n==="left"?"beforebegin":"afterend",i);}},{key:"createAvatar",value:function createAvatar(e,t){var n,o,a,l,c;var s=document.createElement("img");e===b.USER_ROLE?(s.src=((n=t==null?void 0:t.user)==null?void 0:n.src)||((o=t==null?void 0:t["default"])==null?void 0:o.src)||yi,s.onerror=Ie.errorFallback.bind(this,yi)):(s.src=((a=t==null?void 0:t[e])==null?void 0:a.src)||((l=t==null?void 0:t.ai)==null?void 0:l.src)||((c=t==null?void 0:t["default"])==null?void 0:c.src)||cn,s.onerror=Ie.errorFallback.bind(this,cn)),s.classList.add("avatar"),s.alt="".concat(e," avatar");var i=document.createElement("div");return i.classList.add(this.className),i.appendChild(s),t&&Ie.applyCustomStyles(i,s,t,e),i;}},{key:"getPosition",value:function getPosition(e,t){var i,n,o,a,l,c;var s=(n=(i=t==null?void 0:t[e])==null?void 0:i.styles)==null?void 0:n.position;return e!==b.USER_ROLE&&(s!==null&&s!==void 0?s:s=(a=(o=t==null?void 0:t.ai)==null?void 0:o.styles)==null?void 0:a.position),s!==null&&s!==void 0?s:s=(c=(l=t==null?void 0:t["default"])==null?void 0:l.styles)==null?void 0:c.position,s!==null&&s!==void 0?s:s=e===b.USER_ROLE?"right":"left",s;}}],[{key:"errorFallback",value:function errorFallback(e,t){var s=t.target;s.onerror=null,s.src=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,s){Object.assign(e.style,s.container),Object.assign(t.style,s.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){var n,o,a,l;if((n=s["default"])!=null&&n.styles&&Ie.applyCustomStylesToElements(e,t,s["default"].styles),i===b.USER_ROLE)(o=s.user)!=null&&o.styles&&Ie.applyCustomStylesToElements(e,t,s.user.styles);else{(a=s.ai)!=null&&a.styles&&Ie.applyCustomStylesToElements(e,t,s.ai.styles);var c=(l=s[i])==null?void 0:l.styles;c&&Ie.applyCustomStylesToElements(e,t,c);}}}]);}($n);var Jt=/*#__PURE__*/function(_$n2){function Jt(e){var _this4;_classCallCheck(this,Jt);_this4=_callSuper(this,Jt,["name"]),_this4._names=e;return _this4;}_inherits(Jt,_$n2);return _createClass(Jt,[{key:"addBesideMsg",value:function addBesideMsg(e,t){var s=typeof this._names=="boolean"?{}:this._names,i=this.createName(t,s),n=Jt.getPosition(t,s);i.classList.add(n==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(n==="left"?"beforebegin":"afterend",i);}},{key:"createName",value:function createName(e,t){var s=document.createElement("div");return s.classList.add(this.className),s.textContent=Jt.getNameText(e,t),Jt.applyStyle(s,e,t),s;}}],[{key:"getPosition",value:function getPosition(e,t){var i,n,o;var s=(i=t==null?void 0:t[e])==null?void 0:i.position;return e!==b.USER_ROLE&&(s!==null&&s!==void 0?s:s=(n=t==null?void 0:t.ai)==null?void 0:n.position),s!==null&&s!==void 0?s:s=(o=t==null?void 0:t["default"])==null?void 0:o.position,s!==null&&s!==void 0?s:s=e===b.USER_ROLE?"right":"left",s;}},{key:"applyStyle",value:function applyStyle(e,t,s){var i,n,o,a;Object.assign(e.style,(i=s["default"])==null?void 0:i.style),t===b.USER_ROLE?Object.assign(e.style,(n=s.user)==null?void 0:n.style):(Object.assign(e.style,(o=s.ai)==null?void 0:o.style),Object.assign(e.style,(a=s[t])==null?void 0:a.style));}},{key:"getNameText",value:function getNameText(e,t){var s,i,n,o,a,l;return e===b.USER_ROLE?((s=t.user)==null?void 0:s.text)||((i=t["default"])==null?void 0:i.text)||"User":e===b.AI_ROLE?((n=t.ai)==null?void 0:n.text)||((o=t["default"])==null?void 0:o.text)||"AI":((a=t[e])==null?void 0:a.text)||((l=t["default"])==null?void 0:l.text)||e;}}]);}($n);var te=/*#__PURE__*/function(){function te(e){var _this5=this;_classCallCheck(this,te);var t,s;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.elementRef=te.createContainerElement(),this.messageStyles=X.processMessageStyles(e.messageStyles),this._remarkable=os.createNew(e.remarkable),e.avatars&&(this.avatar=new Ie(e.avatars)),e.names&&(this.name=new Jt(e.names)),e.browserStorage&&(this.browserStorage=new $o(e.browserStorage)),this._onMessage=as.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),this.focusMode=e.focusMode,this.focusMode||(this._lastGroupMessagesElement=document.createElement("div")),typeof this.focusMode!="boolean"&&(t=this.focusMode)!=null&&t.fade&&ws.setFade(this.elementRef,this.focusMode.fade),setTimeout(function(){_this5.submitUserMessage=e.submitUserMessage;}),this._customWrappers=e.htmlWrappers||X.processStreamHTMLWrappers((s=e.connect)==null?void 0:s.stream);}return _createClass(te,[{key:"addNewTextMessage",value:function addNewTextMessage(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(s!=null&&s.status){var o=this.overwriteText(t,e,this.messageElementRefs);if(o)return o;s.status=!1;}var n=i?this.createAndPrependNewMessageElement(e,t,i):this.createAndAppendNewMessageElement(e,t);return n.bubbleElement.classList.add(te.TEXT_BUBBLE_CLASS),this.applyCustomStyles(n,t,!1),b.fillEmptyMessageElement(n.bubbleElement,e),n;}// prettier-ignore
|
78
|
+
},{key:"overwriteText",value:function overwriteText(e,t,s){var i=b.overwriteMessage(this.messageToElements,s,t,e,"text",te.TEXT_BUBBLE_CLASS);return i&&this.renderText(i.bubbleElement,t,e),i;}},{key:"createAndAppendNewMessageElement",value:function createAndAppendNewMessageElement(e,t){return this.focusMode?this.appendNewMessageElementFocusMode(e,t):this.createAndAppendNewMessageElementDefault(e,t);}},{key:"appendNewMessageElementFocusMode",value:function appendNewMessageElementFocusMode(e,t){var i;var s=this.createNewMessageElement(e,t);if(this.appendOuterContainerElemet(s.outerContainer,t),t==="user"){var n=typeof this.focusMode!="boolean"&&((i=this.focusMode)==null?void 0:i.scroll);J.scrollToBottom(this.elementRef,n);}return s;}},{key:"createNewGroupElementFocusMode",value:function createNewGroupElementFocusMode(){var t;(t=this._lastGroupMessagesElement)==null||t.classList.remove(te.LAST_GROUP_MESSAGES_ACTIVE);var e=document.createElement("div");this._lastGroupMessagesElement&&e.classList.add(te.LAST_GROUP_MESSAGES_ACTIVE),this._lastGroupMessagesElement=e;}},{key:"createAndAppendNewMessageElementDefault",value:function createAndAppendNewMessageElementDefault(e,t){var _this6=this;var s=this.createNewMessageElement(e,t);return this.appendOuterContainerElemet(s.outerContainer),setTimeout(function(){return J.scrollToBottom(_this6.elementRef);}),s;}},{key:"appendOuterContainerElemet",value:function appendOuterContainerElemet(e,t){var s;this.focusMode&&(t==="user"||!this._lastGroupMessagesElement)&&this.createNewGroupElementFocusMode(),(s=this._lastGroupMessagesElement)==null||s.appendChild(e),this.elementRef.appendChild(this._lastGroupMessagesElement);}},{key:"createAndPrependNewMessageElement",value:function createAndPrependNewMessageElement(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var n=this.createNewMessageElement(e,t,s,i);if(s&&(o=this.elementRef.firstChild)!=null&&o.classList.contains(te.INTRO_CLASS)){this.elementRef.firstChild.insertAdjacentElement("afterend",n.outerContainer);var a=this.messageElementRefs[0];this.messageElementRefs[0]=this.messageElementRefs[1],this.messageElementRefs[1]=a;}else this.elementRef.insertBefore(n.outerContainer,this.elementRef.firstChild);return n;}},{key:"createMessageElementsOnOrientation",value:function createMessageElementsOnOrientation(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;return s?this.createAndPrependNewMessageElement(e,t,s,i):this.createNewMessageElement(e,t,s,i);}},{key:"createNewMessageElement",value:function createNewMessageElement(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;i||(o=this._introPanel)==null||o.hide();var n=this.messageElementRefs[this.messageElementRefs.length-1];return qe.changeFullViewToSmall(this),!s&&te.isTemporaryElement(n)&&(this.revealRoleElementsIfTempRemoved(n,t),this.removeLastMessage()),this.createMessageElements(e,t,s);}// this can be tested by having an ai message, then a temp ai message with html that submits new user message:
|
78
79
|
// https://github.com/OvidijusParsiunas/deep-chat/issues/258
|
79
80
|
// prettier-ignore
|
80
81
|
},{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&Ce.isElementTemporary(e)){var s=this.messageElementRefs[this.messageElementRefs.length-2];s&&this.messageToElements.length>0&&!e.bubbleElement.classList.contains(b.getRoleClass(t))&&b.revealRoleElements(s.innerContainer,this.avatar,this.name);}}},{key:"createElements",value:function createElements(e,t){var s=te.createBaseElements(t),i=s.outerContainer,n=s.innerContainer,o=s.bubbleElement;return i.appendChild(n),this.addInnerContainerElements(o,e,t),s;}},{key:"createMessageElements",value:function createMessageElements(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var i=this.createElements(e,t);return b.updateRefArr(this.messageElementRefs,i,s),b.classifyRoleMessages(this.messageElementRefs,t),i;}},{key:"addInnerContainerElements",value:// prettier-ignore
|
81
|
-
function addInnerContainerElements(e,t,s){var i=this.messageElementRefs[this.messageElementRefs.length-1];return b.areOuterContainerClassRolesSame(s,i)&&!this.isLastMessageError()&&b.hideRoleElements(i.innerContainer,this.avatar,this.name),e.classList.add("message-bubble",b.getRoleClass(s),s===b.USER_ROLE?"user-message-text":"ai-message-text"),this.renderText(e,t),b.addRoleElements(e,s,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
|
82
|
-
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){e&&this.messageStyles&&Q.applyCustomStyles(this.messageStyles,e,t,s,i);}},{key:"removeMessage",value:function removeMessage(e){e.outerContainer.remove();var t=this.messageElementRefs.findIndex(function(s){return s===e;});this.messageElementRefs.splice(t,1);}},{key:"removeLastMessage",value:function removeLastMessage(){this.messageElementRefs[this.messageElementRefs.length-1].outerContainer.remove(),this.messageElementRefs.pop();}},{key:"isLastMessageError",value:function isLastMessageError(){var e;return(e=b.getLastMessageBubbleElement(this.elementRef))==null?void 0:e.classList.contains(b.ERROR_MESSAGE_TEXT_CLASS);}},{key:"sendClientUpdate",value:function sendClientUpdate(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s;(s=this._onMessage)==null||s.call(this,e,t);}
|
83
|
-
},{key:"
|
82
|
+
function addInnerContainerElements(e,t,s){var i=this.messageElementRefs[this.messageElementRefs.length-1];return b.areOuterContainerClassRolesSame(s,i)&&!this.isLastMessageError()&&b.hideRoleElements(i.innerContainer,this.avatar,this.name),e.classList.add("message-bubble",b.getRoleClass(s),s===b.USER_ROLE?"user-message-text":"ai-message-text"),this.renderText(e,t,s),b.addRoleElements(e,s,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
|
83
|
+
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){e&&this.messageStyles&&Q.applyCustomStyles(this.messageStyles,e,t,s,i);}},{key:"removeMessage",value:function removeMessage(e){e.outerContainer.remove();var t=this.messageElementRefs.findIndex(function(s){return s===e;});this.messageElementRefs.splice(t,1);}},{key:"removeLastMessage",value:function removeLastMessage(){this.messageElementRefs[this.messageElementRefs.length-1].outerContainer.remove(),this.messageElementRefs.pop();}},{key:"isLastMessageError",value:function isLastMessageError(){var e;return(e=b.getLastMessageBubbleElement(this.elementRef))==null?void 0:e.classList.contains(b.ERROR_MESSAGE_TEXT_CLASS);}},{key:"sendClientUpdate",value:function sendClientUpdate(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s;(s=this._onMessage)==null||s.call(this,e,t);}// role is optional to not add wrapper to error
|
84
|
+
},{key:"renderText",value:function renderText(e,t,s){var _ee$tryAddWrapper2=ee.tryAddWrapper(e,t,this._customWrappers,s),i=_ee$tryAddWrapper2.contentEl,n=_ee$tryAddWrapper2.wrapper;n&&ee.apply(this,e),i.innerHTML=this._remarkable.render(t),i.innerText.trim().length===0&&i.children.length>0&&i.children[0].tagName!=="P"&&(i.innerText=t);}// this is mostly used for enabling highlight.js to highlight code if it downloads later
|
85
|
+
},{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this7=this;this._remarkable=os.createNew(e),this.messageToElements.forEach(function(t){t[1].text&&t[0].text&&_this7.renderText(t[1].text.bubbleElement,t[0].text,t[0].role);});}}],[{key:"createContainerElement",value:function createContainerElement(){var e=document.createElement("div");return e.id="messages",e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return te.isLoadingMessage(e)||Ce.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=document.createElement("div"),s=document.createElement("div");s.classList.add("inner-message-container"),t.appendChild(s),t.classList.add("outer-message-container"),t.classList.add(b.buildRoleOuterContainerClass(e));var i=document.createElement("div");return i.classList.add("message-bubble"),s.appendChild(i),{outerContainer:t,innerContainer:s,bubbleElement:i};}},{key:"createMessageContent",value:function createMessageContent(e){var t=e.text,s=e.files,i=e.html,n=e.custom,o=e._sessionId,a=e.role,l={role:a||b.AI_ROLE};return t&&(l.text=t),s&&(l.files=s),i&&(l.html=i),!t&&!s&&!i&&(l.text=""),n&&(l.custom=n),o&&(l._sessionId=o),l;}},{key:"isLoadingMessage",value:function isLoadingMessage(e){return e==null?void 0:e.bubbleElement.classList.contains(je.BUBBLE_CLASS);}}]);}();te.TEXT_BUBBLE_CLASS="text-message",te.INTRO_CLASS="deep-chat-intro",te.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var pe=te;var x=/*#__PURE__*/function(){function x(){_classCallCheck(this,x);}return _createClass(x,null,[{key:"getLastElementsByClass",value:function getLastElementsByClass(e,t,s){var _loop=function _loop(){var n=e[i];if(n.bubbleElement.classList.contains(t[0])&&!t.slice(1).find(function(a){return!n.bubbleElement.classList.contains(a);}))if(s){if(!s.find(function(l){return n.bubbleElement.classList.contains(l);}))return{v:n};}else return{v:n};},_ret;for(var i=e.length-1;i>=0;i-=1){_ret=_loop();if(_ret)return _ret.v;}}},{key:"getLastMessage",value:function getLastMessage(e,t,s){for(var i=e.length-1;i>=0;i-=1)if(e[i][0].role===t)if(s){if(e[i][0][s])return e[i][0];}else return e[i][0];}},{key:"getLastTextToElement",value:function getLastTextToElement(e,t){for(var s=e.length-1;s>=0;s-=1)if(e[s][0]===t)return e[s];}// IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message
|
84
86
|
// and if messages have custom roles, it will still look to update the last 'ai' role message
|
85
87
|
// prettier-ignore
|
86
|
-
},{key:"overwriteMessage",value:function overwriteMessage(e,t,s,i,n,o){var a=
|
87
|
-
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e.classList.add(
|
88
|
-
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var s=t?
|
88
|
+
},{key:"overwriteMessage",value:function overwriteMessage(e,t,s,i,n,o){var a=x.getLastElementsByClass(t,[x.getRoleClass(i),o],[je.BUBBLE_CLASS]),l=x.getLastMessage(e,i,n);return l&&(l[n]=s),a;}},{key:"getRoleClass",value:function getRoleClass(e){return"".concat(e,"-message");}// makes sure the bubble has dimensions when there is no text
|
89
|
+
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e.classList.add(x.EMPTY_MESSAGE_CLASS),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e.classList.contains(x.EMPTY_MESSAGE_CLASS)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,s,i,n;return(n=Array.from(((i=(s=(t=x.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:s[0])==null?void 0:i.children)||[]).map(function(o){return Array.from((o==null?void 0:o.children)||[]).find(function(a){return a.classList.contains("message-bubble");});}))==null?void 0:n[0];}},{key:"getLastMessageElement",value:function getLastMessageElement(e){return e.children[e.children.length-1];}},{key:"addRoleElements",value:function addRoleElements(e,t,s,i){s==null||s.addBesideMsg(e,t),i==null||i.addBesideMsg(e,t);}},{key:"hideRoleElements",value:function hideRoleElements(e,t,s){t==null||t.tryHide(e),s==null||s.tryHide(e);}},{key:"revealRoleElements",value:function revealRoleElements(e,t,s){t==null||t.tryReveal(e),s==null||s.tryReveal(e);}},{key:"softRemRoleElements",value:function softRemRoleElements(e,t,s){t==null||t.trySoftRem(e),s==null||s.trySoftRem(e);}},{key:"updateRefArr",value:function updateRefArr(e,t,s){s?e.unshift(t):e.push(t);}},{key:"buildRoleOuterContainerClass",value:function buildRoleOuterContainerClass(e){return"".concat(x.OUTER_CONTAINER_CLASS_ROLE_PREFIX).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$cla;e.outerContainer.classList.remove(x.POSITION_TOP_MESSAGE_CLASS,x.POSITION_MIDDLE_MESSAGE_CLASS,x.POSITION_BOTTOM_MESSAGE_CLASS),(_e$outerContainer$cla=e.outerContainer.classList).add.apply(_e$outerContainer$cla,_toConsumableArray(t));}},{key:"getNumberOfElements",value:function getNumberOfElements(e){var t=0;return e.text!==void 0&&(t+=1),e.html!==void 0&&(t+=1),e.files&&(t+=e.files.length),t;}},{key:"filterdMessageElements",value:function filterdMessageElements(e,t){return e.filter(function(s){return s.bubbleElement.classList.contains(t);});}},{key:"findMessageElements",value:function findMessageElements(e,t){return e.find(function(s){return s.bubbleElement.classList.contains(t);});}},{key:"generateMessageBodyElements",value:function generateMessageBodyElements(e,t){var s={};return e.text&&(s.text=x.findMessageElements(t,pe.TEXT_BUBBLE_CLASS)),e.html&&(s.html=x.findMessageElements(t,Te.HTML_BUBBLE_CLASS)),e.files&&(s.files=x.filterdMessageElements(t,z.FILE_BUBBLE_CLASS)),s;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var i=x.getNumberOfElements(e),n=s?t.slice(0,i):t.slice(t.length-i);return x.generateMessageBodyElements(e,n);}// if role not present - traverse all, if present - traverse last messages
|
90
|
+
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var s=t?x.buildRoleOuterContainerClass(t):void 0;for(var i=e.length-1;i>=0;i-=1){if(t||(s=Array.from(e[i].outerContainer.classList).find(function(u){return u.startsWith(x.OUTER_CONTAINER_CLASS_ROLE_PREFIX);})),!s)continue;var n=e[i],o=n.outerContainer.classList.contains(s),a=e[i-1],l=e[i+1],c=a==null?void 0:a.outerContainer.classList.contains(s),d=l==null?void 0:l.outerContainer.classList.contains(s);if(o)!c&&d?x.addNewPositionClasses(n,[x.POSITION_TOP_MESSAGE_CLASS]):c&&d?x.addNewPositionClasses(n,[x.POSITION_MIDDLE_MESSAGE_CLASS]):c&&!d?x.addNewPositionClasses(n,[x.POSITION_BOTTOM_MESSAGE_CLASS]):!c&&!d&&x.addNewPositionClasses(n,[x.POSITION_TOP_MESSAGE_CLASS,x.POSITION_BOTTOM_MESSAGE_CLASS]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer.classList).find(function(i){return i.startsWith(x.OUTER_CONTAINER_CLASS_ROLE_PREFIX);})===x.buildRoleOuterContainerClass(e):!1;}},{key:"resetAllRoleElements",value:function resetAllRoleElements(e,t,s){if(!t&&!s)return;var i="";e.forEach(function(n,o){n.bubbleElement.classList.contains(x.ERROR_MESSAGE_TEXT_CLASS)||x.revealRoleElements(n.innerContainer,t,s);var a=Array.from(n.outerContainer.classList).find(function(l){return l.startsWith(x.OUTER_CONTAINER_CLASS_ROLE_PREFIX);});i===a&&x.hideRoleElements(e[o-1].innerContainer,t,s),i=a;});}// this is a workaround to prevent JSON.parse(JSON.stringify()) from removing the files' 'ref' property values
|
89
91
|
// and 'custom' property value if it is not shallow copyable
|
90
92
|
// note - structuredClone can fix this but it doesn't have good legacy compatibility
|
91
|
-
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return
|
92
|
-
},{key:"
|
93
|
+
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return x.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!="object")return e;if(Array.isArray(e))return e.map(function(s){return x.processMessageContent(s);});var t={};return Object.entries(e).forEach(function(_ref2){var _ref3=_slicedToArray(_ref2,2),s=_ref3[0],i=_ref3[1];s==="ref"&&i instanceof File||s==="custom"?t[s]=i:i!==null&&_typeof(i)=="object"?t[s]=x.processMessageContent(i):t[s]=i;}),t;}}]);}();x.AI_ROLE="ai",x.USER_ROLE="user",x.ERROR_MESSAGE_TEXT_CLASS="error-message-text",x.OUTER_CONTAINER_CLASS_ROLE_PREFIX="deep-chat-outer-container-role-",x.EMPTY_MESSAGE_CLASS="empty-message",x.POSITION_TOP_MESSAGE_CLASS="deep-chat-top-message",x.POSITION_MIDDLE_MESSAGE_CLASS="deep-chat-middle-message",x.POSITION_BOTTOM_MESSAGE_CLASS="deep-chat-bottom-message";var b=x;var Pe=/*#__PURE__*/function(){function Pe(e,t){_classCallCheck(this,Pe);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialText="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(Pe,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e.text)===void 0&&(e==null?void 0:e.html)===void 0)return console.error(C.INVALID_STREAM_EVENT);e!=null&&e.custom&&this._message&&(this._message.custom=e.custom);var t=(e==null?void 0:e.text)||(e==null?void 0:e.html)||"",s=J.isScrollbarAtBottomOfElement(this._messages.elementRef),i=(e==null?void 0:e.text)!==void 0?"text":"html";if(!this._elements&&!this._message)this.setInitialState(i,t,e==null?void 0:e.role);else{if(this._streamType!==i)return console.error(C.INVALID_STREAM_EVENT_MIX);this.updateBasedOnType(t,i,e==null?void 0:e.overwrite);}s&&J.scrollToBottom(this._messages.elementRef);}},{key:"setInitialState",value:function setInitialState(e,t,s){var o,a;this._streamType=e,s!==null&&s!==void 0?s:s=b.AI_ROLE;var i=((o=this._messages._customWrappers)==null?void 0:o[s])||((a=this._messages._customWrappers)==null?void 0:a["default"]),n=i?"":t;this._elements=e==="text"?this._messages.addNewTextMessage(n,s):Te.add(this._messages,n,s),this._elements&&(this._elements.bubbleElement.classList.add(Pe.MESSAGE_CLASS),this._activeMessageRole=s,this._message=_defineProperty({role:this._activeMessageRole},e,n),this._messages.messageToElements.push([this._message,_defineProperty({},e,this._elements)]),i&&this.setTargetWrapperIfNeeded(this._elements,t,this._streamType,i));}// not using existing MessageBase logic to be able to stream html
|
94
|
+
},{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,s,i){e.bubbleElement.innerHTML=i,this._targetWrapper=ee.getTargetWrapper(e.bubbleElement),this._elements&&ee.apply(this._messages,this._elements.bubbleElement),this.updateBasedOnType(t,s);}},{key:"updateBasedOnType",value:function updateBasedOnType(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var o;var i=this._targetWrapper||((o=this._elements)==null?void 0:o.bubbleElement);this._partialRender||b.unfillEmptyMessageElement(i,e),(t==="text"?this.updateText:this.updateHTML).bind(this)(e,i,s);}},{key:"updateText",value:function updateText(e,t,s){this._message&&(this._message.text=s?e:this._message.text+e,this._partialRender&&this.isNewPartialRenderParagraph(t,s)&&this.partialRenderNewParagraph(t),this._partialBubble?this.partialRenderBubbleUpdate(e):this._messages.renderText(t,this._message.text));}},{key:"isNewPartialRenderParagraph",value:function isNewPartialRenderParagraph(e,t){var s;return t?(e.innerHTML="",!0):this._partialBubble?this._partialText&&this.shouldCreateNewParagraph(this._partialText):((s=this._message)==null?void 0:s.text)&&this.shouldCreateNewParagraph(this._message.text);}},{key:"shouldCreateNewParagraph",value:function shouldCreateNewParagraph(e){var t=e.indexOf(Pe.PARTIAL_RENDER_TEXT_MARK);return t===-1?!1:!e.substring(t+Pe.PARTIAL_RENDER_TEXT_MARK.length).startsWith("---");}},{key:"partialRenderNewParagraph",value:function partialRenderNewParagraph(e){this._partialText="",this._partialBubble=document.createElement("div"),this._partialBubble.classList.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,s){if(this._message)if(s)this._message.html=e,t.innerHTML=e;else{var i=document.createElement("span");i.innerHTML=e,t.appendChild(i),this._message.html=(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(C.NO_VALID_STREAM_EVENTS_SENT);(e=this._elements.bubbleElement)!=null&&e.classList.contains(Pe.MESSAGE_CLASS)&&(this._streamType==="text"?this._messages.textToSpeech&&St.speak(this._message.text||"",this._messages.textToSpeech):this._streamType==="html"&&this._elements&&ee.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement.classList.remove(Pe.MESSAGE_CLASS),this._message&&(this._messages.sendClientUpdate(pe.createMessageContent(this._message),!1),(t=this._messages.browserStorage)==null||t.addMessages(this._messages.messageToElements.map(function(_ref5){var _ref6=_slicedToArray(_ref5,1),s=_ref6[0];return s;}))),this._hasStreamEnded=!0);}}},{key:"markFileAdded",value:function markFileAdded(){this._fileAdded=!0;}},{key:"newMessage",value:function newMessage(){this.finaliseStreamedMessage(),this._elements=void 0,delete this._message,this._fileAdded=!1,this._hasStreamEnded=!1,this._activeMessageRole=void 0;}// prettier-ignore
|
95
|
+
},{key:"endStreamAfterFileDownloaded",value:function(){var _endStreamAfterFileDownloaded=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e,t){var _yield$t,s,i;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;s=_yield$t.text;i=_yield$t.files;s&&this.updateBasedOnType(s,"text",!0),this._endStreamAfterOperation=!1,this.finaliseStreamedMessage(),i&&e.addNewMessage({files:i});case 2:return _context2.a(2);}},_callee2,this);}));function endStreamAfterFileDownloaded(_x3,_x4){return _endStreamAfterFileDownloaded.apply(this,arguments);}return endStreamAfterFileDownloaded;}()}]);}();Pe.MESSAGE_CLASS="streamed-message",Pe.PARTIAL_RENDER_TEXT_MARK="\n\n";var Me=Pe;var ze=/*#__PURE__*/function(){function ze(){_classCallCheck(this,ze);}return _createClass(ze,null,[{key:"tempRemoveContentHeader",value:// need to pass stringifyBody boolean separately as binding is throwing an error for some reason
|
93
96
|
// prettier-ignore
|
94
|
-
function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/
|
95
|
-
},{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,s,i){var o,a;var n={method:((o=e.connectSettings)==null?void 0:o.method)||"POST",headers:t};return n.method!=="GET"&&(n.body=s?JSON.stringify(i):i),e.connectSettings.credentials&&(n.credentials=e.connectSettings.credentials),fetch(((a=e.connectSettings)==null?void 0:a.url)||e.url||"",n);})},{key:"processResponseByType",value:function processResponseByType(e){var t=e.headers.get("content-type");return t!=null&&t.includes("application/json")?e.json():t!=null&&t.includes("text/plain")||!t?e:e.blob();}},{key:"processRequestInterceptor",value:function(){var _processRequestInterceptor=_asyncToGenerator(/*#__PURE__*/
|
96
|
-
},{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/
|
97
|
-
function(){var _request=_asyncToGenerator(/*#__PURE__*/
|
98
|
-
},{key:"handleReadableStream",value:function handleReadableStream(e,t,s,i,n,o,a){var h;var _e$streamHandlers=e.streamHandlers,l=_e$streamHandlers.onOpen,c=_e$streamHandlers.onClose,d=_e$streamHandlers.abortStream;var u=!1;fetch(((h=e.connectSettings)==null?void 0:h.url)||e.url||"",i).then(/*#__PURE__*/function(){var _ref7=_asyncToGenerator(/*#__PURE__*/
|
99
|
-
},{key:"handleEventStream",value:function handleEventStream(e,t,s,i,n,o,a){var u;var _e$streamHandlers2=e.streamHandlers,l=_e$streamHandlers2.onOpen,c=_e$streamHandlers2.onClose,d=_e$streamHandlers2.abortStream;
|
100
|
-
onopen:function onopen(h){return _asyncToGenerator(/*#__PURE__*/
|
97
|
+
function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,s){var i,n,_t2;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("Request settings have not been set up");case 1:i=e.headers[ze.CONTENT_TYPE];delete e.headers[ze.CONTENT_TYPE];_context3.p=2;_context3.n=3;return t(s);case 3:n=_context3.v;_context3.n=5;break;case 4:_context3.p=4;_t2=_context3.v;throw e.headers[ze.CONTENT_TYPE]=i,_t2;case 5:return _context3.a(2,(e.headers[ze.CONTENT_TYPE]=i,n));}},_callee3,null,[[2,4]]);}));function tempRemoveContentHeader(_x9,_x0,_x1){return _tempRemoveContentHeader.apply(this,arguments);}return tempRemoveContentHeader;}()},{key:"displayError",value:function displayError(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"Service error, please try again.";if(console.error(t),_typeof(t)=="object")return t instanceof Error?e.addNewErrorMessage("service",t.message):Array.isArray(t)||typeof t.error=="string"?e.addNewErrorMessage("service",t):Object.keys(t).length===0?e.addNewErrorMessage("service",s):e.addNewErrorMessage("service",JSON.stringify(t));e.addNewErrorMessage("service",t);}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
98
|
+
},{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,s,i){var o,a;var n={method:((o=e.connectSettings)==null?void 0:o.method)||"POST",headers:t};return n.method!=="GET"&&(n.body=s?JSON.stringify(i):i),e.connectSettings.credentials&&(n.credentials=e.connectSettings.credentials),fetch(((a=e.connectSettings)==null?void 0:a.url)||e.url||"",n);})},{key:"processResponseByType",value:function processResponseByType(e){var t=e.headers.get("content-type");return t!=null&&t.includes("application/json")?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,s,i,n,_t3;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:_t3=_context4.v;if(_t3){_context4.n=2;break;}_t3=t;case 2:s=_t3;i=s;n=s;return _context4.a(2,{body:i.body,headers:i.headers,error:n.error});}},_callee4);}));function processRequestInterceptor(_x10,_x11){return _processRequestInterceptor.apply(this,arguments);}return processRequestInterceptor;}()},{key:"validateResponseFormat",value:function validateResponseFormat(e,t){if(!e)return!1;var s=Array.isArray(e)?e:[e];return t&&s.length>1?(console.error(C.INVALID_STREAM_ARRAY_RESPONSE),!1):!s.find(function(n){return _typeof(n)!="object"||!(typeof n.error=="string"||typeof n.text=="string"||typeof n.html=="string"||Array.isArray(n.files));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,s){e.addNewErrorMessage("service",t),s==null||s();}// prettier-ignore
|
99
|
+
},{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e,t){var s,i,_s$displayError,n,_s$useRI,o,a,l,c,d,_args5=arguments,_t4;return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:s=_args5.length>2&&_args5[2]!==undefined?_args5[2]:{};i=s.io,_s$displayError=s.displayError,n=_s$displayError===void 0?!0:_s$displayError,_s$useRI=s.useRI,o=_s$useRI===void 0?!0:_s$useRI;if(i!=null&&i.extractResultData){_context5.n=1;break;}return _context5.a(2,t);case 1:a=o?i.deepChat.responseInterceptor:void 0;_context5.n=2;return a==null?void 0:a(t);case 2:_t4=_context5.v;if(_t4){_context5.n=3;break;}_t4=t;case 3:l=_t4;_context5.n=4;return i.extractResultData(l);case 4:c=_context5.v;if(!(!c||_typeof(c)!="object"&&!Array.isArray(c))){_context5.n=5;break;}if(n){d=C.INVALID_RESPONSE(t,"response",!!a,l);ze.displayError(e,d);}return _context5.a(2);case 5:return _context5.a(2,c);}},_callee5);}));function basicResponseProcessing(_x12,_x13){return _basicResponseProcessing.apply(this,arguments);}return basicResponseProcessing;}()}]);}();ze.CONTENT_TYPE="Content-Type";var E=ze;function Jo(_x14,_x15){return _Jo.apply(this,arguments);}function _Jo(){_Jo=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(r,e){var t,s;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:t=r.getReader();case 1:_context152.n=2;return t.read();case 2:if((s=_context152.v).done){_context152.n=4;break;}e(s.value);case 3:_context152.n=1;break;case 4:return _context152.a(2);}},_callee152);}));return _Jo.apply(this,arguments);}function Xo(r){var e,t,s,i=!1;return function(o){e===void 0?(e=o,t=0,s=-1):e=Zo(e,o);var a=e.length;var l=0;for(;t<a;){i&&(e[t]===10&&(l=++t),i=!1);var c=-1;for(;t<a&&c===-1;++t)switch(e[t]){case 58:s===-1&&(s=t-l);break;case 13:i=!0;case 10:c=t;break;}if(c===-1)break;r(e.subarray(l,c),s),l=t,s=-1;}l===a?e=void 0:l!==0&&(e=e.subarray(l),t-=l);};}function Yo(r,e,t){var s=dn();var i=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(s),s=dn();else if(a>0){var l=i.decode(o.subarray(0,a)),c=a+(o[a+1]===32?2:1),d=i.decode(o.subarray(c));switch(l){case"data":s.data=s.data?s.data+"\n"+d:d;break;case"event":s.event=d;break;case"id":r(s.id=d);break;case"retry":var u=parseInt(d,10);isNaN(u)||e(s.retry=u);break;}}};}function Zo(r,e){var t=new Uint8Array(r.length+e.length);return t.set(r),t.set(e,r.length),t;}function dn(){return{data:"",event:"",id:"",retry:void 0};}var Qo=function Qo(r,e){var t={};for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&e.indexOf(s)<0&&(t[s]=r[s]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,s=Object.getOwnPropertySymbols(r);i<s.length;i++)e.indexOf(s[i])<0&&Object.prototype.propertyIsEnumerable.call(r,s[i])&&(t[s[i]]=r[s[i]]);return t;};var bi="text/event-stream",ea=1e3,hn="last-event-id";function ta(r,e){var t=e.signal,s=e.headers,i=e.onopen,n=e.onmessage,o=e.onclose,a=e.onerror,l=e.openWhenHidden,c=e.fetch,d=Qo(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(u,h){var p=Object.assign({},s);p.accept||(p.accept=bi);var m;function f(){m.abort(),document.hidden||U();}l||document.addEventListener("visibilitychange",f);var g=ea,y=0;function T(){document.removeEventListener("visibilitychange",f),window.clearTimeout(y),m.abort();}t==null||t.addEventListener("abort",function(){T(),u();});var L=c!==null&&c!==void 0?c:window.fetch,O=i!==null&&i!==void 0?i:sa;function U(){return _U.apply(this,arguments);}function _U(){_U=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var ge,we,re,_t5;return _regenerator().w(function(_context6){while(1)switch(_context6.p=_context6.n){case 0:m=new AbortController();_context6.p=1;_context6.n=2;return L(r,Object.assign(Object.assign({},d),{headers:p,signal:m.signal}));case 2:we=_context6.v;_context6.n=3;return O(we);case 3:_context6.n=4;return Jo(we.body,Xo(Yo(function(re){re?p[hn]=re:delete p[hn];},function(re){g=re;},n)));case 4:o==null||o();T();u();_context6.n=6;break;case 5:_context6.p=5;_t5=_context6.v;if(!m.signal.aborted)try{re=(ge=a==null?void 0:a(_t5))!==null&&ge!==void 0?ge:g;window.clearTimeout(y),y=window.setTimeout(U,re);}catch(re){T(),h(re);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _U.apply(this,arguments);}U();});}function sa(r){var e=r.headers.get("content-type");if(!(e!=null&&e.startsWith(bi)))throw new Error("Expected content-type to be ".concat(bi,", Actual: ").concat(e));}var _=/*#__PURE__*/function(){function _(){_classCallCheck(this,_);}return _createClass(_,null,[{key:"request",value:// prettier-ignore
|
100
|
+
function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,s){var i,n,p,m,f,g,y,o,_yield$E$processReque,a,l,c,d,u,h,_args7=arguments;return _regenerator().w(function(_context7){while(1)switch(_context7.n){case 0:i=_args7.length>3&&_args7[3]!==undefined?_args7[3]:!0;n=_args7.length>4&&_args7[4]!==undefined?_args7[4]:!1;o={body:t,headers:(p=e.connectSettings)==null?void 0:p.headers};_context7.n=1;return E.processRequestInterceptor(e.deepChat,o);case 1:_yield$E$processReque=_context7.v;a=_yield$E$processReque.body;l=_yield$E$processReque.headers;c=_yield$E$processReque.error;if(!c){_context7.n=2;break;}return _context7.a(2,E.onInterceptorError(s,c,e.streamHandlers.onClose));case 2:if(!((m=e.connectSettings)!=null&&m.handler)){_context7.n=3;break;}return _context7.a(2,_e.stream(e,a,s));case 3:if(!(((f=e.connectSettings)==null?void 0:f.url)===xe.URL)){_context7.n=4;break;}return _context7.a(2,xe.requestStream(s,e));case 4:d=new Me(s,e.stream),u=E.fetch.bind(this,e,l,i),h={method:((g=e.connectSettings)==null?void 0:g.method)||"POST",headers:l,credentials:(y=e.connectSettings)==null?void 0:y.credentials,body:i?JSON.stringify(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?_.handleReadableStream(e,s,d,h,n,u,a):_.handleEventStream(e,s,d,h,n,u,a),d));}},_callee7,this);}));function request(_x16,_x17,_x18){return _request.apply(this,arguments);}return request;}()// prettier-ignore
|
101
|
+
},{key:"handleReadableStream",value:function handleReadableStream(e,t,s,i,n,o,a){var h;var _e$streamHandlers=e.streamHandlers,l=_e$streamHandlers.onOpen,c=_e$streamHandlers.onClose,d=_e$streamHandlers.abortStream;var u=!1;fetch(((h=e.connectSettings)==null?void 0:h.url)||e.url||"",i).then(/*#__PURE__*/function(){var _ref7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(p){var y,T,m,f,g,_yield$m$read,L,O,U,ge,we,_t6;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(p.body){_context8.n=1;break;}throw new Error(C.READABLE_STREAM_CONNECTION_ERROR);case 1:m=p.body.getReader(),f=new TextDecoder();l();g=!1;case 2:if(!(!g&&!u)){_context8.n=8;break;}_context8.n=3;return m.read();case 3:_yield$m$read=_context8.v;L=_yield$m$read.value;O=_yield$m$read.done;if(!(g=O,g)){_context8.n=4;break;}_.handleClose(e,s,c,n);_context8.n=7;break;case 4:U=f.decode(L,{stream:!0});_context8.n=5;return(T=(y=e.deepChat).responseInterceptor)==null?void 0:T.call(y,U);case 5:_t6=_context8.v;if(_t6){_context8.n=6;break;}_t6=U;case 6:ge=_t6;we=_typeof(ge)=="object"?ge:{text:U};_.handleMessage(e,t,s,we,o,a);case 7:_context8.n=2;break;case 8:return _context8.a(2);}},_callee8);}));return function(_x19){return _ref7.apply(this,arguments);};}())["catch"](function(p){_.handleError(e,t,p);}),d.abort=function(){u=!0;};}// prettier-ignore
|
102
|
+
},{key:"handleEventStream",value:function handleEventStream(e,t,s,i,n,o,a){var u;var _e$streamHandlers2=e.streamHandlers,l=_e$streamHandlers2.onOpen,c=_e$streamHandlers2.onClose,d=_e$streamHandlers2.abortStream;ta(((u=e.connectSettings)==null?void 0:u.url)||e.url||"",_objectSpread(_objectSpread({},i),{},{openWhenHidden:!0,// keep stream open when browser tab not open
|
103
|
+
onopen:function onopen(h){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(){return _regenerator().w(function(_context9){while(1)switch(_context9.n){case 0:if(!h.ok){_context9.n=1;break;}return _context9.a(2,l());case 1:_context9.n=2;return E.processResponseByType(h);case 2:throw _context9.v;case 3:return _context9.a(2);}},_callee9);}))();},onmessage:function onmessage(h){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(){var p,m,f,g,_t7;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(JSON.stringify(h.data)!==JSON.stringify("[DONE]"))){_context0.n=3;break;}try{f=JSON.parse(h.data);}catch(_unused6){f={};}_context0.n=1;return(m=(p=e.deepChat).responseInterceptor)==null?void 0:m.call(p,f);case 1:_t7=_context0.v;if(_t7){_context0.n=2;break;}_t7=f;case 2:g=_t7;_.handleMessage(e,t,s,g,o,a);case 3:return _context0.a(2);}},_callee0);}))();},onerror:function onerror(h){throw c(),h;},onclose:function onclose(){_.handleClose(e,s,c,n);},signal:d.signal}))["catch"](function(h){_.handleError(e,t,h);});}//prettier-ignore
|
101
104
|
},{key:"handleMessage",value:function handleMessage(e,t,s,i,n,o){var a;(a=e.extractResultData)==null||a.call(e,i,n,o).then(function(l){_.upsertWFiles(t,s.upsertStreamedMessage.bind(s),s,l);})["catch"](function(l){return E.displayError(t,l);});}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
102
105
|
},{key:"handleError",value:function handleError(e,t,s){var i;t.isLastMessageError()||(i=e.extractResultData)==null||i.call(e,s).then(function(){E.displayError(t,s);})["catch"](function(n){E.displayError(t,n);});}},{key:"handleClose",value:function handleClose(e,t,s,i){if(!e.asyncCallInProgress)try{t.finaliseStreamedMessage(),s();}catch(n){if(!i)throw n;}}// io is only passed for demo to simulate a real stream
|
103
|
-
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/
|
106
|
+
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,s,i){var n,o,_o2,a,_o3,_a2;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:n=t;_context1.n=1;return E.basicResponseProcessing(e,s,{io:i,useRI:!1});case 1:if(_context1.v){_context1.n=2;break;}return _context1.a(2,t.onClose());case 2:if(!(Array.isArray(s)&&(s=s[0]),s.files)){_context1.n=4;break;}_context1.n=3;return E.basicResponseProcessing(e,{files:s.files},{io:i});case 3:o=_context1.v;e.addNewMessage(_objectSpread({sendUpdate:!1,ignoreText:!0},o),!1);case 4:if(s.text){t.onOpen();_o2=s.text.split(""),a=new Me(e,i==null?void 0:i.stream);_.populateMessages(e,_o2,a,n,"text",0,i);}if(s.html){t.onOpen();_o3=ee.splitHTML(s.html);_o3.length===0&&(_o3=s.html.split(""));_a2=new Me(e,i==null?void 0:i.stream);_.populateMessages(e,_o3,_a2,n,"html",0,i);}s.error&&(E.displayError(e,s.error),t.onClose());case 5:return _context1.a(2);}},_callee1);}));function simulate(_x20,_x21,_x22,_x23){return _simulate.apply(this,arguments);}return simulate;}()// prettier-ignore
|
104
107
|
// io is only passed for demo to simulate a real stream
|
105
|
-
},{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/
|
106
|
-
},{key:"request",value:function request(e,t){var s=
|
107
|
-
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var s=
|
108
|
-
},{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,s,i){if(!i)return;var n=e.stream.simulation;if(typeof n=="string"){var _s$o;var o=i.role||b.AI_ROLE,a=s[o];i.text===n||i.html===n?(a==null||a.finaliseStreamedMessage(),delete s[o]):((_s$o=s[o])!==null&&_s$o!==void 0?_s$o:s[o]=new Me(t,e.stream),s[o].upsertStreamedMessage(i));}else _.simulate(t,e.streamHandlers,i);}}]);}();var _e=/*#__PURE__*/function(){function _e(){_classCallCheck(this,_e);}return _createClass(_e,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/
|
109
|
-
},{key:"stream",value:function stream(e,t,s){var u,h;var i=!0,n=!1;var o=new Me(s,e.stream),a=function a(){n||!i||(e.streamHandlers.onOpen(),n=!0);},l=function l(){i&&(_e.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1);},c=/*#__PURE__*/function(){var _ref10=_asyncToGenerator(/*#__PURE__*/
|
110
|
-
},{key:"websocket",value:function websocket(e,t){var _this9=this;var l,c;var s={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=s;var i=function i(){t.removeError(),s.isOpen=!0;},n=function n(){s.isOpen=!1;},o=/*#__PURE__*/function(){var _ref11=_asyncToGenerator(/*#__PURE__*/
|
111
|
-
function(){var _request3=_asyncToGenerator(/*#__PURE__*/
|
112
|
-
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/
|
113
|
-
},{key:"verifyKey",value:function verifyKey(e,t,s,i,n,o,a,l,c){if(e==="")return o(C.INVALID_KEY);a(),fetch(t,{method:i,headers:s,body:c||null}).then(function(d){return E.processResponseByType(d);}).then(function(d){l(d,e,n,o);})["catch"](function(d){o(C.CONNECTION_FAILED),console.error(d);});}}]);}();var
|
108
|
+
},{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,s,i,n,o,a){var l,c,d;return _regenerator().w(function(_context10){while(1)switch(_context10.n){case 0:l=t[o];if(!l){_context10.n=2;break;}_context10.n=1;return E.basicResponseProcessing(e,_defineProperty({},n,l),{io:a});case 1:c=_context10.v;_.upsertWFiles(e,s.upsertStreamedMessage.bind(s),s,c);d=setTimeout(function(){_.populateMessages(e,t,s,i,n,o+1,a);},i.simulationInterim||6);i.abortStream.abort=function(){_.abort(d,s,i.onClose);};_context10.n=3;break;case 2:s.finaliseStreamedMessage(),i.onClose();case 3:return _context10.a(2);}},_callee10);}));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 _.isSimulation(e)&&t&&(t.text||t.html);}},{key:"abort",value:function abort(e,t,s){clearTimeout(e),t.finaliseStreamedMessage(),s();}},{key:"upsertWFiles",value:function upsertWFiles(e,t,s,i){if(i&&Array.isArray(i)&&(i=i[0]),i!=null&&i.text||i!=null&&i.html){var n=t(i);s!==null&&s!==void 0?s:s=n||void 0;}i!=null&&i.files&&(e.addNewMessage({files:i.files}),s==null||s.markFileAdded());}}]);}();var it=/*#__PURE__*/function(){function it(){_classCallCheck(this,it);}return _createClass(it,null,[{key:"generateResponse",value:function generateResponse(e){var t=e[e.length-1][0];if(t.files&&t.files.length>0){if(t.files.length>1)return"These are interesting files!";var s=t.files[0];return s.src&&s.src.startsWith("data:image/gif")?"That is a nice gif!":s.type==="image"?"That is a nice image!":s.type==="audio"?"I like the sound of that!":"That is an interesting file!";}if(t.text){if(t.text.charAt(t.text.length-1)==="?")return"I'm sorry but I can't answer that question...";if(t.text.includes("updog"))return"What's updog?";}return"Hi there! This is a demo response!";}},{key:"getCustomResponse",value:function getCustomResponse(e,t){return typeof e=="function"?e(t):e;}},{key:"getResponse",value:function getResponse(_ref8){var e=_ref8.customDemoResponse,t=_ref8.messageToElements;return e?it.getCustomResponse(e,t[t.length-1][0]):{text:it.generateResponse(t)};}// timeout is used to simulate a timeout for a response to come back
|
109
|
+
},{key:"request",value:function request(e,t){var s=it.getResponse(t);setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(){var i,n,o;return _regenerator().w(function(_context11){while(1)switch(_context11.n){case 0:_context11.n=1;return E.basicResponseProcessing(t,s,{io:e});case 1:i=_context11.v;if(i){_context11.n=2;break;}return _context11.a(2,e.completionsHandlers.onFinish());case 2:n=Array.isArray(i)?i:[i],o=n.find(function(a){return typeof a.error=="string";});o?(t.addNewErrorMessage("service",o.error),e.completionsHandlers.onFinish()):_.isSimulatable(e.stream,i)?_.simulate(t,e.streamHandlers,i):(n.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
|
110
|
+
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var s=it.getResponse(e);_.simulate(e,t.streamHandlers,s,t);},400);}}]);}();it.URL="deep-chat-demo";var xe=it;var W=/*#__PURE__*/function(){function W(){_classCallCheck(this,W);}return _createClass(W,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(!W.isElementPresentInDOM(e.deepChat))return;var s=e.connectSettings.websocket;if(s){if(e.connectSettings.handler)return _e.websocket(e,t);try{var i=typeof s!="boolean"?s:void 0,n=new WebSocket(e.connectSettings.url||"",i);e.websocket=n,e.websocket.onopen=function(){var o,a;t.removeError(),e.websocket&&_typeof(e.websocket)=="object"&&W.assignListeners(e,n,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console.error(o),W.retryConnection(e,t);};}catch(i){console.error(i),W.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var s,i;(i=(s=e.deepChat)._validationHandler)==null||i.call(s),W.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage("service","Connection error"),setTimeout(function(){W.createConnection(e,t);},5e3));}},{key:"assignListeners",value:function assignListeners(e,t,s){var _this8=this;var i={};t.onmessage=/*#__PURE__*/function(){var _ref0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(n){var o,a,l,c,_l,_c,_t8;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(n.data);_context12.n=2;return E.basicResponseProcessing(s,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(C.INVALID_RESPONSE(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!_.isSimulation(e.stream)){_context12.n=4;break;}l=W.stream.bind(_this8,e,s,i),c=i[o.role||b.AI_ROLE];_.upsertWFiles(s,l,c,a);_context12.n=6;break;case 4:_l=Array.isArray(a)?a:[a],_c=_l.find(function(d){return typeof d.error=="string";});if(!_c){_context12.n=5;break;}throw _c.error;case 5:_l.forEach(function(d){return s.addNewMessage(d);});case 6:_context12.n=8;break;case 7:_context12.p=7;_t8=_context12.v;E.displayError(s,_t8,"Error in server message");case 8:return _context12.a(2);}},_callee12,null,[[1,7]]);}));return function(_x31){return _ref0.apply(this,arguments);};}(),t.onclose=function(){console.error("Connection closed"),s.isLastMessageError()||s.addNewErrorMessage("service","Connection error"),e.stream&&e.streamHandlers.abortStream.abort(),W.createConnection(e,s);};}},{key:"sendWebsocket",value:function(){var _sendWebsocket=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e,t,s){var i,d,u,n,o,_yield$E$processReque2,a,l,c,_args13=arguments;return _regenerator().w(function(_context13){while(1)switch(_context13.n){case 0:i=_args13.length>3&&_args13[3]!==undefined?_args13[3]:!0;if(!(((d=e.connectSettings)==null?void 0:d.url)===xe.URL)){_context13.n=1;break;}return _context13.a(2,xe.request(e,s));case 1:n=e.websocket;if(!(!n||n==="pending")){_context13.n=2;break;}return _context13.a(2);case 2:o={body:t,headers:(u=e.connectSettings)==null?void 0:u.headers};_context13.n=3;return E.processRequestInterceptor(e.deepChat,o);case 3:_yield$E$processReque2=_context13.v;a=_yield$E$processReque2.body;l=_yield$E$processReque2.error;if(!l){_context13.n=4;break;}return _context13.a(2,s.addNewErrorMessage("service",l));case 4:if(W.isWebSocket(n)){_context13.n=5;break;}return _context13.a(2,n.newUserMessage.listener(a));case 5:c=i?JSON.stringify(a):a;n.readyState===void 0||n.readyState!==n.OPEN?(console.error("Connection is not open"),s.isLastMessageError()||s.addNewErrorMessage("service","Connection error")):(n.send(JSON.stringify(c)),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:W.isWebSocket(e)?e.readyState!==void 0&&e.readyState===e.OPEN:e.isOpen:!0;}// if false then it is the internal websocket handler
|
111
|
+
},{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,s,i){if(!i)return;var n=e.stream.simulation;if(typeof n=="string"){var _s$o;var o=i.role||b.AI_ROLE,a=s[o];i.text===n||i.html===n?(a==null||a.finaliseStreamedMessage(),delete s[o]):((_s$o=s[o])!==null&&_s$o!==void 0?_s$o:s[o]=new Me(t,e.stream),s[o].upsertStreamedMessage(i));}else _.simulate(t,e.streamHandlers,i);}}]);}();var _e=/*#__PURE__*/function(){function _e(){_classCallCheck(this,_e);}return _createClass(_e,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(e,t,s){var a,l,i,n,o;return _regenerator().w(function(_context15){while(1)switch(_context15.n){case 0:i=!0;n=/*#__PURE__*/function(){var _ref1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(c){var d,u,h;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(i){_context14.n=1;break;}return _context14.a(2);case 1:i=!1;_context14.n=2;return E.basicResponseProcessing(s,c,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console.error(C.INVALID_RESPONSE(c,"server",!!e.deepChat.responseInterceptor,d)),s.addNewErrorMessage("service","Error in server message"),e.completionsHandlers.onFinish();else{u=Array.isArray(d)?d:[d],h=u.find(function(p){return typeof p.error=="string";});h?(console.error(h.error),s.addNewErrorMessage("service",h.error),e.completionsHandlers.onFinish()):_.isSimulatable(e.stream,d)?_.simulate(s,e.streamHandlers,d):(u.forEach(function(p){return s.addNewMessage(p);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function n(_x38){return _ref1.apply(this,arguments);};}(),o=_e.generateOptionalSignals();(l=(a=e.connectSettings).handler)==null||l.call(a,t,_objectSpread(_objectSpread({},o),{},{onResponse:n}));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 s=t.messageElementRefs[t.messageElementRefs.length-1];pe.isLoadingMessage(s)?t.removeLastMessage():e.finaliseStreamedMessage();}catch(s){console.error(s),t.addNewErrorMessage("service",s);}}// prettier-ignore
|
112
|
+
},{key:"stream",value:function stream(e,t,s){var u,h;var i=!0,n=!1;var o=new Me(s,e.stream),a=function a(){n||!i||(e.streamHandlers.onOpen(),n=!0);},l=function l(){i&&(_e.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1);},c=/*#__PURE__*/function(){var _ref10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(p){var m,f;return _regenerator().w(function(_context16){while(1)switch(_context16.n){case 0:if(i){_context16.n=1;break;}return _context16.a(2);case 1:_context16.n=2;return E.basicResponseProcessing(s,p,{io:e,displayError:!1});case 2:m=_context16.v;if(m)m.error?(_e.streamError(m.error,o,e,s),i=!1):_.upsertWFiles(s,o.upsertStreamedMessage.bind(o),o,m);else{f=C.INVALID_RESPONSE(p,"server",!!e.deepChat.responseInterceptor,m);_e.streamError(f,o,e,s),i=!1;}case 3:return _context16.a(2);}},_callee16);}));return function c(_x39){return _ref10.apply(this,arguments);};}();e.streamHandlers.abortStream.abort=function(){_e.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1;};var d=_e.generateOptionalSignals();(h=(u=e.connectSettings).handler)==null||h.call(u,t,_objectSpread(_objectSpread({},d),{},{onOpen:a,onResponse:c,onClose:l,stopClicked:e.streamHandlers.stopClicked}));}},{key:"streamError",value:function streamError(e,t,s,i){console.error(e),t.finaliseStreamedMessage(),i.addNewErrorMessage("service",e),s.streamHandlers.onClose();}// prettier-ignore
|
113
|
+
},{key:"websocket",value:function websocket(e,t){var _this9=this;var l,c;var s={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=s;var i=function i(){t.removeError(),s.isOpen=!0;},n=function n(){s.isOpen=!1;},o=/*#__PURE__*/function(){var _ref11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(d){var u,h,p,m,f,g;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:if(s.isOpen){_context17.n=1;break;}return _context17.a(2);case 1:_context17.n=2;return E.basicResponseProcessing(t,d,{io:e,displayError:!1});case 2:u=_context17.v;if(!u)console.error(C.INVALID_RESPONSE(d,"server",!!e.deepChat.responseInterceptor,u)),t.addNewErrorMessage("service","Error in server message");else{h=Array.isArray(u)?u:[u],p=h.find(function(m){return typeof m.error=="string";});if(p)console.error(p.error),t.isLastMessageError()||t.addNewErrorMessage("service",p.error);else if(_.isSimulation(e.stream)){m=u,f=W.stream.bind(_this9,e,t,s.roleToStream),g=s.roleToStream[m.role||b.AI_ROLE];_.upsertWFiles(t,f,g,m);}else h.forEach(function(m){return t.addNewMessage(m);});}case 3:return _context17.a(2);}},_callee17);}));return function o(_x40){return _ref11.apply(this,arguments);};}(),a=_e.generateOptionalSignals();(c=(l=e.connectSettings).handler)==null||c.call(l,void 0,_objectSpread(_objectSpread({},a),{},{onOpen:i,onResponse:o,onClose:n,newUserMessage:s.newUserMessage}));}},{key:"generateOptionalSignals",value:function generateOptionalSignals(){return{onClose:function onClose(){},onOpen:function onOpen(){},stopClicked:{listener:function listener(){}},newUserMessage:{listener:function listener(){}}};}}]);}();var R=/*#__PURE__*/function(){function R(){_classCallCheck(this,R);}return _createClass(R,null,[{key:"request",value:// prettier-ignore
|
114
|
+
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,s){var i,h,p,m,n,_yield$E$processReque3,o,a,l,c,d,u,_args19=arguments;return _regenerator().w(function(_context19){while(1)switch(_context19.n){case 0:i=_args19.length>3&&_args19[3]!==undefined?_args19[3]:!0;n={body:t,headers:(h=e.connectSettings)==null?void 0:h.headers};_context19.n=1;return E.processRequestInterceptor(e.deepChat,n);case 1:_yield$E$processReque3=_context19.v;o=_yield$E$processReque3.body;a=_yield$E$processReque3.headers;l=_yield$E$processReque3.error;c=e.completionsHandlers.onFinish;if(!l){_context19.n=2;break;}return _context19.a(2,E.onInterceptorError(s,l,c));case 2:if(!((p=e.connectSettings)!=null&&p.handler)){_context19.n=3;break;}return _context19.a(2,_e.request(e,o,s));case 3:if(!(((m=e.connectSettings)==null?void 0:m.url)===xe.URL)){_context19.n=4;break;}return _context19.a(2,xe.request(e,s));case 4:d=!0;u=E.fetch.bind(this,e,a,i);u(o).then(function(f){return d=!!f.ok,f;}).then(function(f){return E.processResponseByType(f);}).then(/*#__PURE__*/function(){var _ref12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(f){var T,L,g,y,_t9;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(L=(T=e.deepChat).responseInterceptor)==null?void 0:L.call(T,f);case 2:_t9=_context18.v;if(_t9){_context18.n=3;break;}_t9=f;case 3:g=_t9;_context18.n=4;return e.extractResultData(g,u,o);case 4:y=_context18.v;if(d){_context18.n=5;break;}throw f;case 5:if(!(!y||_typeof(y)!="object"&&!Array.isArray(y))){_context18.n=6;break;}throw Error(C.INVALID_RESPONSE(f,"response",!!e.deepChat.responseInterceptor,g));case 6:y.makingAnotherRequest||(_.isSimulatable(e.stream,y)?_.simulate(s,e.streamHandlers,y):((Array.isArray(y)?y:[y]).forEach(function(U){return s.addNewMessage(U);}),c()));case 7:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref12.apply(this,arguments);};}())["catch"](function(f){E.displayError(s,f),c();});case 5:return _context19.a(2);}},_callee19,this);}));function request(_x41,_x42,_x43){return _request3.apply(this,arguments);}return request;}()},{key:"executePollRequest",value:function executePollRequest(e,t,s,i){var n=e.completionsHandlers.onFinish;fetch(t,s).then(function(o){return o.json();}).then(/*#__PURE__*/function(){var _ref13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(o){var l,c,a,_t0,_t1,_t10;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:_t0=e;_context20.n=2;return(c=(l=e.deepChat).responseInterceptor)==null?void 0:c.call(l,o);case 2:_t1=_context20.v;if(_t1){_context20.n=3;break;}_t1=o;case 3:_t10=_t1;_context20.n=4;return _t0.extractPollResultData.call(_t0,_t10);case 4:a=_context20.v;a.timeoutMS?setTimeout(function(){R.executePollRequest(e,t,s,i);},a.timeoutMS):_.isSimulatable(e.stream,a)?_.simulate(i,e.streamHandlers,a):(i.addNewMessage(a),n());case 5:return _context20.a(2);}},_callee20);}));return function(_x45){return _ref13.apply(this,arguments);};}())["catch"](function(o){E.displayError(i,o),n();});}// prettier-ignore
|
115
|
+
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,s){var i,p,m,f,n,_yield$E$processReque4,o,a,l,c,d,u,h,_args21=arguments;return _regenerator().w(function(_context21){while(1)switch(_context21.n){case 0:i=_args21.length>3&&_args21[3]!==undefined?_args21[3]:!0;n={body:t,headers:(p=e.connectSettings)==null?void 0:p.headers};_context21.n=1;return E.processRequestInterceptor(e.deepChat,n);case 1:_yield$E$processReque4=_context21.v;o=_yield$E$processReque4.body;a=_yield$E$processReque4.headers;l=_yield$E$processReque4.error;if(!l){_context21.n=2;break;}return _context21.a(2,E.onInterceptorError(s,l));case 2:c=((m=e.connectSettings)==null?void 0:m.url)||e.url||"",d=((f=e.connectSettings)==null?void 0:f.method)||"POST",u=i?JSON.stringify(o):o,h={method:d,body:u,headers:a};e.connectSettings.credentials&&(h.credentials=e.connectSettings.credentials),R.executePollRequest(e,c,h,s);case 3:return _context21.a(2);}},_callee21);}));function poll(_x46,_x47,_x48){return _poll.apply(this,arguments);}return poll;}()// prettier-ignore
|
116
|
+
},{key:"verifyKey",value:function verifyKey(e,t,s,i,n,o,a,l,c){if(e==="")return o(C.INVALID_KEY);a(),fetch(t,{method:i,headers:s,body:c||null}).then(function(d){return E.processResponseByType(d);}).then(function(d){l(d,e,n,o);})["catch"](function(d){o(C.CONNECTION_FAILED),console.error(d);});}}]);}();var Ke=/*#__PURE__*/function(){function Ke(e,t,s){_classCallCheck(this,Ke);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,s.fetchHistory&&this.fetchHistory(s.fetchHistory),e.loadHistory&&this.setupLoadHistoryOnScroll(e.loadHistory),this.setupInitialHistory(e);}return _createClass(Ke,[{key:"fetchHistory",value:function(){var _fetchHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(e){var _this0=this;var t,s;return _regenerator().w(function(_context22){while(1)switch(_context22.n){case 0:t=qe.addMessage(this._messages);_context22.n=1;return e();case 1:s=_context22.v;this._messages.removeMessage(t),Ke.displayIntroMessages(this._messages.messageElementRefs),s.forEach(function(i){return _this0._messages.addAnyMessage(i,!0);}),setTimeout(function(){return J.scrollToBottom(_this0._messages.elementRef);},0);case 2:return _context22.a(2);}},_callee22,this);}));function fetchHistory(_x49){return _fetchHistory.apply(this,arguments);}return fetchHistory;}()},{key:"processLoadedHistory",value:function processLoadedHistory(e){var _this1=this;var a;var _this$_messages=this._messages,t=_this$_messages.messageElementRefs,s=_this$_messages.messageToElements,i=_this$_messages.elementRef,n=(a=t.find(function(l){return!l.outerContainer.classList.contains(pe.INTRO_CLASS);}))==null?void 0:a.outerContainer,o=i.scrollTop;e==null||e.reverse().map(function(l){var c=_this1._messages.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!0}),!0,!0);if(c){var d=b.generateMessageBody(c,t,!0);s.unshift([c,d]);}return c;}).filter(function(l){return!!l;}).reverse().forEach(function(l){return _this1._messages.sendClientUpdate(l,!0);}),n&&(i.scrollTop=o+n.offsetTop-40);}},{key:"populateMessages",value:function populateMessages(e,t){this._messages.removeMessage(e),this._isPaginationComplete=t.findIndex(function(a){return!a;})<0;var s=t.filter(function(a){return!!a;});this.processLoadedHistory(s);var _this$_messages2=this._messages,i=_this$_messages2.messageElementRefs,n=_this$_messages2.avatar,o=_this$_messages2.name;b.resetAllRoleElements(i,n,o);}},{key:"setupLoadHistoryOnScroll",value:function(){var _setupLoadHistoryOnScroll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(e){var _this10=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,s,_t11;return _regenerator().w(function(_context23){while(1)switch(_context23.p=_context23.n){case 0:if(!(!_this10._isLoading&&!_this10._isPaginationComplete&&_this10._messages.elementRef.scrollTop===0)){_context23.n=4;break;}_this10._isLoading=!0;t=qe.addMessage(_this10._messages,!1);_context23.p=1;_context23.n=2;return e(_this10._index++);case 2:s=_context23.v;_this10.populateMessages(t,s),_this10._isLoading=!1;_context23.n=4;break;case 3:_context23.p=3;_t11=_context23.v;_this10._messages.removeMessage(t),_this10._isPaginationComplete=!0,_this10._messages.addNewErrorMessage("service",Ke.FAILED_ERROR_MESSAGE,!0),console.error(_t11);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 _this11=this;e.forEach(function(t){X.processHistoryFile(t),_this11._messages.addAnyMessage(t,!0);});}},{key:"loadInitialHistory",value:function(){var _loadInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(e){var _this12=this;var t,s,i,_t12;return _regenerator().w(function(_context25){while(1)switch(_context25.p=_context25.n){case 0:this._isLoading=!0;t=qe.addMessage(this._messages);_context25.p=1;_context25.n=2;return e(this._index++);case 2:s=_context25.v;i=this._messages.elementRef.scrollTop;this.populateMessages(t,s),i===0&&setTimeout(function(){return J.scrollToBottom(_this12._messages.elementRef);},0);_context25.n=4;break;case 3:_context25.p=3;_t12=_context25.v;this._messages.removeMessage(t),this._isPaginationComplete=!0,this._messages.addNewErrorMessage("service",Ke.FAILED_ERROR_MESSAGE,!0),console.error(_t12);case 4:Ke.displayIntroMessages(this._messages.messageElementRefs),this._isLoading=!1;case 5:return _context25.a(2);}},_callee25,this,[[1,3]]);}));function loadInitialHistory(_x51){return _loadInitialHistory.apply(this,arguments);}return loadInitialHistory;}()},{key:"setupInitialHistory",value:function(){var _setupInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(e){var s,t;return _regenerator().w(function(_context26){while(1)switch(_context26.n){case 0:e.loadHistory&&this.loadInitialHistory(e.loadHistory);t=e.history||X.processHistory(e)||((s=this._messages.browserStorage)==null?void 0:s.get());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(Ke.FAILED_ERROR_MESSAGE);}},{key:"displayIntroMessages",value:function displayIntroMessages(e){for(var t=0;t<e.length;t+=1){var s=e[0];if(s.outerContainer.classList.contains(pe.INTRO_CLASS))s.outerContainer.style.display="";else break;}}}]);}();Ke.FAILED_ERROR_MESSAGE="Failed to load history";var ls=Ke;var ne=/*#__PURE__*/function(){function ne(){_classCallCheck(this,ne);}return _createClass(ne,null,[{key:"getCharacterLimitMessages",value:function getCharacterLimitMessages(e,t){var n;if(t===-1)return e;var s=0,i=e.length-1;for(i;i>=0;i-=1){var o=(n=e[i])==null?void 0:n.text;if(o!==void 0&&(s+=o.length,s>t)){e[i].text=o.substring(0,o.length-(s-t));break;}}return e.slice(Math.max(i,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
|
114
117
|
// if maxMessages above 0 we send that number
|
115
118
|
// if maxMessages 0 or below we send only what is in the request
|
116
119
|
},{key:"processMessages",value:function processMessages(e,t,s){return t!==void 0?t>0&&(e=ne.getMaxMessages(e,t)):e=[e[e.length-1]],e=JSON.parse(JSON.stringify(e)),s===void 0?e:ne.getCharacterLimitMessages(e,s);}}]);}();var H=/*#__PURE__*/function(){function H(){_classCallCheck(this,H);}return _createClass(H,null,[{key:"parseConfig",value:// prettier-ignore
|
117
|
-
function parseConfig(e,t,s,i){var o;var n={files:t};if(_typeof(i)=="object"){
|
120
|
+
function parseConfig(e,t,s,i){var o;var n={files:t};if(_typeof(i)=="object"){X.processFileConfigConnect(i);var a=i.files,l=i.connect,c=i.button;a&&(a.infoModal&&(n.files.infoModal=a.infoModal,(o=a.infoModal)!=null&&o.textMarkDown&&(n.infoModalTextMarkUp=s.render(a.infoModal.textMarkDown))),a.acceptedFormats&&(n.files.acceptedFormats=a.acceptedFormats),a.maxNumberOfFiles&&(n.files.maxNumberOfFiles=a.maxNumberOfFiles)),n.button=c,l&&(l.headers||l.method||l.url||l.credentials||e.headers||e.method||e.url||e.credentials)&&(n.connect={url:(l==null?void 0:l.url)||e.url,method:(l==null?void 0:l.method)||e.method,headers:(l==null?void 0:l.headers)||e.headers,credentials:(l==null?void 0:l.credentials)||e.credentials});}return n;}},{key:"processMixedFiles",value:function processMixedFiles(e,t,s){if(s){var i={acceptedFormats:""};e.fileTypes.mixedFiles=H.parseConfig(e.connectSettings,i,t,s);}}// needs to be set after audio to overwrite maxNumberOfFiles
|
118
121
|
// prettier-ignore
|
119
122
|
},{key:"processMicrophone",value:function processMicrophone(e,t,s,i){var _l$files,_h$maxNumberOfFiles;var a,l,c,d,u,h;var o=_objectSpread({acceptedFormats:"audio/*"},((a=e.fileTypes.audio)==null?void 0:a.files)||{});s&&(navigator.mediaDevices.getUserMedia!==void 0?(e.recordAudio=H.parseConfig(e.connectSettings,o,t,s),_typeof(s)=="object"&&s.files&&((_l$files=(l=e.recordAudio).files)!==null&&_l$files!==void 0?_l$files:l.files={},e.recordAudio.files.format=(c=s.files)==null?void 0:c.format,e.recordAudio.files.maxDurationSeconds=(d=s.files)==null?void 0:d.maxDurationSeconds,(u=e.fileTypes.audio)!=null&&u.files&&((_h$maxNumberOfFiles=(h=e.fileTypes.audio.files).maxNumberOfFiles)!==null&&_h$maxNumberOfFiles!==void 0?_h$maxNumberOfFiles:h.maxNumberOfFiles=s.files.maxNumberOfFiles))):i||(e.fileTypes.audio=H.parseConfig(e.connectSettings,o,t,s)));}// prettier-ignore
|
120
123
|
},{key:"processAudioConfig",value:function processAudioConfig(e,t,s,i){if(!s&&!i)return;var o=_objectSpread({acceptedFormats:"audio/*"},(i==null?void 0:i.files)||{});e.fileTypes.audio=H.parseConfig(e.connectSettings,o,t,s);}// prettier-ignore
|
@@ -122,92 +125,92 @@ function parseConfig(e,t,s,i){var o;var n={files:t};if(_typeof(i)=="object"){ee.
|
|
122
125
|
// prettier-ignore
|
123
126
|
},{key:"processCamera",value:function processCamera(e,t,s,i){var _l$files2;var a,l,c,d;var o=_objectSpread({acceptedFormats:"image/*"},((a=e.fileTypes.images)==null?void 0:a.files)||{});s&&(navigator.mediaDevices.getUserMedia!==void 0?(e.camera=H.parseConfig(e.connectSettings,o,t,s),_typeof(s)=="object"&&(e.camera.modalContainerStyle=s.modalContainerStyle,s.files&&((_l$files2=(l=e.camera).files)!==null&&_l$files2!==void 0?_l$files2:l.files={},e.camera.files.format=(c=s.files)==null?void 0:c.format,e.camera.files.dimensions=(d=s.files)==null?void 0:d.dimensions))):i||(e.fileTypes.images=H.parseConfig(e.connectSettings,o,t,s)));}// prettier-ignore
|
124
127
|
},{key:"processImagesConfig",value:function processImagesConfig(e,t,s,i){if(!s&&!i)return;var o=_objectSpread({acceptedFormats:"image/*"},(i==null?void 0:i.files)||{});e.fileTypes.images=H.parseConfig(e.connectSettings,o,t,s);}// default for direct service
|
125
|
-
},{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$files,_s$acceptedFormats,_i$maxNumberOfFiles;var s,i;e&&((_e$files=e.files)!==null&&_e$files!==void 0?_e$files:e.files={},(_s$acceptedFormats=(s=e.files).acceptedFormats)!==null&&_s$acceptedFormats!==void 0?_s$acceptedFormats:s.acceptedFormats=t,(_i$maxNumberOfFiles=(i=e.files).maxNumberOfFiles)!==null&&_i$maxNumberOfFiles!==void 0?_i$maxNumberOfFiles:i.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,s){H.populateDefaultFileIO(s==null?void 0:s.audio,".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),H.populateDefaultFileIO(s==null?void 0:s.images,".png,.jpg");var i=os.createNew(e.remarkable);H.processImagesConfig(t,i,e.images,s==null?void 0:s.images),H.processCamera(t,i,e.camera,e.images),H.processGifConfig(t,i,e.gifs,s==null?void 0:s.gifs),H.processAudioConfig(t,i,e.audio,s==null?void 0:s.audio),H.processMicrophone(t,i,e.microphone,e.audio),H.processMixedFiles(t,i,e.mixedFiles);}}]);}();var
|
126
|
-
},{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/
|
127
|
-
function I(e,t,s,i,n){var _this13;_classCallCheck(this,I);var o;_this13=_callSuper(this,I,[e,n]),_this13.insertKeyPlaceholderText="API Key",_this13.keyHelpUrl="",Object.assign(_this13.rawBody,(o=e.connect)==null?void 0:o.additionalBodyProps),_this13._keyVerificationDetails=t,_this13._buildHeadersFunc=s,i&&_this13.setApiKeyProperties(i),_this13.connectSettings=_this13.buildConnectSettings(_this13.key||"",e.connect);return _this13;}_inherits(I,
|
128
|
-
},{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,s=_this$_keyVerificatio.url,i=_this$_keyVerificatio.method,n=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,l=_this$_keyVerificatio.augmentUrl,c=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(l==null?void 0:l(e))||s;R.verifyKey(e,d,c,i,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,n,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}}]);}(
|
129
|
-
function
|
130
|
-
function constructPropertyAccessors(e,t){var s;Object.defineProperty(this,t||e,{get:function get(){return s;},set:function set(o){s=o,t?this[e]=o:As.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,s){if(t===s)return;var i=
|
131
|
-
function changeVisibility(e,t,s,i){i.target.id===
|
132
|
-
},{key:"create",value:function create(e){var t=document.createElement("div");t.id="visibility-icon-container";var s=
|
128
|
+
},{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$files,_s$acceptedFormats,_i$maxNumberOfFiles;var s,i;e&&((_e$files=e.files)!==null&&_e$files!==void 0?_e$files:e.files={},(_s$acceptedFormats=(s=e.files).acceptedFormats)!==null&&_s$acceptedFormats!==void 0?_s$acceptedFormats:s.acceptedFormats=t,(_i$maxNumberOfFiles=(i=e.files).maxNumberOfFiles)!==null&&_i$maxNumberOfFiles!==void 0?_i$maxNumberOfFiles:i.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,s){H.populateDefaultFileIO(s==null?void 0:s.audio,".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),H.populateDefaultFileIO(s==null?void 0:s.images,".png,.jpg");var i=os.createNew(e.remarkable);H.processImagesConfig(t,i,e.images,s==null?void 0:s.images),H.processCamera(t,i,e.camera,e.images),H.processGifConfig(t,i,e.gifs,s==null?void 0:s.gifs),H.processAudioConfig(t,i,e.audio,s==null?void 0:s.audio),H.processMicrophone(t,i,e.microphone,e.audio),H.processMixedFiles(t,i,e.mixedFiles);}}]);}();var ht=/*#__PURE__*/function(){function ht(e,t,s){var _a$url;_classCallCheck(this,ht);var i,n,o,a,l;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=ht.canSendMessage,this.connectSettings={},this.fileTypes={},this.completionsHandlers={},this.streamHandlers={},this.deepChat=e,this.demo=s,Object.assign(this.rawBody,(i=e.connect)==null?void 0:i.additionalBodyProps),this.totalMessagesMaxCharLength=(n=e==null?void 0:e.requestBodyLimits)==null?void 0:n.totalMessagesMaxCharLength,this.maxMessages=(o=e==null?void 0:e.requestBodyLimits)==null?void 0:o.maxMessages,H.set(e,this,t),e.connect&&(this.connectSettings=e.connect),this.demo&&((_a$url=(a=this.connectSettings).url)!==null&&_a$url!==void 0?_a$url:a.url=xe.URL),this.connectSettings.websocket&&W.setup(this),this.stream=((l=this.deepChat.connect)==null?void 0:l.stream)||X.checkForStream(this.deepChat),e.loadHistory&&ls.addErrorPrefix(this);}return _createClass(ht,[{key:"verifyKey",value:function verifyKey(e,t){}},{key:"getServiceIOByType",value:function getServiceIOByType(e){if(e.type.startsWith("audio")&&this.fileTypes.audio)return this.fileTypes.audio;if(e.type.startsWith("image")){if(this.fileTypes.gifs&&e.type.endsWith("/gif"))return this.fileTypes.gifs;if(this.fileTypes.images)return this.fileTypes.images;if(this.camera)return this.camera;}return this.fileTypes.mixedFiles;}},{key:"request",value:function(){var _request4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(e,t){var s,_args27=arguments;return _regenerator().w(function(_context27){while(1)switch(_context27.n){case 0:s=_args27.length>2&&_args27[2]!==undefined?_args27[2]:!0;return _context27.a(2,this.stream&&!_.isSimulation(this.stream)?_.request(this,e,t,s):R.request(this,e,t,s));}},_callee27,this);}));function request(_x53,_x54){return _request4.apply(this,arguments);}return request;}()},{key:"callAPIWithText",value:function(){var _callAPIWithText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(e,t){var _o$headers,_a$ContentType;var n,o,a,l,s,i;return _regenerator().w(function(_context28){while(1)switch(_context28.n){case 0:s=_objectSpread({messages:t},this.rawBody);i=!1;(n=this.connectSettings.headers)!=null&&n["Content-Type"]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$ContentType=(a=this.connectSettings.headers)["Content-Type"])!==null&&_a$ContentType!==void 0?_a$ContentType:a["Content-Type"]="application/json",i=!0);_context28.n=1;return this.request(s,e);case 1:i&&((l=this.connectSettings.headers)==null||delete l["Content-Type"]);case 2:return _context28.a(2);}},_callee28,this);}));function callAPIWithText(_x55,_x56){return _callAPIWithText.apply(this,arguments);}return callAPIWithText;}()},{key:"callApiWithFiles",value:function(){var _callApiWithFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(e,t,s){var i,n,o;return _regenerator().w(function(_context29){while(1)switch(_context29.n){case 0:i=ht.createCustomFormDataBody(this.rawBody,t,s),n=this.connectSettings,o=this.getServiceIOByType(s[0]);this.connectSettings=(o==null?void 0:o.connect)||this.connectSettings;_context29.n=1;return this.request(i,e,!1);case 1:this.connectSettings=n;case 2:return _context29.a(2);}},_callee29,this);}));function callApiWithFiles(_x57,_x58,_x59){return _callApiWithFiles.apply(this,arguments);}return callApiWithFiles;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(e,t,s){return _regenerator().w(function(_context30){while(1)switch(_context30.n){case 0:s?this.callApiWithFiles(e,t,s):this.callAPIWithText(e,t);case 1:return _context30.a(2);}},_callee30,this);}));function callServiceAPI(_x60,_x61,_x62){return _callServiceAPI.apply(this,arguments);}return callServiceAPI;}()// prettier-ignore
|
129
|
+
},{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(e,t){var i,s,n;return _regenerator().w(function(_context31){while(1)switch(_context31.n){case 0:if(this.connectSettings){_context31.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=ne.processMessages(t.messageToElements.map(function(_ref15){var _ref16=_slicedToArray(_ref15,1),n=_ref16[0];return n;}),this.maxMessages,this.totalMessagesMaxCharLength);if(this.connectSettings.websocket&&(!this.connectSettings.handler||this.connectSettings.url!==xe.URL)){n=_objectSpread({messages:s},this.rawBody);e.files&&(i=this.getServiceIOByType(e.files[0]))!=null&&i.connect?this.callApiWithFiles(t,s,e.files):W.sendWebsocket(this,n,t,!1);}else this.callServiceAPI(t,s,e.files);case 2:return _context31.a(2);}},_callee31,this);}));function callAPI(_x63,_x64){return _callAPI.apply(this,arguments);}return callAPI;}()},{key:"extractResultData",value:function(){var _extractResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(e){return _regenerator().w(function(_context32){while(1)switch(_context32.n){case 0:if(!e.result){_context32.n=1;break;}return _context32.a(2,X.handleResponseProperty(e));case 1:if(!E.validateResponseFormat(e,!!this.stream)){_context32.n=2;break;}return _context32.a(2,e);case 2:return _context32.a(2);}},_callee32,this);}));function extractResultData(_x65){return _extractResultData.apply(this,arguments);}return extractResultData;}()},{key:"isDirectConnection",value:function isDirectConnection(){return!1;}},{key:"isWebModel",value:function isWebModel(){return!1;}},{key:"isCustomView",value:function isCustomView(){return!1;}}],[{key:"canSendMessage",value:function canSendMessage(e,t,s){return s?!0:!!(e&&e.trim()!=="")||!!(t&&t.length>0);}},{key:"createCustomFormDataBody",value:function createCustomFormDataBody(e,t,s){var i=new FormData();s.forEach(function(a){return i.append("files",a);}),Object.keys(e).forEach(function(a){return i.append(a,String(e[a]));});var n=0;t.slice(0,t.length-1).forEach(function(a){i.append("message".concat(n+=1),JSON.stringify(a));});var o=t[t.length-1];return o.text&&(delete o.files,i.append("message".concat(n+=1),JSON.stringify(o))),i;}}]);}();var I=/*#__PURE__*/function(_ht){// prettier-ignore
|
130
|
+
function I(e,t,s,i,n){var _this13;_classCallCheck(this,I);var o;_this13=_callSuper(this,I,[e,n]),_this13.insertKeyPlaceholderText="API Key",_this13.keyHelpUrl="",Object.assign(_this13.rawBody,(o=e.connect)==null?void 0:o.additionalBodyProps),_this13._keyVerificationDetails=t,_this13._buildHeadersFunc=s,i&&_this13.setApiKeyProperties(i),_this13.connectSettings=_this13.buildConnectSettings(_this13.key||"",e.connect);return _this13;}_inherits(I,_ht);return _createClass(I,[{key:"setApiKeyProperties",value:function setApiKeyProperties(e){this.key=e.key,e.validateKeyProperty&&(this.validateKeyProperty=e.validateKeyProperty);}},{key:"buildConnectSettings",value:function buildConnectSettings(e,t){var _s$headers;var s=t!==null&&t!==void 0?t:{};return(_s$headers=s.headers)!==null&&_s$headers!==void 0?_s$headers:s.headers={},Object.assign(s.headers,this._buildHeadersFunc(e)),s;}},{key:"keyAuthenticated",value:function keyAuthenticated(e,t){this.connectSettings=this.buildConnectSettings(t,this.connectSettings),this.key=t,e();}// prettier-ignore
|
131
|
+
},{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,s=_this$_keyVerificatio.url,i=_this$_keyVerificatio.method,n=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,l=_this$_keyVerificatio.augmentUrl,c=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(l==null?void 0:l(e))||s;R.verifyKey(e,d,c,i,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,n,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}}]);}(ht);var As=/*#__PURE__*/function(){function As(){_classCallCheck(this,As);}return _createClass(As,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?As.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,As.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var De=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
|
132
|
+
function De(){var _this14;_classCallCheck(this,De);_this14=_callSuper(this,De),_this14._waitingToRender_=!1,_this14._propUpdated_=!1,Object.keys(De._attributeToProperty_).forEach(function(e){var t=De._attributeToProperty_[e];_this14.constructPropertyAccessors(t),_this14.hasOwnProperty(e)||_this14.constructPropertyAccessors(t,e);});return _this14;}_inherits(De,_HTMLElement);return _createClass(De,[{key:"constructPropertyAccessors",value:// need to be called here as accessors need to be set for the class instance
|
133
|
+
function constructPropertyAccessors(e,t){var s;Object.defineProperty(this,t||e,{get:function get(){return s;},set:function set(o){s=o,t?this[e]=o:As.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,s){if(t===s)return;var i=De._attributes_[e](s),n=De._attributeToProperty_[e];this[n]=i;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(De._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));De._attributes_={},De._attributeToProperty_={};var vi=De;var ia="<?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",na="<?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 Ve=/*#__PURE__*/function(){function Ve(){_classCallCheck(this,Ve);}return _createClass(Ve,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var We=/*#__PURE__*/function(){function We(){_classCallCheck(this,We);}return _createClass(We,null,[{key:"changeVisibility",value:// prettier-ignore
|
134
|
+
function changeVisibility(e,t,s,i){i.target.id===We.VISIBLE_ICON_ID?(t.style.display="none",s.style.display="block",e.type="password"):(t.style.display="block",s.style.display="none",e.type="text");}},{key:"createIconElement",value:function createIconElement(e,t){var s=Ve.createSVGElement(e);return s.id=t,s.classList.add("visibility-icon"),s;}// prettier-ignore
|
135
|
+
},{key:"create",value:function create(e){var t=document.createElement("div");t.id="visibility-icon-container";var s=We.createIconElement(na,We.VISIBLE_ICON_ID);s.style.display="none",t.appendChild(s);var i=We.createIconElement(ia,"not-visible-icon");return t.appendChild(i),t.onclick=We.changeVisibility.bind(this,e,s,i),t;}}]);}();We.VISIBLE_ICON_ID="visible-icon";var Ei=We;var Y=/*#__PURE__*/function(){function Y(){_classCallCheck(this,Y);}return _createClass(Y,null,[{key:"createCautionText",value:function createCautionText(){var e=document.createElement("a");return e.classList.add("insert-key-input-help-text"),e.innerText="Please exercise CAUTION when inserting your API key outside of deepchat.dev or localhost!!",e;}},{key:"createHelpLink",value:function createHelpLink(e){var t=document.createElement("a");return t.classList.add("insert-key-input-help-text"),t.href=e,t.innerText="Find more info here",t.target="_blank",t;}},{key:"createFailText",value:function createFailText(){var e=document.createElement("div");return e.id="insert-key-input-invalid-text",e.style.display="none",e;}},{key:"createHelpTextContainer",value:function createHelpTextContainer(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var s=document.createElement("div");s.id="insert-key-help-text-container";var i=document.createElement("div");i.id="insert-key-help-text-contents";var n=Y.createFailText();if(i.appendChild(n),e){var o=Y.createHelpLink(e);i.appendChild(o);}if(t===!0){var _o4=Y.createCautionText();i.appendChild(_o4);}return s.appendChild(i),{helpTextContainerElement:s,failTextElement:n};}},{key:"onFail",value:function onFail(e,t,s,i){e.classList.replace("insert-key-input-valid","insert-key-input-invalid"),s.innerText=i,s.style.display="block",t.innerText="Start",e.classList.remove("loading");}},{key:"onLoad",value:function onLoad(e,t){e.classList.add("loading"),t.innerHTML='<div id="loading-key"></div>';}// prettier-ignore
|
133
136
|
},{key:"verifyKey",value:function verifyKey(e,t,s){var i=e.value.trim();s.verifyKey(i,t);}// prettier-ignore
|
134
137
|
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,s,i,n){var o={onSuccess:i,onFail:Y.onFail.bind(this,e,t,s),onLoad:Y.onLoad.bind(this,e,t)},a=Y.verifyKey.bind(this,e,o,n);t.onclick=a,e.onkeydown=function(l){!e.classList.contains("loading")&&l.key===V.ENTER&&a();};}},{key:"createStartButton",value:function createStartButton(){var e=document.createElement("div");return e.id="start-button",e.innerText="Start",e;}},{key:"onInputFocus",value:function onInputFocus(e){e.target.classList.replace("insert-key-input-invalid","insert-key-input-valid");}},{key:"createInput",value:function createInput(e){var t=document.createElement("div");t.id="insert-key-input-container";var s=document.createElement("input");return s.id="insert-key-input",s.placeholder=e||"API Key",s.type="password",s.classList.add("insert-key-input-valid"),s.onfocus=Y.onInputFocus,t.appendChild(s),t;}// prettier-ignore
|
135
138
|
},{key:"createContents",value:function createContents(e,t){var d;var s=document.createElement("div");s.id="insert-key-contents";var i=Y.createInput(t.insertKeyPlaceholderText),n=i.children[0],o=Ei.create(n);i.appendChild(o),s.appendChild(i);var a=Y.createStartButton(),_Y$createHelpTextCont=Y.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),l=_Y$createHelpTextCont.helpTextContainerElement,c=_Y$createHelpTextCont.failTextElement;return s.appendChild(a),s.appendChild(l),Y.addVerificationEvents(n,a,c,e,t),s;}},{key:"createElements",value:function createElements(e,t){var s=document.createElement("div");s.id="insert-key-view";var i=Y.createContents(e,t);return s.appendChild(i),s;}},{key:"render",value:function render(e,t,s){var i=Y.createElements(t,s);e.replaceChildren(i);}}]);}();var oe=/*#__PURE__*/function(){function oe(){_classCallCheck(this,oe);}return _createClass(oe,null,[{key:"enableButtons",value:function enableButtons(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;window.webLLM?(e&&(e.disabled=!1),t&&(t.disabled=!1)):s<cs.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return oe.enableButtons(e,t,s+1);},250);}// prettier-ignore
|
136
139
|
},{key:"setUpInitial",value:function setUpInitial(e,t,s,i){var n=(t==null?void 0:t.downloadClass)||oe.DOWNLOAD_BUTTON_CLASS,o=(t==null?void 0:t.uploadClass)||oe.UPLOAD_BUTTON_CLASS,a=(t==null?void 0:t.fileInputClass)||oe.FILE_INPUT_CLASS;return setTimeout(function(){var l=s==null?void 0:s.getElementsByClassName(n)[0],c=s==null?void 0:s.getElementsByClassName(a)[0],d=s==null?void 0:s.getElementsByClassName(o)[0];l&&(l.onclick=function(){return e();}),c&&(c.onchange=function(){c.files&&c.files.length>0&&e(c.files);}),d&&(d.onclick=function(){return c.click();}),(l||d)&&oe.enableButtons(l,d);}),(t==null?void 0:t.initialHtml)||"<div>\n Download or upload a web model that will run entirely on your browser: <br/> \n <button disabled class=\"".concat(n," deep-chat-button deep-chat-web-model-button\">Download</button>\n ").concat(i?"":"<input type=\"file\" class=\"".concat(a,"\" hidden multiple />\n <button disabled class=\"").concat(o," deep-chat-button deep-chat-web-model-button\">Upload</button>"),"\n </div>");}},{key:"exportFile",value:function exportFile(e){var t=document.createElement("a"),s=4;var _loop2=function _loop2(i){setTimeout(function(){var n=i*s;for(var o=n;o<Math.min(n+s,e.length);o+=1){var a=URL.createObjectURL(e[o]);t.href=a,t.download=e[o].name,document.body.appendChild(t),t.click(),URL.revokeObjectURL(a);}},500*i);};for(var i=0;i<e.length/s;i+=1){_loop2(i);}}// prettier-ignore
|
137
|
-
},{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,s,i){var n=(t==null?void 0:t.exportFilesClass)||oe.EXPORT_BUTTON_CLASS;return setTimeout(function(){var o=s==null?void 0:s.getElementsByClassName(n)[0];o&&(o.onclick=function(){return oe.exportFile(e);});}),(t==null?void 0:t.afterLoadHtml)||"<div>\n Model loaded successfully and has been cached for future requests.\n ".concat(i?"":"<br/> <button style=\"margin-top: 5px\" class=\"".concat(n," deep-chat-button\">Export</button>"),"\n </div>");}}]);}();oe.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",oe.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",oe.FILE_INPUT_CLASS="deep-chat-file-input",oe.EXPORT_BUTTON_CLASS="deep-chat-export-button";var Cs=oe;var
|
140
|
+
},{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,s,i){var n=(t==null?void 0:t.exportFilesClass)||oe.EXPORT_BUTTON_CLASS;return setTimeout(function(){var o=s==null?void 0:s.getElementsByClassName(n)[0];o&&(o.onclick=function(){return oe.exportFile(e);});}),(t==null?void 0:t.afterLoadHtml)||"<div>\n Model loaded successfully and has been cached for future requests.\n ".concat(i?"":"<br/> <button style=\"margin-top: 5px\" class=\"".concat(n," deep-chat-button\">Export</button>"),"\n </div>");}}]);}();oe.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",oe.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",oe.FILE_INPUT_CLASS="deep-chat-file-input",oe.EXPORT_BUTTON_CLASS="deep-chat-export-button";var Cs=oe;var un={model_list:[// Llama-2
|
138
141
|
{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f32_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f32_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:9109.03,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:6749.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:4618.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-13b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-13b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-13b-chat-hf/Llama-2-13b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:11814.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-70b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-70b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-70b-chat-hf/Llama-2-70b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:43729.05,low_resource_required:!1,required_features:["shader-f16"]},// RedPajama
|
139
142
|
{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
|
140
143
|
{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
|
141
|
-
{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},M=/*#__PURE__*/function(
|
142
|
-
_inherits(M,
|
143
|
-
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Cs.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:b.AI_ROLE,html:t,sendUpdate:!1};}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/
|
144
|
-
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/
|
144
|
+
{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},M=/*#__PURE__*/function(_ht2){function M(e){var _this15;_classCallCheck(this,M);var t,s;_this15=_callSuper(this,M,[e]),_this15._isModelLoaded=!1,_this15._isModelLoading=!1,_this15._loadOnFirstMessage=!1,_this15._webModel={},_this15.permittedErrorPrefixes=[M.MULTIPLE_MODELS_ERROR,M.WEB_LLM_NOT_FOUND_ERROR,M.GENERIC_ERROR],_this15._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this15._webModel=e.webModel),(t=_this15._webModel.load)!=null&&t.clearCache&&M.clearAllCache(),_this15.findModelInWindow(e),_this15.canSendMessage=_this15.canSubmit.bind(_assertThisInitialized(_this15)),_this15._chatEl=(s=e.shadowRoot)==null?void 0:s.children[0],e.history&&M.setUpHistory(_this15._conversationHistory,e.history);return _this15;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
|
145
|
+
_inherits(M,_ht2);return _createClass(M,[{key:"setUpMessages",value:function setUpMessages(e){var _this16=this;this._messages=e,this._removeIntro=function(){e.removeIntroductoryMessage(),_this16._removeIntro=void 0;};}},{key:"findModelInWindow",value:function findModelInWindow(e){var _this17=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var s;window.webLLM?this.configureInit(this.shouldAddIntroMessage(e.introMessage)):t>M.MODULE_SEARCH_LIMIT_S?((s=this._messages)==null||s.addNewErrorMessage("service",M.WEB_LLM_NOT_FOUND_ERROR),console.error("The deep-chat-web-llm module has not been attached to the window object. Please see the following guide:"),console.error("https://deepchat.dev/examples/externalModules")):setTimeout(function(){return _this17.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 _this18=this;var t;((t=this._webModel.introMessage)==null?void 0:t.autoScroll)!==!1&&setTimeout(function(){var s,i;(s=_this18._messages)!=null&&s.elementRef&&J.scrollToTop((i=_this18._messages)==null?void 0:i.elementRef);},e);}// prettier-ignore
|
146
|
+
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Cs.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:b.AI_ROLE,html:t,sendUpdate:!1};}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(e){var t;return _regenerator().w(function(_context33){while(1)switch(_context33.n){case 0:t=this._webModel.load;if(!t){_context33.n=2;break;}if(!t.onInit){_context33.n=1;break;}this.init();return _context33.a(2);case 1:if(!t.onMessage){_context33.n=2;break;}this._loadOnFirstMessage=!0;return _context33.a(2);case 2:e||this.init();case 3:return _context33.a(2);}},_callee33,this);}));function configureInit(_x66){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(e){var s,t,_t13;return _regenerator().w(function(_context34){while(1)switch(_context34.n){case 0:(s=this._messages)==null||s.removeError();t=this.attemptToCreateChat();_t13=t;if(!_t13){_context34.n=1;break;}_context34.n=1;return this.loadModel(t,e);case 1:return _context34.a(2);}},_callee34,this);}));function init(_x67){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var t;if(M.chat){(t=this._messages)==null||t.addNewErrorMessage("service",M.MULTIPLE_MODELS_ERROR),console.error(M.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return un.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var s;var e=M.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=JSON.parse(JSON.stringify(un));if(this._webModel.urls){var i=t.model_list.find(function(n){return n.local_id=e;});i&&(this._webModel.urls.model&&(i.model_url=this._webModel.urls.model),this._webModel.urls.wasm&&(i.model_lib_url=this._webModel.urls.wasm));}return(s=this._webModel.load)!=null&&s.skipCache&&(t.use_cache=!1),{model:e,appConfig:t};}// prettier-ignore
|
147
|
+
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(e,t){var _this19=this;var o,a,l,c,d,u,h,s,i,n,_this$getConfig,p,m,f,_p,_t14;return _regenerator().w(function(_context35){while(1)switch(_context35.p=_context35.n){case 0:this.scrollToTop(),M.chat=e,this._isModelLoading=!0;s=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;i=function i(p){var m;(m=_this19._messages)==null||m.addNewMessage({html:"<div>".concat(p.text,"</div>"),overwrite:!0,sendUpdate:!1}),s&&(setTimeout(function(){var f;return J.scrollToBottom((f=_this19._messages)==null?void 0:f.elementRef);}),s=!1);};M.chat.setInitProgressCallback(i);_context35.p=1;_this$getConfig=this.getConfig(),p=_this$getConfig.model,m=_this$getConfig.appConfig,f={};this._webModel.instruction&&(f.conv_config={system:this._webModel.instruction});this._conversationHistory.length>0&&(f.conversation_history=this._conversationHistory);_context35.n=2;return M.chat.reload(p,f,m,t);case 2:n=_context35.v;_context35.n=4;break;case 3:_context35.p=3;_t14=_context35.v;return _context35.a(2,this.unloadChat(_t14));case 4:if((l=(a=this.deepChat)._validationHandler)==null||l.call(a),(c=this._webModel.introMessage)!=null&&c.removeAfterLoad)this._webModel.introMessage.displayed===!1?(u=this._messages)==null||u.removeLastMessage():(h=this._removeIntro)==null||h.call(this);else{_p=Cs.setUpAfterLoad(n,this._webModel.introMessage,this._chatEl,!!this._webModel.worker);(d=this._messages)==null||d.addNewMessage({html:_p,overwrite:!0,sendUpdate:!1});}this._isModelLoaded=!0,this._isModelLoading=!1;case 5:return _context35.a(2);}},_callee35,this,[[1,3]]);}));function loadModel(_x68,_x69){return _loadModel.apply(this,arguments);}return loadModel;}()},{key:"unloadChat",value:function(){var _unloadChat=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(e){var t,_t15;return _regenerator().w(function(_context36){while(1)switch(_context36.n){case 0:(t=this._messages)==null||t.addNewErrorMessage("service",M.GENERIC_ERROR);console.error(e);this._isModelLoaded=!1;this._isModelLoading=!1;_t15=M.chat;if(!_t15){_context36.n=2;break;}_context36.n=1;return M.chat.unload();case 1:M.chat=void 0;case 2:return _context36.a(2);}},_callee36,this);}));function unloadChat(_x70){return _unloadChat.apply(this,arguments);}return unloadChat;}()},{key:"immediateResp",value:function(){var _immediateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e,t,s){var i,n,_t16;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:_context37.n=1;return s.generate(t,void 0,0);case 1:_t16=_context37.v;i={text:_t16};_context37.n=2;return M.processResponse(this.deepChat,e,i);case 2:n=_context37.v;n&&n.forEach(function(o){return e.addNewMessage(o);}),this.completionsHandlers.onFinish();case 3:return _context37.a(2);}},_callee37,this);}));function immediateResp(_x71,_x72,_x73){return _immediateResp.apply(this,arguments);}return immediateResp;}()},{key:"streamResp",value:function(){var _streamResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(e,t,s){var _this20=this;var i;return _regenerator().w(function(_context39){while(1)switch(_context39.n){case 0:this.streamHandlers.abortStream.abort=function(){s.interruptGenerate();},this.streamHandlers.onOpen();i=new Me(e);_context39.n=1;return s.generate(t,/*#__PURE__*/function(){var _ref17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(n,o){var a;return _regenerator().w(function(_context38){while(1)switch(_context38.n){case 0:_context38.n=1;return M.processResponse(_this20.deepChat,e,{text:o});case 1:a=_context38.v;a&&i.upsertStreamedMessage({text:a[0].text,overwrite:!0});case 2:return _context38.a(2);}},_callee38);}));return function(_x77,_x78){return _ref17.apply(this,arguments);};}());case 1:i.finaliseStreamedMessage();this.streamHandlers.onClose();case 2:return _context39.a(2);}},_callee39,this);}));function streamResp(_x74,_x75,_x76){return _streamResp.apply(this,arguments);}return streamResp;}()},{key:"generateRespByType",value:function(){var _generateRespByType=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(e,t,s,i){var n,_t17;return _regenerator().w(function(_context40){while(1)switch(_context40.p=_context40.n){case 0:_context40.p=0;if(!s){_context40.n=2;break;}_context40.n=1;return this.streamResp(e,t,i);case 1:_context40.n=3;break;case 2:_context40.n=3;return this.immediateResp(e,t,i);case 3:_context40.n=5;break;case 4:_context40.p=4;_t17=_context40.v;(n=this._messages)==null||n.addNewErrorMessage("service"),console.log(_t17);case 5:return _context40.a(2);}},_callee40,this,[[0,4]]);}));function generateRespByType(_x79,_x80,_x81,_x82){return _generateRespByType.apply(this,arguments);}return generateRespByType;}()},{key:"generateResp",value:function(){var _generateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(e,t,s){var i,_yield$E$processReque5,n,o,a,l,c;return _regenerator().w(function(_context41){while(1)switch(_context41.n){case 0:i=t[t.length-1].text;_context41.n=1;return E.processRequestInterceptor(this.deepChat,{body:{text:i}});case 1:_yield$E$processReque5=_context41.v;n=_yield$E$processReque5.body;o=_yield$E$processReque5.error;a=!!this.stream;try{if(o)E.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!n||!n.text){l=C.INVALID_MODEL_REQUEST({body:n},!1);console.error(l);c=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;E.onInterceptorError(e,l,c);}else this.generateRespByType(e,n.text,!!this.stream,s);}catch(l){this.unloadChat(l);}case 2:return _context41.a(2);}},_callee41,this);}));function generateResp(_x83,_x84,_x85){return _generateResp.apply(this,arguments);}return generateResp;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(e,t){var s,i;return _regenerator().w(function(_context42){while(1)switch(_context42.n){case 0:if(this._isModelLoaded){_context42.n=3;break;}if(!this._loadOnFirstMessage){_context42.n=2;break;}_context42.n=1;return this.init();case 1:_context42.n=3;break;case 2:return _context42.a(2);case 3:!M.chat||this._isModelLoading||((s=this._webModel.introMessage)!=null&&s.removeAfterMessage&&((i=this._removeIntro)==null||i.call(this)),e.addLoadingMessage(),this.generateResp(e,t,M.chat));case 4:return _context42.a(2);}},_callee42,this);}));function callServiceAPI(_x86,_x87){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(s,i){if(s.role===b.USER_ROLE&&s.text){var n=t[i+1];n!=null&&n.text&&n.role!==b.USER_ROLE&&e.push([s.text,n.text]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43(e,t,s){var a,l,i,n,o,d,_t18;return _regenerator().w(function(_context43){while(1)switch(_context43.n){case 0:_context43.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,s);case 1:_t18=_context43.v;if(_t18){_context43.n=2;break;}_t18=s;case 2:i=_t18;if(!((l=e.connect)!=null&&l.stream&&Array.isArray(i)&&i.length>1)){_context43.n=3;break;}console.error(C.INVALID_STREAM_ARRAY_RESPONSE);return _context43.a(2);case 3:n=Array.isArray(i)?i:[i],o=n.find(function(c){return typeof c.error=="string";});if(!o){_context43.n=4;break;}E.displayError(t,new Error(o.error));return _context43.a(2);case 4:if(!n.find(function(d){return!d||!d.text;})){_context43.n=5;break;}d=C.INVALID_MODEL_RESPONSE(s,!!e.responseInterceptor,i);E.displayError(t,new Error(d));return _context43.a(2);case 5:return _context43.a(2,n);}},_callee43);}));function processResponse(_x88,_x89,_x90){return _processResponse.apply(this,arguments);}return processResponse;}()},{key:"clearAllCache",value:function clearAllCache(){M.clearCache("webllm/model"),M.clearCache("webllm/wasm");}},{key:"clearCache",value:function clearCache(e){caches.open(e).then(function(t){t.keys().then(function(s){s.forEach(function(i){t["delete"](i);});});});}}]);}(ht);M.GENERIC_ERROR="Error, please check the [troubleshooting](https://deepchat.dev/docs/webModel#troubleshooting) section of documentation for help.",M.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",M.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",M.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",M.MODULE_SEARCH_LIMIT_S=5;var cs=M;var Ts=/*#__PURE__*/function(){function Ts(){_classCallCheck(this,Ts);}return _createClass(Ts,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"// bigcode/santacoder expects this so adding just-in-case
|
145
148
|
};}// prettier-ignore
|
146
149
|
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;Array.isArray(n.error)&&n.error[0]==="Error in `parameters`: field required"?s(t):i(C.INVALID_KEY);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api-inference.huggingface.co/models/gpt2",method:"POST",handleVerificationResult:Ts.handleVerificationResult};}}]);}();var es=/*#__PURE__*/function(_I){// prettier-ignore
|
147
150
|
function es(e,t,s,i,n,o){var _this21;_classCallCheck(this,es);_this21=_callSuper(this,es,[e,Ts.buildKeyVerificationDetails(),Ts.buildHeaders,n,o]),_this21.insertKeyPlaceholderText="Hugging Face Token",_this21.keyHelpUrl="https://huggingface.co/settings/tokens",_this21.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Hugging Face</b></div>\n <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>",_this21.permittedErrorPrefixes=["Authorization header"],_this21.url="".concat(es.URL_PREFIX).concat(s),_this21.textInputPlaceholderText=t,_typeof(i)=="object"&&(i.model&&(_this21.url="".concat(es.URL_PREFIX).concat(i.model)),i.options&&(_this21.rawBody.options=i.options),i.parameters&&(_this21.rawBody.parameters=i.parameters));return _this21;}// prettier-ignore
|
148
|
-
_inherits(es,_I);return _createClass(es,[{key:"preprocessBody",value:function preprocessBody(e,t,s){var _i$options;var i=JSON.parse(JSON.stringify(e)),n=t[t.length-1].text;if(n)return(_i$options=i.options)!==null&&_i$options!==void 0?_i$options:i.options={},i.options.wait_for_model=!0,_objectSpread({inputs:n},i);}},{key:"callServiceAPI",value:function(){var _callServiceAPI3=_asyncToGenerator(/*#__PURE__*/
|
149
|
-
function fs(e,t,s,i,n,o){var _this22;_classCallCheck(this,fs);_this22=_callSuper(this,fs,[e,t,s,i,n,o]),_this22.isTextInputDisabled=!0,_this22.canSendMessage=fs.canSendFile;return _this22;}_inherits(fs,
|
150
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/
|
151
|
-
function
|
151
|
+
_inherits(es,_I);return _createClass(es,[{key:"preprocessBody",value:function preprocessBody(e,t,s){var _i$options;var i=JSON.parse(JSON.stringify(e)),n=t[t.length-1].text;if(n)return(_i$options=i.options)!==null&&_i$options!==void 0?_i$options:i.options={},i.options.wait_for_model=!0,_objectSpread({inputs:n},i);}},{key:"callServiceAPI",value:function(){var _callServiceAPI3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44(e,t,s){var i;return _regenerator().w(function(_context44){while(1)switch(_context44.n){case 0:if(this.connectSettings){_context44.n=1;break;}throw new Error("Request settings have not been set up");case 1:i=this.preprocessBody(this.rawBody,t,s);R.request(this,i,e);case 2:return _context44.a(2);}},_callee44,this);}));function callServiceAPI(_x91,_x92,_x93){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(I);es.URL_PREFIX="https://api-inference.huggingface.co/models/";var Ge=es;var fs=/*#__PURE__*/function(_Ge){// prettier-ignore
|
152
|
+
function fs(e,t,s,i,n,o){var _this22;_classCallCheck(this,fs);_this22=_callSuper(this,fs,[e,t,s,i,n,o]),_this22.isTextInputDisabled=!0,_this22.canSendMessage=fs.canSendFile;return _this22;}_inherits(fs,_Ge);return _createClass(fs,[{key:"preprocessBody",value:function preprocessBody(e,t,s){return s[0];}// prettier-ignore
|
153
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45(e,t,s){return _regenerator().w(function(_context45){while(1)switch(_context45.n){case 0:if(this.connectSettings){_context45.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context45.n=2;break;}throw new Error("No file was added");case 2:R.poll(this,s[0],e,!1);case 3:return _context45.a(2);}},_callee45,this);}));function callServiceAPI(_x94,_x95,_x96){return _callServiceAPI4.apply(this,arguments);}return callServiceAPI;}()}],[{key:"canSendFile",value:function canSendFile(e,t){return!!(t!=null&&t[0]);}}]);}(Ge);var ra=/*#__PURE__*/function(_fs){// prettier-ignore
|
154
|
+
function ra(e){_classCallCheck(this,ra);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.audioClassification,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ra,[e,"Attach an audio file","ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,s,{audio:{}}]);}_inherits(ra,_fs);return _createClass(ra,[{key:"extractPollResultData",value:function(){var _extractPollResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46(e){var t;return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:if(!e.estimated_time){_context46.n=1;break;}return _context46.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context46.n=2;break;}throw e.error;case 2:return _context46.a(2,{text:((t=e[0])==null?void 0:t.label)||""});}},_callee46);}));function extractPollResultData(_x97){return _extractPollResultData.apply(this,arguments);}return extractPollResultData;}()}]);}(fs);var oa=/*#__PURE__*/function(_fs2){function oa(e){_classCallCheck(this,oa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.imageClassification,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,oa,[e,"Attach an image file","google/vit-base-patch16-224",t,s,{images:{}}]);}_inherits(oa,_fs2);return _createClass(oa,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e){var t;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:if(!e.estimated_time){_context47.n=1;break;}return _context47.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context47.n=2;break;}throw e.error;case 2:return _context47.a(2,{text:((t=e[0])==null?void 0:t.label)||""});}},_callee47);}));function extractPollResultData(_x98){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(fs);var At="data:image/png;base64,";var Le=/*#__PURE__*/function(){function Le(){_classCallCheck(this,Le);}return _createClass(Le,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}// prettier-ignore
|
152
155
|
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.message?i(C.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.stability.ai/v1/engines/list",method:"GET",handleVerificationResult:Le.handleVerificationResult};}}]);}();var ii=/*#__PURE__*/function(_I2){// prettier-ignore
|
153
|
-
function ii(e,t,s,i,n){var _this23;_classCallCheck(this,ii);_this23=_callSuper(this,ii,[e,t,s,i,n]),_this23.insertKeyPlaceholderText="Stability AI API Key",_this23.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this23.permittedErrorPrefixes=["Incorrect","invalid_"];return _this23;}_inherits(ii,_I2);return _createClass(ii);}(I);var Rs=/*#__PURE__*/function(_ii){function Rs(e){var _this24;_classCallCheck(this,Rs);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this24=_callSuper(this,Rs,[e,Le.buildKeyVerificationDetails(),Le.buildHeaders,s,i]),_this24.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",_this24.textInputPlaceholderText="Describe image changes",_this24.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI</b></div>\n <div style=\"width: 100%; text-align: center; margin-left: -10px; margin-top: 5px\"><b>Image to Image Upscale</b></div>\n <p>Upload an image to generate a new one with higher resolution.</p>\n <p>Click <a href=\"https://platform.stability.ai/\">here</a> for more info.</p>";var n=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageUpscale;_typeof(n)=="object"&&(n.engine_id&&(_this24.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/image-to-image/upscale")),Rs.cleanConfig(n),Object.assign(_this24.rawBody,n)),_this24.canSendMessage=Rs.canSendFileMessage;return _this24;}_inherits(Rs,_ii);return _createClass(Rs,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var s=new FormData();return s.append("image",t),Object.keys(e).forEach(function(i){s.append(i,String(e[i]));}),s;}// prettier-ignore
|
154
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/
|
155
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/
|
156
|
-
_inherits(
|
157
|
-
},{key:"preprocessBody",value:function preprocessBody(e,t){var _s$options;var s=JSON.parse(JSON.stringify(e)),i=this.processMessages(t);if(i)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:{past_user_inputs:i.past_user_inputs,generated_responses:i.generated_responses,text:i.mostRecentMessageText}},s);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/
|
158
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee57(e,t,s){var o,a,i,n;return _regeneratorRuntime().wrap(function _callee57$(_context57){while(1)switch(_context57.prev=_context57.next){case 0:if(this.connectSettings){_context57.next=2;break;}throw new Error("Request settings have not been set up");case 2:if(s){_context57.next=4;break;}throw new Error("Image was not found");case 4:i=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim(),n=this.createFormDataBody(this.rawBody,s[0],i);E.tempRemoveContentHeader(this.connectSettings,R.request.bind(this,this,n,e),!1);case 6:case"end":return _context57.stop();}},_callee57,this);}));function callServiceAPI(_x112,_x113,_x114){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee58(e){return _regeneratorRuntime().wrap(function _callee58$(_context58){while(1)switch(_context58.prev=_context58.next){case 0:if(!e.message){_context58.next=2;break;}throw e.message;case 2:return _context58.abrupt("return",{files:e.artifacts.map(function(s){return{src:"".concat(At).concat(s.base64),type:"image"};})});case 3:case"end":return _context58.stop();}},_callee58);}));function extractResultData(_x115){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()!=="");}}]);}(ii);var fa=/*#__PURE__*/function(_Ve6){function fa(e){_classCallCheck(this,fa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,fa,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,s]);}_inherits(fa,_Ve6);return _createClass(fa,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee59(e){var t;return _regeneratorRuntime().wrap(function _callee59$(_context59){while(1)switch(_context59.prev=_context59.next){case 0:if(!e.error){_context59.next=2;break;}throw e.error;case 2:return _context59.abrupt("return",{text:((t=e[0])==null?void 0:t.translation_text)||""});case 3:case"end":return _context59.stop();}},_callee59);}));function extractResultData(_x116){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Ls=/*#__PURE__*/function(_ii4){function Ls(e){var _this29;_classCallCheck(this,Ls);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI;_this29=_callSuper(this,Ls,[e,Le.buildKeyVerificationDetails(),Le.buildHeaders,s]),_this29.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this29.textInputPlaceholderText="Describe an image",_this29.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI: Text to Image</b></div>\n <p>Insert text to generate an image.</p>\n <p>Click <a href=\"https://platform.stability.ai/\">here</a> for more info.</p>";var i=(n=t.stabilityAI)==null?void 0:n.textToImage;_typeof(i)=="object"&&(i.engine_id&&(_this29.url="https://api.stability.ai/v1/generation/".concat(i.engine_id,"/text-to-image")),i.weight!==void 0&&i.weight!==null&&(_this29._imageWeight=i.weight),Ls.cleanConfig(i),Object.assign(_this29.rawBody,i)),_this29.canSendMessage=Ls.canSendTextMessage;return _this29;}_inherits(Ls,_ii4);return _createClass(Ls,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i={text:t};return this._imageWeight&&(i.weight=this._imageWeight),s.text_prompts=[i],s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee60(e,t){var s;return _regeneratorRuntime().wrap(function _callee60$(_context60){while(1)switch(_context60.prev=_context60.next){case 0:if(this.connectSettings){_context60.next=2;break;}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,t[t.length-1].text);R.request(this,s,e);case 4:case"end":return _context60.stop();}},_callee60,this);}));function callServiceAPI(_x117,_x118){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee61(e){return _regeneratorRuntime().wrap(function _callee61$(_context61){while(1)switch(_context61.prev=_context61.next){case 0:if(!e.message){_context61.next=2;break;}throw e.message;case 2:return _context61.abrupt("return",{files:e.artifacts.map(function(s){return{src:"".concat(At).concat(s.base64),type:"image"};})});case 3:case"end":return _context61.stop();}},_callee61);}));function extractResultData(_x119){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()!=="");}}]);}(ii);var fn=/*#__PURE__*/function(){function fn(){_classCallCheck(this,fn);}return _createClass(fn,null,[{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.elevenlabs.io/v1/voices",method:"GET",handleVerificationResult:function handleVerificationResult(e){return _typeof(e)=="object"&&e!==null?{key:!0}:{error:"Something went wrong, please check your API key."};}};}},{key:"buildHeaders",value:function buildHeaders(e){return _objectSpread({"Content-Type":"application/json"},e&&{"xi-api-key":e});}}]);}();var vt=/*#__PURE__*/function(_I3){function vt(e){var _o$model_id;var _this30;_classCallCheck(this,vt);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.elevenLabs;_this30=_callSuper(this,vt,[e,fn.buildKeyVerificationDetails(),fn.buildHeaders,s]),_this30.insertKeyPlaceholderText="ElevenLabs API Key",_this30.keyHelpUrl="https://elevenlabs.io/app/speech-synthesis",_this30.url="https://api.elevenlabs.io/v1/text-to-speech",_this30.permittedErrorPrefixes=["Invalid"],_this30.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>ElevenLabs : Text To Speech</b></div>\n <p>Generate an audio file based on your text input.</p>\n <p>Click <a href=\"https://elevenlabs.io/docs/api-reference/text-to-speech\">here</a> for more information.</p>";var i=(n=t==null?void 0:t.elevenLabs)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&Object.assign(_this30.rawBody,i),(_o$model_id=(o=_this30.rawBody).model_id)!==null&&_o$model_id!==void 0?_o$model_id:o.model_id=vt.DEFAULT_MODEL_ID,_this30.voiceId=_this30.rawBody.voice_id||vt.DEFAULT_VOICE_ID,_this30.textInputPlaceholderText="Insert text to generate audio",_this30.url="".concat(_this30.url,"/").concat(_this30.voiceId);return _this30;}_inherits(vt,_I3);return _createClass(vt,[{key:"preprocessBody",value:function preprocessBody(e,t){var n,o;var s=JSON.parse(JSON.stringify(e));delete s.voice_id;var i=(o=(n=t[t.length-1])==null?void 0:n.text)==null?void 0:o.trim();return i&&i!==""&&(s.text=i),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee62(e,t){var i,s;return _regeneratorRuntime().wrap(function _callee62$(_context62){while(1)switch(_context62.prev=_context62.next){case 0:if((i=this.connectSettings)!=null&&i.headers){_context62.next=2;break;}throw new Error("Request settings have not been set up");case 2:this.url=this.connectSettings.url||this.url;s=this.preprocessBody(this.rawBody,t);R.request(this,s,e);case 5:case"end":return _context62.stop();}},_callee62,this);}));function callServiceAPI(_x120,_x121){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee63(e){return _regeneratorRuntime().wrap(function _callee63$(_context63){while(1)switch(_context63.prev=_context63.next){case 0:if(!(e instanceof Blob)){_context63.next=2;break;}return _context63.abrupt("return",new Promise(function(t){var s=new FileReader();s.readAsDataURL(e),s.onload=function(i){t({files:[{src:i.target.result,type:"audio"}]});};}));case 2:if(!e.error){_context63.next=4;break;}throw e.error.message;case 4:return _context63.abrupt("return",{error:"error"});case 5:case"end":return _context63.stop();}},_callee63);}));function extractResultData(_x122){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(I);vt.DEFAULT_VOICE_ID="JBFqnCBsd6RMkjVDRZzb",vt.DEFAULT_MODEL_ID="eleven_multilingual_v2";var _i=vt;var ma=/*#__PURE__*/function(_Ve7){function ma(e){var _this31;_classCallCheck(this,ma);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.fillMask,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this31=_callSuper(this,ma,[e,"The goal of life is [MASK].","bert-base-uncased",t,s]),_this31.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Hugging Face</b></div>\n <p>Insert a sentence with the word [MASK] and the model will try to fill it for you. E.g. I want [MASK].</p>\n <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>",_this31.permittedErrorPrefixes=["Authorization header","No mask_token"];return _this31;}_inherits(ma,_Ve7);return _createClass(ma,[{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee64(e){var t;return _regeneratorRuntime().wrap(function _callee64$(_context64){while(1)switch(_context64.prev=_context64.next){case 0:if(!e.error){_context64.next=2;break;}throw e.error;case 2:return _context64.abrupt("return",{text:((t=e[0])==null?void 0:t.sequence)||""});case 3:case"end":return _context64.stop();}},_callee64);}));function extractResultData(_x123){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var ts=/*#__PURE__*/function(){function ts(){_classCallCheck(this,ts);}return _createClass(ts,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}// prettier-ignore
|
156
|
+
function ii(e,t,s,i,n){var _this23;_classCallCheck(this,ii);_this23=_callSuper(this,ii,[e,t,s,i,n]),_this23.insertKeyPlaceholderText="Stability AI API Key",_this23.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this23.permittedErrorPrefixes=["Incorrect","invalid_"];return _this23;}_inherits(ii,_I2);return _createClass(ii);}(I);var Rs=/*#__PURE__*/function(_ii){function Rs(e){var _this24;_classCallCheck(this,Rs);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this24=_callSuper(this,Rs,[e,Le.buildKeyVerificationDetails(),Le.buildHeaders,s,i]),_this24.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",_this24.textInputPlaceholderText="Describe image changes",_this24.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI</b></div>\n <div style=\"width: 100%; text-align: center; margin-left: -10px; margin-top: 5px\"><b>Image to Image Upscale</b></div>\n <p>Upload an image to generate a new one with higher resolution.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var n=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageUpscale;_typeof(n)=="object"&&(n.engine_id&&(_this24.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/image-to-image/upscale")),Rs.cleanConfig(n),Object.assign(_this24.rawBody,n)),_this24.canSendMessage=Rs.canSendFileMessage;return _this24;}_inherits(Rs,_ii);return _createClass(Rs,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var s=new FormData();return s.append("image",t),Object.keys(e).forEach(function(i){s.append(i,String(e[i]));}),s;}// prettier-ignore
|
157
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48(e,t,s){var i;return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:if(this.connectSettings){_context48.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context48.n=2;break;}throw new Error("Image was not found");case 2:i=this.createFormDataBody(this.rawBody,s[0]);E.tempRemoveContentHeader(this.connectSettings,R.request.bind(this,this,i,e),!1);case 3:return _context48.a(2);}},_callee48,this);}));function callServiceAPI(_x99,_x100,_x101){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49(e){return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(!e.message){_context49.n=1;break;}throw e.message;case 1:return _context49.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(At).concat(s.base64),type:"image"};})});}},_callee49);}));function extractResultData(_x102){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]);}}]);}(ii);var Ms=/*#__PURE__*/function(_ii2){function Ms(e){var _this25;_classCallCheck(this,Ms);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};_this25=_callSuper(this,Ms,[e,Le.buildKeyVerificationDetails(),Le.buildHeaders,s,i]),_this25.url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",_this25._maskSource="MASK_IMAGE_WHITE",_this25.textInputPlaceholderText="Describe image changes",_this25.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI</b></div>\n <div style=\"width: 100%; text-align: center; margin-left: -10px; margin-top: 5px\"><b>Image to Image Masking</b></div>\n <p>Upload an image, its mask image to create a new one based on the changes you have described for the mask area.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var n=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageMasking;_typeof(n)=="object"&&(n.engine_id&&(_this25.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/image-to-image/masking")),n.weight!==void 0&&n.weight!==null&&(_this25._imageWeight=n.weight),n.mask_source!==void 0&&n.mask_source!==null&&(_this25._maskSource=n.mask_source),Ms.cleanConfig(n),Object.assign(_this25.rawBody,n)),_this25.canSendMessage=Ms.canSendFileTextMessage;return _this25;}_inherits(Ms,_ii2);return _createClass(Ms,[{key:"createFormDataBody",value:function createFormDataBody(e,t,s,i){var n=new FormData();return n.append("init_image",t),n.append("mask_source",String(this._maskSource)),n.append("mask_image",s),i&&i!==""&&n.append("text_prompts[0][text]",i),this._imageWeight!==void 0&&this._imageWeight!==null&&n.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(o){n.append(o,String(e[o]));}),n.get("weight")===void 0&&n.append("weight",String(1)),n;}// prettier-ignore
|
158
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(e,t,s){var o,a,i,n;return _regenerator().w(function(_context50){while(1)switch(_context50.n){case 0:if(this.connectSettings){_context50.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!(!s||!s[0]||!s[1])){_context50.n=2;break;}throw new Error("Image was not found");case 2:i=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim(),n=this.createFormDataBody(this.rawBody,s[0],s[1],i);E.tempRemoveContentHeader(this.connectSettings,R.request.bind(this,this,n,e),!1);case 3:return _context50.a(2);}},_callee50,this);}));function callServiceAPI(_x103,_x104,_x105){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e){return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(!e.message){_context51.n=1;break;}throw e.message;case 1:return _context51.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(At).concat(s.base64),type:"image"};})});}},_callee51);}));function extractResultData(_x106){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()!=="");}}]);}(ii);var aa=/*#__PURE__*/function(_fs3){function aa(e){_classCallCheck(this,aa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.audioSpeechRecognition,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,aa,[e,"Attach an audio file","facebook/wav2vec2-large-960h-lv60-self",t,s,{audio:{}}]);}_inherits(aa,_fs3);return _createClass(aa,[{key:"extractPollResultData",value:function(){var _extractPollResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e){return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(!e.estimated_time){_context52.n=1;break;}return _context52.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context52.n=2;break;}throw e.error;case 2:return _context52.a(2,{text:e.text||""});}},_callee52);}));function extractPollResultData(_x107){return _extractPollResultData3.apply(this,arguments);}return extractPollResultData;}()}]);}(fs);var la=/*#__PURE__*/function(_Ge2){function la(e){_classCallCheck(this,la);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.textGeneration,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,la,[e,"Once upon a time","gpt2",t,s]);}_inherits(la,_Ge2);return _createClass(la,[{key:"extractResultData",value:function(){var _extractResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e){var t;return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(!e.error){_context53.n=1;break;}throw e.error;case 1:return _context53.a(2,{text:((t=e[0])==null?void 0:t.generated_text)||""});}},_callee53);}));function extractResultData(_x108){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(Ge);var ca=/*#__PURE__*/function(_Ge3){function ca(e){var _this26;_classCallCheck(this,ca);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.questionAnswer,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this26=_callSuper(this,ca,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,s]),_this26.permittedErrorPrefixes=["Authorization header","Error in"],_this26._context=t.context;return _this26;}_inherits(ca,_Ge3);return _createClass(ca,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return{inputs:{question:s,context:this._context,options:{wait_for_model:!0}}};}},{key:"extractResultData",value:function(){var _extractResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54(e){return _regenerator().w(function(_context54){while(1)switch(_context54.n){case 0:if(!e.error){_context54.n=1;break;}throw e.error;case 1:return _context54.a(2,{text:e.answer||""});}},_callee54);}));function extractResultData(_x109){return _extractResultData5.apply(this,arguments);}return extractResultData;}()}]);}(Ge);var da=/*#__PURE__*/function(_Ge4){function da(e){_classCallCheck(this,da);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.summarization,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,da,[e,"Insert text to summarize","facebook/bart-large-cnn",t,s]);}_inherits(da,_Ge4);return _createClass(da,[{key:"extractResultData",value:function(){var _extractResultData6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(e){var t;return _regenerator().w(function(_context55){while(1)switch(_context55.n){case 0:if(!e.error){_context55.n=1;break;}throw e.error;case 1:return _context55.a(2,{text:((t=e[0])==null?void 0:t.summary_text)||""});}},_callee55);}));function extractResultData(_x110){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(Ge);var ha=/*#__PURE__*/function(_Ge5){function ha(e){var _this27$maxMessages;var _this27;_classCallCheck(this,ha);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.conversation,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this27=_callSuper(this,ha,[e,"Ask me anything!","facebook/blenderbot-400M-distill",t,s]),(_this27$maxMessages=_this27.maxMessages)!==null&&_this27$maxMessages!==void 0?_this27$maxMessages:_this27.maxMessages=-1;return _this27;}// prettier-ignore
|
159
|
+
_inherits(ha,_Ge5);return _createClass(ha,[{key:"processMessages",value:function processMessages(e){var t=e.filter(function(a){return a.text;}),s=t[t.length-1].text,i=t.slice(0,t.length-1);if(!s)return;var n=i.filter(function(a){return a.role==="user";}).map(function(a){return a.text;}),o=i.filter(function(a){return a.role==="ai";}).map(function(a){return a.text;});return{past_user_inputs:n,generated_responses:o,mostRecentMessageText:s};}// prettier-ignore
|
160
|
+
},{key:"preprocessBody",value:function preprocessBody(e,t){var _s$options;var s=JSON.parse(JSON.stringify(e)),i=this.processMessages(t);if(i)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:{past_user_inputs:i.past_user_inputs,generated_responses:i.generated_responses,text:i.mostRecentMessageText}},s);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56(e){return _regenerator().w(function(_context56){while(1)switch(_context56.n){case 0:if(!e.error){_context56.n=1;break;}throw e.error;case 1:return _context56.a(2,{text:e.generated_text||""});}},_callee56);}));function extractResultData(_x111){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(Ge);var ks=/*#__PURE__*/function(_ii3){function ks(e){var _this28;_classCallCheck(this,ks);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this28=_callSuper(this,ks,[e,Le.buildKeyVerificationDetails(),Le.buildHeaders,s,i]),_this28.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this28.textInputPlaceholderText="Describe image changes",_this28.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI: Image to Image</b></div>\n <p>Upload an image to create a new one with the changes you have described.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var n=(o=t.stabilityAI)==null?void 0:o.imageToImage;_typeof(n)=="object"&&(n.engine_id&&(_this28.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/text-to-image")),n.weight!==void 0&&n.weight!==null&&(_this28._imageWeight=n.weight),ks.cleanConfig(n),Object.assign(_this28.rawBody,n)),_this28.canSendMessage=ks.canSendFileTextMessage;return _this28;}_inherits(ks,_ii3);return _createClass(ks,[{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("init_image",t),s&&s!==""&&i.append("text_prompts[0][text]",s),this._imageWeight!==void 0&&this._imageWeight!==null&&i.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i.get("weight")===void 0&&i.append("weight",String(1)),i;}// prettier-ignore
|
161
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57(e,t,s){var o,a,i,n;return _regenerator().w(function(_context57){while(1)switch(_context57.n){case 0:if(this.connectSettings){_context57.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context57.n=2;break;}throw new Error("Image was not found");case 2:i=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim(),n=this.createFormDataBody(this.rawBody,s[0],i);E.tempRemoveContentHeader(this.connectSettings,R.request.bind(this,this,n,e),!1);case 3:return _context57.a(2);}},_callee57,this);}));function callServiceAPI(_x112,_x113,_x114){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58(e){return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(!e.message){_context58.n=1;break;}throw e.message;case 1:return _context58.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(At).concat(s.base64),type:"image"};})});}},_callee58);}));function extractResultData(_x115){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()!=="");}}]);}(ii);var ua=/*#__PURE__*/function(_Ge6){function ua(e){_classCallCheck(this,ua);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ua,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,s]);}_inherits(ua,_Ge6);return _createClass(ua,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){var t;return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e.error){_context59.n=1;break;}throw e.error;case 1:return _context59.a(2,{text:((t=e[0])==null?void 0:t.translation_text)||""});}},_callee59);}));function extractResultData(_x116){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Ge);var Ls=/*#__PURE__*/function(_ii4){function Ls(e){var _this29;_classCallCheck(this,Ls);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI;_this29=_callSuper(this,Ls,[e,Le.buildKeyVerificationDetails(),Le.buildHeaders,s]),_this29.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this29.textInputPlaceholderText="Describe an image",_this29.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI: Text to Image</b></div>\n <p>Insert text to generate an image.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var i=(n=t.stabilityAI)==null?void 0:n.textToImage;_typeof(i)=="object"&&(i.engine_id&&(_this29.url="https://api.stability.ai/v1/generation/".concat(i.engine_id,"/text-to-image")),i.weight!==void 0&&i.weight!==null&&(_this29._imageWeight=i.weight),Ls.cleanConfig(i),Object.assign(_this29.rawBody,i)),_this29.canSendMessage=Ls.canSendTextMessage;return _this29;}_inherits(Ls,_ii4);return _createClass(Ls,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i={text:t};return this._imageWeight&&(i.weight=this._imageWeight),s.text_prompts=[i],s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e,t){var s;return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(this.connectSettings){_context60.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t[t.length-1].text);R.request(this,s,e);case 2:return _context60.a(2);}},_callee60,this);}));function callServiceAPI(_x117,_x118){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e){return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(!e.message){_context61.n=1;break;}throw e.message;case 1:return _context61.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(At).concat(s.base64),type:"image"};})});}},_callee61);}));function extractResultData(_x119){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()!=="");}}]);}(ii);var pa=/*#__PURE__*/function(_Ge7){function pa(e){var _this30;_classCallCheck(this,pa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.fillMask,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this30=_callSuper(this,pa,[e,"The goal of life is [MASK].","bert-base-uncased",t,s]),_this30.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Hugging Face</b></div>\n <p>Insert a sentence with the word [MASK] and the model will try to fill it for you. E.g. I want [MASK].</p>\n <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>",_this30.permittedErrorPrefixes=["Authorization header","No mask_token"];return _this30;}_inherits(pa,_Ge7);return _createClass(pa,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e){var t;return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(!e.error){_context62.n=1;break;}throw e.error;case 1:return _context62.a(2,{text:((t=e[0])==null?void 0:t.sequence)||""});}},_callee62);}));function extractResultData(_x120){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(Ge);var ts=/*#__PURE__*/function(){function ts(){_classCallCheck(this,ts);}return _createClass(ts,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}// prettier-ignore
|
159
162
|
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.openai.com/v1/models",method:"GET",handleVerificationResult:ts.handleVerificationResult};}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
160
|
-
},{key:"directFetch",value:function(){var _directFetch=_asyncToGenerator(/*#__PURE__*/
|
161
|
-
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/
|
163
|
+
},{key:"directFetch",value:function(){var _directFetch=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e,t,s){var i,n,_args63=arguments;return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:i=_args63.length>3&&_args63[3]!==undefined?_args63[3]:!0;e.connectSettings.method=s;_context63.n=1;return E.fetch(e,e.connectSettings.headers,i,t).then(function(o){return E.processResponseByType(o);});case 1:n=_context63.v;if(!n.error){_context63.n=2;break;}throw n.error.message;case 2:return _context63.a(2,n);}},_callee63);}));function directFetch(_x121,_x122,_x123){return _directFetch.apply(this,arguments);}return directFetch;}()}]);}();ts.FUNCTION_TOOL_RESP_ERROR="Response object must either be {response: string}[] for each individual function or {text: string} for a direct response, see https://deepchat.dev/docs/directConnection/OpenAI#FunctionHandler.",ts.FUNCTION_TOOL_RESP_ARR_ERROR="Arrays are not accepted in handler responses";var P=ts;var ae=/*#__PURE__*/function(){function ae(){_classCallCheck(this,ae);}return _createClass(ae,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e,t,s,i){var n,o,a,l,_t19;return _regenerator().w(function(_context65){while(1)switch(_context65.p=_context65.n){case 0:n=e.connectSettings.headers;if(n){_context65.n=1;break;}return _context65.a(2);case 1:e.url=i;o=n[E.CONTENT_TYPE];delete n[E.CONTENT_TYPE];a=s.map(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(l){var c;return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:c=new FormData();return _context64.a(2,(c.append("purpose","assistants"),c.append("file",l),new Promise(function(d){d(P.directFetch(e,c,"POST",!1));})));}},_callee64);}));return function(_x128){return _ref18.apply(this,arguments);};}());_context65.p=2;_context65.n=3;return Promise.all(a);case 3:l=_context65.v.map(function(c){return{id:c.id,name:c.filename};});return _context65.a(2,(n[E.CONTENT_TYPE]=o,l));case 4:_context65.p=4;_t19=_context65.v;throw n[E.CONTENT_TYPE]=o,E.displayError(t,_t19),e.completionsHandlers.onFinish(),_t19;case 5:return _context65.a(2);}},_callee65,null,[[2,4]]);}));function storeFiles(_x124,_x125,_x126,_x127){return _storeFiles.apply(this,arguments);}return storeFiles;}()},{key:"getType",value:function getType(e,t){var s=e[t].path;return!s||s.endsWith("png")?"image":"any";}},{key:"getFiles",value:function(){var _getFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e,t,s,i){var n,a;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:n=t.map(function(_ref19){var l=_ref19.fileId;return e.url="".concat(s).concat(l).concat(i),new Promise(function(c){c(P.directFetch(e,void 0,"GET",!1));});});_context66.n=1;return Promise.all(n);case 1:a=_context66.v.map(function(l,c){return new Promise(function(d){var u=new FileReader();u.readAsDataURL(l),u.onload=function(h){d({src:h.target.result,name:t[c].name,type:ae.getType(t,c)});};});});_context66.n=2;return Promise.all(a);case 2:return _context66.a(2,_context66.v);}},_callee66);}));function getFiles(_x129,_x130,_x131,_x132){return _getFiles.apply(this,arguments);}return getFiles;}()},{key:"getFileName",value:function getFileName(e){var t=e.split("/");return t[t.length-1];}// prettier-ignore
|
164
|
+
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e,t,s,i,n){var c,d,o,a,l,_t20;return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:a=s.getFilesPrefix,l=s.getFilesPostfix;_t20=t.length>0;if(!_t20){_context67.n=2;break;}_context67.n=1;return ae.getFiles(e,t,a,l);case 1:o=_context67.v;(c=n==null?void 0:n.text)!=null&&c.value&&o.forEach(function(u,h){var m;if(!u.src)return;var p=t[h].path;(m=n==null?void 0:n.text)!=null&&m.value&&p&&(n.text.value=n.text.value.replace(p,u.src));});case 2:return _context67.a(2,(d=n==null?void 0:n.text)!=null&&d.value?{text:n.text.value,role:i}:{files:o,role:i});}},_callee67);}));function getFilesAndNewText(_x133,_x134,_x135,_x136,_x137){return _getFilesAndNewText.apply(this,arguments);}return getFilesAndNewText;}()// Noticed an issue where text contains a sandbox hyperlink to a csv, but no annotation provided
|
162
165
|
// To reproduce use the following text:
|
163
166
|
// give example data for a csv and create a suitable bar chart for it with a link
|
164
167
|
// Don't think it can be fixed and it is something on OpenAI side of things
|
165
168
|
// prettier-ignore
|
166
169
|
},{key:"getFileDetails",value:function getFileDetails(e,t){var i;var s=[];return(i=t==null?void 0:t.text)!=null&&i.value&&e.content.forEach(function(n){var o,a;(a=(o=n.text)==null?void 0:o.annotations)==null||a.forEach(function(l){var c;l.text&&l.text.startsWith("sandbox:")&&(c=l.file_path)!=null&&c.file_id&&s.push({path:l.text,fileId:l.file_path.file_id,name:ae.getFileName(l.text)});});}),t!=null&&t.image_file&&s.push({fileId:t.image_file.file_id}),s;}// prettier-ignore
|
167
|
-
},{key:"getFilesAndText",value:function(){var _getFilesAndText=_asyncToGenerator(/*#__PURE__*/
|
170
|
+
},{key:"getFilesAndText",value:function(){var _getFilesAndText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e,t,s,i){var n;return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:n=ae.getFileDetails(t,i);_context68.n=1;return ae.getFilesAndNewText(e,n,s,t.role,i);case 1:return _context68.a(2,_context68.v);}},_callee68);}));function getFilesAndText(_x138,_x139,_x140,_x141){return _getFilesAndText.apply(this,arguments);}return getFilesAndText;}()},{key:"parseResult",value:function parseResult(e,t){var s=[];if(t)s=e.data;else for(var i=0;i<e.data.length;i+=1){var n=e.data[i];if(n.role==="assistant")s.push(n);else break;}return s.reverse();}// test this using this prompt and it should give 2 text mesages and a file:
|
168
171
|
// "give example data for a csv and create a suitable bar chart"
|
169
|
-
},{key:"parseMessages",value:function parseMessages(e,t,s){var i=[];return t.forEach(/*#__PURE__*/function(){var _ref20=_asyncToGenerator(/*#__PURE__*/
|
170
|
-
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/
|
171
|
-
function $e(e,t,s,i,n,o){var
|
172
|
-
},{key:"extractResultData",value:function(){var
|
173
|
-
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/
|
174
|
-
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/
|
172
|
+
},{key:"parseMessages",value:function parseMessages(e,t,s){var i=[];return t.forEach(/*#__PURE__*/function(){var _ref20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(n){return _regenerator().w(function(_context70){while(1)switch(_context70.n){case 0:n.content.filter(function(o){return!!o.text||!!o.image_file;}).sort(function(o){return o.text?-1:o.image_file?1:0;}).forEach(/*#__PURE__*/function(){var _ref21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee69(o){return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:i.push(ae.getFilesAndText(e,n,s,o));case 1:return _context69.a(2);}},_callee69);}));return function(_x143){return _ref21.apply(this,arguments);};}());case 1:return _context70.a(2);}},_callee70);}));return function(_x142){return _ref20.apply(this,arguments);};}()),Promise.all(i);}},{key:"processStreamMessages",value:function(){var _processStreamMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(e,t,s){return _regenerator().w(function(_context71){while(1)switch(_context71.n){case 0:return _context71.a(2,ae.parseMessages(e,[{content:t,role:"assistant"}],s));}},_callee71);}));function processStreamMessages(_x144,_x145,_x146){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
|
173
|
+
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(e,t,s,i){var n;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:n=ae.parseResult(t,s);return _context72.a(2,ae.parseMessages(e,n,i));}},_callee72);}));function processAPIMessages(_x147,_x148,_x149,_x150){return _processAPIMessages.apply(this,arguments);}return processAPIMessages;}()}]);}();ae.FILES_WITH_TEXT_ERROR="content with type `text` must have `text` values",ae.FUNCTION_TOOL_RESP_ERROR="Response must contain an array of strings for each individual function/tool_call, see https://deepchat.dev/docs/directConnection/OpenAI/#assistant-functions.";var Oe=ae;var $e=/*#__PURE__*/function(_I3){// prettier-ignore
|
174
|
+
function $e(e,t,s,i,n,o){var _this31;_classCallCheck(this,$e);if(_this31=_callSuper(this,$e,[e,i,n,o]),_this31.insertKeyPlaceholderText="OpenAI API Key",_this31.keyHelpUrl="https://platform.openai.com/account/api-keys",_this31.url="",_this31.permittedErrorPrefixes=["Incorrect","Please send text",ls.FAILED_ERROR_MESSAGE],_this31.shouldFetchHistory=!1,_this31._searchedForThreadId=!1,_this31._config={},_this31._newAssistantDetails={model:"gpt-4"},_this31._waitingForStreamResponse=!1,_this31._isSSEStream=!1,_this31.urlSegments=s,_typeof(t)=="object"){_this31._config=t;var _this31$_config=_this31._config,a=_this31$_config.new_assistant,l=_this31$_config.thread_id,c=_this31$_config.load_thread_history;Object.assign(_this31._newAssistantDetails,a),l&&(_this31.sessionId=l),c&&(_this31.shouldFetchHistory=!0);}_this31.maxMessages=1,_this31._isSSEStream=!!(_this31.stream&&(_typeof(_this31.stream)!="object"||!_this31.stream.simulation));return _this31;}_inherits($e,_I3);return _createClass($e,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73(){var _this32=this;var e,_t21;return _regenerator().w(function(_context73){while(1)switch(_context73.p=_context73.n){case 0:setTimeout(function(){return _this32.deepChat.disableSubmitButton();},2);_context73.p=1;_context73.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context73.v;return _context73.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context73.p=3;_t21=_context73.v;return _context73.a(2,[{error:"Failed to fetch history"}]);}},_callee73,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processMessage",value:function processMessage(e,t){var s=this.totalMessagesMaxCharLength||-1,i=ne.getCharacterLimitMessages(e,s)[0];if(t&&t.length>0){var n=this.filesToolType;if(typeof this.filesToolType=="function"){var a=this.filesToolType(t.map(function(_ref22){var l=_ref22.name;return l;}));a==="code_interpreter"||a==="file_search"||a==="images"?n=a:(console.error("Tool type \"".concat(a,"\" is not valid")),console.error('Expected "code_interpreter" or "file_search" or "images". Going to default to "images"'));}if(n==="file_search")return $e.processAttachmentsMessage(i,t,"file_search");if(n==="code_interpreter")return $e.processAttachmentsMessage(i,t,"code_interpreter");if(t.find(function(_ref23){var a=_ref23.name;return!z.isImageFileExtension(a);}))console.error("The uploaded files contained a non-image file"),console.error('Make sure only images can be uploaded or define a "code_interpreter" or "file_search" value in the "files_tool_type" property'),console.warn('Make sure your existing assistant supports these "tools" or specify them in the "new_assistant" property');else{var _a3=$e.processImageMessage(i,t);if(_a3)return _a3;}}return{content:i.text||"",role:"user"};}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,s){var i=JSON.parse(JSON.stringify(e)),n=this.processMessage(t,s);return i.thread={messages:[n]},i;}},{key:"callService",value:function callService(e,t,s){if(this._messages=e,this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/messages").concat(this.urlSegments.createMessagePostfix);var i=this.processMessage(t,s);R.request(this,i,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _i2=this.createNewThreadMessages(this.rawBody,t,s);this._isSSEStream?this.createStreamRun(_i2):R.request(this,_i2,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee74(e,t,s){var _n$assistant_id;var n,i,_t22,_t23;return _regenerator().w(function(_context74){while(1)switch(_context74.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context74.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!((_n$assistant_id=(n=this.rawBody).assistant_id)!==null&&_n$assistant_id!==void 0)){_context74.n=2;break;}_n$assistant_id;_context74.n=5;break;case 2:_t22=this._config.assistant_id;if(_t22){_context74.n=4;break;}_context74.n=3;return this.createNewAssistant();case 3:_t22=_context74.v;case 4:n.assistant_id=_t22;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!s){_context74.n=7;break;}_context74.n=6;return Oe.storeFiles(this,e,s,this.urlSegments.storeFiles);case 6:_t23=_context74.v;_context74.n=8;break;case 7:_t23=void 0;case 8:i=_t23;this.connectSettings.method="POST",this.callService(e,t,i);case 9:return _context74.a(2);}},_callee74,this);}));function callServiceAPI(_x151,_x152,_x153){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee75(){var e,_t24;return _regenerator().w(function(_context75){while(1)switch(_context75.p=_context75.n){case 0:_context75.p=0;this.url=this.urlSegments.newAssistantUrl;_context75.n=1;return P.directFetch(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),"POST");case 1:e=_context75.v;return _context75.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context75.p=2;_t24=_context75.v;console.error(_t24),console.error("Failed to create a new assistant");case 3:return _context75.a(2);}},_callee75,this,[[0,2]]);}));function createNewAssistant(){return _createNewAssistant.apply(this,arguments);}return createNewAssistant;}()},{key:"searchPreviousMessagesForThreadId",value:function searchPreviousMessagesForThreadId(e){var t=e.find(function(_ref24){var _ref25=_slicedToArray(_ref24,1),s=_ref25[0];return s._sessionId;});t&&(this.sessionId=t[0]._sessionId),this._searchedForThreadId=!0;}// prettier-ignore
|
175
|
+
},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee76(e){var i,t,s;return _regenerator().w(function(_context76){while(1)switch(_context76.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context76.n=2;break;}_context76.n=1;return this.handleStream(e);case 1:return _context76.a(2,_context76.v);case 2:if(!e.error){_context76.n=3;break;}throw e.error.message.startsWith(Oe.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e.error.message;case 3:_context76.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),s={method:"GET",headers:(i=this.connectSettings)==null?void 0:i.headers};return _context76.a(2,(R.executePollRequest(this,t,s,this._messages),{makingAnotherRequest:!0}));}},_callee76,this);}));function extractResultData(_x154){return _extractResultData10.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(e){var t;return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:if(!this.sessionId){_context77.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context77.n=1;return P.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),"POST");case 1:t=_context77.v;this.run_id=t.id;_context77.n=3;break;case 2:this.sessionId=e.thread_id,this.run_id=e.id,this._messages&&this._messages.messageToElements.length>0&&(this._messages.messageToElements[this._messages.messageToElements.length-1][0]._sessionId=this.sessionId);case 3:return _context77.a(2);}},_callee77,this);}));function assignThreadAndRun(_x155){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(e){var t,i,n,s,_args78=arguments,_t25;return _regenerator().w(function(_context78){while(1)switch(_context78.n){case 0:t=_args78.length>1&&_args78[1]!==undefined?_args78[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context78.n=1;return P.directFetch(this,{},"GET");case 1:s=_context78.v;_t25=!t&&this.deepChat.responseInterceptor;if(!_t25){_context78.n=3;break;}_context78.n=2;return(n=(i=this.deepChat).responseInterceptor)==null?void 0:n.call(i,s);case 2:s=_context78.v;case 3:return _context78.a(2,Oe.processAPIMessages(this,s,t,this.urlSegments));}},_callee78,this);}));function getThreadMessages(_x156){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e){var _this33=this;var n,t,s,o,_o$shift,a,l,i;return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:t=e.status,s=e.required_action;if(!(t==="queued"||t==="in_progress")){_context79.n=1;break;}return _context79.a(2,{timeoutMS:$e.POLLING_TIMEOUT_MS});case 1:if(!(t==="completed"&&this._messages)){_context79.n=3;break;}_context79.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context79.v;_o$shift=o.shift();a=_o$shift.text;l=_o$shift.files;return _context79.a(2,(setTimeout(function(){o.forEach(function(c){return _this33.deepChat.addMessage(c);});}),{text:a,_sessionId:this.sessionId,files:l}));case 3:i=(n=s==null?void 0:s.submit_tool_outputs)==null?void 0:n.tool_calls;if(!(t==="requires_action"&&i)){_context79.n=5;break;}_context79.n=4;return this.handleTools(i);case 4:return _context79.a(2,_context79.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context79.a(2);}},_callee79,this);}));function extractPollResultData(_x157){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
|
176
|
+
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(e){var t,s,i,n,o,a;return _regenerator().w(function(_context80){while(1)switch(_context80.n){case 0:if(this.functionHandler){_context80.n=1;break;}throw Error("Please define the `function_handler` property inside the [openAI](https://deepchat.dev/docs/directConnection/openAI#Assistant) object.");case 1:t=e.map(function(l){return{name:l["function"].name,arguments:l["function"].arguments};});_context80.n=2;return this.functionHandler(t);case 2:s=_context80.v;if(!(!Array.isArray(s)||e.length!==s.length)){_context80.n=3;break;}throw Error(Oe.FUNCTION_TOOL_RESP_ERROR);case 3:_context80.n=4;return Promise.all(s);case 4:i=_context80.v;if(!i.find(function(l){return typeof l!="string";})){_context80.n=5;break;}throw Error(Oe.FUNCTION_TOOL_RESP_ERROR);case 5:n=i.map(function(l,c){return{tool_call_id:e[c].id,output:l};}),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){_context80.n=7;break;}_context80.n=6;return this.createStreamRun({tool_outputs:n});case 6:_context80.n=8;break;case 7:_context80.n=8;return P.directFetch(this,{tool_outputs:n},"POST");case 8:return _context80.a(2,{timeoutMS:$e.POLLING_TIMEOUT_MS});}},_callee80,this);}));function handleTools(_x158){return _handleTools.apply(this,arguments);}return handleTools;}()},{key:"handleStream",value:function(){var _handleStream=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(e){var s,i,t,n;return _regenerator().w(function(_context81){while(1)switch(_context81.n){case 0:t=(i=(s=e.required_action)==null?void 0:s.submit_tool_outputs)==null?void 0:i.tool_calls;if(!(e.status==="requires_action"&&t)){_context81.n=2;break;}this.run_id=e.id;_context81.n=1;return this.handleTools(t);case 1:return _context81.a(2,_context81.v);case 2:if(!this._waitingForStreamResponse){_context81.n=3;break;}return _context81.a(2,this.parseStreamResult(e));case 3:if(this._isSSEStream&&this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);n=JSON.parse(JSON.stringify(this.rawBody));this.createStreamRun(n);}return _context81.a(2,{makingAnotherRequest:!0});}},_callee81,this);}));function handleStream(_x159){return _handleStream.apply(this,arguments);}return handleStream;}()// prettier-ignore
|
177
|
+
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(e){var t,s,i,n,o,a,l,c,_a4,_l2;return _regenerator().w(function(_context82){while(1)switch(_context82.n){case 0:if(!(e.content&&e.content.length>0&&this._messages)){_context82.n=1;break;}a=e.content.find(function(l){return l.text;});if(!((t=a==null?void 0:a.text)!=null&&t.annotations&&a.text.annotations.length>0)){_context82.n=1;break;}l=e.content.find(function(d){return!!d.text;})||e.content[0],c=Oe.getFilesAndText.bind(this,this,{role:"assistant",content:e.content},this.urlSegments,l);return _context82.a(2,((s=this._messageStream)==null||s.endStreamAfterFileDownloaded(this._messages,c),{text:""}));case 1:if(!((i=e.delta)!=null&&i.content)){_context82.n=4;break;}if(!(e.delta.content.length>1)){_context82.n=3;break;}_a4=e.delta.content.find(function(l){return l.text;});if(!((n=_a4==null?void 0:_a4.text)!=null&&n.annotations&&_a4.text.annotations.length===0)){_context82.n=3;break;}_context82.n=2;return Oe.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_l2=_context82.v;return _context82.a(2,{text:_l2[0].text,files:_l2[1].files});case 3:return _context82.a(2,{text:(o=e.delta.content[0].text)==null?void 0:o.value});case 4:return _context82.a(2,(!this.sessionId&&e.thread_id&&(this.sessionId=e.thread_id),{makingAnotherRequest:!0}));}},_callee82,this);}));function parseStreamResult(_x160){return _parseStreamResult.apply(this,arguments);}return parseStreamResult;}()// https://platform.openai.com/docs/api-reference/assistants-streaming
|
175
178
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
176
|
-
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/
|
177
|
-
function
|
178
|
-
},{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 _s2=e[t],i=_s2&&this.customStyles[_s2];i&&j.unsetActionCSS(this.elementRef,i);}}},{key:"reapplyStateStyle",value:function reapplyStateStyle(e,t){if(!this.customStyles)return;t&&this.unsetCustomStateStyles(t);var s=this.customStyles[e];s&&j.setElementCssUpToState(this.elementRef,s,this._mouseState.state),this.setEvents(s);}},{key:"changeElementsByState",value:function changeElementsByState(e){var _this$elementRef;(_this$elementRef=this.elementRef).replaceChildren.apply(_this$elementRef,_toConsumableArray(e)),ke.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,s){var i=ke.createCustomElements(t,this.svg,s);if(i&&i.length>0){if(this.position==="dropup-menu"){var n=this.svg.cloneNode(!0);n.id=i[0]===this.svg?e:"dropup-menu-item-icon-element-custom",i[0]=n;}return i;}return this.buildDefaultIconElement(e);}}]);}();var Zs=/*#__PURE__*/function(
|
179
|
-
},{key:"assignPropertyFromOneToAnother",value:function assignPropertyFromOneToAnother(e,t,s){var _t$e;(_t$e=t[e])!==null&&_t$e!==void 0?_t$e:t[e]={},Object.assign(t[e],s==null?void 0:s[e]);}}]);}();var Qs=/*#__PURE__*/_createClass(function Qs(){_classCallCheck(this,Qs);});Qs.SESSION_STARTED="sts-session-started",Qs.SESSION_STOPPED="sts-session-stopped";var
|
180
|
-
function setUpView(e,t){e.style.display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee86(){var i,e,t,s;return _regeneratorRuntime().wrap(function _callee86$(_context86){while(1)switch(_context86.prev=_context86.next){case 0:e=(i=this._deepChat.directConnection)==null?void 0:i.openAI;if(e){_context86.next=3;break;}return _context86.abrupt("return");case 3:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context86.next=6;break;}return _context86.abrupt("return");case 6:s=this.key||e.key;(t.fetchEphemeralKey||s)&&t.autoStart&&(this.changeToUnavailable(),this.displayLoading()),this.fetchEphemeralKey(t.autoStart);case 8:case"end":return _context86.stop();}},_callee86,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee87(e){var o,t,s,i,n,a;return _regeneratorRuntime().wrap(function _callee87$(_context87){while(1)switch(_context87.prev=_context87.next){case 0:t=(o=this._deepChat.directConnection)==null?void 0:o.openAI,s=_typeof(t==null?void 0:t.realtime)=="object"?t==null?void 0:t.realtime.fetchEphemeralKey:void 0,i=t==null?void 0:t.realtime,n=this.key||t.key;if(!(_typeof(i)=="object")){_context87.next=26;break;}if(this._ephemeralKey){_context87.next=23;break;}_context87.prev=3;if(!s){_context87.next=12;break;}a=s();a.then&&(this._retrievingEphemeralKey=a);_context87.next=9;return a;case 9:this._ephemeralKey=_context87.sent;_context87.next=18;break;case 12:_context87.t0=n;if(!_context87.t0){_context87.next=18;break;}this._retrievingEphemeralKey=this.getEphemeralKey(n);_context87.next=17;return this._retrievingEphemeralKey;case 17:this._ephemeralKey=_context87.sent;case 18:_context87.next=23;break;case 20:_context87.prev=20;_context87.t1=_context87["catch"](3);this.displayFailedToRetrieveEphemeralKey(_context87.t1);case 23:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context87.next=38;break;case 26:if(!n){_context87.next=38;break;}_context87.prev=27;this._retrievingEphemeralKey=this.getEphemeralKey(n);_context87.next=31;return this._retrievingEphemeralKey;case 31:this._ephemeralKey=_context87.sent;e&&this.init(this._ephemeralKey);_context87.next=38;break;case 35:_context87.prev=35;_context87.t2=_context87["catch"](27);this.displayFailedToRetrieveEphemeralKey(_context87.t2);case 38:case"end":return _context87.stop();}},_callee87,this,[[3,20],[27,35]]);}));function fetchEphemeralKey(_x165){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee88(e){return _regeneratorRuntime().wrap(function _callee88$(_context88){while(1)switch(_context88.prev=_context88.next){case 0:_context88.next=2;return fetch("https://api.openai.com/v1/realtime/sessions",{method:"POST",body:JSON.stringify(this.rawBody),headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)}});case 2:_context88.next=4;return _context88.sent.json();case 4:return _context88.abrupt("return",_context88.sent.client_secret.value);case 5:case"end":return _context88.stop();}},_callee88,this);}));function getEphemeralKey(_x166){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this39=this;return{updateConfig:function updateConfig(e){var t;(t=_this39._dc)==null||t.send(JSON.stringify({type:"session.update",session:e}));},sendMessage:function sendMessage(e,t){var s=t||"system",n={role:s,type:"message",content:[{type:s==="system"||s==="user"?"input_text":"text",text:e}]};_this39.sendMessage(n);}};}},{key:"createContainer",value:function createContainer(){var e=document.createElement("div");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,s;var e=document.createElement("div");return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e.style,(s=(t=this._avatarConfig)==null?void 0:t.styles)==null?void 0:s.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var i;var e=document.createElement("div");e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e.style,(i=this._buttonsConfig)==null?void 0:i.container),this._microphoneButton=this.createMicophoneButton();var t=k.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var s=k.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(s),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this40=this;var t;var e=new Os((t=this._buttonsConfig)==null?void 0:t.microphone);return e.elementRef.classList.add(k.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),e.elementRef.onclick=function(){e.isActive?(_this40.toggleMicorphone(!0),e.elementRef.classList.replace(k.MICROPHONE_ACTIVE,k.BUTTON_DEFAULT),e.changeToDefault(),_this40._isMuted=!1):(_this40.toggleMicorphone(!1),e.elementRef.classList.replace(k.BUTTON_DEFAULT,k.MICROPHONE_ACTIVE),F.removeAriaAttributes(e.elementRef),e.changeToActive(),_this40._isMuted=!0);},e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(s){return s.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this41=this;var t;var e=new Os((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef.classList.add(k.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),e.elementRef.onclick=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee89(){var s,i;return _regeneratorRuntime().wrap(function _callee89$(_context89){while(1)switch(_context89.prev=_context89.next){case 0:if(!e.isActive){_context89.next=4;break;}e.changeToDefault(),_this41.stop();_context89.next=30;break;case 4:_context89.prev=4;if(!_this41._ephemeralKey){_context89.next=11;break;}_this41.displayLoading();_context89.next=9;return _this41.init(_this41._ephemeralKey);case 9:_context89.next=25;break;case 11:if(!_this41._retrievingEphemeralKey){_context89.next=22;break;}_this41.displayLoading();_context89.next=15;return _this41._retrievingEphemeralKey;case 15:i=_context89.sent;_context89.t0=(s=_this41._toggleButton)!=null&&s.isActive;if(!_context89.t0){_context89.next=20;break;}_context89.next=20;return _this41.init(i);case 20:_context89.next=25;break;case 22:_this41.displayLoading();_context89.next=25;return _this41.fetchEphemeralKey(!0);case 25:_context89.next=30;break;case 27:_context89.prev=27;_context89.t1=_context89["catch"](4);console.error("Failed to start conversation:",_context89.t1),_this41.displayError(),_this41.hideLoading();case 30:case"end":return _context89.stop();}},_callee89,null,[[4,27]]);})),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee92(e){var _this42=this;var t,s,i,n,o,a,l,c;return _regeneratorRuntime().wrap(function _callee92$(_context92){while(1)switch(_context92.prev=_context92.next){case 0:t=new RTCPeerConnection();this._pc=t;s=document.createElement("audio");s.autoplay=!0;i=new AudioContext(),n=i.createAnalyser();n.fftSize=256;o=new Uint8Array(n.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref30=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee90(a){var l;return _regeneratorRuntime().wrap(function _callee90$(_context90){while(1)switch(_context90.prev=_context90.next){case 0:if(!a.streams[0]){_context90.next=11;break;}s.srcObject=a.streams[0];l=i.createMediaStreamSource(a.streams[0]);_context90.t0=i.state==="suspended";if(!_context90.t0){_context90.next=7;break;}_context90.next=7;return i.resume();case 7:l.connect(n);_this42.monitorFrequencies(n,o);_context90.next=12;break;case 11:console.error("No streams found in the ontrack event."),_this42.displayError();case 12:case"end":return _context90.stop();}},_callee90);}));return function(_x168){return _ref30.apply(this,arguments);};}();_context92.next=10;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var l;t===_this42._pc&&(_this42._mediaStream=a,(l=_this42._pc)==null||l.addTrack(_this42._mediaStream.getTracks()[0]),_this42._isMuted&&_this42.toggleMicorphone(!1));})["catch"](function(a){console.error("Error accessing microphone:",a),_this42.displayError();});case 10:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref31=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee91(a){var c,d,u,l,p,m,f;return _regeneratorRuntime().wrap(function _callee91$(_context91){while(1)switch(_context91.prev=_context91.next){case 0:l=JSON.parse(a.data);if(!(l.type==="session.created")){_context91.next=5;break;}_this42.removeUnavailable(),_this42._toggleButton&&(F.removeAriaAttributes(_this42._toggleButton.elementRef),_this42._toggleButton.changeToActive()),(d=(c=_this42._events)==null?void 0:c.started)==null||d.call(c),_this42._deepChat.dispatchEvent(new CustomEvent(Ps.SESSION_STARTED)),_this42.hideLoading();_context91.next=20;break;case 5:if(!(l.type==="response.done")){_context91.next=19;break;}p=(u=JSON.parse(a.data).response.output)==null?void 0:u[0];if(!((p==null?void 0:p.type)==="function_call")){_context91.next=17;break;}m=p.name,f=p.call_id;_context91.prev=9;_context91.next=12;return _this42.handleTool(m,p.arguments,f);case 12:_context91.next=17;break;case 14:_context91.prev=14;_context91.t0=_context91["catch"](9);_this42.stopOnError(_context91.t0);case 17:_context91.next=20;break;case 19:l.type==="error"?_this42.stopOnError(l.error.message):l.type==="invalid_request_error"?_this42.stopOnError(l.message):l.type;case 20:case"end":return _context91.stop();}},_callee91,null,[[9,14]]);}));return function(_x169){return _ref31.apply(this,arguments);};}());_context92.prev=12;_context92.next=15;return this._pc.createOffer();case 15:a=_context92.sent;_context92.t0=t!==this._pc;if(_context92.t0){_context92.next=21;break;}_context92.next=20;return this._pc.setLocalDescription(a);case 20:_context92.t0=t!==this._pc;case 21:if(!_context92.t0){_context92.next=23;break;}return _context92.abrupt("return");case 23:_context92.next=25;return fetch("https://api.openai.com/v1/realtime",{method:"POST",body:a.sdp,headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/sdp"}});case 25:l=_context92.sent;if(!(t!==this._pc)){_context92.next=28;break;}return _context92.abrupt("return");case 28:_context92.next=30;return l.text();case 30:_context92.t1=_context92.sent;c={type:"answer",sdp:_context92.t1};_context92.t2=t!==this._pc;if(_context92.t2){_context92.next=37;break;}_context92.next=36;return this._pc.setRemoteDescription(c);case 36:_context92.t2=t!==this._pc;case 37:if(!_context92.t2){_context92.next=39;break;}return _context92.abrupt("return");case 39:_context92.next=44;break;case 41:_context92.prev=41;_context92.t3=_context92["catch"](12);console.error(_context92.t3),this.displayError();case 44:case"end":return _context92.stop();}},_callee92,this,[[12,41]]);}));function init(_x167){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
|
179
|
+
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(e){return _regenerator().w(function(_context83){while(1)switch(_context83.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context83.n=1;return _.request(this,e,this._messages,!0,!0);case 1:this._messageStream=_context83.v;case 2:return _context83.a(2);}},_callee83,this);}));function createStreamRun(_x161){return _createStreamRun.apply(this,arguments);}return createStreamRun;}()}],[{key:"processImageMessage",value:function processImageMessage(e,t){var s=t==null?void 0:t.filter(function(i){return z.isImageFileExtension(i.name);}).map(function(i){return{type:"image_file",image_file:{file_id:i.id}};});if(s&&s.length>0)return e.text&&e.text.length>0&&s.push({type:"text",text:e.text}),{content:s,role:"user"};}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,s){return{attachments:t.map(function(n){return{tools:[{type:s}],file_id:n.id};}),content:[{type:"text",text:e.text}],role:"user"};}}]);}(I);$e.POLLING_TIMEOUT_MS=500;var Is=$e;var Fi=/*#__PURE__*/function(_Is){function Fi(e){var _a$headers,_l$OpenAIBeta;var _this34;_classCallCheck(this,Fi);var o,a,l,c,d;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.openAI,i=(o=t.openAI)==null?void 0:o.assistant,n=Fi.buildUrlSegments(i);if(_this34=_callSuper(this,Fi,[e,i,n,P.buildKeyVerificationDetails(),P.buildHeaders,s]),(_a$headers=(a=_this34.connectSettings).headers)!==null&&_a$headers!==void 0?_a$headers:a.headers={},(_l$OpenAIBeta=(l=_this34.connectSettings.headers)["OpenAI-Beta"])!==null&&_l$OpenAIBeta!==void 0?_l$OpenAIBeta:l["OpenAI-Beta"]="assistants=v2",_this34.shouldFetchHistory&&_this34.sessionId&&(_this34.fetchHistory=_this34.fetchHistoryFunc.bind(_assertThisInitialized(_this34))),_typeof(i)=="object"){var _ref26=(d=(c=e.directConnection)==null?void 0:c.openAI)==null?void 0:d.assistant,u=_ref26.function_handler,h=_ref26.files_tool_type;u&&(_this34.functionHandler=u),h&&(_this34.filesToolType=h);}return _this34;}_inherits(Fi,_Is);return _createClass(Fi,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||"https://api.openai.com/v1";return{threadsPrefix:"".concat(t,"/threads"),threadsPosfix:"",newAssistantUrl:"".concat(t,"/assistants"),createMessagePostfix:"",listMessagesPostfix:"order=desc",storeFiles:"".concat(t,"/files"),getFilesPrefix:"".concat(t,"/files/"),getFilesPostfix:"/content"};}}]);}(Is);var Wi=/*#__PURE__*/function(){function Wi(){_classCallCheck(this,Wi);}return _createClass(Wi,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"api-key":e,"Content-Type":"application/json"};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(e){return{url:"".concat(e.endpoint,"/openai/models?api-version=").concat(e.version),method:"GET",handleVerificationResult:P.handleVerificationResult};}},{key:"validateURLDetails",value:function validateURLDetails(e){var t=e.endpoint,s=e.version,i=e.deploymentId;return t&&s&&i;}}]);}();Wi.URL_DETAILS_ERROR_MESSAGE="Please define the Azure URL Details. [More Information](https://deepchat.dev/docs/directConnection/Azure)";var fe=Wi;var Et=/*#__PURE__*/function(_Is2){function Et(e){var _g$headers;var _this35;_classCallCheck(this,Et);var c,d,u,h,p,m,f,g;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.azure,i=(c=t.azure)==null?void 0:c.openAI,n=(i==null?void 0:i.urlDetails)||{},o="".concat((d=i==null?void 0:i.urlDetails)==null?void 0:d.endpoint,"/openai/"),a="?api-version=".concat((u=i==null?void 0:i.urlDetails)==null?void 0:u.version),l={threadsPrefix:"".concat(o).concat(Et.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(Et.NEW_ASSISTANT_RESOURCE).concat(a),createMessagePostfix:a,listMessagesPostfix:"order=desc&api-version=".concat((h=i==null?void 0:i.urlDetails)==null?void 0:h.version),storeFiles:"".concat(o,"files").concat(a),getFilesPrefix:"".concat(o,"files/"),getFilesPostfix:"/content".concat(a)};if(_this35=_callSuper(this,Et,[e,i==null?void 0:i.assistant,l,fe.buildKeyVerificationDetails(n),fe.buildHeaders,s]),_this35.permittedErrorPrefixes=[fe.URL_DETAILS_ERROR_MESSAGE],_this35.insertKeyPlaceholderText="Azure OpenAI API Key",_this35.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",_this35.isTextInputDisabled=!1,_typeof(i==null?void 0:i.assistant)=="object"){var _ref27=(f=(m=(p=e.directConnection)==null?void 0:p.azure)==null?void 0:m.openAI)==null?void 0:f.assistant,y=_ref27.function_handler,T=_ref27.files_tool_type;y&&(_this35.functionHandler=y),T&&(_this35.filesToolType=T);}fe.validateURLDetails(n)?(_g$headers=(g=_this35.connectSettings).headers)!==null&&_g$headers!==void 0?_g$headers:g.headers={}:(_this35.isTextInputDisabled=!0,_this35.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:fe.URL_DETAILS_ERROR_MESSAGE});}));return _this35;}_inherits(Et,_Is2);return _createClass(Et);}(Is);Et.THREAD_RESOURCE="threads",Et.NEW_ASSISTANT_RESOURCE="assistants";var _i=Et;var F=/*#__PURE__*/function(){function F(){_classCallCheck(this,F);}return _createClass(F,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){F.removeAriaBusy(e),F.removeAriaDisabled(e);}}]);}();var Jn="<?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",le=/*#__PURE__*/function(){function le(){_classCallCheck(this,le);}return _createClass(le,null,[{key:"createTextElement",value:function createTextElement(e){var t=document.createElement("div");return t.classList.add(le.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,s,i){s?e.push(Ve.createSVGElement(s)):s!==""&&i&&e.push(t);}},{key:"createCustomElements",value:function createCustomElements(e,t,s){var l,c;var i=s==null?void 0:s[e],n=(l=i==null?void 0:i.text)==null?void 0:l.content,o=(c=i==null?void 0:i.svg)==null?void 0:c.content,a=[];return le.tryAddSVGElement(a,t,o,n),n&&a.push(le.createTextElement(n)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e.classList.remove(le.INPUT_BUTTON_SVG_CLASS,le.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(s){return s.classList.contains(le.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e.classList.add(le.INPUT_BUTTON_SVG_TEXT_CLASS):e.classList.add(le.INPUT_BUTTON_SVG_CLASS);}}]);}();le.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",le.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",le.INPUT_BUTTON_SVG_CLASS="input-button-svg";var ke=le;var Xt=/*#__PURE__*/function(){function Xt(){_classCallCheck(this,Xt);}return _createClass(Xt,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return{svg:e.find(function(t){return t.tagName.toLowerCase()==="svg";}),text:e.find(function(t){return t.tagName.toLowerCase()==="div";})};}}]);}();var j=/*#__PURE__*/function(){function j(){_classCallCheck(this,j);}return _createClass(j,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var n,o;t.container&&N.unsetAllCSSMouseStates(e,t.container);var _Xt$parseSVGTextEleme=Xt.parseSVGTextElements(Array.from(e.children)),s=_Xt$parseSVGTextEleme.svg,i=_Xt$parseSVGTextEleme.text;(n=t.svg)!=null&&n.styles&&s&&N.unsetAllCSSMouseStates(s,t.svg.styles),(o=t.text)!=null&&o.styles&&i&&N.unsetAllCSSMouseStates(i,t.text.styles);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var n,o;t.container&&N.unsetActivityCSSMouseStates(e,t.container);var _Xt$parseSVGTextEleme2=Xt.parseSVGTextElements(Array.from(e.children)),s=_Xt$parseSVGTextEleme2.svg,i=_Xt$parseSVGTextEleme2.text;(n=t.svg)!=null&&n.styles&&s&&N.unsetActivityCSSMouseStates(s,t.svg.styles),(o=t.text)!=null&&o.styles&&i&&N.unsetActivityCSSMouseStates(i,t.text.styles);}},{key:"setElementsCSS",value:function setElementsCSS(e,t,s){var o,a,l,c,d;Object.assign(e.style,(o=t.container)==null?void 0:o[s]);var _Xt$parseSVGTextEleme3=Xt.parseSVGTextElements(Array.from(e.children)),i=_Xt$parseSVGTextEleme3.svg,n=_Xt$parseSVGTextEleme3.text;i&&Object.assign(i.style,(l=(a=t.svg)==null?void 0:a.styles)==null?void 0:l[s]),n&&Object.assign(n.style,(d=(c=t.text)==null?void 0:c.styles)==null?void 0:d[s]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,s){j.setElementsCSS(e,t,"default"),s!=="default"&&(j.setElementsCSS(e,t,"hover"),s!=="hover"&&j.setElementsCSS(e,t,"click"));}}]);}();var mt=/*#__PURE__*/function(){// prettier-ignore
|
180
|
+
function mt(e,t,s,i,n,o){_classCallCheck(this,mt);this._mouseState={state:"default"},this.isCustom=!1,F.addAttributes(e),this.elementRef=e,this.svg=Ve.createSVGElement(t),this.customStyles=n,this.position=s,this._tooltipSettings=i,this.dropupText=o;}return _createClass(mt,[{key:"buttonMouseLeave",value:function buttonMouseLeave(e){var t;this._mouseState.state="default",((t=this._activeTooltip)==null?void 0:t.element.style.visibility)==="visible"&&this._tooltipSettings&&Se.hide(this._activeTooltip,this._tooltipSettings),e&&(j.unsetAllCSS(this.elementRef,e),j.setElementsCSS(this.elementRef,e,"default"));}},{key:"buttonMouseEnter",value:function buttonMouseEnter(e){var t;this._mouseState.state="hover",this._tooltipSettings&&(this._activeTooltip=Se.display(this.elementRef,this._tooltipSettings,(t=this._activeTooltip)==null?void 0:t.element)),e&&j.setElementsCSS(this.elementRef,e,"hover");}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&j.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state="click",e&&j.setElementsCSS(this.elementRef,e,"click");}// be careful not to use onclick as that is used for button functionality
|
181
|
+
},{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 _s2=e[t],i=_s2&&this.customStyles[_s2];i&&j.unsetActionCSS(this.elementRef,i);}}},{key:"reapplyStateStyle",value:function reapplyStateStyle(e,t){if(!this.customStyles)return;t&&this.unsetCustomStateStyles(t);var s=this.customStyles[e];s&&j.setElementCssUpToState(this.elementRef,s,this._mouseState.state),this.setEvents(s);}},{key:"changeElementsByState",value:function changeElementsByState(e){var _this$elementRef;(_this$elementRef=this.elementRef).replaceChildren.apply(_this$elementRef,_toConsumableArray(e)),ke.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,s){var i=ke.createCustomElements(t,this.svg,s);if(i&&i.length>0){if(this.position==="dropup-menu"){var n=this.svg.cloneNode(!0);n.id=i[0]===this.svg?e:"dropup-menu-item-icon-element-custom",i[0]=n;}return i;}return this.buildDefaultIconElement(e);}}]);}();var Zs=/*#__PURE__*/function(_mt){function Zs(e){var _this36;_classCallCheck(this,Zs);var s,i;var t=((i=(s=e==null?void 0:e["default"])==null?void 0:s.svg)==null?void 0:i.content)||Zs.EMPTY_SVG;_this36=_callSuper(this,Zs,[document.createElement("div"),t,void 0,void 0,e]),_this36.isActive=!1,_this36._innerElements=_this36.createInnerElementsForStates(_this36.customStyles),_this36.changeToDefault();return _this36;}_inherits(Zs,_mt);return _createClass(Zs,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{"default":this.createInnerButtonElements("default",e),active:this.createInnerButtonElements("active",e),unavailable:this.createInnerButtonElements("unavailable",e)};}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return ke.createCustomElements(e,this.svg,t)||[this.svg];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef.classList.replace(ke.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements.active),this.reapplyStateStyle("active",["unavailable","default"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,s,i;this.changeState(this._innerElements["default"]),(e=this.customStyles)!=null&&e.active&&j.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(s=this.customStyles)!=null&&s.unavailable&&j.unsetAllCSS(this.elementRef,(i=this.customStyles)==null?void 0:i.unavailable),this.reapplyStateStyle("default",["active","unavailable"]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,s,i;this.changeState(this._innerElements.unavailable),(e=this.customStyles)!=null&&e.active&&j.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(s=this.customStyles)!=null&&s["default"]&&j.unsetAllCSS(this.elementRef,(i=this.customStyles)==null?void 0:i["default"]),this.reapplyStateStyle("unavailable",["default","active"]),this.isActive=!1;}}]);}(mt);Zs.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var Os=Zs;var $=/*#__PURE__*/function(){function $(){_classCallCheck(this,$);}return _createClass($,null,[{key:"setPropertyValueIfDoesNotExist",value:function setPropertyValueIfDoesNotExist(e,t,s){var _e$i,_e$i2;var i=t[0];t.length===1?(_e$i=e[i])!==null&&_e$i!==void 0?_e$i:e[i]=s:((_e$i2=e[i])!==null&&_e$i2!==void 0?_e$i2:e[i]={},t.shift(),$.setPropertyValueIfDoesNotExist(e[i],t,s));}},{key:"setPropertyValue",value:function setPropertyValue(e,t,s){var _e$i3;var i=t[0];t.length===1?e[i]=s:((_e$i3=e[i])!==null&&_e$i3!==void 0?_e$i3:e[i]={},t.shift(),$.setPropertyValue(e[i],t,s));}},{key:"getObjectValue",value:function getObjectValue(e,t){var s=t[0],i=e[s];return i===void 0||t.length===1?i:$.getObjectValue(i,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,s){var i=$.getObjectValue(t,s);if(i){var n=_objectSpread(_objectSpread({},i),$.getObjectValue(e,s)||{});$.setPropertyValue(e,s,n);}}},{key:"isJson",value:function isJson(e){try{return JSON.stringify(e),!0;}catch(_unused8){return!1;}}// prettier-ignore
|
182
|
+
},{key:"assignPropertyFromOneToAnother",value:function assignPropertyFromOneToAnother(e,t,s){var _t$e;(_t$e=t[e])!==null&&_t$e!==void 0?_t$e:t[e]={},Object.assign(t[e],s==null?void 0:s[e]);}}]);}();var Qs=/*#__PURE__*/_createClass(function Qs(){_classCallCheck(this,Qs);});Qs.SESSION_STARTED="sts-session-started",Qs.SESSION_STOPPED="sts-session-stopped";var Ns=Qs;var Xn="<?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>",Si="<?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>",k=/*#__PURE__*/function(_I4){function k(e){var _l$model;var _this37;_classCallCheck(this,k);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=k.getKey(e);_this37=_callSuper(this,k,[e,P.buildKeyVerificationDetails(),P.buildHeaders,{key:s}]),_this37.insertKeyPlaceholderText="OpenAI API Key",_this37.keyHelpUrl="https://platform.openai.com/account/api-keys",_this37._microphoneButton=null,_this37._toggleButton=null,_this37._errorElement=null,_this37._loadingElement=null,_this37._pc=null,_this37._mediaStream=null,_this37._isMuted=!1;var i=(n=t.openAI)==null?void 0:n.realtime;if(_typeof(i)=="object"){_this37._avatarConfig=i.avatar,_this37._ephemeralKey=i.ephemeralKey,_this37._errorConfig=i.error,_this37._loadingConfig=i.loading,Object.assign(_this37.rawBody,i.config);var c=(a=(o=e.directConnection)==null?void 0:o.openAI)==null?void 0:a.realtime,_ref28=c.config||{},d=_ref28.function_handler;d&&(_this37._functionHandler=d),_this37._events=i.events,c.methods=_this37.generateMethods();}(_l$model=(l=_this37.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="gpt-4o-realtime-preview-2025-06-03",_this37._avatarConfig=k.buildAvatarConfig(i),_this37._buttonsConfig=k.buildButtonsConfig(i),_this37._avatarEl=k.createAvatar(_this37._avatarConfig),_this37._containerEl=_this37.createContainer(),_this37._deepChat=e;return _this37;}_inherits(k,_I4);return _createClass(k,[{key:"setUpView",value:// called after API key was inserted
|
183
|
+
function setUpView(e,t){e.style.display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(){var i,e,t,s;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:e=(i=this._deepChat.directConnection)==null?void 0:i.openAI;if(e){_context84.n=1;break;}return _context84.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context84.n=2;break;}return _context84.a(2);case 2:s=this.key||e.key;(t.fetchEphemeralKey||s)&&t.autoStart&&(this.changeToUnavailable(),this.displayLoading()),this.fetchEphemeralKey(t.autoStart);case 3:return _context84.a(2);}},_callee84,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var o,t,s,i,n,a,_t26,_t27,_t28;return _regenerator().w(function(_context85){while(1)switch(_context85.p=_context85.n){case 0:t=(o=this._deepChat.directConnection)==null?void 0:o.openAI,s=_typeof(t==null?void 0:t.realtime)=="object"?t==null?void 0:t.realtime.fetchEphemeralKey:void 0,i=t==null?void 0:t.realtime,n=this.key||t.key;if(!(_typeof(i)=="object")){_context85.n=8;break;}if(this._ephemeralKey){_context85.n=7;break;}_context85.p=1;if(!s){_context85.n=3;break;}a=s();a.then&&(this._retrievingEphemeralKey=a);_context85.n=2;return a;case 2:this._ephemeralKey=_context85.v;_context85.n=5;break;case 3:_t26=n;if(!_t26){_context85.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(n);_context85.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context85.v;case 5:_context85.n=7;break;case 6:_context85.p=6;_t27=_context85.v;this.displayFailedToRetrieveEphemeralKey(_t27);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context85.n=12;break;case 8:if(!n){_context85.n=12;break;}_context85.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(n);_context85.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context85.v;e&&this.init(this._ephemeralKey);_context85.n=12;break;case 11:_context85.p=11;_t28=_context85.v;this.displayFailedToRetrieveEphemeralKey(_t28);case 12:return _context85.a(2);}},_callee85,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x162){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){return _regenerator().w(function(_context86){while(1)switch(_context86.n){case 0:_context86.n=1;return fetch("https://api.openai.com/v1/realtime/sessions",{method:"POST",body:JSON.stringify(this.rawBody),headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)}});case 1:_context86.n=2;return _context86.v.json();case 2:return _context86.a(2,_context86.v.client_secret.value);}},_callee86,this);}));function getEphemeralKey(_x163){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this38=this;return{updateConfig:function updateConfig(e){var t;(t=_this38._dc)==null||t.send(JSON.stringify({type:"session.update",session:e}));},sendMessage:function sendMessage(e,t){var s=t||"system",n={role:s,type:"message",content:[{type:s==="system"||s==="user"?"input_text":"text",text:e}]};_this38.sendMessage(n);}};}},{key:"createContainer",value:function createContainer(){var e=document.createElement("div");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,s;var e=document.createElement("div");return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e.style,(s=(t=this._avatarConfig)==null?void 0:t.styles)==null?void 0:s.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var i;var e=document.createElement("div");e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e.style,(i=this._buttonsConfig)==null?void 0:i.container),this._microphoneButton=this.createMicophoneButton();var t=k.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var s=k.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(s),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this39=this;var t;var e=new Os((t=this._buttonsConfig)==null?void 0:t.microphone);return e.elementRef.classList.add(k.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),e.elementRef.onclick=function(){e.isActive?(_this39.toggleMicorphone(!0),e.elementRef.classList.replace(k.MICROPHONE_ACTIVE,k.BUTTON_DEFAULT),e.changeToDefault(),_this39._isMuted=!1):(_this39.toggleMicorphone(!1),e.elementRef.classList.replace(k.BUTTON_DEFAULT,k.MICROPHONE_ACTIVE),F.removeAriaAttributes(e.elementRef),e.changeToActive(),_this39._isMuted=!0);},e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(s){return s.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this40=this;var t;var e=new Os((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef.classList.add(k.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),e.elementRef.onclick=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(){var s,i,_t29,_t30;return _regenerator().w(function(_context87){while(1)switch(_context87.p=_context87.n){case 0:if(!e.isActive){_context87.n=1;break;}e.changeToDefault(),_this40.stop();_context87.n=9;break;case 1:_context87.p=1;if(!_this40._ephemeralKey){_context87.n=3;break;}_this40.displayLoading();_context87.n=2;return _this40.init(_this40._ephemeralKey);case 2:_context87.n=7;break;case 3:if(!_this40._retrievingEphemeralKey){_context87.n=6;break;}_this40.displayLoading();_context87.n=4;return _this40._retrievingEphemeralKey;case 4:i=_context87.v;_t29=(s=_this40._toggleButton)!=null&&s.isActive;if(!_t29){_context87.n=5;break;}_context87.n=5;return _this40.init(i);case 5:_context87.n=7;break;case 6:_this40.displayLoading();_context87.n=7;return _this40.fetchEphemeralKey(!0);case 7:_context87.n=9;break;case 8:_context87.p=8;_t30=_context87.v;console.error("Failed to start conversation:",_t30),_this40.displayError(),_this40.hideLoading();case 9:return _context87.a(2);}},_callee87,null,[[1,8]]);})),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var _this41=this;var t,s,i,n,o,a,l,c,_t33,_t34,_t35,_t36;return _regenerator().w(function(_context90){while(1)switch(_context90.p=_context90.n){case 0:t=new RTCPeerConnection();this._pc=t;s=document.createElement("audio");s.autoplay=!0;i=new AudioContext(),n=i.createAnalyser();n.fftSize=256;o=new Uint8Array(n.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(a){var l,_t31;return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:if(!a.streams[0]){_context88.n=2;break;}s.srcObject=a.streams[0];l=i.createMediaStreamSource(a.streams[0]);_t31=i.state==="suspended";if(!_t31){_context88.n=1;break;}_context88.n=1;return i.resume();case 1:l.connect(n);_this41.monitorFrequencies(n,o);_context88.n=3;break;case 2:console.error("No streams found in the ontrack event."),_this41.displayError();case 3:return _context88.a(2);}},_callee88);}));return function(_x165){return _ref30.apply(this,arguments);};}();_context90.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var l;t===_this41._pc&&(_this41._mediaStream=a,(l=_this41._pc)==null||l.addTrack(_this41._mediaStream.getTracks()[0]),_this41._isMuted&&_this41.toggleMicorphone(!1));})["catch"](function(a){console.error("Error accessing microphone:",a),_this41.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(a){var c,d,u,l,p,m,f,_t32;return _regenerator().w(function(_context89){while(1)switch(_context89.p=_context89.n){case 0:l=JSON.parse(a.data);if(!(l.type==="session.created")){_context89.n=1;break;}_this41.removeUnavailable(),_this41._toggleButton&&(F.removeAriaAttributes(_this41._toggleButton.elementRef),_this41._toggleButton.changeToActive()),(d=(c=_this41._events)==null?void 0:c.started)==null||d.call(c),_this41._deepChat.dispatchEvent(new CustomEvent(Ns.SESSION_STARTED)),_this41.hideLoading();_context89.n=7;break;case 1:if(!(l.type==="response.done")){_context89.n=6;break;}p=(u=JSON.parse(a.data).response.output)==null?void 0:u[0];if(!((p==null?void 0:p.type)==="function_call")){_context89.n=5;break;}m=p.name,f=p.call_id;_context89.p=2;_context89.n=3;return _this41.handleTool(m,p.arguments,f);case 3:_context89.n=5;break;case 4:_context89.p=4;_t32=_context89.v;_this41.stopOnError(_t32);case 5:_context89.n=7;break;case 6:l.type==="error"?_this41.stopOnError(l.error.message):l.type==="invalid_request_error"?_this41.stopOnError(l.message):l.type;case 7:return _context89.a(2);}},_callee89,null,[[2,4]]);}));return function(_x166){return _ref31.apply(this,arguments);};}());_context90.p=2;_context90.n=3;return this._pc.createOffer();case 3:a=_context90.v;_t33=t!==this._pc;if(_t33){_context90.n=5;break;}_context90.n=4;return this._pc.setLocalDescription(a);case 4:_t33=t!==this._pc;case 5:if(!_t33){_context90.n=6;break;}return _context90.a(2);case 6:_context90.n=7;return fetch("https://api.openai.com/v1/realtime",{method:"POST",body:a.sdp,headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/sdp"}});case 7:l=_context90.v;if(!(t!==this._pc)){_context90.n=8;break;}return _context90.a(2);case 8:_context90.n=9;return l.text();case 9:_t34=_context90.v;c={type:"answer",sdp:_t34};_t35=t!==this._pc;if(_t35){_context90.n=11;break;}_context90.n=10;return this._pc.setRemoteDescription(c);case 10:_t35=t!==this._pc;case 11:if(!_t35){_context90.n=12;break;}return _context90.a(2);case 12:_context90.n=14;break;case 13:_context90.p=13;_t36=_context90.v;console.error(_t36),this.displayError();case 14:return _context90.a(2);}},_callee90,this,[[2,13]]);}));function init(_x164){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
|
181
184
|
// in such instance please wait and refresh at a later time
|
182
|
-
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var
|
183
|
-
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/
|
184
|
-
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify({type:"conversation.item.create",item:e});this._dc.send(t);var s={type:"response.create"};this._dc.send(JSON.stringify(s));}},{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 s=t==null?void 0:t.realtime;if(_typeof(s)=="object"&&(s.ephemeralKey||s.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$microphone,_o$default,_a$svg,_l$content,_t$toggle,_h$default,_p$svg,_m$content,_f$active,_g$svg,_y$content;var s,i,n,o,a,l,c,d,u,h,p,m,f,g,y;var t=_typeof(e)=="object"&&e.buttons?JSON.parse(JSON.stringify(e.buttons)):{};return(n=(i=(s=t.microphone)==null?void 0:s["default"])==null?void 0:i.text)!=null&&n.content||((_t$microphone=t.microphone)!==null&&_t$microphone!==void 0?_t$microphone:t.microphone={},(_o$default=(o=t.microphone)["default"])!==null&&_o$default!==void 0?_o$default:o["default"]={},(_a$svg=(a=t.microphone["default"]).svg)!==null&&_a$svg!==void 0?_a$svg:a.svg={},(_l$content=(l=t.microphone["default"].svg).content)!==null&&_l$content!==void 0?_l$content:l.content=
|
185
|
-
},{key:"callServiceAPI",value:function(){var
|
185
|
+
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this42=this;var s=function(_s3){function s(){return _s3.apply(this,arguments);}s.toString=function(){return _s3.toString();};return s;}(function(){var c;e.getByteFrequencyData(t);var i=t.reduce(function(d,u){return d+u;},0),n=t.length*255,o=i/n*100,a=1,l=a+o/100*(((c=_this42._avatarConfig)==null?void 0:c.maxScale)-a);_this42._avatarEl.style.transform="scale(".concat(l,")"),requestAnimationFrame(s);});s();}},{key:"stopOnError",value:function stopOnError(e){this.stop(),console.error(e),this.displayError();}},{key:"stop",value:function stop(){var e,t,s;(e=this._mediaStream)==null||e.getTracks().forEach(function(i){return i.stop();}),this._mediaStream=null,this._pc&&(this._pc.close(),this._pc=null,(s=(t=this._events)==null?void 0:t.stopped)==null||s.call(t),this._deepChat.dispatchEvent(new CustomEvent(Ns.SESSION_STOPPED)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&k.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&k.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&k.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&k.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&k.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&k.removeButtonUnavailable(this._toggleButton);}},{key:"createError",value:function createError(){var t;var e=document.createElement("div");return e.id="deep-chat-openai-realtime-error",Object.assign(e.style,(t=this._errorConfig)==null?void 0:t.style),this._errorElement=e,e;}},{key:"displayFailedToRetrieveEphemeralKey",value:function displayFailedToRetrieveEphemeralKey(e){console.error("Failed to retrieve ephemeral key"),console.error(e),this.displayError();}},{key:"displayError",value:function displayError(){var e;this._errorElement&&(this._errorElement.style.display="block",this._errorElement.textContent=((e=this._errorConfig)==null?void 0:e.text)||"Error",this.changeToUnavailable()),this.hideLoading();}},{key:"createLoading",value:function createLoading(){var t,s;var e=document.createElement("div");return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t.html&&(this._loadingElement.innerHTML=this._loadingConfig.html),Object.assign(e.style,(s=this._loadingConfig)==null?void 0:s.style),e.style.display="none",e;}},{key:"displayLoading",value:function displayLoading(){var e,t,s;this._toggleButton&&(this._toggleButton.changeToActive(),this._toggleButton.elementRef.classList.add(k.BUTTON_LOADING),F.removeAriaDisabled(this._toggleButton.elementRef),F.addAriaBusy(this._toggleButton.elementRef)),(typeof((e=this._loadingConfig)==null?void 0:e.display)!="boolean"||this._loadingConfig.display)&&this._loadingElement&&(this._loadingElement.style.display="block",(t=this._loadingConfig)!=null&&t.html||(this._loadingElement.textContent=((s=this._loadingConfig)==null?void 0:s.text)||"Loading"));}},{key:"hideLoading",value:function hideLoading(){this._toggleButton&&(this._toggleButton.elementRef.classList.remove(k.BUTTON_LOADING),F.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement.style.display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
|
186
|
+
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e,t,s){var i,n;return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:if(this._functionHandler){_context91.n=1;break;}throw Error("Please define the `function_handler` property inside the [openAI](https://deepchat.dev/docs/directConnection/OpenAI/OpenAIRealtime#OpenAIRealtimeFunction) object.");case 1:_context91.n=2;return this._functionHandler({name:e,arguments:t});case 2:i=_context91.v;if(!(_typeof(i)!="object"||!$.isJson(i))){_context91.n=3;break;}throw Error('The `function_handler` response must be a JSON object, e.g. {response: "My response"}');case 3:n={type:"function_call_output",call_id:s,output:JSON.stringify(i)};this.sendMessage(n);case 4:return _context91.a(2);}},_callee91,this);}));function handleTool(_x167,_x168,_x169){return _handleTool.apply(this,arguments);}return handleTool;}()// https://platform.openai.com/docs/api-reference/realtime-client-events/conversation/item/create
|
187
|
+
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify({type:"conversation.item.create",item:e});this._dc.send(t);var s={type:"response.create"};this._dc.send(JSON.stringify(s));}},{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 s=t==null?void 0:t.realtime;if(_typeof(s)=="object"&&(s.ephemeralKey||s.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$microphone,_o$default,_a$svg,_l$content,_t$toggle,_h$default,_p$svg,_m$content,_f$active,_g$svg,_y$content;var s,i,n,o,a,l,c,d,u,h,p,m,f,g,y;var t=_typeof(e)=="object"&&e.buttons?JSON.parse(JSON.stringify(e.buttons)):{};return(n=(i=(s=t.microphone)==null?void 0:s["default"])==null?void 0:i.text)!=null&&n.content||((_t$microphone=t.microphone)!==null&&_t$microphone!==void 0?_t$microphone:t.microphone={},(_o$default=(o=t.microphone)["default"])!==null&&_o$default!==void 0?_o$default:o["default"]={},(_a$svg=(a=t.microphone["default"]).svg)!==null&&_a$svg!==void 0?_a$svg:a.svg={},(_l$content=(l=t.microphone["default"].svg).content)!==null&&_l$content!==void 0?_l$content:l.content=Jn),(u=(d=(c=t.toggle)==null?void 0:c["default"])==null?void 0:d.text)!=null&&u.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_h$default=(h=t.toggle)["default"])!==null&&_h$default!==void 0?_h$default:h["default"]={},(_p$svg=(p=t.toggle["default"]).svg)!==null&&_p$svg!==void 0?_p$svg:p.svg={},(_m$content=(m=t.toggle["default"].svg).content)!==null&&_m$content!==void 0?_m$content:m.content=Xn,(_f$active=(f=t.toggle).active)!==null&&_f$active!==void 0?_f$active:f.active={},(_g$svg=(g=t.toggle.active).svg)!==null&&_g$svg!==void 0?_g$svg:g.svg={},(_y$content=(y=t.toggle.active.svg).content)!==null&&_y$content!==void 0?_y$content:y.content=Si),t;}},{key:"createAvatar",value:function createAvatar(e){var s;var t=document.createElement("img");return t.id="deep-chat-openai-realtime-avatar",Object.assign(t.style,(s=e==null?void 0:e.styles)==null?void 0:s.image),t.src=(e==null?void 0:e.src)||yi,t;}},{key:"createButtonContainer",value:function createButtonContainer(e){var t=document.createElement("div");return t.classList.add("deep-chat-openai-realtime-button-container"),t.appendChild(e),t;}},{key:"changeButtonToUnavailable",value:function changeButtonToUnavailable(e){e.elementRef.classList.add(k.UNAVAILABLE),F.removeAriaBusy(e.elementRef),F.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){k.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){F.removeAriaDisabled(e.elementRef),e.elementRef.classList.remove(k.UNAVAILABLE);}}]);}(I);k.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",k.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",k.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",k.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var xi=k;var _t=/*#__PURE__*/function(_I5){function _t(e){var _o$model,_a$voice;var _this43;_classCallCheck(this,_t);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this43=_callSuper(this,_t,[e,P.buildKeyVerificationDetails(),P.buildHeaders,s]),_this43.insertKeyPlaceholderText="OpenAI API Key",_this43.keyHelpUrl="https://platform.openai.com/account/api-keys",_this43.url="https://api.openai.com/v1/audio/speech",_this43.permittedErrorPrefixes=["Invalid"],_this43.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI : Text To Speech</b></div>\n <p>Generate an audio file based on your text input.</p>\n <p>Click <a href=\"https://platform.openai.com/docs/guides/text-to-speech\" target=\"_blank\">here</a>\n for more information.</p>";var i=(n=t==null?void 0:t.openAI)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&Object.assign(_this43.rawBody,i),(_o$model=(o=_this43.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model=_t.DEFAULT_MODEL,(_a$voice=(a=_this43.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice=_t.DEFAULT_VOIDE,_this43.textInputPlaceholderText="Insert text to generate audio",_this43.rawBody.response_format="mp3";return _this43;}_inherits(_t,_I5);return _createClass(_t,[{key:"preprocessBody",value:function preprocessBody(e,t){var n,o;var s=JSON.parse(JSON.stringify(e)),i=(o=(n=t[t.length-1])==null?void 0:n.text)==null?void 0:o.trim();return i&&i!==""&&(s.input=i),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(e,t){var i,s;return _regenerator().w(function(_context92){while(1)switch(_context92.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context92.n=1;break;}throw new Error("Request settings have not been set up");case 1:this.url=this.connectSettings.url||this.url;s=this.preprocessBody(this.rawBody,t);R.request(this,s,e);case 2:return _context92.a(2);}},_callee92,this);}));function callServiceAPI(_x170,_x171){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(e){return _regenerator().w(function(_context93){while(1)switch(_context93.n){case 0:if(!(e instanceof Blob)){_context93.n=1;break;}return _context93.a(2,new Promise(function(t){var s=new FileReader();s.readAsDataURL(e),s.onload=function(i){t({files:[{src:i.target.result,type:"audio"}]});};}));case 1:if(!e.error){_context93.n=2;break;}throw e.error.message;case 2:return _context93.a(2,{error:"error"});}},_callee93);}));function extractResultData(_x172){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(I);_t.DEFAULT_MODEL="tts-1",_t.DEFAULT_VOIDE="alloy";var wi=_t;var be=/*#__PURE__*/function(_I6){function be(e){var _o$model2;var _this44;_classCallCheck(this,be);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this44=_callSuper(this,be,[e,P.buildKeyVerificationDetails(),P.buildHeaders,s,{audio:{}}]),_this44.insertKeyPlaceholderText="OpenAI API Key",_this44.keyHelpUrl="https://platform.openai.com/account/api-keys",_this44.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI : Speech To Text</b></div>\n <p><b>Upload an audio file</b> to transcribe it into text. You can optionally provide text to guide the audio\n processing.\n <p>Click <a href=\"https://platform.openai.com/docs/guides/speech-to-text\" target=\"_blank\">here</a> for more info.</p>",_this44.url="",_this44.permittedErrorPrefixes=["Invalid"],_this44.textInputPlaceholderText="Upload an audio file",_this44._service_url=be.AUDIO_TRANSCRIPTIONS_URL;var i=(n=t==null?void 0:t.openAI)==null?void 0:n.audio;_typeof(i)=="object"&&(_this44.processConfig(i),be.cleanConfig(i),Object.assign(_this44.rawBody,i)),(_o$model2=(o=_this44.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model=be.DEFAULT_MODEL,_this44.rawBody.response_format="json",_this44.canSendMessage=be.canSendFileMessage;return _this44;}_inherits(be,_I6);return _createClass(be,[{key:"processConfig",value:function processConfig(e){e!=null&&e.type&&e.type==="translation"&&(this._service_url=be.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var n,o;var s=JSON.parse(JSON.stringify(e)),i=(o=(n=t[t.length-1])==null?void 0:n.text)==null?void 0:o.trim();return i&&i!==""&&(s.prompt=i),s;}// prettier-ignore
|
188
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(e,t,s){var o,i,n;return _regenerator().w(function(_context94){while(1)switch(_context94.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context94.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context94.n=2;break;}throw new Error("No file was added");case 2:this.url=this.connectSettings.url||this._service_url;i=this.preprocessBody(this.rawBody,t),n=be.createFormDataBody(i,s[0]);E.tempRemoveContentHeader(this.connectSettings,R.request.bind(this,this,n,e),!1);case 3:return _context94.a(2);}},_callee94,this);}));function callServiceAPI(_x173,_x174,_x175){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(e){return _regenerator().w(function(_context95){while(1)switch(_context95.n){case 0:if(!e.error){_context95.n=1;break;}throw e.error.message;case 1:return _context95.a(2,{text:e.text});}},_callee95);}));function extractResultData(_x176){return _extractResultData12.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 s=new FormData();return s.append("file",t),Object.keys(e).forEach(function(i){s.append(i,String(e[i]));}),s;}}]);}(I);be.AUDIO_TRANSCRIPTIONS_URL="https://api.openai.com/v1/audio/transcriptions",be.AUDIO_TRANSLATIONS_URL="https://api.openai.com/v1/audio/translations",be.DEFAULT_MODEL="whisper-1";var Ai=be;var me=/*#__PURE__*/function(){function me(){_classCallCheck(this,me);}return _createClass(me,null,[{key:"buildTextToSpeechHeaders",value:function buildTextToSpeechHeaders(e,t){return{"Ocp-Apim-Subscription-Key":t,"Content-Type":"application/ssml+xml","X-Microsoft-OutputFormat":e};}},{key:"buildSpeechToTextHeaders",value:function buildSpeechToTextHeaders(e){return{"Ocp-Apim-Subscription-Key":e,Accept:"application/json"};}// prettier-ignore
|
186
189
|
},{key:"handleSpeechVerificationResult",value:function handleSpeechVerificationResult(e,t,s,i){e.error?i(C.INVALID_KEY):s(t);}},{key:"buildSpeechKeyVerificationDetails",value:function buildSpeechKeyVerificationDetails(e){return{url:"https://".concat(e,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:"POST",createHeaders:function createHeaders(t){return{"Ocp-Apim-Subscription-Key":"".concat(t)};},handleVerificationResult:me.handleSpeechVerificationResult};}},{key:"buildSummarizationHeader",value:function buildSummarizationHeader(e){return{"Ocp-Apim-Subscription-Key":e,"Content-Type":"application/json"};}// prettier-ignore
|
187
190
|
},{key:"handleLanguageVerificationResult",value:function handleLanguageVerificationResult(e,t,s,i){var o;((o=e.error)==null?void 0:o.code)==="401"?i(C.INVALID_KEY):s(t);}},{key:"buildLanguageKeyVerificationDetails",value:function buildLanguageKeyVerificationDetails(e){return{url:"".concat(e,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:"POST",createHeaders:function createHeaders(t){return{"Ocp-Apim-Subscription-Key":"".concat(t)};},handleVerificationResult:me.handleLanguageVerificationResult};}// prettier-ignore
|
188
|
-
},{key:"handleTranslationVerificationResult",value:function handleTranslationVerificationResult(e,t,s,i){e.json().then(function(o){!Array.isArray(o)&&o.error.code===401e3?i(C.INVALID_KEY):s(t);});}},{key:"buildTranslationKeyVerificationDetails",value:function buildTranslationKeyVerificationDetails(e){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:"POST",createHeaders:function createHeaders(t){return me.buildTranslationHeaders(e,t);},handleVerificationResult:me.handleTranslationVerificationResult};}},{key:"buildTranslationHeaders",value:function buildTranslationHeaders(e,t){var s={"Ocp-Apim-Subscription-Key":t,"Content-Type":"application/json"};return e&&(s["Ocp-Apim-Subscription-Region"]=e),s;}}]);}();var
|
189
|
-
function
|
190
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",
|
191
|
-
"Please define the azure endpoint. [More Information](https://deepchat.dev/docs/directConnection/Azure#Summarization)";var
|
192
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.assemblyai.com/v2/upload",method:"POST",handleVerificationResult:Yt.handleVerificationResult};}}]);}();var
|
193
|
-
function
|
194
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal";return
|
195
|
-
function
|
196
|
-
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",
|
197
|
-
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#TextToSpeech)";var
|
191
|
+
},{key:"handleTranslationVerificationResult",value:function handleTranslationVerificationResult(e,t,s,i){e.json().then(function(o){!Array.isArray(o)&&o.error.code===401e3?i(C.INVALID_KEY):s(t);});}},{key:"buildTranslationKeyVerificationDetails",value:function buildTranslationKeyVerificationDetails(e){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:"POST",createHeaders:function createHeaders(t){return me.buildTranslationHeaders(e,t);},handleVerificationResult:me.handleTranslationVerificationResult};}},{key:"buildTranslationHeaders",value:function buildTranslationHeaders(e,t){var s={"Ocp-Apim-Subscription-Key":t,"Content-Type":"application/json"};return e&&(s["Ocp-Apim-Subscription-Region"]=e),s;}}]);}();var fa=/*#__PURE__*/function(_I7){// prettier-ignore
|
192
|
+
function fa(e,t,s,i,n){var _this45;_classCallCheck(this,fa);_this45=_callSuper(this,fa,[e,me.buildLanguageKeyVerificationDetails(s),t,i,n]),_this45.insertKeyPlaceholderText="Azure Language Subscription Key",_this45.keyHelpUrl=// eslint-disable-next-line max-len
|
193
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this45.permittedErrorPrefixes=["Access"];return _this45;}_inherits(fa,_I7);return _createClass(fa);}(I);var ss=/*#__PURE__*/function(_fa){function ss(e){var _a$language;var _this46;_classCallCheck(this,ss);var i,n,o,a;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.summarization,s=(o=e.directConnection)==null?void 0:o.azure;_this46=_callSuper(this,ss,[e,me.buildSummarizationHeader,t.endpoint,s]),_this46.permittedErrorPrefixes=[ss.ENDPOINT_ERROR_MESSAGE],_this46.url="",_this46.textInputPlaceholderText="Insert text to summarize",_this46.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this46.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this46.rawBody,t),_this46.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this46.isTextInputDisabled=!0,_this46.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:ss.ENDPOINT_ERROR_MESSAGE});}));return _this46;}_inherits(ss,_fa);return _createClass(ss,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return{analysisInput:{documents:[{id:"1",language:e.language,text:s}]},tasks:[{kind:"ExtractiveSummarization"}]};}},{key:"callServiceAPI",value:function(){var _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(e,t){var s;return _regenerator().w(function(_context96){while(1)switch(_context96.n){case 0:if(this.connectSettings){_context96.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);R.request(this,s,e),this.messages=e;case 2:return _context96.a(2);}},_callee96,this);}));function callServiceAPI(_x177,_x178){return _callServiceAPI10.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(e){var t,_s4,i;return _regenerator().w(function(_context97){while(1)switch(_context97.n){case 0:if(!e.error){_context97.n=1;break;}throw e.error.message;case 1:if(this.messages&&this.completionsHandlers){_s4=e.headers.get("operation-location"),i={method:"GET",headers:(t=this.connectSettings)==null?void 0:t.headers};R.executePollRequest(this,_s4,i,this.messages);}return _context97.a(2,{makingAnotherRequest:!0});}},_callee97,this);}));function extractResultData(_x179){return _extractResultData13.apply(this,arguments);}return extractResultData;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(e){var t,_iterator,_step,_s5;return _regenerator().w(function(_context98){while(1)switch(_context98.n){case 0:if(!e.error){_context98.n=1;break;}throw e.error;case 1:if(!(e.status==="running")){_context98.n=2;break;}return _context98.a(2,{timeoutMS:2e3});case 2:if(!(e.errors.length>0)){_context98.n=3;break;}throw e.errors[0];case 3:if(!(e.tasks.items[0].results.errors.length>0)){_context98.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;){_s5=_step.value;t+=_s5.text;}}catch(err){_iterator.e(err);}finally{_iterator.f();}return _context98.a(2,{text:t||""});}},_callee98);}));function extractPollResultData(_x180){return _extractPollResultData5.apply(this,arguments);}return extractPollResultData;}()}]);}(fa);ss.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
194
|
+
"Please define the azure endpoint. [More Information](https://deepchat.dev/docs/directConnection/Azure#Summarization)";var Ci=ss;var Yt=/*#__PURE__*/function(){function Yt(){_classCallCheck(this,Yt);}return _createClass(Yt,null,[{key:"poll",value:function(){var _poll2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t){var s,a,l,d,_t37,_t38;return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:s={authorization:e,"content-type":"application/json"};_t37="https://api.assemblyai.com/v2/transcript/";_context99.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:"POST",body:JSON.stringify({audio_url:t}),headers:s});case 1:_context99.n=2;return _context99.v.json();case 2:_t38=_context99.v.id;a=_t37.concat.call(_t37,_t38);case 3:if(l){_context99.n=9;break;}_context99.n=4;return fetch(a,{headers:s});case 4:_context99.n=5;return _context99.v.json();case 5:d=_context99.v;if(!(d.status==="completed")){_context99.n=6;break;}l=d;_context99.n=8;break;case 6:if(!(d.status==="error")){_context99.n=7;break;}throw new Error("Transcription failed: ".concat(d.error));case 7:_context99.n=8;return new Promise(function(u){return setTimeout(u,3e3);});case 8:_context99.n=3;break;case 9:return _context99.a(2,l);}},_callee99);}));function poll(_x181,_x182){return _poll2.apply(this,arguments);}return poll;}()},{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:e,"Content-Type":"application/octet-stream"};}// prettier-ignore
|
195
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.assemblyai.com/v2/upload",method:"POST",handleVerificationResult:Yt.handleVerificationResult};}}]);}();var Ui=/*#__PURE__*/function(_I8){function Ui(e){var _this47;_classCallCheck(this,Ui);var s;var t=(s=e.directConnection)==null?void 0:s.assemblyAI;_this47=_callSuper(this,Ui,[e,Yt.buildKeyVerificationDetails(),Yt.buildHeaders,t,{audio:{}}]),_this47.insertKeyPlaceholderText="AssemblyAI API Key",_this47.keyHelpUrl="https://www.assemblyai.com/app/account",_this47.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>AssemblyAI Audio</b></div>\n <p><b>Upload an audio file</b> to transcribe it into text.\n <p>\n Click <a href=\"https://www.assemblyai.com/docs/Guides/transcribing_an_audio_file#get-started\"\n target=\"_blank\">here</a> for more info.\n </p>",_this47.url="https://api.assemblyai.com/v2/upload",_this47.isTextInputDisabled=!0,_this47.textInputPlaceholderText="Upload an audio file",_this47.permittedErrorPrefixes=["Authentication","Invalid"],_this47.canSendMessage=Ui.canFileSendMessage;return _this47;}_inherits(Ui,_I8);return _createClass(Ui,[{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee100(e,t,s){var i;return _regenerator().w(function(_context100){while(1)switch(_context100.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context100.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context100.n=2;break;}throw new Error("No file was added");case 2:R.request(this,s[0],e,!1);case 3:return _context100.a(2);}},_callee100,this);}));function callServiceAPI(_x183,_x184,_x185){return _callServiceAPI11.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e){var i,n,t,_t39;return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if(!e.error){_context101.n=1;break;}throw e.error;case 1:t=(n=(i=this.connectSettings)==null?void 0:i.headers)==null?void 0:n.Authorization;_context101.n=2;return Yt.poll(t,e.upload_url);case 2:_t39=_context101.v.text;return _context101.a(2,{text:_t39});}},_callee101,this);}));function extractResultData(_x186){return _extractResultData14.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(I);var Yn=/*#__PURE__*/function(_I9){// prettier-ignore
|
196
|
+
function Yn(e,t,s,i,n){var _this48;_classCallCheck(this,Yn);_this48=_callSuper(this,Yn,[e,me.buildSpeechKeyVerificationDetails(s),t,i,n]),_this48.insertKeyPlaceholderText="Azure Speech Subscription Key",_this48.keyHelpUrl=// eslint-disable-next-line max-len
|
197
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal";return _this48;}_inherits(Yn,_I9);return _createClass(Yn);}(I);var nt=/*#__PURE__*/function(_Yn){// prettier-ignore
|
198
|
+
function nt(e){var _a$lang,_l$name,_c$gender;var _this49;_classCallCheck(this,nt);var i,n,o,a,l,c;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.textToSpeech,s=(o=e.directConnection)==null?void 0:o.azure;_this49=_callSuper(this,nt,[e,me.buildTextToSpeechHeaders.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,s]),_this49.permittedErrorPrefixes=[nt.REGION_ERROR_MESSAGE],_this49.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Azure Text To Speech</b></div>\n <p>Insert text to synthesize it to audio.\n <p>\n Click <a href=\"".concat(nt.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this49.isTextInputDisabled=!1,_this49.url="",t.region?(Object.assign(_this49.rawBody,t),(_a$lang=(a=_this49.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_l$name=(l=_this49.rawBody).name)!==null&&_l$name!==void 0?_l$name:l.name="en-US-JennyNeural",(_c$gender=(c=_this49.rawBody).gender)!==null&&_c$gender!==void 0?_c$gender:c.gender="Female",_this49.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this49.isTextInputDisabled=!0,_this49.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:nt.REGION_ERROR_MESSAGE});}));return _this49;}_inherits(nt,_Yn);return _createClass(nt,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)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(s,"\n </voice>\n </speak>");}},{key:"callServiceAPI",value:function(){var _callServiceAPI12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(e,t){var s;return _regenerator().w(function(_context102){while(1)switch(_context102.n){case 0:if(this.connectSettings){_context102.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);R.request(this,s,e,!1);case 2:return _context102.a(2);}},_callee102,this);}));function callServiceAPI(_x187,_x188){return _callServiceAPI12.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103(e){return _regenerator().w(function(_context103){while(1)switch(_context103.n){case 0:return _context103.a(2,new Promise(function(t){var s=new FileReader();s.readAsDataURL(e),s.onload=function(i){t({files:[{src:i.target.result,type:"audio"}]});};}));}},_callee103);}));function extractResultData(_x189){return _extractResultData15.apply(this,arguments);}return extractResultData;}()}]);}(Yn);nt.HELP_LINK=// eslint-disable-next-line max-len
|
199
|
+
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",nt.REGION_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
200
|
+
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#TextToSpeech)";var Ti=nt;var Je=/*#__PURE__*/function(_Yn2){function Je(e){var _this50;_classCallCheck(this,Je);var n,o,a;var t=(o=(n=e.directConnection)==null?void 0:n.azure)==null?void 0:o.speechToText,s=(a=e.directConnection)==null?void 0:a.azure,i={audio:{files:{acceptedFormats:".wav,.ogg"}}};if(_this50=_callSuper(this,Je,[e,me.buildSpeechToTextHeaders,t.region,s,i]),_this50.permittedErrorPrefixes=[Je.REGION_ERROR_MESSAGE],_this50.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Azure Speech To Text</b></div>\n <p><b>Upload a .wav or .ogg audio file</b> to transcribe it into text.\n <p>\n Click <a href=\"".concat(Je.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this50.url="",_this50.isTextInputDisabled=!0,_this50.textInputPlaceholderText="Upload an audio file",!t.region)_this50.isTextInputDisabled=!0,_this50.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:Je.REGION_ERROR_MESSAGE});});else{_this50.canSendMessage=Je.canFileSendMessage;var l=t.lang||"en-US";_this50.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(l,"&format=detailed"),_this50.recordAudio=void 0;}return _this50;}_inherits(Je,_Yn2);return _createClass(Je,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(e,t,s){var i,n;return _regenerator().w(function(_context104){while(1)switch(_context104.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context104.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context104.n=2;break;}throw new Error("No file was added");case 2:(n=this.connectSettings)!=null&&n.headers&&(this.connectSettings.headers["Content-Type"]=s[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),R.request(this,s[0],e,!1);case 3:return _context104.a(2);}},_callee104,this);}));function callServiceAPI(_x190,_x191,_x192){return _callServiceAPI13.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e){return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:if(!e.error){_context105.n=1;break;}throw e.error;case 1:return _context105.a(2,{text:e.DisplayText||""});}},_callee105);}));function extractResultData(_x193){return _extractResultData16.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(Yn);Je.HELP_LINK=// eslint-disable-next-line max-len
|
198
201
|
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",Je.REGION_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
199
|
-
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#SpeechToText)";var
|
200
|
-
function
|
201
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",
|
202
|
+
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#SpeechToText)";var Ri=Je;var ma=/*#__PURE__*/function(_I0){// prettier-ignore
|
203
|
+
function ma(e){var _this51;_classCallCheck(this,ma);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.azure;_this51=_callSuper(this,ma,[e,me.buildTranslationKeyVerificationDetails(t.region),me.buildTranslationHeaders.bind({},t==null?void 0:t.region),s]),_this51.insertKeyPlaceholderText="Azure Translate Subscription Key",_this51.keyHelpUrl=// eslint-disable-next-line max-len
|
204
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this51.url="",_this51.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this51;}_inherits(ma,_I0);return _createClass(ma,[{key:"preprocessBody",value:function preprocessBody(e){var t=e[e.length-1].text;if(t)return[{Text:t}];}},{key:"callServiceAPI",value:function(){var _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(e,t){var s;return _regenerator().w(function(_context106){while(1)switch(_context106.n){case 0:if(this.connectSettings){_context106.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(t);R.request(this,s,e);case 2:return _context106.a(2);}},_callee106,this);}));function callServiceAPI(_x194,_x195){return _callServiceAPI14.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(e){var t;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:if(!Array.isArray(e)){_context107.n=1;break;}return _context107.a(2,{text:((t=e[0].translations)==null?void 0:t[0].text)||""});case 1:throw e.error;case 2:return _context107.a(2);}},_callee107);}));function extractResultData(_x196){return _extractResultData17.apply(this,arguments);}return extractResultData;}()}]);}(I);var ot=/*#__PURE__*/function(_I1){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
|
202
205
|
// prettier-ignore
|
203
|
-
function
|
206
|
+
function ot(e,t,s,i,n){var _this52$maxMessages,_f$model;var _this52;_classCallCheck(this,ot);var u,h,p,m,f;var o=JSON.parse(JSON.stringify(e.directConnection)),a=t||P.buildKeyVerificationDetails(),l=s||P.buildHeaders,c=i||o.openAI;_this52=_callSuper(this,ot,[e,a,l,c]),_this52.insertKeyPlaceholderText="OpenAI API Key",_this52.keyHelpUrl="https://platform.openai.com/account/api-keys",_this52.url="https://api.openai.com/v1/chat/completions",_this52.permittedErrorPrefixes=["Incorrect"],_this52.asyncCallInProgress=!1,_this52._systemMessage=ot.generateSystemMessage("You are a helpful assistant.");var d=n||((u=o.openAI)==null?void 0:u.chat);if(_typeof(d)=="object"){d.system_prompt&&(_this52._systemMessage=ot.generateSystemMessage(d.system_prompt));var g=(m=(p=(h=e.directConnection)==null?void 0:h.openAI)==null?void 0:p.chat)==null?void 0:m.function_handler;g&&(_this52._functionHandler=g),_this52.cleanConfig(d),Object.assign(_this52.rawBody,d);}(_this52$maxMessages=_this52.maxMessages)!==null&&_this52$maxMessages!==void 0?_this52$maxMessages:_this52.maxMessages=-1,(_f$model=(f=_this52.rawBody).model)!==null&&_f$model!==void 0?_f$model:f.model="gpt-4o";return _this52;}_inherits(ot,_I1);return _createClass(ot,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler;}// mention that microphone is not supported because the outputted base64 is not accepted
|
204
207
|
// use speech to speech instead
|
205
208
|
// give allowed regex example for audio format rules
|
206
209
|
},{key:"preprocessBody",value:// prettier-ignore
|
207
|
-
function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.stringify(e)),i=(o=s.modalities)==null?void 0:o.includes("audio"),n=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.content.length:-1).map(function(a){return{content:
|
208
|
-
},{key:"extractResultData",value:function(){var
|
209
|
-
},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/
|
210
|
-
},{key:"callApiWithImage",value:function callApiWithImage(e,t,s){var o,a;var i;var n=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim();if(s[1]||n&&n!==""){this.url=ve.IMAGE_EDIT_URL;var l=this.preprocessBody(this.rawBody,n);i=ve.createFormDataBody(l,s[0],s[1]);}else this.url=ve.IMAGE_VARIATIONS_URL,i=ve.createFormDataBody(this.rawBody,s[0]);E.tempRemoveContentHeader(this.connectSettings,R.request.bind(this,this,i,e),!1);}},{key:"callServiceAPI",value:function(){var
|
210
|
+
function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.stringify(e)),i=(o=s.modalities)==null?void 0:o.includes("audio"),n=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.content.length:-1).map(function(a){return{content:ot.getContent(a,i),role:a.role===b.USER_ROLE?"user":"assistant"};});return t.find(function(a){return a.files&&a.files.length>0;})&&((_s$max_tokens=s.max_tokens)!==null&&_s$max_tokens!==void 0?_s$max_tokens:s.max_tokens=300),s.messages=[this._systemMessage].concat(_toConsumableArray(n)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(e,t){var _this$_messages3;var s,i;return _regenerator().w(function(_context108){while(1)switch(_context108.n){case 0:if(this.connectSettings){_context108.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages3=this._messages)!==null&&_this$_messages3!==void 0?_this$_messages3:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 2:return _context108.a(2);}},_callee108,this);}));function callServiceAPI(_x197,_x198){return _callServiceAPI15.apply(this,arguments);}return callServiceAPI;}()// prettier-ignore
|
211
|
+
},{key:"extractResultData",value:function(){var _extractResultData18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e,t,s){var i,n,o,a,l,c,d,u;return _regenerator().w(function(_context109){while(1)switch(_context109.n){case 0:if(!e.error){_context109.n=1;break;}throw e.error.message;case 1:if(!((n=(i=e.choices)==null?void 0:i[0])!=null&&n.delta)){_context109.n=2;break;}return _context109.a(2,this.extractStreamResult(e.choices[0],t,s));case 2:if(!((a=(o=e.choices)==null?void 0:o[0])!=null&&a.message)){_context109.n=5;break;}if(!e.choices[0].message.tool_calls){_context109.n=3;break;}return _context109.a(2,this.handleTools(e.choices[0].message,t,s));case 3:if(!((l=e.choices[0].message)!=null&&l.audio)){_context109.n=4;break;}d=this.deepChat.textToSpeech,u=_typeof(d)=="object"&&typeof((c=d==null?void 0:d.service)==null?void 0:c.displayText)=="boolean";return _context109.a(2,{files:[{src:"data:audio/wav;base64,".concat(e.choices[0].message.audio.data),type:"audio"}],text:u?e.choices[0].message.audio.transcript:void 0});case 4:return _context109.a(2,{text:e.choices[0].message.content});case 5:return _context109.a(2,{text:""});}},_callee109,this);}));function extractResultData(_x199,_x200,_x201){return _extractResultData18.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(e,t,s){var _this53=this;var i,n,o;return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:i=e.delta,n=e.finish_reason;if(!(n==="tool_calls")){_context110.n=1;break;}this.asyncCallInProgress=!0;o={tool_calls:this._streamToolCalls};return _context110.a(2,(this._streamToolCalls=void 0,this.handleTools(o,t,s)));case 1:i!=null&&i.tool_calls&&(this._streamToolCalls?i.tool_calls.forEach(function(o,a){_this53._streamToolCalls&&(_this53._streamToolCalls[a]["function"].arguments+=o["function"].arguments);}):this._streamToolCalls=i.tool_calls);case 2:return _context110.a(2,(this.asyncCallInProgress=!1,{text:(i==null?void 0:i.content)||""}));}},_callee110,this);}));function extractStreamResult(_x202,_x203,_x204){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()// prettier-ignore
|
212
|
+
},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e,t,s){var l,c,d,u,h,i,n,o,p,m,a,_p2,_t40,_t41,_t42;return _regenerator().w(function(_context111){while(1)switch(_context111.p=_context111.n){case 0:if(!(!e.tool_calls||!t||!s||!this._functionHandler)){_context111.n=1;break;}throw Error("Please define the `function_handler` property inside the [openAI](https://deepchat.dev/docs/directConnection/openAI#Chat) object.");case 1:i=JSON.parse(JSON.stringify(s));n=e.tool_calls.map(function(p){return{name:p["function"].name,arguments:p["function"].arguments};});_context111.n=2;return(l=this._functionHandler)==null?void 0:l.call(this,n);case 2:o=_context111.v;if(Array.isArray(o)){_context111.n=7;break;}if(!o.text){_context111.n=6;break;}p={text:o.text};_context111.n=3;return(d=(c=this.deepChat).responseInterceptor)==null?void 0:d.call(c,p);case 3:_t40=_context111.v;if(_t40){_context111.n=4;break;}_t40=p;case 4:m=_t40;if(!Array.isArray(m)){_context111.n=5;break;}throw Error(P.FUNCTION_TOOL_RESP_ARR_ERROR);case 5:return _context111.a(2,m);case 6:throw Error(P.FUNCTION_TOOL_RESP_ERROR);case 7:_context111.n=8;return Promise.all(o);case 8:a=_context111.v;if(!(i.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!a.find(function(_ref32){var p=_ref32.response;return typeof p!="string";})&&n.length===a.length)){_context111.n=16;break;}a.forEach(function(p,m){var g;var f=(g=e.tool_calls)==null?void 0:g[m];i==null||i.messages.push({role:"tool",tool_call_id:f==null?void 0:f.id,name:f==null?void 0:f["function"].name,content:p.response});});_context111.p=9;if(!(this.stream&&this._messages)){_context111.n=10;break;}return _context111.a(2,(_.request(this,i,this._messages),{text:""}));case 10:_context111.n=11;return t==null?void 0:t(i).then(function(m){return E.processResponseByType(m);});case 11:_p2=_context111.v;_context111.n=12;return(h=(u=this.deepChat).responseInterceptor)==null?void 0:h.call(u,_p2);case 12:_t41=_context111.v;if(_t41){_context111.n=13;break;}_t41=_p2;case 13:_p2=_t41;if(!_p2.error){_context111.n=14;break;}throw _p2.error.message;case 14:return _context111.a(2,{text:_p2.choices[0].message.content||""});case 15:_context111.p=15;_t42=_context111.v;throw this.asyncCallInProgress=!1,_t42;case 16:throw Error(P.FUNCTION_TOOL_RESP_ERROR);case 17:return _context111.a(2);}},_callee111,this,[[9,15]]);}));function handleTools(_x205,_x206,_x207){return _handleTools2.apply(this,arguments);}return handleTools;}()}],[{key:"generateSystemMessage",value:function generateSystemMessage(e){return{role:"system",content:e};}},{key:"getFileContent",value:function getFileContent(e,t){return e.map(function(i){var n,o,a;if(i.type==="audio"&&t){var l=(n=i.src)==null?void 0:n.split(",")[1],c=((a=(o=i.src)==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1])||"wav";return{type:"input_audio",input_audio:{data:l,format:c}};}return{type:"image_url",image_url:{url:i.src}};});}},{key:"getContent",value:function getContent(e,t){if(e.files&&e.files.length>0){var _s6=ot.getFileContent(e.files,t);return e.text&&e.text.trim().length>0&&_s6.unshift({type:"text",text:e.text}),_s6;}return e.text;}}]);}(I);var ji=/*#__PURE__*/function(_ot){function ji(e){var _this54;_classCallCheck(this,ji);var o,a,l,c,d,u,h;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.azure,i=((a=(o=t.azure)==null?void 0:o.openAI)==null?void 0:a.urlDetails)||{},n=(c=(l=t.azure)==null?void 0:l.openAI)==null?void 0:c.chat;if(_this54=_callSuper(this,ji,[e,fe.buildKeyVerificationDetails(i),fe.buildHeaders,s,n]),_this54.permittedErrorPrefixes=[fe.URL_DETAILS_ERROR_MESSAGE],_this54.isTextInputDisabled=!1,_typeof(n)=="object"){var _ref33=(h=(u=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:u.openAI)==null?void 0:h.chat,p=_ref33.function_handler;p&&(_this54._functionHandler=p);}fe.validateURLDetails(i)?_this54.url=ji.buildURL(i):(_this54.isTextInputDisabled=!0,_this54.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:fe.URL_DETAILS_ERROR_MESSAGE});}));return _this54;}_inherits(ji,_ot);return _createClass(ji,null,[{key:"buildURL",value:function buildURL(e){var t=e.endpoint,s=e.deploymentId,i=e.version;return"".concat(t,"/openai/deployments/").concat(s,"/chat/completions?api-version=").concat(i);}}]);}(ot);var ve=/*#__PURE__*/function(_I10){function ve(e){var _this55;_classCallCheck(this,ve);var o;var t=e.directConnection,s=t==null?void 0:t.openAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};_this55=_callSuper(this,ve,[e,P.buildKeyVerificationDetails(),P.buildHeaders,s,i]),_this55.insertKeyPlaceholderText="OpenAI API Key",_this55.keyHelpUrl="https://platform.openai.com/account/api-keys",_this55.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI DALL\xB7E</b></div>\n <p><b>Insert text</b> to generate an image.</p>\n <p><b>Upload 1</b> PNG image to generate its variation and optionally insert text to specify the change.</p>\n <p><b>Upload 2</b> PNG images where the second is a copy of the first with a transparent area where the edit should\n take place and text to specify the edit.</p>\n <p>Click <a href=\"https://platform.openai.com/docs/guides/images/introduction\" target=\"_blank\">here</a>\n for more info.</p>",_this55.url="",_this55.permittedErrorPrefixes=["Incorrect","Invalid input image"];var n=(o=t==null?void 0:t.openAI)==null?void 0:o.images;if(_this55.camera){var a=_typeof(n)=="object"&&n.size?Number.parseInt(n.size):1024;_this55.camera.files={dimensions:{width:a,height:a}};}_typeof(n)=="object"&&Object.assign(_this55.rawBody,n),_this55.canSendMessage=ve.canFileSendMessage;return _this55;}_inherits(ve,_I10);return _createClass(ve,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}// prettier-ignore
|
213
|
+
},{key:"callApiWithImage",value:function callApiWithImage(e,t,s){var o,a;var i;var n=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim();if(s[1]||n&&n!==""){this.url=ve.IMAGE_EDIT_URL;var l=this.preprocessBody(this.rawBody,n);i=ve.createFormDataBody(l,s[0],s[1]);}else this.url=ve.IMAGE_VARIATIONS_URL,i=ve.createFormDataBody(this.rawBody,s[0]);E.tempRemoveContentHeader(this.connectSettings,R.request.bind(this,this,i,e),!1);}},{key:"callServiceAPI",value:function(){var _callServiceAPI16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(e,t,s){var i,n;return _regenerator().w(function(_context112){while(1)switch(_context112.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context112.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!(s!=null&&s[0])){_context112.n=2;break;}this.callApiWithImage(e,t,s);_context112.n=4;break;case 2:if(this.connectSettings){_context112.n=3;break;}throw new Error("Request settings have not been set up");case 3:this.url=ve.IMAGE_GENERATION_URL;n=this.preprocessBody(this.rawBody,t[t.length-1].text);R.request(this,n,e);case 4:return _context112.a(2);}},_callee112,this);}));function callServiceAPI(_x208,_x209,_x210){return _callServiceAPI16.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113(e){return _regenerator().w(function(_context113){while(1)switch(_context113.n){case 0:if(!e.error){_context113.n=1;break;}throw e.error.message;case 1:return _context113.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(At).concat(s.b64_json),type:"image"};})});}},_callee113);}));function extractResultData(_x211){return _extractResultData19.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
|
211
214
|
// 1 image:
|
212
215
|
// - With text - edits image based on the text
|
213
216
|
// - No text - creates a variation of the image
|
@@ -216,36 +219,36 @@ function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.strin
|
|
216
219
|
// Add text to describe the required modification.
|
217
220
|
// Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
|
218
221
|
// `;
|
219
|
-
}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("image",t),s&&i.append("mask",s),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i;}}]);}(I);ve.IMAGE_GENERATION_URL="https://api.openai.com/v1/images/generations",ve.IMAGE_VARIATIONS_URL="https://api.openai.com/v1/images/variations",ve.IMAGE_EDIT_URL="https://api.openai.com/v1/images/edits";var
|
220
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){typeof e.message=="string"?i(C.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.cohere.ai/v1/models",method:"GET",handleVerificationResult:Ds.handleVerificationResult};}}]);}();var va=/*#__PURE__*/function(_I13){function va(e,t,s,i,n){var _this58;_classCallCheck(this,va);_this58=_callSuper(this,va,[e,Ds.buildKeyVerificationDetails(),Ds.buildHeaders,n]),_this58.insertKeyPlaceholderText="Cohere API Key",_this58.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this58.permittedErrorPrefixes=["invalid"],_this58.url=t,_this58.textInputPlaceholderText=s,i&&_typeof(i)=="object"&&Object.assign(_this58.rawBody,i);return _this58;}_inherits(va,_I13);return _createClass(va);}(I);var Bs=/*#__PURE__*/function(_va){function Bs(e){var _this59$maxMessages;var _this59;_classCallCheck(this,Bs);var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.cohere;_this59=_callSuper(this,Bs,[e,"https://api.cohere.com/v2/chat","Ask me anything!",{},s]);var i=t.cohere;if(_typeof(i)=="object"){var n=ee.processCohere(i);_this59.canSendMessage=function(){return n;},_this59.cleanConfig(i),Object.assign(_this59.rawBody,i);}(_this59$maxMessages=_this59.maxMessages)!==null&&_this59$maxMessages!==void 0?_this59$maxMessages:_this59.maxMessages=-1;return _this59;}_inherits(Bs,_va);return _createClass(Bs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t.filter(function(n){return n.text;});return s.messages=i.map(function(n){return{role:n.role==="ai"?"assistant":"user",content:n.text};}),s.model=s.model||"command-a-03-2025",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI19=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee118(e,t){var s,i;return _regeneratorRuntime().wrap(function _callee118$(_context118){while(1)switch(_context118.prev=_context118.next){case 0:if(this.connectSettings){_context118.next=2;break;}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,this.stream={readable:!0},_.request(this,s,e)):R.request(this,s,e);case 4:case"end":return _context118.stop();}},_callee118,this);}));function callServiceAPI(_x218,_x219){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee119(e){var t,s,i,n;return _regeneratorRuntime().wrap(function _callee119$(_context119){while(1)switch(_context119.prev=_context119.next){case 0:if(!(typeof e.message=="string")){_context119.next=2;break;}throw e.message;case 2:if(!(this.stream&&e.text)){_context119.next=5;break;}n=Bs.parseBundledEvents(e.text);return _context119.abrupt("return",{text:Bs.aggregateBundledEventsText(n)});case 5:if(!("message"in e&&(i=(s=(t=e.message)==null?void 0:t.content)==null?void 0:s[0])!=null&&i.text)){_context119.next=7;break;}return _context119.abrupt("return",{text:e.message.content[0].text});case 7:throw new Error("Invalid response format from Cohere API");case 8:case"end":return _context119.stop();}},_callee119,this);}));function extractResultData(_x220){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),s=[];var _iterator2=_createForOfIteratorHelper(t),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var i=_step2.value;if(i.trim())try{var n=JSON.parse(i);s.push(n);}catch(n){console.error("Failed to parse line:",i,n);}}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return s;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var s,i,n;return t.type==="content-delta"&&((n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text);}).map(function(t){var s,i,n;return(n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text;}).join("");}}]);}(va);var Fs=/*#__PURE__*/function(){function Fs(){_classCallCheck(this,Fs);}return _createClass(Fs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:"GET",handleVerificationResult:Fs.handleVerificationResult};}}]);}();var Ea=/*#__PURE__*/function(_I14){function Ea(e){var _this60$maxMessages,_n$model2,_o$temperature,_a$max_tokens;var _this60;_classCallCheck(this,Ea);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.deepSeek;_this60=_callSuper(this,Ea,[e,Fs.buildKeyVerificationDetails(),Fs.buildHeaders,s]),_this60.insertKeyPlaceholderText="DeepSeek API Key",_this60.keyHelpUrl="https://platform.deepseek.com/api_keys",_this60.url="https://api.deepseek.com/v1/chat/completions",_this60.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this60._systemMessage="You are a helpful assistant.";var i=t.deepSeek;_typeof(i)=="object"&&(i.system_prompt&&(_this60._systemMessage=i.system_prompt),_this60.cleanConfig(i),Object.assign(_this60.rawBody,i)),(_this60$maxMessages=_this60.maxMessages)!==null&&_this60$maxMessages!==void 0?_this60$maxMessages:_this60.maxMessages=-1,(_n$model2=(n=_this60.rawBody).model)!==null&&_n$model2!==void 0?_n$model2:n.model="deepseek-chat",(_o$temperature=(o=_this60.rawBody).temperature)!==null&&_o$temperature!==void 0?_o$temperature:o.temperature=1,(_a$max_tokens=(a=_this60.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=4096;return _this60;}_inherits(Ea,_I14);return _createClass(Ea,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee120(e,t){var s,i;return _regeneratorRuntime().wrap(function _callee120$(_context120){while(1)switch(_context120.prev=_context120.next){case 0:if(this.connectSettings){_context120.next=2;break;}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 4:case"end":return _context120.stop();}},_callee120,this);}));function callServiceAPI(_x221,_x222){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee121(e){var t;return _regeneratorRuntime().wrap(function _callee121$(_context121){while(1)switch(_context121.prev=_context121.next){case 0:if(!e.error){_context121.next=2;break;}throw e.error.message;case 2:if(!(e.choices&&e.choices.length>0)){_context121.next=8;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context121.next=6;break;}return _context121.abrupt("return",{text:t.delta.content});case 6:if(!(t.message&&t.message.content)){_context121.next=8;break;}return _context121.abrupt("return",{text:t.message.content});case 8:return _context121.abrupt("return",{text:""});case 9:case"end":return _context121.stop();}},_callee121);}));function extractResultData(_x223){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(I);var xt=/*#__PURE__*/function(){function xt(){_classCallCheck(this,xt);}return _createClass(xt,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"||n.error.type==="invalid_request_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.x.ai/v1/models",method:"GET",handleVerificationResult:xt.handleVerificationResult};}}]);}();var ei=/*#__PURE__*/function(_I15){function ei(e){var _o$model3;var _this61;_classCallCheck(this,ei);var n,o;var t=e.directConnection,s=t==null?void 0:t.grok;_this61=_callSuper(this,ei,[e,xt.buildKeyVerificationDetails(),xt.buildHeaders,s]),_this61.insertKeyPlaceholderText="Grok API Key",_this61.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this61.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Grok Image Generation</b></div>\n <p><b>Insert text</b> to generate an image.</p>\n <p>Click <a target=\"_blank\" href=\"https://docs.x.ai/docs/api-reference#image-generations\">here</a> for more info.</p>",_this61.url=ei.IMAGE_GENERATION_URL,_this61.permittedErrorPrefixes=["invalid_request_error","authentication_error"];var i=(n=t==null?void 0:t.grok)==null?void 0:n.images;_typeof(i)=="object"&&Object.assign(_this61.rawBody,i),(_o$model3=(o=_this61.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model="grok-2-image";return _this61;}_inherits(ei,_I15);return _createClass(ei,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee122(e,t){var i,s;return _regeneratorRuntime().wrap(function _callee122$(_context122){while(1)switch(_context122.prev=_context122.next){case 0:if((i=this.connectSettings)!=null&&i.headers){_context122.next=2;break;}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,t[t.length-1].text);R.request(this,s,e);case 4:case"end":return _context122.stop();}},_callee122,this);}));function callServiceAPI(_x224,_x225){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee123(e){return _regeneratorRuntime().wrap(function _callee123$(_context123){while(1)switch(_context123.prev=_context123.next){case 0:if(!e.error){_context123.next=2;break;}throw e.error.message;case 2:return _context123.abrupt("return",{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(At).concat(s.b64_json),type:"image"};})});case 3:case"end":return _context123.stop();}},_callee123);}));function extractResultData(_x226){return _extractResultData24.apply(this,arguments);}return extractResultData;}()}]);}(I);ei.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Li=ei;var Us=/*#__PURE__*/function(){function Us(){_classCallCheck(this,Us);}return _createClass(Us,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:"GET",handleVerificationResult:Us.handleVerificationResult};}}]);}();var _a=/*#__PURE__*/function(_I16){function _a(e){var _this62$maxMessages,_n$model3;var _this62;_classCallCheck(this,_a);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.kimi;_this62=_callSuper(this,_a,[e,Us.buildKeyVerificationDetails(),Us.buildHeaders,s]),_this62.insertKeyPlaceholderText="Kimi AI API Key",_this62.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this62.url="https://api.moonshot.ai/v1/chat/completions",_this62.permittedErrorPrefixes=["Invalid","Not found"],_this62._systemMessage="You are Kimi, a helpful assistant created by Moonshot AI.";var i=t.kimi;_typeof(i)=="object"&&(i.system_prompt&&(_this62._systemMessage=i.system_prompt),_this62.cleanConfig(i),Object.assign(_this62.rawBody,i)),(_this62$maxMessages=_this62.maxMessages)!==null&&_this62$maxMessages!==void 0?_this62$maxMessages:_this62.maxMessages=-1,(_n$model3=(n=_this62.rawBody).model)!==null&&_n$model3!==void 0?_n$model3:n.model="moonshot-v1-8k";return _this62;}_inherits(_a,_I16);return _createClass(_a,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee124(e,t){var s,i;return _regeneratorRuntime().wrap(function _callee124$(_context124){while(1)switch(_context124.prev=_context124.next){case 0:if(this.connectSettings){_context124.next=2;break;}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 4:case"end":return _context124.stop();}},_callee124,this);}));function callServiceAPI(_x227,_x228){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee125(e){var t;return _regeneratorRuntime().wrap(function _callee125$(_context125){while(1)switch(_context125.prev=_context125.next){case 0:if(!e.error){_context125.next=2;break;}throw e.error.message;case 2:if(!(e.choices&&e.choices.length>0)){_context125.next=8;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context125.next=6;break;}return _context125.abrupt("return",{text:t.delta.content});case 6:if(!(t.message&&t.message.content)){_context125.next=8;break;}return _context125.abrupt("return",{text:t.message.content});case 8:return _context125.abrupt("return",{text:""});case 9:case"end":return _context125.stop();}},_callee125);}));function extractResultData(_x229){return _extractResultData25.apply(this,arguments);}return extractResultData;}()}]);}(I);var js=/*#__PURE__*/function(){function js(){_classCallCheck(this,js);}return _createClass(js,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json",accept:"application/json"};}// prettier-ignore
|
221
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.detail?i(C.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.mistral.ai/v1/models",method:"GET",handleVerificationResult:js.handleVerificationResult};}}]);}();var
|
222
|
+
}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("image",t),s&&i.append("mask",s),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i;}}]);}(I);ve.IMAGE_GENERATION_URL="https://api.openai.com/v1/images/generations",ve.IMAGE_VARIATIONS_URL="https://api.openai.com/v1/images/variations",ve.IMAGE_EDIT_URL="https://api.openai.com/v1/images/edits";var Mi=ve;var Ps=/*#__PURE__*/function(){function Ps(){_classCallCheck(this,Ps);}return _createClass(Ps,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://openrouter.ai/api/v1/generation",method:"GET",handleVerificationResult:Ps.handleVerificationResult};}}]);}();var ga=/*#__PURE__*/function(_I11){function ga(e){var _this56$maxMessages,_n$model,_o$max_tokens;var _this56;_classCallCheck(this,ga);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.openRouter;_this56=_callSuper(this,ga,[e,Ps.buildKeyVerificationDetails(),Ps.buildHeaders,s]),_this56.insertKeyPlaceholderText="OpenRouter API Key",_this56.keyHelpUrl="https://openrouter.ai/keys",_this56.url="https://openrouter.ai/api/v1/chat/completions",_this56.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this56._systemMessage="You are a helpful assistant.";var i=t.openRouter;_typeof(i)=="object"&&(i.system_prompt&&(_this56._systemMessage=i.system_prompt),_this56.cleanConfig(i),Object.assign(_this56.rawBody,i)),(_this56$maxMessages=_this56.maxMessages)!==null&&_this56$maxMessages!==void 0?_this56$maxMessages:_this56.maxMessages=-1,(_n$model=(n=_this56.rawBody).model)!==null&&_n$model!==void 0?_n$model:n.model="openai/gpt-4o",(_o$max_tokens=(o=_this56.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=1e3;return _this56;}_inherits(ga,_I11);return _createClass(ga,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:o.text||"",role:o.role===b.USER_ROLE?"user":"assistant"};}),n=[];return this._systemMessage&&n.push({role:"system",content:this._systemMessage}),n.push.apply(n,_toConsumableArray(i)),s.messages=n,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee114(e,t){var s,i;return _regenerator().w(function(_context114){while(1)switch(_context114.n){case 0:if(this.connectSettings){_context114.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 2:return _context114.a(2);}},_callee114,this);}));function callServiceAPI(_x212,_x213){return _callServiceAPI17.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(e){var t,s,i,n,o,_o5;return _regenerator().w(function(_context115){while(1)switch(_context115.n){case 0:if(!e.error){_context115.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context115.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context115.a(2,(s=o==null?void 0:o.delta)!=null&&s.content?{text:o.delta.content}:{text:""});case 2:if(!(e.object==="chat.completion")){_context115.n=3;break;}_o5=(i=e.choices)==null?void 0:i[0];if(!((n=_o5==null?void 0:_o5.message)!=null&&n.content)){_context115.n=3;break;}return _context115.a(2,{text:_o5.message.content});case 3:return _context115.a(2,{text:""});}},_callee115);}));function extractResultData(_x214){return _extractResultData20.apply(this,arguments);}return extractResultData;}()}]);}(I);var Ds=/*#__PURE__*/function(){function Ds(){_classCallCheck(this,Ds);}return _createClass(Ds,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json",accept:"application/json"};}// prettier-ignore
|
223
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){typeof e.message=="string"?i(C.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.cohere.ai/v1/models",method:"GET",handleVerificationResult:Ds.handleVerificationResult};}}]);}();var ya=/*#__PURE__*/function(_I12){function ya(e,t,s,i,n){var _this57;_classCallCheck(this,ya);_this57=_callSuper(this,ya,[e,Ds.buildKeyVerificationDetails(),Ds.buildHeaders,n]),_this57.insertKeyPlaceholderText="Cohere API Key",_this57.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this57.permittedErrorPrefixes=["invalid"],_this57.url=t,_this57.textInputPlaceholderText=s,i&&_typeof(i)=="object"&&Object.assign(_this57.rawBody,i);return _this57;}_inherits(ya,_I12);return _createClass(ya);}(I);var Bs=/*#__PURE__*/function(_ya){function Bs(e){var _this58$maxMessages;var _this58;_classCallCheck(this,Bs);var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.cohere;_this58=_callSuper(this,Bs,[e,"https://api.cohere.com/v2/chat","Ask me anything!",{},s]);var i=t.cohere;if(_typeof(i)=="object"){var n=X.processCohere(i);_this58.canSendMessage=function(){return n;},_this58.cleanConfig(i),Object.assign(_this58.rawBody,i);}(_this58$maxMessages=_this58.maxMessages)!==null&&_this58$maxMessages!==void 0?_this58$maxMessages:_this58.maxMessages=-1;return _this58;}_inherits(Bs,_ya);return _createClass(Bs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t.filter(function(n){return n.text;});return s.messages=i.map(function(n){return{role:n.role==="ai"?"assistant":"user",content:n.text};}),s.model=s.model||"command-a-03-2025",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee116(e,t){var s,i;return _regenerator().w(function(_context116){while(1)switch(_context116.n){case 0:if(this.connectSettings){_context116.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,this.stream={readable:!0},_.request(this,s,e)):R.request(this,s,e);case 2:return _context116.a(2);}},_callee116,this);}));function callServiceAPI(_x215,_x216){return _callServiceAPI18.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee117(e){var t,s,i,n;return _regenerator().w(function(_context117){while(1)switch(_context117.n){case 0:if(!(typeof e.message=="string")){_context117.n=1;break;}throw e.message;case 1:if(!(this.stream&&e.text)){_context117.n=2;break;}n=Bs.parseBundledEvents(e.text);return _context117.a(2,{text:Bs.aggregateBundledEventsText(n)});case 2:if(!("message"in e&&(i=(s=(t=e.message)==null?void 0:t.content)==null?void 0:s[0])!=null&&i.text)){_context117.n=3;break;}return _context117.a(2,{text:e.message.content[0].text});case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context117.a(2);}},_callee117,this);}));function extractResultData(_x217){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),s=[];var _iterator2=_createForOfIteratorHelper(t),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var i=_step2.value;if(i.trim())try{var n=JSON.parse(i);s.push(n);}catch(n){console.error("Failed to parse line:",i,n);}}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return s;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var s,i,n;return t.type==="content-delta"&&((n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text);}).map(function(t){var s,i,n;return(n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text;}).join("");}}]);}(ya);var Fs=/*#__PURE__*/function(){function Fs(){_classCallCheck(this,Fs);}return _createClass(Fs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:"GET",handleVerificationResult:Fs.handleVerificationResult};}}]);}();var ba=/*#__PURE__*/function(_I13){function ba(e){var _this59$maxMessages,_n$model2,_o$temperature,_a$max_tokens;var _this59;_classCallCheck(this,ba);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.deepSeek;_this59=_callSuper(this,ba,[e,Fs.buildKeyVerificationDetails(),Fs.buildHeaders,s]),_this59.insertKeyPlaceholderText="DeepSeek API Key",_this59.keyHelpUrl="https://platform.deepseek.com/api_keys",_this59.url="https://api.deepseek.com/v1/chat/completions",_this59.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this59._systemMessage="You are a helpful assistant.";var i=t.deepSeek;_typeof(i)=="object"&&(i.system_prompt&&(_this59._systemMessage=i.system_prompt),_this59.cleanConfig(i),Object.assign(_this59.rawBody,i)),(_this59$maxMessages=_this59.maxMessages)!==null&&_this59$maxMessages!==void 0?_this59$maxMessages:_this59.maxMessages=-1,(_n$model2=(n=_this59.rawBody).model)!==null&&_n$model2!==void 0?_n$model2:n.model="deepseek-chat",(_o$temperature=(o=_this59.rawBody).temperature)!==null&&_o$temperature!==void 0?_o$temperature:o.temperature=1,(_a$max_tokens=(a=_this59.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=4096;return _this59;}_inherits(ba,_I13);return _createClass(ba,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee118(e,t){var s,i;return _regenerator().w(function(_context118){while(1)switch(_context118.n){case 0:if(this.connectSettings){_context118.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 2:return _context118.a(2);}},_callee118,this);}));function callServiceAPI(_x218,_x219){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e){var t;return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:if(!e.error){_context119.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context119.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context119.n=2;break;}return _context119.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context119.n=3;break;}return _context119.a(2,{text:t.message.content});case 3:return _context119.a(2,{text:""});}},_callee119);}));function extractResultData(_x220){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(I);var xt=/*#__PURE__*/function(){function xt(){_classCallCheck(this,xt);}return _createClass(xt,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"||n.error.type==="invalid_request_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.x.ai/v1/models",method:"GET",handleVerificationResult:xt.handleVerificationResult};}}]);}();var ei=/*#__PURE__*/function(_I14){function ei(e){var _o$model3;var _this60;_classCallCheck(this,ei);var n,o;var t=e.directConnection,s=t==null?void 0:t.grok;_this60=_callSuper(this,ei,[e,xt.buildKeyVerificationDetails(),xt.buildHeaders,s]),_this60.insertKeyPlaceholderText="Grok API Key",_this60.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this60.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Grok Image Generation</b></div>\n <p><b>Insert text</b> to generate an image.</p>\n <p>Click <a target=\"_blank\" href=\"https://docs.x.ai/docs/api-reference#image-generations\" target=\"_blank\">\n here</a> for more info.</p>",_this60.url=ei.IMAGE_GENERATION_URL,_this60.permittedErrorPrefixes=["invalid_request_error","authentication_error"];var i=(n=t==null?void 0:t.grok)==null?void 0:n.images;_typeof(i)=="object"&&Object.assign(_this60.rawBody,i),(_o$model3=(o=_this60.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model="grok-2-image";return _this60;}_inherits(ei,_I14);return _createClass(ei,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee120(e,t){var i,s;return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context120.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t[t.length-1].text);R.request(this,s,e);case 2:return _context120.a(2);}},_callee120,this);}));function callServiceAPI(_x221,_x222){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e){return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:if(!e.error){_context121.n=1;break;}throw e.error.message;case 1:return _context121.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(At).concat(s.b64_json),type:"image"};})});}},_callee121);}));function extractResultData(_x223){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(I);ei.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var ki=ei;var Us=/*#__PURE__*/function(){function Us(){_classCallCheck(this,Us);}return _createClass(Us,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:"GET",handleVerificationResult:Us.handleVerificationResult};}}]);}();var va=/*#__PURE__*/function(_I15){function va(e){var _this61$maxMessages,_n$model3;var _this61;_classCallCheck(this,va);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.kimi;_this61=_callSuper(this,va,[e,Us.buildKeyVerificationDetails(),Us.buildHeaders,s]),_this61.insertKeyPlaceholderText="Kimi AI API Key",_this61.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this61.url="https://api.moonshot.ai/v1/chat/completions",_this61.permittedErrorPrefixes=["Invalid","Not found"],_this61._systemMessage="You are Kimi, a helpful assistant created by Moonshot AI.";var i=t.kimi;_typeof(i)=="object"&&(i.system_prompt&&(_this61._systemMessage=i.system_prompt),_this61.cleanConfig(i),Object.assign(_this61.rawBody,i)),(_this61$maxMessages=_this61.maxMessages)!==null&&_this61$maxMessages!==void 0?_this61$maxMessages:_this61.maxMessages=-1,(_n$model3=(n=_this61.rawBody).model)!==null&&_n$model3!==void 0?_n$model3:n.model="moonshot-v1-8k";return _this61;}_inherits(va,_I15);return _createClass(va,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e,t){var s,i;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:if(this.connectSettings){_context122.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 2:return _context122.a(2);}},_callee122,this);}));function callServiceAPI(_x224,_x225){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e){var t;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:if(!e.error){_context123.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context123.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context123.n=2;break;}return _context123.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context123.n=3;break;}return _context123.a(2,{text:t.message.content});case 3:return _context123.a(2,{text:""});}},_callee123);}));function extractResultData(_x226){return _extractResultData24.apply(this,arguments);}return extractResultData;}()}]);}(I);var js=/*#__PURE__*/function(){function js(){_classCallCheck(this,js);}return _createClass(js,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json",accept:"application/json"};}// prettier-ignore
|
224
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.detail?i(C.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.mistral.ai/v1/models",method:"GET",handleVerificationResult:js.handleVerificationResult};}}]);}();var Ea=/*#__PURE__*/function(_I16){function Ea(e){var _this62$maxMessages,_i$model;var _this62;_classCallCheck(this,Ea);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).mistral;_this62=_callSuper(this,Ea,[e,js.buildKeyVerificationDetails(),js.buildHeaders,s]),_this62.insertKeyPlaceholderText="Mistral API Key",_this62.keyHelpUrl="https://console.mistral.ai/api-keys/",_this62.url="https://api.mistral.ai/v1/chat/completions",_this62.permittedErrorPrefixes=["Invalid"],s&&(_this62.cleanConfig(s),Object.assign(_this62.rawBody,s)),(_this62$maxMessages=_this62.maxMessages)!==null&&_this62$maxMessages!==void 0?_this62$maxMessages:_this62.maxMessages=-1,(_i$model=(i=_this62.rawBody).model)!==null&&_i$model!==void 0?_i$model:i.model="mistral-small-latest";return _this62;}_inherits(Ea,_I16);return _createClass(Ea,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return s.messages=t.map(function(i){return{role:i.role==="ai"?"assistant":"user",content:i.text||""};}),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e,t){var s,i;return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:if(this.connectSettings){_context124.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 2:return _context124.a(2);}},_callee124,this);}));function callServiceAPI(_x227,_x228){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(e){var t;return _regenerator().w(function(_context125){while(1)switch(_context125.n){case 0:if(!e.message){_context125.n=1;break;}throw e.message;case 1:if(!(e.choices&&e.choices.length>0)){_context125.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context125.n=2;break;}return _context125.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context125.n=3;break;}return _context125.a(2,{text:t.message.content});case 3:return _context125.a(2,{text:""});}},_callee125);}));function extractResultData(_x229){return _extractResultData25.apply(this,arguments);}return extractResultData;}()}]);}(I);var _a=/*#__PURE__*/function(_I17){function _a(e){var _this63$maxMessages,_o$model4;var _this63;_classCallCheck(this,_a);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.grok;_this63=_callSuper(this,_a,[e,xt.buildKeyVerificationDetails(),xt.buildHeaders,s]),_this63.insertKeyPlaceholderText="Grok API Key",_this63.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this63.url="https://api.x.ai/v1/chat/completions",_this63.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this63._systemMessage="You are a helpful assistant.";var i=(n=t.grok)==null?void 0:n.chat;_typeof(i)=="object"&&(i.system_prompt&&(_this63._systemMessage=i.system_prompt),_this63.cleanConfig(i),Object.assign(_this63.rawBody,i)),(_this63$maxMessages=_this63.maxMessages)!==null&&_this63$maxMessages!==void 0?_this63$maxMessages:_this63.maxMessages=-1,(_o$model4=(o=_this63.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model="grok-3-latest";return _this63;}_inherits(_a,_I17);return _createClass(_a,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:o.text||"",role:o.role===b.USER_ROLE?"user":"assistant"};}),n={role:"system",content:this._systemMessage};return s.messages=[n].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(e,t){var s,i;return _regenerator().w(function(_context126){while(1)switch(_context126.n){case 0:if(this.connectSettings){_context126.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 2:return _context126.a(2);}},_callee126,this);}));function callServiceAPI(_x230,_x231){return _callServiceAPI23.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e){var t,s,i,n,o;return _regenerator().w(function(_context127){while(1)switch(_context127.n){case 0:if(!e.error){_context127.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context127.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context127.a(2,(s=o==null?void 0:o.delta)!=null&&s.content?{text:o.delta.content}:{text:""});case 2:return _context127.a(2,e.object==="chat.completion"&&(n=(i=e.choices)==null?void 0:i[0])!=null&&n.message?{text:e.choices[0].message.content||""}:{text:""});}},_callee127);}));function extractResultData(_x232){return _extractResultData26.apply(this,arguments);}return extractResultData;}()}]);}(I);var Hs=/*#__PURE__*/function(){function Hs(){_classCallCheck(this,Hs);}return _createClass(Hs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="invalid_request_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",method:"GET",handleVerificationResult:Hs.handleVerificationResult};}}]);}();var Sa=/*#__PURE__*/function(_I18){function Sa(e){var _this64$maxMessages,_n$model4;var _this64;_classCallCheck(this,Sa);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.qwen;_this64=_callSuper(this,Sa,[e,Hs.buildKeyVerificationDetails(),Hs.buildHeaders,s]),_this64.insertKeyPlaceholderText="Qwen API Key",_this64.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this64.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this64.permittedErrorPrefixes=["No static","The model","Incorrect"],_this64._systemMessage="You are a helpful assistant.";var i=t.qwen;_typeof(i)=="object"&&(i.system_prompt&&(_this64._systemMessage=i.system_prompt),_this64.cleanConfig(i),Object.assign(_this64.rawBody,i)),(_this64$maxMessages=_this64.maxMessages)!==null&&_this64$maxMessages!==void 0?_this64$maxMessages:_this64.maxMessages=-1,(_n$model4=(n=_this64.rawBody).model)!==null&&_n$model4!==void 0?_n$model4:n.model="qwen-plus";return _this64;}_inherits(Sa,_I18);return _createClass(Sa,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e,t){var s,i;return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:if(this.connectSettings){_context128.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 2:return _context128.a(2);}},_callee128,this);}));function callServiceAPI(_x233,_x234){return _callServiceAPI24.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e){var t;return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:if(!e.error){_context129.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context129.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context129.n=2;break;}return _context129.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context129.n=3;break;}return _context129.a(2,{text:t.message.content});case 3:return _context129.a(2,{text:""});}},_callee129);}));function extractResultData(_x235){return _extractResultData27.apply(this,arguments);}return extractResultData;}()}]);}(I);var qs=/*#__PURE__*/function(){function qs(){_classCallCheck(this,qs);}return _createClass(qs,null,[{key:"buildHeaders",value:function buildHeaders(){return{"Content-Type":"application/json"};}// prettier-ignore
|
222
225
|
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var o;var n=e;n.error?n.error.code===403||(o=n.error.message)!=null&&o.includes("API key")?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}// https://ai.google.dev/api/models#method:-models.list
|
223
|
-
},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){var e="https://generativelanguage.googleapis.com/v1beta/models?key=";return{url:e,augmentUrl:function augmentUrl(t){return"".concat(e).concat(t);},method:"GET",handleVerificationResult:
|
224
|
-
function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemInstruction)==null?void 0:n.length)||0):-1).map(function(o){return qi.getContent(o);});return s.contents=i,this._systemInstruction&&(s.systemInstruction={parts:[{text:this._systemInstruction}]}),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee130(e,t){var s,i;return _regeneratorRuntime().wrap(function _callee130$(_context130){while(1)switch(_context130.prev=_context130.next){case 0:if(this.connectSettings){_context130.next=2;break;}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),_.request(this,s,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),R.request(this,s,e));case 4:case"end":return _context130.stop();}},_callee130,this);}));function callServiceAPI(_x236,_x237){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee131(e){var t,s,i,n,o;return _regeneratorRuntime().wrap(function _callee131$(_context131){while(1)switch(_context131.prev=_context131.next){case 0:if(!e.error){_context131.next=2;break;}throw e.error.message||"Gemini API Error";case 2:return _context131.abrupt("return",(o=(n=(i=(s=(t=e.candidates)==null?void 0:t[0])==null?void 0:s.content)==null?void 0:i.parts)==null?void 0:n[0])!=null&&o.text?{text:e.candidates[0].content.parts[0].text}:{text:""});case 3:case"end":return _context131.stop();}},_callee131);}));function extractResultData(_x238){return _extractResultData28.apply(this,arguments);}return extractResultData;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e.text&&e.text.trim().length>0&&t.push({text:e.text}),e.files&&e.files.length>0&&e.files.forEach(function(s){if(s.src&&s.src.includes("data:")){var _s$src$split=s.src.split(","),_s$src$split2=_slicedToArray(_s$src$split,2),i=_s$src$split2[0],n=_s$src$split2[1];t.push({inlineData:{mimeType:i.replace("data:","").replace(";base64",""),data:n}});}}),{parts:t,role:e.role===b.USER_ROLE?"user":"model"};}}]);}(I);var qs=/*#__PURE__*/function(){function qs(){_classCallCheck(this,qs);}return _createClass(qs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"x-api-key":e,"Content-Type":"application/json","anthropic-version":"2023-06-01","anthropic-dangerous-direct-browser-access":"true"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/messages",method:"POST",handleVerificationResult:qs.handleVerificationResult};}}]);}();var Vs=/*#__PURE__*/function(_I20){function Vs(e){var _this66$maxMessages,_c$model,_d$max_tokens;var _this66;_classCallCheck(this,Vs);var a,l,c,d;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.claude,i=t.claude;var n;_typeof(i)=="object"&&i.mcp_servers&&(n=i.mcp_servers);var o=n&&n.length>0?function(u){return{"x-api-key":u,"Content-Type":"application/json","anthropic-version":"2023-06-01","anthropic-dangerous-direct-browser-access":"true","anthropic-beta":"mcp-client-2025-04-04"};}:qs.buildHeaders;if(_this66=_callSuper(this,Vs,[e,qs.buildKeyVerificationDetails(),o,s]),_this66.insertKeyPlaceholderText="Claude API Key",_this66.keyHelpUrl="https://console.anthropic.com/settings/keys",_this66.url="https://api.anthropic.com/v1/messages",_this66.permittedErrorPrefixes=["authentication_error","invalid_request_error"],_this66.asyncCallInProgress=!1,_this66._streamToolCalls={type:"tool_use",id:"",name:"",input:""},_this66._systemMessage="You are a helpful assistant.",_typeof(i)=="object"){i.system_prompt&&(_this66._systemMessage=i.system_prompt);var u=(l=(a=e.directConnection)==null?void 0:a.claude)==null?void 0:l.function_handler;u&&(_this66._functionHandler=u),i.mcp_servers&&(_this66._mcpServers=i.mcp_servers),_this66.cleanConfig(i),Object.assign(_this66.rawBody,i);}(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1,(_c$model=(c=_this66.rawBody).model)!==null&&_c$model!==void 0?_c$model:c.model="claude-3-5-sonnet-20241022",(_d$max_tokens=(d=_this66.rawBody).max_tokens)!==null&&_d$max_tokens!==void 0?_d$max_tokens:d.max_tokens=4096;return _this66;}_inherits(Vs,_I20);return _createClass(Vs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key,delete e.mcp_servers;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Vs.getContent(n),role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=i,this._systemMessage&&(s.system=this._systemMessage),this._mcpServers&&this._mcpServers.length>0&&(s.mcp_servers=this._mcpServers),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee132(e,t){var _this$_messages4;var s,i;return _regeneratorRuntime().wrap(function _callee132$(_context132){while(1)switch(_context132.prev=_context132.next){case 0:if(this.connectSettings){_context132.next=2;break;}throw new Error("Request settings have not been set up");case 2:(_this$_messages4=this._messages)!==null&&_this$_messages4!==void 0?_this$_messages4:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 5:case"end":return _context132.stop();}},_callee132,this);}));function callServiceAPI(_x239,_x240){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee133(e,t,s){var i,n,o,a,l;return _regeneratorRuntime().wrap(function _callee133$(_context133){while(1)switch(_context133.prev=_context133.next){case 0:if(!e.error){_context133.next=2;break;}throw e.error.message;case 2:if(!(e.content&&e.content.length>0)){_context133.next=9;break;}a=e.content.find(function(c){return c.type==="tool_use";});if(!a){_context133.next=6;break;}return _context133.abrupt("return",this.handleTools([a],t,s));case 6:l=e.content.find(function(c){return c.type==="text";});if(!l){_context133.next=9;break;}return _context133.abrupt("return",{text:l.text});case 9:if(!(e.type==="message_start")){_context133.next=13;break;}this.asyncCallInProgress=!1;_context133.next=15;break;case 13:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context133.next=15;break;}return _context133.abrupt("return",{text:e.delta.text||""});case 15:if(!(e.type==="content_block_start"&&((i=e.content_block)==null?void 0:i.type)==="tool_use")){_context133.next=19;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context133.next=25;break;case 19:if(!(e.type==="content_block_delta"&&((n=e.delta)==null?void 0:n.type)==="input_json_delta")){_context133.next=23;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context133.next=25;break;case 23:if(!(e.type==="message_delta"&&((o=e.delta)==null?void 0:o.stop_reason)==="tool_use")){_context133.next=25;break;}return _context133.abrupt("return",(this.asyncCallInProgress=!0,this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t,s)));case 25:return _context133.abrupt("return",{text:""});case 26:case"end":return _context133.stop();}},_callee133,this);}));function extractResultData(_x241,_x242,_x243){return _extractResultData29.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee134(e,t,s){var c,d,u,h,p,i,n,o,m,f,a,l,_m,_f,g;return _regeneratorRuntime().wrap(function _callee134$(_context134){while(1)switch(_context134.prev=_context134.next){case 0:if(!(!e||!t||!s||!this._functionHandler)){_context134.next=2;break;}throw Error("Please define the `function_handler` property inside the [claude](https://deepchat.dev/docs/directConnection/claude) object.");case 2:i=JSON.parse(JSON.stringify(s));n=e.map(function(m){return{name:m.name,arguments:JSON.stringify(m.input)};});_context134.next=6;return(c=this._functionHandler)==null?void 0:c.call(this,n);case 6:o=_context134.sent;if(Array.isArray(o)){_context134.next=20;break;}if(!o.text){_context134.next=19;break;}m={text:o.text};_context134.next=12;return(u=(d=this.deepChat).responseInterceptor)==null?void 0:u.call(d,m);case 12:_context134.t0=_context134.sent;if(_context134.t0){_context134.next=15;break;}_context134.t0=m;case 15:f=_context134.t0;if(!Array.isArray(f)){_context134.next=18;break;}throw Error("Function tool response interceptor cannot return an array");case 18:return _context134.abrupt("return",f);case 19:throw Error("Function tool response must be an array or contain a text property");case 20:_context134.next=22;return Promise.all(o);case 22:a=_context134.sent;l=e.map(function(m){return{type:"tool_use",id:m.id,name:m.name,input:m.input};});if(!(i.messages.push({role:"assistant",content:l}),!a.find(function(_ref34){var m=_ref34.response;return typeof m!="string";})&&n.length===a.length)){_context134.next=51;break;}_m=a.map(function(f,g){return{type:"tool_result",tool_use_id:e[g].id,content:f.response};});i.messages.push({role:"user",content:_m});_context134.prev=27;if(!(this.stream&&this._messages)){_context134.next=30;break;}return _context134.abrupt("return",(_.request(this,i,this._messages),{text:""}));case 30:_context134.next=32;return t==null?void 0:t(i).then(function(g){return E.processResponseByType(g);});case 32:_f=_context134.sent;_context134.next=35;return(p=(h=this.deepChat).responseInterceptor)==null?void 0:p.call(h,_f);case 35:_context134.t1=_context134.sent;if(_context134.t1){_context134.next=38;break;}_context134.t1=_f;case 38:_f=_context134.t1;if(!_f.error){_context134.next=41;break;}throw _f.error.message;case 41:if(!(_f.content&&_f.content.length>0)){_context134.next=45;break;}g=_f.content.find(function(y){return y.type==="text";});if(!g){_context134.next=45;break;}return _context134.abrupt("return",{text:g.text});case 45:return _context134.abrupt("return",{text:""});case 48:_context134.prev=48;_context134.t2=_context134["catch"](27);throw this.asyncCallInProgress=!1,_context134.t2;case 51:throw Error("Function tool response must be an array or contain a text property");case 52:case"end":return _context134.stop();}},_callee134,this,[[27,48]]);}));function handleTools(_x244,_x245,_x246){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var s,i,n;if(t.type==="image"){var o=(s=t.src)==null?void 0:s.split(",")[1];return{type:"image",source:{type:"base64",media_type:((n=(i=t.src)==null?void 0:i.match(/data:([^;]+)/))==null?void 0:n[1])||"image/jpeg",data:o||""}};}return{type:"text",text:"[Unsupported file type: ".concat(t.type,"]")};});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=Vs.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t;}return e.text||"";}}]);}(I);var Gs=/*#__PURE__*/function(){function Gs(){_classCallCheck(this,Gs);}return _createClass(Gs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="invalid_request_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",method:"GET",handleVerificationResult:Gs.handleVerificationResult};}}]);}();var wa=/*#__PURE__*/function(_I21){function wa(e){var _this67$maxMessages,_n$model4;var _this67;_classCallCheck(this,wa);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.qwen;_this67=_callSuper(this,wa,[e,Gs.buildKeyVerificationDetails(),Gs.buildHeaders,s]),_this67.insertKeyPlaceholderText="Qwen API Key",_this67.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this67.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this67.permittedErrorPrefixes=["No static","The model","Incorrect"],_this67._systemMessage="You are a helpful assistant.";var i=t.qwen;_typeof(i)=="object"&&(i.system_prompt&&(_this67._systemMessage=i.system_prompt),_this67.cleanConfig(i),Object.assign(_this67.rawBody,i)),(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1,(_n$model4=(n=_this67.rawBody).model)!==null&&_n$model4!==void 0?_n$model4:n.model="qwen-plus";return _this67;}_inherits(wa,_I21);return _createClass(wa,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee135(e,t){var s,i;return _regeneratorRuntime().wrap(function _callee135$(_context135){while(1)switch(_context135.prev=_context135.next){case 0:if(this.connectSettings){_context135.next=2;break;}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 4:case"end":return _context135.stop();}},_callee135,this);}));function callServiceAPI(_x247,_x248){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee136(e){var t;return _regeneratorRuntime().wrap(function _callee136$(_context136){while(1)switch(_context136.prev=_context136.next){case 0:if(!e.error){_context136.next=2;break;}throw e.error.message;case 2:if(!(e.choices&&e.choices.length>0)){_context136.next=8;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context136.next=6;break;}return _context136.abrupt("return",{text:t.delta.content});case 6:if(!(t.message&&t.message.content)){_context136.next=8;break;}return _context136.abrupt("return",{text:t.message.content});case 8:return _context136.abrupt("return",{text:""});case 9:case"end":return _context136.stop();}},_callee136);}));function extractResultData(_x249){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(I);var mn=/*#__PURE__*/function(){function mn(){_classCallCheck(this,mn);}return _createClass(mn,null,[{key:"buildHeaders",value:function buildHeaders(){return{};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"",method:"GET",handleVerificationResult:function handleVerificationResult(){}};}}]);}();var zs=/*#__PURE__*/function(_I22){function zs(e){var _this68$maxMessages,_l$model2,_c$stream;var _this68;_classCallCheck(this,zs);var o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=mn.buildKeyVerificationDetails(),i=mn.buildHeaders;_this68=_callSuper(this,zs,[e,s,i,{key:"placeholder"}]),_this68.insertKeyPlaceholderText="",_this68.keyHelpUrl="",_this68.validateKeyProperty=!1,_this68.url="http://localhost:11434/api/chat",_this68.permittedErrorPrefixes=["Error"],_this68.asyncCallInProgress=!1;var n=t.ollama;if(_typeof(n)=="object"){n.system&&(_this68._systemMessage=zs.generateSystemMessage(n.system));var d=(a=(o=e.directConnection)==null?void 0:o.ollama)==null?void 0:a.function_handler;d&&(_this68._functionHandler=d),_this68.cleanConfig(n),Object.assign(_this68.rawBody,n);}(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_l$model2=(l=_this68.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="llama3.2",(_c$stream=(c=_this68.rawBody).stream)!==null&&_c$stream!==void 0?_c$stream:c.stream=!1;return _this68;}_inherits(zs,_I22);return _createClass(zs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system,delete e.function_handler;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemMessage)==null?void 0:n.content.length)||0):-1).map(function(o){var a={content:o.text||"",role:o.role===b.USER_ROLE?"user":"assistant"};if(o.files&&o.files.length>0){var l=zs.getImageData(o.files);l.length>0&&(a.images=l);}return a;});return s.messages=_toConsumableArray(i),this._systemMessage&&s.messages.unshift(this._systemMessage),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee137(e,t){var _this$_messages5;var s,i;return _regeneratorRuntime().wrap(function _callee137$(_context137){while(1)switch(_context137.prev=_context137.next){case 0:if(this.connectSettings){_context137.next=2;break;}throw new Error("Request settings have not been set up");case 2:(_this$_messages5=this._messages)!==null&&_this$_messages5!==void 0?_this$_messages5:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,this.stream={readable:!0},_.request(this,s,e)):R.request(this,s,e);case 5:case"end":return _context137.stop();}},_callee137,this);}));function callServiceAPI(_x250,_x251){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee138(e,t,s){var i,n,o;return _regeneratorRuntime().wrap(function _callee138$(_context138){while(1)switch(_context138.prev=_context138.next){case 0:if(!e.error){_context138.next=2;break;}throw e.error.message;case 2:if(!e.text){_context138.next=5;break;}o=JSON.parse(e.text);return _context138.abrupt("return",(i=o.message)!=null&&i.tool_calls?(this.asyncCallInProgress=!0,this.handleTools({tool_calls:o.message.tool_calls},t,s)):(this.asyncCallInProgress=!1,{text:((n=o.message)==null?void 0:n.content)||""}));case 5:return _context138.abrupt("return",e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t,s):{text:e.message.content||""}:{text:""});case 6:case"end":return _context138.stop();}},_callee138,this);}));function extractResultData(_x252,_x253,_x254){return _extractResultData31.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee139(e,t,s){var l,c,d,u,h,p,i,n,o,m,f,a,_m2;return _regeneratorRuntime().wrap(function _callee139$(_context139){while(1)switch(_context139.prev=_context139.next){case 0:if(!(!e.tool_calls||!t||!s||!this._functionHandler)){_context139.next=2;break;}throw Error("Please define the `function_handler` property inside the [ollama](https://deepchat.dev/docs/directConnection/ollama) object.");case 2:i=JSON.parse(JSON.stringify(s));n=e.tool_calls.map(function(m){return{name:m["function"].name,arguments:m["function"].arguments};});_context139.next=6;return(l=this._functionHandler)==null?void 0:l.call(this,n);case 6:o=_context139.sent;if(Array.isArray(o)){_context139.next=20;break;}if(!o.text){_context139.next=19;break;}m={text:o.text};_context139.next=12;return(d=(c=this.deepChat).responseInterceptor)==null?void 0:d.call(c,m);case 12:_context139.t0=_context139.sent;if(_context139.t0){_context139.next=15;break;}_context139.t0=m;case 15:f=_context139.t0;if(!Array.isArray(f)){_context139.next=18;break;}throw Error("Function tool response interceptor cannot return an array");case 18:return _context139.abrupt("return",f);case 19:throw Error("Function tool response must be an array or contain a text property");case 20:_context139.next=22;return Promise.all(o);case 22:a=_context139.sent;if(!(i.messages.push({tool_calls:e.tool_calls,role:"assistant",content:""}),!a.find(function(_ref35){var m=_ref35.response;return typeof m!="string";})&&n.length===a.length)){_context139.next=45;break;}a.forEach(function(m,f){var y;var g=(y=e.tool_calls)==null?void 0:y[f];i==null||i.messages.push({role:"tool",tool_name:g==null?void 0:g["function"].name,content:m.response});});_context139.prev=25;if(!(this.stream&&this._messages)){_context139.next=28;break;}return _context139.abrupt("return",(_.request(this,i,this._messages),{text:""}));case 28:_context139.next=30;return t==null?void 0:t(i).then(function(f){return E.processResponseByType(f);});case 30:_m2=_context139.sent;_context139.next=33;return(h=(u=this.deepChat).responseInterceptor)==null?void 0:h.call(u,_m2);case 33:_context139.t1=_context139.sent;if(_context139.t1){_context139.next=36;break;}_context139.t1=_m2;case 36:_m2=_context139.t1;if(!_m2.error){_context139.next=39;break;}throw _m2.error.message;case 39:return _context139.abrupt("return",{text:((p=_m2.message)==null?void 0:p.content)||""});case 42:_context139.prev=42;_context139.t2=_context139["catch"](25);throw this.asyncCallInProgress=!1,_context139.t2;case 45:throw Error("Function tool response must be an array or contain a text property");case 46:case"end":return _context139.stop();}},_callee139,this,[[25,42]]);}));function handleTools(_x255,_x256,_x257){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"generateSystemMessage",value:function generateSystemMessage(e){return{role:"system",content:e};}},{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t.type==="image";}).map(function(t){var i;return((i=t.src)==null?void 0:i.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(I);var Aa=/*#__PURE__*/function(){function Aa(){_classCallCheck(this,Aa);}return _createClass(Aa,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
|
225
|
-
function create(e){var t=e.directConnection,s=e.connect,i=e.demo,n=e.webModel;if(n)return new cs(e);if(t){if(t.openAI)return t.openAI.images?new
|
226
|
-
},{key:"createImageMessage",value:function createImageMessage(e,t,s,i){var n=K.createImage(t,e.elementRef,!i&&!e.focusMode),o=e.createNewMessageElement("",s);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(K.IMAGE_BUBBLE_CLASS),{type:"image",elements:o};}},{key:"createAudioElement",value:function createAudioElement(e,t){var s=document.createElement("audio");return s.src=e.src,s.classList.add("audio-player"),s.controls=!0,
|
227
|
-
},{key:"addMessages",value:function addMessages(e,t,s,i){K.createMessages(e,t,s,i).filter(function(o){return o!==void 0;}).forEach(function(_ref36){var o=_ref36.type,a=_ref36.elements;z.addMessage(e,a,o,s,i);});}}]);}();K.IMAGE_BUBBLE_CLASS="image-message",K.AUDIO_BUBBLE_CLASS="audio-message",K.ANY_FILE_BUBBLE_CLASS="any-file-message";var
|
228
|
-
},{key:"updateFileMessages",value:function updateFileMessages(e,t,s){var u,h;var i=t[0].role,n
|
229
|
-
},{key:"update",value:function update(e,t,s){var i=e.messageToElements[s];if(i){if(de.isElementActive(i[1]))return console.error("Cannot update a message that is being streamed");t.text&&de.updateTextMessage(e,i,t.text),t.files?de.updateFileMessages(e,i,t.files):de.removeFilesMessages(e,i),t.html&&de.updateHTMLMessage(e,i,t.html),!t.text&&i[1].text&&de.removeTextHTMLMessage(e,i,"text"),!t.html&&i[1].html&&de.removeTextHTMLMessage(e,i,"html");var n=e.messageElementRefs,o=e.avatar,a=e.name;b.classifyRoleMessages(n),b.resetAllRoleElements(n,o,a);}else console.error("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var
|
230
|
-
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var
|
226
|
+
},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){var e="https://generativelanguage.googleapis.com/v1beta/models?key=";return{url:e,augmentUrl:function augmentUrl(t){return"".concat(e).concat(t);},method:"GET",handleVerificationResult:qs.handleVerificationResult};}}]);}();var Hi=/*#__PURE__*/function(_I19){function Hi(e){var _this65$maxMessages;var _this65;_classCallCheck(this,Hi);var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.gemini,i=t.gemini;var n;_this65=_callSuper(this,Hi,[e,qs.buildKeyVerificationDetails(),qs.buildHeaders,s]),_this65.insertKeyPlaceholderText="Gemini API Key",_this65.keyHelpUrl="https://aistudio.google.com/app/apikey",_this65.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent",_this65.url="",_this65.permittedErrorPrefixes=["API_KEY_INVALID"],i&&(i.systemInstruction&&(n=i.systemInstruction),i.model&&(_this65.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(i.model,":generateContent")),Object.defineProperty(_assertThisInitialized(_this65),"_systemInstruction",{value:n,writable:!1}),_this65.cleanConfig(i),Object.assign(_this65.rawBody,i),(_this65$maxMessages=_this65.maxMessages)!==null&&_this65$maxMessages!==void 0?_this65$maxMessages:_this65.maxMessages=-1);return _this65;}_inherits(Hi,_I19);return _createClass(Hi,[{key:"cleanConfig",value:function cleanConfig(e){delete e.systemInstruction,delete e.model,delete e.key;}},{key:"preprocessBody",value:// prettier-ignore
|
227
|
+
function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemInstruction)==null?void 0:n.length)||0):-1).map(function(o){return Hi.getContent(o);});return s.contents=i,this._systemInstruction&&(s.systemInstruction={parts:[{text:this._systemInstruction}]}),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(e,t){var s,i;return _regenerator().w(function(_context130){while(1)switch(_context130.n){case 0:if(this.connectSettings){_context130.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),_.request(this,s,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),R.request(this,s,e));case 2:return _context130.a(2);}},_callee130,this);}));function callServiceAPI(_x236,_x237){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(e){var t,s,i,n,o;return _regenerator().w(function(_context131){while(1)switch(_context131.n){case 0:if(!e.error){_context131.n=1;break;}throw e.error.message||"Gemini API Error";case 1:return _context131.a(2,(o=(n=(i=(s=(t=e.candidates)==null?void 0:t[0])==null?void 0:s.content)==null?void 0:i.parts)==null?void 0:n[0])!=null&&o.text?{text:e.candidates[0].content.parts[0].text}:{text:""});}},_callee131);}));function extractResultData(_x238){return _extractResultData28.apply(this,arguments);}return extractResultData;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e.text&&e.text.trim().length>0&&t.push({text:e.text}),e.files&&e.files.length>0&&e.files.forEach(function(s){if(s.src&&s.src.includes("data:")){var _s$src$split=s.src.split(","),_s$src$split2=_slicedToArray(_s$src$split,2),i=_s$src$split2[0],n=_s$src$split2[1];t.push({inlineData:{mimeType:i.replace("data:","").replace(";base64",""),data:n}});}}),{parts:t,role:e.role===b.USER_ROLE?"user":"model"};}}]);}(I);var Vs=/*#__PURE__*/function(){function Vs(){_classCallCheck(this,Vs);}return _createClass(Vs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"x-api-key":e,"Content-Type":"application/json","anthropic-version":"2023-06-01","anthropic-dangerous-direct-browser-access":"true"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(C.INVALID_KEY):i(C.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/messages",method:"POST",handleVerificationResult:Vs.handleVerificationResult};}}]);}();var Gs=/*#__PURE__*/function(_I20){function Gs(e){var _this66$maxMessages,_c$model,_d$max_tokens;var _this66;_classCallCheck(this,Gs);var a,l,c,d;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.claude,i=t.claude;var n;_typeof(i)=="object"&&i.mcp_servers&&(n=i.mcp_servers);var o=n&&n.length>0?function(u){return{"x-api-key":u,"Content-Type":"application/json","anthropic-version":"2023-06-01","anthropic-dangerous-direct-browser-access":"true","anthropic-beta":"mcp-client-2025-04-04"};}:Vs.buildHeaders;if(_this66=_callSuper(this,Gs,[e,Vs.buildKeyVerificationDetails(),o,s]),_this66.insertKeyPlaceholderText="Claude API Key",_this66.keyHelpUrl="https://console.anthropic.com/settings/keys",_this66.url="https://api.anthropic.com/v1/messages",_this66.permittedErrorPrefixes=["authentication_error","invalid_request_error"],_this66.asyncCallInProgress=!1,_this66._streamToolCalls={type:"tool_use",id:"",name:"",input:""},_this66._systemMessage="You are a helpful assistant.",_typeof(i)=="object"){i.system_prompt&&(_this66._systemMessage=i.system_prompt);var u=(l=(a=e.directConnection)==null?void 0:a.claude)==null?void 0:l.function_handler;u&&(_this66._functionHandler=u),i.mcp_servers&&(_this66._mcpServers=i.mcp_servers),_this66.cleanConfig(i),Object.assign(_this66.rawBody,i);}(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1,(_c$model=(c=_this66.rawBody).model)!==null&&_c$model!==void 0?_c$model:c.model="claude-3-5-sonnet-20241022",(_d$max_tokens=(d=_this66.rawBody).max_tokens)!==null&&_d$max_tokens!==void 0?_d$max_tokens:d.max_tokens=4096;return _this66;}_inherits(Gs,_I20);return _createClass(Gs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key,delete e.mcp_servers;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Gs.getContent(n),role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=i,this._systemMessage&&(s.system=this._systemMessage),this._mcpServers&&this._mcpServers.length>0&&(s.mcp_servers=this._mcpServers),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee132(e,t){var _this$_messages4;var s,i;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:if(this.connectSettings){_context132.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages4=this._messages)!==null&&_this$_messages4!==void 0?_this$_messages4:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):R.request(this,s,e);case 2:return _context132.a(2);}},_callee132,this);}));function callServiceAPI(_x239,_x240){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t,s){var i,n,o,a,l;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:if(!e.error){_context133.n=1;break;}throw e.error.message;case 1:if(!(e.content&&e.content.length>0)){_context133.n=3;break;}a=e.content.find(function(c){return c.type==="tool_use";});if(!a){_context133.n=2;break;}return _context133.a(2,this.handleTools([a],t,s));case 2:l=e.content.find(function(c){return c.type==="text";});if(!l){_context133.n=3;break;}return _context133.a(2,{text:l.text});case 3:if(!(e.type==="message_start")){_context133.n=4;break;}this.asyncCallInProgress=!1;_context133.n=5;break;case 4:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context133.n=5;break;}return _context133.a(2,{text:e.delta.text||""});case 5:if(!(e.type==="content_block_start"&&((i=e.content_block)==null?void 0:i.type)==="tool_use")){_context133.n=6;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context133.n=8;break;case 6:if(!(e.type==="content_block_delta"&&((n=e.delta)==null?void 0:n.type)==="input_json_delta")){_context133.n=7;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context133.n=8;break;case 7:if(!(e.type==="message_delta"&&((o=e.delta)==null?void 0:o.stop_reason)==="tool_use")){_context133.n=8;break;}return _context133.a(2,(this.asyncCallInProgress=!0,this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t,s)));case 8:return _context133.a(2,{text:""});}},_callee133,this);}));function extractResultData(_x241,_x242,_x243){return _extractResultData29.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t,s){var c,d,u,h,p,i,n,o,m,f,a,l,_m,_f,g,_t43,_t44,_t45;return _regenerator().w(function(_context134){while(1)switch(_context134.p=_context134.n){case 0:if(!(!e||!t||!s||!this._functionHandler)){_context134.n=1;break;}throw Error("Please define the `function_handler` property inside the [claude](https://deepchat.dev/docs/directConnection/claude) object.");case 1:i=JSON.parse(JSON.stringify(s));n=e.map(function(m){return{name:m.name,arguments:JSON.stringify(m.input)};});_context134.n=2;return(c=this._functionHandler)==null?void 0:c.call(this,n);case 2:o=_context134.v;if(Array.isArray(o)){_context134.n=7;break;}if(!o.text){_context134.n=6;break;}m={text:o.text};_context134.n=3;return(u=(d=this.deepChat).responseInterceptor)==null?void 0:u.call(d,m);case 3:_t43=_context134.v;if(_t43){_context134.n=4;break;}_t43=m;case 4:f=_t43;if(!Array.isArray(f)){_context134.n=5;break;}throw Error("Function tool response interceptor cannot return an array");case 5:return _context134.a(2,f);case 6:throw Error("Function tool response must be an array or contain a text property");case 7:_context134.n=8;return Promise.all(o);case 8:a=_context134.v;l=e.map(function(m){return{type:"tool_use",id:m.id,name:m.name,input:m.input};});if(!(i.messages.push({role:"assistant",content:l}),!a.find(function(_ref34){var m=_ref34.response;return typeof m!="string";})&&n.length===a.length)){_context134.n=17;break;}_m=a.map(function(f,g){return{type:"tool_result",tool_use_id:e[g].id,content:f.response};});i.messages.push({role:"user",content:_m});_context134.p=9;if(!(this.stream&&this._messages)){_context134.n=10;break;}return _context134.a(2,(_.request(this,i,this._messages),{text:""}));case 10:_context134.n=11;return t==null?void 0:t(i).then(function(g){return E.processResponseByType(g);});case 11:_f=_context134.v;_context134.n=12;return(p=(h=this.deepChat).responseInterceptor)==null?void 0:p.call(h,_f);case 12:_t44=_context134.v;if(_t44){_context134.n=13;break;}_t44=_f;case 13:_f=_t44;if(!_f.error){_context134.n=14;break;}throw _f.error.message;case 14:if(!(_f.content&&_f.content.length>0)){_context134.n=15;break;}g=_f.content.find(function(y){return y.type==="text";});if(!g){_context134.n=15;break;}return _context134.a(2,{text:g.text});case 15:return _context134.a(2,{text:""});case 16:_context134.p=16;_t45=_context134.v;throw this.asyncCallInProgress=!1,_t45;case 17:throw Error("Function tool response must be an array or contain a text property");case 18:return _context134.a(2);}},_callee134,this,[[9,16]]);}));function handleTools(_x244,_x245,_x246){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var s,i,n;if(t.type==="image"){var o=(s=t.src)==null?void 0:s.split(",")[1];return{type:"image",source:{type:"base64",media_type:((n=(i=t.src)==null?void 0:i.match(/data:([^;]+)/))==null?void 0:n[1])||"image/jpeg",data:o||""}};}return{type:"text",text:"[Unsupported file type: ".concat(t.type,"]")};});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=Gs.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t;}return e.text||"";}}]);}(I);var pn=/*#__PURE__*/function(){function pn(){_classCallCheck(this,pn);}return _createClass(pn,null,[{key:"buildHeaders",value:function buildHeaders(){return{};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"",method:"GET",handleVerificationResult:function handleVerificationResult(){}};}}]);}();var zs=/*#__PURE__*/function(_I21){function zs(e){var _this67$maxMessages,_l$model2,_c$stream;var _this67;_classCallCheck(this,zs);var o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=pn.buildKeyVerificationDetails(),i=pn.buildHeaders;_this67=_callSuper(this,zs,[e,s,i,{key:"placeholder"}]),_this67.insertKeyPlaceholderText="",_this67.keyHelpUrl="",_this67.validateKeyProperty=!1,_this67.url="http://localhost:11434/api/chat",_this67.permittedErrorPrefixes=["Error"],_this67.asyncCallInProgress=!1;var n=t.ollama;if(_typeof(n)=="object"){n.system&&(_this67._systemMessage=zs.generateSystemMessage(n.system));var d=(a=(o=e.directConnection)==null?void 0:o.ollama)==null?void 0:a.function_handler;d&&(_this67._functionHandler=d),_this67.cleanConfig(n),Object.assign(_this67.rawBody,n);}(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1,(_l$model2=(l=_this67.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="llama3.2",(_c$stream=(c=_this67.rawBody).stream)!==null&&_c$stream!==void 0?_c$stream:c.stream=!1;return _this67;}_inherits(zs,_I21);return _createClass(zs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system,delete e.function_handler;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=ne.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemMessage)==null?void 0:n.content.length)||0):-1).map(function(o){var a={content:o.text||"",role:o.role===b.USER_ROLE?"user":"assistant"};if(o.files&&o.files.length>0){var l=zs.getImageData(o.files);l.length>0&&(a.images=l);}return a;});return s.messages=_toConsumableArray(i),this._systemMessage&&s.messages.unshift(this._systemMessage),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e,t){var _this$_messages5;var s,i;return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:if(this.connectSettings){_context135.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages5=this._messages)!==null&&_this$_messages5!==void 0?_this$_messages5:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,this.stream={readable:!0},_.request(this,s,e)):R.request(this,s,e);case 2:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x247,_x248){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e,t,s){var i,n,o;return _regenerator().w(function(_context136){while(1)switch(_context136.n){case 0:if(!e.error){_context136.n=1;break;}throw e.error.message;case 1:if(!e.text){_context136.n=2;break;}o=JSON.parse(e.text);return _context136.a(2,(i=o.message)!=null&&i.tool_calls?(this.asyncCallInProgress=!0,this.handleTools({tool_calls:o.message.tool_calls},t,s)):(this.asyncCallInProgress=!1,{text:((n=o.message)==null?void 0:n.content)||""}));case 2:return _context136.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t,s):{text:e.message.content||""}:{text:""});}},_callee136,this);}));function extractResultData(_x249,_x250,_x251){return _extractResultData30.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e,t,s){var l,c,d,u,h,p,i,n,o,m,f,a,_m2,_t46,_t47,_t48;return _regenerator().w(function(_context137){while(1)switch(_context137.p=_context137.n){case 0:if(!(!e.tool_calls||!t||!s||!this._functionHandler)){_context137.n=1;break;}throw Error("Please define the `function_handler` property inside the [ollama](https://deepchat.dev/docs/directConnection/ollama) object.");case 1:i=JSON.parse(JSON.stringify(s));n=e.tool_calls.map(function(m){return{name:m["function"].name,arguments:m["function"].arguments};});_context137.n=2;return(l=this._functionHandler)==null?void 0:l.call(this,n);case 2:o=_context137.v;if(Array.isArray(o)){_context137.n=7;break;}if(!o.text){_context137.n=6;break;}m={text:o.text};_context137.n=3;return(d=(c=this.deepChat).responseInterceptor)==null?void 0:d.call(c,m);case 3:_t46=_context137.v;if(_t46){_context137.n=4;break;}_t46=m;case 4:f=_t46;if(!Array.isArray(f)){_context137.n=5;break;}throw Error("Function tool response interceptor cannot return an array");case 5:return _context137.a(2,f);case 6:throw Error("Function tool response must be an array or contain a text property");case 7:_context137.n=8;return Promise.all(o);case 8:a=_context137.v;if(!(i.messages.push({tool_calls:e.tool_calls,role:"assistant",content:""}),!a.find(function(_ref35){var m=_ref35.response;return typeof m!="string";})&&n.length===a.length)){_context137.n=16;break;}a.forEach(function(m,f){var y;var g=(y=e.tool_calls)==null?void 0:y[f];i==null||i.messages.push({role:"tool",tool_name:g==null?void 0:g["function"].name,content:m.response});});_context137.p=9;if(!(this.stream&&this._messages)){_context137.n=10;break;}return _context137.a(2,(_.request(this,i,this._messages),{text:""}));case 10:_context137.n=11;return t==null?void 0:t(i).then(function(f){return E.processResponseByType(f);});case 11:_m2=_context137.v;_context137.n=12;return(h=(u=this.deepChat).responseInterceptor)==null?void 0:h.call(u,_m2);case 12:_t47=_context137.v;if(_t47){_context137.n=13;break;}_t47=_m2;case 13:_m2=_t47;if(!_m2.error){_context137.n=14;break;}throw _m2.error.message;case 14:return _context137.a(2,{text:((p=_m2.message)==null?void 0:p.content)||""});case 15:_context137.p=15;_t48=_context137.v;throw this.asyncCallInProgress=!1,_t48;case 16:throw Error("Function tool response must be an array or contain a text property");case 17:return _context137.a(2);}},_callee137,this,[[9,15]]);}));function handleTools(_x252,_x253,_x254){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"generateSystemMessage",value:function generateSystemMessage(e){return{role:"system",content:e};}},{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t.type==="image";}).map(function(t){var i;return((i=t.src)==null?void 0:i.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(I);var xa=/*#__PURE__*/function(){function xa(){_classCallCheck(this,xa);}return _createClass(xa,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
|
228
|
+
function create(e){var t=e.directConnection,s=e.connect,i=e.demo,n=e.webModel;if(n)return new cs(e);if(t){if(t.openAI)return t.openAI.images?new Mi(e):t.openAI.speechToText?new Ai(e):t.openAI.textToSpeech?new wi(e):t.openAI.assistant?new Fi(e):t.openAI.realtime?new xi(e):new ot(e);if(t.assemblyAI)return new Ui(e);if(t.cohere)return new Bs(e);if(t.huggingFace)return t.huggingFace.textGeneration?new la(e):t.huggingFace.summarization?new da(e):t.huggingFace.translation?new ua(e):t.huggingFace.fillMask?new pa(e):t.huggingFace.questionAnswer?new ca(e):t.huggingFace.audioSpeechRecognition?new aa(e):t.huggingFace.audioClassification?new ra(e):t.huggingFace.imageClassification?new oa(e):new ha(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new ji(e);if(t.azure.openAI.assistant)return new _i(e);}if(t.azure.speechToText)return new Ri(e);if(t.azure.textToSpeech)return new Ti(e);if(t.azure.summarization)return new Ci(e);if(t.azure.translation)return new ma(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new ks(e):t.stabilityAI.imageToImageUpscale?new Rs(e):t.stabilityAI.imageToImageMasking?new Ms(e):new Ls(e);if(t.mistral)return new Ea(e);if(t.gemini)return new Hi(e);if(t.claude)return new Gs(e);if(t.deepSeek)return new ba(e);if(t.openRouter)return new ga(e);if(t.kimi)return new va(e);if(t.grok)return t.grok.images?new ki(e):new _a(e);if(t.qwen)return new Sa(e);if(t.ollama)return new zs(e);}return s&&Object.keys(s).length>0&&!i?new ht(e):new ht(e,void 0,i||!0);}}]);}();var $i=/*#__PURE__*/_createClass(function $i(){_classCallCheck(this,$i);});$i.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 Li=$i;function w(r){return function(e,t){Object.defineProperty(e,t,{});var s=e.constructor,i=t.toLocaleLowerCase();s._attributes_[i]=Li.attibutes[r],s._attributeToProperty_[i]=t;};}var Ks=/*#__PURE__*/function(){function Ks(e,t,s){_classCallCheck(this,Ks);this._isDisplayed=!1,e?(this._elementRef=this.createIntroPanelWithChild(e,s),this._isDisplayed=!0):t&&(this._elementRef=this.createInternalIntroPanel(t,s),this._isDisplayed=!0);}return _createClass(Ks,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e,t){var s=Ks.createIntroPanel(t);return e.style.display==="none"&&(e.style.display="block"),s.appendChild(e),s;}},{key:"createInternalIntroPanel",value:function createInternalIntroPanel(e,t){var s=Ks.createIntroPanel(t);return s.id="internal-intro-panel",s.innerHTML=e,s;}},{key:"hide",value:function hide(){this._isDisplayed&&this._elementRef&&(this._elementRef.style.display="none",this._isDisplayed=!1);}},{key:"display",value:function display(){!this._isDisplayed&&this._elementRef&&(this._elementRef.style.display="",this._isDisplayed=!0);}}],[{key:"createIntroPanel",value:function createIntroPanel(e){var t=document.createElement("div");return t.classList.add("intro-panel"),Object.assign(t.style,e),t;}}]);}();var wa="<?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>",K=/*#__PURE__*/function(){function K(){_classCallCheck(this,K);}return _createClass(K,null,[{key:"createImage",value:function createImage(e,t,s){var i=new Image();return i.src=e.src,s&&z.scrollDownOnImageLoad(i.src,t),z.processContent("image",i,i.src,e.name);}// WORK - image still does not scroll down when loaded
|
229
|
+
},{key:"createImageMessage",value:function createImageMessage(e,t,s,i){var n=K.createImage(t,e.elementRef,!i&&!e.focusMode),o=e.createNewMessageElement("",s);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(K.IMAGE_BUBBLE_CLASS),{type:"image",elements:o};}},{key:"createAudioElement",value:function createAudioElement(e,t){var s=document.createElement("audio");return s.src=e.src,s.classList.add("audio-player"),s.controls=!0,He.IS_SAFARI&&(s.classList.add("audio-player-safari"),s.classList.add(t===b.USER_ROLE?"audio-player-safari-right":"audio-player-safari-left")),s;}},{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,s,i){var n=K.createAudioElement(t,s),o=e.createMessageElementsOnOrientation("",s,i);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(K.AUDIO_BUBBLE_CLASS),{type:"audio",elements:o,audioElement:n};}},{key:"createAnyFile",value:function createAnyFile(e){var t=document.createElement("div");t.classList.add("any-file-message-contents");var s=document.createElement("div");s.classList.add("any-file-message-icon-container");var i=Ve.createSVGElement(wa);i.classList.add("any-file-message-icon"),s.appendChild(i);var n=document.createElement("div");return n.classList.add("any-file-message-text"),n.textContent=e.name||z.DEFAULT_FILE_NAME,t.appendChild(s),t.appendChild(n),z.processContent("any",t,e.src,n.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,s,i){var n=e.createMessageElementsOnOrientation("",s,i),o=K.createAnyFile(t);return n.bubbleElement.classList.add(K.ANY_FILE_BUBBLE_CLASS),n.bubbleElement.appendChild(o),{type:"file",elements:n};}},{key:"createMessages",value:function createMessages(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;return t.map(function(n){var o;if(n.ref&&(n=z.removeFileRef(n)),z.isAudioFile(n)){var a=K.createNewAudioMessage(e,n,s,i),l=(o=e.textToSpeech)==null?void 0:o.service;return l&&(l.autoPlay&&K.autoPlayAudio(a.audioElement),typeof l.displayAudio=="boolean"&&!l.displayAudio)?void 0:a;}return z.isImageFile(n)?K.createImageMessage(e,n,s,i):K.createNewAnyFileMessage(e,n,s,i);}).filter(function(n){return n!==void 0;});}// no overwrite previous message logic as it is complex to track which files are to be overwritten
|
230
|
+
},{key:"addMessages",value:function addMessages(e,t,s,i){K.createMessages(e,t,s,i).filter(function(o){return o!==void 0;}).forEach(function(_ref36){var o=_ref36.type,a=_ref36.elements;z.addMessage(e,a,o,s,i);});}}]);}();K.IMAGE_BUBBLE_CLASS="image-message",K.AUDIO_BUBBLE_CLASS="audio-message",K.ANY_FILE_BUBBLE_CLASS="any-file-message";var Ws=K;var de=/*#__PURE__*/function(){function de(){_classCallCheck(this,de);}return _createClass(de,null,[{key:"removeElements",value:function removeElements(e,t){if(!t)return;var s=e.findIndex(function(i){return i===t;});e.splice(s,1),t==null||t.outerContainer.remove();}},{key:"removeFilesMessages",value:function removeFilesMessages(e,t){var s;(s=t[1].files)==null||s.forEach(function(i){de.removeElements(e.messageElementRefs,i);}),delete t[0].files,delete t[1].files;}},{key:"removeTextHTMLMessage",value:function removeTextHTMLMessage(e,t,s){var i=t[1][s];de.removeElements(e.messageElementRefs,i),delete t[0][s],delete t[1][s];}},{key:"updateHTMLMessage",value:function updateHTMLMessage(e,t,s){var i,n,o;if(t[1].html)Te.overwriteElements(e,s,t[1].html);else{var a=Te.create(e,s,t[0].role),l=((n=t[1].files)==null?void 0:n[((i=t[1].files)==null?void 0:i.length)-1])||t[1].text,c=l.outerContainer.nextSibling;(o=c==null?void 0:c.parentElement)==null||o.insertBefore(a.outerContainer,c),e.messageElementRefs.splice(e.messageElementRefs.length-1,1);var d=e.messageElementRefs.findIndex(function(u){return u===l;});e.messageElementRefs.splice(d+1,0,a),t[1].html=a;}t[0].html=s;}// finds beforeElement, creates new elements, remove old and adds new ones
|
231
|
+
},{key:"updateFileMessages",value:function updateFileMessages(e,t,s){var u,h;var i=t[0].role,n=Ws.createMessages(e,s,i),o=t[1].html,a=((h=t[1].files)==null?void 0:h[((u=t[1].files)==null?void 0:u.length)-1])||t[1].text,l=o||a;var c=e.messageElementRefs.findIndex(function(p){return p===l;});a&&(c+=1);var d=(o==null?void 0:o.outerContainer)||(a==null?void 0:a.outerContainer.nextSibling);n.forEach(function(_ref37,f){var p=_ref37.type,m=_ref37.elements;var g;z.setElementProps(e,m,p,i),(g=d.parentElement)==null||g.insertBefore(m.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(c+f,0,m);}),de.removeFilesMessages(e,t),t[1].files=n.map(function(_ref38){var p=_ref38.elements;return p;}),t[0].files=s;}},{key:"updateTextMessage",value:function updateTextMessage(e,t,s){var i,n;if(t[1].text)e.renderText(t[1].text.bubbleElement,s,t[0].role);else{var o=e.createElements(s,t[0].role),a=((i=t[1].files)==null?void 0:i[0])||t[1].html;(n=a.outerContainer.parentElement)==null||n.insertBefore(o.outerContainer,a.outerContainer);var l=e.messageElementRefs.findIndex(function(c){return c===a;});e.messageElementRefs.splice(l,0,o),t[1].text=o;}t[0].text=s;}},{key:"isElementActive",value:function isElementActive(e){var t,s;return ue.isActiveElement((t=e.text)==null?void 0:t.bubbleElement.classList)||ue.isActiveElement((s=e.html)==null?void 0:s.bubbleElement.classList);}// note that overwrite and 'deep-chat-temporary-message' are used to remove a message
|
232
|
+
},{key:"update",value:function update(e,t,s){var i=e.messageToElements[s];if(i){if(de.isElementActive(i[1]))return console.error("Cannot update a message that is being streamed");t.text&&de.updateTextMessage(e,i,t.text),t.files?de.updateFileMessages(e,i,t.files):de.removeFilesMessages(e,i),t.html&&de.updateHTMLMessage(e,i,t.html),!t.text&&i[1].text&&de.removeTextHTMLMessage(e,i,"text"),!t.html&&i[1].html&&de.removeTextHTMLMessage(e,i,"html");var n=e.messageElementRefs,o=e.avatar,a=e.name;b.classifyRoleMessages(n),b.resetAllRoleElements(n,o,a);}else console.error("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var Aa=/*#__PURE__*/function(){function Aa(){_classCallCheck(this,Aa);}return _createClass(Aa,null,[{key:"getText",value:function getText(e,t){var s;if(!e.directConnection&&!e.connect&&!e.webModel&&!e.demo)return"Connect to any API using the [connect](https://deepchat.dev/docs/connect#connect-1) property or a popular service via [directConnection](https://deepchat.dev/docs/directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](https://deepchat.dev/docs/webModel).\n To get started checkout the [Start](https://deepchat.dev/start) page and live code [examples](https://deepchat.dev/examples/frameworks).\n To remove this message set the [demo](https://deepchat.dev/docs/modes#demo) property to true.";if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](https://deepchat.dev/docs/directConnection/#directConnection) object.";var i=(s=e.directConnection.openAI)==null?void 0:s.chat;if(_typeof(i)=="object"&&i.tools&&!i.function_handler)return"Please define the `function_handler` property inside the openAI [chat](https://deepchat.dev/docs/directConnection/openAI#Chat) object.";}else if(e.connect&&!e.connect.url&&!e.connect.handler)return"Please define a `url` or a `handler` property inside the [connect](https://deepchat.dev/docs/connect#connect-1) object.";return null;}}]);}();var ue=/*#__PURE__*/function(_pe){function ue(e,t,s){var _this68;_classCallCheck(this,ue);var a,l;_this68=_callSuper(this,ue,[e]);var i=t.permittedErrorPrefixes,n=t.introPanelMarkUp,o=t.demo;_this68._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this68._onClearMessages=as.onClearMessages.bind(_this68,e),_this68._onError=as.onError.bind(_this68,e),_this68._isLoadingMessageAllowed=ue.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this68.setLoadingToggle.bind(_this68)),_this68._permittedErrorPrefixes=i,_this68.addSetupMessageIfNeeded(e,t)||_this68.populateIntroPanel(s,n,e.introPanelStyle),o&&_this68.prepareDemo(X.processDemo(o),e.loadHistory),_this68.addIntroductoryMessages(e,t),new ls(e,_this68,t),_this68._displayServiceErrorMessages=(l=e.errorMessages)==null?void 0:l.displayServiceErrorMessages,e.getMessages=function(){return b.deepCloneMessagesWithReferences(_this68.messageToElements.map(function(_ref39){var _ref40=_slicedToArray(_ref39,1),c=_ref40[0];return c;}));},e.clearMessages=_this68.clearMessages.bind(_this68,t),e.refreshMessages=_this68.refreshTextMessages.bind(_this68,e.remarkable),e.scrollToBottom=J.scrollToBottom.bind(_this68,_this68.elementRef),e.addMessage=function(c,d){_this68.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(c,d){return de.update(_this68,c,d);},t.isWebModel()&&t.setUpMessages(_this68),e.textToSpeech&&St.processConfig(e.textToSpeech,function(c){_this68.textToSpeech=c;});return _this68;}_inherits(ue,_pe);return _createClass(ue,[{key:"setLoadingToggle",value:function setLoadingToggle(){var e=this.messageElementRefs[this.messageElementRefs.length-1];pe.isLoadingMessage(e)?this.removeLastMessage():this.addLoadingMessage(!0);}},{key:"prepareDemo",value:function prepareDemo(e,t){var s;if(_typeof(e)=="object"){if(!t&&e.displayLoading){var i=e.displayLoading.history;i!=null&&i.small&&qe.addMessage(this,!1),i!=null&&i.full&&qe.addMessage(this);}e.displayErrors&&(e.displayErrors["default"]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage("service",""),e.displayErrors.speechToText&&this.addNewErrorMessage("speechToText","")),(s=e.displayLoading)!=null&&s.message&&this.addLoadingMessage(),e.response&&(this.customDemoResponse=e.response);}}},{key:"addSetupMessageIfNeeded",value:function addSetupMessageIfNeeded(e,t){var s=Aa.getText(e,t);if(s){var i=this.createAndAppendNewMessageElement(s,b.AI_ROLE);this.applyCustomStyles(i,b.AI_ROLE,!1);}return!!s;}// WORK - const file for deep chat classes
|
233
|
+
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this69=this;e!=null&&e.shadowRoot&&(this._introMessage=e.introMessage);var s=this._introMessage;t!=null&&t.isWebModel()&&(s!==null&&s!==void 0?s:s=t.getIntroMessage(s));var i=!(e!=null&&e.history)&&!!(e!=null&&e.loadHistory||t!=null&&t.fetchHistory);s&&(Array.isArray(s)?s.forEach(function(n,o){if(o!==0){var a=_this69.messageElementRefs[_this69.messageElementRefs.length-1].innerContainer;b.hideRoleElements(a,_this69.avatar,_this69.name);}_this69.addIntroductoryMessage(n,i);}):this.addIntroductoryMessage(s,i));}},{key:"addIntroductoryMessage",value:function addIntroductoryMessage(e,t){var i;var s;return e!=null&&e.text?s=this.createAndAppendNewMessageElement(e.text,b.AI_ROLE):e!=null&&e.html&&(s=Te.add(this,e.html,b.AI_ROLE)),s&&(this.applyCustomStyles(s,b.AI_ROLE,!1,(i=this.messageStyles)==null?void 0:i.intro),s.outerContainer.classList.add(pe.INTRO_CLASS),t&&(s.outerContainer.style.display="none")),s;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer.classList.contains(pe.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 s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;return e.error?this.addNewErrorMessage("service",e.error,s):this.addNewMessage(e,t,s);}},{key:"tryAddTextMessage",value:function tryAddTextMessage(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;!s.ignoreText&&e.text!==void 0&&s.text!==null&&(this.addNewTextMessage(e.text,e.role,t,n),!i&&this.textToSpeech&&e.role!==b.USER_ROLE&&St.speak(e.text,this.textToSpeech));}},{key:"tryAddFileMessages",value:function tryAddFileMessages(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;e.files&&Array.isArray(e.files)&&Ws.addMessages(this,e.files,e.role,t);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e.html!==void 0&&e.html!==null){var i=Te.add(this,e.html,e.role,t,s);!s&&Ce.isElementTemporary(i)&&delete e.html;}}// this should not be activated by streamed messages
|
231
234
|
},{key:"addNewMessage",value:function addNewMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var a,l,c,d;e.role!==b.USER_ROLE&&((a=this._hiddenAttachments)==null||a.removeHiddenFiles());var i=ue.createMessageContent(e),n=(c=(l=this.textToSpeech)==null?void 0:l.service)==null?void 0:c.displayText;typeof n=="boolean"&&!n&&delete i.text;var o={status:e.overwrite};return s?(this.tryAddHTMLMessage(i,o,s),this.tryAddFileMessages(i,s),this.tryAddTextMessage(i,o,e,t,s)):(this.tryAddTextMessage(i,o,e,t,s),this.tryAddFileMessages(i,s),this.tryAddHTMLMessage(i,o,s)),this.isValidMessageContent(i)&&!s&&(this.updateStateOnMessage(i,e.overwrite,e.sendUpdate,t),t||(d=this.browserStorage)==null||d.addMessages(this.messageToElements.map(function(_ref41){var _ref42=_slicedToArray(_ref41,1),u=_ref42[0];return u;}))),i;}},{key:"isValidMessageContent",value:function isValidMessageContent(e){return e.text||e.html||e.files&&e.files.length>0;}},{key:"updateStateOnMessage",value:function updateStateOnMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(!t){var n=b.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,n]);}s&&this.sendClientUpdate(e,i);}// prettier-ignore
|
232
235
|
},{key:"removeMessageOnError",value:function removeMessageOnError(){var e=this.messageElementRefs[this.messageElementRefs.length-1],t=e==null?void 0:e.bubbleElement;(t!=null&&t.classList.contains(Me.MESSAGE_CLASS)&&t.textContent===""||ue.isTemporaryElement(e))&&this.removeLastMessage();}// prettier-ignore
|
233
|
-
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var
|
234
|
-
function clearMessages(e,t){var _this$messageToElemen;var n,o,a;var s=[];this.messageElementRefs.forEach(function(l){ue.isActiveElement(l.bubbleElement.classList)?s.push(l):l.outerContainer.remove();}),Array.from(this.elementRef.children).forEach(function(l){var d;var c=(d=l.children[0])==null?void 0:d.children[0];c!=null&&c.classList.contains(b.ERROR_MESSAGE_TEXT_CLASS)&&l.remove();}),this.messageElementRefs=s;var i=this.messageToElements.filter(function(l){return l[1].text&&ue.isActiveElement(l[1].text.bubbleElement.classList)||l[1].html&&ue.isActiveElement(l[1].html.bubbleElement.classList);});(_this$messageToElemen=this.messageToElements).splice.apply(_this$messageToElemen,[0,this.messageToElements.length].concat(_toConsumableArray(i))),t!==!1&&((n=this._introPanel)!=null&&n._elementRef&&this._introPanel.display(),this.addIntroductoryMessages()),(o=this.browserStorage)==null||o.clear(),(a=this._onClearMessages)==null||a.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref43;return t.websocket?!!e.displayLoadingBubble:(_ref43=_typeof(e.displayLoadingBubble)=="object"||e.displayLoadingBubble)!==null&&_ref43!==void 0?_ref43:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _s8=0;_s8<e.length;_s8+=1)if(t.startsWith(e[_s8]))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.error?[e.error]:[];}},{key:"isActiveElement",value:function isActiveElement(e){return e?e.contains(
|
236
|
+
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this70=this;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var c,d,u,h,p,m;(c=this._hiddenAttachments)==null||c.readdHiddenFiles(),this.removeMessageOnError();var i=this.getPermittedMessage(t)||((d=this._errorMessageOverrides)==null?void 0:d[e])||((u=this._errorMessageOverrides)==null?void 0:u["default"])||"Error, please try again.",n=this.createMessageElementsOnOrientation(i,"error",s);b.hideRoleElements(n.innerContainer,this.avatar,this.name);var o=n.bubbleElement,a=n.outerContainer;o.classList.add(b.ERROR_MESSAGE_TEXT_CLASS),this.renderText(o,i);var l=Q.extractParticularSharedStyles(["fontSize","fontFamily"],(h=this.messageStyles)==null?void 0:h["default"]);Q.applyCustomStylesToElements(n,!1,l),Q.applyCustomStylesToElements(n,!1,(p=this.messageStyles)==null?void 0:p.error),s||this.appendOuterContainerElemet(a),this.textToSpeech&&St.speak(i,this.textToSpeech),(m=this._onError)==null||m.call(this,i),setTimeout(function(){return J.scrollToBottom(_this70.elementRef);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=ue.extractErrorMessages(e);for(var _s7=0;_s7<t.length;_s7+=1){var i=t[_s7];if(typeof i=="string"){if(this._displayServiceErrorMessages)return i;if(this._permittedErrorPrefixes){var n=ue.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,i);if(n)return n;}}}}}},{key:"removeError",value:function removeError(){this.isLastMessageError()&&b.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(){var e=this.createMessageElements("",b.AI_ROLE),t=e.bubbleElement;e.bubbleElement.classList.add(je.DOTS_CONTAINER_CLASS);var s=document.createElement("div");return s.classList.add("loading-message-dots"),t.appendChild(s),je.setDots(t,this.messageStyles),e;}},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var n,o,a,l,c,d;var t=this.messageElementRefs[this.messageElementRefs.length-1];if(pe.isLoadingMessage(t)||!e&&!this._isLoadingMessageAllowed)return;var s=(a=(o=(n=this.messageStyles)==null?void 0:n.loading)==null?void 0:o.message)==null?void 0:a.html,i=s?Te.createElements(this,s,b.AI_ROLE,!1):this.addDefaultLoadingMessage();this.appendOuterContainerElemet(i.outerContainer),i.bubbleElement.classList.add(je.BUBBLE_CLASS),this.applyCustomStyles(i,b.AI_ROLE,!1,(d=(c=(l=this.messageStyles)==null?void 0:l.loading)==null?void 0:c.message)==null?void 0:d.styles),this.focusMode||J.scrollToBottom(this.elementRef);}},{key:"populateIntroPanel",value:function populateIntroPanel(e,t,s){(e||t)&&(this._introPanel=new Ks(e,t,s),this._introPanel._elementRef&&(ee.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef)));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(e,t){return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:return _context138.a(2,(this._hiddenAttachments=t,Promise.all((e||[]).map(function(s){return new Promise(function(i){if(!s.type||s.type==="any"){var n=s.file.name||z.DEFAULT_FILE_NAME;i({name:n,type:"any",ref:s.file});}else{var _n2=new FileReader();_n2.readAsDataURL(s.file),_n2.onload=function(){i({src:_n2.result,type:s.type,ref:s.file});};}});}))));}},_callee138,this);}));function addMultipleFiles(_x255,_x256){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
|
237
|
+
function clearMessages(e,t){var _this$messageToElemen;var n,o,a;var s=[];this.messageElementRefs.forEach(function(l){ue.isActiveElement(l.bubbleElement.classList)?s.push(l):l.outerContainer.remove();}),Array.from(this.elementRef.children).forEach(function(l){var d;var c=(d=l.children[0])==null?void 0:d.children[0];c!=null&&c.classList.contains(b.ERROR_MESSAGE_TEXT_CLASS)&&l.remove();}),this.messageElementRefs=s;var i=this.messageToElements.filter(function(l){return l[1].text&&ue.isActiveElement(l[1].text.bubbleElement.classList)||l[1].html&&ue.isActiveElement(l[1].html.bubbleElement.classList);});(_this$messageToElemen=this.messageToElements).splice.apply(_this$messageToElemen,[0,this.messageToElements.length].concat(_toConsumableArray(i))),t!==!1&&((n=this._introPanel)!=null&&n._elementRef&&this._introPanel.display(),this.addIntroductoryMessages()),(o=this.browserStorage)==null||o.clear(),(a=this._onClearMessages)==null||a.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref43;return t.websocket?!!e.displayLoadingBubble:(_ref43=_typeof(e.displayLoadingBubble)=="object"||e.displayLoadingBubble)!==null&&_ref43!==void 0?_ref43:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _s8=0;_s8<e.length;_s8+=1)if(t.startsWith(e[_s8]))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.error?[e.error]:[];}},{key:"isActiveElement",value:function isActiveElement(e){return e?e.contains(je.BUBBLE_CLASS)||e.contains(qe.CLASS)||e.contains(Me.MESSAGE_CLASS):!1;}}]);}(pe);var G=/*#__PURE__*/function(){function G(){_classCallCheck(this,G);}return _createClass(G,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t["inside-left"].length>0&&e.classList.add("text-input-inner-left-adjustment"),t["inside-right"].length>0&&e.classList.add("text-input-inner-right-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,s){s["outside-right"].length===0&&s["outside-left"].length>0?(e[0].classList.add(G.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS),t.classList.add(G.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS)):s["outside-left"].length===0&&s["outside-right"].length>0&&(e[3].classList.add(G.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS),t.classList.add(G.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS));}// when submit is the only button
|
235
238
|
// when submit button is outside by itself - we increase the height for a better look
|
236
239
|
},{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,s){if(!(s["inside-left"].length>0||s["inside-right"].length>0)){if(s["outside-right"].length===0&&s["outside-left"].length>0)return e[0].classList.add(G.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),t.classList.add(G.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),s["outside-left"].map(function(i){return i.button.elementRef.classList.add("submit-button-enlarged");});if(s["outside-left"].length===0&&s["outside-right"].length>0)return e[3].classList.add(G.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),t.classList.add(G.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),s["outside-right"].map(function(i){return i.button.elementRef.classList.add("submit-button-enlarged");});}}// prettier-ignore
|
237
|
-
},{key:"set",value:function set(e,t,s,i){!!G.adjustOutsideSubmit(t,s,i)||G.adjustForOutsideButton(t,s,i),G.adjustInputPadding(e,i);}}]);}();G.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment",G.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment",G.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment",G.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var
|
238
|
-
function D(e,t,s,i){var
|
239
|
-
},{key:"setDropupItem",value:function setDropupItem(e){this.elementRef=e,this._originalElementRef=e.cloneNode(!0),this.changeState(this._state,!0);}},{key:"genStateInnerElements",value:function genStateInnerElements(e,t,s,i){var l,c,d,u;var n=this.createInnerElements(e,t,i);var o=(c=(l=i==null?void 0:i[t])==null?void 0:l.svg)==null?void 0:c.content,a=(u=(d=i==null?void 0:i[t])==null?void 0:d.text)==null?void 0:u.content;if(o===void 0||a===void 0){var _Xt$parseSVGTextEleme4=Xt.parseSVGTextElements(s),h=_Xt$parseSVGTextEleme4.svg,p=_Xt$parseSVGTextEleme4.text,_Xt$parseSVGTextEleme5=Xt.parseSVGTextElements(n),m=_Xt$parseSVGTextEleme5.svg,f=_Xt$parseSVGTextEleme5.text,g=[];D.addToInnerElements(g,o,h,m),D.addToInnerElements(g,a,p,f),n=g;}return n;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button",D.BUTTON_CLASS),e;}},{key:"addToInnerElements",value:function addToInnerElements(e,t,s,i){t===void 0&&s?e.push(s.cloneNode(!0)):i&&e.push(i);}},{key:"add",value:function add(e,t){var s=e.customButtons,i=e.focusInput,n=e.dropupStyles;s==null||s.forEach(function(o,a){var l={button:new D(o,a+1,i,n==null?void 0:n.menu)};t["".concat(D.INDICATOR_PREFIX).concat(a+1)]=l;});}}]);}(
|
240
|
+
},{key:"set",value:function set(e,t,s,i){!!G.adjustOutsideSubmit(t,s,i)||G.adjustForOutsideButton(t,s,i),G.adjustInputPadding(e,i);}}]);}();G.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment",G.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment",G.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment",G.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var Ii=G;var wt=/*#__PURE__*/function(){function wt(){_classCallCheck(this,wt);}return _createClass(wt,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var s=document.createElement("div");return s.classList.add("input-button-container"),(t===0||t===3)&&s.classList.add("outer-button-container"),(t===1||t===2)&&s.classList.add("inner-button-container"),s;});}},{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==="outside-left"?0:e==="inside-left"?1:e==="inside-right"?2:3;}},{key:"addButton",value:function addButton(e,t,s){t.classList.add(s);var i=wt.getContainerIndex(s);e[i].appendChild(t),i===3&&t.classList.add("outside-right");}}]);}();var fn=["camera","gifs","images","audio","mixedFiles","submit","microphone"],Ca="<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",se=/*#__PURE__*/function(){function se(){_classCallCheck(this,se);}return _createClass(se,null,[{key:"addItemEvents",value:function addItemEvents(e,t,s,i){Xe.add(t,i),t.addEventListener("click",function(){s.click();}),t.addEventListener("mouseenter",function(n){e.highlightedItem=n.target;}),t.addEventListener("mouseleave",function(){e.highlightedItem=void 0;});}},{key:"createItemText",value:function createItemText(e,t){var s=document.createElement("div");return Object.assign(s.style,t),s.classList.add(se.TEXT_CLASS),s.textContent=e||"File",s;}},{key:"createItemIcon",value:function createItemIcon(e,t){var s=document.createElement("div");return Object.assign(s.style,t),s.classList.add(se.ICON_CLASS),s.appendChild(e),s;}},{key:"populateItem",value:function populateItem(e,t,s){var i=e.elementRef,n=e.dropupText,o=e.svg,a=e.customStyles,l=i.children[0],c=a&&Object.values(a).find(function(d){var u;return((u=d.svg)==null?void 0:u.content)==="";});l.classList.contains(ke.INPUT_BUTTON_INNER_TEXT_CLASS)?(c||t.appendChild(se.createItemIcon(o,s==null?void 0:s.iconContainer)),t.appendChild(se.createItemText(l.textContent,s==null?void 0:s.text))):(c||t.appendChild(se.createItemIcon(i.children[0],s==null?void 0:s.iconContainer)),t.appendChild(se.createItemText(n,s==null?void 0:s.text)));}},{key:"createItem",value:function createItem(e,t,s){var o;var i=document.createElement("div");Object.assign(i.style,(o=s==null?void 0:s.item)==null?void 0:o["default"]),se.populateItem(t,i,s),i.classList.add(se.MENU_ITEM_CLASS);var n=t.elementRef;if(t.isCustom)t.setDropupItem(i);else{var a=N.processStateful((s==null?void 0:s.item)||{});se.addItemEvents(e,i,n,a);}return i;}}]);}();se.MENU_ITEM_CLASS="dropup-menu-item",se.TEXT_CLASS="dropup-menu-item-text",se.ICON_CLASS="dropup-menu-item-icon";var Ae=se;var D=/*#__PURE__*/function(_mt2){// prettier-ignore
|
241
|
+
function D(e,t,s,i){var _this71;_classCallCheck(this,D);var l,c,d,u,h,p;var n=((u=(d=(c=(l=e==null?void 0:e.styles)==null?void 0:l.button)==null?void 0:c["default"])==null?void 0:d.text)==null?void 0:u.content)||"Custom ".concat(t),o=Ca,a=Se.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this71=_callSuper(this,D,[D.createButtonElement(),o,e==null?void 0:e.position,a,((h=e==null?void 0:e.styles)==null?void 0:h.button)||a&&{},n]),_this71._state="default",_this71.isCustom=!0,_this71._innerElements=_this71.createInnerElementsForStates(_this71.customStyles),_this71._menuStyles=i,_this71._onClick=e.onClick,_this71._dropupStyles=(p=e.styles)==null?void 0:p.dropup,_this71.setSetState(e),_this71.addClickListener(s),_this71.changeState(e.initialState,!0);return _this71;}_inherits(D,_mt2);return _createClass(D,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="custom-icon",s=this.createInnerElements(t,"default",e);return{"default":s,active:this.genStateInnerElements(t,"active",s,e),disabled:this.genStateInnerElements(t,"disabled",s,e)};}},{key:"setSetState",value:function setSetState(e){var _this72=this;e.setState=function(t){t==="default"&&_this72.changeToDefault(),t==="active"&&_this72.changeToActive(),t==="disabled"&&_this72.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this73=this;this.elementRef.addEventListener("click",function(){var s;var t=(s=_this73._onClick)==null?void 0:s.call(_this73,_this73._state);e==null||e(),(t==="default"||t==="active"||t==="disabled")&&_this73.changeState(t);});}},{key:"changeState",value:function changeState(e,t){e==="disabled"?this.changeToDisabled(t):e==="active"?this.changeToActive(t):this.changeToDefault(t);}},{key:"applyDropupContentStyles",value:function applyDropupContentStyles(e){var t=Array.from(this.elementRef.children);if(e!=null&&e.text){var _s9=t.find(function(i){return i.classList.contains(Ae.TEXT_CLASS);});_s9&&Object.assign(_s9.style,e.text);}if(e!=null&&e.iconContainer){var _s0=t.find(function(i){return i.classList.contains(Ae.ICON_CLASS);});_s0&&Object.assign(_s0.style,e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var s,i,n;this.elementRef=ee.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((s=e==null?void 0:e.svg)==null?void 0:s.content)===""||this.elementRef.appendChild(Ae.createItemIcon(this.svg,(i=this._menuStyles)==null?void 0:i.iconContainer)),this.elementRef.appendChild(Ae.createItemText(this.dropupText,(n=this._menuStyles)==null?void 0:n.text));}},{key:"assignDropupItemStyle",value:function assignDropupItemStyle(e,t){var i;this.elementRef.parentElement&&this._originalElementRef&&this.resetDropupItem(t),this.applyDropupContentStyles(e),Object.assign(this.elementRef.style,(i=e==null?void 0:e.item)==null?void 0:i["default"]);var s=N.processStateful((e==null?void 0:e.item)||{});Xe.add(this.elementRef,s),this.addClickListener();}},{key:"changeToDefault",value:function changeToDefault(e){var t,s,i,n,o,a;!e&&this._state==="default"||(this.elementRef.classList.contains(Ae.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t["default"],(s=this.customStyles)==null?void 0:s["default"]):(this.changeElementsByState(this._innerElements["default"]),(i=this.customStyles)!=null&&i.active&&j.unsetAllCSS(this.elementRef,(n=this.customStyles)==null?void 0:n.active),(o=this.customStyles)!=null&&o.disabled&&j.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a.disabled),this.reapplyStateStyle("default",["active","disabled"])),this.elementRef.classList.remove(D.DISABLED_CONTAINER_CLASS,D.ACTIVE_CONTAINER_CLASS),this.elementRef.classList.add(D.DEFAULT_CONTAINER_CLASS),F.removeAriaDisabled(this.elementRef),this._state="default");}},{key:"changeToActive",value:function changeToActive(e){var t,s;!e&&this._state==="active"||(this.elementRef.classList.contains(Ae.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t.active,(s=this.customStyles)==null?void 0:s.active):(this.changeElementsByState(this._innerElements.active),this.reapplyStateStyle("active",["disabled","default"])),this.elementRef.classList.remove(D.DISABLED_CONTAINER_CLASS,D.DEFAULT_CONTAINER_CLASS),this.elementRef.classList.add(D.ACTIVE_CONTAINER_CLASS),F.removeAriaDisabled(this.elementRef),this._state="active");}},{key:"changeToDisabled",value:function changeToDisabled(e){var t,s,i,n,o,a;!e&&this._state==="disabled"||(this.elementRef.classList.contains(Ae.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t.disabled,(s=this.customStyles)==null?void 0:s.disabled):(this.changeElementsByState(this._innerElements.disabled),(i=this.customStyles)!=null&&i.active&&j.unsetAllCSS(this.elementRef,(n=this.customStyles)==null?void 0:n.active),(o=this.customStyles)!=null&&o["default"]&&j.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a["default"]),this.reapplyStateStyle("disabled",["default","active"])),this.elementRef.classList.remove(D.ACTIVE_CONTAINER_CLASS,D.DEFAULT_CONTAINER_CLASS),this.elementRef.classList.add(D.DISABLED_CONTAINER_CLASS),F.addAriaDisabled(this.elementRef),this._state="disabled");}// called after class is initialised
|
242
|
+
},{key:"setDropupItem",value:function setDropupItem(e){this.elementRef=e,this._originalElementRef=e.cloneNode(!0),this.changeState(this._state,!0);}},{key:"genStateInnerElements",value:function genStateInnerElements(e,t,s,i){var l,c,d,u;var n=this.createInnerElements(e,t,i);var o=(c=(l=i==null?void 0:i[t])==null?void 0:l.svg)==null?void 0:c.content,a=(u=(d=i==null?void 0:i[t])==null?void 0:d.text)==null?void 0:u.content;if(o===void 0||a===void 0){var _Xt$parseSVGTextEleme4=Xt.parseSVGTextElements(s),h=_Xt$parseSVGTextEleme4.svg,p=_Xt$parseSVGTextEleme4.text,_Xt$parseSVGTextEleme5=Xt.parseSVGTextElements(n),m=_Xt$parseSVGTextEleme5.svg,f=_Xt$parseSVGTextEleme5.text,g=[];D.addToInnerElements(g,o,h,m),D.addToInnerElements(g,a,p,f),n=g;}return n;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button",D.BUTTON_CLASS),e;}},{key:"addToInnerElements",value:function addToInnerElements(e,t,s,i){t===void 0&&s?e.push(s.cloneNode(!0)):i&&e.push(i);}},{key:"add",value:function add(e,t){var s=e.customButtons,i=e.focusInput,n=e.dropupStyles;s==null||s.forEach(function(o,a){var l={button:new D(o,a+1,i,n==null?void 0:n.menu)};t["".concat(D.INDICATOR_PREFIX).concat(a+1)]=l;});}}]);}(mt);D.INDICATOR_PREFIX="custom",D.BUTTON_CLASS="custom-button",D.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",D.DEFAULT_CONTAINER_CLASS="custom-button-container-default",D.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var ct=D;var Ta="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M16 0c-8.836 0-16 7.163-16 16s7.163 16 16 16c8.837 0 16-7.163 16-16s-7.163-16-16-16zM16 30.032c-7.72 0-14-6.312-14-14.032s6.28-14 14-14 14 6.28 14 14-6.28 14.032-14 14.032zM23 15h-6v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1v6h-6c-0.552 0-1 0.448-1 1s0.448 1 1 1h6v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6h6c0.552 0 1-0.448 1-1s-0.448-1-1-1z\"></path>\n</svg>";var ds=/*#__PURE__*/function(){function ds(){_classCallCheck(this,ds);}return _createClass(ds,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var s=t?e.children[0]:e.children[e.children.length-1];ds.focusSiblingItem(s,e,t,!0);}// isEdgeItem means is it a start or end item
|
240
243
|
// prettier-ignore
|
241
|
-
},{key:"focusSiblingItem",value:function focusSiblingItem(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var n=i?e:e[s?"nextSibling":"previousSibling"];n?(e.dispatchEvent(new MouseEvent("mouseleave")),n.dispatchEvent(new MouseEvent("mouseenter"))):(e.dispatchEvent(new MouseEvent("mouseleave")),ds.focusItemWhenOnEdge(t,s));}}]);}();var
|
244
|
+
},{key:"focusSiblingItem",value:function focusSiblingItem(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var n=i?e:e[s?"nextSibling":"previousSibling"];n?(e.dispatchEvent(new MouseEvent("mouseleave")),n.dispatchEvent(new MouseEvent("mouseenter"))):(e.dispatchEvent(new MouseEvent("mouseleave")),ds.focusItemWhenOnEdge(t,s));}}]);}();var qi=/*#__PURE__*/function(){function qi(e,t){var _this74=this;_classCallCheck(this,qi);var s;this._isOpen=!0,this._styles=t,this.elementRef=qi.createElement((s=this._styles)==null?void 0:s.container),this.close(),setTimeout(function(){return _this74.addWindowEvents(e);});}return _createClass(qi,[{key:"open",value:function open(){this.elementRef.style.display="block",this._isOpen=!0;}},{key:"close",value:function close(){this._isOpen&&(this.elementRef.style.display="none",this._isOpen=!1);}},{key:"toggle",value:function toggle(){this._isOpen?this.close():this.open();}},{key:"addItem",value:function addItem(e){var t=Ae.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
|
242
245
|
},{key:"addWindowEvents",value:function addWindowEvents(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener("click",this.clickEvent),this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent);}},{key:"windowClick",value:function windowClick(e,t){var s;!e.isConnected&&this.clickEvent?window.removeEventListener("click",this.clickEvent):e.parentElement!==((s=t.target.shadowRoot)==null?void 0:s.children[0])&&this.close();}// prettier-ignore
|
243
|
-
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var s,i,n;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===V.ESCAPE?(this.close(),(s=this.highlightedItem)==null||s.dispatchEvent(new MouseEvent("mouseleave"))):t.key===V.ENTER?((i=this.highlightedItem)==null||i.click(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===V.ARROW_DOWN?ds.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===V.ARROW_UP&&ds.focusSiblingItem(this.highlightedItem||this.elementRef.children[0],this.elementRef,!1));}}],[{key:"createElement",value:function createElement(e){var t=document.createElement("div");return t.id="dropup-menu",Object.assign(t.style,e),t;}}]);}();var
|
244
|
-
function addToDropup(e,t,s,i){var n=new
|
245
|
-
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Z.createPositionsToButtonsObj();Object.keys(e).forEach(function(i){var o;var n=(o=e[i])==null?void 0:o.button.position;n&&Z.setPosition(e,i,t[n]);}),t["inside-right"].length===0&&e.submit&&Z.setPosition(e,"submit",t["inside-right"]),t["outside-right"].length===0&&(e.submit?Z.setPosition(e,"submit",t["outside-right"]):e.microphone?Z.setPosition(e,"microphone",t["outside-right"]):e.camera?Z.setPosition(e,"camera",t["outside-right"]):e["".concat(
|
246
|
-
},{key:"addButtons",value:function addButtons(e,t,s,i){var n=Z.generatePositionToButtons(t);return Z.addToSideContainer(e,n),n["dropup-menu"].length>0&&Z.addToDropup(e,n,s,i),n;}}]);}();var ka="<?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>",La="<?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",Ia="<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>",Oa="<?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",Pa={images:{id:"upload-images-icon",svgString:La,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:Oa,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:Ia,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:ka,dropupText:"File"}};var ni=/*#__PURE__*/function(_ft4){function ni(e){var _this78;_classCallCheck(this,ni);(e==null?void 0:e.position)==="dropup-menu"&&(e.position="outside-right");var t=Se.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this78=_callSuper(this,ni,[ni.createMicrophoneElement(),Yn,e==null?void 0:e.position,t,e]),_this78.isActive=!1,_this78._innerElements=_this78.createInnerElementsForStates(_this78.customStyles),_this78.changeToDefault();return _this78;}_inherits(ni,_ft4);return _createClass(ni,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return{"default":this.createInnerElements(t,"default",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",["default","commandMode"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements["default"]),this.toggleIconFilter("default"),this.reapplyStateStyle("default",["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.classList.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"default":t.classList.remove("active-microphone-icon","command-microphone-icon"),t.classList.add("default-microphone-icon");break;case"active":t.classList.remove("default-microphone-icon","command-microphone-icon"),t.classList.add("active-microphone-icon");break;case"command":t.classList.remove("active-microphone-icon","default-microphone-icon"),t.classList.add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=document.createElement("div");return e.id="microphone-button",e.classList.add("input-button"),e;}}]);}(ft);function Na(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r["default"]:r;}var vs={},Ct={},Tt={},Rt={},Mt={},yn;function ri(){if(yn)return Mt;yn=1,Object.defineProperty(Mt,"__esModule",{value:!0}),Mt.Text=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"capitalize",value:function capitalize(t){return t.replace(r.FIRST_CHAR_REGEX,function(s){return s.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(t){return t.replace(r.DOUBLE_LINE,"<p></p>").replace(r.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 Mt.Text=r,r.FIRST_CHAR_REGEX=/\S/,r.DOUBLE_LINE=/\n\n/g,r.ONE_LINE=/\n/g,Mt;}var bn;function er(){if(bn)return Rt;bn=1,Object.defineProperty(Rt,"__esModule",{value:!0}),Rt.Translate=void 0;var r=ri();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"translate",value:function translate(s,i){var n=r.Text.breakupIntoWordsArr(s);for(var o=0;o<n.length;o+=1)i[n[o]]&&(n[o]=i[n[o]]);return n.join("");}}]);}();return Rt.Translate=e,Rt;}var vn;function Da(){if(vn)return Tt;vn=1,Object.defineProperty(Tt,"__esModule",{value:!0}),Tt.WebSpeechTranscript=void 0;var r=er();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:function extract(s,i,n){var o="";for(var a=s.resultIndex;a<s.results.length;++a){var l=s.results[a][0].transcript;n&&(l=r.Translate.translate(l,n)),s.results[a].isFinal?i+=l:o+=l;}return{interimTranscript:o,finalTranscript:i,newText:o||i};}},{key:"extractSafari",value:function extractSafari(s,i,n){var o="";var a="";for(var l=s.resultIndex;l<s.results.length;++l){var c=s.results[l][0].transcript;n&&(c=r.Translate.translate(c,n)),o+=c;}return{interimTranscript:a,finalTranscript:o,newText:a||o};}}]);}();return Tt.WebSpeechTranscript=e,Tt;}var kt={},En;function Gi(){if(En)return kt;En=1,Object.defineProperty(kt,"__esModule",{value:!0}),kt.Browser=void 0;var r=/*#__PURE__*/_createClass(function r(){_classCallCheck(this,r);});return kt.Browser=r,r.IS_SAFARI=function(){return r._IS_SAFARI===void 0&&(r._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),r._IS_SAFARI;},kt;}var Lt={},It={},_n;function Ba(){if(_n)return It;_n=1,Object.defineProperty(It,"__esModule",{value:!0}),It.EventListeners=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(t,s){return Array.isArray(t)?t.find(function(i){return s===i;}):s===t?t:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(t){var _this79=this;t.element&&r.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(r.KEY_DOWN_TIMEOUT!==null&&clearTimeout(r.KEY_DOWN_TIMEOUT),r.KEY_DOWN_TIMEOUT=setTimeout(function(){r.KEY_DOWN_TIMEOUT=null,_this79.resetRecording(t);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(t,s){this.mouseDownElement=r.getElementIfFocusedOnAvailable(t,s.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0;}},{key:"add",value:function add(t,s){var i=(s==null?void 0:s.insertInCursorLocation)===void 0||(s==null?void 0:s.insertInCursorLocation);s!=null&&s.element&&i&&(t.mouseDownEvent=r.mouseDownWindow.bind(t,s.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=r.mouseUpWindow.bind(t,s),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=r.keyDownWindow.bind(t,s),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 It.EventListeners=r,r.KEY_DOWN_TIMEOUT=null,It;}var Ot={},Sn;function Fa(){if(Sn)return Ot;Sn=1,Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.PreResultUtils=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"process",value:function process(t,s,i,n,o){var a=n==null?void 0:n(s,i);return a?(setTimeout(function(){a.restart?t.resetRecording(o):a.stop&&t.stop();}),(a.stop||a.restart)&&a.removeNewText):!1;}}]);}();return Ot.PreResultUtils=r,Ot;}var Pt={},Nt={},xn;function tr(){if(xn)return Nt;xn=1,Object.defineProperty(Nt,"__esModule",{value:!0}),Nt.AutoScroll=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(t,s){s&&!t.isCursorAtEnd&&(t.endPadding="",t.scrollingSpan.innerHTML=" ");}},{key:"scrollGeneric",value:function scrollGeneric(t,s){t.isCursorAtEnd?s.scrollTop=s.scrollHeight:t.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
|
246
|
+
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var s,i,n;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===V.ESCAPE?(this.close(),(s=this.highlightedItem)==null||s.dispatchEvent(new MouseEvent("mouseleave"))):t.key===V.ENTER?((i=this.highlightedItem)==null||i.click(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===V.ARROW_DOWN?ds.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===V.ARROW_UP&&ds.focusSiblingItem(this.highlightedItem||this.elementRef.children[0],this.elementRef,!1));}}],[{key:"createElement",value:function createElement(e){var t=document.createElement("div");return t.id="dropup-menu",Object.assign(t.style,e),t;}}]);}();var rt=/*#__PURE__*/function(_mt3){function rt(e,t){var _this75;_classCallCheck(this,rt);var n,o;var s=Se.tryCreateConfig("Options",(n=t==null?void 0:t.button)==null?void 0:n.tooltip);_this75=_callSuper(this,rt,[rt.createButtonElement(),Ta,void 0,s,{styles:(o=t==null?void 0:t.button)==null?void 0:o.styles}]);var i=_this75.createInnerElementsForStates(_this75.customStyles);_this75._menu=new qi(e,t==null?void 0:t.menu),_this75.addClickEvent(),_this75.buttonContainer=rt.createButtonContainer(),_this75.changeElementsByState(i.styles),_this75.buttonContainer.appendChild(_this75.elementRef),_this75.elementRef.classList.add(rt.BUTTON_ICON_CLASS),_this75.buttonContainer.appendChild(_this75._menu.elementRef),_this75.reapplyStateStyle("styles"),_this75.addContainerEvents(e);return _this75;}_inherits(rt,_mt3);return _createClass(rt,[{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 _this76=this;e.addEventListener("click",function(t){var s=t.target.classList;!s.contains(rt.BUTTON_ICON_CLASS)&&!s.contains(ct.DISABLED_CONTAINER_CLASS)&&_this76._menu.close();});}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}},{key:"createButtonContainer",value:function createButtonContainer(){var e=document.createElement("div");return e.id="dropup-container",e;}},{key:"getPosition",value:function getPosition(e,t){var s,i;return(s=t==null?void 0:t.button)!=null&&s.position?(i=t==null?void 0:t.button)==null?void 0:i.position:e["outside-left"].length>0&&e["outside-right"].length===0?"outside-right":"outside-left";}}]);}(mt);rt.BUTTON_ICON_CLASS="dropup-button";var $s=rt;var Z=/*#__PURE__*/function(){function Z(){_classCallCheck(this,Z);}return _createClass(Z,null,[{key:"addToDropup",value:// prettier-ignore
|
247
|
+
function addToDropup(e,t,s,i){var n=new $s(s,i);fn.forEach(function(a){var l=t["dropup-menu"].findIndex(function(d){return d.buttonType===a;}),c=t["dropup-menu"][l];c&&(n.addItem(c.button),t["dropup-menu"].splice(l,1));}),t["dropup-menu"].forEach(function(_ref44){var a=_ref44.button;return n.addItem(a);});var o=$s.getPosition(t,i);wt.addButton(e,n.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){["inside-left","inside-right","outside-left","outside-right"].forEach(function(i){var n=i;t[n].forEach(function(o){wt.addButton(e,o.button.elementRef,n);});});}},{key:"setPosition",value:function setPosition(e,t,s){var i=_objectSpread(_objectSpread({},e[t]),{},{buttonType:t});s.push(i),delete e[t];}},{key:"createPositionsToButtonsObj",value:function createPositionsToButtonsObj(){return{"dropup-menu":[],"outside-left":[],"inside-left":[],"inside-right":[],"outside-right":[]};}// prettier-ignore
|
248
|
+
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Z.createPositionsToButtonsObj();Object.keys(e).forEach(function(i){var o;var n=(o=e[i])==null?void 0:o.button.position;n&&Z.setPosition(e,i,t[n]);}),t["inside-right"].length===0&&e.submit&&Z.setPosition(e,"submit",t["inside-right"]),t["outside-right"].length===0&&(e.submit?Z.setPosition(e,"submit",t["outside-right"]):e.microphone?Z.setPosition(e,"microphone",t["outside-right"]):e.camera?Z.setPosition(e,"camera",t["outside-right"]):e["".concat(ct.INDICATOR_PREFIX,"1")]&&Z.setPosition(e,"".concat(ct.INDICATOR_PREFIX,"1"),t["outside-right"])),e.submit&&Z.setPosition(e,"submit",t["outside-left"].length===0?t["outside-left"]:t["inside-right"]),e.microphone&&Z.setPosition(e,"microphone",t["outside-left"].length===0?t["outside-left"]:t["inside-right"]);var s=Object.keys(e);return s.length>1||t["dropup-menu"].length>0?(fn.forEach(function(i){e[i]&&t["dropup-menu"].push(_objectSpread(_objectSpread({},e[i]),{},{buttonType:i}));}),s.forEach(function(i){var n=i;n.startsWith(ct.INDICATOR_PREFIX)&&e[n]&&t["dropup-menu"].push(_objectSpread(_objectSpread({},e[n]),{},{customType:n}));})):s.length===1&&Z.setPosition(e,s[0],t["outside-right"].length===0?t["outside-right"]:t["outside-left"]),t;}// prettier-ignore
|
249
|
+
},{key:"addButtons",value:function addButtons(e,t,s,i){var n=Z.generatePositionToButtons(t);return Z.addToSideContainer(e,n),n["dropup-menu"].length>0&&Z.addToDropup(e,n,s,i),n;}}]);}();var Ra="<?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>",Ma="<?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",ka="<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>",La="<?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",Ia={images:{id:"upload-images-icon",svgString:Ma,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:La,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:ka,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:Ra,dropupText:"File"}};var ni=/*#__PURE__*/function(_mt4){function ni(e){var _this77;_classCallCheck(this,ni);(e==null?void 0:e.position)==="dropup-menu"&&(e.position="outside-right");var t=Se.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this77=_callSuper(this,ni,[ni.createMicrophoneElement(),Jn,e==null?void 0:e.position,t,e]),_this77.isActive=!1,_this77._innerElements=_this77.createInnerElementsForStates(_this77.customStyles),_this77.changeToDefault();return _this77;}_inherits(ni,_mt4);return _createClass(ni,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return{"default":this.createInnerElements(t,"default",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",["default","commandMode"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements["default"]),this.toggleIconFilter("default"),this.reapplyStateStyle("default",["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.classList.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"default":t.classList.remove("active-microphone-icon","command-microphone-icon"),t.classList.add("default-microphone-icon");break;case"active":t.classList.remove("default-microphone-icon","command-microphone-icon"),t.classList.add("active-microphone-icon");break;case"command":t.classList.remove("active-microphone-icon","default-microphone-icon"),t.classList.add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=document.createElement("div");return e.id="microphone-button",e.classList.add("input-button"),e;}}]);}(mt);function Oa(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r["default"]:r;}var vs={},Ct={},Tt={},Rt={},Mt={},mn;function ri(){if(mn)return Mt;mn=1,Object.defineProperty(Mt,"__esModule",{value:!0}),Mt.Text=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"capitalize",value:function capitalize(t){return t.replace(r.FIRST_CHAR_REGEX,function(s){return s.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(t){return t.replace(r.DOUBLE_LINE,"<p></p>").replace(r.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 Mt.Text=r,r.FIRST_CHAR_REGEX=/\S/,r.DOUBLE_LINE=/\n\n/g,r.ONE_LINE=/\n/g,Mt;}var gn;function Zn(){if(gn)return Rt;gn=1,Object.defineProperty(Rt,"__esModule",{value:!0}),Rt.Translate=void 0;var r=ri();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"translate",value:function translate(s,i){var n=r.Text.breakupIntoWordsArr(s);for(var o=0;o<n.length;o+=1)i[n[o]]&&(n[o]=i[n[o]]);return n.join("");}}]);}();return Rt.Translate=e,Rt;}var yn;function Na(){if(yn)return Tt;yn=1,Object.defineProperty(Tt,"__esModule",{value:!0}),Tt.WebSpeechTranscript=void 0;var r=Zn();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:function extract(s,i,n){var o="";for(var a=s.resultIndex;a<s.results.length;++a){var l=s.results[a][0].transcript;n&&(l=r.Translate.translate(l,n)),s.results[a].isFinal?i+=l:o+=l;}return{interimTranscript:o,finalTranscript:i,newText:o||i};}},{key:"extractSafari",value:function extractSafari(s,i,n){var o="";for(var l=s.resultIndex;l<s.results.length;++l){var c=s.results[l][0].transcript;n&&(c=r.Translate.translate(c,n)),o+=c;}return{interimTranscript:"",finalTranscript:o,newText:o};}}]);}();return Tt.WebSpeechTranscript=e,Tt;}var kt={},bn;function Vi(){if(bn)return kt;bn=1,Object.defineProperty(kt,"__esModule",{value:!0}),kt.Browser=void 0;var r=/*#__PURE__*/_createClass(function r(){_classCallCheck(this,r);});return kt.Browser=r,r.IS_SAFARI=function(){return r._IS_SAFARI===void 0&&(r._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),r._IS_SAFARI;},kt;}var Lt={},It={},vn;function Pa(){if(vn)return It;vn=1,Object.defineProperty(It,"__esModule",{value:!0}),It.EventListeners=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(t,s){return Array.isArray(t)?t.find(function(i){return s===i;}):s===t?t:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(t){var _this78=this;t.element&&r.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(r.KEY_DOWN_TIMEOUT!==null&&clearTimeout(r.KEY_DOWN_TIMEOUT),r.KEY_DOWN_TIMEOUT=setTimeout(function(){r.KEY_DOWN_TIMEOUT=null,_this78.resetRecording(t);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(t,s){this.mouseDownElement=r.getElementIfFocusedOnAvailable(t,s.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0;}},{key:"add",value:function add(t,s){var i=(s==null?void 0:s.insertInCursorLocation)===void 0||(s==null?void 0:s.insertInCursorLocation);s!=null&&s.element&&i&&(t.mouseDownEvent=r.mouseDownWindow.bind(t,s.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=r.mouseUpWindow.bind(t,s),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=r.keyDownWindow.bind(t,s),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 It.EventListeners=r,r.KEY_DOWN_TIMEOUT=null,It;}var Ot={},En;function Da(){if(En)return Ot;En=1,Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.PreResultUtils=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"process",value:function process(t,s,i,n,o){var a=n==null?void 0:n(s,i);return a?(setTimeout(function(){a.restart?t.resetRecording(o):a.stop&&t.stop();}),(a.stop||a.restart)&&a.removeNewText):!1;}}]);}();return Ot.PreResultUtils=r,Ot;}var Nt={},Pt={},_n;function Qn(){if(_n)return Pt;_n=1,Object.defineProperty(Pt,"__esModule",{value:!0}),Pt.AutoScroll=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(t,s){s&&!t.isCursorAtEnd&&(t.endPadding="",t.scrollingSpan.innerHTML=" ");}},{key:"scrollGeneric",value:function scrollGeneric(t,s){t.isCursorAtEnd?s.scrollTop=s.scrollHeight:t.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
|
247
250
|
// they can only safely be scrolled to the end
|
248
|
-
},{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(t){t.scrollLeft=t.scrollWidth,t.scrollTop=t.scrollHeight;}},{key:"isElementOverflown",value:function isElementOverflown(t){return t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;}},{key:"isRequired",value:function isRequired(t,s){return t&&r.isElementOverflown(s);}}]);}();return
|
251
|
+
},{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(t){t.scrollLeft=t.scrollWidth,t.scrollTop=t.scrollHeight;}},{key:"isElementOverflown",value:function isElementOverflown(t){return t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;}},{key:"isRequired",value:function isRequired(t,s){return t&&r.isElementOverflown(s);}}]);}();return Pt.AutoScroll=r,Pt;}var Dt={},Sn;function oi(){if(Sn)return Dt;Sn=1,Object.defineProperty(Dt,"__esModule",{value:!0}),Dt.Elements=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"isPrimitiveElement",value:function isPrimitiveElement(t){return t.tagName==="INPUT"||t.tagName==="TEXTAREA";}},{key:"createInterimSpan",value:function createInterimSpan(){var t=document.createElement("span");return t.style.color="grey",t.style.pointerEvents="none",t;}},{key:"createGenericSpan",value:function createGenericSpan(){var t=document.createElement("span");return t.style.pointerEvents="none",t;}},{key:"appendSpans",value:function appendSpans(t,s){if(t.spansPopulated=!0,t.insertInCursorLocation&&document.activeElement===s){var i=window.getSelection();if(i!=null&&i.focusNode){var n=i.getRangeAt(0);n.insertNode(t.scrollingSpan),n.insertNode(t.interimSpan),n.insertNode(t.finalSpan),n.collapse(!1),i.removeAllRanges(),i.addRange(n);return;}}s.appendChild(t.finalSpan),s.appendChild(t.interimSpan),s.appendChild(t.scrollingSpan);}},{key:"applyCustomColors",value:function applyCustomColors(t,s){s.interim&&(t.interimSpan.style.color=s.interim),s["final"]&&(t.finalSpan.style.color=s["final"]);}},{key:"isInsideShadowDOM",value:function isInsideShadowDOM(t){return t.getRootNode()instanceof ShadowRoot;}}]);}();return Dt.Elements=r,Dt;}var Bt={},xn;function ai(){if(xn)return Bt;xn=1,Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.Cursor=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"setOffsetForGeneric",value:function setOffsetForGeneric(t,s){var i=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var n=0;for(var o=0;o<t.childNodes.length;o+=1){var a=t.childNodes[o];if(a.childNodes.length>0){var l=r.setOffsetForGeneric(a,s,i);if(l===-1)return-1;i+=l;}else if(a.textContent!==null){if(i+a.textContent.length>s){var _l3=document.createRange();_l3.setStart(a,s-i),_l3.collapse(!0);var c=window.getSelection();return c==null||c.removeAllRanges(),c==null||c.addRange(_l3),t.focus(),-1;}i+=a.textContent.length,n+=a.textContent.length;}}return n;}},{key:"focusEndOfGeneric",value:function focusEndOfGeneric(t){var s=document.createRange();s.selectNodeContents(t),s.collapse(!1);var i=window.getSelection();i&&(i.removeAllRanges(),i.addRange(s));}},{key:"setOffsetForSafariGeneric",value:function setOffsetForSafariGeneric(t,s){var i=window.getSelection();if(i){var n=r.getGenericElementCursorOffset(t,i,!0);r.setOffsetForGeneric(t,n+s);}}// set to automatically scroll to cursor (scroll does not work in Safari)
|
249
252
|
},{key:"setOffsetForPrimitive",value:function setOffsetForPrimitive(t,s,i){i&&t.blur(),t.setSelectionRange(s,s),t.focus();}// Scroll Input in Safari - does not work for TextArea and uses span which can have a different style
|
250
253
|
// private static getCursorOffsetFromLeft(inputElement: HTMLInputElement, position: number) {
|
251
254
|
// // Get the value of the input element up to the cursor position
|
@@ -263,39 +266,39 @@ function addToDropup(e,t,s,i){var n=new Js(s,i);gn.forEach(function(a){var l=t["
|
|
263
266
|
// document.body.removeChild(tempSpan);
|
264
267
|
// return {left: offsetWidth, top: offsetHeight};
|
265
268
|
// }
|
266
|
-
},{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(t,s,i){var n=0;if(s.rangeCount>0){var o=s.getRangeAt(0),a=o.cloneRange();a.selectNodeContents(t),i?a.setEnd(o.startContainer,o.startOffset):a.setEnd(o.endContainer,o.endOffset),n=a.toString().length;}return n;}}]);}();return Bt.Cursor=r,Bt;}var
|
267
|
-
},{key:"execCommand",value:function execCommand(a,l,c,d,u){var h,p,m;var f=a.commands;if(!f||!d||!c)return;var g=((h=f.settings)===null||h===void 0?void 0:h.caseSensitive)===!0?l:l.toLowerCase(),y=i.Text.breakupIntoWordsArr(g),T=((p=f.settings)===null||p===void 0?void 0:p.substrings)===!1?n.checkIfMatchesWord:n.checkIfMatchesSubstring;if(f.commandMode&&T(f.commandMode,g,y))return a.setInterimColorToFinal(),setTimeout(function(){return n.toggleCommandModeOn(a);}),{doNotProcessTranscription:!1};if(!(f.commandMode&&!a.isWaitingForCommand)){if(f.stop&&T(f.stop,g,y))return n.toggleCommandModeOff(a),setTimeout(function(){return a.stop();}),{doNotProcessTranscription:!1};if(f.pause&&T(f.pause,g,y))return n.toggleCommandModeOff(a),a.setInterimColorToFinal(),setTimeout(function(){var L;a.isPaused=!0,(L=a.onPauseTrigger)===null||L===void 0||L.call(a,!0);}),{doNotProcessTranscription:!1};if(f.resume&&T(f.resume,g,y))return a.isPaused=!1,(m=a.onPauseTrigger)===null||m===void 0||m.call(a,!1),n.toggleCommandModeOff(a),a.resetRecording(c),{doNotProcessTranscription:!0};if(f.reset&&T(f.reset,g,y))return u!==void 0&&n.setText(a,c,u,d),{doNotProcessTranscription:!0};if(f.removeAllText&&T(f.removeAllText,g,y))return n.setText(a,c,"",d),{doNotProcessTranscription:!0};}}}]);}();return
|
269
|
+
},{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(t,s,i){var n=0;if(s.rangeCount>0){var o=s.getRangeAt(0),a=o.cloneRange();a.selectNodeContents(t),i?a.setEnd(o.startContainer,o.startOffset):a.setEnd(o.endContainer,o.endOffset),n=a.toString().length;}return n;}}]);}();return Bt.Cursor=r,Bt;}var wn;function er(){if(wn)return Nt;wn=1,Object.defineProperty(Nt,"__esModule",{value:!0}),Nt.CommandUtils=void 0;var r=Qn(),e=oi(),t=Vi(),s=ai(),i=ri();var n=/*#__PURE__*/function(){function n(){_classCallCheck(this,n);}return _createClass(n,null,[{key:"processCommand",value:function processCommand(a,l){return(!l||!l.caseSensitive)&&(a=a.toLowerCase()),(l==null?void 0:l.substrings)===!1?i.Text.breakupIntoWordsArr(a):a;}},{key:"process",value:function process(a){var l;return((l=a.settings)===null||l===void 0?void 0:l.caseSensitive)===!0?a:Object.keys(a).reduce(function(d,u){var h=a[u];return d[u]=typeof h=="string"?n.processCommand(h,a.settings):h,d;},{});}},{key:"toggleCommandModeOn",value:function toggleCommandModeOn(a){var l;a.isWaitingForCommand=!0,(l=a.onCommandModeTrigger)===null||l===void 0||l.call(a,!0);}},{key:"toggleCommandModeOff",value:function toggleCommandModeOff(a){var l;a.isWaitingForCommand&&((l=a.onCommandModeTrigger)===null||l===void 0||l.call(a,!1),a.isWaitingForCommand=!1);}},{key:"setText",value:function setText(a,l,c,d){n.toggleCommandModeOff(a),e.Elements.isPrimitiveElement(d)?(d.value=c,a.isTargetInShadow||s.Cursor.setOffsetForPrimitive(d,c.length,!0),t.Browser.IS_SAFARI()&&a.autoScroll&&r.AutoScroll.scrollSafariPrimitiveToEnd(d)):(d.textContent=c,a.isTargetInShadow||s.Cursor.focusEndOfGeneric(d),setTimeout(function(){return r.AutoScroll.scrollGeneric(a,d);})),a.resetRecording(l);}},{key:"checkIfMatchesSubstring",value:function checkIfMatchesSubstring(a,l){return l.includes(a);}},{key:"checkIfMatchesWord",value:function checkIfMatchesWord(a,l,c){var d=a;for(var u=c.length-1;u>=0;u-=1){var h=u,p=d.length-1;for(;c[h]===d[p]&&p>=0;)h-=1,p-=1;if(p<0)return!0;}return!1;}// prettier-ignore
|
270
|
+
},{key:"execCommand",value:function execCommand(a,l,c,d,u){var h,p,m;var f=a.commands;if(!f||!d||!c)return;var g=((h=f.settings)===null||h===void 0?void 0:h.caseSensitive)===!0?l:l.toLowerCase(),y=i.Text.breakupIntoWordsArr(g),T=((p=f.settings)===null||p===void 0?void 0:p.substrings)===!1?n.checkIfMatchesWord:n.checkIfMatchesSubstring;if(f.commandMode&&T(f.commandMode,g,y))return a.setInterimColorToFinal(),setTimeout(function(){return n.toggleCommandModeOn(a);}),{doNotProcessTranscription:!1};if(!(f.commandMode&&!a.isWaitingForCommand)){if(f.stop&&T(f.stop,g,y))return n.toggleCommandModeOff(a),setTimeout(function(){return a.stop();}),{doNotProcessTranscription:!1};if(f.pause&&T(f.pause,g,y))return n.toggleCommandModeOff(a),a.setInterimColorToFinal(),setTimeout(function(){var L;a.isPaused=!0,(L=a.onPauseTrigger)===null||L===void 0||L.call(a,!0);}),{doNotProcessTranscription:!1};if(f.resume&&T(f.resume,g,y))return a.isPaused=!1,(m=a.onPauseTrigger)===null||m===void 0||m.call(a,!1),n.toggleCommandModeOff(a),a.resetRecording(c),{doNotProcessTranscription:!0};if(f.reset&&T(f.reset,g,y))return u!==void 0&&n.setText(a,c,u,d),{doNotProcessTranscription:!0};if(f.removeAllText&&T(f.removeAllText,g,y))return n.setText(a,c,"",d),{doNotProcessTranscription:!0};}}}]);}();return Nt.CommandUtils=n,Nt;}var Ft={},An;function Ba(){if(An)return Ft;An=1,Object.defineProperty(Ft,"__esModule",{value:!0}),Ft.Highlight=void 0;var r=oi(),e=ai();var t=/*#__PURE__*/function(){function t(){_classCallCheck(this,t);}return _createClass(t,null,[{key:"setStateForPrimitive",value:function setStateForPrimitive(i,n){var o,a;n.selectionStart!==null&&(o=n.selectionStart),n.selectionEnd!==null&&(a=n.selectionEnd),i.isHighlighted=o!==a;}},{key:"setStateForGeneric",value:function setStateForGeneric(i,n){var o=window.getSelection();if(o!=null&&o.focusNode){var a=e.Cursor.getGenericElementCursorOffset(n,o,!0),l=e.Cursor.getGenericElementCursorOffset(n,o,!1);i.isHighlighted=a!==l;}}},{key:"setState",value:function setState(i,n){document.activeElement===n&&(r.Elements.isPrimitiveElement(n)?t.setStateForPrimitive(i,n):t.setStateForGeneric(i,n));}},{key:"removeForGeneric",value:function removeForGeneric(i,n){var o=window.getSelection();if(o){var a=e.Cursor.getGenericElementCursorOffset(n,o,!0);o.deleteFromDocument(),e.Cursor.setOffsetForGeneric(n,a),i.isHighlighted=!1;}}},{key:"removeForPrimitive",value:function removeForPrimitive(i,n){var o=n.selectionStart,a=n.selectionEnd,l=n.value;if(o&&a){var c=l.substring(0,o)+l.substring(a);n.value=c,e.Cursor.setOffsetForPrimitive(n,o,i.autoScroll);}i.isHighlighted=!1;}}]);}();return Ft.Highlight=t,Ft;}var Ut={},Cn;function Fa(){if(Cn)return Ut;Cn=1,Object.defineProperty(Ut,"__esModule",{value:!0}),Ut.Padding=void 0;var r=oi(),e=ai(),t=ri();var s=/*#__PURE__*/function(){function s(){_classCallCheck(this,s);}return _createClass(s,null,[{key:"setStateForPrimitiveElement",value:function setStateForPrimitiveElement(n,o){if(document.activeElement===o&&o.selectionStart!==null){var l=o.selectionStart,c=o.value[l-1],d=o.selectionEnd===null?l:o.selectionEnd,u=o.value[d];t.Text.isCharDefined(c)&&(n.startPadding=" ",n.numberOfSpacesBeforeNewText=1),t.Text.isCharDefined(u)&&(n.endPadding=" ",n.numberOfSpacesAfterNewText=1),n.isCursorAtEnd=o.value.length===d;return;}var a=o.value[o.value.length-1];t.Text.isCharDefined(a)&&(n.startPadding=" ",n.numberOfSpacesBeforeNewText=1),n.isCursorAtEnd=!0;}},{key:"setStateForGenericElement",value:function setStateForGenericElement(n,o){var a,l,c;if(document.activeElement===o){var u=window.getSelection();if(u!=null&&u.focusNode){var h=e.Cursor.getGenericElementCursorOffset(o,u,!0),p=(a=o.textContent)===null||a===void 0?void 0:a[h-1],m=e.Cursor.getGenericElementCursorOffset(o,u,!1),f=(l=o.textContent)===null||l===void 0?void 0:l[m];t.Text.isCharDefined(p)&&(n.startPadding=" "),t.Text.isCharDefined(f)&&(n.endPadding=" "),n.isCursorAtEnd=((c=o.textContent)===null||c===void 0?void 0:c.length)===m;return;}}var d=o.innerText.charAt(o.innerText.length-1);t.Text.isCharDefined(d)&&(n.startPadding=" "),n.isCursorAtEnd=!0;}},{key:"setState",value:function setState(n,o){r.Elements.isPrimitiveElement(o)?s.setStateForPrimitiveElement(n,o):s.setStateForGenericElement(n,o);}},{key:"adjustStateAfterRecodingPrimitiveElement",value:function adjustStateAfterRecodingPrimitiveElement(n,o){if(n.primitiveTextRecorded=!0,n.insertInCursorLocation&&document.activeElement===o&&(o.selectionEnd!==null&&(n.endPadding=n.endPadding+o.value.slice(o.selectionEnd)),o.selectionStart!==null)){n.startPadding=o.value.slice(0,o.selectionStart)+n.startPadding;return;}n.startPadding=o.value+n.startPadding;}},{key:"adjustSateForNoTextPrimitiveElement",value:function adjustSateForNoTextPrimitiveElement(n){n.numberOfSpacesBeforeNewText===1&&(n.startPadding=n.startPadding.substring(0,n.startPadding.length-1),n.numberOfSpacesBeforeNewText=0),n.numberOfSpacesAfterNewText===1&&(n.endPadding=n.endPadding.substring(1),n.numberOfSpacesAfterNewText=0);}}]);}();return Ut.Padding=s,Ut;}var Tn;function tr(){if(Tn)return Lt;Tn=1,Object.defineProperty(Lt,"__esModule",{value:!0}),Lt.Speech=void 0;var r=Pa(),e=Da(),t=er(),s=Qn(),i=Ba(),n=oi(),o=Fa(),a=Vi(),l=ai(),c=ri();var d=/*#__PURE__*/function(){function d(){_classCallCheck(this,d);this.finalTranscript="",this.interimSpan=n.Elements.createInterimSpan(),this.finalSpan=n.Elements.createGenericSpan(),this.scrollingSpan=n.Elements.createGenericSpan(),this.isCursorAtEnd=!1,this.spansPopulated=!1,this.startPadding="",this.endPadding="",this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.recognizing=!1,this._displayInterimResults=!0,this.insertInCursorLocation=!0,this.autoScroll=!0,this.isRestarting=!1,this.isPaused=!1,this.isWaitingForCommand=!1,this.isTargetInShadow=!1,this.cannotBeStopped=!1,this.resetState();}return _createClass(d,[{key:"prepareBeforeStart",value:function prepareBeforeStart(h){var p,m;if(h!=null&&h.element)if(r.EventListeners.add(this,h),Array.isArray(h.element)){var g=h.element.find(function(y){return y===document.activeElement;})||h.element[0];if(!g)return;this.prepare(g);}else this.prepare(h.element);(h==null?void 0:h.displayInterimResults)!==void 0&&(this._displayInterimResults=h.displayInterimResults),h!=null&&h.textColor&&(this._finalTextColor=(p=h==null?void 0:h.textColor)===null||p===void 0?void 0:p["final"],n.Elements.applyCustomColors(this,h.textColor)),(h==null?void 0:h.insertInCursorLocation)!==void 0&&(this.insertInCursorLocation=h.insertInCursorLocation),(h==null?void 0:h.autoScroll)!==void 0&&(this.autoScroll=h.autoScroll),this._onResult=h==null?void 0:h.onResult,this._onPreResult=h==null?void 0:h.onPreResult,this._onStart=h==null?void 0:h.onStart,this._onStop=h==null?void 0:h.onStop,this._onError=h==null?void 0:h.onError,this.onCommandModeTrigger=h==null?void 0:h.onCommandModeTrigger,this.onPauseTrigger=h==null?void 0:h.onPauseTrigger,this._options=h,!((m=this._options)===null||m===void 0)&&m.commands&&(this.commands=t.CommandUtils.process(this._options.commands));}},{key:"prepare",value:function prepare(h){o.Padding.setState(this,h),i.Highlight.setState(this,h),this.isTargetInShadow=n.Elements.isInsideShadowDOM(h),n.Elements.isPrimitiveElement(h)?(this._primitiveElement=h,this._originalText=this._primitiveElement.value):(this._genericElement=h,this._originalText=this._genericElement.textContent);}// there was an attempt to optimize this by not having to restart the service and just reset state:
|
268
271
|
// unfortunately it did not work because the service would still continue firing the intermediate and final results
|
269
272
|
// into the new position
|
270
273
|
},{key:"resetRecording",value:function resetRecording(h){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(h,!0);}// prettier-ignore
|
271
274
|
},{key:"updateElements",value:function updateElements(h,p,m){var f;var g=c.Text.capitalize(p);if(this.finalTranscript===g&&h==="")return;e.PreResultUtils.process(this,m,h==="",this._onPreResult,this._options)&&(h="",m="");var y=this.commands&&t.CommandUtils.execCommand(this,m,this._options,this._primitiveElement||this._genericElement,this._originalText);if(y){if(y.doNotProcessTranscription)return;h="",m="";}if(this.isPaused||this.isWaitingForCommand)return;(f=this._onResult)===null||f===void 0||f.call(this,m,h===""),this.finalTranscript=g,this._displayInterimResults||(h="");var T=this.finalTranscript===""&&h==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,h,T):this._genericElement&&this.updateGenericElement(this._genericElement,h,T);}// prettier-ignore
|
272
275
|
// remember that padding values here contain actual text left and right
|
273
|
-
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(h,p,m){this.isHighlighted&&i.Highlight.removeForPrimitive(this,h),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,h),m&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var f=this.startPadding+this.finalTranscript+p;if(h.value=f+this.endPadding,!this.isTargetInShadow){var g=f.length+this.numberOfSpacesAfterNewText;l.Cursor.setOffsetForPrimitive(h,g,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&s.AutoScroll.scrollSafariPrimitiveToEnd(h);}},{key:"updateGenericElement",value:function updateGenericElement(h,p,m){this.isHighlighted&&i.Highlight.removeForGeneric(this,h),this.spansPopulated||n.Elements.appendSpans(this,h);var f=(m?"":this.startPadding)+c.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=f;var g=s.AutoScroll.isRequired(this.autoScroll,h);s.AutoScroll.changeStateIfNeeded(this,g);var y=c.Text.lineBreak(p)+(m?"":this.endPadding);this.interimSpan.innerHTML=y,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&l.Cursor.setOffsetForSafariGeneric(h,f.length+y.length),g&&s.AutoScroll.scrollGeneric(this,h),m&&(this.scrollingSpan.innerHTML="");}},{key:"finalise",value:function finalise(h){this._genericElement&&(h?(this.finalSpan=n.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=n.Elements.createInterimSpan(),this.scrollingSpan=n.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),r.EventListeners.remove(this);}},{key:"setInterimColorToFinal",value:function setInterimColorToFinal(){this.interimSpan.style.color=this._finalTextColor||"black";}},{key:"resetState",value:function resetState(h){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,h||(this.stopTimeout=void 0);}},{key:"setStateOnStart",value:function setStateOnStart(){var h;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(h=this._onStart)===null||h===void 0||h.call(this);}},{key:"setStateOnStop",value:function setStateOnStop(){var h;this.recognizing=!1,this.isRestarting||(h=this._onStop)===null||h===void 0||h.call(this);}},{key:"setStateOnError",value:function setStateOnError(h){var p;(p=this._onError)===null||p===void 0||p.call(this,h),this.recognizing=!1;}}]);}();return Lt.Speech=d,Lt;}var
|
274
|
-
function extract(s,i,n,o){return o&&(s=r.Translate.translate(s,o)),n?{interimTranscript:"",finalTranscript:i+s,newText:s}:{interimTranscript:s,finalTranscript:i,newText:s};}}]);}();return
|
276
|
+
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(h,p,m){this.isHighlighted&&i.Highlight.removeForPrimitive(this,h),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,h),m&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var f=this.startPadding+this.finalTranscript+p;if(h.value=f+this.endPadding,!this.isTargetInShadow){var g=f.length+this.numberOfSpacesAfterNewText;l.Cursor.setOffsetForPrimitive(h,g,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&s.AutoScroll.scrollSafariPrimitiveToEnd(h);}},{key:"updateGenericElement",value:function updateGenericElement(h,p,m){this.isHighlighted&&i.Highlight.removeForGeneric(this,h),this.spansPopulated||n.Elements.appendSpans(this,h);var f=(m?"":this.startPadding)+c.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=f;var g=s.AutoScroll.isRequired(this.autoScroll,h);s.AutoScroll.changeStateIfNeeded(this,g);var y=c.Text.lineBreak(p)+(m?"":this.endPadding);this.interimSpan.innerHTML=y,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&l.Cursor.setOffsetForSafariGeneric(h,f.length+y.length),g&&s.AutoScroll.scrollGeneric(this,h),m&&(this.scrollingSpan.innerHTML="");}},{key:"finalise",value:function finalise(h){this._genericElement&&(h?(this.finalSpan=n.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=n.Elements.createInterimSpan(),this.scrollingSpan=n.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),r.EventListeners.remove(this);}},{key:"setInterimColorToFinal",value:function setInterimColorToFinal(){this.interimSpan.style.color=this._finalTextColor||"black";}},{key:"resetState",value:function resetState(h){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,h||(this.stopTimeout=void 0);}},{key:"setStateOnStart",value:function setStateOnStart(){var h;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(h=this._onStart)===null||h===void 0||h.call(this);}},{key:"setStateOnStop",value:function setStateOnStop(){var h;this.recognizing=!1,this.isRestarting||(h=this._onStop)===null||h===void 0||h.call(this);}},{key:"setStateOnError",value:function setStateOnError(h){var p;(p=this._onError)===null||p===void 0||p.call(this,h),this.recognizing=!1;}}]);}();return Lt.Speech=d,Lt;}var Rn;function Ua(){if(Rn)return Ct;Rn=1,Object.defineProperty(Ct,"__esModule",{value:!0}),Ct.WebSpeech=void 0;var r=Na(),e=Vi(),t=tr();var s=/*#__PURE__*/function(_t$Speech){function s(){_classCallCheck(this,s);return _callSuper(this,s);}_inherits(s,_t$Speech);return _createClass(s,[{key:"start",value:function start(n){var o;this._extractText===void 0&&(this._extractText=e.Browser.IS_SAFARI()?r.WebSpeechTranscript.extractSafari:r.WebSpeechTranscript.extract),this.validate()&&(this.prepareBeforeStart(n),this.instantiateService(n),(o=this._service)===null||o===void 0||o.start(),this._translations=n==null?void 0:n.translations);}},{key:"validate",value:function validate(){return s.getAPI()?!0:(this.error("Speech Recognition is unsupported"),!1);}},{key:"instantiateService",value:function instantiateService(n){var o,a;var l=s.getAPI();this._service=new l(),this._service.continuous=!0,this._service.interimResults=(o=n==null?void 0:n.displayInterimResults)!==null&&o!==void 0?o:!0,this._service.lang=((a=n==null?void 0:n.language)===null||a===void 0?void 0:a.trim())||"en-US",this.setEvents();}},{key:"setEvents",value:function setEvents(){var _this79=this;this._service&&(this._service.onstart=function(){_this79.setStateOnStart();},this._service.onerror=function(n){e.Browser.IS_SAFARI()&&n.message==="Another request is started"||n.error==="aborted"&&_this79.isRestarting||n.error!=="no-speech"&&_this79.error(n.message||n.error);},this._service.onaudioend=function(){_this79.setStateOnStop();},this._service.onend=function(){_this79._stopping=!1;},this._service.onresult=function(n){if(_typeof(n.results)>"u"&&_this79._service)_this79._service.onend=null,_this79._service.stop();else if(_this79._extractText&&!_this79._stopping){var _this79$_extractText=_this79._extractText(n,_this79.finalTranscript,_this79._translations),o=_this79$_extractText.interimTranscript,a=_this79$_extractText.finalTranscript,l=_this79$_extractText.newText;_this79.updateElements(o,a,l);}});}},{key:"stop",value:function stop(n){var o;this._stopping=!0,(o=this._service)===null||o===void 0||o.stop(),this.finalise(n);}},{key:"error",value:function error(n){console.error(n),this.setStateOnError(n),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.webkitSpeechRecognition||window.SpeechRecognition;}}]);}(t.Speech);return Ct.WebSpeech=s,Ct;}var jt={},Mn;function ja(){if(Mn)return jt;Mn=1,Object.defineProperty(jt,"__esModule",{value:!0}),jt.GlobalState=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"doubleClickDetector",value:function doubleClickDetector(){return r.doubleClickPending?!0:(r.doubleClickPending=!0,setTimeout(function(){r.doubleClickPending=!1;},300),!1);}}]);}();return jt.GlobalState=r,r.doubleClickPending=!1,jt;}var Ht={},qt={},kn;function Ha(){if(kn)return qt;kn=1,Object.defineProperty(qt,"__esModule",{value:!0}),qt.PreventConnectionStop=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,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 qt.PreventConnectionStop=r,qt;}var Vt={},Gt={},Ln;function qa(){return Ln||(Ln=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.README_URL=void 0,Gt.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),Gt;}var In;function Va(){if(In)return Vt;In=1,Object.defineProperty(Vt,"__esModule",{value:!0}),Vt.AzureSpeechConfig=void 0;var r=qa();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"validateOptions",value:function validateOptions(s,i){return i?!i.subscriptionKey&&!i.token&&!i.retrieveToken?(s("Please define a 'subscriptionKey', 'token' or 'retrieveToken' property - more info: ".concat(r.README_URL)),!1):i.region?!0:(s("Please define a 'region' property - more info: ".concat(r.README_URL)),!1):(s("Please provide subscription details - more info: ".concat(r.README_URL)),!1);}},{key:"getNewSpeechConfig",value:function(){var _getNewSpeechConfig=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(s,i){return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:if(!i.region){_context139.n=1;break;}return _context139.a(2,i.subscriptionKey?s.fromSubscription(i.subscriptionKey.trim(),i.region.trim()):i.token?s.fromAuthorizationToken(i.token.trim(),i.region.trim()):i.retrieveToken?i.retrieveToken().then(function(n){return i.region?s.fromAuthorizationToken((n==null?void 0:n.trim())||"",i.region.trim()):null;})["catch"](function(n){return console.error(n),null;}):null);case 1:return _context139.a(2);}},_callee139);}));function getNewSpeechConfig(_x257,_x258){return _getNewSpeechConfig.apply(this,arguments);}return getNewSpeechConfig;}()},{key:"process",value:function process(s,i){i.endpointId&&(s.endpointId=i.endpointId.trim()),i.language&&(s.speechRecognitionLanguage=i.language.trim());}},{key:"get",value:function(){var _get=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(s,i){var n;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:_context140.n=1;return e.getNewSpeechConfig(s,i);case 1:n=_context140.v;return _context140.a(2,(n&&e.process(n,i),n));}},_callee140);}));function get(_x259,_x260){return _get.apply(this,arguments);}return get;}()}]);}();return Vt.AzureSpeechConfig=e,Vt;}var zt={},On;function Ga(){if(On)return zt;On=1,Object.defineProperty(zt,"__esModule",{value:!0}),zt.StopTimeout=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"set",value:function set(t){t.stopTimeout=setTimeout(function(){return t.stop();},t.stopTimeoutMS);}},{key:"reset",value:function reset(t,s){t.stopTimeoutMS=s||r.DEFAULT_MS,r.stop(t),r.set(t);}},{key:"stop",value:function stop(t){t.stopTimeout&&clearTimeout(t.stopTimeout);}}]);}();return zt.StopTimeout=r,r.DEFAULT_MS=2e4,zt;}var Kt={},Nn;function za(){if(Nn)return Kt;Nn=1,Object.defineProperty(Kt,"__esModule",{value:!0}),Kt.AzureAudioConfig=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"get",value:function get(t,s){return s?t.fromMicrophoneInput(s):t.fromDefaultMicrophoneInput();}}]);}();return Kt.AzureAudioConfig=r,Kt;}var Wt={},Pn;function Ka(){if(Pn)return Wt;Pn=1,Object.defineProperty(Wt,"__esModule",{value:!0}),Wt.AzureTranscript=void 0;var r=Zn();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
|
277
|
+
function extract(s,i,n,o){return o&&(s=r.Translate.translate(s,o)),n?{interimTranscript:"",finalTranscript:i+s,newText:s}:{interimTranscript:s,finalTranscript:i,newText:s};}}]);}();return Wt.AzureTranscript=e,Wt;}var Dn;function Wa(){if(Dn)return Ht;Dn=1,Object.defineProperty(Ht,"__esModule",{value:!0}),Ht.Azure=void 0;var r=Ha(),e=Va(),t=Ga(),s=za(),i=Ka(),n=tr();var o=/*#__PURE__*/function(_n$Speech){function o(){var _this80;_classCallCheck(this,o);_this80=_callSuper(this,o,arguments),_this80._newTextPadding="";return _this80;}_inherits(o,_n$Speech);return _createClass(o,[{key:"start",value:function start(l,c){this._newTextPadding="",this.stopTimeout===void 0&&t.StopTimeout.reset(this,l==null?void 0:l.stopAfterSilenceMs),this.prepareBeforeStart(l),this.startAsync(l),c||r.PreventConnectionStop.applyPrevention(this);}},{key:"startAsync",value:function(){var _startAsync=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(l){var c,_t49;return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:_t49=this.validate(l);if(!_t49){_context141.n=2;break;}_context141.n=1;return this.instantiateService(l);case 1:this._translations=l==null?void 0:l.translations;(c=this._service)===null||c===void 0||c.startContinuousRecognitionAsync(function(){},this.error);case 2:return _context141.a(2);}},_callee141,this);}));function startAsync(_x261){return _startAsync.apply(this,arguments);}return startAsync;}()},{key:"validate",value:function validate(l){return o.getAPI()?e.AzureSpeechConfig.validateOptions(this.error.bind(this),l):(this.moduleNotFound(),!1);}},{key:"instantiateService",value:function(){var _instantiateService=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(l){var c,d,u,h,_l$autoLanguage,p,m,f,g;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:c=o.getAPI();d=s.AzureAudioConfig.get(c.AudioConfig,l.deviceId);_context142.n=1;return e.AzureSpeechConfig.get(c.SpeechConfig,l);case 1:u=_context142.v;if(u){if(l.autoLanguage&&l.autoLanguage.languages.length>0){_l$autoLanguage=l.autoLanguage,p=_l$autoLanguage.type,m=_l$autoLanguage.languages,f=m.slice(0,p==="Continuous"?10:4),g=c.AutoDetectSourceLanguageConfig.fromLanguages(f);p==="Continuous"&&(g.mode=1),h=c.SpeechRecognizer.FromConfig(u,g,d);}else h=new c.SpeechRecognizer(u,d);this.setEvents(h),this._service=h,l.retrieveToken&&this.retrieveTokenInterval(l.retrieveToken);}else this.error("Unable to contact Azure server");case 2:return _context142.a(2);}},_callee142,this);}));function instantiateService(_x262){return _instantiateService.apply(this,arguments);}return instantiateService;}()},{key:"setEvents",value:function setEvents(l){l.recognizing=this.onRecognizing.bind(this),l.recognized=this.onRecognized.bind(this),l.sessionStarted=this.onSessionStarted.bind(this),l.canceled=this.onCanceled.bind(this),l.sessionStopped=this.onSessionStopped.bind(this);}// prettier-ignore
|
275
278
|
},{key:"onRecognizing",value:function onRecognizing(l,c){if(this._stopping)return;var _i$AzureTranscript$ex=i.AzureTranscript.extract(this._newTextPadding+c.result.text,this.finalTranscript,!1,this._translations),d=_i$AzureTranscript$ex.interimTranscript,u=_i$AzureTranscript$ex.finalTranscript,h=_i$AzureTranscript$ex.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(d,u,h);}// prettier-ignore
|
276
|
-
},{key:"onRecognized",value:function onRecognized(l,c){var d=c.result;switch(d.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(d.text&&!this._stopping){var _i$AzureTranscript$ex2=i.AzureTranscript.extract(this._newTextPadding+d.text,this.finalTranscript,!0,this._translations),u=_i$AzureTranscript$ex2.interimTranscript,h=_i$AzureTranscript$ex2.finalTranscript,p=_i$AzureTranscript$ex2.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(u,h,p),h!==""&&(this._newTextPadding=" ");}break;}}},{key:"onCanceled",value:function onCanceled(l,c){c.reason===window.SpeechSDK.CancellationReason.Error&&this.error(c.errorDetails);}},{key:"onSessionStarted",value:function onSessionStarted(){r.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(l){var
|
277
|
-
_inherits(is,_ni);return _createClass(is,[{key:"processConfiguration",value:function processConfiguration(e,t){var _s$displayInterimResu,_s$textColor,_s$translations,_s$commands,_s$events;var c;var s=_typeof(t)=="object"?t:{},i=_typeof(s.webSpeech)=="object"?s.webSpeech:{},n=s.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_s$displayInterimResu=s.displayInterimResults)!==null&&_s$displayInterimResu!==void 0?_s$displayInterimResu:void 0,textColor:(_s$textColor=s.textColor)!==null&&_s$textColor!==void 0?_s$textColor:void 0,translations:(_s$translations=s.translations)!==null&&_s$translations!==void 0?_s$translations:void 0,commands:(_s$commands=s.commands)!==null&&_s$commands!==void 0?_s$commands:void 0,events:(_s$events=s.events)!==null&&_s$events!==void 0?_s$events:void 0},i),n),a=(c=s.commands)==null?void 0:c.submit;return a&&(o.onPreResult=function(d){return d.toLowerCase().includes(a)?(setTimeout(function(){var u;return(u=e.submit)==null?void 0:u.call(e);}),Es.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),s.submitAfterSilence&&(this._silenceSubmit=new
|
278
|
-
function
|
279
|
-
function
|
280
|
-
},{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var s=this._activePlaceholderAttachment;s&&(s.file=e,
|
281
|
-
function create(e,t,s,i,n,o){return o==="audio"?new us(e,t,s,i,n):new
|
282
|
-
return _createClass(ms,[{key:"addType",value:function addType(e,t,s,i){var n=
|
283
|
-
function
|
279
|
+
},{key:"onRecognized",value:function onRecognized(l,c){var d=c.result;switch(d.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(d.text&&!this._stopping){var _i$AzureTranscript$ex2=i.AzureTranscript.extract(this._newTextPadding+d.text,this.finalTranscript,!0,this._translations),u=_i$AzureTranscript$ex2.interimTranscript,h=_i$AzureTranscript$ex2.finalTranscript,p=_i$AzureTranscript$ex2.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(u,h,p),h!==""&&(this._newTextPadding=" ");}break;}}},{key:"onCanceled",value:function onCanceled(l,c){c.reason===window.SpeechSDK.CancellationReason.Error&&this.error(c.errorDetails);}},{key:"onSessionStarted",value:function onSessionStarted(){r.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(l){var _this81=this;this._retrieveTokenInterval=setInterval(function(){l==null||l().then(function(c){_this81._service&&(_this81._service.authorizationToken=(c==null?void 0:c.trim())||"");})["catch"](function(c){_this81.error(c);});},1e4);}},{key:"stop",value:function stop(l){var c;!l&&this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),this._stopping=!0,(c=this._service)===null||c===void 0||c.stopContinuousRecognitionAsync(),t.StopTimeout.stop(this),this.finalise(l);}},{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(l){this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),console.error(l),this.setStateOnError(l),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.SpeechSDK;}}]);}(n.Speech);return Ht.Azure=o,Ht;}var Bn;function $a(){if(Bn)return vs;Bn=1,Object.defineProperty(vs,"__esModule",{value:!0});var r=Ua(),e=er(),t=ja(),s=Wa();var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"toggle",value:function toggle(o,a){var l,c;var d=o.toLocaleLowerCase().trim();!((l=t.GlobalState.service)===null||l===void 0)&&l.recognizing?this.stop():d==="webspeech"?i.startWebSpeech(a):d==="azure"?i.startAzure(a):(console.error("service not found - must be either 'webspeech' or 'azure'"),(c=a==null?void 0:a.onError)===null||c===void 0||c.call(a,"service not found - must be either 'webspeech' or 'azure'"));}},{key:"startWebSpeech",value:function startWebSpeech(o){i.stop()||(t.GlobalState.service=new r.WebSpeech(),t.GlobalState.service.start(o));}},{key:"isWebSpeechSupported",value:function isWebSpeechSupported(){return!!r.WebSpeech.getAPI();}},{key:"startAzure",value:function startAzure(o){var a;i.stop()||!((a=t.GlobalState.service)===null||a===void 0)&&a.cannotBeStopped||(t.GlobalState.service=new s.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 vs["default"]=i,vs;}var Ja=$a();var Es=/* @__PURE__ */Oa(Ja);var Xa=/*#__PURE__*/function(){function Xa(e,t){_classCallCheck(this,Xa);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(Xa,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this82=this;this._silenceTimeout=setTimeout(function(){var s;(s=e.submit)==null||s.call(e),Es.stop(),_this82._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,s){e?this.resetSilenceTimeout(t,s):this.clearSilenceTimeout();}}]);}();var is=/*#__PURE__*/function(_ni){function is(e,t,s){var _this83;_classCallCheck(this,is);var i=_typeof(e.speechToText)=="object"?e.speechToText:{};_this83=_callSuper(this,is,[i==null?void 0:i.button]);var _this83$processConfig=_this83.processConfiguration(t,e.speechToText),n=_this83$processConfig.serviceName,o=_this83$processConfig.processedConfig;if(_this83._addErrorMessage=s,n==="webspeech"&&!Es.isWebSpeechSupported())_this83.changeToUnsupported();else{var a=!e.textInput||!e.textInput.disabled;_this83.elementRef.onclick=_this83.buttonClick.bind(_this83,t,a,n,o);}setTimeout(function(){_this83._validationHandler=e._validationHandler;});return _this83;}// prettier-ignore
|
280
|
+
_inherits(is,_ni);return _createClass(is,[{key:"processConfiguration",value:function processConfiguration(e,t){var _s$displayInterimResu,_s$textColor,_s$translations,_s$commands,_s$events;var c;var s=_typeof(t)=="object"?t:{},i=_typeof(s.webSpeech)=="object"?s.webSpeech:{},n=s.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_s$displayInterimResu=s.displayInterimResults)!==null&&_s$displayInterimResu!==void 0?_s$displayInterimResu:void 0,textColor:(_s$textColor=s.textColor)!==null&&_s$textColor!==void 0?_s$textColor:void 0,translations:(_s$translations=s.translations)!==null&&_s$translations!==void 0?_s$translations:void 0,commands:(_s$commands=s.commands)!==null&&_s$commands!==void 0?_s$commands:void 0,events:(_s$events=s.events)!==null&&_s$events!==void 0?_s$events:void 0},i),n),a=(c=s.commands)==null?void 0:c.submit;return a&&(o.onPreResult=function(d){return d.toLowerCase().includes(a)?(setTimeout(function(){var u;return(u=e.submit)==null?void 0:u.call(e);}),Es.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),s.submitAfterSilence&&(this._silenceSubmit=new Xa(s.submitAfterSilence,s.stopAfterSubmit)),{serviceName:is.getServiceName(s),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,s,i){var _this84=this;var n=i==null?void 0:i.events;e.removePlaceholderStyle(),Es.toggle(s,_objectSpread({insertInCursorLocation:!1,element:t?e.inputElementRef:void 0,onError:function onError(){var o;_this84.onError(),(o=_this84._silenceSubmit)==null||o.clearSilenceTimeout();},onStart:function onStart(){var o;_this84.changeToActive(),(o=n==null?void 0:n.onStart)==null||o.call(n);},onStop:function onStop(){var o,a,l;(o=_this84._validationHandler)==null||o.call(_this84),(a=_this84._silenceSubmit)==null||a.clearSilenceTimeout(),_this84.changeToDefault(),(l=n==null?void 0:n.onStop)==null||l.call(n);},onPauseTrigger:function onPauseTrigger(o){var a,l;(a=_this84._silenceSubmit)==null||a.onPause(o,e,_this84.elementRef.onclick),(l=n==null?void 0:n.onPauseTrigger)==null||l.call(n,o);},onPreResult:function onPreResult(o,a){var l;(l=n==null?void 0:n.onPreResult)==null||l.call(n,o,a);},onResult:function onResult(o,a){var l,c,d;a&&((l=_this84._validationHandler)==null||l.call(_this84)),(c=_this84._silenceSubmit)==null||c.resetSilenceTimeout(e,_this84.elementRef.onclick),(d=n==null?void 0:n.onResult)==null||d.call(n,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this84.onCommandModeTrigger(o),(a=n==null?void 0:n.onCommandModeTrigger)==null||a.call(n,o);}},i));}},{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.click(),t||setTimeout(function(){return e.click();},is.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(ni);is.MICROPHONE_RESET_TIMEOUT_MS=300;var hs=is;var Ue=/*#__PURE__*/function(){// prettier-ignore
|
281
|
+
function Ue(e,t,s,i,n){var _this85=this;_classCallCheck(this,Ue);this._attachments=[],this._fileCountLimit=99,this._acceptedFormat="",this._hiddenAttachments=/* @__PURE__ */new Set(),s.maxNumberOfFiles&&(this._fileCountLimit=s.maxNumberOfFiles),this._toggleContainerDisplay=i,this._fileAttachmentsContainerRef=n,s.acceptedFormats&&(this._acceptedFormat=s.acceptedFormats),setTimeout(function(){_this85._validationHandler=e._validationHandler,_this85._onInput=t.onInput;});}return _createClass(Ue,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var s;return Ue.isFileTypeValid(e,this._acceptedFormat)?(this.addAttachmentBasedOnType(e,t,!0),(s=this._onInput)==null||s.call(this,!0),!0):!1;}},{key:"addAttachmentBasedOnType",value:function addAttachmentBasedOnType(e,t,s){var i=Ue.getTypeFromBlob(e);if(i==="image"){var n=Ue.createImageAttachment(t);this.addFileAttachment(e,"image",n,s);}else if(i==="audio"){var _n3=us.createAudioAttachment(t);this.addFileAttachment(e,"audio",_n3,s);}else{var _n4=Ue.createAnyFileAttachment(e.name);this.addFileAttachment(e,"any",_n4,s);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,s,i){var a;var n=Ue.createContainer(s);if(this._attachments.length>=this._fileCountLimit){var l=this._attachments[this._attachments.length-1].removeButton;l==null||l.click();var c=this._fileAttachmentsContainerRef.children;this._fileAttachmentsContainerRef.insertBefore(n,c[0]);}else this._fileAttachmentsContainerRef.appendChild(n);var o={file:e,attachmentContainerElement:n,fileType:t};return i&&(o.removeButton=this.createRemoveAttachmentButton(o),n.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=document.createElement("div");t.classList.add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var s=document.createElement("div");return s.classList.add("x-icon"),s.innerText="×",t.appendChild(s),t;}},{key:"removeAttachment",value:function removeAttachment(e,t){var n,o;(n=this._onInput)==null||n.call(this,!!(t!=null&&t.isTrusted));var s=this._attachments.findIndex(function(a){return a===e;}),i=this._attachments[s].attachmentContainerElement;this._attachments.splice(s,1),us.stopAttachmentPlayback(i),i.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{file:e.file,type:e.fileType};});}},{key:"hideAttachments",value:function hideAttachments(){var _this86=this;this._hiddenAttachments.clear(),this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t.click();}),_this86._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.click();});}),this._hiddenAttachments.clear();}},{key:"readdAttachments",value:function readdAttachments(){var _this87=this;var e;Array.from(this._hiddenAttachments).forEach(function(t){_this87._fileAttachmentsContainerRef.appendChild(t.attachmentContainerElement),_this87._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 s=t.split(",");for(var i=0;i<s.length;i++){var n=s[i].trim();if(e.type===n)return!0;if(n.startsWith(".")){var o=n.slice(1);if(e.name.endsWith(o))return!0;}else{if(e.name.endsWith(n))return!0;if(n.endsWith("/*")&&e.type.startsWith(n.slice(0,-2)))return!0;}}return!1;}},{key:"getTypeFromBlob",value:function getTypeFromBlob(e){var t=e.type;return t.startsWith("image")?"image":t.startsWith("audio")?"audio":"any";}},{key:"createImageAttachment",value:function createImageAttachment(e){var t=new Image();return t.src=e,t.classList.add("image-attachment"),t;}},{key:"createAnyFileAttachment",value:function createAnyFileAttachment(e){var t=document.createElement("div");t.classList.add("border-bound-attachment"),He.IS_SAFARI&&t.classList.add("border-bound-attachment-safari");var s=document.createElement("div");s.classList.add("any-file-attachment-text");var i=document.createElement("div");return i.classList.add("file-attachment-text-container"),i.appendChild(s),s.textContent=e,t.appendChild(i),t;}},{key:"createContainer",value:function createContainer(e){var t=document.createElement("div");return t.classList.add("file-attachment"),t.appendChild(e),t;}}]);}();var Be=/*#__PURE__*/function(_Ue){// prettier-ignore
|
282
|
+
function Be(e,t,s,i,n){_classCallCheck(this,Be);return _callSuper(this,Be,[e,t,s,i,n]);}_inherits(Be,_Ue);return _createClass(Be,[{key:"createTimer",value:function createTimer(e,t){var _this88=this;var s=0;var i=t!==void 0&&t<Be.TIMER_LIMIT_S?t:Be.TIMER_LIMIT_S;return setInterval(function(){var a;s+=1,s===i&&((a=_this88.stopPlaceholderCallback)==null||a.call(_this88),_this88.clearTimer()),s===600&&e.classList.add("audio-placeholder-text-4-digits");var n=Math.floor(s/60),o=(s%60).toString().padStart(2,"0");e.textContent="".concat(n,":").concat(o);},1e3);}},{key:"createPlaceholderAudioAttachment",value:function createPlaceholderAudioAttachment(e){var t=Be.createAudioContainer(),s=document.createElement("div");s.classList.add("audio-placeholder-text-3-digits");var i=document.createElement("div");i.classList.add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),i.appendChild(s);var n=Ve.createSVGElement(Si);return n.classList.add("attachment-icon","stop-icon","not-removable-attachment-icon"),s.textContent="0:00",this._activePlaceholderTimer=this.createTimer(s,e),t.appendChild(i),this.addPlaceholderAudioAttachmentEvents(t,n,i),t;}},{key:"addPlaceholderAudioAttachmentEvents",value:function addPlaceholderAudioAttachmentEvents(e,t,s){var _this89=this;var i=function i(){return e.replaceChildren(t);};e.addEventListener("mouseenter",i);var n=function n(){return e.replaceChildren(s);};e.addEventListener("mouseleave",n);var o=function o(){var a;return(a=_this89.stopPlaceholderCallback)==null?void 0:a.call(_this89);};e.addEventListener("click",o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var s=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),"audio",s,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
|
283
|
+
},{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var s=this._activePlaceholderAttachment;s&&(s.file=e,Be.addAudioElements(s.attachmentContainerElement.children[0],t),s.removeButton=this.createRemoveAttachmentButton(s),s.attachmentContainerElement.appendChild(s.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=document.createElement("div");return e.classList.add("border-bound-attachment","audio-attachment-icon-container"),He.IS_SAFARI&&e.classList.add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var s=e.parentElement?J.cloneElement(e):e,i=document.createElement("audio");i.src=t;var n=Ve.createSVGElement(Xn);n.classList.add("attachment-icon","play-icon");var o=Ve.createSVGElement(Si);o.classList.add("attachment-icon","stop-icon"),s.replaceChildren(n),i.onplay=function(){s.replaceChildren(o);},i.onpause=function(){s.replaceChildren(n),i.currentTime=0;},i.onended=function(){s.replaceChildren(n);},s.onclick=function(){i.paused?i.play():i.pause();};}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=Be.createAudioContainer();return Be.addAudioElements(t,e),t;}},{key:"stopAttachmentPlayback",value:function stopAttachmentPlayback(e){var t,s,i;(i=(s=(t=e.children[0])==null?void 0:t.children)==null?void 0:s[0])!=null&&i.classList.contains("stop-icon")&&e.children[0].click();}}]);}(Ue);Be.TIMER_LIMIT_S=5999;var us=Be;var Ya=/*#__PURE__*/function(){function Ya(){_classCallCheck(this,Ya);}return _createClass(Ya,null,[{key:"create",value:// prettier-ignore
|
284
|
+
function create(e,t,s,i,n,o){return o==="audio"?new us(e,t,s,i,n):new Ue(e,t,s,i,n);}}]);}();var ms=/*#__PURE__*/function(){function ms(e,t,s){_classCallCheck(this,ms);this._fileAttachmentsTypes=[],this.elementRef=this.createAttachmentContainer();var i=_typeof(s)=="object"&&!!s.displayFileAttachmentContainer;this.toggleContainerDisplay(i),e.appendChild(this.elementRef),t&&Object.assign(this.elementRef.style,t);}// prettier-ignore
|
285
|
+
return _createClass(ms,[{key:"addType",value:function addType(e,t,s,i){var n=Ya.create(e,t,s,this.toggleContainerDisplay.bind(this),this.elementRef,i);return this._fileAttachmentsTypes.push(n),n;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=document.createElement("div");return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef.style.display="block":this.elementRef.children.length===0&&(this.elementRef.style.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 _callee144(){return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:_context144.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref45=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e){var t;return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:return _context143.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee143);}));return function(_x263){return _ref45.apply(this,arguments);};}()));case 1:return _context144.a(2);}},_callee144,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(s){var i=new FileReader();i.readAsDataURL(s),i.onload=function(n){for(var o=0;o<t.length&&!t[o].attemptAddFile(s,n.target.result);o+=1);};});}}]);}();var Ee=/*#__PURE__*/function(){function Ee(e,t,s){_classCallCheck(this,Ee);this._isOpen=!1,this._contentRef=Ee.createModalContent(t,s==null?void 0:s.backgroundColor),this._buttonPanel=Ee.createButtonPanel(s==null?void 0:s.backgroundColor),this._elementRef=Ee.createContainer(this._contentRef,s),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=Ee.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(Ee,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this90=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){F.addAttributes(t),_this90._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this91=this;this._elementRef.classList.remove("show-modal"),this._elementRef.classList.add("hide-modal"),this._backgroundPanelRef.classList.remove("show-modal-background"),this._backgroundPanelRef.classList.add("hide-modal-background"),this._isOpen=!1,setTimeout(function(){_this91._elementRef.style.display="none",_this91._backgroundPanelRef.style.display="none";},Ee.MODAL_CLOSE_TIMEOUT_MS);}},{key:"displayModalElements",value:function displayModalElements(){this._elementRef.style.display="flex",this._elementRef.classList.remove("hide-modal"),this._elementRef.classList.add("show-modal"),this._backgroundPanelRef.style.display="block",this._backgroundPanelRef.classList.remove("hide-modal-background"),this._backgroundPanelRef.classList.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,s){var _this92=this;var i=t?Ee.createSVGButton(e):Ee.createTextButton(e);return this.addButtons(i),i.onclick=function(){_this92.close(),setTimeout(function(){s==null||s();},140);},i;}},{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 s,i;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===V.ESCAPE?(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)):t.key===V.ENTER&&(this.close(),(i=this.extensionCloseCallback)==null||i.call(this)));}}],[{key:"createContainer",value:function createContainer(e,t){var s=document.createElement("div");return s.classList.add("modal"),s.appendChild(e),t&&delete t.backgroundColor,Object.assign(s.style,t),s;}},{key:"createModalContent",value:function createModalContent(e,t){var _s$classList;var s=document.createElement("div");return(_s$classList=s.classList).add.apply(_s$classList,_toConsumableArray(e)),t&&(s.style.backgroundColor=t),document.createElement("div").appendChild(s),s;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=document.createElement("div");return t.classList.add("modal-button-panel"),e&&(t.style.backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=document.createElement("div");return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=document.createElement("div");return t.classList.add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=document.createElement("div");t.classList.add("modal-button","modal-svg-button");var s=Ve.createSVGElement(e);return s.classList.add("modal-svg-button-icon"),t.appendChild(s),t;}},{key:"createTextModalFunc",value:function createTextModalFunc(e,t,s){var i;if(_typeof(t)=="object"&&(i=t.files)!=null&&i.infoModal){var n=new Ee(e,["modal-content"],t.files.infoModal.containerStyle);return n.addCloseButton("OK",!1,s),n.openTextModal.bind(n,t.infoModalTextMarkUp||"");}}}]);}();Ee.MODAL_CLOSE_TIMEOUT_MS=190;var at=Ee;var Js=/*#__PURE__*/function(_mt5){// prettier-ignore
|
286
|
+
function Js(e,t,s,i,n,o){var _this93;_classCallCheck(this,Js);var u,h,p,m,f,g,y,T,L,O;var a=(u=s==null?void 0:s.button)==null?void 0:u.position,l=((m=(p=(h=s==null?void 0:s.button)==null?void 0:h.styles)==null?void 0:p.text)==null?void 0:m.content)||o,c=Se.tryCreateConfig("Upload File",(f=s==null?void 0:s.button)==null?void 0:f.tooltip);_this93=_callSuper(this,Js,[Js.createButtonElement(),n,a,c,s.button,l]);var d=_this93.createInnerElementsForStates(i,_this93.customStyles);_this93._inputElement=Js.createInputElement((g=s==null?void 0:s.files)==null?void 0:g.acceptedFormats),_this93.addClickEvent(e,s),_this93.changeElementsByState(d.styles),_this93.reapplyStateStyle("styles"),_this93._fileAttachmentsType=t,_this93._openModalOnce=((T=(y=s.files)==null?void 0:y.infoModal)==null?void 0:T.openModalOnce)===!1||(O=(L=s.files)==null?void 0:L.infoModal)==null?void 0:O.openModalOnce;return _this93;}_inherits(Js,_mt5);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.click();}},{key:"import",value:function _import(e){ms.addFilesToType(Array.from(e.files||[]),[this._fileAttachmentsType]),e.value="";}},{key:"addClickEvent",value:function addClickEvent(e,t){var s=this.triggerImportPrompt.bind(this,this._inputElement),i=at.createTextModalFunc(e,t,s);this.elementRef.onclick=this.click.bind(this,i);}},{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=document.createElement("input");return t.type="file",t.accept=e||"",t.hidden=!0,t.multiple=!0,t;}},{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}}]);}(mt);var Fe=/*#__PURE__*/function(){function Fe(){_classCallCheck(this,Fe);}return _createClass(Fe,null,[{key:"create",value:function create(e,t,s){var i=Fe.createElement(s);Fe.addEvents(i,e,t),e.appendChild(i);}},{key:"createElement",value:function createElement(e){var t=document.createElement("div");return t.id="drag-and-drop",_typeof(e)=="object"&&Object.assign(t.style,e),t;}},{key:"addEvents",value:function addEvents(e,t,s){t.ondragenter=function(i){i.preventDefault(),Fe.display(e);},e.ondragleave=function(i){i.preventDefault(),Fe.hide(e);},e.ondragover=function(i){i.preventDefault();},e.ondrop=function(i){i.preventDefault(),Fe.uploadFile(s,i),Fe.hide(e);};}},{key:"uploadFile",value:function uploadFile(e,t){var i;var s=(i=t.dataTransfer)==null?void 0:i.files;s&&e.addFilesToAnyType(Array.from(s));}},{key:"display",value:function display(e){e.style.display="block";}},{key:"hide",value:function hide(e){e.style.display="none";}},{key:"isEnabled",value:function isEnabled(e,t){return t!==void 0&&t===!1?!1:!!t||e.getNumberOfTypes()>0;}}]);}();var Ye=/*#__PURE__*/function(){function Ye(){_classCallCheck(this,Ye);}return _createClass(Ye,null,[{key:"validate",value:// prettier-ignore
|
284
287
|
function validate(e,t,s,i,n){var o=e(s,i,n);return o?t.changeToSubmitIcon():t.changeToDisabledIcon(),o;}// prettier-ignore
|
285
|
-
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/
|
286
|
-
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/
|
287
|
-
},{key:"attach",value:function attach(e,t,s,i,n){var o=e.validateInput||
|
288
|
-
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){
|
289
|
-
function B(e,t,s,i,n,o){var
|
290
|
-
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,s,i,n,o,a,l,c,d;if(!((s=(t=this.customStyles)==null?void 0:t.submit)!=null&&s.svg||(o=(n=(i=this.customStyles)==null?void 0:i.loading)==null?void 0:n.svg)!=null&&o.content||(c=(l=(a=this.customStyles)==null?void 0:a.loading)==null?void 0:l.text)!=null&&c.content)&&(e.displayLoadingBubble===void 0||e.displayLoadingBubble===!0)){var u=document.createElement("style");u.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(u),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),abortStream:this._abortStream,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__*/
|
291
|
-
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/
|
292
|
-
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var
|
293
|
-
},{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef.classList.contains(B.DISABLED_CLASS)||(this.elementRef.classList.remove(B.LOADING_CLASS,B.SUBMIT_CLASS),F.removeAriaBusy(this.elementRef),this.elementRef.classList.add(B.DISABLED_CLASS),F.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements.disabled),this.reapplyStateStyle("disabled",["submit"]),this.elementRef.onclick=function(){});}},{key:"disableSubmitButton",value:function disableSubmitButton(e,t){var s;e.isSubmitProgrammaticallyDisabled=t!==!1,!(this.status.requestInProgress||this.status.loadingActive)&&(t===!1?(s=this._validationHandler)==null||s.call(this):this.changeToDisabledIcon(!0));}}],[{key:"createButtonContainerElement",value:function createButtonContainerElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=document.createElement("div");return e.classList.add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=document.createElement("div");return e.id="stop-icon",e;}}]);}(
|
294
|
-
function
|
295
|
-
},{key:"addButtonEvents",value:function addButtonEvents(e,t,s,i){var
|
296
|
-
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,s,i){var n=new
|
297
|
-
function addClickEvent(e,t,s,i){var n=
|
298
|
-
function createFileUploadComponents(e,t,s,i){var o,a,l,c;var n=new ms(this.elementRef,e.attachmentContainerStyle,t.demo);if(
|
299
|
-
}],[{key:"createPanelElement",value:function createPanelElement(e){var t=document.createElement("div");return t.id="input",Object.assign(t.style,e),t;}},{key:"createUploadButtons",value:function createUploadButtons(e,t,s,i,n,o){Object.keys(s).forEach(function(a){var l=a,c=s[l];if(c.files){var d=i.addType(e,t,c.files,l),
|
300
|
-
},{key:"addElements",value:function addElements(e,t,s,i,n,o){X.addElements(e,t.elementRef);var a=wt.create(),l=Z.addButtons(a,s,i,o);Oi.set(t.inputElementRef,a,n.elementRef,l),wt.add(e,a);}},{key:"assignOnInput",value:function assignOnInput(e,t,s,i){t.onInput=function(n){setTimeout(function(){var o=s.getAllFileData(),l={text:i.inputElementRef.innerText.trim()};o&&(l.files=o.map(function(c){return c.file;})),as.onInput(e,l,n);});};}}]);}();var $i=/*#__PURE__*/function(){function $i(){_classCallCheck(this,$i);}return _createClass($i,null,[{key:"createElements",value:function createElements(e,t,s){var i=document.createElement("div");i.id="chat-view";var n=new ue(e,t,s);t.websocket&&$.createConnection(t,n);var o=new gt(e,n,t,i);return X.addElements(i,n.elementRef,o.elementRef),i;}},{key:"render",value:function render(e,t,s,i){var n=$i.createElements(e,s,i);t.replaceChildren(n),s.isCustomView()&&s.setUpView(n,t);}}]);}();var al="#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-left: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);left:50%;transform:translate(-50%,-50%);font-size:17px}#deep-chat-openai-realtime-loading{position:absolute;font-size:15px;top:50%;left:50%;transform:translate(-50%,-50%)}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;top:44%;left:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-right: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:right;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;right:-1.7em;top:-1.43em}#visible-icon{top:-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-left:8px;padding-right: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}#internal-intro-panel{width:250px;height:min-content;display:block;border-radius:5px;overflow:auto;border:1px solid rgb(203,203,203);padding:10px;max-height:calc(100% - 6.8em)}#internal-intro-panel>p{margin-block-start:.8em;margin-block-end:.8em}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{overflow:auto}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-left:auto;margin-right: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-right:0;margin-left:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-left:0;margin-right:auto}.deep-chat-last-group-messages-active{height:100%}.loading-history-message-full-view{position:absolute;height:70%;width:100%;display:flex;align-items:center}.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:14px auto 10px;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%}.deep-chat-loading-message-dots-container{width:1em;padding:.6em .75em .6em 1.3em}.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{left:-.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{left:.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,.stream-wrapper>p:first-child{margin-top:0}.message-bubble>p:last-child,.message-bubble>.partial-render-message:last-child>p,.stream-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-left{float:left}.audio-player-safari-right{float:right}.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-left:6px;margin-right: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-right:7px}.message-bubble>a{color:inherit}.left-item-position{margin-right:10px}.right-item-position{margin-left: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:left;background-color:#d7d7d73b;padding-left:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-right:.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{left:0;right: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-left:.26rem}.audio-placeholder-text-4-digits{padding-left:.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-left:.13em;margin-left:auto;margin-right:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;right:-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-left:1px solid rgb(217,217,217);border-right:1px solid rgb(217,217,217);border-top-left-radius:inherit;border-top-right-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-left:1em;margin-right:1em}.modal-content>ul{margin-right: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-bottom-left-radius:inherit;border-bottom-right-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;top:0;bottom:0;cursor:pointer;-webkit-user-select:none;user-select:none;margin:auto .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-right{position:absolute;right:calc(10% + .35em);bottom:.85em}.inside-left{position:absolute;left:calc(10% + .35em);bottom:.85em}.outside-left{position:absolute;right:calc(11px - .55em);bottom:.88em}.outside-right{position:absolute;left:calc(11px - .55em);bottom:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;left:.11em;bottom:.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;left:.07em;bottom:.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;left:.17em;bottom:.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;left:.23em;bottom:.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;left:.25em;bottom:.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;left:.25em;bottom:.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;left:.35em;bottom:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-right:.3em;margin-left:.3em}.loading-submit-button{position:relative;left: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;bottom:-.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 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-left: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-left:4px;margin-right: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;left:.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-left-adjustment{margin-left:1.5em}.text-input-container-right-adjustment{margin-right:1.5em}.text-input-container-left-small-adjustment{margin-left:1.1em}.text-input-container-left-small-adjustment>.outside-left{right:calc(14px - .55em)}.text-input-container-right-small-adjustment{margin-right:1.1em}.text-input-container-right-small-adjustment>.outside-right{left:calc(14px - .55em)}#text-input{text-align:left;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-left-adjustment{padding-left:2.2em}.text-input-inner-right-adjustment{padding-right: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-right>#dropup-menu,.inside-right>#dropup-menu{right:0}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;left:.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:.28em .84em .28em .35em;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-top-left-radius:inherit;border-top-right-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-bottom-left-radius:inherit;border-bottom-right-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;left:.28em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%)}.dropup-menu-item-text{margin-left:.56em;margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-left:auto;margin-right:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;display:grid;grid-template-columns:100%}::-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-left:1px}:host{all:initial;display:table-cell}#container{height:inherit;width:inherit;overflow:hidden}";var ll=Object.defineProperty,A=function A(r,e,t,s){for(var i=void 0,n=r.length-1,o;n>=0;n--)(o=r[n])&&(i=o(e,t,i)||i);return i&&ll(e,t,i),i;};var x=/*#__PURE__*/function(_vi){function x(){var _this108;_classCallCheck(this,x);var e;_this108=_callSuper(this,x),_this108.getMessages=function(){return[];},_this108.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.");},_this108.addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.");},_this108.updateMessage=function(){},_this108.clearMessages=function(){},_this108.focusInput=function(){return ps.focusFromParentElement(_this108._elementRef);},_this108.refreshMessages=function(){},_this108.scrollToBottom=function(){},_this108.disableSubmitButton=function(){},_this108.setPlaceholderText=function(){},_this108._hasBeenRendered=!1,_this108._auxiliaryStyleApplied=!1,_this108._elementRef=document.createElement("div"),_this108._elementRef.id="container",_this108.attachShadow({mode:"open"}).appendChild(_this108._elementRef),(e=_this108.shadowRoot)==null||e.appendChild(Se.buildElement()),Jt.apply(al,_this108.shadowRoot),setTimeout(function(){_this108._hasBeenRendered||_this108.onRender();},20);return _this108;}_inherits(x,_vi);return _createClass(x,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
301
|
-
},{key:"onRender",value:function onRender(){var _this$_childElement;Ss.attemptAppendStyleSheetToHead(this.style),
|
288
|
+
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t,s,i){var n,o,a;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:n=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context145.n=1;return s.completePlaceholders();case 1:o=s.getAllFileData(),a=o==null?void 0:o.map(function(l){return l.file;});return _context145.a(2,Ye.validate(e,i,n,a));}},_callee145);}));function useValidationFunc(_x264,_x265,_x266,_x267){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
|
289
|
+
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t,s){var n,i;return _regenerator().w(function(_context146){while(1)switch(_context146.n){case 0:i=(n=t.files)==null?void 0:n.map(function(o){return o.file;});return _context146.a(2,Ye.validate(e,s,t.text,i,!0));}},_callee146);}));function useValidationFuncProgrammatic(_x268,_x269,_x270){return _useValidationFuncProgrammatic.apply(this,arguments);}return useValidationFuncProgrammatic;}()},{key:"validateWebsocket",value:function validateWebsocket(e,t){var s=e.websocket,i=e.connectSettings;return s&&i.url!==xe.URL&&!W.canSendMessage(s)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
|
290
|
+
},{key:"attach",value:function attach(e,t,s,i,n){var o=e.validateInput||X.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref46=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(a){var l;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(!(n.status.loadingActive||n.status.requestInProgress||t.isSubmitProgrammaticallyDisabled===!0||!Ye.validateWebsocket(t,n))){_context147.n=1;break;}return _context147.a(2,!1);case 1:l=o||t.canSendMessage;return _context147.a(2,l?a?Ye.useValidationFuncProgrammatic(l,a,n):Ye.useValidationFunc(l,s,i,n):null);}},_callee147);}));return function(_x271){return _ref46.apply(this,arguments);};}();}}]);}();var sr=/*#__PURE__*/function(){function sr(){_classCallCheck(this,sr);}return _createClass(sr,null,[{key:"getFileName",value:function getFileName(e,t){var s=/* @__PURE__ */new Date(),i=String(s.getHours()).padStart(2,"0"),n=String(s.getMinutes()).padStart(2,"0"),o=String(s.getSeconds()).padStart(2,"0");return"".concat(e,"-").concat(i,"-").concat(n,"-").concat(o,".").concat(t);}}]);}();var Za=/*#__PURE__*/function(_ni2){function Za(e,t){var _this94;_classCallCheck(this,Za);var s,i;_this94=_callSuper(this,Za,[t.button]),_this94._waitingForBrowserApproval=!1,_this94._audioType=e,_this94._extension=((s=t.files)==null?void 0:s.format)||"mp3",_this94._maxDurationSeconds=(i=t.files)==null?void 0:i.maxDurationSeconds,_this94.elementRef.onclick=_this94.buttonClick.bind(_assertThisInitialized(_this94));return _this94;}_inherits(Za,_ni2);return _createClass(Za,[{key:"buttonClick",value:function buttonClick(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()));}},{key:"stop",value:function stop(){var _this95=this;return new Promise(function(e){var t,s;_this95.changeToDefault(),(t=_this95._mediaRecorder)==null||t.stop(),(s=_this95._mediaStream)==null||s.getTracks().forEach(function(i){return i.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this96=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this96.changeToActive(),_this96._mediaRecorder=new MediaRecorder(e),_this96._audioType.addPlaceholderAttachment(_this96.stop.bind(_this96),_this96._maxDurationSeconds),_this96._mediaStream=e,_this96._mediaRecorder.addEventListener("dataavailable",function(t){_this96.createFile(t);}),_this96._mediaRecorder.start();})["catch"](function(e){console.error(e),_this96.stop();})["finally"](function(){_this96._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this97=this;var t=new Blob([e.data],{type:"audio/".concat(this._extension)}),s=sr.getFileName(this._newFilePrefix||"audio",this._extension),i=new File([t],s,{type:t.type}),n=new FileReader();n.readAsDataURL(i),n.onload=function(o){_this97._audioType.completePlaceholderAttachment(i,o.target.result);};}}]);}(ni);var Qa="<?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 lt=/*#__PURE__*/function(){function lt(){_classCallCheck(this,lt);}return _createClass(lt,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 s=JSON.parse(JSON.stringify(e[t]||{}));$.overwritePropertyObjectFromAnother(s,e.submit,["container","default"]),$.overwritePropertyObjectFromAnother(s,e.submit,["text","styles","default"]),$.overwritePropertyObjectFromAnother(s,e.submit,["svg","styles","default"]),e[t]=s;}// prettier-ignore
|
291
|
+
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){$.setPropertyValueIfDoesNotExist(e,["submit","container","default","backgroundColor"],""),$.setPropertyValueIfDoesNotExist(e,["disabled","container","default","backgroundColor"],"unset"),$.setPropertyValueIfDoesNotExist(e.submit,["svg","styles","default","filter"],""),$.setPropertyValueIfDoesNotExist(e.disabled,["svg","styles","default","filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),$.setPropertyValueIfDoesNotExist(e.disabled,["text","styles","default","color"],"grey"),lt.overwriteDefaultStyleWithSubmit(e,"disabled");}},{key:"process",value:function process(e){var t=JSON.parse(JSON.stringify(e||{}));return lt.overwriteDefaultStyleWithSubmit(t,"loading"),lt.overwriteDefaultStyleWithSubmit(t,"stop"),e!=null&&e.alwaysEnabled||lt.setUpDisabledButton(t),t;}}]);}();var B=/*#__PURE__*/function(_mt6){// prettier-ignore
|
292
|
+
function B(e,t,s,i,n,o){var _this98;_classCallCheck(this,B);var a=lt.process(e.submitButtonStyles),l=Qa,c=Se.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this98=_callSuper(this,B,[B.createButtonContainerElement(),l,a==null?void 0:a.position,c,a]),_this98._isSVGLoadingIconOverriden=!1,_this98.status={requestInProgress:!1,loadingActive:!1},_this98._messages=s,_this98._textInput=t,_this98._fileAttachments=n,_this98._innerElements=_this98.createInnerElementsForStates(),_this98._abortStream=new AbortController(),_this98._stopClicked={listener:function listener(){}},_this98._serviceIO=i,_this98._alwaysEnabled=!!(a!=null&&a.alwaysEnabled),e.disableSubmitButton=_this98.disableSubmitButton.bind(_assertThisInitialized(_this98),i),_this98.attemptOverwriteLoadingStyle(e),o.microphone&&_this98.setUpSpeechToText(o.microphone.button,e.speechToText),setTimeout(function(){var d;_this98._validationHandler=e._validationHandler,_this98.assignHandlers(_this98._validationHandler),(d=_this98._validationHandler)==null||d.call(_assertThisInitialized(_this98));});return _this98;}_inherits(B,_mt6);return _createClass(B,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(){var _this$createCustomEle=this.createCustomElements(),e=_this$createCustomEle.submit,t=_this$createCustomEle.loading,s=_this$createCustomEle.stop;return{submit:e,loading:t||[B.createLoadingIconElement()],stop:s||[B.createStopIconElement()],disabled:this.createDisabledIconElement(e)};}},{key:"createCustomElements",value:function createCustomElements(){var _this99=this;var e=ke.createCustomElements("submit",this.svg,this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(s){var i=s,n=ke.createCustomElements(i,_this99.svg,_this99.customStyles);n&&(t[i]=n);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return ke.createCustomElements("disabled",this.svg,this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
|
293
|
+
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,s,i,n,o,a,l,c,d;if(!((s=(t=this.customStyles)==null?void 0:t.submit)!=null&&s.svg||(o=(n=(i=this.customStyles)==null?void 0:i.loading)==null?void 0:n.svg)!=null&&o.content||(c=(l=(a=this.customStyles)==null?void 0:a.loading)==null?void 0:l.text)!=null&&c.content)&&(e.displayLoadingBubble===void 0||e.displayLoadingBubble===!0)){var u=document.createElement("style");u.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(u),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),abortStream:this._abortStream,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 _callee148(){var e,t;return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:_context148.n=1;return this._fileAttachments.completePlaceholders();case 1:e=this._fileAttachments.getAllFileData();if(this._textInput.isTextInputEmpty())this.attemptSubmit({text:"",files:e});else{t=this._textInput.inputElementRef.innerText.trim();this.attemptSubmit({text:t,files:e});}case 2:return _context148.a(2);}},_callee148,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e){var _this100=this;var t;return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:typeof e=="string"&&(e=X.processSubmitUserMessage(e));t={text:e.text};e.files&&(t.files=Array.from(e.files).map(function(s){return{file:s,type:Ue.getTypeFromBlob(s)};})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this100.attemptSubmit(t,!0);});case 1:return _context149.a(2);}},_callee149);}));function programmaticSubmit(_x272){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
|
294
|
+
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e){var t,n,o,a,l,s,i,_args150=arguments,_t50,_t51,_t52;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:t=_args150.length>1&&_args150[1]!==undefined?_args150[1]:!1;_context150.n=1;return(n=this._validationHandler)==null?void 0:n.call(this,t?e:void 0);case 1:_t50=_context150.v;_t51=!1;if(!(_t50===_t51)){_context150.n=2;break;}return _context150.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();_t52=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t52){_context150.n=3;break;}_context150.n=3;return ws.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context150.n=4;return this.addNewMessage(e);case 4:this._serviceIO.isWebModel()||this._messages.addLoadingMessage();s=(a=e.files)==null?void 0:a.map(function(c){return c.file;}),i={text:e.text===""?void 0:e.text,files:s};_context150.n=5;return this._serviceIO.callAPI(i,this._messages);case 5:(l=this._fileAttachments)==null||l.hideFiles();case 6:return _context150.a(2);}},_callee150,this);}));function attemptSubmit(_x273){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(_ref47){var e,t,s,i,_t53;return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:e=_ref47.text,t=_ref47.files,s=_ref47.custom;i={role:b.USER_ROLE,custom:s};e&&(i.text=e);_t53=t;if(!_t53){_context151.n=2;break;}_context151.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:i.files=_context151.v;case 2:this._serviceIO.sessionId&&(i._sessionId=this._serviceIO.sessionId);Object.keys(i).length>0&&this._messages.addNewMessage(i);case 3:return _context151.a(2);}},_callee151,this);}));function addNewMessage(_x274){return _addNewMessage.apply(this,arguments);}return addNewMessage;}()},{key:"stopStream",value:function stopStream(){var e;this._abortStream.abort(),(e=this._stopClicked)==null||e.listener(),this._validationHandler&&this.resetSubmit(this._validationHandler);}},{key:"changeToStopIcon",value:function changeToStopIcon(){this._serviceIO.websocket||(this.elementRef.classList.remove(B.LOADING_CLASS,B.DISABLED_CLASS,B.SUBMIT_CLASS),F.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.classList.remove(B.SUBMIT_CLASS,B.DISABLED_CLASS),F.removeAriaDisabled(this.elementRef),this.elementRef.classList.add(B.LOADING_CLASS),F.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
|
295
|
+
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this101=this;this.elementRef.classList.contains(B.SUBMIT_CLASS)||(this.elementRef.classList.remove(B.LOADING_CLASS,B.DISABLED_CLASS),F.removeAriaAttributes(this.elementRef),this.elementRef.classList.add(B.SUBMIT_CLASS),this.changeElementsByState(this._innerElements.submit),lt.resetSubmit(this,this.status.loadingActive),this.elementRef.onclick=function(){var e;_this101.submitFromInput(),(e=_this101._microphoneButton)!=null&&e.isActive&&hs.toggleSpeechAfterSubmit(_this101._microphoneButton.elementRef,!!_this101._stopSTTAfterSubmit);});}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
|
296
|
+
},{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef.classList.contains(B.DISABLED_CLASS)||(this.elementRef.classList.remove(B.LOADING_CLASS,B.SUBMIT_CLASS),F.removeAriaBusy(this.elementRef),this.elementRef.classList.add(B.DISABLED_CLASS),F.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements.disabled),this.reapplyStateStyle("disabled",["submit"]),this.elementRef.onclick=function(){});}},{key:"disableSubmitButton",value:function disableSubmitButton(e,t){var s;e.isSubmitProgrammaticallyDisabled=t!==!1,!(this.status.requestInProgress||this.status.loadingActive)&&(t===!1?(s=this._validationHandler)==null||s.call(this):this.changeToDisabledIcon(!0));}}],[{key:"createButtonContainerElement",value:function createButtonContainerElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=document.createElement("div");return e.classList.add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=document.createElement("div");return e.id="stop-icon",e;}}]);}(mt);B.SUBMIT_CLASS="submit-button",B.LOADING_CLASS="loading-button",B.DISABLED_CLASS="disabled-button";var Oi=B;var el="<?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",tl="<?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",sl="<?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>",il="<?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 Gi=/*#__PURE__*/function(_at){// prettier-ignore
|
297
|
+
function Gi(e,t,s,i){var _this102;_classCallCheck(this,Gi);_this102=_callSuper(this,Gi,[e,["modal-content","modal-camera-content"],s]),_this102._stopped=!1,_this102._format="image/png",_this102._canvas=document.createElement("canvas"),_this102._canvas.classList.add("camera-modal-canvas");var _this102$addButtonsAn=_this102.addButtonsAndTheirEvents(t),n=_this102$addButtonsAn.captureButton,o=_this102$addButtonsAn.submitButton;_this102._captureButton=n,_this102._submitButton=o,_this102._captureIcon=_this102._captureButton.children[0],_this102._refreshIcon=Ve.createSVGElement(el),_this102._refreshIcon.classList.add("modal-svg-button-icon","modal-svg-refresh-icon"),(i==null?void 0:i.format)==="jpeg"&&(_this102._format="image/jpeg"),i!=null&&i.dimensions&&(_this102._dimensions=i.dimensions),_this102._contentRef.appendChild(_this102._canvas),_this102.extensionCloseCallback=_this102.stop;return _this102;}_inherits(Gi,_at);return _createClass(Gi,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=at.createSVGButton(tl);t.classList.add("modal-svg-camera-button"),t.children[0].classList.add("modal-svg-camera-icon");var s=this.addCloseButton(sl,!0);s.classList.add("modal-svg-close-button"),s.children[0].classList.add("modal-svg-close-icon");var i=at.createSVGButton(il);return i.classList.add("modal-svg-submit-button"),this.addButtons(t,i),this.addButtonEvents(t,s,i,e),{captureButton:t,submitButton:i};}// prettier-ignore
|
298
|
+
},{key:"addButtonEvents",value:function addButtonEvents(e,t,s,i){var _this103=this;e.onclick=function(){_this103.capture();},t.addEventListener("click",this.stop.bind(this)),s.onclick=function(){var n=_this103.getFile();n&&ms.addFilesToType([n],[i]),_this103.stop(),_this103.close();};}},{key:"stop",value:function stop(){var _this104=this;this._mediaStream&&this._mediaStream.getTracks().forEach(function(e){return e.stop();}),this._stopped=!0,setTimeout(function(){_this104._captureButton.replaceChildren(_this104._captureIcon),_this104._captureButton.classList.replace("modal-svg-refresh-button","modal-svg-camera-button");var e=_this104._canvas.getContext("2d");e==null||e.clearRect(0,0,_this104._canvas.width,_this104._canvas.height);},at.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this105=this;this._dataURL=void 0,this._submitButton.classList.add("modal-svg-submit-disabled"),this._stopped=!1,navigator.mediaDevices.getUserMedia({video:this._dimensions||!0}).then(function(e){if(_this105._mediaStream=e,!_this105.isOpen())return _this105.stop();var t=document.createElement("video");t.srcObject=e,t.play(),requestAnimationFrame(_this105.updateCanvas.bind(_this105,t,_this105._canvas));})["catch"](function(e){console.error(e),_this105.stop(),_this105.close();});}},{key:"capture",value:function capture(){this._dataURL?(this._captureButton.replaceChildren(this._captureIcon),this._captureButton.classList.replace("modal-svg-refresh-button","modal-svg-camera-button"),this._submitButton.classList.add("modal-svg-submit-disabled"),this._dataURL=void 0):(this._captureButton.replaceChildren(this._refreshIcon),this._captureButton.classList.replace("modal-svg-camera-button","modal-svg-refresh-button"),this._submitButton.classList.remove("modal-svg-submit-disabled"),this._dataURL=this._canvas.toDataURL());}},{key:"getFile",value:function getFile(){if(this._dataURL){var e=atob(this._dataURL.split(",")[1]),t=new Array(e.length);for(var a=0;a<e.length;a++)t[a]=e.charCodeAt(a);var _s1=new Uint8Array(t),i=new Blob([_s1],{type:this._format}),n=this._format==="image/jpeg"?"jpeg":"png",o=sr.getFileName(this._newFilePrefix||"photo",n);return new File([i],o,{type:i.type});}}},{key:"updateCanvas",value:function updateCanvas(e,t){if(!this._stopped){if(!this._dataURL){t.width=e.videoWidth,t.height=e.videoHeight;var _s10=t.getContext("2d");_s10==null||_s10.drawImage(e,0,0,t.width,t.height);}requestAnimationFrame(this.updateCanvas.bind(this,e,t));}}},{key:"openCameraModal",value:function openCameraModal(e){this.displayModalElements(),e.start();}// prettier-ignore
|
299
|
+
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,s,i){var n=new Gi(e,t,s,i);return n.openCameraModal.bind(n,n);}}]);}(at);var nl="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M29 7h-4.599l-2.401-4h-12l-2.4 4h-4.6c-1 0-3 1-3 2.969v16.031c0 1.657 1.5 3 2.792 3h26.271c1.313 0 2.938-1.406 2.938-2.968v-16.032c0-1-1-3-3-3zM30 26.032c0 0.395-0.639 0.947-0.937 0.969h-26.265c-0.232-0.019-0.797-0.47-0.797-1v-16.031c0-0.634 0.851-0.953 1-0.969h5.732l2.4-4h9.802l1.785 3.030 0.55 0.97h5.731c0.705 0 0.99 0.921 1 1v16.032zM16 10c-3.866 0-7 3.134-7 7s3.134 7 7 7 7-3.134 7-7-3.134-7-7-7zM16 22c-2.757 0-5-2.243-5-5s2.243-5 5-5 5 2.243 5 5-2.243 5-5 5z\"></path>\n</svg>";var zi=/*#__PURE__*/function(_mt7){function zi(e,t,s){var _this106;_classCallCheck(this,zi);var c,d,u,h,p,m;var i=(c=s==null?void 0:s.button)==null?void 0:c.position,n=((h=(u=(d=s==null?void 0:s.button)==null?void 0:d.styles)==null?void 0:u.text)==null?void 0:h.content)||"Photo",o=Se.tryCreateConfig("Camera",(p=s==null?void 0:s.button)==null?void 0:p.tooltip),a=((m=s==null?void 0:s.button)==null?void 0:m.styles)||{};_this106=_callSuper(this,zi,[zi.createButtonElement(),nl,i,o,a,n]);var l=_this106.createInnerElementsForStates(_this106.customStyles);s&&_this106.addClickEvent(e,t,s.modalContainerStyle,s.files),_this106.changeElementsByState(l.styles),_this106.reapplyStateStyle("styles");return _this106;}_inherits(zi,_mt7);return _createClass(zi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("camera-icon","styles",e)};}},{key:"addClickEvent",value:// prettier-ignore
|
300
|
+
function addClickEvent(e,t,s,i){var n=Gi.createCameraModalFunc(e,t,s,i);this.elementRef.onclick=n;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}}]);}(mt);var yt=/*#__PURE__*/function(){function yt(e,t,s,i){_classCallCheck(this,yt);this.elementRef=yt.createPanelElement(e.inputAreaStyle);var n={},o=this.createFileUploadComponents(e,s,i,n),a=new xs(e,s,o);e.speechToText&&!n.microphone&&(n.microphone={button:new hs(e,a,t.addNewErrorMessage.bind(t))});var l=new Oi(e,a,t,s,o,n);a.submit=l.submitFromInput.bind(l),Ye.attach(e,s,a,o,l),e.submitUserMessage=l.programmaticSubmit.bind(l),n.submit={button:l},e.customButtons&&ct.add(e,n),yt.addElements(this.elementRef,a,n,i,o,e.dropupStyles),yt.assignOnInput(e,s,o,a);}return _createClass(yt,[{key:"createFileUploadComponents",value:// prettier-ignore
|
301
|
+
function createFileUploadComponents(e,t,s,i){var o,a,l,c;var n=new ms(this.elementRef,e.attachmentContainerStyle,t.demo);if(yt.createUploadButtons(e,t,t.fileTypes||{},n,s,i),(o=t.camera)!=null&&o.files){var d=((a=i.images)==null?void 0:a.fileType)||n.addType(e,t,t.camera.files,"images");i.camera={button:new zi(s,d,t.camera)};}if((l=t.recordAudio)!=null&&l.files){var _d=((c=i.audio)==null?void 0:c.fileType)||n.addType(e,t,t.recordAudio.files,"audio");i.microphone={button:new Za(_d,t.recordAudio)};}return Fe.isEnabled(n,e.dragAndDrop)&&Fe.create(s,n,e.dragAndDrop),n;}// prettier-ignore
|
302
|
+
}],[{key:"createPanelElement",value:function createPanelElement(e){var t=document.createElement("div");return t.id="input",Object.assign(t.style,e),t;}},{key:"createUploadButtons",value:function createUploadButtons(e,t,s,i,n,o){Object.keys(s).forEach(function(a){var l=a,c=s[l];if(c.files){var d=i.addType(e,t,c.files,l),_Ia$l=Ia[l],u=_Ia$l.id,h=_Ia$l.svgString,p=_Ia$l.dropupText,m=new Js(n,d,c,u,h,p);o[l]={button:m,fileType:d};}});}// prettier-ignore
|
303
|
+
},{key:"addElements",value:function addElements(e,t,s,i,n,o){J.addElements(e,t.elementRef);var a=wt.create(),l=Z.addButtons(a,s,i,o);Ii.set(t.inputElementRef,a,n.elementRef,l),wt.add(e,a);}},{key:"assignOnInput",value:function assignOnInput(e,t,s,i){t.onInput=function(n){setTimeout(function(){var o=s.getAllFileData(),l={text:i.inputElementRef.innerText.trim()};o&&(l.files=o.map(function(c){return c.file;})),as.onInput(e,l,n);});};}}]);}();var Ki=/*#__PURE__*/function(){function Ki(){_classCallCheck(this,Ki);}return _createClass(Ki,null,[{key:"createElements",value:function createElements(e,t,s){var i=document.createElement("div");i.id="chat-view";var n=new ue(e,t,s);t.websocket&&W.createConnection(t,n);var o=new yt(e,n,t,i);return J.addElements(i,n.elementRef,o.elementRef),i;}},{key:"render",value:function render(e,t,s,i){var n=Ki.createElements(e,s,i);t.replaceChildren(n),s.isCustomView()&&s.setUpView(n,t);}}]);}();var rl="#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-left: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);left:50%;transform:translate(-50%,-50%);font-size:17px}#deep-chat-openai-realtime-loading{position:absolute;font-size:15px;top:50%;left:50%;transform:translate(-50%,-50%)}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;top:44%;left:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-right: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:right;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;right:-1.7em;top:-1.43em}#visible-icon{top:-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-left:8px;padding-right: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}#internal-intro-panel{width:250px;height:min-content;display:block;border-radius:5px;overflow:auto;border:1px solid rgb(203,203,203);padding:10px;max-height:calc(100% - 6.8em)}#internal-intro-panel>p{margin-block-start:.8em;margin-block-end:.8em}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{overflow:auto}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-left:auto;margin-right: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-right:0;margin-left:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-left:0;margin-right:auto}.deep-chat-last-group-messages-active{height:100%}.loading-history-message-full-view{position:absolute;height:70%;width:100%;display:flex;align-items:center}.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:14px auto 10px;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%}.deep-chat-loading-message-dots-container{width:1em;padding:.6em .75em .6em 1.3em}.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{left:-.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{left:.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-left{float:left}.audio-player-safari-right{float:right}.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-left:6px;margin-right: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-right:7px}.message-bubble>a{color:inherit}.left-item-position{margin-right:10px}.right-item-position{margin-left: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:left;background-color:#d7d7d73b;padding-left:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-right:.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{left:0;right: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-left:.26rem}.audio-placeholder-text-4-digits{padding-left:.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-left:.13em;margin-left:auto;margin-right:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;right:-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-left:1px solid rgb(217,217,217);border-right:1px solid rgb(217,217,217);border-top-left-radius:inherit;border-top-right-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-left:1em;margin-right:1em}.modal-content>ul{margin-right: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-bottom-left-radius:inherit;border-bottom-right-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;top:0;bottom:0;cursor:pointer;-webkit-user-select:none;user-select:none;margin:auto .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-right{position:absolute;right:calc(10% + .35em);bottom:.85em}.inside-left{position:absolute;left:calc(10% + .35em);bottom:.85em}.outside-left{position:absolute;right:calc(11px - .55em);bottom:.88em}.outside-right{position:absolute;left:calc(11px - .55em);bottom:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;left:.11em;bottom:.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;left:.07em;bottom:.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;left:.17em;bottom:.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;left:.23em;bottom:.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;left:.25em;bottom:.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;left:.25em;bottom:.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;left:.35em;bottom:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-right:.3em;margin-left:.3em}.loading-submit-button{position:relative;left: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;bottom:-.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 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-left: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-left:4px;margin-right: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;left:.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-left-adjustment{margin-left:1.5em}.text-input-container-right-adjustment{margin-right:1.5em}.text-input-container-left-small-adjustment{margin-left:1.1em}.text-input-container-left-small-adjustment>.outside-left{right:calc(14px - .55em)}.text-input-container-right-small-adjustment{margin-right:1.1em}.text-input-container-right-small-adjustment>.outside-right{left:calc(14px - .55em)}#text-input{text-align:left;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-left-adjustment{padding-left:2.2em}.text-input-inner-right-adjustment{padding-right: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-right>#dropup-menu,.inside-right>#dropup-menu{right:0}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;left:.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:.28em .84em .28em .35em;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-top-left-radius:inherit;border-top-right-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-bottom-left-radius:inherit;border-bottom-right-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;left:.28em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%)}.dropup-menu-item-text{margin-left:.56em;margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-left:auto;margin-right:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;display:grid;grid-template-columns:100%}::-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-left:1px}:host{all:initial;display:table-cell}#container{height:inherit;width:inherit;overflow:hidden}";var ol=Object.defineProperty,A=function A(r,e,t,s){for(var i=void 0,n=r.length-1,o;n>=0;n--)(o=r[n])&&(i=o(e,t,i)||i);return i&&ol(e,t,i),i;};var S=/*#__PURE__*/function(_vi){function S(){var _this107;_classCallCheck(this,S);var e;_this107=_callSuper(this,S),_this107.getMessages=function(){return[];},_this107.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.");},_this107.addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.");},_this107.updateMessage=function(){},_this107.clearMessages=function(){},_this107.focusInput=function(){return ps.focusFromParentElement(_this107._elementRef);},_this107.refreshMessages=function(){},_this107.scrollToBottom=function(){},_this107.disableSubmitButton=function(){},_this107.setPlaceholderText=function(){},_this107._hasBeenRendered=!1,_this107._auxiliaryStyleApplied=!1,_this107._elementRef=document.createElement("div"),_this107._elementRef.id="container",_this107.attachShadow({mode:"open"}).appendChild(_this107._elementRef),(e=_this107.shadowRoot)==null||e.appendChild(Se.buildElement()),$t.apply(rl,_this107.shadowRoot),setTimeout(function(){_this107._hasBeenRendered||_this107.onRender();},20);return _this107;}_inherits(S,_vi);return _createClass(S,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
304
|
+
},{key:"onRender",value:function onRender(){var _this$_childElement;Ss.attemptAppendStyleSheetToHead(this.style),X.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=xa.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&($t.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),$t.applyDefaultStyleToComponent(this.style,this.chatStyle),X.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?_s.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof I)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],Ki.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof I&&Y.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||as.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){cs.chat=void 0;}}]);}(vi);A([w("object")],S.prototype,"connect");A([w("object")],S.prototype,"directConnection");A([w("object")],S.prototype,"webModel");A([w("object")],S.prototype,"requestBodyLimits");A([w("function")],S.prototype,"requestInterceptor");A([w("function")],S.prototype,"responseInterceptor");A([w("function")],S.prototype,"validateInput");A([w("function")],S.prototype,"loadHistory");A([w("object")],S.prototype,"chatStyle");A([w("object")],S.prototype,"attachmentContainerStyle");A([w("object")],S.prototype,"dropupStyles");A([w("object")],S.prototype,"inputAreaStyle");A([w("object")],S.prototype,"textInput");A([w("object")],S.prototype,"submitButtonStyles");A([w("object")],S.prototype,"customButtons");A([w("string")],S.prototype,"auxiliaryStyle");A([w("array")],S.prototype,"history");A([w("object")],S.prototype,"browserStorage");A([w("object")],S.prototype,"introMessage");A([w("object")],S.prototype,"avatars");A([w("object")],S.prototype,"names");A([w("object")],S.prototype,"displayLoadingBubble");A([w("object")],S.prototype,"errorMessages");A([w("object")],S.prototype,"messageStyles");A([w("object")],S.prototype,"textToSpeech");A([w("object")],S.prototype,"speechToText");A([w("object")],S.prototype,"images");A([w("object")],S.prototype,"gifs");A([w("object")],S.prototype,"camera");A([w("object")],S.prototype,"audio");A([w("object")],S.prototype,"microphone");A([w("object")],S.prototype,"mixedFiles");A([w("object")],S.prototype,"dragAndDrop");A([w("object")],S.prototype,"introPanelStyle");A([w("object")],S.prototype,"htmlWrappers");A([w("object")],S.prototype,"htmlClassUtilities");A([w("object")],S.prototype,"remarkable");A([w("object")],S.prototype,"focusMode");A([w("function")],S.prototype,"onMessage");A([w("function")],S.prototype,"onClearMessages");A([w("function")],S.prototype,"onComponentRender");A([w("function")],S.prototype,"onInput");A([w("function")],S.prototype,"onError");A([w("object")],S.prototype,"demo");A([w("object")],S.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",S);export{S as DeepChat};
|