deep-chat-dev 9.0.370 → 9.0.371
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 +22178 -22422
- package/dist/deepChat.bundle.js +1 -1
- package/dist/deepChat.js +176 -176
- package/dist/services/openAI/openAIChatIO.d.ts +1 -0
- package/dist/services/openAI/openAIChatIO.d.ts.map +1 -1
- package/dist/types/webModel/webLLM/webLLM.d.ts +2 -2
- package/dist/types/webModel/webLLM/webLLM.d.ts.map +1 -1
- package/dist/types/webModel/webLLM/webLLMChatModule.d.ts +2 -20
- package/dist/types/webModel/webLLM/webLLMChatModule.d.ts.map +1 -1
- package/dist/types/webModel/webLLM/webLLMClient.d.ts +2 -42
- package/dist/types/webModel/webLLM/webLLMClient.d.ts.map +1 -1
- package/dist/types/webModel/webLLM/webLLMShared.d.ts +84 -38
- package/dist/types/webModel/webLLM/webLLMShared.d.ts.map +1 -1
- package/dist/types/webModel/webModel.d.ts +1 -1
- package/dist/types/webModel/webModel.d.ts.map +1 -1
- package/dist/webModel/webModel.d.ts +2 -1
- package/dist/webModel/webModel.d.ts.map +1 -1
- package/dist/webModel/webModelConfig.d.ts +25 -6
- package/dist/webModel/webModelConfig.d.ts.map +1 -1
- package/dist/webModel/webModelFiles.d.ts +10 -0
- package/dist/webModel/webModelFiles.d.ts.map +1 -0
- package/dist/webModel/webModelIntroMessage.d.ts +1 -1
- package/dist/webModel/webModelIntroMessage.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/deepChat.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
function _objectWithoutProperties(e,t){if(null==e)return{};var o,r,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r<n.length;r++)o=n[r],-1===t.indexOf(o)&&{}.propertyIsEnumerable.call(e,o)&&(i[o]=e[o]);}return i;}function _objectWithoutPropertiesLoose(r,e){if(null==r)return{};var t={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(-1!==e.indexOf(n))continue;t[n]=r[n];}return t;}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,F=function F(){};return{s:F,n:function(_n22){function n(){return _n22.apply(this,arguments);}n.toString=function(){return _n22.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _wrapNativeSuper(t){var r="function"==typeof Map?new Map():void 0;return _wrapNativeSuper=function _wrapNativeSuper(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,Wrapper);}function Wrapper(){return _construct(t,arguments,_getPrototypeOf(this).constructor);}return Wrapper.prototype=Object.create(t.prototype,{constructor:{value:Wrapper,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(Wrapper,t);},_wrapNativeSuper(t);}function _construct(t,e,r){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var p=new(t.bind.apply(t,o))();return r&&_setPrototypeOf(p,r.prototype),p;}function _isNativeFunction(t){try{return-1!==Function.toString.call(t).indexOf("[native code]");}catch(n){return"function"==typeof t;}}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof Generator?n:Generator,u=Object.create(c.prototype);return _regeneratorDefine2(u,"_invoke",function(r,n,o){var i,c,u,f=0,p=o||[],y=!1,G={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function d(t,r){return i=t,c=0,u=e,G.n=r,a;}};function d(r,n){for(c=r,u=n,t=0;!y&&f&&!o&&t<p.length;t++){var o,i=p[t],d=G.p,l=i[2];r>3?(o=l===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,G.v=n,G.n=i[1]):d<l&&(o=r<3||i[0]>n||n>l)&&(i[4]=r,i[5]=n,G.n=l,c=0));}if(o||r>1)return a;throw y=!0,n;}return function(o,p,l){if(f>1)throw TypeError("Generator is already running");for(y&&1===p&&d(p,l),c=p,u=l;(t=c<2?e:u)||!y;){i||(c?c<3?(c>1&&(G.n=-1),d(c,u)):G.n=u:G.v=u);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0);}else 1===c&&(t=i["return"])&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e;}else if((t=(y=G.n<0)?u:r.call(n,G))!==a)break;}catch(t){i=e,c=1,u=t;}finally{f=1;}}return{value:t,done:y};};}(r,o,i),!0),u;}var a={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(_regeneratorDefine2(t={},n,function(){return this;}),t),u=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,GeneratorFunctionPrototype):(e.__proto__=GeneratorFunctionPrototype,_regeneratorDefine2(e,o,"GeneratorFunction")),e.prototype=Object.create(u),e;}return GeneratorFunction.prototype=GeneratorFunctionPrototype,_regeneratorDefine2(u,"constructor",GeneratorFunctionPrototype),_regeneratorDefine2(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName="GeneratorFunction",_regeneratorDefine2(GeneratorFunctionPrototype,o,"GeneratorFunction"),_regeneratorDefine2(u),_regeneratorDefine2(u,o,"Generator"),_regeneratorDefine2(u,n,function(){return this;}),_regeneratorDefine2(u,"toString",function(){return"[object Generator]";}),(_regenerator=function _regenerator(){return{w:i,m:f};})();}function _regeneratorDefine2(e,r,n,t){var i=Object.defineProperty;try{i({},"",{});}catch(e){i=0;}_regeneratorDefine2=function _regeneratorDefine(e,r,n,t){function o(r,n){_regeneratorDefine2(e,r,function(e){return this._invoke(r,n,e);});}r?i?i(e,r,{value:n,enumerable:!t,configurable:!t,writable:!t}):e[r]=n:(o("next",0),o("throw",1),o("return",2));},_regeneratorDefine2(e,r,n,t);}function asyncGeneratorStep(n,t,e,r,o,a,c){try{var i=n[a](c),u=i.value;}catch(n){return void e(n);}i.done?t(u):Promise.resolve(u).then(r,o);}function _asyncToGenerator(n){return function(){var t=this,e=arguments;return new Promise(function(r,o){var a=n.apply(t,e);function _next(n){asyncGeneratorStep(a,r,o,_next,_throw,"next",n);}function _throw(n){asyncGeneratorStep(a,r,o,_next,_throw,"throw",n);}_next(void 0);});};}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e;}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1;}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r;}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return;}finally{if(o)throw n;}}return a;}}function _arrayWithHoles(r){if(Array.isArray(r))return r;}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}var f="classList",E="style",Ko="unset",Wo="html-wrapper",W="length",x=function x(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var Xo=/*#__PURE__*/function(){function Xo(){_classCallCheck(this,Xo);}return _createClass(Xo,null,[{key:"render",value:function render(e,t){var n=x();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var js=/*#__PURE__*/function(){function js(){_classCallCheck(this,js);}return _createClass(js,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=x();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=js.createElements(),r={onSuccess:t,onFail:Xo.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:js.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var oe="service",h="text",L="html",p="error",X="https://deepchat.dev/docs/",te="ai",F="user",St="assistant",$s="error-message-text",Rs="deep-chat-outer-container-role-",Mr="empty-message",Si="deep-chat-top-message",kr="deep-chat-middle-message",xi="deep-chat-bottom-message",T="src",y="type",ne="file",m="files",K="image",ee="images",Fe="camera",Bn="gifs",q="audio",pt="microphone",lo="mixedFiles",mn="any",ho="file-message",Jt="start",uo="end",po="messages",Lr="0",Pr="1",S="role",_e="string",ae=function ae(i){return JSON.stringify(i);},w=function w(i){return JSON.parse(ae(i));};function Nr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function Zo(i){return i&&ae(i);}function nr(i,e,t,n){var s="\n".concat(Nr(e)," message: ").concat(ae(i)," \n"),r=t?"".concat(Nr(e)," message after interceptor: ").concat(Zo(n)," \n"):"";return s+r;}function Yo(i,e,t,n){return"".concat(nr(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat(X,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat(X,"interceptors#responseInterceptor");}function Jo(i,e,t){var n="response";return"".concat(nr(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Qo(i,e){var t="request";return"".concat(nr(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function ea(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var On=Yo,ta=Qo,na=Jo,Br=ea,ue="Invalid API Key",He="Failed to connect",je="Request settings have not been set up",pi="No file was added",sr="Image was not found",fo="Multi-response arrays are not supported for streaming",mo="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat(X,"interceptors#responseInterceptor"),sa="Cannot mix {text: string} and {html: string} responses.",ia="No valid stream events were sent.\n".concat(mo),ra="Readable Stream connection error.",Qt="Please define a `function_handler` property inside the service config.",gn="Function tool response must be an array or contain a text property",go="Failed to fetch history";var Xt=/*#__PURE__*/function(){function Xt(){_classCallCheck(this,Xt);}return _createClass(Xt,null,[{key:"apply",value:function apply(e,t){if(t)try{Xt.applyStyleSheet(e,t);}catch(_unused){Xt.addStyleElement(e,t);}}},{key:"applyStyleSheet",value:function applyStyleSheet(e,t){var n=new CSSStyleSheet();n.replaceSync(e),t.adoptedStyleSheets.push(n);}},{key:"addStyleElement",value:function addStyleElement(e,t){var n=x("style");n.innerHTML=e,t.appendChild(n);}},{key:"camelToKebab",value:function camelToKebab(e){return e.replace(/[A-Z]/g,function(t){return"-".concat(t.toLowerCase());});}},{key:"applyChatStyle",value:function applyChatStyle(e,t){if(!e||!t)return;var n=Object.entries(e).filter(function(_ref){var _ref2=_slicedToArray(_ref,2),s=_ref2[1];return s;}).map(function(_ref3){var _ref4=_slicedToArray(_ref3,2),s=_ref4[0],r=_ref4[1];return"".concat(Xt.camelToKebab(s),": ").concat(r,";");}).join(" ");n&&Xt.apply(":host { ".concat(n," }"),t);}}]);}();var Hn="inside-start",_t="inside-end",Pe="outside-start",ve="outside-end",it="dropup-menu",A="default",De="hover",Y="click",j="active",$="disabled",G="svg",$t="unavailable",R="styles",As="mouseenter",bn="mouseleave",oa="mousedown",aa="mouseup",ct="submit",Ot="loading",Mi="stop",Zn="unsupported",Cn="commandMode";var de=/*#__PURE__*/function(){function de(){_classCallCheck(this,de);}return _createClass(de,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var n=Object.keys(t).reduce(function(s,r){return s[r]="",s;},{});Object.assign(e[E],n);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t[Y]&&de.unsetStyle(e,t[Y]),t[De]&&de.unsetStyle(e,t[De]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){de.unsetActivityCSSMouseStates(e,t),t[A]&&de.unsetStyle(e,t[A]);}// if you want to asdd default styling - use pure css classes
|
|
2
|
-
},{key:"processStateful",value:function processStateful(e){var t=e[A]||{},n=Object.assign(w(t),e==null?void 0:e[De]),s=Object.assign(w(n),e==null?void 0:e[
|
|
3
|
-
function add(e,t,n,s){n!==void 0&&e.addEventListener("keydown",
|
|
1
|
+
function _objectWithoutProperties(e,t){if(null==e)return{};var o,r,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r<n.length;r++)o=n[r],-1===t.indexOf(o)&&{}.propertyIsEnumerable.call(e,o)&&(i[o]=e[o]);}return i;}function _objectWithoutPropertiesLoose(r,e){if(null==r)return{};var t={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(-1!==e.indexOf(n))continue;t[n]=r[n];}return t;}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,F=function F(){};return{s:F,n:function(_n22){function n(){return _n22.apply(this,arguments);}n.toString=function(){return _n22.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _wrapNativeSuper(t){var r="function"==typeof Map?new Map():void 0;return _wrapNativeSuper=function _wrapNativeSuper(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,Wrapper);}function Wrapper(){return _construct(t,arguments,_getPrototypeOf(this).constructor);}return Wrapper.prototype=Object.create(t.prototype,{constructor:{value:Wrapper,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(Wrapper,t);},_wrapNativeSuper(t);}function _construct(t,e,r){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var p=new(t.bind.apply(t,o))();return r&&_setPrototypeOf(p,r.prototype),p;}function _isNativeFunction(t){try{return-1!==Function.toString.call(t).indexOf("[native code]");}catch(n){return"function"==typeof t;}}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof Generator?n:Generator,u=Object.create(c.prototype);return _regeneratorDefine2(u,"_invoke",function(r,n,o){var i,c,u,f=0,p=o||[],y=!1,G={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function d(t,r){return i=t,c=0,u=e,G.n=r,a;}};function d(r,n){for(c=r,u=n,t=0;!y&&f&&!o&&t<p.length;t++){var o,i=p[t],d=G.p,l=i[2];r>3?(o=l===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,G.v=n,G.n=i[1]):d<l&&(o=r<3||i[0]>n||n>l)&&(i[4]=r,i[5]=n,G.n=l,c=0));}if(o||r>1)return a;throw y=!0,n;}return function(o,p,l){if(f>1)throw TypeError("Generator is already running");for(y&&1===p&&d(p,l),c=p,u=l;(t=c<2?e:u)||!y;){i||(c?c<3?(c>1&&(G.n=-1),d(c,u)):G.n=u:G.v=u);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0);}else 1===c&&(t=i["return"])&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e;}else if((t=(y=G.n<0)?u:r.call(n,G))!==a)break;}catch(t){i=e,c=1,u=t;}finally{f=1;}}return{value:t,done:y};};}(r,o,i),!0),u;}var a={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(_regeneratorDefine2(t={},n,function(){return this;}),t),u=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,GeneratorFunctionPrototype):(e.__proto__=GeneratorFunctionPrototype,_regeneratorDefine2(e,o,"GeneratorFunction")),e.prototype=Object.create(u),e;}return GeneratorFunction.prototype=GeneratorFunctionPrototype,_regeneratorDefine2(u,"constructor",GeneratorFunctionPrototype),_regeneratorDefine2(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName="GeneratorFunction",_regeneratorDefine2(GeneratorFunctionPrototype,o,"GeneratorFunction"),_regeneratorDefine2(u),_regeneratorDefine2(u,o,"Generator"),_regeneratorDefine2(u,n,function(){return this;}),_regeneratorDefine2(u,"toString",function(){return"[object Generator]";}),(_regenerator=function _regenerator(){return{w:i,m:f};})();}function _regeneratorDefine2(e,r,n,t){var i=Object.defineProperty;try{i({},"",{});}catch(e){i=0;}_regeneratorDefine2=function _regeneratorDefine(e,r,n,t){function o(r,n){_regeneratorDefine2(e,r,function(e){return this._invoke(r,n,e);});}r?i?i(e,r,{value:n,enumerable:!t,configurable:!t,writable:!t}):e[r]=n:(o("next",0),o("throw",1),o("return",2));},_regeneratorDefine2(e,r,n,t);}function asyncGeneratorStep(n,t,e,r,o,a,c){try{var i=n[a](c),u=i.value;}catch(n){return void e(n);}i.done?t(u):Promise.resolve(u).then(r,o);}function _asyncToGenerator(n){return function(){var t=this,e=arguments;return new Promise(function(r,o){var a=n.apply(t,e);function _next(n){asyncGeneratorStep(a,r,o,_next,_throw,"next",n);}function _throw(n){asyncGeneratorStep(a,r,o,_next,_throw,"throw",n);}_next(void 0);});};}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e;}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1;}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r;}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return;}finally{if(o)throw n;}}return a;}}function _arrayWithHoles(r){if(Array.isArray(r))return r;}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}function _asyncIterator(r){var n,t,o,e=2;for("undefined"!=typeof Symbol&&(t=Symbol.asyncIterator,o=Symbol.iterator);e--;){if(t&&null!=(n=r[t]))return n.call(r);if(o&&null!=(n=r[o]))return new AsyncFromSyncIterator(n.call(r));t="@@asyncIterator",o="@@iterator";}throw new TypeError("Object is not async iterable");}function AsyncFromSyncIterator(r){function AsyncFromSyncIteratorContinuation(r){if(Object(r)!==r)return Promise.reject(new TypeError(r+" is not an object."));var n=r.done;return Promise.resolve(r.value).then(function(r){return{value:r,done:n};});}return AsyncFromSyncIterator=function AsyncFromSyncIterator(r){this.s=r,this.n=r.next;},AsyncFromSyncIterator.prototype={s:null,n:null,next:function next(){return AsyncFromSyncIteratorContinuation(this.n.apply(this.s,arguments));},"return":function _return(r){var n=this.s["return"];return void 0===n?Promise.resolve({value:r,done:!0}):AsyncFromSyncIteratorContinuation(n.apply(this.s,arguments));},"throw":function _throw(r){var n=this.s["return"];return void 0===n?Promise.reject(r):AsyncFromSyncIteratorContinuation(n.apply(this.s,arguments));}},new AsyncFromSyncIterator(r);}var f="classList",E="style",Wo="unset",Xo="html-wrapper",K="length",x=function x(){var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(r);};var Zo=/*#__PURE__*/function(){function Zo(){_classCallCheck(this,Zo);}return _createClass(Zo,null,[{key:"render",value:function render(e,t){var n=x();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var Gs=/*#__PURE__*/function(){function Gs(){_classCallCheck(this,Gs);}return _createClass(Gs,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=x();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=Gs.createElements(),i={onSuccess:t,onFail:Zo.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:Gs.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,i),e.replaceChildren(s);}}]);}();var oe="service",h="text",L="html",p="error",X="https://deepchat.dev/docs/",te="ai",F="user",xt="assistant",zs="error-message-text",Ms="deep-chat-outer-container-role-",Lr="empty-message",Ai="deep-chat-top-message",Pr="deep-chat-middle-message",wi="deep-chat-bottom-message",T="src",y="type",ne="file",m="files",W="image",Q="images",Fe="camera",Dn="gifs",G="audio",ft="microphone",ho="mixedFiles",gn="any",uo="file-message",Qt="start",po="end",fo="messages",Or="0",Nr="1",S="role",_e="string",ae=function ae(r){return JSON.stringify(r);},w=function w(r){return JSON.parse(ae(r));};function Br(r){return r.charAt(0).toUpperCase()+r.slice(1);}function Yo(r){return r&&ae(r);}function ir(r,e,t,n){var s="\n".concat(Br(e)," message: ").concat(ae(r)," \n"),i=t?"".concat(Br(e)," message after interceptor: ").concat(Yo(n)," \n"):"";return s+i;}function Jo(r,e,t,n){return"".concat(ir(r,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat(X,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat(X,"interceptors#responseInterceptor");}function Qo(r,e,t){var n="response";return"".concat(ir(r,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function ea(r,e){var t="request";return"".concat(ir(r,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function ta(r){return"".concat(r," failed - please wait for chat view to render before calling this property.");}var Fn=Jo,na=ea,sa=Qo,Dr=ta,ue="Invalid API Key",He="Failed to connect",$e="Request settings have not been set up",mi="No file was added",rr="Image was not found",mo="Multi-response arrays are not supported for streaming",go="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat(X,"interceptors#responseInterceptor"),ia="Cannot mix {text: string} and {html: string} responses.",ra="No valid stream events were sent.\n".concat(go),oa="Readable Stream connection error.",en="Please define a `function_handler` property inside the service config.",bn="Function tool response must be an array or contain a text property",bo="Failed to fetch history";var Zt=/*#__PURE__*/function(){function Zt(){_classCallCheck(this,Zt);}return _createClass(Zt,null,[{key:"apply",value:function apply(e,t){if(t)try{Zt.applyStyleSheet(e,t);}catch(_unused){Zt.addStyleElement(e,t);}}},{key:"applyStyleSheet",value:function applyStyleSheet(e,t){var n=new CSSStyleSheet();n.replaceSync(e),t.adoptedStyleSheets.push(n);}},{key:"addStyleElement",value:function addStyleElement(e,t){var n=x("style");n.innerHTML=e,t.appendChild(n);}},{key:"camelToKebab",value:function camelToKebab(e){return e.replace(/[A-Z]/g,function(t){return"-".concat(t.toLowerCase());});}},{key:"applyChatStyle",value:function applyChatStyle(e,t){if(!e||!t)return;var n=Object.entries(e).filter(function(_ref){var _ref2=_slicedToArray(_ref,2),s=_ref2[1];return s;}).map(function(_ref3){var _ref4=_slicedToArray(_ref3,2),s=_ref4[0],i=_ref4[1];return"".concat(Zt.camelToKebab(s),": ").concat(i,";");}).join(" ");n&&Zt.apply(":host { ".concat(n," }"),t);}}]);}();var jn="inside-start",vt="inside-end",Pe="outside-start",ve="outside-end",rt="dropup-menu",A="default",De="hover",Z="click",$="active",j="disabled",z="svg",Gt="unavailable",R="styles",Cs="mouseenter",yn="mouseleave",aa="mousedown",ca="mouseup",lt="submit",Dt="loading",Li="stop",Yn="unsupported",Tn="commandMode";var de=/*#__PURE__*/function(){function de(){_classCallCheck(this,de);}return _createClass(de,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var n=Object.keys(t).reduce(function(s,i){return s[i]="",s;},{});Object.assign(e[E],n);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t[Z]&&de.unsetStyle(e,t[Z]),t[De]&&de.unsetStyle(e,t[De]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){de.unsetActivityCSSMouseStates(e,t),t[A]&&de.unsetStyle(e,t[A]);}// if you want to asdd default styling - use pure css classes
|
|
2
|
+
},{key:"processStateful",value:function processStateful(e){var t=e[A]||{},n=Object.assign(w(t),e==null?void 0:e[De]),s=Object.assign(w(n),e==null?void 0:e[Z]);return _defineProperty(_defineProperty(_defineProperty({},A,t),De,n),Z,s);}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t=_defineProperty(_defineProperty(_defineProperty({},A,{}),De,{}),Z,{});return e.forEach(function(n){t[A]=Object.assign(t[A],n[A]),t[De]=Object.assign(t[De],n[De]),t[Z]=Object.assign(t[Z],n[Z]);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e[A]||[]).forEach(function(n){var i;var s=n;t[E][s]&&(i=e[A])!=null&&i[s]&&(e[A][n]=t[E][s]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var n in t){var s=t[n];e[n]===""&&s&&(e[n]=s);}}}]);}();var on=/*#__PURE__*/function(){function on(){_classCallCheck(this,on);}return _createClass(on,null,[{key:"buildElement",value:function buildElement(){var e=x();e[f].add("tooltip");var t=x("span");return t[f].add("tooltip-text"),e.appendChild(t),e;}},{key:"tryCreateConfig",value:function tryCreateConfig(e,t){if(t)return typeof t=="boolean"?_defineProperty({},h,e):_defineProperty(_defineProperty(_defineProperty({},h,t[h]||e),"timeout",t.timeout||0),"style",t[E]);}},{key:"traverseParentUntilContainer",value:function traverseParentUntilContainer(e){var t=e;for(;t.parentElement;)t=t.parentElement;return t;}},{key:"setPosition",value:function setPosition(e,t){var s=t.getRootNode().host.getBoundingClientRect(),i=e.getBoundingClientRect(),a=t.getBoundingClientRect().width/2,c=i.left+i.width/2;t[E].left="".concat(c-a-s.left,"px"),t[E].top="".concat(i.top-36-s.top,"px");var l=t.getBoundingClientRect();l.left<s.left?t[E].left="".concat(on.OVERFLOW_NEW_POSITION_PX,"px"):l.right>s.right&&(t[E].left="".concat(s.width-l.width-on.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,n){return n||(n=on.traverseParentUntilContainer(e).nextSibling),t[h]&&(n.children[0].textContent=t[h]),{timeout:setTimeout(function(){n[E].visibility="visible",on.setPosition(e,n),t[E]&&Object.assign(n[E],t[E]);},t.timeout||0),element:n};}},{key:"hide",value:function hide(e,t){clearTimeout(e.timeout),e.element[E].visibility="hidden",t[E]&&de.unsetStyle(e.element,t[E]),e.element[E].left="",e.element[E].top="";}}]);}();on.OVERFLOW_NEW_POSITION_PX=4;var yt=on;var os=/*#__PURE__*/_createClass(function os(){_classCallCheck(this,os);});os.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),os.IS_CHROMIUM=window.chrome,os.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var ze=os;var Ee=/* @__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;}(Ee||{});var an=/*#__PURE__*/function(){function an(){_classCallCheck(this,an);}return _createClass(an,null,[{key:"add",value:// prettier-ignore
|
|
3
|
+
function add(e,t,n,s){n!==void 0&&e.addEventListener("keydown",an.onKeyDown.bind(this,n)),e.oninput=an.onInput.bind(this,n,s),e.addEventListener("paste",function(i){var o;i.preventDefault(),(o=i.clipboardData)!=null&&o[m].length&&t.addFilesToAnyType(Array.from(i.clipboardData[m]));});}// preventing insertion early for a nicer UX
|
|
4
4
|
// prettier-ignore
|
|
5
|
-
},{key:"onKeyDown",value:function onKeyDown(e,t){var s=t.target.textContent;s&&s.length>=e&&!
|
|
6
|
-
function clear(){var t,n,s;var e=window.scrollY;this.inputElementRef[f].contains("text-input-".concat(
|
|
5
|
+
},{key:"onKeyDown",value:function onKeyDown(e,t){var s=t.target.textContent;s&&s.length>=e&&!an.PERMITTED_KEYS.has(t.key)&&!an.isKeyCombinationPermitted(t)&&t.preventDefault();}},{key:"isKeyCombinationPermitted",value:function isKeyCombinationPermitted(e){return e.key==="a"?e.ctrlKey||e.metaKey:!1;}},{key:"onInput",value:function onInput(e,t,n){var s=n.target,i=s.textContent||"";e!==void 0&&i.length>e&&(s.textContent=i.substring(0,e),En.focusEndOfInput(s)),t==null||t();}}]);}();an.PERMITTED_KEYS=/* @__PURE__ */new Set([Ee.BACKSPACE,Ee.DELETE,Ee.ARROW_RIGHT,Ee.ARROW_LEFT,Ee.ARROW_DOWN,Ee.ARROW_UP,Ee.META,Ee.CONTROL,Ee.ENTER]);var Pi=an;var la=/*#__PURE__*/function(){function la(){_classCallCheck(this,la);}return _createClass(la,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var s;e.preventDefault();var t=(s=e.clipboardData)==null?void 0:s.getData("text/plain");if(!t)return;var n=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br>");document.execCommand("insertHTML",!1,n);}}]);}();var zt=/*#__PURE__*/function(){function zt(e,t,n,s){var _this=this;_classCallCheck(this,zt);var o,a,c,l;this._isComposing=!1;var i=zt.processConfig(t,e.textInput);this.elementRef=zt.createContainerElement((o=i==null?void 0:i[R])==null?void 0:o.container),this._config=i,this.inputElementRef=this.createInputElement((a=e.defaultInput)==null?void 0:a[h],s),zt.addFilesToAnyType(n,(c=e.defaultInput)==null?void 0:c[m]),this.elementRef.appendChild(this.inputElementRef),e.setPlaceholderText=this.setPlaceholderText.bind(this),e.setPlaceholderText(((l=this._config.placeholder)==null?void 0:l[h])||"Ask me anything!"),this._browserStorage=s,setTimeout(function(){Pi.add(_this.inputElementRef,n,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(zt,[{key:"clear",value:// this also similarly prevents scroll up
|
|
6
|
+
function clear(){var t,n,s;var e=window.scrollY;this.inputElementRef[f].contains("text-input-".concat(j))||(Object.assign(this.inputElementRef[E],(t=this._config.placeholder)==null?void 0:t[E]),this.inputElementRef.textContent="",En.focusEndOfInput(this.inputElementRef),(n=this._onInput)==null||n.call(this,!1),(s=this._browserStorage)==null||s.addInputText("")),ze.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(e,t){var s,i,o,a;var n=x();return n.id=zt.TEXT_INPUT_ID,n[f].add("text-input-styling"),n[S]="textbox",typeof e=="string"?n.innerText=e:t!=null&&t.trackInputText&&(n.innerText=t.get().inputText||""),ze.IS_MOBILE&&n.setAttribute("tabindex","0"),ze.IS_CHROMIUM&&zt.preventAutomaticScrollUpOnNewLine(n),typeof this._config[j]=="boolean"&&this._config[j]===!0?(n.contentEditable="false",n[f].add("text-input-".concat(j)),n.setAttribute("aria-".concat(j),"true")):(n.contentEditable="true",n.removeAttribute("aria-".concat(j)),this.addEventListeners(n)),Object.assign(n[E],(s=this._config[R])==null?void 0:s[h]),Object.assign(n[E],(i=this._config.placeholder)==null?void 0:i[E]),(a=(o=this._config.placeholder)==null?void 0:o[E])!=null&&a.color||n.setAttribute("textcolor",""),n;}},{key:"removePlaceholderStyle",value:function removePlaceholderStyle(){var e,t,n,s;!this.inputElementRef[f].contains("text-input-".concat(j))&&(e=this._config.placeholder)!=null&&e[E]&&(de.unsetStyle(this.inputElementRef,(t=this._config.placeholder)==null?void 0:t[E]),Object.assign(this.inputElementRef[E],(s=(n=this._config)==null?void 0:n[R])==null?void 0:s[h]));}},{key:"addEventListeners",value:function addEventListeners(e){var _this2=this;var t,n;(t=this._config[R])!=null&&t.focus&&(e.onfocus=function(){var s;return Object.assign(_this2.elementRef[E],(s=_this2._config[R])==null?void 0:s.focus);},e.onblur=this.onBlur.bind(this,this._config[R].focus,(n=this._config[R])==null?void 0:n.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",la.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){de.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef[E],t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===Ee.ENTER&&!ze.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[E],(e=this._config.placeholder)==null?void 0:e[E]):this.removePlaceholderStyle(),(t=this._onInput)==null||t.call(this,!0);}},{key:"setPlaceholderText",value:function setPlaceholderText(e){this.inputElementRef.setAttribute("deep-chat-placeholder-text",e),this.inputElementRef.setAttribute("aria-label",e);}},{key:"isTextInputEmpty",value:function isTextInputEmpty(){return this.inputElementRef.textContent==="";}}],[{key:"processConfig",value:function processConfig(e,t){var _t$j,_t$placeholder,_n$h;var n;return t!==null&&t!==void 0?t:t={},(_t$j=t[j])!==null&&_t$j!==void 0?_t$j:t[j]=e.isTextInputDisabled,(_t$placeholder=t.placeholder)!==null&&_t$placeholder!==void 0?_t$placeholder:t.placeholder={},(_n$h=(n=t.placeholder)[h])!==null&&_n$h!==void 0?_n$h:n[h]=e.textInputPlaceholderText,t;}},{key:"createContainerElement",value:function createContainerElement(e){var t=x();return t.id="text-input-container",Object.assign(t[E],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
|
|
7
7
|
// the browser scrollbar will move up which leads to undesirable UX.
|
|
8
8
|
// More details in this Stack Overflow question:
|
|
9
9
|
// https://stackoverflow.com/questions/76285135/prevent-automatic-scroll-when-text-is-inserted-into-contenteditable-div
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
},{key:"preventAutomaticScrollUpOnNewLine",value:function preventAutomaticScrollUpOnNewLine(e){var t;e.addEventListener("keydown",function(){t=window.scrollY;}),e.addEventListener("input",function(){t!==window.scrollY&&window.scrollTo({top:t});});}},{key:"addFilesToAnyType",value:function addFilesToAnyType(e,t){t&&e.addFilesToAnyType(Array.from(t).map(function(n){return n;}));}}]);}();
|
|
12
|
-
},{key:"handleResponseProperty",value:function handleResponseProperty(e){return console[p]("The {result: ....} response object type".concat(nt,"1.3.0.")),console[p]("".concat(
|
|
13
|
-
},{key:"replaceElementWithNewClone",value:function replaceElementWithNewClone(e,t){var s;var n=(t||e).cloneNode(!0);return(s=e.parentNode)==null||s.replaceChild(n,e),n;}},{key:"tryAddWrapper",value:function tryAddWrapper(e,t,n,s){if(t&&s){var
|
|
14
|
-
},{key:"overwrite",value:function overwrite(e,t,n,s){var r=e.messageToElements,o=O.overwriteMessage(r,s,t,n,L,Gt.HTML_BUBBLE_CLASS);return o&&Gt.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var r=Gt.createElements(e,t,n,s);return O.fillEmptyMessageElement(r.bubbleElement,t),re.apply(e,r.outerContainer),ce.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,n,!1,(o=e.messageStyles)==null?void 0:o[L]),r;}},{key:"add",value:function add(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(s!=null&&s.status){var a=this.overwrite(e,t,n,e.messageElementRefs);if(a)return a;s.status=!1;}if(r&&e.messageElementRefs.length>0&&re.isTemporaryBasedOnHTML(t))return;var o=Gt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();Gt.HTML_BUBBLE_CLASS="html-message";var At=Gt;var pa=/*#__PURE__*/function(){function pa(){_classCallCheck(this,pa);}return _createClass(pa,null,[{key:"katex",value:function katex(e,t,n){var a=(n||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var c=function c(u,g){var b;return((b=window.katex)==null?void 0:b.renderToString(u,_objectSpread({displayMode:g,throwOnError:!1,output:"mathml"},e)))||"";},l=function l(u,g,b){var _=!1,v=u.bMarks[g]+u.tShift[g],C=u.eMarks[g];if(v+1>C)return!1;var B=u[T].charAt(v);if(B!==a)return!1;var se=v;v=u.skipChars(v,B);var fe=v-se;if(fe!==2)return!1;var ie=g;for(;++ie,!(ie>=b||(v=se=u.bMarks[ie]+u.tShift[ie],C=u.eMarks[ie],v<C&&u.tShift[ie]<u.blkIndent));)if(u[T].charAt(v)===a&&!(u.tShift[ie]-u.blkIndent>=4)&&(v=u.skipChars(v,B),!(v-se<fe)&&(v=u.skipSpaces(v),!(v<C)))){_=!0;break;}fe=u.tShift[g],u.line=ie+(_?1:0);var Re=u.getLines(g+1,ie,fe,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:Re,lines:[g,u.line],level:u.level,block:!0}),!0;},d=function d(u,g){var b=u.pos,_=u.posMax;var v=b;if(u[T].charAt(v)!==a)return!1;for(++v;v<_&&u[T].charAt(v)===a;)++v;var C=u[T].slice(b,v);if(C.length>2)return!1;var B=v;var se=0;for(;v<_;){var fe=u[T].charAt(v);if(fe==="{"&&(v===0||u[T].charAt(v-1)!=="\\"))se+=1;else if(fe==="}"&&(v===0||u[T].charAt(v-1)!=="\\")){if(se-=1,se<0)return!1;}else if(fe===a&&se===0){var ie=v;var Re=v+1;for(;Re<_&&u[T].charAt(Re)===a;)++Re;if(Re-ie===C.length){if(!g){var Ht=u[T].slice(B,ie).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:Ht,block:C.length>1,level:u.level});}return u.pos=Re,!0;}}v+=1;}return g||(u.pending+=C),u.pos+=C.length,!0;};t.inline.ruler.push("katex",d,n),t.block.ruler.push("katex",l,n),t.renderer.rules.katex=function(u,g){return c(u[g].content,u[g].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var Ms;function yo(i){return Ms=Ms||document.createElement("textarea"),Ms.innerHTML="&"+i+";",Ms.value;}var fa=Object.prototype.hasOwnProperty;function ma(i,e){return i?fa.call(i,e):!1;}function Eo(i){var e=[].slice.call(arguments,1);return e.forEach(function(t){if(t){if(_typeof(t)!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(n){i[n]=t[n];});}}),i;}var ga=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ps(i){return i.indexOf("\\")<0?i:i.replace(ga,"$1");}function _o(i){return!(i>=55296&&i<=57343||i>=64976&&i<=65007||(i&65535)===65535||(i&65535)===65534||i>=0&&i<=8||i===11||i>=14&&i<=31||i>=127&&i<=159||i>1114111);}function Ni(i){if(i>65535){i-=65536;var e=55296+(i>>10),t=56320+(i&1023);return String.fromCharCode(e,t);}return String.fromCharCode(i);}var ba=/&([a-z#][a-z0-9]{1,31});/gi,ya=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function Ea(i,e){var t=0,n=yo(e);return e!==n?n:e.charCodeAt(0)===35&&ya.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),_o(t))?Ni(t):i;}function En(i){return i.indexOf("&")<0?i:i.replace(ba,Ea);}var _a=/[&<>"]/,va=/[&<>"]/g,Sa={"&":"&","<":"<",">":">",'"':"""};function xa(i){return Sa[i];}function ze(i){return _a.test(i)?i.replace(va,xa):i;}var I={};I.blockquote_open=function(){return"<blockquote>\n";};I.blockquote_close=function(i,e){return"</blockquote>"+Sn(i,e);};I.code=function(i,e){return i[e].block?"<pre><code>"+ze(i[e].content)+"</code></pre>"+Sn(i,e):"<code>"+ze(i[e].content)+"</code>";};I.fence=function(i,e,t,n,s){var r=i[e],o="",a=t.langPrefix,c="",l,d,u;if(r.params){if(l=r.params.split(/\s+/g),d=l.join(" "),ma(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=ze(En(ps(d))),o=' class="'+a+c+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[r.content].concat(l))||ze(r.content):u=ze(r.content),"<pre><code"+o+">"+u+"</code></pre>"+Sn(i,e);};I.fence_custom={};I.heading_open=function(i,e){return"<h"+i[e].hLevel+">";};I.heading_close=function(i,e){return"</h"+i[e].hLevel+">\n";};I.hr=function(i,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+Sn(i,e);};I.bullet_list_open=function(){return"<ul>\n";};I.bullet_list_close=function(i,e){return"</ul>"+Sn(i,e);};I.list_item_open=function(){return"<li>";};I.list_item_close=function(){return"</li>\n";};I.ordered_list_open=function(i,e){var t=i[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};I.ordered_list_close=function(i,e){return"</ol>"+Sn(i,e);};I.paragraph_open=function(i,e){return i[e].tight?"":"<p>";};I.paragraph_close=function(i,e){var t=!(i[e].tight&&e&&i[e-1].type==="inline"&&!i[e-1].content);return(i[e].tight?"":"</p>")+(t?Sn(i,e):"");};I.link_open=function(i,e,t){var n=i[e].title?' title="'+ze(En(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+ze(i[e].href)+'"'+n+s+">";};I.link_close=function(){return"</a>";};I.image=function(i,e,t){var n=' src="'+ze(i[e].src)+'"',s=i[e].title?' title="'+ze(En(i[e].title))+'"':"",r=' alt="'+(i[e].alt?ze(En(ps(i[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+r+s+o+">";};I.table_open=function(){return"<table>\n";};I.table_close=function(){return"</table>\n";};I.thead_open=function(){return"<thead>\n";};I.thead_close=function(){return"</thead>\n";};I.tbody_open=function(){return"<tbody>\n";};I.tbody_close=function(){return"</tbody>\n";};I.tr_open=function(){return"<tr>";};I.tr_close=function(){return"</tr>\n";};I.th_open=function(i,e){var t=i[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.th_close=function(){return"</th>";};I.td_open=function(i,e){var t=i[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.td_close=function(){return"</td>";};I.strong_open=function(){return"<strong>";};I.strong_close=function(){return"</strong>";};I.em_open=function(){return"<em>";};I.em_close=function(){return"</em>";};I.del_open=function(){return"<del>";};I.del_close=function(){return"</del>";};I.ins_open=function(){return"<ins>";};I.ins_close=function(){return"</ins>";};I.mark_open=function(){return"<mark>";};I.mark_close=function(){return"</mark>";};I.sub=function(i,e){return"<sub>"+ze(i[e].content)+"</sub>";};I.sup=function(i,e){return"<sup>"+ze(i[e].content)+"</sup>";};I.hardbreak=function(i,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};I.softbreak=function(i,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};I.text=function(i,e){return ze(i[e].content);};I.htmlblock=function(i,e){return i[e].content;};I.htmltag=function(i,e){return i[e].content;};I.abbr_open=function(i,e){return'<abbr title="'+ze(En(i[e].title))+'">';};I.abbr_close=function(){return"</abbr>";};I.footnote_ref=function(i,e){var t=Number(i[e].id+1).toString(),n="fnref"+t;return i[e].subId>0&&(n+=":"+i[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+n+'">['+t+"]</a></sup>";};I.footnote_block_open=function(i,e,t){var n=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return n+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};I.footnote_block_close=function(){return"</ol>\n</section>\n";};I.footnote_open=function(i,e){var t=Number(i[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};I.footnote_close=function(){return"</li>\n";};I.footnote_anchor=function(i,e){var t=Number(i[e].id+1).toString(),n="fnref"+t;return i[e].subId>0&&(n+=":"+i[e].subId),' <a href="#'+n+'" class="footnote-backref">↩</a>';};I.dl_open=function(){return"<dl>\n";};I.dt_open=function(){return"<dt>";};I.dd_open=function(){return"<dd>";};I.dl_close=function(){return"</dl>\n";};I.dt_close=function(){return"</dt>\n";};I.dd_close=function(){return"</dd>\n";};function vo(i,e){return++e>=i.length-2?e:i[e].type==="paragraph_open"&&i[e].tight&&i[e+1].type==="inline"&&i[e+1].content.length===0&&i[e+2].type==="paragraph_close"&&i[e+2].tight?vo(i,e+2):e;}var Sn=I.getBreak=function(e,t){return t=vo(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function ar(){this.rules=Eo({},I),this.getBreak=I.getBreak;}ar.prototype.renderInline=function(i,e,t){for(var n=this.rules,s=i.length,r=0,o="";s--;)o+=n[i[r].type](i,r++,e,t,this);return o;};ar.prototype.render=function(i,e,t){for(var n=this.rules,s=i.length,r=-1,o="";++r<s;)i[r].type==="inline"?o+=this.renderInline(i[r].children,e,t):o+=n[i[r].type](i,r,e,t,this);return o;};function tt(){this.__rules__=[],this.__cache__=null;}tt.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};tt.prototype.__compile__=function(){var i=this,e=[""];i.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(n){e.indexOf(n)<0&&e.push(n);});}),i.__cache__={},e.forEach(function(t){i.__cache__[t]=[],i.__rules__.forEach(function(n){n.enabled&&(t&&n.alt.indexOf(t)<0||i.__cache__[t].push(n.fn));});});};tt.prototype.at=function(i,e,t){var n=this.__find__(i),s=t||{};if(n===-1)throw new Error("Parser rule not found: "+i);this.__rules__[n].fn=e,this.__rules__[n].alt=s.alt||[],this.__cache__=null;};tt.prototype.before=function(i,e,t,n){var s=this.__find__(i),r=n||{};if(s===-1)throw new Error("Parser rule not found: "+i);this.__rules__.splice(s,0,{name:e,enabled:!0,fn:t,alt:r.alt||[]}),this.__cache__=null;};tt.prototype.after=function(i,e,t,n){var s=this.__find__(i),r=n||{};if(s===-1)throw new Error("Parser rule not found: "+i);this.__rules__.splice(s+1,0,{name:e,enabled:!0,fn:t,alt:r.alt||[]}),this.__cache__=null;};tt.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};tt.prototype.enable=function(i,e){i=Array.isArray(i)?i:[i],e&&this.__rules__.forEach(function(t){t.enabled=!1;}),i.forEach(function(t){var n=this.__find__(t);if(n<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[n].enabled=!0;},this),this.__cache__=null;};tt.prototype.disable=function(i){i=Array.isArray(i)?i:[i],i.forEach(function(e){var t=this.__find__(e);if(t<0)throw new Error("Rules manager: invalid rule name "+e);this.__rules__[t].enabled=!1;},this),this.__cache__=null;};tt.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function Aa(i){i.inlineMode?i.tokens.push({type:"inline",content:i.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):i.block.parse(i.src,i.options,i.env,i.tokens);}function xn(i,e,t,n,s){this.src=i,this.env=n,this.options=t,this.parser=e,this.tokens=s,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0;}xn.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};xn.prototype.push=function(i){this.pending&&this.pushPending(),this.tokens.push(i),this.pendingLevel=this.level;};xn.prototype.cacheSet=function(i,e){for(var t=this.cache.length;t<=i;t++)this.cache.push(0);this.cache[i]=e;};xn.prototype.cacheGet=function(i){return i<this.cache.length?this.cache[i]:0;};function fs(i,e){var t,n,s,r=-1,o=i.posMax,a=i.pos,c=i.isInLabel;if(i.isInLabel)return-1;if(i.labelUnmatchedScopes)return i.labelUnmatchedScopes--,-1;for(i.pos=e+1,i.isInLabel=!0,t=1;i.pos<o;){if(s=i.src.charCodeAt(i.pos),s===91)t++;else if(s===93&&(t--,t===0)){n=!0;break;}i.parser.skipToken(i);}return n?(r=i.pos,i.labelUnmatchedScopes=0):i.labelUnmatchedScopes=t-1,i.pos=a,i.isInLabel=c,r;}function wa(i,e,t,n){var s,r,o,a,c,l;if(i.charCodeAt(0)!==42||i.charCodeAt(1)!==91||i.indexOf("]:")===-1||(s=new xn(i,e,t,n,[]),r=fs(s,1),r<0||i.charCodeAt(r+1)!==58))return-1;for(a=s.posMax,o=r+2;o<a&&s.src.charCodeAt(o)!==10;o++);return c=i.slice(2,r),l=i.slice(r+2,o).trim(),l.length===0?-1:(n.abbreviations||(n.abbreviations={}),_typeof(n.abbreviations[":"+c])>"u"&&(n.abbreviations[":"+c]=l),o);}function Ca(i){var e=i.tokens,t,n,s,r;if(!i.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(r=wa(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Bi(i){var e=En(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function So(i,e){var t,n,s,r=e,o=i.posMax;if(i.src.charCodeAt(e)===60){for(e++;e<o;){if(t=i.src.charCodeAt(e),t===10)return!1;if(t===62)return s=Bi(ps(i.src.slice(r+1,e))),i.parser.validateLink(s)?(i.pos=e+1,i.linkContent=s,!0):!1;if(t===92&&e+1<o){e+=2;continue;}e++;}return!1;}for(n=0;e<o&&(t=i.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue;}if(t===40&&(n++,n>1)||t===41&&(n--,n<0))break;e++;}return r===e||(s=ps(i.src.slice(r,e)),!i.parser.validateLink(s))?!1:(i.linkContent=s,i.pos=e,!0);}function xo(i,e){var t,n=e,s=i.posMax,r=i.src.charCodeAt(e);if(r!==34&&r!==39&&r!==40)return!1;for(e++,r===40&&(r=41);e<s;){if(t=i.src.charCodeAt(e),t===r)return i.pos=e+1,i.linkContent=ps(i.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function Ao(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function Ta(i,e,t,n){var s,r,o,a,c,l,d,u,g;if(i.charCodeAt(0)!==91||i.indexOf("]:")===-1||(s=new xn(i,e,t,n,[]),r=fs(s,0),r<0||i.charCodeAt(r+1)!==58))return-1;for(a=s.posMax,o=r+2;o<a&&(c=s.src.charCodeAt(o),!(c!==32&&c!==10));o++);if(!So(s,o))return-1;for(d=s.linkContent,o=s.pos,l=o,o=o+1;o<a&&(c=s.src.charCodeAt(o),!(c!==32&&c!==10));o++);for(o<a&&l!==o&&xo(s,o)?(u=s.linkContent,o=s.pos):(u="",o=l);o<a&&s.src.charCodeAt(o)===32;)o++;return o<a&&s.src.charCodeAt(o)!==10?-1:(g=Ao(i.slice(1,r)),_typeof(n.references[g])>"u"&&(n.references[g]={title:u,href:d}),o);}function Ra(i){var e=i.tokens,t,n,s,r;if(i.env.references=i.env.references||{},!i.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(r=Ta(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Ia(i){var e=i.tokens,t,n,s;for(n=0,s=e.length;n<s;n++)t=e[n],t.type==="inline"&&i.inline.parse(t.content,i.options,i.env,t.children);}function Ma(i){var e,t,n,s,r,o,a,c,l,d=0,u=!1,g={};if(i.env.footnotes&&(i.tokens=i.tokens.filter(function(b){return b.type==="footnote_reference_open"?(u=!0,c=[],l=b.label,!1):b.type==="footnote_reference_close"?(u=!1,g[":"+l]=c,!1):(u&&c.push(b),!u);}),!!i.env.footnotes.list)){for(o=i.env.footnotes.list,i.tokens.push({type:"footnote_block_open",level:d++}),e=0,t=o.length;e<t;e++){for(i.tokens.push({type:"footnote_open",id:e,level:d++}),o[e].tokens?(a=[],a.push({type:"paragraph_open",tight:!1,level:d++}),a.push({type:"inline",content:"",level:d,children:o[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--d})):o[e].label&&(a=g[":"+o[e].label]),i.tokens=i.tokens.concat(a),i.tokens[i.tokens.length-1].type==="paragraph_close"?r=i.tokens.pop():r=null,s=o[e].count>0?o[e].count:1,n=0;n<s;n++)i.tokens.push({type:"footnote_anchor",id:e,subId:n,level:d});r&&i.tokens.push(r),i.tokens.push({type:"footnote_close",level:--d});}i.tokens.push({type:"footnote_block_close",level:--d});}}var Ur=" \n()[]'\".,!?-";function Ai(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function ka(i){var e,t,n,s,r,o,a,c,l,d,u,g,b=i.tokens;if(i.env.abbreviations){for(i.env.abbrRegExp||(g="(^|["+Ur.split("").map(Ai).join("")+"])("+Object.keys(i.env.abbreviations).map(function(_){return _.substr(1);}).sort(function(_,v){return v.length-_.length;}).map(Ai).join("|")+")($|["+Ur.split("").map(Ai).join("")+"])",i.env.abbrRegExp=new RegExp(g,"g")),d=i.env.abbrRegExp,t=0,n=b.length;t<n;t++)if(b[t].type==="inline"){for(s=b[t].children,e=s.length-1;e>=0;e--)if(r=s[e],r.type==="text"){for(c=0,o=r.content,d.lastIndex=0,l=r.level,a=[];u=d.exec(o);)d.lastIndex>c&&a.push({type:"text",content:o.slice(c,u.index+u[1].length),level:l}),a.push({type:"abbr_open",title:i.env.abbreviations[":"+u[2]],level:l++}),a.push({type:"text",content:u[2],level:l}),a.push({type:"abbr_close",level:--l}),c=d.lastIndex-u[3].length;a.length&&(c<o.length&&a.push({type:"text",content:o.slice(c),level:l}),b[t].children=s=[].concat(s.slice(0,e),a,s.slice(e+1)));}}}}var La=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Pa=/\((c|tm|r|p)\)/ig,Na={c:"©",r:"®",p:"§",tm:"™"};function Ba(i){return i.indexOf("(")<0?i:i.replace(Pa,function(e,t){return Na[t.toLowerCase()];});}function Oa(i){var e,t,n,s,r;if(i.options.typographer){for(r=i.tokens.length-1;r>=0;r--)if(i.tokens[r].type==="inline")for(s=i.tokens[r].children,e=s.length-1;e>=0;e--)t=s[e],t.type==="text"&&(n=t.content,n=Ba(n),La.test(n)&&(n=n.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=n);}}var Da=/['"]/,Hr=/['"]/g,Fa=/[-\s()\[\]]/,jr="’";function $r(i,e){return e<0||e>=i.length?!1:!Fa.test(i[e]);}function Tn(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function Ua(i){var e,t,n,s,r,o,a,c,l,d,u,g,b,_,v,C,B;if(i.options.typographer){for(B=[],v=i.tokens.length-1;v>=0;v--)if(i.tokens[v].type==="inline"){for(C=i.tokens[v].children,B.length=0,e=0;e<C.length;e++)if(t=C[e],!(t.type!=="text"||Da.test(t.text))){for(a=C[e].level,b=B.length-1;b>=0&&!(B[b].level<=a);b--);B.length=b+1,n=t.content,r=0,o=n.length;e:for(;r<o&&(Hr.lastIndex=r,s=Hr.exec(n),!!s);){if(c=!$r(n,s.index-1),r=s.index+1,_=s[0]==="'",l=!$r(n,r),!l&&!c){_&&(t.content=Tn(t.content,s.index,jr));continue;}if(u=!l,g=!c,g){for(b=B.length-1;b>=0&&(d=B[b],!(B[b].level<a));b--)if(d.single===_&&B[b].level===a){d=B[b],_?(C[d.token].content=Tn(C[d.token].content,d.pos,i.options.quotes[2]),t.content=Tn(t.content,s.index,i.options.quotes[3])):(C[d.token].content=Tn(C[d.token].content,d.pos,i.options.quotes[0]),t.content=Tn(t.content,s.index,i.options.quotes[1])),B.length=b;continue e;}}u?B.push({token:e,pos:s.index,single:_,level:a}):g&&_&&(t.content=Tn(t.content,s.index,jr));}}}}}var wi=[["block",Aa],["abbr",Ca],["references",Ra],["inline",Ia],["footnote_tail",Ma],["abbr2",ka],["replacements",Oa],["smartquotes",Ua]];function wo(){this.options={},this.ruler=new tt();for(var i=0;i<wi.length;i++)this.ruler.push(wi[i][0],wi[i][1]);}wo.prototype.process=function(i){var e,t,n;for(n=this.ruler.getRules(""),e=0,t=n.length;e<t;e++)n[e](i);};function An(i,e,t,n,s){var r,o,a,c,l,d,u;for(this.src=i,this.parser=e,this.options=t,this.env=n,this.tokens=s,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,d=0,u=!1,a=c=d=0,l=o.length;c<l;c++){if(r=o.charCodeAt(c),!u)if(r===32){d++;continue;}else u=!0;(r===10||c===l-1)&&(r!==10&&c++,this.bMarks.push(a),this.eMarks.push(c),this.tShift.push(d),u=!1,d=0,a=c+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}An.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};An.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};An.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};An.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};An.prototype.skipCharsBack=function(e,t,n){if(e<=n)return e;for(;e>n;)if(t!==this.src.charCodeAt(--e))return e+1;return e;};An.prototype.getLines=function(e,t,n,s){var r,o,a,c,l,d=e;if(e>=t)return"";if(d+1===t)return o=this.bMarks[d]+Math.min(this.tShift[d],n),a=s?this.eMarks[d]+1:this.eMarks[d],this.src.slice(o,a);for(c=new Array(t-e),r=0;d<t;d++,r++)l=this.tShift[d],l>n&&(l=n),l<0&&(l=0),o=this.bMarks[d]+l,d+1<t||s?a=this.eMarks[d]+1:a=this.eMarks[d],c[r]=this.src.slice(o,a);return c.join("");};function Ha(i,e,t){var n,s;if(i.tShift[e]-i.blkIndent<4)return!1;for(s=n=e+1;n<t;){if(i.isEmpty(n)){n++;continue;}if(i.tShift[n]-i.blkIndent>=4){n++,s=n;continue;}break;}return i.line=n,i.tokens.push({type:"code",content:i.getLines(e,s,4+i.blkIndent,!0),block:!0,lines:[e,i.line],level:i.level}),!0;}function ja(i,e,t,n){var s,r,o,a,c,l=!1,d=i.bMarks[e]+i.tShift[e],u=i.eMarks[e];if(d+3>u||(s=i.src.charCodeAt(d),s!==126&&s!==96)||(c=d,d=i.skipChars(d,s),r=d-c,r<3)||(o=i.src.slice(d,u).trim(),o.indexOf("`")>=0))return!1;if(n)return!0;for(a=e;a++,!(a>=t||(d=c=i.bMarks[a]+i.tShift[a],u=i.eMarks[a],d<u&&i.tShift[a]<i.blkIndent));)if(i.src.charCodeAt(d)===s&&!(i.tShift[a]-i.blkIndent>=4)&&(d=i.skipChars(d,s),!(d-c<r)&&(d=i.skipSpaces(d),!(d<u)))){l=!0;break;}return r=i.tShift[e],i.line=a+(l?1:0),i.tokens.push({type:"fence",params:o,content:i.getLines(e+1,a,r,!0),lines:[e,i.line],level:i.level}),!0;}function $a(i,e,t,n){var s,r,o,a,c,l,d,u,g,b,_,v=i.bMarks[e]+i.tShift[e],C=i.eMarks[e];if(v>C||i.src.charCodeAt(v++)!==62||i.level>=i.options.maxNesting)return!1;if(n)return!0;for(i.src.charCodeAt(v)===32&&v++,c=i.blkIndent,i.blkIndent=0,a=[i.bMarks[e]],i.bMarks[e]=v,v=v<C?i.skipSpaces(v):v,r=v>=C,o=[i.tShift[e]],i.tShift[e]=v-i.bMarks[e],u=i.parser.ruler.getRules("blockquote"),s=e+1;s<t&&(v=i.bMarks[s]+i.tShift[s],C=i.eMarks[s],!(v>=C));s++){if(i.src.charCodeAt(v++)===62){i.src.charCodeAt(v)===32&&v++,a.push(i.bMarks[s]),i.bMarks[s]=v,v=v<C?i.skipSpaces(v):v,r=v>=C,o.push(i.tShift[s]),i.tShift[s]=v-i.bMarks[s];continue;}if(r)break;for(_=!1,g=0,b=u.length;g<b;g++)if(u[g](i,s,t,!0)){_=!0;break;}if(_)break;a.push(i.bMarks[s]),o.push(i.tShift[s]),i.tShift[s]=-1337;}for(l=i.parentType,i.parentType="blockquote",i.tokens.push({type:"blockquote_open",lines:d=[e,0],level:i.level++}),i.parser.tokenize(i,e,s),i.tokens.push({type:"blockquote_close",level:--i.level}),i.parentType=l,d[1]=i.line,g=0;g<o.length;g++)i.bMarks[g+e]=a[g],i.tShift[g+e]=o[g];return i.blkIndent=c,!0;}function qa(i,e,t,n){var s,r,o,a=i.bMarks[e],c=i.eMarks[e];if(a+=i.tShift[e],a>c||(s=i.src.charCodeAt(a++),s!==42&&s!==45&&s!==95))return!1;for(r=1;a<c;){if(o=i.src.charCodeAt(a++),o!==s&&o!==32)return!1;o===s&&r++;}return r<3?!1:(n||(i.line=e+1,i.tokens.push({type:"hr",lines:[e,i.line],level:i.level})),!0);}function qr(i,e){var t,n,s;return n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e],n>=s||(t=i.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<s&&i.src.charCodeAt(n)!==32?-1:n;}function Gr(i,e){var t,n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e];if(n+1>=s||(t=i.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=s)return-1;if(t=i.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return n<s&&i.src.charCodeAt(n)!==32?-1:n;}function Ga(i,e){var t,n,s=i.level+2;for(t=e+2,n=i.tokens.length-2;t<n;t++)i.tokens[t].level===s&&i.tokens[t].type==="paragraph_open"&&(i.tokens[t+2].tight=!0,i.tokens[t].tight=!0,t+=2);}function Va(i,e,t,n){var s,r,o,a,c,l,d,u,g,b,_,v,C,B,se,fe,ie,Re,Ht=!0,jt,Ke,Ir,vi;if((u=Gr(i,e))>=0)C=!0;else if((u=qr(i,e))>=0)C=!1;else return!1;if(i.level>=i.options.maxNesting)return!1;if(v=i.src.charCodeAt(u-1),n)return!0;for(se=i.tokens.length,C?(d=i.bMarks[e]+i.tShift[e],_=Number(i.src.substr(d,u-d-1)),i.tokens.push({type:"ordered_list_open",order:_,lines:ie=[e,0],level:i.level++})):i.tokens.push({type:"bullet_list_open",lines:ie=[e,0],level:i.level++}),s=e,fe=!1,jt=i.parser.ruler.getRules("list");s<t&&(B=i.skipSpaces(u),g=i.eMarks[s],B>=g?b=1:b=B-u,b>4&&(b=1),b<1&&(b=1),r=u-i.bMarks[s]+b,i.tokens.push({type:"list_item_open",lines:Re=[e,0],level:i.level++}),a=i.blkIndent,c=i.tight,o=i.tShift[e],l=i.parentType,i.tShift[e]=B-i.bMarks[e],i.blkIndent=r,i.tight=!0,i.parentType="list",i.parser.tokenize(i,e,t,!0),(!i.tight||fe)&&(Ht=!1),fe=i.line-e>1&&i.isEmpty(i.line-1),i.blkIndent=a,i.tShift[e]=o,i.tight=c,i.parentType=l,i.tokens.push({type:"list_item_close",level:--i.level}),s=e=i.line,Re[1]=s,B=i.bMarks[e],!(s>=t||i.isEmpty(s)||i.tShift[s]<i.blkIndent));){for(vi=!1,Ke=0,Ir=jt.length;Ke<Ir;Ke++)if(jt[Ke](i,s,t,!0)){vi=!0;break;}if(vi)break;if(C){if(u=Gr(i,s),u<0)break;}else if(u=qr(i,s),u<0)break;if(v!==i.src.charCodeAt(u-1))break;}return i.tokens.push({type:C?"ordered_list_close":"bullet_list_close",level:--i.level}),ie[1]=s,i.line=s,Ht&&Ga(i,se),!0;}function za(i,e,t,n){var s,r,o,a,c,l=i.bMarks[e]+i.tShift[e],d=i.eMarks[e];if(l+4>d||i.src.charCodeAt(l)!==91||i.src.charCodeAt(l+1)!==94||i.level>=i.options.maxNesting)return!1;for(a=l+2;a<d;a++){if(i.src.charCodeAt(a)===32)return!1;if(i.src.charCodeAt(a)===93)break;}return a===l+2||a+1>=d||i.src.charCodeAt(++a)!==58?!1:(n||(a++,i.env.footnotes||(i.env.footnotes={}),i.env.footnotes.refs||(i.env.footnotes.refs={}),c=i.src.slice(l+2,a-2),i.env.footnotes.refs[":"+c]=-1,i.tokens.push({type:"footnote_reference_open",label:c,level:i.level++}),s=i.bMarks[e],r=i.tShift[e],o=i.parentType,i.tShift[e]=i.skipSpaces(a)-a,i.bMarks[e]=a,i.blkIndent+=4,i.parentType="footnote",i.tShift[e]<i.blkIndent&&(i.tShift[e]+=i.blkIndent,i.bMarks[e]-=i.blkIndent),i.parser.tokenize(i,e,t,!0),i.parentType=o,i.blkIndent-=4,i.tShift[e]=r,i.bMarks[e]=s,i.tokens.push({type:"footnote_reference_close",level:--i.level})),!0);}function Ka(i,e,t,n){var s,r,o,a=i.bMarks[e]+i.tShift[e],c=i.eMarks[e];if(a>=c||(s=i.src.charCodeAt(a),s!==35||a>=c))return!1;for(r=1,s=i.src.charCodeAt(++a);s===35&&a<c&&r<=6;)r++,s=i.src.charCodeAt(++a);return r>6||a<c&&s!==32?!1:(n||(c=i.skipCharsBack(c,32,a),o=i.skipCharsBack(c,35,a),o>a&&i.src.charCodeAt(o-1)===32&&(c=o),i.line=e+1,i.tokens.push({type:"heading_open",hLevel:r,lines:[e,i.line],level:i.level}),a<c&&i.tokens.push({type:"inline",content:i.src.slice(a,c).trim(),level:i.level+1,lines:[e,i.line],children:[]}),i.tokens.push({type:"heading_close",hLevel:r,level:i.level})),!0);}function Wa(i,e,t){var n,s,r,o=e+1;return o>=t||i.tShift[o]<i.blkIndent||i.tShift[o]-i.blkIndent>3||(s=i.bMarks[o]+i.tShift[o],r=i.eMarks[o],s>=r)||(n=i.src.charCodeAt(s),n!==45&&n!==61)||(s=i.skipChars(s,n),s=i.skipSpaces(s),s<r)?!1:(s=i.bMarks[e]+i.tShift[e],i.line=o+1,i.tokens.push({type:"heading_open",hLevel:n===61?1:2,lines:[e,i.line],level:i.level}),i.tokens.push({type:"inline",content:i.src.slice(s,i.eMarks[e]).trim(),level:i.level+1,lines:[e,i.line-1],children:[]}),i.tokens.push({type:"heading_close",hLevel:n===61?1:2,level:i.level}),!0);}var Co={};["article","aside","button","blockquote","body","canvas","caption","col","colgroup","dd","div","dl","dt","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","iframe","li","map","object","ol","output","p","pre","progress","script","section","style","table","tbody","td","textarea","tfoot","th","tr","thead","ul","video"].forEach(function(i){Co[i]=!0;});var Xa=/^<([a-zA-Z]{1,15})[\s\/>]/,Za=/^<\/([a-zA-Z]{1,15})[\s>]/;function Ya(i){var e=i|32;return e>=97&&e<=122;}function Ja(i,e,t,n){var s,r,o,a=i.bMarks[e],c=i.eMarks[e],l=i.tShift[e];if(a+=l,!i.options.html||l>3||a+2>=c||i.src.charCodeAt(a)!==60)return!1;if(s=i.src.charCodeAt(a+1),s===33||s===63){if(n)return!0;}else if(s===47||Ya(s)){if(s===47){if(r=i.src.slice(a,c).match(Za),!r)return!1;}else if(r=i.src.slice(a,c).match(Xa),!r)return!1;if(Co[r[1].toLowerCase()]!==!0)return!1;if(n)return!0;}else return!1;for(o=e+1;o<i.lineMax&&!i.isEmpty(o);)o++;return i.line=o,i.tokens.push({type:"htmlblock",level:i.level,lines:[e,i.line],content:i.getLines(e,o,0,!0)}),!0;}function Ci(i,e){var t=i.bMarks[e]+i.blkIndent,n=i.eMarks[e];return i.src.substr(t,n-t);}function Qa(i,e,t,n){var s,r,o,a,c,l,d,u,g,b,_;if(e+2>t||(c=e+1,i.tShift[c]<i.blkIndent)||(o=i.bMarks[c]+i.tShift[c],o>=i.eMarks[c])||(s=i.src.charCodeAt(o),s!==124&&s!==45&&s!==58)||(r=Ci(i,e+1),!/^[-:| ]+$/.test(r))||(l=r.split("|"),l<=2))return!1;for(u=[],a=0;a<l.length;a++){if(g=l[a].trim(),!g){if(a===0||a===l.length-1)continue;return!1;}if(!/^:?-+:?$/.test(g))return!1;g.charCodeAt(g.length-1)===58?u.push(g.charCodeAt(0)===58?"center":"right"):g.charCodeAt(0)===58?u.push("left"):u.push("");}if(r=Ci(i,e).trim(),r.indexOf("|")===-1||(l=r.replace(/^\||\|$/g,"").split("|"),u.length!==l.length))return!1;if(n)return!0;for(i.tokens.push({type:"table_open",lines:b=[e,0],level:i.level++}),i.tokens.push({type:"thead_open",lines:[e,e+1],level:i.level++}),i.tokens.push({type:"tr_open",lines:[e,e+1],level:i.level++}),a=0;a<l.length;a++)i.tokens.push({type:"th_open",align:u[a],lines:[e,e+1],level:i.level++}),i.tokens.push({type:"inline",content:l[a].trim(),lines:[e,e+1],level:i.level,children:[]}),i.tokens.push({type:"th_close",level:--i.level});for(i.tokens.push({type:"tr_close",level:--i.level}),i.tokens.push({type:"thead_close",level:--i.level}),i.tokens.push({type:"tbody_open",lines:_=[e+2,0],level:i.level++}),c=e+2;c<t&&!(i.tShift[c]<i.blkIndent||(r=Ci(i,c).trim(),r.indexOf("|")===-1));c++){for(l=r.replace(/^\||\|$/g,"").split("|"),i.tokens.push({type:"tr_open",level:i.level++}),a=0;a<l.length;a++)i.tokens.push({type:"td_open",align:u[a],level:i.level++}),d=l[a].substring(l[a].charCodeAt(0)===124?1:0,l[a].charCodeAt(l[a].length-1)===124?l[a].length-1:l[a].length).trim(),i.tokens.push({type:"inline",content:d,level:i.level,children:[]}),i.tokens.push({type:"td_close",level:--i.level});i.tokens.push({type:"tr_close",level:--i.level});}return i.tokens.push({type:"tbody_close",level:--i.level}),i.tokens.push({type:"table_close",level:--i.level}),b[1]=_[1]=c,i.line=c,!0;}function ks(i,e){var t,n,s=i.bMarks[e]+i.tShift[e],r=i.eMarks[e];return s>=r||(n=i.src.charCodeAt(s++),n!==126&&n!==58)||(t=i.skipSpaces(s),s===t)||t>=r?-1:t;}function ec(i,e){var t,n,s=i.level+2;for(t=e+2,n=i.tokens.length-2;t<n;t++)i.tokens[t].level===s&&i.tokens[t].type==="paragraph_open"&&(i.tokens[t+2].tight=!0,i.tokens[t].tight=!0,t+=2);}function tc(i,e,t,n){var s,r,o,a,c,l,d,u,g,b,_,v,C,B;if(n)return i.ddIndent<0?!1:ks(i,e)>=0;if(d=e+1,i.isEmpty(d)&&++d>t||i.tShift[d]<i.blkIndent||(s=ks(i,d),s<0)||i.level>=i.options.maxNesting)return!1;l=i.tokens.length,i.tokens.push({type:"dl_open",lines:c=[e,0],level:i.level++}),o=e,r=d;e:for(;;){for(B=!0,C=!1,i.tokens.push({type:"dt_open",lines:[o,o],level:i.level++}),i.tokens.push({type:"inline",content:i.getLines(o,o+1,i.blkIndent,!1).trim(),level:i.level+1,lines:[o,o],children:[]}),i.tokens.push({type:"dt_close",level:--i.level});;){if(i.tokens.push({type:"dd_open",lines:a=[d,0],level:i.level++}),v=i.tight,g=i.ddIndent,u=i.blkIndent,_=i.tShift[r],b=i.parentType,i.blkIndent=i.ddIndent=i.tShift[r]+2,i.tShift[r]=s-i.bMarks[r],i.tight=!0,i.parentType="deflist",i.parser.tokenize(i,r,t,!0),(!i.tight||C)&&(B=!1),C=i.line-r>1&&i.isEmpty(i.line-1),i.tShift[r]=_,i.tight=v,i.parentType=b,i.blkIndent=u,i.ddIndent=g,i.tokens.push({type:"dd_close",level:--i.level}),a[1]=d=i.line,d>=t||i.tShift[d]<i.blkIndent)break e;if(s=ks(i,d),s<0)break;r=d;}if(d>=t||(o=d,i.isEmpty(o))||i.tShift[o]<i.blkIndent||(r=o+1,r>=t)||(i.isEmpty(r)&&r++,r>=t)||i.tShift[r]<i.blkIndent||(s=ks(i,r),s<0))break;}return i.tokens.push({type:"dl_close",level:--i.level}),c[1]=d,i.line=d,B&&ec(i,l),!0;}function nc(i,e){var t,n,s,r,o,a=e+1,c;if(t=i.lineMax,a<t&&!i.isEmpty(a)){for(c=i.parser.ruler.getRules("paragraph");a<t&&!i.isEmpty(a);a++)if(!(i.tShift[a]-i.blkIndent>3)){for(s=!1,r=0,o=c.length;r<o;r++)if(c[r](i,a,t,!0)){s=!0;break;}if(s)break;}}return n=i.getLines(e,a,i.blkIndent,!1).trim(),i.line=a,n.length&&(i.tokens.push({type:"paragraph_open",tight:!1,lines:[e,i.line],level:i.level}),i.tokens.push({type:"inline",content:n,level:i.level+1,lines:[e,i.line],children:[]}),i.tokens.push({type:"paragraph_close",tight:!1,level:i.level})),!0;}var Ls=[["code",Ha],["fences",ja,["paragraph","blockquote","list"]],["blockquote",$a,["paragraph","blockquote","list"]],["hr",qa,["paragraph","blockquote","list"]],["list",Va,["paragraph","blockquote"]],["footnote",za,["paragraph"]],["heading",Ka,["paragraph","blockquote"]],["lheading",Wa],["htmlblock",Ja,["paragraph","blockquote"]],["table",Qa,["paragraph"]],["deflist",tc,["paragraph"]],["paragraph",nc]];function cr(){this.ruler=new tt();for(var i=0;i<Ls.length;i++)this.ruler.push(Ls[i][0],Ls[i][1],{alt:(Ls[i][2]||[]).slice()});}cr.prototype.tokenize=function(i,e,t){for(var n=this.ruler.getRules(""),s=n.length,r=e,o=!1,a,c;r<t&&(i.line=r=i.skipEmptyLines(r),!(r>=t||i.tShift[r]<i.blkIndent));){for(c=0;c<s&&(a=n[c](i,r,t,!1),!a);c++);if(i.tight=!o,i.isEmpty(i.line-1)&&(o=!0),r=i.line,r<t&&i.isEmpty(r)){if(o=!0,r++,r<t&&i.parentType==="list"&&i.isEmpty(r))break;i.line=r;}}};var sc=/[\n\t]/g,ic=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,rc=/\u00a0/g;cr.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(rc," "),i=i.replace(ic,"\n"),i.indexOf(" ")>=0&&(i=i.replace(sc,function(a,c){var l;return i.charCodeAt(c)===10?(r=c+1,o=0,a):(l=" ".slice((c-r-o)%4),o=c-r+1,l);})),s=new An(i,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function oc(i){switch(i){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1;}}function ac(i,e){for(var t=i.pos;t<i.posMax&&!oc(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function cc(i,e){var t,n,s=i.pos;if(i.src.charCodeAt(s)!==10)return!1;if(t=i.pending.length-1,n=i.posMax,!e)if(t>=0&&i.pending.charCodeAt(t)===32){if(t>=1&&i.pending.charCodeAt(t-1)===32){for(var r=t-2;r>=0;r--)if(i.pending.charCodeAt(r)!==32){i.pending=i.pending.substring(0,r+1);break;}i.push({type:"hardbreak",level:i.level});}else i.pending=i.pending.slice(0,-1),i.push({type:"softbreak",level:i.level});}else i.push({type:"softbreak",level:i.level});for(s++;s<n&&i.src.charCodeAt(s)===32;)s++;return i.pos=s,!0;}var lr=[];for(var Vr=0;Vr<256;Vr++)lr.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){lr[i.charCodeAt(0)]=1;});function lc(i,e){var t,n=i.pos,s=i.posMax;if(i.src.charCodeAt(n)!==92)return!1;if(n++,n<s){if(t=i.src.charCodeAt(n),t<256&&lr[t]!==0)return e||(i.pending+=i.src[n]),i.pos+=2,!0;if(t===10){for(e||i.push({type:"hardbreak",level:i.level}),n++;n<s&&i.src.charCodeAt(n)===32;)n++;return i.pos=n,!0;}}return e||(i.pending+="\\"),i.pos++,!0;}function hc(i,e){var t,n,s,r,o,a=i.pos,c=i.src.charCodeAt(a);if(c!==96)return!1;for(t=a,a++,n=i.posMax;a<n&&i.src.charCodeAt(a)===96;)a++;for(s=i.src.slice(t,a),r=o=a;(r=i.src.indexOf("`",o))!==-1;){for(o=r+1;o<n&&i.src.charCodeAt(o)===96;)o++;if(o-r===s.length)return e||i.push({type:"code",content:i.src.slice(a,r).replace(/[ \n]+/g," ").trim(),block:!1,level:i.level}),i.pos=o,!0;}return e||(i.pending+=s),i.pos+=s.length,!0;}function dc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==126||e||o+4>=r||i.src.charCodeAt(o+1)!==126||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===126)||c===126||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===126;)n++;if(n>o+3)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===126&&i.src.charCodeAt(i.pos+1)===126&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==126&&a!==126&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"del_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"del_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function uc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==43||e||o+4>=r||i.src.charCodeAt(o+1)!==43||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===43)||c===43||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===43;)n++;if(n!==o+2)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===43&&i.src.charCodeAt(i.pos+1)===43&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==43&&a!==43&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"ins_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"ins_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function pc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==61||e||o+4>=r||i.src.charCodeAt(o+1)!==61||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===61)||c===61||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===61;)n++;if(n!==o+2)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===61&&i.src.charCodeAt(i.pos+1)===61&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==61&&a!==61&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"mark_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"mark_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function zr(i){return i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122;}function Kr(i,e){var t=e,n,s,r,o=!0,a=!0,c=i.posMax,l=i.src.charCodeAt(e);for(n=e>0?i.src.charCodeAt(e-1):-1;t<c&&i.src.charCodeAt(t)===l;)t++;return t>=c&&(o=!1),r=t-e,r>=4?o=a=!1:(s=t<c?i.src.charCodeAt(t):-1,(s===32||s===10)&&(o=!1),(n===32||n===10)&&(a=!1),l===95&&(zr(n)&&(o=!1),zr(s)&&(a=!1))),{can_open:o,can_close:a,delims:r};}function fc(i,e){var t,n,s,r,o,a,c,l=i.posMax,d=i.pos,u=i.src.charCodeAt(d);if(u!==95&&u!==42||e)return!1;if(c=Kr(i,d),t=c.delims,!c.can_open)return i.pos+=t,e||(i.pending+=i.src.slice(d,i.pos)),!0;if(i.level>=i.options.maxNesting)return!1;for(i.pos=d+t,a=[t];i.pos<l;){if(i.src.charCodeAt(i.pos)===u){if(c=Kr(i,i.pos),n=c.delims,c.can_close){for(r=a.pop(),o=n;r!==o;){if(o<r){a.push(r-o);break;}if(o-=r,a.length===0)break;i.pos+=r,r=a.pop();}if(a.length===0){t=r,s=!0;break;}i.pos+=n;continue;}c.can_open&&a.push(n),i.pos+=n;continue;}i.parser.skipToken(i);}return s?(i.posMax=i.pos,i.pos=d+t,e||((t===2||t===3)&&i.push({type:"strong_open",level:i.level++}),(t===1||t===3)&&i.push({type:"em_open",level:i.level++}),i.parser.tokenize(i),(t===1||t===3)&&i.push({type:"em_close",level:--i.level}),(t===2||t===3)&&i.push({type:"strong_close",level:--i.level})),i.pos=i.posMax+t,i.posMax=l,!0):(i.pos=d,!1);}var mc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function gc(i,e){var t,n,s=i.posMax,r=i.pos;if(i.src.charCodeAt(r)!==126||e||r+2>=s||i.level>=i.options.maxNesting)return!1;for(i.pos=r+1;i.pos<s;){if(i.src.charCodeAt(i.pos)===126){t=!0;break;}i.parser.skipToken(i);}return!t||r+1===i.pos||(n=i.src.slice(r+1,i.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(i.pos=r,!1):(i.posMax=i.pos,i.pos=r+1,e||i.push({type:"sub",level:i.level,content:n.replace(mc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var bc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function yc(i,e){var t,n,s=i.posMax,r=i.pos;if(i.src.charCodeAt(r)!==94||e||r+2>=s||i.level>=i.options.maxNesting)return!1;for(i.pos=r+1;i.pos<s;){if(i.src.charCodeAt(i.pos)===94){t=!0;break;}i.parser.skipToken(i);}return!t||r+1===i.pos||(n=i.src.slice(r+1,i.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(i.pos=r,!1):(i.posMax=i.pos,i.pos=r+1,e||i.push({type:"sup",level:i.level,content:n.replace(bc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function Ec(i,e){var t,n,s,r,o,a,c,l,d=!1,u=i.pos,g=i.posMax,b=i.pos,_=i.src.charCodeAt(b);if(_===33&&(d=!0,_=i.src.charCodeAt(++b)),_!==91||i.level>=i.options.maxNesting||(t=b+1,n=fs(i,b),n<0))return!1;if(a=n+1,a<g&&i.src.charCodeAt(a)===40){for(a++;a<g&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a>=g)return!1;for(b=a,So(i,a)?(r=i.linkContent,a=i.pos):r="",b=a;a<g&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<g&&b!==a&&xo(i,a))for(o=i.linkContent,a=i.pos;a<g&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);else o="";if(a>=g||i.src.charCodeAt(a)!==41)return i.pos=u,!1;a++;}else{if(i.linkLevel>0)return!1;for(;a<g&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<g&&i.src.charCodeAt(a)===91&&(b=a+1,a=fs(i,a),a>=0?s=i.src.slice(b,a++):a=b-1),s||(_typeof(s)>"u"&&(a=n+1),s=i.src.slice(t,n)),c=i.env.references[Ao(s)],!c)return i.pos=u,!1;r=c.href,o=c.title;}return e||(i.pos=t,i.posMax=n,d?i.push({type:"image",src:r,title:o,alt:i.src.substr(t,n-t),level:i.level}):(i.push({type:"link_open",href:r,title:o,level:i.level++}),i.linkLevel++,i.parser.tokenize(i),i.linkLevel--,i.push({type:"link_close",level:--i.level}))),i.pos=a,i.posMax=g,!0;}function _c(i,e){var t,n,s,r,o=i.posMax,a=i.pos;return a+2>=o||i.src.charCodeAt(a)!==94||i.src.charCodeAt(a+1)!==91||i.level>=i.options.maxNesting||(t=a+2,n=fs(i,a+1),n<0)?!1:(e||(i.env.footnotes||(i.env.footnotes={}),i.env.footnotes.list||(i.env.footnotes.list=[]),s=i.env.footnotes.list.length,i.pos=t,i.posMax=n,i.push({type:"footnote_ref",id:s,level:i.level}),i.linkLevel++,r=i.tokens.length,i.parser.tokenize(i),i.env.footnotes.list[s]={tokens:i.tokens.splice(r)},i.linkLevel--),i.pos=n+1,i.posMax=o,!0);}function vc(i,e){var t,n,s,r,o=i.posMax,a=i.pos;if(a+3>o||!i.env.footnotes||!i.env.footnotes.refs||i.src.charCodeAt(a)!==91||i.src.charCodeAt(a+1)!==94||i.level>=i.options.maxNesting)return!1;for(n=a+2;n<o;n++){if(i.src.charCodeAt(n)===32||i.src.charCodeAt(n)===10)return!1;if(i.src.charCodeAt(n)===93)break;}return n===a+2||n>=o||(n++,t=i.src.slice(a+2,n-1),_typeof(i.env.footnotes.refs[":"+t])>"u")?!1:(e||(i.env.footnotes.list||(i.env.footnotes.list=[]),i.env.footnotes.refs[":"+t]<0?(s=i.env.footnotes.list.length,i.env.footnotes.list[s]={label:t,count:0},i.env.footnotes.refs[":"+t]=s):s=i.env.footnotes.refs[":"+t],r=i.env.footnotes.list[s].count,i.env.footnotes.list[s].count++,i.push({type:"footnote_ref",id:s,subId:r,level:i.level})),i.pos=n,i.posMax=o,!0);}var Sc=["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"],xc=/^<([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])?)*)>/,Ac=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function wc(i,e){var t,n,s,r,o,a=i.pos;return i.src.charCodeAt(a)!==60||(t=i.src.slice(a),t.indexOf(">")<0)?!1:(n=t.match(Ac),n?Sc.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=Bi(r),!i.parser.validateLink(r))?!1:(e||(i.push({type:"link_open",href:o,level:i.level}),i.push({type:"text",content:r,level:i.level+1}),i.push({type:"link_close",level:i.level})),i.pos+=n[0].length,!0):(s=t.match(xc),s?(r=s[0].slice(1,-1),o=Bi("mailto:"+r),i.parser.validateLink(o)?(e||(i.push({type:"link_open",href:o,level:i.level}),i.push({type:"text",content:r,level:i.level+1}),i.push({type:"link_close",level:i.level})),i.pos+=s[0].length,!0):!1):!1));}function mi(i,e){return i=i.source,e=e||"",function t(n,s){return n?(s=s.source||s,i=i.replace(n,s),t):new RegExp(i,e);};}var Cc=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Tc=/[^"'=<>`\x00-\x20]+/,Rc=/'[^']*'/,Ic=/"[^"]*"/,Mc=mi(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Tc)("single_quoted",Rc)("double_quoted",Ic)(),kc=mi(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Cc)("attr_value",Mc)(),Lc=mi(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",kc)(),Pc=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Nc=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Bc=/<[?].*?[?]>/,Oc=/<![A-Z]+\s+[^>]*>/,Dc=/<!\[CDATA\[[\s\S]*?\]\]>/,Fc=mi(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Lc)("close_tag",Pc)("comment",Nc)("processing",Bc)("declaration",Oc)("cdata",Dc)();function Uc(i){var e=i|32;return e>=97&&e<=122;}function Hc(i,e){var t,n,s,r=i.pos;return!i.options.html||(s=i.posMax,i.src.charCodeAt(r)!==60||r+2>=s)||(t=i.src.charCodeAt(r+1),t!==33&&t!==63&&t!==47&&!Uc(t))||(n=i.src.slice(r).match(Fc),!n)?!1:(e||i.push({type:"htmltag",content:i.src.slice(r,r+n[0].length),level:i.level}),i.pos+=n[0].length,!0);}var jc=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,$c=/^&([a-z][a-z0-9]{1,31});/i;function qc(i,e){var t,n,s,r=i.pos,o=i.posMax;if(i.src.charCodeAt(r)!==38)return!1;if(r+1<o){if(t=i.src.charCodeAt(r+1),t===35){if(s=i.src.slice(r).match(jc),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=_o(n)?Ni(n):Ni(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match($c),s){var a=yo(s[1]);if(s[1]!==a)return e||(i.pending+=a),i.pos+=s[0].length,!0;}}return e||(i.pending+="&"),i.pos++,!0;}var Ti=[["text",ac],["newline",cc],["escape",lc],["backticks",hc],["del",dc],["ins",uc],["mark",pc],["emphasis",fc],["sub",gc],["sup",yc],["links",Ec],["footnote_inline",_c],["footnote_ref",vc],["autolink",wc],["htmltag",Hc],["entity",qc]];function gi(){this.ruler=new tt();for(var i=0;i<Ti.length;i++)this.ruler.push(Ti[i][0],Ti[i][1]);this.validateLink=Gc;}gi.prototype.skipToken=function(i){var e=this.ruler.getRules(""),t=e.length,n=i.pos,s,r;if((r=i.cacheGet(n))>0){i.pos=r;return;}for(s=0;s<t;s++)if(e[s](i,!0)){i.cacheSet(n,i.pos);return;}i.pos++,i.cacheSet(n,i.pos);};gi.prototype.tokenize=function(i){for(var e=this.ruler.getRules(""),t=e.length,n=i.posMax,s,r;i.pos<n;){for(r=0;r<t&&(s=e[r](i,!1),!s);r++);if(s){if(i.pos>=n)break;continue;}i.pending+=i.src[i.pos++];}i.pending&&i.pushPending();};gi.prototype.parse=function(i,e,t,n){var s=new xn(i,this,e,t,n);this.tokenize(s);};function Gc(i){var e=["vbscript","javascript","file","data"],t=i.trim().toLowerCase();return t=En(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var Vc={options:{html:!1,// Enable HTML tags in source
|
|
11
|
+
},{key:"preventAutomaticScrollUpOnNewLine",value:function preventAutomaticScrollUpOnNewLine(e){var t;e.addEventListener("keydown",function(){t=window.scrollY;}),e.addEventListener("input",function(){t!==window.scrollY&&window.scrollTo({top:t});});}},{key:"addFilesToAnyType",value:function addFilesToAnyType(e,t){t&&e.addFilesToAnyType(Array.from(t).map(function(n){return n;}));}}]);}();zt.TEXT_INPUT_ID="text-input";var qs=zt;var En=/*#__PURE__*/function(){function En(){_classCallCheck(this,En);}return _createClass(En,null,[{key:"focusEndOfInput",value:function focusEndOfInput(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n==null||n.removeAllRanges(),n==null||n.addRange(t),(ze.IS_MOBILE||ze.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(qs.TEXT_INPUT_ID));t&&En.focusEndOfInput(t);}}]);}();var yo="Authentication",le="Authorization",ha="authorization",gi="Unauthorized",or="Authorization header",tn="Invalid",Ts="Incorrect",we="authentication_error",et="invalid_request_error",H="Content-Type",da="content-type",Y="application/json",U="object",ar="completed",Ae="Bearer ",he="GET",ye="POST",cr="Upload an audio file",Ds="function_call",fn="input_audio",qe="image_url",ps="system",Oi="placeholder",di=/*#__PURE__*/function(){function di(){_classCallCheck(this,di);}return _createClass(di,null,[{key:"addElements",value:function addElements(e){for(var _len=arguments.length,t=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){t[_key-1]=arguments[_key];}t.forEach(function(n){return e.appendChild(n);});}},{key:"isScrollbarAtBottomOfElement",value:function isScrollbarAtBottomOfElement(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:di.CODE_SNIPPET_GENERATION_JUMP;var n=e.scrollHeight,s=e.clientHeight,i=e.scrollTop,o=n-s;return i>=o-t;}},{key:"cloneElement",value:function cloneElement(e){var t=e.cloneNode(!0);return e.parentNode.replaceChild(t,e),t;}},{key:"scrollToBottom",value:function scrollToBottom(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2?arguments[2]:undefined;e.scrollButton&&e.scrollButton.hiddenElements.size>0&&e.scrollButton.clearHidden(),n?e.elementRef.scrollTo({left:0,top:n.offsetTop}):t?e.elementRef.scrollTo({left:0,top:e.elementRef.scrollHeight,behavior:"smooth"}):e.elementRef.scrollTop=e.elementRef.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}},{key:"isVisibleInParent",value:function isVisibleInParent(e,t){var n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return n.bottom>s.top&&n.top<s.bottom;}},{key:"waitForScrollEnd",value:function waitForScrollEnd(e,t){var n=-1,s=0;var _i2=function i(){var o=e.scrollTop;if(o===n){if(s++,s>2){t();return;}}else s=0,n=o;requestAnimationFrame(_i2);};requestAnimationFrame(_i2);}},{key:"assignButtonEvents",value:function assignButtonEvents(e,t){e.onclick=t,e.onkeydown=function(n){n.key===Ee.ENTER&&setTimeout(t);};}}]);}();di.CODE_SNIPPET_GENERATION_JUMP=1;var q=di;var ui=/*#__PURE__*/function(){function ui(){_classCallCheck(this,ui);}return _createClass(ui,null,[{key:"speak",value:function speak(e,t){if(!t.audio&&window.SpeechSynthesisUtterance){var n=new SpeechSynthesisUtterance(e);Object.assign(n,t),speechSynthesis.speak(n);}}},{key:"processConfig",value:function processConfig(e,t){var n={};setTimeout(function(){if(_typeof(e)=="object"&&(e.audio&&(n.audio=e.audio),e.lang&&(n.lang=e.lang),e.pitch&&(n.pitch=e.pitch),e.rate&&(n.rate=e.rate),e.volume&&(n.volume=e.volume),e.voiceName)){var s=window.speechSynthesis.getVoices().find(function(i){var o;return i.name.toLocaleLowerCase()===((o=e.voiceName)==null?void 0:o.toLocaleLowerCase());});s&&(n.voice=s);}t(n);},ui.LOAD_VOICES_MS);}}]);}();ui.LOAD_VOICES_MS=200;var Un=ui;var Pn=/*#__PURE__*/function(){function Pn(){_classCallCheck(this,Pn);}return _createClass(Pn,null,[{key:"colorToHex",value:function colorToHex(e){var t=x();return t[E].color=e,document.body.appendChild(t),"#".concat(window.getComputedStyle(t).color.match(/\d+/g).map(function(i){return parseInt(i).toString(16).padStart(2,"0");}).join(""));}},{key:"setDots",value:function setDots(e,t){var n,s;if((s=(n=t==null?void 0:t[R])==null?void 0:n.bubble)!=null&&s.color){var i=Pn.colorToHex(t[R].bubble.color);e[E].setProperty("--loading-message-color",i),e[E].setProperty("--loading-message-color-fade","".concat(i,"33"));}else e[E].setProperty("--loading-message-color","#848484"),e[E].setProperty("--loading-message-color-fade","#55555533");}},{key:"setRing",value:function setRing(e,t){var _ref8=t||{},n=_ref8.color,s=_ref8.width,i=_ref8.height,o=_ref8.margin,a=_ref8.border;if(n){var c=Pn.colorToHex(n);e[E].setProperty("--loading-history-color",c);}else e[E].setProperty("--loading-history-color","#dbdbdb");e[E].setProperty("--loading-history-height",i||"57px"),e[E].setProperty("--loading-history-width",s||"57px"),e[E].setProperty("--loading-history-margin",o||"7px"),e[E].setProperty("--loading-history-border",a||"6px solid");}}]);}();Pn.BUBBLE_CLASS="deep-chat-loading-message-bubble",Pn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var St=Pn;var ce=/*#__PURE__*/function(){function ce(){_classCallCheck(this,ce);}return _createClass(ce,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var n=e.containerStyle;n&&(Object.assign(t[E],n),console[p]("The containerStyle property".concat(nt,"1.3.14.")),console[p]("".concat(nn,"the style property instead: ").concat(X,"styles#style")));}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
},{key:"handleResponseProperty",value:function handleResponseProperty(e){return console[p]("The {result: ....} response object type".concat(nt,"1.3.0.")),console[p]("".concat(nn,"the new response object: ").concat(X,"connect#Response")),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console[p]("The initialMessages property".concat(nt,"2.0.0.")),console[p]("".concat(nn,"the history property instead: ").concat(X,"messages/#history")),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e[ne];t&&(console[p]("The file property in MessageContent".concat(nt,"1.3.17.")),console[p]("".concat(nn,"the files array property: ").concat(X,"messages/#MessageContent")),e[m]=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console[p]("The validateMessageBeforeSending property".concat(nt,"1.3.24.")),console[p]("".concat(nn,"validateInput: ").concat(X,"interceptors#validateInput")),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console[p]("The submitUserMessage(text: string) argument string type".concat(nt,"1.4.4.")),console[p]("".concat(nn,"the new argument type: ").concat(X,"methods#submitUserMessage")),_defineProperty({},h,e);}},{key:"flagHTMLUpdateClass",value:function flagHTMLUpdateClass(e){var t;(t=e.children[0])!=null&&t[f].contains("deep-chat-update-message")&&(console[p]("The \"deep-chat-update-message\" html class".concat(nt,"1.4.4.")),console[p]("".concat(nn,"using {..., overwrite: true} object: ").concat(X,"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[p]("The request property".concat(nt,"2.0.0.")),console[p]("".concat(ks,"connect object: ").concat(X,"connect#connect-1")));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console[p]("The stream property".concat(Ur,"the connect object in version 2.0.0.")),console[p]("".concat(ks,"connect object: ").concat(X,"connect#connect-1")),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var s;var n=e;n.onNewMessage&&(console[p]("The onNewMessage event".concat(nt,"2.0.0.")),console[p]("".concat(ks,"onMessage event: ").concat(X,"events#onMessage")),(s=n.onNewMessage)==null||s.call(n,t)),e.dispatchEvent(new CustomEvent("new-message",{detail:t}));}},{key:"processFileConfigConnect",value:function processFileConfigConnect(e){var t=e;t.request&&(console[p]("The request property in file configuration".concat(nt,"2.0.0.")),console[p]("Please use the connect property instead: ".concat(X,"files")),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=w(e),n=t.loading;return n&&(n.outerContainer||n.innerContainer||n.bubble||n.media)&&(console[p]("The loading message styles are defined using LoadingMessageStyles interface".concat(kn,"2.1.0.")),console[p]("Check it out here: ".concat(X,"messages/styles#LoadingMessageStyles")),t.loading={message:{styles:n}}),t;}},{key:"processDemo",value:function processDemo(e){return typeof e=="boolean"||e.displayLoadingBubble&&(console[p]("The demo displayLoadingBubble property".concat(nt,"2.1.0.")),console[p]("Please use displayLoading instead: ".concat(X,"modes#demo")),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,n="".concat(ks,"official documentation: ").concat(X,"directConnection/Cohere");return t.chat&&(console[p]("Cohere chat property".concat(nt,"2.2.3.")),console[p](n),delete t.chat),t.textGeneration?(console[p]("Cohere textGeneration".concat(Fr,"2.2.3.")),console[p](n),delete t.textGeneration,!1):t.summarization?(console[p]("Cohere summarization".concat(Fr,"2.2.3.")),console[p](n),delete t.summarization,!1):!0;}},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==U)return;var t=e.htmlWrappers;if(t)return console[p]("The htmlWrappers property".concat(Ur,"Deep Chat's base").concat(kn,"2.3.0.")),console[p]("Check it out here: ".concat(X,"messages/HTML#htmlWrappers")),t;}},{key:"processFocusMode",value:function processFocusMode(e){return!e||typeof e=="boolean"||e.scroll&&(console[p]("The scroll property in focusMode has been changed to smoothScroll".concat(kn,"2.3.0.")),console[p]("Check it out here: ".concat(X,"modes#focusMode")),e.smoothScroll=!0),e;}},{key:"processPosition",value:function processPosition(e){if(!e)return e;var t="Position names have been updated".concat(kn,"2.3.1.");return e==="inside-left"?(console[p](t),jn):e==="inside-right"?(console[p](t),vt):e==="outside-left"?(console[p](t),Pe):e==="outside-right"?(console[p](t),ve):e;}},{key:"processBrowserStorage",value:function processBrowserStorage(e){var t=e.get();t&&Array.isArray(t)&&e.addMessages(t);}}]);}();var kn=" since version ",nt=" is deprecated ".concat(kn),nn="Please change to using ",ks="Please see the ",Fr=" is not supported ".concat(kn),Ur=" has been moved to ";var Nt=/*#__PURE__*/function(){function Nt(){_classCallCheck(this,Nt);}return _createClass(Nt,null,[{key:"mouseUp",value:function mouseUp(e,t){de.unsetAllCSSMouseStates(e,t),Object.assign(e[E],t[A]),Object.assign(e[E],t[De]);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e[E],t[Z]);}},{key:"mouseLeave",value:function mouseLeave(e,t){de.unsetAllCSSMouseStates(e,t),Object.assign(e[E],t[A]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e[E],t[De]);}},{key:"add",value:function add(e,t){e.addEventListener(Cs,Nt.mouseEnter.bind(this,e,t)),e.addEventListener(yn,Nt.mouseLeave.bind(this,e,t)),e.addEventListener(aa,Nt.mouseDown.bind(this,e,t)),e.addEventListener(ca,Nt.mouseUp.bind(this,e,t));}}]);}();var ua="deep-chat-temporary-message",pa="deep-chat-suggestion-button",Ni={"deep-chat-button":{styles:_defineProperty(_defineProperty(_defineProperty({},A,{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"}),De,{backgroundColor:"#fafafa"}),Z,{backgroundColor:"#f1f1f1"})}},Hr=Object.keys(Ni);var At=/*#__PURE__*/function(){function At(){_classCallCheck(this,At);}return _createClass(At,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener(Z,function(){var n,s;(s=e.submitUserMessage)==null||s.call(e,_defineProperty({},h,((n=t.textContent)==null?void 0:n.trim())||""));});});}},{key:"isElementTemporary",value:function isElementTemporary(e){var t;return e?(t=e.bubbleElement.children[0])==null?void 0:t[f].contains(ua):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return Hr.find(function(t){return e[f].contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var n=Ni[t].events;Object.keys(n||[]).forEach(function(s){e.addEventListener(s,n==null?void 0:n[s]);});}},{key:"getProcessedStyles",value:function getProcessedStyles(e,t,n){var s=Array.from(t[f]).reduce(function(a,c){var d;var l=(d=e[c])==null?void 0:d[R];return l&&e[c][R]&&a.push(l),a;},[]),i=Ni[n][R];if(i){var a=w(i);a[A]&&de.overwriteDefaultWithAlreadyApplied(a,t),s.unshift(a);}var o=de.mergeStatefulStyles(s);return de.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,n){Hr.forEach(function(i){var o=n.getElementsByClassName(i);Array.from(o||[]).forEach(function(a){var c=At.getProcessedStyles(t,a,i);re.applyStylesToElement(a,c),At.applyEvents(a,i);});});var s=n.getElementsByClassName(pa);Array.from(s).forEach(function(i){return At.applySuggestionEvent(e,i);});}}]);}();var re=/*#__PURE__*/function(){function re(){_classCallCheck(this,re);}return _createClass(re,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var n=de.processStateful(t);Nt.add(e,n),Object.assign(e[E],n[A]);}},{key:"applyEventsToElement",value:function applyEventsToElement(e,t){Object.keys(t).forEach(function(n){var s=t[n];s&&e.addEventListener(n,s);});}},{key:"applyClassUtilitiesToElement",value:function applyClassUtilitiesToElement(e,t){var n=t.events,s=t.styles;n&&re.applyEventsToElement(e,n),s&&!At.doesElementContainDeepChatClass(e)&&re.applyStylesToElement(e,s);}},{key:"applyCustomClassUtilities",value:function applyCustomClassUtilities(e,t){Object.keys(e).forEach(function(n){var s=t.getElementsByClassName(n);Array.from(s).forEach(function(i){e[n]&&re.applyClassUtilitiesToElement(i,e[n]);});});}},{key:"apply",value:function apply(e,t){At.applyDeepChatUtilities(e,e.htmlClassUtilities,t),re.applyCustomClassUtilities(e.htmlClassUtilities,t);}},{key:"traverseNodes",value:function traverseNodes(e,t){e.nodeType===Node.ELEMENT_NODE&&t.push(e.outerHTML),e.childNodes.forEach(function(n){re.traverseNodes(n,t);});}},{key:"splitHTML",value:function splitHTML(e){var n=new DOMParser().parseFromString(e,"text/html"),s=[];return n.body.childNodes.forEach(function(i){re.traverseNodes(i,s);}),s;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=x();return t.innerHTML=e,At.isElementTemporary({outerContainer:t,bubbleElement:t,innerContainer:t});}// useful for removing event listeners
|
|
13
|
+
},{key:"replaceElementWithNewClone",value:function replaceElementWithNewClone(e,t){var s;var n=(t||e).cloneNode(!0);return(s=e.parentNode)==null||s.replaceChild(n,e),n;}},{key:"tryAddWrapper",value:function tryAddWrapper(e,t,n,s){if(t&&s){var i=(n==null?void 0:n[s])||(n==null?void 0:n[A]);if(i)return e.innerHTML=i,{contentEl:re.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(Xo)[0]||e;}}]);}();var qt=/*#__PURE__*/function(){function qt(){_classCallCheck(this,qt);}return _createClass(qt,null,[{key:"createElements",value:function createElements(e,t,n,s){var i=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;var o=e.createMessageElementsOnOrientation("",n,s,i);o.bubbleElement[f].add(qt.HTML_BUBBLE_CLASS);var _re$tryAddWrapper=re.tryAddWrapper(o.bubbleElement,t,e._customWrappers,n),a=_re$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,n){n.bubbleElement.innerHTML=t,re.apply(e,n.outerContainer),ce.flagHTMLUpdateClass(n.bubbleElement);}// prettier-ignore
|
|
14
|
+
},{key:"overwrite",value:function overwrite(e,t,n,s){var i=e.messageToElements,o=B.overwriteMessage(i,s,t,n,L,qt.HTML_BUBBLE_CLASS);return o&&qt.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var i=qt.createElements(e,t,n,s);return B.fillEmptyMessageElement(i.bubbleElement,t),re.apply(e,i.outerContainer),ce.flagHTMLUpdateClass(i.bubbleElement),e.applyCustomStyles(i,n,!1,(o=e.messageStyles)==null?void 0:o[L]),i;}},{key:"add",value:function add(e,t,n,s){var i=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(s!=null&&s.status){var a=this.overwrite(e,t,n,e.messageElementRefs);if(a)return a;s.status=!1;}if(i&&e.messageElementRefs.length>0&&re.isTemporaryBasedOnHTML(t))return;var o=qt.create(e,t,n,i);return i||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();qt.HTML_BUBBLE_CLASS="html-message";var wt=qt;var fa=/*#__PURE__*/function(){function fa(){_classCallCheck(this,fa);}return _createClass(fa,null,[{key:"katex",value:function katex(e,t,n){var a=(n||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var c=function c(u,g){var b;return((b=window.katex)==null?void 0:b.renderToString(u,_objectSpread({displayMode:g,throwOnError:!1,output:"mathml"},e)))||"";},l=function l(u,g,b){var _=!1,v=u.bMarks[g]+u.tShift[g],C=u.eMarks[g];if(v+1>C)return!1;var N=u[T].charAt(v);if(N!==a)return!1;var se=v;v=u.skipChars(v,N);var fe=v-se;if(fe!==2)return!1;var ie=g;for(;++ie,!(ie>=b||(v=se=u.bMarks[ie]+u.tShift[ie],C=u.eMarks[ie],v<C&&u.tShift[ie]<u.blkIndent));)if(u[T].charAt(v)===a&&!(u.tShift[ie]-u.blkIndent>=4)&&(v=u.skipChars(v,N),!(v-se<fe)&&(v=u.skipSpaces(v),!(v<C)))){_=!0;break;}fe=u.tShift[g],u.line=ie+(_?1:0);var Re=u.getLines(g+1,ie,fe,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:Re,lines:[g,u.line],level:u.level,block:!0}),!0;},d=function d(u,g){var b=u.pos,_=u.posMax;var v=b;if(u[T].charAt(v)!==a)return!1;for(++v;v<_&&u[T].charAt(v)===a;)++v;var C=u[T].slice(b,v);if(C.length>2)return!1;var N=v;var se=0;for(;v<_;){var fe=u[T].charAt(v);if(fe==="{"&&(v===0||u[T].charAt(v-1)!=="\\"))se+=1;else if(fe==="}"&&(v===0||u[T].charAt(v-1)!=="\\")){if(se-=1,se<0)return!1;}else if(fe===a&&se===0){var ie=v;var Re=v+1;for(;Re<_&&u[T].charAt(Re)===a;)++Re;if(Re-ie===C.length){if(!g){var $t=u[T].slice(N,ie).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:$t,block:C.length>1,level:u.level});}return u.pos=Re,!0;}}v+=1;}return g||(u.pending+=C),u.pos+=C.length,!0;};t.inline.ruler.push("katex",d,n),t.block.ruler.push("katex",l,n),t.renderer.rules.katex=function(u,g){return c(u[g].content,u[g].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var Ls;function Eo(r){return Ls=Ls||document.createElement("textarea"),Ls.innerHTML="&"+r+";",Ls.value;}var ma=Object.prototype.hasOwnProperty;function ga(r,e){return r?ma.call(r,e):!1;}function _o(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(n){r[n]=t[n];});}}),r;}var ba=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function fs(r){return r.indexOf("\\")<0?r:r.replace(ba,"$1");}function vo(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 Bi(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 ya=/&([a-z#][a-z0-9]{1,31});/gi,Ea=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function _a(r,e){var t=0,n=Eo(e);return e!==n?n:e.charCodeAt(0)===35&&Ea.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),vo(t))?Bi(t):r;}function _n(r){return r.indexOf("&")<0?r:r.replace(ya,_a);}var va=/[&<>"]/,Sa=/[&<>"]/g,xa={"&":"&","<":"<",">":">",'"':"""};function Aa(r){return xa[r];}function Ve(r){return va.test(r)?r.replace(Sa,Aa):r;}var I={};I.blockquote_open=function(){return"<blockquote>\n";};I.blockquote_close=function(r,e){return"</blockquote>"+xn(r,e);};I.code=function(r,e){return r[e].block?"<pre><code>"+Ve(r[e].content)+"</code></pre>"+xn(r,e):"<code>"+Ve(r[e].content)+"</code>";};I.fence=function(r,e,t,n,s){var i=r[e],o="",a=t.langPrefix,c="",l,d,u;if(i.params){if(l=i.params.split(/\s+/g),d=l.join(" "),ga(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](r,e,t,n,s);c=Ve(_n(fs(d))),o=' class="'+a+c+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[i.content].concat(l))||Ve(i.content):u=Ve(i.content),"<pre><code"+o+">"+u+"</code></pre>"+xn(r,e);};I.fence_custom={};I.heading_open=function(r,e){return"<h"+r[e].hLevel+">";};I.heading_close=function(r,e){return"</h"+r[e].hLevel+">\n";};I.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+xn(r,e);};I.bullet_list_open=function(){return"<ul>\n";};I.bullet_list_close=function(r,e){return"</ul>"+xn(r,e);};I.list_item_open=function(){return"<li>";};I.list_item_close=function(){return"</li>\n";};I.ordered_list_open=function(r,e){var t=r[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};I.ordered_list_close=function(r,e){return"</ol>"+xn(r,e);};I.paragraph_open=function(r,e){return r[e].tight?"":"<p>";};I.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?xn(r,e):"");};I.link_open=function(r,e,t){var n=r[e].title?' title="'+Ve(_n(r[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Ve(r[e].href)+'"'+n+s+">";};I.link_close=function(){return"</a>";};I.image=function(r,e,t){var n=' src="'+Ve(r[e].src)+'"',s=r[e].title?' title="'+Ve(_n(r[e].title))+'"':"",i=' alt="'+(r[e].alt?Ve(_n(fs(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+i+s+o+">";};I.table_open=function(){return"<table>\n";};I.table_close=function(){return"</table>\n";};I.thead_open=function(){return"<thead>\n";};I.thead_close=function(){return"</thead>\n";};I.tbody_open=function(){return"<tbody>\n";};I.tbody_close=function(){return"</tbody>\n";};I.tr_open=function(){return"<tr>";};I.tr_close=function(){return"</tr>\n";};I.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.th_close=function(){return"</th>";};I.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.td_close=function(){return"</td>";};I.strong_open=function(){return"<strong>";};I.strong_close=function(){return"</strong>";};I.em_open=function(){return"<em>";};I.em_close=function(){return"</em>";};I.del_open=function(){return"<del>";};I.del_close=function(){return"</del>";};I.ins_open=function(){return"<ins>";};I.ins_close=function(){return"</ins>";};I.mark_open=function(){return"<mark>";};I.mark_close=function(){return"</mark>";};I.sub=function(r,e){return"<sub>"+Ve(r[e].content)+"</sub>";};I.sup=function(r,e){return"<sup>"+Ve(r[e].content)+"</sup>";};I.hardbreak=function(r,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};I.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};I.text=function(r,e){return Ve(r[e].content);};I.htmlblock=function(r,e){return r[e].content;};I.htmltag=function(r,e){return r[e].content;};I.abbr_open=function(r,e){return'<abbr title="'+Ve(_n(r[e].title))+'">';};I.abbr_close=function(){return"</abbr>";};I.footnote_ref=function(r,e){var t=Number(r[e].id+1).toString(),n="fnref"+t;return r[e].subId>0&&(n+=":"+r[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+n+'">['+t+"]</a></sup>";};I.footnote_block_open=function(r,e,t){var n=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return n+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};I.footnote_block_close=function(){return"</ol>\n</section>\n";};I.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};I.footnote_close=function(){return"</li>\n";};I.footnote_anchor=function(r,e){var t=Number(r[e].id+1).toString(),n="fnref"+t;return r[e].subId>0&&(n+=":"+r[e].subId),' <a href="#'+n+'" class="footnote-backref">↩</a>';};I.dl_open=function(){return"<dl>\n";};I.dt_open=function(){return"<dt>";};I.dd_open=function(){return"<dd>";};I.dl_close=function(){return"</dl>\n";};I.dt_close=function(){return"</dt>\n";};I.dd_close=function(){return"</dd>\n";};function So(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?So(r,e+2):e;}var xn=I.getBreak=function(e,t){return t=So(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function lr(){this.rules=_o({},I),this.getBreak=I.getBreak;}lr.prototype.renderInline=function(r,e,t){for(var n=this.rules,s=r.length,i=0,o="";s--;)o+=n[r[i].type](r,i++,e,t,this);return o;};lr.prototype.render=function(r,e,t){for(var n=this.rules,s=r.length,i=-1,o="";++i<s;)r[i].type==="inline"?o+=this.renderInline(r[i].children,e,t):o+=n[r[i].type](r,i,e,t,this);return o;};function tt(){this.__rules__=[],this.__cache__=null;}tt.prototype.__find__=function(r){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===r)return t;return-1;};tt.prototype.__compile__=function(){var r=this,e=[""];r.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(n){e.indexOf(n)<0&&e.push(n);});}),r.__cache__={},e.forEach(function(t){r.__cache__[t]=[],r.__rules__.forEach(function(n){n.enabled&&(t&&n.alt.indexOf(t)<0||r.__cache__[t].push(n.fn));});});};tt.prototype.at=function(r,e,t){var n=this.__find__(r),s=t||{};if(n===-1)throw new Error("Parser rule not found: "+r);this.__rules__[n].fn=e,this.__rules__[n].alt=s.alt||[],this.__cache__=null;};tt.prototype.before=function(r,e,t,n){var s=this.__find__(r),i=n||{};if(s===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(s,0,{name:e,enabled:!0,fn:t,alt:i.alt||[]}),this.__cache__=null;};tt.prototype.after=function(r,e,t,n){var s=this.__find__(r),i=n||{};if(s===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(s+1,0,{name:e,enabled:!0,fn:t,alt:i.alt||[]}),this.__cache__=null;};tt.prototype.push=function(r,e,t){var n=t||{};this.__rules__.push({name:r,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};tt.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 n=this.__find__(t);if(n<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[n].enabled=!0;},this),this.__cache__=null;};tt.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;};tt.prototype.getRules=function(r){return this.__cache__===null&&this.__compile__(),this.__cache__[r]||[];};function wa(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 An(r,e,t,n,s){this.src=r,this.env=n,this.options=t,this.parser=e,this.tokens=s,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0;}An.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};An.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level;};An.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e;};An.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0;};function ms(r,e){var t,n,s,i=-1,o=r.posMax,a=r.pos,c=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(s=r.src.charCodeAt(r.pos),s===91)t++;else if(s===93&&(t--,t===0)){n=!0;break;}r.parser.skipToken(r);}return n?(i=r.pos,r.labelUnmatchedScopes=0):r.labelUnmatchedScopes=t-1,r.pos=a,r.isInLabel=c,i;}function Ca(r,e,t,n){var s,i,o,a,c,l;if(r.charCodeAt(0)!==42||r.charCodeAt(1)!==91||r.indexOf("]:")===-1||(s=new An(r,e,t,n,[]),i=ms(s,1),i<0||r.charCodeAt(i+1)!==58))return-1;for(a=s.posMax,o=i+2;o<a&&s.src.charCodeAt(o)!==10;o++);return c=r.slice(2,i),l=r.slice(i+2,o).trim(),l.length===0?-1:(n.abbreviations||(n.abbreviations={}),_typeof(n.abbreviations[":"+c])>"u"&&(n.abbreviations[":"+c]=l),o);}function Ta(r){var e=r.tokens,t,n,s,i;if(!r.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(i=Ca(s,r.inline,r.options,r.env),!(i<0));)s=s.slice(i).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Di(r){var e=_n(r);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function xo(r,e){var t,n,s,i=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 s=Di(fs(r.src.slice(i+1,e))),r.parser.validateLink(s)?(r.pos=e+1,r.linkContent=s,!0):!1;if(t===92&&e+1<o){e+=2;continue;}e++;}return!1;}for(n=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&&(n++,n>1)||t===41&&(n--,n<0))break;e++;}return i===e||(s=fs(r.src.slice(i,e)),!r.parser.validateLink(s))?!1:(r.linkContent=s,r.pos=e,!0);}function Ao(r,e){var t,n=e,s=r.posMax,i=r.src.charCodeAt(e);if(i!==34&&i!==39&&i!==40)return!1;for(e++,i===40&&(i=41);e<s;){if(t=r.src.charCodeAt(e),t===i)return r.pos=e+1,r.linkContent=fs(r.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function wo(r){return r.trim().replace(/\s+/g," ").toUpperCase();}function Ra(r,e,t,n){var s,i,o,a,c,l,d,u,g;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(s=new An(r,e,t,n,[]),i=ms(s,0),i<0||r.charCodeAt(i+1)!==58))return-1;for(a=s.posMax,o=i+2;o<a&&(c=s.src.charCodeAt(o),!(c!==32&&c!==10));o++);if(!xo(s,o))return-1;for(d=s.linkContent,o=s.pos,l=o,o=o+1;o<a&&(c=s.src.charCodeAt(o),!(c!==32&&c!==10));o++);for(o<a&&l!==o&&Ao(s,o)?(u=s.linkContent,o=s.pos):(u="",o=l);o<a&&s.src.charCodeAt(o)===32;)o++;return o<a&&s.src.charCodeAt(o)!==10?-1:(g=wo(r.slice(1,i)),_typeof(n.references[g])>"u"&&(n.references[g]={title:u,href:d}),o);}function Ia(r){var e=r.tokens,t,n,s,i;if(r.env.references=r.env.references||{},!r.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(i=Ra(s,r.inline,r.options,r.env),!(i<0));)s=s.slice(i).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Ma(r){var e=r.tokens,t,n,s;for(n=0,s=e.length;n<s;n++)t=e[n],t.type==="inline"&&r.inline.parse(t.content,r.options,r.env,t.children);}function ka(r){var e,t,n,s,i,o,a,c,l,d=0,u=!1,g={};if(r.env.footnotes&&(r.tokens=r.tokens.filter(function(b){return b.type==="footnote_reference_open"?(u=!0,c=[],l=b.label,!1):b.type==="footnote_reference_close"?(u=!1,g[":"+l]=c,!1):(u&&c.push(b),!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=g[":"+o[e].label]),r.tokens=r.tokens.concat(a),r.tokens[r.tokens.length-1].type==="paragraph_close"?i=r.tokens.pop():i=null,s=o[e].count>0?o[e].count:1,n=0;n<s;n++)r.tokens.push({type:"footnote_anchor",id:e,subId:n,level:d});i&&r.tokens.push(i),r.tokens.push({type:"footnote_close",level:--d});}r.tokens.push({type:"footnote_block_close",level:--d});}}var $r=" \n()[]'\".,!?-";function Ci(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function La(r){var e,t,n,s,i,o,a,c,l,d,u,g,b=r.tokens;if(r.env.abbreviations){for(r.env.abbrRegExp||(g="(^|["+$r.split("").map(Ci).join("")+"])("+Object.keys(r.env.abbreviations).map(function(_){return _.substr(1);}).sort(function(_,v){return v.length-_.length;}).map(Ci).join("|")+")($|["+$r.split("").map(Ci).join("")+"])",r.env.abbrRegExp=new RegExp(g,"g")),d=r.env.abbrRegExp,t=0,n=b.length;t<n;t++)if(b[t].type==="inline"){for(s=b[t].children,e=s.length-1;e>=0;e--)if(i=s[e],i.type==="text"){for(c=0,o=i.content,d.lastIndex=0,l=i.level,a=[];u=d.exec(o);)d.lastIndex>c&&a.push({type:"text",content:o.slice(c,u.index+u[1].length),level:l}),a.push({type:"abbr_open",title:r.env.abbreviations[":"+u[2]],level:l++}),a.push({type:"text",content:u[2],level:l}),a.push({type:"abbr_close",level:--l}),c=d.lastIndex-u[3].length;a.length&&(c<o.length&&a.push({type:"text",content:o.slice(c),level:l}),b[t].children=s=[].concat(s.slice(0,e),a,s.slice(e+1)));}}}}var Pa=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Oa=/\((c|tm|r|p)\)/ig,Na={c:"©",r:"®",p:"§",tm:"™"};function Ba(r){return r.indexOf("(")<0?r:r.replace(Oa,function(e,t){return Na[t.toLowerCase()];});}function Da(r){var e,t,n,s,i;if(r.options.typographer){for(i=r.tokens.length-1;i>=0;i--)if(r.tokens[i].type==="inline")for(s=r.tokens[i].children,e=s.length-1;e>=0;e--)t=s[e],t.type==="text"&&(n=t.content,n=Ba(n),Pa.test(n)&&(n=n.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=n);}}var Fa=/['"]/,jr=/['"]/g,Ua=/[-\s()\[\]]/,Gr="’";function zr(r,e){return e<0||e>=r.length?!1:!Ua.test(r[e]);}function Rn(r,e,t){return r.substr(0,e)+t+r.substr(e+1);}function Ha(r){var e,t,n,s,i,o,a,c,l,d,u,g,b,_,v,C,N;if(r.options.typographer){for(N=[],v=r.tokens.length-1;v>=0;v--)if(r.tokens[v].type==="inline"){for(C=r.tokens[v].children,N.length=0,e=0;e<C.length;e++)if(t=C[e],!(t.type!=="text"||Fa.test(t.text))){for(a=C[e].level,b=N.length-1;b>=0&&!(N[b].level<=a);b--);N.length=b+1,n=t.content,i=0,o=n.length;e:for(;i<o&&(jr.lastIndex=i,s=jr.exec(n),!!s);){if(c=!zr(n,s.index-1),i=s.index+1,_=s[0]==="'",l=!zr(n,i),!l&&!c){_&&(t.content=Rn(t.content,s.index,Gr));continue;}if(u=!l,g=!c,g){for(b=N.length-1;b>=0&&(d=N[b],!(N[b].level<a));b--)if(d.single===_&&N[b].level===a){d=N[b],_?(C[d.token].content=Rn(C[d.token].content,d.pos,r.options.quotes[2]),t.content=Rn(t.content,s.index,r.options.quotes[3])):(C[d.token].content=Rn(C[d.token].content,d.pos,r.options.quotes[0]),t.content=Rn(t.content,s.index,r.options.quotes[1])),N.length=b;continue e;}}u?N.push({token:e,pos:s.index,single:_,level:a}):g&&_&&(t.content=Rn(t.content,s.index,Gr));}}}}}var Ti=[["block",wa],["abbr",Ta],["references",Ia],["inline",Ma],["footnote_tail",ka],["abbr2",La],["replacements",Da],["smartquotes",Ha]];function Co(){this.options={},this.ruler=new tt();for(var r=0;r<Ti.length;r++)this.ruler.push(Ti[r][0],Ti[r][1]);}Co.prototype.process=function(r){var e,t,n;for(n=this.ruler.getRules(""),e=0,t=n.length;e<t;e++)n[e](r);};function wn(r,e,t,n,s){var i,o,a,c,l,d,u;for(this.src=r,this.parser=e,this.options=t,this.env=n,this.tokens=s,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,d=0,u=!1,a=c=d=0,l=o.length;c<l;c++){if(i=o.charCodeAt(c),!u)if(i===32){d++;continue;}else u=!0;(i===10||c===l-1)&&(i!==10&&c++,this.bMarks.push(a),this.eMarks.push(c),this.tShift.push(d),u=!1,d=0,a=c+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}wn.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};wn.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};wn.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};wn.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};wn.prototype.skipCharsBack=function(e,t,n){if(e<=n)return e;for(;e>n;)if(t!==this.src.charCodeAt(--e))return e+1;return e;};wn.prototype.getLines=function(e,t,n,s){var i,o,a,c,l,d=e;if(e>=t)return"";if(d+1===t)return o=this.bMarks[d]+Math.min(this.tShift[d],n),a=s?this.eMarks[d]+1:this.eMarks[d],this.src.slice(o,a);for(c=new Array(t-e),i=0;d<t;d++,i++)l=this.tShift[d],l>n&&(l=n),l<0&&(l=0),o=this.bMarks[d]+l,d+1<t||s?a=this.eMarks[d]+1:a=this.eMarks[d],c[i]=this.src.slice(o,a);return c.join("");};function $a(r,e,t){var n,s;if(r.tShift[e]-r.blkIndent<4)return!1;for(s=n=e+1;n<t;){if(r.isEmpty(n)){n++;continue;}if(r.tShift[n]-r.blkIndent>=4){n++,s=n;continue;}break;}return r.line=n,r.tokens.push({type:"code",content:r.getLines(e,s,4+r.blkIndent,!0),block:!0,lines:[e,r.line],level:r.level}),!0;}function ja(r,e,t,n){var s,i,o,a,c,l=!1,d=r.bMarks[e]+r.tShift[e],u=r.eMarks[e];if(d+3>u||(s=r.src.charCodeAt(d),s!==126&&s!==96)||(c=d,d=r.skipChars(d,s),i=d-c,i<3)||(o=r.src.slice(d,u).trim(),o.indexOf("`")>=0))return!1;if(n)return!0;for(a=e;a++,!(a>=t||(d=c=r.bMarks[a]+r.tShift[a],u=r.eMarks[a],d<u&&r.tShift[a]<r.blkIndent));)if(r.src.charCodeAt(d)===s&&!(r.tShift[a]-r.blkIndent>=4)&&(d=r.skipChars(d,s),!(d-c<i)&&(d=r.skipSpaces(d),!(d<u)))){l=!0;break;}return i=r.tShift[e],r.line=a+(l?1:0),r.tokens.push({type:"fence",params:o,content:r.getLines(e+1,a,i,!0),lines:[e,r.line],level:r.level}),!0;}function Ga(r,e,t,n){var s,i,o,a,c,l,d,u,g,b,_,v=r.bMarks[e]+r.tShift[e],C=r.eMarks[e];if(v>C||r.src.charCodeAt(v++)!==62||r.level>=r.options.maxNesting)return!1;if(n)return!0;for(r.src.charCodeAt(v)===32&&v++,c=r.blkIndent,r.blkIndent=0,a=[r.bMarks[e]],r.bMarks[e]=v,v=v<C?r.skipSpaces(v):v,i=v>=C,o=[r.tShift[e]],r.tShift[e]=v-r.bMarks[e],u=r.parser.ruler.getRules("blockquote"),s=e+1;s<t&&(v=r.bMarks[s]+r.tShift[s],C=r.eMarks[s],!(v>=C));s++){if(r.src.charCodeAt(v++)===62){r.src.charCodeAt(v)===32&&v++,a.push(r.bMarks[s]),r.bMarks[s]=v,v=v<C?r.skipSpaces(v):v,i=v>=C,o.push(r.tShift[s]),r.tShift[s]=v-r.bMarks[s];continue;}if(i)break;for(_=!1,g=0,b=u.length;g<b;g++)if(u[g](r,s,t,!0)){_=!0;break;}if(_)break;a.push(r.bMarks[s]),o.push(r.tShift[s]),r.tShift[s]=-1337;}for(l=r.parentType,r.parentType="blockquote",r.tokens.push({type:"blockquote_open",lines:d=[e,0],level:r.level++}),r.parser.tokenize(r,e,s),r.tokens.push({type:"blockquote_close",level:--r.level}),r.parentType=l,d[1]=r.line,g=0;g<o.length;g++)r.bMarks[g+e]=a[g],r.tShift[g+e]=o[g];return r.blkIndent=c,!0;}function za(r,e,t,n){var s,i,o,a=r.bMarks[e],c=r.eMarks[e];if(a+=r.tShift[e],a>c||(s=r.src.charCodeAt(a++),s!==42&&s!==45&&s!==95))return!1;for(i=1;a<c;){if(o=r.src.charCodeAt(a++),o!==s&&o!==32)return!1;o===s&&i++;}return i<3?!1:(n||(r.line=e+1,r.tokens.push({type:"hr",lines:[e,r.line],level:r.level})),!0);}function qr(r,e){var t,n,s;return n=r.bMarks[e]+r.tShift[e],s=r.eMarks[e],n>=s||(t=r.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<s&&r.src.charCodeAt(n)!==32?-1:n;}function Vr(r,e){var t,n=r.bMarks[e]+r.tShift[e],s=r.eMarks[e];if(n+1>=s||(t=r.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=s)return-1;if(t=r.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return n<s&&r.src.charCodeAt(n)!==32?-1:n;}function qa(r,e){var t,n,s=r.level+2;for(t=e+2,n=r.tokens.length-2;t<n;t++)r.tokens[t].level===s&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function Va(r,e,t,n){var s,i,o,a,c,l,d,u,g,b,_,v,C,N,se,fe,ie,Re,$t=!0,jt,Ke,kr,xi;if((u=Vr(r,e))>=0)C=!0;else if((u=qr(r,e))>=0)C=!1;else return!1;if(r.level>=r.options.maxNesting)return!1;if(v=r.src.charCodeAt(u-1),n)return!0;for(se=r.tokens.length,C?(d=r.bMarks[e]+r.tShift[e],_=Number(r.src.substr(d,u-d-1)),r.tokens.push({type:"ordered_list_open",order:_,lines:ie=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:ie=[e,0],level:r.level++}),s=e,fe=!1,jt=r.parser.ruler.getRules("list");s<t&&(N=r.skipSpaces(u),g=r.eMarks[s],N>=g?b=1:b=N-u,b>4&&(b=1),b<1&&(b=1),i=u-r.bMarks[s]+b,r.tokens.push({type:"list_item_open",lines:Re=[e,0],level:r.level++}),a=r.blkIndent,c=r.tight,o=r.tShift[e],l=r.parentType,r.tShift[e]=N-r.bMarks[e],r.blkIndent=i,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||fe)&&($t=!1),fe=r.line-e>1&&r.isEmpty(r.line-1),r.blkIndent=a,r.tShift[e]=o,r.tight=c,r.parentType=l,r.tokens.push({type:"list_item_close",level:--r.level}),s=e=r.line,Re[1]=s,N=r.bMarks[e],!(s>=t||r.isEmpty(s)||r.tShift[s]<r.blkIndent));){for(xi=!1,Ke=0,kr=jt.length;Ke<kr;Ke++)if(jt[Ke](r,s,t,!0)){xi=!0;break;}if(xi)break;if(C){if(u=Vr(r,s),u<0)break;}else if(u=qr(r,s),u<0)break;if(v!==r.src.charCodeAt(u-1))break;}return r.tokens.push({type:C?"ordered_list_close":"bullet_list_close",level:--r.level}),ie[1]=s,r.line=s,$t&&qa(r,se),!0;}function Ka(r,e,t,n){var s,i,o,a,c,l=r.bMarks[e]+r.tShift[e],d=r.eMarks[e];if(l+4>d||r.src.charCodeAt(l)!==91||r.src.charCodeAt(l+1)!==94||r.level>=r.options.maxNesting)return!1;for(a=l+2;a<d;a++){if(r.src.charCodeAt(a)===32)return!1;if(r.src.charCodeAt(a)===93)break;}return a===l+2||a+1>=d||r.src.charCodeAt(++a)!==58?!1:(n||(a++,r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.refs||(r.env.footnotes.refs={}),c=r.src.slice(l+2,a-2),r.env.footnotes.refs[":"+c]=-1,r.tokens.push({type:"footnote_reference_open",label:c,level:r.level++}),s=r.bMarks[e],i=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]=i,r.bMarks[e]=s,r.tokens.push({type:"footnote_reference_close",level:--r.level})),!0);}function Wa(r,e,t,n){var s,i,o,a=r.bMarks[e]+r.tShift[e],c=r.eMarks[e];if(a>=c||(s=r.src.charCodeAt(a),s!==35||a>=c))return!1;for(i=1,s=r.src.charCodeAt(++a);s===35&&a<c&&i<=6;)i++,s=r.src.charCodeAt(++a);return i>6||a<c&&s!==32?!1:(n||(c=r.skipCharsBack(c,32,a),o=r.skipCharsBack(c,35,a),o>a&&r.src.charCodeAt(o-1)===32&&(c=o),r.line=e+1,r.tokens.push({type:"heading_open",hLevel:i,lines:[e,r.line],level:r.level}),a<c&&r.tokens.push({type:"inline",content:r.src.slice(a,c).trim(),level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"heading_close",hLevel:i,level:r.level})),!0);}function Xa(r,e,t){var n,s,i,o=e+1;return o>=t||r.tShift[o]<r.blkIndent||r.tShift[o]-r.blkIndent>3||(s=r.bMarks[o]+r.tShift[o],i=r.eMarks[o],s>=i)||(n=r.src.charCodeAt(s),n!==45&&n!==61)||(s=r.skipChars(s,n),s=r.skipSpaces(s),s<i)?!1:(s=r.bMarks[e]+r.tShift[e],r.line=o+1,r.tokens.push({type:"heading_open",hLevel:n===61?1:2,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:r.src.slice(s,r.eMarks[e]).trim(),level:r.level+1,lines:[e,r.line-1],children:[]}),r.tokens.push({type:"heading_close",hLevel:n===61?1:2,level:r.level}),!0);}var To={};["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){To[r]=!0;});var Za=/^<([a-zA-Z]{1,15})[\s\/>]/,Ya=/^<\/([a-zA-Z]{1,15})[\s>]/;function Ja(r){var e=r|32;return e>=97&&e<=122;}function Qa(r,e,t,n){var s,i,o,a=r.bMarks[e],c=r.eMarks[e],l=r.tShift[e];if(a+=l,!r.options.html||l>3||a+2>=c||r.src.charCodeAt(a)!==60)return!1;if(s=r.src.charCodeAt(a+1),s===33||s===63){if(n)return!0;}else if(s===47||Ja(s)){if(s===47){if(i=r.src.slice(a,c).match(Ya),!i)return!1;}else if(i=r.src.slice(a,c).match(Za),!i)return!1;if(To[i[1].toLowerCase()]!==!0)return!1;if(n)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 Ri(r,e){var t=r.bMarks[e]+r.blkIndent,n=r.eMarks[e];return r.src.substr(t,n-t);}function ec(r,e,t,n){var s,i,o,a,c,l,d,u,g,b,_;if(e+2>t||(c=e+1,r.tShift[c]<r.blkIndent)||(o=r.bMarks[c]+r.tShift[c],o>=r.eMarks[c])||(s=r.src.charCodeAt(o),s!==124&&s!==45&&s!==58)||(i=Ri(r,e+1),!/^[-:| ]+$/.test(i))||(l=i.split("|"),l<=2))return!1;for(u=[],a=0;a<l.length;a++){if(g=l[a].trim(),!g){if(a===0||a===l.length-1)continue;return!1;}if(!/^:?-+:?$/.test(g))return!1;g.charCodeAt(g.length-1)===58?u.push(g.charCodeAt(0)===58?"center":"right"):g.charCodeAt(0)===58?u.push("left"):u.push("");}if(i=Ri(r,e).trim(),i.indexOf("|")===-1||(l=i.replace(/^\||\|$/g,"").split("|"),u.length!==l.length))return!1;if(n)return!0;for(r.tokens.push({type:"table_open",lines:b=[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<l.length;a++)r.tokens.push({type:"th_open",align:u[a],lines:[e,e+1],level:r.level++}),r.tokens.push({type:"inline",content:l[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:_=[e+2,0],level:r.level++}),c=e+2;c<t&&!(r.tShift[c]<r.blkIndent||(i=Ri(r,c).trim(),i.indexOf("|")===-1));c++){for(l=i.replace(/^\||\|$/g,"").split("|"),r.tokens.push({type:"tr_open",level:r.level++}),a=0;a<l.length;a++)r.tokens.push({type:"td_open",align:u[a],level:r.level++}),d=l[a].substring(l[a].charCodeAt(0)===124?1:0,l[a].charCodeAt(l[a].length-1)===124?l[a].length-1:l[a].length).trim(),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}),b[1]=_[1]=c,r.line=c,!0;}function Ps(r,e){var t,n,s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e];return s>=i||(n=r.src.charCodeAt(s++),n!==126&&n!==58)||(t=r.skipSpaces(s),s===t)||t>=i?-1:t;}function tc(r,e){var t,n,s=r.level+2;for(t=e+2,n=r.tokens.length-2;t<n;t++)r.tokens[t].level===s&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function nc(r,e,t,n){var s,i,o,a,c,l,d,u,g,b,_,v,C,N;if(n)return r.ddIndent<0?!1:Ps(r,e)>=0;if(d=e+1,r.isEmpty(d)&&++d>t||r.tShift[d]<r.blkIndent||(s=Ps(r,d),s<0)||r.level>=r.options.maxNesting)return!1;l=r.tokens.length,r.tokens.push({type:"dl_open",lines:c=[e,0],level:r.level++}),o=e,i=d;e:for(;;){for(N=!0,C=!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++}),v=r.tight,g=r.ddIndent,u=r.blkIndent,_=r.tShift[i],b=r.parentType,r.blkIndent=r.ddIndent=r.tShift[i]+2,r.tShift[i]=s-r.bMarks[i],r.tight=!0,r.parentType="deflist",r.parser.tokenize(r,i,t,!0),(!r.tight||C)&&(N=!1),C=r.line-i>1&&r.isEmpty(r.line-1),r.tShift[i]=_,r.tight=v,r.parentType=b,r.blkIndent=u,r.ddIndent=g,r.tokens.push({type:"dd_close",level:--r.level}),a[1]=d=r.line,d>=t||r.tShift[d]<r.blkIndent)break e;if(s=Ps(r,d),s<0)break;i=d;}if(d>=t||(o=d,r.isEmpty(o))||r.tShift[o]<r.blkIndent||(i=o+1,i>=t)||(r.isEmpty(i)&&i++,i>=t)||r.tShift[i]<r.blkIndent||(s=Ps(r,i),s<0))break;}return r.tokens.push({type:"dl_close",level:--r.level}),c[1]=d,r.line=d,N&&tc(r,l),!0;}function sc(r,e){var t,n,s,i,o,a=e+1,c;if(t=r.lineMax,a<t&&!r.isEmpty(a)){for(c=r.parser.ruler.getRules("paragraph");a<t&&!r.isEmpty(a);a++)if(!(r.tShift[a]-r.blkIndent>3)){for(s=!1,i=0,o=c.length;i<o;i++)if(c[i](r,a,t,!0)){s=!0;break;}if(s)break;}}return n=r.getLines(e,a,r.blkIndent,!1).trim(),r.line=a,n.length&&(r.tokens.push({type:"paragraph_open",tight:!1,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:n,level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"paragraph_close",tight:!1,level:r.level})),!0;}var Os=[["code",$a],["fences",ja,["paragraph","blockquote","list"]],["blockquote",Ga,["paragraph","blockquote","list"]],["hr",za,["paragraph","blockquote","list"]],["list",Va,["paragraph","blockquote"]],["footnote",Ka,["paragraph"]],["heading",Wa,["paragraph","blockquote"]],["lheading",Xa],["htmlblock",Qa,["paragraph","blockquote"]],["table",ec,["paragraph"]],["deflist",nc,["paragraph"]],["paragraph",sc]];function hr(){this.ruler=new tt();for(var r=0;r<Os.length;r++)this.ruler.push(Os[r][0],Os[r][1],{alt:(Os[r][2]||[]).slice()});}hr.prototype.tokenize=function(r,e,t){for(var n=this.ruler.getRules(""),s=n.length,i=e,o=!1,a,c;i<t&&(r.line=i=r.skipEmptyLines(i),!(i>=t||r.tShift[i]<r.blkIndent));){for(c=0;c<s&&(a=n[c](r,i,t,!1),!a);c++);if(r.tight=!o,r.isEmpty(r.line-1)&&(o=!0),i=r.line,i<t&&r.isEmpty(i)){if(o=!0,i++,i<t&&r.parentType==="list"&&r.isEmpty(i))break;r.line=i;}}};var ic=/[\n\t]/g,rc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,oc=/\u00a0/g;hr.prototype.parse=function(r,e,t,n){var s,i=0,o=0;if(!r)return[];r=r.replace(oc," "),r=r.replace(rc,"\n"),r.indexOf(" ")>=0&&(r=r.replace(ic,function(a,c){var l;return r.charCodeAt(c)===10?(i=c+1,o=0,a):(l=" ".slice((c-i-o)%4),o=c-i+1,l);})),s=new wn(r,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function ac(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 cc(r,e){for(var t=r.pos;t<r.posMax&&!ac(r.src.charCodeAt(t));)t++;return t===r.pos?!1:(e||(r.pending+=r.src.slice(r.pos,t)),r.pos=t,!0);}function lc(r,e){var t,n,s=r.pos;if(r.src.charCodeAt(s)!==10)return!1;if(t=r.pending.length-1,n=r.posMax,!e)if(t>=0&&r.pending.charCodeAt(t)===32){if(t>=1&&r.pending.charCodeAt(t-1)===32){for(var i=t-2;i>=0;i--)if(r.pending.charCodeAt(i)!==32){r.pending=r.pending.substring(0,i+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(s++;s<n&&r.src.charCodeAt(s)===32;)s++;return r.pos=s,!0;}var dr=[];for(var Kr=0;Kr<256;Kr++)dr.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){dr[r.charCodeAt(0)]=1;});function hc(r,e){var t,n=r.pos,s=r.posMax;if(r.src.charCodeAt(n)!==92)return!1;if(n++,n<s){if(t=r.src.charCodeAt(n),t<256&&dr[t]!==0)return e||(r.pending+=r.src[n]),r.pos+=2,!0;if(t===10){for(e||r.push({type:"hardbreak",level:r.level}),n++;n<s&&r.src.charCodeAt(n)===32;)n++;return r.pos=n,!0;}}return e||(r.pending+="\\"),r.pos++,!0;}function dc(r,e){var t,n,s,i,o,a=r.pos,c=r.src.charCodeAt(a);if(c!==96)return!1;for(t=a,a++,n=r.posMax;a<n&&r.src.charCodeAt(a)===96;)a++;for(s=r.src.slice(t,a),i=o=a;(i=r.src.indexOf("`",o))!==-1;){for(o=i+1;o<n&&r.src.charCodeAt(o)===96;)o++;if(o-i===s.length)return e||r.push({type:"code",content:r.src.slice(a,i).replace(/[ \n]+/g," ").trim(),block:!1,level:r.level}),r.pos=o,!0;}return e||(r.pending+=s),r.pos+=s.length,!0;}function uc(r,e){var t,n,s,i=r.posMax,o=r.pos,a,c;if(r.src.charCodeAt(o)!==126||e||o+4>=i||r.src.charCodeAt(o+1)!==126||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,c=r.src.charCodeAt(o+2),a===126)||c===126||c===32||c===10)return!1;for(n=o+2;n<i&&r.src.charCodeAt(n)===126;)n++;if(n>o+3)return r.pos+=n-o,e||(r.pending+=r.src.slice(o,n)),!0;for(r.pos=o+2,s=1;r.pos+1<i;){if(r.src.charCodeAt(r.pos)===126&&r.src.charCodeAt(r.pos+1)===126&&(a=r.src.charCodeAt(r.pos-1),c=r.pos+2<i?r.src.charCodeAt(r.pos+2):-1,c!==126&&a!==126&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=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=i,!0):(r.pos=o,!1);}function pc(r,e){var t,n,s,i=r.posMax,o=r.pos,a,c;if(r.src.charCodeAt(o)!==43||e||o+4>=i||r.src.charCodeAt(o+1)!==43||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,c=r.src.charCodeAt(o+2),a===43)||c===43||c===32||c===10)return!1;for(n=o+2;n<i&&r.src.charCodeAt(n)===43;)n++;if(n!==o+2)return r.pos+=n-o,e||(r.pending+=r.src.slice(o,n)),!0;for(r.pos=o+2,s=1;r.pos+1<i;){if(r.src.charCodeAt(r.pos)===43&&r.src.charCodeAt(r.pos+1)===43&&(a=r.src.charCodeAt(r.pos-1),c=r.pos+2<i?r.src.charCodeAt(r.pos+2):-1,c!==43&&a!==43&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=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=i,!0):(r.pos=o,!1);}function fc(r,e){var t,n,s,i=r.posMax,o=r.pos,a,c;if(r.src.charCodeAt(o)!==61||e||o+4>=i||r.src.charCodeAt(o+1)!==61||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,c=r.src.charCodeAt(o+2),a===61)||c===61||c===32||c===10)return!1;for(n=o+2;n<i&&r.src.charCodeAt(n)===61;)n++;if(n!==o+2)return r.pos+=n-o,e||(r.pending+=r.src.slice(o,n)),!0;for(r.pos=o+2,s=1;r.pos+1<i;){if(r.src.charCodeAt(r.pos)===61&&r.src.charCodeAt(r.pos+1)===61&&(a=r.src.charCodeAt(r.pos-1),c=r.pos+2<i?r.src.charCodeAt(r.pos+2):-1,c!==61&&a!==61&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=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=i,!0):(r.pos=o,!1);}function Wr(r){return r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122;}function Xr(r,e){var t=e,n,s,i,o=!0,a=!0,c=r.posMax,l=r.src.charCodeAt(e);for(n=e>0?r.src.charCodeAt(e-1):-1;t<c&&r.src.charCodeAt(t)===l;)t++;return t>=c&&(o=!1),i=t-e,i>=4?o=a=!1:(s=t<c?r.src.charCodeAt(t):-1,(s===32||s===10)&&(o=!1),(n===32||n===10)&&(a=!1),l===95&&(Wr(n)&&(o=!1),Wr(s)&&(a=!1))),{can_open:o,can_close:a,delims:i};}function mc(r,e){var t,n,s,i,o,a,c,l=r.posMax,d=r.pos,u=r.src.charCodeAt(d);if(u!==95&&u!==42||e)return!1;if(c=Xr(r,d),t=c.delims,!c.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<l;){if(r.src.charCodeAt(r.pos)===u){if(c=Xr(r,r.pos),n=c.delims,c.can_close){for(i=a.pop(),o=n;i!==o;){if(o<i){a.push(i-o);break;}if(o-=i,a.length===0)break;r.pos+=i,i=a.pop();}if(a.length===0){t=i,s=!0;break;}r.pos+=n;continue;}c.can_open&&a.push(n),r.pos+=n;continue;}r.parser.skipToken(r);}return s?(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=l,!0):(r.pos=d,!1);}var gc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function bc(r,e){var t,n,s=r.posMax,i=r.pos;if(r.src.charCodeAt(i)!==126||e||i+2>=s||r.level>=r.options.maxNesting)return!1;for(r.pos=i+1;r.pos<s;){if(r.src.charCodeAt(r.pos)===126){t=!0;break;}r.parser.skipToken(r);}return!t||i+1===r.pos||(n=r.src.slice(i+1,r.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=i,!1):(r.posMax=r.pos,r.pos=i+1,e||r.push({type:"sub",level:r.level,content:n.replace(gc,"$1")}),r.pos=r.posMax+1,r.posMax=s,!0);}var yc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Ec(r,e){var t,n,s=r.posMax,i=r.pos;if(r.src.charCodeAt(i)!==94||e||i+2>=s||r.level>=r.options.maxNesting)return!1;for(r.pos=i+1;r.pos<s;){if(r.src.charCodeAt(r.pos)===94){t=!0;break;}r.parser.skipToken(r);}return!t||i+1===r.pos||(n=r.src.slice(i+1,r.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=i,!1):(r.posMax=r.pos,r.pos=i+1,e||r.push({type:"sup",level:r.level,content:n.replace(yc,"$1")}),r.pos=r.posMax+1,r.posMax=s,!0);}function _c(r,e){var t,n,s,i,o,a,c,l,d=!1,u=r.pos,g=r.posMax,b=r.pos,_=r.src.charCodeAt(b);if(_===33&&(d=!0,_=r.src.charCodeAt(++b)),_!==91||r.level>=r.options.maxNesting||(t=b+1,n=ms(r,b),n<0))return!1;if(a=n+1,a<g&&r.src.charCodeAt(a)===40){for(a++;a<g&&(l=r.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a>=g)return!1;for(b=a,xo(r,a)?(i=r.linkContent,a=r.pos):i="",b=a;a<g&&(l=r.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<g&&b!==a&&Ao(r,a))for(o=r.linkContent,a=r.pos;a<g&&(l=r.src.charCodeAt(a),!(l!==32&&l!==10));a++);else o="";if(a>=g||r.src.charCodeAt(a)!==41)return r.pos=u,!1;a++;}else{if(r.linkLevel>0)return!1;for(;a<g&&(l=r.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<g&&r.src.charCodeAt(a)===91&&(b=a+1,a=ms(r,a),a>=0?s=r.src.slice(b,a++):a=b-1),s||(_typeof(s)>"u"&&(a=n+1),s=r.src.slice(t,n)),c=r.env.references[wo(s)],!c)return r.pos=u,!1;i=c.href,o=c.title;}return e||(r.pos=t,r.posMax=n,d?r.push({type:"image",src:i,title:o,alt:r.src.substr(t,n-t),level:r.level}):(r.push({type:"link_open",href:i,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=g,!0;}function vc(r,e){var t,n,s,i,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,n=ms(r,a+1),n<0)?!1:(e||(r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.list||(r.env.footnotes.list=[]),s=r.env.footnotes.list.length,r.pos=t,r.posMax=n,r.push({type:"footnote_ref",id:s,level:r.level}),r.linkLevel++,i=r.tokens.length,r.parser.tokenize(r),r.env.footnotes.list[s]={tokens:r.tokens.splice(i)},r.linkLevel--),r.pos=n+1,r.posMax=o,!0);}function Sc(r,e){var t,n,s,i,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(n=a+2;n<o;n++){if(r.src.charCodeAt(n)===32||r.src.charCodeAt(n)===10)return!1;if(r.src.charCodeAt(n)===93)break;}return n===a+2||n>=o||(n++,t=r.src.slice(a+2,n-1),_typeof(r.env.footnotes.refs[":"+t])>"u")?!1:(e||(r.env.footnotes.list||(r.env.footnotes.list=[]),r.env.footnotes.refs[":"+t]<0?(s=r.env.footnotes.list.length,r.env.footnotes.list[s]={label:t,count:0},r.env.footnotes.refs[":"+t]=s):s=r.env.footnotes.refs[":"+t],i=r.env.footnotes.list[s].count,r.env.footnotes.list[s].count++,r.push({type:"footnote_ref",id:s,subId:i,level:r.level})),r.pos=n,r.posMax=o,!0);}var xc=["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"],Ac=/^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/,wc=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Cc(r,e){var t,n,s,i,o,a=r.pos;return r.src.charCodeAt(a)!==60||(t=r.src.slice(a),t.indexOf(">")<0)?!1:(n=t.match(wc),n?xc.indexOf(n[1].toLowerCase())<0||(i=n[0].slice(1,-1),o=Di(i),!r.parser.validateLink(i))?!1:(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:i,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=n[0].length,!0):(s=t.match(Ac),s?(i=s[0].slice(1,-1),o=Di("mailto:"+i),r.parser.validateLink(o)?(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:i,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=s[0].length,!0):!1):!1));}function bi(r,e){return r=r.source,e=e||"",function t(n,s){return n?(s=s.source||s,r=r.replace(n,s),t):new RegExp(r,e);};}var Tc=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Rc=/[^"'=<>`\x00-\x20]+/,Ic=/'[^']*'/,Mc=/"[^"]*"/,kc=bi(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Rc)("single_quoted",Ic)("double_quoted",Mc)(),Lc=bi(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Tc)("attr_value",kc)(),Pc=bi(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",Lc)(),Oc=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Nc=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Bc=/<[?].*?[?]>/,Dc=/<![A-Z]+\s+[^>]*>/,Fc=/<!\[CDATA\[[\s\S]*?\]\]>/,Uc=bi(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Pc)("close_tag",Oc)("comment",Nc)("processing",Bc)("declaration",Dc)("cdata",Fc)();function Hc(r){var e=r|32;return e>=97&&e<=122;}function $c(r,e){var t,n,s,i=r.pos;return!r.options.html||(s=r.posMax,r.src.charCodeAt(i)!==60||i+2>=s)||(t=r.src.charCodeAt(i+1),t!==33&&t!==63&&t!==47&&!Hc(t))||(n=r.src.slice(i).match(Uc),!n)?!1:(e||r.push({type:"htmltag",content:r.src.slice(i,i+n[0].length),level:r.level}),r.pos+=n[0].length,!0);}var jc=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Gc=/^&([a-z][a-z0-9]{1,31});/i;function zc(r,e){var t,n,s,i=r.pos,o=r.posMax;if(r.src.charCodeAt(i)!==38)return!1;if(i+1<o){if(t=r.src.charCodeAt(i+1),t===35){if(s=r.src.slice(i).match(jc),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),r.pending+=vo(n)?Bi(n):Bi(65533)),r.pos+=s[0].length,!0;}else if(s=r.src.slice(i).match(Gc),s){var a=Eo(s[1]);if(s[1]!==a)return e||(r.pending+=a),r.pos+=s[0].length,!0;}}return e||(r.pending+="&"),r.pos++,!0;}var Ii=[["text",cc],["newline",lc],["escape",hc],["backticks",dc],["del",uc],["ins",pc],["mark",fc],["emphasis",mc],["sub",bc],["sup",Ec],["links",_c],["footnote_inline",vc],["footnote_ref",Sc],["autolink",Cc],["htmltag",$c],["entity",zc]];function yi(){this.ruler=new tt();for(var r=0;r<Ii.length;r++)this.ruler.push(Ii[r][0],Ii[r][1]);this.validateLink=qc;}yi.prototype.skipToken=function(r){var e=this.ruler.getRules(""),t=e.length,n=r.pos,s,i;if((i=r.cacheGet(n))>0){r.pos=i;return;}for(s=0;s<t;s++)if(e[s](r,!0)){r.cacheSet(n,r.pos);return;}r.pos++,r.cacheSet(n,r.pos);};yi.prototype.tokenize=function(r){for(var e=this.ruler.getRules(""),t=e.length,n=r.posMax,s,i;r.pos<n;){for(i=0;i<t&&(s=e[i](r,!1),!s);i++);if(s){if(r.pos>=n)break;continue;}r.pending+=r.src[r.pos++];}r.pending&&r.pushPending();};yi.prototype.parse=function(r,e,t,n){var s=new An(r,this,e,t,n);this.tokenize(s);};function qc(r){var e=["vbscript","javascript","file","data"],t=r.trim().toLowerCase();return t=_n(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var Vc={options:{html:!1,// Enable HTML tags in source
|
|
15
15
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
|
16
16
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
|
17
17
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
|
@@ -25,7 +25,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
|
25
25
|
// function (/*str, lang*/) { return ''; }
|
|
26
26
|
//
|
|
27
27
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
|
28
|
-
},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}},
|
|
28
|
+
},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}},Kc={options:{html:!1,// Enable HTML tags in source
|
|
29
29
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
|
30
30
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
|
31
31
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
|
@@ -40,7 +40,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
|
40
40
|
//
|
|
41
41
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
|
42
42
|
},components:{// Don't restrict core/block/inline rules
|
|
43
|
-
core:{},block:{},inline:{}}},
|
|
43
|
+
core:{},block:{},inline:{}}},Wc={options:{html:!0,// Enable HTML tags in source
|
|
44
44
|
xhtmlOut:!0,// Use '/' to close single tags (<br />)
|
|
45
45
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
|
46
46
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
|
@@ -54,141 +54,141 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
|
54
54
|
// function (/*str, lang*/) { return ''; }
|
|
55
55
|
//
|
|
56
56
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
|
57
|
-
},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}},
|
|
57
|
+
},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}},Xc={"default":Vc,full:Kc,commonmark:Wc};function Ro(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 Ct(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 yi(),this.block=new hr(),this.core=new Co(),this.renderer=new lr(),this.ruler=new tt(),this.options={},this.configure(Xc[r]),this.set(e||{});}Ct.prototype.set=function(r){_o(this.options,r);};Ct.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);});};Ct.prototype.use=function(r,e){return r(this,e),this;};Ct.prototype.parse=function(r,e){var t=new Ro(this,r,e);return this.core.process(t),t.tokens;};Ct.prototype.render=function(r,e){return e=e||{},this.renderer.render(this.parse(r,e),this.options,e);};Ct.prototype.parseInline=function(r,e){var t=new Ro(this,r,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};Ct.prototype.renderInline=function(r,e){return e=e||{},this.renderer.render(this.parseInline(r,e),this.options,e);};var cn=/*#__PURE__*/function(){function cn(){_classCallCheck(this,cn);}return _createClass(cn,null,[{key:"addPlugins",value:function addPlugins(e,t){var n=window.remarkable_plugins;if(n&&n.forEach(function(s){e.use(s.plugin,s.options);}),t!=null&&t.math){window.katex||(console.warn("window.katex not found, use chatElementRef.refreshMessages to re-render messages"),console.warn("See https://deepchat.dev/examples/externalModules"));var s=_typeof(t.math)=="object"?t.math.delimiter:"",i=_typeof(t.math)=="object"&&t.math.options?t.math.options:{};e.use(fa.katex.bind(this,i),{delimiter:s});}}},{key:"instantiate",value:function instantiate(e){if(e)return new Ct(_objectSpread(_objectSpread({},cn.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new Ct({highlight:function highlight(n,s){if(s&&t.getLanguage(s))try{return t.highlight(n,{language:s}).value;}catch(_unused3){console[p]("failed to setup the highlight dependency");}try{return t.highlightAuto(n).value;}catch(_unused4){console[p]("failed to automatically highlight messages");}return"";},html:!1,// Enable HTML tags in source
|
|
58
58
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
|
59
59
|
breaks:!0,// Convert '\n' in paragraphs into <br>
|
|
60
60
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
|
61
61
|
linkTarget:"_blank",// set target to open in a new tab
|
|
62
62
|
typographer:!0// Enable smartypants and other sweet transforms
|
|
63
|
-
});}else return new
|
|
64
|
-
};var
|
|
65
|
-
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s,
|
|
66
|
-
},{key:"extractParticularSharedStyles",value:function extractParticularSharedStyles(e,t){if(!(t!=null&&t.shared))return;var n=t.shared,s={outerContainer:{},innerContainer:{},bubble:{},media:{}};return e.forEach(function(
|
|
67
|
-
function setElementProps(e,t,n,s){var
|
|
68
|
-
},{key:"addMessage",value:function addMessage(e,t,n,s,
|
|
63
|
+
});}else return new Ct(cn.DEFAULT_PROPERTIES);}},{key:"createNew",value:function createNew(e){var t=cn.instantiate(e);return cn.addPlugins(t,e),t.inline.validateLink=function(){return!0;},t;}}]);}();cn.DEFAULT_PROPERTIES={breaks:!0,linkTarget:"_blank"// set target to open in a new tab
|
|
64
|
+
};var gs=cn;var Zc=/*#__PURE__*/function(){function Zc(e){_classCallCheck(this,Zc);this.storageKey="deep-chat-storage",this.maxMessages=1e3,this.trackInputText=!1,this.trackScrollHeight=!1,_typeof(e)=="object"&&(e.key&&(this.storageKey=e.key),e.maxMessages&&(this.maxMessages=e.maxMessages),e.inputText!==void 0&&(this.trackInputText=e.inputText),e.scrollHeight!==void 0&&(this.trackScrollHeight=e.scrollHeight),e.clear=this.clear.bind(this),ce.processBrowserStorage(this));}return _createClass(Zc,[{key:"get",value:function get(){var e=localStorage.getItem(this.storageKey);return e?JSON.parse(e):{messages:[]};}},{key:"set",value:function set(e,t,n){var s={messages:e,inputText:t,scrollHeight:n};localStorage.setItem(this.storageKey,ae(s));}},{key:"addMessages",value:function addMessages(e){var t=e.length-this.maxMessages;t<0&&(t=0);var n=e.slice(t,e.length),s=this.trackInputText||this.trackScrollHeight?localStorage.getItem(this.storageKey):void 0,i=s?JSON.parse(s):void 0;this.set(n,this.trackInputText?i==null?void 0:i.inputText:void 0,this.trackScrollHeight?i==null?void 0:i.scrollHeight:void 0);}},{key:"addInputText",value:function addInputText(e){if(!this.trackInputText)return;var t=localStorage.getItem(this.storageKey),n=t?JSON.parse(t):void 0;this.set((n==null?void 0:n.messages)||[],e,this.trackScrollHeight?n==null?void 0:n.scrollHeight:void 0);}},{key:"addScrollHeight",value:function addScrollHeight(e){if(!this.trackScrollHeight)return;var t=localStorage.getItem(this.storageKey),n=t?JSON.parse(t):void 0;this.set((n==null?void 0:n.messages)||[],this.trackInputText?n==null?void 0:n.inputText:void 0,e);}},{key:"clear",value:function clear(){localStorage.removeItem(this.storageKey);}}]);}();var Be=/*#__PURE__*/function(){function Be(){_classCallCheck(this,Be);}return _createClass(Be,null,[{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){if(n&&(Object.assign(e.outerContainer[E],n.outerContainer),Object.assign(e.innerContainer[E],n.innerContainer),Object.assign(e.bubbleElement[E],n.bubble),t)){var s=e.bubbleElement.children[0],i=s.tagName.toLocaleLowerCase()!=="a"?s:s.children[0];Object.assign(i[E],n.media);}}},{key:"applySideStyles",value:function applySideStyles(e,t,n,s){s&&(Be.applyCustomStylesToElements(e,n,s.shared),t===F?Be.applyCustomStylesToElements(e,n,s.user):(Be.applyCustomStylesToElements(e,n,s.ai),Be.applyCustomStylesToElements(e,n,s[t])));}},{key:"isElementsStyles",value:function isElementsStyles(e){return!!(e.outerContainer||e.innerContainer||e.bubble||e.media);}// prettier-ignore
|
|
65
|
+
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s,i){var o;i&&e[A]!==i?Be.isElementsStyles(i)?(Be.applyCustomStylesToElements(t,s,(o=e[A])==null?void 0:o.shared),Be.applyCustomStylesToElements(t,s,i)):(Be.applySideStyles(t,n,s,e[A]),Be.applySideStyles(t,n,s,i)):Be.applySideStyles(t,n,s,e[A]);}// prettier-ignore
|
|
66
|
+
},{key:"extractParticularSharedStyles",value:function extractParticularSharedStyles(e,t){if(!(t!=null&&t.shared))return;var n=t.shared,s={outerContainer:{},innerContainer:{},bubble:{},media:{}};return e.forEach(function(i){var o,a,c,l;s.outerContainer[i]=((o=n.outerContainer)==null?void 0:o[i])||"",s.innerContainer[i]=((a=n.innerContainer)==null?void 0:a[i])||"",s.bubble[i]=((c=n.bubble)==null?void 0:c[i])||"",s.media[i]=((l=n.media)==null?void 0:l[i])||"";}),s;}}]);}();var Se=/*#__PURE__*/function(){function Se(){_classCallCheck(this,Se);}return _createClass(Se,null,[{key:"setElementProps",value:// prettier-ignore
|
|
67
|
+
function setElementProps(e,t,n,s){var i;n!==Dt&&(e.applyCustomStyles(t,s,!0,(i=e.messageStyles)==null?void 0:i[n]),t.bubbleElement[f].add(uo));}// prettier-ignore
|
|
68
|
+
},{key:"addMessage",value:function addMessage(e,t,n,s,i){Se.setElementProps(e,t,n,s),i?e.elementRef.insertBefore(t.outerContainer,e.elementRef.firstChild):e.appendOuterContainerElemet(t.outerContainer);}},{key:"wrapInLink",value:function wrapInLink(e,t,n){var s=x("a");return s.href=t,s.download=n||ne,s.target="_blank",s.appendChild(e),s;}},{key:"isNonLinkableDataUrl",value:function isNonLinkableDataUrl(e,t){return!t.startsWith("data")||e===W?!1:e===gn&&t.startsWith("data:text/javascript")||!t.startsWith("data:image")&&!t.startsWith("data:application");}},{key:"processContent",value:function processContent(e,t,n,s){return!n||Se.isNonLinkableDataUrl(e,n)?t:Se.wrapInLink(t,n,s);}},{key:"waitToLoadThenScroll",value:function waitToLoadThenScroll(e){setTimeout(function(){e();},60);}},{key:"scrollDownOnImageLoad",value:function scrollDownOnImageLoad(e,t){if(e.startsWith("data"))Se.waitToLoadThenScroll(t);else try{fetch(e,{mode:"no-cors"})["catch"](function(){})["finally"](function(){Se.waitToLoadThenScroll(t);});}catch(_unused5){t();}}// The strategy is to emit the actual file reference in the `onMessage` event for the user to inspect it
|
|
69
69
|
// But it is not actually used by anything in the chat, hence it is removed when adding a message
|
|
70
70
|
// after the body has been stringified and parsed - the file reference will disappear, hence this readds it
|
|
71
|
-
},{key:"reAddFileRefToObject",value:function reAddFileRefToObject(e,t){var n;(n=e[m])==null||n.forEach(function(s,
|
|
72
|
-
},{key:"removeFileRef",value:function removeFileRef(e){var t=_objectSpread({},e);return delete t.ref,t;}},{key:"isAudioFile",value:function isAudioFile(e){var t=/\.(mp3|ogg|wav|aac|webm|4a)$/i,n=e.type,s=e.src;return n===q||(s==null?void 0:s.startsWith("data:audio"))||s&&t.test(s);}},{key:"isImageFile",value:function isImageFile(e){var t=e.type,n=e.src;return t===K||(n==null?void 0:n.startsWith("data:image"))||n&&Se.isImageFileExtension(n);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();var _n=/*#__PURE__*/function(){function _n(){_classCallCheck(this,_n);}return _createClass(_n,null,[{key:"onMessage",value:function onMessage(e,t,n){var r;var s=w({message:t,isHistory:n,isInitial:n});Se.reAddFileRefToObject(t,s.message),(r=e.onMessage)==null||r.call(e,s),e.dispatchEvent(new CustomEvent("message",{detail:s})),ce.fireOnNewMessage(e,s);}},{key:"onClearMessages",value:function onClearMessages(e){var t;(t=e.onClearMessages)==null||t.call(e),e.dispatchEvent(new CustomEvent("clear-messages"));}},{key:"onRender",value:function onRender(e){var t;(t=e.onComponentRender)==null||t.call(e,e),e.dispatchEvent(new CustomEvent("render",{detail:e}));}},{key:"onInput",value:function onInput(e,t,n){var r,o;var s=w({content:t,isUser:n});t[m]&&Se.reAddFileRefToObject(_defineProperty({},m,(r=t[m])==null?void 0:r.map(function(a){return{ref:a};})),s.content),(o=e.onInput)==null||o.call(e,s),e.dispatchEvent(new CustomEvent("input",{detail:s}));}},{key:"onError",value:function onError(e,t){var n;(n=e.onError)==null||n.call(e,t),e.dispatchEvent(new CustomEvent(p,{detail:t}));}}]);}();var Te=/*#__PURE__*/function(){function Te(){_classCallCheck(this,Te);}return _createClass(Te,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=x();return e[f].add("loading-history"),e.appendChild(x()),e.appendChild(x()),e.appendChild(x()),e.appendChild(x()),e;}},{key:"apply",value:function apply(e,t,n){vt.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=w(n),delete n.bubble),e.applyCustomStyles(t,"history",!1,n);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var a,c,l,d,u,g,b,_;e.bubbleElement[f].add(Te.CLASS);var s=n?Te.FULL_VIEW_CLASS:Te.SMALL_CLASS;e.outerContainer[f].add(s);var r=n?(d=(l=(c=(a=t.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.full)==null?void 0:d[R]:(_=(b=(g=(u=t.messageStyles)==null?void 0:u.loading)==null?void 0:g.history)==null?void 0:b.small)==null?void 0:_[R];Te.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==po&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",te),n=t.bubbleElement,s=Te.generateLoadingRingElement();return n.appendChild(s),t;}},{key:"addMessage",value:function addMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var r,o,a,c;var n=(c=(a=(o=(r=e.messageStyles)==null?void 0:r.loading)==null?void 0:o.history)==null?void 0:a.full)==null?void 0:c[L],s=n?At.createElements(e,n,te,!0,!0):Te.createDefaultElements(e);return Te.addLoadHistoryMessage(s,e,t),O.softRemRoleElements(s.innerContainer,e.avatar,e.name),s;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var n,s,r,o,a,c,l,d;if(t!=null&&t.outerContainer[f].contains(Te.FULL_VIEW_CLASS)){t.outerContainer[f].replace(Te.FULL_VIEW_CLASS,Te.SMALL_CLASS);var u=(o=(r=(s=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:s.history)==null?void 0:r.small)==null?void 0:o[R];u&&Te.apply(e,t,u);var g=(d=(l=(c=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.small)==null?void 0:d[L];return g&&(t.bubbleElement.innerHTML=g),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];Te.tryChangeViewToSmall(e,t)||Te.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();Te.CLASS="loading-history-message",Te.FULL_VIEW_CLASS="loading-history-message-full-view",Te.SMALL_CLASS="loading-history-message-small";var Dt=Te;var as=/*#__PURE__*/function(){function as(){_classCallCheck(this,as);}return _createClass(as,null,[{key:"setFade",value:function setFade(e,t){e[E].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(as.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e,t){var n;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:e[E].opacity="0";n=typeof t=="number"?t:as.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(s){setTimeout(function(){return s();},n);});case 1:e[E].opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();as.DEFAULT_FADE_MS=500;var Gs=as;var nn=/*#__PURE__*/function(){function nn(e,t,n){_classCallCheck(this,nn);if(this.hiddenElements=/* @__PURE__ */new Set(),this.isScrollButton=!1,this.isScrollingToBottom=!1,this._messages=e,t){var _s$R;var s={};_typeof(t)=="object"&&(s=w(t),s.onUpdate=t.onUpdate),(_s$R=s[R])!==null&&_s$R!==void 0?_s$R:s[R]={};var r="fit-content";s[R]["default"]=_objectSpread({borderRadius:"10px",width:r,height:r},s[R]["default"]),this.hiddenMessagesConfig=s,this.io=this.initIntersectionObserver(this._messages.elementRef);}if(n){var _s2$R;var _s2=_typeof(n)=="object"?w(n):{};(_s2$R=_s2[R])!==null&&_s2$R!==void 0?_s2$R:_s2[R]={},_s2[R]["default"]=_objectSpread({borderRadius:"50%",width:"1.4rem",height:"1.4rem"},_s2[R]["default"]),this.scrollButtonConfig=_s2;}this.element=this.createElement(),this._messages.elementRef.appendChild(this.element);}return _createClass(nn,[{key:"initIntersectionObserver",value:function initIntersectionObserver(e){var _this3=this;return new IntersectionObserver(function(t){t.forEach(function(n){var s;n.isIntersecting&&_this3.hiddenElements.has(n.target)&&(_this3.hiddenElements["delete"](n.target),(s=_this3.io)==null||s.unobserve(n.target),_this3.updateHiddenElement());});},{root:e,threshold:0.1});}},{key:"createElement",value:function createElement(){var _this4=this;var e=x();return e.id="scroll-button",V.assignButtonEvents(e,function(){var s,r,o;var t=_this4.isScrollButton?(s=_this4.scrollButtonConfig)==null?void 0:s.smoothScroll:(r=_this4.hiddenMessagesConfig)==null?void 0:r.smoothScroll,n=typeof t=="boolean"?t:!0;if(_this4.isScrollButton||((o=_this4.hiddenMessagesConfig)==null?void 0:o.clickScroll)==="last")V.scrollToBottom(_this4._messages,n),n&&_this4.element&&(nn.hideElement(_this4.element),_this4.isScrollingToBottom=!0,V.waitForScrollEnd(_this4._messages.elementRef,function(){_this4.isScrollingToBottom=!1;}));else{var a=_this4.hiddenElements.values().next().value;a&&_this4._messages.elementRef.scrollTo({left:0,top:a.offsetTop,behavior:n?"smooth":"auto"});}}),re.apply(this._messages,e),e;}},{key:"assignStyles",value:function assignStyles(e){if(!this.element)return;Object.assign(this.element[E],e[A]);var t=de.processStateful(e);Nt.add(this.element,t);}},{key:"updateHiddenElement",value:function updateHiddenElement(){var e,t;if(this.element){this.isScrollButton=!1;var n=this.hiddenElements.size;if(n===0){nn.hideElement(this.element);return;}var s="".concat(n," new message").concat(n===1?"":"s");if((e=this.hiddenMessagesConfig)!=null&&e.onUpdate){var r=this.hiddenMessagesConfig.onUpdate(s,n);this.element.innerHTML=r,re.apply(this._messages,this.element);}else this.element.innerHTML=s;(t=this.hiddenMessagesConfig)!=null&&t[R]&&this.assignStyles(this.hiddenMessagesConfig[R]),nn.displayElement(this.element);}}},{key:"updateHidden",value:function updateHidden(){var e,t;if(!this.isScrollingToBottom)if(this.hiddenMessagesConfig){var n=(e=this._messages.getFirstMessageContentEl())==null?void 0:e.outerContainer;n&&!V.isVisibleInParent(n,this._messages.elementRef)&&(this.hiddenElements.add(n),(t=this.io)==null||t.observe(n),this.updateHiddenElement());}else this.updateScroll();}},{key:"clearHidden",value:function clearHidden(){var _this5=this;this.hiddenElements.forEach(function(e){var t;return(t=_this5.io)==null?void 0:t.unobserve(e);}),this.hiddenElements.clear(),this.updateHiddenElement();}},{key:"displayScroll",value:function displayScroll(){var e,t;this.element&&this.element[E].opacity!==Pr&&(nn.displayElement(this.element),this.element.innerHTML=((e=this.scrollButtonConfig)==null?void 0:e.content)||'<span style="font-size: 1.2rem; user-select: none;">↓</span>',(t=this.scrollButtonConfig)!=null&&t[R]&&this.assignStyles(this.scrollButtonConfig[R]));}},{key:"updateScroll",value:function updateScroll(){var e;this.isScrollingToBottom||!this.scrollButtonConfig||(V.isScrollbarAtBottomOfElement(this._messages.elementRef,((e=this.scrollButtonConfig)==null?void 0:e.scrollDelta)||80)?this.element&&this.element[E].opacity!==Lr&&nn.hideElement(this.element):(this.displayScroll(),this.isScrollButton=!0));}}],[{key:"displayElement",value:function displayElement(e){e[E].opacity=Pr,e[E].pointerEvents="auto";}},{key:"hideElement",value:function hideElement(e){e[E].opacity=Lr,e[E].pointerEvents="none";}}]);}();var Wr="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",Oi="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAMAAAC/MqoPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAADNQTFRF////9vX18vLy/Pz86enp4+Li2tnZ1tbWzczM+fn57Ozs4N/f09LS0M/P5uXl7+/v3dzcwtncCAAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAZNSURBVHja7d3bdtsqEABQYABZSLH9/3+ZpnUsIcF5iOM6PfElNoMHMfPQdq3GmL0GkLhEUqLaUExnOtOZznSmM53pTGc605nOdKYznelMZzrTmV4LXSqllKyJDkob26xWq8Zae/iH0QoWTm9d1xur4WuypQJtTd+5dqn0VjcxzNO5/57mEBvdLo8Oron6aseWOjYOFkVvjQs3DmgyONMuht52EfztP+4hdu0i6LCO808/M8c1lE/fuPGej41uUzgdtoO/75N+2ELJ9I3b3//hPXbiMenm3pR/Jt4USgcLBIp4Bh10gqKVhvLo0klCxeSky96nKcj3siw6pJIL4XsoiQ7apyvMY/V3HHrSRioLopvEhSpTCn2TPEuwKYMOIX0tAxRBf/Hpa+lfSqBv9gi1FPsNfTrMAiVmIE/vJhz61FGnQxRIEYE4vfNYdN8Rp6MlHaHotHTn8ejekaZPAjEmyvQWdZFTtYTpXqCGJ0zvcek9Yfoel76nS0ffv1NMp1ca+pkgyfRCGind4L7OWWc605l+cxjsyhqy9AGbPpClc1/nvl5VX0c/3Alk6RU3+Am7shNZ+h6bvidLr7jBB+zKBrL0irOOudmIUDzTmf5gIP+iEuXtRuTVaEmY/oZLfyNMrzjryPc0gerMTdpVg0tvjJUU6bLPcGOoUv46SLL6Wi8yhLf06C7TUyekI0efRaaYqdFltkeNpPumRPSMDxgBYvSM035FrKAmH72hRW99PrpvSdEHkTEGUvSsK3yKVDkuJ92RohcZaehzzirPpOg+J92Tolfc4Cumx5xVXpGiZ34+ICX6W84qv5GiR5NPbiIpOv6BCoSvSkTX+eiaGP092zINvBOj4x8mSf9FqejvNo/cvpOji19ZbmviL0GPLsYMFzgzCor0+Bv/ePDvSJKOb9dJ5UlnbnEHiHgzv6cdTpJOWuc/u3FEucLDOL75xGtBiefrcwgoC9NDSH/jkH6pAuXmBqPQ9HSUPVdZBH1GGOrMXAQdYxcKZfxAoK+KKBKFLosoEoX+u4giUehz8jlcnAuhp78I46yDYNAd+QLR6K+pr+yvxdBTHyVDubQh0UfSxaHSd0lbvNkVRE87JGOtc+PQd2QLQ6fHhJkKsSh6yg13tO08JPprsgrrXWH0dJd2vH1MLPprot4eXoujpzrdhngiD40ek2y92lggPcnWa8qN1Yz0BFuvZhRl0uOfR0v4Ewuli/Bg4Qr3lArqGdndQ3UPO1EunXYwnelMZzrTmc50pjOd6UxnOtOZznSmM53pTGf6kuj6oedFKV0s3fX6sX1S3bsi6a4PD7+/YAqYeBw6pIB/4qEgOqxdSPbGiim4NRRCbzs3Jj0L4UfXtQXQVRfn5IdA/Bw7RZzurEV6EtdsLeGXkIPuA+K1UoVeA0l62zmN/LqfSSft9KkepmoRuvi3nd5uKNFB9zbbXEANqdr941XO0NJx2v2jdJenpf+/3bvn0ts16ph+sd6hX7dPo2+2cZzE02Ia43bzDHqr+2Evnhz74ZHU30ffbKOeng1/NPV30Ns1gYQnSP2P6e65Pfxc6h02XZqXQCjhJ6kPL6bFo4NrGvAU4UII4SE2P1vQuZkuOxckVfehisF1MjUddN/MZBN+kvq5uf0O/xa66gyNS9ktMWlz44rO1Z8C19i5FPdHzPamXn+F3hryPfxMr78+4F+kq22kO6Rf6fUQt+puuustyWv4rbG3l/duztFB96GYoe1cTBdXMr+nw9qVM6ZfxOvzezff0nXi/ZOndvrR6Zvpm0c3h6nhdb+5iS7tsIim/qXZD9+97/Jf+rpZ5BET1ayv0GUzLhEuhBBjIy/RdVPgndutIRt9nt7p5cKFEEJ3Z+jQFDZL+XnMDXxHB73gxn5s9Kc3d3/pFciFkN/QTSXHJpX5l66gDrkQoP6hL3xsPw39la4qOiV8tH78XeSbue6N9mvWa6J/ybpc1CT1Wnh5Qq9meP8IOKH3ddH7E/ri1iYux/SXDrXR4UiPdck/wUpU+FtPf6/orja6O9KL3l56LOvVxe5Ib2qjN0d6Vbex4ghWlU3bPqI90If66MNng680FNpbJijH6kCvaF3uMzQ3+IrpFerV4Y9dffQdN3im10ivbuImhD3Qq5u4HdZkua8znelMZ/pS4z9CPVKkxowNxgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wMy0yN1QxNTo0NToxNSswMDowMN1xSg4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDMtMjdUMTU6NDU6MTUrMDA6MDCsLPKyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAABJRU5ErkJggg==";var Ro=/*#__PURE__*/function(){function Ro(e){_classCallCheck(this,Ro);this.className=e;}return _createClass(Ro,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e)[E]).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e)[E].visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e)[f].add("role-hidden");}}]);}();var Tt=/*#__PURE__*/function(_Ro){function Tt(e){var _this6;_classCallCheck(this,Tt);_this6=_callSuper(this,Tt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(Tt,_Ro);return _createClass(Tt,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._avatars=="boolean"?void 0:this._avatars,s=this.createAvatar(t,n),r=this.getPosition(t,n);s[f].add(r===Jt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Jt?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var r,o,a,c,l;var n=x("img");e===F?(n[T]=((r=t==null?void 0:t[F])==null?void 0:r[T])||((o=t==null?void 0:t[A])==null?void 0:o[T])||Oi,n.onerror=Tt.errorFallback.bind(this,Oi)):(n[T]=((a=t==null?void 0:t[e])==null?void 0:a[T])||((c=t==null?void 0:t[te])==null?void 0:c[T])||((l=t==null?void 0:t[A])==null?void 0:l[T])||Wr,n.onerror=Tt.errorFallback.bind(this,Wr)),n[f].add("avatar"),n.alt="".concat(e," avatar");var s=x();return s[f].add(this.className),s.appendChild(n),t&&Tt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,r,o,a,c,l;var n=ce.processPosition((r=(s=t==null?void 0:t[e])==null?void 0:s[R])==null?void 0:r.position);return e!==F&&(n!==null&&n!==void 0?n:n=(a=(o=t==null?void 0:t.ai)==null?void 0:o[R])==null?void 0:a.position),n!==null&&n!==void 0?n:n=(l=(c=t==null?void 0:t[A])==null?void 0:c[R])==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===F?uo:Jt,n;}}],[{key:"errorFallback",value:function errorFallback(e,t){var n=t.target;n.onerror=null,n[T]=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){Object.assign(e[E],n.container),Object.assign(t[E],n.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){var r,o,a,c;if((r=n[A])!=null&&r[R]&&Tt.applyCustomStylesToElements(e,t,n[A][R]),s===F)(o=n.user)!=null&&o[R]&&Tt.applyCustomStylesToElements(e,t,n.user[R]);else{(a=n.ai)!=null&&a[R]&&Tt.applyCustomStylesToElements(e,t,n.ai[R]);var l=(c=n[s])==null?void 0:c[R];l&&Tt.applyCustomStylesToElements(e,t,l);}}}]);}(Ro);var ts=/*#__PURE__*/function(_Ro2){function ts(e){var _this7;_classCallCheck(this,ts);_this7=_callSuper(this,ts,["name"]),_this7._names=e;return _this7;}_inherits(ts,_Ro2);return _createClass(ts,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),r=ts.getPosition(t,n);s[f].add(r===Jt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===Jt?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=x();return n[f].add(this.className),n.textContent=ts.getNameText(e,t),ts.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,r,o;var n=ce.processPosition((s=t==null?void 0:t[e])==null?void 0:s.position);return e!==F&&(n!==null&&n!==void 0?n:n=(r=t==null?void 0:t[te])==null?void 0:r.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[A])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===F?uo:Jt,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,r,o,a;Object.assign(e[E],(s=n[A])==null?void 0:s[E]),t===F?Object.assign(e[E],(r=n[F])==null?void 0:r[E]):(Object.assign(e[E],(o=n[te])==null?void 0:o[E]),Object.assign(e[E],(a=n[t])==null?void 0:a[E]));}},{key:"getNameText",value:function getNameText(e,t){var n,s,r,o,a,c;return e===F?((n=t[F])==null?void 0:n[h])||((s=t[A])==null?void 0:s[h])||"User":e===te?((r=t[te])==null?void 0:r[h])||((o=t[A])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[A])==null?void 0:c[h])||e;}}]);}(Ro);var $e=/*#__PURE__*/function(){function $e(e){var _this8=this;_classCallCheck(this,$e);var t,n,s,r;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=$e.createContainerElement(),this.messageStyles=ce.processMessageStyles(e.messageStyles),this._remarkable=ms.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new Tt(e.avatars)),e.names&&(this.name=new ts(e.names)),e.browserStorage&&(this.browserStorage=new Xc(e.browserStorage)),this._onMessage=_n.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),(e.hiddenMessages||e.scrollButton)&&(this.scrollButton=new nn(this,e.hiddenMessages,e.scrollButton)),this.focusMode=ce.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=x(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Gs.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||ce.processStreamHTMLWrappers((s=e.connect)==null?void 0:s.stream),typeof this.focusMode!="boolean"&&((r=this.focusMode)==null?void 0:r.streamAutoScroll)===!1&&(this.autoScrollAllowed=!1),e.maxVisibleMessages&&(this.maxVisibleMessages=e.maxVisibleMessages),setTimeout(function(){_this8.submitUserMessage=e.submitUserMessage;});}return _createClass($e,[{key:"addNewTextMessage",value:function addNewTextMessage(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(n!=null&&n.status){var o=this.overwriteText(t,e,this.messageElementRefs);if(o)return o;n.status=!1;}var r=s?this.createAndPrependNewMessageElement(e,t,s):this.createAndAppendNewMessageElement(e,t);return r.bubbleElement[f].add($e.TEXT_BUBBLE_CLASS),this.applyCustomStyles(r,t,!1),O.fillEmptyMessageElement(r.bubbleElement,e),r;}// prettier-ignore
|
|
73
|
-
},{key:"overwriteText",value:function overwriteText(e,t,n){var s=
|
|
71
|
+
},{key:"reAddFileRefToObject",value:function reAddFileRefToObject(e,t){var n;(n=e[m])==null||n.forEach(function(s,i){var o;s.ref&&(o=t[m])!=null&&o[i]&&(t[m][i].ref=s.ref);});}// the chat does not use the actual file
|
|
72
|
+
},{key:"removeFileRef",value:function removeFileRef(e){var t=_objectSpread({},e);return delete t.ref,t;}},{key:"isAudioFile",value:function isAudioFile(e){var t=/\.(mp3|ogg|wav|aac|webm|4a)$/i,n=e.type,s=e.src;return n===G||(s==null?void 0:s.startsWith("data:audio"))||s&&t.test(s);}},{key:"isImageFile",value:function isImageFile(e){var t=e.type,n=e.src;return t===W||(n==null?void 0:n.startsWith("data:image"))||n&&Se.isImageFileExtension(n);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();var vn=/*#__PURE__*/function(){function vn(){_classCallCheck(this,vn);}return _createClass(vn,null,[{key:"onMessage",value:function onMessage(e,t,n){var i;var s=w({message:t,isHistory:n,isInitial:n});Se.reAddFileRefToObject(t,s.message),(i=e.onMessage)==null||i.call(e,s),e.dispatchEvent(new CustomEvent("message",{detail:s})),ce.fireOnNewMessage(e,s);}},{key:"onClearMessages",value:function onClearMessages(e){var t;(t=e.onClearMessages)==null||t.call(e),e.dispatchEvent(new CustomEvent("clear-messages"));}},{key:"onRender",value:function onRender(e){var t;(t=e.onComponentRender)==null||t.call(e,e),e.dispatchEvent(new CustomEvent("render",{detail:e}));}},{key:"onInput",value:function onInput(e,t,n){var i,o;var s=w({content:t,isUser:n});t[m]&&Se.reAddFileRefToObject(_defineProperty({},m,(i=t[m])==null?void 0:i.map(function(a){return{ref:a};})),s.content),(o=e.onInput)==null||o.call(e,s),e.dispatchEvent(new CustomEvent("input",{detail:s}));}},{key:"onError",value:function onError(e,t){var n;(n=e.onError)==null||n.call(e,t),e.dispatchEvent(new CustomEvent(p,{detail:t}));}}]);}();var Te=/*#__PURE__*/function(){function Te(){_classCallCheck(this,Te);}return _createClass(Te,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=x();return e[f].add("loading-history"),e.appendChild(x()),e.appendChild(x()),e.appendChild(x()),e.appendChild(x()),e;}},{key:"apply",value:function apply(e,t,n){St.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=w(n),delete n.bubble),e.applyCustomStyles(t,"history",!1,n);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var a,c,l,d,u,g,b,_;e.bubbleElement[f].add(Te.CLASS);var s=n?Te.FULL_VIEW_CLASS:Te.SMALL_CLASS;e.outerContainer[f].add(s);var i=n?(d=(l=(c=(a=t.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.full)==null?void 0:d[R]:(_=(b=(g=(u=t.messageStyles)==null?void 0:u.loading)==null?void 0:g.history)==null?void 0:b.small)==null?void 0:_[R];Te.apply(t,e,i);var o=t.elementRef;n&&t.elementRef.id!==fo&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",te),n=t.bubbleElement,s=Te.generateLoadingRingElement();return n.appendChild(s),t;}},{key:"addMessage",value:function addMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var i,o,a,c;var n=(c=(a=(o=(i=e.messageStyles)==null?void 0:i.loading)==null?void 0:o.history)==null?void 0:a.full)==null?void 0:c[L],s=n?wt.createElements(e,n,te,!0,!0):Te.createDefaultElements(e);return Te.addLoadHistoryMessage(s,e,t),B.softRemRoleElements(s.innerContainer,e.avatar,e.name),s;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var n,s,i,o,a,c,l,d;if(t!=null&&t.outerContainer[f].contains(Te.FULL_VIEW_CLASS)){t.outerContainer[f].replace(Te.FULL_VIEW_CLASS,Te.SMALL_CLASS);var u=(o=(i=(s=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:s.history)==null?void 0:i.small)==null?void 0:o[R];u&&Te.apply(e,t,u);var g=(d=(l=(c=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.small)==null?void 0:d[L];return g&&(t.bubbleElement.innerHTML=g),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];Te.tryChangeViewToSmall(e,t)||Te.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();Te.CLASS="loading-history-message",Te.FULL_VIEW_CLASS="loading-history-message-full-view",Te.SMALL_CLASS="loading-history-message-small";var Ft=Te;var as=/*#__PURE__*/function(){function as(){_classCallCheck(this,as);}return _createClass(as,null,[{key:"setFade",value:function setFade(e,t){e[E].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(as.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e,t){var n;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:e[E].opacity="0";n=typeof t=="number"?t:as.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(s){setTimeout(function(){return s();},n);});case 1:e[E].opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();as.DEFAULT_FADE_MS=500;var Vs=as;var sn=/*#__PURE__*/function(){function sn(e,t,n){_classCallCheck(this,sn);if(this.hiddenElements=/* @__PURE__ */new Set(),this.isScrollButton=!1,this.isScrollingToBottom=!1,this._messages=e,t){var _s$R;var s={};_typeof(t)=="object"&&(s=w(t),s.onUpdate=t.onUpdate),(_s$R=s[R])!==null&&_s$R!==void 0?_s$R:s[R]={};var i="fit-content";s[R]["default"]=_objectSpread({borderRadius:"10px",width:i,height:i},s[R]["default"]),this.hiddenMessagesConfig=s,this.io=this.initIntersectionObserver(this._messages.elementRef);}if(n){var _s2$R;var _s2=_typeof(n)=="object"?w(n):{};(_s2$R=_s2[R])!==null&&_s2$R!==void 0?_s2$R:_s2[R]={},_s2[R]["default"]=_objectSpread({borderRadius:"50%",width:"1.4rem",height:"1.4rem"},_s2[R]["default"]),this.scrollButtonConfig=_s2;}this.element=this.createElement(),this._messages.elementRef.appendChild(this.element);}return _createClass(sn,[{key:"initIntersectionObserver",value:function initIntersectionObserver(e){var _this3=this;return new IntersectionObserver(function(t){t.forEach(function(n){var s;n.isIntersecting&&_this3.hiddenElements.has(n.target)&&(_this3.hiddenElements["delete"](n.target),(s=_this3.io)==null||s.unobserve(n.target),_this3.updateHiddenElement());});},{root:e,threshold:0.1});}},{key:"createElement",value:function createElement(){var _this4=this;var e=x();return e.id="scroll-button",q.assignButtonEvents(e,function(){var s,i,o;var t=_this4.isScrollButton?(s=_this4.scrollButtonConfig)==null?void 0:s.smoothScroll:(i=_this4.hiddenMessagesConfig)==null?void 0:i.smoothScroll,n=typeof t=="boolean"?t:!0;if(_this4.isScrollButton||((o=_this4.hiddenMessagesConfig)==null?void 0:o.clickScroll)==="last")q.scrollToBottom(_this4._messages,n),n&&_this4.element&&(sn.hideElement(_this4.element),_this4.isScrollingToBottom=!0,q.waitForScrollEnd(_this4._messages.elementRef,function(){_this4.isScrollingToBottom=!1;}));else{var a=_this4.hiddenElements.values().next().value;a&&_this4._messages.elementRef.scrollTo({left:0,top:a.offsetTop,behavior:n?"smooth":"auto"});}}),re.apply(this._messages,e),e;}},{key:"assignStyles",value:function assignStyles(e){if(!this.element)return;Object.assign(this.element[E],e[A]);var t=de.processStateful(e);Nt.add(this.element,t);}},{key:"updateHiddenElement",value:function updateHiddenElement(){var e,t;if(this.element){this.isScrollButton=!1;var n=this.hiddenElements.size;if(n===0){sn.hideElement(this.element);return;}var s="".concat(n," new message").concat(n===1?"":"s");if((e=this.hiddenMessagesConfig)!=null&&e.onUpdate){var i=this.hiddenMessagesConfig.onUpdate(s,n);this.element.innerHTML=i,re.apply(this._messages,this.element);}else this.element.innerHTML=s;(t=this.hiddenMessagesConfig)!=null&&t[R]&&this.assignStyles(this.hiddenMessagesConfig[R]),sn.displayElement(this.element);}}},{key:"updateHidden",value:function updateHidden(){var e,t;if(!this.isScrollingToBottom)if(this.hiddenMessagesConfig){var n=(e=this._messages.getFirstMessageContentEl())==null?void 0:e.outerContainer;n&&!q.isVisibleInParent(n,this._messages.elementRef)&&(this.hiddenElements.add(n),(t=this.io)==null||t.observe(n),this.updateHiddenElement());}else this.updateScroll();}},{key:"clearHidden",value:function clearHidden(){var _this5=this;this.hiddenElements.forEach(function(e){var t;return(t=_this5.io)==null?void 0:t.unobserve(e);}),this.hiddenElements.clear(),this.updateHiddenElement();}},{key:"displayScroll",value:function displayScroll(){var e,t;this.element&&this.element[E].opacity!==Nr&&(sn.displayElement(this.element),this.element.innerHTML=((e=this.scrollButtonConfig)==null?void 0:e.content)||'<span style="font-size: 1.2rem; user-select: none;">↓</span>',(t=this.scrollButtonConfig)!=null&&t[R]&&this.assignStyles(this.scrollButtonConfig[R]));}},{key:"updateScroll",value:function updateScroll(){var e;this.isScrollingToBottom||!this.scrollButtonConfig||(q.isScrollbarAtBottomOfElement(this._messages.elementRef,((e=this.scrollButtonConfig)==null?void 0:e.scrollDelta)||80)?this.element&&this.element[E].opacity!==Or&&sn.hideElement(this.element):(this.displayScroll(),this.isScrollButton=!0));}}],[{key:"displayElement",value:function displayElement(e){e[E].opacity=Nr,e[E].pointerEvents="auto";}},{key:"hideElement",value:function hideElement(e){e[E].opacity=Or,e[E].pointerEvents="none";}}]);}();var Zr="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",Fi="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 Io=/*#__PURE__*/function(){function Io(e){_classCallCheck(this,Io);this.className=e;}return _createClass(Io,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e)[E]).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e)[E].visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e)[f].add("role-hidden");}}]);}();var Rt=/*#__PURE__*/function(_Io){function Rt(e){var _this6;_classCallCheck(this,Rt);_this6=_callSuper(this,Rt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(Rt,_Io);return _createClass(Rt,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._avatars=="boolean"?void 0:this._avatars,s=this.createAvatar(t,n),i=this.getPosition(t,n);s[f].add(i===Qt?"start-item-position":"end-item-position"),e.insertAdjacentElement(i===Qt?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var i,o,a,c,l;var n=x("img");e===F?(n[T]=((i=t==null?void 0:t[F])==null?void 0:i[T])||((o=t==null?void 0:t[A])==null?void 0:o[T])||Fi,n.onerror=Rt.errorFallback.bind(this,Fi)):(n[T]=((a=t==null?void 0:t[e])==null?void 0:a[T])||((c=t==null?void 0:t[te])==null?void 0:c[T])||((l=t==null?void 0:t[A])==null?void 0:l[T])||Zr,n.onerror=Rt.errorFallback.bind(this,Zr)),n[f].add("avatar"),n.alt="".concat(e," avatar");var s=x();return s[f].add(this.className),s.appendChild(n),t&&Rt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,i,o,a,c,l;var n=ce.processPosition((i=(s=t==null?void 0:t[e])==null?void 0:s[R])==null?void 0:i.position);return e!==F&&(n!==null&&n!==void 0?n:n=(a=(o=t==null?void 0:t.ai)==null?void 0:o[R])==null?void 0:a.position),n!==null&&n!==void 0?n:n=(l=(c=t==null?void 0:t[A])==null?void 0:c[R])==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===F?po:Qt,n;}}],[{key:"errorFallback",value:function errorFallback(e,t){var n=t.target;n.onerror=null,n[T]=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){Object.assign(e[E],n.container),Object.assign(t[E],n.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){var i,o,a,c;if((i=n[A])!=null&&i[R]&&Rt.applyCustomStylesToElements(e,t,n[A][R]),s===F)(o=n.user)!=null&&o[R]&&Rt.applyCustomStylesToElements(e,t,n.user[R]);else{(a=n.ai)!=null&&a[R]&&Rt.applyCustomStylesToElements(e,t,n.ai[R]);var l=(c=n[s])==null?void 0:c[R];l&&Rt.applyCustomStylesToElements(e,t,l);}}}]);}(Io);var ts=/*#__PURE__*/function(_Io2){function ts(e){var _this7;_classCallCheck(this,ts);_this7=_callSuper(this,ts,["name"]),_this7._names=e;return _this7;}_inherits(ts,_Io2);return _createClass(ts,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),i=ts.getPosition(t,n);s[f].add(i===Qt?"start-item-position":"end-item-position"),e.insertAdjacentElement(i===Qt?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=x();return n[f].add(this.className),n.textContent=ts.getNameText(e,t),ts.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,i,o;var n=ce.processPosition((s=t==null?void 0:t[e])==null?void 0:s.position);return e!==F&&(n!==null&&n!==void 0?n:n=(i=t==null?void 0:t[te])==null?void 0:i.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[A])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===F?po:Qt,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,i,o,a;Object.assign(e[E],(s=n[A])==null?void 0:s[E]),t===F?Object.assign(e[E],(i=n[F])==null?void 0:i[E]):(Object.assign(e[E],(o=n[te])==null?void 0:o[E]),Object.assign(e[E],(a=n[t])==null?void 0:a[E]));}},{key:"getNameText",value:function getNameText(e,t){var n,s,i,o,a,c;return e===F?((n=t[F])==null?void 0:n[h])||((s=t[A])==null?void 0:s[h])||"User":e===te?((i=t[te])==null?void 0:i[h])||((o=t[A])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[A])==null?void 0:c[h])||e;}}]);}(Io);var je=/*#__PURE__*/function(){function je(e){var _this8=this;_classCallCheck(this,je);var t,n,s,i;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=je.createContainerElement(),this.messageStyles=ce.processMessageStyles(e.messageStyles),this._remarkable=gs.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new Rt(e.avatars)),e.names&&(this.name=new ts(e.names)),e.browserStorage&&(this.browserStorage=new Zc(e.browserStorage)),this._onMessage=vn.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),(e.hiddenMessages||e.scrollButton)&&(this.scrollButton=new sn(this,e.hiddenMessages,e.scrollButton)),this.focusMode=ce.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=x(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Vs.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||ce.processStreamHTMLWrappers((s=e.connect)==null?void 0:s.stream),typeof this.focusMode!="boolean"&&((i=this.focusMode)==null?void 0:i.streamAutoScroll)===!1&&(this.autoScrollAllowed=!1),e.maxVisibleMessages&&(this.maxVisibleMessages=e.maxVisibleMessages),setTimeout(function(){_this8.submitUserMessage=e.submitUserMessage;});}return _createClass(je,[{key:"addNewTextMessage",value:function addNewTextMessage(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(n!=null&&n.status){var o=this.overwriteText(t,e,this.messageElementRefs);if(o)return o;n.status=!1;}var i=s?this.createAndPrependNewMessageElement(e,t,s):this.createAndAppendNewMessageElement(e,t);return i.bubbleElement[f].add(je.TEXT_BUBBLE_CLASS),this.applyCustomStyles(i,t,!1),B.fillEmptyMessageElement(i.bubbleElement,e),i;}// prettier-ignore
|
|
73
|
+
},{key:"overwriteText",value:function overwriteText(e,t,n){var s=B.overwriteMessage(this.messageToElements,n,t,e,"text",je.TEXT_BUBBLE_CLASS);return s&&this.renderText(s.bubbleElement,t,e),s;}},{key:"createAndAppendNewMessageElement",value:function createAndAppendNewMessageElement(e,t){var n=this.createNewMessageElement(e,t);return this.appendOuterContainerElemet(n.outerContainer,this.focusMode?t:void 0),n;}},{key:"createNewGroupElementFocusMode",value:function createNewGroupElementFocusMode(){var t;(t=this._lastGroupMessagesElement)==null||t[f].remove(je.LAST_GROUP_MESSAGES_ACTIVE);var e=x();(this.messageToElements.length>1||this.messageToElements.length===1&&this.messageToElements[0][0][S]!==F)&&e[f].add(je.LAST_GROUP_MESSAGES_ACTIVE),this._lastGroupMessagesElement=e;}},{key:"appendOuterContainerElemet",value:function appendOuterContainerElemet(e,t){var n;this.focusMode&&(t===F||!this._lastGroupMessagesElement)&&this.createNewGroupElementFocusMode(),(n=this._lastGroupMessagesElement)==null||n.appendChild(e),this._lastGroupMessagesElement&&(this.focusMode||!this.elementRef.contains(this._lastGroupMessagesElement))&&this.elementRef.appendChild(this._lastGroupMessagesElement);}},{key:"createAndPrependNewMessageElement",value:function createAndPrependNewMessageElement(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var i=this.createNewMessageElement(e,t,n,s);if(n&&(o=this.elementRef.firstChild)!=null&&o[f].contains(je.INTRO_CLASS)){this.elementRef.firstChild.insertAdjacentElement("afterend",i.outerContainer);var a=this.messageElementRefs[0];this.messageElementRefs[0]=this.messageElementRefs[1],this.messageElementRefs[1]=a;}else this.elementRef.insertBefore(i.outerContainer,this.elementRef.firstChild);return i;}},{key:"createMessageElementsOnOrientation",value:function createMessageElementsOnOrientation(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;return n?this.createAndPrependNewMessageElement(e,t,n,s):this.createNewMessageElement(e,t,n,s);}},{key:"getNumberOfContentMessages",value:function getNumberOfContentMessages(){var t,n;var e=this.messageElementRefs.length;return(n=(t=this.messageElementRefs[e-1])==null?void 0:t.bubbleElement)!=null&&n[f].contains(St.BUBBLE_CLASS)?e-1:e;}},{key:"createNewMessageElement",value:function createNewMessageElement(e,t){var _this9=this;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;!s&&this.getNumberOfContentMessages()>=this.maxVisibleMessages&&setTimeout(function(){return _this9.removeFirstMessage();}),s||(o=this._introPanel)==null||o.hide();var i=this.messageElementRefs[this.messageElementRefs.length-1];return Ft.changeFullViewToSmall(this),!n&&je.isTemporaryElement(i)&&(this.revealRoleElementsIfTempRemoved(i,t),this.removeLastMessage()),this.createMessageElements(e,t,n);}// this can be tested by having an ai message, then a temp ai message with html that submits new user message:
|
|
74
74
|
// https://github.com/OvidijusParsiunas/deep-chat/issues/258
|
|
75
75
|
// prettier-ignore
|
|
76
|
-
},{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&
|
|
77
|
-
function addInnerContainerElements(e,t,n){var s=this.messageElementRefs[this.messageElementRefs.length-1];return
|
|
78
|
-
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){e&&this.messageStyles&&
|
|
79
|
-
},{key:"renderText",value:function renderText(e,t,n){var _re$tryAddWrapper2=re.tryAddWrapper(e,t,this._customWrappers,n),s=_re$tryAddWrapper2.contentEl,
|
|
80
|
-
},{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this0=this;this._remarkable=
|
|
76
|
+
},{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&At.isElementTemporary(e)){var n=this.messageElementRefs[this.messageElementRefs.length-2];n&&this.messageToElements.length>0&&!e.bubbleElement[f].contains(B.getRoleClass(t))&&B.revealRoleElements(n.innerContainer,this.avatar,this.name);}}},{key:"createElements",value:function createElements(e,t){var n=je.createBaseElements(t),s=n.outerContainer,i=n.innerContainer,o=n.bubbleElement;return s.appendChild(i),this.addInnerContainerElements(o,e,t),n;}},{key:"createMessageElements",value:function createMessageElements(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=this.createElements(e,t);return B.updateRefArr(this.messageElementRefs,s,n),B.classifyRoleMessages(this.messageElementRefs,t),s;}},{key:"addInnerContainerElements",value:// prettier-ignore
|
|
77
|
+
function addInnerContainerElements(e,t,n){var s=this.messageElementRefs[this.messageElementRefs.length-1];return B.areOuterContainerClassRolesSame(n,s)&&!this.isLastMessageError()&&B.hideRoleElements(s.innerContainer,this.avatar,this.name),e[f].add("message-bubble",B.getRoleClass(n),n===F?"user-message-text":"ai-message-text"),this.renderText(e,t,n),B.addRoleElements(e,n,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
|
|
78
|
+
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){e&&this.messageStyles&&Be.applyCustomStyles(this.messageStyles,e,t,n,s);}},{key:"removeMessage",value:function removeMessage(e){e.outerContainer.remove();var t=this.messageElementRefs.findIndex(function(n){return n===e;});this.messageElementRefs.splice(t,1);}},{key:"removeFirstMessage",value:function removeFirstMessage(){this.messageElementRefs[0].outerContainer.remove(),this.messageElementRefs.shift();}},{key:"removeLastMessage",value:function removeLastMessage(){this.messageElementRefs[this.messageElementRefs.length-1].outerContainer.remove(),this.messageElementRefs.pop();}},{key:"isLastMessageError",value:function isLastMessageError(){var e;return(e=B.getLastMessageBubbleElement(this.elementRef))==null?void 0:e[f].contains(zs);}},{key:"sendClientUpdate",value:function sendClientUpdate(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n;(n=this._onMessage)==null||n.call(this,e,t);}// role is optional to not add wrapper to error
|
|
79
|
+
},{key:"renderText",value:function renderText(e,t,n){var _re$tryAddWrapper2=re.tryAddWrapper(e,t,this._customWrappers,n),s=_re$tryAddWrapper2.contentEl,i=_re$tryAddWrapper2.wrapper;i&&re.apply(this,e),s.innerHTML=this._remarkable.render(t),this._applyHTMLToRemarkable&&re.apply(this,s),s.innerText.trim().length===0&&s.children.length>0&&s.children[0].tagName!=="P"&&(s.innerText=t);}// this is mostly used for enabling highlight.js to highlight code if it downloads later
|
|
80
|
+
},{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this0=this;this._remarkable=gs.createNew(e),this.messageToElements.forEach(function(t){t[1][h]&&t[0][h]&&_this0.renderText(t[1][h].bubbleElement,t[0][h],t[0][S]);});}},{key:"getFirstMessageContentEl",value:function getFirstMessageContentEl(){var _this$messageToElemen=this.messageToElements[this.messageToElements.length-1][1],e=_this$messageToElemen.text,t=_this$messageToElemen.html,n=_this$messageToElemen.files;return e||t||(n==null?void 0:n[0]);}},{key:"scrollToFirstElement",value:function scrollToFirstElement(e,t){var n;if(e===F){var s=typeof this.focusMode!="boolean"&&((n=this.focusMode)==null?void 0:n.smoothScroll);q.scrollToBottom(this,s);}else if(t&&this.autoScrollAllowed){var _s3=this.getFirstMessageContentEl();q.scrollToBottom(this,!1,_s3==null?void 0:_s3.outerContainer);}}}],[{key:"createContainerElement",value:function createContainerElement(){var e=x();return e.id=fo,e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return je.isLoadingMessage(e)||At.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=x(),n=x();n[f].add("inner-message-container"),t.appendChild(n),t[f].add("outer-message-container"),t[f].add(B.buildRoleOuterContainerClass(e));var s=x();return s[f].add("message-bubble"),n.appendChild(s),{outerContainer:t,innerContainer:n,bubbleElement:s};}},{key:"createMessageContent",value:function createMessageContent(e){var t=e.text,n=e.files,s=e.html,i=e.custom,o=e._sessionId,a=e.role,c=_defineProperty({},S,a||te);return t&&(c[h]=t),n&&(c[m]=n),s&&(c[L]=s),!t&&!n&&!s&&(c[h]=""),i&&(c.custom=i),o&&(c._sessionId=o),c;}},{key:"isLoadingMessage",value:function isLoadingMessage(e){return e==null?void 0:e.bubbleElement[f].contains(St.BUBBLE_CLASS);}}]);}();je.TEXT_BUBBLE_CLASS="text-message",je.INTRO_CLASS="deep-chat-intro",je.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var ct=je;var B=/*#__PURE__*/function(){function B(){_classCallCheck(this,B);}return _createClass(B,null,[{key:"getLastElementsByClass",value:function getLastElementsByClass(e,t,n){var _loop=function _loop(){var i=e[s];if(i.bubbleElement[f].contains(t[0])&&!t.slice(1).find(function(a){return!i.bubbleElement[f].contains(a);}))if(n){if(!n.find(function(c){return i.bubbleElement[f].contains(c);}))return{v:i};}else return{v:i};},_ret;for(var s=e.length-1;s>=0;s-=1){_ret=_loop();if(_ret)return _ret.v;}}},{key:"getLastMessage",value:function getLastMessage(e,t,n){for(var s=e.length-1;s>=0;s-=1)if(e[s][0][S]===t)if(n){if(e[s][0][n])return e[s][0];}else return e[s][0];}},{key:"getLastTextToElement",value:function getLastTextToElement(e,t){for(var n=e.length-1;n>=0;n-=1)if(e[n][0]===t)return e[n];}// IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message
|
|
81
81
|
// and if messages have custom roles, it will still look to update the last 'ai' role message
|
|
82
82
|
// prettier-ignore
|
|
83
|
-
},{key:"overwriteMessage",value:function overwriteMessage(e,t,n,s,
|
|
84
|
-
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e[f].add(
|
|
85
|
-
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var n=t?
|
|
83
|
+
},{key:"overwriteMessage",value:function overwriteMessage(e,t,n,s,i,o){var a=B.getLastElementsByClass(t,[B.getRoleClass(s),o],[St.BUBBLE_CLASS]),c=B.getLastMessage(e,s,i);return c&&(c[i]=n),a;}},{key:"getRoleClass",value:function getRoleClass(e){return"".concat(e,"-message");}// makes sure the bubble has dimensions when there is no text
|
|
84
|
+
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e[f].add(Lr),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e[f].contains(Lr)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,n,s;return Array.from(((s=(n=(t=B.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:n[0])==null?void 0:s.children)||[]).find(function(i){return i[f].contains("message-bubble");});}},{key:"getLastMessageElement",value:function getLastMessageElement(e){var n;var t=(n=e.children[e.children.length-1])==null?void 0:n.children;return t==null?void 0:t[t.length-1];}},{key:"addRoleElements",value:function addRoleElements(e,t,n,s){n==null||n.addBesideBubble(e,t),s==null||s.addBesideBubble(e,t);}},{key:"hideRoleElements",value:function hideRoleElements(e,t,n){t==null||t.tryHide(e),n==null||n.tryHide(e);}},{key:"revealRoleElements",value:function revealRoleElements(e,t,n){t==null||t.tryReveal(e),n==null||n.tryReveal(e);}},{key:"softRemRoleElements",value:function softRemRoleElements(e,t,n){t==null||t.trySoftRem(e),n==null||n.trySoftRem(e);}},{key:"updateRefArr",value:function updateRefArr(e,t,n){n?e.unshift(t):e.push(t);}},{key:"buildRoleOuterContainerClass",value:function buildRoleOuterContainerClass(e){return"".concat(Ms).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$f;e.outerContainer[f].remove(Ai,Pr,wi),(_e$outerContainer$f=e.outerContainer[f]).add.apply(_e$outerContainer$f,_toConsumableArray(t));}},{key:"getNumberOfElements",value:function getNumberOfElements(e){var t=0;return e[h]!==void 0&&(t+=1),e[L]!==void 0&&(t+=1),e[m]&&(t+=e[m].length),t;}},{key:"filterdMessageElements",value:function filterdMessageElements(e,t){return e.filter(function(n){return n.bubbleElement[f].contains(t);});}},{key:"findMessageElements",value:function findMessageElements(e,t){return e.find(function(n){return n.bubbleElement[f].contains(t);});}},{key:"generateMessageBodyElements",value:function generateMessageBodyElements(e,t){var n={};return e[h]&&(n[h]=B.findMessageElements(t,ct.TEXT_BUBBLE_CLASS)),e[L]&&(n[L]=B.findMessageElements(t,wt.HTML_BUBBLE_CLASS)),e[m]&&(n[m]=B.filterdMessageElements(t,uo)),n;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=B.getNumberOfElements(e),i=n?t.slice(0,s):t.slice(t.length-s);return B.generateMessageBodyElements(e,i);}// if role not present - traverse all, if present - traverse last messages
|
|
85
|
+
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var n=t?B.buildRoleOuterContainerClass(t):void 0;for(var s=e.length-1;s>=0;s-=1){if(t||(n=Array.from(e[s].outerContainer[f]).find(function(u){return u.startsWith(Ms);})),!n)continue;var i=e[s],o=i.outerContainer[f].contains(n),a=e[s-1],c=e[s+1],l=a==null?void 0:a.outerContainer[f].contains(n),d=c==null?void 0:c.outerContainer[f].contains(n);if(o)!l&&d?B.addNewPositionClasses(i,[Ai]):l&&d?B.addNewPositionClasses(i,[Pr]):l&&!d?B.addNewPositionClasses(i,[wi]):!l&&!d&&B.addNewPositionClasses(i,[Ai,wi]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer[f]).find(function(s){return s.startsWith(Ms);})===B.buildRoleOuterContainerClass(e):!1;}},{key:"resetAllRoleElements",value:function resetAllRoleElements(e,t,n){if(!t&&!n)return;var s="";e.forEach(function(i,o){i.bubbleElement[f].contains(zs)||B.revealRoleElements(i.innerContainer,t,n);var a=Array.from(i.outerContainer[f]).find(function(c){return c.startsWith(Ms);});s===a&&B.hideRoleElements(e[o-1].innerContainer,t,n),s=a;});}// this is a workaround to prevent JSON.parse(JSON.stringify()) from removing the files' 'ref' property values
|
|
86
86
|
// and 'custom' property value if it is not shallow copyable
|
|
87
87
|
// note - structuredClone can fix this but it doesn't have good legacy compatibility
|
|
88
|
-
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return
|
|
89
|
-
},{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,n,s){e.bubbleElement.innerHTML=s,this._targetWrapper=re.getTargetWrapper(e.bubbleElement),this._elements&&re.apply(this._messages,this._elements.bubbleElement),this.updateBasedOnType(t,n);}},{key:"updateBasedOnType",value:function updateBasedOnType(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var o;var s=this._targetWrapper||((o=this._elements)==null?void 0:o.bubbleElement);this._partialRender||
|
|
88
|
+
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return B.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!==U)return e;if(Array.isArray(e))return e.map(function(n){return B.processMessageContent(n);});var t={};return Object.entries(e).forEach(function(_ref0){var _ref1=_slicedToArray(_ref0,2),n=_ref1[0],s=_ref1[1];n==="ref"&&s instanceof File||n==="custom"?t[n]=s:s!==null&&_typeof(s)===U?t[n]=B.processMessageContent(s):t[n]=s;}),t;}}]);}();var Mt=/*#__PURE__*/function(){function Mt(e,t){_classCallCheck(this,Mt);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialContent="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(Mt,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e[h])===void 0&&(e==null?void 0:e[L])===void 0)return console[p](go);var t=(e==null?void 0:e[h])||(e==null?void 0:e[L])||"",n=q.isScrollbarAtBottomOfElement(this._messages.elementRef),s=(e==null?void 0:e[h])!==void 0?h:L;if(!this._elements&&!this._message)this.setInitialState(s,t,e==null?void 0:e[S]);else{if(this._streamType!==s)return console[p](ia);e!=null&&e[S]&&(e==null?void 0:e[S])!==this._activeMessageRole?(this.finaliseStreamedMessage(!1),this.setInitialState(s,t,e==null?void 0:e[S])):this.updateBasedOnType(t,s,e==null?void 0:e.overwrite);}e!=null&&e._sessionId&&(this._sessionId=e==null?void 0:e._sessionId),e!=null&&e.custom&&this._message&&(this._message.custom=e.custom),n&&this._messages.autoScrollAllowed&&q.scrollToBottom(this._messages);}},{key:"setInitialState",value:function setInitialState(e,t,n){var o,a,c;this._streamType=e,this._targetWrapper=void 0,this._fileAdded=!1,this._partialContent="",this._partialBubble=void 0,n!==null&&n!==void 0?n:n=te;var s=((o=this._messages._customWrappers)==null?void 0:o[n])||((a=this._messages._customWrappers)==null?void 0:a[A]),i=s?"":t;this._elements=e===h?this._messages.addNewTextMessage(i,n):wt.add(this._messages,i,n),this._elements&&(this._elements.bubbleElement[f].add(Mt.MESSAGE_CLASS),this._activeMessageRole=n,this._message=_defineProperty(_defineProperty({},S,this._activeMessageRole),e,i),this._messages.messageToElements.push([this._message,_defineProperty({},e,this._elements)]),s&&this.setTargetWrapperIfNeeded(this._elements,t,this._streamType,s),(c=this._messages.scrollButton)==null||c.updateHidden());}// not using existing htmlUtils htmlWrappers logic to be able to stream html
|
|
89
|
+
},{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,n,s){e.bubbleElement.innerHTML=s,this._targetWrapper=re.getTargetWrapper(e.bubbleElement),this._elements&&re.apply(this._messages,this._elements.bubbleElement),this.updateBasedOnType(t,n);}},{key:"updateBasedOnType",value:function updateBasedOnType(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var o;var s=this._targetWrapper||((o=this._elements)==null?void 0:o.bubbleElement);this._partialRender||B.unfillEmptyMessageElement(s,e),(t===h?this.updateText:this.updateHTML).bind(this)(e,s,n);}},{key:"updateText",value:function updateText(e,t,n){this._message&&(this._message[h]=n?e:this._message[h]+e,this._partialRender&&this.isNewPartialRenderParagraph(t,n,e)&&this.partialRenderNewParagraph(t),this._partialBubble?this.updatePartialRenderBubble(e):this._messages.renderText(t,this._message[h]));}},{key:"containsPartialRenderMark",value:function containsPartialRenderMark(e){var t=e.indexOf(Mt.PARTIAL_RENDER_MARK);return t===-1?!1:!e.substring(t+Mt.PARTIAL_RENDER_MARK.length).startsWith("---");}// checking state BEFORE the current chunk was appended ensures the chunk that closes a code block
|
|
90
90
|
// (transitioning fence count from odd to even) stays in the current bubble alongside its opening fence
|
|
91
91
|
// https://github.com/OvidijusParsiunas/deep-chat/issues/500#issuecomment-4281293147
|
|
92
|
-
},{key:"isInsideOpenCodeBlock",value:function isInsideOpenCodeBlock(e){var
|
|
92
|
+
},{key:"isInsideOpenCodeBlock",value:function isInsideOpenCodeBlock(e){var i;if(this._streamType!==h)return!1;var t=(i=this._message)==null?void 0:i[h];if(!t)return!1;var s=(e?t.slice(0,t.length-e.length):t).match(/```/g);return!!s&&s.length%2===1;}},{key:"isNewPartialRenderParagraph",value:function isNewPartialRenderParagraph(e,t,n){var i;if(t)return e.innerHTML="",!0;if(this.isInsideOpenCodeBlock(n))return!1;var s=this._streamType;if(!this._partialBubble){var o=(i=this._message)==null?void 0:i[s];return!!o&&this.containsPartialRenderMark(o);}return!!this._partialContent&&this.containsPartialRenderMark(this._partialContent);}},{key:"partialRenderNewParagraph",value:function partialRenderNewParagraph(e){this._partialContent="",this._partialBubble=x(),this._partialBubble[f].add("partial-render-message"),e.appendChild(this._partialBubble);}},{key:"updatePartialRenderBubble",value:function updatePartialRenderBubble(e){this._partialContent+=e,this._streamType===h?this._messages.renderText(this._partialBubble,this._partialContent):this._partialBubble.innerHTML=this._partialContent;}},{key:"updateHTML",value:function updateHTML(e,t,n){if(this._message)if(this._message[L]=n?e:(this._message[L]||"")+e,this._partialRender&&this.isNewPartialRenderParagraph(t,n)&&this.partialRenderNewParagraph(t),this._partialBubble)this.updatePartialRenderBubble(e);else if(n)t.innerHTML=e;else{var s=x("span");s.innerHTML=e,t.appendChild(s);}}// asyncCallInProgress introduced specifically a case when stream closed (e.g. tool call) and making another call
|
|
93
93
|
// hence don't throw NO_VALID_STREAM_EVENTS_SENT when no response elements yet
|
|
94
|
-
},{key:"finaliseStreamedMessage",value:function finaliseStreamedMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!0;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n,s,
|
|
95
|
-
},{key:"endStreamAfterFileDownloaded",value:function(){var _endStreamAfterFileDownloaded=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e,t){var _yield$t,n,s;return _regenerator().w(function(_context2){while(1)switch(_context2.n){case 0:this._endStreamAfterOperation=!0;_context2.n=1;return t();case 1:_yield$t=_context2.v;n=_yield$t.text;s=_yield$t.files;n&&this.updateBasedOnType(n,h,!0),this._endStreamAfterOperation=!1,this.finaliseStreamedMessage(),s&&e.addNewMessage(_defineProperty({},m,s));case 2:return _context2.a(2);}},_callee2,this);}));function endStreamAfterFileDownloaded(_x3,_x4){return _endStreamAfterFileDownloaded.apply(this,arguments);}return endStreamAfterFileDownloaded;}()}]);}();
|
|
94
|
+
},{key:"finaliseStreamedMessage",value:function finaliseStreamedMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!0;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n,s,i;if(!this._endStreamAfterOperation&&!(this._fileAdded&&!this._elements)){if(!this._elements&&!t)throw Error(ra);this._message&&(s=(n=this._elements)==null?void 0:n.bubbleElement)!=null&&s[f].contains(Mt.MESSAGE_CLASS)&&(this._streamType===h?this._messages.textToSpeech&&Un.speak(this._message[h]||"",this._messages.textToSpeech):this._streamType===L&&this._elements&&re.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement[f].remove(Mt.MESSAGE_CLASS),this._message&&(this._sessionId&&(this._message._sessionId=this._sessionId),this._messages.sendClientUpdate(ct.createMessageContent(this._message),!1),(i=this._messages.browserStorage)==null||i.addMessages(this._messages.messageToElements.map(function(_ref11){var _ref12=_slicedToArray(_ref11,1),o=_ref12[0];return o;}))),this._hasStreamEnded=e);}}},{key:"markFileAdded",value:function markFileAdded(){this._fileAdded=!0;}// prettier-ignore
|
|
95
|
+
},{key:"endStreamAfterFileDownloaded",value:function(){var _endStreamAfterFileDownloaded=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e,t){var _yield$t,n,s;return _regenerator().w(function(_context2){while(1)switch(_context2.n){case 0:this._endStreamAfterOperation=!0;_context2.n=1;return t();case 1:_yield$t=_context2.v;n=_yield$t.text;s=_yield$t.files;n&&this.updateBasedOnType(n,h,!0),this._endStreamAfterOperation=!1,this.finaliseStreamedMessage(),s&&e.addNewMessage(_defineProperty({},m,s));case 2:return _context2.a(2);}},_callee2,this);}));function endStreamAfterFileDownloaded(_x3,_x4){return _endStreamAfterFileDownloaded.apply(this,arguments);}return endStreamAfterFileDownloaded;}()}]);}();Mt.MESSAGE_CLASS="streamed-message",Mt.PARTIAL_RENDER_MARK="\n\n";var bt=Mt;var D=/*#__PURE__*/function(){function D(){_classCallCheck(this,D);}return _createClass(D,null,[{key:"tempRemoveContentHeader",value:// need to pass stringifyBody boolean separately as binding is throwing an error for some reason
|
|
96
96
|
// prettier-ignore
|
|
97
|
-
function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,n){var s,
|
|
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,n,s){var o,a;var
|
|
99
|
-
},{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e,t){var n,s,_n$displayError,
|
|
100
|
-
function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,n){var s,
|
|
101
|
-
},{key:"handleReadableStream",value:function handleReadableStream(e,t,n,s,
|
|
102
|
-
},{key:"handleEventStream",value:function handleEventStream(e,t,n,s,
|
|
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 D.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 g,b,_,v,_t8;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(ae(u.data)!==ae("[DONE]"))){_context0.n=3;break;}try{_=JSON.parse(u.data);}catch(_unused6){_={};}_context0.n=1;return(b=(g=e.deepChat).responseInterceptor)==null?void 0:b.call(g,_);case 1:_t8=_context0.v;if(_t8){_context0.n=2;break;}_t8=_;case 2:v=_t8;
|
|
104
|
-
},{key:"handleMessage",value:function handleMessage(e,t,n,s,
|
|
105
|
-
},{key:"handleError",value:function handleError(e,t,n){var s;t.isLastMessageError()||(s=e.extractResultData)==null||s.call(e,n).then(function(){D.displayError(t,n);})["catch"](function(
|
|
106
|
-
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,n,s){var
|
|
97
|
+
function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,n){var s,i,_t3;return _regenerator().w(function(_context3){while(1)switch(_context3.p=_context3.n){case 0:if(e!=null&&e.headers){_context3.n=1;break;}throw new Error($e);case 1:s=e.headers[H];delete e.headers[H];_context3.p=2;_context3.n=3;return t(n);case 3:i=_context3.v;_context3.n=5;break;case 4:_context3.p=4;_t3=_context3.v;throw e.headers[H]=s,_t3;case 5:return _context3.a(2,(e.headers[H]=s,i));}},_callee3,null,[[2,4]]);}));function tempRemoveContentHeader(_x9,_x0,_x1){return _tempRemoveContentHeader.apply(this,arguments);}return tempRemoveContentHeader;}()},{key:"displayError",value:function displayError(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"Service error, please try again.";if(console[p](t),_typeof(t)===U)return t instanceof Error?e.addNewErrorMessage(oe,t.message):Array.isArray(t)||_typeof(t[p])===_e?e.addNewErrorMessage(oe,t):Object.keys(t).length===0?e.addNewErrorMessage(oe,n):e.addNewErrorMessage(oe,ae(t));e.addNewErrorMessage(oe,t);}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
},{key:"fetch",value:function(_fetch){function fetch(_x5,_x6,_x7,_x8){return _fetch.apply(this,arguments);}fetch.toString=function(){return _fetch.toString();};return fetch;}(function(e,t,n,s){var o,a;var i={method:((o=e.connectSettings)==null?void 0:o.method)||ye,headers:t};return i.method!==he&&(i.body=n?ae(s):s),e.connectSettings.credentials&&(i.credentials=e.connectSettings.credentials),fetch(((a=e.connectSettings)==null?void 0:a.url)||e.url||"",i);})},{key:"processResponseByType",value:function processResponseByType(e){var t=e.headers.get("content-type");return t!=null&&t.includes(Y)?e.json():t!=null&&t.includes("text/plain")||!t?e:e.blob();}},{key:"processRequestInterceptor",value:function(){var _processRequestInterceptor=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(e,t){var o,n,s,i,_t4;return _regenerator().w(function(_context4){while(1)switch(_context4.n){case 0:_context4.n=1;return(o=e.requestInterceptor)==null?void 0:o.call(e,t);case 1:_t4=_context4.v;if(_t4){_context4.n=2;break;}_t4=t;case 2:n=_t4;s=n;i=n;return _context4.a(2,{body:s.body,headers:s.headers,error:i[p]});}},_callee4);}));function processRequestInterceptor(_x10,_x11){return _processRequestInterceptor.apply(this,arguments);}return processRequestInterceptor;}()},{key:"validateResponseFormat",value:function validateResponseFormat(e,t){if(!e)return!1;var n=Array.isArray(e)?e:[e];return t&&n.length>1?(console[p](mo),!1):!n.find(function(i){return _typeof(i)!="object"||!(_typeof(i[p])===_e||_typeof(i[h])===_e||_typeof(i[L])===_e||Array.isArray(i[m]));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,n){e.addNewErrorMessage(oe,t),n==null||n();}// prettier-ignore
|
|
99
|
+
},{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e,t){var n,s,_n$displayError,i,_n$useRI,o,a,c,l,d,_args5=arguments,_t5;return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:n=_args5.length>2&&_args5[2]!==undefined?_args5[2]:{};s=n.io,_n$displayError=n.displayError,i=_n$displayError===void 0?!0:_n$displayError,_n$useRI=n.useRI,o=_n$useRI===void 0?!0:_n$useRI;if(s!=null&&s.extractResultData){_context5.n=1;break;}return _context5.a(2,t);case 1:a=o?s.deepChat.responseInterceptor:void 0;_context5.n=2;return a==null?void 0:a(t);case 2:_t5=_context5.v;if(_t5){_context5.n=3;break;}_t5=t;case 3:c=_t5;_context5.n=4;return s.extractResultData(c);case 4:l=_context5.v;if(!(!l||_typeof(l)!="object"&&!Array.isArray(l))){_context5.n=5;break;}if(i){d=Fn(t,"response",!!a,c);D.displayError(e,d);}return _context5.a(2);case 5:return _context5.a(2,l);}},_callee5);}));function basicResponseProcessing(_x12,_x13){return _basicResponseProcessing.apply(this,arguments);}return basicResponseProcessing;}()}]);}();function Yc(_x14,_x15){return _Yc.apply(this,arguments);}function _Yc(){_Yc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee199(r,e){var t,n;return _regenerator().w(function(_context199){while(1)switch(_context199.n){case 0:t=r.getReader();case 1:_context199.n=2;return t.read();case 2:if((n=_context199.v).done){_context199.n=4;break;}e(n.value);case 3:_context199.n=1;break;case 4:return _context199.a(2);}},_callee199);}));return _Yc.apply(this,arguments);}function Jc(r){var e,t,n,s=!1;return function(o){e===void 0?(e=o,t=0,n=-1):e=el(e,o);var a=e.length;var c=0;for(;t<a;){s&&(e[t]===10&&(c=++t),s=!1);var l=-1;for(;t<a&&l===-1;++t)switch(e[t]){case 58:n===-1&&(n=t-c);break;case 13:s=!0;case 10:l=t;break;}if(l===-1)break;r(e.subarray(c,l),n),c=t,n=-1;}c===a?e=void 0:c!==0&&(e=e.subarray(c),t-=c);};}function Qc(r,e,t){var n=Yr();var s=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(n),n=Yr();else if(a>0){var c=s.decode(o.subarray(0,a)),l=a+(o[a+1]===32?2:1),d=s.decode(o.subarray(l));switch(c){case"data":n.data=n.data?n.data+"\n"+d:d;break;case"event":n.event=d;break;case"id":r(n.id=d);break;case"retry":var u=parseInt(d,10);isNaN(u)||e(n.retry=u);break;}}};}function el(r,e){var t=new Uint8Array(r.length+e.length);return t.set(r),t.set(e,r.length),t;}function Yr(){return{data:"",event:"",id:"",retry:void 0};}var tl=function tl(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(r);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(r,n[s])&&(t[n[s]]=r[n[s]]);return t;};var Ui="text/event-stream",nl=1e3,Jr="last-event-id";function sl(r,e){var t=e.signal,n=e.headers,s=e.onopen,i=e.onmessage,o=e.onclose,a=e.onerror,c=e.openWhenHidden,l=e.fetch,d=tl(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(u,g){var b=Object.assign({},n);b.accept||(b.accept=Ui);var _;function v(){_.abort(),document.hidden||Re();}c||document.addEventListener("visibilitychange",v);var C=nl,N=0;function se(){document.removeEventListener("visibilitychange",v),window.clearTimeout(N),_.abort();}t==null||t.addEventListener("abort",function(){se(),u();});var fe=l!==null&&l!==void 0?l:window.fetch,ie=s!==null&&s!==void 0?s:il;function Re(){return _Re.apply(this,arguments);}function _Re(){_Re=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var $t,jt,Ke,_t6;return _regenerator().w(function(_context6){while(1)switch(_context6.p=_context6.n){case 0:_=new AbortController();_context6.p=1;_context6.n=2;return fe(r,Object.assign(Object.assign({},d),{headers:b,signal:_.signal}));case 2:jt=_context6.v;_context6.n=3;return ie(jt);case 3:_context6.n=4;return Yc(jt.body,Jc(Qc(function(Ke){Ke?b[Jr]=Ke:delete b[Jr];},function(Ke){C=Ke;},i)));case 4:o==null||o();se();u();_context6.n=6;break;case 5:_context6.p=5;_t6=_context6.v;if(!_.signal.aborted)try{Ke=($t=a==null?void 0:a(_t6))!==null&&$t!==void 0?$t:C;window.clearTimeout(N),N=window.setTimeout(Re,Ke);}catch(Ke){se(),g(Ke);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _Re.apply(this,arguments);}Re();});}function il(r){var e=r.headers.get("content-type");if(!(e!=null&&e.startsWith(Ui)))throw new Error("Expected content-type to be ".concat(Ui,", Actual: ").concat(e));}var V=/*#__PURE__*/function(){function V(){_classCallCheck(this,V);}return _createClass(V,null,[{key:"request",value:// prettier-ignore
|
|
100
|
+
function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,n){var s,i,g,b,_,v,C,o,_yield$D$processReque,a,c,l,d,u,_args7=arguments;return _regenerator().w(function(_context7){while(1)switch(_context7.n){case 0:s=_args7.length>3&&_args7[3]!==undefined?_args7[3]:!0;i=_args7.length>4&&_args7[4]!==undefined?_args7[4]:!1;o={body:t,headers:(g=e.connectSettings)==null?void 0:g.headers};_context7.n=1;return D.processRequestInterceptor(e.deepChat,o);case 1:_yield$D$processReque=_context7.v;a=_yield$D$processReque.body;c=_yield$D$processReque.headers;l=_yield$D$processReque.error;if(!l){_context7.n=2;break;}return _context7.a(2,D.onInterceptorError(n,l,e.streamHandlers.onClose));case 2:if(!((b=e.connectSettings)!=null&&b.handler)){_context7.n=3;break;}return _context7.a(2,gt.stream(e,a,n));case 3:if(!(((_=e.connectSettings)==null?void 0:_.url)===Et.URL)){_context7.n=4;break;}return _context7.a(2,Et.requestStream(n,e));case 4:d=new bt(n,e.stream),u={method:((v=e.connectSettings)==null?void 0:v.method)||ye,headers:c,credentials:(C=e.connectSettings)==null?void 0:C.credentials,body:s?ae(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?V.handleReadableStream(e,n,d,u,i,a):V.handleEventStream(e,n,d,u,i,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,n,s,i,o){var d;var _e$streamHandlers=e.streamHandlers,a=_e$streamHandlers.onOpen,c=_e$streamHandlers.onClose;var l=!1;fetch(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",s).then(/*#__PURE__*/function(){var _ref13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(u){var v,C,g,b,_,_yield$g$read,N,se,fe,ie,Re,_t7;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(u.body){_context8.n=1;break;}throw new Error(oa);case 1:g=u.body.getReader(),b=new TextDecoder();a();_=!1;case 2:if(!(!_&&!l)){_context8.n=8;break;}_context8.n=3;return g.read();case 3:_yield$g$read=_context8.v;N=_yield$g$read.value;se=_yield$g$read.done;if(!(_=se,_)){_context8.n=4;break;}V.handleClose(e,n,c,i);_context8.n=7;break;case 4:fe=b.decode(N,{stream:!0});_context8.n=5;return(C=(v=e.deepChat).responseInterceptor)==null?void 0:C.call(v,fe);case 5:_t7=_context8.v;if(_t7){_context8.n=6;break;}_t7=fe;case 6:ie=_t7;Re=_typeof(ie)=="object"?ie:_defineProperty({},h,fe);V.handleMessage(e,t,n,Re,o);case 7:_context8.n=2;break;case 8:return _context8.a(2);}},_callee8);}));return function(_x19){return _ref13.apply(this,arguments);};}())["catch"](function(u){V.handleError(e,t,u);}),e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l=!0;};}// prettier-ignore
|
|
102
|
+
},{key:"handleEventStream",value:function handleEventStream(e,t,n,s,i,o){var d;var _e$streamHandlers2=e.streamHandlers,a=_e$streamHandlers2.onOpen,c=_e$streamHandlers2.onClose,l=new AbortController();e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l.abort();},sl(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",_objectSpread(_objectSpread({},s),{},{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 D.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 g,b,_,v,_t8;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(ae(u.data)!==ae("[DONE]"))){_context0.n=3;break;}try{_=JSON.parse(u.data);}catch(_unused6){_={};}_context0.n=1;return(b=(g=e.deepChat).responseInterceptor)==null?void 0:b.call(g,_);case 1:_t8=_context0.v;if(_t8){_context0.n=2;break;}_t8=_;case 2:v=_t8;V.handleMessage(e,t,n,v,o);case 3:return _context0.a(2);}},_callee0);}))();},onerror:function onerror(u){throw c(),u;},onclose:function onclose(){V.handleClose(e,n,c,i);},signal:l.signal}))["catch"](function(u){V.handleError(e,t,u);});}//prettier-ignore
|
|
104
|
+
},{key:"handleMessage",value:function handleMessage(e,t,n,s,i){var o;(o=e.extractResultData)==null||o.call(e,s,i).then(function(a){V.upsertContent(t,n.upsertStreamedMessage.bind(n),n,a),t.removeError();})["catch"](function(a){t.isLastMessageError()||D.displayError(t,a);});}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
},{key:"handleError",value:function handleError(e,t,n){var s;t.isLastMessageError()||(s=e.extractResultData)==null||s.call(e,n).then(function(){D.displayError(t,n);})["catch"](function(i){D.displayError(t,i);});}},{key:"handleClose",value:function handleClose(e,t,n,s){if(e.asyncCallInProgress){t.finaliseStreamedMessage(!1,!0),e.asyncCallInProgress=!1;return;}try{t.finaliseStreamedMessage(),n();}catch(i){if(!s)throw i;}}// io is only passed for demo to simulate a real stream
|
|
106
|
+
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,n,s){var i,o,_i3,_i4,_o2;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:_context1.n=1;return D.basicResponseProcessing(e,n,{io:s,useRI:!1});case 1:if(_context1.v){_context1.n=2;break;}return _context1.a(2,t.onClose());case 2:if(Array.isArray(n)&&(n=n[0]),n[L]){t.onOpen();i=re.splitHTML(n[L]);i.length===0&&(i=n[L].split(""));o=new bt(e,s==null?void 0:s.stream);V.populateMessages(e,i,o,t,L,0,s);}if(!n[m]){_context1.n=4;break;}_context1.n=3;return D.basicResponseProcessing(e,_defineProperty({},m,n[m]),{io:s});case 3:_i3=_context1.v;e.addNewMessage(_objectSpread({sendUpdate:!1},_i3)),!n[L]&&!n[h]&&(new bt(e,s==null?void 0:s.stream).finaliseStreamedMessage(),t.onClose());case 4:if(n[h]){t.onOpen();_i4=n[h].split(""),_o2=new bt(e,s==null?void 0:s.stream);V.populateMessages(e,_i4,_o2,t,h,0,s);}n[p]&&(D.displayError(e,n[p]),t.onClose()),t.onAbort=function(){t.onClose();};case 5:return _context1.a(2);}},_callee1);}));function simulate(_x20,_x21,_x22,_x23){return _simulate.apply(this,arguments);}return simulate;}()// prettier-ignore
|
|
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,n,s,
|
|
109
|
-
},{key:"request",value:function request(e,t){var n=
|
|
110
|
-
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var n=
|
|
111
|
-
},{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,n,s){if(!s)return;var
|
|
112
|
-
},{key:"stream",value:function stream(e,t,n){var u,g;var s=!0,
|
|
113
|
-
},{key:"websocket",value:function websocket(e,t){var _this10=this;var c,l;var n={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=n;var s=function s(){t.removeError(),n.isOpen=!0;},
|
|
114
|
-
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,n){var s,u,g,b,
|
|
115
|
-
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,n){var s,b,_,v,
|
|
116
|
-
},{key:"verifyKey",value:function verifyKey(e,t,n,s,
|
|
108
|
+
},{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,n,s,i,o,a){var c,d,l,_t9;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:c=t[o];if(!c){_context10.n=5;break;}_context10.p=1;_context10.n=2;return D.basicResponseProcessing(e,_defineProperty({},i,c),{io:a});case 2:d=_context10.v;V.upsertContent(e,n.upsertStreamedMessage.bind(n),n,d),e.removeError();_context10.n=4;break;case 3:_context10.p=3;_t9=_context10.v;e.isLastMessageError()||D.displayError(e,_t9);case 4:l=setTimeout(function(){V.populateMessages(e,t,n,s,i,o+1,a);},s.simulationInterim||6);s.onAbort=function(){V.abort(l,n,s.onClose);};_context10.n=6;break;case 5:n.finaliseStreamedMessage(),s.onClose();case 6:return _context10.a(2);}},_callee10,null,[[1,3]]);}));function populateMessages(_x24,_x25,_x26,_x27,_x28,_x29,_x30){return _populateMessages.apply(this,arguments);}return populateMessages;}()},{key:"isSimulation",value:function isSimulation(e){return _typeof(e)=="object"&&!!e.simulation;}},{key:"isSimulatable",value:function isSimulatable(e,t){return V.isSimulation(e)&&t&&(t[h]||t[L]);}},{key:"abort",value:function abort(e,t,n){clearTimeout(e),t.finaliseStreamedMessage(),n();}},{key:"upsertContent",value:function upsertContent(e,t,n,s){if(s&&Array.isArray(s)&&(s=s[0]),s!=null&&s[h]||s!=null&&s[L]){var i=t(s);n!==null&&n!==void 0?n:n=i||void 0;}if(s!=null&&s[m]&&(e.addNewMessage(_defineProperty({},m,s[m])),n==null||n.markFileAdded()),s!=null&&s[p])throw s[p];}}]);}();var ln=/*#__PURE__*/function(){function ln(){_classCallCheck(this,ln);}return _createClass(ln,null,[{key:"generateResponse",value:function generateResponse(e){var t=e[e.length-1][0];if(t[m]&&t[m].length>0){if(t[m].length>1)return"These are interesting files!";var n=t[m][0];return n[T]&&n[T].startsWith("data:image/gif")?"That is a nice gif!":n[y]===W?"That is a nice image!":n[y]===G?"I like the sound of that!":"That is an interesting file!";}if(t[h]){if(t[h].charAt(t[h].length-1)==="?")return"I'm sorry but I can't answer that question...";if(t[h].includes("updog"))return"What's updog?";}return"Hi there! This is a demo response!";}},{key:"getCustomResponse",value:function getCustomResponse(e,t){return typeof e=="function"?e(t):e;}},{key:"getResponse",value:function getResponse(_ref15){var e=_ref15.customDemoResponse,t=_ref15.messageToElements;return e?ln.getCustomResponse(e,t[t.length-1][0]):_defineProperty({},h,ln.generateResponse(t));}// timeout is used to simulate a timeout for a response to come back
|
|
109
|
+
},{key:"request",value:function request(e,t){var n=ln.getResponse(t);setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(){var s,i,o;return _regenerator().w(function(_context11){while(1)switch(_context11.n){case 0:_context11.n=1;return D.basicResponseProcessing(t,n,{io:e});case 1:s=_context11.v;if(s){_context11.n=2;break;}return _context11.a(2,e.completionsHandlers.onFinish());case 2:i=Array.isArray(s)?s:[s],o=i.find(function(a){return _typeof(a[p])===_e;});o?(t.addNewErrorMessage(oe,o[p]),e.completionsHandlers.onFinish()):V.isSimulatable(e.stream,s)?V.simulate(t,e.streamHandlers,s):(i.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 n=ln.getResponse(e);V.simulate(e,t.streamHandlers,n,t);},400);}}]);}();ln.URL="deep-chat-demo";var Et=ln;var ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,null,[{key:"setup",value:function setup(e){e.permittedErrorPrefixes=["Connection error","Error in server message"],e.websocket="pending";}},{key:"isElementPresentInDOM",value:function isElementPresentInDOM(e){return e.getRootNode({composed:!0})instanceof Document;}},{key:"createConnection",value:function createConnection(e,t){if(!ke.isElementPresentInDOM(e.deepChat))return;var n=e.connectSettings.websocket;if(n){if(e.connectSettings.handler)return gt.websocket(e,t);try{var s=typeof n!="boolean"?n:void 0,i=new WebSocket(e.connectSettings.url||"",s);e.websocket=i,e.websocket.onopen=function(){var o,a;t.removeError(),e.websocket&&_typeof(e.websocket)===U&&ke.assignListeners(e,i,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console[p](o),ke.retryConnection(e,t);};}catch(s){console[p](s),ke.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var n,s;(s=(n=e.deepChat)._validationHandler)==null||s.call(n),ke.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage(oe,"Connection error"),setTimeout(function(){ke.createConnection(e,t);},5e3));}},{key:"assignListeners",value:function assignListeners(e,t,n){var _this1=this;var s={};t.onmessage=/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(i){var o,a,c,l,_c3,_l2,_t0;return _regenerator().w(function(_context12){while(1)switch(_context12.p=_context12.n){case 0:if(!e.extractResultData){_context12.n=8;break;}_context12.p=1;o=JSON.parse(i.data);_context12.n=2;return D.basicResponseProcessing(n,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(Fn(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!V.isSimulation(e.stream)){_context12.n=4;break;}c=ke.stream.bind(_this1,e,n,s),l=s[o[S]||te];V.upsertContent(n,c,l,a);_context12.n=6;break;case 4:_c3=Array.isArray(a)?a:[a],_l2=_c3.find(function(d){return _typeof(d[p])===_e;});if(!_l2){_context12.n=5;break;}throw _l2[p];case 5:_c3.forEach(function(d){return n.addNewMessage(d);});case 6:_context12.n=8;break;case 7:_context12.p=7;_t0=_context12.v;D.displayError(n,_t0,"Error in server message");case 8:return _context12.a(2);}},_callee12,null,[[1,7]]);}));return function(_x31){return _ref18.apply(this,arguments);};}(),t.onclose=function(){var i,o;console[p]("Connection closed"),n.isLastMessageError()||n.addNewErrorMessage(oe,"Connection error"),e.stream&&((o=(i=e.streamHandlers).onAbort)==null||o.call(i)),ke.createConnection(e,n);};}},{key:"sendWebsocket",value:function(){var _sendWebsocket=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e,t,n){var s,d,u,i,o,_yield$D$processReque2,a,c,l,_args13=arguments;return _regenerator().w(function(_context13){while(1)switch(_context13.n){case 0:s=_args13.length>3&&_args13[3]!==undefined?_args13[3]:!0;if(!(((d=e.connectSettings)==null?void 0:d.url)===Et.URL)){_context13.n=1;break;}return _context13.a(2,Et.request(e,n));case 1:i=e.websocket;if(!(!i||i==="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 D.processRequestInterceptor(e.deepChat,o);case 3:_yield$D$processReque2=_context13.v;a=_yield$D$processReque2.body;c=_yield$D$processReque2.error;if(!c){_context13.n=4;break;}return _context13.a(2,n.addNewErrorMessage(oe,c));case 4:if(ke.isWebSocket(i)){_context13.n=5;break;}return _context13.a(2,i.newUserMessage.listener(a));case 5:l=s?ae(a):a;i.readyState===void 0||i.readyState!==i.OPEN?(console[p]("Connection is not open"),n.isLastMessageError()||n.addNewErrorMessage(oe,"Connection error")):(i.send(ae(l)),e.completionsHandlers.onFinish());case 6:return _context13.a(2);}},_callee13);}));function sendWebsocket(_x32,_x33,_x34){return _sendWebsocket.apply(this,arguments);}return sendWebsocket;}()},{key:"canSendMessage",value:function canSendMessage(e){return e?e==="pending"?!1:ke.isWebSocket(e)?e.readyState!==void 0&&e.readyState===e.OPEN:e.isOpen:!0;}// if false then it is the internal websocket handler
|
|
111
|
+
},{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,n,s){if(!s)return;var i=e.stream.simulation;if(_typeof(i)===_e){var _n$o;var o=s[S]||te,a=n[o];s[h]===i||s[L]===i?(a==null||a.finaliseStreamedMessage(),delete n[o]):((_n$o=n[o])!==null&&_n$o!==void 0?_n$o:n[o]=new bt(t,e.stream),n[o].upsertStreamedMessage(s));}else V.simulate(t,e.streamHandlers,s);}}]);}();var gt=/*#__PURE__*/function(){function gt(){_classCallCheck(this,gt);}return _createClass(gt,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(e,t,n){var a,c,s,i,o;return _regenerator().w(function(_context15){while(1)switch(_context15.n){case 0:s=!0;i=/*#__PURE__*/function(){var _ref19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(l){var d,u,g;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(s){_context14.n=1;break;}return _context14.a(2);case 1:s=!1;_context14.n=2;return D.basicResponseProcessing(n,l,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console[p](Fn(l,"server",!!e.deepChat.responseInterceptor,d)),n.addNewErrorMessage(oe,"Error in server message"),e.completionsHandlers.onFinish();else{u=Array.isArray(d)?d:[d],g=u.find(function(b){return _typeof(b[p])===_e;});g?(console[p](g[p]),n.addNewErrorMessage(oe,g[p]),e.completionsHandlers.onFinish()):V.isSimulatable(e.stream,d)?V.simulate(n,e.streamHandlers,d):(u.forEach(function(b){return n.addNewMessage(b);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function i(_x38){return _ref19.apply(this,arguments);};}(),o=gt.generateOptionalSignals();(c=(a=e.connectSettings).handler)==null||c.call(a,t,_objectSpread(_objectSpread({},o),{},{onResponse:i}));case 1:return _context15.a(2);}},_callee15);}));function request(_x35,_x36,_x37){return _request2.apply(this,arguments);}return request;}()},{key:"attemptToFinaliseStream",value:function attemptToFinaliseStream(e,t){try{var n=t.messageElementRefs[t.messageElementRefs.length-1];ct.isLoadingMessage(n)?t.removeLastMessage():e.finaliseStreamedMessage();}catch(n){console[p](n),t.addNewErrorMessage(oe,n);}}// prettier-ignore
|
|
112
|
+
},{key:"stream",value:function stream(e,t,n){var u,g;var s=!0,i=!1;var o=new bt(n,e.stream),a=function a(){i||!s||(e.streamHandlers.onOpen(),i=!0);},c=function c(){s&&(gt.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1);},l=/*#__PURE__*/function(){var _ref20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(b){var _,v;return _regenerator().w(function(_context16){while(1)switch(_context16.n){case 0:if(s){_context16.n=1;break;}return _context16.a(2);case 1:_context16.n=2;return D.basicResponseProcessing(n,b,{io:e,displayError:!1});case 2:_=_context16.v;if(_)_[p]?(gt.streamError(_[p],o,e,n),s=!1):V.upsertContent(n,o.upsertStreamedMessage.bind(o),o,_);else{v=Fn(b,"server",!!e.deepChat.responseInterceptor,_);gt.streamError(v,o,e,n),s=!1;}case 3:return _context16.a(2);}},_callee16);}));return function l(_x39){return _ref20.apply(this,arguments);};}();e.streamHandlers.onAbort=function(){gt.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1;};var d=gt.generateOptionalSignals();(g=(u=e.connectSettings).handler)==null||g.call(u,t,_objectSpread(_objectSpread({},d),{},{onOpen:a,onResponse:l,onClose:c,stopClicked:e.streamHandlers.stopClicked}));}},{key:"streamError",value:function streamError(e,t,n,s){console[p](e),t.finaliseStreamedMessage(),s.addNewErrorMessage(oe,e),n.streamHandlers.onClose();}// prettier-ignore
|
|
113
|
+
},{key:"websocket",value:function websocket(e,t){var _this10=this;var c,l;var n={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=n;var s=function s(){t.removeError(),n.isOpen=!0;},i=function i(){n.isOpen=!1;},o=/*#__PURE__*/function(){var _ref21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(d){var u,g,b,_,v,C;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:_context17.n=1;return D.basicResponseProcessing(t,d,{io:e,displayError:!1});case 1:u=_context17.v;if(!u)console[p](Fn(d,"server",!!e.deepChat.responseInterceptor,u)),t.addNewErrorMessage(oe,"Error in server message");else{g=Array.isArray(u)?u:[u],b=g.find(function(_){return _typeof(_[p])===_e;});if(b)console[p](b[p]),t.isLastMessageError()||t.addNewErrorMessage(oe,b[p]);else if(V.isSimulation(e.stream)){_=u,v=ke.stream.bind(_this10,e,t,n.roleToStream),C=n.roleToStream[_[S]||te];V.upsertContent(t,v,C,_);}else g.forEach(function(_){return t.addNewMessage(_);});}case 2:return _context17.a(2);}},_callee17);}));return function o(_x40){return _ref21.apply(this,arguments);};}(),a=gt.generateOptionalSignals();(l=(c=e.connectSettings).handler)==null||l.call(c,void 0,_objectSpread(_objectSpread({},a),{},{onOpen:s,onResponse:o,onClose:i,newUserMessage:n.newUserMessage}));}},{key:"generateOptionalSignals",value:function generateOptionalSignals(){return{onClose:function onClose(){},onOpen:function onOpen(){},stopClicked:{listener:function listener(){}},newUserMessage:{listener:function listener(){}}};}}]);}();var be=/*#__PURE__*/function(){function be(){_classCallCheck(this,be);}return _createClass(be,null,[{key:"request",value:// prettier-ignore
|
|
114
|
+
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,n){var s,u,g,b,i,_yield$D$processReque3,o,a,c,l,d,_args19=arguments;return _regenerator().w(function(_context19){while(1)switch(_context19.n){case 0:s=_args19.length>3&&_args19[3]!==undefined?_args19[3]:!0;i={body:t,headers:(u=e.connectSettings)==null?void 0:u.headers};_context19.n=1;return D.processRequestInterceptor(e.deepChat,i);case 1:_yield$D$processReque3=_context19.v;o=_yield$D$processReque3.body;a=_yield$D$processReque3.headers;c=_yield$D$processReque3.error;l=e.completionsHandlers.onFinish;if(!c){_context19.n=2;break;}return _context19.a(2,D.onInterceptorError(n,c,l));case 2:if(!((g=e.connectSettings)!=null&&g.handler)){_context19.n=3;break;}return _context19.a(2,gt.request(e,o,n));case 3:if(!(((b=e.connectSettings)==null?void 0:b.url)===Et.URL)){_context19.n=4;break;}return _context19.a(2,Et.request(e,n));case 4:d=!0;D.fetch(e,a,s,o).then(function(_){return d=!!_.ok,_;}).then(function(_){return D.processResponseByType(_);}).then(/*#__PURE__*/function(){var _ref22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(_){var N,se,v,C,_t1;return _regenerator().w(function(_context18){while(1)switch(_context18.n){case 0:if(e.extractResultData){_context18.n=1;break;}return _context18.a(2);case 1:_context18.n=2;return(se=(N=e.deepChat).responseInterceptor)==null?void 0:se.call(N,_);case 2:_t1=_context18.v;if(_t1){_context18.n=3;break;}_t1=_;case 3:v=_t1;_context18.n=4;return e.extractResultData(v,o);case 4:C=_context18.v;if(d){_context18.n=5;break;}throw _;case 5:if(!(!C||_typeof(C)!==U&&!Array.isArray(C))){_context18.n=6;break;}throw Error(Fn(_,"response",!!e.deepChat.responseInterceptor,v));case 6:if(!C[p]){_context18.n=7;break;}throw C[p];case 7:if(!e.asyncCallInProgress){_context18.n=8;break;}e.asyncCallInProgress=!1;return _context18.a(2);case 8:V.isSimulatable(e.stream,C)?V.simulate(n,e.streamHandlers,C):((Array.isArray(C)?C:[C]).forEach(function(ie){return n.addNewMessage(ie);}),l());case 9:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref22.apply(this,arguments);};}())["catch"](function(_){D.displayError(n,_),l();});case 5:return _context19.a(2);}},_callee19);}));function request(_x41,_x42,_x43){return _request3.apply(this,arguments);}return request;}()},{key:"executePollRequest",value:function executePollRequest(e,t,n,s){var i=e.completionsHandlers.onFinish;fetch(t,n).then(function(o){return o.json();}).then(/*#__PURE__*/function(){var _ref23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(o){var c,l,a,_t10,_t11;return _regenerator().w(function(_context20){while(1)switch(_context20.n){case 0:if(e.extractPollResultData){_context20.n=1;break;}return _context20.a(2);case 1:_t10=e;_context20.n=2;return(l=(c=e.deepChat).responseInterceptor)==null?void 0:l.call(c,o);case 2:_t11=_context20.v;if(_t11){_context20.n=3;break;}_t11=o;case 3:_context20.n=4;return _t10.extractPollResultData.call(_t10,_t11);case 4:a=_context20.v;a.timeoutMS?setTimeout(function(){be.executePollRequest(e,t,n,s);},a.timeoutMS):V.isSimulatable(e.stream,a)?V.simulate(s,e.streamHandlers,a):(s.addNewMessage(a),i());case 5:return _context20.a(2);}},_callee20);}));return function(_x45){return _ref23.apply(this,arguments);};}())["catch"](function(o){D.displayError(s,o),i();});}// prettier-ignore
|
|
115
|
+
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,n){var s,b,_,v,i,_yield$D$processReque4,o,a,c,l,d,u,g,_args21=arguments;return _regenerator().w(function(_context21){while(1)switch(_context21.n){case 0:s=_args21.length>3&&_args21[3]!==undefined?_args21[3]:!0;i={body:t,headers:(b=e.connectSettings)==null?void 0:b.headers};_context21.n=1;return D.processRequestInterceptor(e.deepChat,i);case 1:_yield$D$processReque4=_context21.v;o=_yield$D$processReque4.body;a=_yield$D$processReque4.headers;c=_yield$D$processReque4.error;if(!c){_context21.n=2;break;}return _context21.a(2,D.onInterceptorError(n,c));case 2:l=((_=e.connectSettings)==null?void 0:_.url)||e.url||"",d=((v=e.connectSettings)==null?void 0:v.method)||ye,u=s?ae(o):o,g={method:d,body:u,headers:a};e.connectSettings.credentials&&(g.credentials=e.connectSettings.credentials),be.executePollRequest(e,l,g,n);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,n,s,i,o,a,c,l){if(e==="")return o(ue);a(),fetch(t,{method:s,headers:n,body:l||null}).then(function(d){return D.processResponseByType(d);}).then(function(d){c(d,e,i,o);})["catch"](function(d){o(He),console[p](d);});}}]);}();var Gn=/*#__PURE__*/function(){function Gn(){_classCallCheck(this,Gn);}return _createClass(Gn,null,[{key:"getCharacterLimitMessages",value:function getCharacterLimitMessages(e,t){var i;if(t===-1)return e;var n=0,s=e[K]-1;for(s;s>=0;s-=1){var o=(i=e[s])==null?void 0:i[h];if(o!==void 0&&(n+=o[K],n>t)){e[s][h]=o.substring(0,o[K]-(n-t));break;}}return e.slice(Math.max(s,0));}},{key:"getMaxMessages",value:function getMaxMessages(e,t){return e.slice(Math.max(e[K]-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
|
-
},{key:"processMessages",value:function processMessages(e,t,n){return t!==void 0?t>0&&(e
|
|
119
|
+
},{key:"processMessages",value:function processMessages(e,t,n){return t!==void 0?t>0&&(e=Gn.getMaxMessages(e,t)):e=[e[e[K]-1]],e=w(e),n===void 0?e:Gn.getCharacterLimitMessages(e,n);}}]);}();var Vt=/*#__PURE__*/function(){function Vt(e,t,n){_classCallCheck(this,Vt);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,n.fetchHistory&&this.fetchHistory(n.fetchHistory),this.setupInitialHistory(e);}return _createClass(Vt,[{key:"fetchHistory",value:function(){var _fetchHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(e){var _this11=this;var t,n;return _regenerator().w(function(_context22){while(1)switch(_context22.n){case 0:t=Ft.addMessage(this._messages);_context22.n=1;return e();case 1:n=_context22.v;this._messages.removeMessage(t),Vt.displayIntroMessages(this._messages.messageElementRefs),n.forEach(function(s){return _this11._messages.addAnyMessage(s,!0);}),setTimeout(function(){return q.scrollToBottom(_this11._messages);},0);case 2:return _context22.a(2);}},_callee22,this);}));function fetchHistory(_x49){return _fetchHistory.apply(this,arguments);}return fetchHistory;}()},{key:"scrollToPreloadFirstEl",value:function scrollToPreloadFirstEl(e,t){this._messages.elementRef.scrollTop=t+e.offsetTop-40;}},{key:"processLoadedHistory",value:function processLoadedHistory(e){var _this12=this;var a;var _this$_messages=this._messages,t=_this$_messages.messageElementRefs,n=_this$_messages.messageToElements,s=_this$_messages.elementRef,i=(a=t.find(function(c){return!c.outerContainer[f].contains(ct.INTRO_CLASS);}))==null?void 0:a.outerContainer,o=s.scrollTop;e==null||e.reverse().map(function(c){var l=_this12._messages.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!0}),!0,!0);if(l){var d=B.generateMessageBody(l,t,!0);n.unshift([l,d]);}return l;}).filter(function(c){return!!c;}).reverse().forEach(function(c){return _this12._messages.sendClientUpdate(c,!0);}),i&&(this._messages.messageElementRefs.length>=this._messages.maxVisibleMessages?setTimeout(function(){return _this12.scrollToPreloadFirstEl(i,o);}):this.scrollToPreloadFirstEl(i,o));}},{key:"populateMessages",value:function populateMessages(e,t){this._messages.removeMessage(e),this._isPaginationComplete=t.findIndex(function(a){return!a;})<0;var n=t.filter(function(a){return!!a;});this.processLoadedHistory(n);var _this$_messages2=this._messages,s=_this$_messages2.messageElementRefs,i=_this$_messages2.avatar,o=_this$_messages2.name;B.resetAllRoleElements(s,i,o);}},{key:"loadHistoryOnScroll",value:function(){var _loadHistoryOnScroll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23(e){var t,n,_t12;return _regenerator().w(function(_context23){while(1)switch(_context23.p=_context23.n){case 0:if(!(this._isLoading||this._isPaginationComplete||this._messages.elementRef.scrollTop!==0)){_context23.n=1;break;}return _context23.a(2);case 1:this._isLoading=!0;t=Ft.addMessage(this._messages,!1);_context23.p=2;_context23.n=3;return e(this._index++);case 3:n=_context23.v;this.populateMessages(t,n),this._isLoading=!1;_context23.n=5;break;case 4:_context23.p=4;_t12=_context23.v;this._messages.removeMessage(t),this._isPaginationComplete=!0,this._messages.addNewErrorMessage(oe,Vt.FAILED_ERROR_MESSAGE,!0),console[p](_t12);case 5:return _context23.a(2);}},_callee23,this,[[2,4]]);}));function loadHistoryOnScroll(_x50){return _loadHistoryOnScroll.apply(this,arguments);}return loadHistoryOnScroll;}()},{key:"populateInitialHistory",value:function populateInitialHistory(e){var _this13=this;e.forEach(function(t){ce.processHistoryFile(t),_this13._messages.addAnyMessage(t,!0);});}},{key:"loadInitialHistory",value:function(){var _loadInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(e){var t,n,s,_t13;return _regenerator().w(function(_context24){while(1)switch(_context24.p=_context24.n){case 0:this._isLoading=!0;t=Ft.addMessage(this._messages);_context24.p=1;_context24.n=2;return e(this._index++);case 2:n=_context24.v;s=this._messages.elementRef.scrollTop;this.populateMessages(t,n),this.restoreScrollOrScrollToBottom(s===0);_context24.n=4;break;case 3:_context24.p=3;_t13=_context24.v;this._messages.removeMessage(t),this._isPaginationComplete=!0,this._messages.addNewErrorMessage(oe,Vt.FAILED_ERROR_MESSAGE,!0),console[p](_t13);case 4:Vt.displayIntroMessages(this._messages.messageElementRefs),this._isLoading=!1;case 5:return _context24.a(2);}},_callee24,this,[[1,3]]);}));function loadInitialHistory(_x51){return _loadInitialHistory.apply(this,arguments);}return loadInitialHistory;}()},{key:"setupInitialHistory",value:function(){var _setupInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(e){var s,t,n;return _regenerator().w(function(_context25){while(1)switch(_context25.n){case 0:e.loadHistory&&this.loadInitialHistory(e.loadHistory);t=(s=this._messages.browserStorage)==null?void 0:s.get(),n=e.history||ce.processHistory(e)||(t==null?void 0:t.messages);n&&(this.populateInitialHistory(n),this.restoreScrollOrScrollToBottom(!0),this._index+=1);case 1:return _context25.a(2);}},_callee25,this);}));function setupInitialHistory(_x52){return _setupInitialHistory.apply(this,arguments);}return setupInitialHistory;}()},{key:"restoreScrollOrScrollToBottom",value:function restoreScrollOrScrollToBottom(e){var _this14=this;var n,s,i;var t=(s=(n=this._messages.browserStorage)==null?void 0:n.get())==null?void 0:s.scrollHeight;t!==void 0&&(i=this._messages.browserStorage)!=null&&i.trackScrollHeight?setTimeout(function(){_this14._messages.elementRef.scrollTop=t;},0):e&&setTimeout(function(){return q.scrollToBottom(_this14._messages);},0);}}],[{key:"addErrorPrefix",value:function addErrorPrefix(e){var _e$permittedErrorPref;(_e$permittedErrorPref=e.permittedErrorPrefixes)!==null&&_e$permittedErrorPref!==void 0?_e$permittedErrorPref:e.permittedErrorPrefixes=[],e.permittedErrorPrefixes.push(Vt.FAILED_ERROR_MESSAGE);}},{key:"displayIntroMessages",value:function displayIntroMessages(e){for(var t=0;t<e.length;t+=1){var n=e[0];if(n.outerContainer[f].contains(ct.INTRO_CLASS))n.outerContainer[E].display="";else break;}}}]);}();Vt.FAILED_ERROR_MESSAGE="Failed to load history";var bs=Vt;var Ce=/*#__PURE__*/function(){function Ce(){_classCallCheck(this,Ce);}return _createClass(Ce,null,[{key:"parseConfig",value:function parseConfig(e,t,n){var i;var s={files:e};if(_typeof(n)=="object"){ce.processFileConfigConnect(n);var o=n.files,a=n.connect,c=n.button;o&&(o.infoModal&&(s[m].infoModal=o.infoModal,(i=o.infoModal)!=null&&i.textMarkDown&&(s.infoModalTextMarkUp=t.render(o.infoModal.textMarkDown))),o.acceptedFormats&&(s[m].acceptedFormats=o.acceptedFormats),o.maxNumberOfFiles&&(s[m].maxNumberOfFiles=o.maxNumberOfFiles)),s.button=c,a&&Object.keys(a).length>0&&(s.connect=a);}return s;}},{key:"processMixedFiles",value:function processMixedFiles(e,t,n){if(n){var s={acceptedFormats:""};e.fileTypes.mixedFiles=Ce.parseConfig(s,t,n);}}// needs to be set after audio to overwrite maxNumberOfFiles
|
|
120
120
|
// prettier-ignore
|
|
121
|
-
},{key:"processMicrophone",value:function processMicrophone(e,t,n,s){var _c$m,_g$maxNumberOfFiles;var a,c,l,d,u,g;var o=_objectSpread({acceptedFormats:"audio/*"},((a=e.fileTypes[
|
|
122
|
-
},{key:"processAudioConfig",value:function processAudioConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"audio/*"},(s==null?void 0:s[m])||{});e.fileTypes[
|
|
123
|
-
},{key:"processGifConfig",value:function processGifConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/gif"},(s==null?void 0:s[m])||{});e.fileTypes[
|
|
121
|
+
},{key:"processMicrophone",value:function processMicrophone(e,t,n,s){var _c$m,_g$maxNumberOfFiles;var a,c,l,d,u,g;var o=_objectSpread({acceptedFormats:"audio/*"},((a=e.fileTypes[G])==null?void 0:a[m])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e.recordAudio=Ce.parseConfig(o,t,n),_typeof(n)=="object"&&n[m]&&((_c$m=(c=e.recordAudio)[m])!==null&&_c$m!==void 0?_c$m:c[m]={},e.recordAudio[m].format=(l=n[m])==null?void 0:l.format,e.recordAudio[m].maxDurationSeconds=(d=n[m])==null?void 0:d.maxDurationSeconds,(u=e.fileTypes[G])!=null&&u[m]&&((_g$maxNumberOfFiles=(g=e.fileTypes[G][m]).maxNumberOfFiles)!==null&&_g$maxNumberOfFiles!==void 0?_g$maxNumberOfFiles:g.maxNumberOfFiles=n[m].maxNumberOfFiles))):s||(e.fileTypes[G]=Ce.parseConfig(o,t,n)));}// prettier-ignore
|
|
122
|
+
},{key:"processAudioConfig",value:function processAudioConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"audio/*"},(s==null?void 0:s[m])||{});e.fileTypes[G]=Ce.parseConfig(o,t,n);}// prettier-ignore
|
|
123
|
+
},{key:"processGifConfig",value:function processGifConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/gif"},(s==null?void 0:s[m])||{});e.fileTypes[Dn]=Ce.parseConfig(o,t,n);}// needs to be set after images to overwrite maxNumberOfFiles
|
|
124
124
|
// prettier-ignore
|
|
125
|
-
},{key:"processCamera",value:function processCamera(e,t,n,s){var _c$m2;var a,c,l,d;var o=_objectSpread({acceptedFormats:"image/*"},((a=e.fileTypes[
|
|
126
|
-
},{key:"processImagesConfig",value:function processImagesConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/*"},(s==null?void 0:s[m])||{});e.fileTypes[
|
|
127
|
-
},{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$m,_n$acceptedFormats,_s$maxNumberOfFiles;var n,s;e&&((_e$m=e[m])!==null&&_e$m!==void 0?_e$m:e[m]={},(_n$acceptedFormats=(n=e[m]).acceptedFormats)!==null&&_n$acceptedFormats!==void 0?_n$acceptedFormats:n.acceptedFormats=t,(_s$maxNumberOfFiles=(s=e[m]).maxNumberOfFiles)!==null&&_s$maxNumberOfFiles!==void 0?_s$maxNumberOfFiles:s.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,n){Ce.populateDefaultFileIO(n==null?void 0:n[
|
|
128
|
-
},{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(e,t){var s,n,
|
|
129
|
-
function M(e,t,n,s,
|
|
130
|
-
},{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,n=_this$_keyVerificatio.url,s=_this$_keyVerificatio.method,
|
|
131
|
-
function
|
|
132
|
-
function constructPropertyAccessors(e,t){var n;Object.defineProperty(this,t||e,{get:function get(){return n;},set:function set(o){n=o,t?this[e]=o:
|
|
133
|
-
function changeVisibility(e,t,n,s){s.target.id===
|
|
134
|
-
},{key:"create",value:function create(e){var t=x();t.id="visibility-icon-container";var n=
|
|
125
|
+
},{key:"processCamera",value:function processCamera(e,t,n,s){var _c$m2;var a,c,l,d;var o=_objectSpread({acceptedFormats:"image/*"},((a=e.fileTypes[Q])==null?void 0:a[m])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e[Fe]=Ce.parseConfig(o,t,n),_typeof(n)=="object"&&(e[Fe].modalContainerStyle=n.modalContainerStyle,n[m]&&((_c$m2=(c=e[Fe])[m])!==null&&_c$m2!==void 0?_c$m2:c[m]={},e[Fe][m].format=(l=n[m])==null?void 0:l.format,e[Fe][m].dimensions=(d=n[m])==null?void 0:d.dimensions))):s||(e.fileTypes[Q]=Ce.parseConfig(o,t,n)));}// prettier-ignore
|
|
126
|
+
},{key:"processImagesConfig",value:function processImagesConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/*"},(s==null?void 0:s[m])||{});e.fileTypes[Q]=Ce.parseConfig(o,t,n);}// default for direct service
|
|
127
|
+
},{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$m,_n$acceptedFormats,_s$maxNumberOfFiles;var n,s;e&&((_e$m=e[m])!==null&&_e$m!==void 0?_e$m:e[m]={},(_n$acceptedFormats=(n=e[m]).acceptedFormats)!==null&&_n$acceptedFormats!==void 0?_n$acceptedFormats:n.acceptedFormats=t,(_s$maxNumberOfFiles=(s=e[m]).maxNumberOfFiles)!==null&&_s$maxNumberOfFiles!==void 0?_s$maxNumberOfFiles:s.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,n){Ce.populateDefaultFileIO(n==null?void 0:n[G],".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),Ce.populateDefaultFileIO(n==null?void 0:n[Q],".png,.jpg");var s=gs.createNew(e.remarkable);Ce.processImagesConfig(t,s,e[Q],n==null?void 0:n[Q]),Ce.processCamera(t,s,e[Fe],e[Q]),Ce.processGifConfig(t,s,e[Dn],n==null?void 0:n[Dn]),Ce.processAudioConfig(t,s,e[G],n==null?void 0:n[G]),Ce.processMicrophone(t,s,e[ft],e[G]),Ce.processMixedFiles(t,s,e[ho]);}}]);}();var Sn=/*#__PURE__*/function(){function Sn(e,t,n){var _a$url;_classCallCheck(this,Sn);var s,i,o,a,c;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=Sn.canSendMessage,this.connectSettings={},this.fileTypes={},this.completionsHandlers={},this.streamHandlers={},this.deepChat=e,this.demo=n,Object.assign(this.rawBody,(s=e.connect)==null?void 0:s.additionalBodyProps),this.totalMessagesMaxCharLength=(i=e==null?void 0:e.requestBodyLimits)==null?void 0:i.totalMessagesMaxCharLength,this.maxMessages=(o=e==null?void 0:e.requestBodyLimits)==null?void 0:o.maxMessages,Ce.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=Et.URL),this.connectSettings.websocket&&ke.setup(this),this.stream=((c=this.deepChat.connect)==null?void 0:c.stream)||ce.checkForStream(this.deepChat),e.loadHistory&&bs.addErrorPrefix(this);}return _createClass(Sn,[{key:"verifyKey",value:function verifyKey(e,t){}},{key:"getServiceIOByType",value:function getServiceIOByType(e){if(e[y].startsWith(G)&&this.fileTypes[G])return this.fileTypes[G];if(e[y].startsWith(W)){if(this.fileTypes[Dn]&&e[y].endsWith("/gif"))return this.fileTypes[Dn];if(this.fileTypes[Q])return this.fileTypes[Q];if(this[Fe])return this[Fe];}return this.fileTypes[ho];}},{key:"request",value:function(){var _request4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(e,t){var n,_args26=arguments;return _regenerator().w(function(_context26){while(1)switch(_context26.n){case 0:n=_args26.length>2&&_args26[2]!==undefined?_args26[2]:!0;return _context26.a(2,this.stream&&!V.isSimulation(this.stream)?V.request(this,e,t,n):be.request(this,e,t,n));}},_callee26,this);}));function request(_x53,_x54){return _request4.apply(this,arguments);}return request;}()},{key:"callAPIWithText",value:function(){var _callAPIWithText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(e,t){var _o$headers,_a$H;var i,o,a,c,n,s;return _regenerator().w(function(_context27){while(1)switch(_context27.n){case 0:n=_objectSpread({messages:t},this.rawBody);s=!1;(i=this.connectSettings.headers)!=null&&i[H]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$H=(a=this.connectSettings.headers)[H])!==null&&_a$H!==void 0?_a$H:a[H]=Y,s=!0);_context27.n=1;return this.request(n,e);case 1:s&&((c=this.connectSettings.headers)==null||delete c[H]);case 2:return _context27.a(2);}},_callee27,this);}));function callAPIWithText(_x55,_x56){return _callAPIWithText.apply(this,arguments);}return callAPIWithText;}()},{key:"callApiWithFiles",value:function(){var _callApiWithFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(e,t,n){var s,i,o;return _regenerator().w(function(_context28){while(1)switch(_context28.n){case 0:s=Sn.createCustomFormDataBody(this.rawBody,t,n),i=this.connectSettings,o=this.getServiceIOByType(n[0]);this.connectSettings=(o==null?void 0:o.connect)||this.connectSettings;_context28.n=1;return this.request(s,e,!1);case 1:this.connectSettings=i;case 2:return _context28.a(2);}},_callee28,this);}));function callApiWithFiles(_x57,_x58,_x59){return _callApiWithFiles.apply(this,arguments);}return callApiWithFiles;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(e,t,n){return _regenerator().w(function(_context29){while(1)switch(_context29.n){case 0:n?this.callApiWithFiles(e,t,n):this.callAPIWithText(e,t);case 1:return _context29.a(2);}},_callee29,this);}));function callServiceAPI(_x60,_x61,_x62){return _callServiceAPI.apply(this,arguments);}return callServiceAPI;}()// prettier-ignore
|
|
128
|
+
},{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(e,t){var s,n,i;return _regenerator().w(function(_context30){while(1)switch(_context30.n){case 0:if(this.connectSettings){_context30.n=1;break;}throw new Error($e);case 1:n=Gn.processMessages(t.messageToElements.map(function(_ref24){var _ref25=_slicedToArray(_ref24,1),i=_ref25[0];return i;}),this.maxMessages,this.totalMessagesMaxCharLength);if(this.connectSettings.websocket&&(!this.connectSettings.handler||this.connectSettings.url!==Et.URL)){i=_objectSpread({messages:n},this.rawBody);e[m]&&(s=this.getServiceIOByType(e[m][0]))!=null&&s.connect?this.callApiWithFiles(t,n,e[m]):ke.sendWebsocket(this,i,t,!1);}else this.callServiceAPI(t,n,e[m]);case 2:return _context30.a(2);}},_callee30,this);}));function callAPI(_x63,_x64){return _callAPI.apply(this,arguments);}return callAPI;}()},{key:"extractResultData",value:function(){var _extractResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(e){return _regenerator().w(function(_context31){while(1)switch(_context31.n){case 0:if(!e.result){_context31.n=1;break;}return _context31.a(2,ce.handleResponseProperty(e));case 1:if(!D.validateResponseFormat(e,!!this.stream)){_context31.n=2;break;}return _context31.a(2,e);case 2:return _context31.a(2);}},_callee31,this);}));function extractResultData(_x65){return _extractResultData.apply(this,arguments);}return extractResultData;}()},{key:"isDirectConnection",value:function isDirectConnection(){return!1;}},{key:"isWebModel",value:function isWebModel(){return!1;}},{key:"isCustomView",value:function isCustomView(){return!1;}}],[{key:"canSendMessage",value:function canSendMessage(e,t,n){return n?!0:!!(e&&e.trim()!=="")||!!(t&&t[K]>0);}},{key:"createCustomFormDataBody",value:function createCustomFormDataBody(e,t,n){var s=new FormData();n.forEach(function(a){return s.append("files",a);}),Object.keys(e).forEach(function(a){return s.append(a,String(e[a]));});var i=0;t.slice(0,t[K]-1).forEach(function(a){s.append("message".concat(i+=1),ae(a));});var o=t[t[K]-1];return o[h]&&(delete o[m],s.append("message".concat(i+=1),ae(o))),s;}}]);}();var M=/*#__PURE__*/function(_Sn){// prettier-ignore
|
|
129
|
+
function M(e,t,n,s,i){var _this15;_classCallCheck(this,M);var o;_this15=_callSuper(this,M,[e,i]),_this15.insertKeyPlaceholderText="API Key",_this15.keyHelpUrl="",_this15.asyncCallInProgress=!1,_this15.systemMessage="",Object.assign(_this15.rawBody,(o=e.connect)==null?void 0:o.additionalBodyProps),_this15._keyVerificationDetails=t,_this15._buildHeadersFunc=n,s&&_this15.setApiKeyProperties(s),_this15.connectSettings=_this15.buildConnectSettings(_this15.key||"",e.connect);return _this15;}_inherits(M,_Sn);return _createClass(M,[{key:"setApiKeyProperties",value:function setApiKeyProperties(e){this.key=e.key,e.validateKeyProperty&&(this.validateKeyProperty=e.validateKeyProperty);}},{key:"buildConnectSettings",value:function buildConnectSettings(e,t){var _n$headers;var n=t!==null&&t!==void 0?t:{};return(_n$headers=n.headers)!==null&&_n$headers!==void 0?_n$headers:n.headers={},Object.assign(n.headers,this._buildHeadersFunc(e)),n;}},{key:"completeConfig",value:function completeConfig(e,t){e.system_prompt&&(this.systemMessage=e.system_prompt),t&&(this.functionHandler=t),delete e.system_prompt,delete e.key,delete e.function_handler,Object.assign(this.rawBody,e);}},{key:"keyAuthenticated",value:function keyAuthenticated(e,t){this.connectSettings=this.buildConnectSettings(t,this.connectSettings),this.key=t,e();}// prettier-ignore
|
|
130
|
+
},{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,n=_this$_keyVerificatio.url,s=_this$_keyVerificatio.method,i=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,c=_this$_keyVerificatio.augmentUrl,l=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(c==null?void 0:c(e))||n;be.verifyKey(e,d,l,s,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,i,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}},{key:"processMessages",value:function processMessages(e){return Gn.getCharacterLimitMessages(e,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this.systemMessage[K]:-1);}},{key:"addSystemMessage",value:function addSystemMessage(e){this.systemMessage&&e.unshift(_defineProperty(_defineProperty({},S,ps),"content",this.systemMessage));}},{key:"callDirectServiceServiceAPI",value:function(){var _callDirectServiceServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(e,t,n,s,i){var o,a;return _regenerator().w(function(_context32){while(1)switch(_context32.n){case 0:if(this.connectSettings){_context32.n=1;break;}throw new Error($e);case 1:o=n(this.rawBody,t),a=s?this.stream:!1;if(!(a&&(_typeof(a)!==U||!a.simulation)||o.stream)){_context32.n=2;break;}o.stream=!0,s!=null&&s.readable&&(this.stream={readable:!0}),V.request(this,o,e);_context32.n=4;break;case 2:_context32.n=3;return be.request(this,o,e,i);case 3:return _context32.a(2,_context32.v);case 4:return _context32.a(2);}},_callee32,this);}));function callDirectServiceServiceAPI(_x66,_x67,_x68,_x69,_x70){return _callDirectServiceServiceAPI.apply(this,arguments);}return callDirectServiceServiceAPI;}()},{key:"callToolFunction",value:function(){var _callToolFunction=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(e,t){var i,o,n,a,c,_t14,_t15;return _regenerator().w(function(_context33){while(1)switch(_context33.n){case 0:this.asyncCallInProgress=!0;_context33.n=1;return e(t);case 1:n=_context33.v;if(Array.isArray(n)){_context33.n=6;break;}if(!n[h]){_context33.n=5;break;}a=_defineProperty({},h,n[h]);_context33.n=2;return(o=(i=this.deepChat).responseInterceptor)==null?void 0:o.call(i,a);case 2:_t14=_context33.v;if(_t14){_context33.n=3;break;}_t14=a;case 3:c=_t14;if(!Array.isArray(c)){_context33.n=4;break;}throw Error("Function tool response interceptor cannot return an array");case 4:return _context33.a(2,{processedResponse:c});case 5:throw Error(bn);case 6:_context33.n=7;return Promise.all(n);case 7:_t15=_context33.v;return _context33.a(2,{responses:_t15});}},_callee33,this);}));function callToolFunction(_x71,_x72){return _callToolFunction.apply(this,arguments);}return callToolFunction;}()},{key:"makeAnotherRequest",value:function makeAnotherRequest(e,t,n){try{return t&&(this.stream?V.request(this,e,t):be.request(this,e,t)),_defineProperty({},h,n||"");}catch(s){throw this.asyncCallInProgress=!1,s;}}},{key:"genereteAPIKeyName",value:function genereteAPIKeyName(e){return"".concat(e," API Key");}},{key:"extractStreamResultWToolsGeneric",value:function(){var _extractStreamResultWToolsGeneric=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(e,t,n,s,i){var o,a,c;return _regenerator().w(function(_context34){while(1)switch(_context34.n){case 0:o=t.delta,a=t.finish_reason;if(!(a==="tool_calls")){_context34.n=1;break;}c={tool_calls:e._streamToolCalls};return _context34.a(2,(e._streamToolCalls=void 0,this.handleToolsGeneric(c,n,e.messages,s,i)));case 1:o!=null&&o.tool_calls&&(e._streamToolCalls?o.tool_calls.forEach(function(c,l){e._streamToolCalls&&(e._streamToolCalls[l]["function"].arguments+=c["function"].arguments);}):e._streamToolCalls=o.tool_calls);case 2:return _context34.a(2,_defineProperty({},h,(o==null?void 0:o.content)||""));}},_callee34,this);}));function extractStreamResultWToolsGeneric(_x73,_x74,_x75,_x76,_x77){return _extractStreamResultWToolsGeneric.apply(this,arguments);}return extractStreamResultWToolsGeneric;}()},{key:"handleToolsGeneric",value:function(){var _handleToolsGeneric=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(e,t,n,s,i){var o,a,_yield$this$callToolF,c,l;return _regenerator().w(function(_context35){while(1)switch(_context35.n){case 0:if(!(!e.tool_calls||!s||!t)){_context35.n=1;break;}throw Error(en);case 1:o=w(s);a=e.tool_calls.map(function(d){return{name:d["function"].name,arguments:d["function"].arguments};});_context35.n=2;return this.callToolFunction(t,a);case 2:_yield$this$callToolF=_context35.v;c=_yield$this$callToolF.responses;l=_yield$this$callToolF.processedResponse;if(!l){_context35.n=3;break;}return _context35.a(2,l);case 3:if(!(i&&(o.messages=o.messages.slice(o.messages[K]-1),i.message&&o.messages.unshift(_defineProperty(_defineProperty({},S,ps),"content",i.message))),o.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},S,xt),"content",null)),!c.find(function(_ref28){var d=_ref28.response;return _typeof(d)!==_e;})&&a[K]===c[K])){_context35.n=4;break;}return _context35.a(2,(c.forEach(function(d,u){var b;var g=(b=e.tool_calls)==null?void 0:b[u];o==null||o.messages.push(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},S,"tool"),"tool_call_id",g==null?void 0:g.id),"name",g==null?void 0:g["function"].name),"content",d.response));}),this.makeAnotherRequest(o,n)));case 4:throw Error(bn);case 5:return _context35.a(2);}},_callee35,this);}));function handleToolsGeneric(_x78,_x79,_x80,_x81,_x82){return _handleToolsGeneric.apply(this,arguments);}return handleToolsGeneric;}()},{key:"updateSessionId",value:function updateSessionId(e){this.messages&&this.messages.messageToElements[K]>0&&(this.messages.messageToElements[this.messages.messageToElements[K]-1][0]._sessionId=e);}}],[{key:"getRoleViaUser",value:function getRoleViaUser(e){return e===F?F:xt;}},{key:"getRoleViaAI",value:function getRoleViaAI(e){return e===te?xt:F;}},{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t[y]===W;}).map(function(t){return _defineProperty(_defineProperty({},y,qe),qe,{url:t[T]||""});}).filter(function(t){return t[qe].url[K]>0;});}},{key:"getTextWImagesContent",value:function getTextWImagesContent(e){if(e[m]&&e[m][K]>0){var t=this.getImageContent(e[m]);return e[h]&&e[h].trim()[K]>0&&t.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),t[K]>0?t:e[h]||"";}return e[h]||"";}},{key:"getTextWFilesContent",value:function getTextWFilesContent(e,t){if(e[m]&&e[m][K]>0){var n=t(e[m]);return e[h]&&e[h].trim()[K]>0&&n.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),n;}return e[h]||"";}}]);}(Sn);var Ks=/*#__PURE__*/function(){function Ks(){_classCallCheck(this,Ks);}return _createClass(Ks,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?Ks.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,Ks.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var kt=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
|
|
131
|
+
function kt(){var _this16;_classCallCheck(this,kt);_this16=_callSuper(this,kt),_this16._waitingToRender_=!1,_this16._propUpdated_=!1,Object.keys(kt._attributeToProperty_).forEach(function(e){var t=kt._attributeToProperty_[e];_this16.constructPropertyAccessors(t),_this16.hasOwnProperty(e)||_this16.constructPropertyAccessors(t,e);});return _this16;}_inherits(kt,_HTMLElement);return _createClass(kt,[{key:"constructPropertyAccessors",value:// need to be called here as accessors need to be set for the class instance
|
|
132
|
+
function constructPropertyAccessors(e,t){var n;Object.defineProperty(this,t||e,{get:function get(){return n;},set:function set(o){n=o,t?this[e]=o:Ks.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,n){if(t===n)return;var s=kt._attributes_[e](n),i=kt._attributeToProperty_[e];this[i]=s;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(kt._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));kt._attributes_={},kt._attributeToProperty_={};var Hi=kt;var rl="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path d=\"\n\t\t\tM669.727,273.516c-22.891-2.476-46.15-3.895-69.727-4.248c-103.025,0.457-209.823,25.517-310.913,73.536\n\t\t\tc-75.058,37.122-148.173,89.529-211.67,154.174C46.232,529.978,6.431,577.76,0,628.74c0.76,44.162,48.153,98.67,77.417,131.764\n\t\t\tc59.543,62.106,130.754,113.013,211.67,154.174c2.75,1.335,5.51,2.654,8.276,3.955l-75.072,131.102l102.005,60.286l551.416-960.033\n\t\t\tl-98.186-60.008L669.727,273.516z M902.563,338.995l-74.927,129.857c34.47,44.782,54.932,100.006,54.932,159.888\n\t\t\tc0,149.257-126.522,270.264-282.642,270.264c-6.749,0-13.29-0.728-19.922-1.172l-49.585,85.84c22.868,2.449,45.99,4.233,69.58,4.541\n\t\t\tc103.123-0.463,209.861-25.812,310.84-73.535c75.058-37.122,148.246-89.529,211.743-154.174\n\t\t\tc31.186-32.999,70.985-80.782,77.417-131.764c-0.76-44.161-48.153-98.669-77.417-131.763\n\t\t\tc-59.543-62.106-130.827-113.013-211.743-154.175C908.108,341.478,905.312,340.287,902.563,338.995L902.563,338.995z\n\t\t\tM599.927,358.478c6.846,0,13.638,0.274,20.361,0.732l-58.081,100.561c-81.514,16.526-142.676,85.88-142.676,168.897\n\t\t\tc0,20.854,3.841,40.819,10.913,59.325c0.008,0.021-0.008,0.053,0,0.074l-58.228,100.854\n\t\t\tc-34.551-44.823-54.932-100.229-54.932-160.182C317.285,479.484,443.808,358.477,599.927,358.478L599.927,358.478z M768.896,570.513\n\t\t\tL638.013,797.271c81.076-16.837,141.797-85.875,141.797-168.603C779.81,608.194,775.724,588.729,768.896,570.513L768.896,570.513z\"\n\t\t\t/>\n</svg>\n",ol="<?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 Ut=/*#__PURE__*/function(){function Ut(){_classCallCheck(this,Ut);}return _createClass(Ut,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Kt=/*#__PURE__*/function(){function Kt(){_classCallCheck(this,Kt);}return _createClass(Kt,null,[{key:"changeVisibility",value:// prettier-ignore
|
|
133
|
+
function changeVisibility(e,t,n,s){s.target.id===Kt.VISIBLE_ICON_ID?(t[E].display="none",n[E].display="block",e[y]="password"):(t[E].display="block",n[E].display="none",e[y]=h);}},{key:"createIconElement",value:function createIconElement(e,t){var n=Ut.createSVGElement(e);return n.id=t,n[f].add("visibility-icon"),n;}// prettier-ignore
|
|
134
|
+
},{key:"create",value:function create(e){var t=x();t.id="visibility-icon-container";var n=Kt.createIconElement(ol,Kt.VISIBLE_ICON_ID);n[E].display="none",t.appendChild(n);var s=Kt.createIconElement(rl,"not-visible-icon");return t.appendChild(s),t.onclick=Kt.changeVisibility.bind(this,e,n,s),t;}}]);}();Kt.VISIBLE_ICON_ID="visible-icon";var $i=Kt;var Oe=/*#__PURE__*/function(){function Oe(){_classCallCheck(this,Oe);}return _createClass(Oe,null,[{key:"createCautionText",value:function createCautionText(){var e=x("a");return e[f].add("insert-key-input-help-text"),e.innerText="Please exercise CAUTION when inserting your API key outside of deepchat.dev or localhost!!",e;}},{key:"createHelpLink",value:function createHelpLink(e){var t=x("a");return t[f].add("insert-key-input-help-text"),t.href=e,t.innerText="Find more info here",t.target="_blank",t;}},{key:"createFailText",value:function createFailText(){var e=x();return e.id="insert-key-input-invalid-text",e[E].display="none",e;}},{key:"createHelpTextContainer",value:function createHelpTextContainer(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var n=x();n.id="insert-key-help-text-container";var s=x();s.id="insert-key-help-text-contents";var i=Oe.createFailText();if(s.appendChild(i),e){var o=Oe.createHelpLink(e);s.appendChild(o);}if(t===!0){var _o3=Oe.createCautionText();s.appendChild(_o3);}return n.appendChild(s),{helpTextContainerElement:n,failTextElement:i};}},{key:"onFail",value:function onFail(e,t,n,s){e[f].replace("insert-key-input-valid","insert-key-input-invalid"),n.innerText=s,n[E].display="block",t.innerText="Start",e[f].remove(Dt);}},{key:"onLoad",value:function onLoad(e,t){e[f].add(Dt),t.innerHTML='<div id="loading-key"></div>';}// prettier-ignore
|
|
135
135
|
},{key:"verifyKey",value:function verifyKey(e,t,n){var s=e.value.trim();n.verifyKey(s,t);}// prettier-ignore
|
|
136
|
-
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,n,s,
|
|
137
|
-
},{key:"createContents",value:function createContents(e,t){var d;var n=x();n.id="insert-key-contents";var s=
|
|
138
|
-
},{key:"
|
|
139
|
-
},{key:"
|
|
140
|
-
{
|
|
141
|
-
{
|
|
142
|
-
{
|
|
143
|
-
{
|
|
144
|
-
|
|
145
|
-
},{key:"
|
|
146
|
-
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(e,t){var _this21=this;var o,a,c,l,d,u,g,n,s,r,_this$getConfig,b,_,v,_b,_t17;return _regenerator().w(function(_context38){while(1)switch(_context38.p=_context38.n){case 0:this.scrollToTop(),Z.chat=e,this._isModelLoading=!0;n=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;s=function s(b){var _;(_=_this21._messages)==null||_.addNewMessage({html:"<div>".concat(b[h],"</div>"),overwrite:!0,sendUpdate:!1}),n&&(setTimeout(function(){return V.scrollToBottom(_this21._messages);}),n=!1);};Z.chat.setInitProgressCallback(s);_context38.p=1;_this$getConfig=this.getConfig(),b=_this$getConfig.model,_=_this$getConfig.appConfig,v={};this._webModel.instruction&&(v.conv_config=_defineProperty({},jn,this._webModel.instruction));this._conversationHistory.length>0&&(v.conversation_history=this._conversationHistory);_context38.n=2;return Z.chat.reload(b,v,_,t);case 2:r=_context38.v;_context38.n=4;break;case 3:_context38.p=3;_t17=_context38.v;return _context38.a(2,this.unloadChat(_t17));case 4:if((c=(a=this.deepChat)._validationHandler)==null||c.call(a),(l=this._webModel.introMessage)!=null&&l.removeAfterLoad)this._webModel.introMessage.displayed===!1?(u=this._messages)==null||u.removeLastMessage():(g=this._removeIntro)==null||g.call(this);else{_b=zs.setUpAfterLoad(r,this._webModel.introMessage,this._chatEl,!!this._webModel.worker);(d=this._messages)==null||d.addNewMessage({html:_b,overwrite:!0,sendUpdate:!1});}this._isModelLoaded=!0,this._isModelLoading=!1;case 5:return _context38.a(2);}},_callee38,this,[[1,3]]);}));function loadModel(_x85,_x86){return _loadModel.apply(this,arguments);}return loadModel;}()},{key:"unloadChat",value:function(){var _unloadChat=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(e){var t,_t18;return _regenerator().w(function(_context39){while(1)switch(_context39.n){case 0:(t=this._messages)==null||t.addNewErrorMessage(oe,Z.GENERIC_ERROR);console[p](e);this._isModelLoaded=!1;this._isModelLoading=!1;_t18=Z.chat;if(!_t18){_context39.n=2;break;}_context39.n=1;return Z.chat.unload();case 1:Z.chat=void 0;case 2:return _context39.a(2);}},_callee39,this);}));function unloadChat(_x87){return _unloadChat.apply(this,arguments);}return unloadChat;}()},{key:"immediateResp",value:function(){var _immediateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(e,t,n){var s,r,_t19,_t20,_t21;return _regenerator().w(function(_context40){while(1)switch(_context40.n){case 0:_t19=_defineProperty;_t20={};_t21=h;_context40.n=1;return n.generate(t,void 0,0);case 1:s=_t19(_t20,_t21,_context40.v);_context40.n=2;return Z.processResponse(this.deepChat,e,s);case 2:r=_context40.v;r&&r.forEach(function(o){return e.addNewMessage(o);}),this.completionsHandlers.onFinish();case 3:return _context40.a(2);}},_callee40,this);}));function immediateResp(_x88,_x89,_x90){return _immediateResp.apply(this,arguments);}return immediateResp;}()},{key:"streamResp",value:function(){var _streamResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(e,t,n){var _this22=this;var s;return _regenerator().w(function(_context42){while(1)switch(_context42.n){case 0:this.streamHandlers.onAbort=function(){n.interruptGenerate();},this.streamHandlers.onOpen();s=new gt(e);_context42.n=1;return n.generate(t,/*#__PURE__*/function(){var _ref31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(r,o){var a;return _regenerator().w(function(_context41){while(1)switch(_context41.n){case 0:_context41.n=1;return Z.processResponse(_this22.deepChat,e,_defineProperty({},h,o));case 1:a=_context41.v;a&&s.upsertStreamedMessage(_defineProperty(_defineProperty({},h,a[0][h]),"overwrite",!0));case 2:return _context41.a(2);}},_callee41);}));return function(_x94,_x95){return _ref31.apply(this,arguments);};}());case 1:s.finaliseStreamedMessage();this.streamHandlers.onClose();case 2:return _context42.a(2);}},_callee42,this);}));function streamResp(_x91,_x92,_x93){return _streamResp.apply(this,arguments);}return streamResp;}()},{key:"generateRespByType",value:function(){var _generateRespByType=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43(e,t,n,s){var r,_t22;return _regenerator().w(function(_context43){while(1)switch(_context43.p=_context43.n){case 0:_context43.p=0;if(!n){_context43.n=2;break;}_context43.n=1;return this.streamResp(e,t,s);case 1:_context43.n=3;break;case 2:_context43.n=3;return this.immediateResp(e,t,s);case 3:_context43.n=5;break;case 4:_context43.p=4;_t22=_context43.v;(r=this._messages)==null||r.addNewErrorMessage(oe),console.log(_t22);case 5:return _context43.a(2);}},_callee43,this,[[0,4]]);}));function generateRespByType(_x96,_x97,_x98,_x99){return _generateRespByType.apply(this,arguments);}return generateRespByType;}()},{key:"generateResp",value:function(){var _generateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44(e,t,n){var s,_yield$D$processReque5,r,o,a,c,l;return _regenerator().w(function(_context44){while(1)switch(_context44.n){case 0:s=t[t.length-1][h];_context44.n=1;return D.processRequestInterceptor(this.deepChat,{body:_defineProperty({},h,s)});case 1:_yield$D$processReque5=_context44.v;r=_yield$D$processReque5.body;o=_yield$D$processReque5.error;a=!!this.stream;try{if(o)D.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!r||!r[h]){c=ta({body:r},!1);console[p](c);l=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;D.onInterceptorError(e,c,l);}else this.generateRespByType(e,r[h],!!this.stream,n);}catch(c){this.unloadChat(c);}case 2:return _context44.a(2);}},_callee44,this);}));function generateResp(_x100,_x101,_x102){return _generateResp.apply(this,arguments);}return generateResp;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45(e,t){var n,s;return _regenerator().w(function(_context45){while(1)switch(_context45.n){case 0:if(this._isModelLoaded){_context45.n=3;break;}if(!this._loadOnFirstMessage){_context45.n=2;break;}_context45.n=1;return this.init();case 1:_context45.n=3;break;case 2:return _context45.a(2);case 3:!Z.chat||this._isModelLoading||((n=this._webModel.introMessage)!=null&&n.removeAfterMessage&&((s=this._removeIntro)==null||s.call(this)),e.addLoadingMessage(),this.generateResp(e,t,Z.chat));case 4:return _context45.a(2);}},_callee45,this);}));function callServiceAPI(_x103,_x104){return _callServiceAPI2.apply(this,arguments);}return callServiceAPI;}()},{key:"canSubmit",value:function canSubmit(e){return!(e!=null&&e.trim())||this._isModelLoading?!1:this._loadOnFirstMessage?!0:!!this._isModelLoaded;}},{key:"isWebModel",value:function isWebModel(){return!0;}}],[{key:"setUpHistory",value:function setUpHistory(e,t){t.forEach(function(n,s){if(n[S]===F&&n[h]){var r=t[s+1];r!=null&&r[h]&&r[S]!==F&&e.push([n[h],r[h]]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46(e,t,n){var a,c,s,r,o,d,_t23;return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:_context46.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,n);case 1:_t23=_context46.v;if(_t23){_context46.n=2;break;}_t23=n;case 2:s=_t23;if(!((c=e.connect)!=null&&c.stream&&Array.isArray(s)&&s.length>1)){_context46.n=3;break;}console[p](fo);return _context46.a(2);case 3:r=Array.isArray(s)?s:[s],o=r.find(function(l){return _typeof(l[p])===_e;});if(!o){_context46.n=4;break;}D.displayError(t,new Error(o[p]));return _context46.a(2);case 4:if(!r.find(function(d){return!d||!d[h];})){_context46.n=5;break;}d=na(n,!!e.responseInterceptor,s);D.displayError(t,new Error(d));return _context46.a(2);case 5:return _context46.a(2,r);}},_callee46);}));function processResponse(_x105,_x106,_x107){return _processResponse.apply(this,arguments);}return processResponse;}()},{key:"clearAllCache",value:function clearAllCache(){Z.clearCache("webllm/model"),Z.clearCache("webllm/wasm");}},{key:"clearCache",value:function clearCache(e){caches.open(e).then(function(t){t.keys().then(function(n){n.forEach(function(s){t["delete"](s);});});});}}]);}(vn);Z.GENERIC_ERROR="Error, please check the [troubleshooting](".concat(X,"webModel#troubleshooting) section of documentation for help."),Z.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",Z.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",Z.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",Z.MODULE_SEARCH_LIMIT_S=5;var bs=Z;var pe=function pe(i,e,t,n){return{url:i,method:e,handleVerificationResult:t,augmentUrl:n};},ol=function ol(i){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J);},al=function al(i,e,t,n){var s=i;Array.isArray(s[p])&&s[p][0]==="Error in `parameters`: field required"?t(e):n(ue);},cl=function cl(){return pe("https://api-inference.huggingface.co/models/gpt2",ye,al);},cs=/*#__PURE__*/function(_M){// prettier-ignore
|
|
147
|
-
function cs(e,t,n,s,
|
|
148
|
-
function
|
|
149
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
150
|
-
function
|
|
151
|
-
function
|
|
152
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
153
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
154
|
-
_inherits(
|
|
155
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e,t,n){var o,a,s,r;return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(this.connectSettings){_context60.n=1;break;}throw new Error(je);case 1:if(n){_context60.n=2;break;}throw new Error(sr);case 2:s=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim(),r=this.createFormDataBody(this.rawBody,n[0],s);D.tempRemoveContentHeader(this.connectSettings,be.request.bind(this,this,r,e),!1);case 3:return _context60.a(2);}},_callee60,this);}));function callServiceAPI(_x129,_x130,_x131){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e){var t;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(!e.message){_context61.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.base64)),y,K);});return _context61.a(2,_defineProperty({},m,t));}},_callee61);}));function extractResultData(_x132){return _extractResultData8.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(Ei);var bl=/*#__PURE__*/function(_Ut6){function bl(e){_classCallCheck(this,bl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.translation,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,bl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(bl,_Ut6);return _createClass(bl,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e){var t;return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(!e[p]){_context62.n=1;break;}throw e[p];case 1:return _context62.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.translation_text)||""));}},_callee62);}));function extractResultData(_x133){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Ut);var Zs=/*#__PURE__*/function(_Ei4){function Zs(e){var _this31;_classCallCheck(this,Zs);var r;var t=w(e.directConnection),n=t.stabilityAI;_this31=_callSuper(this,Zs,[e,yi(),bi,n]),_this31.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this31.textInputPlaceholderText="Describe an image";var s=(r=t.stabilityAI)==null?void 0:r.textToImage;_typeof(s)=="object"&&(s.engine_id&&(_this31.url="https://api.stability.ai/v1/generation/".concat(s.engine_id,"/text-to-image")),s.weight!==void 0&&s.weight!==null&&(_this31._imageWeight=s.weight),Zs.cleanConfig(s),Object.assign(_this31.rawBody,s)),_this31.canSendMessage=Zs.canSendTextMessage;return _this31;}_inherits(Zs,_Ei4);return _createClass(Zs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=w(e),r=_defineProperty({},h,n);return this._imageWeight&&(r.weight=this._imageWeight),s.text_prompts=[r],s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e,t){return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context63.a(2);}},_callee63,this);}));function callServiceAPI(_x134,_x135){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e){var t;return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:if(!e.message){_context64.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.base64)),y,K);});return _context64.a(2,_defineProperty({},m,t));}},_callee64);}));function extractResultData(_x136){return _extractResultData0.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendTextMessage",value:function canSendTextMessage(e){return!!(e&&e.trim()!=="");}}]);}(Ei);var yl=/*#__PURE__*/function(_Ut7){function yl(e){var _this32;_classCallCheck(this,yl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.fillMask,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this32=_callSuper(this,yl,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this32.permittedErrorPrefixes=[ir,"No mask_token"];return _this32;}_inherits(yl,_Ut7);return _createClass(yl,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){var t;return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:if(!e[p]){_context65.n=1;break;}throw e[p];case 1:return _context65.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.sequence)||""));}},_callee65);}));function extractResultData(_x137){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(Ut);var hr=function hr(i){return _defineProperty(_defineProperty({},H,J),le,"".concat(Ae).concat(i));},El=function El(i,e,t,n){var s=i;s[p]?s[p].message===fi?n(ue):n(He):t(e);},dr=function dr(){return pe("https://open.bigmodel.cn/api/paas/v4/models",he,El);};var _l=/*#__PURE__*/function(_M3){function _l(e){var _o$model,_a$voice;var _this33;_classCallCheck(this,_l);var r,o,a;var t=w(e.directConnection),n=t.bigModel;_this33=_callSuper(this,_l,[e,dr(),hr,n]),_this33.insertKeyPlaceholderText=_this33.genereteAPIKeyName("BigModel"),_this33.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this33.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this33.permittedErrorPrefixes=[le,we];var s=(r=t.bigModel)==null?void 0:r.textToSpeech;_typeof(s)===U&&(_this33.cleanConfig(s),Object.assign(_this33.rawBody,s)),(_o$model=(o=_this33.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this33.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this33;}_inherits(_l,_M3);return _createClass(_l,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e,t){return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:return _context66.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee66,this);}));function callServiceAPI(_x138,_x139){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e){var t,n;return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:t=new Blob([e],_defineProperty({},y,"audio/mpeg")),n=URL.createObjectURL(t);return _context67.a(2,_defineProperty({},m,[_defineProperty(_defineProperty({},T,n),y,q)]));}},_callee67);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(M);var ur=function ur(i){return _defineProperty(_defineProperty({},H,J),le,"".concat(Ae).concat(i));},vl=function vl(i,e,t,n){var s=i;s[p]?s[p].message===fi?n(ue):n(He):t(e);},pr=function pr(){return pe("https://api.together.xyz/v1/models",he,vl);};var Sl=/*#__PURE__*/function(_M4){function Sl(e){var _o$model2,_a$voice2;var _this34;_classCallCheck(this,Sl);var r,o,a;var t=w(e.directConnection),n=t.together;_this34=_callSuper(this,Sl,[e,pr(),ur,n]),_this34.insertKeyPlaceholderText=_this34.genereteAPIKeyName("Together AI"),_this34.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this34.url="https://api.together.xyz/v1/audio/speech",_this34.permittedErrorPrefixes=[et,we];var s=(r=t.together)==null?void 0:r.textToSpeech;_typeof(s)===U&&_this34.completeConfig(s),(_o$model2=(o=_this34.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this34.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this34;}_inherits(Sl,_M4);return _createClass(Sl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e,t){return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:return _context68.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee68,this);}));function callServiceAPI(_x141,_x142){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee69(e){var t,n;return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:t=new Blob([e],_defineProperty({},y,"audio/mpeg")),n=URL.createObjectURL(t);return _context69.a(2,_defineProperty({},m,[_defineProperty(_defineProperty({},T,n),y,q)]));}},_callee69);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(M);var Qe="https://api.openai.com/v1/",zn="https://platform.openai.com/account/api-keys",Hi="input_text",Jr="input_image",Qr="output_text",Ri="image_generation_call",Io="function_call_output",Yn="response",Kn=function Kn(i){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J);},Mo=function Mo(i,e,t,n){var s=i;s[p]?s[p].code==="invalid_api_key"?n(ue):n(He):t(e);},Wn=function Wn(){return pe("".concat(Qe,"models"),he,Mo);},Zt=/*#__PURE__*/function(){var _ref58=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(i,e,t){var n,s,r,o,a,c,_yield$D$processReque6,l,d,u,g,b,_args70=arguments;return _regenerator().w(function(_context70){while(1)switch(_context70.n){case 0:n=_args70.length>3&&_args70[3]!==undefined?_args70[3]:!0;s=i.connectSettings,r=i.deepChat,o=i.completionsHandlers,a=i.messages;s.method=t;c={body:e,headers:s.headers};_context70.n=1;return D.processRequestInterceptor(r,c);case 1:_yield$D$processReque6=_context70.v;l=_yield$D$processReque6.body;d=_yield$D$processReque6.headers;u=_yield$D$processReque6.error;g=o.onFinish;if(!(u&&a)){_context70.n=2;break;}return _context70.a(2,D.onInterceptorError(a,u,g));case 2:_context70.n=3;return D.fetch(i,d,n,l).then(function(_){return D.processResponseByType(_);});case 3:b=_context70.v;if(!b[p]){_context70.n=4;break;}throw b[p].message;case 4:return _context70.a(2,b);}},_callee70);}));return function Zt(_x144,_x145,_x146){return _ref58.apply(this,arguments);};}(),Xe=/*#__PURE__*/function(){function Xe(){_classCallCheck(this,Xe);}return _createClass(Xe,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(e,t,n,s){var r,o,a,c,_t24;return _regenerator().w(function(_context72){while(1)switch(_context72.p=_context72.n){case 0:r=e.connectSettings.headers;if(r){_context72.n=1;break;}return _context72.a(2);case 1:e.url=s;o=r[H];delete r[H];a=n.map(/*#__PURE__*/function(){var _ref59=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(c){var l;return _regenerator().w(function(_context71){while(1)switch(_context71.n){case 0:l=new FormData();return _context71.a(2,(l.append("purpose","assistants"),l.append("file",c),new Promise(function(d){d(Zt(e,l,ye,!1));})));}},_callee71);}));return function(_x151){return _ref59.apply(this,arguments);};}());_context72.p=2;_context72.n=3;return Promise.all(a);case 3:c=_context72.v.map(function(l){return{id:l.id,name:l.filename};});return _context72.a(2,(r[H]=o,c));case 4:_context72.p=4;_t24=_context72.v;throw r[H]=o,D.displayError(t,_t24),e.completionsHandlers.onFinish(),_t24;case 5:return _context72.a(2);}},_callee72,null,[[2,4]]);}));function storeFiles(_x147,_x148,_x149,_x150){return _storeFiles.apply(this,arguments);}return storeFiles;}()},{key:"getType",value:function getType(e,t){var n=e[t].path;return!n||n.endsWith("png")?K:mn;}},{key:"getFiles",value:function(){var _getFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73(e,t,n,s){var r,a;return _regenerator().w(function(_context73){while(1)switch(_context73.n){case 0:r=t.map(function(_ref60){var c=_ref60.fileId;return e.url="".concat(n).concat(c).concat(s),new Promise(function(l){l(Zt(e,void 0,"GET",!1));});});_context73.n=1;return Promise.all(r);case 1:a=_context73.v.map(function(c,l){return new Promise(function(d){var u=new FileReader();u.readAsDataURL(c),u.onload=function(g){d(_defineProperty(_defineProperty(_defineProperty({},T,g.target.result),"name",t[l].name),y,Xe.getType(t,l)));};});});_context73.n=2;return Promise.all(a);case 2:return _context73.a(2,_context73.v);}},_callee73);}));function getFiles(_x152,_x153,_x154,_x155){return _getFiles.apply(this,arguments);}return getFiles;}()},{key:"getFileName",value:function getFileName(e){var t=e.split("/");return t[t.length-1];}// prettier-ignore
|
|
156
|
-
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
136
|
+
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,n,s,i){var o={onSuccess:s,onFail:Oe.onFail.bind(this,e,t,n),onLoad:Oe.onLoad.bind(this,e,t)},a=Oe.verifyKey.bind(this,e,o,i);t.onclick=a,e.onkeydown=function(c){!e[f].contains(Dt)&&c.key===Ee.ENTER&&a();};}},{key:"createStartButton",value:function createStartButton(){var e=x();return e.id="start-button",e.innerText="Start",e;}},{key:"onInputFocus",value:function onInputFocus(e){e.target[f].replace("insert-key-input-invalid","insert-key-input-valid");}},{key:"createInput",value:function createInput(e){var t=x();t.id="insert-key-input-container";var n=x("input");return n.id="insert-key-input",n.placeholder=e||"API Key",n[y]="password",n[f].add("insert-key-input-valid"),n.onfocus=Oe.onInputFocus,t.appendChild(n),t;}// prettier-ignore
|
|
137
|
+
},{key:"createContents",value:function createContents(e,t){var d;var n=x();n.id="insert-key-contents";var s=Oe.createInput(t.insertKeyPlaceholderText),i=s.children[0],o=$i.create(i);s.appendChild(o),n.appendChild(s);var a=Oe.createStartButton(),_Oe$createHelpTextCon=Oe.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),c=_Oe$createHelpTextCon.helpTextContainerElement,l=_Oe$createHelpTextCon.failTextElement;return n.appendChild(a),n.appendChild(c),Oe.addVerificationEvents(i,a,l,e,t),n;}},{key:"createElements",value:function createElements(e,t){var n=x();n.id="insert-key-view";var s=Oe.createContents(e,t);return n.appendChild(s),n;}},{key:"render",value:function render(e,t,n){var s=Oe.createElements(t,n);e.replaceChildren(s);}}]);}();var it=/*#__PURE__*/function(){function it(){_classCallCheck(this,it);}return _createClass(it,null,[{key:"scopeToTag",value:function scopeToTag(e){return e.replace("webllm/","");}},{key:"encodeName",value:function encodeName(e,t){return"".concat(t.split("/").pop()||"file").concat(it.SEP).concat(it.scopeToTag(e)).concat(it.SEP).concat(encodeURIComponent(t));}// Returns {scope, url} recovered from an exported file name, or undefined if unrecognised.
|
|
138
|
+
},{key:"decodeName",value:function decodeName(e){var t=e.split(it.SEP);if(t.length<3)return;var n=decodeURIComponent(t[t.length-1]),s="webllm/".concat(t[t.length-2]);if(it.CACHE_SCOPES.includes(s))return{scope:s,url:n};}// Read all cached model artifacts into File objects for download/export.
|
|
139
|
+
},{key:"exportFromCache",value:function(){var _exportFromCache=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(){var e,_iterator2,_step2,t,n,s,_iterator3,_step3,i,o,a,_t16,_t17;return _regenerator().w(function(_context36){while(1)switch(_context36.p=_context36.n){case 0:if(!((typeof caches==="undefined"?"undefined":_typeof(caches))>"u")){_context36.n=1;break;}return _context36.a(2,[]);case 1:e=[];_iterator2=_createForOfIteratorHelper(it.CACHE_SCOPES);_context36.p=2;_iterator2.s();case 3:if((_step2=_iterator2.n()).done){_context36.n=18;break;}t=_step2.value;_context36.n=4;return caches.has(t);case 4:if(_context36.v){_context36.n=5;break;}return _context36.a(3,17);case 5:_context36.n=6;return caches.open(t);case 6:n=_context36.v;_context36.n=7;return n.keys();case 7:s=_context36.v;_iterator3=_createForOfIteratorHelper(s);_context36.p=8;_iterator3.s();case 9:if((_step3=_iterator3.n()).done){_context36.n=14;break;}i=_step3.value;_context36.n=10;return n.match(i);case 10:o=_context36.v;if(o){_context36.n=11;break;}return _context36.a(3,13);case 11:_context36.n=12;return o.blob();case 12:a=_context36.v;e.push(new File([a],it.encodeName(t,i.url)));case 13:_context36.n=9;break;case 14:_context36.n=16;break;case 15:_context36.p=15;_t16=_context36.v;_iterator3.e(_t16);case 16:_context36.p=16;_iterator3.f();return _context36.f(16);case 17:_context36.n=3;break;case 18:_context36.n=20;break;case 19:_context36.p=19;_t17=_context36.v;_iterator2.e(_t17);case 20:_context36.p=20;_iterator2.f();return _context36.f(20);case 21:return _context36.a(2,e);}},_callee36,null,[[8,15,16,17],[2,19,20,21]]);}));function exportFromCache(){return _exportFromCache.apply(this,arguments);}return exportFromCache;}()// Seed the cache from previously-exported files so a subsequent reload() resolves offline.
|
|
140
|
+
},{key:"importToCache",value:function(){var _importToCache=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e){var _i5,_Array$from,t,n,_t18,_t19,_t20,_t21;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:if((typeof caches==="undefined"?"undefined":_typeof(caches))>"u"){_context37.n=6;break;}_i5=0,_Array$from=Array.from(e);case 1:if(!(_i5<_Array$from.length)){_context37.n=6;break;}t=_Array$from[_i5];n=it.decodeName(t.name);if(n){_context37.n=2;break;}return _context37.a(3,5);case 2:_context37.n=3;return caches.open(n.scope);case 3:_t18=_context37.v;_t19=new Request(n.url);_t20=Response;_context37.n=4;return t.arrayBuffer();case 4:_t21=_context37.v;_context37.n=5;return _t18.put.call(_t18,_t19,new _t20(_t21));case 5:_i5++;_context37.n=1;break;case 6:return _context37.a(2);}},_callee37);}));function importToCache(_x83){return _importToCache.apply(this,arguments);}return importToCache;}()}]);}();it.CACHE_SCOPES=["webllm/model","webllm/wasm","webllm/config"],it.SEP="__DC__";var ys=it;var We=/*#__PURE__*/function(){function We(){_classCallCheck(this,We);}return _createClass(We,null,[{key:"enableButtons",value:function enableButtons(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;window.webLLM?(e&&(e[j]=!1),t&&(t[j]=!1)):n<Es.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return We.enableButtons(e,t,n+1);},250);}// prettier-ignore
|
|
141
|
+
},{key:"setUpInitial",value:function setUpInitial(e,t,n,s){var i=(t==null?void 0:t.downloadClass)||We.DOWNLOAD_BUTTON_CLASS,o=(t==null?void 0:t.uploadClass)||We.UPLOAD_BUTTON_CLASS,a=(t==null?void 0:t.fileInputClass)||We.FILE_INPUT_CLASS;return setTimeout(function(){var c=n==null?void 0:n.getElementsByClassName(i)[0],l=n==null?void 0:n.getElementsByClassName(a)[0],d=n==null?void 0:n.getElementsByClassName(o)[0];c&&(c.onclick=function(){return e();}),l&&(l.onchange=function(){l[m]&&l[m].length>0&&e(l[m]);}),d&&(d.onclick=function(){return l[Z]();}),(c||d)&&We.enableButtons(c,d);}),(t==null?void 0:t.initialHtml)||"<div>\n Download or upload a web model that will run entirely on your browser: <br/> \n <button disabled class=\"".concat(i," deep-chat-button deep-chat-web-model-button\">Download</button>\n ").concat(s?"":"<input type=\"file\" class=\"".concat(a,"\" hidden multiple />\n <button disabled class=\"").concat(o," deep-chat-button deep-chat-web-model-button\">Upload</button>"),"\n </div>");}},{key:"exportFile",value:function exportFile(e){var t=x("a"),n=4;var _loop2=function _loop2(s){setTimeout(function(){var i=s*n;for(var o=i;o<Math.min(i+n,e.length);o+=1){var a=URL.createObjectURL(e[o]);t.href=a,t.download=e[o].name,document.body.appendChild(t),t[Z](),URL.revokeObjectURL(a);}},500*s);};for(var s=0;s<e.length/n;s+=1){_loop2(s);}}// prettier-ignore
|
|
142
|
+
},{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,n){var s=(e==null?void 0:e.exportFilesClass)||We.EXPORT_BUTTON_CLASS;return setTimeout(function(){var i=t==null?void 0:t.getElementsByClassName(s)[0];i&&(i.onclick=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(){var _t22;return _regenerator().w(function(_context38){while(1)switch(_context38.n){case 0:_t22=We;_context38.n=1;return ys.exportFromCache();case 1:return _context38.a(2,_t22.exportFile.call(_t22,_context38.v));}},_callee38);})));}),(e==null?void 0:e.afterLoadHtml)||"<div>\n Model loaded successfully and has been cached for future requests.\n ".concat(n?"":"<br/> <button style=\"margin-top: 5px\" class=\"".concat(s," deep-chat-button\">Export</button>"),"\n </div>");}}]);}();We.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",We.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",We.FILE_INPUT_CLASS="deep-chat-file-input",We.EXPORT_BUTTON_CLASS="deep-chat-export-button";var Ws=We;var al={model_list:[{model:"https://huggingface.co/mlc-ai/Llama-3.2-1B-Instruct-q4f16_1-MLC",model_id:"Llama-3.2-1B-Instruct-q4f16_1-MLC",model_lib:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/web-llm-models/v0_2_84/base/Llama-3.2-1B-Instruct-q4f16_1_cs1k-webgpu.wasm",vram_required_MB:879.04,low_resource_required:!0,overrides:{context_window_size:4096}},{model:"https://huggingface.co/mlc-ai/Llama-3.2-3B-Instruct-q4f16_1-MLC",model_id:"Llama-3.2-3B-Instruct-q4f16_1-MLC",model_lib:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/web-llm-models/v0_2_84/base/Llama-3.2-3B-Instruct-q4f16_1_cs1k-webgpu.wasm",vram_required_MB:2263.69,low_resource_required:!0,overrides:{context_window_size:4096}},{model:"https://huggingface.co/mlc-ai/Llama-3.1-8B-Instruct-q4f16_1-MLC",model_id:"Llama-3.1-8B-Instruct-q4f16_1-MLC",model_lib:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/web-llm-models/v0_2_84/base/Llama-3_1-8B-Instruct-q4f16_1_cs1k-webgpu.wasm",vram_required_MB:5001,low_resource_required:!1,overrides:{context_window_size:4096}},{model:"https://huggingface.co/mlc-ai/Phi-3.5-mini-instruct-q4f16_1-MLC",model_id:"Phi-3.5-mini-instruct-q4f16_1-MLC",model_lib:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/web-llm-models/v0_2_84/base/Phi-3.5-mini-instruct-q4f16_1_cs1k-webgpu.wasm",vram_required_MB:3672.07,low_resource_required:!1,overrides:{context_window_size:4096}},{model:"https://huggingface.co/mlc-ai/Qwen2.5-1.5B-Instruct-q4f16_1-MLC",model_id:"Qwen2.5-1.5B-Instruct-q4f16_1-MLC",model_lib:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/web-llm-models/v0_2_84/base/Qwen2-1.5B-Instruct-q4f16_1_cs1k-webgpu.wasm",vram_required_MB:1629.75,low_resource_required:!0,overrides:{context_window_size:4096}},{model:"https://huggingface.co/mlc-ai/gemma-2-2b-it-q4f16_1-MLC",model_id:"gemma-2-2b-it-q4f16_1-MLC",model_lib:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/web-llm-models/v0_2_84/base/gemma-2-2b-it-q4f16_1_cs1k-webgpu.wasm",vram_required_MB:1895.3,low_resource_required:!1,required_features:["shader-f16"],overrides:{context_window_size:4096}},{model:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v1.0-q4f16_1-MLC",model_id:"TinyLlama-1.1B-Chat-v1.0-q4f16_1-MLC",model_lib:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/web-llm-models/v0_2_84/base/TinyLlama-1.1B-Chat-v1.0-q4f16_1_cs1k-webgpu.wasm",vram_required_MB:697.24,low_resource_required:!0,required_features:["shader-f16"],overrides:{context_window_size:2048}},{model:"https://huggingface.co/mlc-ai/Mistral-7B-Instruct-v0.3-q4f16_1-MLC",model_id:"Mistral-7B-Instruct-v0.3-q4f16_1-MLC",model_lib:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/web-llm-models/v0_2_84/base/Mistral-7B-Instruct-v0.3-q4f16_1_cs1k-webgpu.wasm",vram_required_MB:4573.39,low_resource_required:!1,required_features:["shader-f16"],overrides:{context_window_size:4096,sliding_window_size:-1}}]},ee=/*#__PURE__*/function(_Sn2){function ee(e){var _this17;_classCallCheck(this,ee);var t,n;_this17=_callSuper(this,ee,[e]),_this17._isModelLoaded=!1,_this17._isModelLoading=!1,_this17._loadOnFirstMessage=!1,_this17._webModel={},_this17.permittedErrorPrefixes=[ee.MULTIPLE_MODELS_ERROR,ee.WEB_LLM_NOT_FOUND_ERROR,ee.GENERIC_ERROR],_this17._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this17._webModel=e.webModel),(t=_this17._webModel.load)!=null&&t.clearCache&&ee.clearAllCache(),_this17.findModelInWindow(e),_this17.canSendMessage=_this17.canSubmit.bind(_assertThisInitialized(_this17)),_this17._chatEl=(n=e.shadowRoot)==null?void 0:n.children[0],e.history&&ee.setUpHistory(_this17._conversationHistory,e.history);return _this17;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
|
|
143
|
+
_inherits(ee,_Sn2);return _createClass(ee,[{key:"setUpMessages",value:function setUpMessages(e){var _this18=this;this._messages=e,this._removeIntro=function(){e.removeIntroductoryMessage(),_this18._removeIntro=void 0;};}},{key:"findModelInWindow",value:function findModelInWindow(e){var _this19=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var n;window.webLLM?this.configureInit(this.shouldAddIntroMessage(e.introMessage)):t>ee.MODULE_SEARCH_LIMIT_S?((n=this._messages)==null||n.addNewErrorMessage(oe,ee.WEB_LLM_NOT_FOUND_ERROR),console[p]("The deep-chat-web-llm module has not been attached to the window object. Please see the following guide:"),console[p]("https://deepchat.dev/examples/externalModules")):setTimeout(function(){return _this19.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 _this20=this;var t;((t=this._webModel.introMessage)==null?void 0:t.autoScroll)!==!1&&setTimeout(function(){var n,s;(n=_this20._messages)!=null&&n.elementRef&&q.scrollToTop((s=_this20._messages)==null?void 0:s.elementRef);},e);}// prettier-ignore
|
|
144
|
+
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Ws.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),_defineProperty(_defineProperty(_defineProperty({},S,te),"html",t),"sendUpdate",!1);}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(e){var t;return _regenerator().w(function(_context39){while(1)switch(_context39.n){case 0:t=this._webModel.load;if(!t){_context39.n=2;break;}if(!t.onInit){_context39.n=1;break;}this.init();return _context39.a(2);case 1:if(!t.onMessage){_context39.n=2;break;}this._loadOnFirstMessage=!0;return _context39.a(2);case 2:e||this.init();case 3:return _context39.a(2);}},_callee39,this);}));function configureInit(_x84){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(e){var n,t,_t23;return _regenerator().w(function(_context40){while(1)switch(_context40.n){case 0:(n=this._messages)==null||n.removeError();t=this.attemptToCreateChat();_t23=t;if(!_t23){_context40.n=1;break;}_context40.n=1;return this.loadModel(t,e);case 1:return _context40.a(2);}},_callee40,this);}));function init(_x85){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var n;if(ee.chat){(n=this._messages)==null||n.addNewErrorMessage(oe,ee.MULTIPLE_MODELS_ERROR),console[p](ee.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker,t={};return e?new window.webLLM.WebWorkerMLCEngine(e,t):new window.webLLM.MLCEngine(t);}},{key:"getConfig",value:function getConfig(){var i,o;var e=ee.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=(o=(i=window.webLLM)==null?void 0:i.prebuiltAppConfig)==null?void 0:o.model_list,n=w(t&&t.length>0?t:al.model_list),s={model_list:n,cacheBackend:"cache"};if(this._webModel.urls){var a=n.find(function(c){return c.model_id===e;});a||(a={model:"",model_id:e,model_lib:""},n.push(a)),this._webModel.urls.model&&(a.model=this._webModel.urls.model),this._webModel.urls.wasm&&(a.model_lib=this._webModel.urls.wasm);}return{model:e,appConfig:s};}// system instruction + prior turns + the new user message, in OpenAI message format
|
|
145
|
+
},{key:"buildMessages",value:function buildMessages(e){var t=[];return this._webModel.instruction&&t.push({role:"system",content:this._webModel.instruction}),t.push.apply(t,_toConsumableArray(this._conversationHistory)),t.push({role:"user",content:e}),t;}// prettier-ignore
|
|
146
|
+
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(e,t){var _this21=this;var i,o,a,c,l,d,u,g,n,s,_this$getConfig,b,_,_b,_t24,_t25,_t26;return _regenerator().w(function(_context41){while(1)switch(_context41.p=_context41.n){case 0:this.scrollToTop(),ee.chat=e,this._isModelLoading=!0;n=((i=this._webModel.introMessage)==null?void 0:i.displayed)===!1;s=function s(b){var _;(_=_this21._messages)==null||_.addNewMessage({html:"<div>".concat(b[h],"</div>"),overwrite:!0,sendUpdate:!1}),n&&(setTimeout(function(){return q.scrollToBottom(_this21._messages);}),n=!1);};e.setInitProgressCallback(s);_context41.p=1;_this$getConfig=this.getConfig(),b=_this$getConfig.model,_=_this$getConfig.appConfig;e.setAppConfig(_);_t24=(o=this._webModel.load)!=null&&o.skipCache;if(!_t24){_context41.n=2;break;}_context41.n=2;return window.webLLM.deleteModelAllInfoInCache(b,_);case 2:_t25=t&&t.length>0;if(!_t25){_context41.n=3;break;}_context41.n=3;return ys.importToCache(t);case 3:_context41.n=4;return e.reload(b);case 4:_context41.n=6;break;case 5:_context41.p=5;_t26=_context41.v;return _context41.a(2,this.unloadChat(_t26));case 6:if((c=(a=this.deepChat)._validationHandler)==null||c.call(a),(l=this._webModel.introMessage)!=null&&l.removeAfterLoad)this._webModel.introMessage.displayed===!1?(u=this._messages)==null||u.removeLastMessage():(g=this._removeIntro)==null||g.call(this);else{_b=Ws.setUpAfterLoad(this._webModel.introMessage,this._chatEl,!!this._webModel.worker);(d=this._messages)==null||d.addNewMessage({html:_b,overwrite:!0,sendUpdate:!1});}this._isModelLoaded=!0,this._isModelLoading=!1;case 7:return _context41.a(2);}},_callee41,this,[[1,5]]);}));function loadModel(_x86,_x87){return _loadModel.apply(this,arguments);}return loadModel;}()},{key:"unloadChat",value:function(){var _unloadChat=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(e){var t,_t27;return _regenerator().w(function(_context42){while(1)switch(_context42.n){case 0:(t=this._messages)==null||t.addNewErrorMessage(oe,ee.GENERIC_ERROR);console[p](e);this._isModelLoaded=!1;this._isModelLoading=!1;_t27=ee.chat;if(!_t27){_context42.n=2;break;}_context42.n=1;return ee.chat.unload();case 1:ee.chat=void 0;case 2:return _context42.a(2);}},_callee42,this);}));function unloadChat(_x88){return _unloadChat.apply(this,arguments);}return unloadChat;}()},{key:"immediateResp",value:function(){var _immediateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43(e,t,n){var c,l,i,o,a,_t28,_t29,_t30,_t31,_t32;return _regenerator().w(function(_context43){while(1)switch(_context43.n){case 0:_context43.n=1;return n.chat.completions.create({messages:this.buildMessages(t),stream:!1});case 1:_t29=c=_context43.v.choices[0];if(!(_t29==null)){_context43.n=2;break;}_t30=void 0;_context43.n=3;break;case 2:_t30=c.message;case 3:_t31=l=_t30;if(!(_t31==null)){_context43.n=4;break;}_t32=void 0;_context43.n=5;break;case 4:_t32=l.content;case 5:_t28=_t32;if(_t28){_context43.n=6;break;}_t28="";case 6:i=_t28;this._conversationHistory.push({role:"user",content:t},{role:"assistant",content:i});o=_defineProperty({},h,i);_context43.n=7;return ee.processResponse(this.deepChat,e,o);case 7:a=_context43.v;a&&a.forEach(function(d){return e.addNewMessage(d);}),this.completionsHandlers.onFinish();case 8:return _context43.a(2);}},_callee43,this);}));function immediateResp(_x89,_x90,_x91){return _immediateResp.apply(this,arguments);}return immediateResp;}()},{key:"streamResp",value:function(){var _streamResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44(e,t,n){var a,c,s,i,o,_iteratorAbruptCompletion,_didIteratorError,_iteratorError,_iterator,_step,l,d,u,_t33;return _regenerator().w(function(_context44){while(1)switch(_context44.p=_context44.n){case 0:this.streamHandlers.onAbort=function(){n.interruptGenerate();},this.streamHandlers.onOpen();s=new bt(e);_context44.n=1;return n.chat.completions.create({messages:this.buildMessages(t),stream:!0,stream_options:{include_usage:!1}});case 1:i=_context44.v;o="";_iteratorAbruptCompletion=false;_didIteratorError=false;_context44.p=2;_iterator=_asyncIterator(i);case 3:_context44.n=4;return _iterator.next();case 4:if(!(_iteratorAbruptCompletion=!(_step=_context44.v).done)){_context44.n=8;break;}l=_step.value;d=((c=(a=l.choices[0])==null?void 0:a.delta)==null?void 0:c.content)||"";if(d){_context44.n=5;break;}return _context44.a(3,7);case 5:o+=d;_context44.n=6;return ee.processResponse(this.deepChat,e,_defineProperty({},h,o));case 6:u=_context44.v;u&&s.upsertStreamedMessage(_defineProperty(_defineProperty({},h,u[0][h]),"overwrite",!0));case 7:_iteratorAbruptCompletion=false;_context44.n=3;break;case 8:_context44.n=10;break;case 9:_context44.p=9;_t33=_context44.v;_didIteratorError=true;_iteratorError=_t33;case 10:_context44.p=10;_context44.p=11;if(!(_iteratorAbruptCompletion&&_iterator["return"]!=null)){_context44.n=12;break;}_context44.n=12;return _iterator["return"]();case 12:_context44.p=12;if(!_didIteratorError){_context44.n=13;break;}throw _iteratorError;case 13:return _context44.f(12);case 14:return _context44.f(10);case 15:this._conversationHistory.push({role:"user",content:t},{role:"assistant",content:o}),s.finaliseStreamedMessage(),this.streamHandlers.onClose();case 16:return _context44.a(2);}},_callee44,this,[[11,,12,14],[2,9,10,15]]);}));function streamResp(_x92,_x93,_x94){return _streamResp.apply(this,arguments);}return streamResp;}()},{key:"generateRespByType",value:function(){var _generateRespByType=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45(e,t,n,s){var i,_t34;return _regenerator().w(function(_context45){while(1)switch(_context45.p=_context45.n){case 0:_context45.p=0;if(!n){_context45.n=2;break;}_context45.n=1;return this.streamResp(e,t,s);case 1:_context45.n=3;break;case 2:_context45.n=3;return this.immediateResp(e,t,s);case 3:_context45.n=5;break;case 4:_context45.p=4;_t34=_context45.v;(i=this._messages)==null||i.addNewErrorMessage(oe),console.log(_t34);case 5:return _context45.a(2);}},_callee45,this,[[0,4]]);}));function generateRespByType(_x95,_x96,_x97,_x98){return _generateRespByType.apply(this,arguments);}return generateRespByType;}()},{key:"generateResp",value:function(){var _generateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46(e,t,n){var s,_yield$D$processReque5,i,o,a,c,l;return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:s=t[t.length-1][h];_context46.n=1;return D.processRequestInterceptor(this.deepChat,{body:_defineProperty({},h,s)});case 1:_yield$D$processReque5=_context46.v;i=_yield$D$processReque5.body;o=_yield$D$processReque5.error;a=!!this.stream;try{if(o)D.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!i||!i[h]){c=na({body:i},!1);console[p](c);l=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;D.onInterceptorError(e,c,l);}else this.generateRespByType(e,i[h],!!this.stream,n);}catch(c){this.unloadChat(c);}case 2:return _context46.a(2);}},_callee46,this);}));function generateResp(_x99,_x100,_x101){return _generateResp.apply(this,arguments);}return generateResp;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e,t){var n,s;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:if(this._isModelLoaded){_context47.n=3;break;}if(!this._loadOnFirstMessage){_context47.n=2;break;}_context47.n=1;return this.init();case 1:_context47.n=3;break;case 2:return _context47.a(2);case 3:!ee.chat||this._isModelLoading||((n=this._webModel.introMessage)!=null&&n.removeAfterMessage&&((s=this._removeIntro)==null||s.call(this)),e.addLoadingMessage(),this.generateResp(e,t,ee.chat));case 4:return _context47.a(2);}},_callee47,this);}));function callServiceAPI(_x102,_x103){return _callServiceAPI2.apply(this,arguments);}return callServiceAPI;}()},{key:"canSubmit",value:function canSubmit(e){return!(e!=null&&e.trim())||this._isModelLoading?!1:this._loadOnFirstMessage?!0:!!this._isModelLoaded;}},{key:"isWebModel",value:function isWebModel(){return!0;}}],[{key:"setUpHistory",value:function setUpHistory(e,t){t.forEach(function(n,s){if(n[S]===F&&n[h]){var i=t[s+1];i!=null&&i[h]&&i[S]!==F&&(e.push({role:"user",content:n[h]}),e.push({role:"assistant",content:i[h]}));}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48(e,t,n){var a,c,s,i,o,d,_t35;return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:_context48.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,n);case 1:_t35=_context48.v;if(_t35){_context48.n=2;break;}_t35=n;case 2:s=_t35;if(!((c=e.connect)!=null&&c.stream&&Array.isArray(s)&&s.length>1)){_context48.n=3;break;}console[p](mo);return _context48.a(2);case 3:i=Array.isArray(s)?s:[s],o=i.find(function(l){return _typeof(l[p])===_e;});if(!o){_context48.n=4;break;}D.displayError(t,new Error(o[p]));return _context48.a(2);case 4:if(!i.find(function(d){return!d||!d[h];})){_context48.n=5;break;}d=sa(n,!!e.responseInterceptor,s);D.displayError(t,new Error(d));return _context48.a(2);case 5:return _context48.a(2,i);}},_callee48);}));function processResponse(_x104,_x105,_x106){return _processResponse.apply(this,arguments);}return processResponse;}()},{key:"clearAllCache",value:function clearAllCache(){ys.CACHE_SCOPES.forEach(function(e){return ee.clearCache(e);});}},{key:"clearCache",value:function clearCache(e){caches.open(e).then(function(t){t.keys().then(function(n){n.forEach(function(s){t["delete"](s);});});});}}]);}(Sn);ee.GENERIC_ERROR="Error, please check the [troubleshooting](".concat(X,"webModel#troubleshooting) section of documentation for help."),ee.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",ee.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",ee.DEFAULT_MODEL="Llama-3.2-1B-Instruct-q4f16_1-MLC",ee.MODULE_SEARCH_LIMIT_S=5;var Es=ee;var pe=function pe(r,e,t,n){return{url:r,method:e,handleVerificationResult:t,augmentUrl:n};},cl=function cl(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},ll=function ll(r,e,t,n){var s=r;Array.isArray(s[p])&&s[p][0]==="Error in `parameters`: field required"?t(e):n(ue);},hl=function hl(){return pe("https://api-inference.huggingface.co/models/gpt2",ye,ll);},cs=/*#__PURE__*/function(_M){// prettier-ignore
|
|
147
|
+
function cs(e,t,n,s,i,o){var _this22;_classCallCheck(this,cs);_this22=_callSuper(this,cs,[e,hl(),cl,i,o]),_this22.insertKeyPlaceholderText="Hugging Face Token",_this22.keyHelpUrl="https://huggingface.co/settings/tokens",_this22.permittedErrorPrefixes=[or],_this22.url="".concat(cs.URL_PREFIX).concat(n),_this22.textInputPlaceholderText=t,_typeof(s)=="object"&&(s.model&&(_this22.url="".concat(cs.URL_PREFIX).concat(s.model)),s.options&&(_this22.rawBody.options=s.options),s.parameters&&(_this22.rawBody.parameters=s.parameters));return _this22;}_inherits(cs,_M);return _createClass(cs,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var _s$options;var s=w(e),i=t[t.length-1][h];if(i)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:i},s);}},{key:"callServiceAPI",value:function(){var _callServiceAPI3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49(e,t,n){var s;return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(this.connectSettings){_context49.n=1;break;}throw new Error($e);case 1:s=this.preprocessBody(this.rawBody,t,n);be.request(this,s,e);case 2:return _context49.a(2);}},_callee49,this);}));function callServiceAPI(_x107,_x108,_x109){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(M);cs.URL_PREFIX="https://api-inference.huggingface.co/models/";var Ht=cs;var Rs=/*#__PURE__*/function(_Ht){// prettier-ignore
|
|
148
|
+
function Rs(e,t,n,s,i,o){var _this23;_classCallCheck(this,Rs);_this23=_callSuper(this,Rs,[e,t,n,s,i,o]),_this23.isTextInputDisabled=!0,_this23.canSendMessage=Rs.canSendFile;return _this23;}_inherits(Rs,_Ht);return _createClass(Rs,[{key:"preprocessBody",value:function preprocessBody(e,t,n){return n[0];}// prettier-ignore
|
|
149
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(e,t,n){return _regenerator().w(function(_context50){while(1)switch(_context50.n){case 0:if(this.connectSettings){_context50.n=1;break;}throw new Error($e);case 1:if(n!=null&&n[0]){_context50.n=2;break;}throw new Error(mi);case 2:be.poll(this,n[0],e,!1);case 3:return _context50.a(2);}},_callee50,this);}));function callServiceAPI(_x110,_x111,_x112){return _callServiceAPI4.apply(this,arguments);}return callServiceAPI;}()}],[{key:"canSendFile",value:function canSendFile(e,t){return!!(t!=null&&t[0]);}}]);}(Ht);var dl=/*#__PURE__*/function(_Rs){// prettier-ignore
|
|
150
|
+
function dl(e){_classCallCheck(this,dl);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.audioClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,dl,[e,"Attach an audio ".concat(ne),"ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,n,{audio:{}}]);}_inherits(dl,_Rs);return _createClass(dl,[{key:"extractPollResultData",value:function(){var _extractPollResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e){var t;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(!e.estimated_time){_context51.n=1;break;}return _context51.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[p]){_context51.n=2;break;}throw e[p];case 2:return _context51.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee51);}));function extractPollResultData(_x113){return _extractPollResultData.apply(this,arguments);}return extractPollResultData;}()}]);}(Rs);var ul=/*#__PURE__*/function(_Rs2){function ul(e){_classCallCheck(this,ul);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.imageClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ul,[e,"Attach an image ".concat(ne),"google/vit-base-patch16-224",t,n,{images:{}}]);}_inherits(ul,_Rs2);return _createClass(ul,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e){var t;return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(!e.estimated_time){_context52.n=1;break;}return _context52.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[p]){_context52.n=2;break;}throw e[p];case 2:return _context52.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee52);}));function extractPollResultData(_x114){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(Rs);var Ei=function Ei(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},pl=function pl(r,e,t,n){r.message?n(ue):t(e);},_i=function _i(){return pe("https://api.stability.ai/v1/engines/list",he,pl);},Vn="data:image/png;base64,";var vi=/*#__PURE__*/function(_M2){// prettier-ignore
|
|
151
|
+
function vi(e,t,n,s,i){var _this24;_classCallCheck(this,vi);_this24=_callSuper(this,vi,[e,t,n,s,i]),_this24.insertKeyPlaceholderText=_this24.genereteAPIKeyName("Stability AI"),_this24.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this24.permittedErrorPrefixes=[Ts,"invalid_"];return _this24;}_inherits(vi,_M2);return _createClass(vi);}(M);var Xs=/*#__PURE__*/function(_vi){function Xs(e){var _this25;_classCallCheck(this,Xs);var o;var t=w(e.directConnection),n=t==null?void 0:t.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this25=_callSuper(this,Xs,[e,_i(),Ei,n,s]),_this25.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",_this25.textInputPlaceholderText="Describe image changes";var i=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageUpscale;_typeof(i)=="object"&&(i.engine_id&&(_this25.url="https://api.stability.ai/v1/generation/".concat(i.engine_id,"/image-to-image/upscale")),Xs.cleanConfig(i),Object.assign(_this25.rawBody,i)),_this25.canSendMessage=Xs.canSendFileMessage;return _this25;}_inherits(Xs,_vi);return _createClass(Xs,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(W,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}// prettier-ignore
|
|
152
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e,t,n){var s;return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(this.connectSettings){_context53.n=1;break;}throw new Error($e);case 1:if(n){_context53.n=2;break;}throw new Error(rr);case 2:s=this.createFormDataBody(this.rawBody,n[0]);D.tempRemoveContentHeader(this.connectSettings,be.request.bind(this,this,s,e),!1);case 3:return _context53.a(2);}},_callee53,this);}));function callServiceAPI(_x115,_x116,_x117){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54(e){var t;return _regenerator().w(function(_context54){while(1)switch(_context54.n){case 0:if(!e.message){_context54.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.base64)),y,W);});return _context54.a(2,_defineProperty({},m,t));}},_callee54);}));function extractResultData(_x118){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]);}}]);}(vi);var Zs=/*#__PURE__*/function(_vi2){function Zs(e){var _this26;_classCallCheck(this,Zs);var o;var t=w(e.directConnection),n=t==null?void 0:t.stabilityAI,s=_defineProperty({},Q,_defineProperty({},m,{acceptedFormats:".png",maxNumberOfFiles:2}));_this26=_callSuper(this,Zs,[e,_i(),Ei,n,s]),_this26.url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",_this26._maskSource="MASK_IMAGE_WHITE",_this26.textInputPlaceholderText="Describe image changes";var i=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageMasking;_typeof(i)=="object"&&(i.engine_id&&(_this26.url="https://api.stability.ai/v1/generation/".concat(i.engine_id,"/image-to-image/masking")),i.weight!==void 0&&i.weight!==null&&(_this26._imageWeight=i.weight),i.mask_source!==void 0&&i.mask_source!==null&&(_this26._maskSource=i.mask_source),Zs.cleanConfig(i),Object.assign(_this26.rawBody,i)),_this26.canSendMessage=Zs.canSendFileTextMessage;return _this26;}_inherits(Zs,_vi2);return _createClass(Zs,[{key:"createFormDataBody",value:function createFormDataBody(e,t,n,s){var i=new FormData();return i.append("init_image",t),i.append("mask_source",String(this._maskSource)),i.append("mask_image",n),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(o){i.append(o,String(e[o]));}),i.get("weight")===void 0&&i.append("weight",String(1)),i;}// prettier-ignore
|
|
153
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(e,t,n){var o,a,s,i;return _regenerator().w(function(_context55){while(1)switch(_context55.n){case 0:if(this.connectSettings){_context55.n=1;break;}throw new Error($e);case 1:if(!(!n||!n[0]||!n[1])){_context55.n=2;break;}throw new Error(rr);case 2:s=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim(),i=this.createFormDataBody(this.rawBody,n[0],n[1],s);D.tempRemoveContentHeader(this.connectSettings,be.request.bind(this,this,i,e),!1);case 3:return _context55.a(2);}},_callee55,this);}));function callServiceAPI(_x119,_x120,_x121){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56(e){var t;return _regenerator().w(function(_context56){while(1)switch(_context56.n){case 0:if(!e.message){_context56.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.base64)),y,W);});return _context56.a(2,_defineProperty({},m,t));}},_callee56);}));function extractResultData(_x122){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()!=="");}}]);}(vi);var fl=/*#__PURE__*/function(_Rs3){function fl(e){_classCallCheck(this,fl);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.audioSpeechRecognition,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,fl,[e,"Attach an audio ".concat(ne),"facebook/wav2vec2-large-960h-lv60-self",t,n,{audio:{}}]);}_inherits(fl,_Rs3);return _createClass(fl,[{key:"extractPollResultData",value:function(){var _extractPollResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57(e){return _regenerator().w(function(_context57){while(1)switch(_context57.n){case 0:if(!e.estimated_time){_context57.n=1;break;}return _context57.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[p]){_context57.n=2;break;}throw e[p];case 2:return _context57.a(2,_defineProperty({},h,e[h]||""));}},_callee57);}));function extractPollResultData(_x123){return _extractPollResultData3.apply(this,arguments);}return extractPollResultData;}()}]);}(Rs);var ml=/*#__PURE__*/function(_Ht2){function ml(e){_classCallCheck(this,ml);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.textGeneration,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ml,[e,"Once upon a time","gpt2",t,n]);}_inherits(ml,_Ht2);return _createClass(ml,[{key:"extractResultData",value:function(){var _extractResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58(e){var t;return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(!e[p]){_context58.n=1;break;}throw e[p];case 1:return _context58.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.generated_text)||""));}},_callee58);}));function extractResultData(_x124){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(Ht);var gl=/*#__PURE__*/function(_Ht3){function gl(e){var _this27;_classCallCheck(this,gl);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.questionAnswer,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this27=_callSuper(this,gl,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,n]),_this27.permittedErrorPrefixes=[or,"Error in"],_this27._context=t.context;return _this27;}_inherits(gl,_Ht3);return _createClass(gl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return{inputs:{question:n,context:this._context,options:{wait_for_model:!0}}};}},{key:"extractResultData",value:function(){var _extractResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e[p]){_context59.n=1;break;}throw e[p];case 1:return _context59.a(2,_defineProperty({},h,e.answer||""));}},_callee59);}));function extractResultData(_x125){return _extractResultData5.apply(this,arguments);}return extractResultData;}()}]);}(Ht);var bl=/*#__PURE__*/function(_Ht4){function bl(e){_classCallCheck(this,bl);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.summarization,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,bl,[e,"Insert text to summarize","facebook/bart-large-cnn",t,n]);}_inherits(bl,_Ht4);return _createClass(bl,[{key:"extractResultData",value:function(){var _extractResultData6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){var t;return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(!e[p]){_context60.n=1;break;}throw e[p];case 1:return _context60.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.summary_text)||""));}},_callee60);}));function extractResultData(_x126){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(Ht);var yl=/*#__PURE__*/function(_Ht5){function yl(e){var _this28$maxMessages;var _this28;_classCallCheck(this,yl);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.conversation,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this28=_callSuper(this,yl,[e,"Ask me anything!","facebook/blenderbot-400M-distill",t,n]),(_this28$maxMessages=_this28.maxMessages)!==null&&_this28$maxMessages!==void 0?_this28$maxMessages:_this28.maxMessages=-1;return _this28;}// prettier-ignore
|
|
154
|
+
_inherits(yl,_Ht5);return _createClass(yl,[{key:"processMessagesI",value:function processMessagesI(e){var t=e.filter(function(a){return a[h];}),n=t[t.length-1][h],s=t.slice(0,t.length-1);if(!n)return;var i=s.filter(function(a){return a[S]===F;}).map(function(a){return a[h];}),o=s.filter(function(a){return a[S]===te;}).map(function(a){return a[h];});return{past_user_inputs:i,generated_responses:o,mostRecentMessageText:n};}},{key:"preprocessBody",value:function preprocessBody(e,t){var _n$options;var n=w(e),s=this.processMessagesI(t);if(s)return(_n$options=n.options)!==null&&_n$options!==void 0?_n$options:n.options={},n.options.wait_for_model=!0,_objectSpread({inputs:_defineProperty({past_user_inputs:s.past_user_inputs,generated_responses:s.generated_responses},h,s.mostRecentMessageText)},n);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e){return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(!e[p]){_context61.n=1;break;}throw e[p];case 1:return _context61.a(2,_defineProperty({},h,e.generated_text||""));}},_callee61);}));function extractResultData(_x127){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(Ht);var Ys=/*#__PURE__*/function(_vi3){function Ys(e){var _this29;_classCallCheck(this,Ys);var o;var t=w(e.directConnection),n=t.stabilityAI,s=_defineProperty({},Q,_defineProperty({},m,{acceptedFormats:".png",maxNumberOfFiles:1}));_this29=_callSuper(this,Ys,[e,_i(),Ei,n,s]),_this29.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this29.textInputPlaceholderText="Describe image changes";var i=(o=t.stabilityAI)==null?void 0:o.imageToImage;_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),Ys.cleanConfig(i),Object.assign(_this29.rawBody,i)),_this29.canSendMessage=Ys.canSendFileTextMessage;return _this29;}_inherits(Ys,_vi3);return _createClass(Ys,[{key:"createFormDataBody",value:function createFormDataBody(e,t,n){var s=new FormData();return s.append("init_image",t),n&&n!==""&&s.append("text_prompts[0][text]",n),this._imageWeight!==void 0&&this._imageWeight!==null&&s.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(i){s.append(i,String(e[i]));}),s.get("weight")===void 0&&s.append("weight",String(1)),s;}// prettier-ignore
|
|
155
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e,t,n){var o,a,s,i;return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(this.connectSettings){_context62.n=1;break;}throw new Error($e);case 1:if(n){_context62.n=2;break;}throw new Error(rr);case 2:s=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim(),i=this.createFormDataBody(this.rawBody,n[0],s);D.tempRemoveContentHeader(this.connectSettings,be.request.bind(this,this,i,e),!1);case 3:return _context62.a(2);}},_callee62,this);}));function callServiceAPI(_x128,_x129,_x130){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e){var t;return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:if(!e.message){_context63.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.base64)),y,W);});return _context63.a(2,_defineProperty({},m,t));}},_callee63);}));function extractResultData(_x131){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()!=="");}}]);}(vi);var El=/*#__PURE__*/function(_Ht6){function El(e){_classCallCheck(this,El);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.translation,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,El,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(El,_Ht6);return _createClass(El,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e){var t;return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:if(!e[p]){_context64.n=1;break;}throw e[p];case 1:return _context64.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.translation_text)||""));}},_callee64);}));function extractResultData(_x132){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Ht);var Js=/*#__PURE__*/function(_vi4){function Js(e){var _this30;_classCallCheck(this,Js);var i;var t=w(e.directConnection),n=t.stabilityAI;_this30=_callSuper(this,Js,[e,_i(),Ei,n]),_this30.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this30.textInputPlaceholderText="Describe an image";var s=(i=t.stabilityAI)==null?void 0:i.textToImage;_typeof(s)=="object"&&(s.engine_id&&(_this30.url="https://api.stability.ai/v1/generation/".concat(s.engine_id,"/text-to-image")),s.weight!==void 0&&s.weight!==null&&(_this30._imageWeight=s.weight),Js.cleanConfig(s),Object.assign(_this30.rawBody,s)),_this30.canSendMessage=Js.canSendTextMessage;return _this30;}_inherits(Js,_vi4);return _createClass(Js,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=w(e),i=_defineProperty({},h,n);return this._imageWeight&&(i.weight=this._imageWeight),s.text_prompts=[i],s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e,t){return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context65.a(2);}},_callee65,this);}));function callServiceAPI(_x133,_x134){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e){var t;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(!e.message){_context66.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.base64)),y,W);});return _context66.a(2,_defineProperty({},m,t));}},_callee66);}));function extractResultData(_x135){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()!=="");}}]);}(vi);var _l=/*#__PURE__*/function(_Ht7){function _l(e){var _this31;_classCallCheck(this,_l);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:i.fillMask,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this31=_callSuper(this,_l,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this31.permittedErrorPrefixes=[or,"No mask_token"];return _this31;}_inherits(_l,_Ht7);return _createClass(_l,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e){var t;return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:if(!e[p]){_context67.n=1;break;}throw e[p];case 1:return _context67.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.sequence)||""));}},_callee67);}));function extractResultData(_x136){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(Ht);var ur=function ur(r){return _defineProperty(_defineProperty({},H,Y),le,"".concat(Ae).concat(r));},vl=function vl(r,e,t,n){var s=r;s[p]?s[p].message===gi?n(ue):n(He):t(e);},pr=function pr(){return pe("https://open.bigmodel.cn/api/paas/v4/models",he,vl);};var Sl=/*#__PURE__*/function(_M3){function Sl(e){var _o$model,_a$voice;var _this32;_classCallCheck(this,Sl);var i,o,a;var t=w(e.directConnection),n=t.bigModel;_this32=_callSuper(this,Sl,[e,pr(),ur,n]),_this32.insertKeyPlaceholderText=_this32.genereteAPIKeyName("BigModel"),_this32.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this32.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this32.permittedErrorPrefixes=[le,we];var s=(i=t.bigModel)==null?void 0:i.textToSpeech;_typeof(s)===U&&(_this32.cleanConfig(s),Object.assign(_this32.rawBody,s)),(_o$model=(o=_this32.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this32.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this32;}_inherits(Sl,_M3);return _createClass(Sl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e,t){return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:return _context68.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee68,this);}));function callServiceAPI(_x137,_x138){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee69(e){var t,n;return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:t=new Blob([e],_defineProperty({},y,"audio/mpeg")),n=URL.createObjectURL(t);return _context69.a(2,_defineProperty({},m,[_defineProperty(_defineProperty({},T,n),y,G)]));}},_callee69);}));function extractResultData(_x139){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(M);var fr=function fr(r){return _defineProperty(_defineProperty({},H,Y),le,"".concat(Ae).concat(r));},xl=function xl(r,e,t,n){var s=r;s[p]?s[p].message===gi?n(ue):n(He):t(e);},mr=function mr(){return pe("https://api.together.xyz/v1/models",he,xl);};var Al=/*#__PURE__*/function(_M4){function Al(e){var _o$model2,_a$voice2;var _this33;_classCallCheck(this,Al);var i,o,a;var t=w(e.directConnection),n=t.together;_this33=_callSuper(this,Al,[e,mr(),fr,n]),_this33.insertKeyPlaceholderText=_this33.genereteAPIKeyName("Together AI"),_this33.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this33.url="https://api.together.xyz/v1/audio/speech",_this33.permittedErrorPrefixes=[et,we];var s=(i=t.together)==null?void 0:i.textToSpeech;_typeof(s)===U&&_this33.completeConfig(s),(_o$model2=(o=_this33.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this33.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this33;}_inherits(Al,_M4);return _createClass(Al,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(e,t){return _regenerator().w(function(_context70){while(1)switch(_context70.n){case 0:return _context70.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee70,this);}));function callServiceAPI(_x140,_x141){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(e){var t,n;return _regenerator().w(function(_context71){while(1)switch(_context71.n){case 0:t=new Blob([e],_defineProperty({},y,"audio/mpeg")),n=URL.createObjectURL(t);return _context71.a(2,_defineProperty({},m,[_defineProperty(_defineProperty({},T,n),y,G)]));}},_callee71);}));function extractResultData(_x142){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(M);var Qe="https://api.openai.com/v1/",Kn="https://platform.openai.com/account/api-keys",ji="input_text",Qr="input_image",eo="output_text",Mi="image_generation_call",Mo="function_call_output",In="response",Wn=function Wn(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},ko=function ko(r,e,t,n){var s=r;s[p]?s[p].code==="invalid_api_key"?n(ue):n(He):t(e);},Xn=function Xn(){return pe("".concat(Qe,"models"),he,ko);},Yt=/*#__PURE__*/function(){var _ref58=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(r,e,t){var n,s,i,o,a,c,_yield$D$processReque6,l,d,u,g,b,_args72=arguments;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:n=_args72.length>3&&_args72[3]!==undefined?_args72[3]:!0;s=r.connectSettings,i=r.deepChat,o=r.completionsHandlers,a=r.messages;s.method=t;c={body:e,headers:s.headers};_context72.n=1;return D.processRequestInterceptor(i,c);case 1:_yield$D$processReque6=_context72.v;l=_yield$D$processReque6.body;d=_yield$D$processReque6.headers;u=_yield$D$processReque6.error;g=o.onFinish;if(!(u&&a)){_context72.n=2;break;}return _context72.a(2,D.onInterceptorError(a,u,g));case 2:_context72.n=3;return D.fetch(r,d,n,l).then(function(_){return D.processResponseByType(_);});case 3:b=_context72.v;if(!b[p]){_context72.n=4;break;}throw b[p].message;case 4:return _context72.a(2,b);}},_callee72);}));return function Yt(_x143,_x144,_x145){return _ref58.apply(this,arguments);};}(),Xe=/*#__PURE__*/function(){function Xe(){_classCallCheck(this,Xe);}return _createClass(Xe,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee74(e,t,n,s){var i,o,a,c,_t36;return _regenerator().w(function(_context74){while(1)switch(_context74.p=_context74.n){case 0:i=e.connectSettings.headers;if(i){_context74.n=1;break;}return _context74.a(2);case 1:e.url=s;o=i[H];delete i[H];a=n.map(/*#__PURE__*/function(){var _ref59=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73(c){var l;return _regenerator().w(function(_context73){while(1)switch(_context73.n){case 0:l=new FormData();return _context73.a(2,(l.append("purpose","assistants"),l.append("file",c),new Promise(function(d){d(Yt(e,l,ye,!1));})));}},_callee73);}));return function(_x150){return _ref59.apply(this,arguments);};}());_context74.p=2;_context74.n=3;return Promise.all(a);case 3:c=_context74.v.map(function(l){return{id:l.id,name:l.filename};});return _context74.a(2,(i[H]=o,c));case 4:_context74.p=4;_t36=_context74.v;throw i[H]=o,D.displayError(t,_t36),e.completionsHandlers.onFinish(),_t36;case 5:return _context74.a(2);}},_callee74,null,[[2,4]]);}));function storeFiles(_x146,_x147,_x148,_x149){return _storeFiles.apply(this,arguments);}return storeFiles;}()},{key:"getType",value:function getType(e,t){var n=e[t].path;return!n||n.endsWith("png")?W:gn;}},{key:"getFiles",value:function(){var _getFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee75(e,t,n,s){var i,a;return _regenerator().w(function(_context75){while(1)switch(_context75.n){case 0:i=t.map(function(_ref60){var c=_ref60.fileId;return e.url="".concat(n).concat(c).concat(s),new Promise(function(l){l(Yt(e,void 0,"GET",!1));});});_context75.n=1;return Promise.all(i);case 1:a=_context75.v.map(function(c,l){return new Promise(function(d){var u=new FileReader();u.readAsDataURL(c),u.onload=function(g){d(_defineProperty(_defineProperty(_defineProperty({},T,g.target.result),"name",t[l].name),y,Xe.getType(t,l)));};});});_context75.n=2;return Promise.all(a);case 2:return _context75.a(2,_context75.v);}},_callee75);}));function getFiles(_x151,_x152,_x153,_x154){return _getFiles.apply(this,arguments);}return getFiles;}()},{key:"getFileName",value:function getFileName(e){var t=e.split("/");return t[t.length-1];}// prettier-ignore
|
|
156
|
+
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee76(e,t,n,s,i){var l,d,o,a,c,_t37;return _regenerator().w(function(_context76){while(1)switch(_context76.n){case 0:a=n.getFilesPrefix,c=n.getFilesPostfix;_t37=t.length>0;if(!_t37){_context76.n=2;break;}_context76.n=1;return Xe.getFiles(e,t,a,c);case 1:o=_context76.v;(l=i==null?void 0:i[h])!=null&&l.value&&o.forEach(function(u,g){var _;if(!u[T])return;var b=t[g].path;(_=i==null?void 0:i[h])!=null&&_.value&&b&&(i[h].value=i[h].value.replace(b,u[T]));});case 2:return _context76.a(2,(d=i==null?void 0:i[h])!=null&&d.value?_defineProperty(_defineProperty({},h,i[h].value),S,s):_defineProperty(_defineProperty({},m,o),S,s));}},_callee76);}));function getFilesAndNewText(_x155,_x156,_x157,_x158,_x159){return _getFilesAndNewText.apply(this,arguments);}return getFilesAndNewText;}()// Noticed an issue where text contains a sandbox hyperlink to a csv, but no annotation provided
|
|
157
157
|
// To reproduce use the following text:
|
|
158
158
|
// give example data for a csv and create a suitable bar chart for it with a link
|
|
159
159
|
// Don't think it can be fixed and it is something on OpenAI side of things
|
|
160
160
|
// prettier-ignore
|
|
161
|
-
},{key:"getFileDetails",value:function getFileDetails(e,t){var s;var n=[];return(s=t==null?void 0:t[h])!=null&&s.value&&e.content.forEach(function(
|
|
162
|
-
},{key:"getFilesAndText",value:function(){var _getFilesAndText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
161
|
+
},{key:"getFileDetails",value:function getFileDetails(e,t){var s;var n=[];return(s=t==null?void 0:t[h])!=null&&s.value&&e.content.forEach(function(i){var o,a;(a=(o=i[h])==null?void 0:o.annotations)==null||a.forEach(function(c){var l;c[h]&&c[h].startsWith("sandbox:")&&(l=c.file_path)!=null&&l.file_id&&n.push({path:c[h],fileId:c.file_path.file_id,name:Xe.getFileName(c[h])});});}),t!=null&&t.image_file&&n.push({fileId:t.image_file.file_id}),n;}// prettier-ignore
|
|
162
|
+
},{key:"getFilesAndText",value:function(){var _getFilesAndText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(e,t,n,s){var i;return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:i=Xe.getFileDetails(t,s);_context77.n=1;return Xe.getFilesAndNewText(e,i,n,t.role,s);case 1:return _context77.a(2,_context77.v);}},_callee77);}));function getFilesAndText(_x160,_x161,_x162,_x163){return _getFilesAndText.apply(this,arguments);}return getFilesAndText;}()},{key:"parseResult",value:function parseResult(e,t){var n=[];if(t)n=e.data;else for(var s=0;s<e.data.length;s+=1){var i=e.data[s];if(i.role===xt)n.push(i);else break;}return n.reverse();}// test this using this prompt and it should give 2 text mesages and a file:
|
|
163
163
|
// "give example data for a csv and create a suitable bar chart"
|
|
164
|
-
},{key:"parseMessages",value:function parseMessages(e,t,n){var s=[];return t.forEach(/*#__PURE__*/function(){var _ref63=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
165
|
-
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
166
|
-
function
|
|
167
|
-
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
168
|
-
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
164
|
+
},{key:"parseMessages",value:function parseMessages(e,t,n){var s=[];return t.forEach(/*#__PURE__*/function(){var _ref63=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(i){return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:i.content.filter(function(o){return!!o[h]||!!o.image_file;}).sort(function(o){return o[h]?-1:o.image_file?1:0;}).forEach(/*#__PURE__*/function(){var _ref64=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(o){return _regenerator().w(function(_context78){while(1)switch(_context78.n){case 0:s.push(Xe.getFilesAndText(e,i,n,o));case 1:return _context78.a(2);}},_callee78);}));return function(_x165){return _ref64.apply(this,arguments);};}());case 1:return _context79.a(2);}},_callee79);}));return function(_x164){return _ref63.apply(this,arguments);};}()),Promise.all(s);}},{key:"processStreamMessages",value:function(){var _processStreamMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(e,t,n){return _regenerator().w(function(_context80){while(1)switch(_context80.n){case 0:return _context80.a(2,Xe.parseMessages(e,[{content:t,role:xt}],n));}},_callee80);}));function processStreamMessages(_x166,_x167,_x168){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
|
|
165
|
+
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(e,t,n,s){var i;return _regenerator().w(function(_context81){while(1)switch(_context81.n){case 0:i=Xe.parseResult(t,n);return _context81.a(2,Xe.parseMessages(e,i,s));}},_callee81);}));function processAPIMessages(_x169,_x170,_x171,_x172){return _processAPIMessages.apply(this,arguments);}return processAPIMessages;}()}]);}();Xe.FILES_WITH_TEXT_ERROR="content with type `text` must have `text` values",Xe.FUNCTION_TOOL_RESP_ERROR="Response must contain an array of strings for each individual function/tool_call, see ".concat(X,"directConnection/OpenAI/#assistant-functions.");var It=Xe;var Wt=/*#__PURE__*/function(_M5){// prettier-ignore
|
|
166
|
+
function Wt(e,t,n,s,i,o){var _this34;_classCallCheck(this,Wt);if(_this34=_callSuper(this,Wt,[e,s,i,o]),_this34.insertKeyPlaceholderText=_this34.genereteAPIKeyName("OpenAI"),_this34.keyHelpUrl=Kn,_this34.url="",_this34.permittedErrorPrefixes=[Ts,"Please send text",bs.FAILED_ERROR_MESSAGE],_this34.shouldFetchHistory=!1,_this34._searchedForThreadId=!1,_this34._config={},_this34._newAssistantDetails={model:"gpt-4"},_this34._waitingForStreamResponse=!1,_this34._isSSEStream=!1,_this34.urlSegments=n,_typeof(t)=="object"){_this34._config=t;var _this34$_config=_this34._config,a=_this34$_config.new_assistant,c=_this34$_config.thread_id,l=_this34$_config.load_thread_history;Object.assign(_this34._newAssistantDetails,a),c&&(_this34.sessionId=c),l&&(_this34.shouldFetchHistory=!0);}_this34.maxMessages=1,_this34._isSSEStream=!!(_this34.stream&&(_typeof(_this34.stream)!="object"||!_this34.stream.simulation));return _this34;}_inherits(Wt,_M5);return _createClass(Wt,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(){var _this35=this;var e,_t38;return _regenerator().w(function(_context82){while(1)switch(_context82.p=_context82.n){case 0:setTimeout(function(){return _this35.deepChat.disableSubmitButton();},2);_context82.p=1;_context82.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context82.v;return _context82.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context82.p=3;_t38=_context82.v;return _context82.a(2,[_defineProperty({},p,bo)]);}},_callee82,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processMessage",value:function processMessage(e,t){var n=this.totalMessagesMaxCharLength||-1,s=Gn.getCharacterLimitMessages(e,n)[0];if(t&&t.length>0){var i=this.filesToolType;if(typeof this.filesToolType=="function"){var a=this.filesToolType(t.map(function(_ref66){var c=_ref66.name;return c;}));a==="code_interpreter"||a==="file_search"||a===Q?i=a:(console[p]("Tool type \"".concat(a,"\" is not valid")),console[p]('Expected "code_interpreter" or "file_search" or "images". Going to default to "images"'));}if(i==="file_search")return Wt.processAttachmentsMessage(s,t,"file_search");if(i==="code_interpreter")return Wt.processAttachmentsMessage(s,t,"code_interpreter");if(t.find(function(_ref67){var a=_ref67.name;return!Se.isImageFileExtension(a);}))console[p]("The uploaded files contained a non-image file"),console[p]('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=Wt.processImageMessage(s,t);if(_a3)return _a3;}}return _defineProperty({content:s[h]||""},S,F);}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,n){var s=w(e),i=this.processMessage(t,n);return s.thread={messages:[i]},s;}},{key:"callService",value:function callService(e,t,n){if(this.messages=e,this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/messages").concat(this.urlSegments.createMessagePostfix);var s=this.processMessage(t,n);be.request(this,s,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _s6=this.createNewThreadMessages(this.rawBody,t,n);this._isSSEStream?this.createStreamRun(_s6):be.request(this,_s6,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(e,t,n){var _i$assistant_id;var i,s,_t39,_t40;return _regenerator().w(function(_context83){while(1)switch(_context83.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context83.n=1;break;}throw new Error($e);case 1:if(!((_i$assistant_id=(i=this.rawBody).assistant_id)!==null&&_i$assistant_id!==void 0)){_context83.n=2;break;}_i$assistant_id;_context83.n=5;break;case 2:_t39=this._config.assistant_id;if(_t39){_context83.n=4;break;}_context83.n=3;return this.createNewAssistant();case 3:_t39=_context83.v;case 4:i.assistant_id=_t39;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!n){_context83.n=7;break;}_context83.n=6;return It.storeFiles(this,e,n,this.urlSegments.storeFiles);case 6:_t40=_context83.v;_context83.n=8;break;case 7:_t40=void 0;case 8:s=_t40;this.connectSettings.method=ye,this.callService(e,t,s);case 9:return _context83.a(2);}},_callee83,this);}));function callServiceAPI(_x173,_x174,_x175){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(){var e,_t41;return _regenerator().w(function(_context84){while(1)switch(_context84.p=_context84.n){case 0:_context84.p=0;this.url=this.urlSegments.newAssistantUrl;_context84.n=1;return Yt(this,w(this._newAssistantDetails),ye);case 1:e=_context84.v;return _context84.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context84.p=2;_t41=_context84.v;console[p](_t41),console[p]("Failed to create a new assistant");case 3:return _context84.a(2);}},_callee84,this,[[0,2]]);}));function createNewAssistant(){return _createNewAssistant.apply(this,arguments);}return createNewAssistant;}()},{key:"searchPreviousMessagesForThreadId",value:function searchPreviousMessagesForThreadId(e){var t=e.find(function(_ref69){var _ref70=_slicedToArray(_ref69,1),n=_ref70[0];return n._sessionId;});t&&(this.sessionId=t[0]._sessionId),this._searchedForThreadId=!0;}},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var s,t,n;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context85.n=2;break;}_context85.n=1;return this.handleStream(e);case 1:return _context85.a(2,_context85.v);case 2:if(!e[p]){_context85.n=3;break;}throw e[p].message.startsWith(It.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e[p].message;case 3:this.asyncCallInProgress=!0;_context85.n=4;return this.assignThreadAndRun(e);case 4:t="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs/").concat(this.run_id).concat(this.urlSegments.threadsPosfix),n={method:he,headers:(s=this.connectSettings)==null?void 0:s.headers};return _context85.a(2,(be.executePollRequest(this,t,n,this.messages),_defineProperty({},h,"")));}},_callee85,this);}));function extractResultData(_x176){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){var t;return _regenerator().w(function(_context86){while(1)switch(_context86.n){case 0:if(!this.sessionId){_context86.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context86.n=1;return Yt(this,w(this.rawBody),ye);case 1:t=_context86.v;this.run_id=t.id;_context86.n=3;break;case 2:this.sessionId=e.thread_id,this.run_id=e.id,this.updateSessionId(this.sessionId);case 3:return _context86.a(2);}},_callee86,this);}));function assignThreadAndRun(_x177){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var t,s,i,n,_args87=arguments,_t42;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:t=_args87.length>1&&_args87[1]!==undefined?_args87[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context87.n=1;return Yt(this,{},he);case 1:n=_context87.v;_t42=!t&&this.deepChat.responseInterceptor;if(!_t42){_context87.n=3;break;}_context87.n=2;return(i=(s=this.deepChat).responseInterceptor)==null?void 0:i.call(s,n);case 2:n=_context87.v;case 3:return _context87.a(2,It.processAPIMessages(this,n,t,this.urlSegments));}},_callee87,this);}));function getThreadMessages(_x178){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){var _this36=this;var i,t,n,o,_o$shift,a,c,s;return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:t=e.status,n=e.required_action;if(!(t==="queued"||t==="in_progress")){_context88.n=1;break;}return _context88.a(2,{timeoutMS:Wt.POLLING_TIMEOUT_MS});case 1:if(!(t===ar&&this.messages)){_context88.n=3;break;}_context88.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context88.v;_o$shift=o.shift();a=_o$shift.text;c=_o$shift.files;return _context88.a(2,(setTimeout(function(){o.forEach(function(l){return _this36.deepChat.addMessage(l);});}),_defineProperty({text:a,_sessionId:this.sessionId},m,c)));case 3:s=(i=n==null?void 0:n.submit_tool_outputs)==null?void 0:i.tool_calls;if(!(t==="requires_action"&&s)){_context88.n=5;break;}_context88.n=4;return this.handleTools(s);case 4:return _context88.a(2,_context88.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context88.a(2);}},_callee88,this);}));function extractPollResultData(_x179){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
|
|
167
|
+
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(e){var t,n,s,i,o,a;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:if(this._functionHandlerI){_context89.n=1;break;}throw Error(en);case 1:t=e.map(function(c){return{name:c["function"].name,arguments:c["function"].arguments};});_context89.n=2;return this._functionHandlerI(t);case 2:n=_context89.v;if(!(!Array.isArray(n)||e.length!==n.length)){_context89.n=3;break;}throw Error(It.FUNCTION_TOOL_RESP_ERROR);case 3:_context89.n=4;return Promise.all(n);case 4:s=_context89.v;if(!s.find(function(c){return _typeof(c)!==_e;})){_context89.n=5;break;}throw Error(It.FUNCTION_TOOL_RESP_ERROR);case 5:i=s.map(function(c,l){return{tool_call_id:e[l].id,output:c};}),o="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId),a="/runs/".concat(this.run_id,"/submit_tool_outputs").concat(this.urlSegments.threadsPosfix);this.url="".concat(o).concat(a);if(!this._isSSEStream){_context89.n=7;break;}_context89.n=6;return this.createStreamRun({tool_outputs:i});case 6:_context89.n=8;break;case 7:_context89.n=8;return Yt(this,{tool_outputs:i},ye);case 8:return _context89.a(2,{timeoutMS:Wt.POLLING_TIMEOUT_MS});}},_callee89,this);}));function handleTools(_x180){return _handleTools.apply(this,arguments);}return handleTools;}()},{key:"handleStream",value:function(){var _handleStream=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var n,s,t,i;return _regenerator().w(function(_context90){while(1)switch(_context90.n){case 0:t=(s=(n=e.required_action)==null?void 0:n.submit_tool_outputs)==null?void 0:s.tool_calls;if(!(e.status==="requires_action"&&t)){_context90.n=2;break;}this.run_id=e.id;_context90.n=1;return this.handleTools(t);case 1:return _context90.a(2,_context90.v);case 2:if(!this._waitingForStreamResponse){_context90.n=3;break;}return _context90.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);i=w(this.rawBody);this.createStreamRun(i);}return _context90.a(2,_defineProperty({},h,""));}},_callee90,this);}));function handleStream(_x181){return _handleStream.apply(this,arguments);}return handleStream;}()// prettier-ignore
|
|
168
|
+
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){var t,n,s,i,o,a,c,l,_a4,_c4;return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:if(!(e.content&&e.content.length>0&&this.messages)){_context91.n=1;break;}a=e.content.find(function(c){return c[h];});if(!((t=a==null?void 0:a[h])!=null&&t.annotations&&a[h].annotations.length>0)){_context91.n=1;break;}c=e.content.find(function(d){return!!d[h];})||e.content[0],l=It.getFilesAndText.bind(this,this,_defineProperty(_defineProperty({},S,xt),"content",e.content),this.urlSegments,c);return _context91.a(2,((n=this._messageStream)==null||n.endStreamAfterFileDownloaded(this.messages,l),_defineProperty({},h,"")));case 1:if(!((s=e.delta)!=null&&s.content)){_context91.n=4;break;}if(!(e.delta.content.length>1)){_context91.n=3;break;}_a4=e.delta.content.find(function(c){return c[h];});if(!((i=_a4==null?void 0:_a4[h])!=null&&i.annotations&&_a4[h].annotations.length===0)){_context91.n=3;break;}_context91.n=2;return It.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_c4=_context91.v;return _context91.a(2,_defineProperty(_defineProperty({},h,_c4[0][h]),m,_c4[1][m]));case 3:return _context91.a(2,_defineProperty({},h,(o=e.delta.content[0][h])==null?void 0:o.value));case 4:return _context91.a(2,(!this.sessionId&&e.thread_id&&(this.sessionId=e.thread_id),_defineProperty({},h,"")));}},_callee91,this);}));function parseStreamResult(_x182){return _parseStreamResult.apply(this,arguments);}return parseStreamResult;}()// https://platform.openai.com/docs/api-reference/assistants-streaming
|
|
169
169
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
170
|
-
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
171
|
-
function
|
|
172
|
-
},{key:"setEvents",value:function setEvents(e){this.elementRef.onmousedown=this.buttonMouseDown.bind(this,e),this.elementRef.onmouseup=this.buttonMouseUp.bind(this,e),this.elementRef.onmouseenter=this.buttonMouseEnter.bind(this,e),this.elementRef.onmouseleave=this.buttonMouseLeave.bind(this,e);}},{key:"unsetCustomStateStyles",value:function unsetCustomStateStyles(e){if(this.customStyles)for(var t=0;t<e.length;t+=1){var _n2=e[t],s=_n2&&this.customStyles[_n2];s&&xe.unsetActionCSS(this.elementRef,s);}}},{key:"reapplyStateStyle",value:function reapplyStateStyle(e,t){if(!this.customStyles)return;t&&this.unsetCustomStateStyles(t);var n=this.customStyles[e];n&&xe.setElementCssUpToState(this.elementRef,n,this._mouseState.state),this.setEvents(n);}},{key:"changeElementsByState",value:function changeElementsByState(e){var _this$elementRef;(_this$elementRef=this.elementRef).replaceChildren.apply(_this$elementRef,_toConsumableArray(e)),
|
|
173
|
-
},{key:"assignPropertyFromOneToAnother",value:function assignPropertyFromOneToAnother(e,t,n){var _t$e;(_t$e=t[e])!==null&&_t$e!==void 0?_t$e:t[e]={},Object.assign(t[e],n==null?void 0:n[e]);}}]);}();var Bo="<?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>"
|
|
170
|
+
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(e){return _regenerator().w(function(_context92){while(1)switch(_context92.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context92.n=1;return V.request(this,e,this.messages,!0,!0);case 1:this._messageStream=_context92.v;case 2:return _context92.a(2);}},_callee92,this);}));function createStreamRun(_x183){return _createStreamRun.apply(this,arguments);}return createStreamRun;}()}],[{key:"processImageMessage",value:function processImageMessage(e,t){var n=t==null?void 0:t.filter(function(s){return Se.isImageFileExtension(s.name);}).map(function(s){return _defineProperty(_defineProperty({},y,"image_file"),"image_file",{file_id:s.id});});if(n&&n.length>0)return e[h]&&e[h].length>0&&n.push(_defineProperty(_defineProperty({},y,h),h,e[h])),_defineProperty({content:n},S,F);}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,n){return _defineProperty({attachments:t.map(function(i){return{tools:[_defineProperty({},y,n)],file_id:i.id};}),content:[_defineProperty(_defineProperty({},y,h),h,e[h])]},S,F);}}]);}(M);Wt.POLLING_TIMEOUT_MS=500;var Qs=Wt;var gr=/*#__PURE__*/function(_Qs){function gr(e){var _a$headers,_c$OpenAIBeta;var _this37;_classCallCheck(this,gr);var o,a,c,l,d;var t=w(e.directConnection),n=t.openAI,s=(o=t.openAI)==null?void 0:o.assistant,i=gr.buildUrlSegments(s);if(_this37=_callSuper(this,gr,[e,s,i,Xn(),Wn,n]),(_a$headers=(a=_this37.connectSettings).headers)!==null&&_a$headers!==void 0?_a$headers:a.headers={},(_c$OpenAIBeta=(c=_this37.connectSettings.headers)["OpenAI-Beta"])!==null&&_c$OpenAIBeta!==void 0?_c$OpenAIBeta:c["OpenAI-Beta"]="assistants=v2",_this37.shouldFetchHistory&&_this37.sessionId&&(_this37.fetchHistory=_this37.fetchHistoryFunc.bind(_assertThisInitialized(_this37))),_typeof(s)===U){var _ref83=(d=(l=e.directConnection)==null?void 0:l.openAI)==null?void 0:d.assistant,u=_ref83.function_handler,g=_ref83.files_tool_type;u&&(_this37._functionHandlerI=u),g&&(_this37.filesToolType=g);}return _this37;}_inherits(gr,_Qs);return _createClass(gr,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||Qe;return{threadsPrefix:"".concat(t,"/threads"),threadsPosfix:"",newAssistantUrl:"".concat(t,"/assistants"),createMessagePostfix:"",listMessagesPostfix:"order=desc",storeFiles:"".concat(t,"/").concat(m),getFilesPrefix:"".concat(t,"/").concat(m,"/"),getFilesPostfix:"/content"};}}]);}(Qs);var ei="Please define the Azure URL Details. [More Information](".concat(X,"directConnection/Azure)"),Lo=function Lo(r){return _defineProperty({"api-key":r},H,Y);},Po=function Po(r){return pe("".concat(r.endpoint,"/openai/models?api-version=").concat(r.version),he,ko);},Oo=function Oo(r){var e=r.endpoint,t=r.version,n=r.deploymentId;return e&&t&&n;},On=/*#__PURE__*/function(_Qs2){function On(e){var _C$headers;var _this38;_classCallCheck(this,On);var l,d,u,g,b,_,v,C;var t=w(e.directConnection),n=t.azure,s=(l=t.azure)==null?void 0:l.openAI,i=(s==null?void 0:s.urlDetails)||{},o="".concat((d=s==null?void 0:s.urlDetails)==null?void 0:d.endpoint,"/openai/"),a="?api-version=".concat((u=s==null?void 0:s.urlDetails)==null?void 0:u.version),c={threadsPrefix:"".concat(o).concat(On.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(On.NEW_ASSISTANT_RESOURCE).concat(a),createMessagePostfix:a,listMessagesPostfix:"order=desc&api-version=".concat((g=s==null?void 0:s.urlDetails)==null?void 0:g.version),storeFiles:"".concat(o).concat(m).concat(a),getFilesPrefix:"".concat(o).concat(m,"/"),getFilesPostfix:"/content".concat(a)};if(_this38=_callSuper(this,On,[e,s==null?void 0:s.assistant,c,Po(i),Lo,n]),_this38.permittedErrorPrefixes=[ei],_this38.insertKeyPlaceholderText=_this38.genereteAPIKeyName("Azure OpenAI"),_this38.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",_this38.isTextInputDisabled=!1,_typeof(s==null?void 0:s.assistant)===U){var _ref85=(v=(_=(b=e.directConnection)==null?void 0:b.azure)==null?void 0:_.openAI)==null?void 0:v.assistant,N=_ref85.function_handler,se=_ref85.files_tool_type;N&&(_this38._functionHandlerI=N),se&&(_this38.filesToolType=se);}Oo(i)?(_C$headers=(C=_this38.connectSettings).headers)!==null&&_C$headers!==void 0?_C$headers:C.headers={}:(_this38.isTextInputDisabled=!0,_this38.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,ei));}));return _this38;}_inherits(On,_Qs2);return _createClass(On);}(Qs);On.THREAD_RESOURCE="threads",On.NEW_ASSISTANT_RESOURCE="assistants";var Gi=On;var wl="sts-session-started",Cl="sts-session-stopped";var ge=/*#__PURE__*/function(){function ge(){_classCallCheck(this,ge);}return _createClass(ge,null,[{key:"addAttributes",value:function addAttributes(e){e[S]="button",e.setAttribute("tabindex","0");}},{key:"addAriaBusy",value:function addAriaBusy(e){e.setAttribute("aria-busy","true");}},{key:"removeAriaBusy",value:function removeAriaBusy(e){e.removeAttribute("aria-busy");}},{key:"addAriaDisabled",value:function addAriaDisabled(e){e.setAttribute("aria-".concat(j),"true");}},{key:"removeAriaDisabled",value:function removeAriaDisabled(e){e.removeAttribute("aria-".concat(j));}},{key:"removeAriaAttributes",value:function removeAriaAttributes(e){ge.removeAriaBusy(e),ge.removeAriaDisabled(e);}}]);}();var No="<?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",Ze=/*#__PURE__*/function(){function Ze(){_classCallCheck(this,Ze);}return _createClass(Ze,null,[{key:"createTextElement",value:function createTextElement(e){var t=x();return t[f].add(Ze.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,n,s){n?e.push(Ut.createSVGElement(n)):n!==""&&s&&e.push(t);}},{key:"createCustomElements",value:function createCustomElements(e,t,n){var c,l;var s=n==null?void 0:n[e],i=(c=s==null?void 0:s[h])==null?void 0:c.content,o=(l=s==null?void 0:s[z])==null?void 0:l.content,a=[];return Ze.tryAddSVGElement(a,t,o,i),i&&a.push(Ze.createTextElement(i)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e[f].remove(Ze.INPUT_BUTTON_SVG_CLASS,Ze.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(n){return n[f].contains(Ze.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e[f].add(Ze.INPUT_BUTTON_SVG_TEXT_CLASS):e[f].add(Ze.INPUT_BUTTON_SVG_CLASS);}}]);}();Ze.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",Ze.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",Ze.INPUT_BUTTON_SVG_CLASS="input-button-svg";var Tt=Ze;var ns=/*#__PURE__*/function(){function ns(){_classCallCheck(this,ns);}return _createClass(ns,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return _defineProperty(_defineProperty({},z,e.find(function(t){return t.tagName.toLowerCase()===z;})),h,e.find(function(t){return t.tagName.toLowerCase()==="div";}));}}]);}();var xe=/*#__PURE__*/function(){function xe(){_classCallCheck(this,xe);}return _createClass(xe,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var i,o;t.container&&de.unsetAllCSSMouseStates(e,t.container);var _ns$parseSVGTextEleme=ns.parseSVGTextElements(Array.from(e.children)),n=_ns$parseSVGTextEleme.svg,s=_ns$parseSVGTextEleme.text;(i=t[z])!=null&&i[R]&&n&&de.unsetAllCSSMouseStates(n,t[z][R]),(o=t[h])!=null&&o[R]&&s&&de.unsetAllCSSMouseStates(s,t[h][R]);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var i,o;t.container&&de.unsetActivityCSSMouseStates(e,t.container);var _ns$parseSVGTextEleme2=ns.parseSVGTextElements(Array.from(e.children)),n=_ns$parseSVGTextEleme2.svg,s=_ns$parseSVGTextEleme2.text;(i=t[z])!=null&&i[R]&&n&&de.unsetActivityCSSMouseStates(n,t[z][R]),(o=t[h])!=null&&o[R]&&s&&de.unsetActivityCSSMouseStates(s,t[h][R]);}},{key:"setElementsCSS",value:function setElementsCSS(e,t,n){var o,a,c,l,d;Object.assign(e[E],(o=t.container)==null?void 0:o[n]);var _ns$parseSVGTextEleme3=ns.parseSVGTextElements(Array.from(e.children)),s=_ns$parseSVGTextEleme3.svg,i=_ns$parseSVGTextEleme3.text;s&&Object.assign(s[E],(c=(a=t[z])==null?void 0:a[R])==null?void 0:c[n]),i&&Object.assign(i[E],(d=(l=t[h])==null?void 0:l[R])==null?void 0:d[n]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,n){xe.setElementsCSS(e,t,A),n!==A&&(xe.setElementsCSS(e,t,De),n!==De&&xe.setElementsCSS(e,t,Z));}}]);}();var Cn=/*#__PURE__*/function(){// prettier-ignore
|
|
171
|
+
function Cn(e,t,n,s,i,o){_classCallCheck(this,Cn);this._mouseState={state:"default"},this.isCustom=!1,ge.addAttributes(e),this.elementRef=e,this[z]=Ut.createSVGElement(t),this.customStyles=i,this.position=ce.processPosition(n),this._tooltipSettings=s,this.dropupText=o;}return _createClass(Cn,[{key:"buttonMouseLeave",value:function buttonMouseLeave(e){var t;this._mouseState.state=A,((t=this._activeTooltip)==null?void 0:t.element[E].visibility)==="visible"&&this._tooltipSettings&&yt.hide(this._activeTooltip,this._tooltipSettings),e&&(xe.unsetAllCSS(this.elementRef,e),xe.setElementsCSS(this.elementRef,e,A));}},{key:"buttonMouseEnter",value:function buttonMouseEnter(e){var t;this._mouseState.state=De,this._tooltipSettings&&(this._activeTooltip=yt.display(this.elementRef,this._tooltipSettings,(t=this._activeTooltip)==null?void 0:t.element)),e&&xe.setElementsCSS(this.elementRef,e,De);}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&xe.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state=Z,e&&xe.setElementsCSS(this.elementRef,e,Z);}// be careful not to use onclick as that is used for button functionality
|
|
172
|
+
},{key:"setEvents",value:function setEvents(e){this.elementRef.onmousedown=this.buttonMouseDown.bind(this,e),this.elementRef.onmouseup=this.buttonMouseUp.bind(this,e),this.elementRef.onmouseenter=this.buttonMouseEnter.bind(this,e),this.elementRef.onmouseleave=this.buttonMouseLeave.bind(this,e);}},{key:"unsetCustomStateStyles",value:function unsetCustomStateStyles(e){if(this.customStyles)for(var t=0;t<e.length;t+=1){var _n2=e[t],s=_n2&&this.customStyles[_n2];s&&xe.unsetActionCSS(this.elementRef,s);}}},{key:"reapplyStateStyle",value:function reapplyStateStyle(e,t){if(!this.customStyles)return;t&&this.unsetCustomStateStyles(t);var n=this.customStyles[e];n&&xe.setElementCssUpToState(this.elementRef,n,this._mouseState.state),this.setEvents(n);}},{key:"changeElementsByState",value:function changeElementsByState(e){var _this$elementRef;(_this$elementRef=this.elementRef).replaceChildren.apply(_this$elementRef,_toConsumableArray(e)),Tt.reassignClassBasedOnChildren(this.elementRef,e);}},{key:"buildDefaultIconElement",value:function buildDefaultIconElement(e){var t=this[z].cloneNode(!0);return t.id=e,[t];}},{key:"createInnerElements",value:function createInnerElements(e,t,n){var s=Tt.createCustomElements(t,this[z],n);if(s&&s.length>0){if(this.position===rt){var i=s[0].cloneNode(!0);i.id=s[0]===this[z]?e:"dropup-menu-item-icon-element-custom",s[0]=i;}return s;}return this.buildDefaultIconElement(e);}}]);}();var pi=/*#__PURE__*/function(_Cn){function pi(e){var _this39;_classCallCheck(this,pi);var n,s;var t=((s=(n=e==null?void 0:e[A])==null?void 0:n[z])==null?void 0:s.content)||pi.EMPTY_SVG;_this39=_callSuper(this,pi,[x(),t,void 0,void 0,e]),_this39.isActive=!1,_this39._innerElements=_this39.createInnerElementsForStates(_this39.customStyles),_this39.changeToDefault();return _this39;}_inherits(pi,_Cn);return _createClass(pi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty(_defineProperty(_defineProperty({},A,this.createInnerButtonElements(A,e)),$,this.createInnerButtonElements($,e)),Gt,this.createInnerButtonElements(Gt,e));}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return Tt.createCustomElements(e,this[z],t)||[this[z]];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef[f].replace(Tt.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements[$]),this.reapplyStateStyle($,[Gt,A]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,n,s;this.changeState(this._innerElements[A]),(e=this.customStyles)!=null&&e[$]&&xe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[$]),(n=this.customStyles)!=null&&n[Gt]&&xe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[Gt]),this.reapplyStateStyle(A,[$,Gt]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,n,s;this.changeState(this._innerElements[Gt]),(e=this.customStyles)!=null&&e[$]&&xe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[$]),(n=this.customStyles)!=null&&n[A]&&xe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[A]),this.reapplyStateStyle(Gt,[A,$]),this.isActive=!1;}}]);}(Cn);pi.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var ti=pi;var Le=/*#__PURE__*/function(){function Le(){_classCallCheck(this,Le);}return _createClass(Le,null,[{key:"setPropertyValueIfDoesNotExist",value:function setPropertyValueIfDoesNotExist(e,t,n){var _e$s,_e$s2;var s=t[0];t.length===1?(_e$s=e[s])!==null&&_e$s!==void 0?_e$s:e[s]=n:((_e$s2=e[s])!==null&&_e$s2!==void 0?_e$s2:e[s]={},t.shift(),Le.setPropertyValueIfDoesNotExist(e[s],t,n));}},{key:"setPropertyValue",value:function setPropertyValue(e,t,n){var _e$s3;var s=t[0];t.length===1?e[s]=n:((_e$s3=e[s])!==null&&_e$s3!==void 0?_e$s3:e[s]={},t.shift(),Le.setPropertyValue(e[s],t,n));}},{key:"getObjectValue",value:function getObjectValue(e,t){var n=t[0],s=e[n];return s===void 0||t.length===1?s:Le.getObjectValue(s,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,n){var s=Le.getObjectValue(t,n);if(s){var i=_objectSpread(_objectSpread({},s),Le.getObjectValue(e,n)||{});Le.setPropertyValue(e,n,i);}}},{key:"isJson",value:function isJson(e){try{return ae(e),!0;}catch(_unused8){return!1;}}// prettier-ignore
|
|
173
|
+
},{key:"assignPropertyFromOneToAnother",value:function assignPropertyFromOneToAnother(e,t,n){var _t$e;(_t$e=t[e])!==null&&_t$e!==void 0?_t$e:t[e]={},Object.assign(t[e],n==null?void 0:n[e]);}}]);}();var Bo="<?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>",zi="<?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>",J=/*#__PURE__*/function(_M6){function J(e){var _l$model;var _this40;_classCallCheck(this,J);var i,o,a,c,l;var t=w(e.directConnection),n=J.getKey(e);_this40=_callSuper(this,J,[e,Xn(),Wn,{key:n}]),_this40.insertKeyPlaceholderText=_this40.genereteAPIKeyName("OpenAI"),_this40.keyHelpUrl=Kn,_this40._microphoneButton=null,_this40._toggleButton=null,_this40._errorElement=null,_this40._loadingElement=null,_this40._pc=null,_this40._mediaStream=null,_this40._isMuted=!1;var s=(i=t.openAI)==null?void 0:i.realtime;if(_typeof(s)===U){_this40._avatarConfig=s.avatar,_this40._ephemeralKey=s.ephemeralKey,_this40._errorConfig=s[p],_this40._loadingConfig=s.loading,Object.assign(_this40.rawBody,s.config);var d=(a=(o=e.directConnection)==null?void 0:o.openAI)==null?void 0:a.realtime,_ref88=d.config||{},u=_ref88.function_handler;u&&(_this40._functionHandlerI=u),_this40._events=s.events,d.methods=_this40.generateMethods(),_this40.setInputAudioTranscribe(e,(c=d.config)==null?void 0:c.input_audio_transcription),delete _this40.rawBody.input_audio_transcription;}(_l$model=(l=_this40.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="gpt-realtime-2",_this40._avatarConfig=J.buildAvatarConfig(s),_this40._buttonsConfig=J.buildButtonsConfig(s),_this40._avatarEl=J.createAvatar(_this40._avatarConfig),_this40._containerEl=_this40.createContainer(),_this40._deepChat=e;return _this40;}_inherits(J,_M6);return _createClass(J,[{key:"setInputAudioTranscribe",value:// https://community.openai.com/t/unable-to-access-user-audio-transcript-in-realtime-api/1001570/3
|
|
174
174
|
function setInputAudioTranscribe(e,t){if(t){var _n3="whisper-1";this.rawBody.audio={input:{transcription:_typeof(t)=="object"?{model:t.model||_n3,language:t.language,prompt:t.prompt}:{model:_n3}}};}else e.onMessage&&(console.warn("To get user audio transcription, set `input_audio_transcription` in the `realtime` config."),console.warn("See: ".concat(X,"directConnection/OpenAI/OpenAIRealtime#OpenAIRealtimeConfig")));}// called after API key was inserted
|
|
175
|
-
},{key:"setUpView",value:function setUpView(e,t){e[E].display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(){var s,e,t,n;return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:e=(s=this._deepChat.directConnection)==null?void 0:s.openAI;if(e){_context91.n=1;break;}return _context91.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context91.n=2;break;}return _context91.a(2);case 2:n=this.key||e.key;(t.fetchEphemeralKey||n)&&t.autoStart&&(this.changeToUnavailable(),this.displayLoading()),this.fetchEphemeralKey(t.autoStart);case 3:return _context91.a(2);}},_callee91,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(e){var o,t,n,s,r,a,_t31,_t32,_t33;return _regenerator().w(function(_context92){while(1)switch(_context92.p=_context92.n){case 0:t=(o=this._deepChat.directConnection)==null?void 0:o.openAI,n=_typeof(t==null?void 0:t.realtime)=="object"?t==null?void 0:t.realtime.fetchEphemeralKey:void 0,s=t==null?void 0:t.realtime,r=this.key||t.key;if(!(_typeof(s)=="object")){_context92.n=8;break;}if(this._ephemeralKey){_context92.n=7;break;}_context92.p=1;if(!n){_context92.n=3;break;}a=n();a.then&&(this._retrievingEphemeralKey=a);_context92.n=2;return a;case 2:this._ephemeralKey=_context92.v;_context92.n=5;break;case 3:_t31=r;if(!_t31){_context92.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(r);_context92.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context92.v;case 5:_context92.n=7;break;case 6:_context92.p=6;_t32=_context92.v;this.displayFailedToRetrieveEphemeralKey(_t32);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context92.n=12;break;case 8:if(!r){_context92.n=12;break;}_context92.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(r);_context92.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context92.v;e&&this.init(this._ephemeralKey);_context92.n=12;break;case 11:_context92.p=11;_t33=_context92.v;this.displayFailedToRetrieveEphemeralKey(_t33);case 12:return _context92.a(2);}},_callee92,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x185){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(e){return _regenerator().w(function(_context93){while(1)switch(_context93.n){case 0:_context93.n=1;return fetch("".concat(Qe,"realtime/client_secrets"),{method:ye,body:ae({session:_objectSpread(_defineProperty({},y,"realtime"),this.rawBody)}),headers:_defineProperty(_defineProperty({},H,J),le,"".concat(Ae).concat(e))});case 1:_context93.n=2;return _context93.v.json();case 2:return _context93.a(2,_context93.v.value);}},_callee93,this);}));function getEphemeralKey(_x186){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this42=this;return{updateConfig:function updateConfig(e){var t;(t=_this42._dc)==null||t.send(ae(_defineProperty(_defineProperty({},y,"session.update"),"session",_objectSpread(_defineProperty({},y,"realtime"),e))));},sendMessage:function sendMessage(e,t){var n=t||jn,s=[_defineProperty(_defineProperty({},y,n===jn||n===F?Hi:h),"text",e)],r=_defineProperty(_defineProperty(_defineProperty({},S,n),y,"message"),"content",s);_this42.sendMessage(r);}};}},{key:"createContainer",value:function createContainer(){var e=x();return e.id="deep-chat-openai-realtime-container",e.appendChild(this.createAvatarContainer()),e.appendChild(this.createButtonsContainer()),e.appendChild(this.createError()),e;}},{key:"createAvatarContainer",value:function createAvatarContainer(){var t,n;var e=x();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[E],(n=(t=this._avatarConfig)==null?void 0:t[R])==null?void 0:n.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var s;var e=x();e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e[E],(s=this._buttonsConfig)==null?void 0:s.container),this._microphoneButton=this.createMicophoneButton();var t=Q.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var n=Q.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(n),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this43=this;var t;var e=new Qs((t=this._buttonsConfig)==null?void 0:t[pt]);return e.elementRef[f].add(Q.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),V.assignButtonEvents(e.elementRef,function(){e.isActive?(_this43.toggleMicorphone(!0),e.elementRef[f].replace(Q.MICROPHONE_ACTIVE,Q.BUTTON_DEFAULT),e.changeToDefault(),_this43._isMuted=!1):(_this43.toggleMicorphone(!1),e.elementRef[f].replace(Q.BUTTON_DEFAULT,Q.MICROPHONE_ACTIVE),ge.removeAriaAttributes(e.elementRef),e.changeToActive(),_this43._isMuted=!0);}),e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(n){return n.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this44=this;var t;var e=new Qs((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[f].add(Q.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),V.assignButtonEvents(e.elementRef,/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(){var n,s,_t34,_t35;return _regenerator().w(function(_context94){while(1)switch(_context94.p=_context94.n){case 0:if(!e.isActive){_context94.n=1;break;}e.changeToDefault(),_this44.stop();_context94.n=9;break;case 1:_context94.p=1;if(!_this44._ephemeralKey){_context94.n=3;break;}_this44.displayLoading();_context94.n=2;return _this44.init(_this44._ephemeralKey);case 2:_context94.n=7;break;case 3:if(!_this44._retrievingEphemeralKey){_context94.n=6;break;}_this44.displayLoading();_context94.n=4;return _this44._retrievingEphemeralKey;case 4:s=_context94.v;_t34=(n=_this44._toggleButton)!=null&&n.isActive;if(!_t34){_context94.n=5;break;}_context94.n=5;return _this44.init(s);case 5:_context94.n=7;break;case 6:_this44.displayLoading();_context94.n=7;return _this44.fetchEphemeralKey(!0);case 7:_context94.n=9;break;case 8:_context94.p=8;_t35=_context94.v;console[p]("Failed to start conversation:",_t35),_this44.displayError(),_this44.hideLoading();case 9:return _context94.a(2);}},_callee94,null,[[1,8]]);}))),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(e){var _this45=this;var t,n,s,r,o,a,c,l,_t38,_t39,_t40,_t41,_t42;return _regenerator().w(function(_context97){while(1)switch(_context97.p=_context97.n){case 0:t=new RTCPeerConnection();this._pc=t;n=x(q);n.autoplay=!0;s=new AudioContext(),r=s.createAnalyser();r.fftSize=256;o=new Uint8Array(r.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref91=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(a){var c,_t36;return _regenerator().w(function(_context95){while(1)switch(_context95.n){case 0:if(!a.streams[0]){_context95.n=2;break;}n.srcObject=a.streams[0];c=s.createMediaStreamSource(a.streams[0]);_t36=s.state==="suspended";if(!_t36){_context95.n=1;break;}_context95.n=1;return s.resume();case 1:c.connect(r);_this45.monitorFrequencies(r,o);_context95.n=3;break;case 2:console[p]("No streams found in the ontrack event."),_this45.displayError();case 3:return _context95.a(2);}},_callee95);}));return function(_x188){return _ref91.apply(this,arguments);};}();_context97.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var c;t===_this45._pc&&(_this45._mediaStream=a,(c=_this45._pc)==null||c.addTrack(_this45._mediaStream.getTracks()[0]),_this45._isMuted&&_this45.toggleMicorphone(!1));})["catch"](function(a){console[p]("Error accessing microphone:",a),_this45.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref92=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(a){var l,d,u,c,b,_,v,_t37;return _regenerator().w(function(_context96){while(1)switch(_context96.p=_context96.n){case 0:c=JSON.parse(a.data);if(!(c[y]==="session.created")){_context96.n=1;break;}_this45.removeUnavailable(),_this45._toggleButton&&(ge.removeAriaAttributes(_this45._toggleButton.elementRef),_this45._toggleButton.changeToActive()),(d=(l=_this45._events)==null?void 0:l.started)==null||d.call(l),_this45._deepChat.dispatchEvent(new CustomEvent(xl)),_this45.hideLoading();_context96.n=7;break;case 1:if(!(c[y]==="response.done")){_context96.n=6;break;}b=(u=JSON.parse(a.data).response.output)==null?void 0:u[0];if(!((b==null?void 0:b[y])===Bs)){_context96.n=5;break;}_=b.name,v=b.call_id;_context96.p=2;_context96.n=3;return _this45.handleTool(_,b.arguments,v);case 3:_context96.n=5;break;case 4:_context96.p=4;_t37=_context96.v;_this45.stopOnError(_t37);case 5:_context96.n=7;break;case 6:c[y]===p?_this45.stopOnError(c[p].message):c[y]===et?_this45.stopOnError(c.message):c[y]==="response.output_audio_transcript.delta"||(c[y]==="response.output_audio_transcript.done"?c.transcript&&_n.onMessage(_this45._deepChat,_defineProperty(_defineProperty({},S,te),h,c.transcript),!1):c[y]==="conversation.item.input_audio_transcription.completed"&&c.transcript&&_n.onMessage(_this45._deepChat,_defineProperty(_defineProperty({},S,F),h,c.transcript),!1));case 7:return _context96.a(2);}},_callee96,null,[[2,4]]);}));return function(_x189){return _ref92.apply(this,arguments);};}());_context97.p=2;_context97.n=3;return this._pc.createOffer();case 3:a=_context97.v;_t38=t!==this._pc;if(_t38){_context97.n=5;break;}_context97.n=4;return this._pc.setLocalDescription(a);case 4:_t38=t!==this._pc;case 5:if(!_t38){_context97.n=6;break;}return _context97.a(2);case 6:_context97.n=7;return fetch("".concat(Qe,"realtime/calls?model=").concat(this.rawBody.model),{method:ye,body:a.sdp,headers:_defineProperty(_defineProperty({},le,"".concat(Ae).concat(e)),H,"application/sdp")});case 7:c=_context97.v;if(!(t!==this._pc)){_context97.n=8;break;}return _context97.a(2);case 8:_t39=_defineProperty;_t40=_defineProperty({},y,"answer");_context97.n=9;return c[h]();case 9:l=_t39(_t40,"sdp",_context97.v);_t41=t!==this._pc;if(_t41){_context97.n=11;break;}_context97.n=10;return this._pc.setRemoteDescription(l);case 10:_t41=t!==this._pc;case 11:if(!_t41){_context97.n=12;break;}return _context97.a(2);case 12:_context97.n=14;break;case 13:_context97.p=13;_t42=_context97.v;console[p](_t42),this.displayError();case 14:return _context97.a(2);}},_callee97,this,[[2,13]]);}));function init(_x187){return _init2.apply(this,arguments);}return init;}()// there is a bug where sometimes upon refreshing the browser too many times the frequencyData is all 0s
|
|
175
|
+
},{key:"setUpView",value:function setUpView(e,t){e[E].display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(){var s,e,t,n;return _regenerator().w(function(_context93){while(1)switch(_context93.n){case 0:e=(s=this._deepChat.directConnection)==null?void 0:s.openAI;if(e){_context93.n=1;break;}return _context93.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context93.n=2;break;}return _context93.a(2);case 2:n=this.key||e.key;(t.fetchEphemeralKey||n)&&t.autoStart&&(this.changeToUnavailable(),this.displayLoading()),this.fetchEphemeralKey(t.autoStart);case 3:return _context93.a(2);}},_callee93,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(e){var o,t,n,s,i,a,_t43,_t44,_t45;return _regenerator().w(function(_context94){while(1)switch(_context94.p=_context94.n){case 0:t=(o=this._deepChat.directConnection)==null?void 0:o.openAI,n=_typeof(t==null?void 0:t.realtime)=="object"?t==null?void 0:t.realtime.fetchEphemeralKey:void 0,s=t==null?void 0:t.realtime,i=this.key||t.key;if(!(_typeof(s)=="object")){_context94.n=8;break;}if(this._ephemeralKey){_context94.n=7;break;}_context94.p=1;if(!n){_context94.n=3;break;}a=n();a.then&&(this._retrievingEphemeralKey=a);_context94.n=2;return a;case 2:this._ephemeralKey=_context94.v;_context94.n=5;break;case 3:_t43=i;if(!_t43){_context94.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(i);_context94.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context94.v;case 5:_context94.n=7;break;case 6:_context94.p=6;_t44=_context94.v;this.displayFailedToRetrieveEphemeralKey(_t44);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context94.n=12;break;case 8:if(!i){_context94.n=12;break;}_context94.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(i);_context94.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context94.v;e&&this.init(this._ephemeralKey);_context94.n=12;break;case 11:_context94.p=11;_t45=_context94.v;this.displayFailedToRetrieveEphemeralKey(_t45);case 12:return _context94.a(2);}},_callee94,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x184){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(e){return _regenerator().w(function(_context95){while(1)switch(_context95.n){case 0:_context95.n=1;return fetch("".concat(Qe,"realtime/client_secrets"),{method:ye,body:ae({session:_objectSpread(_defineProperty({},y,"realtime"),this.rawBody)}),headers:_defineProperty(_defineProperty({},H,Y),le,"".concat(Ae).concat(e))});case 1:_context95.n=2;return _context95.v.json();case 2:return _context95.a(2,_context95.v.value);}},_callee95,this);}));function getEphemeralKey(_x185){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this41=this;return{updateConfig:function updateConfig(e){var t;(t=_this41._dc)==null||t.send(ae(_defineProperty(_defineProperty({},y,"session.update"),"session",_objectSpread(_defineProperty({},y,"realtime"),e))));},sendMessage:function sendMessage(e,t){var n=t||ps,s=[_defineProperty(_defineProperty({},y,n===ps||n===F?ji:h),"text",e)],i=_defineProperty(_defineProperty(_defineProperty({},S,n),y,"message"),"content",s);_this41.sendMessage(i);}};}},{key:"createContainer",value:function createContainer(){var e=x();return e.id="deep-chat-openai-realtime-container",e.appendChild(this.createAvatarContainer()),e.appendChild(this.createButtonsContainer()),e.appendChild(this.createError()),e;}},{key:"createAvatarContainer",value:function createAvatarContainer(){var t,n;var e=x();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[E],(n=(t=this._avatarConfig)==null?void 0:t[R])==null?void 0:n.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var s;var e=x();e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e[E],(s=this._buttonsConfig)==null?void 0:s.container),this._microphoneButton=this.createMicophoneButton();var t=J.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var n=J.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(n),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this42=this;var t;var e=new ti((t=this._buttonsConfig)==null?void 0:t[ft]);return e.elementRef[f].add(J.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),q.assignButtonEvents(e.elementRef,function(){e.isActive?(_this42.toggleMicorphone(!0),e.elementRef[f].replace(J.MICROPHONE_ACTIVE,J.BUTTON_DEFAULT),e.changeToDefault(),_this42._isMuted=!1):(_this42.toggleMicorphone(!1),e.elementRef[f].replace(J.BUTTON_DEFAULT,J.MICROPHONE_ACTIVE),ge.removeAriaAttributes(e.elementRef),e.changeToActive(),_this42._isMuted=!0);}),e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(n){return n.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this43=this;var t;var e=new ti((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[f].add(J.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),q.assignButtonEvents(e.elementRef,/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(){var n,s,_t46,_t47;return _regenerator().w(function(_context96){while(1)switch(_context96.p=_context96.n){case 0:if(!e.isActive){_context96.n=1;break;}e.changeToDefault(),_this43.stop();_context96.n=9;break;case 1:_context96.p=1;if(!_this43._ephemeralKey){_context96.n=3;break;}_this43.displayLoading();_context96.n=2;return _this43.init(_this43._ephemeralKey);case 2:_context96.n=7;break;case 3:if(!_this43._retrievingEphemeralKey){_context96.n=6;break;}_this43.displayLoading();_context96.n=4;return _this43._retrievingEphemeralKey;case 4:s=_context96.v;_t46=(n=_this43._toggleButton)!=null&&n.isActive;if(!_t46){_context96.n=5;break;}_context96.n=5;return _this43.init(s);case 5:_context96.n=7;break;case 6:_this43.displayLoading();_context96.n=7;return _this43.fetchEphemeralKey(!0);case 7:_context96.n=9;break;case 8:_context96.p=8;_t47=_context96.v;console[p]("Failed to start conversation:",_t47),_this43.displayError(),_this43.hideLoading();case 9:return _context96.a(2);}},_callee96,null,[[1,8]]);}))),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e){var _this44=this;var t,n,s,i,o,a,c,l,_t50,_t51,_t52,_t53,_t54;return _regenerator().w(function(_context99){while(1)switch(_context99.p=_context99.n){case 0:t=new RTCPeerConnection();this._pc=t;n=x(G);n.autoplay=!0;s=new AudioContext(),i=s.createAnalyser();i.fftSize=256;o=new Uint8Array(i.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref91=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(a){var c,_t48;return _regenerator().w(function(_context97){while(1)switch(_context97.n){case 0:if(!a.streams[0]){_context97.n=2;break;}n.srcObject=a.streams[0];c=s.createMediaStreamSource(a.streams[0]);_t48=s.state==="suspended";if(!_t48){_context97.n=1;break;}_context97.n=1;return s.resume();case 1:c.connect(i);_this44.monitorFrequencies(i,o);_context97.n=3;break;case 2:console[p]("No streams found in the ontrack event."),_this44.displayError();case 3:return _context97.a(2);}},_callee97);}));return function(_x187){return _ref91.apply(this,arguments);};}();_context99.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var c;t===_this44._pc&&(_this44._mediaStream=a,(c=_this44._pc)==null||c.addTrack(_this44._mediaStream.getTracks()[0]),_this44._isMuted&&_this44.toggleMicorphone(!1));})["catch"](function(a){console[p]("Error accessing microphone:",a),_this44.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref92=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(a){var l,d,u,c,b,_,v,_t49;return _regenerator().w(function(_context98){while(1)switch(_context98.p=_context98.n){case 0:c=JSON.parse(a.data);if(!(c[y]==="session.created")){_context98.n=1;break;}_this44.removeUnavailable(),_this44._toggleButton&&(ge.removeAriaAttributes(_this44._toggleButton.elementRef),_this44._toggleButton.changeToActive()),(d=(l=_this44._events)==null?void 0:l.started)==null||d.call(l),_this44._deepChat.dispatchEvent(new CustomEvent(wl)),_this44.hideLoading();_context98.n=7;break;case 1:if(!(c[y]==="response.done")){_context98.n=6;break;}b=(u=JSON.parse(a.data).response.output)==null?void 0:u[0];if(!((b==null?void 0:b[y])===Ds)){_context98.n=5;break;}_=b.name,v=b.call_id;_context98.p=2;_context98.n=3;return _this44.handleTool(_,b.arguments,v);case 3:_context98.n=5;break;case 4:_context98.p=4;_t49=_context98.v;_this44.stopOnError(_t49);case 5:_context98.n=7;break;case 6:c[y]===p?_this44.stopOnError(c[p].message):c[y]===et?_this44.stopOnError(c.message):c[y]==="response.output_audio_transcript.delta"||(c[y]==="response.output_audio_transcript.done"?c.transcript&&vn.onMessage(_this44._deepChat,_defineProperty(_defineProperty({},S,te),h,c.transcript),!1):c[y]==="conversation.item.input_audio_transcription.completed"&&c.transcript&&vn.onMessage(_this44._deepChat,_defineProperty(_defineProperty({},S,F),h,c.transcript),!1));case 7:return _context98.a(2);}},_callee98,null,[[2,4]]);}));return function(_x188){return _ref92.apply(this,arguments);};}());_context99.p=2;_context99.n=3;return this._pc.createOffer();case 3:a=_context99.v;_t50=t!==this._pc;if(_t50){_context99.n=5;break;}_context99.n=4;return this._pc.setLocalDescription(a);case 4:_t50=t!==this._pc;case 5:if(!_t50){_context99.n=6;break;}return _context99.a(2);case 6:_context99.n=7;return fetch("".concat(Qe,"realtime/calls?model=").concat(this.rawBody.model),{method:ye,body:a.sdp,headers:_defineProperty(_defineProperty({},le,"".concat(Ae).concat(e)),H,"application/sdp")});case 7:c=_context99.v;if(!(t!==this._pc)){_context99.n=8;break;}return _context99.a(2);case 8:_t51=_defineProperty;_t52=_defineProperty({},y,"answer");_context99.n=9;return c[h]();case 9:l=_t51(_t52,"sdp",_context99.v);_t53=t!==this._pc;if(_t53){_context99.n=11;break;}_context99.n=10;return this._pc.setRemoteDescription(l);case 10:_t53=t!==this._pc;case 11:if(!_t53){_context99.n=12;break;}return _context99.a(2);case 12:_context99.n=14;break;case 13:_context99.p=13;_t54=_context99.v;console[p](_t54),this.displayError();case 14:return _context99.a(2);}},_callee99,this,[[2,13]]);}));function init(_x186){return _init2.apply(this,arguments);}return init;}()// there is a bug where sometimes upon refreshing the browser too many times the frequencyData is all 0s
|
|
176
176
|
// in such instance please wait and refresh at a later time
|
|
177
|
-
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var
|
|
178
|
-
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
179
|
-
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=ae(_defineProperty(_defineProperty({},y,"conversation.item.create"),"item",e));this._dc.send(t);var n=_defineProperty({},y,"response.create");this._dc.send(ae(n));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var n=t==null?void 0:t.realtime;if(_typeof(n)=="object"&&(n.ephemeralKey||n.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?w(e.avatar):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$
|
|
180
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
181
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",
|
|
182
|
-
function
|
|
183
|
-
"Please define the azure endpoint. [More Information](".concat(X,"directConnection/Azure#Summarization)");var
|
|
184
|
-
function
|
|
185
|
-
function
|
|
186
|
-
function hs(e){var _a$lang,_c$name,_l$gender;var
|
|
187
|
-
function
|
|
188
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",
|
|
177
|
+
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this45=this;var n=function(_n4){function n(){return _n4.apply(this,arguments);}n.toString=function(){return _n4.toString();};return n;}(function(){var l;e.getByteFrequencyData(t);var s=t.reduce(function(d,u){return d+u;},0),i=t.length*255,o=s/i*100,a=1,c=a+o/100*(((l=_this45._avatarConfig)==null?void 0:l.maxScale)-a);_this45._avatarEl[E].transform="scale(".concat(c,")"),requestAnimationFrame(n);});n();}},{key:"stopOnError",value:function stopOnError(e){this.stop(),console[p](e),this.displayError();}},{key:"stop",value:function stop(){var e,t,n;(e=this._mediaStream)==null||e.getTracks().forEach(function(s){return s.stop();}),this._mediaStream=null,this._pc&&(this._pc.close(),this._pc=null,(n=(t=this._events)==null?void 0:t.stopped)==null||n.call(t),this._deepChat.dispatchEvent(new CustomEvent(Cl)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&J.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&J.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&J.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&J.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&J.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&J.removeButtonUnavailable(this._toggleButton);}},{key:"createError",value:function createError(){var t;var e=x();return e.id="deep-chat-openai-realtime-error",Object.assign(e[E],(t=this._errorConfig)==null?void 0:t[E]),this._errorElement=e,e;}},{key:"displayFailedToRetrieveEphemeralKey",value:function displayFailedToRetrieveEphemeralKey(e){console[p]("Failed to retrieve ephemeral key"),console[p](e),this.displayError();}},{key:"displayError",value:function displayError(){var e;this._errorElement&&(this._errorElement[E].display="block",this._errorElement.textContent=((e=this._errorConfig)==null?void 0:e[h])||"Error",this.changeToUnavailable()),this.hideLoading();}},{key:"createLoading",value:function createLoading(){var t,n;var e=x();return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t[L]&&(this._loadingElement.innerHTML=this._loadingConfig[L]),Object.assign(e[E],(n=this._loadingConfig)==null?void 0:n[E]),e[E].display="none",e;}},{key:"displayLoading",value:function displayLoading(){var e,t,n;this._toggleButton&&(this._toggleButton.changeToActive(),this._toggleButton.elementRef[f].add(J.BUTTON_LOADING),ge.removeAriaDisabled(this._toggleButton.elementRef),ge.addAriaBusy(this._toggleButton.elementRef)),(typeof((e=this._loadingConfig)==null?void 0:e.display)!="boolean"||this._loadingConfig.display)&&this._loadingElement&&(this._loadingElement[E].display="block",(t=this._loadingConfig)!=null&&t[L]||(this._loadingElement.textContent=((n=this._loadingConfig)==null?void 0:n[h])||"Loading"));}},{key:"hideLoading",value:function hideLoading(){this._toggleButton&&(this._toggleButton.elementRef[f].remove(J.BUTTON_LOADING),ge.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement[E].display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
|
|
178
|
+
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee100(e,t,n){var s,i;return _regenerator().w(function(_context100){while(1)switch(_context100.n){case 0:if(this._functionHandlerI){_context100.n=1;break;}throw Error(en);case 1:_context100.n=2;return this._functionHandlerI({name:e,arguments:t});case 2:s=_context100.v;if(!(_typeof(s)!="object"||!Le.isJson(s))){_context100.n=3;break;}throw Error('The `function_handler` response must be a JSON object, e.g. {response: "My response"}');case 3:i=_defineProperty(_defineProperty(_defineProperty({},y,Mo),"call_id",n),"output",ae(s));this.sendMessage(i);case 4:return _context100.a(2);}},_callee100,this);}));function handleTool(_x189,_x190,_x191){return _handleTool.apply(this,arguments);}return handleTool;}()// https://platform.openai.com/docs/api-reference/realtime-client-events/conversation/item/create
|
|
179
|
+
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=ae(_defineProperty(_defineProperty({},y,"conversation.item.create"),"item",e));this._dc.send(t);var n=_defineProperty({},y,"response.create");this._dc.send(ae(n));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var n=t==null?void 0:t.realtime;if(_typeof(n)=="object"&&(n.ephemeralKey||n.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?w(e.avatar):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$ft,_o$A,_a$z,_c$content,_t$toggle,_g$A,_b$z,_$content,_v$$,_C$z,_N$content;var n,s,i,o,a,c,l,d,u,g,b,_,v,C,N;var t=_typeof(e)=="object"&&e.buttons?w(e.buttons):{};return(i=(s=(n=t[ft])==null?void 0:n[A])==null?void 0:s[h])!=null&&i.content||((_t$ft=t[ft])!==null&&_t$ft!==void 0?_t$ft:t[ft]={},(_o$A=(o=t[ft])[A])!==null&&_o$A!==void 0?_o$A:o[A]={},(_a$z=(a=t[ft][A])[z])!==null&&_a$z!==void 0?_a$z:a[z]={},(_c$content=(c=t[ft][A][z]).content)!==null&&_c$content!==void 0?_c$content:c.content=No),(u=(d=(l=t.toggle)==null?void 0:l[A])==null?void 0:d[h])!=null&&u.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_g$A=(g=t.toggle)[A])!==null&&_g$A!==void 0?_g$A:g[A]={},(_b$z=(b=t.toggle[A])[z])!==null&&_b$z!==void 0?_b$z:b[z]={},(_$content=(_=t.toggle[A][z]).content)!==null&&_$content!==void 0?_$content:_.content=Bo,(_v$$=(v=t.toggle)[$])!==null&&_v$$!==void 0?_v$$:v[$]={},(_C$z=(C=t.toggle[$])[z])!==null&&_C$z!==void 0?_C$z:C[z]={},(_N$content=(N=t.toggle[$][z]).content)!==null&&_N$content!==void 0?_N$content:N.content=zi),t;}},{key:"createAvatar",value:function createAvatar(e){var n;var t=x("img");return t.id="deep-chat-openai-realtime-avatar",Object.assign(t[E],(n=e==null?void 0:e[R])==null?void 0:n[W]),t[T]=(e==null?void 0:e[T])||Fi,t;}},{key:"createButtonContainer",value:function createButtonContainer(e){var t=x();return t[f].add("deep-chat-openai-realtime-button-container"),t.appendChild(e),t;}},{key:"changeButtonToUnavailable",value:function changeButtonToUnavailable(e){e.elementRef[f].add(J.UNAVAILABLE),ge.removeAriaBusy(e.elementRef),ge.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){J.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){ge.removeAriaDisabled(e.elementRef),e.elementRef[f].remove(J.UNAVAILABLE);}}]);}(M);J.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",J.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",J.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",J.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var qi=J;var Nn=/*#__PURE__*/function(_M7){function Nn(e){var _o$model3,_a$voice3;var _this46;_classCallCheck(this,Nn);var i,o,a;var t=w(e.directConnection),n=t==null?void 0:t.openAI;_this46=_callSuper(this,Nn,[e,Xn(),Wn,n]),_this46.insertKeyPlaceholderText=_this46.genereteAPIKeyName("OpenAI"),_this46.keyHelpUrl=Kn,_this46.url="".concat(Qe,"audio/speech"),_this46.permittedErrorPrefixes=[tn];var s=(i=t==null?void 0:t.openAI)==null?void 0:i.textToSpeech;_typeof(s)===U&&Object.assign(_this46.rawBody,s),(_o$model3=(o=_this46.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=Nn.DEFAULT_MODEL,(_a$voice3=(a=_this46.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=Nn.DEFAULT_VOIDE,_this46.textInputPlaceholderText="Insert text to generate audio",_this46.rawBody.response_format="mp3";return _this46;}_inherits(Nn,_M7);return _createClass(Nn,[{key:"preprocessBody",value:function preprocessBody(e,t){var i,o;var n=w(e),s=(o=(i=t[t[K]-1])==null?void 0:i[h])==null?void 0:o.trim();return s&&s!==""&&(n.input=s),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e,t){return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:this.url=this.connectSettings.url||this.url,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context101.a(2);}},_callee101,this);}));function callServiceAPI(_x192,_x193){return _callServiceAPI10.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(e){return _regenerator().w(function(_context102){while(1)switch(_context102.n){case 0:if(!(e instanceof Blob)){_context102.n=1;break;}return _context102.a(2,new Promise(function(t){var n=new FileReader();n.readAsDataURL(e),n.onload=function(s){t(_defineProperty({},m,[_defineProperty(_defineProperty({},T,s.target.result),y,G)]));};}));case 1:if(!e[p]){_context102.n=2;break;}throw e[p].message;case 2:return _context102.a(2,_defineProperty({},p,p));}},_callee102);}));function extractResultData(_x194){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(M);Nn.DEFAULT_MODEL="tts-1",Nn.DEFAULT_VOIDE="alloy";var Vi=Nn;var dt=/*#__PURE__*/function(_M8){function dt(e){var _o$model4;var _this47;_classCallCheck(this,dt);var i,o;var t=w(e.directConnection),n=t==null?void 0:t.openAI;_this47=_callSuper(this,dt,[e,Xn(),Wn,n,{audio:{}}]),_this47.insertKeyPlaceholderText=_this47.genereteAPIKeyName("OpenAI"),_this47.keyHelpUrl=Kn,_this47.url="",_this47.permittedErrorPrefixes=[tn],_this47.textInputPlaceholderText=cr,_this47._service_url=dt.AUDIO_TRANSCRIPTIONS_URL;var s=(i=t==null?void 0:t.openAI)==null?void 0:i[G];_typeof(s)=="object"&&(_this47.processConfig(s),dt.cleanConfig(s),Object.assign(_this47.rawBody,s)),(_o$model4=(o=_this47.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=dt.DEFAULT_MODEL,_this47.rawBody.response_format="json",_this47.canSendMessage=dt.canSendFileMessage;return _this47;}_inherits(dt,_M8);return _createClass(dt,[{key:"processConfig",value:function processConfig(e){e!=null&&e[y]&&e[y]==="translation"&&(this._service_url=dt.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var i,o;var n=w(e),s=(o=(i=t[t[K]-1])==null?void 0:i[h])==null?void 0:o.trim();return s&&s!==""&&(n.prompt=s),n;}// prettier-ignore
|
|
180
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103(e,t,n){var o,s,i;return _regenerator().w(function(_context103){while(1)switch(_context103.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context103.n=1;break;}throw new Error($e);case 1:if(n!=null&&n[0]){_context103.n=2;break;}throw new Error(mi);case 2:this.url=this.connectSettings.url||this._service_url;s=this.preprocessBody(this.rawBody,t),i=dt.createFormDataBody(s,n[0]);D.tempRemoveContentHeader(this.connectSettings,be.request.bind(this,this,i,e),!1);case 3:return _context103.a(2);}},_callee103,this);}));function callServiceAPI(_x195,_x196,_x197){return _callServiceAPI11.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(e){return _regenerator().w(function(_context104){while(1)switch(_context104.n){case 0:if(!e[p]){_context104.n=1;break;}throw e[p].message;case 1:return _context104.a(2,_defineProperty({},h,e[h]));}},_callee104);}));function extractResultData(_x198){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[y];}},{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(ne,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}}]);}(M);dt.AUDIO_TRANSCRIPTIONS_URL="".concat(Qe,"audio/transcriptions"),dt.AUDIO_TRANSLATIONS_URL="".concat(Qe,"audio/translations"),dt.DEFAULT_MODEL="whisper-1";var Ki=dt;var Zn="Ocp-Apim-Subscription-Key",Do=// eslint-disable-next-line max-len
|
|
181
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",Tl=function Tl(r,e){return _defineProperty(_defineProperty(_defineProperty({},Zn,e),H,"application/ssml+xml"),"X-Microsoft-OutputFormat",r);},Rl=function Rl(r){return _defineProperty(_defineProperty({},Zn,r),"Accept",Y);},Il=function Il(r,e,t,n){r[p]?n(ue):t(e);},Ml=function Ml(r){return{url:"https://".concat(r,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:ye,createHeaders:function createHeaders(e){return _defineProperty({},Zn,"".concat(e));},handleVerificationResult:Il};},kl=function kl(r){return _defineProperty(_defineProperty({},Zn,r),H,Y);},Ll=function Ll(r,e,t,n){var i;((i=r[p])==null?void 0:i.code)==="401"?n(ue):t(e);},Pl=function Pl(r){return{url:"".concat(r,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:ye,createHeaders:function createHeaders(e){return _defineProperty({},Zn,"".concat(e));},handleVerificationResult:Ll};},Ol=function Ol(r,e,t,n){r.json().then(function(i){!Array.isArray(i)&&i[p].code===401e3?n(ue):t(e);});},Nl=function Nl(r){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:ye,createHeaders:function createHeaders(e){return Fo(r,e);},handleVerificationResult:Ol};},Fo=function Fo(r,e){var t=_defineProperty(_defineProperty({},Zn,e),H,Y);return r&&(t["Ocp-Apim-Subscription-Region"]=r),t;};var Bl=/*#__PURE__*/function(_M9){// prettier-ignore
|
|
182
|
+
function Bl(e,t,n,s,i){var _this48;_classCallCheck(this,Bl);_this48=_callSuper(this,Bl,[e,Pl(n),t,s,i]),_this48.insertKeyPlaceholderText="Azure Language Subscription Key",_this48.keyHelpUrl=Do,_this48.permittedErrorPrefixes=["Access"];return _this48;}_inherits(Bl,_M9);return _createClass(Bl);}(M);var ls=/*#__PURE__*/function(_Bl){function ls(e){var _a$language;var _this49;_classCallCheck(this,ls);var s,i,o,a;var t=(i=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:i.summarization,n=(o=e.directConnection)==null?void 0:o.azure;_this49=_callSuper(this,ls,[e,kl,t.endpoint,n]),_this49.permittedErrorPrefixes=[ls.ENDPOINT_ERROR_MESSAGE],_this49.url="",_this49.textInputPlaceholderText="Insert text to summarize",_this49.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this49.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this49.rawBody,t),_this49.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this49.isTextInputDisabled=!0,_this49.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,ls.ENDPOINT_ERROR_MESSAGE));}));return _this49;}_inherits(ls,_Bl);return _createClass(ls,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return{analysisInput:{documents:[_defineProperty({id:"1",language:e.language},h,n)]},tasks:[{kind:"ExtractiveSummarization"}]};}},{key:"callServiceAPI",value:function(){var _callServiceAPI12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e,t){return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)),this.messages=e;case 1:return _context105.a(2);}},_callee105,this);}));function callServiceAPI(_x199,_x200){return _callServiceAPI12.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(e){var t,_n6,s;return _regenerator().w(function(_context106){while(1)switch(_context106.n){case 0:if(!e[p]){_context106.n=1;break;}throw e[p].message;case 1:if(this.messages&&this.completionsHandlers){this.asyncCallInProgress=!0;_n6=e.headers.get("operation-location"),s={method:he,headers:(t=this.connectSettings)==null?void 0:t.headers};be.executePollRequest(this,_n6,s,this.messages);}return _context106.a(2,_defineProperty({},h,""));}},_callee106,this);}));function extractResultData(_x201){return _extractResultData15.apply(this,arguments);}return extractResultData;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(e){var t,_iterator4,_step4,_n7;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:if(!e[p]){_context107.n=1;break;}throw e[p];case 1:if(!(e.status==="running"||e.status==="notStarted")){_context107.n=2;break;}return _context107.a(2,{timeoutMS:2e3});case 2:if(!(e.errors.length>0)){_context107.n=3;break;}throw e.errors[0];case 3:if(!(e.tasks.items[0].results.errors.length>0)){_context107.n=4;break;}throw e.tasks.items[0].results.errors[0];case 4:t="";_iterator4=_createForOfIteratorHelper(e.tasks.items[0].results.documents[0].sentences);try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){_n7=_step4.value;t+=_n7[h];}}catch(err){_iterator4.e(err);}finally{_iterator4.f();}return _context107.a(2,_defineProperty({},h,t||""));}},_callee107);}));function extractPollResultData(_x202){return _extractPollResultData5.apply(this,arguments);}return extractPollResultData;}()}]);}(Bl);ls.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
|
183
|
+
"Please define the azure endpoint. [More Information](".concat(X,"directConnection/Azure#Summarization)");var Wi=ls;var Dl=/*#__PURE__*/function(){var _ref104=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(r,e){var t,o,a,l,_t58;return _regenerator().w(function(_context108){while(1)switch(_context108.n){case 0:t=_defineProperty(_defineProperty({},ha,r),da,Y);_t58="https://api.assemblyai.com/v2/transcript/";_context108.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:ye,body:ae({audio_url:e}),headers:t});case 1:_context108.n=2;return _context108.v.json();case 2:o=_t58.concat.call(_t58,_context108.v.id);case 3:if(a){_context108.n=9;break;}_context108.n=4;return fetch(o,{headers:t});case 4:_context108.n=5;return _context108.v.json();case 5:l=_context108.v;if(!(l.status===ar)){_context108.n=6;break;}a=l;_context108.n=8;break;case 6:if(!(l.status===p)){_context108.n=7;break;}throw new Error("Transcription failed: ".concat(l[p]));case 7:_context108.n=8;return new Promise(function(d){return setTimeout(d,3e3);});case 8:_context108.n=3;break;case 9:return _context108.a(2,a);}},_callee108);}));return function Dl(_x203,_x204){return _ref104.apply(this,arguments);};}(),Fl=function Fl(r){return _defineProperty(_defineProperty({},le,r),H,"application/octet-stream");},Ul=function Ul(r,e,t,n){var s=r;s[p]?s[p].code==="invalid_api_key"?n(ue):n(He):t(e);},Hl=function Hl(){return pe("https://api.assemblyai.com/v2/upload",ye,Ul);};var br=/*#__PURE__*/function(_M0){function br(e){var _this50;_classCallCheck(this,br);var n;var t=(n=e.directConnection)==null?void 0:n.assemblyAI;_this50=_callSuper(this,br,[e,Hl(),Fl,t,{audio:{}}]),_this50.insertKeyPlaceholderText=_this50.genereteAPIKeyName("AssemblyAI"),_this50.keyHelpUrl="https://www.assemblyai.com/app/account",_this50.url="https://api.assemblyai.com/v2/upload",_this50.isTextInputDisabled=!0,_this50.textInputPlaceholderText=cr,_this50.permittedErrorPrefixes=[yo,tn],_this50.canSendMessage=br.canFileSendMessage;return _this50;}_inherits(br,_M0);return _createClass(br,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e,t,n){var s;return _regenerator().w(function(_context109){while(1)switch(_context109.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context109.n=1;break;}throw new Error($e);case 1:if(n!=null&&n[0]){_context109.n=2;break;}throw new Error(mi);case 2:be.request(this,n[0],e,!1);case 3:return _context109.a(2);}},_callee109,this);}));function callServiceAPI(_x205,_x206,_x207){return _callServiceAPI13.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(e){var s,i,t,n;return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:if(!e[p]){_context110.n=1;break;}throw e[p];case 1:t=(i=(s=this.connectSettings)==null?void 0:s.headers)==null?void 0:i[le];_context110.n=2;return Dl(t,e.upload_url);case 2:n=_context110.v;return _context110.a(2,_defineProperty({},h,n[h]));}},_callee110,this);}));function extractResultData(_x208){return _extractResultData16.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(M);var ni=/*#__PURE__*/function(_M1){// prettier-ignore
|
|
184
|
+
function ni(e,t,n,s,i){var _this51$maxMessages,_g$model;var _this51;_classCallCheck(this,ni);var u,g;var o=w(e.directConnection),a=t||Xn(),c=n||Wn,l=s||o.openAI;_this51=_callSuper(this,ni,[e,a,c,l]),_this51.insertKeyPlaceholderText=_this51.genereteAPIKeyName("OpenAI"),_this51.keyHelpUrl="https://platform.openai.com/account/api-keys",_this51.permittedErrorPrefixes=[Ts,"Invalid value"];var d=i||((u=o.openAI)==null?void 0:u.chat);_typeof(d)===U&&_this51.processConfig(d,e),(_this51$maxMessages=_this51.maxMessages)!==null&&_this51$maxMessages!==void 0?_this51$maxMessages:_this51.maxMessages=-1,(_g$model=(g=_this51.rawBody).model)!==null&&_g$model!==void 0?_g$model:g.model="gpt-5.4";return _this51;}_inherits(ni,_M1);return _createClass(ni,[{key:"processConfig",value:function processConfig(e,t){var n,s,i;this.completeConfig(e,(i=(s=(n=t.directConnection)==null?void 0:n.openAI)==null?void 0:s.chat)==null?void 0:i.function_handler);}}],[{key:"getBaseFileContent",value:function getBaseFileContent(e){return e.map(function(t){var n,s,i;if(t[y]===G){var o=(n=t[T])==null?void 0:n.split(",")[1],a=((i=(s=t.name)==null?void 0:s.split(".").pop())==null?void 0:i.toLowerCase())||"wav";return _defineProperty(_defineProperty({},y,fn),fn,{data:o,format:a});}return t;});}},{key:"getBaseContent",value:function getBaseContent(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;if(t&&e[m]&&e[m][K]>0){var s=this.getBaseFileContent(e[m]);return e[h]&&e[h].trim()[K]>0&&s.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),s;}return e[h];}}]);}(M);var si=/*#__PURE__*/function(_ni){function si(){var _this52;_classCallCheck(this,si);_this52=_callSuper(this,si,arguments),_this52.url="".concat(Qe,"chat/completions");return _this52;}_inherits(si,_ni);return _createClass(si,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:si.getContent(i)},S,M.getRoleViaUser(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e,t){var _this$messages;return _regenerator().w(function(_context111){while(1)switch(_context111.n){case 0:(_this$messages=this.messages)!==null&&_this$messages!==void 0?_this$messages:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context111.a(2);}},_callee111,this);}));function callServiceAPI(_x209,_x210){return _callServiceAPI14.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(e,t){var n,s,i,o,a,c,l,d;return _regenerator().w(function(_context112){while(1)switch(_context112.n){case 0:if(!e[p]){_context112.n=1;break;}throw e[p].message;case 1:if(!((s=(n=e.choices)==null?void 0:n[0])!=null&&s.delta)){_context112.n=2;break;}return _context112.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(i=e.choices)==null?void 0:i[0])!=null&&o.message)){_context112.n=5;break;}if(!e.choices[0].message.tool_calls){_context112.n=3;break;}return _context112.a(2,this.handleToolsGeneric(e.choices[0].message,this.functionHandler,this.messages,t));case 3:if(!((a=e.choices[0].message)!=null&&a[G])){_context112.n=4;break;}l=this.deepChat.textToSpeech,d=_typeof(l)=="object"&&typeof((c=l==null?void 0:l[G])==null?void 0:c.displayText)=="boolean";return _context112.a(2,_defineProperty(_defineProperty({},m,[_defineProperty(_defineProperty({},T,"data:audio/wav;base64,".concat(e.choices[0].message[G].data)),y,G)]),h,d?e.choices[0].message[G].transcript:void 0));case 4:return _context112.a(2,_defineProperty({},h,e.choices[0].message.content));case 5:return _context112.a(2,_defineProperty({},h,""));}},_callee112,this);}));function extractResultData(_x211,_x212){return _extractResultData17.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113(e,t){return _regenerator().w(function(_context113){while(1)switch(_context113.n){case 0:return _context113.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee113,this);}));function extractStreamResult(_x213,_x214){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return ni.getBaseFileContent(e).map(function(n){return n[y]===fn?n:_defineProperty(_defineProperty({},y,qe),qe,{url:n[T]});});}},{key:"getContent",value:function getContent(e){if(e[m]&&e[m][K]>0){var t=si.getFileContent(e[m]);return e[h]&&e[h].trim()[K]>0&&t.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),t;}return e[h];}}]);}(ni);var Ir=/*#__PURE__*/function(_M10){// prettier-ignore
|
|
185
|
+
function Ir(e,t,n,s,i){var _this53;_classCallCheck(this,Ir);_this53=_callSuper(this,Ir,[e,Ml(n),t,s,i]),_this53.insertKeyPlaceholderText="Azure Speech Subscription Key",_this53.keyHelpUrl=Do;return _this53;}_inherits(Ir,_M10);return _createClass(Ir);}(M);Ir.REGION_ERROR_PREFIX="Please define a region config property. [More Information](".concat(X,"directConnection/Azure#");var zn=Ir;var hs=/*#__PURE__*/function(_zn){// prettier-ignore
|
|
186
|
+
function hs(e){var _a$lang,_c$name,_l$gender;var _this54;_classCallCheck(this,hs);var s,i,o,a,c,l;var t=(i=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:i.textToSpeech,n=(o=e.directConnection)==null?void 0:o.azure;_this54=_callSuper(this,hs,[e,Tl.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,n]),_this54.permittedErrorPrefixes=[hs.REGION_ERROR_MESSAGE],_this54.isTextInputDisabled=!1,_this54.url="",t.region?(Object.assign(_this54.rawBody,t),(_a$lang=(a=_this54.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_c$name=(c=_this54.rawBody).name)!==null&&_c$name!==void 0?_c$name:c.name="en-US-JennyNeural",(_l$gender=(l=_this54.rawBody).gender)!==null&&_l$gender!==void 0?_l$gender:l.gender="Female",_this54.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this54.isTextInputDisabled=!0,_this54.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,hs.REGION_ERROR_MESSAGE));}));return _this54;}_inherits(hs,_zn);return _createClass(hs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return"<speak version='1.0' xml:lang='".concat(e.lang,"'>\n <voice xml:lang='").concat(e.lang,"' xml:gender='").concat(e.gender,"' name='").concat(e.name,"'>\n ").concat(n,"\n </voice>\n </speak>");}},{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee114(e,t){return _regenerator().w(function(_context114){while(1)switch(_context114.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),void 0,!1);case 1:return _context114.a(2);}},_callee114,this);}));function callServiceAPI(_x215,_x216){return _callServiceAPI15.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(e){return _regenerator().w(function(_context115){while(1)switch(_context115.n){case 0:return _context115.a(2,new Promise(function(t){var n=new FileReader();n.readAsDataURL(e),n.onload=function(s){t(_defineProperty({},m,[_defineProperty(_defineProperty({},T,s.target.result),y,G)]));};}));}},_callee115);}));function extractResultData(_x217){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}]);}(zn);hs.REGION_ERROR_MESSAGE="".concat(zn.REGION_ERROR_PREFIX,"TextToSpeech)");var Xi=hs;var Bn=/*#__PURE__*/function(_zn2){function Bn(e){var _this55;_classCallCheck(this,Bn);var i,o,a;var t=(o=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:o.speechToText,n=(a=e.directConnection)==null?void 0:a.azure,s={audio:_defineProperty({},m,{acceptedFormats:".wav,.ogg"})};if(_this55=_callSuper(this,Bn,[e,Rl,t.region,n,s]),_this55.permittedErrorPrefixes=[Bn.REGION_ERROR_MESSAGE],_this55.url="",_this55.isTextInputDisabled=!0,_this55.textInputPlaceholderText=cr,!t.region)_this55.isTextInputDisabled=!0,_this55.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,Bn.REGION_ERROR_MESSAGE));});else{_this55.canSendMessage=Bn.canFileSendMessage;var c=t.lang||"en-US";_this55.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(c,"&format=detailed"),_this55.recordAudio=void 0;}return _this55;}_inherits(Bn,_zn2);return _createClass(Bn,[{key:"callServiceAPI",value:function(){var _callServiceAPI16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee116(e,t,n){var s,i;return _regenerator().w(function(_context116){while(1)switch(_context116.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context116.n=1;break;}throw new Error($e);case 1:if(n!=null&&n[0]){_context116.n=2;break;}throw new Error(mi);case 2:(i=this.connectSettings)!=null&&i.headers&&(this.connectSettings.headers[H]=n[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),be.request(this,n[0],e,!1);case 3:return _context116.a(2);}},_callee116,this);}));function callServiceAPI(_x218,_x219,_x220){return _callServiceAPI16.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee117(e){return _regenerator().w(function(_context117){while(1)switch(_context117.n){case 0:if(!e[p]){_context117.n=1;break;}throw e[p];case 1:return _context117.a(2,_defineProperty({},h,e.DisplayText||""));}},_callee117);}));function extractResultData(_x221){return _extractResultData19.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(zn);Bn.REGION_ERROR_MESSAGE="".concat(zn.REGION_ERROR_PREFIX,"SpeechToText)");var Zi=Bn;var $l=/*#__PURE__*/function(_M11){// prettier-ignore
|
|
187
|
+
function $l(e){var _this56;_classCallCheck(this,$l);var s,i,o;var t=(i=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:i.translation,n=(o=e.directConnection)==null?void 0:o.azure;_this56=_callSuper(this,$l,[e,Nl(t.region),Fo.bind({},t==null?void 0:t.region),n]),_this56.insertKeyPlaceholderText="Azure Translate Subscription Key",_this56.keyHelpUrl=// eslint-disable-next-line max-len
|
|
188
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this56.url="",_this56.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this56;}_inherits($l,_M11);return _createClass($l,[{key:"preprocessBody",value:function preprocessBody(e){var t=e[e.length-1][h];if(t)return[{Text:t}];}},{key:"callServiceAPI",value:function(){var _callServiceAPI17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee118(e,t){return _regenerator().w(function(_context118){while(1)switch(_context118.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context118.a(2);}},_callee118,this);}));function callServiceAPI(_x222,_x223){return _callServiceAPI17.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e){var t;return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:if(!Array.isArray(e)){_context119.n=1;break;}return _context119.a(2,_defineProperty({},h,((t=e[0].translations)==null?void 0:t[0][h])||""));case 1:throw e[p];case 2:return _context119.a(2);}},_callee119);}));function extractResultData(_x224){return _extractResultData20.apply(this,arguments);}return extractResultData;}()}]);}(M);var jl=/*#__PURE__*/function(_M12){function jl(e){var _o$model5;var _this57;_classCallCheck(this,jl);var i,o;var t=w(e.directConnection),n=t.bigModel;_this57=_callSuper(this,jl,[e,pr(),ur,n]),_this57.insertKeyPlaceholderText=_this57.genereteAPIKeyName("BigModel"),_this57.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this57.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this57.permittedErrorPrefixes=[le,we];var s=(i=t.bigModel)==null?void 0:i[Q];_typeof(s)===U&&(_this57.cleanConfig(s),Object.assign(_this57.rawBody,s)),(_o$model5=(o=_this57.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this57;}_inherits(jl,_M12);return _createClass(jl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t[t.length-1];return n.prompt=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee120(e,t){return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:return _context120.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee120,this);}));function callServiceAPI(_x225,_x226){return _callServiceAPI18.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e){var t;return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:t=e.data.map(function(n){return n!=null&&n.url?_defineProperty(_defineProperty({},T,n.url),y,W):_defineProperty(_defineProperty({},T,""),y,W);});return _context121.a(2,_defineProperty({},m,t));}},_callee121);}));function extractResultData(_x227){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(M);var Uo=function Uo(r){return _defineProperty(_defineProperty({},H,Y),le,"".concat(Ae).concat(r));},Gl=function Gl(r,e,t,n){var s=r;s[p]?s[p].message===gi?n(ue):n(He):t(e);},Ho=function Ho(){return pe("https://api.groq.com/openai/v1/models",he,Gl);};var zl=/*#__PURE__*/function(_M13){function zl(e){var _o$model6,_a$voice4,_c$response_format;var _this58;_classCallCheck(this,zl);var i,o,a,c;var t=w(e.directConnection),n=t.groq;_this58=_callSuper(this,zl,[e,Ho(),Uo,n]),_this58.insertKeyPlaceholderText=_this58.genereteAPIKeyName("Groq"),_this58.keyHelpUrl="https://console.groq.com/keys",_this58.url="https://api.groq.com/openai/v1/audio/speech",_this58.permittedErrorPrefixes=[tn,"property"];var s=(i=t.groq)==null?void 0:i.textToSpeech;_typeof(s)===U&&_this58.completeConfig(s),(_o$model6=(o=_this58.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this58.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_c$response_format=(c=_this58.rawBody).response_format)!==null&&_c$response_format!==void 0?_c$response_format:c.response_format="mp3";return _this58;}_inherits(zl,_M13);return _createClass(zl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e,t){return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:return _context122.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee122,this);}));function callServiceAPI(_x228,_x229){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e){var t,n,s;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:t=this.rawBody.response_format||"mp3",n=new Blob([e],_defineProperty({},y,"audio/".concat(t))),s=URL.createObjectURL(n);return _context123.a(2,_defineProperty({},m,[_defineProperty(_defineProperty({},T,s),y,G)]));}},_callee123,this);}));function extractResultData(_x230){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(M);var ql=/*#__PURE__*/function(_M14){function ql(e){var _o$model7;var _this59;_classCallCheck(this,ql);var i,o;var t=w(e.directConnection),n=t.together;_this59=_callSuper(this,ql,[e,mr(),fr,n]),_this59.insertKeyPlaceholderText=_this59.genereteAPIKeyName("Together AI"),_this59.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this59.url="https://api.together.xyz/v1/images/generations",_this59.permittedErrorPrefixes=[et,we];var s=(i=t.together)==null?void 0:i[Q];_typeof(s)===U&&_this59.completeConfig(s),(_o$model7=(o=_this59.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this59;}_inherits(ql,_M14);return _createClass(ql,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t[t.length-1];return n.prompt=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e,t){return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:return _context124.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee124,this);}));function callServiceAPI(_x231,_x232){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(e){var t;return _regenerator().w(function(_context125){while(1)switch(_context125.n){case 0:t=e.data.map(function(n){return n!=null&&n.url?_defineProperty(_defineProperty({},T,n.url),y,W):n!=null&&n.b64_json?_defineProperty(_defineProperty({},T,"data:image/png;base64,".concat(n.b64_json)),y,W):_defineProperty(_defineProperty({},T,""),y,W);});return _context125.a(2,_defineProperty({},m,t));}},_callee125);}));function extractResultData(_x233){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ye=/*#__PURE__*/function(_ni2){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
|
|
189
189
|
// prettier-ignore
|
|
190
|
-
function Ye(e,t,n,s,r){var _this61;_classCallCheck(this,Ye);var a,c;_this61=_callSuper(this,Ye,[e,t,n,s,r]),_this61.keyHelpUrl=zn,_this61.url="".concat(Qe,"responses"),_this61._functionStreamInProgress=!1,_this61._useConversation=!1,_this61._conversationLoadLimit=50;var o=r||((c=(a=e.directConnection)==null?void 0:a.openAI)==null?void 0:c.chat);_this61._urlSegments=Ye.buildUrlSegments(o),_this61.url=_this61._urlSegments.responsesUrl,_typeof(o)===U&&o!==!0&&o&&(o.conversation&&(_this61._useConversation=!0,typeof o.conversation=="string"&&(_this61._conversationId=o.conversation)),typeof o.conversationLoadLimit=="number"&&(_this61._conversationLoadLimit=o.conversationLoadLimit),_this61.cleanConfig(o)),_this61._conversationId&&(_this61.fetchHistory=_this61.fetchHistoryFunc.bind(_this61));return _this61;}_inherits(Ye,_ei2);return _createClass(Ye,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Ye,"processConfig",this,3)([e,t]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.conversation,delete e.conversationLoadLimit,delete e.custom_base_url;}},{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(){var _this62=this;var e,t,_n8,_t48;return _regenerator().w(function(_context124){while(1)switch(_context124.p=_context124.n){case 0:setTimeout(function(){return _this62.deepChat.disableSubmitButton();},2);_context124.p=1;e=this.url,t=this._urlSegments.conversationsUrl;this.url="".concat(t,"/").concat(this._conversationId,"/items?limit=").concat(this._conversationLoadLimit);_context124.n=2;return Zt(this,{},he);case 2:_n8=_context124.v;return _context124.a(2,(this.connectSettings.method=ye,this.url=e,this.deepChat.disableSubmitButton(!1),this.processConversationHistory(_n8)));case 3:_context124.p=3;_t48=_context124.v;return _context124.a(2,(this.deepChat.disableSubmitButton(!1),[_defineProperty({},p,go)]));}},_callee124,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc2.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processConversationHistory",value:function processConversationHistory(e){if(!e.data||!Array.isArray(e.data))return[];var t=[];var _iterator2=_createForOfIteratorHelper(Ye.filterCompleted(e.data.reverse())),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _n9=_step2.value;if(_n9[y]==="message"&&_n9.content&&Array.isArray(_n9.content)){var _iterator3=_createForOfIteratorHelper(_n9.content),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var s=_step3.value;(s[y]===Hi||s[y]===Qr)&&s[h]?t.push(_defineProperty(_defineProperty({},S,_n9[S]),h,s[h])):s[y]===Jr&&t.push(_defineProperty(_defineProperty({},S,_n9[S]),m,Ye.generateImageFile(s[Ve]||"")));}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}else _n9[y]===Ri&&t.push(_defineProperty(_defineProperty({},S,te),m,Ye.generateImageFile(_n9.result)));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e);t=this.processMessages(t),t=this._useConversation?[t[t[W]-1]]:t;var s=t.map(function(r){return _defineProperty({content:Ye.getContent(r)},S,M.getRoleViaUser(r[S]));});return n.input=s,this._conversationId&&(n.conversation=this._conversationId),n;}},{key:"createConversation",value:function(){var _createConversation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(){var e,t,_t49;return _regenerator().w(function(_context125){while(1)switch(_context125.p=_context125.n){case 0:_context125.p=0;e=this.url;this.url=this._urlSegments.conversationsUrl;_context125.n=1;return Zt(this,{},ye);case 1:t=_context125.v;return _context125.a(2,(this.url=e,t.id));case 2:_context125.p=2;_t49=_context125.v;throw console[p]("Failed to create conversation:",_t49),_t49;case 3:return _context125.a(2);}},_callee125,this,[[0,2]]);}));function createConversation(){return _createConversation.apply(this,arguments);}return createConversation;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(e,t){var _this$messages2;var _t50;return _regenerator().w(function(_context126){while(1)switch(_context126.n){case 0:(_this$messages2=this.messages)!==null&&_this$messages2!==void 0?_this$messages2:this.messages=e;_t50=this._useConversation&&!this._conversationId;if(!_t50){_context126.n=2;break;}_context126.n=1;return this.createConversation();case 1:this._conversationId=_context126.v;case 2:this._conversationId&&this.updateSessionId(this._conversationId);this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 3:return _context126.a(2);}},_callee126,this);}));function callServiceAPI(_x235,_x236){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var n;return _regenerator().w(function(_context127){while(1)switch(_context127.n){case 0:_context127.n=1;return this.extractResult(e,t);case 1:n=_context127.v;return _context127.a(2,(this._conversationId&&(n._sessionId=this._conversationId),n));}},_callee127,this);}));function extractResultData(_x237,_x238){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractResult",value:function(){var _extractResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:if(!e[p]){_context128.n=1;break;}throw e[p].message;case 1:if(!e.status){_context128.n=5;break;}a=Ye.filterCompleted(e.output);if(!(a[W]>0)){_context128.n=4;break;}c=(r=(s=(n=a.find(function(u){var g,b;return _typeof((b=(g=u.content)==null?void 0:g[0])==null?void 0:b[h])===_e;}))==null?void 0:n.content)==null?void 0:s[0])==null?void 0:r[h];_context128.n=2;return this.handleResponsesFunctionCalls(a,t,c);case 2:l=_context128.v;if(!l){_context128.n=3;break;}return _context128.a(2,l);case 3:d=this.handleFileGenerationResponse(a,c);return _context128.a(2,d||_defineProperty({},h,c));case 4:return _context128.a(2,_defineProperty({},h,""));case 5:return _context128.a(2,((o=e.item)==null?void 0:o[y])===Bs&&e[y]?this.handleStreamedResponsesFunctionCall(e,t):e[y]==="".concat(Yn,".").concat(Ri,".partial_image")&&e.partial_image_b64?_defineProperty({},m,[_defineProperty(_defineProperty({},T,"".concat(Ye.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),y,K)]):e.delta&&!this._functionStreamInProgress&&e[y]==="".concat(Yn,".").concat(Qr,".delta")?_defineProperty({},h,e.delta):_defineProperty({},h,""));}},_callee128,this);}));function extractResult(_x239,_x240){return _extractResult.apply(this,arguments);}return extractResult;}()},{key:"handleStreamedResponsesFunctionCall",value:function(){var _handleStreamedResponsesFunctionCall=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e,t){var n;return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:if(!(e[y]==="".concat(Yn,".output_item.done"))){_context129.n=2;break;}if(!(this._functionStreamInProgress=!1,((n=e.item)==null?void 0:n[y])===Bs)){_context129.n=1;break;}return _context129.a(2,this.handleResponsesFunctionCalls([e.item],t));case 1:_context129.n=3;break;case 2:e[y]==="".concat(Yn,".output_item.added")&&(this._functionStreamInProgress=!0);case 3:return _context129.a(2,_defineProperty({},h,""));}},_callee129,this);}));function handleStreamedResponsesFunctionCall(_x241,_x242){return _handleStreamedResponsesFunctionCall.apply(this,arguments);}return handleStreamedResponsesFunctionCall;}()},{key:"handleFileGenerationResponse",value:function handleFileGenerationResponse(e,t){var n=e.find(function(s){return s[y]===Ri;});return n?_defineProperty(_defineProperty({},m,Ye.generateImageFile(n.result)),h,t):null;}},{key:"handleResponsesFunctionCalls",value:function(){var _handleResponsesFunctionCalls=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(e,t,n){var s,r,_yield$this$callToolF2,o,a,c;return _regenerator().w(function(_context130){while(1)switch(_context130.n){case 0:s=e.filter(function(l){return l[y]===Bs;});if(!(s[W]===0)){_context130.n=1;break;}return _context130.a(2,null);case 1:if(!(!t||!this.functionHandler)){_context130.n=2;break;}throw Error(Qt);case 2:r=s.map(function(l){return{name:l.name,arguments:l.arguments};});_context130.n=3;return this.callToolFunction(this.functionHandler,r);case 3:_yield$this$callToolF2=_context130.v;o=_yield$this$callToolF2.responses;a=_yield$this$callToolF2.processedResponse;if(!a){_context130.n=4;break;}return _context130.a(2,a);case 4:c=w(t);if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref137){var l=_ref137.response;return _typeof(l)!==_e;})&&r[W]===o[W]))){_context130.n=5;break;}return _context130.a(2,(o.forEach(function(l,d){var u=s[d];c.input.push(_defineProperty(_defineProperty(_defineProperty({},y,Io),"call_id",u.call_id),"output",l[Yn]));}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(gn);case 6:return _context130.a(2);}},_callee130,this);}));function handleResponsesFunctionCalls(_x243,_x244,_x245){return _handleResponsesFunctionCalls.apply(this,arguments);}return handleResponsesFunctionCalls;}()}],[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&(e==null?void 0:e.custom_base_url)||Qe;return{responsesUrl:"".concat(t,"responses"),conversationsUrl:"".concat(t,"conversations")};}},{key:"getFileContent",value:function getFileContent(e){return ei.getBaseFileContent(e).map(function(n){return n[y]===pn?n:_defineProperty(_defineProperty({detail:"auto"},y,Jr),Ve,n[T]);});}},{key:"getContent",value:function getContent(e){if(e[S]===F&&e[m]&&e[m][W]>0){var _n0=Ye.getFileContent(e[m]);return e[h]&&e[h].trim()[W]>0&&_n0.unshift(_defineProperty(_defineProperty({},y,Hi),h,e[h])),_n0;}return e[h];}},{key:"filterCompleted",value:function filterCompleted(e){return(e==null?void 0:e.filter(function(t){return t.status===rr;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},T,"".concat(Ye.IMAGE_BASE64_PREFIX).concat(e)),y,K)];}}]);}(ei);Ye.IMAGE_BASE64_PREFIX="data:image/png;base64,";var ni=Ye;var gr=/*#__PURE__*/function(_ni){function gr(e){var _this63;_classCallCheck(this,gr);var o,a,c,l,d,u,g;var t=w(e.directConnection),n=t.azure,s=((a=(o=t.azure)==null?void 0:o.openAI)==null?void 0:a.urlDetails)||{},r=(l=(c=t.azure)==null?void 0:c.openAI)==null?void 0:l.chat;if(_this63=_callSuper(this,gr,[e,Lo(s),ko,n,r]),_this63.permittedErrorPrefixes=[Js],_this63.isTextInputDisabled=!1,_typeof(r)===U){var _ref140=(g=(u=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:u.openAI)==null?void 0:g.chat,b=_ref140.function_handler;b&&(_this63.functionHandler=b);}Po(s)?_this63.url=gr.buildURL(s):(_this63.isTextInputDisabled=!0,_this63.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,Js));}));return _this63;}_inherits(gr,_ni);return _createClass(gr,null,[{key:"buildURL",value:function buildURL(e){var t=e.endpoint,n=e.deploymentId,s=e.version;return"".concat(t,"/openai/deployments/").concat(n,"/chat/completions?api-version=").concat(s);}}]);}(ni);var si=/*#__PURE__*/function(_M15){function si(e){var _this64$maxMessages,_l$model2;var _this64;_classCallCheck(this,si);var r,o,a,c,l;var t=w(e.directConnection),n=t.bigModel;_this64=_callSuper(this,si,[e,dr(),hr,n]),_this64.insertKeyPlaceholderText=_this64.genereteAPIKeyName("BigModel"),_this64.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this64.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this64.permittedErrorPrefixes=[le,we];var s=(r=t.bigModel)==null?void 0:r.chat;_typeof(s)===U&&_this64.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.bigModel)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this64$maxMessages=_this64.maxMessages)!==null&&_this64$maxMessages!==void 0?_this64$maxMessages:_this64.maxMessages=-1,(_l$model2=(l=_this64.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="glm-4.5";return _this64;}_inherits(si,_M15);return _createClass(si,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:si.getTextWFilesContent(r,si.getFileContent)},S,M.getRoleViaAI(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(e,t){var _this$messages3;return _regenerator().w(function(_context131){while(1)switch(_context131.n){case 0:(_this$messages3=this.messages)!==null&&_this$messages3!==void 0?_this$messages3:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context131.a(2);}},_callee131,this);}));function callServiceAPI(_x246,_x247){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee132(e,t){var _n1;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:if(!e[p]){_context132.n=1;break;}throw e[p].message;case 1:if(!(e.choices.length>0)){_context132.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context132.n=2;break;}return _context132.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context132.n=3;break;}_n1=e.choices[0].message;return _context132.a(2,_n1.tool_calls?this.handleToolsGeneric({tool_calls:_n1.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n1.content));case 3:return _context132.a(2,_defineProperty({},h,""));}},_callee132,this);}));function extractResultData(_x248,_x249){return _extractResultData25.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var o,a,c,l,n,s,r,d;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:n=e.delta,s=e.finish_reason,r=(o=this.messages)==null?void 0:o.messageToElements[this.messages.messageToElements.length-2];if(!((r==null?void 0:r[0][S])===te&&((a=r==null?void 0:r[0][h])==null?void 0:a.replace(/\n/g,"").trim().length)===0&&((c=this.messages)==null||c.removeMessage(r[1][h]),(l=this.messages)==null||l.messageToElements.splice(this.messages.messageToElements.length-2,1)),s==="tool_calls")){_context133.n=2;break;}if(!n.tool_calls){_context133.n=1;break;}d={tool_calls:n.tool_calls};return _context133.a(2,this.handleToolsGeneric(d,this.functionHandler,this.messages,t));case 1:return _context133.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));case 2:return _context133.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee133,this);}));function extractStreamResult(_x250,_x251){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t[y]===K?_defineProperty(_defineProperty({},y,Ve),Ve,{url:t[T]||""}):_defineProperty(_defineProperty({},y,ne),"file_url",{url:t[T]||""});});}}]);}(M);var Gl=/*#__PURE__*/function(_M16){function Gl(e){var _this65$maxMessages,_o$model8;var _this65;_classCallCheck(this,Gl);var r,o;var t=w(e.directConnection),n=t.together;_this65=_callSuper(this,Gl,[e,pr(),ur,n]),_this65.insertKeyPlaceholderText=_this65.genereteAPIKeyName("Together AI"),_this65.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this65.url="https://api.together.xyz/v1/chat/completions",_this65.permittedErrorPrefixes=[et,we];var s=(r=t.together)==null?void 0:r.chat;_typeof(s)===U&&_this65.completeConfig(s),(_this65$maxMessages=_this65.maxMessages)!==null&&_this65$maxMessages!==void 0?_this65$maxMessages:_this65.maxMessages=-1,(_o$model8=(o=_this65.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this65;}_inherits(Gl,_M16);return _createClass(Gl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,r[S]===te?St:r[S]);});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t){return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context134.a(2);}},_callee134,this);}));function callServiceAPI(_x252,_x253){return _callServiceAPI23.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e){return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:if(!e[p]){_context135.n=1;break;}throw e[p].message;case 1:if(!(e.choices.length>0)){_context135.n=3;break;}if(!(e.choices[0].message!==void 0)){_context135.n=2;break;}return _context135.a(2,_defineProperty({},h,e.choices[0].message.content));case 2:if(!(e.choices[0].delta!==void 0)){_context135.n=3;break;}return _context135.a(2,_defineProperty({},h,e.choices[0].delta.content));case 3:return _context135.a(2,_defineProperty({},h,""));}},_callee135);}));function extractResultData(_x254){return _extractResultData26.apply(this,arguments);}return extractResultData;}()}]);}(M);var dt=/*#__PURE__*/function(_M17){function dt(e){var _this66;_classCallCheck(this,dt);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},m,{acceptedFormats:".png",maxNumberOfFiles:2})};_this66=_callSuper(this,dt,[e,Wn(),Kn,n,s]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("OpenAI"),_this66.keyHelpUrl=zn,_this66.url="",_this66.permittedErrorPrefixes=[ws,"Invalid input image"];var r=(o=t==null?void 0:t.openAI)==null?void 0:o[ee];if(_this66[Fe]){var a=_typeof(r)=="object"&&r.size?Number.parseInt(r.size):1024;_this66[Fe][m]={dimensions:{width:a,height:a}};}_typeof(r)===U&&Object.assign(_this66.rawBody,r),_this66.canSendMessage=dt.canFileSendMessage;return _this66;}_inherits(dt,_M17);return _createClass(dt,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e);return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
|
|
191
|
-
},{key:"callApiWithImage",value:function callApiWithImage(e,t,n){var o,a;var s;var
|
|
190
|
+
function Ye(e,t,n,s,i){var _this60;_classCallCheck(this,Ye);var a,c;_this60=_callSuper(this,Ye,[e,t,n,s,i]),_this60.keyHelpUrl=Kn,_this60.url="".concat(Qe,"responses"),_this60._functionStreamInProgress=!1,_this60._streamedResponseFunctionCalls=[],_this60._useConversation=!1,_this60._conversationLoadLimit=50;var o=i||((c=(a=e.directConnection)==null?void 0:a.openAI)==null?void 0:c.chat);_this60._urlSegments=Ye.buildUrlSegments(o),_this60.url=_this60._urlSegments.responsesUrl,_typeof(o)===U&&o!==!0&&o&&(o.conversation&&(_this60._useConversation=!0,typeof o.conversation=="string"&&(_this60._conversationId=o.conversation)),typeof o.conversationLoadLimit=="number"&&(_this60._conversationLoadLimit=o.conversationLoadLimit),_this60.cleanConfig(o)),_this60._conversationId&&(_this60.fetchHistory=_this60.fetchHistoryFunc.bind(_this60));return _this60;}_inherits(Ye,_ni2);return _createClass(Ye,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Ye,"processConfig",this,3)([e,t]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.conversation,delete e.conversationLoadLimit,delete e.custom_base_url;}},{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(){var _this61=this;var e,t,_n8,_t60;return _regenerator().w(function(_context126){while(1)switch(_context126.p=_context126.n){case 0:setTimeout(function(){return _this61.deepChat.disableSubmitButton();},2);_context126.p=1;e=this.url,t=this._urlSegments.conversationsUrl;this.url="".concat(t,"/").concat(this._conversationId,"/items?limit=").concat(this._conversationLoadLimit);_context126.n=2;return Yt(this,{},he);case 2:_n8=_context126.v;return _context126.a(2,(this.connectSettings.method=ye,this.url=e,this.deepChat.disableSubmitButton(!1),this.processConversationHistory(_n8)));case 3:_context126.p=3;_t60=_context126.v;return _context126.a(2,(this.deepChat.disableSubmitButton(!1),[_defineProperty({},p,bo)]));}},_callee126,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc2.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processConversationHistory",value:function processConversationHistory(e){if(!e.data||!Array.isArray(e.data))return[];var t=[];var _iterator5=_createForOfIteratorHelper(Ye.filterCompleted(e.data.reverse())),_step5;try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var _n9=_step5.value;if(_n9[y]==="message"&&_n9.content&&Array.isArray(_n9.content)){var _iterator6=_createForOfIteratorHelper(_n9.content),_step6;try{for(_iterator6.s();!(_step6=_iterator6.n()).done;){var s=_step6.value;(s[y]===ji||s[y]===eo)&&s[h]?t.push(_defineProperty(_defineProperty({},S,_n9[S]),h,s[h])):s[y]===Qr&&t.push(_defineProperty(_defineProperty({},S,_n9[S]),m,Ye.generateImageFile(s[qe]||"")));}}catch(err){_iterator6.e(err);}finally{_iterator6.f();}}else _n9[y]===Mi&&t.push(_defineProperty(_defineProperty({},S,te),m,Ye.generateImageFile(_n9.result)));}}catch(err){_iterator5.e(err);}finally{_iterator5.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e);t=this.processMessages(t),t=this._useConversation?[t[t[K]-1]]:t;var s=t.map(function(i){return _defineProperty({content:Ye.getContent(i)},S,M.getRoleViaUser(i[S]));});return n.input=s,this._conversationId&&(n.conversation=this._conversationId),n;}},{key:"createConversation",value:function(){var _createConversation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(){var e,t,_t61;return _regenerator().w(function(_context127){while(1)switch(_context127.p=_context127.n){case 0:_context127.p=0;e=this.url;this.url=this._urlSegments.conversationsUrl;_context127.n=1;return Yt(this,{},ye);case 1:t=_context127.v;return _context127.a(2,(this.url=e,t.id));case 2:_context127.p=2;_t61=_context127.v;throw console[p]("Failed to create conversation:",_t61),_t61;case 3:return _context127.a(2);}},_callee127,this,[[0,2]]);}));function createConversation(){return _createConversation.apply(this,arguments);}return createConversation;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e,t){var _this$messages2;var _t62;return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:this._streamedResponseFunctionCalls=[];(_this$messages2=this.messages)!==null&&_this$messages2!==void 0?_this$messages2:this.messages=e;_t62=this._useConversation&&!this._conversationId;if(!_t62){_context128.n=2;break;}_context128.n=1;return this.createConversation();case 1:this._conversationId=_context128.v;case 2:this._conversationId&&this.updateSessionId(this._conversationId);this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 3:return _context128.a(2);}},_callee128,this);}));function callServiceAPI(_x234,_x235){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e,t){var n;return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:_context129.n=1;return this.extractResult(e,t);case 1:n=_context129.v;return _context129.a(2,(this._conversationId&&(n._sessionId=this._conversationId),n));}},_callee129,this);}));function extractResultData(_x236,_x237){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractResult",value:function(){var _extractResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(e,t){var n,s,i,o,a,c,l,d,_a5;return _regenerator().w(function(_context130){while(1)switch(_context130.n){case 0:if(!e[p]){_context130.n=1;break;}throw e[p].message;case 1:if(!e.status){_context130.n=5;break;}a=Ye.filterCompleted(e.output);if(!(a[K]>0)){_context130.n=4;break;}c=(i=(s=(n=a.find(function(u){var g,b;return _typeof((b=(g=u.content)==null?void 0:g[0])==null?void 0:b[h])===_e;}))==null?void 0:n.content)==null?void 0:s[0])==null?void 0:i[h];_context130.n=2;return this.handleResponsesFunctionCalls(a,t,c);case 2:l=_context130.v;if(!l){_context130.n=3;break;}return _context130.a(2,l);case 3:d=this.handleFileGenerationResponse(a,c);return _context130.a(2,d||_defineProperty({},h,c));case 4:return _context130.a(2,_defineProperty({},h,""));case 5:if(!(e[y]==="".concat(In,".completed")&&this._streamedResponseFunctionCalls[K]>0)){_context130.n=6;break;}_a5=this._streamedResponseFunctionCalls;return _context130.a(2,(this._streamedResponseFunctionCalls=[],this.handleResponsesFunctionCalls(_a5,t)));case 6:return _context130.a(2,((o=e.item)==null?void 0:o[y])===Ds&&e[y]?this.handleStreamedResponsesFunctionCall(e):e[y]==="".concat(In,".").concat(Mi,".partial_image")&&e.partial_image_b64?_defineProperty({},m,[_defineProperty(_defineProperty({},T,"".concat(Ye.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),y,W)]):e.delta&&!this._functionStreamInProgress&&e[y]==="".concat(In,".").concat(eo,".delta")?_defineProperty({},h,e.delta):_defineProperty({},h,""));}},_callee130,this);}));function extractResult(_x238,_x239){return _extractResult.apply(this,arguments);}return extractResult;}()},{key:"handleStreamedResponsesFunctionCall",value:function(){var _handleStreamedResponsesFunctionCall=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(e){var t;return _regenerator().w(function(_context131){while(1)switch(_context131.n){case 0:return _context131.a(2,(e[y]==="".concat(In,".output_item.done")?(this._functionStreamInProgress=!1,((t=e.item)==null?void 0:t[y])===Ds&&this._streamedResponseFunctionCalls.push(e.item)):e[y]==="".concat(In,".output_item.added")&&(this._functionStreamInProgress=!0),_defineProperty({},h,"")));}},_callee131,this);}));function handleStreamedResponsesFunctionCall(_x240){return _handleStreamedResponsesFunctionCall.apply(this,arguments);}return handleStreamedResponsesFunctionCall;}()},{key:"handleFileGenerationResponse",value:function handleFileGenerationResponse(e,t){var n=e.find(function(s){return s[y]===Mi;});return n?_defineProperty(_defineProperty({},m,Ye.generateImageFile(n.result)),h,t):null;}},{key:"handleResponsesFunctionCalls",value:function(){var _handleResponsesFunctionCalls=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee132(e,t,n){var s,i,_yield$this$callToolF2,o,a,c;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:s=e.filter(function(l){return l[y]===Ds;});if(!(s[K]===0)){_context132.n=1;break;}return _context132.a(2,null);case 1:if(!(!t||!this.functionHandler)){_context132.n=2;break;}throw Error(en);case 2:i=s.map(function(l){return{name:l.name,arguments:l.arguments};});_context132.n=3;return this.callToolFunction(this.functionHandler,i);case 3:_yield$this$callToolF2=_context132.v;o=_yield$this$callToolF2.responses;a=_yield$this$callToolF2.processedResponse;if(!a){_context132.n=4;break;}return _context132.a(2,a);case 4:c=w(t);if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref137){var l=_ref137.response;return _typeof(l)!==_e;})&&i[K]===o[K]))){_context132.n=5;break;}return _context132.a(2,(o.forEach(function(l,d){var u=s[d];c.input.push(_defineProperty(_defineProperty(_defineProperty({},y,Mo),"call_id",u.call_id),"output",l[In]));}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(bn);case 6:return _context132.a(2);}},_callee132,this);}));function handleResponsesFunctionCalls(_x241,_x242,_x243){return _handleResponsesFunctionCalls.apply(this,arguments);}return handleResponsesFunctionCalls;}()}],[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&(e==null?void 0:e.custom_base_url)||Qe;return{responsesUrl:"".concat(t,"responses"),conversationsUrl:"".concat(t,"conversations")};}},{key:"getFileContent",value:function getFileContent(e){return ni.getBaseFileContent(e).map(function(n){return n[y]===fn?n:_defineProperty(_defineProperty({detail:"auto"},y,Qr),qe,n[T]);});}},{key:"getContent",value:function getContent(e){if(e[S]===F&&e[m]&&e[m][K]>0){var _n0=Ye.getFileContent(e[m]);return e[h]&&e[h].trim()[K]>0&&_n0.unshift(_defineProperty(_defineProperty({},y,ji),h,e[h])),_n0;}return e[h];}},{key:"filterCompleted",value:function filterCompleted(e){return(e==null?void 0:e.filter(function(t){return t.status===ar;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},T,"".concat(Ye.IMAGE_BASE64_PREFIX).concat(e)),y,W)];}}]);}(ni);Ye.IMAGE_BASE64_PREFIX="data:image/png;base64,";var ii=Ye;var yr=/*#__PURE__*/function(_ii){function yr(e){var _this62;_classCallCheck(this,yr);var o,a,c,l,d,u,g;var t=w(e.directConnection),n=t.azure,s=((a=(o=t.azure)==null?void 0:o.openAI)==null?void 0:a.urlDetails)||{},i=(l=(c=t.azure)==null?void 0:c.openAI)==null?void 0:l.chat;if(_this62=_callSuper(this,yr,[e,Po(s),Lo,n,i]),_this62.permittedErrorPrefixes=[ei],_this62.isTextInputDisabled=!1,_typeof(i)===U){var _ref140=(g=(u=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:u.openAI)==null?void 0:g.chat,b=_ref140.function_handler;b&&(_this62.functionHandler=b);}Oo(s)?_this62.url=yr.buildURL(s):(_this62.isTextInputDisabled=!0,_this62.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,ei));}));return _this62;}_inherits(yr,_ii);return _createClass(yr,null,[{key:"buildURL",value:function buildURL(e){var t=e.endpoint,n=e.deploymentId,s=e.version;return"".concat(t,"/openai/deployments/").concat(n,"/chat/completions?api-version=").concat(s);}}]);}(ii);var ri=/*#__PURE__*/function(_M15){function ri(e){var _this63$maxMessages,_l$model2;var _this63;_classCallCheck(this,ri);var i,o,a,c,l;var t=w(e.directConnection),n=t.bigModel;_this63=_callSuper(this,ri,[e,pr(),ur,n]),_this63.insertKeyPlaceholderText=_this63.genereteAPIKeyName("BigModel"),_this63.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this63.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this63.permittedErrorPrefixes=[le,we];var s=(i=t.bigModel)==null?void 0:i.chat;_typeof(s)===U&&_this63.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.bigModel)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this63$maxMessages=_this63.maxMessages)!==null&&_this63$maxMessages!==void 0?_this63$maxMessages:_this63.maxMessages=-1,(_l$model2=(l=_this63.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="glm-4.5";return _this63;}_inherits(ri,_M15);return _createClass(ri,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:ri.getTextWFilesContent(i,ri.getFileContent)},S,M.getRoleViaAI(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var _this$messages3;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:(_this$messages3=this.messages)!==null&&_this$messages3!==void 0?_this$messages3:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context133.a(2);}},_callee133,this);}));function callServiceAPI(_x244,_x245){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t){var _n1;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:if(!e[p]){_context134.n=1;break;}throw e[p].message;case 1:if(!(e.choices.length>0)){_context134.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context134.n=2;break;}return _context134.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context134.n=3;break;}_n1=e.choices[0].message;return _context134.a(2,_n1.tool_calls?this.handleToolsGeneric({tool_calls:_n1.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n1.content));case 3:return _context134.a(2,_defineProperty({},h,""));}},_callee134,this);}));function extractResultData(_x246,_x247){return _extractResultData25.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e,t){var o,a,c,l,n,s,i,d;return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:n=e.delta,s=e.finish_reason,i=(o=this.messages)==null?void 0:o.messageToElements[this.messages.messageToElements.length-2];if(!((i==null?void 0:i[0][S])===te&&((a=i==null?void 0:i[0][h])==null?void 0:a.replace(/\n/g,"").trim().length)===0&&((c=this.messages)==null||c.removeMessage(i[1][h]),(l=this.messages)==null||l.messageToElements.splice(this.messages.messageToElements.length-2,1)),s==="tool_calls")){_context135.n=2;break;}if(!n.tool_calls){_context135.n=1;break;}d={tool_calls:n.tool_calls};return _context135.a(2,this.handleToolsGeneric(d,this.functionHandler,this.messages,t));case 1:return _context135.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));case 2:return _context135.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee135,this);}));function extractStreamResult(_x248,_x249){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t[y]===W?_defineProperty(_defineProperty({},y,qe),qe,{url:t[T]||""}):_defineProperty(_defineProperty({},y,ne),"file_url",{url:t[T]||""});});}}]);}(M);var Vl=/*#__PURE__*/function(_M16){function Vl(e){var _this64$maxMessages,_o$model8;var _this64;_classCallCheck(this,Vl);var i,o;var t=w(e.directConnection),n=t.together;_this64=_callSuper(this,Vl,[e,mr(),fr,n]),_this64.insertKeyPlaceholderText=_this64.genereteAPIKeyName("Together AI"),_this64.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this64.url="https://api.together.xyz/v1/chat/completions",_this64.permittedErrorPrefixes=[et,we];var s=(i=t.together)==null?void 0:i.chat;_typeof(s)===U&&_this64.completeConfig(s),(_this64$maxMessages=_this64.maxMessages)!==null&&_this64$maxMessages!==void 0?_this64$maxMessages:_this64.maxMessages=-1,(_o$model8=(o=_this64.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this64;}_inherits(Vl,_M16);return _createClass(Vl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:i[h]||""},S,i[S]===te?xt:i[S]);});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e,t){return _regenerator().w(function(_context136){while(1)switch(_context136.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context136.a(2);}},_callee136,this);}));function callServiceAPI(_x250,_x251){return _callServiceAPI23.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e){return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:if(!e[p]){_context137.n=1;break;}throw e[p].message;case 1:if(!(e.choices.length>0)){_context137.n=3;break;}if(!(e.choices[0].message!==void 0)){_context137.n=2;break;}return _context137.a(2,_defineProperty({},h,e.choices[0].message.content));case 2:if(!(e.choices[0].delta!==void 0)){_context137.n=3;break;}return _context137.a(2,_defineProperty({},h,e.choices[0].delta.content));case 3:return _context137.a(2,_defineProperty({},h,""));}},_callee137);}));function extractResultData(_x252){return _extractResultData26.apply(this,arguments);}return extractResultData;}()}]);}(M);var ut=/*#__PURE__*/function(_M17){function ut(e){var _this65;_classCallCheck(this,ut);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},m,{acceptedFormats:".png",maxNumberOfFiles:2})};_this65=_callSuper(this,ut,[e,Xn(),Wn,n,s]),_this65.insertKeyPlaceholderText=_this65.genereteAPIKeyName("OpenAI"),_this65.keyHelpUrl=Kn,_this65.url="",_this65.permittedErrorPrefixes=[Ts,"Invalid input image"];var i=(o=t==null?void 0:t.openAI)==null?void 0:o[Q];if(_this65[Fe]){var a=_typeof(i)=="object"&&i.size?Number.parseInt(i.size):1024;_this65[Fe][m]={dimensions:{width:a,height:a}};}_typeof(i)===U&&Object.assign(_this65.rawBody,i),_this65.canSendMessage=ut.canFileSendMessage;return _this65;}_inherits(ut,_M17);return _createClass(ut,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e);return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
|
|
191
|
+
},{key:"callApiWithImage",value:function callApiWithImage(e,t,n){var o,a;var s;var i=(a=(o=t[t[K]-1])==null?void 0:o[h])==null?void 0:a.trim();if(n[1]||i&&i!==""){this.url=ut.IMAGE_EDIT_URL;var c=this.preprocessBody(this.rawBody,i);s=ut.createFormDataBody(c,n[0],n[1]);}else this.url=ut.IMAGE_VARIATIONS_URL,s=ut.createFormDataBody(this.rawBody,n[0]);D.tempRemoveContentHeader(this.connectSettings,be.request.bind(this,this,s,e),!1);}},{key:"callServiceAPI",value:function(){var _callServiceAPI24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(e,t,n){var s,i;return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context138.n=1;break;}throw new Error($e);case 1:if(!(n!=null&&n[0])){_context138.n=2;break;}this.callApiWithImage(e,t,n);_context138.n=4;break;case 2:if(this.connectSettings){_context138.n=3;break;}throw new Error($e);case 3:this.url=ut.IMAGE_GENERATION_URL;i=this.preprocessBody(this.rawBody,t[t[K]-1][h]);be.request(this,i,e);case 4:return _context138.a(2);}},_callee138,this);}));function callServiceAPI(_x253,_x254,_x255){return _callServiceAPI24.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(e){var t;return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:if(!e[p]){_context139.n=1;break;}throw e[p].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},T,n.url),y,W):_defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.b64_json)),y,W);});return _context139.a(2,_defineProperty({},m,t));}},_callee139);}));function extractResultData(_x256){return _extractResultData27.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
|
|
192
192
|
// 1 image:
|
|
193
193
|
// - With text - edits image based on the text
|
|
194
194
|
// - No text - creates a variation of the image
|
|
@@ -197,34 +197,34 @@ function Ye(e,t,n,s,r){var _this61;_classCallCheck(this,Ye);var a,c;_this61=_cal
|
|
|
197
197
|
// Add text to describe the required modification.
|
|
198
198
|
// Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
|
|
199
199
|
// `;
|
|
200
|
-
}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,n){var s=new FormData();return s.append(K,t),n&&s.append("mask",n),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s;}}]);}(M);dt.IMAGE_GENERATION_URL="".concat(Qe,"images/generations"),dt.IMAGE_VARIATIONS_URL="".concat(Qe,"images/variations"),dt.IMAGE_EDIT_URL="".concat(Qe,"images/edits");var Xi=dt;var Vl=function Vl(i){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J);},zl=function zl(i,e,t,n){var s=i;s[p]?s[p][y]===we?n(ue):n(He):t(e);},Kl=function Kl(){return pe("https://openrouter.ai/api/v1/key",he,zl);};var ss=/*#__PURE__*/function(_M18){function ss(e){var _this67$maxMessages,_o$model9,_a$max_tokens;var _this67;_classCallCheck(this,ss);var s,r,o,a;var n=w(e.directConnection).openRouter;_this67=_callSuper(this,ss,[e,Kl(),Vl,n]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenRouter"),_this67.keyHelpUrl="https://openrouter.ai/keys",_this67.url="https://openrouter.ai/api/v1/chat/completions",_this67.permittedErrorPrefixes=[et,we],_typeof(n)===U&&_this67.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.openRouter)==null?void 0:r.function_handler),(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1,(_o$model9=(o=_this67.rawBody).model)!==null&&_o$model9!==void 0?_o$model9:o.model="openai/gpt-4o",(_a$max_tokens=(a=_this67.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=1e3;return _this67;}_inherits(ss,_M18);return _createClass(ss,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(o){return _defineProperty({content:ss.getContent(o)},S,M.getRoleViaUser(o[S]));}),r=[];return this.systemMessage&&r.push(_defineProperty(_defineProperty({},S,jn),"content",this.systemMessage)),r.push.apply(r,_toConsumableArray(s)),n.messages=r,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(e,t){var _this$messages4;return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:(_this$messages4=this.messages)!==null&&_this$messages4!==void 0?_this$messages4:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context138.a(2);}},_callee138,this);}));function callServiceAPI(_x259,_x260){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(e,t){var n,s,r,o,a,c,_a5,_c5;return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:if(!e[p]){_context139.n=1;break;}throw e[p].message;case 1:if(!(e.object==="chat.completion.chunk")){_context139.n=4;break;}a=(n=e.choices)==null?void 0:n[0];if(!(a!=null&&a.delta)){_context139.n=2;break;}return _context139.a(2,this.extractStreamResult(a,t));case 2:if(!((s=e.message)!=null&&s[ee])){_context139.n=3;break;}c=e.message[ee].map(function(l){return _defineProperty({},T,l[Ve].url);});return _context139.a(2,_defineProperty(_defineProperty({},h,e.message.content||""),m,c));case 3:return _context139.a(2,_defineProperty({},h,""));case 4:if(!(e.object==="chat.completion")){_context139.n=6;break;}_a5=(r=e.choices)==null?void 0:r[0];if(!(_a5!=null&&_a5.message)){_context139.n=6;break;}if(!_a5.message.tool_calls){_context139.n=5;break;}return _context139.a(2,this.handleToolsGeneric({tool_calls:_a5.message.tool_calls},this.functionHandler,this.messages,t));case 5:_c5=((o=_a5.message[ee])==null?void 0:o.map(function(l){return _defineProperty({},T,l[Ve].url);}))||[];return _context139.a(2,_defineProperty(_defineProperty({},h,_a5.message.content||""),"files",_c5));case 6:return _context139.a(2,_defineProperty({},h,""));}},_callee139,this);}));function extractResultData(_x261,_x262){return _extractResultData28.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e,t){var n,s;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:n=e.delta;if(!(n!=null&&n[ee])){_context140.n=1;break;}s=n[ee].map(function(r){return _defineProperty({},T,r[Ve].url);});return _context140.a(2,_defineProperty(_defineProperty({},h,n.content||""),m,s));case 1:return _context140.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee140,this);}));function extractStreamResult(_x263,_x264){return _extractStreamResult3.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getAudioContent",value:function getAudioContent(e){return e.filter(function(t){return t[y]===q;}).map(function(t){var r,o,a;var n=(r=t[T])==null?void 0:r.split(",")[1],s=(a=(o=t[T])==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return _defineProperty(_defineProperty({},y,pn),pn,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[pn].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[m]&&e[m].length>0){var t=[].concat(_toConsumableArray(ss.getImageContent(e[m])),_toConsumableArray(ss.getAudioContent(e[m])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(M);var Wl=function Wl(i){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J);},Xl=function Xl(i,e,t,n){i[p]?n(ue):t(e);},Zl=function Zl(){return pe("https://api.perplexity.ai/chat/completions",ye,Xl);};var Yl=/*#__PURE__*/function(_M19){function Yl(e){var _this68$maxMessages,_s$model;var _this68;_classCallCheck(this,Yl);var s;var n=w(e.directConnection).perplexity;_this68=_callSuper(this,Yl,[e,Zl(),Wl,n]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("Perplexity"),_this68.keyHelpUrl="https://www.perplexity.ai/settings/api",_this68.url="https://api.perplexity.ai/chat/completions",_this68.permittedErrorPrefixes=[en,bo,"Permission denied"],_typeof(n)===U&&_this68.completeConfig(n),(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_s$model=(s=_this68.rawBody).model)!==null&&_s$model!==void 0?_s$model:s.model="sonar";return _this68;}_inherits(Yl,_M19);return _createClass(Yl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context141.a(2);}},_callee141,this);}));function callServiceAPI(_x265,_x266){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e){var t;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:if(!e[p]){_context142.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context142.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context142.n=2;break;}return _context142.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context142.n=3;break;}return _context142.a(2,_defineProperty({},h,t.message.content));case 3:return _context142.a(2,_defineProperty({},h,""));}},_callee142);}));function extractResultData(_x267){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(M);var Jl=function Jl(i){return _defineProperty(_defineProperty({},le,"Bearer ".concat(i)),H,J);},Ql=function Ql(i,e,t,n){var s=i;s.detail?n(s.detail):t(e);},eh=function eh(){return pe("http://localhost:3000/api/v1/models",he,Ql);};var th=/*#__PURE__*/function(_M20){function th(e){var _this69$maxMessages,_o$model0,_a$stream;var _this69;_classCallCheck(this,th);var s,r,o,a;var n=w(e.directConnection).openWebUI;_this69=_callSuper(this,th,[e,eh(),Jl,n]),_this69.insertKeyPlaceholderText="Open WebUI API Key",_this69.keyHelpUrl="https://docs.openwebui.com/getting-started/api-endpoints/",_this69.url="http://localhost:3000/api/chat/completions",_this69.permittedErrorPrefixes=["Error"],_typeof(n)===U&&(_this69.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.openWebUI)==null?void 0:r.function_handler),n[m]&&n[m].length>0&&(_this69.rawBody[m]=n[m])),(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_o$model0=(o=_this69.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="llama3.2",(_a$stream=(a=_this69.rawBody).stream)!==null&&_a$stream!==void 0?_a$stream:a.stream=!1;return _this69;}_inherits(th,_M20);return _createClass(th,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:M.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e,t){var _this$messages5;return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:(_this$messages5=this.messages)!==null&&_this$messages5!==void 0?_this$messages5:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context143.a(2);}},_callee143,this);}));function callServiceAPI(_x268,_x269){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){var n,s,_s8;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:if(!e[p]){_context144.n=1;break;}throw e[p].message;case 1:if(!e[h]){_context144.n=2;break;}s=e[h].trim();return _context144.a(2,this.processStreamingResponse(s,t));case 2:if(!(e.choices&&(n=e.choices[0])!=null&&n.message)){_context144.n=3;break;}_s8=e.choices[0].message;return _context144.a(2,_s8.tool_calls?this.handleTools({tool_calls:_s8.tool_calls},t):_defineProperty({},h,_s8.content||""));case 3:return _context144.a(2,_defineProperty({},h,""));}},_callee144,this);}));function extractResultData(_x270,_x271){return _extractResultData30.apply(this,arguments);}return extractResultData;}()},{key:"processStreamingResponse",value:function(){var _processStreamingResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var r,n,s,_iterator4,_step4,o,a,c,l,_t51,_t52;return _regenerator().w(function(_context145){while(1)switch(_context145.p=_context145.n){case 0:n=e.split("\n").filter(function(o){return o.trim()!=="";});s="";_iterator4=_createForOfIteratorHelper(n);_context145.p=1;_iterator4.s();case 2:if((_step4=_iterator4.n()).done){_context145.n=8;break;}o=_step4.value;a=o.trim();if(!(a.startsWith("data: ")&&(a=a.substring(6)),a!=="[DONE]")){_context145.n=7;break;}_context145.p=3;c=JSON.parse(a);if(!(c.choices&&(r=c.choices[0])!=null&&r.delta)){_context145.n=5;break;}l=c.choices[0].delta;if(!l.tool_calls){_context145.n=4;break;}return _context145.a(2,this.handleTools({tool_calls:l.tool_calls},t));case 4:l.content&&(s+=l.content);case 5:_context145.n=7;break;case 6:_context145.p=6;_t51=_context145.v;return _context145.a(3,7);case 7:_context145.n=2;break;case 8:_context145.n=10;break;case 9:_context145.p=9;_t52=_context145.v;_iterator4.e(_t52);case 10:_context145.p=10;_iterator4.f();return _context145.f(10);case 11:return _context145.a(2,_defineProperty({},h,s));}},_callee145,this,[[3,6],[1,9,10,11]]);}));function processStreamingResponse(_x272,_x273){return _processStreamingResponse.apply(this,arguments);}return processStreamingResponse;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){var n,s,_yield$this$callToolF3,r,o;return _regenerator().w(function(_context146){while(1)switch(_context146.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context146.n=1;break;}throw Error(Qt);case 1:n=w(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context146.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF3=_context146.v;r=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context146.n=3;break;}return _context146.a(2,o);case 3:if(!(n.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},S,St),"content","")),!r.find(function(_ref176){var a=_ref176.response;return _typeof(a)!==_e;})&&s.length===r.length)){_context146.n=4;break;}return _context146.a(2,(r.forEach(function(a,c){var d;var l=(d=e.tool_calls)==null?void 0:d[c];n==null||n.messages.push(_defineProperty(_defineProperty(_defineProperty({},S,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(gn);case 5:return _context146.a(2);}},_callee146,this);}));function handleTools(_x274,_x275){return _handleTools2.apply(this,arguments);}return handleTools;}()}]);}(M);var nh=function nh(i){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J);},sh=function sh(i,e,t,n){var s=i;s[p]?s[p][y]===we?n(ue):n(He):t(e);},ih=function ih(){return pe("https://api.deepseek.com/models",he,sh);};var rh=/*#__PURE__*/function(_M21){function rh(e){var _this70$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this70;_classCallCheck(this,rh);var s,r,o;var n=w(e.directConnection).deepSeek;_this70=_callSuper(this,rh,[e,ih(),nh,n]),_this70.insertKeyPlaceholderText=_this70.genereteAPIKeyName("DeepSeek"),_this70.keyHelpUrl="https://platform.deepseek.com/api_keys",_this70.url="https://api.deepseek.com/v1/chat/completions",_this70.permittedErrorPrefixes=[et,we],_typeof(n)===U&&_this70.completeConfig(n),(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_s$model2=(s=_this70.rawBody).model)!==null&&_s$model2!==void 0?_s$model2:s.model="deepseek-chat",(_r$temperature=(r=_this70.rawBody).temperature)!==null&&_r$temperature!==void 0?_r$temperature:r.temperature=1,(_o$max_tokens=(o=_this70.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this70;}_inherits(rh,_M21);return _createClass(rh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context147.a(2);}},_callee147,this);}));function callServiceAPI(_x276,_x277){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e){var t;return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:if(!e[p]){_context148.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context148.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context148.n=2;break;}return _context148.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context148.n=3;break;}return _context148.a(2,_defineProperty({},h,t.message.content));case 3:return _context148.a(2,_defineProperty({},h,""));}},_callee148);}));function extractResultData(_x278){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(M);var oh=function oh(i){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J);},ah=function ah(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(ue):t(e);},ch=function ch(){return pe("https://api.minimax.io/v1/files/delete",ye,ah);};var lh=/*#__PURE__*/function(_M22){function lh(e){var _this71$maxMessages,_s$model3;var _this71;_classCallCheck(this,lh);var s;var n=w(e.directConnection).miniMax;_this71=_callSuper(this,lh,[e,ch(),oh,n]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("MiniMax"),_this71.keyHelpUrl="https://www.minimaxi.com",_this71.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this71.permittedErrorPrefixes=[et,we,"insufficient balance"],_typeof(n)===U&&_this71.completeConfig(n),(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_s$model3=(s=_this71.rawBody).model)!==null&&_s$model3!==void 0?_s$model3:s.model="MiniMax-M1";return _this71;}_inherits(lh,_M22);return _createClass(lh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e,t){return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context149.a(2);}},_callee149,this);}));function callServiceAPI(_x279,_x280){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e){var t,_n10;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:if(!e[p]){_context150.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context150.n=3;break;}_n10=e.choices[0];if(!(_n10.delta&&_n10.delta.content)){_context150.n=2;break;}return _context150.a(2,_defineProperty({},h,_n10.delta.content));case 2:if(!(_n10.message&&_n10.message.content)){_context150.n=3;break;}return _context150.a(2,_defineProperty({},h,_n10.message.content));case 3:if(!(typeof((t=e.base_resp)==null?void 0:t.status_code)=="number"&&e.base_resp.status_code>0)){_context150.n=4;break;}throw e.base_resp.status_msg;case 4:return _context150.a(2,_defineProperty({},h,""));}},_callee150);}));function extractResultData(_x281){return _extractResultData32.apply(this,arguments);}return extractResultData;}()}]);}(M);var hh=function hh(i){return _defineProperty(_defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J),"accept",J);},dh=function dh(i,e,t,n){i.detail?n(ue):t(e);},uh=function uh(){return pe("https://api.mistral.ai/v1/models",he,dh);};var br=/*#__PURE__*/function(_M23){function br(e){var _this72$maxMessages,_o$model1;var _this72;_classCallCheck(this,br);var s,r,o;var n=w(e.directConnection).mistral;_this72=_callSuper(this,br,[e,uh(),hh,n]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("Mistral"),_this72.keyHelpUrl="https://console.mistral.ai/api-keys/",_this72.url="https://api.mistral.ai/v1/chat/completions",_this72.permittedErrorPrefixes=[en],_typeof(n)===U&&_this72.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.mistral)==null?void 0:r.function_handler),(_this72$maxMessages=_this72.maxMessages)!==null&&_this72$maxMessages!==void 0?_this72$maxMessages:_this72.maxMessages=-1,(_o$model1=(o=_this72.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="mistral-small-latest";return _this72;}_inherits(br,_M23);return _createClass(br,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty(_defineProperty({},S,M.getRoleViaAI(r[S])),"content",M.getTextWFilesContent(r,br.getFileContent));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e,t){var _this$messages6;return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:(_this$messages6=this.messages)!==null&&_this$messages6!==void 0?_this$messages6:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context151.a(2);}},_callee151,this);}));function callServiceAPI(_x282,_x283){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e,t){var _n11;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:if(!e.message){_context152.n=1;break;}throw e.message;case 1:if(!e[p]){_context152.n=2;break;}throw e[p].message;case 2:if(!(e.choices&&e.choices.length>0)){_context152.n=4;break;}_n11=e.choices[0];if(!_n11.delta){_context152.n=3;break;}return _context152.a(2,this.extractStreamResult(_n11,t));case 3:if(!_n11.message){_context152.n=4;break;}return _context152.a(2,_n11.message.tool_calls?this.handleToolsGeneric({tool_calls:_n11.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n11.message.content||""));case 4:return _context152.a(2,_defineProperty({},h,""));}},_callee152,this);}));function extractResultData(_x284,_x285){return _extractResultData33.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var n,s,r;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:n=e.delta,s=e.finish_reason;if(!(s==="tool_calls"&&n!=null&&n.tool_calls)){_context153.n=1;break;}r={tool_calls:n.tool_calls};return _context153.a(2,this.handleToolsGeneric(r,this.functionHandler,this.messages,t));case 1:return _context153.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee153,this);}));function extractStreamResult(_x286,_x287){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t[y]===K?_defineProperty(_defineProperty({},y,Ve),Ve,t[T]||""):_defineProperty(_defineProperty({},y,h),h,"[Unsupported ".concat(ne," ").concat(y,": ").concat(t[y],"]"));});}}]);}(M);var yr=/*#__PURE__*/function(_M24){function yr(e){var _this73$maxMessages,_l$model3;var _this73;_classCallCheck(this,yr);var r,o,a,c,l;var t=w(e.directConnection),n=t.groq;_this73=_callSuper(this,yr,[e,Uo(),Fo,n]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("Groq"),_this73.keyHelpUrl="https://console.groq.com/keys",_this73.url="https://api.groq.com/openai/v1/chat/completions",_this73.permittedErrorPrefixes=[en,"property"];var s=(r=t.groq)==null?void 0:r.chat;_typeof(s)===U&&_this73.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.groq)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this73$maxMessages=_this73.maxMessages)!==null&&_this73$maxMessages!==void 0?_this73$maxMessages:_this73.maxMessages=-1,(_l$model3=(l=_this73.rawBody).model)!==null&&_l$model3!==void 0?_l$model3:l.model="llama-3.3-70b-versatile";return _this73;}_inherits(yr,_M24);return _createClass(yr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:yr.getTextWImagesContent(r)},S,r[S]===te?St:r[S]);});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var _this$messages7;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:(_this$messages7=this.messages)!==null&&_this$messages7!==void 0?_this$messages7:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context154.a(2);}},_callee154,this);}));function callServiceAPI(_x288,_x289){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e,t){var n,s,r,o;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:if(!e[p]){_context155.n=1;break;}throw e[p].message;case 1:return _context155.a(2,(s=(n=e.choices)==null?void 0:n[0])!=null&&s.delta?this.extractStreamResult(e.choices[0],t):(o=(r=e.choices)==null?void 0:r[0])!=null&&o.message?e.choices[0].message.tool_calls?this.handleToolsGeneric(e.choices[0].message,this.functionHandler,this.messages,t,{message:this.systemMessage}):_defineProperty({},h,e.choices[0].message.content||""):_defineProperty({},h,""));}},_callee155,this);}));function extractResultData(_x290,_x291){return _extractResultData34.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
|
|
201
|
-
},{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
202
|
-
},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if(!e[p]){_context160.n=1;break;}throw e[p].message||"Gemini API Error";case 1:if(!((r=(s=(n=e.candidates)==null?void 0:n[0])==null?void 0:s.content)!=null&&r.parts)){_context160.n=3;break;}a=e.candidates[0].content.parts,c=a.find(function(u){return u.functionCall;});if(!(c!=null&&c.functionCall)){_context160.n=2;break;}return _context160.a(2,this.handleTools([c.functionCall],t));case 2:l=a.find(function(u){return u[h];}),d=a.find(function(u){var g;return((g=u.inlineData)==null?void 0:g.mimeType)==="image/png";});return _context160.a(2,_defineProperty(_defineProperty({},h,(l==null?void 0:l[h])||""),m,(o=d==null?void 0:d.inlineData)!=null&&o.data?[_defineProperty({},T,"data:image/png;base64,".concat(d.inlineData.data))]:[]));case 3:return _context160.a(2,_defineProperty({},h,""));}},_callee160,this);}));function extractResultData(_x299,_x300){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var n,s,_yield$this$callToolF4,r,o,a,c;return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(!(!e||!t||!this.functionHandler)){_context161.n=1;break;}throw Error(Qt);case 1:n=w(t);s=e.map(function(c){return{name:c.name,arguments:ae(c.args)};});_context161.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF4=_context161.v;r=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context161.n=3;break;}return _context161.a(2,o);case 3:a=_defineProperty({parts:e.map(function(c){return{functionCall:{name:c.name,args:c.args}};})},S,"model");if(!(n.contents.push(a),!r.find(function(_ref205){var c=_ref205.response;return _typeof(c)!==_e;})&&s.length===r.length)){_context161.n=4;break;}c=_defineProperty({parts:r.map(function(l,d){return{functionResponse:{name:e[d].name,response:{result:l.response}}};})},S,F);return _context161.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(gn);case 5:return _context161.a(2);}},_callee161,this);}));function handleTools(_x301,_x302){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e[h]&&e[h].trim().length>0&&t.push(_defineProperty({},h,e[h])),e[m]&&e[m].length>0&&e[m].forEach(function(n){if(n[T]&&n[T].includes("data:")){var _n$T$split=n[T].split(","),_n$T$split2=_slicedToArray(_n$T$split,2),s=_n$T$split2[0],r=_n$T$split2[1];t.push({inlineData:{mimeType:s.replace("data:","").replace(";base64",""),data:r}});}}),_defineProperty({parts:t},S,e[S]===F?F:"model");}}]);}(M);var Eh=function Eh(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},H,J),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");},_h=function _h(i,e,t,n){var s=i;s[p]?s[p][y]===we?n(ue):n(He):t(e);},vh=function vh(){return pe("https://api.anthropic.com/v1/models",he,_h);},Wt=/*#__PURE__*/function(_M27){function Wt(e){var _this76$maxMessages,_o$model10,_a$max_tokens2;var _this76;_classCallCheck(this,Wt);var s,r,o,a;var n=w(e.directConnection).claude;if(_this76=_callSuper(this,Wt,[e,vh(),Eh,n]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("Claude"),_this76.keyHelpUrl="https://console.anthropic.com/settings/keys",_this76.url="".concat(Wt.CLAUDE_BASE_URL,"messages"),_this76.permittedErrorPrefixes=[we,et],_this76._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},y,"tool_use"),"id",""),"name",""),"input",""),_this76.url=Wt.buildUrl(n),_typeof(n)===U){var c=n;_this76.extractSystemBlocks(c),_this76.cleanConfig(c),_this76.completeConfig(c,(r=(s=e.directConnection)==null?void 0:s.claude)==null?void 0:r.function_handler);}(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1,(_o$model10=(o=_this76.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="claude-sonnet-4-6",(_a$max_tokens2=(a=_this76.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this76;}_inherits(Wt,_M27);return _createClass(Wt,[{key:"extractSystemBlocks",value:function extractSystemBlocks(e){Array.isArray(e.system_prompt)&&(this._systemBlocks=e.system_prompt,delete e.system_prompt);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.custom_base_url;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Wt.getTextWFilesContent(r,Wt.getFileContent)},S,M.getRoleViaUser(r[S]));});return n.messages=s,this._systemBlocks?n.system=this._systemBlocks:this.systemMessage&&(n.system=this.systemMessage),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){var _this$messages9;return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:(_this$messages9=this.messages)!==null&&_this$messages9!==void 0?_this$messages9:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context162.a(2);}},_callee162,this);}));function callServiceAPI(_x303,_x304){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee163(e,t){var n,s,r,o,a;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:if(!e[p]){_context163.n=1;break;}throw e[p].message;case 1:if(!(e.content&&e.content.length>0)){_context163.n=3;break;}o=e.content.find(function(c){return c[y]==="tool_use";});if(!o){_context163.n=2;break;}return _context163.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(c){return c[y]===h;});if(!a){_context163.n=3;break;}return _context163.a(2,_defineProperty({},h,a[h]));case 3:if(!(e[y]==="content_block_delta"&&e.delta&&e.delta[y]==="text_delta")){_context163.n=4;break;}return _context163.a(2,_defineProperty({},h,e.delta[h]||""));case 4:if(!(e[y]==="content_block_start"&&((n=e.content_block)==null?void 0:n[y])==="tool_use")){_context163.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context163.n=7;break;case 5:if(!(e[y]==="content_block_delta"&&((s=e.delta)==null?void 0:s[y])==="input_json_delta")){_context163.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context163.n=7;break;case 6:if(!(e[y]==="message_delta"&&((r=e.delta)==null?void 0:r.stop_reason)==="tool_use")){_context163.n=7;break;}return _context163.a(2,(this._streamToolCalls.input=this._streamToolCalls.input?JSON.parse(this._streamToolCalls.input):{},this.handleTools([this._streamToolCalls],t)));case 7:return _context163.a(2,_defineProperty({},h,""));}},_callee163,this);}));function extractResultData(_x305,_x306){return _extractResultData37.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var n,s,_yield$this$callToolF5,r,o,a,c;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:if(!(!e||!t||!this.functionHandler)){_context164.n=1;break;}throw Error(Qt);case 1:n=w(t);s=e.map(function(c){return{name:c.name,arguments:ae(c.input)};});_context164.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF5=_context164.v;r=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context164.n=3;break;}return _context164.a(2,o);case 3:a=e.map(function(c){return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},y,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push(_defineProperty(_defineProperty({},S,"assistant"),"content",a)),!r.find(function(_ref213){var c=_ref213.response;return _typeof(c)!==_e;})&&s.length===r.length)){_context164.n=4;break;}c=r.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},y,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context164.a(2,(n.messages.push(_defineProperty(_defineProperty({},S,F),"content",c)),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(gn);case 5:return _context164.a(2);}},_callee164,this);}));function handleTools(_x307,_x308){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"buildUrl",value:function buildUrl(e){return"".concat(_typeof(e)=="object"&&(e==null?void 0:e.custom_base_url)||Wt.CLAUDE_BASE_URL,"messages");}},{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var n,s,r;if(t[y]===K){var o=(n=t[T])==null?void 0:n.split(",")[1],a=((r=(s=t[T])==null?void 0:s.match(/data:([^;]+)/))==null?void 0:r[1])||"image/jpeg";return _defineProperty(_defineProperty({},y,K),"source",_defineProperty(_defineProperty(_defineProperty({},y,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},y,h),h,"[Unsupported ".concat(ne," ").concat(y,": ").concat(t[y],"]"));});}}]);}(M);Wt.CLAUDE_BASE_URL="https://api.anthropic.com/v1/";var Zi=Wt;var Sh=function Sh(){return{};},xh=function xh(){},Ah=function Ah(){return pe("",he,xh);},ds=/*#__PURE__*/function(_M28){function ds(e){var _this77$maxMessages,_o$model11,_a$stream2;var _this77;_classCallCheck(this,ds);var s,r,o,a;var t=w(e.directConnection);_this77=_callSuper(this,ds,[e,Ah(),Sh,{key:"placeholder"}]),_this77.insertKeyPlaceholderText="",_this77.keyHelpUrl="",_this77.validateKeyProperty=!1,_this77.url="http://localhost:11434/api/chat",_this77.permittedErrorPrefixes=["Error"];var n=t.ollama;_typeof(n)===U&&_this77.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.ollama)==null?void 0:r.function_handler),(_this77$maxMessages=_this77.maxMessages)!==null&&_this77$maxMessages!==void 0?_this77$maxMessages:_this77.maxMessages=-1,(_o$model11=(o=_this77.rawBody).model)!==null&&_o$model11!==void 0?_o$model11:o.model="llama3.2",(_a$stream2=(a=_this77.rawBody).stream)!==null&&_a$stream2!==void 0?_a$stream2:a.stream=!1;return _this77;}_inherits(ds,_M28);return _createClass(ds,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){var o=_defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));if(r[m]&&r[m].length>0){var a=ds.getImageData(r[m]);a.length>0&&(o[ee]=a);}return o;});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){var _this$messages0;return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:(_this$messages0=this.messages)!==null&&_this$messages0!==void 0?_this$messages0:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context165.a(2);}},_callee165,this);}));function callServiceAPI(_x309,_x310){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"parseMessage",value:function parseMessage(e){return e.split("\n").filter(function(t){return t.trim();}).map(function(t){return JSON.parse(t);});}},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee166(e,t){var n,s,r,o,_iterator6,_step6,l,a,c,_t53,_t54,_t55;return _regenerator().w(function(_context166){while(1)switch(_context166.p=_context166.n){case 0:if(!e[p]){_context166.n=1;break;}throw e[p].message;case 1:if(!e[h]){_context166.n=11;break;}r=this.parseMessage(e[h]),o=[];_iterator6=_createForOfIteratorHelper(r);_context166.p=2;_iterator6.s();case 3:if((_step6=_iterator6.n()).done){_context166.n=7;break;}l=_step6.value;_t53=(n=l.message)!=null&&n.tool_calls;if(!_t53){_context166.n=5;break;}_t54=o;_context166.n=4;return this.handleTools({tool_calls:l.message.tool_calls},t);case 4:_t54.push.call(_t54,_context166.v);case 5:o.push(_defineProperty({},h,((s=l.message)==null?void 0:s.content)||""));case 6:_context166.n=3;break;case 7:_context166.n=9;break;case 8:_context166.p=8;_t55=_context166.v;_iterator6.e(_t55);case 9:_context166.p=9;_iterator6.f();return _context166.f(9);case 10:a=o.map(function(l){return l[h];}),c=a.lastIndexOf(ds.THINK_END);return _context166.a(2,c===-1||t!=null&&t.think?_defineProperty({},h,a.join("")):_defineProperty(_defineProperty({},h,a.slice(c+1).join("")),"overwrite",!0));case 11:return _context166.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},h,e.message.content||""):_defineProperty({},h,""));}},_callee166,this,[[2,8,9,10]]);}));function extractResultData(_x311,_x312){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e,t){var n,s,_yield$this$callToolF6,r,o;return _regenerator().w(function(_context167){while(1)switch(_context167.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context167.n=1;break;}throw Error(Qt);case 1:n=w(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:ae(a["function"].arguments)};});_context167.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF6=_context167.v;r=_yield$this$callToolF6.responses;o=_yield$this$callToolF6.processedResponse;if(!o){_context167.n=3;break;}return _context167.a(2,o);case 3:if(!(n.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},S,St),"content","")),!r.find(function(_ref221){var a=_ref221.response;return _typeof(a)!==_e;})&&s.length===r.length)){_context167.n=4;break;}return _context167.a(2,(r.forEach(function(a,c){var d;var l=(d=e.tool_calls)==null?void 0:d[c];n==null||n.messages.push(_defineProperty(_defineProperty(_defineProperty({},S,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(gn);case 5:return _context167.a(2);}},_callee167,this);}));function handleTools(_x313,_x314){return _handleTools5.apply(this,arguments);}return handleTools;}()}],[{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t[y]===K;}).map(function(t){var s;return((s=t[T])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(M);ds.THINK_END="</think>";var Yi=ds;var Ho=function Ho(i){return _defineProperty({Authorization:"".concat(Ae).concat(i)},H,J);},wh=function wh(i,e,t,n){var s=i;s[p]?s[p][y]===we||s[p][y]===et?n(ue):n(He):t(e);},jo=function jo(){return pe("https://api.x.ai/v1/models",he,wh);},ui=/*#__PURE__*/function(_M29){function ui(e){var _o$model12;var _this78;_classCallCheck(this,ui);var r,o;var t=e.directConnection,n=t==null?void 0:t.x;_this78=_callSuper(this,ui,[e,jo(),Ho,n]),_this78.insertKeyPlaceholderText=_this78.genereteAPIKeyName("X"),_this78.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this78.url=ui.IMAGE_GENERATION_URL,_this78.permittedErrorPrefixes=[et,we];var s=(r=t==null?void 0:t.x)==null?void 0:r[ee];_typeof(s)===U&&Object.assign(_this78.rawBody,s),(_o$model12=(o=_this78.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="grok-imagine-image-quality";return _this78;}_inherits(ui,_M29);return _createClass(ui,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=w(e);return n&&n!==""&&(s.prompt=n),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context168.a(2);}},_callee168,this);}));function callServiceAPI(_x315,_x316){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e){var t;return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:if(!e[p]){_context169.n=1;break;}throw e[p].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},T,n.url),y,K):_defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.b64_json)),y,K);});return _context169.a(2,_defineProperty({},m,t));}},_callee169);}));function extractResultData(_x317){return _extractResultData39.apply(this,arguments);}return extractResultData;}()}]);}(M);ui.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Ji=ui;var Ch=function Ch(i){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J);},Th=function Th(i,e,t,n){var s=i;s[p]?s[p][y]===et?n(ue):n(He):t(e);},Rh=function Rh(){return pe("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",he,Th);};var _r=/*#__PURE__*/function(_M30){function _r(e){var _this79$maxMessages,_o$model13;var _this79;_classCallCheck(this,_r);var s,r,o;var n=w(e.directConnection).qwen;_this79=_callSuper(this,_r,[e,Rh(),Ch,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("Qwen"),_this79.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this79.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this79.permittedErrorPrefixes=["No static","The model",ws],_typeof(n)===U&&_this79.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.qwen)==null?void 0:r.function_handler),(_this79$maxMessages=_this79.maxMessages)!==null&&_this79$maxMessages!==void 0?_this79$maxMessages:_this79.maxMessages=-1,(_o$model13=(o=_this79.rawBody).model)!==null&&_o$model13!==void 0?_o$model13:o.model="qwen-plus";return _this79;}_inherits(_r,_M30);return _createClass(_r,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:_r.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e,t){var _this$messages1;return _regenerator().w(function(_context170){while(1)switch(_context170.n){case 0:(_this$messages1=this.messages)!==null&&_this$messages1!==void 0?_this$messages1:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context170.a(2);}},_callee170,this);}));function callServiceAPI(_x318,_x319){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(e,t){var _n12;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:if(!e[p]){_context171.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context171.n=3;break;}_n12=e.choices[0];if(!_n12.delta){_context171.n=2;break;}return _context171.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context171.n=3;break;}return _context171.a(2,_n12.message.tool_calls?this.handleToolsGeneric({tool_calls:_n12.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n12.message.content||""));case 3:return _context171.a(2,_defineProperty({},h,""));}},_callee171,this);}));function extractResultData(_x320,_x321){return _extractResultData40.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee172(e,t){return _regenerator().w(function(_context172){while(1)switch(_context172.n){case 0:return _context172.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee172,this);}));function extractStreamResult(_x322,_x323){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()}]);}(M);var Ih=function Ih(i){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(i)),H,J);},Mh=function Mh(i,e,t,n){var s=i;s[p]?s[p][y]===we?n(ue):n(He):t(e);},kh=function kh(){return pe("https://api.moonshot.ai/v1/models",he,Mh);};var vr=/*#__PURE__*/function(_M31){function vr(e){var _this80$maxMessages,_o$model14;var _this80;_classCallCheck(this,vr);var s,r,o;var n=w(e.directConnection).kimi;_this80=_callSuper(this,vr,[e,kh(),Ih,n]),_this80.insertKeyPlaceholderText=_this80.genereteAPIKeyName("Kimi"),_this80.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this80.url="https://api.moonshot.ai/v1/chat/completions",_this80.permittedErrorPrefixes=[en,"Not found"],_typeof(n)===U&&_this80.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.kimi)==null?void 0:r.function_handler),(_this80$maxMessages=_this80.maxMessages)!==null&&_this80$maxMessages!==void 0?_this80$maxMessages:_this80.maxMessages=-1,(_o$model14=(o=_this80.rawBody).model)!==null&&_o$model14!==void 0?_o$model14:o.model="moonshot-v1-8k";return _this80;}_inherits(vr,_M31);return _createClass(vr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:vr.getTextWImagesContent(r)},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e,t){var _this$messages10;return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:(_this$messages10=this.messages)!==null&&_this$messages10!==void 0?_this$messages10:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context173.a(2);}},_callee173,this);}));function callServiceAPI(_x324,_x325){return _callServiceAPI38.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(e,t){var _n13;return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:if(!e[p]){_context174.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context174.n=3;break;}_n13=e.choices[0];if(!_n13.delta){_context174.n=2;break;}return _context174.a(2,this.extractStreamResult(_n13,t));case 2:if(!_n13.message){_context174.n=3;break;}return _context174.a(2,_n13.message.tool_calls?this.handleToolsGeneric({tool_calls:_n13.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n13.message.content||""));case 3:return _context174.a(2,_defineProperty({},h,""));}},_callee174,this);}));function extractResultData(_x326,_x327){return _extractResultData41.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(e,t){return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:return _context175.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee175,this);}));function extractStreamResult(_x328,_x329){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()}]);}(M);var Lh=/*#__PURE__*/function(_M32){function Lh(e){var _this81$maxMessages,_o$model15;var _this81;_classCallCheck(this,Lh);var r,o;var t=w(e.directConnection),n=t.x;_this81=_callSuper(this,Lh,[e,jo(),Ho,n]),_this81.insertKeyPlaceholderText=_this81.genereteAPIKeyName("X"),_this81.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this81.url="https://api.x.ai/v1/responses",_this81.permittedErrorPrefixes=[et,we];var s=(r=t.x)==null?void 0:r.chat;_typeof(s)===U&&_this81.completeConfig(s),(_this81$maxMessages=_this81.maxMessages)!==null&&_this81$maxMessages!==void 0?_this81$maxMessages:_this81.maxMessages=-1,(_o$model15=(o=_this81.rawBody).model)!==null&&_o$model15!==void 0?_o$model15:o.model="grok-4.3";return _this81;}_inherits(Lh,_M32);return _createClass(Lh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});return n.input=s,this.systemMessage&&(n.instructions=this.systemMessage),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee176(e,t){return _regenerator().w(function(_context176){while(1)switch(_context176.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context176.a(2);}},_callee176,this);}));function callServiceAPI(_x330,_x331){return _callServiceAPI39.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData42=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee177(e){var t,n,s;return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:if(!e[p]){_context177.n=1;break;}throw e[p].message;case 1:t=e;if(!(typeof t.type=="string"&&t.type.startsWith("response."))){_context177.n=2;break;}return _context177.a(2,t.type==="response.output_text.delta"?_defineProperty({},h,t.delta||""):_defineProperty({},h,""));case 2:n=e;if(!(n.object==="response"&&Array.isArray(n.output))){_context177.n=3;break;}s=n.output.filter(function(r){return r.type==="message";}).flatMap(function(r){return r.content||[];}).filter(function(r){return r.type==="output_text";}).map(function(r){return r.text||"";}).join("");return _context177.a(2,_defineProperty({},h,s));case 3:return _context177.a(2,_defineProperty({},h,""));}},_callee177);}));function extractResultData(_x332){return _extractResultData42.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ph=function Ph(i){return _defineProperty(_defineProperty({},le,i===Li?"":"".concat(Ae).concat(i)),H,J);},Nh=function Nh(){},Bh=function Bh(){return pe("",he,Nh);};var Oh=/*#__PURE__*/function(_M33){function Oh(e){var _n$key,_this82$maxMessages,_r$model,_o$temperature,_a$max_tokens3;var _this82;_classCallCheck(this,Oh);var r,o,a;var n=w(e.directConnection).liteLLM,s=_typeof(n)===U?(_n$key=n.key)!==null&&_n$key!==void 0?_n$key:Li:Li;_this82=_callSuper(this,Oh,[e,Bh(),Ph,{key:s}]),_this82.url="http://localhost:4000/v1/chat/completions",_this82.permittedErrorPrefixes=[et,we],_typeof(n)===U&&_this82.completeConfig(n),(_this82$maxMessages=_this82.maxMessages)!==null&&_this82$maxMessages!==void 0?_this82$maxMessages:_this82.maxMessages=-1,(_r$model=(r=_this82.rawBody).model)!==null&&_r$model!==void 0?_r$model:r.model="gpt-4o-mini",(_o$temperature=(o=_this82.rawBody).temperature)!==null&&_o$temperature!==void 0?_o$temperature:o.temperature=1,(_a$max_tokens3=(a=_this82.rawBody).max_tokens)!==null&&_a$max_tokens3!==void 0?_a$max_tokens3:a.max_tokens=4096;return _this82;}_inherits(Oh,_M33);return _createClass(Oh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee178(e,t){return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context178.a(2);}},_callee178,this);}));function callServiceAPI(_x333,_x334){return _callServiceAPI40.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData43=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e){var t;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:if(!e[p]){_context179.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context179.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context179.n=2;break;}return _context179.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context179.n=3;break;}return _context179.a(2,_defineProperty({},h,t.message.content));case 3:return _context179.a(2,_defineProperty({},h,""));}},_callee179);}));function extractResultData(_x335){return _extractResultData43.apply(this,arguments);}return extractResultData;}()}]);}(M);var Os=/* @__PURE__ */function(i){return i.BLOCKING="blocking",i.STREAMING="streaming",i;}(Os||{}),Rn=/* @__PURE__ */function(i){return i.MESSAGE="message",i.AGENT_MESSAGE="agent_message",i.WORKFLOW_FINISHED="workflow_finished",i.ERROR="error",i;}(Rn||{});var Dh="image/",Fh="data:",Uh=function Uh(i,e){return{type:e,transfer_method:"local_file",upload_file_id:i};},Hh=function Hh(i){var e=i.trim();if(!e.startsWith(Fh))return null;var t=e.replace(/^data:\s*/,"").trim();return t?JSON.parse(t):null;};function jh(_x336,_x337){return _jh.apply(this,arguments);}function _jh(){_jh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee198(i,e){var t,_e$headers,n,s,r,a,o;return _regenerator().w(function(_context198){while(1)switch(_context198.n){case 0:t=new FormData();t.append(ne,i),t.append(F,e[F]);_e$headers=e.headers;n=_e$headers[H];s=_objectWithoutProperties(_e$headers,[H].map(_toPropertyKey));_context198.n=1;return fetch(e.url,{method:ye,headers:s,body:t});case 1:r=_context198.v;if(r.ok){_context198.n=3;break;}_context198.n=2;return r.text();case 2:a=_context198.v;throw new Error(a);case 3:_context198.n=4;return r.json();case 4:o=_context198.v;if(o.id){_context198.n=5;break;}throw new Error("Upload response missing file ID");case 5:return _context198.a(2,o.id);}},_callee198);}));return _jh.apply(this,arguments);}function $h(_x338,_x339){return _$h.apply(this,arguments);}function _$h(){_$h=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee200(i,e){var t;return _regenerator().w(function(_context200){while(1)switch(_context200.n){case 0:if(!(i.length===0)){_context200.n=1;break;}return _context200.a(2,[]);case 1:t=i.map(/*#__PURE__*/function(){var _ref275=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee199(s){var r,o;return _regenerator().w(function(_context199){while(1)switch(_context199.n){case 0:_context199.n=1;return jh(s,e);case 1:r=_context199.v;o=s[y].startsWith(Dh)?K:ne;return _context199.a(2,Uh(r,o));}},_callee199);}));return function(_x370){return _ref275.apply(this,arguments);};}());_context200.n=2;return Promise.all(t);case 2:return _context200.a(2,_context200.v.filter(function(s){return s!==null;}));}},_callee200);}));return _$h.apply(this,arguments);}function qh(i,e){return i.conversation_id&&e(i.conversation_id),i.code&&i.message&&!i.answer?_defineProperty({},p,i.message):_defineProperty({},h,i.answer||"");}var Gh=function Gh(i,e,t){var n,s;switch(!e.conversationIdSet&&i.conversation_id&&(t(i.conversation_id),e.conversationIdSet=!0),i.event){case Rn.MESSAGE:case Rn.AGENT_MESSAGE:e.fullAnswer+=i.answer||"";break;case Rn.WORKFLOW_FINISHED:!e.fullAnswer&&(s=(n=i.data)==null?void 0:n.outputs)!=null&&s.answer&&(e.fullAnswer=i.data.outputs.answer);break;case Rn.ERROR:e.errorMessage=i.message||Rn.ERROR;break;}};function Vh(_x340,_x341){return _Vh.apply(this,arguments);}function _Vh(){_Vh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee201(i,e){var t,s,_iterator7,_step7,r,o;return _regenerator().w(function(_context201){while(1)switch(_context201.n){case 0:t={fullAnswer:"",conversationIdSet:!1,errorMessage:""};_context201.n=1;return i.text();case 1:s=_context201.v.split(/\r?\n\r?\n/);_iterator7=_createForOfIteratorHelper(s);try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){r=_step7.value;o=Hh(r);o&&Gh(o,t,e);}}catch(err){_iterator7.e(err);}finally{_iterator7.f();}return _context201.a(2,t.errorMessage?_defineProperty({},p,t.errorMessage):_defineProperty({},h,t.fullAnswer));}},_callee201);}));return _Vh.apply(this,arguments);}var zh=function zh(i){return _defineProperty(_defineProperty({},H,J),le,"".concat(Ae).concat(i));},Kh=function Kh(i,e,t,n){var s=i;s[p]?s[p].message===fi?n(ue):n(He):"user_input_form"in i||"opening_statement"in i||"file_upload"in i?t(e):n(He);},Wh=function Wh(i){return pe("".concat(i,"/parameters"),he,Kh);};var Xh=/*#__PURE__*/function(_M34){function Xh(e){var _ref247,_this83$maxMessages;var _this83;_classCallCheck(this,Xh);var r;var t=w(e.directConnection),n=t==null?void 0:t.dify,s=(_ref247=(r=e.connect)==null?void 0:r.url)!==null&&_ref247!==void 0?_ref247:"https://api.dify.ai/v1";_this83=_callSuper(this,Xh,[e,Wh(s),zh,n]),_this83.insertKeyPlaceholderText=_this83.genereteAPIKeyName("Dify"),_this83.keyHelpUrl="https://docs.dify.ai/en/use-dify/publish/developing-with-apis",_this83.permittedErrorPrefixes=[we],_this83._conversationId="",_this83._user=F,_this83._inputs={},_this83.url="".concat(s,"/chat-messages"),_this83._uploadUrl="".concat(s,"/").concat(m,"/upload"),_typeof(n)===U&&(n[F]&&(_this83._user=n[F]),n.inputs&&(_this83._inputs=n.inputs),_this83.completeConfig(n)),(_this83$maxMessages=_this83.maxMessages)!==null&&_this83$maxMessages!==void 0?_this83$maxMessages:_this83.maxMessages=-1,_this83._mode=_this83.stream?Os.STREAMING:Os.BLOCKING;return _this83;}_inherits(Xh,_M34);return _createClass(Xh,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var s=this.processMessages(t),r=s[s.length-1],o=(r==null?void 0:r[h])||" ",a=_defineProperty({inputs:this._inputs,query:o,response_mode:this._mode},F,this._user);return this._conversationId&&(a.conversation_id=this._conversationId),n&&n.length>0&&(a[m]=n),a;}},{key:"callServiceAPI",value:function(){var _callServiceAPI41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(e,t,n){var _this$messages11,_this84=this;var s,_t56;return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:(_this$messages11=this.messages)!==null&&_this$messages11!==void 0?_this$messages11:this.messages=e;s=[];_t56=n&&n.length>0;if(!_t56){_context180.n=2;break;}_context180.n=1;return $h(n,_defineProperty(_defineProperty({url:this._uploadUrl},F,this._user),"headers",this.connectSettings.headers));case 1:s=_context180.v;case 2:this.callDirectServiceServiceAPI(e,t,function(r,o){return _this84.preprocessBody(r,o,s);});case 3:return _context180.a(2);}},_callee180,this);}));function callServiceAPI(_x342,_x343,_x344){return _callServiceAPI41.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData44=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee181(e){var _this85=this;var t;return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:t=function t(n){_this85._conversationId=n;};return _context181.a(2,this._mode===Os.BLOCKING&&!this.stream?qh(e,t):Vh(e,t));}},_callee181,this);}));function extractResultData(_x345){return _extractResultData44.apply(this,arguments);}return extractResultData;}()}]);}(M);var Zh=/*#__PURE__*/function(){function Zh(){_classCallCheck(this,Zh);}return _createClass(Zh,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
|
|
203
|
-
function create(e){var t=e.directConnection,n=e.connect,s=e.demo,
|
|
204
|
-
},{key:"createImageMessage",value:function createImageMessage(e,t,n,s,
|
|
205
|
-
},{key:"addMessages",value:function addMessages(e,t,n,s,
|
|
206
|
-
},{key:"updateFileMessages",value:function updateFileMessages(e,t,n){var u,g;var s=t[0][S],
|
|
207
|
-
},{key:"update",value:function update(e,t,n){var s=e.messageToElements[n];if(s){if(st.isElementActive(s[1]))return console[p]("Cannot update a message that is being streamed");t[h]&&st.updateTextMessage(e,s,t[h]),t[m]?st.updateFileMessages(e,s,t[m]):st.removeFilesMessages(e,s),t[L]&&st.updateHTMLMessage(e,s,t[L]),!t[h]&&s[1][h]&&st.removeTextHTMLMessage(e,s,h),!t[L]&&s[1][L]&&st.removeTextHTMLMessage(e,s,L);var
|
|
208
|
-
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var
|
|
209
|
-
},{key:"addNewMessage",value:function addNewMessage(e){var
|
|
210
|
-
},{key:"removeMessageOnError",value:function removeMessageOnError(){var e=this.messageElementRefs[this.messageElementRefs.length-1],t=e==null?void 0:e.bubbleElement;(t!=null&&t[f].contains(
|
|
211
|
-
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var
|
|
212
|
-
},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,c,l,d,u,g;if(
|
|
213
|
-
},{key:"updateLoadingMessage",value:function updateLoadingMessage(e){var s;var t=(s=this._activeLoadingConfig)==null?void 0:s[E],n=t==null?void 0:t[L];e.innerHTML=n||"";}},{key:"populateIntroPanel",value:function populateIntroPanel(e){e&&(this._introPanel=new
|
|
214
|
-
function clearMessages(e,t){var _this$messageToElemen2;var
|
|
200
|
+
}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,n){var s=new FormData();return s.append(W,t),n&&s.append("mask",n),Object.keys(e).forEach(function(i){s.append(i,String(e[i]));}),s;}}]);}(M);ut.IMAGE_GENERATION_URL="".concat(Qe,"images/generations"),ut.IMAGE_VARIATIONS_URL="".concat(Qe,"images/variations"),ut.IMAGE_EDIT_URL="".concat(Qe,"images/edits");var Yi=ut;var Kl=function Kl(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},Wl=function Wl(r,e,t,n){var s=r;s[p]?s[p][y]===we?n(ue):n(He):t(e);},Xl=function Xl(){return pe("https://openrouter.ai/api/v1/key",he,Wl);};var ss=/*#__PURE__*/function(_M18){function ss(e){var _this66$maxMessages,_o$model9,_a$max_tokens;var _this66;_classCallCheck(this,ss);var s,i,o,a;var n=w(e.directConnection).openRouter;_this66=_callSuper(this,ss,[e,Xl(),Kl,n]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("OpenRouter"),_this66.keyHelpUrl="https://openrouter.ai/keys",_this66.url="https://openrouter.ai/api/v1/chat/completions",_this66.permittedErrorPrefixes=[et,we],_typeof(n)===U&&_this66.completeConfig(n,(i=(s=e.directConnection)==null?void 0:s.openRouter)==null?void 0:i.function_handler),(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1,(_o$model9=(o=_this66.rawBody).model)!==null&&_o$model9!==void 0?_o$model9:o.model="openai/gpt-4o",(_a$max_tokens=(a=_this66.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=1e3;return _this66;}_inherits(ss,_M18);return _createClass(ss,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(o){return _defineProperty({content:ss.getContent(o)},S,M.getRoleViaUser(o[S]));}),i=[];return this.systemMessage&&i.push(_defineProperty(_defineProperty({},S,ps),"content",this.systemMessage)),i.push.apply(i,_toConsumableArray(s)),n.messages=i,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e,t){var _this$messages4;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:(_this$messages4=this.messages)!==null&&_this$messages4!==void 0?_this$messages4:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context140.a(2);}},_callee140,this);}));function callServiceAPI(_x257,_x258){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){var n,s,i,o,a,c,_a6,_c5;return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:if(!e[p]){_context141.n=1;break;}throw e[p].message;case 1:if(!(e.object==="chat.completion.chunk")){_context141.n=4;break;}a=(n=e.choices)==null?void 0:n[0];if(!(a!=null&&a.delta)){_context141.n=2;break;}return _context141.a(2,this.extractStreamResult(a,t));case 2:if(!((s=e.message)!=null&&s[Q])){_context141.n=3;break;}c=e.message[Q].map(function(l){return _defineProperty({},T,l[qe].url);});return _context141.a(2,_defineProperty(_defineProperty({},h,e.message.content||""),m,c));case 3:return _context141.a(2,_defineProperty({},h,""));case 4:if(!(e.object==="chat.completion")){_context141.n=6;break;}_a6=(i=e.choices)==null?void 0:i[0];if(!(_a6!=null&&_a6.message)){_context141.n=6;break;}if(!_a6.message.tool_calls){_context141.n=5;break;}return _context141.a(2,this.handleToolsGeneric({tool_calls:_a6.message.tool_calls},this.functionHandler,this.messages,t));case 5:_c5=((o=_a6.message[Q])==null?void 0:o.map(function(l){return _defineProperty({},T,l[qe].url);}))||[];return _context141.a(2,_defineProperty(_defineProperty({},h,_a6.message.content||""),"files",_c5));case 6:return _context141.a(2,_defineProperty({},h,""));}},_callee141,this);}));function extractResultData(_x259,_x260){return _extractResultData28.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e,t){var n,s;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:n=e.delta;if(!(n!=null&&n[Q])){_context142.n=1;break;}s=n[Q].map(function(i){return _defineProperty({},T,i[qe].url);});return _context142.a(2,_defineProperty(_defineProperty({},h,n.content||""),m,s));case 1:return _context142.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee142,this);}));function extractStreamResult(_x261,_x262){return _extractStreamResult3.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getAudioContent",value:function getAudioContent(e){return e.filter(function(t){return t[y]===G;}).map(function(t){var i,o,a;var n=(i=t[T])==null?void 0:i.split(",")[1],s=(a=(o=t[T])==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return _defineProperty(_defineProperty({},y,fn),fn,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[fn].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[m]&&e[m].length>0){var t=[].concat(_toConsumableArray(ss.getImageContent(e[m])),_toConsumableArray(ss.getAudioContent(e[m])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(M);var Zl=function Zl(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},Yl=function Yl(r,e,t,n){r[p]?n(ue):t(e);},Jl=function Jl(){return pe("https://api.perplexity.ai/chat/completions",ye,Yl);};var Ql=/*#__PURE__*/function(_M19){function Ql(e){var _this67$maxMessages,_s$model;var _this67;_classCallCheck(this,Ql);var s;var n=w(e.directConnection).perplexity;_this67=_callSuper(this,Ql,[e,Jl(),Zl,n]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("Perplexity"),_this67.keyHelpUrl="https://www.perplexity.ai/settings/api",_this67.url="https://api.perplexity.ai/chat/completions",_this67.permittedErrorPrefixes=[tn,yo,"Permission denied"],_typeof(n)===U&&_this67.completeConfig(n),(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1,(_s$model=(s=_this67.rawBody).model)!==null&&_s$model!==void 0?_s$model:s.model="sonar";return _this67;}_inherits(Ql,_M19);return _createClass(Ql,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:i[h]||""},S,M.getRoleViaUser(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e,t){return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context143.a(2);}},_callee143,this);}));function callServiceAPI(_x263,_x264){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e){var t;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:if(!e[p]){_context144.n=1;break;}throw e[p].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,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context144.n=3;break;}return _context144.a(2,_defineProperty({},h,t.message.content));case 3:return _context144.a(2,_defineProperty({},h,""));}},_callee144);}));function extractResultData(_x265){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(M);var eh=function eh(r){return _defineProperty(_defineProperty({},le,"Bearer ".concat(r)),H,Y);},th=function th(r,e,t,n){var s=r;s.detail?n(s.detail):t(e);},nh=function nh(){return pe("http://localhost:3000/api/v1/models",he,th);};var sh=/*#__PURE__*/function(_M20){function sh(e){var _this68$maxMessages,_o$model0,_a$stream;var _this68;_classCallCheck(this,sh);var s,i,o,a;var n=w(e.directConnection).openWebUI;_this68=_callSuper(this,sh,[e,nh(),eh,n]),_this68.insertKeyPlaceholderText="Open WebUI API Key",_this68.keyHelpUrl="https://docs.openwebui.com/getting-started/api-endpoints/",_this68.url="http://localhost:3000/api/chat/completions",_this68.permittedErrorPrefixes=["Error"],_typeof(n)===U&&(_this68.completeConfig(n,(i=(s=e.directConnection)==null?void 0:s.openWebUI)==null?void 0:i.function_handler),n[m]&&n[m].length>0&&(_this68.rawBody[m]=n[m])),(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_o$model0=(o=_this68.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="llama3.2",(_a$stream=(a=_this68.rawBody).stream)!==null&&_a$stream!==void 0?_a$stream:a.stream=!1;return _this68;}_inherits(sh,_M20);return _createClass(sh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:M.getTextWImagesContent(i)},S,M.getRoleViaUser(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var _this$messages5;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:(_this$messages5=this.messages)!==null&&_this$messages5!==void 0?_this$messages5:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context145.a(2);}},_callee145,this);}));function callServiceAPI(_x266,_x267){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){var n,s,_s7;return _regenerator().w(function(_context146){while(1)switch(_context146.n){case 0:if(!e[p]){_context146.n=1;break;}throw e[p].message;case 1:if(!e[h]){_context146.n=2;break;}s=e[h].trim();return _context146.a(2,this.processStreamingResponse(s,t));case 2:if(!(e.choices&&(n=e.choices[0])!=null&&n.message)){_context146.n=3;break;}_s7=e.choices[0].message;return _context146.a(2,_s7.tool_calls?this.handleTools({tool_calls:_s7.tool_calls},t):_defineProperty({},h,_s7.content||""));case 3:return _context146.a(2,_defineProperty({},h,""));}},_callee146,this);}));function extractResultData(_x268,_x269){return _extractResultData30.apply(this,arguments);}return extractResultData;}()},{key:"processStreamingResponse",value:function(){var _processStreamingResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){var i,n,s,_iterator7,_step7,o,a,c,l,_t63,_t64;return _regenerator().w(function(_context147){while(1)switch(_context147.p=_context147.n){case 0:n=e.split("\n").filter(function(o){return o.trim()!=="";});s="";_iterator7=_createForOfIteratorHelper(n);_context147.p=1;_iterator7.s();case 2:if((_step7=_iterator7.n()).done){_context147.n=8;break;}o=_step7.value;a=o.trim();if(!(a.startsWith("data: ")&&(a=a.substring(6)),a!=="[DONE]")){_context147.n=7;break;}_context147.p=3;c=JSON.parse(a);if(!(c.choices&&(i=c.choices[0])!=null&&i.delta)){_context147.n=5;break;}l=c.choices[0].delta;if(!l.tool_calls){_context147.n=4;break;}return _context147.a(2,this.handleTools({tool_calls:l.tool_calls},t));case 4:l.content&&(s+=l.content);case 5:_context147.n=7;break;case 6:_context147.p=6;_t63=_context147.v;return _context147.a(3,7);case 7:_context147.n=2;break;case 8:_context147.n=10;break;case 9:_context147.p=9;_t64=_context147.v;_iterator7.e(_t64);case 10:_context147.p=10;_iterator7.f();return _context147.f(10);case 11:return _context147.a(2,_defineProperty({},h,s));}},_callee147,this,[[3,6],[1,9,10,11]]);}));function processStreamingResponse(_x270,_x271){return _processStreamingResponse.apply(this,arguments);}return processStreamingResponse;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e,t){var n,s,_yield$this$callToolF3,i,o;return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context148.n=1;break;}throw Error(en);case 1:n=w(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context148.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF3=_context148.v;i=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context148.n=3;break;}return _context148.a(2,o);case 3:if(!(n.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},S,xt),"content","")),!i.find(function(_ref176){var a=_ref176.response;return _typeof(a)!==_e;})&&s.length===i.length)){_context148.n=4;break;}return _context148.a(2,(i.forEach(function(a,c){var d;var l=(d=e.tool_calls)==null?void 0:d[c];n==null||n.messages.push(_defineProperty(_defineProperty(_defineProperty({},S,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(bn);case 5:return _context148.a(2);}},_callee148,this);}));function handleTools(_x272,_x273){return _handleTools2.apply(this,arguments);}return handleTools;}()}]);}(M);var ih=function ih(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},rh=function rh(r,e,t,n){var s=r;s[p]?s[p][y]===we?n(ue):n(He):t(e);},oh=function oh(){return pe("https://api.deepseek.com/models",he,rh);};var ah=/*#__PURE__*/function(_M21){function ah(e){var _this69$maxMessages,_s$model2,_i$temperature,_o$max_tokens;var _this69;_classCallCheck(this,ah);var s,i,o;var n=w(e.directConnection).deepSeek;_this69=_callSuper(this,ah,[e,oh(),ih,n]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("DeepSeek"),_this69.keyHelpUrl="https://platform.deepseek.com/api_keys",_this69.url="https://api.deepseek.com/v1/chat/completions",_this69.permittedErrorPrefixes=[et,we],_typeof(n)===U&&_this69.completeConfig(n),(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_s$model2=(s=_this69.rawBody).model)!==null&&_s$model2!==void 0?_s$model2:s.model="deepseek-chat",(_i$temperature=(i=_this69.rawBody).temperature)!==null&&_i$temperature!==void 0?_i$temperature:i.temperature=1,(_o$max_tokens=(o=_this69.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this69;}_inherits(ah,_M21);return _createClass(ah,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:i[h]||""},S,M.getRoleViaUser(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e,t){return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context149.a(2);}},_callee149,this);}));function callServiceAPI(_x274,_x275){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e){var t;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:if(!e[p]){_context150.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context150.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context150.n=2;break;}return _context150.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context150.n=3;break;}return _context150.a(2,_defineProperty({},h,t.message.content));case 3:return _context150.a(2,_defineProperty({},h,""));}},_callee150);}));function extractResultData(_x276){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(M);var ch=function ch(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},lh=function lh(r,e,t,n){var i;((i=r.base_resp)==null?void 0:i.status_code)===1004?n(ue):t(e);},hh=function hh(){return pe("https://api.minimax.io/v1/files/delete",ye,lh);};var dh=/*#__PURE__*/function(_M22){function dh(e){var _this70$maxMessages,_s$model3;var _this70;_classCallCheck(this,dh);var s;var n=w(e.directConnection).miniMax;_this70=_callSuper(this,dh,[e,hh(),ch,n]),_this70.insertKeyPlaceholderText=_this70.genereteAPIKeyName("MiniMax"),_this70.keyHelpUrl="https://www.minimaxi.com",_this70.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this70.permittedErrorPrefixes=[et,we,"insufficient balance"],_typeof(n)===U&&_this70.completeConfig(n),(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_s$model3=(s=_this70.rawBody).model)!==null&&_s$model3!==void 0?_s$model3:s.model="MiniMax-M1";return _this70;}_inherits(dh,_M22);return _createClass(dh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:i[h]||""},S,M.getRoleViaUser(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e,t){return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context151.a(2);}},_callee151,this);}));function callServiceAPI(_x277,_x278){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e){var t,_n10;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:if(!e[p]){_context152.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context152.n=3;break;}_n10=e.choices[0];if(!(_n10.delta&&_n10.delta.content)){_context152.n=2;break;}return _context152.a(2,_defineProperty({},h,_n10.delta.content));case 2:if(!(_n10.message&&_n10.message.content)){_context152.n=3;break;}return _context152.a(2,_defineProperty({},h,_n10.message.content));case 3:if(!(typeof((t=e.base_resp)==null?void 0:t.status_code)=="number"&&e.base_resp.status_code>0)){_context152.n=4;break;}throw e.base_resp.status_msg;case 4:return _context152.a(2,_defineProperty({},h,""));}},_callee152);}));function extractResultData(_x279){return _extractResultData32.apply(this,arguments);}return extractResultData;}()}]);}(M);var uh=function uh(r){return _defineProperty(_defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y),"accept",Y);},ph=function ph(r,e,t,n){r.detail?n(ue):t(e);},fh=function fh(){return pe("https://api.mistral.ai/v1/models",he,ph);};var Er=/*#__PURE__*/function(_M23){function Er(e){var _this71$maxMessages,_o$model1;var _this71;_classCallCheck(this,Er);var s,i,o;var n=w(e.directConnection).mistral;_this71=_callSuper(this,Er,[e,fh(),uh,n]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("Mistral"),_this71.keyHelpUrl="https://console.mistral.ai/api-keys/",_this71.url="https://api.mistral.ai/v1/chat/completions",_this71.permittedErrorPrefixes=[tn],_typeof(n)===U&&_this71.completeConfig(n,(i=(s=e.directConnection)==null?void 0:s.mistral)==null?void 0:i.function_handler),(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_o$model1=(o=_this71.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="mistral-small-latest";return _this71;}_inherits(Er,_M23);return _createClass(Er,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty(_defineProperty({},S,M.getRoleViaAI(i[S])),"content",M.getTextWFilesContent(i,Er.getFileContent));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var _this$messages6;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:(_this$messages6=this.messages)!==null&&_this$messages6!==void 0?_this$messages6:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context153.a(2);}},_callee153,this);}));function callServiceAPI(_x280,_x281){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var _n11;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:if(!e.message){_context154.n=1;break;}throw e.message;case 1:if(!e[p]){_context154.n=2;break;}throw e[p].message;case 2:if(!(e.choices&&e.choices.length>0)){_context154.n=4;break;}_n11=e.choices[0];if(!_n11.delta){_context154.n=3;break;}return _context154.a(2,this.extractStreamResult(_n11,t));case 3:if(!_n11.message){_context154.n=4;break;}return _context154.a(2,_n11.message.tool_calls?this.handleToolsGeneric({tool_calls:_n11.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n11.message.content||""));case 4:return _context154.a(2,_defineProperty({},h,""));}},_callee154,this);}));function extractResultData(_x282,_x283){return _extractResultData33.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e,t){var n,s,i;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:n=e.delta,s=e.finish_reason;if(!(s==="tool_calls"&&n!=null&&n.tool_calls)){_context155.n=1;break;}i={tool_calls:n.tool_calls};return _context155.a(2,this.handleToolsGeneric(i,this.functionHandler,this.messages,t));case 1:return _context155.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee155,this);}));function extractStreamResult(_x284,_x285){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t[y]===W?_defineProperty(_defineProperty({},y,qe),qe,t[T]||""):_defineProperty(_defineProperty({},y,h),h,"[Unsupported ".concat(ne," ").concat(y,": ").concat(t[y],"]"));});}}]);}(M);var _r=/*#__PURE__*/function(_M24){function _r(e){var _this72$maxMessages,_l$model3;var _this72;_classCallCheck(this,_r);var i,o,a,c,l;var t=w(e.directConnection),n=t.groq;_this72=_callSuper(this,_r,[e,Ho(),Uo,n]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("Groq"),_this72.keyHelpUrl="https://console.groq.com/keys",_this72.url="https://api.groq.com/openai/v1/chat/completions",_this72.permittedErrorPrefixes=[tn,"property"];var s=(i=t.groq)==null?void 0:i.chat;_typeof(s)===U&&_this72.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.groq)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this72$maxMessages=_this72.maxMessages)!==null&&_this72$maxMessages!==void 0?_this72$maxMessages:_this72.maxMessages=-1,(_l$model3=(l=_this72.rawBody).model)!==null&&_l$model3!==void 0?_l$model3:l.model="llama-3.3-70b-versatile";return _this72;}_inherits(_r,_M24);return _createClass(_r,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:_r.getTextWImagesContent(i)},S,i[S]===te?xt:i[S]);});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var _this$messages7;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:(_this$messages7=this.messages)!==null&&_this$messages7!==void 0?_this$messages7:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context156.a(2);}},_callee156,this);}));function callServiceAPI(_x286,_x287){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var n,s,i,o;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(!e[p]){_context157.n=1;break;}throw e[p].message;case 1:return _context157.a(2,(s=(n=e.choices)==null?void 0:n[0])!=null&&s.delta?this.extractStreamResult(e.choices[0],t):(o=(i=e.choices)==null?void 0:i[0])!=null&&o.message?e.choices[0].message.tool_calls?this.handleToolsGeneric(e.choices[0].message,this.functionHandler,this.messages,t,{message:this.systemMessage}):_defineProperty({},h,e.choices[0].message.content||""):_defineProperty({},h,""));}},_callee157,this);}));function extractResultData(_x288,_x289){return _extractResultData34.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
|
|
201
|
+
},{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:return _context158.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee158,this);}));function extractStreamResult(_x290,_x291){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(M);var mh=function mh(r){return _defineProperty(_defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y),"accept",Y);},gh=function gh(r,e,t,n){_typeof(r.message)===_e?n(ue):t(e);},bh=function bh(){return pe("https://api.cohere.ai/v1/models",he,gh);};var oi=/*#__PURE__*/function(_M25){function oi(e){var _this73$maxMessages,_s$model4;var _this73;_classCallCheck(this,oi);var s;var n=w(e.directConnection).cohere;if(_this73=_callSuper(this,oi,[e,bh(),mh,n]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("Cohere"),_this73.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this73.permittedErrorPrefixes=["invalid"],_this73.url="https://api.cohere.com/v2/chat",_typeof(n)===U){var i=ce.processCohere(n);_this73.canSendMessage=function(){return i;},_this73.cleanConfig(n),Object.assign(_this73.rawBody,n);}(_this73$maxMessages=_this73.maxMessages)!==null&&_this73$maxMessages!==void 0?_this73$maxMessages:_this73.maxMessages=-1,(_s$model4=(s=_this73.rawBody).model)!==null&&_s$model4!==void 0?_s$model4:s.model="command-a-03-2025";return _this73;}_inherits(oi,_M25);return _createClass(oi,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t.filter(function(i){return i[h];});return n.messages=s.map(function(i){return _defineProperty(_defineProperty({},S,M.getRoleViaAI(i[S])),"content",i[h]);}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e,t){return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context159.a(2);}},_callee159,this);}));function callServiceAPI(_x292,_x293){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e){var t,n,s,i;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if(!(typeof e.message=="string")){_context160.n=1;break;}throw e.message;case 1:if(!(this.stream&&e[h])){_context160.n=2;break;}i=oi.parseBundledEvents(e[h]);return _context160.a(2,{text:oi.aggregateBundledEventsText(i)});case 2:if(!("message"in e&&(s=(n=(t=e.message)==null?void 0:t.content)==null?void 0:n[0])!=null&&s[h])){_context160.n=3;break;}return _context160.a(2,_defineProperty({},h,e.message.content[0][h]));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context160.a(2);}},_callee160,this);}));function extractResultData(_x294){return _extractResultData35.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),n=[];var _iterator8=_createForOfIteratorHelper(t),_step8;try{for(_iterator8.s();!(_step8=_iterator8.n()).done;){var s=_step8.value;if(s.trim())try{var i=JSON.parse(s);n.push(i);}catch(i){console[p]("Failed to parse line:",s,i);}}}catch(err){_iterator8.e(err);}finally{_iterator8.f();}return n;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var n,s,i;return t[y]==="content-delta"&&((i=(s=(n=t.delta)==null?void 0:n.message)==null?void 0:s.content)==null?void 0:i[h]);}).map(function(t){var n,s,i;return(i=(s=(n=t.delta)==null?void 0:n.message)==null?void 0:s.content)==null?void 0:i[h];}).join("");}}]);}(M);var yh=function yh(){return _defineProperty({},H,Y);},Eh=function Eh(r,e,t,n){var i;var s=r;s[p]?s[p].code===403||(i=s[p].message)!=null&&i.includes("API key")?n(ue):n(He):t(e);},_h=function _h(){var r="https://generativelanguage.googleapis.com/v1beta/models?key=";return pe(r,he,Eh,function(e){return"".concat(r).concat(e);});};var vr=/*#__PURE__*/function(_M26){function vr(e){var _this74$maxMessages;var _this74;_classCallCheck(this,vr);var s,i;var n=w(e.directConnection).gemini;if(_this74=_callSuper(this,vr,[e,_h(),yh,n]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Gemini"),_this74.keyHelpUrl="https://aistudio.google.com/app/apikey",_this74.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",_this74.url="",_this74.permittedErrorPrefixes=["API_KEY_INVALID"],_typeof(n)===U){var o=n;o.model&&(_this74.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(o.model,":generateContent")),_this74.cleanConfig(o),_this74.completeConfig(o,(i=(s=e.directConnection)==null?void 0:s.gemini)==null?void 0:i.function_handler);}(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1;return _this74;}_inherits(vr,_M26);return _createClass(vr,[{key:"cleanConfig",value:function cleanConfig(e){delete e.model;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return vr.getContent(i);});return n.contents=s,this.systemMessage&&(n.systemInstruction={parts:[_defineProperty({},h,this.systemMessage)]}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var _this$messages8;var n,s;return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(this.connectSettings){_context161.n=1;break;}throw new Error($e);case 1:(_this$messages8=this.messages)!==null&&_this$messages8!==void 0?_this$messages8:this.messages=e;n=this.preprocessBody(this.rawBody,t),s=this.stream;s&&(_typeof(s)!==U||!s.simulation)||n.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),V.request(this,n,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),be.request(this,n,e));case 2:return _context161.a(2);}},_callee161,this);}));function callServiceAPI(_x295,_x296){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()// https://ai.google.dev/gemini-api/docs/function-calling?example=weather
|
|
202
|
+
},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){var n,s,i,o,a,c,l,d;return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:if(!e[p]){_context162.n=1;break;}throw e[p].message||"Gemini API Error";case 1:if(!((i=(s=(n=e.candidates)==null?void 0:n[0])==null?void 0:s.content)!=null&&i.parts)){_context162.n=3;break;}a=e.candidates[0].content.parts,c=a.find(function(u){return u.functionCall;});if(!(c!=null&&c.functionCall)){_context162.n=2;break;}return _context162.a(2,this.handleTools([c.functionCall],t));case 2:l=a.find(function(u){return u[h];}),d=a.find(function(u){var g;return((g=u.inlineData)==null?void 0:g.mimeType)==="image/png";});return _context162.a(2,_defineProperty(_defineProperty({},h,(l==null?void 0:l[h])||""),m,(o=d==null?void 0:d.inlineData)!=null&&o.data?[_defineProperty({},T,"data:image/png;base64,".concat(d.inlineData.data))]:[]));case 3:return _context162.a(2,_defineProperty({},h,""));}},_callee162,this);}));function extractResultData(_x297,_x298){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee163(e,t){var n,s,_yield$this$callToolF4,i,o,a,c;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:if(!(!e||!t||!this.functionHandler)){_context163.n=1;break;}throw Error(en);case 1:n=w(t);s=e.map(function(c){return{name:c.name,arguments:ae(c.args)};});_context163.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF4=_context163.v;i=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context163.n=3;break;}return _context163.a(2,o);case 3:a=_defineProperty({parts:e.map(function(c){return{functionCall:{name:c.name,args:c.args}};})},S,"model");if(!(n.contents.push(a),!i.find(function(_ref205){var c=_ref205.response;return _typeof(c)!==_e;})&&s.length===i.length)){_context163.n=4;break;}c=_defineProperty({parts:i.map(function(l,d){return{functionResponse:{name:e[d].name,response:{result:l.response}}};})},S,F);return _context163.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(bn);case 5:return _context163.a(2);}},_callee163,this);}));function handleTools(_x299,_x300){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e[h]&&e[h].trim().length>0&&t.push(_defineProperty({},h,e[h])),e[m]&&e[m].length>0&&e[m].forEach(function(n){if(n[T]&&n[T].includes("data:")){var _n$T$split=n[T].split(","),_n$T$split2=_slicedToArray(_n$T$split,2),s=_n$T$split2[0],i=_n$T$split2[1];t.push({inlineData:{mimeType:s.replace("data:","").replace(";base64",""),data:i}});}}),_defineProperty({parts:t},S,e[S]===F?F:"model");}}]);}(M);var vh=function vh(r){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":r},H,Y),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");},Sh=function Sh(r,e,t,n){var s=r;s[p]?s[p][y]===we?n(ue):n(He):t(e);},xh=function xh(){return pe("https://api.anthropic.com/v1/models",he,Sh);},Xt=/*#__PURE__*/function(_M27){function Xt(e){var _this75$maxMessages,_o$model10,_a$max_tokens2;var _this75;_classCallCheck(this,Xt);var s,i,o,a;var n=w(e.directConnection).claude;if(_this75=_callSuper(this,Xt,[e,xh(),vh,n]),_this75.insertKeyPlaceholderText=_this75.genereteAPIKeyName("Claude"),_this75.keyHelpUrl="https://console.anthropic.com/settings/keys",_this75.url="".concat(Xt.CLAUDE_BASE_URL,"messages"),_this75.permittedErrorPrefixes=[we,et],_this75._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},y,"tool_use"),"id",""),"name",""),"input",""),_this75.url=Xt.buildUrl(n),_typeof(n)===U){var c=n;_this75.extractSystemBlocks(c),_this75.cleanConfig(c),_this75.completeConfig(c,(i=(s=e.directConnection)==null?void 0:s.claude)==null?void 0:i.function_handler);}(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1,(_o$model10=(o=_this75.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="claude-sonnet-4-6",(_a$max_tokens2=(a=_this75.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this75;}_inherits(Xt,_M27);return _createClass(Xt,[{key:"extractSystemBlocks",value:function extractSystemBlocks(e){Array.isArray(e.system_prompt)&&(this._systemBlocks=e.system_prompt,delete e.system_prompt);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.custom_base_url;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:Xt.getTextWFilesContent(i,Xt.getFileContent)},S,M.getRoleViaUser(i[S]));});return n.messages=s,this._systemBlocks?n.system=this._systemBlocks:this.systemMessage&&(n.system=this.systemMessage),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var _this$messages9;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:(_this$messages9=this.messages)!==null&&_this$messages9!==void 0?_this$messages9:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context164.a(2);}},_callee164,this);}));function callServiceAPI(_x301,_x302){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){var n,s,i,o,a;return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:if(!e[p]){_context165.n=1;break;}throw e[p].message;case 1:if(!(e.content&&e.content.length>0)){_context165.n=3;break;}o=e.content.find(function(c){return c[y]==="tool_use";});if(!o){_context165.n=2;break;}return _context165.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(c){return c[y]===h;});if(!a){_context165.n=3;break;}return _context165.a(2,_defineProperty({},h,a[h]));case 3:if(!(e[y]==="content_block_delta"&&e.delta&&e.delta[y]==="text_delta")){_context165.n=4;break;}return _context165.a(2,_defineProperty({},h,e.delta[h]||""));case 4:if(!(e[y]==="content_block_start"&&((n=e.content_block)==null?void 0:n[y])==="tool_use")){_context165.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context165.n=7;break;case 5:if(!(e[y]==="content_block_delta"&&((s=e.delta)==null?void 0:s[y])==="input_json_delta")){_context165.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context165.n=7;break;case 6:if(!(e[y]==="message_delta"&&((i=e.delta)==null?void 0:i.stop_reason)==="tool_use")){_context165.n=7;break;}return _context165.a(2,(this._streamToolCalls.input=this._streamToolCalls.input?JSON.parse(this._streamToolCalls.input):{},this.handleTools([this._streamToolCalls],t)));case 7:return _context165.a(2,_defineProperty({},h,""));}},_callee165,this);}));function extractResultData(_x303,_x304){return _extractResultData37.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee166(e,t){var n,s,_yield$this$callToolF5,i,o,a,c;return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:if(!(!e||!t||!this.functionHandler)){_context166.n=1;break;}throw Error(en);case 1:n=w(t);s=e.map(function(c){return{name:c.name,arguments:ae(c.input)};});_context166.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF5=_context166.v;i=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context166.n=3;break;}return _context166.a(2,o);case 3:a=e.map(function(c){return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},y,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push(_defineProperty(_defineProperty({},S,"assistant"),"content",a)),!i.find(function(_ref213){var c=_ref213.response;return _typeof(c)!==_e;})&&s.length===i.length)){_context166.n=4;break;}c=i.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},y,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context166.a(2,(n.messages.push(_defineProperty(_defineProperty({},S,F),"content",c)),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(bn);case 5:return _context166.a(2);}},_callee166,this);}));function handleTools(_x305,_x306){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"buildUrl",value:function buildUrl(e){return"".concat(_typeof(e)=="object"&&(e==null?void 0:e.custom_base_url)||Xt.CLAUDE_BASE_URL,"messages");}},{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var n,s,i;if(t[y]===W){var o=(n=t[T])==null?void 0:n.split(",")[1],a=((i=(s=t[T])==null?void 0:s.match(/data:([^;]+)/))==null?void 0:i[1])||"image/jpeg";return _defineProperty(_defineProperty({},y,W),"source",_defineProperty(_defineProperty(_defineProperty({},y,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},y,h),h,"[Unsupported ".concat(ne," ").concat(y,": ").concat(t[y],"]"));});}}]);}(M);Xt.CLAUDE_BASE_URL="https://api.anthropic.com/v1/";var Ji=Xt;var Ah=function Ah(){return{};},wh=function wh(){},Ch=function Ch(){return pe("",he,wh);},ds=/*#__PURE__*/function(_M28){function ds(e){var _this76$maxMessages,_o$model11,_a$stream2;var _this76;_classCallCheck(this,ds);var s,i,o,a;var t=w(e.directConnection);_this76=_callSuper(this,ds,[e,Ch(),Ah,{key:"placeholder"}]),_this76.insertKeyPlaceholderText="",_this76.keyHelpUrl="",_this76.validateKeyProperty=!1,_this76.url="http://localhost:11434/api/chat",_this76.permittedErrorPrefixes=["Error"];var n=t.ollama;_typeof(n)===U&&_this76.completeConfig(n,(i=(s=e.directConnection)==null?void 0:s.ollama)==null?void 0:i.function_handler),(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1,(_o$model11=(o=_this76.rawBody).model)!==null&&_o$model11!==void 0?_o$model11:o.model="llama3.2",(_a$stream2=(a=_this76.rawBody).stream)!==null&&_a$stream2!==void 0?_a$stream2:a.stream=!1;return _this76;}_inherits(ds,_M28);return _createClass(ds,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){var o=_defineProperty({content:i[h]||""},S,M.getRoleViaUser(i[S]));if(i[m]&&i[m].length>0){var a=ds.getImageData(i[m]);a.length>0&&(o[Q]=a);}return o;});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e,t){var _this$messages0;return _regenerator().w(function(_context167){while(1)switch(_context167.n){case 0:(_this$messages0=this.messages)!==null&&_this$messages0!==void 0?_this$messages0:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context167.a(2);}},_callee167,this);}));function callServiceAPI(_x307,_x308){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"parseMessage",value:function parseMessage(e){return e.split("\n").filter(function(t){return t.trim();}).map(function(t){return JSON.parse(t);});}},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){var n,s,i,o,_iterator9,_step9,l,a,c,_t65,_t66,_t67;return _regenerator().w(function(_context168){while(1)switch(_context168.p=_context168.n){case 0:if(!e[p]){_context168.n=1;break;}throw e[p].message;case 1:if(!e[h]){_context168.n=11;break;}i=this.parseMessage(e[h]),o=[];_iterator9=_createForOfIteratorHelper(i);_context168.p=2;_iterator9.s();case 3:if((_step9=_iterator9.n()).done){_context168.n=7;break;}l=_step9.value;_t65=(n=l.message)!=null&&n.tool_calls;if(!_t65){_context168.n=5;break;}_t66=o;_context168.n=4;return this.handleTools({tool_calls:l.message.tool_calls},t);case 4:_t66.push.call(_t66,_context168.v);case 5:o.push(_defineProperty({},h,((s=l.message)==null?void 0:s.content)||""));case 6:_context168.n=3;break;case 7:_context168.n=9;break;case 8:_context168.p=8;_t67=_context168.v;_iterator9.e(_t67);case 9:_context168.p=9;_iterator9.f();return _context168.f(9);case 10:a=o.map(function(l){return l[h];}),c=a.lastIndexOf(ds.THINK_END);return _context168.a(2,c===-1||t!=null&&t.think?_defineProperty({},h,a.join("")):_defineProperty(_defineProperty({},h,a.slice(c+1).join("")),"overwrite",!0));case 11:return _context168.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},h,e.message.content||""):_defineProperty({},h,""));}},_callee168,this,[[2,8,9,10]]);}));function extractResultData(_x309,_x310){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e,t){var n,s,_yield$this$callToolF6,i,o;return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context169.n=1;break;}throw Error(en);case 1:n=w(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:ae(a["function"].arguments)};});_context169.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF6=_context169.v;i=_yield$this$callToolF6.responses;o=_yield$this$callToolF6.processedResponse;if(!o){_context169.n=3;break;}return _context169.a(2,o);case 3:if(!(n.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},S,xt),"content","")),!i.find(function(_ref221){var a=_ref221.response;return _typeof(a)!==_e;})&&s.length===i.length)){_context169.n=4;break;}return _context169.a(2,(i.forEach(function(a,c){var d;var l=(d=e.tool_calls)==null?void 0:d[c];n==null||n.messages.push(_defineProperty(_defineProperty(_defineProperty({},S,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(bn);case 5:return _context169.a(2);}},_callee169,this);}));function handleTools(_x311,_x312){return _handleTools5.apply(this,arguments);}return handleTools;}()}],[{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t[y]===W;}).map(function(t){var s;return((s=t[T])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(M);ds.THINK_END="</think>";var Qi=ds;var $o=function $o(r){return _defineProperty({Authorization:"".concat(Ae).concat(r)},H,Y);},Th=function Th(r,e,t,n){var s=r;s[p]?s[p][y]===we||s[p][y]===et?n(ue):n(He):t(e);},jo=function jo(){return pe("https://api.x.ai/v1/models",he,Th);},fi=/*#__PURE__*/function(_M29){function fi(e){var _o$model12;var _this77;_classCallCheck(this,fi);var i,o;var t=e.directConnection,n=t==null?void 0:t.x;_this77=_callSuper(this,fi,[e,jo(),$o,n]),_this77.insertKeyPlaceholderText=_this77.genereteAPIKeyName("X"),_this77.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this77.url=fi.IMAGE_GENERATION_URL,_this77.permittedErrorPrefixes=[et,we];var s=(i=t==null?void 0:t.x)==null?void 0:i[Q];_typeof(s)===U&&Object.assign(_this77.rawBody,s),(_o$model12=(o=_this77.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="grok-imagine-image-quality";return _this77;}_inherits(fi,_M29);return _createClass(fi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=w(e);return n&&n!==""&&(s.prompt=n),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e,t){return _regenerator().w(function(_context170){while(1)switch(_context170.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context170.a(2);}},_callee170,this);}));function callServiceAPI(_x313,_x314){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(e){var t;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:if(!e[p]){_context171.n=1;break;}throw e[p].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},T,n.url),y,W):_defineProperty(_defineProperty({},T,"".concat(Vn).concat(n.b64_json)),y,W);});return _context171.a(2,_defineProperty({},m,t));}},_callee171);}));function extractResultData(_x315){return _extractResultData39.apply(this,arguments);}return extractResultData;}()}]);}(M);fi.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var er=fi;var Rh=function Rh(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},Ih=function Ih(r,e,t,n){var s=r;s[p]?s[p][y]===et?n(ue):n(He):t(e);},Mh=function Mh(){return pe("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",he,Ih);};var Sr=/*#__PURE__*/function(_M30){function Sr(e){var _this78$maxMessages,_o$model13;var _this78;_classCallCheck(this,Sr);var s,i,o;var n=w(e.directConnection).qwen;_this78=_callSuper(this,Sr,[e,Mh(),Rh,n]),_this78.insertKeyPlaceholderText=_this78.genereteAPIKeyName("Qwen"),_this78.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this78.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this78.permittedErrorPrefixes=["No static","The model",Ts],_typeof(n)===U&&_this78.completeConfig(n,(i=(s=e.directConnection)==null?void 0:s.qwen)==null?void 0:i.function_handler),(_this78$maxMessages=_this78.maxMessages)!==null&&_this78$maxMessages!==void 0?_this78$maxMessages:_this78.maxMessages=-1,(_o$model13=(o=_this78.rawBody).model)!==null&&_o$model13!==void 0?_o$model13:o.model="qwen-plus";return _this78;}_inherits(Sr,_M30);return _createClass(Sr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:Sr.getTextWImagesContent(i)},S,M.getRoleViaUser(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee172(e,t){var _this$messages1;return _regenerator().w(function(_context172){while(1)switch(_context172.n){case 0:(_this$messages1=this.messages)!==null&&_this$messages1!==void 0?_this$messages1:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context172.a(2);}},_callee172,this);}));function callServiceAPI(_x316,_x317){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e,t){var _n12;return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:if(!e[p]){_context173.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context173.n=3;break;}_n12=e.choices[0];if(!_n12.delta){_context173.n=2;break;}return _context173.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context173.n=3;break;}return _context173.a(2,_n12.message.tool_calls?this.handleToolsGeneric({tool_calls:_n12.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n12.message.content||""));case 3:return _context173.a(2,_defineProperty({},h,""));}},_callee173,this);}));function extractResultData(_x318,_x319){return _extractResultData40.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(e,t){return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:return _context174.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee174,this);}));function extractStreamResult(_x320,_x321){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()}]);}(M);var kh=function kh(r){return _defineProperty(_defineProperty({},le,"".concat(Ae).concat(r)),H,Y);},Lh=function Lh(r,e,t,n){var s=r;s[p]?s[p][y]===we?n(ue):n(He):t(e);},Ph=function Ph(){return pe("https://api.moonshot.ai/v1/models",he,Lh);};var xr=/*#__PURE__*/function(_M31){function xr(e){var _this79$maxMessages,_o$model14;var _this79;_classCallCheck(this,xr);var s,i,o;var n=w(e.directConnection).kimi;_this79=_callSuper(this,xr,[e,Ph(),kh,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("Kimi"),_this79.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this79.url="https://api.moonshot.ai/v1/chat/completions",_this79.permittedErrorPrefixes=[tn,"Not found"],_typeof(n)===U&&_this79.completeConfig(n,(i=(s=e.directConnection)==null?void 0:s.kimi)==null?void 0:i.function_handler),(_this79$maxMessages=_this79.maxMessages)!==null&&_this79$maxMessages!==void 0?_this79$maxMessages:_this79.maxMessages=-1,(_o$model14=(o=_this79.rawBody).model)!==null&&_o$model14!==void 0?_o$model14:o.model="moonshot-v1-8k";return _this79;}_inherits(xr,_M31);return _createClass(xr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:xr.getTextWImagesContent(i)},S,M.getRoleViaUser(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(e,t){var _this$messages10;return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:(_this$messages10=this.messages)!==null&&_this$messages10!==void 0?_this$messages10:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context175.a(2);}},_callee175,this);}));function callServiceAPI(_x322,_x323){return _callServiceAPI38.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee176(e,t){var _n13;return _regenerator().w(function(_context176){while(1)switch(_context176.n){case 0:if(!e[p]){_context176.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context176.n=3;break;}_n13=e.choices[0];if(!_n13.delta){_context176.n=2;break;}return _context176.a(2,this.extractStreamResult(_n13,t));case 2:if(!_n13.message){_context176.n=3;break;}return _context176.a(2,_n13.message.tool_calls?this.handleToolsGeneric({tool_calls:_n13.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n13.message.content||""));case 3:return _context176.a(2,_defineProperty({},h,""));}},_callee176,this);}));function extractResultData(_x324,_x325){return _extractResultData41.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee177(e,t){return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:return _context177.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee177,this);}));function extractStreamResult(_x326,_x327){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()}]);}(M);var Oh=/*#__PURE__*/function(_M32){function Oh(e){var _this80$maxMessages,_o$model15;var _this80;_classCallCheck(this,Oh);var i,o;var t=w(e.directConnection),n=t.x;_this80=_callSuper(this,Oh,[e,jo(),$o,n]),_this80.insertKeyPlaceholderText=_this80.genereteAPIKeyName("X"),_this80.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this80.url="https://api.x.ai/v1/responses",_this80.permittedErrorPrefixes=[et,we];var s=(i=t.x)==null?void 0:i.chat;_typeof(s)===U&&_this80.completeConfig(s),(_this80$maxMessages=_this80.maxMessages)!==null&&_this80$maxMessages!==void 0?_this80$maxMessages:_this80.maxMessages=-1,(_o$model15=(o=_this80.rawBody).model)!==null&&_o$model15!==void 0?_o$model15:o.model="grok-4.3";return _this80;}_inherits(Oh,_M32);return _createClass(Oh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:i[h]||""},S,M.getRoleViaUser(i[S]));});return n.input=s,this.systemMessage&&(n.instructions=this.systemMessage),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee178(e,t){return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context178.a(2);}},_callee178,this);}));function callServiceAPI(_x328,_x329){return _callServiceAPI39.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData42=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e){var t,n,s;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:if(!e[p]){_context179.n=1;break;}throw e[p].message;case 1:t=e;if(!(typeof t.type=="string"&&t.type.startsWith("response."))){_context179.n=2;break;}return _context179.a(2,t.type==="response.output_text.delta"?_defineProperty({},h,t.delta||""):_defineProperty({},h,""));case 2:n=e;if(!(n.object==="response"&&Array.isArray(n.output))){_context179.n=3;break;}s=n.output.filter(function(i){return i.type==="message";}).flatMap(function(i){return i.content||[];}).filter(function(i){return i.type==="output_text";}).map(function(i){return i.text||"";}).join("");return _context179.a(2,_defineProperty({},h,s));case 3:return _context179.a(2,_defineProperty({},h,""));}},_callee179);}));function extractResultData(_x330){return _extractResultData42.apply(this,arguments);}return extractResultData;}()}]);}(M);var Nh=function Nh(r){return _defineProperty(_defineProperty({},le,r===Oi?"":"".concat(Ae).concat(r)),H,Y);},Bh=function Bh(){},Dh=function Dh(){return pe("",he,Bh);};var Fh=/*#__PURE__*/function(_M33){function Fh(e){var _n$key,_this81$maxMessages,_i$model,_o$temperature,_a$max_tokens3;var _this81;_classCallCheck(this,Fh);var i,o,a;var n=w(e.directConnection).liteLLM,s=_typeof(n)===U?(_n$key=n.key)!==null&&_n$key!==void 0?_n$key:Oi:Oi;_this81=_callSuper(this,Fh,[e,Dh(),Nh,{key:s}]),_this81.url="http://localhost:4000/v1/chat/completions",_this81.permittedErrorPrefixes=[et,we],_typeof(n)===U&&_this81.completeConfig(n),(_this81$maxMessages=_this81.maxMessages)!==null&&_this81$maxMessages!==void 0?_this81$maxMessages:_this81.maxMessages=-1,(_i$model=(i=_this81.rawBody).model)!==null&&_i$model!==void 0?_i$model:i.model="gpt-4o-mini",(_o$temperature=(o=_this81.rawBody).temperature)!==null&&_o$temperature!==void 0?_o$temperature:o.temperature=1,(_a$max_tokens3=(a=_this81.rawBody).max_tokens)!==null&&_a$max_tokens3!==void 0?_a$max_tokens3:a.max_tokens=4096;return _this81;}_inherits(Fh,_M33);return _createClass(Fh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(i){return _defineProperty({content:i[h]||""},S,M.getRoleViaUser(i[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(e,t){return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context180.a(2);}},_callee180,this);}));function callServiceAPI(_x331,_x332){return _callServiceAPI40.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData43=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee181(e){var t;return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:if(!e[p]){_context181.n=1;break;}throw e[p].message;case 1:if(!(e.choices&&e.choices.length>0)){_context181.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context181.n=2;break;}return _context181.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context181.n=3;break;}return _context181.a(2,_defineProperty({},h,t.message.content));case 3:return _context181.a(2,_defineProperty({},h,""));}},_callee181);}));function extractResultData(_x333){return _extractResultData43.apply(this,arguments);}return extractResultData;}()}]);}(M);var Fs=/* @__PURE__ */function(r){return r.BLOCKING="blocking",r.STREAMING="streaming",r;}(Fs||{}),Mn=/* @__PURE__ */function(r){return r.MESSAGE="message",r.AGENT_MESSAGE="agent_message",r.WORKFLOW_FINISHED="workflow_finished",r.ERROR="error",r;}(Mn||{});var Uh="image/",Hh="data:",$h=function $h(r,e){return{type:e,transfer_method:"local_file",upload_file_id:r};},jh=function jh(r){var e=r.trim();if(!e.startsWith(Hh))return null;var t=e.replace(/^data:\s*/,"").trim();return t?JSON.parse(t):null;};function Gh(_x334,_x335){return _Gh.apply(this,arguments);}function _Gh(){_Gh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee200(r,e){var t,_e$headers,n,s,i,a,o;return _regenerator().w(function(_context200){while(1)switch(_context200.n){case 0:t=new FormData();t.append(ne,r),t.append(F,e[F]);_e$headers=e.headers;n=_e$headers[H];s=_objectWithoutProperties(_e$headers,[H].map(_toPropertyKey));_context200.n=1;return fetch(e.url,{method:ye,headers:s,body:t});case 1:i=_context200.v;if(i.ok){_context200.n=3;break;}_context200.n=2;return i.text();case 2:a=_context200.v;throw new Error(a);case 3:_context200.n=4;return i.json();case 4:o=_context200.v;if(o.id){_context200.n=5;break;}throw new Error("Upload response missing file ID");case 5:return _context200.a(2,o.id);}},_callee200);}));return _Gh.apply(this,arguments);}function zh(_x336,_x337){return _zh.apply(this,arguments);}function _zh(){_zh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee202(r,e){var t;return _regenerator().w(function(_context202){while(1)switch(_context202.n){case 0:if(!(r.length===0)){_context202.n=1;break;}return _context202.a(2,[]);case 1:t=r.map(/*#__PURE__*/function(){var _ref275=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee201(s){var i,o;return _regenerator().w(function(_context201){while(1)switch(_context201.n){case 0:_context201.n=1;return Gh(s,e);case 1:i=_context201.v;o=s[y].startsWith(Uh)?W:ne;return _context201.a(2,$h(i,o));}},_callee201);}));return function(_x368){return _ref275.apply(this,arguments);};}());_context202.n=2;return Promise.all(t);case 2:return _context202.a(2,_context202.v.filter(function(s){return s!==null;}));}},_callee202);}));return _zh.apply(this,arguments);}function qh(r,e){return r.conversation_id&&e(r.conversation_id),r.code&&r.message&&!r.answer?_defineProperty({},p,r.message):_defineProperty({},h,r.answer||"");}var Vh=function Vh(r,e,t){var n,s;switch(!e.conversationIdSet&&r.conversation_id&&(t(r.conversation_id),e.conversationIdSet=!0),r.event){case Mn.MESSAGE:case Mn.AGENT_MESSAGE:e.fullAnswer+=r.answer||"";break;case Mn.WORKFLOW_FINISHED:!e.fullAnswer&&(s=(n=r.data)==null?void 0:n.outputs)!=null&&s.answer&&(e.fullAnswer=r.data.outputs.answer);break;case Mn.ERROR:e.errorMessage=r.message||Mn.ERROR;break;}};function Kh(_x338,_x339){return _Kh.apply(this,arguments);}function _Kh(){_Kh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee203(r,e){var t,s,_iterator0,_step0,i,o;return _regenerator().w(function(_context203){while(1)switch(_context203.n){case 0:t={fullAnswer:"",conversationIdSet:!1,errorMessage:""};_context203.n=1;return r.text();case 1:s=_context203.v.split(/\r?\n\r?\n/);_iterator0=_createForOfIteratorHelper(s);try{for(_iterator0.s();!(_step0=_iterator0.n()).done;){i=_step0.value;o=jh(i);o&&Vh(o,t,e);}}catch(err){_iterator0.e(err);}finally{_iterator0.f();}return _context203.a(2,t.errorMessage?_defineProperty({},p,t.errorMessage):_defineProperty({},h,t.fullAnswer));}},_callee203);}));return _Kh.apply(this,arguments);}var Wh=function Wh(r){return _defineProperty(_defineProperty({},H,Y),le,"".concat(Ae).concat(r));},Xh=function Xh(r,e,t,n){var s=r;s[p]?s[p].message===gi?n(ue):n(He):"user_input_form"in r||"opening_statement"in r||"file_upload"in r?t(e):n(He);},Zh=function Zh(r){return pe("".concat(r,"/parameters"),he,Xh);};var Yh=/*#__PURE__*/function(_M34){function Yh(e){var _ref247,_this82$maxMessages;var _this82;_classCallCheck(this,Yh);var i;var t=w(e.directConnection),n=t==null?void 0:t.dify,s=(_ref247=(i=e.connect)==null?void 0:i.url)!==null&&_ref247!==void 0?_ref247:"https://api.dify.ai/v1";_this82=_callSuper(this,Yh,[e,Zh(s),Wh,n]),_this82.insertKeyPlaceholderText=_this82.genereteAPIKeyName("Dify"),_this82.keyHelpUrl="https://docs.dify.ai/en/use-dify/publish/developing-with-apis",_this82.permittedErrorPrefixes=[we],_this82._conversationId="",_this82._user=F,_this82._inputs={},_this82.url="".concat(s,"/chat-messages"),_this82._uploadUrl="".concat(s,"/").concat(m,"/upload"),_typeof(n)===U&&(n[F]&&(_this82._user=n[F]),n.inputs&&(_this82._inputs=n.inputs),_this82.completeConfig(n)),(_this82$maxMessages=_this82.maxMessages)!==null&&_this82$maxMessages!==void 0?_this82$maxMessages:_this82.maxMessages=-1,_this82._mode=_this82.stream?Fs.STREAMING:Fs.BLOCKING;return _this82;}_inherits(Yh,_M34);return _createClass(Yh,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var s=this.processMessages(t),i=s[s.length-1],o=(i==null?void 0:i[h])||" ",a=_defineProperty({inputs:this._inputs,query:o,response_mode:this._mode},F,this._user);return this._conversationId&&(a.conversation_id=this._conversationId),n&&n.length>0&&(a[m]=n),a;}},{key:"callServiceAPI",value:function(){var _callServiceAPI41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee182(e,t,n){var _this$messages11,_this83=this;var s,_t68;return _regenerator().w(function(_context182){while(1)switch(_context182.n){case 0:(_this$messages11=this.messages)!==null&&_this$messages11!==void 0?_this$messages11:this.messages=e;s=[];_t68=n&&n.length>0;if(!_t68){_context182.n=2;break;}_context182.n=1;return zh(n,_defineProperty(_defineProperty({url:this._uploadUrl},F,this._user),"headers",this.connectSettings.headers));case 1:s=_context182.v;case 2:this.callDirectServiceServiceAPI(e,t,function(i,o){return _this83.preprocessBody(i,o,s);});case 3:return _context182.a(2);}},_callee182,this);}));function callServiceAPI(_x340,_x341,_x342){return _callServiceAPI41.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData44=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee183(e){var _this84=this;var t;return _regenerator().w(function(_context183){while(1)switch(_context183.n){case 0:t=function t(n){_this84._conversationId=n;};return _context183.a(2,this._mode===Fs.BLOCKING&&!this.stream?qh(e,t):Kh(e,t));}},_callee183,this);}));function extractResultData(_x343){return _extractResultData44.apply(this,arguments);}return extractResultData;}()}]);}(M);var Jh=/*#__PURE__*/function(){function Jh(){_classCallCheck(this,Jh);}return _createClass(Jh,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
|
|
203
|
+
function create(e){var t=e.directConnection,n=e.connect,s=e.demo,i=e.webModel;if(i)return new Es(e);if(t){if(t.openAI)return t.openAI[Q]?new Yi(e):t.openAI.speechToText?new Ki(e):t.openAI.textToSpeech?new Vi(e):t.openAI.assistant?new gr(e):t.openAI.realtime?new qi(e):t.openAI.completions?new si(e):new ii(e);if(t.assemblyAI)return new br(e);if(t.cohere)return new oi(e);if(t.huggingFace)return t.huggingFace.textGeneration?new ml(e):t.huggingFace.summarization?new bl(e):t.huggingFace.translation?new El(e):t.huggingFace.fillMask?new _l(e):t.huggingFace.questionAnswer?new gl(e):t.huggingFace.audioSpeechRecognition?new fl(e):t.huggingFace.audioClassification?new dl(e):t.huggingFace.imageClassification?new ul(e):new yl(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new yr(e);if(t.azure.openAI.assistant)return new Gi(e);}if(t.azure.speechToText)return new Zi(e);if(t.azure.textToSpeech)return new Xi(e);if(t.azure.summarization)return new Wi(e);if(t.azure.translation)return new $l(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new Ys(e):t.stabilityAI.imageToImageUpscale?new Xs(e):t.stabilityAI.imageToImageMasking?new Zs(e):new Js(e);if(t.mistral)return new Er(e);if(t.gemini)return new vr(e);if(t.claude)return new Ji(e);if(t.deepSeek)return new ah(e);if(t.miniMax)return new dh(e);if(t.openRouter)return new ss(e);if(t.kimi)return new xr(e);if(t.x)return t.x[Q]?new er(e):new Oh(e);if(t.qwen)return new Sr(e);if(t.together)return t.together[Q]?new ql(e):t.together.textToSpeech?new Al(e):new Vl(e);if(t.bigModel)return t.bigModel[Q]?new jl(e):t.bigModel.textToSpeech?new Sl(e):new ri(e);if(t.groq)return t.groq.textToSpeech?new zl(e):new _r(e);if(t.perplexity)return new Ql(e);if(t.ollama)return new Qi(e);if(t.openWebUI)return new sh(e);if(t.dify)return new Yh(e);if(t.liteLLM)return new Fh(e);}return n&&Object.keys(n).length>0&&!s?new Sn(e):new Sn(e,void 0,s||!0);}}]);}();var hn=/*#__PURE__*/function(){function hn(){_classCallCheck(this,hn);}return _createClass(hn,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e,t){var n=e.fontFamily||t;if(n&&n!==hn.DEFAULT_FONT_FAMILY)return;var s=document.getElementsByTagName("head")[0];if(!Array.from(s.getElementsByTagName("link")).some(function(o){return o.getAttribute("href")===hn.FONT_URL;})){var o=x("link");o.rel="stylesheet",o.href=hn.FONT_URL,s.appendChild(o);}}}]);}();hn.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",hn.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var tr=hn;var Mr=/*#__PURE__*/_createClass(function Mr(){_classCallCheck(this,Mr);});Mr.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 nr=Mr;function P(r){return function(e,t){Object.defineProperty(e,t,{});var n=e.constructor,s=t.toLocaleLowerCase();n._attributes_[s]=nr.attibutes[r],n._attributeToProperty_[s]=t;};}var Qh="deep-chat-downwards-mode",ed="deep-chat-upwards-mode",Jn="submit-button",Ns="loading-button",Qn="disabled-button",to="text-input-container-start-adjustment",no="text-input-container-end-adjustment",so="text-input-container-start-small-adjustment",io="text-input-container-end-small-adjustment";var Ar=/*#__PURE__*/function(){function Ar(e){_classCallCheck(this,Ar);this._isDisplayed=!1,this._elementRef=this.createIntroPanelWithChild(e),this._isDisplayed=!0;}return _createClass(Ar,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e){var t=Ar.createIntroPanel();return e[E].display==="none"&&(e[E].display="block"),t.appendChild(e),t;}},{key:"hide",value:function hide(){this._isDisplayed&&(this._elementRef[E].display="none",this._isDisplayed=!1);}},{key:"display",value:function display(){this._isDisplayed||(this._elementRef[E].display="",this._isDisplayed=!0);}}],[{key:"createIntroPanel",value:function createIntroPanel(){var e=x();return e[f].add("intro-panel"),Object.assign(e[E]),e;}}]);}();var td="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n\t viewBox=\"50 30 420 450\" xml:space=\"preserve\">\n<g filter=\"brightness(0) saturate(100%) invert(16%) sepia(0%) saturate(1942%) hue-rotate(215deg) brightness(99%) contrast(93%)\">\n\t<g>\n\t\t<path d=\"M447.933,103.629c-0.034-3.076-1.224-6.09-3.485-8.352L352.683,3.511c-0.004-0.004-0.007-0.005-0.011-0.008\n\t\t\tC350.505,1.338,347.511,0,344.206,0H89.278C75.361,0,64.04,11.32,64.04,25.237v461.525c0,13.916,11.32,25.237,25.237,25.237\n\t\t\th333.444c13.916,0,25.237-11.32,25.237-25.237V103.753C447.96,103.709,447.937,103.672,447.933,103.629z M356.194,40.931\n\t\t\tl50.834,50.834h-49.572c-0.695,0-1.262-0.567-1.262-1.262V40.931z M423.983,486.763c0,0.695-0.566,1.261-1.261,1.261H89.278\n\t\t\tc-0.695,0-1.261-0.566-1.261-1.261V25.237c0-0.695,0.566-1.261,1.261-1.261h242.94v66.527c0,13.916,11.322,25.239,25.239,25.239\n\t\t\th66.527V486.763z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,164.014H149.912c-6.62,0-11.988,5.367-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.368,11.988-11.988C374.076,169.381,368.707,164.014,362.088,164.014z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,236.353H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.368,11.988-11.988C374.076,241.721,368.707,236.353,362.088,236.353z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,308.691H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.367,11.988-11.988C374.076,314.06,368.707,308.691,362.088,308.691z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M256,381.031H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988H256\n\t\t\tc6.62,0,11.988-5.367,11.988-11.988C267.988,386.398,262.62,381.031,256,381.031z\"/>\n\t</g>\n</g>\n</svg>",Ie=/*#__PURE__*/function(){function Ie(){_classCallCheck(this,Ie);}return _createClass(Ie,null,[{key:"createImage",value:function createImage(e,t){var n=new Image();return n[T]=e[T],t&&Se.scrollDownOnImageLoad(n[T],t),Se.processContent(W,n,n[T],e.name);}// WORK - image still does not scroll down when loaded
|
|
204
|
+
},{key:"createImageMessage",value:function createImageMessage(e,t,n,s,i){var o=e.createNewMessageElement("",n,s),a=!s&&i?e.scrollToFirstElement.bind(e,n,i):void 0,c=Ie.createImage(t,a);return o.bubbleElement.appendChild(c),o.bubbleElement[f].add(Ie.IMAGE_BUBBLE_CLASS),_defineProperty(_defineProperty({},y,W),"elements",o);}},{key:"createAudioElement",value:function createAudioElement(e,t){var n=x(G);return n[T]=e[T],n[f].add("audio-player"),n.controls=!0,ze.IS_SAFARI&&(n[f].add("audio-player-safari"),n[f].add(t===F?"audio-player-safari-end":"audio-player-safari-start")),n;}},{key:"autoPlayAudio",value:function autoPlayAudio(e){e.addEventListener("loadeddata",function(){e.play()["catch"](function(t){console.warn("Auto-play failed:",t);});});}},{key:"createNewAudioMessage",value:function createNewAudioMessage(e,t,n,s){var i=Ie.createAudioElement(t,n),o=e.createMessageElementsOnOrientation("",n,s);return o.bubbleElement.appendChild(i),o.bubbleElement[f].add(Ie.AUDIO_BUBBLE_CLASS),_defineProperty(_defineProperty(_defineProperty({},y,G),"elements",o),"audioElement",i);}},{key:"createAnyFile",value:function createAnyFile(e){var t=x();t[f].add("any-file-message-contents");var n=x();n[f].add("any-file-message-icon-container");var s=Ut.createSVGElement(td);s[f].add("any-file-message-icon"),n.appendChild(s);var i=x();return i[f].add("any-file-message-text"),i.textContent=e.name||ne,t.appendChild(n),t.appendChild(i),Se.processContent(gn,t,e[T],i.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,n,s){var i=e.createMessageElementsOnOrientation("",n,s),o=Ie.createAnyFile(t);return i.bubbleElement[f].add(Ie.ANY_FILE_BUBBLE_CLASS),i.bubbleElement.appendChild(o),_defineProperty(_defineProperty({},y,ne),"elements",i);}},{key:"createMessages",value:function createMessages(e,t,n,s){var i=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;return t.map(function(o,a){var c;if(o.ref&&(o=Se.removeFileRef(o)),Se.isAudioFile(o)){var l=Ie.createNewAudioMessage(e,o,n,i),d=(c=e.textToSpeech)==null?void 0:c.audio;return d&&(d.autoPlay&&Ie.autoPlayAudio(l.audioElement),typeof d.displayAudio=="boolean"&&!d.displayAudio)?void 0:l;}return Se.isImageFile(o)?Ie.createImageMessage(e,o,n,i,s&&a===0):Ie.createNewAnyFileMessage(e,o,n,i);}).filter(function(o){return o!==void 0;});}// no overwrite previous message logic as it is complex to track which files are to be overwritten
|
|
205
|
+
},{key:"addMessages",value:function addMessages(e,t,n,s,i){Ie.createMessages(e,t,n,s,i).filter(function(a){return a!==void 0;}).forEach(function(_ref251){var a=_ref251[y],c=_ref251.elements;Se.addMessage(e,c,a,n,i);});}}]);}();Ie.IMAGE_BUBBLE_CLASS="image-message",Ie.AUDIO_BUBBLE_CLASS="audio-message",Ie.ANY_FILE_BUBBLE_CLASS="any-file-message";var ai=Ie;var st=/*#__PURE__*/function(){function st(){_classCallCheck(this,st);}return _createClass(st,null,[{key:"removeElements",value:function removeElements(e,t){if(!t)return;var n=e.findIndex(function(s){return s===t;});e.splice(n,1),t==null||t.outerContainer.remove();}},{key:"removeFilesMessages",value:function removeFilesMessages(e,t){var n;(n=t[1][m])==null||n.forEach(function(s){st.removeElements(e.messageElementRefs,s);}),delete t[0][m],delete t[1][m];}},{key:"removeTextHTMLMessage",value:function removeTextHTMLMessage(e,t,n){var s=t[1][n];st.removeElements(e.messageElementRefs,s),delete t[0][n],delete t[1][n];}},{key:"updateHTMLMessage",value:function updateHTMLMessage(e,t,n){var s,i,o;if(t[1][L])wt.overwriteElements(e,n,t[1][L]);else{var a=wt.create(e,n,t[0][S]),c=((i=t[1][m])==null?void 0:i[((s=t[1][m])==null?void 0:s.length)-1])||t[1][h],l=c.outerContainer.nextSibling;(o=l==null?void 0:l.parentElement)==null||o.insertBefore(a.outerContainer,l),e.messageElementRefs.splice(e.messageElementRefs.length-1,1);var d=e.messageElementRefs.findIndex(function(u){return u===c;});e.messageElementRefs.splice(d+1,0,a),t[1][L]=a;}t[0][L]=n;}// finds beforeElement, creates new elements, remove old and adds new ones
|
|
206
|
+
},{key:"updateFileMessages",value:function updateFileMessages(e,t,n){var u,g;var s=t[0][S],i=ai.createMessages(e,n,s,!1),o=t[1][L],a=((g=t[1][m])==null?void 0:g[((u=t[1][m])==null?void 0:u.length)-1])||t[1][h],c=o||a;var l=e.messageElementRefs.findIndex(function(b){return b===c;});a&&(l+=1);var d=(o==null?void 0:o.outerContainer)||(a==null?void 0:a.outerContainer.nextSibling);i.forEach(function(_ref252,v){var b=_ref252.type,_=_ref252.elements;var C;Se.setElementProps(e,_,b,s),(C=d.parentElement)==null||C.insertBefore(_.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(l+v,0,_);}),st.removeFilesMessages(e,t),t[1][m]=i.map(function(_ref253){var b=_ref253.elements;return b;}),t[0][m]=n;}},{key:"updateTextMessage",value:function updateTextMessage(e,t,n){var s,i;if(t[1][h])e.renderText(t[1][h].bubbleElement,n,t[0][S]);else{var o=e.createElements(n,t[0][S]),a=((s=t[1][m])==null?void 0:s[0])||t[1][L];(i=a.outerContainer.parentElement)==null||i.insertBefore(o.outerContainer,a.outerContainer);var c=e.messageElementRefs.findIndex(function(l){return l===a;});e.messageElementRefs.splice(c,0,o),t[1][h]=o;}t[0][h]=n;}},{key:"isElementActive",value:function isElementActive(e){var t,n;return ot.isActiveElement((t=e[h])==null?void 0:t.bubbleElement[f])||ot.isActiveElement((n=e[L])==null?void 0:n.bubbleElement[f]);}// note that overwrite and 'deep-chat-temporary-message' are used to remove a message
|
|
207
|
+
},{key:"update",value:function update(e,t,n){var s=e.messageToElements[n];if(s){if(st.isElementActive(s[1]))return console[p]("Cannot update a message that is being streamed");t[h]&&st.updateTextMessage(e,s,t[h]),t[m]?st.updateFileMessages(e,s,t[m]):st.removeFilesMessages(e,s),t[L]&&st.updateHTMLMessage(e,s,t[L]),!t[h]&&s[1][h]&&st.removeTextHTMLMessage(e,s,h),!t[L]&&s[1][L]&&st.removeTextHTMLMessage(e,s,L);var i=e.messageElementRefs,o=e.avatar,a=e.name;B.classifyRoleMessages(i),B.resetAllRoleElements(i,o,a);}else console[p]("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var nd=/*#__PURE__*/function(){function nd(){_classCallCheck(this,nd);}return _createClass(nd,null,[{key:"getText",value:function getText(e,t){var n,s;if(!e.directConnection&&!e.connect&&!e.webModel&&!e.demo)return"Connect to any API using the [connect](".concat(X,"connect#connect-1) property or a popular service via [directConnection](").concat(X,"directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](").concat(X,"webModel).\n To get started checkout the [Start](https://deepchat.dev/start) page and live code [examples](https://deepchat.dev/examples/frameworks).\n To remove this message set the [demo](").concat(X,"modes#demo) property to true.");if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](".concat(X,"directConnection/#directConnection) object.");var i=(n=e.directConnection.openAI)==null?void 0:n.chat;if(_typeof(i)=="object"&&(s=i.tools)!=null&&s.find(function(o){return o[y]==="function";})&&!i.function_handler)return"Please define the `function_handler` property inside the openAI [chat](".concat(X,"directConnection/openAI#Chat) object.");}else if(e.connect&&!e.connect.url&&!e.connect.handler&&!e.webModel)return"Please define a `url` or a `handler` property inside the [connect](".concat(X,"connect#connect-1) object.");return null;}}]);}();var ot=/*#__PURE__*/function(_ct){function ot(e,t,n){var _this85;_classCallCheck(this,ot);var a,c;_this85=_callSuper(this,ot,[e]);var s=t.permittedErrorPrefixes,i=t.demo;_this85._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this85._onClearMessages=vn.onClearMessages.bind(_this85,e),_this85._onError=vn.onError.bind(_this85,e),_this85._isLoadingMessageAllowed=ot.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this85.setLoadingToggle.bind(_this85)),_this85._permittedErrorPrefixes=s,_this85.addSetupMessageIfNeeded(e,t)||_this85.populateIntroPanel(n),i&&_this85.prepareDemo(ce.processDemo(i),e.loadHistory),_this85.addIntroductoryMessages(e,t);var o=new bs(e,_this85,t);_this85._displayServiceErrorMessages=(c=e.errorMessages)==null?void 0:c.displayServiceErrorMessages,e.getMessages=function(){return B.deepCloneMessagesWithReferences(_this85.messageToElements.map(function(_ref254){var _ref255=_slicedToArray(_ref254,1),l=_ref255[0];return l;}));},e.clearMessages=_this85.clearMessages.bind(_this85,t),e.refreshMessages=_this85.refreshTextMessages.bind(_this85,e.remarkable),e.scrollToBottom=q.scrollToBottom.bind(_this85,_this85),e.addMessage=function(l,d){_this85.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(l,d){return st.update(_this85,l,d);},t.isWebModel()&&t.setUpMessages(_this85),e.textToSpeech&&Un.processConfig(e.textToSpeech,function(l){_this85.textToSpeech=l;}),_this85.elementRef.onscroll=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee184(){var l,d;return _regenerator().w(function(_context184){while(1)switch(_context184.n){case 0:e.loadHistory&&o.loadHistoryOnScroll(e.loadHistory),(l=_this85.scrollButton)==null||l.updateScroll(),(d=_this85.browserStorage)!=null&&d.trackScrollHeight&&_this85.browserStorage.addScrollHeight(_this85.elementRef.scrollTop);case 1:return _context184.a(2);}},_callee184);}));return _this85;}_inherits(ot,_ct);return _createClass(ot,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1],n=ct.isLoadingMessage(t);if(!e&&n)this.removeLastMessage(),delete this._activeLoadingConfig;else{if(this._activeLoadingConfig&&n){var s=re.getTargetWrapper(t.bubbleElement);if(s)return this._activeLoadingConfig=e||{},this.updateLoadingMessage(s);this.removeLastMessage();}this._activeLoadingConfig=e||{},this.addLoadingMessage(!0);}}},{key:"prepareDemo",value:function prepareDemo(e,t){var n;if(_typeof(e)=="object"){if(!t&&e.displayLoading){var s=e.displayLoading.history;s!=null&&s.small&&Ft.addMessage(this,!1),s!=null&&s.full&&Ft.addMessage(this);}e.displayErrors&&(e.displayErrors[A]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage(oe,""),e.displayErrors.speechToText&&this.addNewErrorMessage("speechToText","")),(n=e.displayLoading)!=null&&n.message&&this.addLoadingMessage(),e.response&&(this.customDemoResponse=e.response);}}},{key:"addSetupMessageIfNeeded",value:function addSetupMessageIfNeeded(e,t){var n=nd.getText(e,t);if(n){var s=this.createAndAppendNewMessageElement(n,te);this.applyCustomStyles(s,te,!1);}return!!n;}// WORK - const file for deep chat classes
|
|
208
|
+
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this86=this;e!=null&&e.shadowRoot&&(this._introMessage=e.introMessage);var n=this._introMessage;t!=null&&t.isWebModel()&&(n!==null&&n!==void 0?n:n=t.getIntroMessage(n));var s=!(e!=null&&e.history)&&!!(e!=null&&e.loadHistory||t!=null&&t.fetchHistory);n&&(Array.isArray(n)?n.forEach(function(i,o){if(o!==0){var a=_this86.messageElementRefs[_this86.messageElementRefs.length-1].innerContainer;B.hideRoleElements(a,_this86.avatar,_this86.name);}_this86.addIntroductoryMessage(i,s);}):this.addIntroductoryMessage(n,s));}},{key:"addIntroductoryMessage",value:function addIntroductoryMessage(e,t){var s;var n;return e!=null&&e[h]?n=this.createAndAppendNewMessageElement(e[h],te):e!=null&&e[L]&&(n=wt.add(this,e[L],te)),n&&(this.applyCustomStyles(n,te,!1,(s=this.messageStyles)==null?void 0:s.intro),n.outerContainer[f].add(ct.INTRO_CLASS),t&&(n.outerContainer[E].display="none")),n;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer[f].contains(ct.INTRO_CLASS)&&(e.outerContainer.remove(),this.messageElementRefs.shift());}},{key:"addAnyMessage",value:function addAnyMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;return e[p]?this.addNewErrorMessage(oe,e[p],n):this.addNewMessage(e,t,n);}},{key:"tryAddTextMessage",value:function tryAddTextMessage(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var i=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;e[h]!==void 0&&n[h]!==null&&(this.addNewTextMessage(e[h],e[S],t,i),!s&&this.textToSpeech&&e[S]!==F&&Un.speak(e[h],this.textToSpeech));}},{key:"tryAddFileMessages",value:function tryAddFileMessages(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;e[m]&&Array.isArray(e[m])&&ai.addMessages(this,e[m],e[S],t,n);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e[L]!==void 0&&e[L]!==null){var s=wt.add(this,e[L],e[S],t,n);!n&&At.isElementTemporary(s)&&delete e[L];}}// this should not be activated by streamed messages
|
|
209
|
+
},{key:"addNewMessage",value:function addNewMessage(e){var _this87=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var c,l,d,u;e[S]!==F&&((c=this._hiddenAttachments)==null||c.removeHiddenFiles());var s=ot.createMessageContent(e),i=(d=(l=this.textToSpeech)==null?void 0:l.audio)==null?void 0:d.displayText;typeof i=="boolean"&&!i&&delete s[h];var o=q.isScrollbarAtBottomOfElement(this.elementRef),a={status:e.overwrite};return n?(this.tryAddFileMessages(s,o,n),this.tryAddHTMLMessage(s,a,n),this.tryAddTextMessage(s,a,e,t,n)):(this.tryAddTextMessage(s,a,e,t,n),this.tryAddHTMLMessage(s,a,n),this.tryAddFileMessages(s,o,n)),this.isValidMessageContent(s)&&!n&&(this.updateStateOnMessage(s,e.overwrite,e.sendUpdate,t),a.status||setTimeout(function(){return _this87.scrollToFirstElement(s[S],o);}),t||(u=this.browserStorage)==null||u.addMessages(this.messageToElements.map(function(_ref257){var _ref258=_slicedToArray(_ref257,1),g=_ref258[0];return g;})),this.scrollButton&&s[S]!==F&&this.tryUpdateHiddenMessageCount(t,e)),this._activeLoadingConfig&&this.addLoadingMessage(!1),s;}},{key:"tryUpdateHiddenMessageCount",value:function tryUpdateHiddenMessageCount(e,t){var _this88=this;(!e||t.sendUpdate!==void 0)&&setTimeout(function(){var n,s;return(s=(n=_this88.scrollButton)==null?void 0:n.updateHidden)==null?void 0:s.call(n);});}},{key:"isValidMessageContent",value:function isValidMessageContent(e){return e[h]||e[L]||e[m]&&e[m].length>0;}},{key:"updateStateOnMessage",value:function updateStateOnMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(!t){var i=B.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,i]);}n&&this.sendClientUpdate(e,s);}// prettier-ignore
|
|
210
|
+
},{key:"removeMessageOnError",value:function removeMessageOnError(){var e=this.messageElementRefs[this.messageElementRefs.length-1],t=e==null?void 0:e.bubbleElement;(t!=null&&t[f].contains(bt.MESSAGE_CLASS)&&t.textContent===""||ot.isTemporaryElement(e))&&this.removeLastMessage();}// prettier-ignore
|
|
211
|
+
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this89=this;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var l,d,u,g,b,_;(l=this._hiddenAttachments)==null||l.readdHiddenFiles(),this.removeMessageOnError();var s=this.getPermittedMessage(t)||((d=this._errorMessageOverrides)==null?void 0:d[e])||((u=this._errorMessageOverrides)==null?void 0:u[A])||"Error, please try again.",i=this.createMessageElementsOnOrientation(s,p,n);B.hideRoleElements(i.innerContainer,this.avatar,this.name);var o=i.bubbleElement,a=i.outerContainer;o[f].add(zs),this.renderText(o,s);var c=Be.extractParticularSharedStyles(["fontSize","fontFamily"],(g=this.messageStyles)==null?void 0:g[A]);Be.applyCustomStylesToElements(i,!1,c),Be.applyCustomStylesToElements(i,!1,(b=this.messageStyles)==null?void 0:b[p]),n||this.appendOuterContainerElemet(a),this.textToSpeech&&Un.speak(s,this.textToSpeech),(_=this._onError)==null||_.call(this,s),setTimeout(function(){return q.scrollToBottom(_this89);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=ot.extractErrorMessages(e);for(var _n14=0;_n14<t.length;_n14+=1){var s=t[_n14];if(_typeof(s)===_e){if(this._displayServiceErrorMessages)return s;if(this._permittedErrorPrefixes){var i=ot.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,s);if(i)return i;}}}}}},{key:"removeError",value:function removeError(){this.isLastMessageError()&&B.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:te;var n=this.createMessageElements("",t),s=n.bubbleElement;n.bubbleElement[f].add(St.DOTS_CONTAINER_CLASS);var i=x();return i[f].add("loading-message-dots"),s.appendChild(i),St.setDots(s,e),n;}// prettier-ignore
|
|
212
|
+
},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,c,l,d,u,g;if(ct.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((a=this._activeLoadingConfig)==null?void 0:a[S])||te,n=((c=this._activeLoadingConfig)==null?void 0:c[E])||((d=(l=this.messageStyles)==null?void 0:l.loading)==null?void 0:d.message),s=n==null?void 0:n[L],i=s?wt.createElements(this,s,t,!1):this.addDefaultLoadingMessage(n,t);this.appendOuterContainerElemet(i.outerContainer),i.bubbleElement[f].add(St.BUBBLE_CLASS),this.applyCustomStyles(i,t,!1,n==null?void 0:n[R]),(g=(u=this.avatar)==null?void 0:u.getAvatarContainer(i.innerContainer))==null||g[f].add("loading-avatar-container"),!this.focusMode&&q.isScrollbarAtBottomOfElement(this.elementRef)&&q.scrollToBottom(this);}// this is a special method not to constantly refresh loading animations
|
|
213
|
+
},{key:"updateLoadingMessage",value:function updateLoadingMessage(e){var s;var t=(s=this._activeLoadingConfig)==null?void 0:s[E],n=t==null?void 0:t[L];e.innerHTML=n||"";}},{key:"populateIntroPanel",value:function populateIntroPanel(e){e&&(this._introPanel=new Ar(e),re.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee185(e,t){return _regenerator().w(function(_context185){while(1)switch(_context185.n){case 0:return _context185.a(2,(this._hiddenAttachments=t,Promise.all((e||[]).map(function(n){return new Promise(function(s){if(!n[y]||n[y]===gn){var i=n[ne].name||ne;s(_defineProperty(_defineProperty({name:i},y,gn),"ref",n[ne]));}else{var _i9=new FileReader();_i9.readAsDataURL(n[ne]),_i9.onload=function(){var o=n[ne].name;s(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},T,_i9.result),"name",o),y,n[y]),"ref",n[ne]));};}});}))));}},_callee185,this);}));function addMultipleFiles(_x344,_x345){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
|
|
214
|
+
function clearMessages(e,t){var _this$messageToElemen2;var i,o,a,c;var n=[];this.messageElementRefs.forEach(function(l){ot.isActiveElement(l.bubbleElement[f])?n.push(l):l.outerContainer.remove();}),Array.from(this.elementRef.children).forEach(function(l){var u;var d=(u=l.children[0])==null?void 0:u.children[0];d!=null&&d[f].contains(zs)&&l.remove();}),this.messageElementRefs=n;var s=this.messageToElements.filter(function(l){return l[1][h]&&ot.isActiveElement(l[1][h].bubbleElement[f])||l[1][L]&&ot.isActiveElement(l[1][L].bubbleElement[f]);});(_this$messageToElemen2=this.messageToElements).splice.apply(_this$messageToElemen2,[0,this.messageToElements.length].concat(_toConsumableArray(s))),t!==!1&&((i=this._introPanel)!=null&&i._elementRef&&this._introPanel.display(),this.addIntroductoryMessages()),(o=this.browserStorage)==null||o.clear(),(a=this.scrollButton)==null||a.clearHidden(),(c=this._onClearMessages)==null||c.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref259;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===U?!1:!!e.displayLoadingBubble:(_ref259=_typeof(e.displayLoadingBubble)===U||e.displayLoadingBubble)!==null&&_ref259!==void 0?_ref259:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _n15=0;_n15<e.length;_n15+=1)if(t.startsWith(e[_n15]))return t;}},{key:"extractErrorMessages",value:function extractErrorMessages(e){return Array.isArray(e)?e:e instanceof Error?[e.message]:typeof e=="string"?[e]:_typeof(e)=="object"&&e[p]?[e[p]]:[];}},{key:"isActiveElement",value:function isActiveElement(e){return e?e.contains(St.BUBBLE_CLASS)||e.contains(Ft.CLASS)||e.contains(bt.MESSAGE_CLASS):!1;}}]);}(ct);var is=/*#__PURE__*/function(){function is(){_classCallCheck(this,is);}return _createClass(is,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t[jn].length>0&&e[f].add("text-input-inner-start-adjustment"),t[vt].length>0&&e[f].add("text-input-inner-end-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,n){n[ve].length===0&&n[Pe].length>0?(e[0][f].add(so),t[f].add(so)):n[Pe].length===0&&n[ve].length>0&&(e[3][f].add(io),t[f].add(io));}// when submit is the only button
|
|
215
215
|
// when submit button is outside by itself - we increase the height for a better look
|
|
216
|
-
},{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,n){if(!(n[
|
|
217
|
-
},{key:"set",value:function set(e,t,n,s){!!is.adjustOutsideSubmit(t,n,s)||is.adjustForOutsideButton(t,n,s),is.adjustInputPadding(e,s);}}]);}();var
|
|
218
|
-
function me(e,t,n,s){var
|
|
219
|
-
},{key:"setDropupItem",value:function setDropupItem(e,t){this._menu=e,this.elementRef=t,this._originalElementRef=t.cloneNode(!0),this.changeState(this._state,!0);}},{key:"genStateInnerElements",value:function genStateInnerElements(e,t,n,s){var c,l,d,u;var
|
|
220
|
-
},{key:"focusSiblingItem",value:function focusSiblingItem(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var
|
|
221
|
-
},{key:"addWindowEvents",value:function addWindowEvents(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener(
|
|
222
|
-
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var n,s,
|
|
223
|
-
function addToDropup(e,t,n,s){var
|
|
224
|
-
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=
|
|
225
|
-
},{key:"addButtons",value:function addButtons(e,t,n,s){var r=Be.generatePositionToButtons(t);return Be.addToSideContainer(e,r),r[it].length>0&&Be.addToDropup(e,r,n,s),r;}}]);}();var sd="<?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>",id="<?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",rd="<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>",od="<?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",ad=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},ee,{id:"upload-images-icon",svgString:id,dropupText:"Image"}),Bn,{id:"upload-gifs-icon",svgString:od,dropupText:"GIF"}),q,{id:"upload-audio-icon",svgString:rd,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:sd,dropupText:"File"});var _i=/*#__PURE__*/function(_wn4){function _i(e){var _this98;_classCallCheck(this,_i);(e==null?void 0:e.position)===it&&(e.position=ve);var t=bt.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this98=_callSuper(this,_i,[_i.createMicrophoneElement(),No,e==null?void 0:e.position,t,e]),_this98.isActive=!1,_this98._innerElements=_this98.createInnerElementsForStates(_this98.customStyles),_this98.changeToDefault();return _this98;}_inherits(_i,_wn4);return _createClass(_i,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},A,this.createInnerElements(t,A,e)),j,this.createInnerElements(t,j,e)),Zn,this.createInnerElements(t,Zn,e)),Cn,this.createInnerElements(t,Cn,e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements[j]),this.toggleIconFilter(j),this.reapplyStateStyle(j,[A,Cn]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[A]),this.toggleIconFilter(A),this.reapplyStateStyle(A,[j,Cn]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements[Cn]),this.toggleIconFilter("command"),this.reapplyStateStyle(Cn,[j]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements[Zn]),this.elementRef[f].add("".concat(Zn,"-microphone")),this.reapplyStateStyle(Zn,[j]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()===G)switch(e){case A:t[f].remove("active-microphone-icon","command-microphone-icon"),t[f].add("default-microphone-icon");break;case j:t[f].remove("default-microphone-icon","command-microphone-icon"),t[f].add("active-microphone-icon");break;case"command":t[f].remove("active-microphone-icon","default-microphone-icon"),t[f].add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=x();return e.id="microphone-button",e[f].add("input-button"),e;}}]);}(wn);var Ds=/*#__PURE__*/function(){function Fs(){_classCallCheck(this,Fs);}return _createClass(Fs,null,[{key:"capitalize",value:function capitalize(e){return e.replace(Fs.FIRST_CHAR_REGEX,function(t){return t.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(e){return e.replace(Fs.DOUBLE_LINE,"<p></p>").replace(Fs.ONE_LINE,"<br>");}},{key:"isCharDefined",value:function isCharDefined(e){return e!==void 0&&e!==" "&&e!==" "&&e!=="\n"&&e!=="";}},{key:"breakupIntoWordsArr",value:function breakupIntoWordsArr(e){return e.split(/(\W+)/);}}]);}();Ds.FIRST_CHAR_REGEX=/\S/,Ds.DOUBLE_LINE=/\n\n/g,Ds.ONE_LINE=/\n/g;var ot=Ds;var tr=/*#__PURE__*/function(){function tr(){_classCallCheck(this,tr);}return _createClass(tr,null,[{key:"translate",value:function translate(e,t){var n=ot.breakupIntoWordsArr(e);for(var s=0;s<n.length;s+=1)t[n[s]]&&(n[s]=t[n[s]]);return n.join("");}}]);}();var ro=/*#__PURE__*/function(){function ro(){_classCallCheck(this,ro);}return _createClass(ro,null,[{key:"extract",value:function extract(e,t,n){var s="";for(var r=e.resultIndex;r<e.results.length;++r){var o=e.results[r][0].transcript;n&&(o=tr.translate(o,n)),e.results[r].isFinal?t+=o:s+=o;}return{interimTranscript:s,finalTranscript:t,newText:s||t};}},{key:"extractSafari",value:function extractSafari(e,t,n){var s="";for(var r=e.resultIndex;r<e.results.length;++r){var o=e.results[r][0].transcript;n&&(o=tr.translate(o,n)),s+=o;}return{interimTranscript:"",finalTranscript:s,newText:s};}}]);}();var es=/*#__PURE__*/_createClass(function es(){_classCallCheck(this,es);});es.IS_SAFARI=function(){return es._IS_SAFARI===void 0&&(es._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),es._IS_SAFARI;};var Es=es;var $o=/*#__PURE__*/function(){function Et(){_classCallCheck(this,Et);}return _createClass(Et,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(e,t){return Array.isArray(e)?e.find(function(n){return t===n;}):t===e?e:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(e){var _this99=this;e.element&&Et.getElementIfFocusedOnAvailable(e.element,document.activeElement)&&(Et.KEY_DOWN_TIMEOUT!==null&&clearTimeout(Et.KEY_DOWN_TIMEOUT),Et.KEY_DOWN_TIMEOUT=setTimeout(function(){Et.KEY_DOWN_TIMEOUT=null,_this99.resetRecording(e);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(e,t){this.mouseDownElement=Et.getElementIfFocusedOnAvailable(e,t.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(e){this.mouseDownElement&&this.resetRecording(e),this.mouseDownElement=void 0;}},{key:"add",value:function add(e,t){var n=(t==null?void 0:t.insertInCursorLocation)===void 0||(t==null?void 0:t.insertInCursorLocation);t!=null&&t.element&&n&&(e.mouseDownEvent=Et.mouseDownWindow.bind(e,t.element),document.addEventListener("mousedown",e.mouseDownEvent),e.mouseUpEvent=Et.mouseUpWindow.bind(e,t),document.addEventListener("mouseup",e.mouseUpEvent),e.keyDownEvent=Et.keyDownWindow.bind(e,t),document.addEventListener("keydown",e.keyDownEvent));}},{key:"remove",value:function remove(e){document.removeEventListener("mousedown",e.mouseDownEvent),document.removeEventListener("mouseup",e.mouseUpEvent),document.removeEventListener("keydown",e.keyDownEvent);}}]);}();$o.KEY_DOWN_TIMEOUT=null;var oo=$o;var cd=/*#__PURE__*/function(){function cd(){_classCallCheck(this,cd);}return _createClass(cd,null,[{key:"process",value:function process(e,t,n,s,r){var o=s==null?void 0:s(t,n);return o?(setTimeout(function(){o.restart?e.resetRecording(r):o.stop&&e.stop();}),(o.stop||o.restart)&&o.removeNewText):!1;}}]);}();var Yt=/*#__PURE__*/function(){function Yt(){_classCallCheck(this,Yt);}return _createClass(Yt,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(e,t){t&&!e.isCursorAtEnd&&(e.endPadding="",e.scrollingSpan.innerHTML=" ");}},{key:"scrollGeneric",value:function scrollGeneric(e,t){e.isCursorAtEnd?t.scrollTop=t.scrollHeight:e.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
|
|
216
|
+
},{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,n){if(!(n[jn].length>0||n[vt].length>0)){if(n[ve].length===0&&n[Pe].length>0)return e[0][f].add(to),t[f].add(to),n[Pe].map(function(s){return s.button.elementRef[f].add("submit-button-enlarged");});if(n[Pe].length===0&&n[ve].length>0)return e[3][f].add(no),t[f].add(no),n[ve].map(function(s){return s.button.elementRef[f].add("submit-button-enlarged");});}}// prettier-ignore
|
|
217
|
+
},{key:"set",value:function set(e,t,n,s){!!is.adjustOutsideSubmit(t,n,s)||is.adjustForOutsideButton(t,n,s),is.adjustInputPadding(e,s);}}]);}();var qn=/*#__PURE__*/function(){function qn(){_classCallCheck(this,qn);}return _createClass(qn,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var n=x();return n[f].add("input-button-container"),(t===0||t===3)&&n[f].add("outer-button-container"),(t===1||t===2)&&n[f].add("inner-button-container"),n;});}},{key:"add",value:function add(e,t){e.insertBefore(t[1],e.firstChild),e.insertBefore(t[0],e.firstChild),e.appendChild(t[2]),e.appendChild(t[3]);}},{key:"getContainerIndex",value:function getContainerIndex(e){return e===Pe?0:e===jn?1:e===vt?2:3;}},{key:"addButton",value:function addButton(e,t,n){t[f].add(n);var s=qn.getContainerIndex(n);e[s].appendChild(t),s===3&&t[f].add(ve);}}]);}();var ro=["camera","gifs","images","audio","mixedFiles",lt,"microphone"],sd="<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 22 22\" fill=\"none\">\n <rect x=\"2.5\" y=\"2.5\" width=\"17\" height=\"17\" rx=\"2\" stroke=\"#000000\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>\n",Me=/*#__PURE__*/function(){function Me(){_classCallCheck(this,Me);}return _createClass(Me,null,[{key:"addHighlightEvents",value:function addHighlightEvents(e,t){t.addEventListener(Cs,function(n){e.highlightedItem=n.target;}),t.addEventListener(yn,function(){e.highlightedItem=void 0;});}},{key:"addItemEvents",value:function addItemEvents(e,t,n,s){Nt.add(t,s),t.addEventListener(Z,function(){n[Z]();}),Me.addHighlightEvents(e,t);}},{key:"createItemText",value:function createItemText(e,t){var n=x();return Object.assign(n[E],t),n[f].add(Me.TEXT_CLASS),n.textContent=e||"File",n;}},{key:"createItemIcon",value:function createItemIcon(e,t){var n=x();return Object.assign(n[E],t),n[f].add(Me.ICON_CLASS),n.appendChild(e),n;}},{key:"populateItem",value:function populateItem(e,t,n){var s=e.elementRef,i=e.dropupText,o=e.svg,a=e.customStyles,c=s.children[0],l=a&&Object.values(a).find(function(d){var u;return((u=d[z])==null?void 0:u.content)==="";});c[f].contains(Tt.INPUT_BUTTON_INNER_TEXT_CLASS)?(l||t.appendChild(Me.createItemIcon(o,n==null?void 0:n.iconContainer)),t.appendChild(Me.createItemText(c.textContent,n==null?void 0:n[h]))):(l||t.appendChild(Me.createItemIcon(s.children[0],n==null?void 0:n.iconContainer)),t.appendChild(Me.createItemText(i,n==null?void 0:n[h])));}},{key:"createItem",value:function createItem(e,t,n){var o;var s=x();Object.assign(s[E],(o=n==null?void 0:n.item)==null?void 0:o[A]),Me.populateItem(t,s,n),s[f].add(Me.MENU_ITEM_CLASS),s.tabIndex=0;var i=t.elementRef;if(t.isCustom)t.setDropupItem(e,s);else{var a=de.processStateful((n==null?void 0:n.item)||{});Me.addItemEvents(e,s,i,a);}return s;}}]);}();Me.MENU_ITEM_CLASS="dropup-menu-item",Me.CUSTOM_BUTTON_ITEM_CLASS="dropup-menu-item-custom-button",Me.TEXT_CLASS="dropup-menu-item-text",Me.ICON_CLASS="dropup-menu-item-icon";var mt=Me;var me=/*#__PURE__*/function(_Cn2){// prettier-ignore
|
|
218
|
+
function me(e,t,n,s){var _this90;_classCallCheck(this,me);var c,l,d,u,g,b;var i=((u=(d=(l=(c=e==null?void 0:e[R])==null?void 0:c.button)==null?void 0:l[A])==null?void 0:d[h])==null?void 0:u.content)||"Custom ".concat(t),o=sd,a=yt.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this90=_callSuper(this,me,[me.createButtonElement(),o,e==null?void 0:e.position,a,((g=e==null?void 0:e[R])==null?void 0:g.button)||a&&{},i]),_this90._state=A,_this90.isCustom=!0,_this90._innerElements=_this90.createInnerElementsForStates(_this90.customStyles),_this90._menuStyles=s,_this90._onClick=e.onClick,_this90._dropupStyles=(b=e[R])==null?void 0:b.dropup,_this90.setSetState(e),_this90.addClickListener(n),_this90.changeState(e.initialState,!0);return _this90;}_inherits(me,_Cn2);return _createClass(me,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="custom-icon",n=this.createInnerElements(t,A,e);return _defineProperty(_defineProperty(_defineProperty({},A,n),$,this.genStateInnerElements(t,$,n,e)),j,this.genStateInnerElements(t,j,n,e));}},{key:"setSetState",value:function setSetState(e){var _this91=this;e.setState=function(t){t===A&&_this91.changeToDefault(),t===$&&_this91.changeToActive(),t===j&&_this91.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this92=this;q.assignButtonEvents(this.elementRef,function(){var n;var t=(n=_this92._onClick)==null?void 0:n.call(_this92,_this92._state);e==null||e(),(t===A||t===$||t===j)&&_this92.changeState(t);});}},{key:"changeState",value:function changeState(e,t){e===j?this.changeToDisabled(t):e===$?this.changeToActive(t):this.changeToDefault(t);}},{key:"applyDropupContentStyles",value:function applyDropupContentStyles(e){var t=Array.from(this.elementRef.children);if(e!=null&&e[h]){var _n16=t.find(function(s){return s[f].contains(mt.TEXT_CLASS);});_n16&&Object.assign(_n16[E],e[h]);}if(e!=null&&e.iconContainer){var _n17=t.find(function(s){return s[f].contains(mt.ICON_CLASS);});_n17&&Object.assign(_n17[E],e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var n,s,i;this.elementRef=re.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((n=e==null?void 0:e[z])==null?void 0:n.content)===""||this.elementRef.appendChild(mt.createItemIcon(this[z],(s=this._menuStyles)==null?void 0:s.iconContainer)),this.elementRef.appendChild(mt.createItemText(this.dropupText,(i=this._menuStyles)==null?void 0:i[h]));}},{key:"assignDropupItemStyle",value:function assignDropupItemStyle(e,t){var s;this.elementRef.parentElement&&this._originalElementRef&&this.resetDropupItem(t),mt.addHighlightEvents(this._menu,this.elementRef),this.applyDropupContentStyles(e),Object.assign(this.elementRef[E],(s=e==null?void 0:e.item)==null?void 0:s[A]);var n=de.processStateful((e==null?void 0:e.item)||{});Nt.add(this.elementRef,n),this.addClickListener();}},{key:"changeToDefault",value:function changeToDefault(e){var t,n,s,i,o,a;!e&&this._state===A||(this.elementRef[f].contains(mt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[A],(n=this.customStyles)==null?void 0:n[A]):(this.changeElementsByState(this._innerElements[A]),(s=this.customStyles)!=null&&s[$]&&xe.unsetAllCSS(this.elementRef,(i=this.customStyles)==null?void 0:i[$]),(o=this.customStyles)!=null&&o[j]&&xe.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[j]),this.reapplyStateStyle(A,[$,j])),this.elementRef[f].remove(me.DISABLED_CONTAINER_CLASS,me.ACTIVE_CONTAINER_CLASS),this.elementRef[f].add(me.DEFAULT_CONTAINER_CLASS),ge.removeAriaDisabled(this.elementRef),this._state=A);}},{key:"changeToActive",value:function changeToActive(e){var t,n;!e&&this._state===$||(this.elementRef[f].contains(mt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[$],(n=this.customStyles)==null?void 0:n[$]):(this.changeElementsByState(this._innerElements[$]),this.reapplyStateStyle($,[j,A])),this.elementRef[f].remove(me.DISABLED_CONTAINER_CLASS,me.DEFAULT_CONTAINER_CLASS),this.elementRef[f].add(me.ACTIVE_CONTAINER_CLASS),ge.removeAriaDisabled(this.elementRef),this._state=$);}},{key:"changeToDisabled",value:function changeToDisabled(e){var t,n,s,i,o,a;!e&&this._state===j||(this.elementRef[f].contains(mt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[j],(n=this.customStyles)==null?void 0:n[j]):(this.changeElementsByState(this._innerElements[j]),(s=this.customStyles)!=null&&s[$]&&xe.unsetAllCSS(this.elementRef,(i=this.customStyles)==null?void 0:i[$]),(o=this.customStyles)!=null&&o[A]&&xe.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[A]),this.reapplyStateStyle(j,[A,$])),this.elementRef[f].remove(me.ACTIVE_CONTAINER_CLASS,me.DEFAULT_CONTAINER_CLASS),this.elementRef[f].add(me.DISABLED_CONTAINER_CLASS),ge.addAriaDisabled(this.elementRef),this._state=j);}// called after class is initialised
|
|
219
|
+
},{key:"setDropupItem",value:function setDropupItem(e,t){this._menu=e,this.elementRef=t,this._originalElementRef=t.cloneNode(!0),this.changeState(this._state,!0);}},{key:"genStateInnerElements",value:function genStateInnerElements(e,t,n,s){var c,l,d,u;var i=this.createInnerElements(e,t,s);var o=(l=(c=s==null?void 0:s[t])==null?void 0:c[z])==null?void 0:l.content,a=(u=(d=s==null?void 0:s[t])==null?void 0:d[h])==null?void 0:u.content;if(o===void 0||a===void 0){var _ns$parseSVGTextEleme4=ns.parseSVGTextElements(n),g=_ns$parseSVGTextEleme4.svg,b=_ns$parseSVGTextEleme4[h],_ns$parseSVGTextEleme5=ns.parseSVGTextElements(i),_=_ns$parseSVGTextEleme5.svg,v=_ns$parseSVGTextEleme5[h],C=[];me.addToInnerElements(C,o,g,_),me.addToInnerElements(C,a,b,v),i=C;}return i;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[f].add("input-button",me.BUTTON_CLASS),e;}},{key:"addToInnerElements",value:function addToInnerElements(e,t,n,s){t===void 0&&n?e.push(n.cloneNode(!0)):s&&e.push(s);}},{key:"add",value:function add(e,t){var n=e.customButtons,s=e.focusInput,i=e.dropupStyles;n==null||n.forEach(function(o,a){var c={button:new me(o,a+1,s,i==null?void 0:i.menu)};t["".concat(me.INDICATOR_PREFIX).concat(a+1)]=c;});}}]);}(Cn);me.INDICATOR_PREFIX="custom",me.BUTTON_CLASS="custom-button",me.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",me.DEFAULT_CONTAINER_CLASS="custom-button-container-default",me.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var mn=me;var id="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M16 0c-8.836 0-16 7.163-16 16s7.163 16 16 16c8.837 0 16-7.163 16-16s-7.163-16-16-16zM16 30.032c-7.72 0-14-6.312-14-14.032s6.28-14 14-14 14 6.28 14 14-6.28 14.032-14 14.032zM23 15h-6v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1v6h-6c-0.552 0-1 0.448-1 1s0.448 1 1 1h6v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6h6c0.552 0 1-0.448 1-1s-0.448-1-1-1z\"></path>\n</svg>";var _s=/*#__PURE__*/function(){function _s(){_classCallCheck(this,_s);}return _createClass(_s,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var n=e.elementRef,s=t?n.children[0]:n.children[n.children.length-1];_s.focusSiblingItem(e,s,t,!0);}// isEdgeItem means is it a start or end item
|
|
220
|
+
},{key:"focusSiblingItem",value:function focusSiblingItem(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var i=s?t:t[n?"nextSibling":"previousSibling"];i?(t.dispatchEvent(new MouseEvent(yn)),i.dispatchEvent(new MouseEvent(Cs)),i.focus()):(t.dispatchEvent(new MouseEvent(yn)),_s.focusItemWhenOnEdge(e,n));}}]);}();var wr=/*#__PURE__*/function(){function wr(e,t){var _this93=this;_classCallCheck(this,wr);var n;this._isOpen=!0,this._styles=t,this.elementRef=wr.createElement((n=this._styles)==null?void 0:n.container),this.close(),setTimeout(function(){return _this93.addWindowEvents(e);});}return _createClass(wr,[{key:"open",value:function open(){this.elementRef[E].display="block",this._isOpen=!0;}},{key:"close",value:function close(){this._isOpen&&(this.elementRef[E].display="none",this._isOpen=!1);}},{key:"toggle",value:function toggle(){this._isOpen?this.close():this.open();}},{key:"addItem",value:function addItem(e){var t=mt.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
|
|
221
|
+
},{key:"addWindowEvents",value:function addWindowEvents(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener(Z,this.clickEvent),this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent);}},{key:"windowClick",value:function windowClick(e,t){var n;!e.isConnected&&this.clickEvent?window.removeEventListener(Z,this.clickEvent):e.parentElement!==((n=t.target.shadowRoot)==null?void 0:n.children[0])&&this.close();}// prettier-ignore
|
|
222
|
+
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var n,s,i;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===Ee.ESCAPE?(this.close(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent(yn))):t.key===Ee.ENTER?((s=this.highlightedItem)==null||s[Z](),(i=this.highlightedItem)==null||i.dispatchEvent(new MouseEvent(yn))):t.key===Ee.ARROW_DOWN?_s.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],!0):t.key===Ee.ARROW_UP&&_s.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[0],!1));}}],[{key:"createElement",value:function createElement(e){var t=x();return t.id=rt,Object.assign(t[E],e),t;}}]);}();var dn=/*#__PURE__*/function(_Cn3){function dn(e,t){var _this94;_classCallCheck(this,dn);var i,o;var n=yt.tryCreateConfig("Options",(i=t==null?void 0:t.button)==null?void 0:i.tooltip);_this94=_callSuper(this,dn,[dn.createButtonElement(),id,void 0,n,_defineProperty({},R,(o=t==null?void 0:t.button)==null?void 0:o[R])]);var s=_this94.createInnerElementsForStates(_this94.customStyles);_this94._menu=new wr(e,t==null?void 0:t.menu),_this94.addClickEvent(),_this94.buttonContainer=dn.createButtonContainer(),_this94.changeElementsByState(s[R]),_this94.buttonContainer.appendChild(_this94.elementRef),_this94.elementRef[f].add(dn.BUTTON_ICON_CLASS),_this94.buttonContainer.appendChild(_this94._menu.elementRef),_this94.reapplyStateStyle(R),_this94.addContainerEvents(e);return _this94;}_inherits(dn,_Cn3);return _createClass(dn,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty({},R,this.createInnerElements("dropup-icon",R,e));}},{key:"addClickEvent",value:function addClickEvent(){var _this95=this;this.elementRef.onclick=this._menu.toggle.bind(this._menu),this.elementRef.onkeydown=function(e){e.key===Ee.ENTER&&setTimeout(function(){_this95._menu.toggle();var t=_this95._menu.elementRef.children[0];t.focus(),t.dispatchEvent(new MouseEvent(Cs));});};}},{key:"addItem",value:function addItem(e){this._menu.addItem(e);}},{key:"addContainerEvents",value:function addContainerEvents(e){var _this96=this;e.addEventListener(Z,function(t){var n=t.target[f];!n.contains(dn.BUTTON_ICON_CLASS)&&!n.contains(mn.DISABLED_CONTAINER_CLASS)&&_this96._menu.close();});}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[f].add("input-button"),e;}},{key:"createButtonContainer",value:function createButtonContainer(){var e=x();return e.id="dropup-container",e;}},{key:"getPosition",value:function getPosition(e,t){var n,s;return(n=t==null?void 0:t.button)!=null&&n.position?ce.processPosition((s=t==null?void 0:t.button)==null?void 0:s.position):e[Pe].length>0&&e[ve].length===0?ve:Pe;}}]);}(Cn);dn.BUTTON_ICON_CLASS="dropup-button";var ci=dn;var Ne=/*#__PURE__*/function(){function Ne(){_classCallCheck(this,Ne);}return _createClass(Ne,null,[{key:"addToDropup",value:// prettier-ignore
|
|
223
|
+
function addToDropup(e,t,n,s){var i=new ci(n,s);ro.forEach(function(a){var c=t[rt].findIndex(function(d){return d.buttonType===a;}),l=t[rt][c];l&&(i.addItem(l.button),t[rt].splice(c,1));}),t[rt].forEach(function(_ref263){var a=_ref263.button;return i.addItem(a);});var o=ci.getPosition(t,s);qn.addButton(e,i.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){[jn,vt,Pe,ve].forEach(function(s){var i=s;t[i].forEach(function(o){qn.addButton(e,o.button.elementRef,i);});});}},{key:"setPosition",value:function setPosition(e,t,n){var s=_objectSpread(_objectSpread({},e[t]),{},{buttonType:t});n.push(s),delete e[t];}},{key:"createPositionsToButtonsObj",value:function createPositionsToButtonsObj(){return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},rt,[]),Pe,[]),jn,[]),vt,[]),ve,[]);}// prettier-ignore
|
|
224
|
+
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Ne.createPositionsToButtonsObj();Object.keys(e).forEach(function(s){var o;var i=(o=e[s])==null?void 0:o.button.position;i&&Ne.setPosition(e,s,t[i]);}),t[vt].length===0&&e.submit&&Ne.setPosition(e,lt,t[vt]),t[ve].length===0&&(e.submit?Ne.setPosition(e,lt,t[ve]):e.microphone?Ne.setPosition(e,ft,t[ve]):e.camera?Ne.setPosition(e,Fe,t[ve]):e["".concat(mn.INDICATOR_PREFIX,"1")]&&Ne.setPosition(e,"".concat(mn.INDICATOR_PREFIX,"1"),t[ve])),e.submit&&Ne.setPosition(e,lt,t[Pe].length===0?t[Pe]:t[vt]),e.microphone&&Ne.setPosition(e,ft,t[Pe].length===0?t[Pe]:t[vt]);var n=Object.keys(e);return n.length>1||t[rt].length>0?(ro.forEach(function(s){e[s]&&t[rt].push(_objectSpread(_objectSpread({},e[s]),{},{buttonType:s}));}),n.forEach(function(s){var i=s;i.startsWith(mn.INDICATOR_PREFIX)&&e[i]&&t[rt].push(_objectSpread(_objectSpread({},e[i]),{},{customType:i}));})):n.length===1&&Ne.setPosition(e,n[0],t[ve].length===0?t[ve]:t[Pe]),t;}// prettier-ignore
|
|
225
|
+
},{key:"addButtons",value:function addButtons(e,t,n,s){var i=Ne.generatePositionToButtons(t);return Ne.addToSideContainer(e,i),i[rt].length>0&&Ne.addToDropup(e,i,n,s),i;}}]);}();var rd="<?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>",od="<?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",ad="<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>",cd="<?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",ld=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},Q,{id:"upload-images-icon",svgString:od,dropupText:"Image"}),Dn,{id:"upload-gifs-icon",svgString:cd,dropupText:"GIF"}),G,{id:"upload-audio-icon",svgString:ad,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:rd,dropupText:"File"});var Si=/*#__PURE__*/function(_Cn4){function Si(e){var _this97;_classCallCheck(this,Si);(e==null?void 0:e.position)===rt&&(e.position=ve);var t=yt.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this97=_callSuper(this,Si,[Si.createMicrophoneElement(),No,e==null?void 0:e.position,t,e]),_this97.isActive=!1,_this97._innerElements=_this97.createInnerElementsForStates(_this97.customStyles),_this97.changeToDefault();return _this97;}_inherits(Si,_Cn4);return _createClass(Si,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},A,this.createInnerElements(t,A,e)),$,this.createInnerElements(t,$,e)),Yn,this.createInnerElements(t,Yn,e)),Tn,this.createInnerElements(t,Tn,e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements[$]),this.toggleIconFilter($),this.reapplyStateStyle($,[A,Tn]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[A]),this.toggleIconFilter(A),this.reapplyStateStyle(A,[$,Tn]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements[Tn]),this.toggleIconFilter("command"),this.reapplyStateStyle(Tn,[$]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements[Yn]),this.elementRef[f].add("".concat(Yn,"-microphone")),this.reapplyStateStyle(Yn,[$]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()===z)switch(e){case A:t[f].remove("active-microphone-icon","command-microphone-icon"),t[f].add("default-microphone-icon");break;case $:t[f].remove("default-microphone-icon","command-microphone-icon"),t[f].add("active-microphone-icon");break;case"command":t[f].remove("active-microphone-icon","default-microphone-icon"),t[f].add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=x();return e.id="microphone-button",e[f].add("input-button"),e;}}]);}(Cn);var Us=/*#__PURE__*/function(){function Hs(){_classCallCheck(this,Hs);}return _createClass(Hs,null,[{key:"capitalize",value:function capitalize(e){return e.replace(Hs.FIRST_CHAR_REGEX,function(t){return t.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(e){return e.replace(Hs.DOUBLE_LINE,"<p></p>").replace(Hs.ONE_LINE,"<br>");}},{key:"isCharDefined",value:function isCharDefined(e){return e!==void 0&&e!==" "&&e!==" "&&e!=="\n"&&e!=="";}},{key:"breakupIntoWordsArr",value:function breakupIntoWordsArr(e){return e.split(/(\W+)/);}}]);}();Us.FIRST_CHAR_REGEX=/\S/,Us.DOUBLE_LINE=/\n\n/g,Us.ONE_LINE=/\n/g;var at=Us;var sr=/*#__PURE__*/function(){function sr(){_classCallCheck(this,sr);}return _createClass(sr,null,[{key:"translate",value:function translate(e,t){var n=at.breakupIntoWordsArr(e);for(var s=0;s<n.length;s+=1)t[n[s]]&&(n[s]=t[n[s]]);return n.join("");}}]);}();var oo=/*#__PURE__*/function(){function oo(){_classCallCheck(this,oo);}return _createClass(oo,null,[{key:"extract",value:function extract(e,t,n){var s="";for(var i=e.resultIndex;i<e.results.length;++i){var o=e.results[i][0].transcript;n&&(o=sr.translate(o,n)),e.results[i].isFinal?t+=o:s+=o;}return{interimTranscript:s,finalTranscript:t,newText:s||t};}},{key:"extractSafari",value:function extractSafari(e,t,n){var s="";for(var i=e.resultIndex;i<e.results.length;++i){var o=e.results[i][0].transcript;n&&(o=sr.translate(o,n)),s+=o;}return{interimTranscript:"",finalTranscript:s,newText:s};}}]);}();var es=/*#__PURE__*/_createClass(function es(){_classCallCheck(this,es);});es.IS_SAFARI=function(){return es._IS_SAFARI===void 0&&(es._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),es._IS_SAFARI;};var vs=es;var Go=/*#__PURE__*/function(){function _t(){_classCallCheck(this,_t);}return _createClass(_t,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(e,t){return Array.isArray(e)?e.find(function(n){return t===n;}):t===e?e:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(e){var _this98=this;e.element&&_t.getElementIfFocusedOnAvailable(e.element,document.activeElement)&&(_t.KEY_DOWN_TIMEOUT!==null&&clearTimeout(_t.KEY_DOWN_TIMEOUT),_t.KEY_DOWN_TIMEOUT=setTimeout(function(){_t.KEY_DOWN_TIMEOUT=null,_this98.resetRecording(e);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(e,t){this.mouseDownElement=_t.getElementIfFocusedOnAvailable(e,t.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(e){this.mouseDownElement&&this.resetRecording(e),this.mouseDownElement=void 0;}},{key:"add",value:function add(e,t){var n=(t==null?void 0:t.insertInCursorLocation)===void 0||(t==null?void 0:t.insertInCursorLocation);t!=null&&t.element&&n&&(e.mouseDownEvent=_t.mouseDownWindow.bind(e,t.element),document.addEventListener("mousedown",e.mouseDownEvent),e.mouseUpEvent=_t.mouseUpWindow.bind(e,t),document.addEventListener("mouseup",e.mouseUpEvent),e.keyDownEvent=_t.keyDownWindow.bind(e,t),document.addEventListener("keydown",e.keyDownEvent));}},{key:"remove",value:function remove(e){document.removeEventListener("mousedown",e.mouseDownEvent),document.removeEventListener("mouseup",e.mouseUpEvent),document.removeEventListener("keydown",e.keyDownEvent);}}]);}();Go.KEY_DOWN_TIMEOUT=null;var ao=Go;var hd=/*#__PURE__*/function(){function hd(){_classCallCheck(this,hd);}return _createClass(hd,null,[{key:"process",value:function process(e,t,n,s,i){var o=s==null?void 0:s(t,n);return o?(setTimeout(function(){o.restart?e.resetRecording(i):o.stop&&e.stop();}),(o.stop||o.restart)&&o.removeNewText):!1;}}]);}();var Jt=/*#__PURE__*/function(){function Jt(){_classCallCheck(this,Jt);}return _createClass(Jt,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(e,t){t&&!e.isCursorAtEnd&&(e.endPadding="",e.scrollingSpan.innerHTML=" ");}},{key:"scrollGeneric",value:function scrollGeneric(e,t){e.isCursorAtEnd?t.scrollTop=t.scrollHeight:e.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
|
|
226
226
|
// they can only safely be scrolled to the end
|
|
227
|
-
},{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(e){e.scrollLeft=e.scrollWidth,e.scrollTop=e.scrollHeight;}},{key:"isElementOverflown",value:function isElementOverflown(e){return e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth;}},{key:"isRequired",value:function isRequired(e,t){return e&&
|
|
227
|
+
},{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(e){e.scrollLeft=e.scrollWidth,e.scrollTop=e.scrollHeight;}},{key:"isElementOverflown",value:function isElementOverflown(e){return e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth;}},{key:"isRequired",value:function isRequired(e,t){return e&&Jt.isElementOverflown(t);}}]);}();var Je=/*#__PURE__*/function(){function Je(){_classCallCheck(this,Je);}return _createClass(Je,null,[{key:"isPrimitiveElement",value:function isPrimitiveElement(e){return e.tagName==="INPUT"||e.tagName==="TEXTAREA";}},{key:"createInterimSpan",value:function createInterimSpan(){var e=document.createElement("span");return e.style.color="grey",e.style.pointerEvents="none",e;}},{key:"createGenericSpan",value:function createGenericSpan(){var e=document.createElement("span");return e.style.pointerEvents="none",e;}},{key:"appendSpans",value:function appendSpans(e,t){if(e.spansPopulated=!0,e.insertInCursorLocation&&document.activeElement===t){var _n18=window.getSelection();if(_n18!=null&&_n18.focusNode){var s=_n18.getRangeAt(0);s.insertNode(e.scrollingSpan),s.insertNode(e.interimSpan),s.insertNode(e.finalSpan),s.collapse(!1),_n18.removeAllRanges(),_n18.addRange(s);return;}}t.appendChild(e.finalSpan),t.appendChild(e.interimSpan),t.appendChild(e.scrollingSpan);}},{key:"applyCustomColors",value:function applyCustomColors(e,t){t.interim&&(e.interimSpan.style.color=t.interim),t["final"]&&(e.finalSpan.style.color=t["final"]);}},{key:"isInsideShadowDOM",value:function isInsideShadowDOM(e){return e.getRootNode()instanceof ShadowRoot;}}]);}();var Ue=/*#__PURE__*/function(){function Ue(){_classCallCheck(this,Ue);}return _createClass(Ue,null,[{key:"setOffsetForGeneric",value:function setOffsetForGeneric(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var s=0;for(var i=0;i<e.childNodes.length;i+=1){var o=e.childNodes[i];if(o.childNodes.length>0){var a=Ue.setOffsetForGeneric(o,t,n);if(a===-1)return-1;n+=a;}else if(o.textContent!==null){if(n+o.textContent.length>t){var _a9=document.createRange();_a9.setStart(o,t-n),_a9.collapse(!0);var c=window.getSelection();return c==null||c.removeAllRanges(),c==null||c.addRange(_a9),e.focus(),-1;}n+=o.textContent.length,s+=o.textContent.length;}}return s;}},{key:"focusEndOfGeneric",value:function focusEndOfGeneric(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n&&(n.removeAllRanges(),n.addRange(t));}},{key:"setOffsetForSafariGeneric",value:function setOffsetForSafariGeneric(e,t){var n=window.getSelection();if(n){var s=Ue.getGenericElementCursorOffset(e,n,!0);Ue.setOffsetForGeneric(e,s+t);}}// set to automatically scroll to cursor (scroll does not work in Safari)
|
|
228
228
|
},{key:"setOffsetForPrimitive",value:function setOffsetForPrimitive(e,t,n){n&&e.blur(),e.setSelectionRange(t,t),e.focus();}// Scroll Input in Safari - does not work for TextArea and uses span which can have a different style
|
|
229
229
|
// private static getCursorOffsetFromLeft(inputElement: HTMLInputElement, position: number) {
|
|
230
230
|
// // Get the value of the input element up to the cursor position
|
|
@@ -242,7 +242,7 @@ function addToDropup(e,t,n,s){var r=new oi(n,s);io.forEach(function(a){var c=t[i
|
|
|
242
242
|
// document.body.removeChild(tempSpan);
|
|
243
243
|
// return {left: offsetWidth, top: offsetHeight};
|
|
244
244
|
// }
|
|
245
|
-
},{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(e,t,n){var s=0;if(t.rangeCount>0){var
|
|
245
|
+
},{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(e,t,n){var s=0;if(t.rangeCount>0){var i=t.getRangeAt(0),o=i.cloneRange();o.selectNodeContents(e),n?o.setEnd(i.startContainer,i.startOffset):o.setEnd(i.endContainer,i.endOffset),s=o.toString().length;}return s;}// for input
|
|
246
246
|
// private static insertTextAtCursor(text: string, input: HTMLInputElement) {
|
|
247
247
|
// const startPos = input.selectionStart;
|
|
248
248
|
// const endPos = input.selectionEnd;
|
|
@@ -251,42 +251,42 @@ function addToDropup(e,t,n,s){var r=new oi(n,s);io.forEach(function(a){var c=t[i
|
|
|
251
251
|
// input.selectionStart = input.selectionEnd = startPos + text.length;
|
|
252
252
|
// }
|
|
253
253
|
// }
|
|
254
|
-
}]);}();var
|
|
255
|
-
},{key:"execCommand",value:function execCommand(e,t,n,s,
|
|
256
|
-
function
|
|
254
|
+
}]);}();var Ge=/*#__PURE__*/function(){function Ge(){_classCallCheck(this,Ge);}return _createClass(Ge,null,[{key:"processCommand",value:function processCommand(e,t){return(!t||!t.caseSensitive)&&(e=e.toLowerCase()),(t==null?void 0:t.substrings)===!1?at.breakupIntoWordsArr(e):e;}},{key:"process",value:function process(e){var t;return((t=e.settings)==null?void 0:t.caseSensitive)===!0?e:Object.keys(e).reduce(function(n,s){var i=e[s];return n[s]=typeof i=="string"?Ge.processCommand(i,e.settings):i,n;},{});}},{key:"toggleCommandModeOn",value:function toggleCommandModeOn(e){var t;e.isWaitingForCommand=!0,(t=e.onCommandModeTrigger)==null||t.call(e,!0);}},{key:"toggleCommandModeOff",value:function toggleCommandModeOff(e){var t;e.isWaitingForCommand&&((t=e.onCommandModeTrigger)==null||t.call(e,!1),e.isWaitingForCommand=!1);}},{key:"setText",value:function setText(e,t,n,s){Ge.toggleCommandModeOff(e),Je.isPrimitiveElement(s)?(s.value=n,e.isTargetInShadow||Ue.setOffsetForPrimitive(s,n.length,!0),vs.IS_SAFARI()&&e.autoScroll&&Jt.scrollSafariPrimitiveToEnd(s)):(s.textContent=n,e.isTargetInShadow||Ue.focusEndOfGeneric(s),setTimeout(function(){return Jt.scrollGeneric(e,s);})),e.resetRecording(t);}},{key:"checkIfMatchesSubstring",value:function checkIfMatchesSubstring(e,t){return t.includes(e);}},{key:"checkIfMatchesWord",value:function checkIfMatchesWord(e,t,n){var s=e;for(var i=n.length-1;i>=0;i-=1){var o=i,a=s.length-1;for(;n[o]===s[a]&&a>=0;)o-=1,a-=1;if(a<0)return!0;}return!1;}// prettier-ignore
|
|
255
|
+
},{key:"execCommand",value:function execCommand(e,t,n,s,i){var o,a,c;var l=e.commands;if(!l||!s||!n)return;var d=((o=l.settings)==null?void 0:o.caseSensitive)===!0?t:t.toLowerCase(),u=at.breakupIntoWordsArr(d),g=((a=l.settings)==null?void 0:a.substrings)===!1?Ge.checkIfMatchesWord:Ge.checkIfMatchesSubstring;if(l.commandMode&&g(l.commandMode,d,u))return e.setInterimColorToFinal(),setTimeout(function(){return Ge.toggleCommandModeOn(e);}),{doNotProcessTranscription:!1};if(!(l.commandMode&&!e.isWaitingForCommand)){if(l.stop&&g(l.stop,d,u))return Ge.toggleCommandModeOff(e),setTimeout(function(){return e.stop();}),{doNotProcessTranscription:!1};if(l.pause&&g(l.pause,d,u))return Ge.toggleCommandModeOff(e),e.setInterimColorToFinal(),setTimeout(function(){var b;e.isPaused=!0,(b=e.onPauseTrigger)==null||b.call(e,!0);}),{doNotProcessTranscription:!1};if(l.resume&&g(l.resume,d,u))return e.isPaused=!1,(c=e.onPauseTrigger)==null||c.call(e,!1),Ge.toggleCommandModeOff(e),e.resetRecording(n),{doNotProcessTranscription:!0};if(l.reset&&g(l.reset,d,u))return i!==void 0&&Ge.setText(e,n,i,s),{doNotProcessTranscription:!0};if(l.removeAllText&&g(l.removeAllText,d,u))return Ge.setText(e,n,"",s),{doNotProcessTranscription:!0};}}}]);}();var Hn=/*#__PURE__*/function(){function Hn(){_classCallCheck(this,Hn);}return _createClass(Hn,null,[{key:"setStateForPrimitive",value:function setStateForPrimitive(e,t){var n,s;t.selectionStart!==null&&(n=t.selectionStart),t.selectionEnd!==null&&(s=t.selectionEnd),e.isHighlighted=n!==s;}},{key:"setStateForGeneric",value:function setStateForGeneric(e,t){var n=window.getSelection();if(n!=null&&n.focusNode){var s=Ue.getGenericElementCursorOffset(t,n,!0),i=Ue.getGenericElementCursorOffset(t,n,!1);e.isHighlighted=s!==i;}}},{key:"setState",value:function setState(e,t){document.activeElement===t&&(Je.isPrimitiveElement(t)?Hn.setStateForPrimitive(e,t):Hn.setStateForGeneric(e,t));}},{key:"removeForGeneric",value:function removeForGeneric(e,t){var n=window.getSelection();if(n){var s=Ue.getGenericElementCursorOffset(t,n,!0);n.deleteFromDocument(),Ue.setOffsetForGeneric(t,s),e.isHighlighted=!1;}}},{key:"removeForPrimitive",value:function removeForPrimitive(e,t){var n=t.selectionStart,s=t.selectionEnd,i=t.value;if(n&&s){var o=i.substring(0,n)+i.substring(s);t.value=o,Ue.setOffsetForPrimitive(t,n,e.autoScroll);}e.isHighlighted=!1;}}]);}();var $n=/*#__PURE__*/function(){function $n(){_classCallCheck(this,$n);}return _createClass($n,null,[{key:"setStateForPrimitiveElement",value:function setStateForPrimitiveElement(e,t){if(document.activeElement===t&&t.selectionStart!==null){var s=t.selectionStart,i=t.value[s-1],o=t.selectionEnd===null?s:t.selectionEnd,a=t.value[o];at.isCharDefined(i)&&(e.startPadding=" ",e.numberOfSpacesBeforeNewText=1),at.isCharDefined(a)&&(e.endPadding=" ",e.numberOfSpacesAfterNewText=1),e.isCursorAtEnd=t.value.length===o;return;}var n=t.value[t.value.length-1];at.isCharDefined(n)&&(e.startPadding=" ",e.numberOfSpacesBeforeNewText=1),e.isCursorAtEnd=!0;}},{key:"setStateForGenericElement",value:function setStateForGenericElement(e,t){var n,s,i;if(document.activeElement===t){var a=window.getSelection();if(a!=null&&a.focusNode){var c=Ue.getGenericElementCursorOffset(t,a,!0),l=(n=t.textContent)==null?void 0:n[c-1],d=Ue.getGenericElementCursorOffset(t,a,!1),u=(s=t.textContent)==null?void 0:s[d];at.isCharDefined(l)&&(e.startPadding=" "),at.isCharDefined(u)&&(e.endPadding=" "),e.isCursorAtEnd=((i=t.textContent)==null?void 0:i.length)===d;return;}}var o=t.innerText.charAt(t.innerText.length-1);at.isCharDefined(o)&&(e.startPadding=" "),e.isCursorAtEnd=!0;}},{key:"setState",value:function setState(e,t){Je.isPrimitiveElement(t)?$n.setStateForPrimitiveElement(e,t):$n.setStateForGenericElement(e,t);}},{key:"adjustStateAfterRecodingPrimitiveElement",value:function adjustStateAfterRecodingPrimitiveElement(e,t){if(e.primitiveTextRecorded=!0,e.insertInCursorLocation&&document.activeElement===t&&(t.selectionEnd!==null&&(e.endPadding=e.endPadding+t.value.slice(t.selectionEnd)),t.selectionStart!==null)){e.startPadding=t.value.slice(0,t.selectionStart)+e.startPadding;return;}e.startPadding=t.value+e.startPadding;}},{key:"adjustSateForNoTextPrimitiveElement",value:function adjustSateForNoTextPrimitiveElement(e){e.numberOfSpacesBeforeNewText===1&&(e.startPadding=e.startPadding.substring(0,e.startPadding.length-1),e.numberOfSpacesBeforeNewText=0),e.numberOfSpacesAfterNewText===1&&(e.endPadding=e.endPadding.substring(1),e.numberOfSpacesAfterNewText=0);}}]);}();var zo=/*#__PURE__*/function(){// this is mostly used for Azure to prevent user from stopping when it is connecting
|
|
256
|
+
function zo(){_classCallCheck(this,zo);this.finalTranscript="",this.interimSpan=Je.createInterimSpan(),this.finalSpan=Je.createGenericSpan(),this.scrollingSpan=Je.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(zo,[{key:"prepareBeforeStart",value:function prepareBeforeStart(e){var t,n;if(e!=null&&e.element)if(ao.add(this,e),Array.isArray(e.element)){var s=e.element.find(function(i){return i===document.activeElement;})||e.element[0];if(!s)return;this.prepare(s);}else this.prepare(e.element);(e==null?void 0:e.displayInterimResults)!==void 0&&(this._displayInterimResults=e.displayInterimResults),e!=null&&e.textColor&&(this._finalTextColor=(t=e==null?void 0:e.textColor)==null?void 0:t["final"],Je.applyCustomColors(this,e.textColor)),(e==null?void 0:e.insertInCursorLocation)!==void 0&&(this.insertInCursorLocation=e.insertInCursorLocation),(e==null?void 0:e.autoScroll)!==void 0&&(this.autoScroll=e.autoScroll),this._onResult=e==null?void 0:e.onResult,this._onPreResult=e==null?void 0:e.onPreResult,this._onStart=e==null?void 0:e.onStart,this._onStop=e==null?void 0:e.onStop,this._onError=e==null?void 0:e.onError,this.onCommandModeTrigger=e==null?void 0:e.onCommandModeTrigger,this.onPauseTrigger=e==null?void 0:e.onPauseTrigger,this._options=e,(n=this._options)!=null&&n.commands&&(this.commands=Ge.process(this._options.commands));}},{key:"prepare",value:function prepare(e){$n.setState(this,e),Hn.setState(this,e),this.isTargetInShadow=Je.isInsideShadowDOM(e),Je.isPrimitiveElement(e)?(this._primitiveElement=e,this._originalText=this._primitiveElement.value):(this._genericElement=e,this._originalText=this._genericElement.textContent);}// there was an attempt to optimize this by not having to restart the service and just reset state:
|
|
257
257
|
// unfortunately it did not work because the service would still continue firing the intermediate and final results
|
|
258
258
|
// into the new position
|
|
259
259
|
},{key:"resetRecording",value:function resetRecording(e){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(e,!0);}// prettier-ignore
|
|
260
|
-
},{key:"updateElements",value:function updateElements(e,t,n){var s;var
|
|
260
|
+
},{key:"updateElements",value:function updateElements(e,t,n){var s;var i=at.capitalize(t);if(this.finalTranscript===i&&e==="")return;hd.process(this,n,e==="",this._onPreResult,this._options)&&(e="",n="");var o=this.commands&&Ge.execCommand(this,n,this._options,this._primitiveElement||this._genericElement,this._originalText);if(o){if(o.doNotProcessTranscription)return;e="",n="";}if(this.isPaused||this.isWaitingForCommand)return;(s=this._onResult)==null||s.call(this,n,e===""),this.finalTranscript=i,this._displayInterimResults||(e="");var a=this.finalTranscript===""&&e==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,e,a):this._genericElement&&this.updateGenericElement(this._genericElement,e,a);}// prettier-ignore
|
|
261
261
|
// remember that padding values here contain actual text left and right
|
|
262
|
-
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(e,t,n){this.isHighlighted&&
|
|
263
|
-
function set(e){e.stopTimeout=setTimeout(function(){return e.stop();},e.stopTimeoutMS);}},{key:"reset",value:function reset(e,t){e.stopTimeoutMS=t||
|
|
264
|
-
function extract(e,t,n,s){return s&&(e=
|
|
265
|
-
_inherits(
|
|
266
|
-
},{key:"onRecognizing",value:function onRecognizing(e,t){if(this._stopping)return;var
|
|
267
|
-
},{key:"onRecognized",value:function onRecognized(e,t){var n=t.result;switch(n.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(n.text&&!this._stopping){var
|
|
268
|
-
_inherits(us,
|
|
269
|
-
function
|
|
270
|
-
function
|
|
271
|
-
},{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[ne]=e,
|
|
272
|
-
function create(e,t,n,s,
|
|
273
|
-
return _createClass(
|
|
274
|
-
function
|
|
275
|
-
function validate(e,t,n,s,
|
|
276
|
-
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
277
|
-
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
278
|
-
},{key:"attach",value:function attach(e,t,n,s,
|
|
279
|
-
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){Le.setPropertyValueIfDoesNotExist(e,[
|
|
280
|
-
function rs(e,t,n,s,
|
|
281
|
-
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,n,s,
|
|
282
|
-
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
283
|
-
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var
|
|
284
|
-
},{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef[f].contains(Qn)||(this.elementRef[f].remove(
|
|
285
|
-
function
|
|
286
|
-
},{key:"addButtonEvents",value:function addButtonEvents(e,t,n,s){var
|
|
287
|
-
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,n,s){var
|
|
288
|
-
function addClickEvent(e,t,n,s){var
|
|
289
|
-
function createFileUploadComponents(e,t,n,s){var o,a,c,l;var
|
|
290
|
-
}],[{key:"createPanelElement",value:function createPanelElement(e){var t=x();return t.id="input",Object.assign(t[E],e),t;}},{key:"createUploadButtons",value:function createUploadButtons(e,t,n,s,
|
|
291
|
-
},{key:"addElements",value:function addElements(e,t,n,s,r,o){V.addElements(e,t.elementRef);var a=Gn.create(),c=Be.addButtons(a,n,s,o);is.set(t.inputElementRef,a,r.elementRef,c),Gn.add(e,a);}},{key:"assignOnInput",value:function assignOnInput(e,t,n,s){t.onInput=function(r){setTimeout(function(){var o=n.getAllFileData(),a=s.inputElementRef.innerText.trim(),c=_defineProperty({},h,a);o&&(c[m]=o.map(function(l){return l[ne];})),_n.onInput(e,c,r);});};}}]);}();var Cr=/*#__PURE__*/function(){function Cr(){_classCallCheck(this,Cr);}return _createClass(Cr,null,[{key:"createElements",value:function createElements(e,t,n){var s=x();s.id="chat-view";var r=!e.focusMode&&e.upwardsMode;s.classList.add(r?Jh:Yh);var o=new rt(e,t,n);t.websocket&&ke.createConnection(t,o);var a=new Mn(e,o,t,s),c=r?o.elementRef.parentElement:o.elementRef;return V.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=Cr.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var Ed="#validate-property-key-view{height:100%;position:relative;display:flex;justify-content:center;align-items:center;padding:8px}#loading-validate-key-property{display:inline-block;width:50px;height:50px}#loading-validate-key-property:after{content:\" \";display:block;width:38px;height:38px;margin:1px;border-radius:50%;border:5px solid #5fb2ff;border-color:#5fb2ff transparent #5fb2ff transparent;animation:loading-spinner 1.4s linear infinite}#deep-chat-openai-realtime-container{height:100%;width:100%}#deep-chat-openai-realtime-avatar-container{height:60%;width:100%;display:flex;justify-content:center;align-items:center}#deep-chat-openai-realtime-avatar{border-radius:50%;height:110px;border:1px solid rgb(215,215,215);padding:8px;-webkit-user-select:none;user-select:none;margin-top:20px}#deep-chat-openai-realtime-buttons-container{height:40%;display:flex;position:relative}.deep-chat-openai-realtime-button-container{height:100%;width:50%;display:flex;justify-content:center;align-items:center}.deep-chat-openai-realtime-button{width:70px;height:70px;border-radius:50%;display:flex;justify-content:center;align-items:center;cursor:pointer}.deep-chat-openai-realtime-button-default{background-color:#e3e3e3}.deep-chat-openai-realtime-button-default:hover{background-color:#d4d4d4}.deep-chat-openai-realtime-button-default:active{background-color:#c5c5c5}.deep-chat-openai-realtime-button-loading{opacity:.7;pointer-events:none}.deep-chat-openai-realtime-microphone-active{background-color:#ffe7e7}.deep-chat-openai-realtime-microphone-active:hover{background-color:#ffdede}.deep-chat-openai-realtime-microphone-active:active{background-color:#ffd2d2}.deep-chat-openai-realtime-microphone>*{height:30px;width:30px}.deep-chat-openai-realtime-microphone-active>*{filter:brightness(0) saturate(100%) invert(35%) sepia(60%) saturate(1360%) hue-rotate(325deg) brightness(95%) contrast(92%)}.deep-chat-openai-realtime-toggle>*{height:32px;width:32px;padding-inline-start:3px;filter:brightness(0) saturate(100%) invert(22%) sepia(0%) saturate(4537%) hue-rotate(208deg) brightness(105%) contrast(91%)}.deep-chat-openai-realtime-button-unavailable{opacity:.45;pointer-events:none}#deep-chat-openai-realtime-error{color:red;position:absolute;top:calc(50% + 40px);inset-inline-start:50%;transform:translate(-50%,-50%);font-size:17px}#deep-chat-openai-realtime-loading{position:absolute;font-size:15px;top:50%;inset-inline-start:50%;transform:translate(-50%,-50%)}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;inset-block-start:44%;inset-inline-start:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-inline-end:2.7em;width:calc(100% - 80px)}#insert-key-input{padding:.3em 1.7em .3em .3em;border-width:1px;border-style:solid;border-radius:3px;width:100%;font-size:inherit}.insert-key-input-valid{border-color:gray}.insert-key-input-invalid{border-color:red}#visibility-icon-container{position:relative;float:inline-end;cursor:pointer;-webkit-user-select:none;user-select:none}.visibility-icon{filter:brightness(0) saturate(100%) invert(63%) sepia(1%) saturate(9%) hue-rotate(43deg) brightness(98%) contrast(92%);position:absolute;inset-inline-end:-1.7em;inset-block-start:-1.43em}#visible-icon{inset-block-start:-1.4em}.visibility-icon:hover{filter:unset}.visibility-icon>*{pointer-events:none}#start-button{border:1px solid grey;color:#454545;border-radius:4px;width:3em;display:flex;justify-content:center;align-items:center;cursor:pointer;padding:.28em .3em;-webkit-user-select:none;user-select:none;background-color:#fff}#start-button:hover{background-color:#f2f2f2}#start-button:active{background-color:#d2d2d2}#insert-key-help-text-container{width:100%;position:absolute;margin-top:32px;margin-bottom:20px}#insert-key-help-text-contents{width:100%;position:absolute}#insert-key-input-invalid-text{display:block;margin-top:1em;margin-bottom:.5em;color:red}.insert-key-input-help-text{display:block;margin-top:16px}#loading-key{display:inline-block;width:16px;height:16px}#loading-key:after{content:\" \";display:block;width:11px;height:11px;margin:1px;border-radius:50%;border:2px solid #0084ff;border-color:#0084ff transparent #0084ff transparent;animation:loading-spinner 1.2s linear infinite}#error-view{color:red;font-size:1.2em;line-height:1.3em;margin-top:-5px;text-align:center;height:100%;display:flex;justify-content:center;align-items:center;padding-inline:8px}@keyframes loading-spinner{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.intro-panel{position:absolute;display:flex;justify-content:center;right:0;bottom:0;left:0;margin:auto;height:fit-content;top:-2.5em}pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!\n Theme: a11y-dark\n Author: @ericwbailey\n Maintainer: @ericwbailey\n\n Based on the Tomorrow Night Eighties theme: https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css\n*/.hljs{background:#2b2b2b;color:#f8f8f2}.hljs-comment,.hljs-quote{color:#d4d0ab}.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#ffa07a}.hljs-built_in,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#f5ab35}.hljs-attribute{color:gold}.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#abe338}.hljs-section,.hljs-title{color:#00e0e0}.hljs-keyword,.hljs-selector-tag{color:#dcc6e0}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}@media screen and (-ms-high-contrast:active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}}#messages,.deep-chat-upwards-mode #messages>div{overflow:auto;overflow-anchor:none}.deep-chat-upwards-mode #messages{height:100%;display:flex;flex-direction:column;justify-content:flex-end}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-inline:auto;width:calc(97.5% - 24px);max-width:100%}.message-bubble{margin-top:10px;word-wrap:break-word;width:fit-content;max-width:60%;border-radius:10px;padding:.42em .55em;height:fit-content;line-height:1.26}.user-message-text{color:#fff;background-color:#0084ff;margin-inline-end:0px;margin-inline-start:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-inline-start:0px;margin-inline-end:auto}.deep-chat-last-group-messages-active{height:100%}#scroll-button{position:absolute;top:75%;left:50%;right:50%;transform:translate(-50%,-50%);transition:opacity .1s ease;display:flex;opacity:0;padding:8px;background-color:#fff;border:.5px solid #000000;justify-content:center;align-items:center;white-space:nowrap;cursor:pointer}#scroll-button:hover{background-color:#fafafa}.loading-history-message-full-view{position:absolute;height:70%;width:100%;display:flex;align-items:center}.deep-chat-upwards-mode #messages .loading-history-message-full-view{height:100%}.loading-history-message-small{height:20px;margin-bottom:30px}.loading-history-message-small>div>div{scale:.6}.loading-history-message{margin-top:0;width:100%;max-width:100%;display:flex;justify-content:center;background-color:unset}.loading-history{width:70px}.loading-history div{position:absolute;width:var(--loading-history-width);height:var(--loading-history-height);margin:var(--loading-history-margin);border:var(--loading-history-border);border-radius:50%;animation:loading-spinner 1.2s cubic-bezier(.5,0,.5,1) infinite;border-color:var(--loading-history-color) transparent transparent transparent}.loading-history div:nth-child(1){animation-delay:-.45s}.loading-history div:nth-child(2){animation-delay:-.3s}.loading-history div:nth-child(3){animation-delay:-.15s}.html-message{max-width:unset}.error-message-text{margin-inline:auto;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%;margin-top:14px;margin-bottom:10px}.deep-chat-loading-message-dots-container{width:1em;padding-top:.6em;padding-bottom:.6em;padding-inline-start:1.3em;padding-inline-end:.75em}.loading-message-dots{position:relative;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite linear alternate;animation-delay:.5s}.loading-message-dots:before,.loading-message-dots:after{content:\"\";display:inline-block;position:absolute;top:0}.loading-message-dots:before{inset-inline-start:-.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:0s}.loading-message-dots:after{inset-inline-start:.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:1s}@keyframes loading-message-dots{0%{background-color:var(--loading-message-color)}50%,to{background-color:var(--loading-message-color-fade)}}.message-bubble>p:first-child,.message-bubble>.partial-render-message>p:first-child,.html-wrapper>p:first-child{margin-top:0}.message-bubble>p:last-child,.message-bubble>.partial-render-message:last-child>p,.html-wrapper>p:last-child{margin-bottom:0}pre{overflow:auto;display:block;word-break:break-all;word-wrap:break-word;border-radius:7px;background:#2b2b2b;color:#f8f8f2;margin-top:.8em;margin-bottom:.8em;padding:.6em;font-size:.9em;line-height:1.5em}.image-message{padding:0;display:flex;background-color:#ddd}.image-message>*,.image-message>*>*{width:100%;border-radius:8px;display:flex}.audio-message{width:60%;max-width:300px;height:2.2em;max-height:54px;padding:0;background-color:unset}.audio-player{width:100%;height:100%}.audio-player-safari{height:fit-content;width:40px}.audio-player-safari-start{float:inline-start}.audio-player-safari-end{float:inline-end}.any-file-message{padding:1px}.any-file-message-contents{display:flex}.any-file-message-icon-container{width:1.3em;min-width:1.3em;position:relative;border-radius:4px;margin-inline-start:6px;margin-inline-end:2px}.any-file-message-icon{background-color:#fff;border-radius:4px;position:absolute;width:1em;height:1.25em;padding:1px;margin-top:auto;margin-bottom:auto;top:0;bottom:0}.any-file-message-text{padding-top:5px;overflow-wrap:anywhere;padding-bottom:5px;padding-inline-end:7px}.message-bubble>a{color:inherit}.start-item-position{margin-inline-end:10px}.end-item-position{margin-inline-start:10px}.role-hidden{display:none}.avatar{padding-top:5px;width:1.5em;height:1.5em;border-radius:1px}.avatar-container{margin-top:9px}.name{margin-top:16px;font-size:15px}#drag-and-drop{position:absolute;display:none;z-index:10;height:calc(100% - 10px);width:calc(100% - 10px);background-color:#70c6ff4d;border:5px dashed #6dafff}#file-attachment-container{position:absolute;height:3.6em;width:calc(80% - 4px);top:-2.5em;border-radius:5px;overflow:auto;text-align:start;background-color:#d7d7d73b;padding-inline-start:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-inline-end:.6em;margin-bottom:.44em;margin-top:4px;position:relative;background-color:#fff;border-radius:5px}.image-attachment{width:100%;height:100%;object-fit:cover;border-radius:5px}.border-bound-attachment{width:calc(100% - 2px);height:calc(100% - 2px);border:1px solid #c3c3c3;border-radius:5px;overflow:hidden}.border-bound-attachment-safari{width:calc(100% - 1px);height:calc(100% - 1px)}.audio-attachment-icon-container{cursor:pointer}.audio-attachment-icon-container:hover{background-color:#f8f8f8}.attachment-icon{inset-inline:0;bottom:0;top:2px;margin:auto;position:absolute;width:25px;-webkit-user-select:none;user-select:none}.not-removable-attachment-icon{top:0;right:0;bottom:0;left:0}.play-icon{filter:brightness(0) saturate(100%) invert(17%) sepia(0%) saturate(1392%) hue-rotate(67deg) brightness(98%) contrast(97%)}.stop-icon{filter:brightness(0) saturate(100%) invert(29%) sepia(90%) saturate(1228%) hue-rotate(198deg) brightness(93%) contrast(98%)}.audio-placeholder-text-3-digits{padding-inline-start:.26rem}.audio-placeholder-text-4-digits{padding-inline-start:.1rem}.any-file-attachment{padding:2px 0}.file-attachment-text-container{position:absolute;width:inherit;display:flex;align-items:center;height:100%;top:-1px}.audio-placeholder-text-3-digits-container{padding-top:1px;cursor:default}.any-file-attachment-text{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;padding-inline-start:.13em;margin-inline:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;inset-inline-end:-5px;position:absolute;display:flex;justify-content:center;cursor:pointer;-webkit-user-select:none;user-select:none}.remove-file-attachment-button:hover{background-color:#e4e4e4}.remove-file-attachment-button:active{background-color:#d7d7d7}.x-icon{color:#4e4e4e;top:-.075em;position:relative;font-size:1.05em}.modal{display:none;flex-direction:column;align-items:center;justify-content:center;position:absolute;width:80%;max-width:420px;max-height:80%;margin:auto;top:0;right:0;bottom:0;left:0;z-index:3}.modal-content{border-top:1px solid rgb(217,217,217);border-inline:1px solid rgb(217,217,217);border-start-start-radius:inherit;border-start-end-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-inline:1em}.modal-content>ul{margin-inline-end:1em}.modal-button-panel{height:3.3em;border:1px solid;border-color:rgb(223,223,223) rgb(217,217,217) rgb(217,217,217);border-end-start-radius:inherit;border-end-end-radius:inherit;background-color:#fff;text-align:center;justify-content:center;display:flex;width:100%}.modal-button{min-width:2.5em;text-align:center;color:#fff;border-radius:5px;padding:.4em .4em .3em;height:1.25em;background-color:#3279b2;inset-block:0;margin-top:auto;margin-bottom:auto;cursor:pointer;-webkit-user-select:none;user-select:none;margin-inline:.31em}.modal-button:hover{background-color:#276da7}.modal-button:active{background-color:#1b5687}.modal-svg-button{padding:0 0 2px;width:2em;height:1.8em}.modal-svg-button-icon{width:100%;height:100%;filter:brightness(0) saturate(100%) invert(100%) sepia(15%) saturate(4%) hue-rotate(346deg) brightness(101%) contrast(102%)}#modal-background-panel{position:absolute;width:100%;height:100%;background-color:#00000042;z-index:2;display:none}.show-modal-background{animation:fadeInBackground .3s ease-in-out}@keyframes fadeInBackground{0%{opacity:0}to{opacity:1}}.show-modal{animation:fadeInModal .3s ease-in-out}@keyframes fadeInModal{0%{opacity:0;scale:.95}to{opacity:1;scale:1}}.hide-modal-background{animation:fadeOutBackground .2s ease-in-out}@keyframes fadeOutBackground{0%{opacity:1}to{opacity:0}}.hide-modal{animation:fadeOutModal .2s ease-in-out}@keyframes fadeOutModal{0%{opacity:1;scale:1}to{opacity:0;scale:.95}}.modal-camera-content{overflow:hidden;text-align:center;border:unset;height:100%;background-color:#2a2a2a;display:flex;justify-content:center}.camera-modal-canvas{max-width:100%;max-height:100%;margin-top:auto;margin-bottom:auto}.modal-svg-submit-button{background-color:green}.modal-svg-submit-button:hover{background-color:#007500}.modal-svg-submit-button:active{background-color:#006500}.modal-svg-submit-disabled{pointer-events:none;background-color:#747474}.modal-svg-close-button{height:1.56em;padding-top:.37em;padding-bottom:0;background-color:#c13e3e}.modal-svg-close-button:hover{background-color:#b43434}.modal-svg-close-button:active{background-color:#972929}.modal-svg-close-icon{width:80%;height:80%}.modal-svg-camera-button{height:1.6em;padding-top:.38em;padding-bottom:0}.modal-svg-camera-icon{height:76%}.modal-svg-refresh-icon{height:105%}.modal-svg-refresh-button{height:1.66em;padding-top:.11em;padding-bottom:.21em}.input-button-container{position:relative;z-index:1}.inside-end{position:absolute;inset-inline-end:calc(10% + .35em);inset-block-end:.85em}.inside-start{position:absolute;inset-inline-start:calc(10% + .35em);inset-block-end:.85em}.outside-start{position:absolute;inset-inline-end:calc(11px - .55em);inset-block-end:.88em}.outside-end{position:absolute;inset-inline-start:calc(11px - .55em);inset-block-end:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;inset-inline-start:.11em;inset-block-end:.08em;filter:brightness(0) saturate(100%) invert(43%) sepia(0%) saturate(740%) hue-rotate(77deg) brightness(99%) contrast(92%)}#upload-gifs-icon{position:absolute;pointer-events:none;width:1.5em;height:1.48em;inset-inline-start:.07em;inset-block-end:.08em;filter:brightness(0) saturate(100%) invert(49%) sepia(0%) saturate(2586%) hue-rotate(12deg) brightness(93%) contrast(90%)}#upload-audio-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.17em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%);transform:scaleX(.95)}#camera-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.23em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(52%) sepia(0%) saturate(161%) hue-rotate(164deg) brightness(91%) contrast(92%);transform:scaleX(.95)}#upload-mixed-files-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.25em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(53%) sepia(0%) saturate(36%) hue-rotate(74deg) brightness(98%) contrast(93%);transform:scaleX(.95)}#interim-text{color:gray}#microphone-button{padding-top:.5px}.outer-button-container>#microphone-button{padding-bottom:1px}#microphone-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.25em;inset-block-end:.25em}.default-microphone-icon{filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%)}.active-microphone-icon{filter:brightness(0) saturate(100%) invert(10%) sepia(97%) saturate(7495%) hue-rotate(0deg) brightness(101%) contrast(107%);border-radius:10px}.command-microphone-icon{filter:brightness(0) saturate(100%) invert(42%) sepia(96%) saturate(1067%) hue-rotate(77deg) brightness(99%) contrast(102%)}.unsupported-microphone{display:none}#submit-icon{height:100%;filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%);width:1.21em}#stop-icon{background-color:#acacac;position:absolute;width:.95em;height:.95em;inset-inline-start:.35em;inset-block-end:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-inline:.3em}.loading-submit-button{position:relative;inset-inline-start:calc(-9990px + .275em);width:.22em;height:.22em;border-radius:5px;background-color:#848484;color:#848484;box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484;animation:loading-submit-button 1.5s infinite linear;inset-block-end:-.75em}@keyframes loading-submit-button{0%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}16.667%{box-shadow:9990px -6px #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}33.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}50%{box-shadow:9990px 0 #848484,calc(9990px + .44em) -6px 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}66.667%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}83.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) -6px 0 0 #848484}to{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}}.tooltip{position:absolute;visibility:hidden;z-index:1;pointer-events:none;padding:5px;padding-inline:7px;background-color:#333;border-radius:5px;width:max-content}.tooltip-text{color:#fff;font-size:13px}.input-button{border-radius:4px;cursor:pointer;margin-bottom:.2em;-webkit-user-select:none;user-select:none}.input-button-svg{width:1.65em;height:1.65em}.input-button-svg-text{padding:1px;height:1.65em;display:flex}.input-button-svg-text>svg{padding:.22rem}.input-button-svg-text>div{margin-inline-start:2px}.input-button:hover,.input-button:focus-visible{background-color:#9c9c9c2e}.input-button:active{background-color:#9c9c9c5e}.input-button:active:not(:hover){background-color:transparent}.loading-button{cursor:auto}.loading-button:hover{background-color:unset}.text-button{filter:unset!important;display:flex;justify-content:center;align-items:center;margin-inline:4px;height:1.6em;width:max-content}#custom-icon{height:100%;width:1.2em}.custom-button-container-default{color:#505050}.custom-button-container-default>.dropup-menu-item-icon{color:unset}.custom-button-container-default>svg{filter:brightness(0) saturate(100%) invert(39%) sepia(1%) saturate(0%) hue-rotate(83deg) brightness(93%) contrast(90%)}.custom-button-container-default>.dropup-menu-item-icon>svg{position:absolute;inset-inline-start:.2em}.custom-button-container-active{background-color:#edf7ff;color:#0285ff}.custom-button-container-active:hover,.custom-button-container-active:focus-visible{background-color:#def0ff}.custom-button-container-active:active{background-color:#d2eaff}.custom-button-container-active>svg{filter:brightness(0) saturate(100%) invert(32%) sepia(34%) saturate(4196%) hue-rotate(196deg) brightness(107%) contrast(104%)}.custom-button-container-disabled{color:#aeaeae;cursor:auto}.custom-button-container-disabled>div{pointer-events:none}.custom-button-container-disabled:hover,.custom-button-container-disabled:focus-visible{background-color:transparent}.custom-button-container-disabled:active{background-color:transparent}.custom-button-container-disabled>svg{filter:brightness(0) saturate(100%) invert(67%) sepia(0%) saturate(818%) hue-rotate(28deg) brightness(102%) contrast(100%)}#text-input-container{background-color:#fff;width:80%;display:flex;border:1px solid #0000001a;border-radius:5px;margin-top:.8em;margin-bottom:.8em;box-shadow:#959da533 0 1px 12px;overflow-y:auto;max-height:200px;position:relative}.text-input-container-start-adjustment{margin-inline-start:1.5em}.text-input-container-end-adjustment{margin-inline-end:1.5em}.text-input-container-start-small-adjustment{margin-inline-start:1.1em}.text-input-container-start-small-adjustment>.outside-start{inset-inline-end:calc(14px - .55em)}.text-input-container-end-small-adjustment{margin-inline-end:1.1em}.text-input-container-end-small-adjustment>.outside-end{inset-inline-start:calc(14px - .55em)}#text-input{text-align:start;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-start-adjustment{padding-inline-start:2.2em}.text-input-inner-end-adjustment{padding-inline-end:2em}.text-input-disabled{pointer-events:none;-webkit-user-select:none;user-select:none}[contenteditable]:empty:before{content:attr(deep-chat-placeholder-text);pointer-events:none}[contenteditable][textcolor]:empty:before{color:gray}.outside-end>#dropup-menu,.inside-end>#dropup-menu{inset-inline-end:0px}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;inset-inline-start:.265em;bottom:.43em;filter:brightness(0) saturate(100%) invert(54%) sepia(0%) saturate(724%) hue-rotate(6deg) brightness(92%) contrast(90%)}.dropup-button>*{pointer-events:none}#dropup-menu{background-color:#fff;position:absolute;transform:translateY(-100%);border-radius:5px;z-index:1;top:-.49em;box-shadow:#0003 -1px 2px 10px,#0000001a 0 2px 4px;cursor:pointer;-webkit-user-select:none;user-select:none}.dropup-menu-item{height:1.4em;padding-inline-start:.35em;padding-inline-end:.84em;padding-top:.28em;padding-bottom:.28em;display:flex;position:relative}.dropup-menu-item:hover,.dropup-menu-item:focus-visible{background-color:#f3f3f3}.dropup-menu-item:active{background-color:#ebebeb}.dropup-menu-item:active:not(:hover){background-color:transparent}.dropup-menu-item:first-child{padding-top:.49em;border-start-start-radius:inherit;border-start-end-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-end-start-radius:inherit;border-end-end-radius:inherit}.dropup-menu-item-icon{width:1.39em;position:relative}.dropup-menu-item-icon>svg{bottom:0!important;top:0!important;margin-bottom:auto;margin-top:auto}#dropup-menu-item-icon-element-custom{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.28em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%)}.dropup-menu-item-text{margin-inline-start:.56em;margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-inline:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;grid-template-columns:100%}.deep-chat-downwards-mode{display:grid}.deep-chat-upwards-mode{display:flex;flex-direction:column}::-webkit-scrollbar{width:9px;height:9px}::-webkit-scrollbar-thumb{background-color:#d0d0d0;border-radius:5px}::-webkit-scrollbar-track{background-color:#f2f2f2}.deep-chat-web-model-button{margin-top:10px;margin-bottom:5px;margin-inline-start:1px}:host{all:initial;display:table-cell;height:350px;width:320px;border:1px solid #cacaca;font-family:Inter,sans-serif,Avenir,Helvetica,Arial;font-size:.9rem;background-color:#fff;position:relative;overflow:hidden}#container{height:inherit;width:inherit;overflow:hidden}";var _d=Object.defineProperty,N=function N(i,e,t,n){for(var s=void 0,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=o(e,t,s)||s);return s&&_d(e,t,s),s;};var k=/*#__PURE__*/function(_Fi){function k(){var _this130;_classCallCheck(this,k);var e;_this130=_callSuper(this,k),_this130.getMessages=function(){return[];},_this130.submitUserMessage=function(){return console.warn(Br("submitUserMessage"));},_this130.addMessage=function(){return console.warn(Br("addMessage"));},_this130.updateMessage=function(){},_this130.clearMessages=function(){},_this130.focusInput=function(){return yn.focusFromParentElement(_this130._elementRef);},_this130.refreshMessages=function(){},_this130.scrollToBottom=function(){},_this130.disableSubmitButton=function(){},_this130.setPlaceholderText=function(){},_this130._hasBeenRendered=!1,_this130._auxiliaryStyleApplied=!1,_this130._chatStyleApplied=!1,_this130._elementRef=x(),_this130._elementRef.id="container",_this130.attachShadow({mode:"open"}).appendChild(_this130._elementRef),(e=_this130.shadowRoot)==null||e.appendChild(bt.buildElement()),Xt.apply(Ed,_this130.shadowRoot),setTimeout(function(){_this130._hasBeenRendered||_this130.onRender();},20);return _this130;}_inherits(k,_Fi);return _createClass(k,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
|
292
|
-
},{key:"onRender",value:function onRender(){var _this$_childElement;var e;
|
|
262
|
+
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(e,t,n){this.isHighlighted&&Hn.removeForPrimitive(this,e),this.primitiveTextRecorded||$n.adjustStateAfterRecodingPrimitiveElement(this,e),n&&$n.adjustSateForNoTextPrimitiveElement(this);var s=this.startPadding+this.finalTranscript+t;if(e.value=s+this.endPadding,!this.isTargetInShadow){var i=s.length+this.numberOfSpacesAfterNewText;Ue.setOffsetForPrimitive(e,i,this.autoScroll);}this.autoScroll&&vs.IS_SAFARI()&&this.isCursorAtEnd&&Jt.scrollSafariPrimitiveToEnd(e);}},{key:"updateGenericElement",value:function updateGenericElement(e,t,n){this.isHighlighted&&Hn.removeForGeneric(this,e),this.spansPopulated||Je.appendSpans(this,e);var s=(n?"":this.startPadding)+at.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=s;var i=Jt.isRequired(this.autoScroll,e);Jt.changeStateIfNeeded(this,i);var o=at.lineBreak(t)+(n?"":this.endPadding);this.interimSpan.innerHTML=o,vs.IS_SAFARI()&&this.insertInCursorLocation&&Ue.setOffsetForSafariGeneric(e,s.length+o.length),i&&Jt.scrollGeneric(this,e),n&&(this.scrollingSpan.innerHTML="");}},{key:"finalise",value:function finalise(e){this._genericElement&&(e?(this.finalSpan=Je.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=Je.createInterimSpan(),this.scrollingSpan=Je.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),ao.remove(this);}},{key:"setInterimColorToFinal",value:function setInterimColorToFinal(){this.interimSpan.style.color=this._finalTextColor||"black";}},{key:"resetState",value:function resetState(e){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,e||(this.stopTimeout=void 0);}},{key:"setStateOnStart",value:function setStateOnStart(){var e;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(e=this._onStart)==null||e.call(this);}},{key:"setStateOnStop",value:function setStateOnStop(){var e;this.recognizing=!1,this.isRestarting||(e=this._onStop)==null||e.call(this);}},{key:"setStateOnError",value:function setStateOnError(e){var t;(t=this._onError)==null||t.call(this,e),this.recognizing=!1;}}]);}();var Ss=/*#__PURE__*/function(_zo){function Ss(){_classCallCheck(this,Ss);return _callSuper(this,Ss);}_inherits(Ss,_zo);return _createClass(Ss,[{key:"start",value:function start(e){var t;this._extractText===void 0&&(this._extractText=vs.IS_SAFARI()?oo.extractSafari:oo.extract),this.validate()&&(this.prepareBeforeStart(e),this.instantiateService(e),(t=this._service)==null||t.start(),this._translations=e==null?void 0:e.translations);}},{key:"validate",value:function validate(){return Ss.getAPI()?!0:(this.error("Speech Recognition is unsupported"),!1);}},{key:"instantiateService",value:function instantiateService(e){var _ref266;var t;var n=Ss.getAPI();this._service=new n(),this._service.continuous=!0,this._service.interimResults=(_ref266=e==null?void 0:e.displayInterimResults)!==null&&_ref266!==void 0?_ref266:!0,this._service.lang=((t=e==null?void 0:e.language)==null?void 0:t.trim())||"en-US",this.setEvents();}},{key:"setEvents",value:function setEvents(){var _this99=this;this._service&&(this._service.onstart=function(){_this99.setStateOnStart();},this._service.onerror=function(e){vs.IS_SAFARI()&&e.message==="Another request is started"||e.error==="aborted"&&_this99.isRestarting||e.error!=="no-speech"&&_this99.error(e.message||e.error);},this._service.onaudioend=function(){_this99.setStateOnStop();},this._service.onend=function(){_this99._stopping=!1;},this._service.onresult=function(e){if(_typeof(e.results)>"u"&&_this99._service)_this99._service.onend=null,_this99._service.stop();else if(_this99._extractText&&!_this99._stopping){var _this99$_extractText=_this99._extractText(e,_this99.finalTranscript,_this99._translations),t=_this99$_extractText.interimTranscript,_n19=_this99$_extractText.finalTranscript,s=_this99$_extractText.newText;_this99.updateElements(t,_n19,s);}});}},{key:"stop",value:function stop(e){var t;this._stopping=!0,(t=this._service)==null||t.stop(),this.finalise(e);}},{key:"error",value:function error(e){console.error(e),this.setStateOnError(e),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.webkitSpeechRecognition||window.SpeechRecognition;}}]);}(zo);var qo=/*#__PURE__*/function(){function $s(){_classCallCheck(this,$s);}return _createClass($s,null,[{key:"doubleClickDetector",value:function doubleClickDetector(){return $s.doubleClickPending?!0:($s.doubleClickPending=!0,setTimeout(function(){$s.doubleClickPending=!1;},300),!1);}}]);}();qo.doubleClickPending=!1;var ht=qo;var co=/*#__PURE__*/function(){function co(){_classCallCheck(this,co);}return _createClass(co,null,[{key:"applyPrevention",value:function applyPrevention(e){clearTimeout(e._manualConnectionStopPrevention),e.cannotBeStopped=!0,e._manualConnectionStopPrevention=setTimeout(function(){e.cannotBeStopped=!1;},800);}},{key:"clearPrevention",value:function clearPrevention(e){clearTimeout(e._manualConnectionStopPrevention),e.cannotBeStopped=!1;}}]);}();var ki="https://github.com/OvidijusParsiunas/speech-to-element";var xs=/*#__PURE__*/function(){function xs(){_classCallCheck(this,xs);}return _createClass(xs,null,[{key:"validateOptions",value:function validateOptions(e,t){return t?!t.subscriptionKey&&!t.token&&!t.retrieveToken?(e("Please define a 'subscriptionKey', 'token' or 'retrieveToken' property - more info: ".concat(ki)),!1):t.region?!0:(e("Please define a 'region' property - more info: ".concat(ki)),!1):(e("Please provide subscription details - more info: ".concat(ki)),!1);}},{key:"getNewSpeechConfig",value:function(){var _getNewSpeechConfig=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee186(e,t){return _regenerator().w(function(_context186){while(1)switch(_context186.n){case 0:if(!t.region){_context186.n=1;break;}return _context186.a(2,t.subscriptionKey?e.fromSubscription(t.subscriptionKey.trim(),t.region.trim()):t.token?e.fromAuthorizationToken(t.token.trim(),t.region.trim()):t.retrieveToken?t.retrieveToken().then(function(n){return t.region?e.fromAuthorizationToken((n==null?void 0:n.trim())||"",t.region.trim()):null;})["catch"](function(n){return console.error(n),null;}):null);case 1:return _context186.a(2);}},_callee186);}));function getNewSpeechConfig(_x346,_x347){return _getNewSpeechConfig.apply(this,arguments);}return getNewSpeechConfig;}()},{key:"process",value:function process(e,t){t.endpointId&&(e.endpointId=t.endpointId.trim()),t.language&&(e.speechRecognitionLanguage=t.language.trim());}},{key:"get",value:function(){var _get2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee187(e,t){var n;return _regenerator().w(function(_context187){while(1)switch(_context187.n){case 0:_context187.n=1;return xs.getNewSpeechConfig(e,t);case 1:n=_context187.v;return _context187.a(2,(n&&xs.process(n,t),n));}},_callee187);}));function get(_x348,_x349){return _get2.apply(this,arguments);}return get;}()}]);}();var Vo=/*#__PURE__*/function(){function js(){_classCallCheck(this,js);}return _createClass(js,null,[{key:"set",value:// 20s
|
|
263
|
+
function set(e){e.stopTimeout=setTimeout(function(){return e.stop();},e.stopTimeoutMS);}},{key:"reset",value:function reset(e,t){e.stopTimeoutMS=t||js.DEFAULT_MS,js.stop(e),js.set(e);}},{key:"stop",value:function stop(e){e.stopTimeout&&clearTimeout(e.stopTimeout);}}]);}();Vo.DEFAULT_MS=2e4;var Bs=Vo;var dd=/*#__PURE__*/function(){function dd(){_classCallCheck(this,dd);}return _createClass(dd,null,[{key:"get",value:function get(e,t){return t?e.fromMicrophoneInput(t):e.fromDefaultMicrophoneInput();}}]);}();var lo=/*#__PURE__*/function(){function lo(){_classCallCheck(this,lo);}return _createClass(lo,null,[{key:"extract",value:// newText is used to only send new text in onResult as finalTranscript is continuously accumulated
|
|
264
|
+
function extract(e,t,n,s){return s&&(e=sr.translate(e,s)),n?{interimTranscript:"",finalTranscript:t+e,newText:e}:{interimTranscript:e,finalTranscript:t,newText:e};}}]);}();var li=/*#__PURE__*/function(_zo2){function li(){var _this100;_classCallCheck(this,li);_this100=_callSuper(this,li,arguments),_this100._newTextPadding="";return _this100;}// Unlike webspeech there is no automatic space between final results
|
|
265
|
+
_inherits(li,_zo2);return _createClass(li,[{key:"start",value:function start(e,t){this._newTextPadding="",this.stopTimeout===void 0&&Bs.reset(this,e==null?void 0:e.stopAfterSilenceMs),this.prepareBeforeStart(e),this.startAsync(e),t||co.applyPrevention(this);}},{key:"startAsync",value:function(){var _startAsync=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee188(e){var t,_t69;return _regenerator().w(function(_context188){while(1)switch(_context188.n){case 0:_t69=this.validate(e);if(!_t69){_context188.n=2;break;}_context188.n=1;return this.instantiateService(e);case 1:this._translations=e==null?void 0:e.translations;(t=this._service)==null||t.startContinuousRecognitionAsync(function(){},this.error);case 2:return _context188.a(2);}},_callee188,this);}));function startAsync(_x350){return _startAsync.apply(this,arguments);}return startAsync;}()},{key:"validate",value:function validate(e){return li.getAPI()?xs.validateOptions(this.error.bind(this),e):(this.moduleNotFound(),!1);}},{key:"instantiateService",value:function(){var _instantiateService=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee189(e){var t,n,s,i,_e$autoLanguage,o,a,c,l;return _regenerator().w(function(_context189){while(1)switch(_context189.n){case 0:t=li.getAPI();n=dd.get(t.AudioConfig,e.deviceId);_context189.n=1;return xs.get(t.SpeechConfig,e);case 1:s=_context189.v;if(s){if(e.autoLanguage&&e.autoLanguage.languages.length>0){_e$autoLanguage=e.autoLanguage,o=_e$autoLanguage.type,a=_e$autoLanguage.languages,c=a.slice(0,o==="Continuous"?10:4),l=t.AutoDetectSourceLanguageConfig.fromLanguages(c);o==="Continuous"&&(l.mode=1),i=t.SpeechRecognizer.FromConfig(s,l,n);}else i=new t.SpeechRecognizer(s,n);this.setEvents(i),this._service=i,e.retrieveToken&&this.retrieveTokenInterval(e.retrieveToken);}else this.error("Unable to contact Azure server");case 2:return _context189.a(2);}},_callee189,this);}));function instantiateService(_x351){return _instantiateService.apply(this,arguments);}return instantiateService;}()},{key:"setEvents",value:function setEvents(e){e.recognizing=this.onRecognizing.bind(this),e.recognized=this.onRecognized.bind(this),e.sessionStarted=this.onSessionStarted.bind(this),e.canceled=this.onCanceled.bind(this),e.sessionStopped=this.onSessionStopped.bind(this);}// prettier-ignore
|
|
266
|
+
},{key:"onRecognizing",value:function onRecognizing(e,t){if(this._stopping)return;var _lo$extract=lo.extract(this._newTextPadding+t.result.text,this.finalTranscript,!1,this._translations),n=_lo$extract.interimTranscript,s=_lo$extract.finalTranscript,i=_lo$extract.newText;Bs.reset(this,this.stopTimeoutMS),this.updateElements(n,s,i);}// prettier-ignore
|
|
267
|
+
},{key:"onRecognized",value:function onRecognized(e,t){var n=t.result;switch(n.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(n.text&&!this._stopping){var _lo$extract2=lo.extract(this._newTextPadding+n.text,this.finalTranscript,!0,this._translations),s=_lo$extract2.interimTranscript,i=_lo$extract2.finalTranscript,o=_lo$extract2.newText;Bs.reset(this,this.stopTimeoutMS),this.updateElements(s,i,o),i!==""&&(this._newTextPadding=" ");}break;}}},{key:"onCanceled",value:function onCanceled(e,t){t.reason===window.SpeechSDK.CancellationReason.Error&&this.error(t.errorDetails);}},{key:"onSessionStarted",value:function onSessionStarted(){co.clearPrevention(this),this.setStateOnStart();}},{key:"onSessionStopped",value:function onSessionStopped(){this._retrieveTokenInterval||clearInterval(this._retrieveTokenInterval),this._stopping=!1,this.setStateOnStop();}},{key:"retrieveTokenInterval",value:function retrieveTokenInterval(e){var _this101=this;this._retrieveTokenInterval=setInterval(function(){e==null||e().then(function(t){_this101._service&&(_this101._service.authorizationToken=(t==null?void 0:t.trim())||"");})["catch"](function(t){_this101.error(t);});},1e4);}},{key:"stop",value:function stop(e){var t;!e&&this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),this._stopping=!0,(t=this._service)==null||t.stopContinuousRecognitionAsync(),Bs.stop(this),this.finalise(e);}},{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(e){this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),console.error(e),this.setStateOnError(e),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.SpeechSDK;}}]);}(zo);var Bt=/*#__PURE__*/function(){function Bt(){_classCallCheck(this,Bt);}return _createClass(Bt,null,[{key:"toggle",value:function toggle(e,t){var n,s;var i=e.toLocaleLowerCase().trim();(n=ht.service)!=null&&n.recognizing?this.stop():i==="webspeech"?Bt.startWebSpeech(t):i==="azure"?Bt.startAzure(t):(console.error("service not found - must be either 'webspeech' or 'azure'"),(s=t==null?void 0:t.onError)==null||s.call(t,"service not found - must be either 'webspeech' or 'azure'"));}},{key:"startWebSpeech",value:function startWebSpeech(e){Bt.stop()||(ht.service=new Ss(),ht.service.start(e));}},{key:"isWebSpeechSupported",value:function isWebSpeechSupported(){return!!Ss.getAPI();}},{key:"startAzure",value:function startAzure(e){var t;Bt.stop()||(t=ht.service)!=null&&t.cannotBeStopped||(ht.service=new li(),ht.service.start(e));}},{key:"stop",value:function stop(){var e;return ht.doubleClickDetector()?!0:((e=ht.service)!=null&&e.recognizing&&ht.service.stop(),!1);}},{key:"endCommandMode",value:function endCommandMode(){ht.service&&Ge.toggleCommandModeOff(ht.service);}}]);}();var ud=/*#__PURE__*/function(){function ud(e,t){_classCallCheck(this,ud);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(ud,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this102=this;this._silenceTimeout=setTimeout(function(){var n;(n=e.submit)==null||n.call(e),Bt.stop(),_this102._stop||setTimeout(t,As.MICROPHONE_RESET_TIMEOUT_MS);},this._silenceMS);}},{key:"clearSilenceTimeout",value:function clearSilenceTimeout(){this._silenceTimeout&&clearTimeout(this._silenceTimeout);}},{key:"resetSilenceTimeout",value:function resetSilenceTimeout(e,t){this.clearSilenceTimeout(),this.setSilenceTimeout(e,t);}},{key:"onPause",value:function onPause(e,t,n){e?this.resetSilenceTimeout(t,n):this.clearSilenceTimeout();}}]);}();var us=/*#__PURE__*/function(_Si){function us(e,t,n){var _this103;_classCallCheck(this,us);var s=_typeof(e.speechToText)=="object"?e.speechToText:{};_this103=_callSuper(this,us,[s==null?void 0:s.button]);var _this103$processConfi=_this103.processConfiguration(t,e.speechToText),i=_this103$processConfi.serviceName,o=_this103$processConfi.processedConfig;if(_this103._addErrorMessage=n,i==="webspeech"&&!Bt.isWebSpeechSupported())_this103.changeToUnsupported();else{var a=!e.textInput||!e.textInput[j];q.assignButtonEvents(_this103.elementRef,_this103.buttonClick.bind(_this103,t,a,i,o));}setTimeout(function(){_this103._validationHandler=e._validationHandler;});return _this103;}// prettier-ignore
|
|
268
|
+
_inherits(us,_Si);return _createClass(us,[{key:"processConfiguration",value:function processConfiguration(e,t){var _n$displayInterimResu,_n$textColor,_n$translations,_n$commands,_n$events;var l;var n=_typeof(t)=="object"?t:{},s=_typeof(n.webSpeech)=="object"?n.webSpeech:{},i=n.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_n$displayInterimResu=n.displayInterimResults)!==null&&_n$displayInterimResu!==void 0?_n$displayInterimResu:void 0,textColor:(_n$textColor=n.textColor)!==null&&_n$textColor!==void 0?_n$textColor:void 0,translations:(_n$translations=n.translations)!==null&&_n$translations!==void 0?_n$translations:void 0,commands:(_n$commands=n.commands)!==null&&_n$commands!==void 0?_n$commands:void 0,events:(_n$events=n.events)!==null&&_n$events!==void 0?_n$events:void 0},s),i),a=(l=n.commands)==null?void 0:l.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);}),Bt.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),n.submitAfterSilence&&(this._silenceSubmit=new ud(n.submitAfterSilence,n.stopAfterSubmit)),{serviceName:us.getServiceName(n),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,n,s){var _this104=this;var i=s==null?void 0:s.events;e.removePlaceholderStyle(),Bt.toggle(n,_objectSpread({insertInCursorLocation:!1,element:t?e.inputElementRef:void 0,onError:function onError(){var o;_this104.onError(),(o=_this104._silenceSubmit)==null||o.clearSilenceTimeout();},onStart:function onStart(){var o;_this104.changeToActive(),(o=i==null?void 0:i.onStart)==null||o.call(i);},onStop:function onStop(){var o,a,c;(o=_this104._validationHandler)==null||o.call(_this104),(a=_this104._silenceSubmit)==null||a.clearSilenceTimeout(),_this104.changeToDefault(),(c=i==null?void 0:i.onStop)==null||c.call(i);},onPauseTrigger:function onPauseTrigger(o){var a,c;(a=_this104._silenceSubmit)==null||a.onPause(o,e,_this104.elementRef.onclick),(c=i==null?void 0:i.onPauseTrigger)==null||c.call(i,o);},onPreResult:function onPreResult(o,a){var c;(c=i==null?void 0:i.onPreResult)==null||c.call(i,o,a);},onResult:function onResult(o,a){var c,l,d;a&&((c=_this104._validationHandler)==null||c.call(_this104)),(l=_this104._silenceSubmit)==null||l.resetSilenceTimeout(e,_this104.elementRef.onclick),(d=i==null?void 0:i.onResult)==null||d.call(i,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this104.onCommandModeTrigger(o),(a=i==null?void 0:i.onCommandModeTrigger)==null||a.call(i,o);}},s));}},{key:"onCommandModeTrigger",value:function onCommandModeTrigger(e){e?this.changeToCommandMode():this.changeToActive();}},{key:"onError",value:function onError(){this._addErrorMessage("speechToText","speech input error");}}],[{key:"getServiceName",value:function getServiceName(e){return e.azure?"azure":"webspeech";}},{key:"toggleSpeechAfterSubmit",value:function toggleSpeechAfterSubmit(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;e[Z](),t||setTimeout(function(){return e[Z]();},us.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(Si);us.MICROPHONE_RESET_TIMEOUT_MS=300;var As=us;var Ot=/*#__PURE__*/function(){// prettier-ignore
|
|
269
|
+
function Ot(e,t,n,s,i){var _this105=this;_classCallCheck(this,Ot);this._attachments=[],this._fileCountLimit=99,this._acceptedFormat="",this._hiddenAttachments=/* @__PURE__ */new Set(),n.maxNumberOfFiles&&(this._fileCountLimit=n.maxNumberOfFiles),this._toggleContainerDisplay=s,this._fileAttachmentsContainerRef=i,n.acceptedFormats&&(this._acceptedFormat=n.acceptedFormats),setTimeout(function(){_this105._validationHandler=e._validationHandler,_this105._onInput=t.onInput;});}return _createClass(Ot,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var n;return Ot.isFileTypeValid(e,this._acceptedFormat)?(this.addAttachmentBasedOnType(e,t,!0),(n=this._onInput)==null||n.call(this,!0),!0):!1;}},{key:"addAttachmentBasedOnType",value:function addAttachmentBasedOnType(e,t,n){var s=Ot.getTypeFromBlob(e);if(s===W){var i=Ot.createImageAttachment(t);this.addFileAttachment(e,W,i,n);}else if(s===G){var _i0=ws.createAudioAttachment(t);this.addFileAttachment(e,G,_i0,n);}else{var _i1=Ot.createAnyFileAttachment(e.name);this.addFileAttachment(e,gn,_i1,n);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,n,s){var a;var i=Ot.createContainer(n);if(this._attachments.length>=this._fileCountLimit){var c=this._attachments[this._attachments.length-1].removeButton;c==null||c[Z]();var l=this._fileAttachmentsContainerRef.children;this._fileAttachmentsContainerRef.insertBefore(i,l[0]);}else this._fileAttachmentsContainerRef.appendChild(i);var o={file:e,attachmentContainerElement:i,fileType:t};return s&&(o.removeButton=this.createRemoveAttachmentButton(o),i.appendChild(o.removeButton)),this._toggleContainerDisplay(!0),this._attachments.push(o),this._fileAttachmentsContainerRef.scrollTop=this._fileAttachmentsContainerRef.scrollHeight,(a=this._validationHandler)==null||a.call(this),o;}},{key:"createRemoveAttachmentButton",value:function createRemoveAttachmentButton(e){var t=x();t[f].add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var n=x();return n[f].add("x-icon"),n.innerText="×",t.appendChild(n),t;}},{key:"removeAttachment",value:function removeAttachment(e,t){var i,o;var n=this._attachments.findIndex(function(a){return a===e;});if(n<0)return;(i=this._onInput)==null||i.call(this,!!(t!=null&&t.isTrusted));var s=this._attachments[n].attachmentContainerElement;this._attachments.splice(n,1),ws.stopAttachmentPlayback(s),s.remove(),this._toggleContainerDisplay(!1),(o=this._validationHandler)==null||o.call(this);}},{key:"getFiles",value:function getFiles(){return Array.from(this._attachments).map(function(e){return _defineProperty(_defineProperty({},ne,e[ne]),y,e.fileType);});}},{key:"hideAttachments",value:function hideAttachments(){var _this106=this;this._hiddenAttachments.clear(),this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t[Z]();}),_this106._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[Z]();});}),this._hiddenAttachments.clear();}},{key:"readdAttachments",value:function readdAttachments(){var _this107=this;var e;Array.from(this._hiddenAttachments).forEach(function(t){_this107._fileAttachmentsContainerRef.appendChild(t.attachmentContainerElement),_this107._attachments.push(t);}),(e=this._onInput)==null||e.call(this,!1),this._hiddenAttachments.clear();}}],[{key:"isFileTypeValid",value:function isFileTypeValid(e,t){if(t==="")return!0;var n=t.split(",");for(var s=0;s<n.length;s++){var i=n[s].trim();if(e[y]===i)return!0;if(i.startsWith(".")){var o=i.slice(1);if(e.name.endsWith(o))return!0;}else{if(e.name.endsWith(i))return!0;if(i.endsWith("/*")&&e[y].startsWith(i.slice(0,-2)))return!0;}}return!1;}},{key:"getTypeFromBlob",value:function getTypeFromBlob(e){var t=e.type;return t.startsWith(W)?W:t.startsWith(G)?G:gn;}},{key:"createImageAttachment",value:function createImageAttachment(e){var t=new Image();return t[T]=e,t[f].add("image-attachment"),t;}},{key:"createAnyFileAttachment",value:function createAnyFileAttachment(e){var t=x();t[f].add("border-bound-attachment"),ze.IS_SAFARI&&t[f].add("border-bound-attachment-safari");var n=x();n[f].add("any-file-attachment-text");var s=x();return s[f].add("file-attachment-text-container"),s.appendChild(n),n.textContent=e,t.appendChild(s),t;}},{key:"createContainer",value:function createContainer(e){var t=x();return t[f].add("file-attachment"),t.appendChild(e),t;}}]);}();var Lt=/*#__PURE__*/function(_Ot){// prettier-ignore
|
|
270
|
+
function Lt(e,t,n,s,i){_classCallCheck(this,Lt);return _callSuper(this,Lt,[e,t,n,s,i]);}_inherits(Lt,_Ot);return _createClass(Lt,[{key:"createTimer",value:function createTimer(e,t){var _this108=this;var n=0;var s=t!==void 0&&t<Lt.TIMER_LIMIT_S?t:Lt.TIMER_LIMIT_S;return setInterval(function(){var a;n+=1,n===s&&((a=_this108.stopPlaceholderCallback)==null||a.call(_this108),_this108.clearTimer()),n===600&&e[f].add("audio-placeholder-text-4-digits");var i=Math.floor(n/60),o=(n%60).toString().padStart(2,"0");e.textContent="".concat(i,":").concat(o);},1e3);}},{key:"createPlaceholderAudioAttachment",value:function createPlaceholderAudioAttachment(e){var t=Lt.createAudioContainer(),n=x();n[f].add("audio-placeholder-text-3-digits");var s=x();s[f].add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),s.appendChild(n);var i=Ut.createSVGElement(zi);return i[f].add("attachment-icon","stop-icon","not-removable-attachment-icon"),n.textContent="0:00",this._activePlaceholderTimer=this.createTimer(n,e),t.appendChild(s),this.addPlaceholderAudioAttachmentEvents(t,i,s),t;}},{key:"addPlaceholderAudioAttachmentEvents",value:function addPlaceholderAudioAttachmentEvents(e,t,n){var _this109=this;var s=function s(){return e.replaceChildren(t);};e.addEventListener(Cs,s);var i=function i(){return e.replaceChildren(n);};e.addEventListener(yn,i);var o=function o(){var a;return(a=_this109.stopPlaceholderCallback)==null?void 0:a.call(_this109);};e.addEventListener(Z,o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var n=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),G,n,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
|
|
271
|
+
},{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[ne]=e,Lt.addAudioElements(n.attachmentContainerElement.children[0],t),n.removeButton=this.createRemoveAttachmentButton(n),n.attachmentContainerElement.appendChild(n.removeButton),this._activePlaceholderAttachment=void 0,this.clearTimer());}},{key:"removePlaceholderAttachment",value:function removePlaceholderAttachment(){this._activePlaceholderAttachment&&(this.removeAttachment(this._activePlaceholderAttachment),this._activePlaceholderAttachment=void 0,this.clearTimer());}},{key:"clearTimer",value:function clearTimer(){this._activePlaceholderTimer!==void 0&&(clearInterval(this._activePlaceholderTimer),this._activePlaceholderTimer=void 0,this.stopPlaceholderCallback=void 0);}}],[{key:"createAudioContainer",value:function createAudioContainer(){var e=x();return e[f].add("border-bound-attachment","audio-attachment-icon-container"),ze.IS_SAFARI&&e[f].add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var n=e.parentElement?q.cloneElement(e):e,s=x(G);s[T]=t;var i=Ut.createSVGElement(Bo);i[f].add("attachment-icon","play-icon");var o=Ut.createSVGElement(zi);o[f].add("attachment-icon","stop-icon"),n.replaceChildren(i),s.onplay=function(){n.replaceChildren(o);},s.onpause=function(){n.replaceChildren(i),s.currentTime=0;},s.onended=function(){n.replaceChildren(i);},q.assignButtonEvents(n,function(){s.paused?s.play():s.pause();});}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=Lt.createAudioContainer();return Lt.addAudioElements(t,e),t;}},{key:"stopAttachmentPlayback",value:function stopAttachmentPlayback(e){var t,n,s;(s=(n=(t=e.children[0])==null?void 0:t.children)==null?void 0:n[0])!=null&&s[f].contains("stop-icon")&&e.children[0][Z]();}}]);}(Ot);Lt.TIMER_LIMIT_S=5999;var ws=Lt;var pd=/*#__PURE__*/function(){function pd(){_classCallCheck(this,pd);}return _createClass(pd,null,[{key:"create",value:// prettier-ignore
|
|
272
|
+
function create(e,t,n,s,i,o){return o===G?new ws(e,t,n,s,i):new Ot(e,t,n,s,i);}}]);}();var Is=/*#__PURE__*/function(){function Is(e,t,n){_classCallCheck(this,Is);this._fileAttachmentsTypes=[],this.elementRef=this.createAttachmentContainer();var s=_typeof(n)=="object"&&!!n.displayFileAttachmentContainer;this.toggleContainerDisplay(s),e.appendChild(this.elementRef),t&&Object.assign(this.elementRef[E],t);}// prettier-ignore
|
|
273
|
+
return _createClass(Is,[{key:"addType",value:function addType(e,t,n,s){var i=pd.create(e,t,n,this.toggleContainerDisplay.bind(this),this.elementRef,s);return this._fileAttachmentsTypes.push(i),i;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=x();return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef[E].display="block":this.elementRef.children.length===0&&(this.elementRef[E].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 _callee191(){return _regenerator().w(function(_context191){while(1)switch(_context191.n){case 0:_context191.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref268=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee190(e){var t;return _regenerator().w(function(_context190){while(1)switch(_context190.n){case 0:return _context190.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee190);}));return function(_x352){return _ref268.apply(this,arguments);};}()));case 1:return _context191.a(2);}},_callee191,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){Is.addFilesToType(e,this._fileAttachmentsTypes);}},{key:"hideFiles",value:function hideFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.hideAttachments();}),this.elementRef.replaceChildren(),this.toggleContainerDisplay(!1);}},{key:"removeHiddenFiles",value:function removeHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.removeAttachments();});}},{key:"readdHiddenFiles",value:function readdHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.readdAttachments();}),this.toggleContainerDisplay(!0);}},{key:"getNumberOfTypes",value:function getNumberOfTypes(){return this._fileAttachmentsTypes.length;}}],[{key:"addFilesToType",value:function addFilesToType(e,t){e.forEach(function(n){var s=new FileReader();s.readAsDataURL(n),s.onload=function(i){for(var o=0;o<t.length&&!t[o].attemptAddFile(n,i.target.result);o+=1);};});}}]);}();var pt=/*#__PURE__*/function(){function pt(e,t,n){_classCallCheck(this,pt);this._isOpen=!1,this._contentRef=pt.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=pt.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=pt.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=pt.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(pt,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this110=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){ge.addAttributes(t),_this110._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this111=this;this._elementRef[f].remove("show-modal"),this._elementRef[f].add("hide-modal"),this._backgroundPanelRef[f].remove("show-modal-background"),this._backgroundPanelRef[f].add("hide-modal-background"),this._isOpen=!1,setTimeout(function(){_this111._elementRef[E].display="none",_this111._backgroundPanelRef[E].display="none";},pt.MODAL_CLOSE_TIMEOUT_MS);}},{key:"displayModalElements",value:function displayModalElements(){this._elementRef[E].display="flex",this._elementRef[f].remove("hide-modal"),this._elementRef[f].add("show-modal"),this._backgroundPanelRef[E].display="block",this._backgroundPanelRef[f].remove("hide-modal-background"),this._backgroundPanelRef[f].add("show-modal-background"),this._isOpen=!0;}},{key:"openTextModal",value:function openTextModal(e){this._contentRef.innerHTML=e,this.displayModalElements();}},{key:"addCloseButton",value:function addCloseButton(e,t,n){var _this112=this;var s=t?pt.createSVGButton(e):pt.createTextButton(e);return this.addButtons(s),q.assignButtonEvents(s,function(){_this112.close(),setTimeout(function(){n==null||n();},140);}),s;}},{key:"addWindowEvents",value:function addWindowEvents(e){this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent);}},{key:"windowKeyDown",value:function windowKeyDown(e,t){var n,s;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===Ee.ESCAPE?(this.close(),(n=this.extensionCloseCallback)==null||n.call(this)):t.key===Ee.ENTER&&(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)));}}],[{key:"createContainer",value:function createContainer(e,t){var n=x();return n[f].add("modal"),n.appendChild(e),t&&delete t.backgroundColor,Object.assign(n[E],t),n;}},{key:"createModalContent",value:function createModalContent(e,t){var _n$f;var n=x();return(_n$f=n[f]).add.apply(_n$f,_toConsumableArray(e)),t&&(n[E].backgroundColor=t),x().appendChild(n),n;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=x();return t[f].add("modal-button-panel"),e&&(t[E].backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=x();return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=x();return t[f].add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=x();t[f].add("modal-button","modal-svg-button");var n=Ut.createSVGElement(e);return n[f].add("modal-svg-button-icon"),t.appendChild(n),t;}},{key:"createTextModalFunc",value:function createTextModalFunc(e,t,n){var s;if(_typeof(t)=="object"&&(s=t[m])!=null&&s.infoModal){var i=new pt(e,["modal-content"],t[m].infoModal.containerStyle);return i.addCloseButton("OK",!1,n),i.openTextModal.bind(i,t.infoModalTextMarkUp||"");}}}]);}();pt.MODAL_CLOSE_TIMEOUT_MS=190;var un=pt;var hi=/*#__PURE__*/function(_Cn5){// prettier-ignore
|
|
274
|
+
function hi(e,t,n,s,i,o){var _this113;_classCallCheck(this,hi);var u,g,b,_,v,C,N,se,fe,ie;var a=ce.processPosition((u=n==null?void 0:n.button)==null?void 0:u.position),c=((_=(b=(g=n==null?void 0:n.button)==null?void 0:g[R])==null?void 0:b[h])==null?void 0:_.content)||o,l=yt.tryCreateConfig("Upload File",(v=n==null?void 0:n.button)==null?void 0:v.tooltip);_this113=_callSuper(this,hi,[hi.createButtonElement(),i,a,l,n.button,c]);var d=_this113.createInnerElementsForStates(s,_this113.customStyles);_this113._inputElement=hi.createInputElement((C=n==null?void 0:n[m])==null?void 0:C.acceptedFormats),_this113.addClickEvent(e,n),_this113.changeElementsByState(d[R]),_this113.reapplyStateStyle(R),_this113._fileAttachmentsType=t,_this113._openModalOnce=((se=(N=n[m])==null?void 0:N.infoModal)==null?void 0:se.openModalOnce)===!1||(ie=(fe=n[m])==null?void 0:fe.infoModal)==null?void 0:ie.openModalOnce;return _this113;}_inherits(hi,_Cn5);return _createClass(hi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e,t){return _defineProperty({},R,this.createInnerElements(e,R,t));}},{key:"triggerImportPrompt",value:function triggerImportPrompt(e){e.onchange=this["import"].bind(this,e),e[Z]();}},{key:"import",value:function _import(e){Is.addFilesToType(Array.from(e[m]||[]),[this._fileAttachmentsType]),e.value="";}},{key:"addClickEvent",value:function addClickEvent(e,t){var n=this.triggerImportPrompt.bind(this,this._inputElement),s=un.createTextModalFunc(e,t,n);this.elementRef.onclick=this[Z].bind(this,s);}},{key:"click",value:function click(e){e&&(this._openModalOnce===void 0||this._openModalOnce===!0)?(e(),this._openModalOnce===!0&&(this._openModalOnce=!1)):this.triggerImportPrompt(this._inputElement);}}],[{key:"createInputElement",value:function createInputElement(e){var t=x("input");return t[y]=ne,t.accept=e||"",t.hidden=!0,t.multiple=!0,t;}},{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[f].add("input-button"),e;}}]);}(Cn);var Pt=/*#__PURE__*/function(){function Pt(){_classCallCheck(this,Pt);}return _createClass(Pt,null,[{key:"create",value:function create(e,t,n){var s=Pt.createElement(n);Pt.addEvents(s,e,t),e.appendChild(s);}},{key:"createElement",value:function createElement(e){var t=x();return t.id="drag-and-drop",_typeof(e)===U&&Object.assign(t[E],e),t;}},{key:"addEvents",value:function addEvents(e,t,n){t.ondragenter=function(s){s.preventDefault(),Pt.display(e);},e.ondragleave=function(s){s.preventDefault(),Pt.hide(e);},e.ondragover=function(s){s.preventDefault();},e.ondrop=function(s){s.preventDefault(),Pt.uploadFile(n,s),Pt.hide(e);};}},{key:"uploadFile",value:function uploadFile(e,t){var s;var n=(s=t.dataTransfer)==null?void 0:s[m];n&&e.addFilesToAnyType(Array.from(n));}},{key:"display",value:function display(e){e[E].display="block";}},{key:"hide",value:function hide(e){e[E].display="none";}},{key:"isEnabled",value:function isEnabled(e,t){return t!==void 0&&t===!1?!1:!!t||e.getNumberOfTypes()>0;}}]);}();var rn=/*#__PURE__*/function(){function rn(){_classCallCheck(this,rn);}return _createClass(rn,null,[{key:"validate",value:// prettier-ignore
|
|
275
|
+
function validate(e,t,n,s,i,o,a){var c=n.isSubmitProgrammaticallyDisabled?!1:e(s,i,a);return c?t.changeToSubmitIcon():t.changeToDisabledIcon(),o==null||o.addInputText(s||""),c;}// prettier-ignore
|
|
276
|
+
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee192(e,t,n,s,i,o){var a,c,l;return _regenerator().w(function(_context192){while(1)switch(_context192.n){case 0:a=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context192.n=1;return n.completePlaceholders();case 1:c=n.getAllFileData(),l=c==null?void 0:c.map(function(d){return d[ne];});return _context192.a(2,rn.validate(e,s,i,a,l,o));}},_callee192);}));function useValidationFunc(_x353,_x354,_x355,_x356,_x357,_x358){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
|
|
277
|
+
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee193(e,t,n,s,i){var a,o;return _regenerator().w(function(_context193){while(1)switch(_context193.n){case 0:o=(a=t[m])==null?void 0:a.map(function(c){return c[ne];});return _context193.a(2,rn.validate(e,n,s,t[h],o,i,!0));}},_callee193);}));function useValidationFuncProgrammatic(_x359,_x360,_x361,_x362,_x363){return _useValidationFuncProgrammatic.apply(this,arguments);}return useValidationFuncProgrammatic;}()},{key:"validateWebsocket",value:function validateWebsocket(e,t){var n=e.websocket,s=e.connectSettings;return n&&s.url!==Et.URL&&!ke.canSendMessage(n)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
|
|
278
|
+
},{key:"attach",value:function attach(e,t,n,s,i,o){var a=e.validateInput||ce.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref270=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee194(c){var l;return _regenerator().w(function(_context194){while(1)switch(_context194.n){case 0:if(!(i.status.loadingActive||i.status.requestInProgress||!rn.validateWebsocket(t,i))){_context194.n=1;break;}return _context194.a(2,!1);case 1:l=a||t.canSendMessage;return _context194.a(2,l?c?rn.useValidationFuncProgrammatic(l,c,i,t,o):rn.useValidationFunc(l,n,s,i,t,o):null);}},_callee194);}));return function(_x364){return _ref270.apply(this,arguments);};}();}}]);}();var Ko=/*#__PURE__*/function(){function Ko(){_classCallCheck(this,Ko);}return _createClass(Ko,null,[{key:"getFileName",value:function getFileName(e,t){var n=/* @__PURE__ */new Date(),s=String(n.getHours()).padStart(2,"0"),i=String(n.getMinutes()).padStart(2,"0"),o=String(n.getSeconds()).padStart(2,"0");return"".concat(e,"-").concat(s,"-").concat(i,"-").concat(o,".").concat(t);}}]);}();var fd=/*#__PURE__*/function(_Si2){function fd(e,t){var _this114;_classCallCheck(this,fd);var n,s;_this114=_callSuper(this,fd,[t.button]),_this114._waitingForBrowserApproval=!1,_this114._audioType=e,_this114._extension=((n=t[m])==null?void 0:n.format)||"mp3",_this114._maxDurationSeconds=(s=t[m])==null?void 0:s.maxDurationSeconds,q.assignButtonEvents(_this114.elementRef,_this114.buttonClick.bind(_assertThisInitialized(_this114)));return _this114;}_inherits(fd,_Si2);return _createClass(fd,[{key:"buttonClick",value:function buttonClick(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()));}},{key:"stop",value:function stop(){var _this115=this;return new Promise(function(e){var t,n;_this115.changeToDefault(),(t=_this115._mediaRecorder)==null||t.stop(),(n=_this115._mediaStream)==null||n.getTracks().forEach(function(s){return s.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this116=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this116.changeToActive(),_this116._mediaRecorder=new MediaRecorder(e),_this116._audioType.addPlaceholderAttachment(_this116.stop.bind(_this116),_this116._maxDurationSeconds),_this116._mediaStream=e,_this116._mediaRecorder.addEventListener("dataavailable",function(t){_this116.createFile(t);}),_this116._mediaRecorder[Qt]();})["catch"](function(e){console[p](e),_this116.stop();})["finally"](function(){_this116._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this117=this;var t=new Blob([e.data],{type:"audio/".concat(this._extension)}),n=Ko.getFileName(this._newFilePrefix||G,this._extension),s=new File([t],n,{type:t[y]}),i=new FileReader();i.readAsDataURL(s),i.onload=function(o){_this117._audioType.completePlaceholderAttachment(s,o.target.result);};}}]);}(Si);var md="<?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 pn=/*#__PURE__*/function(){function pn(){_classCallCheck(this,pn);}return _createClass(pn,null,[{key:"resetSubmit",value:function resetSubmit(e,t){t?e.unsetCustomStateStyles([Dt,lt]):e.unsetCustomStateStyles([Li,Dt,lt]),e.reapplyStateStyle(lt);}},{key:"overwriteDefaultStyleWithSubmit",value:function overwriteDefaultStyleWithSubmit(e,t){if(!e.submit)return;var n=w(e[t]||{});Le.overwritePropertyObjectFromAnother(n,e.submit,["container",A]),Le.overwritePropertyObjectFromAnother(n,e.submit,[h,"styles",A]),Le.overwritePropertyObjectFromAnother(n,e.submit,[z,"styles",A]),e[t]=n;}// prettier-ignore
|
|
279
|
+
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){Le.setPropertyValueIfDoesNotExist(e,[lt,"container",A,"backgroundColor"],""),Le.setPropertyValueIfDoesNotExist(e,[j,"container",A,"backgroundColor"],Wo),Le.setPropertyValueIfDoesNotExist(e.submit,[z,"styles",A,"filter"],""),Le.setPropertyValueIfDoesNotExist(e[j],[z,"styles",A,"filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),Le.setPropertyValueIfDoesNotExist(e[j],[h,"styles",A,"color"],"grey"),pn.overwriteDefaultStyleWithSubmit(e,j);}},{key:"process",value:function process(e){var t=w(e||{});return pn.overwriteDefaultStyleWithSubmit(t,Dt),pn.overwriteDefaultStyleWithSubmit(t,Li),e!=null&&e.alwaysEnabled||pn.setUpDisabledButton(t),t;}}]);}();var rs=/*#__PURE__*/function(_Cn6){// prettier-ignore
|
|
280
|
+
function rs(e,t,n,s,i,o){var _this118;_classCallCheck(this,rs);var a=pn.process(e.submitButtonStyles),c=md,l=yt.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this118=_callSuper(this,rs,[rs.createButtonContainerElement(),c,a==null?void 0:a.position,l,a]),_this118._isSVGLoadingIconOverriden=!1,_this118.status={requestInProgress:!1,loadingActive:!1},_this118._messages=n,_this118._textInput=t,_this118._fileAttachments=i,_this118._innerElements=_this118.createInnerElementsForStates(),_this118._stopClicked={listener:function listener(){}},_this118._serviceIO=s,_this118._alwaysEnabled=!!(a!=null&&a.alwaysEnabled),e.disableSubmitButton=_this118.disableSubmitButton.bind(_assertThisInitialized(_this118),s),_this118.attemptOverwriteLoadingStyle(e),o.microphone&&_this118.setUpSpeechToText(o.microphone.button,e.speechToText),setTimeout(function(){var d;_this118._validationHandler=e._validationHandler,_this118.assignHandlers(_this118._validationHandler),(d=_this118._validationHandler)==null||d.call(_assertThisInitialized(_this118));});return _this118;}_inherits(rs,_Cn6);return _createClass(rs,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(){var _this$createCustomEle=this.createCustomElements(),e=_this$createCustomEle.submit,t=_this$createCustomEle.loading,n=_this$createCustomEle.stop;return _defineProperty({submit:e,loading:t||[rs.createLoadingIconElement()],stop:n||[rs.createStopIconElement()]},j,this.createDisabledIconElement(e));}},{key:"createCustomElements",value:function createCustomElements(){var _this119=this;var e=Tt.createCustomElements(lt,this[z],this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(n){var s=n,i=Tt.createCustomElements(s,_this119[z],_this119.customStyles);i&&(t[s]=i);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return Tt.createCustomElements(j,this[z],this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
|
|
281
|
+
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,n,s,i,o,a,c,l,d;if(!((n=(t=this.customStyles)==null?void 0:t.submit)!=null&&n[z]||(o=(i=(s=this.customStyles)==null?void 0:s.loading)==null?void 0:i[z])!=null&&o.content||(l=(c=(a=this.customStyles)==null?void 0:a.loading)==null?void 0:c[h])!=null&&l.content)&&(e.displayLoadingBubble===void 0||e.displayLoadingBubble===!0)){var u=x("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),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 _callee195(){var _this120=this;var e,t;return _regenerator().w(function(_context195){while(1)switch(_context195.n){case 0:_context195.n=1;return this._fileAttachments.completePlaceholders();case 1:e=this._fileAttachments.getAllFileData();if(this._textInput.isTextInputEmpty())this.attemptSubmit(_defineProperty(_defineProperty({},h,""),m,e));else{t=this._textInput.inputElementRef.innerText.trim();this.attemptSubmit(_defineProperty(_defineProperty({},h,t),m,e));}(ze.IS_SAFARI||ze.IS_MOBILE)&&setTimeout(function(){return En.focusEndOfInput(_this120._textInput.inputElementRef);});case 2:return _context195.a(2);}},_callee195,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee196(e){var _this121=this;var t;return _regenerator().w(function(_context196){while(1)switch(_context196.n){case 0:typeof e=="string"&&(e=ce.processSubmitUserMessage(e));t=_defineProperty({},h,e[h]);e[m]&&(t[m]=Array.from(e[m]).map(function(n){return _defineProperty({file:n},y,Ot.getTypeFromBlob(n));})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this121.attemptSubmit(t,!0);});case 1:return _context196.a(2);}},_callee196);}));function programmaticSubmit(_x365){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
|
|
282
|
+
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee197(e){var _this122=this;var t,i,o,a,c,n,s,_args197=arguments,_t71,_t72,_t73;return _regenerator().w(function(_context197){while(1)switch(_context197.n){case 0:t=_args197.length>1&&_args197[1]!==undefined?_args197[1]:!1;_context197.n=1;return(i=this._validationHandler)==null?void 0:i.call(this,t?e:void 0);case 1:_t71=_context197.v;_t72=!1;if(!(_t71===_t72)){_context197.n=2;break;}return _context197.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();ze.IS_MOBILE&&setTimeout(function(){return _this122._textInput.inputElementRef.focus();});_t73=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t73){_context197.n=3;break;}_context197.n=3;return Vs.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context197.n=4;return this.addNewMessage(e);case 4:this._serviceIO.isWebModel()||this._messages.addLoadingMessage();n=(a=e[m])==null?void 0:a.map(function(l){return l[ne];}),s=_defineProperty(_defineProperty({},h,e[h]===""?void 0:e[h]),m,n);_context197.n=5;return this._serviceIO.callAPI(s,this._messages);case 5:(c=this._fileAttachments)==null||c.hideFiles();case 6:return _context197.a(2);}},_callee197,this);}));function attemptSubmit(_x366){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee198(_ref273){var e,t,n,s,_t74;return _regenerator().w(function(_context198){while(1)switch(_context198.n){case 0:e=_ref273.text,t=_ref273.files,n=_ref273.custom;s=_defineProperty(_defineProperty({},S,F),"custom",n);e&&(s[h]=e);_t74=t;if(!_t74){_context198.n=2;break;}_context198.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:s[m]=_context198.v;case 2:this._serviceIO.sessionId&&(s._sessionId=this._serviceIO.sessionId);Object.keys(s).length>0&&this._messages.addNewMessage(s);case 3:return _context198.a(2);}},_callee198,this);}));function addNewMessage(_x367){return _addNewMessage.apply(this,arguments);}return addNewMessage;}()},{key:"stopStream",value:function stopStream(){var e,t,n;(t=(e=this._serviceIO.streamHandlers).onAbort)==null||t.call(e),(n=this._stopClicked)==null||n.listener(),this._validationHandler&&this.resetSubmit(this._validationHandler);}},{key:"changeToStopIcon",value:function changeToStopIcon(){this._serviceIO.websocket||(this.elementRef[f].remove(Ns,Qn,Jn),ge.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle(Li,[Dt,lt]),q.assignButtonEvents(this.elementRef,this.stopStream.bind(this)),this.status.loadingActive=!1);}},{key:"changeToLoadingIcon",value:function changeToLoadingIcon(){this._serviceIO.websocket||(this._isSVGLoadingIconOverriden||this.changeElementsByState(this._innerElements.loading),this.elementRef[f].remove(Jn,Qn),ge.removeAriaDisabled(this.elementRef),this.elementRef[f].add(Ns),ge.addAriaBusy(this.elementRef),this.reapplyStateStyle(Dt,[lt]),q.assignButtonEvents(this.elementRef,function(){}),this.status.requestInProgress=!0,this.status.loadingActive=!0);}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
|
|
283
|
+
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this123=this;this.elementRef[f].contains(Jn)||(this.elementRef[f].remove(Ns,Qn),ge.removeAriaAttributes(this.elementRef),this.elementRef[f].add(Jn),this.changeElementsByState(this._innerElements.submit),pn.resetSubmit(this,this.status.loadingActive),q.assignButtonEvents(this.elementRef,function(){var e;_this123.submitFromInput(),(e=_this123._microphoneButton)!=null&&e.isActive&&As.toggleSpeechAfterSubmit(_this123._microphoneButton.elementRef,!!_this123._stopSTTAfterSubmit),setTimeout(function(){return En.focusEndOfInput(_this123._textInput.inputElementRef);});}));}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
|
|
284
|
+
},{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef[f].contains(Qn)||(this.elementRef[f].remove(Ns,Jn),ge.removeAriaBusy(this.elementRef),this.elementRef[f].add(Qn),ge.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements[j]),this.reapplyStateStyle(j,[lt]),q.assignButtonEvents(this.elementRef,function(){}));}},{key:"disableSubmitButton",value:function disableSubmitButton(e,t){var n;e.isSubmitProgrammaticallyDisabled=t!==!1,!(this.status.requestInProgress||this.status.loadingActive)&&(t===!1?(n=this._validationHandler)==null||n.call(this):this.changeToDisabledIcon(!0));}}],[{key:"createButtonContainerElement",value:function createButtonContainerElement(){var e=x();return e[f].add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=x();return e[f].add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=x();return e.id="stop-icon",e;}}]);}(Cn);var gd="<?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",bd="<?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",yd="<?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>",Ed="<?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 Cr=/*#__PURE__*/function(_un){// prettier-ignore
|
|
285
|
+
function Cr(e,t,n,s){var _this124;_classCallCheck(this,Cr);_this124=_callSuper(this,Cr,[e,["modal-content","modal-camera-content"],n]),_this124._stopped=!1,_this124._format="image/png",_this124._canvas=x("canvas"),_this124._canvas[f].add("camera-modal-canvas");var _this124$addButtonsAn=_this124.addButtonsAndTheirEvents(t),i=_this124$addButtonsAn.captureButton,o=_this124$addButtonsAn.submitButton;_this124._captureButton=i,_this124._submitButton=o,_this124._captureIcon=_this124._captureButton.children[0],_this124._refreshIcon=Ut.createSVGElement(gd),_this124._refreshIcon[f].add("modal-svg-button-icon","modal-svg-refresh-icon"),(s==null?void 0:s.format)==="jpeg"&&(_this124._format="image/jpeg"),s!=null&&s.dimensions&&(_this124._dimensions=s.dimensions),_this124._contentRef.appendChild(_this124._canvas),_this124.extensionCloseCallback=_this124.stop;return _this124;}_inherits(Cr,_un);return _createClass(Cr,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=un.createSVGButton(bd);t[f].add("modal-svg-camera-button"),t.children[0][f].add("modal-svg-camera-icon");var n=this.addCloseButton(yd,!0);n[f].add("modal-svg-close-button"),n.children[0][f].add("modal-svg-close-icon");var s=un.createSVGButton(Ed);return s[f].add("modal-svg-submit-button"),this.addButtons(t,s),this.addButtonEvents(t,n,s,e),{captureButton:t,submitButton:s};}// prettier-ignore
|
|
286
|
+
},{key:"addButtonEvents",value:function addButtonEvents(e,t,n,s){var _this125=this;q.assignButtonEvents(e,this.capture.bind(this)),q.assignButtonEvents(t,this.stop.bind(this)),q.assignButtonEvents(n,function(){var i=_this125.getFile();i&&Is.addFilesToType([i],[s]),_this125.stop(),_this125.close();});}},{key:"stop",value:function stop(){var _this126=this;this._mediaStream&&this._mediaStream.getTracks().forEach(function(e){return e.stop();}),this._stopped=!0,setTimeout(function(){_this126._captureButton.replaceChildren(_this126._captureIcon),_this126._captureButton[f].replace("modal-svg-refresh-button","modal-svg-camera-button");var e=_this126._canvas.getContext("2d");e==null||e.clearRect(0,0,_this126._canvas.width,_this126._canvas.height);},un.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this127=this;this._dataURL=void 0,this._submitButton[f].add("modal-svg-submit-".concat(j)),this._stopped=!1,navigator.mediaDevices.getUserMedia({video:this._dimensions||!0}).then(function(e){if(_this127._mediaStream=e,!_this127.isOpen())return _this127.stop();var t=x("video");t.srcObject=e,t.play(),requestAnimationFrame(_this127.updateCanvas.bind(_this127,t,_this127._canvas));})["catch"](function(e){console[p](e),_this127.stop(),_this127.close();});}},{key:"capture",value:function capture(){this._dataURL?(this._captureButton.replaceChildren(this._captureIcon),this._captureButton[f].replace("modal-svg-refresh-button","modal-svg-camera-button"),this._submitButton[f].add("modal-svg-submit-".concat(j)),this._dataURL=void 0):(this._captureButton.replaceChildren(this._refreshIcon),this._captureButton[f].replace("modal-svg-camera-button","modal-svg-refresh-button"),this._submitButton[f].remove("modal-svg-submit-".concat(j)),this._dataURL=this._canvas.toDataURL());}},{key:"getFile",value:function getFile(){if(this._dataURL){var e=atob(this._dataURL.split(",")[1]),t=new Array(e.length);for(var a=0;a<e.length;a++)t[a]=e.charCodeAt(a);var _n20=new Uint8Array(t),s=new Blob([_n20],{type:this._format}),i=this._format==="image/jpeg"?"jpeg":"png",o=Ko.getFileName(this._newFilePrefix||"photo",i);return new File([s],o,{type:s[y]});}}},{key:"updateCanvas",value:function updateCanvas(e,t){if(!this._stopped){if(!this._dataURL){t.width=e.videoWidth,t.height=e.videoHeight;var _n21=t.getContext("2d");_n21==null||_n21.drawImage(e,0,0,t.width,t.height);}requestAnimationFrame(this.updateCanvas.bind(this,e,t));}}},{key:"openCameraModal",value:function openCameraModal(e){this.displayModalElements(),e[Qt]();}// prettier-ignore
|
|
287
|
+
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,n,s){var i=new Cr(e,t,n,s);return i.openCameraModal.bind(i,i);}}]);}(un);var _d="<?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 Tr=/*#__PURE__*/function(_Cn7){function Tr(e,t,n){var _this128;_classCallCheck(this,Tr);var l,d,u,g,b,_;var s=ce.processPosition((l=n==null?void 0:n.button)==null?void 0:l.position),i=((g=(u=(d=n==null?void 0:n.button)==null?void 0:d[R])==null?void 0:u[h])==null?void 0:g.content)||"Photo",o=yt.tryCreateConfig("Camera",(b=n==null?void 0:n.button)==null?void 0:b.tooltip),a=((_=n==null?void 0:n.button)==null?void 0:_[R])||{};_this128=_callSuper(this,Tr,[Tr.createButtonElement(),_d,s,o,a,i]);var c=_this128.createInnerElementsForStates(_this128.customStyles);n&&_this128.addClickEvent(e,t,n.modalContainerStyle,n[m]),_this128.changeElementsByState(c[R]),_this128.reapplyStateStyle(R);return _this128;}_inherits(Tr,_Cn7);return _createClass(Tr,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty({},R,this.createInnerElements("camera-icon",R,e));}},{key:"addClickEvent",value:// prettier-ignore
|
|
288
|
+
function addClickEvent(e,t,n,s){var i=Cr.createCameraModalFunc(e,t,n,s);q.assignButtonEvents(this.elementRef,i);}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[f].add("input-button"),e;}}]);}(Cn);var Ln=/*#__PURE__*/function(){function Ln(e,t,n,s){_classCallCheck(this,Ln);this.elementRef=Ln.createPanelElement(e.inputAreaStyle);var i={},o=this.createFileUploadComponents(e,n,s,i),a=new qs(e,n,o,t.browserStorage);e.speechToText&&!i.microphone&&(i.microphone={button:new As(e,a,t.addNewErrorMessage.bind(t))});var c=new rs(e,a,t,n,o,i);a.submit=c.submitFromInput.bind(c),rn.attach(e,n,a,o,c,t.browserStorage),e.submitUserMessage=c.programmaticSubmit.bind(c),i.submit={button:c},e.customButtons&&mn.add(e,i),Ln.addElements(this.elementRef,a,i,s,o,e.dropupStyles),Ln.assignOnInput(e,n,o,a);}return _createClass(Ln,[{key:"createFileUploadComponents",value:// prettier-ignore
|
|
289
|
+
function createFileUploadComponents(e,t,n,s){var o,a,c,l;var i=new Is(this.elementRef,e.attachmentContainerStyle,t.demo);if(Ln.createUploadButtons(e,t,t.fileTypes||{},i,n,s),(o=t[Fe])!=null&&o[m]){var d=((a=s[Q])==null?void 0:a.fileType)||i.addType(e,t,t[Fe][m],Q);s[Fe]={button:new Tr(n,d,t[Fe])};}if((c=t.recordAudio)!=null&&c[m]){var _d3=((l=s[G])==null?void 0:l.fileType)||i.addType(e,t,t.recordAudio[m],G);s.microphone={button:new fd(_d3,t.recordAudio)};}return Pt.isEnabled(i,e.dragAndDrop)&&Pt.create(n,i,e.dragAndDrop),i;}// prettier-ignore
|
|
290
|
+
}],[{key:"createPanelElement",value:function createPanelElement(e){var t=x();return t.id="input",Object.assign(t[E],e),t;}},{key:"createUploadButtons",value:function createUploadButtons(e,t,n,s,i,o){Object.keys(n).forEach(function(a){var c=a,l=n[c];if(l[m]){var d=s.addType(e,t,l[m],c),_ld$c=ld[c],u=_ld$c.id,g=_ld$c.svgString,b=_ld$c.dropupText,_=new hi(i,d,l,u,g,b);o[c]={button:_,fileType:d};}});}// prettier-ignore
|
|
291
|
+
},{key:"addElements",value:function addElements(e,t,n,s,i,o){q.addElements(e,t.elementRef);var a=qn.create(),c=Ne.addButtons(a,n,s,o);is.set(t.inputElementRef,a,i.elementRef,c),qn.add(e,a);}},{key:"assignOnInput",value:function assignOnInput(e,t,n,s){t.onInput=function(i){setTimeout(function(){var o=n.getAllFileData(),a=s.inputElementRef.innerText.trim(),c=_defineProperty({},h,a);o&&(c[m]=o.map(function(l){return l[ne];})),vn.onInput(e,c,i);});};}}]);}();var Rr=/*#__PURE__*/function(){function Rr(){_classCallCheck(this,Rr);}return _createClass(Rr,null,[{key:"createElements",value:function createElements(e,t,n){var s=x();s.id="chat-view";var i=!e.focusMode&&e.upwardsMode;s.classList.add(i?ed:Qh);var o=new ot(e,t,n);t.websocket&&ke.createConnection(t,o);var a=new Ln(e,o,t,s),c=i?o.elementRef.parentElement:o.elementRef;return q.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var i=Rr.createElements(e,n,s);t.replaceChildren(i),n.isCustomView()&&n.setUpView(i,t);}}]);}();var vd="#validate-property-key-view{height:100%;position:relative;display:flex;justify-content:center;align-items:center;padding:8px}#loading-validate-key-property{display:inline-block;width:50px;height:50px}#loading-validate-key-property:after{content:\" \";display:block;width:38px;height:38px;margin:1px;border-radius:50%;border:5px solid #5fb2ff;border-color:#5fb2ff transparent #5fb2ff transparent;animation:loading-spinner 1.4s linear infinite}#deep-chat-openai-realtime-container{height:100%;width:100%}#deep-chat-openai-realtime-avatar-container{height:60%;width:100%;display:flex;justify-content:center;align-items:center}#deep-chat-openai-realtime-avatar{border-radius:50%;height:110px;border:1px solid rgb(215,215,215);padding:8px;-webkit-user-select:none;user-select:none;margin-top:20px}#deep-chat-openai-realtime-buttons-container{height:40%;display:flex;position:relative}.deep-chat-openai-realtime-button-container{height:100%;width:50%;display:flex;justify-content:center;align-items:center}.deep-chat-openai-realtime-button{width:70px;height:70px;border-radius:50%;display:flex;justify-content:center;align-items:center;cursor:pointer}.deep-chat-openai-realtime-button-default{background-color:#e3e3e3}.deep-chat-openai-realtime-button-default:hover{background-color:#d4d4d4}.deep-chat-openai-realtime-button-default:active{background-color:#c5c5c5}.deep-chat-openai-realtime-button-loading{opacity:.7;pointer-events:none}.deep-chat-openai-realtime-microphone-active{background-color:#ffe7e7}.deep-chat-openai-realtime-microphone-active:hover{background-color:#ffdede}.deep-chat-openai-realtime-microphone-active:active{background-color:#ffd2d2}.deep-chat-openai-realtime-microphone>*{height:30px;width:30px}.deep-chat-openai-realtime-microphone-active>*{filter:brightness(0) saturate(100%) invert(35%) sepia(60%) saturate(1360%) hue-rotate(325deg) brightness(95%) contrast(92%)}.deep-chat-openai-realtime-toggle>*{height:32px;width:32px;padding-inline-start:3px;filter:brightness(0) saturate(100%) invert(22%) sepia(0%) saturate(4537%) hue-rotate(208deg) brightness(105%) contrast(91%)}.deep-chat-openai-realtime-button-unavailable{opacity:.45;pointer-events:none}#deep-chat-openai-realtime-error{color:red;position:absolute;top:calc(50% + 40px);inset-inline-start:50%;transform:translate(-50%,-50%);font-size:17px}#deep-chat-openai-realtime-loading{position:absolute;font-size:15px;top:50%;inset-inline-start:50%;transform:translate(-50%,-50%)}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;inset-block-start:44%;inset-inline-start:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-inline-end:2.7em;width:calc(100% - 80px)}#insert-key-input{padding:.3em 1.7em .3em .3em;border-width:1px;border-style:solid;border-radius:3px;width:100%;font-size:inherit}.insert-key-input-valid{border-color:gray}.insert-key-input-invalid{border-color:red}#visibility-icon-container{position:relative;float:inline-end;cursor:pointer;-webkit-user-select:none;user-select:none}.visibility-icon{filter:brightness(0) saturate(100%) invert(63%) sepia(1%) saturate(9%) hue-rotate(43deg) brightness(98%) contrast(92%);position:absolute;inset-inline-end:-1.7em;inset-block-start:-1.43em}#visible-icon{inset-block-start:-1.4em}.visibility-icon:hover{filter:unset}.visibility-icon>*{pointer-events:none}#start-button{border:1px solid grey;color:#454545;border-radius:4px;width:3em;display:flex;justify-content:center;align-items:center;cursor:pointer;padding:.28em .3em;-webkit-user-select:none;user-select:none;background-color:#fff}#start-button:hover{background-color:#f2f2f2}#start-button:active{background-color:#d2d2d2}#insert-key-help-text-container{width:100%;position:absolute;margin-top:32px;margin-bottom:20px}#insert-key-help-text-contents{width:100%;position:absolute}#insert-key-input-invalid-text{display:block;margin-top:1em;margin-bottom:.5em;color:red}.insert-key-input-help-text{display:block;margin-top:16px}#loading-key{display:inline-block;width:16px;height:16px}#loading-key:after{content:\" \";display:block;width:11px;height:11px;margin:1px;border-radius:50%;border:2px solid #0084ff;border-color:#0084ff transparent #0084ff transparent;animation:loading-spinner 1.2s linear infinite}#error-view{color:red;font-size:1.2em;line-height:1.3em;margin-top:-5px;text-align:center;height:100%;display:flex;justify-content:center;align-items:center;padding-inline:8px}@keyframes loading-spinner{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.intro-panel{position:absolute;display:flex;justify-content:center;right:0;bottom:0;left:0;margin:auto;height:fit-content;top:-2.5em}pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!\n Theme: a11y-dark\n Author: @ericwbailey\n Maintainer: @ericwbailey\n\n Based on the Tomorrow Night Eighties theme: https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css\n*/.hljs{background:#2b2b2b;color:#f8f8f2}.hljs-comment,.hljs-quote{color:#d4d0ab}.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#ffa07a}.hljs-built_in,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#f5ab35}.hljs-attribute{color:gold}.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#abe338}.hljs-section,.hljs-title{color:#00e0e0}.hljs-keyword,.hljs-selector-tag{color:#dcc6e0}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}@media screen and (-ms-high-contrast:active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}}#messages,.deep-chat-upwards-mode #messages>div{overflow:auto;overflow-anchor:none}.deep-chat-upwards-mode #messages{height:100%;display:flex;flex-direction:column;justify-content:flex-end}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-inline:auto;width:calc(97.5% - 24px);max-width:100%}.message-bubble{margin-top:10px;word-wrap:break-word;width:fit-content;max-width:60%;border-radius:10px;padding:.42em .55em;height:fit-content;line-height:1.26}.user-message-text{color:#fff;background-color:#0084ff;margin-inline-end:0px;margin-inline-start:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-inline-start:0px;margin-inline-end:auto}.deep-chat-last-group-messages-active{height:100%}#scroll-button{position:absolute;top:75%;left:50%;right:50%;transform:translate(-50%,-50%);transition:opacity .1s ease;display:flex;opacity:0;padding:8px;background-color:#fff;border:.5px solid #000000;justify-content:center;align-items:center;white-space:nowrap;cursor:pointer}#scroll-button:hover{background-color:#fafafa}.loading-history-message-full-view{position:absolute;height:70%;width:100%;display:flex;align-items:center}.deep-chat-upwards-mode #messages .loading-history-message-full-view{height:100%}.loading-history-message-small{height:20px;margin-bottom:30px}.loading-history-message-small>div>div{scale:.6}.loading-history-message{margin-top:0;width:100%;max-width:100%;display:flex;justify-content:center;background-color:unset}.loading-history{width:70px}.loading-history div{position:absolute;width:var(--loading-history-width);height:var(--loading-history-height);margin:var(--loading-history-margin);border:var(--loading-history-border);border-radius:50%;animation:loading-spinner 1.2s cubic-bezier(.5,0,.5,1) infinite;border-color:var(--loading-history-color) transparent transparent transparent}.loading-history div:nth-child(1){animation-delay:-.45s}.loading-history div:nth-child(2){animation-delay:-.3s}.loading-history div:nth-child(3){animation-delay:-.15s}.html-message{max-width:unset}.error-message-text{margin-inline:auto;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%;margin-top:14px;margin-bottom:10px}.deep-chat-loading-message-dots-container{width:1em;padding-top:.6em;padding-bottom:.6em;padding-inline-start:1.3em;padding-inline-end:.75em}.loading-message-dots{position:relative;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite linear alternate;animation-delay:.5s}.loading-message-dots:before,.loading-message-dots:after{content:\"\";display:inline-block;position:absolute;top:0}.loading-message-dots:before{inset-inline-start:-.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:0s}.loading-message-dots:after{inset-inline-start:.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:1s}@keyframes loading-message-dots{0%{background-color:var(--loading-message-color)}50%,to{background-color:var(--loading-message-color-fade)}}.message-bubble>p:first-child,.message-bubble>.partial-render-message>p:first-child,.html-wrapper>p:first-child{margin-top:0}.message-bubble>p:last-child,.message-bubble>.partial-render-message:last-child>p,.html-wrapper>p:last-child{margin-bottom:0}pre{overflow:auto;display:block;word-break:break-all;word-wrap:break-word;border-radius:7px;background:#2b2b2b;color:#f8f8f2;margin-top:.8em;margin-bottom:.8em;padding:.6em;font-size:.9em;line-height:1.5em}.image-message{padding:0;display:flex;background-color:#ddd}.image-message>*,.image-message>*>*{width:100%;border-radius:8px;display:flex}.audio-message{width:60%;max-width:300px;height:2.2em;max-height:54px;padding:0;background-color:unset}.audio-player{width:100%;height:100%}.audio-player-safari{height:fit-content;width:40px}.audio-player-safari-start{float:inline-start}.audio-player-safari-end{float:inline-end}.any-file-message{padding:1px}.any-file-message-contents{display:flex}.any-file-message-icon-container{width:1.3em;min-width:1.3em;position:relative;border-radius:4px;margin-inline-start:6px;margin-inline-end:2px}.any-file-message-icon{background-color:#fff;border-radius:4px;position:absolute;width:1em;height:1.25em;padding:1px;margin-top:auto;margin-bottom:auto;top:0;bottom:0}.any-file-message-text{padding-top:5px;overflow-wrap:anywhere;padding-bottom:5px;padding-inline-end:7px}.message-bubble>a{color:inherit}.start-item-position{margin-inline-end:10px}.end-item-position{margin-inline-start:10px}.role-hidden{display:none}.avatar{padding-top:5px;width:1.5em;height:1.5em;border-radius:1px}.avatar-container{margin-top:9px}.name{margin-top:16px;font-size:15px}#drag-and-drop{position:absolute;display:none;z-index:10;height:calc(100% - 10px);width:calc(100% - 10px);background-color:#70c6ff4d;border:5px dashed #6dafff}#file-attachment-container{position:absolute;height:3.6em;width:calc(80% - 4px);top:-2.5em;border-radius:5px;overflow:auto;text-align:start;background-color:#d7d7d73b;padding-inline-start:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-inline-end:.6em;margin-bottom:.44em;margin-top:4px;position:relative;background-color:#fff;border-radius:5px}.image-attachment{width:100%;height:100%;object-fit:cover;border-radius:5px}.border-bound-attachment{width:calc(100% - 2px);height:calc(100% - 2px);border:1px solid #c3c3c3;border-radius:5px;overflow:hidden}.border-bound-attachment-safari{width:calc(100% - 1px);height:calc(100% - 1px)}.audio-attachment-icon-container{cursor:pointer}.audio-attachment-icon-container:hover{background-color:#f8f8f8}.attachment-icon{inset-inline:0;bottom:0;top:2px;margin:auto;position:absolute;width:25px;-webkit-user-select:none;user-select:none}.not-removable-attachment-icon{top:0;right:0;bottom:0;left:0}.play-icon{filter:brightness(0) saturate(100%) invert(17%) sepia(0%) saturate(1392%) hue-rotate(67deg) brightness(98%) contrast(97%)}.stop-icon{filter:brightness(0) saturate(100%) invert(29%) sepia(90%) saturate(1228%) hue-rotate(198deg) brightness(93%) contrast(98%)}.audio-placeholder-text-3-digits{padding-inline-start:.26rem}.audio-placeholder-text-4-digits{padding-inline-start:.1rem}.any-file-attachment{padding:2px 0}.file-attachment-text-container{position:absolute;width:inherit;display:flex;align-items:center;height:100%;top:-1px}.audio-placeholder-text-3-digits-container{padding-top:1px;cursor:default}.any-file-attachment-text{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;padding-inline-start:.13em;margin-inline:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;inset-inline-end:-5px;position:absolute;display:flex;justify-content:center;cursor:pointer;-webkit-user-select:none;user-select:none}.remove-file-attachment-button:hover{background-color:#e4e4e4}.remove-file-attachment-button:active{background-color:#d7d7d7}.x-icon{color:#4e4e4e;top:-.075em;position:relative;font-size:1.05em}.modal{display:none;flex-direction:column;align-items:center;justify-content:center;position:absolute;width:80%;max-width:420px;max-height:80%;margin:auto;top:0;right:0;bottom:0;left:0;z-index:3}.modal-content{border-top:1px solid rgb(217,217,217);border-inline:1px solid rgb(217,217,217);border-start-start-radius:inherit;border-start-end-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-inline:1em}.modal-content>ul{margin-inline-end:1em}.modal-button-panel{height:3.3em;border:1px solid;border-color:rgb(223,223,223) rgb(217,217,217) rgb(217,217,217);border-end-start-radius:inherit;border-end-end-radius:inherit;background-color:#fff;text-align:center;justify-content:center;display:flex;width:100%}.modal-button{min-width:2.5em;text-align:center;color:#fff;border-radius:5px;padding:.4em .4em .3em;height:1.25em;background-color:#3279b2;inset-block:0;margin-top:auto;margin-bottom:auto;cursor:pointer;-webkit-user-select:none;user-select:none;margin-inline:.31em}.modal-button:hover{background-color:#276da7}.modal-button:active{background-color:#1b5687}.modal-svg-button{padding:0 0 2px;width:2em;height:1.8em}.modal-svg-button-icon{width:100%;height:100%;filter:brightness(0) saturate(100%) invert(100%) sepia(15%) saturate(4%) hue-rotate(346deg) brightness(101%) contrast(102%)}#modal-background-panel{position:absolute;width:100%;height:100%;background-color:#00000042;z-index:2;display:none}.show-modal-background{animation:fadeInBackground .3s ease-in-out}@keyframes fadeInBackground{0%{opacity:0}to{opacity:1}}.show-modal{animation:fadeInModal .3s ease-in-out}@keyframes fadeInModal{0%{opacity:0;scale:.95}to{opacity:1;scale:1}}.hide-modal-background{animation:fadeOutBackground .2s ease-in-out}@keyframes fadeOutBackground{0%{opacity:1}to{opacity:0}}.hide-modal{animation:fadeOutModal .2s ease-in-out}@keyframes fadeOutModal{0%{opacity:1;scale:1}to{opacity:0;scale:.95}}.modal-camera-content{overflow:hidden;text-align:center;border:unset;height:100%;background-color:#2a2a2a;display:flex;justify-content:center}.camera-modal-canvas{max-width:100%;max-height:100%;margin-top:auto;margin-bottom:auto}.modal-svg-submit-button{background-color:green}.modal-svg-submit-button:hover{background-color:#007500}.modal-svg-submit-button:active{background-color:#006500}.modal-svg-submit-disabled{pointer-events:none;background-color:#747474}.modal-svg-close-button{height:1.56em;padding-top:.37em;padding-bottom:0;background-color:#c13e3e}.modal-svg-close-button:hover{background-color:#b43434}.modal-svg-close-button:active{background-color:#972929}.modal-svg-close-icon{width:80%;height:80%}.modal-svg-camera-button{height:1.6em;padding-top:.38em;padding-bottom:0}.modal-svg-camera-icon{height:76%}.modal-svg-refresh-icon{height:105%}.modal-svg-refresh-button{height:1.66em;padding-top:.11em;padding-bottom:.21em}.input-button-container{position:relative;z-index:1}.inside-end{position:absolute;inset-inline-end:calc(10% + .35em);inset-block-end:.85em}.inside-start{position:absolute;inset-inline-start:calc(10% + .35em);inset-block-end:.85em}.outside-start{position:absolute;inset-inline-end:calc(11px - .55em);inset-block-end:.88em}.outside-end{position:absolute;inset-inline-start:calc(11px - .55em);inset-block-end:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;inset-inline-start:.11em;inset-block-end:.08em;filter:brightness(0) saturate(100%) invert(43%) sepia(0%) saturate(740%) hue-rotate(77deg) brightness(99%) contrast(92%)}#upload-gifs-icon{position:absolute;pointer-events:none;width:1.5em;height:1.48em;inset-inline-start:.07em;inset-block-end:.08em;filter:brightness(0) saturate(100%) invert(49%) sepia(0%) saturate(2586%) hue-rotate(12deg) brightness(93%) contrast(90%)}#upload-audio-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.17em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%);transform:scaleX(.95)}#camera-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.23em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(52%) sepia(0%) saturate(161%) hue-rotate(164deg) brightness(91%) contrast(92%);transform:scaleX(.95)}#upload-mixed-files-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.25em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(53%) sepia(0%) saturate(36%) hue-rotate(74deg) brightness(98%) contrast(93%);transform:scaleX(.95)}#interim-text{color:gray}#microphone-button{padding-top:.5px}.outer-button-container>#microphone-button{padding-bottom:1px}#microphone-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.25em;inset-block-end:.25em}.default-microphone-icon{filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%)}.active-microphone-icon{filter:brightness(0) saturate(100%) invert(10%) sepia(97%) saturate(7495%) hue-rotate(0deg) brightness(101%) contrast(107%);border-radius:10px}.command-microphone-icon{filter:brightness(0) saturate(100%) invert(42%) sepia(96%) saturate(1067%) hue-rotate(77deg) brightness(99%) contrast(102%)}.unsupported-microphone{display:none}#submit-icon{height:100%;filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%);width:1.21em}#stop-icon{background-color:#acacac;position:absolute;width:.95em;height:.95em;inset-inline-start:.35em;inset-block-end:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-inline:.3em}.loading-submit-button{position:relative;inset-inline-start:calc(-9990px + .275em);width:.22em;height:.22em;border-radius:5px;background-color:#848484;color:#848484;box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484;animation:loading-submit-button 1.5s infinite linear;inset-block-end:-.75em}@keyframes loading-submit-button{0%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}16.667%{box-shadow:9990px -6px #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}33.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}50%{box-shadow:9990px 0 #848484,calc(9990px + .44em) -6px 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}66.667%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}83.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) -6px 0 0 #848484}to{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}}.tooltip{position:absolute;visibility:hidden;z-index:1;pointer-events:none;padding:5px;padding-inline:7px;background-color:#333;border-radius:5px;width:max-content}.tooltip-text{color:#fff;font-size:13px}.input-button{border-radius:4px;cursor:pointer;margin-bottom:.2em;-webkit-user-select:none;user-select:none}.input-button-svg{width:1.65em;height:1.65em}.input-button-svg-text{padding:1px;height:1.65em;display:flex}.input-button-svg-text>svg{padding:.22rem}.input-button-svg-text>div{margin-inline-start:2px}.input-button:hover,.input-button:focus-visible{background-color:#9c9c9c2e}.input-button:active{background-color:#9c9c9c5e}.input-button:active:not(:hover){background-color:transparent}.loading-button{cursor:auto}.loading-button:hover{background-color:unset}.text-button{filter:unset!important;display:flex;justify-content:center;align-items:center;margin-inline:4px;height:1.6em;width:max-content}#custom-icon{height:100%;width:1.2em}.custom-button-container-default{color:#505050}.custom-button-container-default>.dropup-menu-item-icon{color:unset}.custom-button-container-default>svg{filter:brightness(0) saturate(100%) invert(39%) sepia(1%) saturate(0%) hue-rotate(83deg) brightness(93%) contrast(90%)}.custom-button-container-default>.dropup-menu-item-icon>svg{position:absolute;inset-inline-start:.2em}.custom-button-container-active{background-color:#edf7ff;color:#0285ff}.custom-button-container-active:hover,.custom-button-container-active:focus-visible{background-color:#def0ff}.custom-button-container-active:active{background-color:#d2eaff}.custom-button-container-active>svg{filter:brightness(0) saturate(100%) invert(32%) sepia(34%) saturate(4196%) hue-rotate(196deg) brightness(107%) contrast(104%)}.custom-button-container-disabled{color:#aeaeae;cursor:auto}.custom-button-container-disabled>div{pointer-events:none}.custom-button-container-disabled:hover,.custom-button-container-disabled:focus-visible{background-color:transparent}.custom-button-container-disabled:active{background-color:transparent}.custom-button-container-disabled>svg{filter:brightness(0) saturate(100%) invert(67%) sepia(0%) saturate(818%) hue-rotate(28deg) brightness(102%) contrast(100%)}#text-input-container{background-color:#fff;width:80%;display:flex;border:1px solid #0000001a;border-radius:5px;margin-top:.8em;margin-bottom:.8em;box-shadow:#959da533 0 1px 12px;overflow-y:auto;max-height:200px;position:relative}.text-input-container-start-adjustment{margin-inline-start:1.5em}.text-input-container-end-adjustment{margin-inline-end:1.5em}.text-input-container-start-small-adjustment{margin-inline-start:1.1em}.text-input-container-start-small-adjustment>.outside-start{inset-inline-end:calc(14px - .55em)}.text-input-container-end-small-adjustment{margin-inline-end:1.1em}.text-input-container-end-small-adjustment>.outside-end{inset-inline-start:calc(14px - .55em)}#text-input{text-align:start;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-start-adjustment{padding-inline-start:2.2em}.text-input-inner-end-adjustment{padding-inline-end:2em}.text-input-disabled{pointer-events:none;-webkit-user-select:none;user-select:none}[contenteditable]:empty:before{content:attr(deep-chat-placeholder-text);pointer-events:none}[contenteditable][textcolor]:empty:before{color:gray}.outside-end>#dropup-menu,.inside-end>#dropup-menu{inset-inline-end:0px}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;inset-inline-start:.265em;bottom:.43em;filter:brightness(0) saturate(100%) invert(54%) sepia(0%) saturate(724%) hue-rotate(6deg) brightness(92%) contrast(90%)}.dropup-button>*{pointer-events:none}#dropup-menu{background-color:#fff;position:absolute;transform:translateY(-100%);border-radius:5px;z-index:1;top:-.49em;box-shadow:#0003 -1px 2px 10px,#0000001a 0 2px 4px;cursor:pointer;-webkit-user-select:none;user-select:none}.dropup-menu-item{height:1.4em;padding-inline-start:.35em;padding-inline-end:.84em;padding-top:.28em;padding-bottom:.28em;display:flex;position:relative}.dropup-menu-item:hover,.dropup-menu-item:focus-visible{background-color:#f3f3f3}.dropup-menu-item:active{background-color:#ebebeb}.dropup-menu-item:active:not(:hover){background-color:transparent}.dropup-menu-item:first-child{padding-top:.49em;border-start-start-radius:inherit;border-start-end-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-end-start-radius:inherit;border-end-end-radius:inherit}.dropup-menu-item-icon{width:1.39em;position:relative}.dropup-menu-item-icon>svg{bottom:0!important;top:0!important;margin-bottom:auto;margin-top:auto}#dropup-menu-item-icon-element-custom{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.28em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%)}.dropup-menu-item-text{margin-inline-start:.56em;margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-inline:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;grid-template-columns:100%}.deep-chat-downwards-mode{display:grid}.deep-chat-upwards-mode{display:flex;flex-direction:column}::-webkit-scrollbar{width:9px;height:9px}::-webkit-scrollbar-thumb{background-color:#d0d0d0;border-radius:5px}::-webkit-scrollbar-track{background-color:#f2f2f2}.deep-chat-web-model-button{margin-top:10px;margin-bottom:5px;margin-inline-start:1px}:host{all:initial;display:table-cell;height:350px;width:320px;border:1px solid #cacaca;font-family:Inter,sans-serif,Avenir,Helvetica,Arial;font-size:.9rem;background-color:#fff;position:relative;overflow:hidden}#container{height:inherit;width:inherit;overflow:hidden}";var Sd=Object.defineProperty,O=function O(r,e,t,n){for(var s=void 0,i=r.length-1,o;i>=0;i--)(o=r[i])&&(s=o(e,t,s)||s);return s&&Sd(e,t,s),s;};var k=/*#__PURE__*/function(_Hi){function k(){var _this129;_classCallCheck(this,k);var e;_this129=_callSuper(this,k),_this129.getMessages=function(){return[];},_this129.submitUserMessage=function(){return console.warn(Dr("submitUserMessage"));},_this129.addMessage=function(){return console.warn(Dr("addMessage"));},_this129.updateMessage=function(){},_this129.clearMessages=function(){},_this129.focusInput=function(){return En.focusFromParentElement(_this129._elementRef);},_this129.refreshMessages=function(){},_this129.scrollToBottom=function(){},_this129.disableSubmitButton=function(){},_this129.setPlaceholderText=function(){},_this129._hasBeenRendered=!1,_this129._auxiliaryStyleApplied=!1,_this129._chatStyleApplied=!1,_this129._elementRef=x(),_this129._elementRef.id="container",_this129.attachShadow({mode:"open"}).appendChild(_this129._elementRef),(e=_this129.shadowRoot)==null||e.appendChild(yt.buildElement()),Zt.apply(vd,_this129.shadowRoot),setTimeout(function(){_this129._hasBeenRendered||_this129.onRender();},20);return _this129;}_inherits(k,_Hi);return _createClass(k,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
|
292
|
+
},{key:"onRender",value:function onRender(){var _this$_childElement;var e;tr.attemptAppendStyleSheetToHead(this.style,(e=this.chatStyle)==null?void 0:e.fontFamily),ce.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=Jh.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(Zt.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),this.chatStyle&&!this._chatStyleApplied&&(Zt.applyChatStyle(this.chatStyle,this.shadowRoot),this._chatStyleApplied=!0),ce.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?Gs.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],Rr.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof M&&Oe.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||vn.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){Es.chat=void 0;}}]);}(Hi);O([P("object")],k.prototype,"connect");O([P("object")],k.prototype,"directConnection");O([P("object")],k.prototype,"webModel");O([P("object")],k.prototype,"requestBodyLimits");O([P("function")],k.prototype,"requestInterceptor");O([P("function")],k.prototype,"responseInterceptor");O([P("function")],k.prototype,"validateInput");O([P("function")],k.prototype,"loadHistory");O([P("object")],k.prototype,"chatStyle");O([P("object")],k.prototype,"attachmentContainerStyle");O([P("object")],k.prototype,"dropupStyles");O([P("object")],k.prototype,"inputAreaStyle");O([P("object")],k.prototype,"textInput");O([P("object")],k.prototype,"defaultInput");O([P("object")],k.prototype,"submitButtonStyles");O([P("object")],k.prototype,"customButtons");O([P("string")],k.prototype,"auxiliaryStyle");O([P("array")],k.prototype,"history");O([P("object")],k.prototype,"browserStorage");O([P("object")],k.prototype,"introMessage");O([P("object")],k.prototype,"avatars");O([P("object")],k.prototype,"names");O([P("object")],k.prototype,"displayLoadingBubble");O([P("object")],k.prototype,"errorMessages");O([P("object")],k.prototype,"messageStyles");O([P("object")],k.prototype,"textToSpeech");O([P("object")],k.prototype,"speechToText");O([P("object")],k.prototype,"images");O([P("object")],k.prototype,"gifs");O([P("object")],k.prototype,"camera");O([P("object")],k.prototype,"audio");O([P("object")],k.prototype,"microphone");O([P("object")],k.prototype,"mixedFiles");O([P("object")],k.prototype,"dragAndDrop");O([P("object")],k.prototype,"htmlWrappers");O([P("object")],k.prototype,"htmlClassUtilities");O([P("object")],k.prototype,"remarkable");O([P("object")],k.prototype,"focusMode");O([P("boolean")],k.prototype,"upwardsMode");O([P("object")],k.prototype,"scrollButton");O([P("object")],k.prototype,"hiddenMessages");O([P("number")],k.prototype,"maxVisibleMessages");O([P("function")],k.prototype,"onMessage");O([P("function")],k.prototype,"onClearMessages");O([P("function")],k.prototype,"onComponentRender");O([P("function")],k.prototype,"onInput");O([P("function")],k.prototype,"onError");O([P("object")],k.prototype,"demo");O([P("object")],k.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",k);export{k as DeepChat};
|