deep-chat-dev 9.0.297 → 9.0.298
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 +14244 -14157
- package/dist/deepChat.bundle.js +1 -1
- package/dist/deepChat.js +115 -115
- package/dist/services/azure/azureSummarizationIO.d.ts +2 -3
- package/dist/services/azure/azureSummarizationIO.d.ts.map +1 -1
- package/dist/services/groq/groqChatIO.d.ts.map +1 -1
- package/dist/services/kimi/kimiChatIO.d.ts +9 -2
- package/dist/services/kimi/kimiChatIO.d.ts.map +1 -1
- package/dist/services/openAI/assistant/openAIAssistantIOI.d.ts +1 -3
- package/dist/services/openAI/assistant/openAIAssistantIOI.d.ts.map +1 -1
- package/dist/services/openRouter/openRouterIO.d.ts.map +1 -1
- package/dist/services/serviceIO.d.ts +1 -3
- package/dist/services/serviceIO.d.ts.map +1 -1
- package/dist/services/utils/baseServiceIO.d.ts +1 -3
- package/dist/services/utils/baseServiceIO.d.ts.map +1 -1
- package/dist/types/azureResult.d.ts +1 -1
- package/dist/types/azureResult.d.ts.map +1 -1
- package/dist/types/kimi.d.ts +10 -0
- package/dist/types/kimi.d.ts.map +1 -1
- package/dist/types/kimiInternal.d.ts +22 -2
- package/dist/types/kimiInternal.d.ts.map +1 -1
- package/dist/types/kimiResult.d.ts +8 -2
- package/dist/types/kimiResult.d.ts.map +1 -1
- package/dist/types/loading.d.ts +6 -1
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/utils/HTTP/customHandler.d.ts.map +1 -1
- package/dist/utils/HTTP/stream.d.ts +1 -1
- package/dist/utils/HTTP/stream.d.ts.map +1 -1
- package/dist/utils/loading/loadingStyle.d.ts +2 -2
- package/dist/utils/loading/loadingStyle.d.ts.map +1 -1
- package/dist/views/chat/messages/messages.d.ts +2 -1
- package/dist/views/chat/messages/messages.d.ts.map +1 -1
- package/dist/views/chat/messages/utils/messageUtils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/deepChat.js
CHANGED
@@ -1,18 +1,18 @@
|
|
1
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 ar=/*#__PURE__*/function(){function ar(){_classCallCheck(this,ar);}return _createClass(ar,null,[{key:"render",value:function render(e,t){var s=document.createElement("div");s.id="error-view",s.innerText=t,e.replaceChildren(s);}}]);}();var ws=/*#__PURE__*/function(){function ws(){_classCallCheck(this,ws);}return _createClass(ws,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=document.createElement("div");return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,s){var i=ws.createElements(),n={onSuccess:t,onFail:ar.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:ws.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 et=/*#__PURE__*/function(){function et(){_classCallCheck(this,et);}return _createClass(et,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==et.DEFAULT_FONT_FAMILY)return;var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(i){return i.getAttribute("href")===et.FONT_URL;})){var i=document.createElement("link");i.rel="stylesheet",i.href=et.FONT_URL,t.appendChild(i);}}}]);}();et.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",et.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var
|
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 et=/*#__PURE__*/function(){function et(){_classCallCheck(this,et);}return _createClass(et,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==et.DEFAULT_FONT_FAMILY)return;var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(i){return i.getAttribute("href")===et.FONT_URL;})){var i=document.createElement("link");i.rel="stylesheet",i.href=et.FONT_URL,t.appendChild(i);}}}]);}();et.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",et.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var Cs=et;var Et=/*#__PURE__*/function(){function Et(){_classCallCheck(this,Et);}return _createClass(Et,null,[{key:"apply",value:function apply(e,t){if(t)try{Et.applyStyleSheet(e,t);}catch(_unused){Et.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,Et.DEFAULT_COMPONENT_STYLE);}}]);}();Et.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:Cs.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 Yt=Et;var tt=/*#__PURE__*/function(){function tt(){_classCallCheck(this,tt);}return _createClass(tt,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(tt.OVERFLOW_NEW_POSITION_PX,"px"):c.right>i.right&&(t.style.left="".concat(i.width-c.width-tt.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,s){return s||(s=tt.traverseParentUntilContainer(e).nextSibling),t.text&&(s.children[0].textContent=t.text),{timeout:setTimeout(function(){s.style.visibility="visible",tt.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="";}}]);}();tt.OVERFLOW_NEW_POSITION_PX=4;var _e=tt;var ts=/*#__PURE__*/_createClass(function ts(){_classCallCheck(this,ts);});ts.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),ts.IS_CHROMIUM=window.chrome,ts.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var je=ts;var
|
6
|
+
overflow:"hidden"};var Yt=Et;var tt=/*#__PURE__*/function(){function tt(){_classCallCheck(this,tt);}return _createClass(tt,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(tt.OVERFLOW_NEW_POSITION_PX,"px"):c.right>i.right&&(t.style.left="".concat(i.width-c.width-tt.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,s){return s||(s=tt.traverseParentUntilContainer(e).nextSibling),t.text&&(s.children[0].textContent=t.text),{timeout:setTimeout(function(){s.style.visibility="visible",tt.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="";}}]);}();tt.OVERFLOW_NEW_POSITION_PX=4;var _e=tt;var ts=/*#__PURE__*/_createClass(function ts(){_classCallCheck(this,ts);});ts.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),ts.IS_CHROMIUM=window.chrome,ts.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var je=ts;var q=/* @__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;}(q||{});var st=/*#__PURE__*/function(){function st(){_classCallCheck(this,st);}return _createClass(st,null,[{key:"add",value:// prettier-ignore
|
7
7
|
function add(e,t,s,i){s!==void 0&&e.addEventListener("keydown",st.onKeyDown.bind(this,s)),e.oninput=st.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&&!st.PERMITTED_KEYS.has(t.key)&&!st.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),gs.focusEndOfInput(i)),t==null||t();}}]);}();st.PERMITTED_KEYS=/* @__PURE__ */new Set([
|
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="",gs.focusEndOfInput(this.inputElementRef),(s=this._onInput)==null||s.call(this,!1)),je.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(){var t,s,i,n;var e=document.createElement("div");return e.id=it.TEXT_INPUT_ID,e.classList.add("text-input-styling"),e.role="textbox",je.IS_CHROMIUM&&it.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",lr.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===
|
9
|
+
},{key:"onKeyDown",value:function onKeyDown(e,t){var i=t.target.textContent;i&&i.length>=e&&!st.PERMITTED_KEYS.has(t.key)&&!st.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),gs.focusEndOfInput(i)),t==null||t();}}]);}();st.PERMITTED_KEYS=/* @__PURE__ */new Set([q.BACKSPACE,q.DELETE,q.ARROW_RIGHT,q.ARROW_LEFT,q.ARROW_DOWN,q.ARROW_UP,q.META,q.CONTROL,q.ENTER]);var yi=st;var lr=/*#__PURE__*/function(){function lr(){_classCallCheck(this,lr);}return _createClass(lr,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 it=/*#__PURE__*/function(){function it(e,t,s){var _this=this;_classCallCheck(this,it);var n,o;this._isComposing=!1;var i=it.processConfig(t,e.textInput);this.elementRef=it.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(){yi.add(_this.inputElementRef,s,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(it,[{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="",gs.focusEndOfInput(this.inputElementRef),(s=this._onInput)==null||s.call(this,!1)),je.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(){var t,s,i,n;var e=document.createElement("div");return e.id=it.TEXT_INPUT_ID,e.classList.add("text-input-styling"),e.role="textbox",je.IS_CHROMIUM&&it.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",lr.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===q.ENTER&&!je.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});});}}]);}();it.TEXT_INPUT_ID="text-input";var
|
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});});}}]);}();it.TEXT_INPUT_ID="text-input";var Ts=it;var gs=/*#__PURE__*/function(){function gs(){_classCallCheck(this,gs);}return _createClass(gs,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(Ts.TEXT_INPUT_ID));t&&(je.IS_SAFARI&&t.focus(),gs.focusEndOfInput(t));}}]);}();function en(r){return r.charAt(0).toUpperCase()+r.slice(1);}function cr(r){return r&&JSON.stringify(r);}function Fi(r,e,t,s){var i="\n".concat(en(e)," message: ").concat(JSON.stringify(r)," \n"),n=t?"".concat(en(e)," message after interceptor: ").concat(cr(s)," \n"):"";return i+n;}function dr(r,e,t,s){return"".concat(Fi(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 hr(r,e,t){var s="response";return"".concat(Fi(r,s,e,t),"Make sure the ").concat(s," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function ur(r,e){var t="request";return"".concat(Fi(r,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}var tn="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",E={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",INVALID_RESPONSE:dr,INVALID_MODEL_REQUEST:ur,INVALID_MODEL_RESPONSE:hr,INVALID_STREAM_ARRAY_RESPONSE:"Multi-response arrays are not supported for streaming",INVALID_STREAM_EVENT:tn,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(tn),READABLE_STREAM_CONNECTION_ERROR:"Readable Stream connection error.",DEFINE_FUNCTION_HANDLER:"Please define a `function_handler` property inside the service config."},ei=/*#__PURE__*/function(){function ei(){_classCallCheck(this,ei);}return _createClass(ei,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-ei.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;}}]);}();ei.CODE_SNIPPET_GENERATION_JUMP=0.5;var X=ei;var ti=/*#__PURE__*/function(){function ti(){_classCallCheck(this,ti);}return _createClass(ti,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);},ti.LOAD_VOICES_MS);}}]);}();ti.LOAD_VOICES_MS=200;var wt=ti;var _t=/*#__PURE__*/function(){function _t(){_classCallCheck(this,_t);}return _createClass(_t,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;if((i=(s=t==null?void 0:t.styles)==null?void 0:s.bubble)!=null&&i.color){var n=_t.colorToHex(t.styles.bubble.color);e.style.setProperty("--loading-message-color",n),e.style.setProperty("--loading-message-color-fade","".concat(n,"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=_t.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");}}]);}();_t.BUBBLE_CLASS="deep-chat-loading-message-bubble",_t.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var Ue=_t;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
|
@@ -20,9 +20,9 @@ function setElementProps(e,t,s,i){var n;s!=="loading"&&(e.applyCustomStyles(t,i,
|
|
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
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 G=he;var Y=/*#__PURE__*/function(){function Y(){_classCallCheck(this,Y);}return _createClass(Y,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
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
|
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 fr="deep-chat-temporary-message",pr="deep-chat-suggestion-button",bi={"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"}}}},sn=Object.keys(bi);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(fr):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return sn.find(function(t){return e.classList.contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var s=bi[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=bi[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){sn.forEach(function(n){var o=s.getElementsByClassName(n);Array.from(o||[]).forEach(function(a){var l=Ce.getProcessedStyles(t,a,n);te.applyStylesToElement(a,l),Ce.applyEvents(a,n);});});var i=s.getElementsByClassName(pr);Array.from(i).forEach(function(n){return Ce.applySuggestionEvent(e,n);});}}]);}();var ge=/*#__PURE__*/function(){function ge(){_classCallCheck(this,ge);}return _createClass(ge,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&&ge.applyEventsToElement(e,s),i&&!Ce.doesElementContainDeepChatClass(e)&&ge.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]&&ge.applyClassUtilitiesToElement(n,e[s]);});});}},{key:"apply",value:function apply(e,t){Ce.applyDeepChatUtilities(e,e.htmlClassUtilities,t),ge.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){ge.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){ge.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
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:ge.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(ge.TARGET_WRAPPER_CLASS)[0]||e;}}]);}();ge.TARGET_WRAPPER_CLASS="html-wrapper";var te=ge;var Oe=/*#__PURE__*/function(){function Oe(){_classCallCheck(this,Oe);}return _createClass(Oe,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(Oe.HTML_BUBBLE_CLASS);var _te$tryAddWrapper=te.tryAddWrapper(o.bubbleElement,t,e._customWrappers,s),a=_te$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,s){s.bubbleElement.innerHTML=t,te.apply(e,s.outerContainer),Y.flagHTMLUpdateClass(s.bubbleElement);}// prettier-ignore
|
25
|
-
},{key:"overwrite",value:function overwrite(e,t,s,i){var n=e.messageToElements,o=y.overwriteMessage(n,i,t,s,"html",Oe.HTML_BUBBLE_CLASS);return o&&Oe.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=Oe.createElements(e,t,s,i);return y.fillEmptyMessageElement(n.bubbleElement,t),te.apply(e,n.outerContainer),Y.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&&te.isTemporaryBasedOnHTML(t))return;var o=Oe.create(e,t,s,n);return n||Oe.addElement(e,o.outerContainer),o;}}]);}();Oe.HTML_BUBBLE_CLASS="html-message";var Ce=Oe;var mr=/*#__PURE__*/function(){function mr(){_classCallCheck(this,mr);}return _createClass(mr,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 v=u.src.charAt(f);if(v!==a)return!1;var R=f;f=u.skipChars(f,v);var O=f-R;if(O!==2)return!1;var I=h;for(;++I,!(I>=p||(f=R=u.bMarks[I]+u.tShift[I],g=u.eMarks[I],f<g&&u.tShift[I]<u.blkIndent));)if(u.src.charAt(f)===a&&!(u.tShift[I]-u.blkIndent>=4)&&(f=u.skipChars(f,v),!(f-R<O)&&(f=u.skipSpaces(f),!(f<g)))){m=!0;break;}O=u.tShift[h],u.line=I+(m?1:0);var V=u.getLines(h+1,I,O,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:V,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 v=f;var R=0;for(;f<m;){var O=u.src.charAt(f);if(O==="{"&&(f===0||u.src.charAt(f-1)!=="\\"))R+=1;else if(O==="}"&&(f===0||u.src.charAt(f-1)!=="\\")){if(R-=1,R<0)return!1;}else if(O===a&&R===0){var I=f;var V=f+1;for(;V<m&&u.src.charAt(V)===a;)++V;if(V-I===g.length){if(!h){var xe=u.src.slice(v,I).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:xe,block:g.length>1,level:u.level});}return u.pos=V,!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 vs;function Hn(r){return vs=vs||document.createElement("textarea"),vs.innerHTML="&"+r+";",vs.value;}var gr=Object.prototype.hasOwnProperty;function yr(r,e){return r?gr.call(r,e):!1;}function Vn(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 br=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function as(r){return r.indexOf("\\")<0?r:r.replace(br,"$1");}function zn(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 vi(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 vr=/&([a-z#][a-z0-9]{1,31});/gi,Er=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function _r(r,e){var t=0,s=Hn(e);return e!==s?s:e.charCodeAt(0)===35&&Er.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),zn(t))?vi(t):r;}function ut(r){return r.indexOf("&")<0?r:r.replace(vr,_r);}var Sr=/[&<>"]/,xr=/[&<>"]/g,wr={"&":"&","<":"<",">":">",'"':"""};function Ar(r){return wr[r];}function ne(r){return Sr.test(r)?r.replace(xr,Ar):r;}var b={};b.blockquote_open=function(){return"<blockquote>\n";};b.blockquote_close=function(r,e){return"</blockquote>"+ft(r,e);};b.code=function(r,e){return r[e].block?"<pre><code>"+ne(r[e].content)+"</code></pre>"+ft(r,e):"<code>"+ne(r[e].content)+"</code>";};b.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(" "),yr(i.rules.fence_custom,c[0]))return i.rules.fence_custom[c[0]](r,e,t,s,i);l=ne(ut(as(d))),o=' class="'+a+l+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[n.content].concat(c))||ne(n.content):u=ne(n.content),"<pre><code"+o+">"+u+"</code></pre>"+ft(r,e);};b.fence_custom={};b.heading_open=function(r,e){return"<h"+r[e].hLevel+">";};b.heading_close=function(r,e){return"</h"+r[e].hLevel+">\n";};b.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+ft(r,e);};b.bullet_list_open=function(){return"<ul>\n";};b.bullet_list_close=function(r,e){return"</ul>"+ft(r,e);};b.list_item_open=function(){return"<li>";};b.list_item_close=function(){return"</li>\n";};b.ordered_list_open=function(r,e){var t=r[e],s=t.order>1?' start="'+t.order+'"':"";return"<ol"+s+">\n";};b.ordered_list_close=function(r,e){return"</ol>"+ft(r,e);};b.paragraph_open=function(r,e){return r[e].tight?"":"<p>";};b.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?ft(r,e):"");};b.link_open=function(r,e,t){var s=r[e].title?' title="'+ne(ut(r[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+ne(r[e].href)+'"'+s+i+">";};b.link_close=function(){return"</a>";};b.image=function(r,e,t){var s=' src="'+ne(r[e].src)+'"',i=r[e].title?' title="'+ne(ut(r[e].title))+'"':"",n=' alt="'+(r[e].alt?ne(ut(as(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+s+n+i+o+">";};b.table_open=function(){return"<table>\n";};b.table_close=function(){return"</table>\n";};b.thead_open=function(){return"<thead>\n";};b.thead_close=function(){return"</thead>\n";};b.tbody_open=function(){return"<tbody>\n";};b.tbody_close=function(){return"</tbody>\n";};b.tr_open=function(){return"<tr>";};b.tr_close=function(){return"</tr>\n";};b.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};b.th_close=function(){return"</th>";};b.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};b.td_close=function(){return"</td>";};b.strong_open=function(){return"<strong>";};b.strong_close=function(){return"</strong>";};b.em_open=function(){return"<em>";};b.em_close=function(){return"</em>";};b.del_open=function(){return"<del>";};b.del_close=function(){return"</del>";};b.ins_open=function(){return"<ins>";};b.ins_close=function(){return"</ins>";};b.mark_open=function(){return"<mark>";};b.mark_close=function(){return"</mark>";};b.sub=function(r,e){return"<sub>"+ne(r[e].content)+"</sub>";};b.sup=function(r,e){return"<sup>"+ne(r[e].content)+"</sup>";};b.hardbreak=function(r,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};b.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};b.text=function(r,e){return ne(r[e].content);};b.htmlblock=function(r,e){return r[e].content;};b.htmltag=function(r,e){return r[e].content;};b.abbr_open=function(r,e){return'<abbr title="'+ne(ut(r[e].title))+'">';};b.abbr_close=function(){return"</abbr>";};b.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>";};b.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";};b.footnote_block_close=function(){return"</ol>\n</section>\n";};b.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};b.footnote_close=function(){return"</li>\n";};b.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>';};b.dl_open=function(){return"<dl>\n";};b.dt_open=function(){return"<dt>";};b.dd_open=function(){return"<dd>";};b.dl_close=function(){return"</dl>\n";};b.dt_close=function(){return"</dt>\n";};b.dd_close=function(){return"</dd>\n";};function Gn(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?Gn(r,e+2):e;}var ft=b.getBreak=function(e,t){return t=Gn(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function Ui(){this.rules=Vn({},b),this.getBreak=b.getBreak;}Ui.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;};Ui.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 Cr(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 mt(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;}mt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};mt.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level;};mt.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e;};mt.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0;};function ls(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 Tr(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 mt(r,e,t,s,[]),n=ls(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 Rr(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=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 Ei(r){var e=ut(r);try{e=decodeURI(e);}catch(_unused3){}return encodeURI(e);}function Kn(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=Ei(as(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=as(r.src.slice(n,e)),!r.parser.validateLink(i))?!1:(r.linkContent=i,r.pos=e,!0);}function Jn(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=as(r.src.slice(s+1,e)),!0;if(t===92&&e+1<i){e+=2;continue;}e++;}return!1;}function $n(r){return r.trim().replace(/\s+/g," ").toUpperCase();}function Mr(r,e,t,s){var i,n,o,a,l,c,d,u,h;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(i=new mt(r,e,t,s,[]),n=ls(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(!Kn(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&&Jn(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=$n(r.slice(1,n)),_typeof(s.references[h])>"u"&&(s.references[h]={title:u,href:d}),o);}function kr(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=Mr(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 Lr(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 Ir(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 nn=" \n()[]'\".,!?-";function pi(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function Or(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="(^|["+nn.split("").map(pi).join("")+"])("+Object.keys(r.env.abbreviations).map(function(m){return m.substr(1);}).sort(function(m,f){return f.length-m.length;}).map(pi).join("|")+")($|["+nn.split("").map(pi).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 Nr=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Pr=/\((c|tm|r|p)\)/ig,Br={c:"©",r:"®",p:"§",tm:"™"};function Dr(r){return r.indexOf("(")<0?r:r.replace(Pr,function(e,t){return Br[t.toLowerCase()];});}function Fr(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=Dr(s),Nr.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 Ur=/['"]/,rn=/['"]/g,jr=/[-\s()\[\]]/,on="’";function an(r,e){return e<0||e>=r.length?!1:!jr.test(r[e]);}function bt(r,e,t){return r.substr(0,e)+t+r.substr(e+1);}function qr(r){var e,t,s,i,n,o,a,l,c,d,u,h,p,m,f,g,v;if(r.options.typographer){for(v=[],f=r.tokens.length-1;f>=0;f--)if(r.tokens[f].type==="inline"){for(g=r.tokens[f].children,v.length=0,e=0;e<g.length;e++)if(t=g[e],!(t.type!=="text"||Ur.test(t.text))){for(a=g[e].level,p=v.length-1;p>=0&&!(v[p].level<=a);p--);v.length=p+1,s=t.content,n=0,o=s.length;e:for(;n<o&&(rn.lastIndex=n,i=rn.exec(s),!!i);){if(l=!an(s,i.index-1),n=i.index+1,m=i[0]==="'",c=!an(s,n),!c&&!l){m&&(t.content=bt(t.content,i.index,on));continue;}if(u=!c,h=!l,h){for(p=v.length-1;p>=0&&(d=v[p],!(v[p].level<a));p--)if(d.single===m&&v[p].level===a){d=v[p],m?(g[d.token].content=bt(g[d.token].content,d.pos,r.options.quotes[2]),t.content=bt(t.content,i.index,r.options.quotes[3])):(g[d.token].content=bt(g[d.token].content,d.pos,r.options.quotes[0]),t.content=bt(t.content,i.index,r.options.quotes[1])),v.length=p;continue e;}}u?v.push({token:e,pos:i.index,single:m,level:a}):h&&m&&(t.content=bt(t.content,i.index,on));}}}}}var fi=[["block",Cr],["abbr",Rr],["references",kr],["inline",Lr],["footnote_tail",Ir],["abbr2",Or],["replacements",Fr],["smartquotes",qr]];function Wn(){this.options={},this.ruler=new ce();for(var r=0;r<fi.length;r++)this.ruler.push(fi[r][0],fi[r][1]);}Wn.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 gt(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;}gt.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};gt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};gt.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};gt.prototype.skipChars=function(e,t){for(var s=this.src.length;e<s&&this.src.charCodeAt(e)===t;e++);return e;};gt.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;};gt.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 Hr(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 Vr(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 zr(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 Gr(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 ln(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 cn(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 Kr(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 Jr(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m,f,g,v,R,O,I,V,xe=!0,ze,re,Qi,ui;if((u=cn(r,e))>=0)g=!0;else if((u=ln(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(R=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:I=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:I=[e,0],level:r.level++}),i=e,O=!1,ze=r.parser.ruler.getRules("list");i<t&&(v=r.skipSpaces(u),h=r.eMarks[i],v>=h?p=1:p=v-u,p>4&&(p=1),p<1&&(p=1),n=u-r.bMarks[i]+p,r.tokens.push({type:"list_item_open",lines:V=[e,0],level:r.level++}),a=r.blkIndent,l=r.tight,o=r.tShift[e],c=r.parentType,r.tShift[e]=v-r.bMarks[e],r.blkIndent=n,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||O)&&(xe=!1),O=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,V[1]=i,v=r.bMarks[e],!(i>=t||r.isEmpty(i)||r.tShift[i]<r.blkIndent));){for(ui=!1,re=0,Qi=ze.length;re<Qi;re++)if(ze[re](r,i,t,!0)){ui=!0;break;}if(ui)break;if(g){if(u=cn(r,i),u<0)break;}else if(u=ln(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}),I[1]=i,r.line=i,xe&&Kr(r,R),!0;}function $r(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 Wr(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 Xr(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 Xn={};["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){Xn[r]=!0;});var Yr=/^<([a-zA-Z]{1,15})[\s\/>]/,Zr=/^<\/([a-zA-Z]{1,15})[\s>]/;function Qr(r){var e=r|32;return e>=97&&e<=122;}function eo(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||Qr(i)){if(i===47){if(n=r.src.slice(a,l).match(Zr),!n)return!1;}else if(n=r.src.slice(a,l).match(Yr),!n)return!1;if(Xn[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 mi(r,e){var t=r.bMarks[e]+r.blkIndent,s=r.eMarks[e];return r.src.substr(t,s-t);}function to(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=mi(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=mi(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=mi(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 Es(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 so(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 io(r,e,t,s){var i,n,o,a,l,c,d,u,h,p,m,f,g,v;if(s)return r.ddIndent<0?!1:Es(r,e)>=0;if(d=e+1,r.isEmpty(d)&&++d>t||r.tShift[d]<r.blkIndent||(i=Es(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(v=!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)&&(v=!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=Es(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=Es(r,n),i<0))break;}return r.tokens.push({type:"dl_close",level:--r.level}),l[1]=d,r.line=d,v&&so(r,c),!0;}function no(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 _s=[["code",Hr],["fences",Vr,["paragraph","blockquote","list"]],["blockquote",zr,["paragraph","blockquote","list"]],["hr",Gr,["paragraph","blockquote","list"]],["list",Jr,["paragraph","blockquote"]],["footnote",$r,["paragraph"]],["heading",Wr,["paragraph","blockquote"]],["lheading",Xr],["htmlblock",eo,["paragraph","blockquote"]],["table",to,["paragraph"]],["deflist",io,["paragraph"]],["paragraph",no]];function ji(){this.ruler=new ce();for(var r=0;r<_s.length;r++)this.ruler.push(_s[r][0],_s[r][1],{alt:(_s[r][2]||[]).slice()});}ji.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 ro=/[\n\t]/g,oo=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,ao=/\u00a0/g;ji.prototype.parse=function(r,e,t,s){var i,n=0,o=0;if(!r)return[];r=r.replace(ao," "),r=r.replace(oo,"\n"),r.indexOf(" ")>=0&&(r=r.replace(ro,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 gt(r,this,e,t,s),this.tokenize(i,i.line,i.lineMax);};function lo(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 co(r,e){for(var t=r.pos;t<r.posMax&&!lo(r.src.charCodeAt(t));)t++;return t===r.pos?!1:(e||(r.pending+=r.src.slice(r.pos,t)),r.pos=t,!0);}function ho(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 qi=[];for(var dn=0;dn<256;dn++)qi.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){qi[r.charCodeAt(0)]=1;});function uo(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&&qi[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 po(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 fo(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 mo(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 go(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 hn(r){return r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122;}function un(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&&(hn(s)&&(o=!1),hn(i)&&(a=!1))),{can_open:o,can_close:a,delims:n};}function yo(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=un(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=un(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 bo=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function vo(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(bo,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}var Eo=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function _o(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(Eo,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}function So(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=ls(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,Kn(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&&Jn(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=ls(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[$n(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 xo(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=ls(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 wo(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 Ao=["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"],Co=/^<([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])?)*)>/,To=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Ro(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(To),s?Ao.indexOf(s[1].toLowerCase())<0||(n=s[0].slice(1,-1),o=Ei(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(Co),i?(n=i[0].slice(1,-1),o=Ei("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 ri(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 Mo=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,ko=/[^"'=<>`\x00-\x20]+/,Lo=/'[^']*'/,Io=/"[^"]*"/,Oo=ri(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",ko)("single_quoted",Lo)("double_quoted",Io)(),No=ri(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Mo)("attr_value",Oo)(),Po=ri(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",No)(),Bo=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Do=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Fo=/<[?].*?[?]>/,Uo=/<![A-Z]+\s+[^>]*>/,jo=/<!\[CDATA\[[\s\S]*?\]\]>/,qo=ri(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Po)("close_tag",Bo)("comment",Do)("processing",Fo)("declaration",Uo)("cdata",jo)();function Ho(r){var e=r|32;return e>=97&&e<=122;}function Vo(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&&!Ho(t))||(s=r.src.slice(n).match(qo),!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 zo=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Go=/^&([a-z][a-z0-9]{1,31});/i;function Ko(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(zo),i)return e||(s=i[1][0].toLowerCase()==="x"?parseInt(i[1].slice(1),16):parseInt(i[1],10),r.pending+=zn(s)?vi(s):vi(65533)),r.pos+=i[0].length,!0;}else if(i=r.src.slice(n).match(Go),i){var a=Hn(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 gi=[["text",co],["newline",ho],["escape",uo],["backticks",po],["del",fo],["ins",mo],["mark",go],["emphasis",yo],["sub",vo],["sup",_o],["links",So],["footnote_inline",xo],["footnote_ref",wo],["autolink",Ro],["htmltag",Vo],["entity",Ko]];function oi(){this.ruler=new ce();for(var r=0;r<gi.length;r++)this.ruler.push(gi[r][0],gi[r][1]);this.validateLink=Jo;}oi.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);};oi.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();};oi.prototype.parse=function(r,e,t,s){var i=new mt(r,this,e,t,s);this.tokenize(i);};function Jo(r){var e=["vbscript","javascript","file","data"],t=r.trim().toLowerCase();return t=ut(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var $o={options:{html:!1,// Enable HTML tags in source
|
25
|
+
},{key:"overwrite",value:function overwrite(e,t,s,i){var n=e.messageToElements,o=y.overwriteMessage(n,i,t,s,"html",Oe.HTML_BUBBLE_CLASS);return o&&Oe.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=Oe.createElements(e,t,s,i);return y.fillEmptyMessageElement(n.bubbleElement,t),te.apply(e,n.outerContainer),Y.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&&te.isTemporaryBasedOnHTML(t))return;var o=Oe.create(e,t,s,n);return n||Oe.addElement(e,o.outerContainer),o;}}]);}();Oe.HTML_BUBBLE_CLASS="html-message";var Te=Oe;var mr=/*#__PURE__*/function(){function mr(){_classCallCheck(this,mr);}return _createClass(mr,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 f;return((f=window.katex)==null?void 0:f.renderToString(u,_objectSpread({displayMode:h,throwOnError:!1,output:"mathml"},e)))||"";},c=function c(u,h,f){var m=!1,p=u.bMarks[h]+u.tShift[h],g=u.eMarks[h];if(p+1>g)return!1;var v=u.src.charAt(p);if(v!==a)return!1;var R=p;p=u.skipChars(p,v);var O=p-R;if(O!==2)return!1;var I=h;for(;++I,!(I>=f||(p=R=u.bMarks[I]+u.tShift[I],g=u.eMarks[I],p<g&&u.tShift[I]<u.blkIndent));)if(u.src.charAt(p)===a&&!(u.tShift[I]-u.blkIndent>=4)&&(p=u.skipChars(p,v),!(p-R<O)&&(p=u.skipSpaces(p),!(p<g)))){m=!0;break;}O=u.tShift[h],u.line=I+(m?1:0);var V=u.getLines(h+1,I,O,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:V,lines:[h,u.line],level:u.level,block:!0}),!0;},d=function d(u,h){var f=u.pos,m=u.posMax;var p=f;if(u.src.charAt(p)!==a)return!1;for(++p;p<m&&u.src.charAt(p)===a;)++p;var g=u.src.slice(f,p);if(g.length>2)return!1;var v=p;var R=0;for(;p<m;){var O=u.src.charAt(p);if(O==="{"&&(p===0||u.src.charAt(p-1)!=="\\"))R+=1;else if(O==="}"&&(p===0||u.src.charAt(p-1)!=="\\")){if(R-=1,R<0)return!1;}else if(O===a&&R===0){var I=p;var V=p+1;for(;V<m&&u.src.charAt(V)===a;)++V;if(V-I===g.length){if(!h){var xe=u.src.slice(v,I).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:xe,block:g.length>1,level:u.level});}return u.pos=V,!0;}}p+=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 vs;function qn(r){return vs=vs||document.createElement("textarea"),vs.innerHTML="&"+r+";",vs.value;}var gr=Object.prototype.hasOwnProperty;function yr(r,e){return r?gr.call(r,e):!1;}function Vn(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 br=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function as(r){return r.indexOf("\\")<0?r:r.replace(br,"$1");}function zn(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 vi(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 vr=/&([a-z#][a-z0-9]{1,31});/gi,Er=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function _r(r,e){var t=0,s=qn(e);return e!==s?s:e.charCodeAt(0)===35&&Er.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),zn(t))?vi(t):r;}function ut(r){return r.indexOf("&")<0?r:r.replace(vr,_r);}var Sr=/[&<>"]/,xr=/[&<>"]/g,wr={"&":"&","<":"<",">":">",'"':"""};function Cr(r){return wr[r];}function ne(r){return Sr.test(r)?r.replace(xr,Cr):r;}var b={};b.blockquote_open=function(){return"<blockquote>\n";};b.blockquote_close=function(r,e){return"</blockquote>"+pt(r,e);};b.code=function(r,e){return r[e].block?"<pre><code>"+ne(r[e].content)+"</code></pre>"+pt(r,e):"<code>"+ne(r[e].content)+"</code>";};b.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(" "),yr(i.rules.fence_custom,c[0]))return i.rules.fence_custom[c[0]](r,e,t,s,i);l=ne(ut(as(d))),o=' class="'+a+l+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[n.content].concat(c))||ne(n.content):u=ne(n.content),"<pre><code"+o+">"+u+"</code></pre>"+pt(r,e);};b.fence_custom={};b.heading_open=function(r,e){return"<h"+r[e].hLevel+">";};b.heading_close=function(r,e){return"</h"+r[e].hLevel+">\n";};b.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+pt(r,e);};b.bullet_list_open=function(){return"<ul>\n";};b.bullet_list_close=function(r,e){return"</ul>"+pt(r,e);};b.list_item_open=function(){return"<li>";};b.list_item_close=function(){return"</li>\n";};b.ordered_list_open=function(r,e){var t=r[e],s=t.order>1?' start="'+t.order+'"':"";return"<ol"+s+">\n";};b.ordered_list_close=function(r,e){return"</ol>"+pt(r,e);};b.paragraph_open=function(r,e){return r[e].tight?"":"<p>";};b.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?pt(r,e):"");};b.link_open=function(r,e,t){var s=r[e].title?' title="'+ne(ut(r[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+ne(r[e].href)+'"'+s+i+">";};b.link_close=function(){return"</a>";};b.image=function(r,e,t){var s=' src="'+ne(r[e].src)+'"',i=r[e].title?' title="'+ne(ut(r[e].title))+'"':"",n=' alt="'+(r[e].alt?ne(ut(as(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+s+n+i+o+">";};b.table_open=function(){return"<table>\n";};b.table_close=function(){return"</table>\n";};b.thead_open=function(){return"<thead>\n";};b.thead_close=function(){return"</thead>\n";};b.tbody_open=function(){return"<tbody>\n";};b.tbody_close=function(){return"</tbody>\n";};b.tr_open=function(){return"<tr>";};b.tr_close=function(){return"</tr>\n";};b.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};b.th_close=function(){return"</th>";};b.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};b.td_close=function(){return"</td>";};b.strong_open=function(){return"<strong>";};b.strong_close=function(){return"</strong>";};b.em_open=function(){return"<em>";};b.em_close=function(){return"</em>";};b.del_open=function(){return"<del>";};b.del_close=function(){return"</del>";};b.ins_open=function(){return"<ins>";};b.ins_close=function(){return"</ins>";};b.mark_open=function(){return"<mark>";};b.mark_close=function(){return"</mark>";};b.sub=function(r,e){return"<sub>"+ne(r[e].content)+"</sub>";};b.sup=function(r,e){return"<sup>"+ne(r[e].content)+"</sup>";};b.hardbreak=function(r,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};b.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};b.text=function(r,e){return ne(r[e].content);};b.htmlblock=function(r,e){return r[e].content;};b.htmltag=function(r,e){return r[e].content;};b.abbr_open=function(r,e){return'<abbr title="'+ne(ut(r[e].title))+'">';};b.abbr_close=function(){return"</abbr>";};b.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>";};b.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";};b.footnote_block_close=function(){return"</ol>\n</section>\n";};b.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};b.footnote_close=function(){return"</li>\n";};b.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>';};b.dl_open=function(){return"<dl>\n";};b.dt_open=function(){return"<dt>";};b.dd_open=function(){return"<dd>";};b.dl_close=function(){return"</dl>\n";};b.dt_close=function(){return"</dt>\n";};b.dd_close=function(){return"</dd>\n";};function Gn(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?Gn(r,e+2):e;}var pt=b.getBreak=function(e,t){return t=Gn(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function Ui(){this.rules=Vn({},b),this.getBreak=b.getBreak;}Ui.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;};Ui.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 Tr(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 mt(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;}mt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};mt.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level;};mt.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e;};mt.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0;};function ls(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 mt(r,e,t,s,[]),n=ls(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 Rr(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 Ei(r){var e=ut(r);try{e=decodeURI(e);}catch(_unused3){}return encodeURI(e);}function Kn(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=Ei(as(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=as(r.src.slice(n,e)),!r.parser.validateLink(i))?!1:(r.linkContent=i,r.pos=e,!0);}function Jn(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=as(r.src.slice(s+1,e)),!0;if(t===92&&e+1<i){e+=2;continue;}e++;}return!1;}function $n(r){return r.trim().replace(/\s+/g," ").toUpperCase();}function Mr(r,e,t,s){var i,n,o,a,l,c,d,u,h;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(i=new mt(r,e,t,s,[]),n=ls(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(!Kn(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&&Jn(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=$n(r.slice(1,n)),_typeof(s.references[h])>"u"&&(s.references[h]={title:u,href:d}),o);}function kr(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=Mr(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 Lr(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 Ir(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(f){return f.type==="footnote_reference_open"?(u=!0,l=[],c=f.label,!1):f.type==="footnote_reference_close"?(u=!1,h[":"+c]=l,!1):(u&&l.push(f),!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 nn=" \n()[]'\".,!?-";function fi(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function Or(r){var e,t,s,i,n,o,a,l,c,d,u,h,f=r.tokens;if(r.env.abbreviations){for(r.env.abbrRegExp||(h="(^|["+nn.split("").map(fi).join("")+"])("+Object.keys(r.env.abbreviations).map(function(m){return m.substr(1);}).sort(function(m,p){return p.length-m.length;}).map(fi).join("|")+")($|["+nn.split("").map(fi).join("")+"])",r.env.abbrRegExp=new RegExp(h,"g")),d=r.env.abbrRegExp,t=0,s=f.length;t<s;t++)if(f[t].type==="inline"){for(i=f[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}),f[t].children=i=[].concat(i.slice(0,e),a,i.slice(e+1)));}}}}var Nr=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Pr=/\((c|tm|r|p)\)/ig,Br={c:"©",r:"®",p:"§",tm:"™"};function Dr(r){return r.indexOf("(")<0?r:r.replace(Pr,function(e,t){return Br[t.toLowerCase()];});}function Fr(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=Dr(s),Nr.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 Ur=/['"]/,rn=/['"]/g,jr=/[-\s()\[\]]/,on="’";function an(r,e){return e<0||e>=r.length?!1:!jr.test(r[e]);}function bt(r,e,t){return r.substr(0,e)+t+r.substr(e+1);}function Hr(r){var e,t,s,i,n,o,a,l,c,d,u,h,f,m,p,g,v;if(r.options.typographer){for(v=[],p=r.tokens.length-1;p>=0;p--)if(r.tokens[p].type==="inline"){for(g=r.tokens[p].children,v.length=0,e=0;e<g.length;e++)if(t=g[e],!(t.type!=="text"||Ur.test(t.text))){for(a=g[e].level,f=v.length-1;f>=0&&!(v[f].level<=a);f--);v.length=f+1,s=t.content,n=0,o=s.length;e:for(;n<o&&(rn.lastIndex=n,i=rn.exec(s),!!i);){if(l=!an(s,i.index-1),n=i.index+1,m=i[0]==="'",c=!an(s,n),!c&&!l){m&&(t.content=bt(t.content,i.index,on));continue;}if(u=!c,h=!l,h){for(f=v.length-1;f>=0&&(d=v[f],!(v[f].level<a));f--)if(d.single===m&&v[f].level===a){d=v[f],m?(g[d.token].content=bt(g[d.token].content,d.pos,r.options.quotes[2]),t.content=bt(t.content,i.index,r.options.quotes[3])):(g[d.token].content=bt(g[d.token].content,d.pos,r.options.quotes[0]),t.content=bt(t.content,i.index,r.options.quotes[1])),v.length=f;continue e;}}u?v.push({token:e,pos:i.index,single:m,level:a}):h&&m&&(t.content=bt(t.content,i.index,on));}}}}}var pi=[["block",Tr],["abbr",Rr],["references",kr],["inline",Lr],["footnote_tail",Ir],["abbr2",Or],["replacements",Fr],["smartquotes",Hr]];function Wn(){this.options={},this.ruler=new ce();for(var r=0;r<pi.length;r++)this.ruler.push(pi[r][0],pi[r][1]);}Wn.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 gt(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;}gt.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};gt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};gt.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};gt.prototype.skipChars=function(e,t){for(var s=this.src.length;e<s&&this.src.charCodeAt(e)===t;e++);return e;};gt.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;};gt.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 qr(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 Vr(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 zr(r,e,t,s){var i,n,o,a,l,c,d,u,h,f,m,p=r.bMarks[e]+r.tShift[e],g=r.eMarks[e];if(p>g||r.src.charCodeAt(p++)!==62||r.level>=r.options.maxNesting)return!1;if(s)return!0;for(r.src.charCodeAt(p)===32&&p++,l=r.blkIndent,r.blkIndent=0,a=[r.bMarks[e]],r.bMarks[e]=p,p=p<g?r.skipSpaces(p):p,n=p>=g,o=[r.tShift[e]],r.tShift[e]=p-r.bMarks[e],u=r.parser.ruler.getRules("blockquote"),i=e+1;i<t&&(p=r.bMarks[i]+r.tShift[i],g=r.eMarks[i],!(p>=g));i++){if(r.src.charCodeAt(p++)===62){r.src.charCodeAt(p)===32&&p++,a.push(r.bMarks[i]),r.bMarks[i]=p,p=p<g?r.skipSpaces(p):p,n=p>=g,o.push(r.tShift[i]),r.tShift[i]=p-r.bMarks[i];continue;}if(n)break;for(m=!1,h=0,f=u.length;h<f;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 Gr(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 ln(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 cn(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 Kr(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 Jr(r,e,t,s){var i,n,o,a,l,c,d,u,h,f,m,p,g,v,R,O,I,V,xe=!0,ze,re,Qi,ui;if((u=cn(r,e))>=0)g=!0;else if((u=ln(r,e))>=0)g=!1;else return!1;if(r.level>=r.options.maxNesting)return!1;if(p=r.src.charCodeAt(u-1),s)return!0;for(R=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:I=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:I=[e,0],level:r.level++}),i=e,O=!1,ze=r.parser.ruler.getRules("list");i<t&&(v=r.skipSpaces(u),h=r.eMarks[i],v>=h?f=1:f=v-u,f>4&&(f=1),f<1&&(f=1),n=u-r.bMarks[i]+f,r.tokens.push({type:"list_item_open",lines:V=[e,0],level:r.level++}),a=r.blkIndent,l=r.tight,o=r.tShift[e],c=r.parentType,r.tShift[e]=v-r.bMarks[e],r.blkIndent=n,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||O)&&(xe=!1),O=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,V[1]=i,v=r.bMarks[e],!(i>=t||r.isEmpty(i)||r.tShift[i]<r.blkIndent));){for(ui=!1,re=0,Qi=ze.length;re<Qi;re++)if(ze[re](r,i,t,!0)){ui=!0;break;}if(ui)break;if(g){if(u=cn(r,i),u<0)break;}else if(u=ln(r,i),u<0)break;if(p!==r.src.charCodeAt(u-1))break;}return r.tokens.push({type:g?"ordered_list_close":"bullet_list_close",level:--r.level}),I[1]=i,r.line=i,xe&&Kr(r,R),!0;}function $r(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 Wr(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 Xr(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 Xn={};["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){Xn[r]=!0;});var Yr=/^<([a-zA-Z]{1,15})[\s\/>]/,Zr=/^<\/([a-zA-Z]{1,15})[\s>]/;function Qr(r){var e=r|32;return e>=97&&e<=122;}function eo(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||Qr(i)){if(i===47){if(n=r.src.slice(a,l).match(Zr),!n)return!1;}else if(n=r.src.slice(a,l).match(Yr),!n)return!1;if(Xn[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 mi(r,e){var t=r.bMarks[e]+r.blkIndent,s=r.eMarks[e];return r.src.substr(t,s-t);}function to(r,e,t,s){var i,n,o,a,l,c,d,u,h,f,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=mi(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=mi(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:f=[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=mi(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}),f[1]=m[1]=l,r.line=l,!0;}function Es(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 so(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 io(r,e,t,s){var i,n,o,a,l,c,d,u,h,f,m,p,g,v;if(s)return r.ddIndent<0?!1:Es(r,e)>=0;if(d=e+1,r.isEmpty(d)&&++d>t||r.tShift[d]<r.blkIndent||(i=Es(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(v=!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++}),p=r.tight,h=r.ddIndent,u=r.blkIndent,m=r.tShift[n],f=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)&&(v=!1),g=r.line-n>1&&r.isEmpty(r.line-1),r.tShift[n]=m,r.tight=p,r.parentType=f,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=Es(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=Es(r,n),i<0))break;}return r.tokens.push({type:"dl_close",level:--r.level}),l[1]=d,r.line=d,v&&so(r,c),!0;}function no(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 _s=[["code",qr],["fences",Vr,["paragraph","blockquote","list"]],["blockquote",zr,["paragraph","blockquote","list"]],["hr",Gr,["paragraph","blockquote","list"]],["list",Jr,["paragraph","blockquote"]],["footnote",$r,["paragraph"]],["heading",Wr,["paragraph","blockquote"]],["lheading",Xr],["htmlblock",eo,["paragraph","blockquote"]],["table",to,["paragraph"]],["deflist",io,["paragraph"]],["paragraph",no]];function ji(){this.ruler=new ce();for(var r=0;r<_s.length;r++)this.ruler.push(_s[r][0],_s[r][1],{alt:(_s[r][2]||[]).slice()});}ji.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 ro=/[\n\t]/g,oo=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,ao=/\u00a0/g;ji.prototype.parse=function(r,e,t,s){var i,n=0,o=0;if(!r)return[];r=r.replace(ao," "),r=r.replace(oo,"\n"),r.indexOf(" ")>=0&&(r=r.replace(ro,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 gt(r,this,e,t,s),this.tokenize(i,i.line,i.lineMax);};function lo(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 co(r,e){for(var t=r.pos;t<r.posMax&&!lo(r.src.charCodeAt(t));)t++;return t===r.pos?!1:(e||(r.pending+=r.src.slice(r.pos,t)),r.pos=t,!0);}function ho(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 Hi=[];for(var dn=0;dn<256;dn++)Hi.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){Hi[r.charCodeAt(0)]=1;});function uo(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&&Hi[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 fo(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 po(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 mo(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 go(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 hn(r){return r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122;}function un(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&&(hn(s)&&(o=!1),hn(i)&&(a=!1))),{can_open:o,can_close:a,delims:n};}function yo(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=un(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=un(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 bo=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function vo(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(bo,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}var Eo=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function _o(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(Eo,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}function So(r,e){var t,s,i,n,o,a,l,c,d=!1,u=r.pos,h=r.posMax,f=r.pos,m=r.src.charCodeAt(f);if(m===33&&(d=!0,m=r.src.charCodeAt(++f)),m!==91||r.level>=r.options.maxNesting||(t=f+1,s=ls(r,f),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(f=a,Kn(r,a)?(n=r.linkContent,a=r.pos):n="",f=a;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<h&&f!==a&&Jn(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&&(f=a+1,a=ls(r,a),a>=0?i=r.src.slice(f,a++):a=f-1),i||(_typeof(i)>"u"&&(a=s+1),i=r.src.slice(t,s)),l=r.env.references[$n(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 xo(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=ls(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 wo(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 Co=["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"],To=/^<([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 Ro(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?Co.indexOf(s[1].toLowerCase())<0||(n=s[0].slice(1,-1),o=Ei(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(To),i?(n=i[0].slice(1,-1),o=Ei("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 ri(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 Mo=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,ko=/[^"'=<>`\x00-\x20]+/,Lo=/'[^']*'/,Io=/"[^"]*"/,Oo=ri(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",ko)("single_quoted",Lo)("double_quoted",Io)(),No=ri(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Mo)("attr_value",Oo)(),Po=ri(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",No)(),Bo=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Do=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Fo=/<[?].*?[?]>/,Uo=/<![A-Z]+\s+[^>]*>/,jo=/<!\[CDATA\[[\s\S]*?\]\]>/,Ho=ri(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Po)("close_tag",Bo)("comment",Do)("processing",Fo)("declaration",Uo)("cdata",jo)();function qo(r){var e=r|32;return e>=97&&e<=122;}function Vo(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&&!qo(t))||(s=r.src.slice(n).match(Ho),!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 zo=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Go=/^&([a-z][a-z0-9]{1,31});/i;function Ko(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(zo),i)return e||(s=i[1][0].toLowerCase()==="x"?parseInt(i[1].slice(1),16):parseInt(i[1],10),r.pending+=zn(s)?vi(s):vi(65533)),r.pos+=i[0].length,!0;}else if(i=r.src.slice(n).match(Go),i){var a=qn(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 gi=[["text",co],["newline",ho],["escape",uo],["backticks",fo],["del",po],["ins",mo],["mark",go],["emphasis",yo],["sub",vo],["sup",_o],["links",So],["footnote_inline",xo],["footnote_ref",wo],["autolink",Ro],["htmltag",Vo],["entity",Ko]];function oi(){this.ruler=new ce();for(var r=0;r<gi.length;r++)this.ruler.push(gi[r][0],gi[r][1]);this.validateLink=Jo;}oi.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);};oi.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();};oi.prototype.parse=function(r,e,t,s){var i=new mt(r,this,e,t,s);this.tokenize(i);};function Jo(r){var e=["vbscript","javascript","file","data"],t=r.trim().toLowerCase();return t=ut(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var $o={options:{html:!1,// Enable HTML tags in source
|
26
26
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
27
27
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
28
28
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
@@ -65,55 +65,55 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
65
65
|
// function (/*str, lang*/) { return ''; }
|
66
66
|
//
|
67
67
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
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"]}}},Yo={"default":$o,full:Wo,commonmark:Xo};function Yn(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
|
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"]}}},Yo={"default":$o,full:Wo,commonmark:Xo};function Yn(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 Ae(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 oi(),this.block=new ji(),this.core=new Wn(),this.renderer=new Ui(),this.ruler=new ce(),this.options={},this.configure(Yo[r]),this.set(e||{});}Ae.prototype.set=function(r){Vn(this.options,r);};Ae.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);});};Ae.prototype.use=function(r,e){return r(this,e),this;};Ae.prototype.parse=function(r,e){var t=new Yn(this,r,e);return this.core.process(t),t.tokens;};Ae.prototype.render=function(r,e){return e=e||{},this.renderer.render(this.parse(r,e),this.options,e);};Ae.prototype.parseInline=function(r,e){var t=new Yn(this,r,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};Ae.prototype.renderInline=function(r,e){return e=e||{},this.renderer.render(this.parseInline(r,e),this.options,e);};var nt=/*#__PURE__*/function(){function nt(){_classCallCheck(this,nt);}return _createClass(nt,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(mr.katex.bind(this,n),{delimiter:i});}}},{key:"instantiate",value:function instantiate(e){if(e)return new Ae(_objectSpread(_objectSpread({},nt.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new Ae({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
|
69
69
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
70
70
|
breaks:!0,// Convert '\n' in paragraphs into <br>
|
71
71
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
72
72
|
linkTarget:"_blank",// set target to open in a new tab
|
73
73
|
typographer:!0// Enable smartypants and other sweet transforms
|
74
|
-
});}else return new
|
74
|
+
});}else return new Ae(nt.DEFAULT_PROPERTIES);}},{key:"createNew",value:function createNew(e){var t=nt.instantiate(e);return nt.addPlugins(t,e),t.inline.validateLink=function(){return!0;},t;}}]);}();nt.DEFAULT_PROPERTIES={breaks:!0,linkTarget:"_blank"// set target to open in a new tab
|
75
75
|
};var cs=nt;var Zo=/*#__PURE__*/function(){function Zo(e){_classCallCheck(this,Zo);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(Zo,[{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 ee=/*#__PURE__*/function(){function ee(){_classCallCheck(this,ee);}return _createClass(ee,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&&(ee.applyCustomStylesToElements(e,s,i.shared),t===y.USER_ROLE?ee.applyCustomStylesToElements(e,s,i.user):(ee.applyCustomStylesToElements(e,s,i.ai),ee.applyCustomStylesToElements(e,s,i[t])));}},{key:"isElementsStyles",value:function isElementsStyles(e){return!!(e.outerContainer||e.innerContainer||e.bubble||e.media);}// prettier-ignore
|
76
76
|
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i,n){var o;n&&e["default"]!==n?ee.isElementsStyles(n)?(ee.applyCustomStylesToElements(t,i,(o=e["default"])==null?void 0:o.shared),ee.applyCustomStylesToElements(t,i,n)):(ee.applySideStyles(t,s,i,e["default"]),ee.applySideStyles(t,s,i,n)):ee.applySideStyles(t,s,i,e["default"]);}// prettier-ignore
|
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 ds=/*#__PURE__*/function(){function ds(){_classCallCheck(this,ds);}return _createClass(ds,null,[{key:"onMessage",value:function onMessage(e,t,s){var n;var i=JSON.parse(JSON.stringify({message:t,isHistory:s,isInitial:s}));G.reAddFileRefToObject(t,i.message),(n=e.onMessage)==null||n.call(e,i),e.dispatchEvent(new CustomEvent("message",{detail:i})),Y.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&&G.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("",y.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?Ce.createElements(e,s,y.AI_ROLE,!0,!0):q.createDefaultElements(e);return q.addLoadHistoryMessage(i,e,t),y.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 ss=/*#__PURE__*/function(){function ss(){_classCallCheck(this,ss);}return _createClass(ss,null,[{key:"setFade",value:function setFade(e,t){e.style.transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(ss.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:ss.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;}()}]);}();ss.DEFAULT_FADE_MS=500;var Ts=ss;var pn="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='iso-8859-1'?%3e%3csvg%20fill='%23000000'%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%2032%2032'%20xml:space='preserve'%3e%3cpath%20d='M23,30.36H9c-2.404,0-4.36-1.956-4.36-4.36V15c0-2.404,1.956-4.36,4.36-4.36h3.659%20c0.167-1.566,1.415-2.813,2.981-2.981V5.333c-1.131-0.174-2-1.154-2-2.333c0-1.301,1.059-2.36,2.36-2.36%20c1.302,0,2.36,1.059,2.36,2.36c0,1.179-0.869,2.159-2,2.333V7.66c1.566,0.167,2.814,1.415,2.981,2.981H23%20c2.404,0,4.36,1.956,4.36,4.36v11C27.36,28.404,25.404,30.36,23,30.36z%20M9,11.36c-2.007,0-3.64,1.633-3.64,3.64v11%20c0,2.007,1.633,3.64,3.64,3.64h14c2.007,0,3.64-1.633,3.64-3.64V15c0-2.007-1.633-3.64-3.64-3.64H9z%20M13.384,10.64h5.231%20C18.439,9.354,17.334,8.36,16,8.36C14.667,8.36,13.561,9.354,13.384,10.64z%20M16,1.36c-0.904,0-1.64,0.736-1.64,1.64%20S15.096,4.64,16,4.64c0.904,0,1.64-0.736,1.64-1.64S16.904,1.36,16,1.36z%20M20,27.36h-8c-1.301,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36h8c1.302,0,2.36,1.059,2.36,2.36S21.302,27.36,20,27.36z%20M12,23.36c-0.904,0-1.64,0.735-1.64,1.64%20s0.736,1.64,1.64,1.64h8c0.904,0,1.64-0.735,1.64-1.64s-0.735-1.64-1.64-1.64H12z%20M31,23.86h-2c-0.199,0-0.36-0.161-0.36-0.36V15%20c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5C31.36,23.699,31.199,23.86,31,23.86z%20M29.36,23.14h1.279v-7.78%20H29.36V23.14z%20M3,23.86H1c-0.199,0-0.36-0.161-0.36-0.36V15c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5%20C3.36,23.699,3.199,23.86,3,23.86z%20M1.36,23.14h1.28v-7.78H1.36V23.14z%20M20,20.36c-1.302,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36s2.36,1.059,2.36,2.36C22.36,19.302,21.302,20.36,20,20.36z%20M20,16.36c-0.904,0-1.64,0.736-1.64,1.64%20s0.735,1.64,1.64,1.64s1.64-0.735,1.64-1.64S20.904,16.36,20,16.36z%20M12,20.36c-1.301,0-2.36-1.059-2.36-2.36s1.059-2.36,2.36-2.36%20s2.36,1.059,2.36,2.36C14.36,19.302,13.301,20.36,12,20.36z%20M12,16.36c-0.904,0-1.64,0.736-1.64,1.64s0.736,1.64,1.64,1.64%20s1.64-0.735,1.64-1.64S12.904,16.36,12,16.36z'/%3e%3crect%20style='fill:none;'%20width='32'%20height='32'/%3e%3c/svg%3e",_i="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAMAAAC/MqoPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAADNQTFRF////9vX18vLy/Pz86enp4+Li2tnZ1tbWzczM+fn57Ozs4N/f09LS0M/P5uXl7+/v3dzcwtncCAAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAZNSURBVHja7d3bdtsqEABQYABZSLH9/3+ZpnUsIcF5iOM6PfElNoMHMfPQdq3GmL0GkLhEUqLaUExnOtOZznSmM53pTGc605nOdKYznelMZzrTmV4LXSqllKyJDkob26xWq8Zae/iH0QoWTm9d1xur4WuypQJtTd+5dqn0VjcxzNO5/57mEBvdLo8Oron6aseWOjYOFkVvjQs3DmgyONMuht52EfztP+4hdu0i6LCO808/M8c1lE/fuPGej41uUzgdtoO/75N+2ELJ9I3b3//hPXbiMenm3pR/Jt4USgcLBIp4Bh10gqKVhvLo0klCxeSky96nKcj3siw6pJIL4XsoiQ7apyvMY/V3HHrSRioLopvEhSpTCn2TPEuwKYMOIX0tAxRBf/Hpa+lfSqBv9gi1FPsNfTrMAiVmIE/vJhz61FGnQxRIEYE4vfNYdN8Rp6MlHaHotHTn8ejekaZPAjEmyvQWdZFTtYTpXqCGJ0zvcek9Yfoel76nS0ffv1NMp1ca+pkgyfRCGind4L7OWWc605l+cxjsyhqy9AGbPpClc1/nvl5VX0c/3Alk6RU3+Am7shNZ+h6bvidLr7jBB+zKBrL0irOOudmIUDzTmf5gIP+iEuXtRuTVaEmY/oZLfyNMrzjryPc0gerMTdpVg0tvjJUU6bLPcGOoUv46SLL6Wi8yhLf06C7TUyekI0efRaaYqdFltkeNpPumRPSMDxgBYvSM035FrKAmH72hRW99PrpvSdEHkTEGUvSsK3yKVDkuJ92RohcZaehzzirPpOg+J92Tolfc4Cumx5xVXpGiZ34+ICX6W84qv5GiR5NPbiIpOv6BCoSvSkTX+eiaGP092zINvBOj4x8mSf9FqejvNo/cvpOji19ZbmviL0GPLsYMFzgzCor0+Bv/ePDvSJKOb9dJ5UlnbnEHiHgzv6cdTpJOWuc/u3FEucLDOL75xGtBiefrcwgoC9NDSH/jkH6pAuXmBqPQ9HSUPVdZBH1GGOrMXAQdYxcKZfxAoK+KKBKFLosoEoX+u4giUehz8jlcnAuhp78I46yDYNAd+QLR6K+pr+yvxdBTHyVDubQh0UfSxaHSd0lbvNkVRE87JGOtc+PQd2QLQ6fHhJkKsSh6yg13tO08JPprsgrrXWH0dJd2vH1MLPprot4eXoujpzrdhngiD40ek2y92lggPcnWa8qN1Yz0BFuvZhRl0uOfR0v4Ewuli/Bg4Qr3lArqGdndQ3UPO1EunXYwnelMZzrTmc50pjOd6UxnOtOZznSmM53pTGf6kuj6oedFKV0s3fX6sX1S3bsi6a4PD7+/YAqYeBw6pIB/4qEgOqxdSPbGiim4NRRCbzs3Jj0L4UfXtQXQVRfn5IdA/Bw7RZzurEV6EtdsLeGXkIPuA+K1UoVeA0l62zmN/LqfSSft9KkepmoRuvi3nd5uKNFB9zbbXEANqdr941XO0NJx2v2jdJenpf+/3bvn0ts16ph+sd6hX7dPo2+2cZzE02Ia43bzDHqr+2Evnhz74ZHU30ffbKOeng1/NPV30Ns1gYQnSP2P6e65Pfxc6h02XZqXQCjhJ6kPL6bFo4NrGvAU4UII4SE2P1vQuZkuOxckVfehisF1MjUddN/MZBN+kvq5uf0O/xa66gyNS9ktMWlz44rO1Z8C19i5FPdHzPamXn+F3hryPfxMr78+4F+kq22kO6Rf6fUQt+puuustyWv4rbG3l/duztFB96GYoe1cTBdXMr+nw9qVM6ZfxOvzezff0nXi/ZOndvrR6Zvpm0c3h6nhdb+5iS7tsIim/qXZD9+97/Jf+rpZ5BET1ayv0GUzLhEuhBBjIy/RdVPgndutIRt9nt7p5cKFEEJ3Z+jQFDZL+XnMDXxHB73gxn5s9Kc3d3/pFciFkN/QTSXHJpX5l66gDrkQoP6hL3xsPw39la4qOiV8tH78XeSbue6N9mvWa6J/ybpc1CT1Wnh5Qq9meP8IOKH3ddH7E/ri1iYux/SXDrXR4UiPdck/wUpU+FtPf6/orja6O9KL3l56LOvVxe5Ib2qjN0d6Vbex4ghWlU3bPqI90If66MNng680FNpbJijH6kCvaF3uMzQ3+IrpFerV4Y9dffQdN3im10ivbuImhD3Qq5u4HdZkua8znelMZ/pS4z9CPVKkxowNxgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wMy0yN1QxNTo0NToxNSswMDowMN1xSg4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDMtMjdUMTU6NDU6MTUrMDA6MDCsLPKyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAABJRU5ErkJggg==";var Zn=/*#__PURE__*/function(){function Zn(e){_classCallCheck(this,Zn);this.className=e;}return _createClass(Zn,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e).style).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e).style.visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e).classList.add("role-hidden");}}]);}();var Le=/*#__PURE__*/function(_Zn){function Le(e){var _this3;_classCallCheck(this,Le);_this3=_callSuper(this,Le,["avatar-container"]),_this3._avatars=e;return _this3;}_inherits(Le,_Zn);return _createClass(Le,[{key:"addBesideBubble",value:function addBesideBubble(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===y.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)||_i,s.onerror=Le.errorFallback.bind(this,_i)):(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)||pn,s.onerror=Le.errorFallback.bind(this,pn)),s.classList.add("avatar"),s.alt="".concat(e," avatar");var i=document.createElement("div");return i.classList.add(this.className),i.appendChild(s),t&&Le.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!==y.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===y.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&&Le.applyCustomStylesToElements(e,t,s["default"].styles),i===y.USER_ROLE)(o=s.user)!=null&&o.styles&&Le.applyCustomStylesToElements(e,t,s.user.styles);else{(a=s.ai)!=null&&a.styles&&Le.applyCustomStylesToElements(e,t,s.ai.styles);var c=(l=s[i])==null?void 0:l.styles;c&&Le.applyCustomStylesToElements(e,t,c);}}}]);}(Zn);var Zt=/*#__PURE__*/function(_Zn2){function Zt(e){var _this4;_classCallCheck(this,Zt);_this4=_callSuper(this,Zt,["name"]),_this4._names=e;return _this4;}_inherits(Zt,_Zn2);return _createClass(Zt,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var s=typeof this._names=="boolean"?{}:this._names,i=this.createName(t,s),n=Zt.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=Zt.getNameText(e,t),Zt.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!==y.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===y.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===y.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===y.USER_ROLE?((s=t.user)==null?void 0:s.text)||((i=t["default"])==null?void 0:i.text)||"User":e===y.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;}}]);}(Zn);var se=/*#__PURE__*/function(){function se(e){var _this5=this;_classCallCheck(this,se);var t,s;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.elementRef=se.createContainerElement(),this.messageStyles=Y.processMessageStyles(e.messageStyles),this._remarkable=cs.createNew(e.remarkable),e.avatars&&(this.avatar=new Le(e.avatars)),e.names&&(this.name=new Zt(e.names)),e.browserStorage&&(this.browserStorage=new Zo(e.browserStorage)),this._onMessage=ds.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&&Ts.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||Y.processStreamHTMLWrappers((s=e.connect)==null?void 0:s.stream),setTimeout(function(){_this5.submitUserMessage=e.submitUserMessage;});}return _createClass(se,[{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(se.TEXT_BUBBLE_CLASS),this.applyCustomStyles(n,t,!1),y.fillEmptyMessageElement(n.bubbleElement,e),n;}// prettier-ignore
|
78
|
-
},{key:"overwriteText",value:function overwriteText(e,t,s){var i=y.overwriteMessage(this.messageToElements,s,t,e,"text",se.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);X.scrollToBottom(this.elementRef,n);}return s;}},{key:"createNewGroupElementFocusMode",value:function createNewGroupElementFocusMode(){var t;(t=this._lastGroupMessagesElement)==null||t.classList.remove(se.LAST_GROUP_MESSAGES_ACTIVE);var e=document.createElement("div");this._lastGroupMessagesElement&&e.classList.add(se.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 X.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(se.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
|
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 ds=/*#__PURE__*/function(){function ds(){_classCallCheck(this,ds);}return _createClass(ds,null,[{key:"onMessage",value:function onMessage(e,t,s){var n;var i=JSON.parse(JSON.stringify({message:t,isHistory:s,isInitial:s}));G.reAddFileRefToObject(t,i.message),(n=e.onMessage)==null||n.call(e,i),e.dispatchEvent(new CustomEvent("message",{detail:i})),Y.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&&G.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 H=/*#__PURE__*/function(){function H(){_classCallCheck(this,H);}return _createClass(H,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,f;e.bubbleElement.classList.add(H.CLASS);var i=s?H.FULL_VIEW_CLASS:H.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:(f=(h=(u=(d=t.messageStyles)==null?void 0:d.loading)==null?void 0:u.history)==null?void 0:h.small)==null?void 0:f.styles;H.apply(t,e,n),t.elementRef.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",y.AI_ROLE),s=t.bubbleElement,i=H.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,y.AI_ROLE,!0,!0):H.createDefaultElements(e);return H.addLoadHistoryMessage(i,e,t),y.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(H.FULL_VIEW_CLASS)){t.outerContainer.classList.replace(H.FULL_VIEW_CLASS,H.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&&H.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];H.tryChangeViewToSmall(e,t)||H.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();H.CLASS="loading-history-message",H.FULL_VIEW_CLASS="loading-history-message-full-view",H.SMALL_CLASS="loading-history-message-small";var He=H;var ss=/*#__PURE__*/function(){function ss(){_classCallCheck(this,ss);}return _createClass(ss,null,[{key:"setFade",value:function setFade(e,t){e.style.transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(ss.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:ss.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;}()}]);}();ss.DEFAULT_FADE_MS=500;var As=ss;var fn="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='iso-8859-1'?%3e%3csvg%20fill='%23000000'%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%2032%2032'%20xml:space='preserve'%3e%3cpath%20d='M23,30.36H9c-2.404,0-4.36-1.956-4.36-4.36V15c0-2.404,1.956-4.36,4.36-4.36h3.659%20c0.167-1.566,1.415-2.813,2.981-2.981V5.333c-1.131-0.174-2-1.154-2-2.333c0-1.301,1.059-2.36,2.36-2.36%20c1.302,0,2.36,1.059,2.36,2.36c0,1.179-0.869,2.159-2,2.333V7.66c1.566,0.167,2.814,1.415,2.981,2.981H23%20c2.404,0,4.36,1.956,4.36,4.36v11C27.36,28.404,25.404,30.36,23,30.36z%20M9,11.36c-2.007,0-3.64,1.633-3.64,3.64v11%20c0,2.007,1.633,3.64,3.64,3.64h14c2.007,0,3.64-1.633,3.64-3.64V15c0-2.007-1.633-3.64-3.64-3.64H9z%20M13.384,10.64h5.231%20C18.439,9.354,17.334,8.36,16,8.36C14.667,8.36,13.561,9.354,13.384,10.64z%20M16,1.36c-0.904,0-1.64,0.736-1.64,1.64%20S15.096,4.64,16,4.64c0.904,0,1.64-0.736,1.64-1.64S16.904,1.36,16,1.36z%20M20,27.36h-8c-1.301,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36h8c1.302,0,2.36,1.059,2.36,2.36S21.302,27.36,20,27.36z%20M12,23.36c-0.904,0-1.64,0.735-1.64,1.64%20s0.736,1.64,1.64,1.64h8c0.904,0,1.64-0.735,1.64-1.64s-0.735-1.64-1.64-1.64H12z%20M31,23.86h-2c-0.199,0-0.36-0.161-0.36-0.36V15%20c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5C31.36,23.699,31.199,23.86,31,23.86z%20M29.36,23.14h1.279v-7.78%20H29.36V23.14z%20M3,23.86H1c-0.199,0-0.36-0.161-0.36-0.36V15c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5%20C3.36,23.699,3.199,23.86,3,23.86z%20M1.36,23.14h1.28v-7.78H1.36V23.14z%20M20,20.36c-1.302,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36s2.36,1.059,2.36,2.36C22.36,19.302,21.302,20.36,20,20.36z%20M20,16.36c-0.904,0-1.64,0.736-1.64,1.64%20s0.735,1.64,1.64,1.64s1.64-0.735,1.64-1.64S20.904,16.36,20,16.36z%20M12,20.36c-1.301,0-2.36-1.059-2.36-2.36s1.059-2.36,2.36-2.36%20s2.36,1.059,2.36,2.36C14.36,19.302,13.301,20.36,12,20.36z%20M12,16.36c-0.904,0-1.64,0.736-1.64,1.64s0.736,1.64,1.64,1.64%20s1.64-0.735,1.64-1.64S12.904,16.36,12,16.36z'/%3e%3crect%20style='fill:none;'%20width='32'%20height='32'/%3e%3c/svg%3e",_i="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAMAAAC/MqoPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAADNQTFRF////9vX18vLy/Pz86enp4+Li2tnZ1tbWzczM+fn57Ozs4N/f09LS0M/P5uXl7+/v3dzcwtncCAAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAZNSURBVHja7d3bdtsqEABQYABZSLH9/3+ZpnUsIcF5iOM6PfElNoMHMfPQdq3GmL0GkLhEUqLaUExnOtOZznSmM53pTGc605nOdKYznelMZzrTmV4LXSqllKyJDkob26xWq8Zae/iH0QoWTm9d1xur4WuypQJtTd+5dqn0VjcxzNO5/57mEBvdLo8Oron6aseWOjYOFkVvjQs3DmgyONMuht52EfztP+4hdu0i6LCO808/M8c1lE/fuPGej41uUzgdtoO/75N+2ELJ9I3b3//hPXbiMenm3pR/Jt4USgcLBIp4Bh10gqKVhvLo0klCxeSky96nKcj3siw6pJIL4XsoiQ7apyvMY/V3HHrSRioLopvEhSpTCn2TPEuwKYMOIX0tAxRBf/Hpa+lfSqBv9gi1FPsNfTrMAiVmIE/vJhz61FGnQxRIEYE4vfNYdN8Rp6MlHaHotHTn8ejekaZPAjEmyvQWdZFTtYTpXqCGJ0zvcek9Yfoel76nS0ffv1NMp1ca+pkgyfRCGind4L7OWWc605l+cxjsyhqy9AGbPpClc1/nvl5VX0c/3Alk6RU3+Am7shNZ+h6bvidLr7jBB+zKBrL0irOOudmIUDzTmf5gIP+iEuXtRuTVaEmY/oZLfyNMrzjryPc0gerMTdpVg0tvjJUU6bLPcGOoUv46SLL6Wi8yhLf06C7TUyekI0efRaaYqdFltkeNpPumRPSMDxgBYvSM035FrKAmH72hRW99PrpvSdEHkTEGUvSsK3yKVDkuJ92RohcZaehzzirPpOg+J92Tolfc4Cumx5xVXpGiZ34+ICX6W84qv5GiR5NPbiIpOv6BCoSvSkTX+eiaGP092zINvBOj4x8mSf9FqejvNo/cvpOji19ZbmviL0GPLsYMFzgzCor0+Bv/ePDvSJKOb9dJ5UlnbnEHiHgzv6cdTpJOWuc/u3FEucLDOL75xGtBiefrcwgoC9NDSH/jkH6pAuXmBqPQ9HSUPVdZBH1GGOrMXAQdYxcKZfxAoK+KKBKFLosoEoX+u4giUehz8jlcnAuhp78I46yDYNAd+QLR6K+pr+yvxdBTHyVDubQh0UfSxaHSd0lbvNkVRE87JGOtc+PQd2QLQ6fHhJkKsSh6yg13tO08JPprsgrrXWH0dJd2vH1MLPprot4eXoujpzrdhngiD40ek2y92lggPcnWa8qN1Yz0BFuvZhRl0uOfR0v4Ewuli/Bg4Qr3lArqGdndQ3UPO1EunXYwnelMZzrTmc50pjOd6UxnOtOZznSmM53pTGf6kuj6oedFKV0s3fX6sX1S3bsi6a4PD7+/YAqYeBw6pIB/4qEgOqxdSPbGiim4NRRCbzs3Jj0L4UfXtQXQVRfn5IdA/Bw7RZzurEV6EtdsLeGXkIPuA+K1UoVeA0l62zmN/LqfSSft9KkepmoRuvi3nd5uKNFB9zbbXEANqdr941XO0NJx2v2jdJenpf+/3bvn0ts16ph+sd6hX7dPo2+2cZzE02Ia43bzDHqr+2Evnhz74ZHU30ffbKOeng1/NPV30Ns1gYQnSP2P6e65Pfxc6h02XZqXQCjhJ6kPL6bFo4NrGvAU4UII4SE2P1vQuZkuOxckVfehisF1MjUddN/MZBN+kvq5uf0O/xa66gyNS9ktMWlz44rO1Z8C19i5FPdHzPamXn+F3hryPfxMr78+4F+kq22kO6Rf6fUQt+puuustyWv4rbG3l/duztFB96GYoe1cTBdXMr+nw9qVM6ZfxOvzezff0nXi/ZOndvrR6Zvpm0c3h6nhdb+5iS7tsIim/qXZD9+97/Jf+rpZ5BET1ayv0GUzLhEuhBBjIy/RdVPgndutIRt9nt7p5cKFEEJ3Z+jQFDZL+XnMDXxHB73gxn5s9Kc3d3/pFciFkN/QTSXHJpX5l66gDrkQoP6hL3xsPw39la4qOiV8tH78XeSbue6N9mvWa6J/ybpc1CT1Wnh5Qq9meP8IOKH3ddH7E/ri1iYux/SXDrXR4UiPdck/wUpU+FtPf6/orja6O9KL3l56LOvVxe5Ib2qjN0d6Vbex4ghWlU3bPqI90If66MNng680FNpbJijH6kCvaF3uMzQ3+IrpFerV4Y9dffQdN3im10ivbuImhD3Qq5u4HdZkua8znelMZ/pS4z9CPVKkxowNxgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wMy0yN1QxNTo0NToxNSswMDowMN1xSg4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDMtMjdUMTU6NDU6MTUrMDA6MDCsLPKyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAABJRU5ErkJggg==";var Zn=/*#__PURE__*/function(){function Zn(e){_classCallCheck(this,Zn);this.className=e;}return _createClass(Zn,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e).style).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e).style.visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e).classList.add("role-hidden");}}]);}();var Le=/*#__PURE__*/function(_Zn){function Le(e){var _this3;_classCallCheck(this,Le);_this3=_callSuper(this,Le,["avatar-container"]),_this3._avatars=e;return _this3;}_inherits(Le,_Zn);return _createClass(Le,[{key:"addBesideBubble",value:function addBesideBubble(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===y.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)||_i,s.onerror=Le.errorFallback.bind(this,_i)):(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)||fn,s.onerror=Le.errorFallback.bind(this,fn)),s.classList.add("avatar"),s.alt="".concat(e," avatar");var i=document.createElement("div");return i.classList.add(this.className),i.appendChild(s),t&&Le.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!==y.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===y.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&&Le.applyCustomStylesToElements(e,t,s["default"].styles),i===y.USER_ROLE)(o=s.user)!=null&&o.styles&&Le.applyCustomStylesToElements(e,t,s.user.styles);else{(a=s.ai)!=null&&a.styles&&Le.applyCustomStylesToElements(e,t,s.ai.styles);var c=(l=s[i])==null?void 0:l.styles;c&&Le.applyCustomStylesToElements(e,t,c);}}}]);}(Zn);var Zt=/*#__PURE__*/function(_Zn2){function Zt(e){var _this4;_classCallCheck(this,Zt);_this4=_callSuper(this,Zt,["name"]),_this4._names=e;return _this4;}_inherits(Zt,_Zn2);return _createClass(Zt,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var s=typeof this._names=="boolean"?{}:this._names,i=this.createName(t,s),n=Zt.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=Zt.getNameText(e,t),Zt.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!==y.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===y.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===y.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===y.USER_ROLE?((s=t.user)==null?void 0:s.text)||((i=t["default"])==null?void 0:i.text)||"User":e===y.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;}}]);}(Zn);var se=/*#__PURE__*/function(){function se(e){var _this5=this;_classCallCheck(this,se);var t,s;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.elementRef=se.createContainerElement(),this.messageStyles=Y.processMessageStyles(e.messageStyles),this._remarkable=cs.createNew(e.remarkable),e.avatars&&(this.avatar=new Le(e.avatars)),e.names&&(this.name=new Zt(e.names)),e.browserStorage&&(this.browserStorage=new Zo(e.browserStorage)),this._onMessage=ds.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&&As.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||Y.processStreamHTMLWrappers((s=e.connect)==null?void 0:s.stream),setTimeout(function(){_this5.submitUserMessage=e.submitUserMessage;});}return _createClass(se,[{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(se.TEXT_BUBBLE_CLASS),this.applyCustomStyles(n,t,!1),y.fillEmptyMessageElement(n.bubbleElement,e),n;}// prettier-ignore
|
78
|
+
},{key:"overwriteText",value:function overwriteText(e,t,s){var i=y.overwriteMessage(this.messageToElements,s,t,e,"text",se.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);X.scrollToBottom(this.elementRef,n);}return s;}},{key:"createNewGroupElementFocusMode",value:function createNewGroupElementFocusMode(){var t;(t=this._lastGroupMessagesElement)==null||t.classList.remove(se.LAST_GROUP_MESSAGES_ACTIVE);var e=document.createElement("div");this._lastGroupMessagesElement&&e.classList.add(se.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 X.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(se.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 He.changeFullViewToSmall(this),!s&&se.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:
|
79
79
|
// https://github.com/OvidijusParsiunas/deep-chat/issues/258
|
80
80
|
// prettier-ignore
|
81
|
-
},{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&
|
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(y.getRoleClass(t))&&y.revealRoleElements(s.innerContainer,this.avatar,this.name);}}},{key:"createElements",value:function createElements(e,t){var s=se.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 y.updateRefArr(this.messageElementRefs,i,s),y.classifyRoleMessages(this.messageElementRefs,t),i;}},{key:"addInnerContainerElements",value:// prettier-ignore
|
82
82
|
function addInnerContainerElements(e,t,s){var i=this.messageElementRefs[this.messageElementRefs.length-1];return y.areOuterContainerClassRolesSame(s,i)&&!this.isLastMessageError()&&y.hideRoleElements(i.innerContainer,this.avatar,this.name),e.classList.add("message-bubble",y.getRoleClass(s),s===y.USER_ROLE?"user-message-text":"ai-message-text"),this.renderText(e,t,s),y.addRoleElements(e,s,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
|
83
83
|
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){e&&this.messageStyles&&ee.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=y.getLastMessageBubbleElement(this.elementRef))==null?void 0:e.classList.contains(y.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
84
|
},{key:"renderText",value:function renderText(e,t,s){var _te$tryAddWrapper2=te.tryAddWrapper(e,t,this._customWrappers,s),i=_te$tryAddWrapper2.contentEl,n=_te$tryAddWrapper2.wrapper;n&&te.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=cs.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 se.isLoadingMessage(e)||
|
85
|
+
},{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this7=this;this._remarkable=cs.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 se.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(y.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||y.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(Ue.BUBBLE_CLASS);}}]);}();se.TEXT_BUBBLE_CLASS="text-message",se.INTRO_CLASS="deep-chat-intro",se.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var fe=se;var w=/*#__PURE__*/function(){function w(){_classCallCheck(this,w);}return _createClass(w,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
|
86
86
|
// and if messages have custom roles, it will still look to update the last 'ai' role message
|
87
87
|
// prettier-ignore
|
88
88
|
},{key:"overwriteMessage",value:function overwriteMessage(e,t,s,i,n,o){var a=w.getLastElementsByClass(t,[w.getRoleClass(i),o],[Ue.BUBBLE_CLASS]),l=w.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(w.EMPTY_MESSAGE_CLASS),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e.classList.contains(w.EMPTY_MESSAGE_CLASS)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,s,i
|
89
|
+
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e.classList.add(w.EMPTY_MESSAGE_CLASS),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e.classList.contains(w.EMPTY_MESSAGE_CLASS)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,s,i;return Array.from(((i=(s=(t=w.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:s[0])==null?void 0:i.children)||[]).find(function(n){return n.classList.contains("message-bubble");});}},{key:"getLastMessageElement",value:function getLastMessageElement(e){var s;var t=(s=e.children[e.children.length-1])==null?void 0:s.children;return t==null?void 0:t[t.length-1];}},{key:"addRoleElements",value:function addRoleElements(e,t,s,i){s==null||s.addBesideBubble(e,t),i==null||i.addBesideBubble(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(w.OUTER_CONTAINER_CLASS_ROLE_PREFIX).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$cla;e.outerContainer.classList.remove(w.POSITION_TOP_MESSAGE_CLASS,w.POSITION_MIDDLE_MESSAGE_CLASS,w.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=w.findMessageElements(t,fe.TEXT_BUBBLE_CLASS)),e.html&&(s.html=w.findMessageElements(t,Te.HTML_BUBBLE_CLASS)),e.files&&(s.files=w.filterdMessageElements(t,G.FILE_BUBBLE_CLASS)),s;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var i=w.getNumberOfElements(e),n=s?t.slice(0,i):t.slice(t.length-i);return w.generateMessageBodyElements(e,n);}// if role not present - traverse all, if present - traverse last messages
|
90
90
|
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var s=t?w.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(w.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?w.addNewPositionClasses(n,[w.POSITION_TOP_MESSAGE_CLASS]):c&&d?w.addNewPositionClasses(n,[w.POSITION_MIDDLE_MESSAGE_CLASS]):c&&!d?w.addNewPositionClasses(n,[w.POSITION_BOTTOM_MESSAGE_CLASS]):!c&&!d&&w.addNewPositionClasses(n,[w.POSITION_TOP_MESSAGE_CLASS,w.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(w.OUTER_CONTAINER_CLASS_ROLE_PREFIX);})===w.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(w.ERROR_MESSAGE_TEXT_CLASS)||w.revealRoleElements(n.innerContainer,t,s);var a=Array.from(n.outerContainer.classList).find(function(l){return l.startsWith(w.OUTER_CONTAINER_CLASS_ROLE_PREFIX);});i===a&&w.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
|
91
91
|
// and 'custom' property value if it is not shallow copyable
|
92
92
|
// note - structuredClone can fix this but it doesn't have good legacy compatibility
|
93
|
-
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return w.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 w.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]=w.processMessageContent(i):t[s]=i;}),t;}}]);}();w.AI_ROLE="ai",w.USER_ROLE="user",w.ERROR_MESSAGE_TEXT_CLASS="error-message-text",w.OUTER_CONTAINER_CLASS_ROLE_PREFIX="deep-chat-outer-container-role-",w.EMPTY_MESSAGE_CLASS="empty-message",w.POSITION_TOP_MESSAGE_CLASS="deep-chat-top-message",w.POSITION_MIDDLE_MESSAGE_CLASS="deep-chat-middle-message",w.POSITION_BOTTOM_MESSAGE_CLASS="deep-chat-bottom-message";var y=w;var Ne=/*#__PURE__*/function(){function Ne(e,t){_classCallCheck(this,Ne);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialText="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(Ne,[{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(E.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=X.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(E.INVALID_STREAM_EVENT_MIX);this.updateBasedOnType(t,i,e==null?void 0:e.overwrite);}s&&X.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=y.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):
|
94
|
-
},{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,s,i){e.bubbleElement.innerHTML=i,this._targetWrapper=te.getTargetWrapper(e.bubbleElement),this._elements&&te.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||y.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(Ne.PARTIAL_RENDER_TEXT_MARK);return t===-1?!1:!e.substring(t+Ne.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(E.NO_VALID_STREAM_EVENTS_SENT);(e=this._elements.bubbleElement)!=null&&e.classList.contains(Ne.MESSAGE_CLASS)&&(this._streamType==="text"?this._messages.textToSpeech&&wt.speak(this._message.text||"",this._messages.textToSpeech):this._streamType==="html"&&this._elements&&te.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement.classList.remove(Ne.MESSAGE_CLASS),this._message&&(this._messages.sendClientUpdate(
|
93
|
+
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return w.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 w.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]=w.processMessageContent(i):t[s]=i;}),t;}}]);}();w.AI_ROLE="ai",w.USER_ROLE="user",w.ERROR_MESSAGE_TEXT_CLASS="error-message-text",w.OUTER_CONTAINER_CLASS_ROLE_PREFIX="deep-chat-outer-container-role-",w.EMPTY_MESSAGE_CLASS="empty-message",w.POSITION_TOP_MESSAGE_CLASS="deep-chat-top-message",w.POSITION_MIDDLE_MESSAGE_CLASS="deep-chat-middle-message",w.POSITION_BOTTOM_MESSAGE_CLASS="deep-chat-bottom-message";var y=w;var Ne=/*#__PURE__*/function(){function Ne(e,t){_classCallCheck(this,Ne);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialText="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(Ne,[{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(E.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=X.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(E.INVALID_STREAM_EVENT_MIX);this.updateBasedOnType(t,i,e==null?void 0:e.overwrite);}s&&X.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=y.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(Ne.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 htmlUtils htmlWrappers logic to be able to stream html
|
94
|
+
},{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,s,i){e.bubbleElement.innerHTML=i,this._targetWrapper=te.getTargetWrapper(e.bubbleElement),this._elements&&te.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||y.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(Ne.PARTIAL_RENDER_TEXT_MARK);return t===-1?!1:!e.substring(t+Ne.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(E.NO_VALID_STREAM_EVENTS_SENT);(e=this._elements.bubbleElement)!=null&&e.classList.contains(Ne.MESSAGE_CLASS)&&(this._streamType==="text"?this._messages.textToSpeech&&wt.speak(this._message.text||"",this._messages.textToSpeech):this._streamType==="html"&&this._elements&&te.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement.classList.remove(Ne.MESSAGE_CLASS),this._message&&(this._messages.sendClientUpdate(fe.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;}// prettier-ignore
|
95
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;}()}]);}();Ne.MESSAGE_CLASS="streamed-message",Ne.PARTIAL_RENDER_TEXT_MARK="\n\n";var Re=Ne;var Ge=/*#__PURE__*/function(){function Ge(){_classCallCheck(this,Ge);}return _createClass(Ge,null,[{key:"tempRemoveContentHeader",value:// need to pass stringifyBody boolean separately as binding is throwing an error for some reason
|
96
96
|
// prettier-ignore
|
97
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[Ge.CONTENT_TYPE];delete e.headers[Ge.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[Ge.CONTENT_TYPE]=i,_t2;case 5:return _context3.a(2,(e.headers[Ge.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
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(E.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=E.INVALID_RESPONSE(t,"response",!!a,l);Ge.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;}()}]);}();Ge.CONTENT_TYPE="Content-Type";var S=Ge;function Qo(_x14,_x15){return _Qo.apply(this,arguments);}function _Qo(){_Qo=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
100
|
-
function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,s){var i,n,h,
|
101
|
-
},{key:"handleReadableStream",value:function handleReadableStream(e,t,s,i,n,o){var u;var _e$streamHandlers=e.streamHandlers,a=_e$streamHandlers.onOpen,l=_e$streamHandlers.onClose,c=_e$streamHandlers.abortStream;var d=!1;fetch(((u=e.connectSettings)==null?void 0:u.url)||e.url||"",i).then(/*#__PURE__*/function(){var _ref7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(h){var g,v,
|
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=E.INVALID_RESPONSE(t,"response",!!a,l);Ge.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;}()}]);}();Ge.CONTENT_TYPE="Content-Type";var S=Ge;function Qo(_x14,_x15){return _Qo.apply(this,arguments);}function _Qo(){_Qo=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee176(r,e){var t,s;return _regenerator().w(function(_context176){while(1)switch(_context176.n){case 0:t=r.getReader();case 1:_context176.n=2;return t.read();case 2:if((s=_context176.v).done){_context176.n=4;break;}e(s.value);case 3:_context176.n=1;break;case 4:return _context176.a(2);}},_callee176);}));return _Qo.apply(this,arguments);}function ea(r){var e,t,s,i=!1;return function(o){e===void 0?(e=o,t=0,s=-1):e=sa(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 ta(r,e,t){var s=pn();var i=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(s),s=pn();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 sa(r,e){var t=new Uint8Array(r.length+e.length);return t.set(r),t.set(e,r.length),t;}function pn(){return{data:"",event:"",id:"",retry:void 0};}var ia=function ia(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 Si="text/event-stream",na=1e3,mn="last-event-id";function ra(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=ia(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(u,h){var f=Object.assign({},s);f.accept||(f.accept=Si);var m;function p(){m.abort(),document.hidden||V();}l||document.addEventListener("visibilitychange",p);var g=na,v=0;function R(){document.removeEventListener("visibilitychange",p),window.clearTimeout(v),m.abort();}t==null||t.addEventListener("abort",function(){R(),u();});var O=c!==null&&c!==void 0?c:window.fetch,I=i!==null&&i!==void 0?i:oa;function V(){return _V.apply(this,arguments);}function _V(){_V=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var xe,ze,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 O(r,Object.assign(Object.assign({},d),{headers:f,signal:m.signal}));case 2:ze=_context6.v;_context6.n=3;return I(ze);case 3:_context6.n=4;return Qo(ze.body,ea(ta(function(re){re?f[mn]=re:delete f[mn];},function(re){g=re;},n)));case 4:o==null||o();R();u();_context6.n=6;break;case 5:_context6.p=5;_t5=_context6.v;if(!m.signal.aborted)try{re=(xe=a==null?void 0:a(_t5))!==null&&xe!==void 0?xe:g;window.clearTimeout(v),v=window.setTimeout(V,re);}catch(re){R(),h(re);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _V.apply(this,arguments);}V();});}function oa(r){var e=r.headers.get("content-type");if(!(e!=null&&e.startsWith(Si)))throw new Error("Expected content-type to be ".concat(Si,", 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,h,f,m,p,g,o,_yield$S$processReque,a,l,c,d,u,_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:(h=e.connectSettings)==null?void 0:h.headers};_context7.n=1;return S.processRequestInterceptor(e.deepChat,o);case 1:_yield$S$processReque=_context7.v;a=_yield$S$processReque.body;l=_yield$S$processReque.headers;c=_yield$S$processReque.error;if(!c){_context7.n=2;break;}return _context7.a(2,S.onInterceptorError(s,c,e.streamHandlers.onClose));case 2:if(!((f=e.connectSettings)!=null&&f.handler)){_context7.n=3;break;}return _context7.a(2,Ee.stream(e,a,s));case 3:if(!(((m=e.connectSettings)==null?void 0:m.url)===Se.URL)){_context7.n=4;break;}return _context7.a(2,Se.requestStream(s,e));case 4:d=new Re(s,e.stream),u={method:((p=e.connectSettings)==null?void 0:p.method)||"POST",headers:l,credentials:(g=e.connectSettings)==null?void 0:g.credentials,body:i?JSON.stringify(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?_.handleReadableStream(e,s,d,u,n,a):_.handleEventStream(e,s,d,u,n,a),d));}},_callee7);}));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){var u;var _e$streamHandlers=e.streamHandlers,a=_e$streamHandlers.onOpen,l=_e$streamHandlers.onClose,c=_e$streamHandlers.abortStream;var d=!1;fetch(((u=e.connectSettings)==null?void 0:u.url)||e.url||"",i).then(/*#__PURE__*/function(){var _ref7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(h){var g,v,f,m,p,_yield$f$read,R,O,I,V,xe,_t6;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(h.body){_context8.n=1;break;}throw new Error(E.READABLE_STREAM_CONNECTION_ERROR);case 1:f=h.body.getReader(),m=new TextDecoder();a();p=!1;case 2:if(!(!p&&!d)){_context8.n=8;break;}_context8.n=3;return f.read();case 3:_yield$f$read=_context8.v;R=_yield$f$read.value;O=_yield$f$read.done;if(!(p=O,p)){_context8.n=4;break;}_.handleClose(e,s,l,n);_context8.n=7;break;case 4:I=m.decode(R,{stream:!0});_context8.n=5;return(v=(g=e.deepChat).responseInterceptor)==null?void 0:v.call(g,I);case 5:_t6=_context8.v;if(_t6){_context8.n=6;break;}_t6=I;case 6:V=_t6;xe=_typeof(V)=="object"?V:{text:I};_.handleMessage(e,t,s,xe,o);case 7:_context8.n=2;break;case 8:return _context8.a(2);}},_callee8);}));return function(_x19){return _ref7.apply(this,arguments);};}())["catch"](function(h){_.handleError(e,t,h);}),c.abort=function(){d=!0;};}// prettier-ignore
|
102
102
|
},{key:"handleEventStream",value:function handleEventStream(e,t,s,i,n,o){var d;var _e$streamHandlers2=e.streamHandlers,a=_e$streamHandlers2.onOpen,l=_e$streamHandlers2.onClose,c=_e$streamHandlers2.abortStream;ra(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",_objectSpread(_objectSpread({},i),{},{openWhenHidden:!0,// keep stream open when browser tab not open
|
103
|
-
onopen:function onopen(u){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(){return _regenerator().w(function(_context9){while(1)switch(_context9.n){case 0:if(!u.ok){_context9.n=1;break;}return _context9.a(2,a());case 1:_context9.n=2;return S.processResponseByType(u);case 2:throw _context9.v;case 3:return _context9.a(2);}},_callee9);}))();},onmessage:function onmessage(u){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(){var h,
|
104
|
-
},{key:"handleMessage",value:function handleMessage(e,t,s,i,n){var o;(o=e.extractResultData)==null||o.call(e,i,n).then(function(a){_.
|
103
|
+
onopen:function onopen(u){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(){return _regenerator().w(function(_context9){while(1)switch(_context9.n){case 0:if(!u.ok){_context9.n=1;break;}return _context9.a(2,a());case 1:_context9.n=2;return S.processResponseByType(u);case 2:throw _context9.v;case 3:return _context9.a(2);}},_callee9);}))();},onmessage:function onmessage(u){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(){var h,f,m,p,_t7;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(JSON.stringify(u.data)!==JSON.stringify("[DONE]"))){_context0.n=3;break;}try{m=JSON.parse(u.data);}catch(_unused6){m={};}_context0.n=1;return(f=(h=e.deepChat).responseInterceptor)==null?void 0:f.call(h,m);case 1:_t7=_context0.v;if(_t7){_context0.n=2;break;}_t7=m;case 2:p=_t7;_.handleMessage(e,t,s,p,o);case 3:return _context0.a(2);}},_callee0);}))();},onerror:function onerror(u){throw l(),u;},onclose:function onclose(){_.handleClose(e,s,l,n);},signal:c.signal}))["catch"](function(u){_.handleError(e,t,u);});}//prettier-ignore
|
104
|
+
},{key:"handleMessage",value:function handleMessage(e,t,s,i,n){var o;(o=e.extractResultData)==null||o.call(e,i,n).then(function(a){_.upsertContent(t,s.upsertStreamedMessage.bind(s),s,a);})["catch"](function(a){return S.displayError(t,a);});}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
105
105
|
},{key:"handleError",value:function handleError(e,t,s){var i;t.isLastMessageError()||(i=e.extractResultData)==null||i.call(e,s).then(function(){S.displayError(t,s);})["catch"](function(n){S.displayError(t,n);});}},{key:"handleClose",value:function handleClose(e,t,s,i){if(e.asyncCallInProgress){e.asyncCallInProgress=!1;return;}try{t.finaliseStreamedMessage(),s();}catch(n){if(!i)throw n;}}// io is only passed for demo to simulate a real stream
|
106
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 S.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 S.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 Re(e,i==null?void 0:i.stream);_.populateMessages(e,_o2,a,n,"text",0,i);}if(s.html){t.onOpen();_o3=te.splitHTML(s.html);_o3.length===0&&(_o3=s.html.split(""));_a2=new Re(e,i==null?void 0:i.stream);_.populateMessages(e,_o3,_a2,n,"html",0,i);}s.error&&(S.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
|
107
107
|
// io is only passed for demo to simulate a real stream
|
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 S.basicResponseProcessing(e,_defineProperty({},n,l),{io:a});case 1:c=_context10.v;_.
|
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 S.basicResponseProcessing(e,_defineProperty({},n,l),{io:a});case 1:c=_context10.v;_.upsertContent(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:"upsertContent",value:function upsertContent(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 rt=/*#__PURE__*/function(){function rt(){_classCallCheck(this,rt);}return _createClass(rt,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?rt.getCustomResponse(e,t[t.length-1][0]):{text:rt.generateResponse(t)};}// timeout is used to simulate a timeout for a response to come back
|
109
109
|
},{key:"request",value:function request(e,t){var s=rt.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 S.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=rt.getResponse(e);_.simulate(e,t.streamHandlers,s,t);},400);}}]);}();rt.URL="deep-chat-demo";var Se=rt;var $=/*#__PURE__*/function(){function $(){_classCallCheck(this,$);}return _createClass($,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(!$.isElementPresentInDOM(e.deepChat))return;var s=e.connectSettings.websocket;if(s){if(e.connectSettings.handler)return Ee.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"&&$.assignListeners(e,n,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console.error(o),$.retryConnection(e,t);};}catch(i){console.error(i),$.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var s,i;(i=(s=e.deepChat)._validationHandler)==null||i.call(s),$.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage("service","Connection error"),setTimeout(function(){$.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 S.basicResponseProcessing(s,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(E.INVALID_RESPONSE(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!_.isSimulation(e.stream)){_context12.n=4;break;}l=$.stream.bind(_this8,e,s,i),c=i[o.role||y.AI_ROLE];_.
|
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||y.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 Re(t,e.stream),s[o].upsertStreamedMessage(i));}else _.simulate(t,e.streamHandlers,i);}}]);}();var Ee=/*#__PURE__*/function(){function Ee(){_classCallCheck(this,Ee);}return _createClass(Ee,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 S.basicResponseProcessing(s,c,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console.error(E.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(
|
112
|
-
},{key:"stream",value:function stream(e,t,s){var u,h;var i=!0,n=!1;var o=new Re(s,e.stream),a=function a(){n||!i||(e.streamHandlers.onOpen(),n=!0);},l=function l(){i&&(Ee.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1);},c=/*#__PURE__*/function(){var _ref10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(
|
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,
|
114
|
-
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,s){var i,u,h,
|
115
|
-
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,s){var i,
|
116
|
-
},{key:"verifyKey",value:function verifyKey(e,t,s,i,n,o,a,l,c){if(e==="")return o(E.INVALID_KEY);a(),fetch(t,{method:i,headers:s,body:c||null}).then(function(d){return S.processResponseByType(d);}).then(function(d){l(d,e,n,o);})["catch"](function(d){o(E.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=
|
110
|
+
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var s=rt.getResponse(e);_.simulate(e,t.streamHandlers,s,t);},400);}}]);}();rt.URL="deep-chat-demo";var Se=rt;var $=/*#__PURE__*/function(){function $(){_classCallCheck(this,$);}return _createClass($,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(!$.isElementPresentInDOM(e.deepChat))return;var s=e.connectSettings.websocket;if(s){if(e.connectSettings.handler)return Ee.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"&&$.assignListeners(e,n,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console.error(o),$.retryConnection(e,t);};}catch(i){console.error(i),$.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var s,i;(i=(s=e.deepChat)._validationHandler)==null||i.call(s),$.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage("service","Connection error"),setTimeout(function(){$.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 S.basicResponseProcessing(s,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(E.INVALID_RESPONSE(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!_.isSimulation(e.stream)){_context12.n=4;break;}l=$.stream.bind(_this8,e,s,i),c=i[o.role||y.AI_ROLE];_.upsertContent(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;S.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(),$.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$S$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)===Se.URL)){_context13.n=1;break;}return _context13.a(2,Se.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 S.processRequestInterceptor(e.deepChat,o);case 3:_yield$S$processReque2=_context13.v;a=_yield$S$processReque2.body;l=_yield$S$processReque2.error;if(!l){_context13.n=4;break;}return _context13.a(2,s.addNewErrorMessage("service",l));case 4:if($.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:$.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||y.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 Re(t,e.stream),s[o].upsertStreamedMessage(i));}else _.simulate(t,e.streamHandlers,i);}}]);}();var Ee=/*#__PURE__*/function(){function Ee(){_classCallCheck(this,Ee);}return _createClass(Ee,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 S.basicResponseProcessing(s,c,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console.error(E.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(f){return typeof f.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(f){return s.addNewMessage(f);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function n(_x38){return _ref1.apply(this,arguments);};}(),o=Ee.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];fe.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 Re(s,e.stream),a=function a(){n||!i||(e.streamHandlers.onOpen(),n=!0);},l=function l(){i&&(Ee.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1);},c=/*#__PURE__*/function(){var _ref10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(f){var m,p;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 S.basicResponseProcessing(s,f,{io:e,displayError:!1});case 2:m=_context16.v;if(m)m.error?(Ee.streamError(m.error,o,e,s),i=!1):_.upsertContent(s,o.upsertStreamedMessage.bind(o),o,m);else{p=E.INVALID_RESPONSE(f,"server",!!e.deepChat.responseInterceptor,m);Ee.streamError(p,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(){Ee.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1;};var d=Ee.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,f,m,p,g;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:_context17.n=1;return S.basicResponseProcessing(t,d,{io:e,displayError:!1});case 1:u=_context17.v;if(!u)console.error(E.INVALID_RESPONSE(d,"server",!!e.deepChat.responseInterceptor,u)),t.addNewErrorMessage("service","Error in server message");else{h=Array.isArray(u)?u:[u],f=h.find(function(m){return typeof m.error=="string";});if(f)console.error(f.error),t.isLastMessageError()||t.addNewErrorMessage("service",f.error);else if(_.isSimulation(e.stream)){m=u,p=$.stream.bind(_this9,e,t,s.roleToStream),g=s.roleToStream[m.role||y.AI_ROLE];_.upsertContent(t,p,g,m);}else h.forEach(function(m){return t.addNewMessage(m);});}case 2:return _context17.a(2);}},_callee17);}));return function o(_x40){return _ref11.apply(this,arguments);};}(),a=Ee.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 C=/*#__PURE__*/function(){function C(){_classCallCheck(this,C);}return _createClass(C,null,[{key:"request",value:// prettier-ignore
|
114
|
+
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,s){var i,u,h,f,n,_yield$S$processReque3,o,a,l,c,d,_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:(u=e.connectSettings)==null?void 0:u.headers};_context19.n=1;return S.processRequestInterceptor(e.deepChat,n);case 1:_yield$S$processReque3=_context19.v;o=_yield$S$processReque3.body;a=_yield$S$processReque3.headers;l=_yield$S$processReque3.error;c=e.completionsHandlers.onFinish;if(!l){_context19.n=2;break;}return _context19.a(2,S.onInterceptorError(s,l,c));case 2:if(!((h=e.connectSettings)!=null&&h.handler)){_context19.n=3;break;}return _context19.a(2,Ee.request(e,o,s));case 3:if(!(((f=e.connectSettings)==null?void 0:f.url)===Se.URL)){_context19.n=4;break;}return _context19.a(2,Se.request(e,s));case 4:d=!0;S.fetch(e,a,i,o).then(function(m){return d=!!m.ok,m;}).then(function(m){return S.processResponseByType(m);}).then(/*#__PURE__*/function(){var _ref12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(m){var v,R,p,g,_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(R=(v=e.deepChat).responseInterceptor)==null?void 0:R.call(v,m);case 2:_t9=_context18.v;if(_t9){_context18.n=3;break;}_t9=m;case 3:p=_t9;_context18.n=4;return e.extractResultData(p,o);case 4:g=_context18.v;if(d){_context18.n=5;break;}throw m;case 5:if(!(!g||_typeof(g)!="object"&&!Array.isArray(g))){_context18.n=6;break;}throw Error(E.INVALID_RESPONSE(m,"response",!!e.deepChat.responseInterceptor,p));case 6:if(!e.asyncCallInProgress){_context18.n=7;break;}e.asyncCallInProgress=!1;return _context18.a(2);case 7:_.isSimulatable(e.stream,g)?_.simulate(s,e.streamHandlers,g):((Array.isArray(g)?g:[g]).forEach(function(I){return s.addNewMessage(I);}),c());case 8:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref12.apply(this,arguments);};}())["catch"](function(m){S.displayError(s,m),c();});case 5:return _context19.a(2);}},_callee19);}));function request(_x41,_x42,_x43){return _request3.apply(this,arguments);}return request;}()},{key:"executePollRequest",value:function executePollRequest(e,t,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(){C.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){S.displayError(i,o),n();});}// prettier-ignore
|
115
|
+
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,s){var i,f,m,p,n,_yield$S$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:(f=e.connectSettings)==null?void 0:f.headers};_context21.n=1;return S.processRequestInterceptor(e.deepChat,n);case 1:_yield$S$processReque4=_context21.v;o=_yield$S$processReque4.body;a=_yield$S$processReque4.headers;l=_yield$S$processReque4.error;if(!l){_context21.n=2;break;}return _context21.a(2,S.onInterceptorError(s,l));case 2:c=((m=e.connectSettings)==null?void 0:m.url)||e.url||"",d=((p=e.connectSettings)==null?void 0:p.method)||"POST",u=i?JSON.stringify(o):o,h={method:d,body:u,headers:a};e.connectSettings.credentials&&(h.credentials=e.connectSettings.credentials),C.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(E.INVALID_KEY);a(),fetch(t,{method:i,headers:s,body:c||null}).then(function(d){return S.processResponseByType(d);}).then(function(d){l(d,e,n,o);})["catch"](function(d){o(E.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=He.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 X.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(fe.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=y.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;y.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=He.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){Y.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=He.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 X.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||Y.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(fe.INTRO_CLASS))s.outerContainer.style.display="";else break;}}}]);}();Ke.FAILED_ERROR_MESSAGE="Failed to load history";var hs=Ke;var K=/*#__PURE__*/function(){function K(){_classCallCheck(this,K);}return _createClass(K,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
|
117
117
|
// if maxMessages above 0 we send that number
|
118
118
|
// if maxMessages 0 or below we send only what is in the request
|
119
119
|
},{key:"processMessages",value:function processMessages(e,t,s){return t!==void 0?t>0&&(e=K.getMaxMessages(e,t)):e=[e[e.length-1]],e=JSON.parse(JSON.stringify(e)),s===void 0?e:K.getCharacterLimitMessages(e,s);}}]);}();var j=/*#__PURE__*/function(){function j(){_classCallCheck(this,j);}return _createClass(j,null,[{key:"parseConfig",value:// prettier-ignore
|
@@ -125,43 +125,43 @@ function parseConfig(e,t,s,i){var o;var n={files:t};if(_typeof(i)=="object"){Y.p
|
|
125
125
|
// prettier-ignore
|
126
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=j.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=j.parseConfig(e.connectSettings,o,t,s)));}// prettier-ignore
|
127
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=j.parseConfig(e.connectSettings,o,t,s);}// default for direct service
|
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){j.populateDefaultFileIO(s==null?void 0:s.audio,".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),j.populateDefaultFileIO(s==null?void 0:s.images,".png,.jpg");var i=cs.createNew(e.remarkable);j.processImagesConfig(t,i,e.images,s==null?void 0:s.images),j.processCamera(t,i,e.camera,e.images),j.processGifConfig(t,i,e.gifs,s==null?void 0:s.gifs),j.processAudioConfig(t,i,e.audio,s==null?void 0:s.audio),j.processMicrophone(t,i,e.microphone,e.audio),j.processMixedFiles(t,i,e.mixedFiles);}}]);}();var
|
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=K.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!==Se.URL)){n=_objectSpread({messages:s},this.rawBody);e.files&&(i=this.getServiceIOByType(e.files[0]))!=null&&i.connect?this.callApiWithFiles(t,s,e.files):$.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,Y.handleResponseProperty(e));case 1:if(!S.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 M=/*#__PURE__*/function(
|
130
|
-
function M(e,t,s,i,n){var _this13;_classCallCheck(this,M);var o;_this13=_callSuper(this,M,[e,n]),_this13.insertKeyPlaceholderText="API Key",_this13.keyHelpUrl="",_this13.asyncCallInProgress=!1,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(M,
|
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;
|
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){j.populateDefaultFileIO(s==null?void 0:s.audio,".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),j.populateDefaultFileIO(s==null?void 0:s.images,".png,.jpg");var i=cs.createNew(e.remarkable);j.processImagesConfig(t,i,e.images,s==null?void 0:s.images),j.processCamera(t,i,e.camera,e.images),j.processGifConfig(t,i,e.gifs,s==null?void 0:s.gifs),j.processAudioConfig(t,i,e.audio,s==null?void 0:s.audio),j.processMicrophone(t,i,e.microphone,e.audio),j.processMixedFiles(t,i,e.mixedFiles);}}]);}();var ft=/*#__PURE__*/function(){function ft(e,t,s){var _a$url;_classCallCheck(this,ft);var i,n,o,a,l;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=ft.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,j.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=Se.URL),this.connectSettings.websocket&&$.setup(this),this.stream=((l=this.deepChat.connect)==null?void 0:l.stream)||Y.checkForStream(this.deepChat),e.loadHistory&&hs.addErrorPrefix(this);}return _createClass(ft,[{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):C.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=ft.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=K.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!==Se.URL)){n=_objectSpread({messages:s},this.rawBody);e.files&&(i=this.getServiceIOByType(e.files[0]))!=null&&i.connect?this.callApiWithFiles(t,s,e.files):$.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,Y.handleResponseProperty(e));case 1:if(!S.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 M=/*#__PURE__*/function(_ft){// prettier-ignore
|
130
|
+
function M(e,t,s,i,n){var _this13;_classCallCheck(this,M);var o;_this13=_callSuper(this,M,[e,n]),_this13.insertKeyPlaceholderText="API Key",_this13.keyHelpUrl="",_this13.asyncCallInProgress=!1,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(M,_ft);return _createClass(M,[{key:"setApiKeyProperties",value:function setApiKeyProperties(e){this.key=e.key,e.validateKeyProperty&&(this.validateKeyProperty=e.validateKeyProperty);}},{key:"buildConnectSettings",value:function buildConnectSettings(e,t){var _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;C.verifyKey(e,d,c,i,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,n,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}},{key:"callToolFunction",value:function(){var _callToolFunction=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(e,t){var n,o,s,a,l,_t13,_t14;return _regenerator().w(function(_context33){while(1)switch(_context33.n){case 0:this.asyncCallInProgress=!0;_context33.n=1;return e(t);case 1:s=_context33.v;if(Array.isArray(s)){_context33.n=6;break;}if(!s.text){_context33.n=5;break;}a={text:s.text};_context33.n=2;return(o=(n=this.deepChat).responseInterceptor)==null?void 0:o.call(n,a);case 2:_t13=_context33.v;if(_t13){_context33.n=3;break;}_t13=a;case 3:l=_t13;if(!Array.isArray(l)){_context33.n=4;break;}throw Error("Function tool response interceptor cannot return an array");case 4:return _context33.a(2,{processedResponse:l});case 5:throw Error("Function tool response must be an array or contain a text property");case 6:_context33.n=7;return Promise.all(s);case 7:_t14=_context33.v;return _context33.a(2,{responses:_t14});}},_callee33,this);}));function callToolFunction(_x66,_x67){return _callToolFunction.apply(this,arguments);}return callToolFunction;}()},{key:"makeAnotherRequest",value:function makeAnotherRequest(e,t){try{return t&&(this.stream?_.request(this,e,t):C.request(this,e,t)),{text:""};}catch(s){throw this.asyncCallInProgress=!1,s;}}}]);}(ft);var Rs=/*#__PURE__*/function(){function Rs(){_classCallCheck(this,Rs);}return _createClass(Rs,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?Rs.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,Rs.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var Pe=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
|
132
132
|
function Pe(){var _this14;_classCallCheck(this,Pe);_this14=_callSuper(this,Pe),_this14._waitingToRender_=!1,_this14._propUpdated_=!1,Object.keys(Pe._attributeToProperty_).forEach(function(e){var t=Pe._attributeToProperty_[e];_this14.constructPropertyAccessors(t),_this14.hasOwnProperty(e)||_this14.constructPropertyAccessors(t,e);});return _this14;}_inherits(Pe,_HTMLElement);return _createClass(Pe,[{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:Rs.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,s){if(t===s)return;var i=Pe._attributes_[e](s),n=Pe._attributeToProperty_[e];this[n]=i;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(Pe._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));Pe._attributes_={},Pe._attributeToProperty_={};var xi=Pe;var aa="<?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",la="<?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
|
134
|
-
function changeVisibility(e,t,s,i){i.target.id===Je.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=
|
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:Rs.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,s){if(t===s)return;var i=Pe._attributes_[e](s),n=Pe._attributeToProperty_[e];this[n]=i;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(Pe._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));Pe._attributes_={},Pe._attributeToProperty_={};var xi=Pe;var aa="<?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",la="<?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 qe=/*#__PURE__*/function(){function qe(){_classCallCheck(this,qe);}return _createClass(qe,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Je=/*#__PURE__*/function(){function Je(){_classCallCheck(this,Je);}return _createClass(Je,null,[{key:"changeVisibility",value:// prettier-ignore
|
134
|
+
function changeVisibility(e,t,s,i){i.target.id===Je.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=qe.createSVGElement(e);return s.id=t,s.classList.add("visibility-icon"),s;}// prettier-ignore
|
135
135
|
},{key:"create",value:function create(e){var t=document.createElement("div");t.id="visibility-icon-container";var s=Je.createIconElement(la,Je.VISIBLE_ICON_ID);s.style.display="none",t.appendChild(s);var i=Je.createIconElement(aa,"not-visible-icon");return t.appendChild(i),t.onclick=Je.changeVisibility.bind(this,e,s,i),t;}}]);}();Je.VISIBLE_ICON_ID="visible-icon";var wi=Je;var Z=/*#__PURE__*/function(){function Z(){_classCallCheck(this,Z);}return _createClass(Z,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=Z.createFailText();if(i.appendChild(n),e){var o=Z.createHelpLink(e);i.appendChild(o);}if(t===!0){var _o4=Z.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
|
136
136
|
},{key:"verifyKey",value:function verifyKey(e,t,s){var i=e.value.trim();s.verifyKey(i,t);}// prettier-ignore
|
137
|
-
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,s,i,n){var o={onSuccess:i,onFail:Z.onFail.bind(this,e,t,s),onLoad:Z.onLoad.bind(this,e,t)},a=Z.verifyKey.bind(this,e,o,n);t.onclick=a,e.onkeydown=function(l){!e.classList.contains("loading")&&l.key===
|
137
|
+
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,s,i,n){var o={onSuccess:i,onFail:Z.onFail.bind(this,e,t,s),onLoad:Z.onLoad.bind(this,e,t)},a=Z.verifyKey.bind(this,e,o,n);t.onclick=a,e.onkeydown=function(l){!e.classList.contains("loading")&&l.key===q.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=Z.onInputFocus,t.appendChild(s),t;}// prettier-ignore
|
138
138
|
},{key:"createContents",value:function createContents(e,t){var d;var s=document.createElement("div");s.id="insert-key-contents";var i=Z.createInput(t.insertKeyPlaceholderText),n=i.children[0],o=wi.create(n);i.appendChild(o),s.appendChild(i);var a=Z.createStartButton(),_Z$createHelpTextCont=Z.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),l=_Z$createHelpTextCont.helpTextContainerElement,c=_Z$createHelpTextCont.failTextElement;return s.appendChild(a),s.appendChild(l),Z.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=Z.createContents(e,t);return s.appendChild(i),s;}},{key:"render",value:function render(e,t,s){var i=Z.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<us.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return oe.enableButtons(e,t,s+1);},250);}// prettier-ignore
|
139
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
|
140
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 Ms=oe;var gn={model_list:[// Llama-2
|
141
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
|
142
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
|
143
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
|
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},k=/*#__PURE__*/function(
|
145
|
-
_inherits(k,
|
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},k=/*#__PURE__*/function(_ft2){function k(e){var _this15;_classCallCheck(this,k);var t,s;_this15=_callSuper(this,k,[e]),_this15._isModelLoaded=!1,_this15._isModelLoading=!1,_this15._loadOnFirstMessage=!1,_this15._webModel={},_this15.permittedErrorPrefixes=[k.MULTIPLE_MODELS_ERROR,k.WEB_LLM_NOT_FOUND_ERROR,k.GENERIC_ERROR],_this15._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this15._webModel=e.webModel),(t=_this15._webModel.load)!=null&&t.clearCache&&k.clearAllCache(),_this15.findModelInWindow(e),_this15.canSendMessage=_this15.canSubmit.bind(_assertThisInitialized(_this15)),_this15._chatEl=(s=e.shadowRoot)==null?void 0:s.children[0],e.history&&k.setUpHistory(_this15._conversationHistory,e.history);return _this15;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
|
145
|
+
_inherits(k,_ft2);return _createClass(k,[{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>k.MODULE_SEARCH_LIMIT_S?((s=this._messages)==null||s.addNewErrorMessage("service",k.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&&X.scrollToTop((i=_this18._messages)==null?void 0:i.elementRef);},e);}// prettier-ignore
|
146
146
|
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Ms.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:y.AI_ROLE,html:t,sendUpdate:!1};}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(e){var t;return _regenerator().w(function(_context34){while(1)switch(_context34.n){case 0:t=this._webModel.load;if(!t){_context34.n=2;break;}if(!t.onInit){_context34.n=1;break;}this.init();return _context34.a(2);case 1:if(!t.onMessage){_context34.n=2;break;}this._loadOnFirstMessage=!0;return _context34.a(2);case 2:e||this.init();case 3:return _context34.a(2);}},_callee34,this);}));function configureInit(_x68){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(e){var s,t,_t15;return _regenerator().w(function(_context35){while(1)switch(_context35.n){case 0:(s=this._messages)==null||s.removeError();t=this.attemptToCreateChat();_t15=t;if(!_t15){_context35.n=1;break;}_context35.n=1;return this.loadModel(t,e);case 1:return _context35.a(2);}},_callee35,this);}));function init(_x69){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var t;if(k.chat){(t=this._messages)==null||t.addNewErrorMessage("service",k.MULTIPLE_MODELS_ERROR),console.error(k.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return gn.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var s;var e=k.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=JSON.parse(JSON.stringify(gn));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 _callee36(e,t){var _this19=this;var o,a,l,c,d,u,h,s,i,n,_this$getConfig,
|
147
|
+
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(e,t){var _this19=this;var o,a,l,c,d,u,h,s,i,n,_this$getConfig,f,m,p,_f,_t16;return _regenerator().w(function(_context36){while(1)switch(_context36.p=_context36.n){case 0:this.scrollToTop(),k.chat=e,this._isModelLoading=!0;s=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;i=function i(f){var m;(m=_this19._messages)==null||m.addNewMessage({html:"<div>".concat(f.text,"</div>"),overwrite:!0,sendUpdate:!1}),s&&(setTimeout(function(){var p;return X.scrollToBottom((p=_this19._messages)==null?void 0:p.elementRef);}),s=!1);};k.chat.setInitProgressCallback(i);_context36.p=1;_this$getConfig=this.getConfig(),f=_this$getConfig.model,m=_this$getConfig.appConfig,p={};this._webModel.instruction&&(p.conv_config={system:this._webModel.instruction});this._conversationHistory.length>0&&(p.conversation_history=this._conversationHistory);_context36.n=2;return k.chat.reload(f,p,m,t);case 2:n=_context36.v;_context36.n=4;break;case 3:_context36.p=3;_t16=_context36.v;return _context36.a(2,this.unloadChat(_t16));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{_f=Ms.setUpAfterLoad(n,this._webModel.introMessage,this._chatEl,!!this._webModel.worker);(d=this._messages)==null||d.addNewMessage({html:_f,overwrite:!0,sendUpdate:!1});}this._isModelLoaded=!0,this._isModelLoading=!1;case 5:return _context36.a(2);}},_callee36,this,[[1,3]]);}));function loadModel(_x70,_x71){return _loadModel.apply(this,arguments);}return loadModel;}()},{key:"unloadChat",value:function(){var _unloadChat=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e){var t,_t17;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:(t=this._messages)==null||t.addNewErrorMessage("service",k.GENERIC_ERROR);console.error(e);this._isModelLoaded=!1;this._isModelLoading=!1;_t17=k.chat;if(!_t17){_context37.n=2;break;}_context37.n=1;return k.chat.unload();case 1:k.chat=void 0;case 2:return _context37.a(2);}},_callee37,this);}));function unloadChat(_x72){return _unloadChat.apply(this,arguments);}return unloadChat;}()},{key:"immediateResp",value:function(){var _immediateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(e,t,s){var i,n,_t18;return _regenerator().w(function(_context38){while(1)switch(_context38.n){case 0:_context38.n=1;return s.generate(t,void 0,0);case 1:_t18=_context38.v;i={text:_t18};_context38.n=2;return k.processResponse(this.deepChat,e,i);case 2:n=_context38.v;n&&n.forEach(function(o){return e.addNewMessage(o);}),this.completionsHandlers.onFinish();case 3:return _context38.a(2);}},_callee38,this);}));function immediateResp(_x73,_x74,_x75){return _immediateResp.apply(this,arguments);}return immediateResp;}()},{key:"streamResp",value:function(){var _streamResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(e,t,s){var _this20=this;var i;return _regenerator().w(function(_context40){while(1)switch(_context40.n){case 0:this.streamHandlers.abortStream.abort=function(){s.interruptGenerate();},this.streamHandlers.onOpen();i=new Re(e);_context40.n=1;return s.generate(t,/*#__PURE__*/function(){var _ref17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(n,o){var a;return _regenerator().w(function(_context39){while(1)switch(_context39.n){case 0:_context39.n=1;return k.processResponse(_this20.deepChat,e,{text:o});case 1:a=_context39.v;a&&i.upsertStreamedMessage({text:a[0].text,overwrite:!0});case 2:return _context39.a(2);}},_callee39);}));return function(_x79,_x80){return _ref17.apply(this,arguments);};}());case 1:i.finaliseStreamedMessage();this.streamHandlers.onClose();case 2:return _context40.a(2);}},_callee40,this);}));function streamResp(_x76,_x77,_x78){return _streamResp.apply(this,arguments);}return streamResp;}()},{key:"generateRespByType",value:function(){var _generateRespByType=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(e,t,s,i){var n,_t19;return _regenerator().w(function(_context41){while(1)switch(_context41.p=_context41.n){case 0:_context41.p=0;if(!s){_context41.n=2;break;}_context41.n=1;return this.streamResp(e,t,i);case 1:_context41.n=3;break;case 2:_context41.n=3;return this.immediateResp(e,t,i);case 3:_context41.n=5;break;case 4:_context41.p=4;_t19=_context41.v;(n=this._messages)==null||n.addNewErrorMessage("service"),console.log(_t19);case 5:return _context41.a(2);}},_callee41,this,[[0,4]]);}));function generateRespByType(_x81,_x82,_x83,_x84){return _generateRespByType.apply(this,arguments);}return generateRespByType;}()},{key:"generateResp",value:function(){var _generateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(e,t,s){var i,_yield$S$processReque5,n,o,a,l,c;return _regenerator().w(function(_context42){while(1)switch(_context42.n){case 0:i=t[t.length-1].text;_context42.n=1;return S.processRequestInterceptor(this.deepChat,{body:{text:i}});case 1:_yield$S$processReque5=_context42.v;n=_yield$S$processReque5.body;o=_yield$S$processReque5.error;a=!!this.stream;try{if(o)S.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!n||!n.text){l=E.INVALID_MODEL_REQUEST({body:n},!1);console.error(l);c=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;S.onInterceptorError(e,l,c);}else this.generateRespByType(e,n.text,!!this.stream,s);}catch(l){this.unloadChat(l);}case 2:return _context42.a(2);}},_callee42,this);}));function generateResp(_x85,_x86,_x87){return _generateResp.apply(this,arguments);}return generateResp;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43(e,t){var s,i;return _regenerator().w(function(_context43){while(1)switch(_context43.n){case 0:if(this._isModelLoaded){_context43.n=3;break;}if(!this._loadOnFirstMessage){_context43.n=2;break;}_context43.n=1;return this.init();case 1:_context43.n=3;break;case 2:return _context43.a(2);case 3:!k.chat||this._isModelLoading||((s=this._webModel.introMessage)!=null&&s.removeAfterMessage&&((i=this._removeIntro)==null||i.call(this)),e.addLoadingMessage(),this.generateResp(e,t,k.chat));case 4:return _context43.a(2);}},_callee43,this);}));function callServiceAPI(_x88,_x89){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===y.USER_ROLE&&s.text){var n=t[i+1];n!=null&&n.text&&n.role!==y.USER_ROLE&&e.push([s.text,n.text]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44(e,t,s){var a,l,i,n,o,d,_t20;return _regenerator().w(function(_context44){while(1)switch(_context44.n){case 0:_context44.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,s);case 1:_t20=_context44.v;if(_t20){_context44.n=2;break;}_t20=s;case 2:i=_t20;if(!((l=e.connect)!=null&&l.stream&&Array.isArray(i)&&i.length>1)){_context44.n=3;break;}console.error(E.INVALID_STREAM_ARRAY_RESPONSE);return _context44.a(2);case 3:n=Array.isArray(i)?i:[i],o=n.find(function(c){return typeof c.error=="string";});if(!o){_context44.n=4;break;}S.displayError(t,new Error(o.error));return _context44.a(2);case 4:if(!n.find(function(d){return!d||!d.text;})){_context44.n=5;break;}d=E.INVALID_MODEL_RESPONSE(s,!!e.responseInterceptor,i);S.displayError(t,new Error(d));return _context44.a(2);case 5:return _context44.a(2,n);}},_callee44);}));function processResponse(_x90,_x91,_x92){return _processResponse.apply(this,arguments);}return processResponse;}()},{key:"clearAllCache",value:function clearAllCache(){k.clearCache("webllm/model"),k.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);});});});}}]);}(ft);k.GENERIC_ERROR="Error, please check the [troubleshooting](https://deepchat.dev/docs/webModel#troubleshooting) section of documentation for help.",k.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",k.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",k.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",k.MODULE_SEARCH_LIMIT_S=5;var us=k;var ks=/*#__PURE__*/function(){function ks(){_classCallCheck(this,ks);}return _createClass(ks,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
|
148
148
|
};}// prettier-ignore
|
149
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(E.INVALID_KEY);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api-inference.huggingface.co/models/gpt2",method:"POST",handleVerificationResult:ks.handleVerificationResult};}}]);}();var is=/*#__PURE__*/function(_M){// prettier-ignore
|
150
150
|
function is(e,t,s,i,n,o){var _this21;_classCallCheck(this,is);_this21=_callSuper(this,is,[e,ks.buildKeyVerificationDetails(),ks.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(is.URL_PREFIX).concat(s),_this21.textInputPlaceholderText=t,_typeof(i)=="object"&&(i.model&&(_this21.url="".concat(is.URL_PREFIX).concat(i.model)),i.options&&(_this21.rawBody.options=i.options),i.parameters&&(_this21.rawBody.parameters=i.parameters));return _this21;}// prettier-ignore
|
151
|
-
_inherits(is,_M);return _createClass(is,[{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 _callee45(e,t,s){var i;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:i=this.preprocessBody(this.rawBody,t,s);
|
151
|
+
_inherits(is,_M);return _createClass(is,[{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 _callee45(e,t,s){var i;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:i=this.preprocessBody(this.rawBody,t,s);C.request(this,i,e);case 2:return _context45.a(2);}},_callee45,this);}));function callServiceAPI(_x93,_x94,_x95){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(M);is.URL_PREFIX="https://api-inference.huggingface.co/models/";var Ve=is;var ys=/*#__PURE__*/function(_Ve){// prettier-ignore
|
152
152
|
function ys(e,t,s,i,n,o){var _this22;_classCallCheck(this,ys);_this22=_callSuper(this,ys,[e,t,s,i,n,o]),_this22.isTextInputDisabled=!0,_this22.canSendMessage=ys.canSendFile;return _this22;}_inherits(ys,_Ve);return _createClass(ys,[{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 _callee46(e,t,s){return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:if(this.connectSettings){_context46.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context46.n=2;break;}throw new Error("No file was added");case 2:
|
153
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46(e,t,s){return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:if(this.connectSettings){_context46.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context46.n=2;break;}throw new Error("No file was added");case 2:C.poll(this,s[0],e,!1);case 3:return _context46.a(2);}},_callee46,this);}));function callServiceAPI(_x96,_x97,_x98){return _callServiceAPI4.apply(this,arguments);}return callServiceAPI;}()}],[{key:"canSendFile",value:function canSendFile(e,t){return!!(t!=null&&t[0]);}}]);}(Ve);var ca=/*#__PURE__*/function(_ys){// prettier-ignore
|
154
154
|
function ca(e){_classCallCheck(this,ca);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,ca,[e,"Attach an audio file","ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,s,{audio:{}}]);}_inherits(ca,_ys);return _createClass(ca,[{key:"extractPollResultData",value:function(){var _extractPollResultData=_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(_x99){return _extractPollResultData.apply(this,arguments);}return extractPollResultData;}()}]);}(ys);var da=/*#__PURE__*/function(_ys2){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.imageClassification,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,da,[e,"Attach an image file","google/vit-base-patch16-224",t,s,{images:{}}]);}_inherits(da,_ys2);return _createClass(da,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48(e){var t;return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:if(!e.estimated_time){_context48.n=1;break;}return _context48.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context48.n=2;break;}throw e.error;case 2:return _context48.a(2,{text:((t=e[0])==null?void 0:t.label)||""});}},_callee48);}));function extractPollResultData(_x100){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(ys);var Rt="data:image/png;base64,";var ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}// prettier-ignore
|
155
155
|
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.message?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.stability.ai/v1/engines/list",method:"GET",handleVerificationResult:ke.handleVerificationResult};}}]);}();var ai=/*#__PURE__*/function(_M2){// prettier-ignore
|
156
156
|
function ai(e,t,s,i,n){var _this23;_classCallCheck(this,ai);_this23=_callSuper(this,ai,[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(ai,_M2);return _createClass(ai);}(M);var Ls=/*#__PURE__*/function(_ai){function Ls(e){var _this24;_classCallCheck(this,Ls);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,Ls,[e,ke.buildKeyVerificationDetails(),ke.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")),Ls.cleanConfig(n),Object.assign(_this24.rawBody,n)),_this24.canSendMessage=Ls.canSendFileMessage;return _this24;}_inherits(Ls,_ai);return _createClass(Ls,[{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 _callee49(e,t,s){var i;return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(this.connectSettings){_context49.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context49.n=2;break;}throw new Error("Image was not found");case 2:i=this.createFormDataBody(this.rawBody,s[0]);S.tempRemoveContentHeader(this.connectSettings,
|
158
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e,t,s){var o,a,i,n;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(this.connectSettings){_context51.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!(!s||!s[0]||!s[1])){_context51.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);S.tempRemoveContentHeader(this.connectSettings,
|
157
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49(e,t,s){var i;return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(this.connectSettings){_context49.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context49.n=2;break;}throw new Error("Image was not found");case 2:i=this.createFormDataBody(this.rawBody,s[0]);S.tempRemoveContentHeader(this.connectSettings,C.request.bind(this,this,i,e),!1);case 3:return _context49.a(2);}},_callee49,this);}));function callServiceAPI(_x101,_x102,_x103){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(e){return _regenerator().w(function(_context50){while(1)switch(_context50.n){case 0:if(!e.message){_context50.n=1;break;}throw e.message;case 1:return _context50.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Rt).concat(s.base64),type:"image"};})});}},_callee50);}));function extractResultData(_x104){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]);}}]);}(ai);var Is=/*#__PURE__*/function(_ai2){function Is(e){var _this25;_classCallCheck(this,Is);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,Is,[e,ke.buildKeyVerificationDetails(),ke.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),Is.cleanConfig(n),Object.assign(_this25.rawBody,n)),_this25.canSendMessage=Is.canSendFileTextMessage;return _this25;}_inherits(Is,_ai2);return _createClass(Is,[{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 _callee51(e,t,s){var o,a,i,n;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(this.connectSettings){_context51.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!(!s||!s[0]||!s[1])){_context51.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);S.tempRemoveContentHeader(this.connectSettings,C.request.bind(this,this,n,e),!1);case 3:return _context51.a(2);}},_callee51,this);}));function callServiceAPI(_x105,_x106,_x107){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e){return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(!e.message){_context52.n=1;break;}throw e.message;case 1:return _context52.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Rt).concat(s.base64),type:"image"};})});}},_callee52);}));function extractResultData(_x108){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()!=="");}}]);}(ai);var ha=/*#__PURE__*/function(_ys3){function ha(e){_classCallCheck(this,ha);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,ha,[e,"Attach an audio file","facebook/wav2vec2-large-960h-lv60-self",t,s,{audio:{}}]);}_inherits(ha,_ys3);return _createClass(ha,[{key:"extractPollResultData",value:function(){var _extractPollResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e){return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(!e.estimated_time){_context53.n=1;break;}return _context53.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context53.n=2;break;}throw e.error;case 2:return _context53.a(2,{text:e.text||""});}},_callee53);}));function extractPollResultData(_x109){return _extractPollResultData3.apply(this,arguments);}return extractPollResultData;}()}]);}(ys);var ua=/*#__PURE__*/function(_Ve2){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.textGeneration,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ua,[e,"Once upon a time","gpt2",t,s]);}_inherits(ua,_Ve2);return _createClass(ua,[{key:"extractResultData",value:function(){var _extractResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54(e){var t;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:((t=e[0])==null?void 0:t.generated_text)||""});}},_callee54);}));function extractResultData(_x110){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var fa=/*#__PURE__*/function(_Ve3){function fa(e){var _this26;_classCallCheck(this,fa);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,fa,[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(fa,_Ve3);return _createClass(fa,[{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 _callee55(e){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:e.answer||""});}},_callee55);}));function extractResultData(_x111){return _extractResultData5.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var pa=/*#__PURE__*/function(_Ve4){function pa(e){_classCallCheck(this,pa);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,pa,[e,"Insert text to summarize","facebook/bart-large-cnn",t,s]);}_inherits(pa,_Ve4);return _createClass(pa,[{key:"extractResultData",value:function(){var _extractResultData6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56(e){var t;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:((t=e[0])==null?void 0:t.summary_text)||""});}},_callee56);}));function extractResultData(_x112){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var ma=/*#__PURE__*/function(_Ve5){function ma(e){var _this27$maxMessages;var _this27;_classCallCheck(this,ma);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,ma,[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
159
|
_inherits(ma,_Ve5);return _createClass(ma,[{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
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 _callee57(e){return _regenerator().w(function(_context57){while(1)switch(_context57.n){case 0:if(!e.error){_context57.n=1;break;}throw e.error;case 1:return _context57.a(2,{text:e.generated_text||""});}},_callee57);}));function extractResultData(_x113){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Os=/*#__PURE__*/function(_ai3){function Os(e){var _this28;_classCallCheck(this,Os);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this28=_callSuper(this,Os,[e,ke.buildKeyVerificationDetails(),ke.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),Os.cleanConfig(n),Object.assign(_this28.rawBody,n)),_this28.canSendMessage=Os.canSendFileTextMessage;return _this28;}_inherits(Os,_ai3);return _createClass(Os,[{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 _callee58(e,t,s){var o,a,i,n;return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(this.connectSettings){_context58.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context58.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);S.tempRemoveContentHeader(this.connectSettings,A.request.bind(this,this,n,e),!1);case 3:return _context58.a(2);}},_callee58,this);}));function callServiceAPI(_x114,_x115,_x116){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e.message){_context59.n=1;break;}throw e.message;case 1:return _context59.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Rt).concat(s.base64),type:"image"};})});}},_callee59);}));function extractResultData(_x117){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()!=="");}}]);}(ai);var ga=/*#__PURE__*/function(_Ve6){function ga(e){_classCallCheck(this,ga);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,ga,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,s]);}_inherits(ga,_Ve6);return _createClass(ga,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){var t;return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(!e.error){_context60.n=1;break;}throw e.error;case 1:return _context60.a(2,{text:((t=e[0])==null?void 0:t.translation_text)||""});}},_callee60);}));function extractResultData(_x118){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Ns=/*#__PURE__*/function(_ai4){function Ns(e){var _this29;_classCallCheck(this,Ns);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI;_this29=_callSuper(this,Ns,[e,ke.buildKeyVerificationDetails(),ke.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),Ns.cleanConfig(i),Object.assign(_this29.rawBody,i)),_this29.canSendMessage=Ns.canSendTextMessage;return _this29;}_inherits(Ns,_ai4);return _createClass(Ns,[{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 _callee61(e,t){var s;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(this.connectSettings){_context61.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);A.request(this,s,e);case 2:return _context61.a(2);}},_callee61,this);}));function callServiceAPI(_x119,_x120){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e){return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(!e.message){_context62.n=1;break;}throw e.message;case 1:return _context62.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Rt).concat(s.base64),type:"image"};})});}},_callee62);}));function extractResultData(_x121){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()!=="");}}]);}(ai);var ya=/*#__PURE__*/function(_Ve7){function ya(e){var _this30;_classCallCheck(this,ya);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,ya,[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(ya,_Ve7);return _createClass(ya,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e){var t;return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:if(!e.error){_context63.n=1;break;}throw e.error;case 1:return _context63.a(2,{text:((t=e[0])==null?void 0:t.sequence)||""});}},_callee63);}));function extractResultData(_x122){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Ye=/*#__PURE__*/function(){function Ye(){_classCallCheck(this,Ye);}return _createClass(Ye,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message==="Unauthorized"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://open.bigmodel.cn/api/paas/v4/models",method:"GET",handleVerificationResult:Ye.handleVerificationResult};}}]);}();var ba=/*#__PURE__*/function(_M3){function ba(e){var _o$model,_a$voice;var _this31;_classCallCheck(this,ba);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this31=_callSuper(this,ba,[e,Ye.buildKeyVerificationDetails(),Ye.buildHeaders,s]),_this31.insertKeyPlaceholderText="BigModel API Key",_this31.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this31.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this31.permittedErrorPrefixes=["Authorization","authentication_error"];var i=(n=t.bigModel)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&(_this31.cleanConfig(i),Object.assign(_this31.rawBody,i)),(_o$model=(o=_this31.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this31.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this31;}_inherits(ba,_M3);return _createClass(ba,[{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[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e,t){var s;return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:if(this.connectSettings){_context64.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context64.n=2;return A.request(this,s,e);case 2:return _context64.a(2,_context64.v);}},_callee64,this);}));function callServiceAPI(_x123,_x124){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){var t;return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context65.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee65);}));function extractResultData(_x125){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ze=/*#__PURE__*/function(){function Ze(){_classCallCheck(this,Ze);}return _createClass(Ze,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message==="Unauthorized"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.together.xyz/v1/models",method:"GET",handleVerificationResult:Ze.handleVerificationResult};}}]);}();var va=/*#__PURE__*/function(_M4){function va(e){var _o$model2,_a$voice2;var _this32;_classCallCheck(this,va);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this32=_callSuper(this,va,[e,Ze.buildKeyVerificationDetails(),Ze.buildHeaders,s]),_this32.insertKeyPlaceholderText="Together AI API Key",_this32.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this32.url="https://api.together.xyz/v1/audio/speech",_this32.permittedErrorPrefixes=["invalid_request_error","authentication_error"];var i=(n=t.together)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&(_this32.cleanConfig(i),Object.assign(_this32.rawBody,i)),(_o$model2=(o=_this32.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this32.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this32;}_inherits(va,_M4);return _createClass(va,[{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[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e,t){var s;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(this.connectSettings){_context66.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context66.n=2;return A.request(this,s,e);case 2:return _context66.a(2,_context66.v);}},_callee66,this);}));function callServiceAPI(_x126,_x127){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e){var t;return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context67.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee67);}));function extractResultData(_x128){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(M);var ns=/*#__PURE__*/function(){function ns(){_classCallCheck(this,ns);}return _createClass(ns,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}// prettier-ignore
|
161
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58(e,t,s){var o,a,i,n;return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(this.connectSettings){_context58.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context58.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);S.tempRemoveContentHeader(this.connectSettings,C.request.bind(this,this,n,e),!1);case 3:return _context58.a(2);}},_callee58,this);}));function callServiceAPI(_x114,_x115,_x116){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e.message){_context59.n=1;break;}throw e.message;case 1:return _context59.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Rt).concat(s.base64),type:"image"};})});}},_callee59);}));function extractResultData(_x117){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()!=="");}}]);}(ai);var ga=/*#__PURE__*/function(_Ve6){function ga(e){_classCallCheck(this,ga);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,ga,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,s]);}_inherits(ga,_Ve6);return _createClass(ga,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){var t;return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(!e.error){_context60.n=1;break;}throw e.error;case 1:return _context60.a(2,{text:((t=e[0])==null?void 0:t.translation_text)||""});}},_callee60);}));function extractResultData(_x118){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Ns=/*#__PURE__*/function(_ai4){function Ns(e){var _this29;_classCallCheck(this,Ns);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI;_this29=_callSuper(this,Ns,[e,ke.buildKeyVerificationDetails(),ke.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),Ns.cleanConfig(i),Object.assign(_this29.rawBody,i)),_this29.canSendMessage=Ns.canSendTextMessage;return _this29;}_inherits(Ns,_ai4);return _createClass(Ns,[{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 _callee61(e,t){var s;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(this.connectSettings){_context61.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);C.request(this,s,e);case 2:return _context61.a(2);}},_callee61,this);}));function callServiceAPI(_x119,_x120){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e){return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(!e.message){_context62.n=1;break;}throw e.message;case 1:return _context62.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Rt).concat(s.base64),type:"image"};})});}},_callee62);}));function extractResultData(_x121){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()!=="");}}]);}(ai);var ya=/*#__PURE__*/function(_Ve7){function ya(e){var _this30;_classCallCheck(this,ya);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,ya,[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(ya,_Ve7);return _createClass(ya,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e){var t;return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:if(!e.error){_context63.n=1;break;}throw e.error;case 1:return _context63.a(2,{text:((t=e[0])==null?void 0:t.sequence)||""});}},_callee63);}));function extractResultData(_x122){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Ye=/*#__PURE__*/function(){function Ye(){_classCallCheck(this,Ye);}return _createClass(Ye,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message==="Unauthorized"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://open.bigmodel.cn/api/paas/v4/models",method:"GET",handleVerificationResult:Ye.handleVerificationResult};}}]);}();var ba=/*#__PURE__*/function(_M3){function ba(e){var _o$model,_a$voice;var _this31;_classCallCheck(this,ba);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this31=_callSuper(this,ba,[e,Ye.buildKeyVerificationDetails(),Ye.buildHeaders,s]),_this31.insertKeyPlaceholderText="BigModel API Key",_this31.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this31.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this31.permittedErrorPrefixes=["Authorization","authentication_error"];var i=(n=t.bigModel)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&(_this31.cleanConfig(i),Object.assign(_this31.rawBody,i)),(_o$model=(o=_this31.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this31.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this31;}_inherits(ba,_M3);return _createClass(ba,[{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[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e,t){var s;return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:if(this.connectSettings){_context64.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context64.n=2;return C.request(this,s,e);case 2:return _context64.a(2,_context64.v);}},_callee64,this);}));function callServiceAPI(_x123,_x124){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){var t;return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context65.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee65);}));function extractResultData(_x125){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ze=/*#__PURE__*/function(){function Ze(){_classCallCheck(this,Ze);}return _createClass(Ze,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message==="Unauthorized"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.together.xyz/v1/models",method:"GET",handleVerificationResult:Ze.handleVerificationResult};}}]);}();var va=/*#__PURE__*/function(_M4){function va(e){var _o$model2,_a$voice2;var _this32;_classCallCheck(this,va);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this32=_callSuper(this,va,[e,Ze.buildKeyVerificationDetails(),Ze.buildHeaders,s]),_this32.insertKeyPlaceholderText="Together AI API Key",_this32.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this32.url="https://api.together.xyz/v1/audio/speech",_this32.permittedErrorPrefixes=["invalid_request_error","authentication_error"];var i=(n=t.together)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&(_this32.cleanConfig(i),Object.assign(_this32.rawBody,i)),(_o$model2=(o=_this32.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this32.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this32;}_inherits(va,_M4);return _createClass(va,[{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[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e,t){var s;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(this.connectSettings){_context66.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context66.n=2;return C.request(this,s,e);case 2:return _context66.a(2,_context66.v);}},_callee66,this);}));function callServiceAPI(_x126,_x127){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e){var t;return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context67.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee67);}));function extractResultData(_x128){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(M);var ns=/*#__PURE__*/function(){function ns(){_classCallCheck(this,ns);}return _createClass(ns,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}// prettier-ignore
|
162
162
|
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.openai.com/v1/models",method:"GET",handleVerificationResult:ns.handleVerificationResult};}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
163
163
|
},{key:"directFetch",value:function(){var _directFetch=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e,t,s){var i,n,_args68=arguments;return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:i=_args68.length>3&&_args68[3]!==undefined?_args68[3]:!0;e.connectSettings.method=s;_context68.n=1;return S.fetch(e,e.connectSettings.headers,i,t).then(function(o){return S.processResponseByType(o);});case 1:n=_context68.v;if(!n.error){_context68.n=2;break;}throw n.error.message;case 2:return _context68.a(2,n);}},_callee68);}));function directFetch(_x129,_x130,_x131){return _directFetch.apply(this,arguments);}return directFetch;}()}]);}();ns.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.",ns.FUNCTION_TOOL_RESP_ARR_ERROR="Arrays are not accepted in handler responses";var F=ns;var ae=/*#__PURE__*/function(){function ae(){_classCallCheck(this,ae);}return _createClass(ae,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(e,t,s,i){var n,o,a,l,_t21;return _regenerator().w(function(_context70){while(1)switch(_context70.p=_context70.n){case 0:n=e.connectSettings.headers;if(n){_context70.n=1;break;}return _context70.a(2);case 1:e.url=i;o=n[S.CONTENT_TYPE];delete n[S.CONTENT_TYPE];a=s.map(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee69(l){var c;return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:c=new FormData();return _context69.a(2,(c.append("purpose","assistants"),c.append("file",l),new Promise(function(d){d(F.directFetch(e,c,"POST",!1));})));}},_callee69);}));return function(_x136){return _ref18.apply(this,arguments);};}());_context70.p=2;_context70.n=3;return Promise.all(a);case 3:l=_context70.v.map(function(c){return{id:c.id,name:c.filename};});return _context70.a(2,(n[S.CONTENT_TYPE]=o,l));case 4:_context70.p=4;_t21=_context70.v;throw n[S.CONTENT_TYPE]=o,S.displayError(t,_t21),e.completionsHandlers.onFinish(),_t21;case 5:return _context70.a(2);}},_callee70,null,[[2,4]]);}));function storeFiles(_x132,_x133,_x134,_x135){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 _callee71(e,t,s,i){var n,a;return _regenerator().w(function(_context71){while(1)switch(_context71.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(F.directFetch(e,void 0,"GET",!1));});});_context71.n=1;return Promise.all(n);case 1:a=_context71.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)});};});});_context71.n=2;return Promise.all(a);case 2:return _context71.a(2,_context71.v);}},_callee71);}));function getFiles(_x137,_x138,_x139,_x140){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 _callee72(e,t,s,i,n){var c,d,o,a,l,_t22;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:a=s.getFilesPrefix,l=s.getFilesPostfix;_t22=t.length>0;if(!_t22){_context72.n=2;break;}_context72.n=1;return ae.getFiles(e,t,a,l);case 1:o=_context72.v;(c=n==null?void 0:n.text)!=null&&c.value&&o.forEach(function(u,h){var m;if(!u.src)return;var
|
164
|
+
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(e,t,s,i,n){var c,d,o,a,l,_t22;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:a=s.getFilesPrefix,l=s.getFilesPostfix;_t22=t.length>0;if(!_t22){_context72.n=2;break;}_context72.n=1;return ae.getFiles(e,t,a,l);case 1:o=_context72.v;(c=n==null?void 0:n.text)!=null&&c.value&&o.forEach(function(u,h){var m;if(!u.src)return;var f=t[h].path;(m=n==null?void 0:n.text)!=null&&m.value&&f&&(n.text.value=n.text.value.replace(f,u.src));});case 2:return _context72.a(2,(d=n==null?void 0:n.text)!=null&&d.value?{text:n.text.value,role:i}:{files:o,role:i});}},_callee72);}));function getFilesAndNewText(_x141,_x142,_x143,_x144,_x145){return _getFilesAndNewText.apply(this,arguments);}return getFilesAndNewText;}()// Noticed an issue where text contains a sandbox hyperlink to a csv, but no annotation provided
|
165
165
|
// To reproduce use the following text:
|
166
166
|
// give example data for a csv and create a suitable bar chart for it with a link
|
167
167
|
// Don't think it can be fixed and it is something on OpenAI side of things
|
@@ -171,44 +171,43 @@ _inherits(ma,_Ve5);return _createClass(ma,[{key:"processMessages",value:function
|
|
171
171
|
// "give example data for a csv and create a suitable bar chart"
|
172
172
|
},{key:"parseMessages",value:function parseMessages(e,t,s){var i=[];return t.forEach(/*#__PURE__*/function(){var _ref20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee75(n){return _regenerator().w(function(_context75){while(1)switch(_context75.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 _callee74(o){return _regenerator().w(function(_context74){while(1)switch(_context74.n){case 0:i.push(ae.getFilesAndText(e,n,s,o));case 1:return _context74.a(2);}},_callee74);}));return function(_x151){return _ref21.apply(this,arguments);};}());case 1:return _context75.a(2);}},_callee75);}));return function(_x150){return _ref20.apply(this,arguments);};}()),Promise.all(i);}},{key:"processStreamMessages",value:function(){var _processStreamMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee76(e,t,s){return _regenerator().w(function(_context76){while(1)switch(_context76.n){case 0:return _context76.a(2,ae.parseMessages(e,[{content:t,role:"assistant"}],s));}},_callee76);}));function processStreamMessages(_x152,_x153,_x154){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
|
173
173
|
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(e,t,s,i){var n;return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:n=ae.parseResult(t,s);return _context77.a(2,ae.parseMessages(e,n,i));}},_callee77);}));function processAPIMessages(_x155,_x156,_x157,_x158){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 Ie=ae;var $e=/*#__PURE__*/function(_M5){// prettier-ignore
|
174
|
-
function $e(e,t,s,i,n,o){var _this33;_classCallCheck(this,$e);if(_this33=_callSuper(this,$e,[e,i,n,o]),_this33.insertKeyPlaceholderText="OpenAI API Key",_this33.keyHelpUrl="https://platform.openai.com/account/api-keys",_this33.url="",_this33.permittedErrorPrefixes=["Incorrect","Please send text",hs.FAILED_ERROR_MESSAGE],_this33.shouldFetchHistory=!1,_this33._searchedForThreadId=!1,_this33._config={},_this33._newAssistantDetails={model:"gpt-4"},_this33._waitingForStreamResponse=!1,_this33._isSSEStream=!1,_this33.urlSegments=s,_typeof(t)=="object"){_this33._config=t;var _this33$_config=_this33._config,a=_this33$_config.new_assistant,l=_this33$_config.thread_id,c=_this33$_config.load_thread_history;Object.assign(_this33._newAssistantDetails,a),l&&(_this33.sessionId=l),c&&(_this33.shouldFetchHistory=!0);}_this33.maxMessages=1,_this33._isSSEStream=!!(_this33.stream&&(_typeof(_this33.stream)!="object"||!_this33.stream.simulation));return _this33;}_inherits($e,_M5);return _createClass($e,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(){var _this34=this;var e,_t23;return _regenerator().w(function(_context78){while(1)switch(_context78.p=_context78.n){case 0:setTimeout(function(){return _this34.deepChat.disableSubmitButton();},2);_context78.p=1;_context78.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context78.v;return _context78.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context78.p=3;_t23=_context78.v;return _context78.a(2,[{error:"Failed to fetch history"}]);}},_callee78,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=K.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!G.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);A.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):A.request(this,_i2,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,s){var _n$assistant_id;var n,i,_t24,_t25;return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context79.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)){_context79.n=2;break;}_n$assistant_id;_context79.n=5;break;case 2:_t24=this._config.assistant_id;if(_t24){_context79.n=4;break;}_context79.n=3;return this.createNewAssistant();case 3:_t24=_context79.v;case 4:n.assistant_id=_t24;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!s){_context79.n=7;break;}_context79.n=6;return Ie.storeFiles(this,e,s,this.urlSegments.storeFiles);case 6:_t25=_context79.v;_context79.n=8;break;case 7:_t25=void 0;case 8:i=_t25;this.connectSettings.method="POST",this.callService(e,t,i);case 9:return _context79.a(2);}},_callee79,this);}));function callServiceAPI(_x159,_x160,_x161){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(){var e,_t26;return _regenerator().w(function(_context80){while(1)switch(_context80.p=_context80.n){case 0:_context80.p=0;this.url=this.urlSegments.newAssistantUrl;_context80.n=1;return F.directFetch(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),"POST");case 1:e=_context80.v;return _context80.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context80.p=2;_t26=_context80.v;console.error(_t26),console.error("Failed to create a new assistant");case 3:return _context80.a(2);}},_callee80,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:"
|
176
|
-
},{key:"
|
177
|
-
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var t,s,i,n,o,a,l,c,_a4,_l2;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:if(!(e.content&&e.content.length>0&&this._messages)){_context87.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)){_context87.n=1;break;}l=e.content.find(function(d){return!!d.text;})||e.content[0],c=Ie.getFilesAndText.bind(this,this,{role:"assistant",content:e.content},this.urlSegments,l);return _context87.a(2,((s=this._messageStream)==null||s.endStreamAfterFileDownloaded(this._messages,c),{text:""}));case 1:if(!((i=e.delta)!=null&&i.content)){_context87.n=4;break;}if(!(e.delta.content.length>1)){_context87.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)){_context87.n=3;break;}_context87.n=2;return Ie.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_l2=_context87.v;return _context87.a(2,{text:_l2[0].text,files:_l2[1].files});case 3:return _context87.a(2,{text:(o=e.delta.content[0].text)==null?void 0:o.value});case 4:return _context87.a(2,(!this.sessionId&&e.thread_id&&(this.sessionId=e.thread_id),{makingAnotherRequest:!0}));}},_callee87,this);}));function parseStreamResult(_x168){return _parseStreamResult.apply(this,arguments);}return parseStreamResult;}()// https://platform.openai.com/docs/api-reference/assistants-streaming
|
174
|
+
function $e(e,t,s,i,n,o){var _this33;_classCallCheck(this,$e);if(_this33=_callSuper(this,$e,[e,i,n,o]),_this33.insertKeyPlaceholderText="OpenAI API Key",_this33.keyHelpUrl="https://platform.openai.com/account/api-keys",_this33.url="",_this33.permittedErrorPrefixes=["Incorrect","Please send text",hs.FAILED_ERROR_MESSAGE],_this33.shouldFetchHistory=!1,_this33._searchedForThreadId=!1,_this33._config={},_this33._newAssistantDetails={model:"gpt-4"},_this33._waitingForStreamResponse=!1,_this33._isSSEStream=!1,_this33.urlSegments=s,_typeof(t)=="object"){_this33._config=t;var _this33$_config=_this33._config,a=_this33$_config.new_assistant,l=_this33$_config.thread_id,c=_this33$_config.load_thread_history;Object.assign(_this33._newAssistantDetails,a),l&&(_this33.sessionId=l),c&&(_this33.shouldFetchHistory=!0);}_this33.maxMessages=1,_this33._isSSEStream=!!(_this33.stream&&(_typeof(_this33.stream)!="object"||!_this33.stream.simulation));return _this33;}_inherits($e,_M5);return _createClass($e,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(){var _this34=this;var e,_t23;return _regenerator().w(function(_context78){while(1)switch(_context78.p=_context78.n){case 0:setTimeout(function(){return _this34.deepChat.disableSubmitButton();},2);_context78.p=1;_context78.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context78.v;return _context78.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context78.p=3;_t23=_context78.v;return _context78.a(2,[{error:"Failed to fetch history"}]);}},_callee78,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=K.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!G.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);C.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):C.request(this,_i2,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,s){var _n$assistant_id;var n,i,_t24,_t25;return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context79.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)){_context79.n=2;break;}_n$assistant_id;_context79.n=5;break;case 2:_t24=this._config.assistant_id;if(_t24){_context79.n=4;break;}_context79.n=3;return this.createNewAssistant();case 3:_t24=_context79.v;case 4:n.assistant_id=_t24;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!s){_context79.n=7;break;}_context79.n=6;return Ie.storeFiles(this,e,s,this.urlSegments.storeFiles);case 6:_t25=_context79.v;_context79.n=8;break;case 7:_t25=void 0;case 8:i=_t25;this.connectSettings.method="POST",this.callService(e,t,i);case 9:return _context79.a(2);}},_callee79,this);}));function callServiceAPI(_x159,_x160,_x161){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(){var e,_t26;return _regenerator().w(function(_context80){while(1)switch(_context80.p=_context80.n){case 0:_context80.p=0;this.url=this.urlSegments.newAssistantUrl;_context80.n=1;return F.directFetch(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),"POST");case 1:e=_context80.v;return _context80.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context80.p=2;_t26=_context80.v;console.error(_t26),console.error("Failed to create a new assistant");case 3:return _context80.a(2);}},_callee80,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;}},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(e){var i,t,s;return _regenerator().w(function(_context81){while(1)switch(_context81.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context81.n=2;break;}_context81.n=1;return this.handleStream(e);case 1:return _context81.a(2,_context81.v);case 2:if(!e.error){_context81.n=3;break;}throw e.error.message.startsWith(Ie.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e.error.message;case 3:this.asyncCallInProgress=!0;_context81.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 _context81.a(2,(C.executePollRequest(this,t,s,this._messages),{text:""}));}},_callee81,this);}));function extractResultData(_x162){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(e){var t;return _regenerator().w(function(_context82){while(1)switch(_context82.n){case 0:if(!this.sessionId){_context82.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context82.n=1;return F.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),"POST");case 1:t=_context82.v;this.run_id=t.id;_context82.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 _context82.a(2);}},_callee82,this);}));function assignThreadAndRun(_x163){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(e){var t,i,n,s,_args83=arguments,_t27;return _regenerator().w(function(_context83){while(1)switch(_context83.n){case 0:t=_args83.length>1&&_args83[1]!==undefined?_args83[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context83.n=1;return F.directFetch(this,{},"GET");case 1:s=_context83.v;_t27=!t&&this.deepChat.responseInterceptor;if(!_t27){_context83.n=3;break;}_context83.n=2;return(n=(i=this.deepChat).responseInterceptor)==null?void 0:n.call(i,s);case 2:s=_context83.v;case 3:return _context83.a(2,Ie.processAPIMessages(this,s,t,this.urlSegments));}},_callee83,this);}));function getThreadMessages(_x164){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(e){var _this35=this;var n,t,s,o,_o$shift,a,l,i;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:t=e.status,s=e.required_action;if(!(t==="queued"||t==="in_progress")){_context84.n=1;break;}return _context84.a(2,{timeoutMS:$e.POLLING_TIMEOUT_MS});case 1:if(!(t==="completed"&&this._messages)){_context84.n=3;break;}_context84.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context84.v;_o$shift=o.shift();a=_o$shift.text;l=_o$shift.files;return _context84.a(2,(setTimeout(function(){o.forEach(function(c){return _this35.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)){_context84.n=5;break;}_context84.n=4;return this.handleTools(i);case 4:return _context84.a(2,_context84.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context84.a(2);}},_callee84,this);}));function extractPollResultData(_x165){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
|
175
|
+
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var t,s,i,n,o,a;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:if(this.functionHandler){_context85.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:t=e.map(function(l){return{name:l["function"].name,arguments:l["function"].arguments};});_context85.n=2;return this.functionHandler(t);case 2:s=_context85.v;if(!(!Array.isArray(s)||e.length!==s.length)){_context85.n=3;break;}throw Error(Ie.FUNCTION_TOOL_RESP_ERROR);case 3:_context85.n=4;return Promise.all(s);case 4:i=_context85.v;if(!i.find(function(l){return typeof l!="string";})){_context85.n=5;break;}throw Error(Ie.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){_context85.n=7;break;}_context85.n=6;return this.createStreamRun({tool_outputs:n});case 6:_context85.n=8;break;case 7:_context85.n=8;return F.directFetch(this,{tool_outputs:n},"POST");case 8:return _context85.a(2,{timeoutMS:$e.POLLING_TIMEOUT_MS});}},_callee85,this);}));function handleTools(_x166){return _handleTools.apply(this,arguments);}return handleTools;}()},{key:"handleStream",value:function(){var _handleStream=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){var s,i,t,n;return _regenerator().w(function(_context86){while(1)switch(_context86.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)){_context86.n=2;break;}this.run_id=e.id;_context86.n=1;return this.handleTools(t);case 1:return _context86.a(2,_context86.v);case 2:if(!this._waitingForStreamResponse){_context86.n=3;break;}return _context86.a(2,this.parseStreamResult(e));case 3:if(this._isSSEStream&&this.sessionId){this.asyncCallInProgress=!0,this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);n=JSON.parse(JSON.stringify(this.rawBody));this.createStreamRun(n);}return _context86.a(2,{text:""});}},_callee86,this);}));function handleStream(_x167){return _handleStream.apply(this,arguments);}return handleStream;}()// prettier-ignore
|
176
|
+
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var t,s,i,n,o,a,l,c,_a4,_l2;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:if(!(e.content&&e.content.length>0&&this._messages)){_context87.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)){_context87.n=1;break;}l=e.content.find(function(d){return!!d.text;})||e.content[0],c=Ie.getFilesAndText.bind(this,this,{role:"assistant",content:e.content},this.urlSegments,l);return _context87.a(2,((s=this._messageStream)==null||s.endStreamAfterFileDownloaded(this._messages,c),{text:""}));case 1:if(!((i=e.delta)!=null&&i.content)){_context87.n=4;break;}if(!(e.delta.content.length>1)){_context87.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)){_context87.n=3;break;}_context87.n=2;return Ie.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_l2=_context87.v;return _context87.a(2,{text:_l2[0].text,files:_l2[1].files});case 3:return _context87.a(2,{text:(o=e.delta.content[0].text)==null?void 0:o.value});case 4:return _context87.a(2,(!this.sessionId&&e.thread_id&&(this.sessionId=e.thread_id),{text:""}));}},_callee87,this);}));function parseStreamResult(_x168){return _parseStreamResult.apply(this,arguments);}return parseStreamResult;}()// https://platform.openai.com/docs/api-reference/assistants-streaming
|
178
177
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
179
|
-
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context88.n=1;return _.request(this,e,this._messages,!0,!0);case 1:this._messageStream=_context88.v;case 2:return _context88.a(2);}},_callee88,this);}));function createStreamRun(_x169){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 G.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"};}}]);}(M);$e.POLLING_TIMEOUT_MS=500;var Ps=$e;var
|
180
|
-
function yt(e,t,s,i,n,o){_classCallCheck(this,yt);this._mouseState={state:"default"},this.isCustom=!1,D.addAttributes(e),this.elementRef=e,this.svg=
|
178
|
+
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context88.n=1;return _.request(this,e,this._messages,!0,!0);case 1:this._messageStream=_context88.v;case 2:return _context88.a(2);}},_callee88,this);}));function createStreamRun(_x169){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 G.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"};}}]);}(M);$e.POLLING_TIMEOUT_MS=500;var Ps=$e;var qi=/*#__PURE__*/function(_Ps){function qi(e){var _a$headers,_l$OpenAIBeta;var _this36;_classCallCheck(this,qi);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=qi.buildUrlSegments(i);if(_this36=_callSuper(this,qi,[e,i,n,F.buildKeyVerificationDetails(),F.buildHeaders,s]),(_a$headers=(a=_this36.connectSettings).headers)!==null&&_a$headers!==void 0?_a$headers:a.headers={},(_l$OpenAIBeta=(l=_this36.connectSettings.headers)["OpenAI-Beta"])!==null&&_l$OpenAIBeta!==void 0?_l$OpenAIBeta:l["OpenAI-Beta"]="assistants=v2",_this36.shouldFetchHistory&&_this36.sessionId&&(_this36.fetchHistory=_this36.fetchHistoryFunc.bind(_assertThisInitialized(_this36))),_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&&(_this36.functionHandler=u),h&&(_this36.filesToolType=h);}return _this36;}_inherits(qi,_Ps);return _createClass(qi,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"};}}]);}(Ps);var Yi=/*#__PURE__*/function(){function Yi(){_classCallCheck(this,Yi);}return _createClass(Yi,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:F.handleVerificationResult};}},{key:"validateURLDetails",value:function validateURLDetails(e){var t=e.endpoint,s=e.version,i=e.deploymentId;return t&&s&&i;}}]);}();Yi.URL_DETAILS_ERROR_MESSAGE="Please define the Azure URL Details. [More Information](https://deepchat.dev/docs/directConnection/Azure)";var pe=Yi;var St=/*#__PURE__*/function(_Ps2){function St(e){var _g$headers;var _this37;_classCallCheck(this,St);var c,d,u,h,f,m,p,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(St.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(St.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(_this37=_callSuper(this,St,[e,i==null?void 0:i.assistant,l,pe.buildKeyVerificationDetails(n),pe.buildHeaders,s]),_this37.permittedErrorPrefixes=[pe.URL_DETAILS_ERROR_MESSAGE],_this37.insertKeyPlaceholderText="Azure OpenAI API Key",_this37.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",_this37.isTextInputDisabled=!1,_typeof(i==null?void 0:i.assistant)=="object"){var _ref27=(p=(m=(f=e.directConnection)==null?void 0:f.azure)==null?void 0:m.openAI)==null?void 0:p.assistant,v=_ref27.function_handler,R=_ref27.files_tool_type;v&&(_this37.functionHandler=v),R&&(_this37.filesToolType=R);}pe.validateURLDetails(n)?(_g$headers=(g=_this37.connectSettings).headers)!==null&&_g$headers!==void 0?_g$headers:g.headers={}:(_this37.isTextInputDisabled=!0,_this37.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:pe.URL_DETAILS_ERROR_MESSAGE});}));return _this37;}_inherits(St,_Ps2);return _createClass(St);}(Ps);St.THREAD_RESOURCE="threads",St.NEW_ASSISTANT_RESOURCE="assistants";var Ci=St;var D=/*#__PURE__*/function(){function D(){_classCallCheck(this,D);}return _createClass(D,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){D.removeAriaBusy(e),D.removeAriaDisabled(e);}}]);}();var Qn="<?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(qe.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 Me=le;var Qt=/*#__PURE__*/function(){function Qt(){_classCallCheck(this,Qt);}return _createClass(Qt,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 U=/*#__PURE__*/function(){function U(){_classCallCheck(this,U);}return _createClass(U,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var n,o;t.container&&N.unsetAllCSSMouseStates(e,t.container);var _Qt$parseSVGTextEleme=Qt.parseSVGTextElements(Array.from(e.children)),s=_Qt$parseSVGTextEleme.svg,i=_Qt$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 _Qt$parseSVGTextEleme2=Qt.parseSVGTextElements(Array.from(e.children)),s=_Qt$parseSVGTextEleme2.svg,i=_Qt$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 _Qt$parseSVGTextEleme3=Qt.parseSVGTextElements(Array.from(e.children)),i=_Qt$parseSVGTextEleme3.svg,n=_Qt$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){U.setElementsCSS(e,t,"default"),s!=="default"&&(U.setElementsCSS(e,t,"hover"),s!=="hover"&&U.setElementsCSS(e,t,"click"));}}]);}();var yt=/*#__PURE__*/function(){// prettier-ignore
|
179
|
+
function yt(e,t,s,i,n,o){_classCallCheck(this,yt);this._mouseState={state:"default"},this.isCustom=!1,D.addAttributes(e),this.elementRef=e,this.svg=qe.createSVGElement(t),this.customStyles=n,this.position=s,this._tooltipSettings=i,this.dropupText=o;}return _createClass(yt,[{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&&_e.hide(this._activeTooltip,this._tooltipSettings),e&&(U.unsetAllCSS(this.elementRef,e),U.setElementsCSS(this.elementRef,e,"default"));}},{key:"buttonMouseEnter",value:function buttonMouseEnter(e){var t;this._mouseState.state="hover",this._tooltipSettings&&(this._activeTooltip=_e.display(this.elementRef,this._tooltipSettings,(t=this._activeTooltip)==null?void 0:t.element)),e&&U.setElementsCSS(this.elementRef,e,"hover");}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&U.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state="click",e&&U.setElementsCSS(this.elementRef,e,"click");}// be careful not to use onclick as that is used for button functionality
|
181
180
|
},{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&&U.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&&U.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)),Me.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=Me.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 si=/*#__PURE__*/function(_yt){function si(e){var _this38;_classCallCheck(this,si);var s,i;var t=((i=(s=e==null?void 0:e["default"])==null?void 0:s.svg)==null?void 0:i.content)||si.EMPTY_SVG;_this38=_callSuper(this,si,[document.createElement("div"),t,void 0,void 0,e]),_this38.isActive=!1,_this38._innerElements=_this38.createInnerElementsForStates(_this38.customStyles),_this38.changeToDefault();return _this38;}_inherits(si,_yt);return _createClass(si,[{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 Me.createCustomElements(e,this.svg,t)||[this.svg];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef.classList.replace(Me.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&&U.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(s=this.customStyles)!=null&&s.unavailable&&U.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&&U.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(s=this.customStyles)!=null&&s["default"]&&U.unsetAllCSS(this.elementRef,(i=this.customStyles)==null?void 0:i["default"]),this.reapplyStateStyle("unavailable",["default","active"]),this.isActive=!1;}}]);}(yt);si.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var Bs=si;var W=/*#__PURE__*/function(){function W(){_classCallCheck(this,W);}return _createClass(W,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(),W.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(),W.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:W.getObjectValue(i,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,s){var i=W.getObjectValue(t,s);if(i){var n=_objectSpread(_objectSpread({},i),W.getObjectValue(e,s)||{});W.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 ii=/*#__PURE__*/_createClass(function ii(){_classCallCheck(this,ii);});ii.SESSION_STARTED="sts-session-started",ii.SESSION_STOPPED="sts-session-stopped";var Ds=ii;var er="<?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>",
|
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 _callee89(){var i,e,t,s;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:e=(i=this._deepChat.directConnection)==null?void 0:i.openAI;if(e){_context89.n=1;break;}return _context89.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context89.n=2;break;}return _context89.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 _context89.a(2);}},_callee89,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var o,t,s,i,n,a,_t28,_t29,_t30;return _regenerator().w(function(_context90){while(1)switch(_context90.p=_context90.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")){_context90.n=8;break;}if(this._ephemeralKey){_context90.n=7;break;}_context90.p=1;if(!s){_context90.n=3;break;}a=s();a.then&&(this._retrievingEphemeralKey=a);_context90.n=2;return a;case 2:this._ephemeralKey=_context90.v;_context90.n=5;break;case 3:_t28=n;if(!_t28){_context90.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(n);_context90.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context90.v;case 5:_context90.n=7;break;case 6:_context90.p=6;_t29=_context90.v;this.displayFailedToRetrieveEphemeralKey(_t29);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context90.n=12;break;case 8:if(!n){_context90.n=12;break;}_context90.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(n);_context90.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context90.v;e&&this.init(this._ephemeralKey);_context90.n=12;break;case 11:_context90.p=11;_t30=_context90.v;this.displayFailedToRetrieveEphemeralKey(_t30);case 12:return _context90.a(2);}},_callee90,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x170){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:_context91.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:_context91.n=2;return _context91.v.json();case 2:return _context91.a(2,_context91.v.client_secret.value);}},_callee91,this);}));function getEphemeralKey(_x171){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this40=this;return{updateConfig:function updateConfig(e){var t;(t=_this40._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}]};_this40.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=L.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var s=L.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(s),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this41=this;var t;var e=new Bs((t=this._buttonsConfig)==null?void 0:t.microphone);return e.elementRef.classList.add(L.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),e.elementRef.onclick=function(){e.isActive?(_this41.toggleMicorphone(!0),e.elementRef.classList.replace(L.MICROPHONE_ACTIVE,L.BUTTON_DEFAULT),e.changeToDefault(),_this41._isMuted=!1):(_this41.toggleMicorphone(!1),e.elementRef.classList.replace(L.BUTTON_DEFAULT,L.MICROPHONE_ACTIVE),D.removeAriaAttributes(e.elementRef),e.changeToActive(),_this41._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 _this42=this;var t;var e=new Bs((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef.classList.add(L.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),e.elementRef.onclick=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(){var s,i,_t31,_t32;return _regenerator().w(function(_context92){while(1)switch(_context92.p=_context92.n){case 0:if(!e.isActive){_context92.n=1;break;}e.changeToDefault(),_this42.stop();_context92.n=9;break;case 1:_context92.p=1;if(!_this42._ephemeralKey){_context92.n=3;break;}_this42.displayLoading();_context92.n=2;return _this42.init(_this42._ephemeralKey);case 2:_context92.n=7;break;case 3:if(!_this42._retrievingEphemeralKey){_context92.n=6;break;}_this42.displayLoading();_context92.n=4;return _this42._retrievingEphemeralKey;case 4:i=_context92.v;_t31=(s=_this42._toggleButton)!=null&&s.isActive;if(!_t31){_context92.n=5;break;}_context92.n=5;return _this42.init(i);case 5:_context92.n=7;break;case 6:_this42.displayLoading();_context92.n=7;return _this42.fetchEphemeralKey(!0);case 7:_context92.n=9;break;case 8:_context92.p=8;_t32=_context92.v;console.error("Failed to start conversation:",_t32),_this42.displayError(),_this42.hideLoading();case 9:return _context92.a(2);}},_callee92,null,[[1,8]]);})),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(e){var _this43=this;var t,s,i,n,o,a,l,c,_t35,_t36,_t37,_t38;return _regenerator().w(function(_context95){while(1)switch(_context95.p=_context95.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 _callee93(a){var l,_t33;return _regenerator().w(function(_context93){while(1)switch(_context93.n){case 0:if(!a.streams[0]){_context93.n=2;break;}s.srcObject=a.streams[0];l=i.createMediaStreamSource(a.streams[0]);_t33=i.state==="suspended";if(!_t33){_context93.n=1;break;}_context93.n=1;return i.resume();case 1:l.connect(n);_this43.monitorFrequencies(n,o);_context93.n=3;break;case 2:console.error("No streams found in the ontrack event."),_this43.displayError();case 3:return _context93.a(2);}},_callee93);}));return function(_x173){return _ref30.apply(this,arguments);};}();_context95.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var l;t===_this43._pc&&(_this43._mediaStream=a,(l=_this43._pc)==null||l.addTrack(_this43._mediaStream.getTracks()[0]),_this43._isMuted&&_this43.toggleMicorphone(!1));})["catch"](function(a){console.error("Error accessing microphone:",a),_this43.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(a){var c,d,u,l,p,m,f,_t34;return _regenerator().w(function(_context94){while(1)switch(_context94.p=_context94.n){case 0:l=JSON.parse(a.data);if(!(l.type==="session.created")){_context94.n=1;break;}_this43.removeUnavailable(),_this43._toggleButton&&(D.removeAriaAttributes(_this43._toggleButton.elementRef),_this43._toggleButton.changeToActive()),(d=(c=_this43._events)==null?void 0:c.started)==null||d.call(c),_this43._deepChat.dispatchEvent(new CustomEvent(Ds.SESSION_STARTED)),_this43.hideLoading();_context94.n=7;break;case 1:if(!(l.type==="response.done")){_context94.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")){_context94.n=5;break;}m=p.name,f=p.call_id;_context94.p=2;_context94.n=3;return _this43.handleTool(m,p.arguments,f);case 3:_context94.n=5;break;case 4:_context94.p=4;_t34=_context94.v;_this43.stopOnError(_t34);case 5:_context94.n=7;break;case 6:l.type==="error"?_this43.stopOnError(l.error.message):l.type==="invalid_request_error"?_this43.stopOnError(l.message):l.type;case 7:return _context94.a(2);}},_callee94,null,[[2,4]]);}));return function(_x174){return _ref31.apply(this,arguments);};}());_context95.p=2;_context95.n=3;return this._pc.createOffer();case 3:a=_context95.v;_t35=t!==this._pc;if(_t35){_context95.n=5;break;}_context95.n=4;return this._pc.setLocalDescription(a);case 4:_t35=t!==this._pc;case 5:if(!_t35){_context95.n=6;break;}return _context95.a(2);case 6:_context95.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=_context95.v;if(!(t!==this._pc)){_context95.n=8;break;}return _context95.a(2);case 8:_context95.n=9;return l.text();case 9:_t36=_context95.v;c={type:"answer",sdp:_t36};_t37=t!==this._pc;if(_t37){_context95.n=11;break;}_context95.n=10;return this._pc.setRemoteDescription(c);case 10:_t37=t!==this._pc;case 11:if(!_t37){_context95.n=12;break;}return _context95.a(2);case 12:_context95.n=14;break;case 13:_context95.p=13;_t38=_context95.v;console.error(_t38),this.displayError();case 14:return _context95.a(2);}},_callee95,this,[[2,13]]);}));function init(_x172){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
|
+
},{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 ii=/*#__PURE__*/_createClass(function ii(){_classCallCheck(this,ii);});ii.SESSION_STARTED="sts-session-started",ii.SESSION_STOPPED="sts-session-stopped";var Ds=ii;var er="<?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>",Ti="<?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>",L=/*#__PURE__*/function(_M6){function L(e){var _l$model;var _this39;_classCallCheck(this,L);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=L.getKey(e);_this39=_callSuper(this,L,[e,F.buildKeyVerificationDetails(),F.buildHeaders,{key:s}]),_this39.insertKeyPlaceholderText="OpenAI API Key",_this39.keyHelpUrl="https://platform.openai.com/account/api-keys",_this39._microphoneButton=null,_this39._toggleButton=null,_this39._errorElement=null,_this39._loadingElement=null,_this39._pc=null,_this39._mediaStream=null,_this39._isMuted=!1;var i=(n=t.openAI)==null?void 0:n.realtime;if(_typeof(i)=="object"){_this39._avatarConfig=i.avatar,_this39._ephemeralKey=i.ephemeralKey,_this39._errorConfig=i.error,_this39._loadingConfig=i.loading,Object.assign(_this39.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&&(_this39._functionHandler=d),_this39._events=i.events,c.methods=_this39.generateMethods();}(_l$model=(l=_this39.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="gpt-4o-realtime-preview-2025-06-03",_this39._avatarConfig=L.buildAvatarConfig(i),_this39._buttonsConfig=L.buildButtonsConfig(i),_this39._avatarEl=L.createAvatar(_this39._avatarConfig),_this39._containerEl=_this39.createContainer(),_this39._deepChat=e;return _this39;}_inherits(L,_M6);return _createClass(L,[{key:"setUpView",value:// called after API key was inserted
|
182
|
+
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 _callee89(){var i,e,t,s;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:e=(i=this._deepChat.directConnection)==null?void 0:i.openAI;if(e){_context89.n=1;break;}return _context89.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context89.n=2;break;}return _context89.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 _context89.a(2);}},_callee89,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var o,t,s,i,n,a,_t28,_t29,_t30;return _regenerator().w(function(_context90){while(1)switch(_context90.p=_context90.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")){_context90.n=8;break;}if(this._ephemeralKey){_context90.n=7;break;}_context90.p=1;if(!s){_context90.n=3;break;}a=s();a.then&&(this._retrievingEphemeralKey=a);_context90.n=2;return a;case 2:this._ephemeralKey=_context90.v;_context90.n=5;break;case 3:_t28=n;if(!_t28){_context90.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(n);_context90.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context90.v;case 5:_context90.n=7;break;case 6:_context90.p=6;_t29=_context90.v;this.displayFailedToRetrieveEphemeralKey(_t29);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context90.n=12;break;case 8:if(!n){_context90.n=12;break;}_context90.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(n);_context90.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context90.v;e&&this.init(this._ephemeralKey);_context90.n=12;break;case 11:_context90.p=11;_t30=_context90.v;this.displayFailedToRetrieveEphemeralKey(_t30);case 12:return _context90.a(2);}},_callee90,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x170){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:_context91.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:_context91.n=2;return _context91.v.json();case 2:return _context91.a(2,_context91.v.client_secret.value);}},_callee91,this);}));function getEphemeralKey(_x171){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this40=this;return{updateConfig:function updateConfig(e){var t;(t=_this40._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}]};_this40.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=L.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var s=L.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(s),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this41=this;var t;var e=new Bs((t=this._buttonsConfig)==null?void 0:t.microphone);return e.elementRef.classList.add(L.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),e.elementRef.onclick=function(){e.isActive?(_this41.toggleMicorphone(!0),e.elementRef.classList.replace(L.MICROPHONE_ACTIVE,L.BUTTON_DEFAULT),e.changeToDefault(),_this41._isMuted=!1):(_this41.toggleMicorphone(!1),e.elementRef.classList.replace(L.BUTTON_DEFAULT,L.MICROPHONE_ACTIVE),D.removeAriaAttributes(e.elementRef),e.changeToActive(),_this41._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 _this42=this;var t;var e=new Bs((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef.classList.add(L.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),e.elementRef.onclick=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(){var s,i,_t31,_t32;return _regenerator().w(function(_context92){while(1)switch(_context92.p=_context92.n){case 0:if(!e.isActive){_context92.n=1;break;}e.changeToDefault(),_this42.stop();_context92.n=9;break;case 1:_context92.p=1;if(!_this42._ephemeralKey){_context92.n=3;break;}_this42.displayLoading();_context92.n=2;return _this42.init(_this42._ephemeralKey);case 2:_context92.n=7;break;case 3:if(!_this42._retrievingEphemeralKey){_context92.n=6;break;}_this42.displayLoading();_context92.n=4;return _this42._retrievingEphemeralKey;case 4:i=_context92.v;_t31=(s=_this42._toggleButton)!=null&&s.isActive;if(!_t31){_context92.n=5;break;}_context92.n=5;return _this42.init(i);case 5:_context92.n=7;break;case 6:_this42.displayLoading();_context92.n=7;return _this42.fetchEphemeralKey(!0);case 7:_context92.n=9;break;case 8:_context92.p=8;_t32=_context92.v;console.error("Failed to start conversation:",_t32),_this42.displayError(),_this42.hideLoading();case 9:return _context92.a(2);}},_callee92,null,[[1,8]]);})),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(e){var _this43=this;var t,s,i,n,o,a,l,c,_t35,_t36,_t37,_t38;return _regenerator().w(function(_context95){while(1)switch(_context95.p=_context95.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 _callee93(a){var l,_t33;return _regenerator().w(function(_context93){while(1)switch(_context93.n){case 0:if(!a.streams[0]){_context93.n=2;break;}s.srcObject=a.streams[0];l=i.createMediaStreamSource(a.streams[0]);_t33=i.state==="suspended";if(!_t33){_context93.n=1;break;}_context93.n=1;return i.resume();case 1:l.connect(n);_this43.monitorFrequencies(n,o);_context93.n=3;break;case 2:console.error("No streams found in the ontrack event."),_this43.displayError();case 3:return _context93.a(2);}},_callee93);}));return function(_x173){return _ref30.apply(this,arguments);};}();_context95.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var l;t===_this43._pc&&(_this43._mediaStream=a,(l=_this43._pc)==null||l.addTrack(_this43._mediaStream.getTracks()[0]),_this43._isMuted&&_this43.toggleMicorphone(!1));})["catch"](function(a){console.error("Error accessing microphone:",a),_this43.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(a){var c,d,u,l,f,m,p,_t34;return _regenerator().w(function(_context94){while(1)switch(_context94.p=_context94.n){case 0:l=JSON.parse(a.data);if(!(l.type==="session.created")){_context94.n=1;break;}_this43.removeUnavailable(),_this43._toggleButton&&(D.removeAriaAttributes(_this43._toggleButton.elementRef),_this43._toggleButton.changeToActive()),(d=(c=_this43._events)==null?void 0:c.started)==null||d.call(c),_this43._deepChat.dispatchEvent(new CustomEvent(Ds.SESSION_STARTED)),_this43.hideLoading();_context94.n=7;break;case 1:if(!(l.type==="response.done")){_context94.n=6;break;}f=(u=JSON.parse(a.data).response.output)==null?void 0:u[0];if(!((f==null?void 0:f.type)==="function_call")){_context94.n=5;break;}m=f.name,p=f.call_id;_context94.p=2;_context94.n=3;return _this43.handleTool(m,f.arguments,p);case 3:_context94.n=5;break;case 4:_context94.p=4;_t34=_context94.v;_this43.stopOnError(_t34);case 5:_context94.n=7;break;case 6:l.type==="error"?_this43.stopOnError(l.error.message):l.type==="invalid_request_error"?_this43.stopOnError(l.message):l.type;case 7:return _context94.a(2);}},_callee94,null,[[2,4]]);}));return function(_x174){return _ref31.apply(this,arguments);};}());_context95.p=2;_context95.n=3;return this._pc.createOffer();case 3:a=_context95.v;_t35=t!==this._pc;if(_t35){_context95.n=5;break;}_context95.n=4;return this._pc.setLocalDescription(a);case 4:_t35=t!==this._pc;case 5:if(!_t35){_context95.n=6;break;}return _context95.a(2);case 6:_context95.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=_context95.v;if(!(t!==this._pc)){_context95.n=8;break;}return _context95.a(2);case 8:_context95.n=9;return l.text();case 9:_t36=_context95.v;c={type:"answer",sdp:_t36};_t37=t!==this._pc;if(_t37){_context95.n=11;break;}_context95.n=10;return this._pc.setRemoteDescription(c);case 10:_t37=t!==this._pc;case 11:if(!_t37){_context95.n=12;break;}return _context95.a(2);case 12:_context95.n=14;break;case 13:_context95.p=13;_t38=_context95.v;console.error(_t38),this.displayError();case 14:return _context95.a(2);}},_callee95,this,[[2,13]]);}));function init(_x172){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
|
184
183
|
// in such instance please wait and refresh at a later time
|
185
184
|
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this44=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=_this44._avatarConfig)==null?void 0:c.maxScale)-a);_this44._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(Ds.SESSION_STOPPED)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&L.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&L.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&L.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&L.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&L.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&L.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(L.BUTTON_LOADING),D.removeAriaDisabled(this._toggleButton.elementRef),D.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(L.BUTTON_LOADING),D.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement.style.display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
|
186
185
|
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(e,t,s){var i,n;return _regenerator().w(function(_context96){while(1)switch(_context96.n){case 0:if(this._functionHandler){_context96.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:_context96.n=2;return this._functionHandler({name:e,arguments:t});case 2:i=_context96.v;if(!(_typeof(i)!="object"||!W.isJson(i))){_context96.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 _context96.a(2);}},_callee96,this);}));function handleTool(_x175,_x176,_x177){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,
|
188
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t,s){var o,i,n;return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context99.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context99.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=ye.createFormDataBody(i,s[0]);S.tempRemoveContentHeader(this.connectSettings,
|
186
|
+
},{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,_f$svg,_m$content,_p$active,_g$svg,_v$content;var s,i,n,o,a,l,c,d,u,h,f,m,p,g,v;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=Qn),(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"]={},(_f$svg=(f=t.toggle["default"]).svg)!==null&&_f$svg!==void 0?_f$svg:f.svg={},(_m$content=(m=t.toggle["default"].svg).content)!==null&&_m$content!==void 0?_m$content:m.content=er,(_p$active=(p=t.toggle).active)!==null&&_p$active!==void 0?_p$active:p.active={},(_g$svg=(g=t.toggle.active).svg)!==null&&_g$svg!==void 0?_g$svg:g.svg={},(_v$content=(v=t.toggle.active.svg).content)!==null&&_v$content!==void 0?_v$content:v.content=Ti),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)||_i,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(L.UNAVAILABLE),D.removeAriaBusy(e.elementRef),D.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){L.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){D.removeAriaDisabled(e.elementRef),e.elementRef.classList.remove(L.UNAVAILABLE);}}]);}(M);L.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",L.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",L.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",L.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var Ai=L;var xt=/*#__PURE__*/function(_M7){function xt(e){var _o$model3,_a$voice3;var _this45;_classCallCheck(this,xt);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this45=_callSuper(this,xt,[e,F.buildKeyVerificationDetails(),F.buildHeaders,s]),_this45.insertKeyPlaceholderText="OpenAI API Key",_this45.keyHelpUrl="https://platform.openai.com/account/api-keys",_this45.url="https://api.openai.com/v1/audio/speech",_this45.permittedErrorPrefixes=["Invalid"],_this45.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(_this45.rawBody,i),(_o$model3=(o=_this45.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=xt.DEFAULT_MODEL,(_a$voice3=(a=_this45.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=xt.DEFAULT_VOIDE,_this45.textInputPlaceholderText="Insert text to generate audio",_this45.rawBody.response_format="mp3";return _this45;}_inherits(xt,_M7);return _createClass(xt,[{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 _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(e,t){var i,s;return _regenerator().w(function(_context97){while(1)switch(_context97.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context97.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);C.request(this,s,e);case 2:return _context97.a(2);}},_callee97,this);}));function callServiceAPI(_x178,_x179){return _callServiceAPI10.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(e){return _regenerator().w(function(_context98){while(1)switch(_context98.n){case 0:if(!(e instanceof Blob)){_context98.n=1;break;}return _context98.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){_context98.n=2;break;}throw e.error.message;case 2:return _context98.a(2,{error:"error"});}},_callee98);}));function extractResultData(_x180){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(M);xt.DEFAULT_MODEL="tts-1",xt.DEFAULT_VOIDE="alloy";var Ri=xt;var ye=/*#__PURE__*/function(_M8){function ye(e){var _o$model4;var _this46;_classCallCheck(this,ye);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this46=_callSuper(this,ye,[e,F.buildKeyVerificationDetails(),F.buildHeaders,s,{audio:{}}]),_this46.insertKeyPlaceholderText="OpenAI API Key",_this46.keyHelpUrl="https://platform.openai.com/account/api-keys",_this46.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>",_this46.url="",_this46.permittedErrorPrefixes=["Invalid"],_this46.textInputPlaceholderText="Upload an audio file",_this46._service_url=ye.AUDIO_TRANSCRIPTIONS_URL;var i=(n=t==null?void 0:t.openAI)==null?void 0:n.audio;_typeof(i)=="object"&&(_this46.processConfig(i),ye.cleanConfig(i),Object.assign(_this46.rawBody,i)),(_o$model4=(o=_this46.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=ye.DEFAULT_MODEL,_this46.rawBody.response_format="json",_this46.canSendMessage=ye.canSendFileMessage;return _this46;}_inherits(ye,_M8);return _createClass(ye,[{key:"processConfig",value:function processConfig(e){e!=null&&e.type&&e.type==="translation"&&(this._service_url=ye.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
|
187
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t,s){var o,i,n;return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context99.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context99.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=ye.createFormDataBody(i,s[0]);S.tempRemoveContentHeader(this.connectSettings,C.request.bind(this,this,n,e),!1);case 3:return _context99.a(2);}},_callee99,this);}));function callServiceAPI(_x181,_x182,_x183){return _callServiceAPI11.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee100(e){return _regenerator().w(function(_context100){while(1)switch(_context100.n){case 0:if(!e.error){_context100.n=1;break;}throw e.error.message;case 1:return _context100.a(2,{text:e.text});}},_callee100);}));function extractResultData(_x184){return _extractResultData14.apply(this,arguments);}return extractResultData;}()}],[{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.type;}},{key:"createFormDataBody",value:function createFormDataBody(e,t){var s=new FormData();return s.append("file",t),Object.keys(e).forEach(function(i){s.append(i,String(e[i]));}),s;}}]);}(M);ye.AUDIO_TRANSCRIPTIONS_URL="https://api.openai.com/v1/audio/transcriptions",ye.AUDIO_TRANSLATIONS_URL="https://api.openai.com/v1/audio/translations",ye.DEFAULT_MODEL="whisper-1";var Mi=ye;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
|
189
188
|
},{key:"handleSpeechVerificationResult",value:function handleSpeechVerificationResult(e,t,s,i){e.error?i(E.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
|
190
189
|
},{key:"handleLanguageVerificationResult",value:function handleLanguageVerificationResult(e,t,s,i){var o;((o=e.error)==null?void 0:o.code)==="401"?i(E.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
|
191
190
|
},{key:"handleTranslationVerificationResult",value:function handleTranslationVerificationResult(e,t,s,i){e.json().then(function(o){!Array.isArray(o)&&o.error.code===401e3?i(E.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 Ea=/*#__PURE__*/function(_M9){// prettier-ignore
|
192
191
|
function Ea(e,t,s,i,n){var _this47;_classCallCheck(this,Ea);_this47=_callSuper(this,Ea,[e,me.buildLanguageKeyVerificationDetails(s),t,i,n]),_this47.insertKeyPlaceholderText="Azure Language Subscription Key",_this47.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",_this47.permittedErrorPrefixes=["Access"];return _this47;}_inherits(Ea,_M9);return _createClass(Ea);}(M);var rs=/*#__PURE__*/function(_Ea){function rs(e){var _a$language;var _this48;_classCallCheck(this,rs);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;_this48=_callSuper(this,rs,[e,me.buildSummarizationHeader,t.endpoint,s]),_this48.permittedErrorPrefixes=[rs.ENDPOINT_ERROR_MESSAGE],_this48.url="",_this48.textInputPlaceholderText="Insert text to summarize",_this48.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this48.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this48.rawBody,t),_this48.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this48.isTextInputDisabled=!0,_this48.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:rs.ENDPOINT_ERROR_MESSAGE});}));return _this48;}_inherits(rs,_Ea);return _createClass(rs,[{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 _callServiceAPI12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e,t){var s;return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if(this.connectSettings){_context101.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);
|
192
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this47.permittedErrorPrefixes=["Access"];return _this47;}_inherits(Ea,_M9);return _createClass(Ea);}(M);var rs=/*#__PURE__*/function(_Ea){function rs(e){var _a$language;var _this48;_classCallCheck(this,rs);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;_this48=_callSuper(this,rs,[e,me.buildSummarizationHeader,t.endpoint,s]),_this48.permittedErrorPrefixes=[rs.ENDPOINT_ERROR_MESSAGE],_this48.url="",_this48.textInputPlaceholderText="Insert text to summarize",_this48.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this48.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this48.rawBody,t),_this48.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this48.isTextInputDisabled=!0,_this48.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:rs.ENDPOINT_ERROR_MESSAGE});}));return _this48;}_inherits(rs,_Ea);return _createClass(rs,[{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 _callServiceAPI12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e,t){var s;return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if(this.connectSettings){_context101.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);C.request(this,s,e),this.messages=e;case 2:return _context101.a(2);}},_callee101,this);}));function callServiceAPI(_x185,_x186){return _callServiceAPI12.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(e){var t,_s4,i;return _regenerator().w(function(_context102){while(1)switch(_context102.n){case 0:if(!e.error){_context102.n=1;break;}throw e.error.message;case 1:if(this.messages&&this.completionsHandlers){this.asyncCallInProgress=!0;_s4=e.headers.get("operation-location"),i={method:"GET",headers:(t=this.connectSettings)==null?void 0:t.headers};C.executePollRequest(this,_s4,i,this.messages);}return _context102.a(2,{text:""});}},_callee102,this);}));function extractResultData(_x187){return _extractResultData15.apply(this,arguments);}return extractResultData;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103(e){var t,_iterator,_step,_s5;return _regenerator().w(function(_context103){while(1)switch(_context103.n){case 0:if(!e.error){_context103.n=1;break;}throw e.error;case 1:if(!(e.status==="running"||e.status==="notStarted")){_context103.n=2;break;}return _context103.a(2,{timeoutMS:2e3});case 2:if(!(e.errors.length>0)){_context103.n=3;break;}throw e.errors[0];case 3:if(!(e.tasks.items[0].results.errors.length>0)){_context103.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 _context103.a(2,{text:t||""});}},_callee103);}));function extractPollResultData(_x188){return _extractPollResultData5.apply(this,arguments);}return extractPollResultData;}()}]);}(Ea);rs.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
194
193
|
"Please define the azure endpoint. [More Information](https://deepchat.dev/docs/directConnection/Azure#Summarization)";var ki=rs;var es=/*#__PURE__*/function(){function es(){_classCallCheck(this,es);}return _createClass(es,null,[{key:"poll",value:function(){var _poll2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(e,t){var s,a,l,d,_t39,_t40;return _regenerator().w(function(_context104){while(1)switch(_context104.n){case 0:s={authorization:e,"content-type":"application/json"};_t39="https://api.assemblyai.com/v2/transcript/";_context104.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:"POST",body:JSON.stringify({audio_url:t}),headers:s});case 1:_context104.n=2;return _context104.v.json();case 2:_t40=_context104.v.id;a=_t39.concat.call(_t39,_t40);case 3:if(l){_context104.n=9;break;}_context104.n=4;return fetch(a,{headers:s});case 4:_context104.n=5;return _context104.v.json();case 5:d=_context104.v;if(!(d.status==="completed")){_context104.n=6;break;}l=d;_context104.n=8;break;case 6:if(!(d.status==="error")){_context104.n=7;break;}throw new Error("Transcription failed: ".concat(d.error));case 7:_context104.n=8;return new Promise(function(u){return setTimeout(u,3e3);});case 8:_context104.n=3;break;case 9:return _context104.a(2,l);}},_callee104);}));function poll(_x189,_x190){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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.assemblyai.com/v2/upload",method:"POST",handleVerificationResult:es.handleVerificationResult};}}]);}();var Vi=/*#__PURE__*/function(_M0){function Vi(e){var _this49;_classCallCheck(this,Vi);var s;var t=(s=e.directConnection)==null?void 0:s.assemblyAI;_this49=_callSuper(this,Vi,[e,es.buildKeyVerificationDetails(),es.buildHeaders,t,{audio:{}}]),_this49.insertKeyPlaceholderText="AssemblyAI API Key",_this49.keyHelpUrl="https://www.assemblyai.com/app/account",_this49.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>",_this49.url="https://api.assemblyai.com/v2/upload",_this49.isTextInputDisabled=!0,_this49.textInputPlaceholderText="Upload an audio file",_this49.permittedErrorPrefixes=["Authentication","Invalid"],_this49.canSendMessage=Vi.canFileSendMessage;return _this49;}_inherits(Vi,_M0);return _createClass(Vi,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e,t,s){var i;return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context105.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context105.n=2;break;}throw new Error("No file was added");case 2:
|
194
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.assemblyai.com/v2/upload",method:"POST",handleVerificationResult:es.handleVerificationResult};}}]);}();var Vi=/*#__PURE__*/function(_M0){function Vi(e){var _this49;_classCallCheck(this,Vi);var s;var t=(s=e.directConnection)==null?void 0:s.assemblyAI;_this49=_callSuper(this,Vi,[e,es.buildKeyVerificationDetails(),es.buildHeaders,t,{audio:{}}]),_this49.insertKeyPlaceholderText="AssemblyAI API Key",_this49.keyHelpUrl="https://www.assemblyai.com/app/account",_this49.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>",_this49.url="https://api.assemblyai.com/v2/upload",_this49.isTextInputDisabled=!0,_this49.textInputPlaceholderText="Upload an audio file",_this49.permittedErrorPrefixes=["Authentication","Invalid"],_this49.canSendMessage=Vi.canFileSendMessage;return _this49;}_inherits(Vi,_M0);return _createClass(Vi,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e,t,s){var i;return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context105.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context105.n=2;break;}throw new Error("No file was added");case 2:C.request(this,s[0],e,!1);case 3:return _context105.a(2);}},_callee105,this);}));function callServiceAPI(_x191,_x192,_x193){return _callServiceAPI13.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(e){var i,n,t,_t41;return _regenerator().w(function(_context106){while(1)switch(_context106.n){case 0:if(!e.error){_context106.n=1;break;}throw e.error;case 1:t=(n=(i=this.connectSettings)==null?void 0:i.headers)==null?void 0:n.Authorization;_context106.n=2;return es.poll(t,e.upload_url);case 2:_t41=_context106.v.text;return _context106.a(2,{text:_t41});}},_callee106,this);}));function extractResultData(_x194){return _extractResultData16.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(M);var tr=/*#__PURE__*/function(_M1){// prettier-ignore
|
196
195
|
function tr(e,t,s,i,n){var _this50;_classCallCheck(this,tr);_this50=_callSuper(this,tr,[e,me.buildSpeechKeyVerificationDetails(s),t,i,n]),_this50.insertKeyPlaceholderText="Azure Speech Subscription Key",_this50.keyHelpUrl=// eslint-disable-next-line max-len
|
197
196
|
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal";return _this50;}_inherits(tr,_M1);return _createClass(tr);}(M);var ot=/*#__PURE__*/function(_tr){// prettier-ignore
|
198
|
-
function ot(e){var _a$lang,_l$name,_c$gender;var _this51;_classCallCheck(this,ot);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;_this51=_callSuper(this,ot,[e,me.buildTextToSpeechHeaders.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,s]),_this51.permittedErrorPrefixes=[ot.REGION_ERROR_MESSAGE],_this51.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(ot.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this51.isTextInputDisabled=!1,_this51.url="",t.region?(Object.assign(_this51.rawBody,t),(_a$lang=(a=_this51.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_l$name=(l=_this51.rawBody).name)!==null&&_l$name!==void 0?_l$name:l.name="en-US-JennyNeural",(_c$gender=(c=_this51.rawBody).gender)!==null&&_c$gender!==void 0?_c$gender:c.gender="Female",_this51.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this51.isTextInputDisabled=!0,_this51.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:ot.REGION_ERROR_MESSAGE});}));return _this51;}_inherits(ot,_tr);return _createClass(ot,[{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 _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(e,t){var s;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:if(this.connectSettings){_context107.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);
|
197
|
+
function ot(e){var _a$lang,_l$name,_c$gender;var _this51;_classCallCheck(this,ot);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;_this51=_callSuper(this,ot,[e,me.buildTextToSpeechHeaders.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,s]),_this51.permittedErrorPrefixes=[ot.REGION_ERROR_MESSAGE],_this51.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(ot.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this51.isTextInputDisabled=!1,_this51.url="",t.region?(Object.assign(_this51.rawBody,t),(_a$lang=(a=_this51.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_l$name=(l=_this51.rawBody).name)!==null&&_l$name!==void 0?_l$name:l.name="en-US-JennyNeural",(_c$gender=(c=_this51.rawBody).gender)!==null&&_c$gender!==void 0?_c$gender:c.gender="Female",_this51.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this51.isTextInputDisabled=!0,_this51.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:ot.REGION_ERROR_MESSAGE});}));return _this51;}_inherits(ot,_tr);return _createClass(ot,[{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 _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(e,t){var s;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:if(this.connectSettings){_context107.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);C.request(this,s,e,!1);case 2:return _context107.a(2);}},_callee107,this);}));function callServiceAPI(_x195,_x196){return _callServiceAPI14.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(e){return _regenerator().w(function(_context108){while(1)switch(_context108.n){case 0:return _context108.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"}]});};}));}},_callee108);}));function extractResultData(_x197){return _extractResultData17.apply(this,arguments);}return extractResultData;}()}]);}(tr);ot.HELP_LINK=// eslint-disable-next-line max-len
|
199
198
|
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",ot.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 Li=ot;var We=/*#__PURE__*/function(_tr2){function We(e){var _this52;_classCallCheck(this,We);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(_this52=_callSuper(this,We,[e,me.buildSpeechToTextHeaders,t.region,s,i]),_this52.permittedErrorPrefixes=[We.REGION_ERROR_MESSAGE],_this52.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(We.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this52.url="",_this52.isTextInputDisabled=!0,_this52.textInputPlaceholderText="Upload an audio file",!t.region)_this52.isTextInputDisabled=!0,_this52.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:We.REGION_ERROR_MESSAGE});});else{_this52.canSendMessage=We.canFileSendMessage;var l=t.lang||"en-US";_this52.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(l,"&format=detailed"),_this52.recordAudio=void 0;}return _this52;}_inherits(We,_tr2);return _createClass(We,[{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e,t,s){var i,n;return _regenerator().w(function(_context109){while(1)switch(_context109.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context109.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context109.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"),
|
199
|
+
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#TextToSpeech)";var Li=ot;var We=/*#__PURE__*/function(_tr2){function We(e){var _this52;_classCallCheck(this,We);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(_this52=_callSuper(this,We,[e,me.buildSpeechToTextHeaders,t.region,s,i]),_this52.permittedErrorPrefixes=[We.REGION_ERROR_MESSAGE],_this52.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(We.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this52.url="",_this52.isTextInputDisabled=!0,_this52.textInputPlaceholderText="Upload an audio file",!t.region)_this52.isTextInputDisabled=!0,_this52.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:We.REGION_ERROR_MESSAGE});});else{_this52.canSendMessage=We.canFileSendMessage;var l=t.lang||"en-US";_this52.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(l,"&format=detailed"),_this52.recordAudio=void 0;}return _this52;}_inherits(We,_tr2);return _createClass(We,[{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e,t,s){var i,n;return _regenerator().w(function(_context109){while(1)switch(_context109.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context109.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context109.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"),C.request(this,s[0],e,!1);case 3:return _context109.a(2);}},_callee109,this);}));function callServiceAPI(_x198,_x199,_x200){return _callServiceAPI15.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(e){return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:if(!e.error){_context110.n=1;break;}throw e.error;case 1:return _context110.a(2,{text:e.DisplayText||""});}},_callee110);}));function extractResultData(_x201){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(tr);We.HELP_LINK=// eslint-disable-next-line max-len
|
201
200
|
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",We.REGION_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
202
201
|
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#SpeechToText)";var Ii=We;var _a=/*#__PURE__*/function(_M10){// prettier-ignore
|
203
202
|
function _a(e){var _this53;_classCallCheck(this,_a);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;_this53=_callSuper(this,_a,[e,me.buildTranslationKeyVerificationDetails(t.region),me.buildTranslationHeaders.bind({},t==null?void 0:t.region),s]),_this53.insertKeyPlaceholderText="Azure Translate Subscription Key",_this53.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",_this53.url="",_this53.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this53;}_inherits(_a,_M10);return _createClass(_a,[{key:"preprocessBody",value:function preprocessBody(e){var t=e[e.length-1].text;if(t)return[{Text:t}];}},{key:"callServiceAPI",value:function(){var _callServiceAPI16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e,t){var s;return _regenerator().w(function(_context111){while(1)switch(_context111.n){case 0:if(this.connectSettings){_context111.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(t);
|
203
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this53.url="",_this53.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this53;}_inherits(_a,_M10);return _createClass(_a,[{key:"preprocessBody",value:function preprocessBody(e){var t=e[e.length-1].text;if(t)return[{Text:t}];}},{key:"callServiceAPI",value:function(){var _callServiceAPI16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e,t){var s;return _regenerator().w(function(_context111){while(1)switch(_context111.n){case 0:if(this.connectSettings){_context111.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(t);C.request(this,s,e);case 2:return _context111.a(2);}},_callee111,this);}));function callServiceAPI(_x202,_x203){return _callServiceAPI16.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(e){var t;return _regenerator().w(function(_context112){while(1)switch(_context112.n){case 0:if(!Array.isArray(e)){_context112.n=1;break;}return _context112.a(2,{text:((t=e[0].translations)==null?void 0:t[0].text)||""});case 1:throw e.error;case 2:return _context112.a(2);}},_callee112);}));function extractResultData(_x204){return _extractResultData19.apply(this,arguments);}return extractResultData;}()}]);}(M);var Sa=/*#__PURE__*/function(_M11){function Sa(e){var _o$model5;var _this54;_classCallCheck(this,Sa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this54=_callSuper(this,Sa,[e,Ye.buildKeyVerificationDetails(),Ye.buildHeaders,s]),_this54.insertKeyPlaceholderText="BigModel API Key",_this54.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this54.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this54.permittedErrorPrefixes=["Authorization","authentication_error"];var i=(n=t.bigModel)==null?void 0:n.images;_typeof(i)=="object"&&(_this54.cleanConfig(i),Object.assign(_this54.rawBody,i)),(_o$model5=(o=_this54.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this54;}_inherits(Sa,_M11);return _createClass(Sa,[{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[t.length-1];return s.prompt=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113(e,t){var s;return _regenerator().w(function(_context113){while(1)switch(_context113.n){case 0:if(this.connectSettings){_context113.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context113.n=2;return C.request(this,s,e);case 2:return _context113.a(2,_context113.v);}},_callee113,this);}));function callServiceAPI(_x205,_x206){return _callServiceAPI17.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee114(e){return _regenerator().w(function(_context114){while(1)switch(_context114.n){case 0:return _context114.a(2,{files:e.data.map(function(s){return s!=null&&s.url?{src:s.url,type:"image"}:{src:"",type:"image"};})});}},_callee114);}));function extractResultData(_x207){return _extractResultData20.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ct=/*#__PURE__*/function(){function Ct(){_classCallCheck(this,Ct);}return _createClass(Ct,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message==="Unauthorized"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.groq.com/openai/v1/models",method:"GET",handleVerificationResult:Ct.handleVerificationResult};}}]);}();var xa=/*#__PURE__*/function(_M12){function xa(e){var _o$model6,_a$voice4,_l$response_format;var _this55;_classCallCheck(this,xa);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this55=_callSuper(this,xa,[e,Ct.buildKeyVerificationDetails(),Ct.buildHeaders,s]),_this55.insertKeyPlaceholderText="Groq API Key",_this55.keyHelpUrl="https://console.groq.com/keys",_this55.url="https://api.groq.com/openai/v1/audio/speech",_this55.permittedErrorPrefixes=["Invalid","property"];var i=(n=t.groq)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&(_this55.cleanConfig(i),Object.assign(_this55.rawBody,i)),(_o$model6=(o=_this55.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this55.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_l$response_format=(l=_this55.rawBody).response_format)!==null&&_l$response_format!==void 0?_l$response_format:l.response_format="mp3";return _this55;}_inherits(xa,_M12);return _createClass(xa,[{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[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(e,t){var s;return _regenerator().w(function(_context115){while(1)switch(_context115.n){case 0:if(this.connectSettings){_context115.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context115.n=2;return C.request(this,s,e);case 2:return _context115.a(2,_context115.v);}},_callee115,this);}));function callServiceAPI(_x208,_x209){return _callServiceAPI18.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee116(e){var t,s;return _regenerator().w(function(_context116){while(1)switch(_context116.n){case 0:t=this.rawBody.response_format||"mp3",s=new Blob([e],{type:"audio/".concat(t)});return _context116.a(2,{files:[{src:URL.createObjectURL(s),type:"audio"}]});}},_callee116,this);}));function extractResultData(_x210){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(M);var wa=/*#__PURE__*/function(_M13){function wa(e){var _o$model7;var _this56;_classCallCheck(this,wa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this56=_callSuper(this,wa,[e,Ze.buildKeyVerificationDetails(),Ze.buildHeaders,s]),_this56.insertKeyPlaceholderText="Together AI API Key",_this56.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this56.url="https://api.together.xyz/v1/images/generations",_this56.permittedErrorPrefixes=["invalid_request_error","authentication_error"];var i=(n=t.together)==null?void 0:n.images;_typeof(i)=="object"&&(_this56.cleanConfig(i),Object.assign(_this56.rawBody,i)),(_o$model7=(o=_this56.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this56;}_inherits(wa,_M13);return _createClass(wa,[{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[t.length-1];return s.prompt=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee117(e,t){var s;return _regenerator().w(function(_context117){while(1)switch(_context117.n){case 0:if(this.connectSettings){_context117.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context117.n=2;return C.request(this,s,e);case 2:return _context117.a(2,_context117.v);}},_callee117,this);}));function callServiceAPI(_x211,_x212){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee118(e){return _regenerator().w(function(_context118){while(1)switch(_context118.n){case 0:return _context118.a(2,{files:e.data.map(function(s){return s!=null&&s.url?{src:s.url,type:"image"}:s!=null&&s.b64_json?{src:"data:image/png;base64,".concat(s.b64_json),type:"image"}:{src:"",type:"image"};})});}},_callee118);}));function extractResultData(_x213){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(M);var lt=/*#__PURE__*/function(_M14){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
|
205
204
|
// prettier-ignore
|
206
|
-
function lt(e,t,s,i,n){var _this57$maxMessages,
|
205
|
+
function lt(e,t,s,i,n){var _this57$maxMessages,_p$model;var _this57;_classCallCheck(this,lt);var u,h,f,m,p;var o=JSON.parse(JSON.stringify(e.directConnection)),a=t||F.buildKeyVerificationDetails(),l=s||F.buildHeaders,c=i||o.openAI;_this57=_callSuper(this,lt,[e,a,l,c]),_this57.insertKeyPlaceholderText="OpenAI API Key",_this57.keyHelpUrl="https://platform.openai.com/account/api-keys",_this57.url="https://api.openai.com/v1/chat/completions",_this57.permittedErrorPrefixes=["Incorrect"],_this57._systemMessage=lt.generateSystemMessage("You are a helpful assistant.");var d=n||((u=o.openAI)==null?void 0:u.chat);if(_typeof(d)=="object"){d.system_prompt&&(_this57._systemMessage=lt.generateSystemMessage(d.system_prompt));var g=(m=(f=(h=e.directConnection)==null?void 0:h.openAI)==null?void 0:f.chat)==null?void 0:m.function_handler;g&&(_this57._functionHandler=g),_this57.cleanConfig(d),Object.assign(_this57.rawBody,d);}(_this57$maxMessages=_this57.maxMessages)!==null&&_this57$maxMessages!==void 0?_this57$maxMessages:_this57.maxMessages=-1,(_p$model=(p=_this57.rawBody).model)!==null&&_p$model!==void 0?_p$model:p.model="gpt-4o";return _this57;}_inherits(lt,_M14);return _createClass(lt,[{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
|
207
206
|
// use speech to speech instead
|
208
207
|
// give allowed regex example for audio format rules
|
209
208
|
},{key:"preprocessBody",value:// prettier-ignore
|
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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.content.length:-1).map(function(a){return{content:lt.getContent(a,i),role:a.role===y.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 _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e,t){var _this$_messages3;var s,i;return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:if(this.connectSettings){_context119.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)):A.request(this,s,e);case 2:return _context119.a(2);}},_callee119,this);}));function callServiceAPI(_x214,_x215){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee120(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:if(!e.error){_context120.n=1;break;}throw e.error.message;case 1:if(!((i=(s=e.choices)==null?void 0:s[0])!=null&&i.delta)){_context120.n=2;break;}return _context120.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(n=e.choices)==null?void 0:n[0])!=null&&o.message)){_context120.n=5;break;}if(!e.choices[0].message.tool_calls){_context120.n=3;break;}return _context120.a(2,this.handleTools(e.choices[0].message,t));case 3:if(!((a=e.choices[0].message)!=null&&a.audio)){_context120.n=4;break;}c=this.deepChat.textToSpeech,d=_typeof(c)=="object"&&typeof((l=c==null?void 0:c.service)==null?void 0:l.displayText)=="boolean";return _context120.a(2,{files:[{src:"data:audio/wav;base64,".concat(e.choices[0].message.audio.data),type:"audio"}],text:d?e.choices[0].message.audio.transcript:void 0});case 4:return _context120.a(2,{text:e.choices[0].message.content});case 5:return _context120.a(2,{text:""});}},_callee120,this);}));function extractResultData(_x216,_x217){return _extractResultData23.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e,t){var _this58=this;var s,i,n;return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context121.n=1;break;}n={tool_calls:this._streamToolCalls};return _context121.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this58._streamToolCalls&&(_this58._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context121.a(2,{text:(s==null?void 0:s.content)||""});}},_callee121,this);}));function extractStreamResult(_x218,_x219){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e,t){var s,i,_yield$this$callToolF,n,o;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context122.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context122.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF=_context122.v;n=_yield$this$callToolF.responses;o=_yield$this$callToolF.processedResponse;if(!o){_context122.n=3;break;}return _context122.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref32){var a=_ref32.response;return typeof a!="string";})&&i.length===n.length)){_context122.n=4;break;}return _context122.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error(F.FUNCTION_TOOL_RESP_ERROR);case 5:return _context122.a(2);}},_callee122,this);}));function handleTools(_x220,_x221){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=lt.getFileContent(e.files,t);return e.text&&e.text.trim().length>0&&_s6.unshift({type:"text",text:e.text}),_s6;}return e.text;}}]);}(M);var zi=/*#__PURE__*/function(_lt){function zi(e){var _this59;_classCallCheck(this,zi);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(_this59=_callSuper(this,zi,[e,fe.buildKeyVerificationDetails(i),fe.buildHeaders,s,n]),_this59.permittedErrorPrefixes=[fe.URL_DETAILS_ERROR_MESSAGE],_this59.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&&(_this59._functionHandler=p);}fe.validateURLDetails(i)?_this59.url=zi.buildURL(i):(_this59.isTextInputDisabled=!0,_this59.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:fe.URL_DETAILS_ERROR_MESSAGE});}));return _this59;}_inherits(zi,_lt);return _createClass(zi,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);}}]);}(lt);var Fs=/*#__PURE__*/function(_M15){function Fs(e){var _this60$maxMessages,_c$model;var _this60;_classCallCheck(this,Fs);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this60=_callSuper(this,Fs,[e,Ye.buildKeyVerificationDetails(),Ye.buildHeaders,s]),_this60.insertKeyPlaceholderText="BigModel API Key",_this60.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this60.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this60.permittedErrorPrefixes=["Authorization","authentication_error"],_this60._systemMessage="You are a helpful assistant.";var i=(n=t.bigModel)==null?void 0:n.chat;if(_typeof(i)=="object"){i.system_prompt&&(_this60._systemMessage=i.system_prompt);var d=(l=(a=(o=e.directConnection)==null?void 0:o.bigModel)==null?void 0:a.chat)==null?void 0:l.function_handler;d&&(_this60._functionHandler=d),_this60.cleanConfig(i),Object.assign(_this60.rawBody,i);}(_this60$maxMessages=_this60.maxMessages)!==null&&_this60$maxMessages!==void 0?_this60$maxMessages:_this60.maxMessages=-1,(_c$model=(c=_this60.rawBody).model)!==null&&_c$model!==void 0?_c$model:c.model="glm-4.5";return _this60;}_inherits(Fs,_M15);return _createClass(Fs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Fs.getContent(n),role:n.role==="ai"?"assistant":"user"};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e,t){var _this$_messages4;var s,i;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:if(this.connectSettings){_context123.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)):A.request(this,s,e);case 2:return _context123.a(2);}},_callee123,this);}));function callServiceAPI(_x222,_x223){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e,t){var _s7;return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:if(!e.error){_context124.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context124.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context124.n=2;break;}return _context124.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context124.n=3;break;}_s7=e.choices[0].message;return _context124.a(2,_s7.tool_calls?this.handleTools({tool_calls:_s7.tool_calls},t):{text:_s7.content});case 3:return _context124.a(2,{text:""});}},_callee124,this);}));function extractResultData(_x224,_x225){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(e,t){var o,a,l,c,s,i,n,d;return _regenerator().w(function(_context125){while(1)switch(_context125.n){case 0:s=e.delta,i=e.finish_reason,n=(o=this._messages)==null?void 0:o.messageToElements[this._messages.messageToElements.length-2];if(!((n==null?void 0:n[0].role)==="ai"&&((a=n==null?void 0:n[0].text)==null?void 0:a.replace(/\n/g,"").trim().length)===0&&((l=this._messages)==null||l.removeMessage(n[1].text),(c=this._messages)==null||c.messageToElements.splice(this._messages.messageToElements.length-2,1)),i==="tool_calls")){_context125.n=2;break;}if(!s.tool_calls){_context125.n=1;break;}d={tool_calls:s.tool_calls};return _context125.a(2,this.handleTools(d,t));case 1:return _context125.a(2,{text:(s==null?void 0:s.content)||""});case 2:return _context125.a(2,{text:(s==null?void 0:s.content)||""});}},_callee125,this);}));function extractStreamResult(_x226,_x227){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(e,t){var s,i,_yield$this$callToolF2,n,o;return _regenerator().w(function(_context126){while(1)switch(_context126.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context126.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context126.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF2=_context126.v;n=_yield$this$callToolF2.responses;o=_yield$this$callToolF2.processedResponse;if(!o){_context126.n=3;break;}return _context126.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref34){var a=_ref34.response;return typeof a!="string";})&&i.length===n.length)){_context126.n=4;break;}return _context126.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context126.a(2);}},_callee126,this);}));function handleTools(_x228,_x229){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t.type==="image"?{type:"image_url",image_url:{url:t.src||""}}:{type:"file",file_url:{url:t.src||""}};});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=Fs.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t;}return e.text||"";}}]);}(M);var Aa=/*#__PURE__*/function(_M16){function Aa(e){var _this61$maxMessages,_o$model8;var _this61;_classCallCheck(this,Aa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this61=_callSuper(this,Aa,[e,Ze.buildKeyVerificationDetails(),Ze.buildHeaders,s]),_this61.insertKeyPlaceholderText="Together AI API Key",_this61.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this61.url="https://api.together.xyz/v1/chat/completions",_this61.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this61._systemMessage="You are a helpful assistant.";var i=(n=t.together)==null?void 0:n.chat;_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,(_o$model8=(o=_this61.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this61;}_inherits(Aa,_M16);return _createClass(Aa,[{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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role==="ai"?"assistant":n.role};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var s,i;return _regenerator().w(function(_context127){while(1)switch(_context127.n){case 0:if(this.connectSettings){_context127.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)):A.request(this,s,e);case 2:return _context127.a(2);}},_callee127,this);}));function callServiceAPI(_x230,_x231){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e){return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:if(!e.error){_context128.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context128.n=3;break;}if(!(e.choices[0].message!==void 0)){_context128.n=2;break;}return _context128.a(2,{text:e.choices[0].message.content});case 2:if(!(e.choices[0].delta!==void 0)){_context128.n=3;break;}return _context128.a(2,{text:e.choices[0].delta.content});case 3:return _context128.a(2,{text:""});}},_callee128);}));function extractResultData(_x232){return _extractResultData25.apply(this,arguments);}return extractResultData;}()}]);}(M);var be=/*#__PURE__*/function(_M17){function be(e){var _this62;_classCallCheck(this,be);var o;var t=e.directConnection,s=t==null?void 0:t.openAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};_this62=_callSuper(this,be,[e,F.buildKeyVerificationDetails(),F.buildHeaders,s,i]),_this62.insertKeyPlaceholderText="OpenAI API Key",_this62.keyHelpUrl="https://platform.openai.com/account/api-keys",_this62.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>",_this62.url="",_this62.permittedErrorPrefixes=["Incorrect","Invalid input image"];var n=(o=t==null?void 0:t.openAI)==null?void 0:o.images;if(_this62.camera){var a=_typeof(n)=="object"&&n.size?Number.parseInt(n.size):1024;_this62.camera.files={dimensions:{width:a,height:a}};}_typeof(n)=="object"&&Object.assign(_this62.rawBody,n),_this62.canSendMessage=be.canFileSendMessage;return _this62;}_inherits(be,_M17);return _createClass(be,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}// prettier-ignore
|
211
|
-
},{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=be.IMAGE_EDIT_URL;var l=this.preprocessBody(this.rawBody,n);i=be.createFormDataBody(l,s[0],s[1]);}else this.url=be.IMAGE_VARIATIONS_URL,i=be.createFormDataBody(this.rawBody,s[0]);S.tempRemoveContentHeader(this.connectSettings,
|
209
|
+
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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.content.length:-1).map(function(a){return{content:lt.getContent(a,i),role:a.role===y.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 _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e,t){var _this$_messages3;var s,i;return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:if(this.connectSettings){_context119.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)):C.request(this,s,e);case 2:return _context119.a(2);}},_callee119,this);}));function callServiceAPI(_x214,_x215){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee120(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:if(!e.error){_context120.n=1;break;}throw e.error.message;case 1:if(!((i=(s=e.choices)==null?void 0:s[0])!=null&&i.delta)){_context120.n=2;break;}return _context120.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(n=e.choices)==null?void 0:n[0])!=null&&o.message)){_context120.n=5;break;}if(!e.choices[0].message.tool_calls){_context120.n=3;break;}return _context120.a(2,this.handleTools(e.choices[0].message,t));case 3:if(!((a=e.choices[0].message)!=null&&a.audio)){_context120.n=4;break;}c=this.deepChat.textToSpeech,d=_typeof(c)=="object"&&typeof((l=c==null?void 0:c.service)==null?void 0:l.displayText)=="boolean";return _context120.a(2,{files:[{src:"data:audio/wav;base64,".concat(e.choices[0].message.audio.data),type:"audio"}],text:d?e.choices[0].message.audio.transcript:void 0});case 4:return _context120.a(2,{text:e.choices[0].message.content});case 5:return _context120.a(2,{text:""});}},_callee120,this);}));function extractResultData(_x216,_x217){return _extractResultData23.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e,t){var _this58=this;var s,i,n;return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context121.n=1;break;}n={tool_calls:this._streamToolCalls};return _context121.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this58._streamToolCalls&&(_this58._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context121.a(2,{text:(s==null?void 0:s.content)||""});}},_callee121,this);}));function extractStreamResult(_x218,_x219){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e,t){var s,i,_yield$this$callToolF,n,o;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context122.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context122.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF=_context122.v;n=_yield$this$callToolF.responses;o=_yield$this$callToolF.processedResponse;if(!o){_context122.n=3;break;}return _context122.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref32){var a=_ref32.response;return typeof a!="string";})&&i.length===n.length)){_context122.n=4;break;}return _context122.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error(F.FUNCTION_TOOL_RESP_ERROR);case 5:return _context122.a(2);}},_callee122,this);}));function handleTools(_x220,_x221){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=lt.getFileContent(e.files,t);return e.text&&e.text.trim().length>0&&_s6.unshift({type:"text",text:e.text}),_s6;}return e.text;}}]);}(M);var zi=/*#__PURE__*/function(_lt){function zi(e){var _this59;_classCallCheck(this,zi);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(_this59=_callSuper(this,zi,[e,pe.buildKeyVerificationDetails(i),pe.buildHeaders,s,n]),_this59.permittedErrorPrefixes=[pe.URL_DETAILS_ERROR_MESSAGE],_this59.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,f=_ref33.function_handler;f&&(_this59._functionHandler=f);}pe.validateURLDetails(i)?_this59.url=zi.buildURL(i):(_this59.isTextInputDisabled=!0,_this59.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:pe.URL_DETAILS_ERROR_MESSAGE});}));return _this59;}_inherits(zi,_lt);return _createClass(zi,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);}}]);}(lt);var Fs=/*#__PURE__*/function(_M15){function Fs(e){var _this60$maxMessages,_c$model;var _this60;_classCallCheck(this,Fs);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this60=_callSuper(this,Fs,[e,Ye.buildKeyVerificationDetails(),Ye.buildHeaders,s]),_this60.insertKeyPlaceholderText="BigModel API Key",_this60.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this60.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this60.permittedErrorPrefixes=["Authorization","authentication_error"],_this60._systemMessage="You are a helpful assistant.";var i=(n=t.bigModel)==null?void 0:n.chat;if(_typeof(i)=="object"){i.system_prompt&&(_this60._systemMessage=i.system_prompt);var d=(l=(a=(o=e.directConnection)==null?void 0:o.bigModel)==null?void 0:a.chat)==null?void 0:l.function_handler;d&&(_this60._functionHandler=d),_this60.cleanConfig(i),Object.assign(_this60.rawBody,i);}(_this60$maxMessages=_this60.maxMessages)!==null&&_this60$maxMessages!==void 0?_this60$maxMessages:_this60.maxMessages=-1,(_c$model=(c=_this60.rawBody).model)!==null&&_c$model!==void 0?_c$model:c.model="glm-4.5";return _this60;}_inherits(Fs,_M15);return _createClass(Fs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Fs.getContent(n),role:n.role==="ai"?"assistant":"user"};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e,t){var _this$_messages4;var s,i;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:if(this.connectSettings){_context123.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)):C.request(this,s,e);case 2:return _context123.a(2);}},_callee123,this);}));function callServiceAPI(_x222,_x223){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e,t){var _s7;return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:if(!e.error){_context124.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context124.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context124.n=2;break;}return _context124.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context124.n=3;break;}_s7=e.choices[0].message;return _context124.a(2,_s7.tool_calls?this.handleTools({tool_calls:_s7.tool_calls},t):{text:_s7.content});case 3:return _context124.a(2,{text:""});}},_callee124,this);}));function extractResultData(_x224,_x225){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(e,t){var o,a,l,c,s,i,n,d;return _regenerator().w(function(_context125){while(1)switch(_context125.n){case 0:s=e.delta,i=e.finish_reason,n=(o=this._messages)==null?void 0:o.messageToElements[this._messages.messageToElements.length-2];if(!((n==null?void 0:n[0].role)==="ai"&&((a=n==null?void 0:n[0].text)==null?void 0:a.replace(/\n/g,"").trim().length)===0&&((l=this._messages)==null||l.removeMessage(n[1].text),(c=this._messages)==null||c.messageToElements.splice(this._messages.messageToElements.length-2,1)),i==="tool_calls")){_context125.n=2;break;}if(!s.tool_calls){_context125.n=1;break;}d={tool_calls:s.tool_calls};return _context125.a(2,this.handleTools(d,t));case 1:return _context125.a(2,{text:(s==null?void 0:s.content)||""});case 2:return _context125.a(2,{text:(s==null?void 0:s.content)||""});}},_callee125,this);}));function extractStreamResult(_x226,_x227){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(e,t){var s,i,_yield$this$callToolF2,n,o;return _regenerator().w(function(_context126){while(1)switch(_context126.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context126.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context126.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF2=_context126.v;n=_yield$this$callToolF2.responses;o=_yield$this$callToolF2.processedResponse;if(!o){_context126.n=3;break;}return _context126.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref34){var a=_ref34.response;return typeof a!="string";})&&i.length===n.length)){_context126.n=4;break;}return _context126.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context126.a(2);}},_callee126,this);}));function handleTools(_x228,_x229){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t.type==="image"?{type:"image_url",image_url:{url:t.src||""}}:{type:"file",file_url:{url:t.src||""}};});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=Fs.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t;}return e.text||"";}}]);}(M);var Ca=/*#__PURE__*/function(_M16){function Ca(e){var _this61$maxMessages,_o$model8;var _this61;_classCallCheck(this,Ca);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this61=_callSuper(this,Ca,[e,Ze.buildKeyVerificationDetails(),Ze.buildHeaders,s]),_this61.insertKeyPlaceholderText="Together AI API Key",_this61.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this61.url="https://api.together.xyz/v1/chat/completions",_this61.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this61._systemMessage="You are a helpful assistant.";var i=(n=t.together)==null?void 0:n.chat;_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,(_o$model8=(o=_this61.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this61;}_inherits(Ca,_M16);return _createClass(Ca,[{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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role==="ai"?"assistant":n.role};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var s,i;return _regenerator().w(function(_context127){while(1)switch(_context127.n){case 0:if(this.connectSettings){_context127.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)):C.request(this,s,e);case 2:return _context127.a(2);}},_callee127,this);}));function callServiceAPI(_x230,_x231){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e){return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:if(!e.error){_context128.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context128.n=3;break;}if(!(e.choices[0].message!==void 0)){_context128.n=2;break;}return _context128.a(2,{text:e.choices[0].message.content});case 2:if(!(e.choices[0].delta!==void 0)){_context128.n=3;break;}return _context128.a(2,{text:e.choices[0].delta.content});case 3:return _context128.a(2,{text:""});}},_callee128);}));function extractResultData(_x232){return _extractResultData25.apply(this,arguments);}return extractResultData;}()}]);}(M);var be=/*#__PURE__*/function(_M17){function be(e){var _this62;_classCallCheck(this,be);var o;var t=e.directConnection,s=t==null?void 0:t.openAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};_this62=_callSuper(this,be,[e,F.buildKeyVerificationDetails(),F.buildHeaders,s,i]),_this62.insertKeyPlaceholderText="OpenAI API Key",_this62.keyHelpUrl="https://platform.openai.com/account/api-keys",_this62.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>",_this62.url="",_this62.permittedErrorPrefixes=["Incorrect","Invalid input image"];var n=(o=t==null?void 0:t.openAI)==null?void 0:o.images;if(_this62.camera){var a=_typeof(n)=="object"&&n.size?Number.parseInt(n.size):1024;_this62.camera.files={dimensions:{width:a,height:a}};}_typeof(n)=="object"&&Object.assign(_this62.rawBody,n),_this62.canSendMessage=be.canFileSendMessage;return _this62;}_inherits(be,_M17);return _createClass(be,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}// prettier-ignore
|
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=be.IMAGE_EDIT_URL;var l=this.preprocessBody(this.rawBody,n);i=be.createFormDataBody(l,s[0],s[1]);}else this.url=be.IMAGE_VARIATIONS_URL,i=be.createFormDataBody(this.rawBody,s[0]);S.tempRemoveContentHeader(this.connectSettings,C.request.bind(this,this,i,e),!1);}},{key:"callServiceAPI",value:function(){var _callServiceAPI23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e,t,s){var i,n;return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context129.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!(s!=null&&s[0])){_context129.n=2;break;}this.callApiWithImage(e,t,s);_context129.n=4;break;case 2:if(this.connectSettings){_context129.n=3;break;}throw new Error("Request settings have not been set up");case 3:this.url=be.IMAGE_GENERATION_URL;n=this.preprocessBody(this.rawBody,t[t.length-1].text);C.request(this,n,e);case 4:return _context129.a(2);}},_callee129,this);}));function callServiceAPI(_x233,_x234,_x235){return _callServiceAPI23.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(e){return _regenerator().w(function(_context130){while(1)switch(_context130.n){case 0:if(!e.error){_context130.n=1;break;}throw e.error.message;case 1:return _context130.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(Rt).concat(s.b64_json),type:"image"};})});}},_callee130);}));function extractResultData(_x236){return _extractResultData26.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
|
212
211
|
// 1 image:
|
213
212
|
// - With text - edits image based on the text
|
214
213
|
// - No text - creates a variation of the image
|
@@ -217,39 +216,40 @@ function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.strin
|
|
217
216
|
// Add text to describe the required modification.
|
218
217
|
// Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
|
219
218
|
// `;
|
220
|
-
}],[{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;}}]);}(M);be.IMAGE_GENERATION_URL="https://api.openai.com/v1/images/generations",be.IMAGE_VARIATIONS_URL="https://api.openai.com/v1/images/variations",be.IMAGE_EDIT_URL="https://api.openai.com/v1/images/edits";var Oi=be;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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://openrouter.ai/api/v1/generation",method:"GET",handleVerificationResult:Us.handleVerificationResult};}}]);}();var
|
221
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){typeof e.message=="string"?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.cohere.ai/v1/models",method:"GET",handleVerificationResult:js.handleVerificationResult};}}]);}();var Ta=/*#__PURE__*/function(_M19){function Ta(e,t,s,i,n){var _this64;_classCallCheck(this,Ta);_this64=_callSuper(this,Ta,[e,js.buildKeyVerificationDetails(),js.buildHeaders,n]),_this64.insertKeyPlaceholderText="Cohere API Key",_this64.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this64.permittedErrorPrefixes=["invalid"],_this64.url=t,_this64.textInputPlaceholderText=s,i&&_typeof(i)=="object"&&Object.assign(_this64.rawBody,i);return _this64;}_inherits(Ta,_M19);return _createClass(Ta);}(M);var qs=/*#__PURE__*/function(_Ta){function qs(e){var _this65$maxMessages;var _this65;_classCallCheck(this,qs);var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.cohere;_this65=_callSuper(this,qs,[e,"https://api.cohere.com/v2/chat","Ask me anything!",{},s]);var i=t.cohere;if(_typeof(i)=="object"){var n=Y.processCohere(i);_this65.canSendMessage=function(){return n;},_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(qs,_Ta);return _createClass(qs,[{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 _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var s,i;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:if(this.connectSettings){_context133.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)):A.request(this,s,e);case 2:return _context133.a(2);}},_callee133,this);}));function callServiceAPI(_x240,_x241){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e){var t,s,i,n;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:if(!(typeof e.message=="string")){_context134.n=1;break;}throw e.message;case 1:if(!(this.stream&&e.text)){_context134.n=2;break;}n=qs.parseBundledEvents(e.text);return _context134.a(2,{text:qs.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)){_context134.n=3;break;}return _context134.a(2,{text:e.message.content[0].text});case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context134.a(2);}},_callee134,this);}));function extractResultData(_x242){return _extractResultData28.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("");}}]);}(Ta);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==="authentication_error"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:"GET",handleVerificationResult:Hs.handleVerificationResult};}}]);}();var Ra=/*#__PURE__*/function(_M20){function Ra(e){var _this66$maxMessages,_n$model2,_o$temperature,_a$max_tokens;var _this66;_classCallCheck(this,Ra);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.deepSeek;_this66=_callSuper(this,Ra,[e,Hs.buildKeyVerificationDetails(),Hs.buildHeaders,s]),_this66.insertKeyPlaceholderText="DeepSeek API Key",_this66.keyHelpUrl="https://platform.deepseek.com/api_keys",_this66.url="https://api.deepseek.com/v1/chat/completions",_this66.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this66._systemMessage="You are a helpful assistant.";var i=t.deepSeek;_typeof(i)=="object"&&(i.system_prompt&&(_this66._systemMessage=i.system_prompt),_this66.cleanConfig(i),Object.assign(_this66.rawBody,i)),(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1,(_n$model2=(n=_this66.rawBody).model)!==null&&_n$model2!==void 0?_n$model2:n.model="deepseek-chat",(_o$temperature=(o=_this66.rawBody).temperature)!==null&&_o$temperature!==void 0?_o$temperature:o.temperature=1,(_a$max_tokens=(a=_this66.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=4096;return _this66;}_inherits(Ra,_M20);return _createClass(Ra,[{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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e,t){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:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):A.request(this,s,e);case 2:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x243,_x244){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e){var t;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.choices&&e.choices.length>0)){_context136.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context136.n=2;break;}return _context136.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context136.n=3;break;}return _context136.a(2,{text:t.message.content});case 3:return _context136.a(2,{text:""});}},_callee136);}));function extractResultData(_x245){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ct=/*#__PURE__*/function(){function Ct(){_classCallCheck(this,Ct);}return _createClass(Ct,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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.x.ai/v1/models",method:"GET",handleVerificationResult:Ct.handleVerificationResult};}}]);}();var ni=/*#__PURE__*/function(_M21){function ni(e){var _o$model9;var _this67;_classCallCheck(this,ni);var n,o;var t=e.directConnection,s=t==null?void 0:t.grok;_this67=_callSuper(this,ni,[e,Ct.buildKeyVerificationDetails(),Ct.buildHeaders,s]),_this67.insertKeyPlaceholderText="Grok API Key",_this67.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this67.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>",_this67.url=ni.IMAGE_GENERATION_URL,_this67.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(_this67.rawBody,i),(_o$model9=(o=_this67.rawBody).model)!==null&&_o$model9!==void 0?_o$model9:o.model="grok-2-image";return _this67;}_inherits(ni,_M21);return _createClass(ni,[{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 _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e,t){var i,s;return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context137.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);A.request(this,s,e);case 2:return _context137.a(2);}},_callee137,this);}));function callServiceAPI(_x246,_x247){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(e){return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:if(!e.error){_context138.n=1;break;}throw e.error.message;case 1:return _context138.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(Rt).concat(s.b64_json),type:"image"};})});}},_callee138);}));function extractResultData(_x248){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(M);ni.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Ni=ni;var Vs=/*#__PURE__*/function(){function Vs(){_classCallCheck(this,Vs);}return _createClass(Vs,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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:"GET",handleVerificationResult:Vs.handleVerificationResult};}}]);}();var Ma=/*#__PURE__*/function(_M22){function Ma(e){var _this68$maxMessages,_n$model3;var _this68;_classCallCheck(this,Ma);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.kimi;_this68=_callSuper(this,Ma,[e,Vs.buildKeyVerificationDetails(),Vs.buildHeaders,s]),_this68.insertKeyPlaceholderText="Kimi AI API Key",_this68.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this68.url="https://api.moonshot.ai/v1/chat/completions",_this68.permittedErrorPrefixes=["Invalid","Not found"],_this68._systemMessage="You are Kimi, a helpful assistant created by Moonshot AI.";var i=t.kimi;_typeof(i)=="object"&&(i.system_prompt&&(_this68._systemMessage=i.system_prompt),_this68.cleanConfig(i),Object.assign(_this68.rawBody,i)),(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_n$model3=(n=_this68.rawBody).model)!==null&&_n$model3!==void 0?_n$model3:n.model="moonshot-v1-8k";return _this68;}_inherits(Ma,_M22);return _createClass(Ma,[{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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(e,t){var s,i;return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:if(this.connectSettings){_context139.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)):A.request(this,s,e);case 2:return _context139.a(2);}},_callee139,this);}));function callServiceAPI(_x249,_x250){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e){var t;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:if(!e.error){_context140.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context140.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context140.n=2;break;}return _context140.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context140.n=3;break;}return _context140.a(2,{text:t.message.content});case 3:return _context140.a(2,{text:""});}},_callee140);}));function extractResultData(_x251){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(M);var zs=/*#__PURE__*/function(){function zs(){_classCallCheck(this,zs);}return _createClass(zs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json",accept:"application/json"};}// prettier-ignore
|
222
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.detail?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.mistral.ai/v1/models",method:"GET",handleVerificationResult:zs.handleVerificationResult};}}]);}();var ka=/*#__PURE__*/function(_M23){function ka(e){var
|
223
|
-
},{key:"handleTools",value:function(){var
|
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;}}]);}(M);be.IMAGE_GENERATION_URL="https://api.openai.com/v1/images/generations",be.IMAGE_VARIATIONS_URL="https://api.openai.com/v1/images/variations",be.IMAGE_EDIT_URL="https://api.openai.com/v1/images/edits";var Oi=be;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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://openrouter.ai/api/v1/generation",method:"GET",handleVerificationResult:Us.handleVerificationResult};}}]);}();var Ta=/*#__PURE__*/function(_M18){function Ta(e){var _this63$maxMessages,_n$model,_o$max_tokens;var _this63;_classCallCheck(this,Ta);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.openRouter;_this63=_callSuper(this,Ta,[e,Us.buildKeyVerificationDetails(),Us.buildHeaders,s]),_this63.insertKeyPlaceholderText="OpenRouter API Key",_this63.keyHelpUrl="https://openrouter.ai/keys",_this63.url="https://openrouter.ai/api/v1/chat/completions",_this63.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this63._systemMessage="You are a helpful assistant.";var i=t.openRouter;_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,(_n$model=(n=_this63.rawBody).model)!==null&&_n$model!==void 0?_n$model:n.model="openai/gpt-4o",(_o$max_tokens=(o=_this63.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=1e3;return _this63;}_inherits(Ta,_M18);return _createClass(Ta,[{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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:o.text||"",role:o.role===y.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 _callServiceAPI24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(e,t){var s,i;return _regenerator().w(function(_context131){while(1)switch(_context131.n){case 0:if(this.connectSettings){_context131.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)):C.request(this,s,e);case 2:return _context131.a(2);}},_callee131,this);}));function callServiceAPI(_x237,_x238){return _callServiceAPI24.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee132(e){var t,s,i,n,o,_o5;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:if(!e.error){_context132.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context132.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context132.a(2,(s=o==null?void 0:o.delta)!=null&&s.content?{text:o.delta.content}:{text:""});case 2:if(!(e.object==="chat.completion")){_context132.n=3;break;}_o5=(i=e.choices)==null?void 0:i[0];if(!((n=_o5==null?void 0:_o5.message)!=null&&n.content)){_context132.n=3;break;}return _context132.a(2,{text:_o5.message.content});case 3:return _context132.a(2,{text:""});}},_callee132);}));function extractResultData(_x239){return _extractResultData27.apply(this,arguments);}return extractResultData;}()}]);}(M);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
|
220
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){typeof e.message=="string"?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.cohere.ai/v1/models",method:"GET",handleVerificationResult:js.handleVerificationResult};}}]);}();var Aa=/*#__PURE__*/function(_M19){function Aa(e,t,s,i,n){var _this64;_classCallCheck(this,Aa);_this64=_callSuper(this,Aa,[e,js.buildKeyVerificationDetails(),js.buildHeaders,n]),_this64.insertKeyPlaceholderText="Cohere API Key",_this64.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this64.permittedErrorPrefixes=["invalid"],_this64.url=t,_this64.textInputPlaceholderText=s,i&&_typeof(i)=="object"&&Object.assign(_this64.rawBody,i);return _this64;}_inherits(Aa,_M19);return _createClass(Aa);}(M);var Hs=/*#__PURE__*/function(_Aa){function Hs(e){var _this65$maxMessages;var _this65;_classCallCheck(this,Hs);var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.cohere;_this65=_callSuper(this,Hs,[e,"https://api.cohere.com/v2/chat","Ask me anything!",{},s]);var i=t.cohere;if(_typeof(i)=="object"){var n=Y.processCohere(i);_this65.canSendMessage=function(){return n;},_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(Hs,_Aa);return _createClass(Hs,[{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 _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var s,i;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:if(this.connectSettings){_context133.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)):C.request(this,s,e);case 2:return _context133.a(2);}},_callee133,this);}));function callServiceAPI(_x240,_x241){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e){var t,s,i,n;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:if(!(typeof e.message=="string")){_context134.n=1;break;}throw e.message;case 1:if(!(this.stream&&e.text)){_context134.n=2;break;}n=Hs.parseBundledEvents(e.text);return _context134.a(2,{text:Hs.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)){_context134.n=3;break;}return _context134.a(2,{text:e.message.content[0].text});case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context134.a(2);}},_callee134,this);}));function extractResultData(_x242){return _extractResultData28.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("");}}]);}(Aa);var qs=/*#__PURE__*/function(){function qs(){_classCallCheck(this,qs);}return _createClass(qs,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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:"GET",handleVerificationResult:qs.handleVerificationResult};}}]);}();var Ra=/*#__PURE__*/function(_M20){function Ra(e){var _this66$maxMessages,_n$model2,_o$temperature,_a$max_tokens;var _this66;_classCallCheck(this,Ra);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.deepSeek;_this66=_callSuper(this,Ra,[e,qs.buildKeyVerificationDetails(),qs.buildHeaders,s]),_this66.insertKeyPlaceholderText="DeepSeek API Key",_this66.keyHelpUrl="https://platform.deepseek.com/api_keys",_this66.url="https://api.deepseek.com/v1/chat/completions",_this66.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this66._systemMessage="You are a helpful assistant.";var i=t.deepSeek;_typeof(i)=="object"&&(i.system_prompt&&(_this66._systemMessage=i.system_prompt),_this66.cleanConfig(i),Object.assign(_this66.rawBody,i)),(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1,(_n$model2=(n=_this66.rawBody).model)!==null&&_n$model2!==void 0?_n$model2:n.model="deepseek-chat",(_o$temperature=(o=_this66.rawBody).temperature)!==null&&_o$temperature!==void 0?_o$temperature:o.temperature=1,(_a$max_tokens=(a=_this66.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=4096;return _this66;}_inherits(Ra,_M20);return _createClass(Ra,[{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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e,t){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:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,_.request(this,s,e)):C.request(this,s,e);case 2:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x243,_x244){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e){var t;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.choices&&e.choices.length>0)){_context136.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context136.n=2;break;}return _context136.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context136.n=3;break;}return _context136.a(2,{text:t.message.content});case 3:return _context136.a(2,{text:""});}},_callee136);}));function extractResultData(_x245){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(M);var Tt=/*#__PURE__*/function(){function Tt(){_classCallCheck(this,Tt);}return _createClass(Tt,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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.x.ai/v1/models",method:"GET",handleVerificationResult:Tt.handleVerificationResult};}}]);}();var ni=/*#__PURE__*/function(_M21){function ni(e){var _o$model9;var _this67;_classCallCheck(this,ni);var n,o;var t=e.directConnection,s=t==null?void 0:t.grok;_this67=_callSuper(this,ni,[e,Tt.buildKeyVerificationDetails(),Tt.buildHeaders,s]),_this67.insertKeyPlaceholderText="Grok API Key",_this67.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this67.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>",_this67.url=ni.IMAGE_GENERATION_URL,_this67.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(_this67.rawBody,i),(_o$model9=(o=_this67.rawBody).model)!==null&&_o$model9!==void 0?_o$model9:o.model="grok-2-image";return _this67;}_inherits(ni,_M21);return _createClass(ni,[{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 _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e,t){var i,s;return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context137.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);C.request(this,s,e);case 2:return _context137.a(2);}},_callee137,this);}));function callServiceAPI(_x246,_x247){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(e){return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:if(!e.error){_context138.n=1;break;}throw e.error.message;case 1:return _context138.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(Rt).concat(s.b64_json),type:"image"};})});}},_callee138);}));function extractResultData(_x248){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(M);ni.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Ni=ni;var Vs=/*#__PURE__*/function(){function Vs(){_classCallCheck(this,Vs);}return _createClass(Vs,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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:"GET",handleVerificationResult:Vs.handleVerificationResult};}}]);}();var Ma=/*#__PURE__*/function(_M22){function Ma(e){var _this68$maxMessages,_a$model;var _this68;_classCallCheck(this,Ma);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.kimi;_this68=_callSuper(this,Ma,[e,Vs.buildKeyVerificationDetails(),Vs.buildHeaders,s]),_this68.insertKeyPlaceholderText="Kimi AI API Key",_this68.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this68.url="https://api.moonshot.ai/v1/chat/completions",_this68.permittedErrorPrefixes=["Invalid","Not found"],_this68._systemMessage="You are Kimi, a helpful assistant created by Moonshot AI.";var i=t.kimi;if(_typeof(i)=="object"){i.system_prompt&&(_this68._systemMessage=i.system_prompt);var l=(o=(n=e.directConnection)==null?void 0:n.kimi)==null?void 0:o.function_handler;l&&(_this68._functionHandler=l),_this68.cleanConfig(i),Object.assign(_this68.rawBody,i);}(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_a$model=(a=_this68.rawBody).model)!==null&&_a$model!==void 0?_a$model:a.model="moonshot-v1-8k";return _this68;}_inherits(Ma,_M22);return _createClass(Ma,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(e,t){var _this$_messages5;var s,i;return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:if(this.connectSettings){_context139.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,_.request(this,s,e)):C.request(this,s,e);case 2:return _context139.a(2);}},_callee139,this);}));function callServiceAPI(_x249,_x250){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e,t){var _s8;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:if(!e.error){_context140.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context140.n=3;break;}_s8=e.choices[0];if(!_s8.delta){_context140.n=2;break;}return _context140.a(2,this.extractStreamResult(_s8,t));case 2:if(!_s8.message){_context140.n=3;break;}return _context140.a(2,_s8.message.tool_calls?this.handleTools({tool_calls:_s8.message.tool_calls},t):{text:_s8.message.content||""});case 3:return _context140.a(2,{text:""});}},_callee140,this);}));function extractResultData(_x251,_x252){return _extractResultData31.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){var _this69=this;var s,i,n;return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context141.n=1;break;}n={tool_calls:this._streamToolCalls};return _context141.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this69._streamToolCalls&&(_this69._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context141.a(2,{text:(s==null?void 0:s.content)||""});}},_callee141,this);}));function extractStreamResult(_x253,_x254){return _extractStreamResult3.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e,t){var s,i,_yield$this$callToolF3,n,o;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context142.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context142.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF3=_context142.v;n=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context142.n=3;break;}return _context142.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref35){var a=_ref35.response;return typeof a!="string";})&&i.length===n.length)){_context142.n=4;break;}return _context142.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context142.a(2);}},_callee142,this);}));function handleTools(_x255,_x256){return _handleTools4.apply(this,arguments);}return handleTools;}()}]);}(M);var zs=/*#__PURE__*/function(){function zs(){_classCallCheck(this,zs);}return _createClass(zs,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(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.mistral.ai/v1/models",method:"GET",handleVerificationResult:zs.handleVerificationResult};}}]);}();var ka=/*#__PURE__*/function(_M23){function ka(e){var _this70$maxMessages,_i$model;var _this70;_classCallCheck(this,ka);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).mistral;_this70=_callSuper(this,ka,[e,zs.buildKeyVerificationDetails(),zs.buildHeaders,s]),_this70.insertKeyPlaceholderText="Mistral API Key",_this70.keyHelpUrl="https://console.mistral.ai/api-keys/",_this70.url="https://api.mistral.ai/v1/chat/completions",_this70.permittedErrorPrefixes=["Invalid"],s&&(_this70.cleanConfig(s),Object.assign(_this70.rawBody,s)),(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_i$model=(i=_this70.rawBody).model)!==null&&_i$model!==void 0?_i$model:i.model="mistral-small-latest";return _this70;}_inherits(ka,_M23);return _createClass(ka,[{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 _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e,t){var s,i;return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:if(this.connectSettings){_context143.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)):C.request(this,s,e);case 2:return _context143.a(2);}},_callee143,this);}));function callServiceAPI(_x257,_x258){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e){var t;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:if(!e.message){_context144.n=1;break;}throw e.message;case 1:if(!(e.choices&&e.choices.length>0)){_context144.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context144.n=2;break;}return _context144.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context144.n=3;break;}return _context144.a(2,{text:t.message.content});case 3:return _context144.a(2,{text:""});}},_callee144);}));function extractResultData(_x259){return _extractResultData32.apply(this,arguments);}return extractResultData;}()}]);}(M);var La=/*#__PURE__*/function(_M24){function La(e){var _this71$maxMessages,_o$model0;var _this71;_classCallCheck(this,La);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.grok;_this71=_callSuper(this,La,[e,Tt.buildKeyVerificationDetails(),Tt.buildHeaders,s]),_this71.insertKeyPlaceholderText="Grok API Key",_this71.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this71.url="https://api.x.ai/v1/chat/completions",_this71.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this71._systemMessage="You are a helpful assistant.";var i=(n=t.grok)==null?void 0:n.chat;_typeof(i)=="object"&&(i.system_prompt&&(_this71._systemMessage=i.system_prompt),_this71.cleanConfig(i),Object.assign(_this71.rawBody,i)),(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_o$model0=(o=_this71.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="grok-3-latest";return _this71;}_inherits(La,_M24);return _createClass(La,[{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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:o.text||"",role:o.role===y.USER_ROLE?"user":"assistant"};}),n={role:"system",content:this._systemMessage};return s.messages=[n].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var s,i;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:if(this.connectSettings){_context145.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)):C.request(this,s,e);case 2:return _context145.a(2);}},_callee145,this);}));function callServiceAPI(_x260,_x261){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e){var t,s,i,n,o;return _regenerator().w(function(_context146){while(1)switch(_context146.n){case 0:if(!e.error){_context146.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context146.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context146.a(2,(s=o==null?void 0:o.delta)!=null&&s.content?{text:o.delta.content}:{text:""});case 2:return _context146.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:""});}},_callee146);}));function extractResultData(_x262){return _extractResultData33.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ia=/*#__PURE__*/function(_M25){function Ia(e){var _this72$maxMessages,_c$model2;var _this72;_classCallCheck(this,Ia);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this72=_callSuper(this,Ia,[e,Ct.buildKeyVerificationDetails(),Ct.buildHeaders,s]),_this72.insertKeyPlaceholderText="Groq API Key",_this72.keyHelpUrl="https://console.groq.com/keys",_this72.url="https://api.groq.com/openai/v1/chat/completions",_this72.permittedErrorPrefixes=["Invalid","property"],_this72._systemMessage="You are a helpful assistant.";var i=(n=t.groq)==null?void 0:n.chat;if(_typeof(i)=="object"){i.system_prompt&&(_this72._systemMessage=i.system_prompt);var d=(l=(a=(o=e.directConnection)==null?void 0:o.groq)==null?void 0:a.chat)==null?void 0:l.function_handler;d&&(_this72._functionHandler=d),_this72.cleanConfig(i),Object.assign(_this72.rawBody,i);}(_this72$maxMessages=_this72.maxMessages)!==null&&_this72$maxMessages!==void 0?_this72$maxMessages:_this72.maxMessages=-1,(_c$model2=(c=_this72.rawBody).model)!==null&&_c$model2!==void 0?_c$model2:c.model="llama-3.3-70b-versatile";return _this72;}_inherits(Ia,_M25);return _createClass(Ia,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role==="ai"?"assistant":n.role};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){var _this$_messages6;var s,i;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(this.connectSettings){_context147.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages6=this._messages)!==null&&_this$_messages6!==void 0?_this$_messages6: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)):C.request(this,s,e);case 2:return _context147.a(2);}},_callee147,this);}));function callServiceAPI(_x263,_x264){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e,t){var s,i,n,o;return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:if(!e.error){_context148.n=1;break;}throw e.error.message;case 1:return _context148.a(2,(i=(s=e.choices)==null?void 0:s[0])!=null&&i.delta?this.extractStreamResult(e.choices[0],t):(o=(n=e.choices)==null?void 0:n[0])!=null&&o.message?e.choices[0].message.tool_calls?this.handleTools(e.choices[0].message,t):{text:e.choices[0].message.content||""}:{text:""});}},_callee148,this);}));function extractResultData(_x265,_x266){return _extractResultData34.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e,t){var _this73=this;var s,i,n;return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context149.n=1;break;}n={tool_calls:this._streamToolCalls};return _context149.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this73._streamToolCalls&&(_this73._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context149.a(2,{text:(s==null?void 0:s.content)||""});}},_callee149,this);}));function extractStreamResult(_x267,_x268){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()// https://console.groq.com/docs/tool-use
|
222
|
+
},{key:"handleTools",value:function(){var _handleTools5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){var s,i,_yield$this$callToolF4,n,o;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context150.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context150.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF4=_context150.v;n=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context150.n=3;break;}return _context150.a(2,o);case 3:if(!(s.messages=s.messages.slice(s.messages.length-1),this._systemMessage&&s.messages.unshift({role:"system",content:this._systemMessage}),s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref36){var a=_ref36.response;return typeof a!="string";})&&i.length===n.length)){_context150.n=4;break;}return _context150.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context150.a(2);}},_callee150,this);}));function handleTools(_x269,_x270){return _handleTools5.apply(this,arguments);}return handleTools;}()}]);}(M);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(E.INVALID_KEY):i(E.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 Oa=/*#__PURE__*/function(_M26){function Oa(e){var _this74$maxMessages,_n$model3;var _this74;_classCallCheck(this,Oa);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.qwen;_this74=_callSuper(this,Oa,[e,Gs.buildKeyVerificationDetails(),Gs.buildHeaders,s]),_this74.insertKeyPlaceholderText="Qwen API Key",_this74.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this74.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this74.permittedErrorPrefixes=["No static","The model","Incorrect"],_this74._systemMessage="You are a helpful assistant.";var i=t.qwen;_typeof(i)=="object"&&(i.system_prompt&&(_this74._systemMessage=i.system_prompt),_this74.cleanConfig(i),Object.assign(_this74.rawBody,i)),(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_n$model3=(n=_this74.rawBody).model)!==null&&_n$model3!==void 0?_n$model3:n.model="qwen-plus";return _this74;}_inherits(Oa,_M26);return _createClass(Oa,[{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=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e,t){var s,i;return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:if(this.connectSettings){_context151.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)):C.request(this,s,e);case 2:return _context151.a(2);}},_callee151,this);}));function callServiceAPI(_x271,_x272){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e){var t;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:if(!e.error){_context152.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context152.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context152.n=2;break;}return _context152.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context152.n=3;break;}return _context152.a(2,{text:t.message.content});case 3:return _context152.a(2,{text:""});}},_callee152);}));function extractResultData(_x273){return _extractResultData35.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ks=/*#__PURE__*/function(){function Ks(){_classCallCheck(this,Ks);}return _createClass(Ks,null,[{key:"buildHeaders",value:function buildHeaders(){return{"Content-Type":"application/json"};}// prettier-ignore
|
224
223
|
},{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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}// https://ai.google.dev/api/models#method:-models.list
|
225
|
-
},{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:Ks.handleVerificationResult};}}]);}();var Gi=/*#__PURE__*/function(_M27){function Gi(e){var
|
226
|
-
function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemInstruction)==null?void 0:n.length)||0):-1).map(function(o){return Gi.getContent(o);});return s.contents=i,this._systemInstruction&&(s.systemInstruction={parts:[{text:this._systemInstruction}]}),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
227
|
-
},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:if(!e.error){_context152.n=1;break;}throw e.error.message||"Gemini API Error";case 1:if(!((n=(i=(s=e.candidates)==null?void 0:s[0])==null?void 0:i.content)!=null&&n.parts)){_context152.n=3;break;}a=e.candidates[0].content.parts,l=a.find(function(u){return u.functionCall;});if(!(l!=null&&l.functionCall)){_context152.n=2;break;}return _context152.a(2,this.handleTools([l.functionCall],t));case 2:c=a.find(function(u){return u.text;}),d=a.find(function(u){var h;return((h=u.inlineData)==null?void 0:h.mimeType)==="image/png";});return _context152.a(2,{text:(c==null?void 0:c.text)||"",files:(o=d==null?void 0:d.inlineData)!=null&&o.data?[{src:"data:image/png;base64,".concat(d.inlineData.data)}]:[]});case 3:return _context152.a(2,{text:""});}},_callee152,this);}));function extractResultData(_x271,_x272){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var s,i,_yield$this$callToolF4,n,o,a,l;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:if(!(!e||!t||!this._functionHandler)){_context153.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.map(function(l){return{name:l.name,arguments:JSON.stringify(l.args)};});_context153.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF4=_context153.v;n=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context153.n=3;break;}return _context153.a(2,o);case 3:a={parts:e.map(function(l){return{functionCall:{name:l.name,args:l.args}};}),role:"model"};if(!(s.contents.push(a),!n.find(function(_ref37){var l=_ref37.response;return typeof l!="string";})&&i.length===n.length)){_context153.n=4;break;}l={parts:n.map(function(c,d){return{functionResponse:{name:e[d].name,response:{result:c.response}}};}),role:"user"};return _context153.a(2,(s.contents.push(l),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context153.a(2);}},_callee153,this);}));function handleTools(_x273,_x274){return _handleTools5.apply(this,arguments);}return handleTools;}()}],[{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===y.USER_ROLE?"user":"model"};}}]);}(M);var Js=/*#__PURE__*/function(){function Js(){_classCallCheck(this,Js);}return _createClass(Js,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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/models",method:"GET",handleVerificationResult:Js.handleVerificationResult};}}]);}();var $s=/*#__PURE__*/function(_M28){function $s(e){var _this75$maxMessages,_a$model,_l$max_tokens;var _this75;_classCallCheck(this,$s);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.claude;_this75=_callSuper(this,$s,[e,Js.buildKeyVerificationDetails(),Js.buildHeaders,s]),_this75.insertKeyPlaceholderText="Claude API Key",_this75.keyHelpUrl="https://console.anthropic.com/settings/keys",_this75.url="https://api.anthropic.com/v1/messages",_this75.permittedErrorPrefixes=["authentication_error","invalid_request_error"],_this75._streamToolCalls={type:"tool_use",id:"",name:"",input:""},_this75._systemMessage="You are a helpful assistant.";var i=t.claude;if(_typeof(i)=="object"){i.system_prompt&&(_this75._systemMessage=i.system_prompt);var c=(o=(n=e.directConnection)==null?void 0:n.claude)==null?void 0:o.function_handler;c&&(_this75._functionHandler=c),_this75.cleanConfig(i),Object.assign(_this75.rawBody,i);}(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1,(_a$model=(a=_this75.rawBody).model)!==null&&_a$model!==void 0?_a$model:a.model="claude-3-5-sonnet-20241022",(_l$max_tokens=(l=_this75.rawBody).max_tokens)!==null&&_l$max_tokens!==void 0?_l$max_tokens:l.max_tokens=4096;return _this75;}_inherits($s,_M28);return _createClass($s,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:$s.getContent(n),role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=i,this._systemMessage&&(s.system=this._systemMessage),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var _this$_messages7;var s,i;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:if(this.connectSettings){_context154.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages7=this._messages)!==null&&_this$_messages7!==void 0?_this$_messages7: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)):A.request(this,s,e);case 2:return _context154.a(2);}},_callee154,this);}));function callServiceAPI(_x275,_x276){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e,t){var s,i,n,o,a;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:if(!e.error){_context155.n=1;break;}throw e.error.message;case 1:if(!(e.content&&e.content.length>0)){_context155.n=3;break;}o=e.content.find(function(l){return l.type==="tool_use";});if(!o){_context155.n=2;break;}return _context155.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(l){return l.type==="text";});if(!a){_context155.n=3;break;}return _context155.a(2,{text:a.text});case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context155.n=4;break;}return _context155.a(2,{text:e.delta.text||""});case 4:if(!(e.type==="content_block_start"&&((s=e.content_block)==null?void 0:s.type)==="tool_use")){_context155.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context155.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((i=e.delta)==null?void 0:i.type)==="input_json_delta")){_context155.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context155.n=7;break;case 6:if(!(e.type==="message_delta"&&((n=e.delta)==null?void 0:n.stop_reason)==="tool_use")){_context155.n=7;break;}return _context155.a(2,(this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t)));case 7:return _context155.a(2,{text:""});}},_callee155,this);}));function extractResultData(_x277,_x278){return _extractResultData37.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var s,i,_yield$this$callToolF5,n,o,a,l;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(!(!e||!t||!this._functionHandler)){_context156.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.map(function(l){return{name:l.name,arguments:JSON.stringify(l.input)};});_context156.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF5=_context156.v;n=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context156.n=3;break;}return _context156.a(2,o);case 3:a=e.map(function(l){return{type:"tool_use",id:l.id,name:l.name,input:l.input};});if(!(s.messages.push({role:"assistant",content:a}),!n.find(function(_ref38){var l=_ref38.response;return typeof l!="string";})&&i.length===n.length)){_context156.n=4;break;}l=n.map(function(c,d){return{type:"tool_result",tool_use_id:e[d].id,content:c.response};});return _context156.a(2,(s.messages.push({role:"user",content:l}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context156.a(2);}},_callee156,this);}));function handleTools(_x279,_x280){return _handleTools6.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=$s.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t;}return e.text||"";}}]);}(M);var yn=/*#__PURE__*/function(){function yn(){_classCallCheck(this,yn);}return _createClass(yn,null,[{key:"buildHeaders",value:function buildHeaders(){return{};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"",method:"GET",handleVerificationResult:function handleVerificationResult(){}};}}]);}();var Ws=/*#__PURE__*/function(_M29){function Ws(e){var _this76$maxMessages,_l$model2,_c$stream;var _this76;_classCallCheck(this,Ws);var o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=yn.buildKeyVerificationDetails(),i=yn.buildHeaders;_this76=_callSuper(this,Ws,[e,s,i,{key:"placeholder"}]),_this76.insertKeyPlaceholderText="",_this76.keyHelpUrl="",_this76.validateKeyProperty=!1,_this76.url="http://localhost:11434/api/chat",_this76.permittedErrorPrefixes=["Error"];var n=t.ollama;if(_typeof(n)=="object"){n.system&&(_this76._systemMessage=Ws.generateSystemMessage(n.system));var d=(a=(o=e.directConnection)==null?void 0:o.ollama)==null?void 0:a.function_handler;d&&(_this76._functionHandler=d),_this76.cleanConfig(n),Object.assign(_this76.rawBody,n);}(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1,(_l$model2=(l=_this76.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="llama3.2",(_c$stream=(c=_this76.rawBody).stream)!==null&&_c$stream!==void 0?_c$stream:c.stream=!1;return _this76;}_inherits(Ws,_M29);return _createClass(Ws,[{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=K.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===y.USER_ROLE?"user":"assistant"};if(o.files&&o.files.length>0){var l=Ws.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 _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var _this$_messages8;var s,i;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(this.connectSettings){_context157.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages8=this._messages)!==null&&_this$_messages8!==void 0?_this$_messages8: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)):A.request(this,s,e);case 2:return _context157.a(2);}},_callee157,this);}));function callServiceAPI(_x281,_x282){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){var s,i,n;return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:if(!e.error){_context158.n=1;break;}throw e.error.message;case 1:if(!e.text){_context158.n=2;break;}n=JSON.parse(e.text);return _context158.a(2,(s=n.message)!=null&&s.tool_calls?this.handleTools({tool_calls:n.message.tool_calls},t):{text:((i=n.message)==null?void 0:i.content)||""});case 2:return _context158.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):{text:e.message.content||""}:{text:""});}},_callee158,this);}));function extractResultData(_x283,_x284){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e,t){var s,i,_yield$this$callToolF6,n,o;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context159.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:JSON.stringify(a["function"].arguments)};});_context159.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF6=_context159.v;n=_yield$this$callToolF6.responses;o=_yield$this$callToolF6.processedResponse;if(!o){_context159.n=3;break;}return _context159.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:""}),!n.find(function(_ref39){var a=_ref39.response;return typeof a!="string";})&&i.length===n.length)){_context159.n=4;break;}return _context159.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context159.a(2);}},_callee159,this);}));function handleTools(_x285,_x286){return _handleTools7.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;});}}]);}(M);var Na=/*#__PURE__*/function(){function Na(){_classCallCheck(this,Na);}return _createClass(Na,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 us(e);if(t){if(t.openAI)return t.openAI.images?new Oi(e):t.openAI.speechToText?new Mi(e):t.openAI.textToSpeech?new Ri(e):t.openAI.assistant?new
|
229
|
-
},{key:"createImageMessage",value:function createImageMessage(e,t,s,i){var n=J.createImage(t,e.elementRef,!i&&!e.focusMode),o=e.createNewMessageElement("",s);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(J.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,je.IS_SAFARI&&(s.classList.add("audio-player-safari"),s.classList.add(t===y.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=J.createAudioElement(t,s),o=e.createMessageElementsOnOrientation("",s,i);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(J.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=
|
230
|
-
},{key:"addMessages",value:function addMessages(e,t,s,i){J.createMessages(e,t,s,i).filter(function(o){return o!==void 0;}).forEach(function(
|
231
|
-
},{key:"updateFileMessages",value:function updateFileMessages(e,t,s){var u,h;var i=t[0].role,n=Ys.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(
|
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;y.classifyRoleMessages(n),y.resetAllRoleElements(n,o,a);}else console.error("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var Ba=/*#__PURE__*/function(){function Ba(){_classCallCheck(this,Ba);}return _createClass(Ba,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(
|
233
|
-
function setLoadingToggle(){var
|
234
|
-
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var
|
235
|
-
},{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!==y.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(
|
224
|
+
},{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:Ks.handleVerificationResult};}}]);}();var Gi=/*#__PURE__*/function(_M27){function Gi(e){var _this75$maxMessages;var _this75;_classCallCheck(this,Gi);var a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.gemini,i=t.gemini;var n;if(_this75=_callSuper(this,Gi,[e,Ks.buildKeyVerificationDetails(),Ks.buildHeaders,s]),_this75.insertKeyPlaceholderText="Gemini API Key",_this75.keyHelpUrl="https://aistudio.google.com/app/apikey",_this75.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent",_this75.url="",_this75.permittedErrorPrefixes=["API_KEY_INVALID"],!i)return _possibleConstructorReturn(_this75);i.systemInstruction&&(n=i.systemInstruction);var _ref37=(a=e.directConnection)==null?void 0:a.gemini,o=_ref37.function_handler;o&&(_this75._functionHandler=o),i.model&&(_this75.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(i.model,":generateContent")),Object.defineProperty(_this75,"_systemInstruction",{value:n,writable:!1}),_this75.cleanConfig(i),Object.assign(_this75.rawBody,i),(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1;return _this75;}_inherits(Gi,_M27);return _createClass(Gi,[{key:"cleanConfig",value:function cleanConfig(e){delete e.systemInstruction,delete e.function_handler,delete e.model,delete e.key;}},{key:"preprocessBody",value:// prettier-ignore
|
225
|
+
function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemInstruction)==null?void 0:n.length)||0):-1).map(function(o){return Gi.getContent(o);});return s.contents=i,this._systemInstruction&&(s.systemInstruction={parts:[{text:this._systemInstruction}]}),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var _this$_messages7;var s,i;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:if(this.connectSettings){_context153.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages7=this._messages)!==null&&_this$_messages7!==void 0?_this$_messages7:this._messages=e;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),C.request(this,s,e));case 2:return _context153.a(2);}},_callee153,this);}));function callServiceAPI(_x274,_x275){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()// https://ai.google.dev/gemini-api/docs/function-calling?example=weather
|
226
|
+
},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:if(!e.error){_context154.n=1;break;}throw e.error.message||"Gemini API Error";case 1:if(!((n=(i=(s=e.candidates)==null?void 0:s[0])==null?void 0:i.content)!=null&&n.parts)){_context154.n=3;break;}a=e.candidates[0].content.parts,l=a.find(function(u){return u.functionCall;});if(!(l!=null&&l.functionCall)){_context154.n=2;break;}return _context154.a(2,this.handleTools([l.functionCall],t));case 2:c=a.find(function(u){return u.text;}),d=a.find(function(u){var h;return((h=u.inlineData)==null?void 0:h.mimeType)==="image/png";});return _context154.a(2,{text:(c==null?void 0:c.text)||"",files:(o=d==null?void 0:d.inlineData)!=null&&o.data?[{src:"data:image/png;base64,".concat(d.inlineData.data)}]:[]});case 3:return _context154.a(2,{text:""});}},_callee154,this);}));function extractResultData(_x276,_x277){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e,t){var s,i,_yield$this$callToolF5,n,o,a,l;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:if(!(!e||!t||!this._functionHandler)){_context155.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.map(function(l){return{name:l.name,arguments:JSON.stringify(l.args)};});_context155.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF5=_context155.v;n=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context155.n=3;break;}return _context155.a(2,o);case 3:a={parts:e.map(function(l){return{functionCall:{name:l.name,args:l.args}};}),role:"model"};if(!(s.contents.push(a),!n.find(function(_ref38){var l=_ref38.response;return typeof l!="string";})&&i.length===n.length)){_context155.n=4;break;}l={parts:n.map(function(c,d){return{functionResponse:{name:e[d].name,response:{result:c.response}}};}),role:"user"};return _context155.a(2,(s.contents.push(l),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context155.a(2);}},_callee155,this);}));function handleTools(_x278,_x279){return _handleTools6.apply(this,arguments);}return handleTools;}()}],[{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===y.USER_ROLE?"user":"model"};}}]);}(M);var Js=/*#__PURE__*/function(){function Js(){_classCallCheck(this,Js);}return _createClass(Js,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(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/models",method:"GET",handleVerificationResult:Js.handleVerificationResult};}}]);}();var $s=/*#__PURE__*/function(_M28){function $s(e){var _this76$maxMessages,_a$model2,_l$max_tokens;var _this76;_classCallCheck(this,$s);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.claude;_this76=_callSuper(this,$s,[e,Js.buildKeyVerificationDetails(),Js.buildHeaders,s]),_this76.insertKeyPlaceholderText="Claude API Key",_this76.keyHelpUrl="https://console.anthropic.com/settings/keys",_this76.url="https://api.anthropic.com/v1/messages",_this76.permittedErrorPrefixes=["authentication_error","invalid_request_error"],_this76._streamToolCalls={type:"tool_use",id:"",name:"",input:""},_this76._systemMessage="You are a helpful assistant.";var i=t.claude;if(_typeof(i)=="object"){i.system_prompt&&(_this76._systemMessage=i.system_prompt);var c=(o=(n=e.directConnection)==null?void 0:n.claude)==null?void 0:o.function_handler;c&&(_this76._functionHandler=c),_this76.cleanConfig(i),Object.assign(_this76.rawBody,i);}(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1,(_a$model2=(a=_this76.rawBody).model)!==null&&_a$model2!==void 0?_a$model2:a.model="claude-3-5-sonnet-20241022",(_l$max_tokens=(l=_this76.rawBody).max_tokens)!==null&&_l$max_tokens!==void 0?_l$max_tokens:l.max_tokens=4096;return _this76;}_inherits($s,_M28);return _createClass($s,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=K.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:$s.getContent(n),role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=i,this._systemMessage&&(s.system=this._systemMessage),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var _this$_messages8;var s,i;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(this.connectSettings){_context156.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages8=this._messages)!==null&&_this$_messages8!==void 0?_this$_messages8: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)):C.request(this,s,e);case 2:return _context156.a(2);}},_callee156,this);}));function callServiceAPI(_x280,_x281){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var s,i,n,o,a;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(!e.error){_context157.n=1;break;}throw e.error.message;case 1:if(!(e.content&&e.content.length>0)){_context157.n=3;break;}o=e.content.find(function(l){return l.type==="tool_use";});if(!o){_context157.n=2;break;}return _context157.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(l){return l.type==="text";});if(!a){_context157.n=3;break;}return _context157.a(2,{text:a.text});case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context157.n=4;break;}return _context157.a(2,{text:e.delta.text||""});case 4:if(!(e.type==="content_block_start"&&((s=e.content_block)==null?void 0:s.type)==="tool_use")){_context157.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context157.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((i=e.delta)==null?void 0:i.type)==="input_json_delta")){_context157.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context157.n=7;break;case 6:if(!(e.type==="message_delta"&&((n=e.delta)==null?void 0:n.stop_reason)==="tool_use")){_context157.n=7;break;}return _context157.a(2,(this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t)));case 7:return _context157.a(2,{text:""});}},_callee157,this);}));function extractResultData(_x282,_x283){return _extractResultData37.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){var s,i,_yield$this$callToolF6,n,o,a,l;return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:if(!(!e||!t||!this._functionHandler)){_context158.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.map(function(l){return{name:l.name,arguments:JSON.stringify(l.input)};});_context158.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF6=_context158.v;n=_yield$this$callToolF6.responses;o=_yield$this$callToolF6.processedResponse;if(!o){_context158.n=3;break;}return _context158.a(2,o);case 3:a=e.map(function(l){return{type:"tool_use",id:l.id,name:l.name,input:l.input};});if(!(s.messages.push({role:"assistant",content:a}),!n.find(function(_ref39){var l=_ref39.response;return typeof l!="string";})&&i.length===n.length)){_context158.n=4;break;}l=n.map(function(c,d){return{type:"tool_result",tool_use_id:e[d].id,content:c.response};});return _context158.a(2,(s.messages.push({role:"user",content:l}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context158.a(2);}},_callee158,this);}));function handleTools(_x284,_x285){return _handleTools7.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=$s.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t;}return e.text||"";}}]);}(M);var yn=/*#__PURE__*/function(){function yn(){_classCallCheck(this,yn);}return _createClass(yn,null,[{key:"buildHeaders",value:function buildHeaders(){return{};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"",method:"GET",handleVerificationResult:function handleVerificationResult(){}};}}]);}();var Ws=/*#__PURE__*/function(_M29){function Ws(e){var _this77$maxMessages,_l$model2,_c$stream;var _this77;_classCallCheck(this,Ws);var o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=yn.buildKeyVerificationDetails(),i=yn.buildHeaders;_this77=_callSuper(this,Ws,[e,s,i,{key:"placeholder"}]),_this77.insertKeyPlaceholderText="",_this77.keyHelpUrl="",_this77.validateKeyProperty=!1,_this77.url="http://localhost:11434/api/chat",_this77.permittedErrorPrefixes=["Error"];var n=t.ollama;if(_typeof(n)=="object"){n.system&&(_this77._systemMessage=Ws.generateSystemMessage(n.system));var d=(a=(o=e.directConnection)==null?void 0:o.ollama)==null?void 0:a.function_handler;d&&(_this77._functionHandler=d),_this77.cleanConfig(n),Object.assign(_this77.rawBody,n);}(_this77$maxMessages=_this77.maxMessages)!==null&&_this77$maxMessages!==void 0?_this77$maxMessages:_this77.maxMessages=-1,(_l$model2=(l=_this77.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="llama3.2",(_c$stream=(c=_this77.rawBody).stream)!==null&&_c$stream!==void 0?_c$stream:c.stream=!1;return _this77;}_inherits(Ws,_M29);return _createClass(Ws,[{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=K.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===y.USER_ROLE?"user":"assistant"};if(o.files&&o.files.length>0){var l=Ws.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 _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e,t){var _this$_messages9;var s,i;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(this.connectSettings){_context159.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages9=this._messages)!==null&&_this$_messages9!==void 0?_this$_messages9: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)):C.request(this,s,e);case 2:return _context159.a(2);}},_callee159,this);}));function callServiceAPI(_x286,_x287){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e,t){var s,i,n;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if(!e.error){_context160.n=1;break;}throw e.error.message;case 1:if(!e.text){_context160.n=2;break;}n=JSON.parse(e.text);return _context160.a(2,(s=n.message)!=null&&s.tool_calls?this.handleTools({tool_calls:n.message.tool_calls},t):{text:((i=n.message)==null?void 0:i.content)||""});case 2:return _context160.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):{text:e.message.content||""}:{text:""});}},_callee160,this);}));function extractResultData(_x288,_x289){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var s,i,_yield$this$callToolF7,n,o;return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context161.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:JSON.stringify(a["function"].arguments)};});_context161.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF7=_context161.v;n=_yield$this$callToolF7.responses;o=_yield$this$callToolF7.processedResponse;if(!o){_context161.n=3;break;}return _context161.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:""}),!n.find(function(_ref40){var a=_ref40.response;return typeof a!="string";})&&i.length===n.length)){_context161.n=4;break;}return _context161.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context161.a(2);}},_callee161,this);}));function handleTools(_x290,_x291){return _handleTools8.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;});}}]);}(M);var Na=/*#__PURE__*/function(){function Na(){_classCallCheck(this,Na);}return _createClass(Na,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
|
227
|
+
function create(e){var t=e.directConnection,s=e.connect,i=e.demo,n=e.webModel;if(n)return new us(e);if(t){if(t.openAI)return t.openAI.images?new Oi(e):t.openAI.speechToText?new Mi(e):t.openAI.textToSpeech?new Ri(e):t.openAI.assistant?new qi(e):t.openAI.realtime?new Ai(e):new lt(e);if(t.assemblyAI)return new Vi(e);if(t.cohere)return new Hs(e);if(t.huggingFace)return t.huggingFace.textGeneration?new ua(e):t.huggingFace.summarization?new pa(e):t.huggingFace.translation?new ga(e):t.huggingFace.fillMask?new ya(e):t.huggingFace.questionAnswer?new fa(e):t.huggingFace.audioSpeechRecognition?new ha(e):t.huggingFace.audioClassification?new ca(e):t.huggingFace.imageClassification?new da(e):new ma(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new zi(e);if(t.azure.openAI.assistant)return new Ci(e);}if(t.azure.speechToText)return new Ii(e);if(t.azure.textToSpeech)return new Li(e);if(t.azure.summarization)return new ki(e);if(t.azure.translation)return new _a(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new Os(e):t.stabilityAI.imageToImageUpscale?new Ls(e):t.stabilityAI.imageToImageMasking?new Is(e):new Ns(e);if(t.mistral)return new ka(e);if(t.gemini)return new Gi(e);if(t.claude)return new $s(e);if(t.deepSeek)return new Ra(e);if(t.openRouter)return new Ta(e);if(t.kimi)return new Ma(e);if(t.grok)return t.grok.images?new Ni(e):new La(e);if(t.qwen)return new Oa(e);if(t.together)return t.together.images?new wa(e):t.together.textToSpeech?new va(e):new Ca(e);if(t.bigModel)return t.bigModel.images?new Sa(e):t.bigModel.textToSpeech?new ba(e):new Fs(e);if(t.groq)return t.groq.textToSpeech?new xa(e):new Ia(e);if(t.ollama)return new Ws(e);}return s&&Object.keys(s).length>0&&!i?new ft(e):new ft(e,void 0,i||!0);}}]);}();var Zi=/*#__PURE__*/_createClass(function Zi(){_classCallCheck(this,Zi);});Zi.attibutes={string:function string(e){return e;},number:function number(e){return parseFloat(e);},"boolean":function boolean(e){return e==="true";},object:function object(e){return JSON.parse(e);},array:function array(e){return JSON.parse(e);},"function":function _function(e){return new Function("return ".concat(e))();}};var Pi=Zi;function T(r){return function(e,t){Object.defineProperty(e,t,{});var s=e.constructor,i=t.toLocaleLowerCase();s._attributes_[i]=Pi.attibutes[r],s._attributeToProperty_[i]=t;};}var Xs=/*#__PURE__*/function(){function Xs(e,t,s){_classCallCheck(this,Xs);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(Xs,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e,t){var s=Xs.createIntroPanel(t);return e.style.display==="none"&&(e.style.display="block"),s.appendChild(e),s;}},{key:"createInternalIntroPanel",value:function createInternalIntroPanel(e,t){var s=Xs.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 Pa="<?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>",J=/*#__PURE__*/function(){function J(){_classCallCheck(this,J);}return _createClass(J,null,[{key:"createImage",value:function createImage(e,t,s){var i=new Image();return i.src=e.src,s&&G.scrollDownOnImageLoad(i.src,t),G.processContent("image",i,i.src,e.name);}// WORK - image still does not scroll down when loaded
|
228
|
+
},{key:"createImageMessage",value:function createImageMessage(e,t,s,i){var n=J.createImage(t,e.elementRef,!i&&!e.focusMode),o=e.createNewMessageElement("",s);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(J.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,je.IS_SAFARI&&(s.classList.add("audio-player-safari"),s.classList.add(t===y.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=J.createAudioElement(t,s),o=e.createMessageElementsOnOrientation("",s,i);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(J.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=qe.createSVGElement(Pa);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||G.DEFAULT_FILE_NAME,t.appendChild(s),t.appendChild(n),G.processContent("any",t,e.src,n.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,s,i){var n=e.createMessageElementsOnOrientation("",s,i),o=J.createAnyFile(t);return n.bubbleElement.classList.add(J.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=G.removeFileRef(n)),G.isAudioFile(n)){var a=J.createNewAudioMessage(e,n,s,i),l=(o=e.textToSpeech)==null?void 0:o.service;return l&&(l.autoPlay&&J.autoPlayAudio(a.audioElement),typeof l.displayAudio=="boolean"&&!l.displayAudio)?void 0:a;}return G.isImageFile(n)?J.createImageMessage(e,n,s,i):J.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
|
229
|
+
},{key:"addMessages",value:function addMessages(e,t,s,i){J.createMessages(e,t,s,i).filter(function(o){return o!==void 0;}).forEach(function(_ref41){var o=_ref41.type,a=_ref41.elements;G.addMessage(e,a,o,s,i);});}}]);}();J.IMAGE_BUBBLE_CLASS="image-message",J.AUDIO_BUBBLE_CLASS="audio-message",J.ANY_FILE_BUBBLE_CLASS="any-file-message";var Ys=J;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
|
230
|
+
},{key:"updateFileMessages",value:function updateFileMessages(e,t,s){var u,h;var i=t[0].role,n=Ys.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(f){return f===l;});a&&(c+=1);var d=(o==null?void 0:o.outerContainer)||(a==null?void 0:a.outerContainer.nextSibling);n.forEach(function(_ref42,p){var f=_ref42.type,m=_ref42.elements;var g;G.setElementProps(e,m,f,i),(g=d.parentElement)==null||g.insertBefore(m.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(c+p,0,m);}),de.removeFilesMessages(e,t),t[1].files=n.map(function(_ref43){var f=_ref43.elements;return f;}),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
|
231
|
+
},{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;y.classifyRoleMessages(n),y.resetAllRoleElements(n,o,a);}else console.error("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var Ba=/*#__PURE__*/function(){function Ba(){_classCallCheck(this,Ba);}return _createClass(Ba,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(_fe){function ue(e,t,s){var _this78;_classCallCheck(this,ue);var a,l;_this78=_callSuper(this,ue,[e]);var i=t.permittedErrorPrefixes,n=t.introPanelMarkUp,o=t.demo;_this78._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this78._onClearMessages=ds.onClearMessages.bind(_this78,e),_this78._onError=ds.onError.bind(_this78,e),_this78._isLoadingMessageAllowed=ue.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this78.setLoadingToggle.bind(_this78)),_this78._permittedErrorPrefixes=i,_this78.addSetupMessageIfNeeded(e,t)||_this78.populateIntroPanel(s,n,e.introPanelStyle),o&&_this78.prepareDemo(Y.processDemo(o),e.loadHistory),_this78.addIntroductoryMessages(e,t),new hs(e,_this78,t),_this78._displayServiceErrorMessages=(l=e.errorMessages)==null?void 0:l.displayServiceErrorMessages,e.getMessages=function(){return y.deepCloneMessagesWithReferences(_this78.messageToElements.map(function(_ref44){var _ref45=_slicedToArray(_ref44,1),c=_ref45[0];return c;}));},e.clearMessages=_this78.clearMessages.bind(_this78,t),e.refreshMessages=_this78.refreshTextMessages.bind(_this78,e.remarkable),e.scrollToBottom=X.scrollToBottom.bind(_this78,_this78.elementRef),e.addMessage=function(c,d){_this78.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(c,d){return de.update(_this78,c,d);},t.isWebModel()&&t.setUpMessages(_this78),e.textToSpeech&&wt.processConfig(e.textToSpeech,function(c){_this78.textToSpeech=c;});return _this78;}// WORK - document how to display loading with toggle after user message via onMessage
|
232
|
+
_inherits(ue,_fe);return _createClass(ue,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1];!e&&fe.isLoadingMessage(t)?(this.removeLastMessage(),delete this._activeLoadingConfig):(this._activeLoadingConfig&&this.removeLastMessage(),this._activeLoadingConfig=e||{},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&&He.addMessage(this,!1),i!=null&&i.full&&He.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=Ba.getText(e,t);if(s){var i=this.createAndAppendNewMessageElement(s,y.AI_ROLE);this.applyCustomStyles(i,y.AI_ROLE,!1);}return!!s;}// WORK - const file for deep chat classes
|
233
|
+
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this79=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=_this79.messageElementRefs[_this79.messageElementRefs.length-1].innerContainer;y.hideRoleElements(a,_this79.avatar,_this79.name);}_this79.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,y.AI_ROLE):e!=null&&e.html&&(s=Te.add(this,e.html,y.AI_ROLE)),s&&(this.applyCustomStyles(s,y.AI_ROLE,!1,(i=this.messageStyles)==null?void 0:i.intro),s.outerContainer.classList.add(fe.INTRO_CLASS),t&&(s.outerContainer.style.display="none")),s;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer.classList.contains(fe.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!==y.USER_ROLE&&wt.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)&&Ys.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
|
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!==y.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(_ref46){var _ref47=_slicedToArray(_ref46,1),u=_ref47[0];return u;}))),this._activeLoadingConfig&&this.addLoadingMessage(!1),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=y.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,n]);}s&&this.sendClientUpdate(e,i);}// prettier-ignore
|
236
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(Re.MESSAGE_CLASS)&&t.textContent===""||ue.isTemporaryElement(e))&&this.removeLastMessage();}// prettier-ignore
|
237
|
-
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var
|
238
|
-
function
|
236
|
+
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this80=this;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var c,d,u,h,f,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);y.hideRoleElements(n.innerContainer,this.avatar,this.name);var o=n.bubbleElement,a=n.outerContainer;o.classList.add(y.ERROR_MESSAGE_TEXT_CLASS),this.renderText(o,i);var l=ee.extractParticularSharedStyles(["fontSize","fontFamily"],(h=this.messageStyles)==null?void 0:h["default"]);ee.applyCustomStylesToElements(n,!1,l),ee.applyCustomStylesToElements(n,!1,(f=this.messageStyles)==null?void 0:f.error),s||this.appendOuterContainerElemet(a),this.textToSpeech&&wt.speak(i,this.textToSpeech),(m=this._onError)==null||m.call(this,i),setTimeout(function(){return X.scrollToBottom(_this80.elementRef);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=ue.extractErrorMessages(e);for(var _s9=0;_s9<t.length;_s9+=1){var i=t[_s9];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()&&y.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:y.AI_ROLE;var s=this.createMessageElements("",t),i=s.bubbleElement;s.bubbleElement.classList.add(Ue.DOTS_CONTAINER_CLASS);var n=document.createElement("div");return n.classList.add("loading-message-dots"),i.appendChild(n),Ue.setDots(i,e),s;}// prettier-ignore
|
237
|
+
},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var o,a,l,c,d,u;if(fe.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((o=this._activeLoadingConfig)==null?void 0:o.role)||y.AI_ROLE,s=((a=this._activeLoadingConfig)==null?void 0:a.style)||((c=(l=this.messageStyles)==null?void 0:l.loading)==null?void 0:c.message),i=s==null?void 0:s.html,n=i?Te.createElements(this,i,t,!1):this.addDefaultLoadingMessage(s,t);this.appendOuterContainerElemet(n.outerContainer),n.bubbleElement.classList.add(Ue.BUBBLE_CLASS),this.applyCustomStyles(n,t,!1,s==null?void 0:s.styles),(u=(d=this.avatar)==null?void 0:d.getAvatarContainer(n.innerContainer))==null||u.classList.add("loading-avatar-container"),this.focusMode||X.scrollToBottom(this.elementRef);}},{key:"populateIntroPanel",value:function populateIntroPanel(e,t,s){(e||t)&&(this._introPanel=new Xs(e,t,s),this._introPanel._elementRef&&(te.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef)));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:return _context162.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||G.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});};}});}))));}},_callee162,this);}));function addMultipleFiles(_x292,_x293){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
|
238
|
+
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(y.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 _ref48;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)=="object"?!1:!!e.displayLoadingBubble:(_ref48=_typeof(e.displayLoadingBubble)=="object"||e.displayLoadingBubble)!==null&&_ref48!==void 0?_ref48:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _s0=0;_s0<e.length;_s0+=1)if(t.startsWith(e[_s0]))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(Ue.BUBBLE_CLASS)||e.contains(He.CLASS)||e.contains(Re.MESSAGE_CLASS):!1;}}]);}(fe);var z=/*#__PURE__*/function(){function z(){_classCallCheck(this,z);}return _createClass(z,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(z.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS),t.classList.add(z.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS)):s["outside-left"].length===0&&s["outside-right"].length>0&&(e[3].classList.add(z.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS),t.classList.add(z.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS));}// when submit is the only button
|
239
239
|
// when submit button is outside by itself - we increase the height for a better look
|
240
240
|
},{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(z.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),t.classList.add(z.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(z.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),t.classList.add(z.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),s["outside-right"].map(function(i){return i.button.elementRef.classList.add("submit-button-enlarged");});}}// prettier-ignore
|
241
|
-
},{key:"set",value:function set(e,t,s,i){!!z.adjustOutsideSubmit(t,s,i)||z.adjustForOutsideButton(t,s,i),z.adjustInputPadding(e,i);}}]);}();z.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment",z.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment",z.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment",z.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var Bi=z;var
|
242
|
-
function P(e,t,s,i){var
|
243
|
-
},{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 _Qt$parseSVGTextEleme4=Qt.parseSVGTextElements(s),h=_Qt$parseSVGTextEleme4.svg,
|
241
|
+
},{key:"set",value:function set(e,t,s,i){!!z.adjustOutsideSubmit(t,s,i)||z.adjustForOutsideButton(t,s,i),z.adjustInputPadding(e,i);}}]);}();z.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment",z.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment",z.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment",z.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var Bi=z;var At=/*#__PURE__*/function(){function At(){_classCallCheck(this,At);}return _createClass(At,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=At.getContainerIndex(s);e[i].appendChild(t),i===3&&t.classList.add("outside-right");}}]);}();var bn=["camera","gifs","images","audio","mixedFiles","submit","microphone"],Da="<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",ie=/*#__PURE__*/function(){function ie(){_classCallCheck(this,ie);}return _createClass(ie,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(ie.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(ie.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(Me.INPUT_BUTTON_INNER_TEXT_CLASS)?(c||t.appendChild(ie.createItemIcon(o,s==null?void 0:s.iconContainer)),t.appendChild(ie.createItemText(l.textContent,s==null?void 0:s.text))):(c||t.appendChild(ie.createItemIcon(i.children[0],s==null?void 0:s.iconContainer)),t.appendChild(ie.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"]),ie.populateItem(t,i,s),i.classList.add(ie.MENU_ITEM_CLASS);var n=t.elementRef;if(t.isCustom)t.setDropupItem(i);else{var a=N.processStateful((s==null?void 0:s.item)||{});ie.addItemEvents(e,i,n,a);}return i;}}]);}();ie.MENU_ITEM_CLASS="dropup-menu-item",ie.TEXT_CLASS="dropup-menu-item-text",ie.ICON_CLASS="dropup-menu-item-icon";var we=ie;var P=/*#__PURE__*/function(_yt2){// prettier-ignore
|
242
|
+
function P(e,t,s,i){var _this81;_classCallCheck(this,P);var l,c,d,u,h,f;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=Da,a=_e.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this81=_callSuper(this,P,[P.createButtonElement(),o,e==null?void 0:e.position,a,((h=e==null?void 0:e.styles)==null?void 0:h.button)||a&&{},n]),_this81._state="default",_this81.isCustom=!0,_this81._innerElements=_this81.createInnerElementsForStates(_this81.customStyles),_this81._menuStyles=i,_this81._onClick=e.onClick,_this81._dropupStyles=(f=e.styles)==null?void 0:f.dropup,_this81.setSetState(e),_this81.addClickListener(s),_this81.changeState(e.initialState,!0);return _this81;}_inherits(P,_yt2);return _createClass(P,[{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 _this82=this;e.setState=function(t){t==="default"&&_this82.changeToDefault(),t==="active"&&_this82.changeToActive(),t==="disabled"&&_this82.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this83=this;this.elementRef.addEventListener("click",function(){var s;var t=(s=_this83._onClick)==null?void 0:s.call(_this83,_this83._state);e==null||e(),(t==="default"||t==="active"||t==="disabled")&&_this83.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 _s1=t.find(function(i){return i.classList.contains(we.TEXT_CLASS);});_s1&&Object.assign(_s1.style,e.text);}if(e!=null&&e.iconContainer){var _s10=t.find(function(i){return i.classList.contains(we.ICON_CLASS);});_s10&&Object.assign(_s10.style,e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var s,i,n;this.elementRef=te.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((s=e==null?void 0:e.svg)==null?void 0:s.content)===""||this.elementRef.appendChild(we.createItemIcon(this.svg,(i=this._menuStyles)==null?void 0:i.iconContainer)),this.elementRef.appendChild(we.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(we.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&&U.unsetAllCSS(this.elementRef,(n=this.customStyles)==null?void 0:n.active),(o=this.customStyles)!=null&&o.disabled&&U.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a.disabled),this.reapplyStateStyle("default",["active","disabled"])),this.elementRef.classList.remove(P.DISABLED_CONTAINER_CLASS,P.ACTIVE_CONTAINER_CLASS),this.elementRef.classList.add(P.DEFAULT_CONTAINER_CLASS),D.removeAriaDisabled(this.elementRef),this._state="default");}},{key:"changeToActive",value:function changeToActive(e){var t,s;!e&&this._state==="active"||(this.elementRef.classList.contains(we.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(P.DISABLED_CONTAINER_CLASS,P.DEFAULT_CONTAINER_CLASS),this.elementRef.classList.add(P.ACTIVE_CONTAINER_CLASS),D.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(we.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&&U.unsetAllCSS(this.elementRef,(n=this.customStyles)==null?void 0:n.active),(o=this.customStyles)!=null&&o["default"]&&U.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a["default"]),this.reapplyStateStyle("disabled",["default","active"])),this.elementRef.classList.remove(P.ACTIVE_CONTAINER_CLASS,P.DEFAULT_CONTAINER_CLASS),this.elementRef.classList.add(P.DISABLED_CONTAINER_CLASS),D.addAriaDisabled(this.elementRef),this._state="disabled");}// called after class is initialised
|
243
|
+
},{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 _Qt$parseSVGTextEleme4=Qt.parseSVGTextElements(s),h=_Qt$parseSVGTextEleme4.svg,f=_Qt$parseSVGTextEleme4.text,_Qt$parseSVGTextEleme5=Qt.parseSVGTextElements(n),m=_Qt$parseSVGTextEleme5.svg,p=_Qt$parseSVGTextEleme5.text,g=[];P.addToInnerElements(g,o,h,m),P.addToInnerElements(g,a,f,p),n=g;}return n;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button",P.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 P(o,a+1,i,n==null?void 0:n.menu)};t["".concat(P.INDICATOR_PREFIX).concat(a+1)]=l;});}}]);}(yt);P.INDICATOR_PREFIX="custom",P.BUTTON_CLASS="custom-button",P.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",P.DEFAULT_CONTAINER_CLASS="custom-button-container-default",P.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var ht=P;var Fa="<?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 fs=/*#__PURE__*/function(){function fs(){_classCallCheck(this,fs);}return _createClass(fs,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var s=t?e.children[0]:e.children[e.children.length-1];fs.focusSiblingItem(s,e,t,!0);}// isEdgeItem means is it a start or end item
|
244
244
|
// prettier-ignore
|
245
|
-
},{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")),
|
245
|
+
},{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")),fs.focusItemWhenOnEdge(t,s));}}]);}();var Ki=/*#__PURE__*/function(){function Ki(e,t){var _this84=this;_classCallCheck(this,Ki);var s;this._isOpen=!0,this._styles=t,this.elementRef=Ki.createElement((s=this._styles)==null?void 0:s.container),this.close(),setTimeout(function(){return _this84.addWindowEvents(e);});}return _createClass(Ki,[{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=we.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
|
246
246
|
},{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
|
247
|
-
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var s,i,n;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===
|
248
|
-
function addToDropup(e,t,s,i){var n=new Zs(s,i);bn.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(
|
247
|
+
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var s,i,n;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===q.ESCAPE?(this.close(),(s=this.highlightedItem)==null||s.dispatchEvent(new MouseEvent("mouseleave"))):t.key===q.ENTER?((i=this.highlightedItem)==null||i.click(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===q.ARROW_DOWN?fs.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===q.ARROW_UP&&fs.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 at=/*#__PURE__*/function(_yt3){function at(e,t){var _this85;_classCallCheck(this,at);var n,o;var s=_e.tryCreateConfig("Options",(n=t==null?void 0:t.button)==null?void 0:n.tooltip);_this85=_callSuper(this,at,[at.createButtonElement(),Fa,void 0,s,{styles:(o=t==null?void 0:t.button)==null?void 0:o.styles}]);var i=_this85.createInnerElementsForStates(_this85.customStyles);_this85._menu=new Ki(e,t==null?void 0:t.menu),_this85.addClickEvent(),_this85.buttonContainer=at.createButtonContainer(),_this85.changeElementsByState(i.styles),_this85.buttonContainer.appendChild(_this85.elementRef),_this85.elementRef.classList.add(at.BUTTON_ICON_CLASS),_this85.buttonContainer.appendChild(_this85._menu.elementRef),_this85.reapplyStateStyle("styles"),_this85.addContainerEvents(e);return _this85;}_inherits(at,_yt3);return _createClass(at,[{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 _this86=this;e.addEventListener("click",function(t){var s=t.target.classList;!s.contains(at.BUTTON_ICON_CLASS)&&!s.contains(ht.DISABLED_CONTAINER_CLASS)&&_this86._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";}}]);}(yt);at.BUTTON_ICON_CLASS="dropup-button";var Zs=at;var Q=/*#__PURE__*/function(){function Q(){_classCallCheck(this,Q);}return _createClass(Q,null,[{key:"addToDropup",value:// prettier-ignore
|
248
|
+
function addToDropup(e,t,s,i){var n=new Zs(s,i);bn.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(_ref49){var a=_ref49.button;return n.addItem(a);});var o=Zs.getPosition(t,i);At.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){At.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
|
249
249
|
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Q.createPositionsToButtonsObj();Object.keys(e).forEach(function(i){var o;var n=(o=e[i])==null?void 0:o.button.position;n&&Q.setPosition(e,i,t[n]);}),t["inside-right"].length===0&&e.submit&&Q.setPosition(e,"submit",t["inside-right"]),t["outside-right"].length===0&&(e.submit?Q.setPosition(e,"submit",t["outside-right"]):e.microphone?Q.setPosition(e,"microphone",t["outside-right"]):e.camera?Q.setPosition(e,"camera",t["outside-right"]):e["".concat(ht.INDICATOR_PREFIX,"1")]&&Q.setPosition(e,"".concat(ht.INDICATOR_PREFIX,"1"),t["outside-right"])),e.submit&&Q.setPosition(e,"submit",t["outside-left"].length===0?t["outside-left"]:t["inside-right"]),e.microphone&&Q.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?(bn.forEach(function(i){e[i]&&t["dropup-menu"].push(_objectSpread(_objectSpread({},e[i]),{},{buttonType:i}));}),s.forEach(function(i){var n=i;n.startsWith(ht.INDICATOR_PREFIX)&&e[n]&&t["dropup-menu"].push(_objectSpread(_objectSpread({},e[n]),{},{customType:n}));})):s.length===1&&Q.setPosition(e,s[0],t["outside-right"].length===0?t["outside-right"]:t["outside-left"]),t;}// prettier-ignore
|
250
|
-
},{key:"addButtons",value:function addButtons(e,t,s,i){var n=Q.generatePositionToButtons(t);return Q.addToSideContainer(e,n),n["dropup-menu"].length>0&&Q.addToDropup(e,n,s,i),n;}}]);}();var Ua="<?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>",ja="<?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",qa="<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>",Ha="<?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",Va={images:{id:"upload-images-icon",svgString:ja,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:Ha,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:qa,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:Ua,dropupText:"File"}};var li=/*#__PURE__*/function(_yt4){function li(e){var _this86;_classCallCheck(this,li);(e==null?void 0:e.position)==="dropup-menu"&&(e.position="outside-right");var t=_e.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this86=_callSuper(this,li,[li.createMicrophoneElement(),Qn,e==null?void 0:e.position,t,e]),_this86.isActive=!1,_this86._innerElements=_this86.createInnerElementsForStates(_this86.customStyles),_this86.changeToDefault();return _this86;}_inherits(li,_yt4);return _createClass(li,[{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;}}]);}(yt);function za(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r["default"]:r;}var Ss={},Mt={},kt={},Lt={},It={},vn;function ci(){if(vn)return It;vn=1,Object.defineProperty(It,"__esModule",{value:!0}),It.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 It.Text=r,r.FIRST_CHAR_REGEX=/\S/,r.DOUBLE_LINE=/\n\n/g,r.ONE_LINE=/\n/g,It;}var En;function sr(){if(En)return Lt;En=1,Object.defineProperty(Lt,"__esModule",{value:!0}),Lt.Translate=void 0;var r=ci();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 Lt.Translate=e,Lt;}var _n;function Ga(){if(_n)return kt;_n=1,Object.defineProperty(kt,"__esModule",{value:!0}),kt.WebSpeechTranscript=void 0;var r=sr();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 kt.WebSpeechTranscript=e,kt;}var Ot={},Sn;function Ji(){if(Sn)return Ot;Sn=1,Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.Browser=void 0;var r=/*#__PURE__*/_createClass(function r(){_classCallCheck(this,r);});return Ot.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;},Ot;}var Nt={},Pt={},xn;function Ka(){if(xn)return Pt;xn=1,Object.defineProperty(Pt,"__esModule",{value:!0}),Pt.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 _this87=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,_this87.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 Pt.EventListeners=r,r.KEY_DOWN_TIMEOUT=null,Pt;}var Bt={},wn;function Ja(){if(wn)return Bt;wn=1,Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.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 Bt.PreResultUtils=r,Bt;}var Dt={},Ft={},An;function ir(){if(An)return Ft;An=1,Object.defineProperty(Ft,"__esModule",{value:!0}),Ft.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
|
250
|
+
},{key:"addButtons",value:function addButtons(e,t,s,i){var n=Q.generatePositionToButtons(t);return Q.addToSideContainer(e,n),n["dropup-menu"].length>0&&Q.addToDropup(e,n,s,i),n;}}]);}();var Ua="<?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>",ja="<?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",Ha="<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>",qa="<?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",Va={images:{id:"upload-images-icon",svgString:ja,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:qa,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:Ha,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:Ua,dropupText:"File"}};var li=/*#__PURE__*/function(_yt4){function li(e){var _this87;_classCallCheck(this,li);(e==null?void 0:e.position)==="dropup-menu"&&(e.position="outside-right");var t=_e.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this87=_callSuper(this,li,[li.createMicrophoneElement(),Qn,e==null?void 0:e.position,t,e]),_this87.isActive=!1,_this87._innerElements=_this87.createInnerElementsForStates(_this87.customStyles),_this87.changeToDefault();return _this87;}_inherits(li,_yt4);return _createClass(li,[{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;}}]);}(yt);function za(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r["default"]:r;}var Ss={},Mt={},kt={},Lt={},It={},vn;function ci(){if(vn)return It;vn=1,Object.defineProperty(It,"__esModule",{value:!0}),It.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 It.Text=r,r.FIRST_CHAR_REGEX=/\S/,r.DOUBLE_LINE=/\n\n/g,r.ONE_LINE=/\n/g,It;}var En;function sr(){if(En)return Lt;En=1,Object.defineProperty(Lt,"__esModule",{value:!0}),Lt.Translate=void 0;var r=ci();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 Lt.Translate=e,Lt;}var _n;function Ga(){if(_n)return kt;_n=1,Object.defineProperty(kt,"__esModule",{value:!0}),kt.WebSpeechTranscript=void 0;var r=sr();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 kt.WebSpeechTranscript=e,kt;}var Ot={},Sn;function Ji(){if(Sn)return Ot;Sn=1,Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.Browser=void 0;var r=/*#__PURE__*/_createClass(function r(){_classCallCheck(this,r);});return Ot.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;},Ot;}var Nt={},Pt={},xn;function Ka(){if(xn)return Pt;xn=1,Object.defineProperty(Pt,"__esModule",{value:!0}),Pt.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 _this88=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,_this88.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 Pt.EventListeners=r,r.KEY_DOWN_TIMEOUT=null,Pt;}var Bt={},wn;function Ja(){if(wn)return Bt;wn=1,Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.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 Bt.PreResultUtils=r,Bt;}var Dt={},Ft={},Cn;function ir(){if(Cn)return Ft;Cn=1,Object.defineProperty(Ft,"__esModule",{value:!0}),Ft.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
|
251
251
|
// they can only safely be scrolled to the end
|
252
|
-
},{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 Ft.AutoScroll=r,Ft;}var Ut={},
|
252
|
+
},{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 Ft.AutoScroll=r,Ft;}var Ut={},Tn;function di(){if(Tn)return Ut;Tn=1,Object.defineProperty(Ut,"__esModule",{value:!0}),Ut.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 Ut.Elements=r,Ut;}var jt={},An;function hi(){if(An)return jt;An=1,Object.defineProperty(jt,"__esModule",{value:!0}),jt.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)
|
253
253
|
},{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
|
254
254
|
// private static getCursorOffsetFromLeft(inputElement: HTMLInputElement, position: number) {
|
255
255
|
// // Get the value of the input element up to the cursor position
|
@@ -267,39 +267,39 @@ function addToDropup(e,t,s,i){var n=new Zs(s,i);bn.forEach(function(a){var l=t["
|
|
267
267
|
// document.body.removeChild(tempSpan);
|
268
268
|
// return {left: offsetWidth, top: offsetHeight};
|
269
269
|
// }
|
270
|
-
},{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 jt.Cursor=r,jt;}var Rn;function nr(){if(Rn)return Dt;Rn=1,Object.defineProperty(Dt,"__esModule",{value:!0}),Dt.CommandUtils=void 0;var r=ir(),e=di(),t=Ji(),s=hi(),i=ci();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,
|
271
|
-
},{key:"execCommand",value:function execCommand(a,l,c,d,u){var h,
|
270
|
+
},{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 jt.Cursor=r,jt;}var Rn;function nr(){if(Rn)return Dt;Rn=1,Object.defineProperty(Dt,"__esModule",{value:!0}),Dt.CommandUtils=void 0;var r=ir(),e=di(),t=Ji(),s=hi(),i=ci();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,f=d.length-1;for(;c[h]===d[f]&&f>=0;)h-=1,f-=1;if(f<0)return!0;}return!1;}// prettier-ignore
|
271
|
+
},{key:"execCommand",value:function execCommand(a,l,c,d,u){var h,f,m;var p=a.commands;if(!p||!d||!c)return;var g=((h=p.settings)===null||h===void 0?void 0:h.caseSensitive)===!0?l:l.toLowerCase(),v=i.Text.breakupIntoWordsArr(g),R=((f=p.settings)===null||f===void 0?void 0:f.substrings)===!1?n.checkIfMatchesWord:n.checkIfMatchesSubstring;if(p.commandMode&&R(p.commandMode,g,v))return a.setInterimColorToFinal(),setTimeout(function(){return n.toggleCommandModeOn(a);}),{doNotProcessTranscription:!1};if(!(p.commandMode&&!a.isWaitingForCommand)){if(p.stop&&R(p.stop,g,v))return n.toggleCommandModeOff(a),setTimeout(function(){return a.stop();}),{doNotProcessTranscription:!1};if(p.pause&&R(p.pause,g,v))return n.toggleCommandModeOff(a),a.setInterimColorToFinal(),setTimeout(function(){var O;a.isPaused=!0,(O=a.onPauseTrigger)===null||O===void 0||O.call(a,!0);}),{doNotProcessTranscription:!1};if(p.resume&&R(p.resume,g,v))return a.isPaused=!1,(m=a.onPauseTrigger)===null||m===void 0||m.call(a,!1),n.toggleCommandModeOff(a),a.resetRecording(c),{doNotProcessTranscription:!0};if(p.reset&&R(p.reset,g,v))return u!==void 0&&n.setText(a,c,u,d),{doNotProcessTranscription:!0};if(p.removeAllText&&R(p.removeAllText,g,v))return n.setText(a,c,"",d),{doNotProcessTranscription:!0};}}}]);}();return Dt.CommandUtils=n,Dt;}var Ht={},Mn;function $a(){if(Mn)return Ht;Mn=1,Object.defineProperty(Ht,"__esModule",{value:!0}),Ht.Highlight=void 0;var r=di(),e=hi();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 Ht.Highlight=t,Ht;}var qt={},kn;function Wa(){if(kn)return qt;kn=1,Object.defineProperty(qt,"__esModule",{value:!0}),qt.Padding=void 0;var r=di(),e=hi(),t=ci();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),f=(a=o.textContent)===null||a===void 0?void 0:a[h-1],m=e.Cursor.getGenericElementCursorOffset(o,u,!1),p=(l=o.textContent)===null||l===void 0?void 0:l[m];t.Text.isCharDefined(f)&&(n.startPadding=" "),t.Text.isCharDefined(p)&&(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 qt.Padding=s,qt;}var Ln;function rr(){if(Ln)return Nt;Ln=1,Object.defineProperty(Nt,"__esModule",{value:!0}),Nt.Speech=void 0;var r=Ka(),e=Ja(),t=nr(),s=ir(),i=$a(),n=di(),o=Wa(),a=Ji(),l=hi(),c=ci();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 f,m;if(h!=null&&h.element)if(r.EventListeners.add(this,h),Array.isArray(h.element)){var g=h.element.find(function(v){return v===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=(f=h==null?void 0:h.textColor)===null||f===void 0?void 0:f["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:
|
272
272
|
// unfortunately it did not work because the service would still continue firing the intermediate and final results
|
273
273
|
// into the new position
|
274
274
|
},{key:"resetRecording",value:function resetRecording(h){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(h,!0);}// prettier-ignore
|
275
|
-
},{key:"updateElements",value:function updateElements(h,
|
275
|
+
},{key:"updateElements",value:function updateElements(h,f,m){var p;var g=c.Text.capitalize(f);if(this.finalTranscript===g&&h==="")return;e.PreResultUtils.process(this,m,h==="",this._onPreResult,this._options)&&(h="",m="");var v=this.commands&&t.CommandUtils.execCommand(this,m,this._options,this._primitiveElement||this._genericElement,this._originalText);if(v){if(v.doNotProcessTranscription)return;h="",m="";}if(this.isPaused||this.isWaitingForCommand)return;(p=this._onResult)===null||p===void 0||p.call(this,m,h===""),this.finalTranscript=g,this._displayInterimResults||(h="");var R=this.finalTranscript===""&&h==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,h,R):this._genericElement&&this.updateGenericElement(this._genericElement,h,R);}// prettier-ignore
|
276
276
|
// remember that padding values here contain actual text left and right
|
277
|
-
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(h,
|
278
|
-
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 Xt.AzureTranscript=e,Xt;}var jn;function nl(){if(jn)return zt;jn=1,Object.defineProperty(zt,"__esModule",{value:!0}),zt.Azure=void 0;var r=Za(),e=el(),t=tl(),s=sl(),i=il(),n=rr();var o=/*#__PURE__*/function(_n$Speech){function o(){var
|
277
|
+
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(h,f,m){this.isHighlighted&&i.Highlight.removeForPrimitive(this,h),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,h),m&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var p=this.startPadding+this.finalTranscript+f;if(h.value=p+this.endPadding,!this.isTargetInShadow){var g=p.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,f,m){this.isHighlighted&&i.Highlight.removeForGeneric(this,h),this.spansPopulated||n.Elements.appendSpans(this,h);var p=(m?"":this.startPadding)+c.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=p;var g=s.AutoScroll.isRequired(this.autoScroll,h);s.AutoScroll.changeStateIfNeeded(this,g);var v=c.Text.lineBreak(f)+(m?"":this.endPadding);this.interimSpan.innerHTML=v,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&l.Cursor.setOffsetForSafariGeneric(h,p.length+v.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 f;(f=this._onError)===null||f===void 0||f.call(this,h),this.recognizing=!1;}}]);}();return Nt.Speech=d,Nt;}var In;function Xa(){if(In)return Mt;In=1,Object.defineProperty(Mt,"__esModule",{value:!0}),Mt.WebSpeech=void 0;var r=Ga(),e=Ji(),t=rr();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 _this89=this;this._service&&(this._service.onstart=function(){_this89.setStateOnStart();},this._service.onerror=function(n){e.Browser.IS_SAFARI()&&n.message==="Another request is started"||n.error==="aborted"&&_this89.isRestarting||n.error!=="no-speech"&&_this89.error(n.message||n.error);},this._service.onaudioend=function(){_this89.setStateOnStop();},this._service.onend=function(){_this89._stopping=!1;},this._service.onresult=function(n){if(_typeof(n.results)>"u"&&_this89._service)_this89._service.onend=null,_this89._service.stop();else if(_this89._extractText&&!_this89._stopping){var _this89$_extractText=_this89._extractText(n,_this89.finalTranscript,_this89._translations),o=_this89$_extractText.interimTranscript,a=_this89$_extractText.finalTranscript,l=_this89$_extractText.newText;_this89.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 Mt.WebSpeech=s,Mt;}var Vt={},On;function Ya(){if(On)return Vt;On=1,Object.defineProperty(Vt,"__esModule",{value:!0}),Vt.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 Vt.GlobalState=r,r.doubleClickPending=!1,Vt;}var zt={},Gt={},Nn;function Za(){if(Nn)return Gt;Nn=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.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 Gt.PreventConnectionStop=r,Gt;}var Kt={},Jt={},Pn;function Qa(){return Pn||(Pn=1,Object.defineProperty(Jt,"__esModule",{value:!0}),Jt.README_URL=void 0,Jt.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),Jt;}var Bn;function el(){if(Bn)return Kt;Bn=1,Object.defineProperty(Kt,"__esModule",{value:!0}),Kt.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 _callee163(s,i){return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:if(!i.region){_context163.n=1;break;}return _context163.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 _context163.a(2);}},_callee163);}));function getNewSpeechConfig(_x294,_x295){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 _callee164(s,i){var n;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:_context164.n=1;return e.getNewSpeechConfig(s,i);case 1:n=_context164.v;return _context164.a(2,(n&&e.process(n,i),n));}},_callee164);}));function get(_x296,_x297){return _get.apply(this,arguments);}return get;}()}]);}();return Kt.AzureSpeechConfig=e,Kt;}var $t={},Dn;function tl(){if(Dn)return $t;Dn=1,Object.defineProperty($t,"__esModule",{value:!0}),$t.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 $t.StopTimeout=r,r.DEFAULT_MS=2e4,$t;}var Wt={},Fn;function sl(){if(Fn)return Wt;Fn=1,Object.defineProperty(Wt,"__esModule",{value:!0}),Wt.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 Wt.AzureAudioConfig=r,Wt;}var Xt={},Un;function il(){if(Un)return Xt;Un=1,Object.defineProperty(Xt,"__esModule",{value:!0}),Xt.AzureTranscript=void 0;var r=sr();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
|
278
|
+
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 Xt.AzureTranscript=e,Xt;}var jn;function nl(){if(jn)return zt;jn=1,Object.defineProperty(zt,"__esModule",{value:!0}),zt.Azure=void 0;var r=Za(),e=el(),t=tl(),s=sl(),i=il(),n=rr();var o=/*#__PURE__*/function(_n$Speech){function o(){var _this90;_classCallCheck(this,o);_this90=_callSuper(this,o,arguments),_this90._newTextPadding="";return _this90;}_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 _callee165(l){var c,_t42;return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:_t42=this.validate(l);if(!_t42){_context165.n=2;break;}_context165.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 _context165.a(2);}},_callee165,this);}));function startAsync(_x298){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 _callee166(l){var c,d,u,h,_l$autoLanguage,f,m,p,g;return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:c=o.getAPI();d=s.AzureAudioConfig.get(c.AudioConfig,l.deviceId);_context166.n=1;return e.AzureSpeechConfig.get(c.SpeechConfig,l);case 1:u=_context166.v;if(u){if(l.autoLanguage&&l.autoLanguage.languages.length>0){_l$autoLanguage=l.autoLanguage,f=_l$autoLanguage.type,m=_l$autoLanguage.languages,p=m.slice(0,f==="Continuous"?10:4),g=c.AutoDetectSourceLanguageConfig.fromLanguages(p);f==="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 _context166.a(2);}},_callee166,this);}));function instantiateService(_x299){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
|
279
279
|
},{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
|
280
|
-
},{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,
|
281
|
-
_inherits(os,_li);return _createClass(os,[{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);}),xs.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),s.submitAfterSilence&&(this._silenceSubmit=new al(s.submitAfterSilence,s.stopAfterSubmit)),{serviceName:os.getServiceName(s),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,s,i){var
|
282
|
-
function Fe(e,t,s,i,n){var
|
283
|
-
function Be(e,t,s,i,n){_classCallCheck(this,Be);return _callSuper(this,Be,[e,t,s,i,n]);}_inherits(Be,_Fe);return _createClass(Be,[{key:"createTimer",value:function createTimer(e,t){var
|
284
|
-
},{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"),je.IS_SAFARI&&e.classList.add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var s=e.parentElement?X.cloneElement(e):e,i=document.createElement("audio");i.src=t;var n=
|
280
|
+
},{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,f=_i$AzureTranscript$ex2.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(u,h,f),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 _this91=this;this._retrieveTokenInterval=setInterval(function(){l==null||l().then(function(c){_this91._service&&(_this91._service.authorizationToken=(c==null?void 0:c.trim())||"");})["catch"](function(c){_this91.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 zt.Azure=o,zt;}var Hn;function rl(){if(Hn)return Ss;Hn=1,Object.defineProperty(Ss,"__esModule",{value:!0});var r=Xa(),e=nr(),t=Ya(),s=nl();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 Ss["default"]=i,Ss;}var ol=rl();var xs=/* @__PURE__ */za(ol);var al=/*#__PURE__*/function(){function al(e,t){_classCallCheck(this,al);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(al,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this92=this;this._silenceTimeout=setTimeout(function(){var s;(s=e.submit)==null||s.call(e),xs.stop(),_this92._stop||setTimeout(t,ps.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 os=/*#__PURE__*/function(_li){function os(e,t,s){var _this93;_classCallCheck(this,os);var i=_typeof(e.speechToText)=="object"?e.speechToText:{};_this93=_callSuper(this,os,[i==null?void 0:i.button]);var _this93$processConfig=_this93.processConfiguration(t,e.speechToText),n=_this93$processConfig.serviceName,o=_this93$processConfig.processedConfig;if(_this93._addErrorMessage=s,n==="webspeech"&&!xs.isWebSpeechSupported())_this93.changeToUnsupported();else{var a=!e.textInput||!e.textInput.disabled;_this93.elementRef.onclick=_this93.buttonClick.bind(_this93,t,a,n,o);}setTimeout(function(){_this93._validationHandler=e._validationHandler;});return _this93;}// prettier-ignore
|
281
|
+
_inherits(os,_li);return _createClass(os,[{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);}),xs.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),s.submitAfterSilence&&(this._silenceSubmit=new al(s.submitAfterSilence,s.stopAfterSubmit)),{serviceName:os.getServiceName(s),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,s,i){var _this94=this;var n=i==null?void 0:i.events;e.removePlaceholderStyle(),xs.toggle(s,_objectSpread({insertInCursorLocation:!1,element:t?e.inputElementRef:void 0,onError:function onError(){var o;_this94.onError(),(o=_this94._silenceSubmit)==null||o.clearSilenceTimeout();},onStart:function onStart(){var o;_this94.changeToActive(),(o=n==null?void 0:n.onStart)==null||o.call(n);},onStop:function onStop(){var o,a,l;(o=_this94._validationHandler)==null||o.call(_this94),(a=_this94._silenceSubmit)==null||a.clearSilenceTimeout(),_this94.changeToDefault(),(l=n==null?void 0:n.onStop)==null||l.call(n);},onPauseTrigger:function onPauseTrigger(o){var a,l;(a=_this94._silenceSubmit)==null||a.onPause(o,e,_this94.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=_this94._validationHandler)==null||l.call(_this94)),(c=_this94._silenceSubmit)==null||c.resetSilenceTimeout(e,_this94.elementRef.onclick),(d=n==null?void 0:n.onResult)==null||d.call(n,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this94.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();},os.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(li);os.MICROPHONE_RESET_TIMEOUT_MS=300;var ps=os;var Fe=/*#__PURE__*/function(){// prettier-ignore
|
282
|
+
function Fe(e,t,s,i,n){var _this95=this;_classCallCheck(this,Fe);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(){_this95._validationHandler=e._validationHandler,_this95._onInput=t.onInput;});}return _createClass(Fe,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var s;return Fe.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=Fe.getTypeFromBlob(e);if(i==="image"){var n=Fe.createImageAttachment(t);this.addFileAttachment(e,"image",n,s);}else if(i==="audio"){var _n3=ms.createAudioAttachment(t);this.addFileAttachment(e,"audio",_n3,s);}else{var _n4=Fe.createAnyFileAttachment(e.name);this.addFileAttachment(e,"any",_n4,s);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,s,i){var a;var n=Fe.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),ms.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 _this96=this;this._hiddenAttachments.clear(),this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t.click();}),_this96._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 _this97=this;var e;Array.from(this._hiddenAttachments).forEach(function(t){_this97._fileAttachmentsContainerRef.appendChild(t.attachmentContainerElement),_this97._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"),je.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(_Fe){// prettier-ignore
|
283
|
+
function Be(e,t,s,i,n){_classCallCheck(this,Be);return _callSuper(this,Be,[e,t,s,i,n]);}_inherits(Be,_Fe);return _createClass(Be,[{key:"createTimer",value:function createTimer(e,t){var _this98=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=_this98.stopPlaceholderCallback)==null||a.call(_this98),_this98.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=qe.createSVGElement(Ti);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 _this99=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=_this99.stopPlaceholderCallback)==null?void 0:a.call(_this99);};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
|
284
|
+
},{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"),je.IS_SAFARI&&e.classList.add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var s=e.parentElement?X.cloneElement(e):e,i=document.createElement("audio");i.src=t;var n=qe.createSVGElement(er);n.classList.add("attachment-icon","play-icon");var o=qe.createSVGElement(Ti);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();}}]);}(Fe);Be.TIMER_LIMIT_S=5999;var ms=Be;var ll=/*#__PURE__*/function(){function ll(){_classCallCheck(this,ll);}return _createClass(ll,null,[{key:"create",value:// prettier-ignore
|
285
285
|
function create(e,t,s,i,n,o){return o==="audio"?new ms(e,t,s,i,n):new Fe(e,t,s,i,n);}}]);}();var bs=/*#__PURE__*/function(){function bs(e,t,s){_classCallCheck(this,bs);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
|
286
|
-
return _createClass(bs,[{key:"addType",value:function addType(e,t,s,i){var n=ll.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
|
287
|
-
function Qs(e,t,s,i,n,o){var
|
286
|
+
return _createClass(bs,[{key:"addType",value:function addType(e,t,s,i){var n=ll.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 _callee168(){return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:_context168.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref50=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e){var t;return _regenerator().w(function(_context167){while(1)switch(_context167.n){case 0:return _context167.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee167);}));return function(_x300){return _ref50.apply(this,arguments);};}()));case 1:return _context168.a(2);}},_callee168,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){bs.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 ve=/*#__PURE__*/function(){function ve(e,t,s){_classCallCheck(this,ve);this._isOpen=!1,this._contentRef=ve.createModalContent(t,s==null?void 0:s.backgroundColor),this._buttonPanel=ve.createButtonPanel(s==null?void 0:s.backgroundColor),this._elementRef=ve.createContainer(this._contentRef,s),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=ve.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(ve,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this100=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){D.addAttributes(t),_this100._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this101=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(){_this101._elementRef.style.display="none",_this101._backgroundPanelRef.style.display="none";},ve.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 _this102=this;var i=t?ve.createSVGButton(e):ve.createTextButton(e);return this.addButtons(i),i.onclick=function(){_this102.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===q.ESCAPE?(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)):t.key===q.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=qe.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 ve(e,["modal-content"],t.files.infoModal.containerStyle);return n.addCloseButton("OK",!1,s),n.openTextModal.bind(n,t.infoModalTextMarkUp||"");}}}]);}();ve.MODAL_CLOSE_TIMEOUT_MS=190;var ct=ve;var Qs=/*#__PURE__*/function(_yt5){// prettier-ignore
|
287
|
+
function Qs(e,t,s,i,n,o){var _this103;_classCallCheck(this,Qs);var u,h,f,m,p,g,v,R,O,I;var a=(u=s==null?void 0:s.button)==null?void 0:u.position,l=((m=(f=(h=s==null?void 0:s.button)==null?void 0:h.styles)==null?void 0:f.text)==null?void 0:m.content)||o,c=_e.tryCreateConfig("Upload File",(p=s==null?void 0:s.button)==null?void 0:p.tooltip);_this103=_callSuper(this,Qs,[Qs.createButtonElement(),n,a,c,s.button,l]);var d=_this103.createInnerElementsForStates(i,_this103.customStyles);_this103._inputElement=Qs.createInputElement((g=s==null?void 0:s.files)==null?void 0:g.acceptedFormats),_this103.addClickEvent(e,s),_this103.changeElementsByState(d.styles),_this103.reapplyStateStyle("styles"),_this103._fileAttachmentsType=t,_this103._openModalOnce=((R=(v=s.files)==null?void 0:v.infoModal)==null?void 0:R.openModalOnce)===!1||(I=(O=s.files)==null?void 0:O.infoModal)==null?void 0:I.openModalOnce;return _this103;}_inherits(Qs,_yt5);return _createClass(Qs,[{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){bs.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=ct.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;}}]);}(yt);var De=/*#__PURE__*/function(){function De(){_classCallCheck(this,De);}return _createClass(De,null,[{key:"create",value:function create(e,t,s){var i=De.createElement(s);De.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(),De.display(e);},e.ondragleave=function(i){i.preventDefault(),De.hide(e);},e.ondragover=function(i){i.preventDefault();},e.ondrop=function(i){i.preventDefault(),De.uploadFile(s,i),De.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 Qe=/*#__PURE__*/function(){function Qe(){_classCallCheck(this,Qe);}return _createClass(Qe,null,[{key:"validate",value:// prettier-ignore
|
288
288
|
function validate(e,t,s,i,n){var o=e(s,i,n);return o?t.changeToSubmitIcon():t.changeToDisabledIcon(),o;}// prettier-ignore
|
289
|
-
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
290
|
-
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
291
|
-
},{key:"attach",value:function attach(e,t,s,i,n){var o=e.validateInput||Y.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var
|
289
|
+
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e,t,s,i){var n,o,a;return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:n=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context169.n=1;return s.completePlaceholders();case 1:o=s.getAllFileData(),a=o==null?void 0:o.map(function(l){return l.file;});return _context169.a(2,Qe.validate(e,i,n,a));}},_callee169);}));function useValidationFunc(_x301,_x302,_x303,_x304){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
|
290
|
+
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e,t,s){var n,i;return _regenerator().w(function(_context170){while(1)switch(_context170.n){case 0:i=(n=t.files)==null?void 0:n.map(function(o){return o.file;});return _context170.a(2,Qe.validate(e,s,t.text,i,!0));}},_callee170);}));function useValidationFuncProgrammatic(_x305,_x306,_x307){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!==Se.URL&&!$.canSendMessage(s)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
|
291
|
+
},{key:"attach",value:function attach(e,t,s,i,n){var o=e.validateInput||Y.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref51=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(a){var l;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:if(!(n.status.loadingActive||n.status.requestInProgress||t.isSubmitProgrammaticallyDisabled===!0||!Qe.validateWebsocket(t,n))){_context171.n=1;break;}return _context171.a(2,!1);case 1:l=o||t.canSendMessage;return _context171.a(2,l?a?Qe.useValidationFuncProgrammatic(l,a,n):Qe.useValidationFunc(l,s,i,n):null);}},_callee171);}));return function(_x308){return _ref51.apply(this,arguments);};}();}}]);}();var or=/*#__PURE__*/function(){function or(){_classCallCheck(this,or);}return _createClass(or,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 cl=/*#__PURE__*/function(_li2){function cl(e,t){var _this104;_classCallCheck(this,cl);var s,i;_this104=_callSuper(this,cl,[t.button]),_this104._waitingForBrowserApproval=!1,_this104._audioType=e,_this104._extension=((s=t.files)==null?void 0:s.format)||"mp3",_this104._maxDurationSeconds=(i=t.files)==null?void 0:i.maxDurationSeconds,_this104.elementRef.onclick=_this104.buttonClick.bind(_assertThisInitialized(_this104));return _this104;}_inherits(cl,_li2);return _createClass(cl,[{key:"buttonClick",value:function buttonClick(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()));}},{key:"stop",value:function stop(){var _this105=this;return new Promise(function(e){var t,s;_this105.changeToDefault(),(t=_this105._mediaRecorder)==null||t.stop(),(s=_this105._mediaStream)==null||s.getTracks().forEach(function(i){return i.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this106=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this106.changeToActive(),_this106._mediaRecorder=new MediaRecorder(e),_this106._audioType.addPlaceholderAttachment(_this106.stop.bind(_this106),_this106._maxDurationSeconds),_this106._mediaStream=e,_this106._mediaRecorder.addEventListener("dataavailable",function(t){_this106.createFile(t);}),_this106._mediaRecorder.start();})["catch"](function(e){console.error(e),_this106.stop();})["finally"](function(){_this106._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this107=this;var t=new Blob([e.data],{type:"audio/".concat(this._extension)}),s=or.getFileName(this._newFilePrefix||"audio",this._extension),i=new File([t],s,{type:t.type}),n=new FileReader();n.readAsDataURL(i),n.onload=function(o){_this107._audioType.completePlaceholderAttachment(i,o.target.result);};}}]);}(li);var dl="<?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 dt=/*#__PURE__*/function(){function dt(){_classCallCheck(this,dt);}return _createClass(dt,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]||{}));W.overwritePropertyObjectFromAnother(s,e.submit,["container","default"]),W.overwritePropertyObjectFromAnother(s,e.submit,["text","styles","default"]),W.overwritePropertyObjectFromAnother(s,e.submit,["svg","styles","default"]),e[t]=s;}// prettier-ignore
|
292
292
|
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){W.setPropertyValueIfDoesNotExist(e,["submit","container","default","backgroundColor"],""),W.setPropertyValueIfDoesNotExist(e,["disabled","container","default","backgroundColor"],"unset"),W.setPropertyValueIfDoesNotExist(e.submit,["svg","styles","default","filter"],""),W.setPropertyValueIfDoesNotExist(e.disabled,["svg","styles","default","filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),W.setPropertyValueIfDoesNotExist(e.disabled,["text","styles","default","color"],"grey"),dt.overwriteDefaultStyleWithSubmit(e,"disabled");}},{key:"process",value:function process(e){var t=JSON.parse(JSON.stringify(e||{}));return dt.overwriteDefaultStyleWithSubmit(t,"loading"),dt.overwriteDefaultStyleWithSubmit(t,"stop"),e!=null&&e.alwaysEnabled||dt.setUpDisabledButton(t),t;}}]);}();var B=/*#__PURE__*/function(_yt6){// prettier-ignore
|
293
|
-
function B(e,t,s,i,n,o){var
|
294
|
-
},{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
|
295
|
-
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
296
|
-
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var
|
297
|
-
},{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),D.removeAriaBusy(this.elementRef),this.elementRef.classList.add(B.DISABLED_CLASS),D.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;}}]);}(yt);B.SUBMIT_CLASS="submit-button",B.LOADING_CLASS="loading-button",B.DISABLED_CLASS="disabled-button";var Di=B;var hl="<?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",ul="<?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",
|
298
|
-
function $i(e,t,s,i){var
|
299
|
-
},{key:"addButtonEvents",value:function addButtonEvents(e,t,s,i){var
|
300
|
-
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,s,i){var n=new $i(e,t,s,i);return n.openCameraModal.bind(n,n);}}]);}(ct);var ml="<?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 Wi=/*#__PURE__*/function(_yt7){function Wi(e,t,s){var
|
301
|
-
function addClickEvent(e,t,s,i){var n=$i.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;}}]);}(yt);var vt=/*#__PURE__*/function(){function vt(e,t,s,i){_classCallCheck(this,vt);this.elementRef=vt.createPanelElement(e.inputAreaStyle);var n={},o=this.createFileUploadComponents(e,s,i,n),a=new
|
293
|
+
function B(e,t,s,i,n,o){var _this108;_classCallCheck(this,B);var a=dt.process(e.submitButtonStyles),l=dl,c=_e.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this108=_callSuper(this,B,[B.createButtonContainerElement(),l,a==null?void 0:a.position,c,a]),_this108._isSVGLoadingIconOverriden=!1,_this108.status={requestInProgress:!1,loadingActive:!1},_this108._messages=s,_this108._textInput=t,_this108._fileAttachments=n,_this108._innerElements=_this108.createInnerElementsForStates(),_this108._abortStream=new AbortController(),_this108._stopClicked={listener:function listener(){}},_this108._serviceIO=i,_this108._alwaysEnabled=!!(a!=null&&a.alwaysEnabled),e.disableSubmitButton=_this108.disableSubmitButton.bind(_assertThisInitialized(_this108),i),_this108.attemptOverwriteLoadingStyle(e),o.microphone&&_this108.setUpSpeechToText(o.microphone.button,e.speechToText),setTimeout(function(){var d;_this108._validationHandler=e._validationHandler,_this108.assignHandlers(_this108._validationHandler),(d=_this108._validationHandler)==null||d.call(_assertThisInitialized(_this108));});return _this108;}_inherits(B,_yt6);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 _this109=this;var e=Me.createCustomElements("submit",this.svg,this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(s){var i=s,n=Me.createCustomElements(i,_this109.svg,_this109.customStyles);n&&(t[i]=n);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return Me.createCustomElements("disabled",this.svg,this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
|
294
|
+
},{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 _callee172(){var e,t;return _regenerator().w(function(_context172){while(1)switch(_context172.n){case 0:_context172.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 _context172.a(2);}},_callee172,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e){var _this110=this;var t;return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:typeof e=="string"&&(e=Y.processSubmitUserMessage(e));t={text:e.text};e.files&&(t.files=Array.from(e.files).map(function(s){return{file:s,type:Fe.getTypeFromBlob(s)};})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this110.attemptSubmit(t,!0);});case 1:return _context173.a(2);}},_callee173);}));function programmaticSubmit(_x309){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
|
295
|
+
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(e){var t,n,o,a,l,s,i,_args174=arguments,_t43,_t44,_t45;return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:t=_args174.length>1&&_args174[1]!==undefined?_args174[1]:!1;_context174.n=1;return(n=this._validationHandler)==null?void 0:n.call(this,t?e:void 0);case 1:_t43=_context174.v;_t44=!1;if(!(_t43===_t44)){_context174.n=2;break;}return _context174.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();_t45=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t45){_context174.n=3;break;}_context174.n=3;return As.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context174.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};_context174.n=5;return this._serviceIO.callAPI(i,this._messages);case 5:(l=this._fileAttachments)==null||l.hideFiles();case 6:return _context174.a(2);}},_callee174,this);}));function attemptSubmit(_x310){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(_ref52){var e,t,s,i,_t46;return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:e=_ref52.text,t=_ref52.files,s=_ref52.custom;i={role:y.USER_ROLE,custom:s};e&&(i.text=e);_t46=t;if(!_t46){_context175.n=2;break;}_context175.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:i.files=_context175.v;case 2:this._serviceIO.sessionId&&(i._sessionId=this._serviceIO.sessionId);Object.keys(i).length>0&&this._messages.addNewMessage(i);case 3:return _context175.a(2);}},_callee175,this);}));function addNewMessage(_x311){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),D.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),D.removeAriaDisabled(this.elementRef),this.elementRef.classList.add(B.LOADING_CLASS),D.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
|
296
|
+
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this111=this;this.elementRef.classList.contains(B.SUBMIT_CLASS)||(this.elementRef.classList.remove(B.LOADING_CLASS,B.DISABLED_CLASS),D.removeAriaAttributes(this.elementRef),this.elementRef.classList.add(B.SUBMIT_CLASS),this.changeElementsByState(this._innerElements.submit),dt.resetSubmit(this,this.status.loadingActive),this.elementRef.onclick=function(){var e;_this111.submitFromInput(),(e=_this111._microphoneButton)!=null&&e.isActive&&ps.toggleSpeechAfterSubmit(_this111._microphoneButton.elementRef,!!_this111._stopSTTAfterSubmit);});}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
|
297
|
+
},{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),D.removeAriaBusy(this.elementRef),this.elementRef.classList.add(B.DISABLED_CLASS),D.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;}}]);}(yt);B.SUBMIT_CLASS="submit-button",B.LOADING_CLASS="loading-button",B.DISABLED_CLASS="disabled-button";var Di=B;var hl="<?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",ul="<?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",fl="<?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>",pl="<?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 $i=/*#__PURE__*/function(_ct){// prettier-ignore
|
298
|
+
function $i(e,t,s,i){var _this112;_classCallCheck(this,$i);_this112=_callSuper(this,$i,[e,["modal-content","modal-camera-content"],s]),_this112._stopped=!1,_this112._format="image/png",_this112._canvas=document.createElement("canvas"),_this112._canvas.classList.add("camera-modal-canvas");var _this112$addButtonsAn=_this112.addButtonsAndTheirEvents(t),n=_this112$addButtonsAn.captureButton,o=_this112$addButtonsAn.submitButton;_this112._captureButton=n,_this112._submitButton=o,_this112._captureIcon=_this112._captureButton.children[0],_this112._refreshIcon=qe.createSVGElement(hl),_this112._refreshIcon.classList.add("modal-svg-button-icon","modal-svg-refresh-icon"),(i==null?void 0:i.format)==="jpeg"&&(_this112._format="image/jpeg"),i!=null&&i.dimensions&&(_this112._dimensions=i.dimensions),_this112._contentRef.appendChild(_this112._canvas),_this112.extensionCloseCallback=_this112.stop;return _this112;}_inherits($i,_ct);return _createClass($i,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=ct.createSVGButton(ul);t.classList.add("modal-svg-camera-button"),t.children[0].classList.add("modal-svg-camera-icon");var s=this.addCloseButton(fl,!0);s.classList.add("modal-svg-close-button"),s.children[0].classList.add("modal-svg-close-icon");var i=ct.createSVGButton(pl);return i.classList.add("modal-svg-submit-button"),this.addButtons(t,i),this.addButtonEvents(t,s,i,e),{captureButton:t,submitButton:i};}// prettier-ignore
|
299
|
+
},{key:"addButtonEvents",value:function addButtonEvents(e,t,s,i){var _this113=this;e.onclick=function(){_this113.capture();},t.addEventListener("click",this.stop.bind(this)),s.onclick=function(){var n=_this113.getFile();n&&bs.addFilesToType([n],[i]),_this113.stop(),_this113.close();};}},{key:"stop",value:function stop(){var _this114=this;this._mediaStream&&this._mediaStream.getTracks().forEach(function(e){return e.stop();}),this._stopped=!0,setTimeout(function(){_this114._captureButton.replaceChildren(_this114._captureIcon),_this114._captureButton.classList.replace("modal-svg-refresh-button","modal-svg-camera-button");var e=_this114._canvas.getContext("2d");e==null||e.clearRect(0,0,_this114._canvas.width,_this114._canvas.height);},ct.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this115=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(_this115._mediaStream=e,!_this115.isOpen())return _this115.stop();var t=document.createElement("video");t.srcObject=e,t.play(),requestAnimationFrame(_this115.updateCanvas.bind(_this115,t,_this115._canvas));})["catch"](function(e){console.error(e),_this115.stop(),_this115.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 _s11=new Uint8Array(t),i=new Blob([_s11],{type:this._format}),n=this._format==="image/jpeg"?"jpeg":"png",o=or.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 _s12=t.getContext("2d");_s12==null||_s12.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
|
300
|
+
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,s,i){var n=new $i(e,t,s,i);return n.openCameraModal.bind(n,n);}}]);}(ct);var ml="<?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 Wi=/*#__PURE__*/function(_yt7){function Wi(e,t,s){var _this116;_classCallCheck(this,Wi);var c,d,u,h,f,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=_e.tryCreateConfig("Camera",(f=s==null?void 0:s.button)==null?void 0:f.tooltip),a=((m=s==null?void 0:s.button)==null?void 0:m.styles)||{};_this116=_callSuper(this,Wi,[Wi.createButtonElement(),ml,i,o,a,n]);var l=_this116.createInnerElementsForStates(_this116.customStyles);s&&_this116.addClickEvent(e,t,s.modalContainerStyle,s.files),_this116.changeElementsByState(l.styles),_this116.reapplyStateStyle("styles");return _this116;}_inherits(Wi,_yt7);return _createClass(Wi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("camera-icon","styles",e)};}},{key:"addClickEvent",value:// prettier-ignore
|
301
|
+
function addClickEvent(e,t,s,i){var n=$i.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;}}]);}(yt);var vt=/*#__PURE__*/function(){function vt(e,t,s,i){_classCallCheck(this,vt);this.elementRef=vt.createPanelElement(e.inputAreaStyle);var n={},o=this.createFileUploadComponents(e,s,i,n),a=new Ts(e,s,o);e.speechToText&&!n.microphone&&(n.microphone={button:new ps(e,a,t.addNewErrorMessage.bind(t))});var l=new Di(e,a,t,s,o,n);a.submit=l.submitFromInput.bind(l),Qe.attach(e,s,a,o,l),e.submitUserMessage=l.programmaticSubmit.bind(l),n.submit={button:l},e.customButtons&&ht.add(e,n),vt.addElements(this.elementRef,a,n,i,o,e.dropupStyles),vt.assignOnInput(e,s,o,a);}return _createClass(vt,[{key:"createFileUploadComponents",value:// prettier-ignore
|
302
302
|
function createFileUploadComponents(e,t,s,i){var o,a,l,c;var n=new bs(this.elementRef,e.attachmentContainerStyle,t.demo);if(vt.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 Wi(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 cl(_d,t.recordAudio)};}return De.isEnabled(n,e.dragAndDrop)&&De.create(s,n,e.dragAndDrop),n;}// prettier-ignore
|
303
|
-
}],[{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),_Va$l=Va[l],u=_Va$l.id,h=_Va$l.svgString,
|
304
|
-
},{key:"addElements",value:function addElements(e,t,s,i,n,o){X.addElements(e,t.elementRef);var a=Tt.create(),l=Q.addButtons(a,s,i,o);Bi.set(t.inputElementRef,a,n.elementRef,l),Tt.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;})),ds.onInput(e,l,n);});};}}]);}();var Xi=/*#__PURE__*/function(){function Xi(){_classCallCheck(this,Xi);}return _createClass(Xi,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 vt(e,n,t,i);return X.addElements(i,n.elementRef,o.elementRef),i;}},{key:"render",value:function render(e,t,s,i){var n=Xi.createElements(e,s,i);t.replaceChildren(n),s.isCustomView()&&s.setUpView(n,t);}}]);}();var gl="#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 yl=Object.defineProperty,T=function T(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&&yl(e,t,i),i;};var x=/*#__PURE__*/function(_xi){function x(){var _this116;_classCallCheck(this,x);var e;_this116=_callSuper(this,x),_this116.getMessages=function(){return[];},_this116.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.");},_this116.addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.");},_this116.updateMessage=function(){},_this116.clearMessages=function(){},_this116.focusInput=function(){return gs.focusFromParentElement(_this116._elementRef);},_this116.refreshMessages=function(){},_this116.scrollToBottom=function(){},_this116.disableSubmitButton=function(){},_this116.setPlaceholderText=function(){},_this116._hasBeenRendered=!1,_this116._auxiliaryStyleApplied=!1,_this116._elementRef=document.createElement("div"),_this116._elementRef.id="container",_this116.attachShadow({mode:"open"}).appendChild(_this116._elementRef),(e=_this116.shadowRoot)==null||e.appendChild(_e.buildElement()),Yt.apply(gl,_this116.shadowRoot),setTimeout(function(){_this116._hasBeenRendered||_this116.onRender();},20);return _this116;}_inherits(x,_xi);return _createClass(x,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
305
|
-
},{key:"onRender",value:function onRender(){var _this$_childElement;
|
303
|
+
}],[{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),_Va$l=Va[l],u=_Va$l.id,h=_Va$l.svgString,f=_Va$l.dropupText,m=new Qs(n,d,c,u,h,f);o[l]={button:m,fileType:d};}});}// prettier-ignore
|
304
|
+
},{key:"addElements",value:function addElements(e,t,s,i,n,o){X.addElements(e,t.elementRef);var a=At.create(),l=Q.addButtons(a,s,i,o);Bi.set(t.inputElementRef,a,n.elementRef,l),At.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;})),ds.onInput(e,l,n);});};}}]);}();var Xi=/*#__PURE__*/function(){function Xi(){_classCallCheck(this,Xi);}return _createClass(Xi,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 vt(e,n,t,i);return X.addElements(i,n.elementRef,o.elementRef),i;}},{key:"render",value:function render(e,t,s,i){var n=Xi.createElements(e,s,i);t.replaceChildren(n),s.isCustomView()&&s.setUpView(n,t);}}]);}();var gl="#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 yl=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&&yl(e,t,i),i;};var x=/*#__PURE__*/function(_xi){function x(){var _this117;_classCallCheck(this,x);var e;_this117=_callSuper(this,x),_this117.getMessages=function(){return[];},_this117.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.");},_this117.addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.");},_this117.updateMessage=function(){},_this117.clearMessages=function(){},_this117.focusInput=function(){return gs.focusFromParentElement(_this117._elementRef);},_this117.refreshMessages=function(){},_this117.scrollToBottom=function(){},_this117.disableSubmitButton=function(){},_this117.setPlaceholderText=function(){},_this117._hasBeenRendered=!1,_this117._auxiliaryStyleApplied=!1,_this117._elementRef=document.createElement("div"),_this117._elementRef.id="container",_this117.attachShadow({mode:"open"}).appendChild(_this117._elementRef),(e=_this117.shadowRoot)==null||e.appendChild(_e.buildElement()),Yt.apply(gl,_this117.shadowRoot),setTimeout(function(){_this117._hasBeenRendered||_this117.onRender();},20);return _this117;}_inherits(x,_xi);return _createClass(x,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
305
|
+
},{key:"onRender",value:function onRender(){var _this$_childElement;Cs.attemptAppendStyleSheetToHead(this.style),Y.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=Na.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(Yt.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),Yt.applyDefaultStyleToComponent(this.style,this.chatStyle),Y.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?ws.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof M)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],Xi.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof M&&Z.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||ds.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){us.chat=void 0;}}]);}(xi);A([T("object")],x.prototype,"connect");A([T("object")],x.prototype,"directConnection");A([T("object")],x.prototype,"webModel");A([T("object")],x.prototype,"requestBodyLimits");A([T("function")],x.prototype,"requestInterceptor");A([T("function")],x.prototype,"responseInterceptor");A([T("function")],x.prototype,"validateInput");A([T("function")],x.prototype,"loadHistory");A([T("object")],x.prototype,"chatStyle");A([T("object")],x.prototype,"attachmentContainerStyle");A([T("object")],x.prototype,"dropupStyles");A([T("object")],x.prototype,"inputAreaStyle");A([T("object")],x.prototype,"textInput");A([T("object")],x.prototype,"submitButtonStyles");A([T("object")],x.prototype,"customButtons");A([T("string")],x.prototype,"auxiliaryStyle");A([T("array")],x.prototype,"history");A([T("object")],x.prototype,"browserStorage");A([T("object")],x.prototype,"introMessage");A([T("object")],x.prototype,"avatars");A([T("object")],x.prototype,"names");A([T("object")],x.prototype,"displayLoadingBubble");A([T("object")],x.prototype,"errorMessages");A([T("object")],x.prototype,"messageStyles");A([T("object")],x.prototype,"textToSpeech");A([T("object")],x.prototype,"speechToText");A([T("object")],x.prototype,"images");A([T("object")],x.prototype,"gifs");A([T("object")],x.prototype,"camera");A([T("object")],x.prototype,"audio");A([T("object")],x.prototype,"microphone");A([T("object")],x.prototype,"mixedFiles");A([T("object")],x.prototype,"dragAndDrop");A([T("object")],x.prototype,"introPanelStyle");A([T("object")],x.prototype,"htmlWrappers");A([T("object")],x.prototype,"htmlClassUtilities");A([T("object")],x.prototype,"remarkable");A([T("object")],x.prototype,"focusMode");A([T("function")],x.prototype,"onMessage");A([T("function")],x.prototype,"onClearMessages");A([T("function")],x.prototype,"onComponentRender");A([T("function")],x.prototype,"onInput");A([T("function")],x.prototype,"onError");A([T("object")],x.prototype,"demo");A([T("object")],x.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",x);export{x as DeepChat};
|