deep-chat-dev 9.0.365 → 9.0.367
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 +17545 -17468
- package/dist/deepChat.bundle.js +1 -1
- package/dist/deepChat.js +182 -167
- package/dist/services/claude/claudeIO.d.ts +5 -0
- package/dist/services/claude/claudeIO.d.ts.map +1 -1
- package/dist/services/openAI/realtime/openAIRealtimeIO.d.ts.map +1 -1
- package/dist/types/claude.d.ts +13 -1
- package/dist/types/claude.d.ts.map +1 -1
- package/dist/types/claudeInternal.d.ts +3 -2
- package/dist/types/claudeInternal.d.ts.map +1 -1
- package/dist/views/chat/messages/stream/messageStream.d.ts +1 -0
- package/dist/views/chat/messages/stream/messageStream.d.ts.map +1 -1
- package/package.json +2 -2
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(_n20){function n(){return _n20.apply(this,arguments);}n.toString=function(){return _n20.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 m="classList",v="style",ga="unset",ba="html-wrapper",X="length",A=function A(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var ya=/*#__PURE__*/function(){function ya(){_classCallCheck(this,ya);}return _createClass(ya,null,[{key:"render",value:function render(e,t){var n=A();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var zs=/*#__PURE__*/function(){function zs(){_classCallCheck(this,zs);}return _createClass(zs,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=A();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=zs.createElements(),r={onSuccess:t,onFail:ya.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:zs.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var ae="service",h="text",L="html",f="error",Z="https://deepchat.dev/docs/",ne="ai",F="user",gt="assistant",Vs="error-message-text",Ns="deep-chat-outer-container-role-",Or="empty-message",Ii="deep-chat-top-message",Nr="deep-chat-middle-message",Mi="deep-chat-bottom-message",T="src",E="type",se="file",b="files",W="image",ee="images",Fe="camera",Cn="gifs",$="audio",ct="microphone",Lo="mixedFiles",on="any",Oo="file-message",qt="start",No="end",Bo="messages",Br="0",Dr="1",x="role",Ee="string",ce=function ce(i){return JSON.stringify(i);},C=function C(i){return JSON.parse(ce(i));};function Fr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function _a(i){return i&&ce(i);}function rr(i,e,t,n){var s="\n".concat(Fr(e)," message: ").concat(ce(i)," \n"),r=t?"".concat(Fr(e)," message after interceptor: ").concat(_a(n)," \n"):"";return s+r;}function Ea(i,e,t,n){return"".concat(rr(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat(Z,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat(Z,"interceptors#responseInterceptor");}function va(i,e,t){var n="response";return"".concat(rr(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Sa(i,e){var t="request";return"".concat(rr(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function xa(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var Tn=Ea,Aa=Sa,wa=va,Ur=xa,pe="Invalid API Key",Ue="Failed to connect",He="Request settings have not been set up",bi="No file was added",or="Image was not found",Do="Multi-response arrays are not supported for streaming",Fo="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat(Z,"interceptors#responseInterceptor"),Ca="Cannot mix {text: string} and {html: string} responses.",Ta="No valid stream events were sent.\n".concat(Fo),Ra="Readable Stream connection error.",Gt="Please define a `function_handler` property inside the service config.",an="Function tool response must be an array or contain a text property",Uo="Failed to fetch history";var jt=/*#__PURE__*/function(){function jt(){_classCallCheck(this,jt);}return _createClass(jt,null,[{key:"apply",value:function apply(e,t){if(t)try{jt.applyStyleSheet(e,t);}catch(_unused){jt.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=A("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(jt.camelToKebab(s),": ").concat(r,";");}).join(" ");n&&jt.apply(":host { ".concat(n," }"),t);}}]);}();var In="inside-start",ft="inside-end",Le="outside-start",ve="outside-end",et="dropup-menu",w="default",De="hover",J="click",H="active",j="disabled",G="svg",Nt="unavailable",R="styles",ks="mouseenter",cn="mouseleave",Ia="mousedown",Ma="mouseup",st="submit",It="loading",Bi="stop",Un="unsupported",bn="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[v],n);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t[J]&&de.unsetStyle(e,t[J]),t[De]&&de.unsetStyle(e,t[De]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){de.unsetActivityCSSMouseStates(e,t),t[w]&&de.unsetStyle(e,t[w]);}// if you want to asdd default styling - use pure css classes
|
|
2
|
-
},{key:"processStateful",value:function processStateful(e){var t=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);}var f="classList",E="style",Vo="unset",Ko="html-wrapper",W="length",x=function x(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var Wo=/*#__PURE__*/function(){function Wo(){_classCallCheck(this,Wo);}return _createClass(Wo,null,[{key:"render",value:function render(e,t){var n=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:Wo.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-",Ir="empty-message",Si="deep-chat-top-message",Mr="deep-chat-middle-message",xi="deep-chat-bottom-message",T="src",y="type",ne="file",m="files",K="image",Q="images",Fe="camera",Bn="gifs",$="audio",pt="microphone",co="mixedFiles",mn="any",lo="file-message",Jt="start",ho="end",uo="messages",kr="0",Lr="1",S="role",_e="string",ae=function ae(i){return JSON.stringify(i);},w=function w(i){return JSON.parse(ae(i));};function Pr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function Xo(i){return i&&ae(i);}function tr(i,e,t,n){var s="\n".concat(Pr(e)," message: ").concat(ae(i)," \n"),r=t?"".concat(Pr(e)," message after interceptor: ").concat(Xo(n)," \n"):"";return s+r;}function Zo(i,e,t,n){return"".concat(tr(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 Yo(i,e,t){var n="response";return"".concat(tr(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Jo(i,e){var t="request";return"".concat(tr(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function Qo(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var On=Zo,ea=Jo,ta=Yo,Nr=Qo,ue="Invalid API Key",He="Failed to connect",je="Request settings have not been set up",pi="No file was added",nr="Image was not found",po="Multi-response arrays are not supported for streaming",fo="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"),na="Cannot mix {text: string} and {html: string} responses.",sa="No valid stream events were sent.\n".concat(fo),ia="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",mo="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",st="dropup-menu",A="default",De="hover",Y="click",H="active",j="disabled",G="svg",$t="unavailable",R="styles",As="mouseenter",bn="mouseleave",ra="mousedown",oa="mouseup",at="submit",Ot="loading",Mi="stop",Zn="unsupported",Cn="commandMode";var le=/*#__PURE__*/function(){function le(){_classCallCheck(this,le);}return _createClass(le,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]&&le.unsetStyle(e,t[Y]),t[De]&&le.unsetStyle(e,t[De]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){le.unsetActivityCSSMouseStates(e,t),t[A]&&le.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[Y]);return _defineProperty(_defineProperty(_defineProperty({},A,t),De,n),Y,s);}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t=_defineProperty(_defineProperty(_defineProperty({},A,{}),De,{}),Y,{});return e.forEach(function(n){t[A]=Object.assign(t[A],n[A]),t[De]=Object.assign(t[De],n[De]),t[Y]=Object.assign(t[Y],n[Y]);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e[A]||[]).forEach(function(n){var r;var s=n;t[E][s]&&(r=e[A])!=null&&r[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 rn=/*#__PURE__*/function(){function rn(){_classCallCheck(this,rn);}return _createClass(rn,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(),r=e.getBoundingClientRect(),a=t.getBoundingClientRect().width/2,c=r.left+r.width/2;t[E].left="".concat(c-a-s.left,"px"),t[E].top="".concat(r.top-36-s.top,"px");var l=t.getBoundingClientRect();l.left<s.left?t[E].left="".concat(rn.OVERFLOW_NEW_POSITION_PX,"px"):l.right>s.right&&(t[E].left="".concat(s.width-l.width-rn.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,n){return n||(n=rn.traverseParentUntilContainer(e).nextSibling),t[h]&&(n.children[0].textContent=t[h]),{timeout:setTimeout(function(){n[E].visibility="visible",rn.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]&&le.unsetStyle(e.element,t[E]),e.element[E].left="",e.element[E].top="";}}]);}();rn.OVERFLOW_NEW_POSITION_PX=4;var bt=rn;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 Ge=os;var Ee=/* @__PURE__ */function(i){return i.ESCAPE="Escape",i.ENTER="Enter",i.TAB="Tab",i.ARROW_UP="ArrowUp",i.ARROW_DOWN="ArrowDown",i.ARROW_RIGHT="ArrowRight",i.ARROW_LEFT="ArrowLeft",i.BACKSPACE="Backspace",i.DELETE="Delete",i.META="Meta",i.CONTROL="Control",i;}(Ee||{});var on=/*#__PURE__*/function(){function on(){_classCallCheck(this,on);}return _createClass(on,null,[{key:"add",value:// prettier-ignore
|
|
3
|
+
function add(e,t,n,s){n!==void 0&&e.addEventListener("keydown",on.onKeyDown.bind(this,n)),e.oninput=on.onInput.bind(this,n,s),e.addEventListener("paste",function(r){var o;r.preventDefault(),(o=r.clipboardData)!=null&&o[m].length&&t.addFilesToAnyType(Array.from(r.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[
|
|
5
|
+
},{key:"onKeyDown",value:function onKeyDown(e,t){var s=t.target.textContent;s&&s.length>=e&&!on.PERMITTED_KEYS.has(t.key)&&!on.isKeyCombinationPermitted(t)&&t.preventDefault();}},{key:"isKeyCombinationPermitted",value:function isKeyCombinationPermitted(e){return e.key==="a"?e.ctrlKey||e.metaKey:!1;}},{key:"onInput",value:function onInput(e,t,n){var s=n.target,r=s.textContent||"";e!==void 0&&r.length>e&&(s.textContent=r.substring(0,e),yn.focusEndOfInput(s)),t==null||t();}}]);}();on.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 ki=on;var aa=/*#__PURE__*/function(){function aa(){_classCallCheck(this,aa);}return _createClass(aa,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 qt=/*#__PURE__*/function(){function qt(e,t,n,s){var _this=this;_classCallCheck(this,qt);var o,a,c,l;this._isComposing=!1;var r=qt.processConfig(t,e.textInput);this.elementRef=qt.createContainerElement((o=r==null?void 0:r[R])==null?void 0:o.container),this._config=r,this.inputElementRef=this.createInputElement((a=e.defaultInput)==null?void 0:a[h],s),qt.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(){ki.add(_this.inputElementRef,n,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(qt,[{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="",yn.focusEndOfInput(this.inputElementRef),(n=this._onInput)==null||n.call(this,!1),(s=this._browserStorage)==null||s.addInputText("")),Ge.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(e,t){var s,r,o,a;var n=x();return n.id=qt.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||""),Ge.IS_MOBILE&&n.setAttribute("tabindex","0"),Ge.IS_CHROMIUM&&qt.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],(r=this._config.placeholder)==null?void 0:r[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]&&(le.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",aa.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){le.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef[E],t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===Ee.ENTER&&!Ge.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[
|
|
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 r=(n==null?void 0:n[s])||(n==null?void 0:n[
|
|
14
|
-
},{key:"overwrite",value:function overwrite(e,t,n,s){var r=e.messageToElements,o=B.overwriteMessage(r,s,t,n,L,Dt.HTML_BUBBLE_CLASS);return o&&Dt.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=Dt.createElements(e,t,n,s);return B.fillEmptyMessageElement(r.bubbleElement,t),oe.apply(e,r.outerContainer),le.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&&oe.isTemporaryBasedOnHTML(t))return;var o=Dt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();Dt.HTML_BUBBLE_CLASS="html-message";var yt=Dt;var Ba=/*#__PURE__*/function(){function Ba(){_classCallCheck(this,Ba);}return _createClass(Ba,null,[{key:"katex",value:function katex(e,t,n){var a=(n||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var c=function c(p,u){var g;return((g=window.katex)==null?void 0:g.renderToString(p,_objectSpread({displayMode:u,throwOnError:!1,output:"mathml"},e)))||"";},l=function l(p,u,g){var y=!1,_=p.bMarks[u]+p.tShift[u],S=p.eMarks[u];if(_+1>S)return!1;var M=p[T].charAt(_);if(M!==a)return!1;var K=_;_=p.skipChars(_,M);var ie=_-K;if(ie!==2)return!1;var re=u;for(;++re,!(re>=g||(_=K=p.bMarks[re]+p.tShift[re],S=p.eMarks[re],_<S&&p.tShift[re]<p.blkIndent));)if(p[T].charAt(_)===a&&!(p.tShift[re]-p.blkIndent>=4)&&(_=p.skipChars(_,M),!(_-K<ie)&&(_=p.skipSpaces(_),!(_<S)))){y=!0;break;}ie=p.tShift[u],p.line=re+(y?1:0);var Re=p.getLines(u+1,re,ie,!0).replace(/[ \n]+/g," ").trim();return p.tokens.push({type:"katex",params:null,content:Re,lines:[u,p.line],level:p.level,block:!0}),!0;},d=function d(p,u){var g=p.pos,y=p.posMax;var _=g;if(p[T].charAt(_)!==a)return!1;for(++_;_<y&&p[T].charAt(_)===a;)++_;var S=p[T].slice(g,_);if(S.length>2)return!1;var M=_;var K=0;for(;_<y;){var ie=p[T].charAt(_);if(ie==="{"&&(_===0||p[T].charAt(_-1)!=="\\"))K+=1;else if(ie==="}"&&(_===0||p[T].charAt(_-1)!=="\\")){if(K-=1,K<0)return!1;}else if(ie===a&&K===0){var re=_;var Re=_+1;for(;Re<y&&p[T].charAt(Re)===a;)++Re;if(Re-re===S.length){if(!u){var Lt=p[T].slice(M,re).replace(/[ \n]+/g," ").trim();p.push({type:"katex",content:Lt,block:S.length>1,level:p.level});}return p.pos=Re,!0;}}_+=1;}return u||(p.pending+=S),p.pos+=S.length,!0;};t.inline.ruler.push("katex",d,n),t.block.ruler.push("katex",l,n),t.renderer.rules.katex=function(p,u){return c(p[u].content,p[u].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var Ds;function jo(i){return Ds=Ds||document.createElement("textarea"),Ds.innerHTML="&"+i+";",Ds.value;}var Da=Object.prototype.hasOwnProperty;function Fa(i,e){return i?Da.call(i,e):!1;}function $o(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 Ua=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function xs(i){return i.indexOf("\\")<0?i:i.replace(Ua,"$1");}function qo(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 Ui(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 Ha=/&([a-z#][a-z0-9]{1,31});/gi,ja=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function $a(i,e){var t=0,n=jo(e);return e!==n?n:e.charCodeAt(0)===35&&ja.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),qo(t))?Ui(t):i;}function dn(i){return i.indexOf("&")<0?i:i.replace(Ha,$a);}var qa=/[&<>"]/,Ga=/[&<>"]/g,za={"&":"&","<":"<",">":">",'"':"""};function Va(i){return za[i];}function Ge(i){return qa.test(i)?i.replace(Ga,Va):i;}var I={};I.blockquote_open=function(){return"<blockquote>\n";};I.blockquote_close=function(i,e){return"</blockquote>"+pn(i,e);};I.code=function(i,e){return i[e].block?"<pre><code>"+Ge(i[e].content)+"</code></pre>"+pn(i,e):"<code>"+Ge(i[e].content)+"</code>";};I.fence=function(i,e,t,n,s){var r=i[e],o="",a=t.langPrefix,c="",l,d,p;if(r.params){if(l=r.params.split(/\s+/g),d=l.join(" "),Fa(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=Ge(dn(xs(d))),o=' class="'+a+c+'"';}return t.highlight?p=t.highlight.apply(t.highlight,[r.content].concat(l))||Ge(r.content):p=Ge(r.content),"<pre><code"+o+">"+p+"</code></pre>"+pn(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>")+pn(i,e);};I.bullet_list_open=function(){return"<ul>\n";};I.bullet_list_close=function(i,e){return"</ul>"+pn(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>"+pn(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?pn(i,e):"");};I.link_open=function(i,e,t){var n=i[e].title?' title="'+Ge(dn(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Ge(i[e].href)+'"'+n+s+">";};I.link_close=function(){return"</a>";};I.image=function(i,e,t){var n=' src="'+Ge(i[e].src)+'"',s=i[e].title?' title="'+Ge(dn(i[e].title))+'"':"",r=' alt="'+(i[e].alt?Ge(dn(xs(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>"+Ge(i[e].content)+"</sub>";};I.sup=function(i,e){return"<sup>"+Ge(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 Ge(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="'+Ge(dn(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 Go(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?Go(i,e+2):e;}var pn=I.getBreak=function(e,t){return t=Go(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function dr(){this.rules=$o({},I),this.getBreak=I.getBreak;}dr.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;};dr.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 Ye(){this.__rules__=[],this.__cache__=null;}Ye.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};Ye.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));});});};Ye.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;};Ye.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;};Ye.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;};Ye.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};Ye.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;};Ye.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;};Ye.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function Ka(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 fn(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;}fn.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};fn.prototype.push=function(i){this.pending&&this.pushPending(),this.tokens.push(i),this.pendingLevel=this.level;};fn.prototype.cacheSet=function(i,e){for(var t=this.cache.length;t<=i;t++)this.cache.push(0);this.cache[i]=e;};fn.prototype.cacheGet=function(i){return i<this.cache.length?this.cache[i]:0;};function As(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 fn(i,e,t,n,[]),r=As(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 Xa(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 Hi(i){var e=dn(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function zo(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=Hi(xs(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=xs(i.src.slice(r,e)),!i.parser.validateLink(s))?!1:(i.linkContent=s,i.pos=e,!0);}function Vo(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=xs(i.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function Ko(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function Za(i,e,t,n){var s,r,o,a,c,l,d,p,u;if(i.charCodeAt(0)!==91||i.indexOf("]:")===-1||(s=new fn(i,e,t,n,[]),r=As(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(!zo(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&&Vo(s,o)?(p=s.linkContent,o=s.pos):(p="",o=l);o<a&&s.src.charCodeAt(o)===32;)o++;return o<a&&s.src.charCodeAt(o)!==10?-1:(u=Ko(i.slice(1,r)),_typeof(n.references[u])>"u"&&(n.references[u]={title:p,href:d}),o);}function Ya(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=Za(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 Ja(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 Qa(i){var e,t,n,s,r,o,a,c,l,d=0,p=!1,u={};if(i.env.footnotes&&(i.tokens=i.tokens.filter(function(g){return g.type==="footnote_reference_open"?(p=!0,c=[],l=g.label,!1):g.type==="footnote_reference_close"?(p=!1,u[":"+l]=c,!1):(p&&c.push(g),!p);}),!!i.env.footnotes.list)){for(o=i.env.footnotes.list,i.tokens.push({type:"footnote_block_open",level:d++}),e=0,t=o.length;e<t;e++){for(i.tokens.push({type:"footnote_open",id:e,level:d++}),o[e].tokens?(a=[],a.push({type:"paragraph_open",tight:!1,level:d++}),a.push({type:"inline",content:"",level:d,children:o[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--d})):o[e].label&&(a=u[":"+o[e].label]),i.tokens=i.tokens.concat(a),i.tokens[i.tokens.length-1].type==="paragraph_close"?r=i.tokens.pop():r=null,s=o[e].count>0?o[e].count:1,n=0;n<s;n++)i.tokens.push({type:"footnote_anchor",id:e,subId:n,level:d});r&&i.tokens.push(r),i.tokens.push({type:"footnote_close",level:--d});}i.tokens.push({type:"footnote_block_close",level:--d});}}var qr=" \n()[]'\".,!?-";function ki(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function ec(i){var e,t,n,s,r,o,a,c,l,d,p,u,g=i.tokens;if(i.env.abbreviations){for(i.env.abbrRegExp||(u="(^|["+qr.split("").map(ki).join("")+"])("+Object.keys(i.env.abbreviations).map(function(y){return y.substr(1);}).sort(function(y,_){return _.length-y.length;}).map(ki).join("|")+")($|["+qr.split("").map(ki).join("")+"])",i.env.abbrRegExp=new RegExp(u,"g")),d=i.env.abbrRegExp,t=0,n=g.length;t<n;t++)if(g[t].type==="inline"){for(s=g[t].children,e=s.length-1;e>=0;e--)if(r=s[e],r.type==="text"){for(c=0,o=r.content,d.lastIndex=0,l=r.level,a=[];p=d.exec(o);)d.lastIndex>c&&a.push({type:"text",content:o.slice(c,p.index+p[1].length),level:l}),a.push({type:"abbr_open",title:i.env.abbreviations[":"+p[2]],level:l++}),a.push({type:"text",content:p[2],level:l}),a.push({type:"abbr_close",level:--l}),c=d.lastIndex-p[3].length;a.length&&(c<o.length&&a.push({type:"text",content:o.slice(c),level:l}),g[t].children=s=[].concat(s.slice(0,e),a,s.slice(e+1)));}}}}var tc=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,nc=/\((c|tm|r|p)\)/ig,sc={c:"©",r:"®",p:"§",tm:"™"};function ic(i){return i.indexOf("(")<0?i:i.replace(nc,function(e,t){return sc[t.toLowerCase()];});}function rc(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=ic(n),tc.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 oc=/['"]/,Gr=/['"]/g,ac=/[-\s()\[\]]/,zr="’";function Vr(i,e){return e<0||e>=i.length?!1:!ac.test(i[e]);}function yn(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function cc(i){var e,t,n,s,r,o,a,c,l,d,p,u,g,y,_,S,M;if(i.options.typographer){for(M=[],_=i.tokens.length-1;_>=0;_--)if(i.tokens[_].type==="inline"){for(S=i.tokens[_].children,M.length=0,e=0;e<S.length;e++)if(t=S[e],!(t.type!=="text"||oc.test(t.text))){for(a=S[e].level,g=M.length-1;g>=0&&!(M[g].level<=a);g--);M.length=g+1,n=t.content,r=0,o=n.length;e:for(;r<o&&(Gr.lastIndex=r,s=Gr.exec(n),!!s);){if(c=!Vr(n,s.index-1),r=s.index+1,y=s[0]==="'",l=!Vr(n,r),!l&&!c){y&&(t.content=yn(t.content,s.index,zr));continue;}if(p=!l,u=!c,u){for(g=M.length-1;g>=0&&(d=M[g],!(M[g].level<a));g--)if(d.single===y&&M[g].level===a){d=M[g],y?(S[d.token].content=yn(S[d.token].content,d.pos,i.options.quotes[2]),t.content=yn(t.content,s.index,i.options.quotes[3])):(S[d.token].content=yn(S[d.token].content,d.pos,i.options.quotes[0]),t.content=yn(t.content,s.index,i.options.quotes[1])),M.length=g;continue e;}}p?M.push({token:e,pos:s.index,single:y,level:a}):u&&y&&(t.content=yn(t.content,s.index,zr));}}}}}var Pi=[["block",Ka],["abbr",Xa],["references",Ya],["inline",Ja],["footnote_tail",Qa],["abbr2",ec],["replacements",rc],["smartquotes",cc]];function Wo(){this.options={},this.ruler=new Ye();for(var i=0;i<Pi.length;i++)this.ruler.push(Pi[i][0],Pi[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 mn(i,e,t,n,s){var r,o,a,c,l,d,p;for(this.src=i,this.parser=e,this.options=t,this.env=n,this.tokens=s,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,d=0,p=!1,a=c=d=0,l=o.length;c<l;c++){if(r=o.charCodeAt(c),!p)if(r===32){d++;continue;}else p=!0;(r===10||c===l-1)&&(r!==10&&c++,this.bMarks.push(a),this.eMarks.push(c),this.tShift.push(d),p=!1,d=0,a=c+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}mn.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};mn.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};mn.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};mn.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};mn.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;};mn.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 lc(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 dc(i,e,t,n){var s,r,o,a,c,l=!1,d=i.bMarks[e]+i.tShift[e],p=i.eMarks[e];if(d+3>p||(s=i.src.charCodeAt(d),s!==126&&s!==96)||(c=d,d=i.skipChars(d,s),r=d-c,r<3)||(o=i.src.slice(d,p).trim(),o.indexOf("`")>=0))return!1;if(n)return!0;for(a=e;a++,!(a>=t||(d=c=i.bMarks[a]+i.tShift[a],p=i.eMarks[a],d<p&&i.tShift[a]<i.blkIndent));)if(i.src.charCodeAt(d)===s&&!(i.tShift[a]-i.blkIndent>=4)&&(d=i.skipChars(d,s),!(d-c<r)&&(d=i.skipSpaces(d),!(d<p)))){l=!0;break;}return r=i.tShift[e],i.line=a+(l?1:0),i.tokens.push({type:"fence",params:o,content:i.getLines(e+1,a,r,!0),lines:[e,i.line],level:i.level}),!0;}function hc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_=i.bMarks[e]+i.tShift[e],S=i.eMarks[e];if(_>S||i.src.charCodeAt(_++)!==62||i.level>=i.options.maxNesting)return!1;if(n)return!0;for(i.src.charCodeAt(_)===32&&_++,c=i.blkIndent,i.blkIndent=0,a=[i.bMarks[e]],i.bMarks[e]=_,_=_<S?i.skipSpaces(_):_,r=_>=S,o=[i.tShift[e]],i.tShift[e]=_-i.bMarks[e],p=i.parser.ruler.getRules("blockquote"),s=e+1;s<t&&(_=i.bMarks[s]+i.tShift[s],S=i.eMarks[s],!(_>=S));s++){if(i.src.charCodeAt(_++)===62){i.src.charCodeAt(_)===32&&_++,a.push(i.bMarks[s]),i.bMarks[s]=_,_=_<S?i.skipSpaces(_):_,r=_>=S,o.push(i.tShift[s]),i.tShift[s]=_-i.bMarks[s];continue;}if(r)break;for(y=!1,u=0,g=p.length;u<g;u++)if(p[u](i,s,t,!0)){y=!0;break;}if(y)break;a.push(i.bMarks[s]),o.push(i.tShift[s]),i.tShift[s]=-1337;}for(l=i.parentType,i.parentType="blockquote",i.tokens.push({type:"blockquote_open",lines:d=[e,0],level:i.level++}),i.parser.tokenize(i,e,s),i.tokens.push({type:"blockquote_close",level:--i.level}),i.parentType=l,d[1]=i.line,u=0;u<o.length;u++)i.bMarks[u+e]=a[u],i.tShift[u+e]=o[u];return i.blkIndent=c,!0;}function uc(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 Kr(i,e){var t,n,s;return n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e],n>=s||(t=i.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<s&&i.src.charCodeAt(n)!==32?-1:n;}function Wr(i,e){var t,n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e];if(n+1>=s||(t=i.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=s)return-1;if(t=i.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return n<s&&i.src.charCodeAt(n)!==32?-1:n;}function pc(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 fc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_,S,M,K,ie,re,Re,Lt=!0,Ot,ze,Lr,Ri;if((p=Wr(i,e))>=0)S=!0;else if((p=Kr(i,e))>=0)S=!1;else return!1;if(i.level>=i.options.maxNesting)return!1;if(_=i.src.charCodeAt(p-1),n)return!0;for(K=i.tokens.length,S?(d=i.bMarks[e]+i.tShift[e],y=Number(i.src.substr(d,p-d-1)),i.tokens.push({type:"ordered_list_open",order:y,lines:re=[e,0],level:i.level++})):i.tokens.push({type:"bullet_list_open",lines:re=[e,0],level:i.level++}),s=e,ie=!1,Ot=i.parser.ruler.getRules("list");s<t&&(M=i.skipSpaces(p),u=i.eMarks[s],M>=u?g=1:g=M-p,g>4&&(g=1),g<1&&(g=1),r=p-i.bMarks[s]+g,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]=M-i.bMarks[e],i.blkIndent=r,i.tight=!0,i.parentType="list",i.parser.tokenize(i,e,t,!0),(!i.tight||ie)&&(Lt=!1),ie=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,M=i.bMarks[e],!(s>=t||i.isEmpty(s)||i.tShift[s]<i.blkIndent));){for(Ri=!1,ze=0,Lr=Ot.length;ze<Lr;ze++)if(Ot[ze](i,s,t,!0)){Ri=!0;break;}if(Ri)break;if(S){if(p=Wr(i,s),p<0)break;}else if(p=Kr(i,s),p<0)break;if(_!==i.src.charCodeAt(p-1))break;}return i.tokens.push({type:S?"ordered_list_close":"bullet_list_close",level:--i.level}),re[1]=s,i.line=s,Lt&&pc(i,K),!0;}function mc(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 gc(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 bc(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 Xo={};["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){Xo[i]=!0;});var yc=/^<([a-zA-Z]{1,15})[\s\/>]/,_c=/^<\/([a-zA-Z]{1,15})[\s>]/;function Ec(i){var e=i|32;return e>=97&&e<=122;}function vc(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||Ec(s)){if(s===47){if(r=i.src.slice(a,c).match(_c),!r)return!1;}else if(r=i.src.slice(a,c).match(yc),!r)return!1;if(Xo[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 Li(i,e){var t=i.bMarks[e]+i.blkIndent,n=i.eMarks[e];return i.src.substr(t,n-t);}function Sc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y;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=Li(i,e+1),!/^[-:| ]+$/.test(r))||(l=r.split("|"),l<=2))return!1;for(p=[],a=0;a<l.length;a++){if(u=l[a].trim(),!u){if(a===0||a===l.length-1)continue;return!1;}if(!/^:?-+:?$/.test(u))return!1;u.charCodeAt(u.length-1)===58?p.push(u.charCodeAt(0)===58?"center":"right"):u.charCodeAt(0)===58?p.push("left"):p.push("");}if(r=Li(i,e).trim(),r.indexOf("|")===-1||(l=r.replace(/^\||\|$/g,"").split("|"),p.length!==l.length))return!1;if(n)return!0;for(i.tokens.push({type:"table_open",lines:g=[e,0],level:i.level++}),i.tokens.push({type:"thead_open",lines:[e,e+1],level:i.level++}),i.tokens.push({type:"tr_open",lines:[e,e+1],level:i.level++}),a=0;a<l.length;a++)i.tokens.push({type:"th_open",align:p[a],lines:[e,e+1],level:i.level++}),i.tokens.push({type:"inline",content:l[a].trim(),lines:[e,e+1],level:i.level,children:[]}),i.tokens.push({type:"th_close",level:--i.level});for(i.tokens.push({type:"tr_close",level:--i.level}),i.tokens.push({type:"thead_close",level:--i.level}),i.tokens.push({type:"tbody_open",lines:y=[e+2,0],level:i.level++}),c=e+2;c<t&&!(i.tShift[c]<i.blkIndent||(r=Li(i,c).trim(),r.indexOf("|")===-1));c++){for(l=r.replace(/^\||\|$/g,"").split("|"),i.tokens.push({type:"tr_open",level:i.level++}),a=0;a<l.length;a++)i.tokens.push({type:"td_open",align:p[a],level:i.level++}),d=l[a].substring(l[a].charCodeAt(0)===124?1:0,l[a].charCodeAt(l[a].length-1)===124?l[a].length-1:l[a].length).trim(),i.tokens.push({type:"inline",content:d,level:i.level,children:[]}),i.tokens.push({type:"td_close",level:--i.level});i.tokens.push({type:"tr_close",level:--i.level});}return i.tokens.push({type:"tbody_close",level:--i.level}),i.tokens.push({type:"table_close",level:--i.level}),g[1]=y[1]=c,i.line=c,!0;}function Fs(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 xc(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 Ac(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_,S,M;if(n)return i.ddIndent<0?!1:Fs(i,e)>=0;if(d=e+1,i.isEmpty(d)&&++d>t||i.tShift[d]<i.blkIndent||(s=Fs(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(M=!0,S=!1,i.tokens.push({type:"dt_open",lines:[o,o],level:i.level++}),i.tokens.push({type:"inline",content:i.getLines(o,o+1,i.blkIndent,!1).trim(),level:i.level+1,lines:[o,o],children:[]}),i.tokens.push({type:"dt_close",level:--i.level});;){if(i.tokens.push({type:"dd_open",lines:a=[d,0],level:i.level++}),_=i.tight,u=i.ddIndent,p=i.blkIndent,y=i.tShift[r],g=i.parentType,i.blkIndent=i.ddIndent=i.tShift[r]+2,i.tShift[r]=s-i.bMarks[r],i.tight=!0,i.parentType="deflist",i.parser.tokenize(i,r,t,!0),(!i.tight||S)&&(M=!1),S=i.line-r>1&&i.isEmpty(i.line-1),i.tShift[r]=y,i.tight=_,i.parentType=g,i.blkIndent=p,i.ddIndent=u,i.tokens.push({type:"dd_close",level:--i.level}),a[1]=d=i.line,d>=t||i.tShift[d]<i.blkIndent)break e;if(s=Fs(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=Fs(i,r),s<0))break;}return i.tokens.push({type:"dl_close",level:--i.level}),c[1]=d,i.line=d,M&&xc(i,l),!0;}function wc(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 Us=[["code",lc],["fences",dc,["paragraph","blockquote","list"]],["blockquote",hc,["paragraph","blockquote","list"]],["hr",uc,["paragraph","blockquote","list"]],["list",fc,["paragraph","blockquote"]],["footnote",mc,["paragraph"]],["heading",gc,["paragraph","blockquote"]],["lheading",bc],["htmlblock",vc,["paragraph","blockquote"]],["table",Sc,["paragraph"]],["deflist",Ac,["paragraph"]],["paragraph",wc]];function hr(){this.ruler=new Ye();for(var i=0;i<Us.length;i++)this.ruler.push(Us[i][0],Us[i][1],{alt:(Us[i][2]||[]).slice()});}hr.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 Cc=/[\n\t]/g,Tc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,Rc=/\u00a0/g;hr.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(Rc," "),i=i.replace(Tc,"\n"),i.indexOf(" ")>=0&&(i=i.replace(Cc,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 mn(i,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function Ic(i){switch(i){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1;}}function Mc(i,e){for(var t=i.pos;t<i.posMax&&!Ic(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function kc(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 ur=[];for(var Xr=0;Xr<256;Xr++)ur.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){ur[i.charCodeAt(0)]=1;});function Pc(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&&ur[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 Lc(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 Oc(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 Nc(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 Bc(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 Yr(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 Dc(i,e){var t,n,s,r,o,a,c,l=i.posMax,d=i.pos,p=i.src.charCodeAt(d);if(p!==95&&p!==42||e)return!1;if(c=Yr(i,d),t=c.delims,!c.can_open)return i.pos+=t,e||(i.pending+=i.src.slice(d,i.pos)),!0;if(i.level>=i.options.maxNesting)return!1;for(i.pos=d+t,a=[t];i.pos<l;){if(i.src.charCodeAt(i.pos)===p){if(c=Yr(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 Fc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Uc(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(Fc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var Hc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function jc(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(Hc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function $c(i,e){var t,n,s,r,o,a,c,l,d=!1,p=i.pos,u=i.posMax,g=i.pos,y=i.src.charCodeAt(g);if(y===33&&(d=!0,y=i.src.charCodeAt(++g)),y!==91||i.level>=i.options.maxNesting||(t=g+1,n=As(i,g),n<0))return!1;if(a=n+1,a<u&&i.src.charCodeAt(a)===40){for(a++;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a>=u)return!1;for(g=a,zo(i,a)?(r=i.linkContent,a=i.pos):r="",g=a;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<u&&g!==a&&Vo(i,a))for(o=i.linkContent,a=i.pos;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);else o="";if(a>=u||i.src.charCodeAt(a)!==41)return i.pos=p,!1;a++;}else{if(i.linkLevel>0)return!1;for(;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<u&&i.src.charCodeAt(a)===91&&(g=a+1,a=As(i,a),a>=0?s=i.src.slice(g,a++):a=g-1),s||(_typeof(s)>"u"&&(a=n+1),s=i.src.slice(t,n)),c=i.env.references[Ko(s)],!c)return i.pos=p,!1;r=c.href,o=c.title;}return e||(i.pos=t,i.posMax=n,d?i.push({type:"image",src:r,title:o,alt:i.src.substr(t,n-t),level:i.level}):(i.push({type:"link_open",href:r,title:o,level:i.level++}),i.linkLevel++,i.parser.tokenize(i),i.linkLevel--,i.push({type:"link_close",level:--i.level}))),i.pos=a,i.posMax=u,!0;}function qc(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=As(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 Gc(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 zc=["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"],Vc=/^<([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])?)*)>/,Kc=/^<([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(Kc),n?zc.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=Hi(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(Vc),s?(r=s[0].slice(1,-1),o=Hi("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 _i(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 Xc=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Zc=/[^"'=<>`\x00-\x20]+/,Yc=/'[^']*'/,Jc=/"[^"]*"/,Qc=_i(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Zc)("single_quoted",Yc)("double_quoted",Jc)(),el=_i(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Xc)("attr_value",Qc)(),tl=_i(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",el)(),nl=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,sl=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,il=/<[?].*?[?]>/,rl=/<![A-Z]+\s+[^>]*>/,ol=/<!\[CDATA\[[\s\S]*?\]\]>/,al=_i(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",tl)("close_tag",nl)("comment",sl)("processing",il)("declaration",rl)("cdata",ol)();function cl(i){var e=i|32;return e>=97&&e<=122;}function ll(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&&!cl(t))||(n=i.src.slice(r).match(al),!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 dl=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,hl=/^&([a-z][a-z0-9]{1,31});/i;function ul(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(dl),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=qo(n)?Ui(n):Ui(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match(hl),s){var a=jo(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 Oi=[["text",Mc],["newline",kc],["escape",Pc],["backticks",Lc],["del",Oc],["ins",Nc],["mark",Bc],["emphasis",Dc],["sub",Uc],["sup",jc],["links",$c],["footnote_inline",qc],["footnote_ref",Gc],["autolink",Wc],["htmltag",ll],["entity",ul]];function Ei(){this.ruler=new Ye();for(var i=0;i<Oi.length;i++)this.ruler.push(Oi[i][0],Oi[i][1]);this.validateLink=pl;}Ei.prototype.skipToken=function(i){var e=this.ruler.getRules(""),t=e.length,n=i.pos,s,r;if((r=i.cacheGet(n))>0){i.pos=r;return;}for(s=0;s<t;s++)if(e[s](i,!0)){i.cacheSet(n,i.pos);return;}i.pos++,i.cacheSet(n,i.pos);};Ei.prototype.tokenize=function(i){for(var e=this.ruler.getRules(""),t=e.length,n=i.posMax,s,r;i.pos<n;){for(r=0;r<t&&(s=e[r](i,!1),!s);r++);if(s){if(i.pos>=n)break;continue;}i.pending+=i.src[i.pos++];}i.pending&&i.pushPending();};Ei.prototype.parse=function(i,e,t,n){var s=new fn(i,this,e,t,n);this.tokenize(s);};function pl(i){var e=["vbscript","javascript","file","data"],t=i.trim().toLowerCase();return t=dn(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var fl={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;}));}}]);}();qt.TEXT_INPUT_ID="text-input";var qs=qt;var yn=/*#__PURE__*/function(){function yn(){_classCallCheck(this,yn);}return _createClass(yn,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),(Ge.IS_MOBILE||Ge.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(qs.TEXT_INPUT_ID));t&&yn.focusEndOfInput(t);}}]);}();var go="Authentication",he="Authorization",ca="authorization",fi="Unauthorized",sr="Authorization header",en="Invalid",ws="Incorrect",Te="authentication_error",ct="invalid_request_error",q="Content-Type",la="content-type",ee="application/json",U="object",ir="completed",Ce="Bearer ",de="GET",ye="POST",rr="Upload an audio file",Bs="function_call",pn="input_audio",ze="image_url",jn="system",li=/*#__PURE__*/function(){function li(){_classCallCheck(this,li);}return _createClass(li,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]:li.CODE_SNIPPET_GENERATION_JUMP;var n=e.scrollHeight,s=e.clientHeight,r=e.scrollTop,o=n-s;return r>=o-t;}},{key:"cloneElement",value:function cloneElement(e){var t=e.cloneNode(!0);return e.parentNode.replaceChild(t,e),t;}},{key:"scrollToBottom",value:function scrollToBottom(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2?arguments[2]:undefined;e.scrollButton&&e.scrollButton.hiddenElements.size>0&&e.scrollButton.clearHidden(),n?e.elementRef.scrollTo({left:0,top:n.offsetTop}):t?e.elementRef.scrollTo({left:0,top:e.elementRef.scrollHeight,behavior:"smooth"}):e.elementRef.scrollTop=e.elementRef.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}},{key:"isVisibleInParent",value:function isVisibleInParent(e,t){var n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return n.bottom>s.top&&n.top<s.bottom;}},{key:"waitForScrollEnd",value:function waitForScrollEnd(e,t){var n=-1,s=0;var _r2=function r(){var o=e.scrollTop;if(o===n){if(s++,s>2){t();return;}}else s=0,n=o;requestAnimationFrame(_r2);};requestAnimationFrame(_r2);}},{key:"assignButtonEvents",value:function assignButtonEvents(e,t){e.onclick=t,e.onkeydown=function(n){n.key===Ee.ENTER&&setTimeout(t);};}}]);}();li.CODE_SNIPPET_GENERATION_JUMP=1;var z=li;var hi=/*#__PURE__*/function(){function hi(){_classCallCheck(this,hi);}return _createClass(hi,null,[{key:"speak",value:function speak(e,t){if(!t.audio&&window.SpeechSynthesisUtterance){var n=new SpeechSynthesisUtterance(e);Object.assign(n,t),speechSynthesis.speak(n);}}},{key:"processConfig",value:function processConfig(e,t){var n={};setTimeout(function(){if(_typeof(e)=="object"&&(e.audio&&(n.audio=e.audio),e.lang&&(n.lang=e.lang),e.pitch&&(n.pitch=e.pitch),e.rate&&(n.rate=e.rate),e.volume&&(n.volume=e.volume),e.voiceName)){var s=window.speechSynthesis.getVoices().find(function(r){var o;return r.name.toLocaleLowerCase()===((o=e.voiceName)==null?void 0:o.toLocaleLowerCase());});s&&(n.voice=s);}t(n);},hi.LOAD_VOICES_MS);}}]);}();hi.LOAD_VOICES_MS=200;var Dn=hi;var kn=/*#__PURE__*/function(){function kn(){_classCallCheck(this,kn);}return _createClass(kn,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(r){return parseInt(r).toString(16).padStart(2,"0");}).join(""));}},{key:"setDots",value:function setDots(e,t){var n,s;if((s=(n=t==null?void 0:t[R])==null?void 0:n.bubble)!=null&&s.color){var r=kn.colorToHex(t[R].bubble.color);e[E].setProperty("--loading-message-color",r),e[E].setProperty("--loading-message-color-fade","".concat(r,"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,r=_ref8.height,o=_ref8.margin,a=_ref8.border;if(n){var c=kn.colorToHex(n);e[E].setProperty("--loading-history-color",c);}else e[E].setProperty("--loading-history-color","#dbdbdb");e[E].setProperty("--loading-history-height",r||"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");}}]);}();kn.BUBBLE_CLASS="deep-chat-loading-message-bubble",kn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var vt=kn;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(tt,"1.3.14.")),console[p]("".concat(tn,"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(tt,"1.3.0.")),console[p]("".concat(tn,"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(tt,"2.0.0.")),console[p]("".concat(tn,"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(tt,"1.3.17.")),console[p]("".concat(tn,"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(tt,"1.3.24.")),console[p]("".concat(tn,"validateInput: ").concat(X,"interceptors#validateInput")),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console[p]("The submitUserMessage(text: string) argument string type".concat(tt,"1.4.4.")),console[p]("".concat(tn,"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(tt,"1.4.4.")),console[p]("".concat(tn,"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(tt,"2.0.0.")),console[p]("".concat(Is,"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(Or,"the connect object in version 2.0.0.")),console[p]("".concat(Is,"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(tt,"2.0.0.")),console[p]("".concat(Is,"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(tt,"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(In,"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(tt,"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(Is,"official documentation: ").concat(X,"directConnection/Cohere");return t.chat&&(console[p]("Cohere chat property".concat(tt,"2.2.3.")),console[p](n),delete t.chat),t.textGeneration?(console[p]("Cohere textGeneration".concat(Br,"2.2.3.")),console[p](n),delete t.textGeneration,!1):t.summarization?(console[p]("Cohere summarization".concat(Br,"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(Or,"Deep Chat's base").concat(In,"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(In,"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(In,"2.3.1.");return e==="inside-left"?(console[p](t),Hn):e==="inside-right"?(console[p](t),_t):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 In=" since version ",tt=" is deprecated ".concat(In),tn="Please change to using ",Is="Please see the ",Br=" is not supported ".concat(In),Or=" has been moved to ";var Nt=/*#__PURE__*/function(){function Nt(){_classCallCheck(this,Nt);}return _createClass(Nt,null,[{key:"mouseUp",value:function mouseUp(e,t){le.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[Y]);}},{key:"mouseLeave",value:function mouseLeave(e,t){le.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(As,Nt.mouseEnter.bind(this,e,t)),e.addEventListener(bn,Nt.mouseLeave.bind(this,e,t)),e.addEventListener(ra,Nt.mouseDown.bind(this,e,t)),e.addEventListener(oa,Nt.mouseUp.bind(this,e,t));}}]);}();var ha="deep-chat-temporary-message",da="deep-chat-suggestion-button",Li={"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"}),Y,{backgroundColor:"#f1f1f1"})}},Dr=Object.keys(Li);var xt=/*#__PURE__*/function(){function xt(){_classCallCheck(this,xt);}return _createClass(xt,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener(Y,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(ha):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return Dr.find(function(t){return e[f].contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var n=Li[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;},[]),r=Li[n][R];if(r){var a=w(r);a[A]&&le.overwriteDefaultWithAlreadyApplied(a,t),s.unshift(a);}var o=le.mergeStatefulStyles(s);return le.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,n){Dr.forEach(function(r){var o=n.getElementsByClassName(r);Array.from(o||[]).forEach(function(a){var c=xt.getProcessedStyles(t,a,r);re.applyStylesToElement(a,c),xt.applyEvents(a,r);});});var s=n.getElementsByClassName(da);Array.from(s).forEach(function(r){return xt.applySuggestionEvent(e,r);});}}]);}();var re=/*#__PURE__*/function(){function re(){_classCallCheck(this,re);}return _createClass(re,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var n=le.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&&!xt.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(r){e[n]&&re.applyClassUtilitiesToElement(r,e[n]);});});}},{key:"apply",value:function apply(e,t){xt.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(r){re.traverseNodes(r,s);}),s;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=x();return t.innerHTML=e,xt.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 r=(n==null?void 0:n[s])||(n==null?void 0:n[A]);if(r)return e.innerHTML=r,{contentEl:re.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(Ko)[0]||e;}}]);}();var Gt=/*#__PURE__*/function(){function Gt(){_classCallCheck(this,Gt);}return _createClass(Gt,null,[{key:"createElements",value:function createElements(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;var o=e.createMessageElementsOnOrientation("",n,s,r);o.bubbleElement[f].add(Gt.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 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 ua=/*#__PURE__*/function(){function ua(){_classCallCheck(this,ua);}return _createClass(ua,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 pe=v-se;if(pe!==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<pe)&&(v=u.skipSpaces(v),!(v<C)))){_=!0;break;}pe=u.tShift[g],u.line=ie+(_?1:0);var Re=u.getLines(g+1,ie,pe,!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 pe=u[T].charAt(v);if(pe==="{"&&(v===0||u[T].charAt(v-1)!=="\\"))se+=1;else if(pe==="}"&&(v===0||u[T].charAt(v-1)!=="\\")){if(se-=1,se<0)return!1;}else if(pe===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 bo(i){return Ms=Ms||document.createElement("textarea"),Ms.innerHTML="&"+i+";",Ms.value;}var pa=Object.prototype.hasOwnProperty;function fa(i,e){return i?pa.call(i,e):!1;}function yo(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 ma=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ps(i){return i.indexOf("\\")<0?i:i.replace(ma,"$1");}function Eo(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 Pi(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 ga=/&([a-z#][a-z0-9]{1,31});/gi,ba=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function ya(i,e){var t=0,n=bo(e);return e!==n?n:e.charCodeAt(0)===35&&ba.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),Eo(t))?Pi(t):i;}function En(i){return i.indexOf("&")<0?i:i.replace(ga,ya);}var Ea=/[&<>"]/,_a=/[&<>"]/g,va={"&":"&","<":"<",">":">",'"':"""};function Sa(i){return va[i];}function Ve(i){return Ea.test(i)?i.replace(_a,Sa):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>"+Ve(i[e].content)+"</code></pre>"+Sn(i,e):"<code>"+Ve(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(" "),fa(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=Ve(En(ps(d))),o=' class="'+a+c+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[r.content].concat(l))||Ve(r.content):u=Ve(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="'+Ve(En(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Ve(i[e].href)+'"'+n+s+">";};I.link_close=function(){return"</a>";};I.image=function(i,e,t){var n=' src="'+Ve(i[e].src)+'"',s=i[e].title?' title="'+Ve(En(i[e].title))+'"':"",r=' alt="'+(i[e].alt?Ve(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>"+Ve(i[e].content)+"</sub>";};I.sup=function(i,e){return"<sup>"+Ve(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 Ve(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="'+Ve(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 _o(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?_o(i,e+2):e;}var Sn=I.getBreak=function(e,t){return t=_o(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function or(){this.rules=yo({},I),this.getBreak=I.getBreak;}or.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;};or.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 et(){this.__rules__=[],this.__cache__=null;}et.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};et.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));});});};et.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;};et.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;};et.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;};et.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};et.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;};et.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;};et.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function xa(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 Aa(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 wa(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=Aa(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 Ni(i){var e=En(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function vo(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=Ni(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 So(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 xo(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function Ca(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(!vo(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&&So(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=xo(i.slice(1,r)),_typeof(n.references[g])>"u"&&(n.references[g]={title:u,href:d}),o);}function Ta(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=Ca(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 Ra(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 Ia(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 Fr=" \n()[]'\".,!?-";function Ai(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function Ma(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="(^|["+Fr.split("").map(Ai).join("")+"])("+Object.keys(i.env.abbreviations).map(function(_){return _.substr(1);}).sort(function(_,v){return v.length-_.length;}).map(Ai).join("|")+")($|["+Fr.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 ka=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,La=/\((c|tm|r|p)\)/ig,Pa={c:"©",r:"®",p:"§",tm:"™"};function Na(i){return i.indexOf("(")<0?i:i.replace(La,function(e,t){return Pa[t.toLowerCase()];});}function Ba(i){var e,t,n,s,r;if(i.options.typographer){for(r=i.tokens.length-1;r>=0;r--)if(i.tokens[r].type==="inline")for(s=i.tokens[r].children,e=s.length-1;e>=0;e--)t=s[e],t.type==="text"&&(n=t.content,n=Na(n),ka.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 Oa=/['"]/,Ur=/['"]/g,Da=/[-\s()\[\]]/,Hr="’";function jr(i,e){return e<0||e>=i.length?!1:!Da.test(i[e]);}function Tn(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function Fa(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"||Oa.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&&(Ur.lastIndex=r,s=Ur.exec(n),!!s);){if(c=!jr(n,s.index-1),r=s.index+1,_=s[0]==="'",l=!jr(n,r),!l&&!c){_&&(t.content=Tn(t.content,s.index,Hr));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,Hr));}}}}}var wi=[["block",xa],["abbr",wa],["references",Ta],["inline",Ra],["footnote_tail",Ia],["abbr2",Ma],["replacements",Ba],["smartquotes",Fa]];function Ao(){this.options={},this.ruler=new et();for(var i=0;i<wi.length;i++)this.ruler.push(wi[i][0],wi[i][1]);}Ao.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 Ua(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 Ha(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 ja(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 $a(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 $r(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 qr(i,e){var t,n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e];if(n+1>=s||(t=i.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=s)return-1;if(t=i.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return n<s&&i.src.charCodeAt(n)!==32?-1:n;}function qa(i,e){var t,n,s=i.level+2;for(t=e+2,n=i.tokens.length-2;t<n;t++)i.tokens[t].level===s&&i.tokens[t].type==="paragraph_open"&&(i.tokens[t+2].tight=!0,i.tokens[t].tight=!0,t+=2);}function Ga(i,e,t,n){var s,r,o,a,c,l,d,u,g,b,_,v,C,B,se,pe,ie,Re,Ht=!0,jt,Ke,Rr,vi;if((u=qr(i,e))>=0)C=!0;else if((u=$r(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,pe=!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||pe)&&(Ht=!1),pe=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,Rr=jt.length;Ke<Rr;Ke++)if(jt[Ke](i,s,t,!0)){vi=!0;break;}if(vi)break;if(C){if(u=qr(i,s),u<0)break;}else if(u=$r(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&&qa(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 Va(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 Ka(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 wo={};["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){wo[i]=!0;});var Wa=/^<([a-zA-Z]{1,15})[\s\/>]/,Xa=/^<\/([a-zA-Z]{1,15})[\s>]/;function Za(i){var e=i|32;return e>=97&&e<=122;}function Ya(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||Za(s)){if(s===47){if(r=i.src.slice(a,c).match(Xa),!r)return!1;}else if(r=i.src.slice(a,c).match(Wa),!r)return!1;if(wo[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 Ja(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 Qa(i,e){var t,n,s=i.level+2;for(t=e+2,n=i.tokens.length-2;t<n;t++)i.tokens[t].level===s&&i.tokens[t].type==="paragraph_open"&&(i.tokens[t+2].tight=!0,i.tokens[t].tight=!0,t+=2);}function ec(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&&Qa(i,l),!0;}function tc(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",Ua],["fences",Ha,["paragraph","blockquote","list"]],["blockquote",ja,["paragraph","blockquote","list"]],["hr",$a,["paragraph","blockquote","list"]],["list",Ga,["paragraph","blockquote"]],["footnote",za,["paragraph"]],["heading",Va,["paragraph","blockquote"]],["lheading",Ka],["htmlblock",Ya,["paragraph","blockquote"]],["table",Ja,["paragraph"]],["deflist",ec,["paragraph"]],["paragraph",tc]];function ar(){this.ruler=new et();for(var i=0;i<Ls.length;i++)this.ruler.push(Ls[i][0],Ls[i][1],{alt:(Ls[i][2]||[]).slice()});}ar.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 nc=/[\n\t]/g,sc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,ic=/\u00a0/g;ar.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(ic," "),i=i.replace(sc,"\n"),i.indexOf(" ")>=0&&(i=i.replace(nc,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 rc(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 oc(i,e){for(var t=i.pos;t<i.posMax&&!rc(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function ac(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 cr=[];for(var Gr=0;Gr<256;Gr++)cr.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){cr[i.charCodeAt(0)]=1;});function cc(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&&cr[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 lc(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 hc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==126||e||o+4>=r||i.src.charCodeAt(o+1)!==126||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===126)||c===126||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===126;)n++;if(n>o+3)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===126&&i.src.charCodeAt(i.pos+1)===126&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==126&&a!==126&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"del_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"del_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function dc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==43||e||o+4>=r||i.src.charCodeAt(o+1)!==43||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===43)||c===43||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===43;)n++;if(n!==o+2)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===43&&i.src.charCodeAt(i.pos+1)===43&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==43&&a!==43&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"ins_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"ins_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function uc(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 Vr(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 pc(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=Vr(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=Vr(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 fc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function mc(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(fc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var gc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function bc(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(gc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function yc(i,e){var t,n,s,r,o,a,c,l,d=!1,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,vo(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&&So(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[xo(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 Ec(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 _c(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 vc=["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"],Sc=/^<([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])?)*)>/,xc=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Ac(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(xc),n?vc.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=Ni(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(Sc),s?(r=s[0].slice(1,-1),o=Ni("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 wc=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Cc=/[^"'=<>`\x00-\x20]+/,Tc=/'[^']*'/,Rc=/"[^"]*"/,Ic=mi(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Cc)("single_quoted",Tc)("double_quoted",Rc)(),Mc=mi(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",wc)("attr_value",Ic)(),kc=mi(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",Mc)(),Lc=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Pc=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Nc=/<[?].*?[?]>/,Bc=/<![A-Z]+\s+[^>]*>/,Oc=/<!\[CDATA\[[\s\S]*?\]\]>/,Dc=mi(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",kc)("close_tag",Lc)("comment",Pc)("processing",Nc)("declaration",Bc)("cdata",Oc)();function Fc(i){var e=i|32;return e>=97&&e<=122;}function Uc(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&&!Fc(t))||(n=i.src.slice(r).match(Dc),!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 Hc=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,jc=/^&([a-z][a-z0-9]{1,31});/i;function $c(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(Hc),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=Eo(n)?Pi(n):Pi(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match(jc),s){var a=bo(s[1]);if(s[1]!==a)return e||(i.pending+=a),i.pos+=s[0].length,!0;}}return e||(i.pending+="&"),i.pos++,!0;}var Ti=[["text",oc],["newline",ac],["escape",cc],["backticks",lc],["del",hc],["ins",dc],["mark",uc],["emphasis",pc],["sub",mc],["sup",bc],["links",yc],["footnote_inline",Ec],["footnote_ref",_c],["autolink",Ac],["htmltag",Uc],["entity",$c]];function gi(){this.ruler=new et();for(var i=0;i<Ti.length;i++)this.ruler.push(Ti[i][0],Ti[i][1]);this.validateLink=qc;}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 qc(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 Gc={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"]}}},zc={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:{}}},Vc={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,138 +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"]}}},Kc={"default":Gc,full:zc,commonmark:Vc};function Co(i,e,t){this.src=e,this.env=t,this.options=i.options,this.tokens=[],this.inlineMode=!1,this.inline=i.inline,this.block=i.block,this.renderer=i.renderer,this.typographer=i.typographer;}function wt(i,e){typeof i!="string"&&(e=i,i="default"),e&&e.linkify!=null&&console.warn("linkify option is removed. Use linkify plugin instead:\n\nimport Remarkable from 'remarkable';\nimport linkify from 'remarkable/linkify';\nnew Remarkable().use(linkify)\n"),this.inline=new gi(),this.block=new ar(),this.core=new Ao(),this.renderer=new or(),this.ruler=new et(),this.options={},this.configure(Kc[i]),this.set(e||{});}wt.prototype.set=function(i){yo(this.options,i);};wt.prototype.configure=function(i){var e=this;if(!i)throw new Error("Wrong `remarkable` preset, check name/content");i.options&&e.set(i.options),i.components&&Object.keys(i.components).forEach(function(t){i.components[t].rules&&e[t].ruler.enable(i.components[t].rules,!0);});};wt.prototype.use=function(i,e){return i(this,e),this;};wt.prototype.parse=function(i,e){var t=new Co(this,i,e);return this.core.process(t),t.tokens;};wt.prototype.render=function(i,e){return e=e||{},this.renderer.render(this.parse(i,e),this.options,e);};wt.prototype.parseInline=function(i,e){var t=new Co(this,i,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};wt.prototype.renderInline=function(i,e){return e=e||{},this.renderer.render(this.parseInline(i,e),this.options,e);};var an=/*#__PURE__*/function(){function an(){_classCallCheck(this,an);}return _createClass(an,null,[{key:"addPlugins",value:function addPlugins(e,t){var n=window.remarkable_plugins;if(n&&n.forEach(function(s){e.use(s.plugin,s.options);}),t!=null&&t.math){window.katex||(console.warn("window.katex not found, use chatElementRef.refreshMessages to re-render messages"),console.warn("See https://deepchat.dev/examples/externalModules"));var s=_typeof(t.math)=="object"?t.math.delimiter:"",r=_typeof(t.math)=="object"&&t.math.options?t.math.options:{};e.use(ua.katex.bind(this,r),{delimiter:s});}}},{key:"instantiate",value:function instantiate(e){if(e)return new wt(_objectSpread(_objectSpread({},an.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new wt({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,r){var o;r&&e[
|
|
63
|
+
});}else return new wt(an.DEFAULT_PROPERTIES);}},{key:"createNew",value:function createNew(e){var t=an.instantiate(e);return an.addPlugins(t,e),t.inline.validateLink=function(){return!0;},t;}}]);}();an.DEFAULT_PROPERTIES={breaks:!0,linkTarget:"_blank"// set target to open in a new tab
|
|
64
|
+
};var ms=an;var Wc=/*#__PURE__*/function(){function Wc(e){_classCallCheck(this,Wc);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(Wc,[{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,r=s?JSON.parse(s):void 0;this.set(n,this.trackInputText?r==null?void 0:r.inputText:void 0,this.trackScrollHeight?r==null?void 0:r.scrollHeight:void 0);}},{key:"addInputText",value:function addInputText(e){if(!this.trackInputText)return;var t=localStorage.getItem(this.storageKey),n=t?JSON.parse(t):void 0;this.set((n==null?void 0:n.messages)||[],e,this.trackScrollHeight?n==null?void 0:n.scrollHeight:void 0);}},{key:"addScrollHeight",value:function addScrollHeight(e){if(!this.trackScrollHeight)return;var t=localStorage.getItem(this.storageKey),n=t?JSON.parse(t):void 0;this.set((n==null?void 0:n.messages)||[],this.trackInputText?n==null?void 0:n.inputText:void 0,e);}},{key:"clear",value:function clear(){localStorage.removeItem(this.storageKey);}}]);}();var Oe=/*#__PURE__*/function(){function Oe(){_classCallCheck(this,Oe);}return _createClass(Oe,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],r=s.tagName.toLocaleLowerCase()!=="a"?s:s.children[0];Object.assign(r[E],n.media);}}},{key:"applySideStyles",value:function applySideStyles(e,t,n,s){s&&(Oe.applyCustomStylesToElements(e,n,s.shared),t===F?Oe.applyCustomStylesToElements(e,n,s.user):(Oe.applyCustomStylesToElements(e,n,s.ai),Oe.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,r){var o;r&&e[A]!==r?Oe.isElementsStyles(r)?(Oe.applyCustomStylesToElements(t,s,(o=e[A])==null?void 0:o.shared),Oe.applyCustomStylesToElements(t,s,r)):(Oe.applySideStyles(t,n,s,e[A]),Oe.applySideStyles(t,n,s,r)):Oe.applySideStyles(t,n,s,e[A]);}// prettier-ignore
|
|
66
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(r){var o,a,c,l;s.outerContainer[r]=((o=n.outerContainer)==null?void 0:o[r])||"",s.innerContainer[r]=((a=n.innerContainer)==null?void 0:a[r])||"",s.bubble[r]=((c=n.bubble)==null?void 0:c[r])||"",s.media[r]=((l=n.media)==null?void 0:l[r])||"";}),s;}}]);}();var 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 r;n!==
|
|
68
|
-
},{key:"addMessage",value:function addMessage(e,t,n,s,r){Se.setElementProps(e,t,n,s),r?e.elementRef.insertBefore(t.outerContainer,e.elementRef.firstChild):e.appendOuterContainerElemet(t.outerContainer);}},{key:"wrapInLink",value:function wrapInLink(e,t,n){var s=
|
|
67
|
+
function setElementProps(e,t,n,s){var r;n!==Ot&&(e.applyCustomStyles(t,s,!0,(r=e.messageStyles)==null?void 0:r[n]),t.bubbleElement[f].add(lo));}// prettier-ignore
|
|
68
|
+
},{key:"addMessage",value:function addMessage(e,t,n,s,r){Se.setElementProps(e,t,n,s),r?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===K?!1:e===mn&&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[
|
|
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===$||(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 hn=/*#__PURE__*/function(){function hn(){_classCallCheck(this,hn);}return _createClass(hn,null,[{key:"onMessage",value:function onMessage(e,t,n){var r;var s=C({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})),le.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=C({content:t,isUser:n});t[b]&&Se.reAddFileRefToObject(_defineProperty({},b,(r=t[b])==null?void 0:r.map(function(a){return{ref:a};})),s.content),(o=e.onInput)==null||o.call(e,s),e.dispatchEvent(new CustomEvent("input",{detail:s}));}},{key:"onError",value:function onError(e,t){var n;(n=e.onError)==null||n.call(e,t),e.dispatchEvent(new CustomEvent(f,{detail:t}));}}]);}();var we=/*#__PURE__*/function(){function we(){_classCallCheck(this,we);}return _createClass(we,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=A();return e[m].add("loading-history"),e.appendChild(A()),e.appendChild(A()),e.appendChild(A()),e.appendChild(A()),e;}},{key:"apply",value:function apply(e,t,n){mt.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=C(n),delete n.bubble),e.applyCustomStyles(t,"history",!1,n);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var a,c,l,d,p,u,g,y;e.bubbleElement[m].add(we.CLASS);var s=n?we.FULL_VIEW_CLASS:we.SMALL_CLASS;e.outerContainer[m].add(s);var r=n?(d=(l=(c=(a=t.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.full)==null?void 0:d[R]:(y=(g=(u=(p=t.messageStyles)==null?void 0:p.loading)==null?void 0:u.history)==null?void 0:g.small)==null?void 0:y[R];we.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==Bo&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",ne),n=t.bubbleElement,s=we.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?yt.createElements(e,n,ne,!0,!0):we.createDefaultElements(e);return we.addLoadHistoryMessage(s,e,t),B.softRemRoleElements(s.innerContainer,e.avatar,e.name),s;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var n,s,r,o,a,c,l,d;if(t!=null&&t.outerContainer[m].contains(we.FULL_VIEW_CLASS)){t.outerContainer[m].replace(we.FULL_VIEW_CLASS,we.SMALL_CLASS);var p=(o=(r=(s=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:s.history)==null?void 0:r.small)==null?void 0:o[R];p&&we.apply(e,t,p);var u=(d=(l=(c=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.small)==null?void 0:d[L];return u&&(t.bubbleElement.innerHTML=u),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];we.tryChangeViewToSmall(e,t)||we.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();we.CLASS="loading-history-message",we.FULL_VIEW_CLASS="loading-history-message-full-view",we.SMALL_CLASS="loading-history-message-small";var Mt=we;var bs=/*#__PURE__*/function(){function bs(){_classCallCheck(this,bs);}return _createClass(bs,null,[{key:"setFade",value:function setFade(e,t){e[v].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(bs.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e,t){var n;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:e[v].opacity="0";n=typeof t=="number"?t:bs.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(s){setTimeout(function(){return s();},n);});case 1:e[v].opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();bs.DEFAULT_FADE_MS=500;var Ws=bs;var Kt=/*#__PURE__*/function(){function Kt(e,t,n){_classCallCheck(this,Kt);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=C(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"?C(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(Kt,[{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=A();return e.id="scroll-button",z.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")z.scrollToBottom(_this4._messages,n),n&&_this4.element&&(Kt.hideElement(_this4.element),_this4.isScrollingToBottom=!0,z.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"});}}),oe.apply(this._messages,e),e;}},{key:"assignStyles",value:function assignStyles(e){if(!this.element)return;Object.assign(this.element[v],e[w]);var t=de.processStateful(e);Rt.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){Kt.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,oe.apply(this._messages,this.element);}else this.element.innerHTML=s;(t=this.hiddenMessagesConfig)!=null&&t[R]&&this.assignStyles(this.hiddenMessagesConfig[R]),Kt.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&&!z.isVisibleInParent(n,this._messages.elementRef)&&(this.hiddenElements.add(n),(t=this.io)==null||t.observe(n),this.updateHiddenElement());}else this.updateScroll();}},{key:"clearHidden",value:function clearHidden(){var _this5=this;this.hiddenElements.forEach(function(e){var t;return(t=_this5.io)==null?void 0:t.unobserve(e);}),this.hiddenElements.clear(),this.updateHiddenElement();}},{key:"displayScroll",value:function displayScroll(){var e,t;this.element&&this.element[v].opacity!==Dr&&(Kt.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||(z.isScrollbarAtBottomOfElement(this._messages.elementRef,((e=this.scrollButtonConfig)==null?void 0:e.scrollDelta)||80)?this.element&&this.element[v].opacity!==Br&&Kt.hideElement(this.element):(this.displayScroll(),this.isScrollButton=!0));}}],[{key:"displayElement",value:function displayElement(e){e[v].opacity=Dr,e[v].pointerEvents="auto";}},{key:"hideElement",value:function hideElement(e){e[v].opacity=Br,e[v].pointerEvents="none";}}]);}();var Jr="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='iso-8859-1'?%3e%3csvg%20fill='%23000000'%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%2032%2032'%20xml:space='preserve'%3e%3cpath%20d='M23,30.36H9c-2.404,0-4.36-1.956-4.36-4.36V15c0-2.404,1.956-4.36,4.36-4.36h3.659%20c0.167-1.566,1.415-2.813,2.981-2.981V5.333c-1.131-0.174-2-1.154-2-2.333c0-1.301,1.059-2.36,2.36-2.36%20c1.302,0,2.36,1.059,2.36,2.36c0,1.179-0.869,2.159-2,2.333V7.66c1.566,0.167,2.814,1.415,2.981,2.981H23%20c2.404,0,4.36,1.956,4.36,4.36v11C27.36,28.404,25.404,30.36,23,30.36z%20M9,11.36c-2.007,0-3.64,1.633-3.64,3.64v11%20c0,2.007,1.633,3.64,3.64,3.64h14c2.007,0,3.64-1.633,3.64-3.64V15c0-2.007-1.633-3.64-3.64-3.64H9z%20M13.384,10.64h5.231%20C18.439,9.354,17.334,8.36,16,8.36C14.667,8.36,13.561,9.354,13.384,10.64z%20M16,1.36c-0.904,0-1.64,0.736-1.64,1.64%20S15.096,4.64,16,4.64c0.904,0,1.64-0.736,1.64-1.64S16.904,1.36,16,1.36z%20M20,27.36h-8c-1.301,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36h8c1.302,0,2.36,1.059,2.36,2.36S21.302,27.36,20,27.36z%20M12,23.36c-0.904,0-1.64,0.735-1.64,1.64%20s0.736,1.64,1.64,1.64h8c0.904,0,1.64-0.735,1.64-1.64s-0.735-1.64-1.64-1.64H12z%20M31,23.86h-2c-0.199,0-0.36-0.161-0.36-0.36V15%20c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5C31.36,23.699,31.199,23.86,31,23.86z%20M29.36,23.14h1.279v-7.78%20H29.36V23.14z%20M3,23.86H1c-0.199,0-0.36-0.161-0.36-0.36V15c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5%20C3.36,23.699,3.199,23.86,3,23.86z%20M1.36,23.14h1.28v-7.78H1.36V23.14z%20M20,20.36c-1.302,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36s2.36,1.059,2.36,2.36C22.36,19.302,21.302,20.36,20,20.36z%20M20,16.36c-0.904,0-1.64,0.736-1.64,1.64%20s0.735,1.64,1.64,1.64s1.64-0.735,1.64-1.64S20.904,16.36,20,16.36z%20M12,20.36c-1.301,0-2.36-1.059-2.36-2.36s1.059-2.36,2.36-2.36%20s2.36,1.059,2.36,2.36C14.36,19.302,13.301,20.36,12,20.36z%20M12,16.36c-0.904,0-1.64,0.736-1.64,1.64s0.736,1.64,1.64,1.64%20s1.64-0.735,1.64-1.64S12.904,16.36,12,16.36z'/%3e%3crect%20style='fill:none;'%20width='32'%20height='32'/%3e%3c/svg%3e",ji="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 Yo=/*#__PURE__*/function(){function Yo(e){_classCallCheck(this,Yo);this.className=e;}return _createClass(Yo,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e)[v]).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e)[v].visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e)[m].add("role-hidden");}}]);}();var vt=/*#__PURE__*/function(_Yo){function vt(e){var _this6;_classCallCheck(this,vt);_this6=_callSuper(this,vt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(vt,_Yo);return _createClass(vt,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._avatars=="boolean"?void 0:this._avatars,s=this.createAvatar(t,n),r=this.getPosition(t,n);s[m].add(r===qt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===qt?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var r,o,a,c,l;var n=A("img");e===F?(n[T]=((r=t==null?void 0:t[F])==null?void 0:r[T])||((o=t==null?void 0:t[w])==null?void 0:o[T])||ji,n.onerror=vt.errorFallback.bind(this,ji)):(n[T]=((a=t==null?void 0:t[e])==null?void 0:a[T])||((c=t==null?void 0:t[ne])==null?void 0:c[T])||((l=t==null?void 0:t[w])==null?void 0:l[T])||Jr,n.onerror=vt.errorFallback.bind(this,Jr)),n[m].add("avatar"),n.alt="".concat(e," avatar");var s=A();return s[m].add(this.className),s.appendChild(n),t&&vt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,r,o,a,c,l;var n=le.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[w])==null?void 0:c[R])==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===F?No: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[v],n.container),Object.assign(t[v],n.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){var r,o,a,c;if((r=n[w])!=null&&r[R]&&vt.applyCustomStylesToElements(e,t,n[w][R]),s===F)(o=n.user)!=null&&o[R]&&vt.applyCustomStylesToElements(e,t,n.user[R]);else{(a=n.ai)!=null&&a[R]&&vt.applyCustomStylesToElements(e,t,n.ai[R]);var l=(c=n[s])==null?void 0:c[R];l&&vt.applyCustomStylesToElements(e,t,l);}}}]);}(Yo);var hs=/*#__PURE__*/function(_Yo2){function hs(e){var _this7;_classCallCheck(this,hs);_this7=_callSuper(this,hs,["name"]),_this7._names=e;return _this7;}_inherits(hs,_Yo2);return _createClass(hs,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),r=hs.getPosition(t,n);s[m].add(r===qt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===qt?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=A();return n[m].add(this.className),n.textContent=hs.getNameText(e,t),hs.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,r,o;var n=le.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[ne])==null?void 0:r.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[w])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===F?No:qt,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,r,o,a;Object.assign(e[v],(s=n[w])==null?void 0:s[v]),t===F?Object.assign(e[v],(r=n[F])==null?void 0:r[v]):(Object.assign(e[v],(o=n[ne])==null?void 0:o[v]),Object.assign(e[v],(a=n[t])==null?void 0:a[v]));}},{key:"getNameText",value:function getNameText(e,t){var n,s,r,o,a,c;return e===F?((n=t[F])==null?void 0:n[h])||((s=t[w])==null?void 0:s[h])||"User":e===ne?((r=t[ne])==null?void 0:r[h])||((o=t[w])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[w])==null?void 0:c[h])||e;}}]);}(Yo);var je=/*#__PURE__*/function(){function je(e){var _this8=this;_classCallCheck(this,je);var t,n,s,r;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=je.createContainerElement(),this.messageStyles=le.processMessageStyles(e.messageStyles),this._remarkable=ws.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new vt(e.avatars)),e.names&&(this.name=new hs(e.names)),e.browserStorage&&(this.browserStorage=new yl(e.browserStorage)),this._onMessage=hn.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),(e.hiddenMessages||e.scrollButton)&&(this.scrollButton=new Kt(this,e.hiddenMessages,e.scrollButton)),this.focusMode=le.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=A(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Ws.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||le.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(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 r=s?this.createAndPrependNewMessageElement(e,t,s):this.createAndAppendNewMessageElement(e,t);return r.bubbleElement[m].add(je.TEXT_BUBBLE_CLASS),this.applyCustomStyles(r,t,!1),B.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,r){var o;s.ref&&(o=t[m])!=null&&o[r]&&(t[m][r].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===$||(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 we=/*#__PURE__*/function(){function we(){_classCallCheck(this,we);}return _createClass(we,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(we.CLASS);var s=n?we.FULL_VIEW_CLASS:we.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];we.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==uo&&(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=we.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):we.createDefaultElements(e);return we.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(we.FULL_VIEW_CLASS)){t.outerContainer[f].replace(we.FULL_VIEW_CLASS,we.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&&we.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];we.tryChangeViewToSmall(e,t)||we.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();we.CLASS="loading-history-message",we.FULL_VIEW_CLASS="loading-history-message-full-view",we.SMALL_CLASS="loading-history-message-small";var Dt=we;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",z.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")z.scrollToBottom(_this4._messages,n),n&&_this4.element&&(nn.hideElement(_this4.element),_this4.isScrollingToBottom=!0,z.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=le.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&&!z.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!==Lr&&(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||(z.isScrollbarAtBottomOfElement(this._messages.elementRef,((e=this.scrollButtonConfig)==null?void 0:e.scrollDelta)||80)?this.element&&this.element[E].opacity!==kr&&nn.hideElement(this.element):(this.displayScroll(),this.isScrollButton=!0));}}],[{key:"displayElement",value:function displayElement(e){e[E].opacity=Lr,e[E].pointerEvents="auto";}},{key:"hideElement",value:function hideElement(e){e[E].opacity=kr,e[E].pointerEvents="none";}}]);}();var Kr="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",Bi="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 To=/*#__PURE__*/function(){function To(e){_classCallCheck(this,To);this.className=e;}return _createClass(To,[{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(_To){function Tt(e){var _this6;_classCallCheck(this,Tt);_this6=_callSuper(this,Tt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(Tt,_To);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])||Bi,n.onerror=Tt.errorFallback.bind(this,Bi)):(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])||Kr,n.onerror=Tt.errorFallback.bind(this,Kr)),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?ho: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);}}}]);}(To);var ts=/*#__PURE__*/function(_To2){function ts(e){var _this7;_classCallCheck(this,ts);_this7=_callSuper(this,ts,["name"]),_this7._names=e;return _this7;}_inherits(ts,_To2);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?ho: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;}}]);}(To);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 Wc(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=O.overwriteMessage(this.messageToElements,n,t,e,"text",$e.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($e.LAST_GROUP_MESSAGES_ACTIVE);var e=x();(this.messageToElements.length>1||this.messageToElements.length===1&&this.messageToElements[0][0][S]!==F)&&e[f].add($e.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 r=this.createNewMessageElement(e,t,n,s);if(n&&(o=this.elementRef.firstChild)!=null&&o[f].contains($e.INTRO_CLASS)){this.elementRef.firstChild.insertAdjacentElement("afterend",r.outerContainer);var a=this.messageElementRefs[0];this.messageElementRefs[0]=this.messageElementRefs[1],this.messageElementRefs[1]=a;}else this.elementRef.insertBefore(r.outerContainer,this.elementRef.firstChild);return r;}},{key:"createMessageElementsOnOrientation",value:function createMessageElementsOnOrientation(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;return n?this.createAndPrependNewMessageElement(e,t,n,s):this.createNewMessageElement(e,t,n,s);}},{key:"getNumberOfContentMessages",value:function getNumberOfContentMessages(){var t,n;var e=this.messageElementRefs.length;return(n=(t=this.messageElementRefs[e-1])==null?void 0:t.bubbleElement)!=null&&n[f].contains(vt.BUBBLE_CLASS)?e-1:e;}},{key:"createNewMessageElement",value:function createNewMessageElement(e,t){var _this9=this;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;!s&&this.getNumberOfContentMessages()>=this.maxVisibleMessages&&setTimeout(function(){return _this9.removeFirstMessage();}),s||(o=this._introPanel)==null||o.hide();var r=this.messageElementRefs[this.messageElementRefs.length-1];return Dt.changeFullViewToSmall(this),!n&&$e.isTemporaryElement(r)&&(this.revealRoleElementsIfTempRemoved(r,t),this.removeLastMessage()),this.createMessageElements(e,t,n);}// this can be tested by having an ai message, then a temp ai message with html that submits new user message:
|
|
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
|
|
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)&&xt.isElementTemporary(e)){var n=this.messageElementRefs[this.messageElementRefs.length-2];n&&this.messageToElements.length>0&&!e.bubbleElement[f].contains(O.getRoleClass(t))&&O.revealRoleElements(n.innerContainer,this.avatar,this.name);}}},{key:"createElements",value:function createElements(e,t){var n=$e.createBaseElements(t),s=n.outerContainer,r=n.innerContainer,o=n.bubbleElement;return s.appendChild(r),this.addInnerContainerElements(o,e,t),n;}},{key:"createMessageElements",value:function createMessageElements(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=this.createElements(e,t);return O.updateRefArr(this.messageElementRefs,s,n),O.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 O.areOuterContainerClassRolesSame(n,s)&&!this.isLastMessageError()&&O.hideRoleElements(s.innerContainer,this.avatar,this.name),e[f].add("message-bubble",O.getRoleClass(n),n===F?"user-message-text":"ai-message-text"),this.renderText(e,t,n),O.addRoleElements(e,n,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
|
|
78
|
+
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){e&&this.messageStyles&&Oe.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=O.getLastMessageBubbleElement(this.elementRef))==null?void 0:e[f].contains($s);}},{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,r=_re$tryAddWrapper2.wrapper;r&&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=ms.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);z.scrollToBottom(this,s);}else if(t&&this.autoScrollAllowed){var _s3=this.getFirstMessageContentEl();z.scrollToBottom(this,!1,_s3==null?void 0:_s3.outerContainer);}}}],[{key:"createContainerElement",value:function createContainerElement(){var e=x();return e.id=uo,e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return $e.isLoadingMessage(e)||xt.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(O.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,r=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]=""),r&&(c.custom=r),o&&(c._sessionId=o),c;}},{key:"isLoadingMessage",value:function isLoadingMessage(e){return e==null?void 0:e.bubbleElement[f].contains(vt.BUBBLE_CLASS);}}]);}();$e.TEXT_BUBBLE_CLASS="text-message",$e.INTRO_CLASS="deep-chat-intro",$e.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var ot=$e;var O=/*#__PURE__*/function(){function O(){_classCallCheck(this,O);}return _createClass(O,null,[{key:"getLastElementsByClass",value:function getLastElementsByClass(e,t,n){var _loop=function _loop(){var r=e[s];if(r.bubbleElement[f].contains(t[0])&&!t.slice(1).find(function(a){return!r.bubbleElement[f].contains(a);}))if(n){if(!n.find(function(c){return r.bubbleElement[f].contains(c);}))return{v:r};}else return{v:r};},_ret;for(var s=e.length-1;s>=0;s-=1){_ret=_loop();if(_ret)return _ret.v;}}},{key:"getLastMessage",value:function getLastMessage(e,t,n){for(var s=e.length-1;s>=0;s-=1)if(e[s][0][S]===t)if(n){if(e[s][0][n])return e[s][0];}else return e[s][0];}},{key:"getLastTextToElement",value:function getLastTextToElement(e,t){for(var n=e.length-1;n>=0;n-=1)if(e[n][0]===t)return e[n];}// IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message
|
|
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,r,o){var a=
|
|
84
|
-
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e[
|
|
85
|
-
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var n=t?
|
|
83
|
+
},{key:"overwriteMessage",value:function overwriteMessage(e,t,n,s,r,o){var a=O.getLastElementsByClass(t,[O.getRoleClass(s),o],[vt.BUBBLE_CLASS]),c=O.getLastMessage(e,s,r);return c&&(c[r]=n),a;}},{key:"getRoleClass",value:function getRoleClass(e){return"".concat(e,"-message");}// makes sure the bubble has dimensions when there is no text
|
|
84
|
+
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e[f].add(Ir),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e[f].contains(Ir)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,n,s;return Array.from(((s=(n=(t=O.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:n[0])==null?void 0:s.children)||[]).find(function(r){return r[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(Rs).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$f;e.outerContainer[f].remove(Si,Mr,xi),(_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]=O.findMessageElements(t,ot.TEXT_BUBBLE_CLASS)),e[L]&&(n[L]=O.findMessageElements(t,At.HTML_BUBBLE_CLASS)),e[m]&&(n[m]=O.filterdMessageElements(t,lo)),n;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=O.getNumberOfElements(e),r=n?t.slice(0,s):t.slice(t.length-s);return O.generateMessageBodyElements(e,r);}// if role not present - traverse all, if present - traverse last messages
|
|
85
|
+
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var n=t?O.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(Rs);})),!n)continue;var r=e[s],o=r.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?O.addNewPositionClasses(r,[Si]):l&&d?O.addNewPositionClasses(r,[Mr]):l&&!d?O.addNewPositionClasses(r,[xi]):!l&&!d&&O.addNewPositionClasses(r,[Si,xi]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer[f]).find(function(s){return s.startsWith(Rs);})===O.buildRoleOuterContainerClass(e):!1;}},{key:"resetAllRoleElements",value:function resetAllRoleElements(e,t,n){if(!t&&!n)return;var s="";e.forEach(function(r,o){r.bubbleElement[f].contains($s)||O.revealRoleElements(r.innerContainer,t,n);var a=Array.from(r.outerContainer[f]).find(function(c){return c.startsWith(Rs);});s===a&&O.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=
|
|
88
|
+
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return O.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 O.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]=O.processMessageContent(s):t[n]=s;}),t;}}]);}();var It=/*#__PURE__*/function(){function It(e,t){_classCallCheck(this,It);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialContent="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(It,[{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](fo);var t=(e==null?void 0:e[h])||(e==null?void 0:e[L])||"",n=z.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](na);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&&z.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]),r=s?"":t;this._elements=e===h?this._messages.addNewTextMessage(r,n):At.add(this._messages,r,n),this._elements&&(this._elements.bubbleElement[f].add(It.MESSAGE_CLASS),this._activeMessageRole=n,this._message=_defineProperty(_defineProperty({},S,this._activeMessageRole),e,r),this._messages.messageToElements.push([this._message,_defineProperty({},e,this._elements)]),s&&this.setTargetWrapperIfNeeded(this._elements,t,this._streamType,s),(c=this._messages.scrollButton)==null||c.updateHidden());}// not using existing htmlUtils htmlWrappers logic to be able to stream html
|
|
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||O.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(It.PARTIAL_RENDER_MARK);return t===-1?!1:!e.substring(t+It.PARTIAL_RENDER_MARK.length).startsWith("---");}// checking state BEFORE the current chunk was appended ensures the chunk that closes a code block
|
|
90
|
+
// (transitioning fence count from odd to even) stays in the current bubble alongside its opening fence
|
|
91
|
+
// https://github.com/OvidijusParsiunas/deep-chat/issues/500#issuecomment-4281293147
|
|
92
|
+
},{key:"isInsideOpenCodeBlock",value:function isInsideOpenCodeBlock(e){var r;if(this._streamType!==h)return!1;var t=(r=this._message)==null?void 0:r[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 r;if(t)return e.innerHTML="",!0;if(this.isInsideOpenCodeBlock(n))return!1;var s=this._streamType;if(!this._partialBubble){var o=(r=this._message)==null?void 0:r[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
|
|
90
93
|
// hence don't throw NO_VALID_STREAM_EVENTS_SENT when no response elements yet
|
|
91
|
-
},{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,r;if(!this._endStreamAfterOperation&&!(this._fileAdded&&!this._elements)){if(!this._elements&&!t)throw Error(
|
|
92
|
-
},{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({},
|
|
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,r;if(!this._endStreamAfterOperation&&!(this._fileAdded&&!this._elements)){if(!this._elements&&!t)throw Error(sa);this._message&&(s=(n=this._elements)==null?void 0:n.bubbleElement)!=null&&s[f].contains(It.MESSAGE_CLASS)&&(this._streamType===h?this._messages.textToSpeech&&Dn.speak(this._message[h]||"",this._messages.textToSpeech):this._streamType===L&&this._elements&&re.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement[f].remove(It.MESSAGE_CLASS),this._message&&(this._sessionId&&(this._message._sessionId=this._sessionId),this._messages.sendClientUpdate(ot.createMessageContent(this._message),!1),(r=this._messages.browserStorage)==null||r.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;}()}]);}();It.MESSAGE_CLASS="streamed-message",It.PARTIAL_RENDER_MARK="\n\n";var gt=It;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
|
|
93
96
|
// prettier-ignore
|
|
94
|
-
function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,n){var s,r,_t3;return _regenerator().w(function(_context3){while(1)switch(_context3.p=_context3.n){case 0:if(e!=null&&e.headers){_context3.n=1;break;}throw new Error(
|
|
95
|
-
},{key:"fetch",value:function(_fetch){function fetch(_x5,_x6,_x7,_x8){return _fetch.apply(this,arguments);}fetch.toString=function(){return _fetch.toString();};return fetch;}(function(e,t,n,s){var o,a;var r={method:((o=e.connectSettings)==null?void 0:o.method)||ye,headers:t};return r.method!==
|
|
96
|
-
},{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e,t){var n,s,_n$displayError,r,_n$useRI,o,a,c,l,d,_args5=arguments,_t5;return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:n=_args5.length>2&&_args5[2]!==undefined?_args5[2]:{};s=n.io,_n$displayError=n.displayError,r=_n$displayError===void 0?!0:_n$displayError,_n$useRI=n.useRI,o=_n$useRI===void 0?!0:_n$useRI;if(s!=null&&s.extractResultData){_context5.n=1;break;}return _context5.a(2,t);case 1:a=o?s.deepChat.responseInterceptor:void 0;_context5.n=2;return a==null?void 0:a(t);case 2:_t5=_context5.v;if(_t5){_context5.n=3;break;}_t5=t;case 3:c=_t5;_context5.n=4;return s.extractResultData(c);case 4:l=_context5.v;if(!(!l||_typeof(l)!="object"&&!Array.isArray(l))){_context5.n=5;break;}if(r){d=
|
|
97
|
-
function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,n){var s,r,
|
|
98
|
-
},{key:"handleReadableStream",value:function handleReadableStream(e,t,n,s,r,o){var d;var _e$streamHandlers=e.streamHandlers,a=_e$streamHandlers.onOpen,c=_e$streamHandlers.onClose;var l=!1;fetch(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",s).then(/*#__PURE__*/function(){var _ref13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(
|
|
99
|
-
},{key:"handleEventStream",value:function handleEventStream(e,t,n,s,r,o){var d;var _e$streamHandlers2=e.streamHandlers,a=_e$streamHandlers2.onOpen,c=_e$streamHandlers2.onClose,l=new AbortController();e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l.abort();},
|
|
100
|
-
onopen:function onopen(
|
|
97
|
+
function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,n){var s,r,_t3;return _regenerator().w(function(_context3){while(1)switch(_context3.p=_context3.n){case 0:if(e!=null&&e.headers){_context3.n=1;break;}throw new Error(je);case 1:s=e.headers[q];delete e.headers[q];_context3.p=2;_context3.n=3;return t(n);case 3:r=_context3.v;_context3.n=5;break;case 4:_context3.p=4;_t3=_context3.v;throw e.headers[q]=s,_t3;case 5:return _context3.a(2,(e.headers[q]=s,r));}},_callee3,null,[[2,4]]);}));function tempRemoveContentHeader(_x9,_x0,_x1){return _tempRemoveContentHeader.apply(this,arguments);}return tempRemoveContentHeader;}()},{key:"displayError",value:function displayError(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"Service error, please try again.";if(console[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 r={method:((o=e.connectSettings)==null?void 0:o.method)||ye,headers:t};return r.method!==de&&(r.body=n?ae(s):s),e.connectSettings.credentials&&(r.credentials=e.connectSettings.credentials),fetch(((a=e.connectSettings)==null?void 0:a.url)||e.url||"",r);})},{key:"processResponseByType",value:function processResponseByType(e){var t=e.headers.get("content-type");return t!=null&&t.includes(ee)?e.json():t!=null&&t.includes("text/plain")||!t?e:e.blob();}},{key:"processRequestInterceptor",value:function(){var _processRequestInterceptor=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(e,t){var o,n,s,r,_t4;return _regenerator().w(function(_context4){while(1)switch(_context4.n){case 0:_context4.n=1;return(o=e.requestInterceptor)==null?void 0:o.call(e,t);case 1:_t4=_context4.v;if(_t4){_context4.n=2;break;}_t4=t;case 2:n=_t4;s=n;r=n;return _context4.a(2,{body:s.body,headers:s.headers,error:r[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](po),!1):!n.find(function(r){return _typeof(r)!="object"||!(_typeof(r[p])===_e||_typeof(r[h])===_e||_typeof(r[L])===_e||Array.isArray(r[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,r,_n$useRI,o,a,c,l,d,_args5=arguments,_t5;return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:n=_args5.length>2&&_args5[2]!==undefined?_args5[2]:{};s=n.io,_n$displayError=n.displayError,r=_n$displayError===void 0?!0:_n$displayError,_n$useRI=n.useRI,o=_n$useRI===void 0?!0:_n$useRI;if(s!=null&&s.extractResultData){_context5.n=1;break;}return _context5.a(2,t);case 1:a=o?s.deepChat.responseInterceptor:void 0;_context5.n=2;return a==null?void 0:a(t);case 2:_t5=_context5.v;if(_t5){_context5.n=3;break;}_t5=t;case 3:c=_t5;_context5.n=4;return s.extractResultData(c);case 4:l=_context5.v;if(!(!l||_typeof(l)!="object"&&!Array.isArray(l))){_context5.n=5;break;}if(r){d=On(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 Xc(_x14,_x15){return _Xc.apply(this,arguments);}function _Xc(){_Xc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee195(i,e){var t,n;return _regenerator().w(function(_context195){while(1)switch(_context195.n){case 0:t=i.getReader();case 1:_context195.n=2;return t.read();case 2:if((n=_context195.v).done){_context195.n=4;break;}e(n.value);case 3:_context195.n=1;break;case 4:return _context195.a(2);}},_callee195);}));return _Xc.apply(this,arguments);}function Zc(i){var e,t,n,s=!1;return function(o){e===void 0?(e=o,t=0,n=-1):e=Jc(e,o);var a=e.length;var c=0;for(;t<a;){s&&(e[t]===10&&(c=++t),s=!1);var l=-1;for(;t<a&&l===-1;++t)switch(e[t]){case 58:n===-1&&(n=t-c);break;case 13:s=!0;case 10:l=t;break;}if(l===-1)break;i(e.subarray(c,l),n),c=t,n=-1;}c===a?e=void 0:c!==0&&(e=e.subarray(c),t-=c);};}function Yc(i,e,t){var n=Wr();var s=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(n),n=Wr();else if(a>0){var c=s.decode(o.subarray(0,a)),l=a+(o[a+1]===32?2:1),d=s.decode(o.subarray(l));switch(c){case"data":n.data=n.data?n.data+"\n"+d:d;break;case"event":n.event=d;break;case"id":i(n.id=d);break;case"retry":var u=parseInt(d,10);isNaN(u)||e(n.retry=u);break;}}};}function Jc(i,e){var t=new Uint8Array(i.length+e.length);return t.set(i),t.set(e,i.length),t;}function Wr(){return{data:"",event:"",id:"",retry:void 0};}var Qc=function Qc(i,e){var t={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&e.indexOf(n)<0&&(t[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(i);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(i,n[s])&&(t[n[s]]=i[n[s]]);return t;};var Oi="text/event-stream",el=1e3,Xr="last-event-id";function tl(i,e){var t=e.signal,n=e.headers,s=e.onopen,r=e.onmessage,o=e.onclose,a=e.onerror,c=e.openWhenHidden,l=e.fetch,d=Qc(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(u,g){var b=Object.assign({},n);b.accept||(b.accept=Oi);var _;function v(){_.abort(),document.hidden||Re();}c||document.addEventListener("visibilitychange",v);var C=el,B=0;function se(){document.removeEventListener("visibilitychange",v),window.clearTimeout(B),_.abort();}t==null||t.addEventListener("abort",function(){se(),u();});var pe=l!==null&&l!==void 0?l:window.fetch,ie=s!==null&&s!==void 0?s:nl;function Re(){return _Re.apply(this,arguments);}function _Re(){_Re=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var Ht,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 pe(i,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 Xc(jt.body,Zc(Yc(function(Ke){Ke?b[Xr]=Ke:delete b[Xr];},function(Ke){C=Ke;},r)));case 4:o==null||o();se();u();_context6.n=6;break;case 5:_context6.p=5;_t6=_context6.v;if(!_.signal.aborted)try{Ke=(Ht=a==null?void 0:a(_t6))!==null&&Ht!==void 0?Ht:C;window.clearTimeout(B),B=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 nl(i){var e=i.headers.get("content-type");if(!(e!=null&&e.startsWith(Oi)))throw new Error("Expected content-type to be ".concat(Oi,", 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,r,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;r=_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,mt.stream(e,a,n));case 3:if(!(((_=e.connectSettings)==null?void 0:_.url)===yt.URL)){_context7.n=4;break;}return _context7.a(2,yt.requestStream(n,e));case 4:d=new gt(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,r,a):V.handleEventStream(e,n,d,u,r,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,r,o){var d;var _e$streamHandlers=e.streamHandlers,a=_e$streamHandlers.onOpen,c=_e$streamHandlers.onClose;var l=!1;fetch(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",s).then(/*#__PURE__*/function(){var _ref13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(u){var v,C,g,b,_,_yield$g$read,B,se,pe,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(ia);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;B=_yield$g$read.value;se=_yield$g$read.done;if(!(_=se,_)){_context8.n=4;break;}V.handleClose(e,n,c,r);_context8.n=7;break;case 4:pe=b.decode(B,{stream:!0});_context8.n=5;return(C=(v=e.deepChat).responseInterceptor)==null?void 0:C.call(v,pe);case 5:_t7=_context8.v;if(_t7){_context8.n=6;break;}_t7=pe;case 6:ie=_t7;Re=_typeof(ie)=="object"?ie:_defineProperty({},h,pe);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,r,o){var d;var _e$streamHandlers2=e.streamHandlers,a=_e$streamHandlers2.onOpen,c=_e$streamHandlers2.onClose,l=new AbortController();e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l.abort();},tl(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",_objectSpread(_objectSpread({},s),{},{openWhenHidden:!0,// keep stream open when browser tab not open
|
|
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,r);},signal:l.signal}))["catch"](function(u){V.handleError(e,t,u);});}//prettier-ignore
|
|
101
104
|
},{key:"handleMessage",value:function handleMessage(e,t,n,s,r){var o;(o=e.extractResultData)==null||o.call(e,s,r).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
|
|
102
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(r){D.displayError(t,r);});}},{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(r){if(!s)throw r;}}// io is only passed for demo to simulate a real stream
|
|
103
|
-
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,n,s){var r,o,_r3,_r4,_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();r=
|
|
106
|
+
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,n,s){var r,o,_r3,_r4,_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();r=re.splitHTML(n[L]);r.length===0&&(r=n[L].split(""));o=new gt(e,s==null?void 0:s.stream);V.populateMessages(e,r,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:_r3=_context1.v;e.addNewMessage(_objectSpread({sendUpdate:!1},_r3)),!n[L]&&!n[h]&&(new gt(e,s==null?void 0:s.stream).finaliseStreamedMessage(),t.onClose());case 4:if(n[h]){t.onOpen();_r4=n[h].split(""),_o2=new gt(e,s==null?void 0:s.stream);V.populateMessages(e,_r4,_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
|
|
104
107
|
// io is only passed for demo to simulate a real stream
|
|
105
|
-
},{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,n,s,r,o,a){var c,d,l,_t9;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:c=t[o];if(!c){_context10.n=5;break;}_context10.p=1;_context10.n=2;return D.basicResponseProcessing(e,_defineProperty({},r,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,r,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 r=t(s);n!==null&&n!==void 0?n:n=r||void 0;}if(s!=null&&s[
|
|
106
|
-
},{key:"request",value:function request(e,t){var n=
|
|
107
|
-
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var n=
|
|
108
|
-
},{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,n,s){if(!s)return;var r=e.stream.simulation;if(_typeof(r)===
|
|
109
|
-
},{key:"stream",value:function stream(e,t,n){var
|
|
110
|
-
},{key:"websocket",value:function websocket(e,t){var _this10=this;var c,l;var n={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=n;var s=function s(){t.removeError(),n.isOpen=!0;},r=function r(){n.isOpen=!1;},o=/*#__PURE__*/function(){var _ref21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(d){var
|
|
111
|
-
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,n){var s,
|
|
112
|
-
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,n){var s,
|
|
113
|
-
},{key:"verifyKey",value:function verifyKey(e,t,n,s,r,o,a,c,l){if(e==="")return o(
|
|
108
|
+
},{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,n,s,r,o,a){var c,d,l,_t9;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:c=t[o];if(!c){_context10.n=5;break;}_context10.p=1;_context10.n=2;return D.basicResponseProcessing(e,_defineProperty({},r,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,r,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 r=t(s);n!==null&&n!==void 0?n:n=r||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 cn=/*#__PURE__*/function(){function cn(){_classCallCheck(this,cn);}return _createClass(cn,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]===K?"That is a nice image!":n[y]===$?"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?cn.getCustomResponse(e,t[t.length-1][0]):_defineProperty({},h,cn.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=cn.getResponse(t);setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(){var s,r,o;return _regenerator().w(function(_context11){while(1)switch(_context11.n){case 0:_context11.n=1;return 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:r=Array.isArray(s)?s:[s],o=r.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):(r.forEach(function(a){return t.addNewMessage(a);}),e.completionsHandlers.onFinish());case 3:return _context11.a(2);}},_callee11);})),400);}// timeout is used to simulate a timeout for a response to come back
|
|
110
|
+
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var n=cn.getResponse(e);V.simulate(e,t.streamHandlers,n,t);},400);}}]);}();cn.URL="deep-chat-demo";var yt=cn;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 mt.websocket(e,t);try{var s=typeof n!="boolean"?n:void 0,r=new WebSocket(e.connectSettings.url||"",s);e.websocket=r,e.websocket.onopen=function(){var o,a;t.removeError(),e.websocket&&_typeof(e.websocket)===U&&ke.assignListeners(e,r,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(r){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(r.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(On(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 r,o;console[p]("Connection closed"),n.isLastMessageError()||n.addNewErrorMessage(oe,"Connection error"),e.stream&&((o=(r=e.streamHandlers).onAbort)==null||o.call(r)),ke.createConnection(e,n);};}},{key:"sendWebsocket",value:function(){var _sendWebsocket=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e,t,n){var s,d,u,r,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)===yt.URL)){_context13.n=1;break;}return _context13.a(2,yt.request(e,n));case 1:r=e.websocket;if(!(!r||r==="pending")){_context13.n=2;break;}return _context13.a(2);case 2:o={body:t,headers:(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(r)){_context13.n=5;break;}return _context13.a(2,r.newUserMessage.listener(a));case 5:l=s?ae(a):a;r.readyState===void 0||r.readyState!==r.OPEN?(console[p]("Connection is not open"),n.isLastMessageError()||n.addNewErrorMessage(oe,"Connection error")):(r.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 r=e.stream.simulation;if(_typeof(r)===_e){var _n$o;var o=s[S]||te,a=n[o];s[h]===r||s[L]===r?(a==null||a.finaliseStreamedMessage(),delete n[o]):((_n$o=n[o])!==null&&_n$o!==void 0?_n$o:n[o]=new gt(t,e.stream),n[o].upsertStreamedMessage(s));}else V.simulate(t,e.streamHandlers,s);}}]);}();var mt=/*#__PURE__*/function(){function mt(){_classCallCheck(this,mt);}return _createClass(mt,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(e,t,n){var a,c,s,r,o;return _regenerator().w(function(_context15){while(1)switch(_context15.n){case 0:s=!0;r=/*#__PURE__*/function(){var _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](On(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 r(_x38){return _ref19.apply(this,arguments);};}(),o=mt.generateOptionalSignals();(c=(a=e.connectSettings).handler)==null||c.call(a,t,_objectSpread(_objectSpread({},o),{},{onResponse:r}));case 1:return _context15.a(2);}},_callee15);}));function request(_x35,_x36,_x37){return _request2.apply(this,arguments);}return request;}()},{key:"attemptToFinaliseStream",value:function attemptToFinaliseStream(e,t){try{var n=t.messageElementRefs[t.messageElementRefs.length-1];ot.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,r=!1;var o=new gt(n,e.stream),a=function a(){r||!s||(e.streamHandlers.onOpen(),r=!0);},c=function c(){s&&(mt.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]?(mt.streamError(_[p],o,e,n),s=!1):V.upsertContent(n,o.upsertStreamedMessage.bind(o),o,_);else{v=On(b,"server",!!e.deepChat.responseInterceptor,_);mt.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(){mt.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1;};var d=mt.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;},r=function r(){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](On(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=mt.generateOptionalSignals();(l=(c=e.connectSettings).handler)==null||l.call(c,void 0,_objectSpread(_objectSpread({},a),{},{onOpen:s,onResponse:o,onClose:r,newUserMessage:n.newUserMessage}));}},{key:"generateOptionalSignals",value:function generateOptionalSignals(){return{onClose:function onClose(){},onOpen:function onOpen(){},stopClicked:{listener:function listener(){}},newUserMessage:{listener:function listener(){}}};}}]);}();var ge=/*#__PURE__*/function(){function ge(){_classCallCheck(this,ge);}return _createClass(ge,null,[{key:"request",value:// prettier-ignore
|
|
114
|
+
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,n){var s,u,g,b,r,_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;r={body:t,headers:(u=e.connectSettings)==null?void 0:u.headers};_context19.n=1;return D.processRequestInterceptor(e.deepChat,r);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,mt.request(e,o,n));case 3:if(!(((b=e.connectSettings)==null?void 0:b.url)===yt.URL)){_context19.n=4;break;}return _context19.a(2,yt.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 B,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=(B=e.deepChat).responseInterceptor)==null?void 0:se.call(B,_);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(On(_,"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 r=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(){ge.executePollRequest(e,t,n,s);},a.timeoutMS):V.isSimulatable(e.stream,a)?V.simulate(s,e.streamHandlers,a):(s.addNewMessage(a),r());case 5:return _context20.a(2);}},_callee20);}));return function(_x45){return _ref23.apply(this,arguments);};}())["catch"](function(o){D.displayError(s,o),r();});}// prettier-ignore
|
|
115
|
+
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,n){var s,b,_,v,r,_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;r={body:t,headers:(b=e.connectSettings)==null?void 0:b.headers};_context21.n=1;return D.processRequestInterceptor(e.deepChat,r);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),ge.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,r,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,r,o);})["catch"](function(d){o(He),console[p](d);});}}]);}();var $n=/*#__PURE__*/function(){function $n(){_classCallCheck(this,$n);}return _createClass($n,null,[{key:"getCharacterLimitMessages",value:function getCharacterLimitMessages(e,t){var r;if(t===-1)return e;var n=0,s=e[W]-1;for(s;s>=0;s-=1){var o=(r=e[s])==null?void 0:r[h];if(o!==void 0&&(n+=o[W],n>t)){e[s][h]=o.substring(0,o[W]-(n-t));break;}}return e.slice(Math.max(s,0));}},{key:"getMaxMessages",value:function getMaxMessages(e,t){return e.slice(Math.max(e[W]-t,0));}// if maxMessages is not defined we send all messages
|
|
114
117
|
// if maxMessages above 0 we send that number
|
|
115
118
|
// if maxMessages 0 or below we send only what is in the request
|
|
116
|
-
},{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=$n.getMaxMessages(e,t)):e=[e[e[W]-1]],e=w(e),n===void 0?e:$n.getCharacterLimitMessages(e,n);}}]);}();var zt=/*#__PURE__*/function(){function zt(e,t,n){_classCallCheck(this,zt);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,n.fetchHistory&&this.fetchHistory(n.fetchHistory),this.setupInitialHistory(e);}return _createClass(zt,[{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=Dt.addMessage(this._messages);_context22.n=1;return e();case 1:n=_context22.v;this._messages.removeMessage(t),zt.displayIntroMessages(this._messages.messageElementRefs),n.forEach(function(s){return _this11._messages.addAnyMessage(s,!0);}),setTimeout(function(){return z.scrollToBottom(_this11._messages);},0);case 2:return _context22.a(2);}},_callee22,this);}));function fetchHistory(_x49){return _fetchHistory.apply(this,arguments);}return fetchHistory;}()},{key:"scrollToPreloadFirstEl",value:function scrollToPreloadFirstEl(e,t){this._messages.elementRef.scrollTop=t+e.offsetTop-40;}},{key:"processLoadedHistory",value:function processLoadedHistory(e){var _this12=this;var a;var _this$_messages=this._messages,t=_this$_messages.messageElementRefs,n=_this$_messages.messageToElements,s=_this$_messages.elementRef,r=(a=t.find(function(c){return!c.outerContainer[f].contains(ot.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=O.generateMessageBody(l,t,!0);n.unshift([l,d]);}return l;}).filter(function(c){return!!c;}).reverse().forEach(function(c){return _this12._messages.sendClientUpdate(c,!0);}),r&&(this._messages.messageElementRefs.length>=this._messages.maxVisibleMessages?setTimeout(function(){return _this12.scrollToPreloadFirstEl(r,o);}):this.scrollToPreloadFirstEl(r,o));}},{key:"populateMessages",value:function populateMessages(e,t){this._messages.removeMessage(e),this._isPaginationComplete=t.findIndex(function(a){return!a;})<0;var n=t.filter(function(a){return!!a;});this.processLoadedHistory(n);var _this$_messages2=this._messages,s=_this$_messages2.messageElementRefs,r=_this$_messages2.avatar,o=_this$_messages2.name;O.resetAllRoleElements(s,r,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=Dt.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,zt.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=Dt.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,zt.FAILED_ERROR_MESSAGE,!0),console[p](_t13);case 4:zt.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,r;var t=(s=(n=this._messages.browserStorage)==null?void 0:n.get())==null?void 0:s.scrollHeight;t!==void 0&&(r=this._messages.browserStorage)!=null&&r.trackScrollHeight?setTimeout(function(){_this14._messages.elementRef.scrollTop=t;},0):e&&setTimeout(function(){return z.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(zt.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(ot.INTRO_CLASS))n.outerContainer[E].display="";else break;}}}]);}();zt.FAILED_ERROR_MESSAGE="Failed to load history";var gs=zt;var Ae=/*#__PURE__*/function(){function Ae(){_classCallCheck(this,Ae);}return _createClass(Ae,null,[{key:"parseConfig",value:function parseConfig(e,t,n){var r;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,(r=o.infoModal)!=null&&r.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=Ae.parseConfig(s,t,n);}}// needs to be set after audio to overwrite maxNumberOfFiles
|
|
117
120
|
// prettier-ignore
|
|
118
|
-
},{key:"processMicrophone",value:function processMicrophone(e,t,n,s){var _c$
|
|
119
|
-
},{key:"processAudioConfig",value:function processAudioConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"audio/*"},(s==null?void 0:s[
|
|
120
|
-
},{key:"processGifConfig",value:function processGifConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/gif"},(s==null?void 0:s[
|
|
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[$])==null?void 0:a[m])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e.recordAudio=Ae.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[$])!=null&&u[m]&&((_g$maxNumberOfFiles=(g=e.fileTypes[$][m]).maxNumberOfFiles)!==null&&_g$maxNumberOfFiles!==void 0?_g$maxNumberOfFiles:g.maxNumberOfFiles=n[m].maxNumberOfFiles))):s||(e.fileTypes[$]=Ae.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[$]=Ae.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[Bn]=Ae.parseConfig(o,t,n);}// needs to be set after images to overwrite maxNumberOfFiles
|
|
121
124
|
// prettier-ignore
|
|
122
|
-
},{key:"processCamera",value:function processCamera(e,t,n,s){var _c$
|
|
123
|
-
},{key:"processImagesConfig",value:function processImagesConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/*"},(s==null?void 0:s[
|
|
124
|
-
},{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$
|
|
125
|
-
},{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(e,t){var s,n,r;return _regenerator().w(function(_context30){while(1)switch(_context30.n){case 0:if(this.connectSettings){_context30.n=1;break;}throw new Error(
|
|
126
|
-
function
|
|
127
|
-
},{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,n=_this$_keyVerificatio.url,s=_this$_keyVerificatio.method,r=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,c=_this$_keyVerificatio.augmentUrl,l=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(c==null?void 0:c(e))||n;ge.verifyKey(e,d,l,s,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,r,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}},{key:"processMessages",value:function processMessages(e){return
|
|
128
|
-
function
|
|
129
|
-
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:
|
|
130
|
-
function changeVisibility(e,t,n,s){s.target.id===
|
|
131
|
-
},{key:"create",value:function create(e){var t=
|
|
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]=Ae.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]=Ae.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]=Ae.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){Ae.populateDefaultFileIO(n==null?void 0:n[$],".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),Ae.populateDefaultFileIO(n==null?void 0:n[Q],".png,.jpg");var s=ms.createNew(e.remarkable);Ae.processImagesConfig(t,s,e[Q],n==null?void 0:n[Q]),Ae.processCamera(t,s,e[Fe],e[Q]),Ae.processGifConfig(t,s,e[Bn],n==null?void 0:n[Bn]),Ae.processAudioConfig(t,s,e[$],n==null?void 0:n[$]),Ae.processMicrophone(t,s,e[pt],e[$]),Ae.processMixedFiles(t,s,e[co]);}}]);}();var vn=/*#__PURE__*/function(){function vn(e,t,n){var _a$url;_classCallCheck(this,vn);var s,r,o,a,c;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=vn.canSendMessage,this.connectSettings={},this.fileTypes={},this.completionsHandlers={},this.streamHandlers={},this.deepChat=e,this.demo=n,Object.assign(this.rawBody,(s=e.connect)==null?void 0:s.additionalBodyProps),this.totalMessagesMaxCharLength=(r=e==null?void 0:e.requestBodyLimits)==null?void 0:r.totalMessagesMaxCharLength,this.maxMessages=(o=e==null?void 0:e.requestBodyLimits)==null?void 0:o.maxMessages,Ae.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=yt.URL),this.connectSettings.websocket&&ke.setup(this),this.stream=((c=this.deepChat.connect)==null?void 0:c.stream)||ce.checkForStream(this.deepChat),e.loadHistory&&gs.addErrorPrefix(this);}return _createClass(vn,[{key:"verifyKey",value:function verifyKey(e,t){}},{key:"getServiceIOByType",value:function getServiceIOByType(e){if(e[y].startsWith($)&&this.fileTypes[$])return this.fileTypes[$];if(e[y].startsWith(K)){if(this.fileTypes[Bn]&&e[y].endsWith("/gif"))return this.fileTypes[Bn];if(this.fileTypes[Q])return this.fileTypes[Q];if(this[Fe])return this[Fe];}return this.fileTypes[co];}},{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):ge.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$q;var r,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;(r=this.connectSettings.headers)!=null&&r[q]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$q=(a=this.connectSettings.headers)[q])!==null&&_a$q!==void 0?_a$q:a[q]=ee,s=!0);_context27.n=1;return this.request(n,e);case 1:s&&((c=this.connectSettings.headers)==null||delete c[q]);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,r,o;return _regenerator().w(function(_context28){while(1)switch(_context28.n){case 0:s=vn.createCustomFormDataBody(this.rawBody,t,n),r=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=r;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,r;return _regenerator().w(function(_context30){while(1)switch(_context30.n){case 0:if(this.connectSettings){_context30.n=1;break;}throw new Error(je);case 1:n=$n.processMessages(t.messageToElements.map(function(_ref24){var _ref25=_slicedToArray(_ref24,1),r=_ref25[0];return r;}),this.maxMessages,this.totalMessagesMaxCharLength);if(this.connectSettings.websocket&&(!this.connectSettings.handler||this.connectSettings.url!==yt.URL)){r=_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,r,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[W]>0);}},{key:"createCustomFormDataBody",value:function createCustomFormDataBody(e,t,n){var s=new FormData();n.forEach(function(a){return s.append("files",a);}),Object.keys(e).forEach(function(a){return s.append(a,String(e[a]));});var r=0;t.slice(0,t[W]-1).forEach(function(a){s.append("message".concat(r+=1),ae(a));});var o=t[t[W]-1];return o[h]&&(delete o[m],s.append("message".concat(r+=1),ae(o))),s;}}]);}();var M=/*#__PURE__*/function(_vn){// prettier-ignore
|
|
129
|
+
function M(e,t,n,s,r){var _this15;_classCallCheck(this,M);var o;_this15=_callSuper(this,M,[e,r]),_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,_vn);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,r=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,c=_this$_keyVerificatio.augmentUrl,l=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(c==null?void 0:c(e))||n;ge.verifyKey(e,d,l,s,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,r,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}},{key:"processMessages",value:function processMessages(e){return $n.getCharacterLimitMessages(e,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this.systemMessage[W]:-1);}},{key:"addSystemMessage",value:function addSystemMessage(e){this.systemMessage&&e.unshift(_defineProperty(_defineProperty({},S,jn),"content",this.systemMessage));}},{key:"callDirectServiceServiceAPI",value:function(){var _callDirectServiceServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(e,t,n,s,r){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(je);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 ge.request(this,o,e,r);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 r,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=(r=this.deepChat).responseInterceptor)==null?void 0:o.call(r,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(gn);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):ge.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,r){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,r)));case 1:o!=null&&o.tool_calls&&(e._streamToolCalls?o.tool_calls.forEach(function(c,l){e._streamToolCalls&&(e._streamToolCalls[l]["function"].arguments+=c["function"].arguments);}):e._streamToolCalls=o.tool_calls);case 2:return _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,r){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(Qt);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(!(r&&(o.messages=o.messages.slice(o.messages[W]-1),r.message&&o.messages.unshift(_defineProperty(_defineProperty({},S,jn),"content",r.message))),o.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},S,St),"content",null)),!c.find(function(_ref28){var d=_ref28.response;return _typeof(d)!==_e;})&&a[W]===c[W])){_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(gn);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[W]>0&&(this.messages.messageToElements[this.messages.messageToElements[W]-1][0]._sessionId=e);}}],[{key:"getRoleViaUser",value:function getRoleViaUser(e){return e===F?F:St;}},{key:"getRoleViaAI",value:function getRoleViaAI(e){return e===te?St:F;}},{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t[y]===K;}).map(function(t){return _defineProperty(_defineProperty({},y,ze),ze,{url:t[T]||""});}).filter(function(t){return t[ze].url[W]>0;});}},{key:"getTextWImagesContent",value:function getTextWImagesContent(e){if(e[m]&&e[m][W]>0){var t=this.getImageContent(e[m]);return e[h]&&e[h].trim()[W]>0&&t.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),t[W]>0?t:e[h]||"";}return e[h]||"";}},{key:"getTextWFilesContent",value:function getTextWFilesContent(e,t){if(e[m]&&e[m][W]>0){var n=t(e[m]);return e[h]&&e[h].trim()[W]>0&&n.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),n;}return e[h]||"";}}]);}(vn);var zs=/*#__PURE__*/function(){function zs(){_classCallCheck(this,zs);}return _createClass(zs,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?zs.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,zs.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var Mt=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
|
|
131
|
+
function Mt(){var _this16;_classCallCheck(this,Mt);_this16=_callSuper(this,Mt),_this16._waitingToRender_=!1,_this16._propUpdated_=!1,Object.keys(Mt._attributeToProperty_).forEach(function(e){var t=Mt._attributeToProperty_[e];_this16.constructPropertyAccessors(t),_this16.hasOwnProperty(e)||_this16.constructPropertyAccessors(t,e);});return _this16;}_inherits(Mt,_HTMLElement);return _createClass(Mt,[{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:zs.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,n){if(t===n)return;var s=Mt._attributes_[e](n),r=Mt._attributeToProperty_[e];this[r]=s;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(Mt._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));Mt._attributes_={},Mt._attributeToProperty_={};var Di=Mt;var sl="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path d=\"\n\t\t\tM669.727,273.516c-22.891-2.476-46.15-3.895-69.727-4.248c-103.025,0.457-209.823,25.517-310.913,73.536\n\t\t\tc-75.058,37.122-148.173,89.529-211.67,154.174C46.232,529.978,6.431,577.76,0,628.74c0.76,44.162,48.153,98.67,77.417,131.764\n\t\t\tc59.543,62.106,130.754,113.013,211.67,154.174c2.75,1.335,5.51,2.654,8.276,3.955l-75.072,131.102l102.005,60.286l551.416-960.033\n\t\t\tl-98.186-60.008L669.727,273.516z M902.563,338.995l-74.927,129.857c34.47,44.782,54.932,100.006,54.932,159.888\n\t\t\tc0,149.257-126.522,270.264-282.642,270.264c-6.749,0-13.29-0.728-19.922-1.172l-49.585,85.84c22.868,2.449,45.99,4.233,69.58,4.541\n\t\t\tc103.123-0.463,209.861-25.812,310.84-73.535c75.058-37.122,148.246-89.529,211.743-154.174\n\t\t\tc31.186-32.999,70.985-80.782,77.417-131.764c-0.76-44.161-48.153-98.669-77.417-131.763\n\t\t\tc-59.543-62.106-130.827-113.013-211.743-154.175C908.108,341.478,905.312,340.287,902.563,338.995L902.563,338.995z\n\t\t\tM599.927,358.478c6.846,0,13.638,0.274,20.361,0.732l-58.081,100.561c-81.514,16.526-142.676,85.88-142.676,168.897\n\t\t\tc0,20.854,3.841,40.819,10.913,59.325c0.008,0.021-0.008,0.053,0,0.074l-58.228,100.854\n\t\t\tc-34.551-44.823-54.932-100.229-54.932-160.182C317.285,479.484,443.808,358.477,599.927,358.478L599.927,358.478z M768.896,570.513\n\t\t\tL638.013,797.271c81.076-16.837,141.797-85.875,141.797-168.603C779.81,608.194,775.724,588.729,768.896,570.513L768.896,570.513z\"\n\t\t\t/>\n</svg>\n",il="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path id=\"path6686\" inkscape:connector-curvature=\"0\" d=\"M779.843,599.925c0,95.331-80.664,172.612-180.169,172.612\n\t\t\tc-99.504,0-180.168-77.281-180.168-172.612c0-95.332,80.664-172.612,180.168-172.612\n\t\t\tC699.179,427.312,779.843,504.594,779.843,599.925z M600,240.521c-103.025,0.457-209.814,25.538-310.904,73.557\n\t\t\tc-75.058,37.122-148.206,89.496-211.702,154.141C46.208,501.218,6.431,549,0,599.981c0.76,44.161,48.13,98.669,77.394,131.763\n\t\t\tc59.543,62.106,130.786,113.018,211.702,154.179c94.271,45.751,198.616,72.092,310.904,73.557\n\t\t\tc103.123-0.464,209.888-25.834,310.866-73.557c75.058-37.122,148.243-89.534,211.74-154.179\n\t\t\tc31.185-32.999,70.962-80.782,77.394-131.763c-0.76-44.161-48.13-98.671-77.394-131.764\n\t\t\tc-59.543-62.106-130.824-112.979-211.74-154.141C816.644,268.36,712.042,242.2,600,240.521z M599.924,329.769\n\t\t\tc156.119,0,282.675,120.994,282.675,270.251c0,149.256-126.556,270.25-282.675,270.25S317.249,749.275,317.249,600.02\n\t\t\tC317.249,450.763,443.805,329.769,599.924,329.769L599.924,329.769z\"/>\n</svg>\n";var Ft=/*#__PURE__*/function(){function Ft(){_classCallCheck(this,Ft);}return _createClass(Ft,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Vt=/*#__PURE__*/function(){function Vt(){_classCallCheck(this,Vt);}return _createClass(Vt,null,[{key:"changeVisibility",value:// prettier-ignore
|
|
133
|
+
function changeVisibility(e,t,n,s){s.target.id===Vt.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=Ft.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=Vt.createIconElement(il,Vt.VISIBLE_ICON_ID);n[E].display="none",t.appendChild(n);var s=Vt.createIconElement(sl,"not-visible-icon");return t.appendChild(s),t.onclick=Vt.changeVisibility.bind(this,e,n,s),t;}}]);}();Vt.VISIBLE_ICON_ID="visible-icon";var Fi=Vt;var Ne=/*#__PURE__*/function(){function Ne(){_classCallCheck(this,Ne);}return _createClass(Ne,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 r=Ne.createFailText();if(s.appendChild(r),e){var o=Ne.createHelpLink(e);s.appendChild(o);}if(t===!0){var _o3=Ne.createCautionText();s.appendChild(_o3);}return n.appendChild(s),{helpTextContainerElement:n,failTextElement:r};}},{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(Ot);}},{key:"onLoad",value:function onLoad(e,t){e[f].add(Ot),t.innerHTML='<div id="loading-key"></div>';}// prettier-ignore
|
|
132
135
|
},{key:"verifyKey",value:function verifyKey(e,t,n){var s=e.value.trim();n.verifyKey(s,t);}// prettier-ignore
|
|
133
|
-
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,n,s,r){var o={onSuccess:s,onFail:
|
|
134
|
-
},{key:"createContents",value:function createContents(e,t){var d;var n=
|
|
135
|
-
},{key:"setUpInitial",value:function setUpInitial(e,t,n,s){var r=(t==null?void 0:t.downloadClass)||
|
|
136
|
-
},{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,n,s){var r=(t==null?void 0:t.exportFilesClass)||
|
|
136
|
+
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,n,s,r){var o={onSuccess:s,onFail:Ne.onFail.bind(this,e,t,n),onLoad:Ne.onLoad.bind(this,e,t)},a=Ne.verifyKey.bind(this,e,o,r);t.onclick=a,e.onkeydown=function(c){!e[f].contains(Ot)&&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=Ne.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=Ne.createInput(t.insertKeyPlaceholderText),r=s.children[0],o=Fi.create(r);s.appendChild(o),n.appendChild(s);var a=Ne.createStartButton(),_Ne$createHelpTextCon=Ne.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),c=_Ne$createHelpTextCon.helpTextContainerElement,l=_Ne$createHelpTextCon.failTextElement;return n.appendChild(a),n.appendChild(c),Ne.addVerificationEvents(r,a,l,e,t),n;}},{key:"createElements",value:function createElements(e,t){var n=x();n.id="insert-key-view";var s=Ne.createContents(e,t);return n.appendChild(s),n;}},{key:"render",value:function render(e,t,n){var s=Ne.createElements(t,n);e.replaceChildren(s);}}]);}();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<bs.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return We.enableButtons(e,t,n+1);},250);}// prettier-ignore
|
|
138
|
+
},{key:"setUpInitial",value:function setUpInitial(e,t,n,s){var r=(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(r)[0],l=n==null?void 0:n.getElementsByClassName(a)[0],d=n==null?void 0:n.getElementsByClassName(o)[0];c&&(c.onclick=function(){return e();}),l&&(l.onchange=function(){l[m]&&l[m].length>0&&e(l[m]);}),d&&(d.onclick=function(){return l[Y]();}),(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(r," deep-chat-button deep-chat-web-model-button\">Download</button>\n ").concat(s?"":"<input type=\"file\" class=\"".concat(a,"\" hidden multiple />\n <button disabled class=\"").concat(o," deep-chat-button deep-chat-web-model-button\">Upload</button>"),"\n </div>");}},{key:"exportFile",value:function exportFile(e){var t=x("a"),n=4;var _loop2=function _loop2(s){setTimeout(function(){var r=s*n;for(var o=r;o<Math.min(r+n,e.length);o+=1){var a=URL.createObjectURL(e[o]);t.href=a,t.download=e[o].name,document.body.appendChild(t),t[Y](),URL.revokeObjectURL(a);}},500*s);};for(var s=0;s<e.length/n;s+=1){_loop2(s);}}// prettier-ignore
|
|
139
|
+
},{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,n,s){var r=(t==null?void 0:t.exportFilesClass)||We.EXPORT_BUTTON_CLASS;return setTimeout(function(){var o=n==null?void 0:n.getElementsByClassName(r)[0];o&&(o.onclick=function(){return We.exportFile(e);});}),(t==null?void 0:t.afterLoadHtml)||"<div>\n Model loaded successfully and has been cached for future requests.\n ".concat(s?"":"<br/> <button style=\"margin-top: 5px\" class=\"".concat(r," deep-chat-button\">Export</button>"),"\n </div>");}}]);}();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 Vs=We;var Zr={model_list:[// Llama-2
|
|
137
140
|
{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f32_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f32_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:9109.03,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:6749.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:4618.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-13b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-13b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-13b-chat-hf/Llama-2-13b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:11814.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-70b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-70b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-70b-chat-hf/Llama-2-70b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:43729.05,low_resource_required:!1,required_features:["shader-f16"]},// RedPajama
|
|
138
141
|
{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f16_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f16_1-ctx2k-webgpu.wasm",vram_required_MB:2972.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f32_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f32_1-ctx2k-webgpu.wasm",vram_required_MB:3928.09,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f16_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:2041.09,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f32_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:2558.09,low_resource_required:!0},// Mistral variants
|
|
139
142
|
{model_url:"https://huggingface.co/mlc-ai/WizardMath-7B-V1.1-q4f16_1-MLC/resolve/main/",local_id:"WizardMath-7B-V1.1-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Mistral-7B-Instruct-v0.2-q4f16_1-MLC/resolve/main/",local_id:"Mistral-7B-Instruct-v0.2-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/OpenHermes-2.5-Mistral-7B-q4f16_1-MLC/resolve/main/",local_id:"OpenHermes-2.5-Mistral-7B-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/NeuralHermes-2.5-Mistral-7B-q4f16_1-MLC/resolve/main/",local_id:"NeuralHermes-2.5-Mistral-7B-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},// TinyLlama
|
|
140
|
-
{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f16-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f16",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f16-ctx2k-webgpu.wasm",vram_required_MB:5063.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f32-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f32",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f32-ctx2k-webgpu.wasm",vram_required_MB:5394.53,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:899.11,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f32_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:992.11,low_resource_required:!0}],use_web_worker:!0},
|
|
141
|
-
_inherits(
|
|
142
|
-
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=
|
|
143
|
-
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(e,t){var _this21=this;var o,a,c,l,d,
|
|
144
|
-
function
|
|
145
|
-
function
|
|
146
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48(e,t,n){return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:if(this.connectSettings){_context48.n=1;break;}throw new Error(
|
|
147
|
-
function
|
|
148
|
-
function
|
|
149
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e,t,n){var s;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(this.connectSettings){_context51.n=1;break;}throw new Error(
|
|
150
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e,t,n){var o,a,s,r;return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(this.connectSettings){_context53.n=1;break;}throw new Error(
|
|
151
|
-
_inherits(
|
|
152
|
-
},{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(He);case 1:if(n){_context60.n=2;break;}throw new Error(or);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,ge.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(On).concat(n.base64)),E,W);});return _context61.a(2,_defineProperty({},b,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()!=="");}}]);}(xi);var Hl=/*#__PURE__*/function(_Pt6){function Hl(e){_classCallCheck(this,Hl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.translation,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Hl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(Hl,_Pt6);return _createClass(Hl,[{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[f]){_context62.n=1;break;}throw e[f];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;}()}]);}(Pt);var ei=/*#__PURE__*/function(_xi4){function ei(e){var _this31;_classCallCheck(this,ei);var r;var t=C(e.directConnection),n=t.stabilityAI;_this31=_callSuper(this,ei,[e,Si(),vi,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),ei.cleanConfig(s),Object.assign(_this31.rawBody,s)),_this31.canSendMessage=ei.canSendTextMessage;return _this31;}_inherits(ei,_xi4);return _createClass(ei,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=C(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(On).concat(n.base64)),E,W);});return _context64.a(2,_defineProperty({},b,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()!=="");}}]);}(xi);var jl=/*#__PURE__*/function(_Pt7){function jl(e){var _this32;_classCallCheck(this,jl);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,jl,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this32.permittedErrorPrefixes=[ar,"No mask_token"];return _this32;}_inherits(jl,_Pt7);return _createClass(jl,[{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[f]){_context65.n=1;break;}throw e[f];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;}()}]);}(Pt);var pr=function pr(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},$l=function $l(i,e,t,n){var s=i;s[f]?s[f].message===yi?n(pe):n(Ue):t(e);},fr=function fr(){return be("https://open.bigmodel.cn/api/paas/v4/models",ue,$l);};var ql=/*#__PURE__*/function(_k3){function ql(e){var _o$model,_a$voice;var _this33;_classCallCheck(this,ql);var r,o,a;var t=C(e.directConnection),n=t.bigModel;_this33=_callSuper(this,ql,[e,fr(),pr,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=[he,Te];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(ql,_k3);return _createClass(ql,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(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({},E,"audio/mpeg")),n=URL.createObjectURL(t);return _context67.a(2,_defineProperty({},b,[_defineProperty(_defineProperty({},T,n),E,$)]));}},_callee67);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(k);var mr=function mr(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},Gl=function Gl(i,e,t,n){var s=i;s[f]?s[f].message===yi?n(pe):n(Ue):t(e);},gr=function gr(){return be("https://api.together.xyz/v1/models",ue,Gl);};var zl=/*#__PURE__*/function(_k4){function zl(e){var _o$model2,_a$voice2;var _this34;_classCallCheck(this,zl);var r,o,a;var t=C(e.directConnection),n=t.together;_this34=_callSuper(this,zl,[e,gr(),mr,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=[it,Te];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(zl,_k4);return _createClass(zl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(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({},E,"audio/mpeg")),n=URL.createObjectURL(t);return _context69.a(2,_defineProperty({},b,[_defineProperty(_defineProperty({},T,n),E,$)]));}},_callee69);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(k);var Ze="https://api.openai.com/v1/",Nn="https://platform.openai.com/account/api-keys",zi="input_text",no="input_image",so="output_text",Ni="image_generation_call",Jo="function_call_output",Hn="response",Bn=function Bn(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Qo=function Qo(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(pe):n(Ue):t(e);},Dn=function Dn(){return be("".concat(Ze,"models"),ue,Qo);},$t=/*#__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,p,u,g,_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;p=_yield$D$processReque6.error;u=o.onFinish;if(!(p&&a)){_context70.n=2;break;}return _context70.a(2,D.onInterceptorError(a,p,u));case 2:_context70.n=3;return D.fetch(i,d,n,l).then(function(y){return D.processResponseByType(y);});case 3:g=_context70.v;if(!g[f]){_context70.n=4;break;}throw g[f].message;case 4:return _context70.a(2,g);}},_callee70);}));return function $t(_x144,_x145,_x146){return _ref58.apply(this,arguments);};}(),Ke=/*#__PURE__*/function(){function Ke(){_classCallCheck(this,Ke);}return _createClass(Ke,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[q];delete r[q];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($t(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[q]=o,c));case 4:_context72.p=4;_t24=_context72.v;throw r[q]=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")?W:on;}},{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($t(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 p=new FileReader();p.readAsDataURL(c),p.onload=function(u){d(_defineProperty(_defineProperty(_defineProperty({},T,u.target.result),"name",t[l].name),E,Ke.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
|
|
153
|
-
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee74(e,t,n,s,r){var l,d,o,a,c,_t25;return _regenerator().w(function(_context74){while(1)switch(_context74.n){case 0:a=n.getFilesPrefix,c=n.getFilesPostfix;_t25=t.length>0;if(!_t25){_context74.n=2;break;}_context74.n=1;return
|
|
143
|
+
{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f16-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f16",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f16-ctx2k-webgpu.wasm",vram_required_MB:5063.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f32-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f32",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f32-ctx2k-webgpu.wasm",vram_required_MB:5394.53,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:899.11,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f32_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:992.11,low_resource_required:!0}],use_web_worker:!0},Z=/*#__PURE__*/function(_vn2){function Z(e){var _this17;_classCallCheck(this,Z);var t,n;_this17=_callSuper(this,Z,[e]),_this17._isModelLoaded=!1,_this17._isModelLoading=!1,_this17._loadOnFirstMessage=!1,_this17._webModel={},_this17.permittedErrorPrefixes=[Z.MULTIPLE_MODELS_ERROR,Z.WEB_LLM_NOT_FOUND_ERROR,Z.GENERIC_ERROR],_this17._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this17._webModel=e.webModel),(t=_this17._webModel.load)!=null&&t.clearCache&&Z.clearAllCache(),_this17.findModelInWindow(e),_this17.canSendMessage=_this17.canSubmit.bind(_assertThisInitialized(_this17)),_this17._chatEl=(n=e.shadowRoot)==null?void 0:n.children[0],e.history&&Z.setUpHistory(_this17._conversationHistory,e.history);return _this17;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
|
|
144
|
+
_inherits(Z,_vn2);return _createClass(Z,[{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>Z.MODULE_SEARCH_LIMIT_S?((n=this._messages)==null||n.addNewErrorMessage(oe,Z.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&&z.scrollToTop((s=_this20._messages)==null?void 0:s.elementRef);},e);}// prettier-ignore
|
|
145
|
+
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Vs.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 _callee36(e){var t;return _regenerator().w(function(_context36){while(1)switch(_context36.n){case 0:t=this._webModel.load;if(!t){_context36.n=2;break;}if(!t.onInit){_context36.n=1;break;}this.init();return _context36.a(2);case 1:if(!t.onMessage){_context36.n=2;break;}this._loadOnFirstMessage=!0;return _context36.a(2);case 2:e||this.init();case 3:return _context36.a(2);}},_callee36,this);}));function configureInit(_x83){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e){var n,t,_t16;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:(n=this._messages)==null||n.removeError();t=this.attemptToCreateChat();_t16=t;if(!_t16){_context37.n=1;break;}_context37.n=1;return this.loadModel(t,e);case 1:return _context37.a(2);}},_callee37,this);}));function init(_x84){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var t;if(Z.chat){(t=this._messages)==null||t.addNewErrorMessage(oe,Z.MULTIPLE_MODELS_ERROR),console[p](Z.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return Zr.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var n;var e=Z.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=w(Zr);if(this._webModel.urls){var s=t.model_list.find(function(r){return r.local_id=e;});s&&(this._webModel.urls.model&&(s.model_url=this._webModel.urls.model),this._webModel.urls.wasm&&(s.model_lib_url=this._webModel.urls.wasm));}return(n=this._webModel.load)!=null&&n.skipCache&&(t.use_cache=!1),{model:e,appConfig:t};}// prettier-ignore
|
|
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 z.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=Vs.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=ea({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](po);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=ta(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 be=function be(i,e,t,n){return{url:i,method:e,handleVerificationResult:t,augmentUrl:n};},rl=function rl(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},ol=function ol(i,e,t,n){var s=i;Array.isArray(s[p])&&s[p][0]==="Error in `parameters`: field required"?t(e):n(ue);},al=function al(){return be("https://api-inference.huggingface.co/models/gpt2",ye,ol);},cs=/*#__PURE__*/function(_M){// prettier-ignore
|
|
147
|
+
function cs(e,t,n,s,r,o){var _this23;_classCallCheck(this,cs);_this23=_callSuper(this,cs,[e,al(),rl,r,o]),_this23.insertKeyPlaceholderText="Hugging Face Token",_this23.keyHelpUrl="https://huggingface.co/settings/tokens",_this23.permittedErrorPrefixes=[sr],_this23.url="".concat(cs.URL_PREFIX).concat(n),_this23.textInputPlaceholderText=t,_typeof(s)=="object"&&(s.model&&(_this23.url="".concat(cs.URL_PREFIX).concat(s.model)),s.options&&(_this23.rawBody.options=s.options),s.parameters&&(_this23.rawBody.parameters=s.parameters));return _this23;}_inherits(cs,_M);return _createClass(cs,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var _s$options;var s=w(e),r=t[t.length-1][h];if(r)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:r},s);}},{key:"callServiceAPI",value:function(){var _callServiceAPI3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e,t,n){var s;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:if(this.connectSettings){_context47.n=1;break;}throw new Error(je);case 1:s=this.preprocessBody(this.rawBody,t,n);ge.request(this,s,e);case 2:return _context47.a(2);}},_callee47,this);}));function callServiceAPI(_x108,_x109,_x110){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(M);cs.URL_PREFIX="https://api-inference.huggingface.co/models/";var Ut=cs;var Cs=/*#__PURE__*/function(_Ut){// prettier-ignore
|
|
148
|
+
function Cs(e,t,n,s,r,o){var _this24;_classCallCheck(this,Cs);_this24=_callSuper(this,Cs,[e,t,n,s,r,o]),_this24.isTextInputDisabled=!0,_this24.canSendMessage=Cs.canSendFile;return _this24;}_inherits(Cs,_Ut);return _createClass(Cs,[{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 _callee48(e,t,n){return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:if(this.connectSettings){_context48.n=1;break;}throw new Error(je);case 1:if(n!=null&&n[0]){_context48.n=2;break;}throw new Error(pi);case 2:ge.poll(this,n[0],e,!1);case 3:return _context48.a(2);}},_callee48,this);}));function callServiceAPI(_x111,_x112,_x113){return _callServiceAPI4.apply(this,arguments);}return callServiceAPI;}()}],[{key:"canSendFile",value:function canSendFile(e,t){return!!(t!=null&&t[0]);}}]);}(Ut);var cl=/*#__PURE__*/function(_Cs){// prettier-ignore
|
|
150
|
+
function cl(e){_classCallCheck(this,cl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.audioClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,cl,[e,"Attach an audio ".concat(ne),"ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,n,{audio:{}}]);}_inherits(cl,_Cs);return _createClass(cl,[{key:"extractPollResultData",value:function(){var _extractPollResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49(e){var t;return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(!e.estimated_time){_context49.n=1;break;}return _context49.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[p]){_context49.n=2;break;}throw e[p];case 2:return _context49.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee49);}));function extractPollResultData(_x114){return _extractPollResultData.apply(this,arguments);}return extractPollResultData;}()}]);}(Cs);var ll=/*#__PURE__*/function(_Cs2){function ll(e){_classCallCheck(this,ll);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.imageClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ll,[e,"Attach an image ".concat(ne),"google/vit-base-patch16-224",t,n,{images:{}}]);}_inherits(ll,_Cs2);return _createClass(ll,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(e){var t;return _regenerator().w(function(_context50){while(1)switch(_context50.n){case 0:if(!e.estimated_time){_context50.n=1;break;}return _context50.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[p]){_context50.n=2;break;}throw e[p];case 2:return _context50.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee50);}));function extractPollResultData(_x115){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(Cs);var bi=function bi(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},hl=function hl(i,e,t,n){i.message?n(ue):t(e);},yi=function yi(){return be("https://api.stability.ai/v1/engines/list",de,hl);},zn="data:image/png;base64,";var Ei=/*#__PURE__*/function(_M2){// prettier-ignore
|
|
151
|
+
function Ei(e,t,n,s,r){var _this25;_classCallCheck(this,Ei);_this25=_callSuper(this,Ei,[e,t,n,s,r]),_this25.insertKeyPlaceholderText=_this25.genereteAPIKeyName("Stability AI"),_this25.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this25.permittedErrorPrefixes=[ws,"invalid_"];return _this25;}_inherits(Ei,_M2);return _createClass(Ei);}(M);var Ks=/*#__PURE__*/function(_Ei){function Ks(e){var _this26;_classCallCheck(this,Ks);var o;var t=w(e.directConnection),n=t==null?void 0:t.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this26=_callSuper(this,Ks,[e,yi(),bi,n,s]),_this26.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",_this26.textInputPlaceholderText="Describe image changes";var r=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageUpscale;_typeof(r)=="object"&&(r.engine_id&&(_this26.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/image-to-image/upscale")),Ks.cleanConfig(r),Object.assign(_this26.rawBody,r)),_this26.canSendMessage=Ks.canSendFileMessage;return _this26;}_inherits(Ks,_Ei);return _createClass(Ks,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(K,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 _callee51(e,t,n){var s;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(this.connectSettings){_context51.n=1;break;}throw new Error(je);case 1:if(n){_context51.n=2;break;}throw new Error(nr);case 2:s=this.createFormDataBody(this.rawBody,n[0]);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,s,e),!1);case 3:return _context51.a(2);}},_callee51,this);}));function callServiceAPI(_x116,_x117,_x118){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e){var t;return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(!e.message){_context52.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(zn).concat(n.base64)),y,K);});return _context52.a(2,_defineProperty({},m,t));}},_callee52);}));function extractResultData(_x119){return _extractResultData2.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id;}},{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}}]);}(Ei);var Ws=/*#__PURE__*/function(_Ei2){function Ws(e){var _this27;_classCallCheck(this,Ws);var o;var t=w(e.directConnection),n=t==null?void 0:t.stabilityAI,s=_defineProperty({},Q,_defineProperty({},m,{acceptedFormats:".png",maxNumberOfFiles:2}));_this27=_callSuper(this,Ws,[e,yi(),bi,n,s]),_this27.url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",_this27._maskSource="MASK_IMAGE_WHITE",_this27.textInputPlaceholderText="Describe image changes";var r=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageMasking;_typeof(r)=="object"&&(r.engine_id&&(_this27.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/image-to-image/masking")),r.weight!==void 0&&r.weight!==null&&(_this27._imageWeight=r.weight),r.mask_source!==void 0&&r.mask_source!==null&&(_this27._maskSource=r.mask_source),Ws.cleanConfig(r),Object.assign(_this27.rawBody,r)),_this27.canSendMessage=Ws.canSendFileTextMessage;return _this27;}_inherits(Ws,_Ei2);return _createClass(Ws,[{key:"createFormDataBody",value:function createFormDataBody(e,t,n,s){var r=new FormData();return r.append("init_image",t),r.append("mask_source",String(this._maskSource)),r.append("mask_image",n),s&&s!==""&&r.append("text_prompts[0][text]",s),this._imageWeight!==void 0&&this._imageWeight!==null&&r.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(o){r.append(o,String(e[o]));}),r.get("weight")===void 0&&r.append("weight",String(1)),r;}// prettier-ignore
|
|
153
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e,t,n){var o,a,s,r;return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(this.connectSettings){_context53.n=1;break;}throw new Error(je);case 1:if(!(!n||!n[0]||!n[1])){_context53.n=2;break;}throw new Error(nr);case 2:s=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim(),r=this.createFormDataBody(this.rawBody,n[0],n[1],s);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,r,e),!1);case 3:return _context53.a(2);}},_callee53,this);}));function callServiceAPI(_x120,_x121,_x122){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_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(zn).concat(n.base64)),y,K);});return _context54.a(2,_defineProperty({},m,t));}},_callee54);}));function extractResultData(_x123){return _extractResultData3.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(Ei);var dl=/*#__PURE__*/function(_Cs3){function dl(e){_classCallCheck(this,dl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.audioSpeechRecognition,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,dl,[e,"Attach an audio ".concat(ne),"facebook/wav2vec2-large-960h-lv60-self",t,n,{audio:{}}]);}_inherits(dl,_Cs3);return _createClass(dl,[{key:"extractPollResultData",value:function(){var _extractPollResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(e){return _regenerator().w(function(_context55){while(1)switch(_context55.n){case 0:if(!e.estimated_time){_context55.n=1;break;}return _context55.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[p]){_context55.n=2;break;}throw e[p];case 2:return _context55.a(2,_defineProperty({},h,e[h]||""));}},_callee55);}));function extractPollResultData(_x124){return _extractPollResultData3.apply(this,arguments);}return extractPollResultData;}()}]);}(Cs);var ul=/*#__PURE__*/function(_Ut2){function ul(e){_classCallCheck(this,ul);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.textGeneration,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ul,[e,"Once upon a time","gpt2",t,n]);}_inherits(ul,_Ut2);return _createClass(ul,[{key:"extractResultData",value:function(){var _extractResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56(e){var t;return _regenerator().w(function(_context56){while(1)switch(_context56.n){case 0:if(!e[p]){_context56.n=1;break;}throw e[p];case 1:return _context56.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.generated_text)||""));}},_callee56);}));function extractResultData(_x125){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(Ut);var pl=/*#__PURE__*/function(_Ut3){function pl(e){var _this28;_classCallCheck(this,pl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.questionAnswer,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this28=_callSuper(this,pl,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,n]),_this28.permittedErrorPrefixes=[sr,"Error in"],_this28._context=t.context;return _this28;}_inherits(pl,_Ut3);return _createClass(pl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return{inputs:{question:n,context:this._context,options:{wait_for_model:!0}}};}},{key:"extractResultData",value:function(){var _extractResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57(e){return _regenerator().w(function(_context57){while(1)switch(_context57.n){case 0:if(!e[p]){_context57.n=1;break;}throw e[p];case 1:return _context57.a(2,_defineProperty({},h,e.answer||""));}},_callee57);}));function extractResultData(_x126){return _extractResultData5.apply(this,arguments);}return extractResultData;}()}]);}(Ut);var fl=/*#__PURE__*/function(_Ut4){function fl(e){_classCallCheck(this,fl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.summarization,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,fl,[e,"Insert text to summarize","facebook/bart-large-cnn",t,n]);}_inherits(fl,_Ut4);return _createClass(fl,[{key:"extractResultData",value:function(){var _extractResultData6=_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.summary_text)||""));}},_callee58);}));function extractResultData(_x127){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(Ut);var ml=/*#__PURE__*/function(_Ut5){function ml(e){var _this29$maxMessages;var _this29;_classCallCheck(this,ml);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.conversation,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this29=_callSuper(this,ml,[e,"Ask me anything!","facebook/blenderbot-400M-distill",t,n]),(_this29$maxMessages=_this29.maxMessages)!==null&&_this29$maxMessages!==void 0?_this29$maxMessages:_this29.maxMessages=-1;return _this29;}// prettier-ignore
|
|
154
|
+
_inherits(ml,_Ut5);return _createClass(ml,[{key:"processMessagesI",value:function processMessagesI(e){var t=e.filter(function(a){return a[h];}),n=t[t.length-1][h],s=t.slice(0,t.length-1);if(!n)return;var r=s.filter(function(a){return a[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:r,generated_responses:o,mostRecentMessageText:n};}},{key:"preprocessBody",value:function preprocessBody(e,t){var _n$options;var n=w(e),s=this.processMessagesI(t);if(s)return(_n$options=n.options)!==null&&_n$options!==void 0?_n$options:n.options={},n.options.wait_for_model=!0,_objectSpread({inputs:_defineProperty({past_user_inputs:s.past_user_inputs,generated_responses:s.generated_responses},h,s.mostRecentMessageText)},n);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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.generated_text||""));}},_callee59);}));function extractResultData(_x128){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(Ut);var Xs=/*#__PURE__*/function(_Ei3){function Xs(e){var _this30;_classCallCheck(this,Xs);var o;var t=w(e.directConnection),n=t.stabilityAI,s=_defineProperty({},Q,_defineProperty({},m,{acceptedFormats:".png",maxNumberOfFiles:1}));_this30=_callSuper(this,Xs,[e,yi(),bi,n,s]),_this30.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this30.textInputPlaceholderText="Describe image changes";var r=(o=t.stabilityAI)==null?void 0:o.imageToImage;_typeof(r)=="object"&&(r.engine_id&&(_this30.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/text-to-image")),r.weight!==void 0&&r.weight!==null&&(_this30._imageWeight=r.weight),Xs.cleanConfig(r),Object.assign(_this30.rawBody,r)),_this30.canSendMessage=Xs.canSendFileTextMessage;return _this30;}_inherits(Xs,_Ei3);return _createClass(Xs,[{key:"createFormDataBody",value:function createFormDataBody(e,t,n){var s=new FormData();return s.append("init_image",t),n&&n!==""&&s.append("text_prompts[0][text]",n),this._imageWeight!==void 0&&this._imageWeight!==null&&s.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s.get("weight")===void 0&&s.append("weight",String(1)),s;}// prettier-ignore
|
|
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(nr);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,ge.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(zn).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 gl=/*#__PURE__*/function(_Ut6){function gl(e){_classCallCheck(this,gl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.translation,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,gl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(gl,_Ut6);return _createClass(gl,[{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(zn).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 bl=/*#__PURE__*/function(_Ut7){function bl(e){var _this32;_classCallCheck(this,bl);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,bl,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this32.permittedErrorPrefixes=[sr,"No mask_token"];return _this32;}_inherits(bl,_Ut7);return _createClass(bl,[{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 lr=function lr(i){return _defineProperty(_defineProperty({},q,ee),he,"".concat(Ce).concat(i));},yl=function yl(i,e,t,n){var s=i;s[p]?s[p].message===fi?n(ue):n(He):t(e);},hr=function hr(){return be("https://open.bigmodel.cn/api/paas/v4/models",de,yl);};var El=/*#__PURE__*/function(_M3){function El(e){var _o$model,_a$voice;var _this33;_classCallCheck(this,El);var r,o,a;var t=w(e.directConnection),n=t.bigModel;_this33=_callSuper(this,El,[e,hr(),lr,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=[he,Te];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(El,_M3);return _createClass(El,[{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,$)]));}},_callee67);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(M);var dr=function dr(i){return _defineProperty(_defineProperty({},q,ee),he,"".concat(Ce).concat(i));},_l=function _l(i,e,t,n){var s=i;s[p]?s[p].message===fi?n(ue):n(He):t(e);},ur=function ur(){return be("https://api.together.xyz/v1/models",de,_l);};var vl=/*#__PURE__*/function(_M4){function vl(e){var _o$model2,_a$voice2;var _this34;_classCallCheck(this,vl);var r,o,a;var t=w(e.directConnection),n=t.together;_this34=_callSuper(this,vl,[e,ur(),dr,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=[ct,Te];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(vl,_M4);return _createClass(vl,[{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,$)]));}},_callee69);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(M);var Qe="https://api.openai.com/v1/",Vn="https://platform.openai.com/account/api-keys",Ui="input_text",Yr="input_image",Jr="output_text",Ri="image_generation_call",Ro="function_call_output",Yn="response",Kn=function Kn(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},Io=function Io(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 be("".concat(Qe,"models"),de,Io);},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[q];delete r[q];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[q]=o,c));case 4:_context72.p=4;_t24=_context72.v;throw r[q]=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 _callee74(e,t,n,s,r){var l,d,o,a,c,_t25;return _regenerator().w(function(_context74){while(1)switch(_context74.n){case 0:a=n.getFilesPrefix,c=n.getFilesPostfix;_t25=t.length>0;if(!_t25){_context74.n=2;break;}_context74.n=1;return Xe.getFiles(e,t,a,c);case 1:o=_context74.v;(l=r==null?void 0:r[h])!=null&&l.value&&o.forEach(function(u,g){var _;if(!u[T])return;var b=t[g].path;(_=r==null?void 0:r[h])!=null&&_.value&&b&&(r[h].value=r[h].value.replace(b,u[T]));});case 2:return _context74.a(2,(d=r==null?void 0:r[h])!=null&&d.value?_defineProperty(_defineProperty({},h,r[h].value),S,s):_defineProperty(_defineProperty({},m,o),S,s));}},_callee74);}));function getFilesAndNewText(_x156,_x157,_x158,_x159,_x160){return _getFilesAndNewText.apply(this,arguments);}return getFilesAndNewText;}()// Noticed an issue where text contains a sandbox hyperlink to a csv, but no annotation provided
|
|
154
157
|
// To reproduce use the following text:
|
|
155
158
|
// give example data for a csv and create a suitable bar chart for it with a link
|
|
156
159
|
// Don't think it can be fixed and it is something on OpenAI side of things
|
|
157
160
|
// prettier-ignore
|
|
158
|
-
},{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(r){var o,a;(a=(o=r[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:
|
|
159
|
-
},{key:"getFilesAndText",value:function(){var _getFilesAndText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee75(e,t,n,s){var r;return _regenerator().w(function(_context75){while(1)switch(_context75.n){case 0:r=
|
|
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(r){var o,a;(a=(o=r[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 _callee75(e,t,n,s){var r;return _regenerator().w(function(_context75){while(1)switch(_context75.n){case 0:r=Xe.getFileDetails(t,s);_context75.n=1;return Xe.getFilesAndNewText(e,r,n,t.role,s);case 1:return _context75.a(2,_context75.v);}},_callee75);}));function getFilesAndText(_x161,_x162,_x163,_x164){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 r=e.data[s];if(r.role===St)n.push(r);else break;}return n.reverse();}// test this using this prompt and it should give 2 text mesages and a file:
|
|
160
163
|
// "give example data for a csv and create a suitable bar chart"
|
|
161
|
-
},{key:"parseMessages",value:function parseMessages(e,t,n){var s=[];return t.forEach(/*#__PURE__*/function(){var _ref63=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(r){return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:r.content.filter(function(o){return!!o[h]||!!o.image_file;}).sort(function(o){return o[h]?-1:o.image_file?1:0;}).forEach(/*#__PURE__*/function(){var _ref64=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee76(o){return _regenerator().w(function(_context76){while(1)switch(_context76.n){case 0:s.push(
|
|
162
|
-
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,n,s){var r;return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:r=
|
|
163
|
-
function
|
|
164
|
-
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var t,n,s,r,o,a;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:if(this._functionHandlerI){_context87.n=1;break;}throw Error(
|
|
165
|
-
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(e){var t,n,s,r,o,a,c,l,_a4,_c4;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:if(!(e.content&&e.content.length>0&&this.messages)){_context89.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)){_context89.n=1;break;}c=e.content.find(function(d){return!!d[h];})||e.content[0],l=
|
|
164
|
+
},{key:"parseMessages",value:function parseMessages(e,t,n){var s=[];return t.forEach(/*#__PURE__*/function(){var _ref63=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(r){return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:r.content.filter(function(o){return!!o[h]||!!o.image_file;}).sort(function(o){return o[h]?-1:o.image_file?1:0;}).forEach(/*#__PURE__*/function(){var _ref64=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee76(o){return _regenerator().w(function(_context76){while(1)switch(_context76.n){case 0:s.push(Xe.getFilesAndText(e,r,n,o));case 1:return _context76.a(2);}},_callee76);}));return function(_x166){return _ref64.apply(this,arguments);};}());case 1:return _context77.a(2);}},_callee77);}));return function(_x165){return _ref63.apply(this,arguments);};}()),Promise.all(s);}},{key:"processStreamMessages",value:function(){var _processStreamMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(e,t,n){return _regenerator().w(function(_context78){while(1)switch(_context78.n){case 0:return _context78.a(2,Xe.parseMessages(e,[{content:t,role:St}],n));}},_callee78);}));function processStreamMessages(_x167,_x168,_x169){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
|
|
165
|
+
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,n,s){var r;return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:r=Xe.parseResult(t,n);return _context79.a(2,Xe.parseMessages(e,r,s));}},_callee79);}));function processAPIMessages(_x170,_x171,_x172,_x173){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 Rt=Xe;var Kt=/*#__PURE__*/function(_M5){// prettier-ignore
|
|
166
|
+
function Kt(e,t,n,s,r,o){var _this35;_classCallCheck(this,Kt);if(_this35=_callSuper(this,Kt,[e,s,r,o]),_this35.insertKeyPlaceholderText=_this35.genereteAPIKeyName("OpenAI"),_this35.keyHelpUrl=Vn,_this35.url="",_this35.permittedErrorPrefixes=[ws,"Please send text",gs.FAILED_ERROR_MESSAGE],_this35.shouldFetchHistory=!1,_this35._searchedForThreadId=!1,_this35._config={},_this35._newAssistantDetails={model:"gpt-4"},_this35._waitingForStreamResponse=!1,_this35._isSSEStream=!1,_this35.urlSegments=n,_typeof(t)=="object"){_this35._config=t;var _this35$_config=_this35._config,a=_this35$_config.new_assistant,c=_this35$_config.thread_id,l=_this35$_config.load_thread_history;Object.assign(_this35._newAssistantDetails,a),c&&(_this35.sessionId=c),l&&(_this35.shouldFetchHistory=!0);}_this35.maxMessages=1,_this35._isSSEStream=!!(_this35.stream&&(_typeof(_this35.stream)!="object"||!_this35.stream.simulation));return _this35;}_inherits(Kt,_M5);return _createClass(Kt,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(){var _this36=this;var e,_t26;return _regenerator().w(function(_context80){while(1)switch(_context80.p=_context80.n){case 0:setTimeout(function(){return _this36.deepChat.disableSubmitButton();},2);_context80.p=1;_context80.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context80.v;return _context80.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context80.p=3;_t26=_context80.v;return _context80.a(2,[_defineProperty({},p,mo)]);}},_callee80,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=$n.getCharacterLimitMessages(e,n)[0];if(t&&t.length>0){var r=this.filesToolType;if(typeof this.filesToolType=="function"){var a=this.filesToolType(t.map(function(_ref66){var c=_ref66.name;return c;}));a==="code_interpreter"||a==="file_search"||a===Q?r=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(r==="file_search")return Kt.processAttachmentsMessage(s,t,"file_search");if(r==="code_interpreter")return Kt.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=Kt.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),r=this.processMessage(t,n);return s.thread={messages:[r]},s;}},{key:"callService",value:function callService(e,t,n){if(this.messages=e,this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/messages").concat(this.urlSegments.createMessagePostfix);var s=this.processMessage(t,n);ge.request(this,s,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _s7=this.createNewThreadMessages(this.rawBody,t,n);this._isSSEStream?this.createStreamRun(_s7):ge.request(this,_s7,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(e,t,n){var _r$assistant_id;var r,s,_t27,_t28;return _regenerator().w(function(_context81){while(1)switch(_context81.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context81.n=1;break;}throw new Error(je);case 1:if(!((_r$assistant_id=(r=this.rawBody).assistant_id)!==null&&_r$assistant_id!==void 0)){_context81.n=2;break;}_r$assistant_id;_context81.n=5;break;case 2:_t27=this._config.assistant_id;if(_t27){_context81.n=4;break;}_context81.n=3;return this.createNewAssistant();case 3:_t27=_context81.v;case 4:r.assistant_id=_t27;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!n){_context81.n=7;break;}_context81.n=6;return Rt.storeFiles(this,e,n,this.urlSegments.storeFiles);case 6:_t28=_context81.v;_context81.n=8;break;case 7:_t28=void 0;case 8:s=_t28;this.connectSettings.method=ye,this.callService(e,t,s);case 9:return _context81.a(2);}},_callee81,this);}));function callServiceAPI(_x174,_x175,_x176){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(){var e,_t29;return _regenerator().w(function(_context82){while(1)switch(_context82.p=_context82.n){case 0:_context82.p=0;this.url=this.urlSegments.newAssistantUrl;_context82.n=1;return Zt(this,w(this._newAssistantDetails),ye);case 1:e=_context82.v;return _context82.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context82.p=2;_t29=_context82.v;console[p](_t29),console[p]("Failed to create a new assistant");case 3:return _context82.a(2);}},_callee82,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 _callee83(e){var s,t,n;return _regenerator().w(function(_context83){while(1)switch(_context83.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context83.n=2;break;}_context83.n=1;return this.handleStream(e);case 1:return _context83.a(2,_context83.v);case 2:if(!e[p]){_context83.n=3;break;}throw e[p].message.startsWith(Rt.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e[p].message;case 3:this.asyncCallInProgress=!0;_context83.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:de,headers:(s=this.connectSettings)==null?void 0:s.headers};return _context83.a(2,(ge.executePollRequest(this,t,n,this.messages),_defineProperty({},h,"")));}},_callee83,this);}));function extractResultData(_x177){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(e){var t;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:if(!this.sessionId){_context84.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context84.n=1;return Zt(this,w(this.rawBody),ye);case 1:t=_context84.v;this.run_id=t.id;_context84.n=3;break;case 2:this.sessionId=e.thread_id,this.run_id=e.id,this.updateSessionId(this.sessionId);case 3:return _context84.a(2);}},_callee84,this);}));function assignThreadAndRun(_x178){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var t,s,r,n,_args85=arguments,_t30;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:t=_args85.length>1&&_args85[1]!==undefined?_args85[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context85.n=1;return Zt(this,{},de);case 1:n=_context85.v;_t30=!t&&this.deepChat.responseInterceptor;if(!_t30){_context85.n=3;break;}_context85.n=2;return(r=(s=this.deepChat).responseInterceptor)==null?void 0:r.call(s,n);case 2:n=_context85.v;case 3:return _context85.a(2,Rt.processAPIMessages(this,n,t,this.urlSegments));}},_callee85,this);}));function getThreadMessages(_x179){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){var _this37=this;var r,t,n,o,_o$shift,a,c,s;return _regenerator().w(function(_context86){while(1)switch(_context86.n){case 0:t=e.status,n=e.required_action;if(!(t==="queued"||t==="in_progress")){_context86.n=1;break;}return _context86.a(2,{timeoutMS:Kt.POLLING_TIMEOUT_MS});case 1:if(!(t===ir&&this.messages)){_context86.n=3;break;}_context86.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context86.v;_o$shift=o.shift();a=_o$shift.text;c=_o$shift.files;return _context86.a(2,(setTimeout(function(){o.forEach(function(l){return _this37.deepChat.addMessage(l);});}),_defineProperty({text:a,_sessionId:this.sessionId},m,c)));case 3:s=(r=n==null?void 0:n.submit_tool_outputs)==null?void 0:r.tool_calls;if(!(t==="requires_action"&&s)){_context86.n=5;break;}_context86.n=4;return this.handleTools(s);case 4:return _context86.a(2,_context86.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context86.a(2);}},_callee86,this);}));function extractPollResultData(_x180){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
|
|
167
|
+
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var t,n,s,r,o,a;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:if(this._functionHandlerI){_context87.n=1;break;}throw Error(Qt);case 1:t=e.map(function(c){return{name:c["function"].name,arguments:c["function"].arguments};});_context87.n=2;return this._functionHandlerI(t);case 2:n=_context87.v;if(!(!Array.isArray(n)||e.length!==n.length)){_context87.n=3;break;}throw Error(Rt.FUNCTION_TOOL_RESP_ERROR);case 3:_context87.n=4;return Promise.all(n);case 4:s=_context87.v;if(!s.find(function(c){return _typeof(c)!==_e;})){_context87.n=5;break;}throw Error(Rt.FUNCTION_TOOL_RESP_ERROR);case 5:r=s.map(function(c,l){return{tool_call_id:e[l].id,output:c};}),o="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId),a="/runs/".concat(this.run_id,"/submit_tool_outputs").concat(this.urlSegments.threadsPosfix);this.url="".concat(o).concat(a);if(!this._isSSEStream){_context87.n=7;break;}_context87.n=6;return this.createStreamRun({tool_outputs:r});case 6:_context87.n=8;break;case 7:_context87.n=8;return Zt(this,{tool_outputs:r},ye);case 8:return _context87.a(2,{timeoutMS:Kt.POLLING_TIMEOUT_MS});}},_callee87,this);}));function handleTools(_x181){return _handleTools.apply(this,arguments);}return handleTools;}()},{key:"handleStream",value:function(){var _handleStream=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){var n,s,t,r;return _regenerator().w(function(_context88){while(1)switch(_context88.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)){_context88.n=2;break;}this.run_id=e.id;_context88.n=1;return this.handleTools(t);case 1:return _context88.a(2,_context88.v);case 2:if(!this._waitingForStreamResponse){_context88.n=3;break;}return _context88.a(2,this.parseStreamResult(e));case 3:if(this._isSSEStream&&this.sessionId){this.asyncCallInProgress=!0,this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);r=w(this.rawBody);this.createStreamRun(r);}return _context88.a(2,_defineProperty({},h,""));}},_callee88,this);}));function handleStream(_x182){return _handleStream.apply(this,arguments);}return handleStream;}()// prettier-ignore
|
|
168
|
+
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(e){var t,n,s,r,o,a,c,l,_a4,_c4;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:if(!(e.content&&e.content.length>0&&this.messages)){_context89.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)){_context89.n=1;break;}c=e.content.find(function(d){return!!d[h];})||e.content[0],l=Rt.getFilesAndText.bind(this,this,_defineProperty(_defineProperty({},S,St),"content",e.content),this.urlSegments,c);return _context89.a(2,((n=this._messageStream)==null||n.endStreamAfterFileDownloaded(this.messages,l),_defineProperty({},h,"")));case 1:if(!((s=e.delta)!=null&&s.content)){_context89.n=4;break;}if(!(e.delta.content.length>1)){_context89.n=3;break;}_a4=e.delta.content.find(function(c){return c[h];});if(!((r=_a4==null?void 0:_a4[h])!=null&&r.annotations&&_a4[h].annotations.length===0)){_context89.n=3;break;}_context89.n=2;return Rt.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_c4=_context89.v;return _context89.a(2,_defineProperty(_defineProperty({},h,_c4[0][h]),m,_c4[1][m]));case 3:return _context89.a(2,_defineProperty({},h,(o=e.delta.content[0][h])==null?void 0:o.value));case 4:return _context89.a(2,(!this.sessionId&&e.thread_id&&(this.sessionId=e.thread_id),_defineProperty({},h,"")));}},_callee89,this);}));function parseStreamResult(_x183){return _parseStreamResult.apply(this,arguments);}return parseStreamResult;}()// https://platform.openai.com/docs/api-reference/assistants-streaming
|
|
166
169
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
|
-
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){return _regenerator().w(function(_context90){while(1)switch(_context90.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context90.n=1;return V.request(this,e,this.messages,!0,!0);case 1:this._messageStream=_context90.v;case 2:return _context90.a(2);}},_callee90,this);}));function createStreamRun(_x184){return _createStreamRun.apply(this,arguments);}return createStreamRun;}()}],[{key:"processImageMessage",value:function processImageMessage(e,t){var n=t==null?void 0:t.filter(function(s){return Se.isImageFileExtension(s.name);}).map(function(s){return _defineProperty(_defineProperty({},
|
|
168
|
-
function
|
|
169
|
-
},{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)),
|
|
170
|
-
},{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
|
|
171
|
-
function setInputAudioTranscribe(e,t){if(t){var _n3="whisper-1";_typeof(t)=="object"?
|
|
172
|
-
},{key:"setUpView",value:function setUpView(e,t){e[v].display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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(Ze,"realtime/sessions"),{method:ye,body:ce(this.rawBody),headers:_defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(e))});case 1:_context93.n=2;return _context93.v.json();case 2:return _context93.a(2,_context93.v.client_secret.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(ce(_defineProperty(_defineProperty({},E,"session.update"),"session",e)));},sendMessage:function sendMessage(e,t){var n=t||Mn,s=[_defineProperty(_defineProperty({},E,n===Mn||n===F?zi:h),"text",e)],r=_defineProperty(_defineProperty(_defineProperty({},x,n),E,"message"),"content",s);_this42.sendMessage(r);}};}},{key:"createContainer",value:function createContainer(){var e=A();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=A();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[v],(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=A();e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e[v],(s=this._buttonsConfig)==null?void 0:s.container),this._microphoneButton=this.createMicophoneButton();var t=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 si((t=this._buttonsConfig)==null?void 0:t[ct]);return e.elementRef[m].add(Q.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),z.assignButtonEvents(e.elementRef,function(){e.isActive?(_this43.toggleMicorphone(!0),e.elementRef[m].replace(Q.MICROPHONE_ACTIVE,Q.BUTTON_DEFAULT),e.changeToDefault(),_this43._isMuted=!1):(_this43.toggleMicorphone(!1),e.elementRef[m].replace(Q.BUTTON_DEFAULT,Q.MICROPHONE_ACTIVE),me.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 si((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[m].add(Q.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),z.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[f]("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=A($);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[f]("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[f]("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,p,c,g,y,_,_t37;return _regenerator().w(function(_context96){while(1)switch(_context96.p=_context96.n){case 0:c=JSON.parse(a.data);if(!(c[E]==="session.created")){_context96.n=1;break;}_this45.removeUnavailable(),_this45._toggleButton&&(me.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(Vl)),_this45.hideLoading();_context96.n=7;break;case 1:if(!(c[E]==="response.done")){_context96.n=6;break;}g=(p=JSON.parse(a.data).response.output)==null?void 0:p[0];if(!((g==null?void 0:g[E])===$s)){_context96.n=5;break;}y=g.name,_=g.call_id;_context96.p=2;_context96.n=3;return _this45.handleTool(y,g.arguments,_);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[E]===f?_this45.stopOnError(c[f].message):c[E]===it?_this45.stopOnError(c.message):c[E]==="response.audio_transcript.delta"||(c[E]==="response.audio_transcript.done"?c.transcript&&hn.onMessage(_this45._deepChat,_defineProperty(_defineProperty({},x,ne),h,c.transcript),!1):c[E]==="conversation.item.input_audio_transcription.completed"&&c.transcript&&hn.onMessage(_this45._deepChat,_defineProperty(_defineProperty({},x,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(Ze,"realtime"),{method:ye,body:a.sdp,headers:_defineProperty(_defineProperty({},he,"".concat(Ce).concat(e)),q,"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({},E,"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[f](_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
|
|
170
|
+
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){return _regenerator().w(function(_context90){while(1)switch(_context90.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context90.n=1;return V.request(this,e,this.messages,!0,!0);case 1:this._messageStream=_context90.v;case 2:return _context90.a(2);}},_callee90,this);}));function createStreamRun(_x184){return _createStreamRun.apply(this,arguments);}return createStreamRun;}()}],[{key:"processImageMessage",value:function processImageMessage(e,t){var n=t==null?void 0:t.filter(function(s){return 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(r){return{tools:[_defineProperty({},y,n)],file_id:r.id};}),content:[_defineProperty(_defineProperty({},y,h),h,e[h])]},S,F);}}]);}(M);Kt.POLLING_TIMEOUT_MS=500;var Ys=Kt;var pr=/*#__PURE__*/function(_Ys){function pr(e){var _a$headers,_c$OpenAIBeta;var _this38;_classCallCheck(this,pr);var o,a,c,l,d;var t=w(e.directConnection),n=t.openAI,s=(o=t.openAI)==null?void 0:o.assistant,r=pr.buildUrlSegments(s);if(_this38=_callSuper(this,pr,[e,s,r,Wn(),Kn,n]),(_a$headers=(a=_this38.connectSettings).headers)!==null&&_a$headers!==void 0?_a$headers:a.headers={},(_c$OpenAIBeta=(c=_this38.connectSettings.headers)["OpenAI-Beta"])!==null&&_c$OpenAIBeta!==void 0?_c$OpenAIBeta:c["OpenAI-Beta"]="assistants=v2",_this38.shouldFetchHistory&&_this38.sessionId&&(_this38.fetchHistory=_this38.fetchHistoryFunc.bind(_assertThisInitialized(_this38))),_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&&(_this38._functionHandlerI=u),g&&(_this38.filesToolType=g);}return _this38;}_inherits(pr,_Ys);return _createClass(pr,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"};}}]);}(Ys);var Js="Please define the Azure URL Details. [More Information](".concat(X,"directConnection/Azure)"),Mo=function Mo(i){return _defineProperty({"api-key":i},q,ee);},ko=function ko(i){return be("".concat(i.endpoint,"/openai/models?api-version=").concat(i.version),de,Io);},Lo=function Lo(i){var e=i.endpoint,t=i.version,n=i.deploymentId;return e&&t&&n;},Ln=/*#__PURE__*/function(_Ys2){function Ln(e){var _C$headers;var _this39;_classCallCheck(this,Ln);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,r=(s==null?void 0:s.urlDetails)||{},o="".concat((d=s==null?void 0:s.urlDetails)==null?void 0:d.endpoint,"/openai/"),a="?api-version=".concat((u=s==null?void 0:s.urlDetails)==null?void 0:u.version),c={threadsPrefix:"".concat(o).concat(Ln.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(Ln.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(_this39=_callSuper(this,Ln,[e,s==null?void 0:s.assistant,c,ko(r),Mo,n]),_this39.permittedErrorPrefixes=[Js],_this39.insertKeyPlaceholderText=_this39.genereteAPIKeyName("Azure OpenAI"),_this39.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",_this39.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,B=_ref85.function_handler,se=_ref85.files_tool_type;B&&(_this39._functionHandlerI=B),se&&(_this39.filesToolType=se);}Lo(r)?(_C$headers=(C=_this39.connectSettings).headers)!==null&&_C$headers!==void 0?_C$headers:C.headers={}:(_this39.isTextInputDisabled=!0,_this39.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,Js));}));return _this39;}_inherits(Ln,_Ys2);return _createClass(Ln);}(Ys);Ln.THREAD_RESOURCE="threads",Ln.NEW_ASSISTANT_RESOURCE="assistants";var Hi=Ln;var Sl="sts-session-started",xl="sts-session-stopped";var me=/*#__PURE__*/function(){function me(){_classCallCheck(this,me);}return _createClass(me,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){me.removeAriaBusy(e),me.removeAriaDisabled(e);}}]);}();var Po="<?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(Ft.createSVGElement(n)):n!==""&&s&&e.push(t);}},{key:"createCustomElements",value:function createCustomElements(e,t,n){var c,l;var s=n==null?void 0:n[e],r=(c=s==null?void 0:s[h])==null?void 0:c.content,o=(l=s==null?void 0:s[G])==null?void 0:l.content,a=[];return Ze.tryAddSVGElement(a,t,o,r),r&&a.push(Ze.createTextElement(r)),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 Ct=Ze;var ns=/*#__PURE__*/function(){function ns(){_classCallCheck(this,ns);}return _createClass(ns,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return _defineProperty(_defineProperty({},G,e.find(function(t){return t.tagName.toLowerCase()===G;})),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 r,o;t.container&&le.unsetAllCSSMouseStates(e,t.container);var _ns$parseSVGTextEleme=ns.parseSVGTextElements(Array.from(e.children)),n=_ns$parseSVGTextEleme.svg,s=_ns$parseSVGTextEleme.text;(r=t[G])!=null&&r[R]&&n&&le.unsetAllCSSMouseStates(n,t[G][R]),(o=t[h])!=null&&o[R]&&s&&le.unsetAllCSSMouseStates(s,t[h][R]);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var r,o;t.container&&le.unsetActivityCSSMouseStates(e,t.container);var _ns$parseSVGTextEleme2=ns.parseSVGTextElements(Array.from(e.children)),n=_ns$parseSVGTextEleme2.svg,s=_ns$parseSVGTextEleme2.text;(r=t[G])!=null&&r[R]&&n&&le.unsetActivityCSSMouseStates(n,t[G][R]),(o=t[h])!=null&&o[R]&&s&&le.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,r=_ns$parseSVGTextEleme3.text;s&&Object.assign(s[E],(c=(a=t[G])==null?void 0:a[R])==null?void 0:c[n]),r&&Object.assign(r[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,Y));}}]);}();var wn=/*#__PURE__*/function(){// prettier-ignore
|
|
171
|
+
function wn(e,t,n,s,r,o){_classCallCheck(this,wn);this._mouseState={state:"default"},this.isCustom=!1,me.addAttributes(e),this.elementRef=e,this[G]=Ft.createSVGElement(t),this.customStyles=r,this.position=ce.processPosition(n),this._tooltipSettings=s,this.dropupText=o;}return _createClass(wn,[{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&&bt.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=bt.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=Y,e&&xe.setElementsCSS(this.elementRef,e,Y);}// 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)),Ct.reassignClassBasedOnChildren(this.elementRef,e);}},{key:"buildDefaultIconElement",value:function buildDefaultIconElement(e){var t=this[G].cloneNode(!0);return t.id=e,[t];}},{key:"createInnerElements",value:function createInnerElements(e,t,n){var s=Ct.createCustomElements(t,this[G],n);if(s&&s.length>0){if(this.position===st){var r=s[0].cloneNode(!0);r.id=s[0]===this[G]?e:"dropup-menu-item-icon-element-custom",s[0]=r;}return s;}return this.buildDefaultIconElement(e);}}]);}();var di=/*#__PURE__*/function(_wn){function di(e){var _this40;_classCallCheck(this,di);var n,s;var t=((s=(n=e==null?void 0:e[A])==null?void 0:n[G])==null?void 0:s.content)||di.EMPTY_SVG;_this40=_callSuper(this,di,[x(),t,void 0,void 0,e]),_this40.isActive=!1,_this40._innerElements=_this40.createInnerElementsForStates(_this40.customStyles),_this40.changeToDefault();return _this40;}_inherits(di,_wn);return _createClass(di,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty(_defineProperty(_defineProperty({},A,this.createInnerButtonElements(A,e)),H,this.createInnerButtonElements(H,e)),$t,this.createInnerButtonElements($t,e));}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return Ct.createCustomElements(e,this[G],t)||[this[G]];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef[f].replace(Ct.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements[H]),this.reapplyStateStyle(H,[$t,A]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,n,s;this.changeState(this._innerElements[A]),(e=this.customStyles)!=null&&e[H]&&xe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[H]),(n=this.customStyles)!=null&&n[$t]&&xe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[$t]),this.reapplyStateStyle(A,[H,$t]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,n,s;this.changeState(this._innerElements[$t]),(e=this.customStyles)!=null&&e[H]&&xe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[H]),(n=this.customStyles)!=null&&n[A]&&xe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[A]),this.reapplyStateStyle($t,[A,H]),this.isActive=!1;}}]);}(wn);di.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var Qs=di;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 r=_objectSpread(_objectSpread({},s),Le.getObjectValue(e,n)||{});Le.setPropertyValue(e,n,r);}}},{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 No="<?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>",ji="<?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 _this41;_classCallCheck(this,J);var r,o,a,c,l;var t=w(e.directConnection),n=J.getKey(e);_this41=_callSuper(this,J,[e,Wn(),Kn,{key:n}]),_this41.insertKeyPlaceholderText=_this41.genereteAPIKeyName("OpenAI"),_this41.keyHelpUrl=Vn,_this41._microphoneButton=null,_this41._toggleButton=null,_this41._errorElement=null,_this41._loadingElement=null,_this41._pc=null,_this41._mediaStream=null,_this41._isMuted=!1;var s=(r=t.openAI)==null?void 0:r.realtime;if(_typeof(s)===U){_this41._avatarConfig=s.avatar,_this41._ephemeralKey=s.ephemeralKey,_this41._errorConfig=s[p],_this41._loadingConfig=s.loading,Object.assign(_this41.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&&(_this41._functionHandlerI=u),_this41._events=s.events,d.methods=_this41.generateMethods(),_this41.setInputAudioTranscribe(e,(c=d.config)==null?void 0:c.input_audio_transcription),delete _this41.rawBody.input_audio_transcription;}(_l$model=(l=_this41.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="gpt-realtime-2",_this41._avatarConfig=J.buildAvatarConfig(s),_this41._buttonsConfig=J.buildButtonsConfig(s),_this41._avatarEl=J.createAvatar(_this41._avatarConfig),_this41._containerEl=_this41.createContainer(),_this41._deepChat=e;return _this41;}_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
|
+
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({},q,ee),he,"".concat(Ce).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?Ui: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=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 _this43=this;var t;var e=new Qs((t=this._buttonsConfig)==null?void 0:t[pt]);return e.elementRef[f].add(J.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),z.assignButtonEvents(e.elementRef,function(){e.isActive?(_this43.toggleMicorphone(!0),e.elementRef[f].replace(J.MICROPHONE_ACTIVE,J.BUTTON_DEFAULT),e.changeToDefault(),_this43._isMuted=!1):(_this43.toggleMicorphone(!1),e.elementRef[f].replace(J.BUTTON_DEFAULT,J.MICROPHONE_ACTIVE),me.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(J.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),z.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($);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&&(me.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(Sl)),_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]===ct?_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({},he,"".concat(Ce).concat(e)),q,"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
|
|
173
176
|
// in such instance please wait and refresh at a later time
|
|
174
|
-
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this46=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,
|
|
175
|
-
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(e,t,n){var s,r;return _regenerator().w(function(_context98){while(1)switch(_context98.n){case 0:if(this._functionHandlerI){_context98.n=1;break;}throw Error(
|
|
176
|
-
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=
|
|
177
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e,t,n){var o,s,r;return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context101.n=1;break;}throw new Error(
|
|
178
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",
|
|
179
|
-
function
|
|
180
|
-
"Please define the azure endpoint. [More Information](".concat(
|
|
181
|
-
function
|
|
182
|
-
function
|
|
183
|
-
function
|
|
184
|
-
function
|
|
185
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this57.url="",_this57.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this57;}_inherits(
|
|
177
|
+
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this46=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),r=t.length*255,o=s/r*100,a=1,c=a+o/100*(((l=_this46._avatarConfig)==null?void 0:l.maxScale)-a);_this46._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(xl)),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),me.removeAriaDisabled(this._toggleButton.elementRef),me.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),me.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 _callee98(e,t,n){var s,r;return _regenerator().w(function(_context98){while(1)switch(_context98.n){case 0:if(this._functionHandlerI){_context98.n=1;break;}throw Error(Qt);case 1:_context98.n=2;return this._functionHandlerI({name:e,arguments:t});case 2:s=_context98.v;if(!(_typeof(s)!="object"||!Le.isJson(s))){_context98.n=3;break;}throw Error('The `function_handler` response must be a JSON object, e.g. {response: "My response"}');case 3:r=_defineProperty(_defineProperty(_defineProperty({},y,Ro),"call_id",n),"output",ae(s));this.sendMessage(r);case 4:return _context98.a(2);}},_callee98,this);}));function handleTool(_x190,_x191,_x192){return _handleTool.apply(this,arguments);}return handleTool;}()// https://platform.openai.com/docs/api-reference/realtime-client-events/conversation/item/create
|
|
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$pt,_o$A,_a$G,_c$content,_t$toggle,_g$A,_b$G,_$content,_v$H,_C$G,_B$content;var n,s,r,o,a,c,l,d,u,g,b,_,v,C,B;var t=_typeof(e)=="object"&&e.buttons?w(e.buttons):{};return(r=(s=(n=t[pt])==null?void 0:n[A])==null?void 0:s[h])!=null&&r.content||((_t$pt=t[pt])!==null&&_t$pt!==void 0?_t$pt:t[pt]={},(_o$A=(o=t[pt])[A])!==null&&_o$A!==void 0?_o$A:o[A]={},(_a$G=(a=t[pt][A])[G])!==null&&_a$G!==void 0?_a$G:a[G]={},(_c$content=(c=t[pt][A][G]).content)!==null&&_c$content!==void 0?_c$content:c.content=Po),(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$G=(b=t.toggle[A])[G])!==null&&_b$G!==void 0?_b$G:b[G]={},(_$content=(_=t.toggle[A][G]).content)!==null&&_$content!==void 0?_$content:_.content=No,(_v$H=(v=t.toggle)[H])!==null&&_v$H!==void 0?_v$H:v[H]={},(_C$G=(C=t.toggle[H])[G])!==null&&_C$G!==void 0?_C$G:C[G]={},(_B$content=(B=t.toggle[H][G]).content)!==null&&_B$content!==void 0?_B$content:B.content=ji),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[K]),t[T]=(e==null?void 0:e[T])||Bi,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),me.removeAriaBusy(e.elementRef),me.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){J.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){me.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 $i=J;var Pn=/*#__PURE__*/function(_M7){function Pn(e){var _o$model3,_a$voice3;var _this47;_classCallCheck(this,Pn);var r,o,a;var t=w(e.directConnection),n=t==null?void 0:t.openAI;_this47=_callSuper(this,Pn,[e,Wn(),Kn,n]),_this47.insertKeyPlaceholderText=_this47.genereteAPIKeyName("OpenAI"),_this47.keyHelpUrl=Vn,_this47.url="".concat(Qe,"audio/speech"),_this47.permittedErrorPrefixes=[en];var s=(r=t==null?void 0:t.openAI)==null?void 0:r.textToSpeech;_typeof(s)===U&&Object.assign(_this47.rawBody,s),(_o$model3=(o=_this47.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=Pn.DEFAULT_MODEL,(_a$voice3=(a=_this47.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=Pn.DEFAULT_VOIDE,_this47.textInputPlaceholderText="Insert text to generate audio",_this47.rawBody.response_format="mp3";return _this47;}_inherits(Pn,_M7);return _createClass(Pn,[{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=w(e),s=(o=(r=t[t[W]-1])==null?void 0:r[h])==null?void 0:o.trim();return s&&s!==""&&(n.input=s),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t){return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:this.url=this.connectSettings.url||this.url,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context99.a(2);}},_callee99,this);}));function callServiceAPI(_x193,_x194){return _callServiceAPI10.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee100(e){return _regenerator().w(function(_context100){while(1)switch(_context100.n){case 0:if(!(e instanceof Blob)){_context100.n=1;break;}return _context100.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,$)]));};}));case 1:if(!e[p]){_context100.n=2;break;}throw e[p].message;case 2:return _context100.a(2,_defineProperty({},p,p));}},_callee100);}));function extractResultData(_x195){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(M);Pn.DEFAULT_MODEL="tts-1",Pn.DEFAULT_VOIDE="alloy";var qi=Pn;var ht=/*#__PURE__*/function(_M8){function ht(e){var _o$model4;var _this48;_classCallCheck(this,ht);var r,o;var t=w(e.directConnection),n=t==null?void 0:t.openAI;_this48=_callSuper(this,ht,[e,Wn(),Kn,n,{audio:{}}]),_this48.insertKeyPlaceholderText=_this48.genereteAPIKeyName("OpenAI"),_this48.keyHelpUrl=Vn,_this48.url="",_this48.permittedErrorPrefixes=[en],_this48.textInputPlaceholderText=rr,_this48._service_url=ht.AUDIO_TRANSCRIPTIONS_URL;var s=(r=t==null?void 0:t.openAI)==null?void 0:r[$];_typeof(s)=="object"&&(_this48.processConfig(s),ht.cleanConfig(s),Object.assign(_this48.rawBody,s)),(_o$model4=(o=_this48.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=ht.DEFAULT_MODEL,_this48.rawBody.response_format="json",_this48.canSendMessage=ht.canSendFileMessage;return _this48;}_inherits(ht,_M8);return _createClass(ht,[{key:"processConfig",value:function processConfig(e){e!=null&&e[y]&&e[y]==="translation"&&(this._service_url=ht.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=w(e),s=(o=(r=t[t[W]-1])==null?void 0:r[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 _callee101(e,t,n){var o,s,r;return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context101.n=1;break;}throw new Error(je);case 1:if(n!=null&&n[0]){_context101.n=2;break;}throw new Error(pi);case 2:this.url=this.connectSettings.url||this._service_url;s=this.preprocessBody(this.rawBody,t),r=ht.createFormDataBody(s,n[0]);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,r,e),!1);case 3:return _context101.a(2);}},_callee101,this);}));function callServiceAPI(_x196,_x197,_x198){return _callServiceAPI11.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(e){return _regenerator().w(function(_context102){while(1)switch(_context102.n){case 0:if(!e[p]){_context102.n=1;break;}throw e[p].message;case 1:return _context102.a(2,_defineProperty({},h,e[h]));}},_callee102);}));function extractResultData(_x199){return _extractResultData14.apply(this,arguments);}return extractResultData;}()}],[{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e[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);ht.AUDIO_TRANSCRIPTIONS_URL="".concat(Qe,"audio/transcriptions"),ht.AUDIO_TRANSLATIONS_URL="".concat(Qe,"audio/translations"),ht.DEFAULT_MODEL="whisper-1";var Gi=ht;var Xn="Ocp-Apim-Subscription-Key",Bo=// 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",Al=function Al(i,e){return _defineProperty(_defineProperty(_defineProperty({},Xn,e),q,"application/ssml+xml"),"X-Microsoft-OutputFormat",i);},wl=function wl(i){return _defineProperty(_defineProperty({},Xn,i),"Accept",ee);},Cl=function Cl(i,e,t,n){i[p]?n(ue):t(e);},Tl=function Tl(i){return{url:"https://".concat(i,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:ye,createHeaders:function createHeaders(e){return _defineProperty({},Xn,"".concat(e));},handleVerificationResult:Cl};},Rl=function Rl(i){return _defineProperty(_defineProperty({},Xn,i),q,ee);},Il=function Il(i,e,t,n){var r;((r=i[p])==null?void 0:r.code)==="401"?n(ue):t(e);},Ml=function Ml(i){return{url:"".concat(i,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:ye,createHeaders:function createHeaders(e){return _defineProperty({},Xn,"".concat(e));},handleVerificationResult:Il};},kl=function kl(i,e,t,n){i.json().then(function(r){!Array.isArray(r)&&r[p].code===401e3?n(ue):t(e);});},Ll=function Ll(i){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:ye,createHeaders:function createHeaders(e){return Oo(i,e);},handleVerificationResult:kl};},Oo=function Oo(i,e){var t=_defineProperty(_defineProperty({},Xn,e),q,ee);return i&&(t["Ocp-Apim-Subscription-Region"]=i),t;};var Pl=/*#__PURE__*/function(_M9){// prettier-ignore
|
|
182
|
+
function Pl(e,t,n,s,r){var _this49;_classCallCheck(this,Pl);_this49=_callSuper(this,Pl,[e,Ml(n),t,s,r]),_this49.insertKeyPlaceholderText="Azure Language Subscription Key",_this49.keyHelpUrl=Bo,_this49.permittedErrorPrefixes=["Access"];return _this49;}_inherits(Pl,_M9);return _createClass(Pl);}(M);var ls=/*#__PURE__*/function(_Pl){function ls(e){var _a$language;var _this50;_classCallCheck(this,ls);var s,r,o,a;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.summarization,n=(o=e.directConnection)==null?void 0:o.azure;_this50=_callSuper(this,ls,[e,Rl,t.endpoint,n]),_this50.permittedErrorPrefixes=[ls.ENDPOINT_ERROR_MESSAGE],_this50.url="",_this50.textInputPlaceholderText="Insert text to summarize",_this50.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this50.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this50.rawBody,t),_this50.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this50.isTextInputDisabled=!0,_this50.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,ls.ENDPOINT_ERROR_MESSAGE));}));return _this50;}_inherits(ls,_Pl);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 _callee103(e,t){return _regenerator().w(function(_context103){while(1)switch(_context103.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)),this.messages=e;case 1:return _context103.a(2);}},_callee103,this);}));function callServiceAPI(_x200,_x201){return _callServiceAPI12.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(e){var t,_n6,s;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:if(this.messages&&this.completionsHandlers){this.asyncCallInProgress=!0;_n6=e.headers.get("operation-location"),s={method:de,headers:(t=this.connectSettings)==null?void 0:t.headers};ge.executePollRequest(this,_n6,s,this.messages);}return _context104.a(2,_defineProperty({},h,""));}},_callee104,this);}));function extractResultData(_x202){return _extractResultData15.apply(this,arguments);}return extractResultData;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e){var t,_iterator,_step,_n7;return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:if(!e[p]){_context105.n=1;break;}throw e[p];case 1:if(!(e.status==="running"||e.status==="notStarted")){_context105.n=2;break;}return _context105.a(2,{timeoutMS:2e3});case 2:if(!(e.errors.length>0)){_context105.n=3;break;}throw e.errors[0];case 3:if(!(e.tasks.items[0].results.errors.length>0)){_context105.n=4;break;}throw e.tasks.items[0].results.errors[0];case 4:t="";_iterator=_createForOfIteratorHelper(e.tasks.items[0].results.documents[0].sentences);try{for(_iterator.s();!(_step=_iterator.n()).done;){_n7=_step.value;t+=_n7[h];}}catch(err){_iterator.e(err);}finally{_iterator.f();}return _context105.a(2,_defineProperty({},h,t||""));}},_callee105);}));function extractPollResultData(_x203){return _extractPollResultData5.apply(this,arguments);}return extractPollResultData;}()}]);}(Pl);ls.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
|
183
|
+
"Please define the azure endpoint. [More Information](".concat(X,"directConnection/Azure#Summarization)");var zi=ls;var Nl=/*#__PURE__*/function(){var _ref104=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(i,e){var t,o,a,l,_t46;return _regenerator().w(function(_context106){while(1)switch(_context106.n){case 0:t=_defineProperty(_defineProperty({},ca,i),la,ee);_t46="https://api.assemblyai.com/v2/transcript/";_context106.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:ye,body:ae({audio_url:e}),headers:t});case 1:_context106.n=2;return _context106.v.json();case 2:o=_t46.concat.call(_t46,_context106.v.id);case 3:if(a){_context106.n=9;break;}_context106.n=4;return fetch(o,{headers:t});case 4:_context106.n=5;return _context106.v.json();case 5:l=_context106.v;if(!(l.status===ir)){_context106.n=6;break;}a=l;_context106.n=8;break;case 6:if(!(l.status===p)){_context106.n=7;break;}throw new Error("Transcription failed: ".concat(l[p]));case 7:_context106.n=8;return new Promise(function(d){return setTimeout(d,3e3);});case 8:_context106.n=3;break;case 9:return _context106.a(2,a);}},_callee106);}));return function Nl(_x204,_x205){return _ref104.apply(this,arguments);};}(),Bl=function Bl(i){return _defineProperty(_defineProperty({},he,i),q,"application/octet-stream");},Ol=function Ol(i,e,t,n){var s=i;s[p]?s[p].code==="invalid_api_key"?n(ue):n(He):t(e);},Dl=function Dl(){return be("https://api.assemblyai.com/v2/upload",ye,Ol);};var fr=/*#__PURE__*/function(_M0){function fr(e){var _this51;_classCallCheck(this,fr);var n;var t=(n=e.directConnection)==null?void 0:n.assemblyAI;_this51=_callSuper(this,fr,[e,Dl(),Bl,t,{audio:{}}]),_this51.insertKeyPlaceholderText=_this51.genereteAPIKeyName("AssemblyAI"),_this51.keyHelpUrl="https://www.assemblyai.com/app/account",_this51.url="https://api.assemblyai.com/v2/upload",_this51.isTextInputDisabled=!0,_this51.textInputPlaceholderText=rr,_this51.permittedErrorPrefixes=[go,en],_this51.canSendMessage=fr.canFileSendMessage;return _this51;}_inherits(fr,_M0);return _createClass(fr,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(e,t,n){var s;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context107.n=1;break;}throw new Error(je);case 1:if(n!=null&&n[0]){_context107.n=2;break;}throw new Error(pi);case 2:ge.request(this,n[0],e,!1);case 3:return _context107.a(2);}},_callee107,this);}));function callServiceAPI(_x206,_x207,_x208){return _callServiceAPI13.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(e){var s,r,t,n;return _regenerator().w(function(_context108){while(1)switch(_context108.n){case 0:if(!e[p]){_context108.n=1;break;}throw e[p];case 1:t=(r=(s=this.connectSettings)==null?void 0:s.headers)==null?void 0:r[he];_context108.n=2;return Nl(t,e.upload_url);case 2:n=_context108.v;return _context108.a(2,_defineProperty({},h,n[h]));}},_callee108,this);}));function extractResultData(_x209){return _extractResultData16.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(M);var ei=/*#__PURE__*/function(_M1){// prettier-ignore
|
|
184
|
+
function ei(e,t,n,s,r){var _this52$maxMessages,_g$model;var _this52;_classCallCheck(this,ei);var u,g;var o=w(e.directConnection),a=t||Wn(),c=n||Kn,l=s||o.openAI;_this52=_callSuper(this,ei,[e,a,c,l]),_this52.insertKeyPlaceholderText=_this52.genereteAPIKeyName("OpenAI"),_this52.keyHelpUrl="https://platform.openai.com/account/api-keys",_this52.permittedErrorPrefixes=[ws,"Invalid value"];var d=r||((u=o.openAI)==null?void 0:u.chat);_typeof(d)===U&&_this52.processConfig(d,e),(_this52$maxMessages=_this52.maxMessages)!==null&&_this52$maxMessages!==void 0?_this52$maxMessages:_this52.maxMessages=-1,(_g$model=(g=_this52.rawBody).model)!==null&&_g$model!==void 0?_g$model:g.model="gpt-4o";return _this52;}_inherits(ei,_M1);return _createClass(ei,[{key:"processConfig",value:function processConfig(e,t){var n,s,r;this.completeConfig(e,(r=(s=(n=t.directConnection)==null?void 0:n.openAI)==null?void 0:s.chat)==null?void 0:r.function_handler);}}],[{key:"getBaseFileContent",value:function getBaseFileContent(e){return e.map(function(t){var n,s,r;if(t[y]===$){var o=(n=t[T])==null?void 0:n.split(",")[1],a=((r=(s=t.name)==null?void 0:s.split(".").pop())==null?void 0:r.toLowerCase())||"wav";return _defineProperty(_defineProperty({},y,pn),pn,{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][W]>0){var s=this.getBaseFileContent(e[m]);return e[h]&&e[h].trim()[W]>0&&s.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),s;}return e[h];}}]);}(M);var ti=/*#__PURE__*/function(_ei){function ti(){var _this53;_classCallCheck(this,ti);_this53=_callSuper(this,ti,arguments),_this53.url="".concat(Qe,"chat/completions");return _this53;}_inherits(ti,_ei);return _createClass(ti,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:ti.getContent(r)},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e,t){var _this$messages;return _regenerator().w(function(_context109){while(1)switch(_context109.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 _context109.a(2);}},_callee109,this);}));function callServiceAPI(_x210,_x211){return _callServiceAPI14.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:if(!e[p]){_context110.n=1;break;}throw e[p].message;case 1:if(!((s=(n=e.choices)==null?void 0:n[0])!=null&&s.delta)){_context110.n=2;break;}return _context110.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(r=e.choices)==null?void 0:r[0])!=null&&o.message)){_context110.n=5;break;}if(!e.choices[0].message.tool_calls){_context110.n=3;break;}return _context110.a(2,this.handleToolsGeneric(e.choices[0].message,this.functionHandler,this.messages,t));case 3:if(!((a=e.choices[0].message)!=null&&a[$])){_context110.n=4;break;}l=this.deepChat.textToSpeech,d=_typeof(l)=="object"&&typeof((c=l==null?void 0:l[$])==null?void 0:c.displayText)=="boolean";return _context110.a(2,_defineProperty(_defineProperty({},m,[_defineProperty(_defineProperty({},T,"data:audio/wav;base64,".concat(e.choices[0].message[$].data)),y,$)]),h,d?e.choices[0].message[$].transcript:void 0));case 4:return _context110.a(2,_defineProperty({},h,e.choices[0].message.content));case 5:return _context110.a(2,_defineProperty({},h,""));}},_callee110,this);}));function extractResultData(_x212,_x213){return _extractResultData17.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e,t){return _regenerator().w(function(_context111){while(1)switch(_context111.n){case 0:return _context111.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee111,this);}));function extractStreamResult(_x214,_x215){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return ei.getBaseFileContent(e).map(function(n){return n[y]===pn?n:_defineProperty(_defineProperty({},y,ze),ze,{url:n[T]});});}},{key:"getContent",value:function getContent(e){if(e[m]&&e[m][W]>0){var t=ti.getFileContent(e[m]);return e[h]&&e[h].trim()[W]>0&&t.unshift(_defineProperty(_defineProperty({},y,h),h,e[h])),t;}return e[h];}}]);}(ei);var Cr=/*#__PURE__*/function(_M10){// prettier-ignore
|
|
185
|
+
function Cr(e,t,n,s,r){var _this54;_classCallCheck(this,Cr);_this54=_callSuper(this,Cr,[e,Tl(n),t,s,r]),_this54.insertKeyPlaceholderText="Azure Speech Subscription Key",_this54.keyHelpUrl=Bo;return _this54;}_inherits(Cr,_M10);return _createClass(Cr);}(M);Cr.REGION_ERROR_PREFIX="Please define a region config property. [More Information](".concat(X,"directConnection/Azure#");var qn=Cr;var hs=/*#__PURE__*/function(_qn){// prettier-ignore
|
|
186
|
+
function hs(e){var _a$lang,_c$name,_l$gender;var _this55;_classCallCheck(this,hs);var s,r,o,a,c,l;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.textToSpeech,n=(o=e.directConnection)==null?void 0:o.azure;_this55=_callSuper(this,hs,[e,Al.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,n]),_this55.permittedErrorPrefixes=[hs.REGION_ERROR_MESSAGE],_this55.isTextInputDisabled=!1,_this55.url="",t.region?(Object.assign(_this55.rawBody,t),(_a$lang=(a=_this55.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_c$name=(c=_this55.rawBody).name)!==null&&_c$name!==void 0?_c$name:c.name="en-US-JennyNeural",(_l$gender=(l=_this55.rawBody).gender)!==null&&_l$gender!==void 0?_l$gender:l.gender="Female",_this55.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this55.isTextInputDisabled=!0,_this55.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,hs.REGION_ERROR_MESSAGE));}));return _this55;}_inherits(hs,_qn);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 _callee112(e,t){return _regenerator().w(function(_context112){while(1)switch(_context112.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),void 0,!1);case 1:return _context112.a(2);}},_callee112,this);}));function callServiceAPI(_x216,_x217){return _callServiceAPI15.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113(e){return _regenerator().w(function(_context113){while(1)switch(_context113.n){case 0:return _context113.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,$)]));};}));}},_callee113);}));function extractResultData(_x218){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}]);}(qn);hs.REGION_ERROR_MESSAGE="".concat(qn.REGION_ERROR_PREFIX,"TextToSpeech)");var Vi=hs;var Nn=/*#__PURE__*/function(_qn2){function Nn(e){var _this56;_classCallCheck(this,Nn);var r,o,a;var t=(o=(r=e.directConnection)==null?void 0:r.azure)==null?void 0:o.speechToText,n=(a=e.directConnection)==null?void 0:a.azure,s={audio:_defineProperty({},m,{acceptedFormats:".wav,.ogg"})};if(_this56=_callSuper(this,Nn,[e,wl,t.region,n,s]),_this56.permittedErrorPrefixes=[Nn.REGION_ERROR_MESSAGE],_this56.url="",_this56.isTextInputDisabled=!0,_this56.textInputPlaceholderText=rr,!t.region)_this56.isTextInputDisabled=!0,_this56.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,Nn.REGION_ERROR_MESSAGE));});else{_this56.canSendMessage=Nn.canFileSendMessage;var c=t.lang||"en-US";_this56.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(c,"&format=detailed"),_this56.recordAudio=void 0;}return _this56;}_inherits(Nn,_qn2);return _createClass(Nn,[{key:"callServiceAPI",value:function(){var _callServiceAPI16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee114(e,t,n){var s,r;return _regenerator().w(function(_context114){while(1)switch(_context114.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context114.n=1;break;}throw new Error(je);case 1:if(n!=null&&n[0]){_context114.n=2;break;}throw new Error(pi);case 2:(r=this.connectSettings)!=null&&r.headers&&(this.connectSettings.headers[q]=n[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),ge.request(this,n[0],e,!1);case 3:return _context114.a(2);}},_callee114,this);}));function callServiceAPI(_x219,_x220,_x221){return _callServiceAPI16.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(e){return _regenerator().w(function(_context115){while(1)switch(_context115.n){case 0:if(!e[p]){_context115.n=1;break;}throw e[p];case 1:return _context115.a(2,_defineProperty({},h,e.DisplayText||""));}},_callee115);}));function extractResultData(_x222){return _extractResultData19.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(qn);Nn.REGION_ERROR_MESSAGE="".concat(qn.REGION_ERROR_PREFIX,"SpeechToText)");var Ki=Nn;var Fl=/*#__PURE__*/function(_M11){// prettier-ignore
|
|
187
|
+
function Fl(e){var _this57;_classCallCheck(this,Fl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.translation,n=(o=e.directConnection)==null?void 0:o.azure;_this57=_callSuper(this,Fl,[e,Ll(t.region),Oo.bind({},t==null?void 0:t.region),n]),_this57.insertKeyPlaceholderText="Azure Translate Subscription Key",_this57.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",_this57.url="",_this57.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this57;}_inherits(Fl,_M11);return _createClass(Fl,[{key:"preprocessBody",value:function preprocessBody(e){var t=e[e.length-1][h];if(t)return[{Text:t}];}},{key:"callServiceAPI",value:function(){var _callServiceAPI17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee116(e,t){return _regenerator().w(function(_context116){while(1)switch(_context116.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context116.a(2);}},_callee116,this);}));function callServiceAPI(_x223,_x224){return _callServiceAPI17.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee117(e){var t;return _regenerator().w(function(_context117){while(1)switch(_context117.n){case 0:if(!Array.isArray(e)){_context117.n=1;break;}return _context117.a(2,_defineProperty({},h,((t=e[0].translations)==null?void 0:t[0][h])||""));case 1:throw e[p];case 2:return _context117.a(2);}},_callee117);}));function extractResultData(_x225){return _extractResultData20.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ul=/*#__PURE__*/function(_M12){function Ul(e){var _o$model5;var _this58;_classCallCheck(this,Ul);var r,o;var t=w(e.directConnection),n=t.bigModel;_this58=_callSuper(this,Ul,[e,hr(),lr,n]),_this58.insertKeyPlaceholderText=_this58.genereteAPIKeyName("BigModel"),_this58.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this58.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this58.permittedErrorPrefixes=[he,Te];var s=(r=t.bigModel)==null?void 0:r[Q];_typeof(s)===U&&(_this58.cleanConfig(s),Object.assign(_this58.rawBody,s)),(_o$model5=(o=_this58.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this58;}_inherits(Ul,_M12);return _createClass(Ul,[{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 _callee118(e,t){return _regenerator().w(function(_context118){while(1)switch(_context118.n){case 0:return _context118.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee118,this);}));function callServiceAPI(_x226,_x227){return _callServiceAPI18.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e){var t;return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:t=e.data.map(function(n){return n!=null&&n.url?_defineProperty(_defineProperty({},T,n.url),y,K):_defineProperty(_defineProperty({},T,""),y,K);});return _context119.a(2,_defineProperty({},m,t));}},_callee119);}));function extractResultData(_x228){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(M);var Do=function Do(i){return _defineProperty(_defineProperty({},q,ee),he,"".concat(Ce).concat(i));},Hl=function Hl(i,e,t,n){var s=i;s[p]?s[p].message===fi?n(ue):n(He):t(e);},Fo=function Fo(){return be("https://api.groq.com/openai/v1/models",de,Hl);};var jl=/*#__PURE__*/function(_M13){function jl(e){var _o$model6,_a$voice4,_c$response_format;var _this59;_classCallCheck(this,jl);var r,o,a,c;var t=w(e.directConnection),n=t.groq;_this59=_callSuper(this,jl,[e,Fo(),Do,n]),_this59.insertKeyPlaceholderText=_this59.genereteAPIKeyName("Groq"),_this59.keyHelpUrl="https://console.groq.com/keys",_this59.url="https://api.groq.com/openai/v1/audio/speech",_this59.permittedErrorPrefixes=[en,"property"];var s=(r=t.groq)==null?void 0:r.textToSpeech;_typeof(s)===U&&_this59.completeConfig(s),(_o$model6=(o=_this59.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this59.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_c$response_format=(c=_this59.rawBody).response_format)!==null&&_c$response_format!==void 0?_c$response_format:c.response_format="mp3";return _this59;}_inherits(jl,_M13);return _createClass(jl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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(_x229,_x230){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e){var t,n,s;return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:t=this.rawBody.response_format||"mp3",n=new Blob([e],_defineProperty({},y,"audio/".concat(t))),s=URL.createObjectURL(n);return _context121.a(2,_defineProperty({},m,[_defineProperty(_defineProperty({},T,s),y,$)]));}},_callee121,this);}));function extractResultData(_x231){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(M);var $l=/*#__PURE__*/function(_M14){function $l(e){var _o$model7;var _this60;_classCallCheck(this,$l);var r,o;var t=w(e.directConnection),n=t.together;_this60=_callSuper(this,$l,[e,ur(),dr,n]),_this60.insertKeyPlaceholderText=_this60.genereteAPIKeyName("Together AI"),_this60.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this60.url="https://api.together.xyz/v1/images/generations",_this60.permittedErrorPrefixes=[ct,Te];var s=(r=t.together)==null?void 0:r[Q];_typeof(s)===U&&_this60.completeConfig(s),(_o$model7=(o=_this60.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this60;}_inherits($l,_M14);return _createClass($l,[{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 _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(_x232,_x233){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e){var t;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:t=e.data.map(function(n){return n!=null&&n.url?_defineProperty(_defineProperty({},T,n.url),y,K):n!=null&&n.b64_json?_defineProperty(_defineProperty({},T,"data:image/png;base64,".concat(n.b64_json)),y,K):_defineProperty(_defineProperty({},T,""),y,K);});return _context123.a(2,_defineProperty({},m,t));}},_callee123);}));function extractResultData(_x234){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ye=/*#__PURE__*/function(_ei2){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
|
|
186
189
|
// prettier-ignore
|
|
187
|
-
function Xe(e,t,n,s,r){var _this61;_classCallCheck(this,Xe);var a,c;_this61=_callSuper(this,Xe,[e,t,n,s,r]),_this61.keyHelpUrl=Nn,_this61.url="".concat(Ze,"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=Xe.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(Xe,_ii2);return _createClass(Xe,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Xe,"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 $t(this,{},ue);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({},f,Uo)]));}},_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(Xe.filterCompleted(e.data.reverse())),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _n9=_step2.value;if(_n9[E]==="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[E]===zi||s[E]===so)&&s[h]?t.push(_defineProperty(_defineProperty({},x,_n9[x]),h,s[h])):s[E]===no&&t.push(_defineProperty(_defineProperty({},x,_n9[x]),b,Xe.generateImageFile(s[qe]||"")));}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}else _n9[E]===Ni&&t.push(_defineProperty(_defineProperty({},x,ne),b,Xe.generateImageFile(_n9.result)));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e);t=this.processMessages(t),t=this._useConversation?[t[t[X]-1]]:t;var s=t.map(function(r){return _defineProperty({content:Xe.getContent(r)},x,k.getRoleViaUser(r[x]));});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 $t(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[f]("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[f]){_context128.n=1;break;}throw e[f].message;case 1:if(!e.status){_context128.n=5;break;}a=Xe.filterCompleted(e.output);if(!(a[X]>0)){_context128.n=4;break;}c=(r=(s=(n=a.find(function(p){var u,g;return _typeof((g=(u=p.content)==null?void 0:u[0])==null?void 0:g[h])===Ee;}))==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[E])===$s&&e[E]?this.handleStreamedResponsesFunctionCall(e,t):e[E]==="".concat(Hn,".").concat(Ni,".partial_image")&&e.partial_image_b64?_defineProperty({},b,[_defineProperty(_defineProperty({},T,"".concat(Xe.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),E,W)]):e.delta&&!this._functionStreamInProgress&&e[E]==="".concat(Hn,".").concat(so,".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[E]==="".concat(Hn,".output_item.done"))){_context129.n=2;break;}if(!(this._functionStreamInProgress=!1,((n=e.item)==null?void 0:n[E])===$s)){_context129.n=1;break;}return _context129.a(2,this.handleResponsesFunctionCalls([e.item],t));case 1:_context129.n=3;break;case 2:e[E]==="".concat(Hn,".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[E]===Ni;});return n?_defineProperty(_defineProperty({},b,Xe.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[E]===$s;});if(!(s[X]===0)){_context130.n=1;break;}return _context130.a(2,null);case 1:if(!(!t||!this.functionHandler)){_context130.n=2;break;}throw Error(Gt);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=C(t);if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref137){var l=_ref137.response;return _typeof(l)!==Ee;})&&r[X]===o[X]))){_context130.n=5;break;}return _context130.a(2,(o.forEach(function(l,d){var p=s[d];c.input.push(_defineProperty(_defineProperty(_defineProperty({},E,Jo),"call_id",p.call_id),"output",l[Hn]));}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(an);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)||Ze;return{responsesUrl:"".concat(t,"responses"),conversationsUrl:"".concat(t,"conversations")};}},{key:"getFileContent",value:function getFileContent(e){return ii.getBaseFileContent(e).map(function(n){return n[E]===sn?n:_defineProperty(_defineProperty({detail:"auto"},E,no),qe,n[T]);});}},{key:"getContent",value:function getContent(e){if(e[x]===F&&e[b]&&e[b][X]>0){var _n0=Xe.getFileContent(e[b]);return e[h]&&e[h].trim()[X]>0&&_n0.unshift(_defineProperty(_defineProperty({},E,zi),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===cr;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},T,"".concat(Xe.IMAGE_BASE64_PREFIX).concat(e)),E,W)];}}]);}(ii);Xe.IMAGE_BASE64_PREFIX="data:image/png;base64,";var oi=Xe;var _r=/*#__PURE__*/function(_oi){function _r(e){var _this63;_classCallCheck(this,_r);var o,a,c,l,d,p,u;var t=C(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,_r,[e,ta(s),ea,n,r]),_this63.permittedErrorPrefixes=[ni],_this63.isTextInputDisabled=!1,_typeof(r)===U){var _ref140=(u=(p=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:p.openAI)==null?void 0:u.chat,g=_ref140.function_handler;g&&(_this63.functionHandler=g);}na(s)?_this63.url=_r.buildURL(s):(_this63.isTextInputDisabled=!0,_this63.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,ni));}));return _this63;}_inherits(_r,_oi);return _createClass(_r,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);}}]);}(oi);var ai=/*#__PURE__*/function(_k15){function ai(e){var _this64$maxMessages,_l$model2;var _this64;_classCallCheck(this,ai);var r,o,a,c,l;var t=C(e.directConnection),n=t.bigModel;_this64=_callSuper(this,ai,[e,fr(),pr,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=[he,Te];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(ai,_k15);return _createClass(ai,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:ai.getTextWFilesContent(r,ai.getFileContent)},x,k.getRoleViaAI(r[x]));});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[f]){_context132.n=1;break;}throw e[f].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][x])===ne&&((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[E]===W?_defineProperty(_defineProperty({},E,qe),qe,{url:t[T]||""}):_defineProperty(_defineProperty({},E,se),"file_url",{url:t[T]||""});});}}]);}(k);var pd=/*#__PURE__*/function(_k16){function pd(e){var _this65$maxMessages,_o$model8;var _this65;_classCallCheck(this,pd);var r,o;var t=C(e.directConnection),n=t.together;_this65=_callSuper(this,pd,[e,gr(),mr,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=[it,Te];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(pd,_k16);return _createClass(pd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,r[x]===ne?gt:r[x]);});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[f]){_context135.n=1;break;}throw e[f].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;}()}]);}(k);var ot=/*#__PURE__*/function(_k17){function ot(e){var _this66;_classCallCheck(this,ot);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},b,{acceptedFormats:".png",maxNumberOfFiles:2})};_this66=_callSuper(this,ot,[e,Dn(),Bn,n,s]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("OpenAI"),_this66.keyHelpUrl=Nn,_this66.url="",_this66.permittedErrorPrefixes=[Ps,"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][b]={dimensions:{width:a,height:a}};}_typeof(r)===U&&Object.assign(_this66.rawBody,r),_this66.canSendMessage=ot.canFileSendMessage;return _this66;}_inherits(ot,_k17);return _createClass(ot,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e);return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
|
|
188
|
-
},{key:"callApiWithImage",value:function callApiWithImage(e,t,n){var o,a;var s;var r=(a=(o=t[t[
|
|
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=Vn,_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,{},de);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,mo)]));}},_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]===Ui||s[y]===Jr)&&s[h]?t.push(_defineProperty(_defineProperty({},S,_n9[S]),h,s[h])):s[y]===Yr&&t.push(_defineProperty(_defineProperty({},S,_n9[S]),m,Ye.generateImageFile(s[ze]||"")));}}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(Jr,".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,Ro),"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,Yr),ze,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,Ui),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===ir;}))||[];}},{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 mr=/*#__PURE__*/function(_ni){function mr(e){var _this63;_classCallCheck(this,mr);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,mr,[e,ko(s),Mo,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);}Lo(s)?_this63.url=mr.buildURL(s):(_this63.isTextInputDisabled=!0,_this63.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},p,Js));}));return _this63;}_inherits(mr,_ni);return _createClass(mr,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,hr(),lr,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=[he,Te];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,ze),ze,{url:t[T]||""}):_defineProperty(_defineProperty({},y,ne),"file_url",{url:t[T]||""});});}}]);}(M);var ql=/*#__PURE__*/function(_M16){function ql(e){var _this65$maxMessages,_o$model8;var _this65;_classCallCheck(this,ql);var r,o;var t=w(e.directConnection),n=t.together;_this65=_callSuper(this,ql,[e,ur(),dr,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=[ct,Te];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(ql,_M16);return _createClass(ql,[{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=Vn,_this66.url="",_this66.permittedErrorPrefixes=[ws,"Invalid input image"];var r=(o=t==null?void 0:t.openAI)==null?void 0:o[Q];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 r=(a=(o=t[t[W]-1])==null?void 0:o[h])==null?void 0:a.trim();if(n[1]||r&&r!==""){this.url=dt.IMAGE_EDIT_URL;var c=this.preprocessBody(this.rawBody,r);s=dt.createFormDataBody(c,n[0],n[1]);}else this.url=dt.IMAGE_VARIATIONS_URL,s=dt.createFormDataBody(this.rawBody,n[0]);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,s,e),!1);}},{key:"callServiceAPI",value:function(){var _callServiceAPI24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e,t,n){var s,r;return _regenerator().w(function(_context136){while(1)switch(_context136.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context136.n=1;break;}throw new Error(je);case 1:if(!(n!=null&&n[0])){_context136.n=2;break;}this.callApiWithImage(e,t,n);_context136.n=4;break;case 2:if(this.connectSettings){_context136.n=3;break;}throw new Error(je);case 3:this.url=dt.IMAGE_GENERATION_URL;r=this.preprocessBody(this.rawBody,t[t[W]-1][h]);ge.request(this,r,e);case 4:return _context136.a(2);}},_callee136,this);}));function callServiceAPI(_x255,_x256,_x257){return _callServiceAPI24.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e){var t;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:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},T,n.url),y,K):_defineProperty(_defineProperty({},T,"".concat(zn).concat(n.b64_json)),y,K);});return _context137.a(2,_defineProperty({},m,t));}},_callee137);}));function extractResultData(_x258){return _extractResultData27.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
|
|
189
192
|
// 1 image:
|
|
190
193
|
// - With text - edits image based on the text
|
|
191
194
|
// - No text - creates a variation of the image
|
|
@@ -194,35 +197,35 @@ function Xe(e,t,n,s,r){var _this61;_classCallCheck(this,Xe);var a,c;_this61=_cal
|
|
|
194
197
|
// Add text to describe the required modification.
|
|
195
198
|
// Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
|
|
196
199
|
// `;
|
|
197
|
-
}],[{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(r){s.append(r,String(e[r]));}),s;}}]);}(k);ot.IMAGE_GENERATION_URL="".concat(Ze,"images/generations"),ot.IMAGE_VARIATIONS_URL="".concat(Ze,"images/variations"),ot.IMAGE_EDIT_URL="".concat(Ze,"images/edits");var er=ot;var fd=function fd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},md=function md(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},gd=function gd(){return be("https://openrouter.ai/api/v1/key",ue,md);};var ps=/*#__PURE__*/function(_k18){function ps(e){var _this67$maxMessages,_o$model9,_a$max_tokens;var _this67;_classCallCheck(this,ps);var s,r,o,a;var n=C(e.directConnection).openRouter;_this67=_callSuper(this,ps,[e,gd(),fd,n]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenRouter"),_this67.keyHelpUrl="https://openrouter.ai/keys",_this67.url="https://openrouter.ai/api/v1/chat/completions",_this67.permittedErrorPrefixes=[it,Te],_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(ps,_k18);return _createClass(ps,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(o){return _defineProperty({content:ps.getContent(o)},x,k.getRoleViaUser(o[x]));}),r=[];return this.systemMessage&&r.push(_defineProperty(_defineProperty({},x,Mn),"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[f]){_context139.n=1;break;}throw e[f].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[qe].url);});return _context139.a(2,_defineProperty(_defineProperty({},h,e.message.content||""),b,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[qe].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[qe].url);});return _context140.a(2,_defineProperty(_defineProperty({},h,n.content||""),b,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[E]===$;}).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({},E,sn),sn,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[sn].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[b]&&e[b].length>0){var t=[].concat(_toConsumableArray(ps.getImageContent(e[b])),_toConsumableArray(ps.getAudioContent(e[b])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(k);var bd=function bd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},yd=function yd(i,e,t,n){i[f]?n(pe):t(e);},_d=function _d(){return be("https://api.perplexity.ai/chat/completions",ye,yd);};var Ed=/*#__PURE__*/function(_k19){function Ed(e){var _this68$maxMessages,_s$model;var _this68;_classCallCheck(this,Ed);var s;var n=C(e.directConnection).perplexity;_this68=_callSuper(this,Ed,[e,_d(),bd,n]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("Perplexity"),_this68.keyHelpUrl="https://www.perplexity.ai/settings/api",_this68.url="https://api.perplexity.ai/chat/completions",_this68.permittedErrorPrefixes=[zt,Ho,"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(Ed,_k19);return _createClass(Ed,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});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[f]){_context142.n=1;break;}throw e[f].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;}()}]);}(k);var vd=function vd(i){return _defineProperty(_defineProperty({},he,"Bearer ".concat(i)),q,te);},Sd=function Sd(i,e,t,n){var s=i;s.detail?n(s.detail):t(e);},xd=function xd(){return be("http://localhost:3000/api/v1/models",ue,Sd);};var Ad=/*#__PURE__*/function(_k20){function Ad(e){var _this69$maxMessages,_o$model0,_a$stream;var _this69;_classCallCheck(this,Ad);var s,r,o,a;var n=C(e.directConnection).openWebUI;_this69=_callSuper(this,Ad,[e,xd(),vd,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[b]&&n[b].length>0&&(_this69.rawBody[b]=n[b])),(_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(Ad,_k20);return _createClass(Ad,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:k.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});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[f]){_context144.n=1;break;}throw e[f].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(Gt);case 1:n=C(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},x,gt),"content","")),!r.find(function(_ref176){var a=_ref176.response;return _typeof(a)!==Ee;})&&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({},x,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(an);case 5:return _context146.a(2);}},_callee146,this);}));function handleTools(_x274,_x275){return _handleTools2.apply(this,arguments);}return handleTools;}()}]);}(k);var wd=function wd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Cd=function Cd(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},Td=function Td(){return be("https://api.deepseek.com/models",ue,Cd);};var Rd=/*#__PURE__*/function(_k21){function Rd(e){var _this70$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this70;_classCallCheck(this,Rd);var s,r,o;var n=C(e.directConnection).deepSeek;_this70=_callSuper(this,Rd,[e,Td(),wd,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=[it,Te],_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(Rd,_k21);return _createClass(Rd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});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[f]){_context148.n=1;break;}throw e[f].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;}()}]);}(k);var Id=function Id(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Md=function Md(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(pe):t(e);},kd=function kd(){return be("https://api.minimax.io/v1/files/delete",ye,Md);};var Pd=/*#__PURE__*/function(_k22){function Pd(e){var _this71$maxMessages,_s$model3;var _this71;_classCallCheck(this,Pd);var s;var n=C(e.directConnection).miniMax;_this71=_callSuper(this,Pd,[e,kd(),Id,n]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("MiniMax"),_this71.keyHelpUrl="https://www.minimaxi.com",_this71.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this71.permittedErrorPrefixes=[it,Te,"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(Pd,_k22);return _createClass(Pd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});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[f]){_context150.n=1;break;}throw e[f].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;}()}]);}(k);var Ld=function Ld(i){return _defineProperty(_defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te),"accept",te);},Od=function Od(i,e,t,n){i.detail?n(pe):t(e);},Nd=function Nd(){return be("https://api.mistral.ai/v1/models",ue,Od);};var Er=/*#__PURE__*/function(_k23){function Er(e){var _this72$maxMessages,_o$model1;var _this72;_classCallCheck(this,Er);var s,r,o;var n=C(e.directConnection).mistral;_this72=_callSuper(this,Er,[e,Nd(),Ld,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=[zt],_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(Er,_k23);return _createClass(Er,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty(_defineProperty({},x,k.getRoleViaAI(r[x])),"content",k.getTextWFilesContent(r,Er.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[f]){_context152.n=2;break;}throw e[f].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[E]===W?_defineProperty(_defineProperty({},E,qe),qe,t[T]||""):_defineProperty(_defineProperty({},E,h),h,"[Unsupported ".concat(se," ").concat(E,": ").concat(t[E],"]"));});}}]);}(k);var vr=/*#__PURE__*/function(_k24){function vr(e){var _this73$maxMessages,_l$model3;var _this73;_classCallCheck(this,vr);var r,o,a,c,l;var t=C(e.directConnection),n=t.groq;_this73=_callSuper(this,vr,[e,ca(),aa,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=[zt,"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(vr,_k24);return _createClass(vr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:vr.getTextWImagesContent(r)},x,r[x]===ne?gt:r[x]);});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[f]){_context155.n=1;break;}throw e[f].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
|
|
198
|
-
},{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:return _context156.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee156,this);}));function extractStreamResult(_x292,_x293){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(
|
|
199
|
-
},{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[f]){_context160.n=1;break;}throw e[f].message||"Gemini API Error";case 1:if(!((r=(s=(n=e.candidates)==null?void 0:n[0])==null?void 0:s.content)!=null&&r.parts)){_context160.n=3;break;}a=e.candidates[0].content.parts,c=a.find(function(p){return p.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(p){return p[h];}),d=a.find(function(p){var u;return((u=p.inlineData)==null?void 0:u.mimeType)==="image/png";});return _context160.a(2,_defineProperty(_defineProperty({},h,(l==null?void 0:l[h])||""),b,(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(Gt);case 1:n=C(t);s=e.map(function(c){return{name:c.name,arguments:ce(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}};})},x,"model");if(!(n.contents.push(a),!r.find(function(_ref205){var c=_ref205.response;return _typeof(c)!==Ee;})&&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}}};})},x,F);return _context161.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(an);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[b]&&e[b].length>0&&e[b].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},x,e[x]===F?F:"model");}}]);}(k);var $d=function $d(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},q,te),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");},qd=function qd(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},Gd=function Gd(){return be("https://api.anthropic.com/v1/models",ue,qd);};var li=/*#__PURE__*/function(_k27){function li(e){var _this76$maxMessages,_o$model10,_a$max_tokens2;var _this76;_classCallCheck(this,li);var s,r,o,a;var n=C(e.directConnection).claude;_this76=_callSuper(this,li,[e,Gd(),$d,n]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("Claude"),_this76.keyHelpUrl="https://console.anthropic.com/settings/keys",_this76.url="https://api.anthropic.com/v1/messages",_this76.permittedErrorPrefixes=[Te,it],_this76._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},E,"tool_use"),"id",""),"name",""),"input",""),_typeof(n)===U&&_this76.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.claude)==null?void 0:r.function_handler),(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1,(_o$model10=(o=_this76.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="claude-sonnet-4-5-20250929",(_a$max_tokens2=(a=_this76.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this76;}_inherits(li,_k27);return _createClass(li,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:li.getTextWFilesContent(r,li.getFileContent)},x,k.getRoleViaUser(r[x]));});return n.messages=s,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[f]){_context163.n=1;break;}throw e[f].message;case 1:if(!(e.content&&e.content.length>0)){_context163.n=3;break;}o=e.content.find(function(c){return c[E]==="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[E]===h;});if(!a){_context163.n=3;break;}return _context163.a(2,_defineProperty({},h,a[h]));case 3:if(!(e[E]==="content_block_delta"&&e.delta&&e.delta[E]==="text_delta")){_context163.n=4;break;}return _context163.a(2,_defineProperty({},h,e.delta[h]||""));case 4:if(!(e[E]==="content_block_start"&&((n=e.content_block)==null?void 0:n[E])==="tool_use")){_context163.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context163.n=7;break;case 5:if(!(e[E]==="content_block_delta"&&((s=e.delta)==null?void 0:s[E])==="input_json_delta")){_context163.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context163.n=7;break;case 6:if(!(e[E]==="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(Gt);case 1:n=C(t);s=e.map(function(c){return{name:c.name,arguments:ce(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({},E,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push(_defineProperty(_defineProperty({},x,"assistant"),"content",a)),!r.find(function(_ref213){var c=_ref213.response;return _typeof(c)!==Ee;})&&s.length===r.length)){_context164.n=4;break;}c=r.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},E,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context164.a(2,(n.messages.push(_defineProperty(_defineProperty({},x,F),"content",c)),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(an);case 5:return _context164.a(2);}},_callee164,this);}));function handleTools(_x307,_x308){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var n,s,r;if(t[E]===W){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({},E,W),"source",_defineProperty(_defineProperty(_defineProperty({},E,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},E,h),h,"[Unsupported ".concat(se," ").concat(E,": ").concat(t[E],"]"));});}}]);}(k);var zd=function zd(){return{};},Vd=function Vd(){},Kd=function Kd(){return be("",ue,Vd);},vs=/*#__PURE__*/function(_k28){function vs(e){var _this77$maxMessages,_o$model11,_a$stream2;var _this77;_classCallCheck(this,vs);var s,r,o,a;var t=C(e.directConnection);_this77=_callSuper(this,vs,[e,Kd(),zd,{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(vs,_k28);return _createClass(vs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){var o=_defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));if(r[b]&&r[b].length>0){var a=vs.getImageData(r[b]);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[f]){_context166.n=1;break;}throw e[f].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(vs.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(Gt);case 1:n=C(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:ce(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},x,gt),"content","")),!r.find(function(_ref221){var a=_ref221.response;return _typeof(a)!==Ee;})&&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({},x,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(an);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[E]===W;}).map(function(t){var s;return((s=t[T])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(k);vs.THINK_END="</think>";var tr=vs;var la=function la(i){return _defineProperty({Authorization:"".concat(Ce).concat(i)},q,te);},Wd=function Wd(i,e,t,n){var s=i;s[f]?s[f][E]===Te||s[f][E]===it?n(pe):n(Ue):t(e);},da=function da(){return be("https://api.x.ai/v1/models",ue,Wd);},gi=/*#__PURE__*/function(_k29){function gi(e){var _o$model12;var _this78;_classCallCheck(this,gi);var r,o;var t=e.directConnection,n=t==null?void 0:t.x;_this78=_callSuper(this,gi,[e,da(),la,n]),_this78.insertKeyPlaceholderText=_this78.genereteAPIKeyName("X"),_this78.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this78.url=gi.IMAGE_GENERATION_URL,_this78.permittedErrorPrefixes=[it,Te];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-2-image";return _this78;}_inherits(gi,_k29);return _createClass(gi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=C(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[f]){_context169.n=1;break;}throw e[f].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},T,n.url),E,W):_defineProperty(_defineProperty({},T,"".concat(On).concat(n.b64_json)),E,W);});return _context169.a(2,_defineProperty({},b,t));}},_callee169);}));function extractResultData(_x317){return _extractResultData39.apply(this,arguments);}return extractResultData;}()}]);}(k);gi.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var nr=gi;var Xd=function Xd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Zd=function Zd(i,e,t,n){var s=i;s[f]?s[f][E]===it?n(pe):n(Ue):t(e);},Yd=function Yd(){return be("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",ue,Zd);};var xr=/*#__PURE__*/function(_k30){function xr(e){var _this79$maxMessages,_o$model13;var _this79;_classCallCheck(this,xr);var s,r,o;var n=C(e.directConnection).qwen;_this79=_callSuper(this,xr,[e,Yd(),Xd,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("Qwen"),_this79.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this79.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this79.permittedErrorPrefixes=["No static","The model",Ps],_typeof(n)===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(xr,_k30);return _createClass(xr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:xr.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});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[f]){_context171.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context171.n=3;break;}_n12=e.choices[0];if(!_n12.delta){_context171.n=2;break;}return _context171.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context171.n=3;break;}return _context171.a(2,_n12.message.tool_calls?this.handleToolsGeneric({tool_calls:_n12.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n12.message.content||""));case 3:return _context171.a(2,_defineProperty({},h,""));}},_callee171,this);}));function extractResultData(_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;}()}]);}(k);var Jd=function Jd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Qd=function Qd(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},eh=function eh(){return be("https://api.moonshot.ai/v1/models",ue,Qd);};var Ar=/*#__PURE__*/function(_k31){function Ar(e){var _this80$maxMessages,_o$model14;var _this80;_classCallCheck(this,Ar);var s,r,o;var n=C(e.directConnection).kimi;_this80=_callSuper(this,Ar,[e,eh(),Jd,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=[zt,"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(Ar,_k31);return _createClass(Ar,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Ar.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});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[f]){_context174.n=1;break;}throw e[f].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;}()}]);}(k);var th=/*#__PURE__*/function(_k32){function th(e){var _this81$maxMessages,_o$model15;var _this81;_classCallCheck(this,th);var r,o;var t=C(e.directConnection),n=t.x;_this81=_callSuper(this,th,[e,da(),la,n]),_this81.insertKeyPlaceholderText=_this81.genereteAPIKeyName("X"),_this81.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this81.url="https://api.x.ai/v1/chat/completions",_this81.permittedErrorPrefixes=[it,Te];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-3-latest";return _this81;}_inherits(th,_k32);return _createClass(th,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,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,r,o;return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:if(!e[f]){_context177.n=1;break;}throw e[f].message;case 1:if(!(e.object==="chat.completion.chunk")){_context177.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context177.a(2,(n=o==null?void 0:o.delta)!=null&&n.content?_defineProperty({},h,o.delta.content):_defineProperty({},h,""));case 2:return _context177.a(2,e.object==="chat.completion"&&(r=(s=e.choices)==null?void 0:s[0])!=null&&r.message?_defineProperty({},h,e.choices[0].message.content||""):_defineProperty({},h,""));}},_callee177);}));function extractResultData(_x332){return _extractResultData42.apply(this,arguments);}return extractResultData;}()}]);}(k);var qs=/* @__PURE__ */function(i){return i.BLOCKING="blocking",i.STREAMING="streaming",i;}(qs||{}),_n=/* @__PURE__ */function(i){return i.MESSAGE="message",i.AGENT_MESSAGE="agent_message",i.WORKFLOW_FINISHED="workflow_finished",i.ERROR="error",i;}(_n||{});var nh="image/",sh="data:",ih=function ih(i,e){return{type:e,transfer_method:"local_file",upload_file_id:i};},rh=function rh(i){var e=i.trim();if(!e.startsWith(sh))return null;var t=e.replace(/^data:\s*/,"").trim();return t?JSON.parse(t):null;};function oh(_x333,_x334){return _oh.apply(this,arguments);}function _oh(){_oh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee196(i,e){var t,_e$headers,n,s,r,a,o;return _regenerator().w(function(_context196){while(1)switch(_context196.n){case 0:t=new FormData();t.append(se,i),t.append(F,e[F]);_e$headers=e.headers;n=_e$headers[q];s=_objectWithoutProperties(_e$headers,[q].map(_toPropertyKey));_context196.n=1;return fetch(e.url,{method:ye,headers:s,body:t});case 1:r=_context196.v;if(r.ok){_context196.n=3;break;}_context196.n=2;return r.text();case 2:a=_context196.v;throw new Error(a);case 3:_context196.n=4;return r.json();case 4:o=_context196.v;if(o.id){_context196.n=5;break;}throw new Error("Upload response missing file ID");case 5:return _context196.a(2,o.id);}},_callee196);}));return _oh.apply(this,arguments);}function ah(_x335,_x336){return _ah.apply(this,arguments);}function _ah(){_ah=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee198(i,e){var t;return _regenerator().w(function(_context198){while(1)switch(_context198.n){case 0:if(!(i.length===0)){_context198.n=1;break;}return _context198.a(2,[]);case 1:t=i.map(/*#__PURE__*/function(){var _ref269=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee197(s){var r,o;return _regenerator().w(function(_context197){while(1)switch(_context197.n){case 0:_context197.n=1;return oh(s,e);case 1:r=_context197.v;o=s[E].startsWith(nh)?W:se;return _context197.a(2,ih(r,o));}},_callee197);}));return function(_x367){return _ref269.apply(this,arguments);};}());_context198.n=2;return Promise.all(t);case 2:return _context198.a(2,_context198.v.filter(function(s){return s!==null;}));}},_callee198);}));return _ah.apply(this,arguments);}function ch(i,e){return i.conversation_id&&e(i.conversation_id),i.code&&i.message&&!i.answer?_defineProperty({},f,i.message):_defineProperty({},h,i.answer||"");}var lh=function lh(i,e,t){var n,s;switch(!e.conversationIdSet&&i.conversation_id&&(t(i.conversation_id),e.conversationIdSet=!0),i.event){case _n.MESSAGE:case _n.AGENT_MESSAGE:e.fullAnswer+=i.answer||"";break;case _n.WORKFLOW_FINISHED:!e.fullAnswer&&(s=(n=i.data)==null?void 0:n.outputs)!=null&&s.answer&&(e.fullAnswer=i.data.outputs.answer);break;case _n.ERROR:e.errorMessage=i.message||_n.ERROR;break;}};function dh(_x337,_x338){return _dh.apply(this,arguments);}function _dh(){_dh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee199(i,e){var t,s,_iterator7,_step7,r,o;return _regenerator().w(function(_context199){while(1)switch(_context199.n){case 0:t={fullAnswer:"",conversationIdSet:!1,errorMessage:""};_context199.n=1;return i.text();case 1:s=_context199.v.split(/\r?\n\r?\n/);_iterator7=_createForOfIteratorHelper(s);try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){r=_step7.value;o=rh(r);o&&lh(o,t,e);}}catch(err){_iterator7.e(err);}finally{_iterator7.f();}return _context199.a(2,t.errorMessage?_defineProperty({},f,t.errorMessage):_defineProperty({},h,t.fullAnswer));}},_callee199);}));return _dh.apply(this,arguments);}var hh=function hh(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},uh=function uh(i,e,t,n){var s=i;s[f]?s[f].message===yi?n(pe):n(Ue):"user_input_form"in i||"opening_statement"in i||"file_upload"in i?t(e):n(Ue);},ph=function ph(i){return be("".concat(i,"/parameters"),ue,uh);};var fh=/*#__PURE__*/function(_k33){function fh(e){var _ref242,_this82$maxMessages;var _this82;_classCallCheck(this,fh);var r;var t=C(e.directConnection),n=t==null?void 0:t.dify,s=(_ref242=(r=e.connect)==null?void 0:r.url)!==null&&_ref242!==void 0?_ref242:"https://api.dify.ai/v1";_this82=_callSuper(this,fh,[e,ph(s),hh,n]),_this82.insertKeyPlaceholderText=_this82.genereteAPIKeyName("Dify"),_this82.keyHelpUrl="https://docs.dify.ai/en/use-dify/publish/developing-with-apis",_this82.permittedErrorPrefixes=[Te],_this82._conversationId="",_this82._user=F,_this82._inputs={},_this82.url="".concat(s,"/chat-messages"),_this82._uploadUrl="".concat(s,"/").concat(b,"/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?qs.STREAMING:qs.BLOCKING;return _this82;}_inherits(fh,_k33);return _createClass(fh,[{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[b]=n),a;}},{key:"callServiceAPI",value:function(){var _callServiceAPI40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee178(e,t,n){var _this$messages11,_this83=this;var s,_t56;return _regenerator().w(function(_context178){while(1)switch(_context178.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){_context178.n=2;break;}_context178.n=1;return ah(n,_defineProperty(_defineProperty({url:this._uploadUrl},F,this._user),"headers",this.connectSettings.headers));case 1:s=_context178.v;case 2:this.callDirectServiceServiceAPI(e,t,function(r,o){return _this83.preprocessBody(r,o,s);});case 3:return _context178.a(2);}},_callee178,this);}));function callServiceAPI(_x339,_x340,_x341){return _callServiceAPI40.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData43=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e){var _this84=this;var t;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:t=function t(n){_this84._conversationId=n;};return _context179.a(2,this._mode===qs.BLOCKING&&!this.stream?ch(e,t):dh(e,t));}},_callee179,this);}));function extractResultData(_x342){return _extractResultData43.apply(this,arguments);}return extractResultData;}()}]);}(k);var mh=/*#__PURE__*/function(){function mh(){_classCallCheck(this,mh);}return _createClass(mh,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
|
|
200
|
-
function create(e){var t=e.directConnection,n=e.connect,s=e.demo,r=e.webModel;if(r)return new
|
|
201
|
-
},{key:"createImageMessage",value:function createImageMessage(e,t,n,s,r){var o=e.createNewMessageElement("",n,s),a=!s&&r?e.scrollToFirstElement.bind(e,n,r):void 0,c=Ie.createImage(t,a);return o.bubbleElement.appendChild(c),o.bubbleElement[
|
|
202
|
-
},{key:"addMessages",value:function addMessages(e,t,n,s,r){Ie.createMessages(e,t,n,s,r).filter(function(a){return a!==void 0;}).forEach(function(_ref246){var a=_ref246[
|
|
203
|
-
},{key:"updateFileMessages",value:function updateFileMessages(e,t,n){var
|
|
204
|
-
},{key:"update",value:function update(e,t,n){var s=e.messageToElements[n];if(s){if(
|
|
205
|
-
},{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(r,o){if(o!==0){var a=_this86.messageElementRefs[_this86.messageElementRefs.length-1].innerContainer;
|
|
206
|
-
},{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,
|
|
207
|
-
},{key:"removeMessageOnError",value:function removeMessageOnError(){var e=this.messageElementRefs[this.messageElementRefs.length-1],t=e==null?void 0:e.bubbleElement;(t!=null&&t[
|
|
208
|
-
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this89=this;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var l,d,
|
|
209
|
-
},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,c,l,d,
|
|
210
|
-
},{key:"updateLoadingMessage",value:function updateLoadingMessage(e){var s;var t=(s=this._activeLoadingConfig)==null?void 0:s[
|
|
211
|
-
function clearMessages(e,t){var _this$messageToElemen2;var r,o,a,c;var n=[];this.messageElementRefs.forEach(function(l){
|
|
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 Wi=dt;var Gl=function Gl(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},zl=function zl(i,e,t,n){var s=i;s[p]?s[p][y]===Te?n(ue):n(He):t(e);},Vl=function Vl(){return be("https://openrouter.ai/api/v1/key",de,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,Vl(),Gl,n]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenRouter"),_this67.keyHelpUrl="https://openrouter.ai/keys",_this67.url="https://openrouter.ai/api/v1/chat/completions",_this67.permittedErrorPrefixes=[ct,Te],_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[Q])){_context139.n=3;break;}c=e.message[Q].map(function(l){return _defineProperty({},T,l[ze].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[Q])==null?void 0:o.map(function(l){return _defineProperty({},T,l[ze].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[Q])){_context140.n=1;break;}s=n[Q].map(function(r){return _defineProperty({},T,r[ze].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]===$;}).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 Kl=function Kl(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},Wl=function Wl(i,e,t,n){i[p]?n(ue):t(e);},Xl=function Xl(){return be("https://api.perplexity.ai/chat/completions",ye,Wl);};var Zl=/*#__PURE__*/function(_M19){function Zl(e){var _this68$maxMessages,_s$model;var _this68;_classCallCheck(this,Zl);var s;var n=w(e.directConnection).perplexity;_this68=_callSuper(this,Zl,[e,Xl(),Kl,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,go,"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(Zl,_M19);return _createClass(Zl,[{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 Yl=function Yl(i){return _defineProperty(_defineProperty({},he,"Bearer ".concat(i)),q,ee);},Jl=function Jl(i,e,t,n){var s=i;s.detail?n(s.detail):t(e);},Ql=function Ql(){return be("http://localhost:3000/api/v1/models",de,Jl);};var eh=/*#__PURE__*/function(_M20){function eh(e){var _this69$maxMessages,_o$model0,_a$stream;var _this69;_classCallCheck(this,eh);var s,r,o,a;var n=w(e.directConnection).openWebUI;_this69=_callSuper(this,eh,[e,Ql(),Yl,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(eh,_M20);return _createClass(eh,[{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 th=function th(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},nh=function nh(i,e,t,n){var s=i;s[p]?s[p][y]===Te?n(ue):n(He):t(e);},sh=function sh(){return be("https://api.deepseek.com/models",de,nh);};var ih=/*#__PURE__*/function(_M21){function ih(e){var _this70$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this70;_classCallCheck(this,ih);var s,r,o;var n=w(e.directConnection).deepSeek;_this70=_callSuper(this,ih,[e,sh(),th,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=[ct,Te],_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(ih,_M21);return _createClass(ih,[{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 rh=function rh(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},oh=function oh(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(ue):t(e);},ah=function ah(){return be("https://api.minimax.io/v1/files/delete",ye,oh);};var ch=/*#__PURE__*/function(_M22){function ch(e){var _this71$maxMessages,_s$model3;var _this71;_classCallCheck(this,ch);var s;var n=w(e.directConnection).miniMax;_this71=_callSuper(this,ch,[e,ah(),rh,n]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("MiniMax"),_this71.keyHelpUrl="https://www.minimaxi.com",_this71.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this71.permittedErrorPrefixes=[ct,Te,"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(ch,_M22);return _createClass(ch,[{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 lh=function lh(i){return _defineProperty(_defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee),"accept",ee);},hh=function hh(i,e,t,n){i.detail?n(ue):t(e);},dh=function dh(){return be("https://api.mistral.ai/v1/models",de,hh);};var gr=/*#__PURE__*/function(_M23){function gr(e){var _this72$maxMessages,_o$model1;var _this72;_classCallCheck(this,gr);var s,r,o;var n=w(e.directConnection).mistral;_this72=_callSuper(this,gr,[e,dh(),lh,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(gr,_M23);return _createClass(gr,[{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,gr.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,ze),ze,t[T]||""):_defineProperty(_defineProperty({},y,h),h,"[Unsupported ".concat(ne," ").concat(y,": ").concat(t[y],"]"));});}}]);}(M);var br=/*#__PURE__*/function(_M24){function br(e){var _this73$maxMessages,_l$model3;var _this73;_classCallCheck(this,br);var r,o,a,c,l;var t=w(e.directConnection),n=t.groq;_this73=_callSuper(this,br,[e,Fo(),Do,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(br,_M24);return _createClass(br,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:br.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 _callee156(e,t){return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:return _context156.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee156,this);}));function extractStreamResult(_x292,_x293){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(M);var uh=function uh(i){return _defineProperty(_defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee),"accept",ee);},ph=function ph(i,e,t,n){_typeof(i.message)===_e?n(ue):t(e);},fh=function fh(){return be("https://api.cohere.ai/v1/models",de,ph);};var ii=/*#__PURE__*/function(_M25){function ii(e){var _this74$maxMessages,_s$model4;var _this74;_classCallCheck(this,ii);var s;var n=w(e.directConnection).cohere;if(_this74=_callSuper(this,ii,[e,fh(),uh,n]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Cohere"),_this74.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this74.permittedErrorPrefixes=["invalid"],_this74.url="https://api.cohere.com/v2/chat",_typeof(n)===U){var r=ce.processCohere(n);_this74.canSendMessage=function(){return r;},_this74.cleanConfig(n),Object.assign(_this74.rawBody,n);}(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_s$model4=(s=_this74.rawBody).model)!==null&&_s$model4!==void 0?_s$model4:s.model="command-a-03-2025";return _this74;}_inherits(ii,_M25);return _createClass(ii,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=t.filter(function(r){return r[h];});return n.messages=s.map(function(r){return _defineProperty(_defineProperty({},S,M.getRoleViaAI(r[S])),"content",r[h]);}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context157.a(2);}},_callee157,this);}));function callServiceAPI(_x294,_x295){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e){var t,n,s,r;return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:if(!(typeof e.message=="string")){_context158.n=1;break;}throw e.message;case 1:if(!(this.stream&&e[h])){_context158.n=2;break;}r=ii.parseBundledEvents(e[h]);return _context158.a(2,{text:ii.aggregateBundledEventsText(r)});case 2:if(!("message"in e&&(s=(n=(t=e.message)==null?void 0:t.content)==null?void 0:n[0])!=null&&s[h])){_context158.n=3;break;}return _context158.a(2,_defineProperty({},h,e.message.content[0][h]));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context158.a(2);}},_callee158,this);}));function extractResultData(_x296){return _extractResultData35.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),n=[];var _iterator5=_createForOfIteratorHelper(t),_step5;try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var s=_step5.value;if(s.trim())try{var r=JSON.parse(s);n.push(r);}catch(r){console[p]("Failed to parse line:",s,r);}}}catch(err){_iterator5.e(err);}finally{_iterator5.f();}return n;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var n,s,r;return t[y]==="content-delta"&&((r=(s=(n=t.delta)==null?void 0:n.message)==null?void 0:s.content)==null?void 0:r[h]);}).map(function(t){var n,s,r;return(r=(s=(n=t.delta)==null?void 0:n.message)==null?void 0:s.content)==null?void 0:r[h];}).join("");}}]);}(M);var mh=function mh(){return _defineProperty({},q,ee);},gh=function gh(i,e,t,n){var r;var s=i;s[p]?s[p].code===403||(r=s[p].message)!=null&&r.includes("API key")?n(ue):n(He):t(e);},bh=function bh(){var i="https://generativelanguage.googleapis.com/v1beta/models?key=";return be(i,de,gh,function(e){return"".concat(i).concat(e);});};var yr=/*#__PURE__*/function(_M26){function yr(e){var _this75$maxMessages;var _this75;_classCallCheck(this,yr);var s,r;var n=w(e.directConnection).gemini;if(_this75=_callSuper(this,yr,[e,bh(),mh,n]),_this75.insertKeyPlaceholderText=_this75.genereteAPIKeyName("Gemini"),_this75.keyHelpUrl="https://aistudio.google.com/app/apikey",_this75.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",_this75.url="",_this75.permittedErrorPrefixes=["API_KEY_INVALID"],_typeof(n)===U){var o=n;o.model&&(_this75.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(o.model,":generateContent")),_this75.cleanConfig(o),_this75.completeConfig(o,(r=(s=e.directConnection)==null?void 0:s.gemini)==null?void 0:r.function_handler);}(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1;return _this75;}_inherits(yr,_M26);return _createClass(yr,[{key:"cleanConfig",value:function cleanConfig(e){delete e.model;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return yr.getContent(r);});return n.contents=s,this.systemMessage&&(n.systemInstruction={parts:[_defineProperty({},h,this.systemMessage)]}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e,t){var _this$messages8;var n,s;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(this.connectSettings){_context159.n=1;break;}throw new Error(je);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),ge.request(this,n,e));case 2:return _context159.a(2);}},_callee159,this);}));function callServiceAPI(_x297,_x298){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 _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 yh=function yh(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},q,ee),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");},Eh=function Eh(i,e,t,n){var s=i;s[p]?s[p][y]===Te?n(ue):n(He):t(e);},_h=function _h(){return be("https://api.anthropic.com/v1/models",de,Eh);},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,_h(),yh,n]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("Claude"),_this76.keyHelpUrl="https://console.anthropic.com/settings/keys",_this76.url="".concat(Wt.CLAUDE_BASE_URL,"messages"),_this76.permittedErrorPrefixes=[Te,ct],_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-5-20250929",(_a$max_tokens2=(a=_this76.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this76;}_inherits(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 Xi=Wt;var vh=function vh(){return{};},Sh=function Sh(){},xh=function xh(){return be("",de,Sh);},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,xh(),vh,{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[Q]=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 Zi=ds;var Uo=function Uo(i){return _defineProperty({Authorization:"".concat(Ce).concat(i)},q,ee);},Ah=function Ah(i,e,t,n){var s=i;s[p]?s[p][y]===Te||s[p][y]===ct?n(ue):n(He):t(e);},Ho=function Ho(){return be("https://api.x.ai/v1/models",de,Ah);},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,Ho(),Uo,n]),_this78.insertKeyPlaceholderText=_this78.genereteAPIKeyName("X"),_this78.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this78.url=ui.IMAGE_GENERATION_URL,_this78.permittedErrorPrefixes=[ct,Te];var s=(r=t==null?void 0:t.x)==null?void 0:r[Q];_typeof(s)===U&&Object.assign(_this78.rawBody,s),(_o$model12=(o=_this78.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="grok-2-image";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(zn).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 Yi=ui;var wh=function wh(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},Ch=function Ch(i,e,t,n){var s=i;s[p]?s[p][y]===ct?n(ue):n(He):t(e);},Th=function Th(){return be("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",de,Ch);};var Er=/*#__PURE__*/function(_M30){function Er(e){var _this79$maxMessages,_o$model13;var _this79;_classCallCheck(this,Er);var s,r,o;var n=w(e.directConnection).qwen;_this79=_callSuper(this,Er,[e,Th(),wh,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(Er,_M30);return _createClass(Er,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Er.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 Rh=function Rh(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,ee);},Ih=function Ih(i,e,t,n){var s=i;s[p]?s[p][y]===Te?n(ue):n(He):t(e);},Mh=function Mh(){return be("https://api.moonshot.ai/v1/models",de,Ih);};var _r=/*#__PURE__*/function(_M31){function _r(e){var _this80$maxMessages,_o$model14;var _this80;_classCallCheck(this,_r);var s,r,o;var n=w(e.directConnection).kimi;_this80=_callSuper(this,_r,[e,Mh(),Rh,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(_r,_M31);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 _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 kh=/*#__PURE__*/function(_M32){function kh(e){var _this81$maxMessages,_o$model15;var _this81;_classCallCheck(this,kh);var r,o;var t=w(e.directConnection),n=t.x;_this81=_callSuper(this,kh,[e,Ho(),Uo,n]),_this81.insertKeyPlaceholderText=_this81.genereteAPIKeyName("X"),_this81.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this81.url="https://api.x.ai/v1/chat/completions",_this81.permittedErrorPrefixes=[ct,Te];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-3-latest";return _this81;}_inherits(kh,_M32);return _createClass(kh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=w(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},S,M.getRoleViaUser(r[S]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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,r,o;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:if(!(e.object==="chat.completion.chunk")){_context177.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context177.a(2,(n=o==null?void 0:o.delta)!=null&&n.content?_defineProperty({},h,o.delta.content):_defineProperty({},h,""));case 2:return _context177.a(2,e.object==="chat.completion"&&(r=(s=e.choices)==null?void 0:s[0])!=null&&r.message?_defineProperty({},h,e.choices[0].message.content||""):_defineProperty({},h,""));}},_callee177);}));function extractResultData(_x332){return _extractResultData42.apply(this,arguments);}return extractResultData;}()}]);}(M);var Os=/* @__PURE__ */function(i){return i.BLOCKING="blocking",i.STREAMING="streaming",i;}(Os||{}),Rn=/* @__PURE__ */function(i){return i.MESSAGE="message",i.AGENT_MESSAGE="agent_message",i.WORKFLOW_FINISHED="workflow_finished",i.ERROR="error",i;}(Rn||{});var Lh="image/",Ph="data:",Nh=function Nh(i,e){return{type:e,transfer_method:"local_file",upload_file_id:i};},Bh=function Bh(i){var e=i.trim();if(!e.startsWith(Ph))return null;var t=e.replace(/^data:\s*/,"").trim();return t?JSON.parse(t):null;};function Oh(_x333,_x334){return _Oh.apply(this,arguments);}function _Oh(){_Oh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee196(i,e){var t,_e$headers,n,s,r,a,o;return _regenerator().w(function(_context196){while(1)switch(_context196.n){case 0:t=new FormData();t.append(ne,i),t.append(F,e[F]);_e$headers=e.headers;n=_e$headers[q];s=_objectWithoutProperties(_e$headers,[q].map(_toPropertyKey));_context196.n=1;return fetch(e.url,{method:ye,headers:s,body:t});case 1:r=_context196.v;if(r.ok){_context196.n=3;break;}_context196.n=2;return r.text();case 2:a=_context196.v;throw new Error(a);case 3:_context196.n=4;return r.json();case 4:o=_context196.v;if(o.id){_context196.n=5;break;}throw new Error("Upload response missing file ID");case 5:return _context196.a(2,o.id);}},_callee196);}));return _Oh.apply(this,arguments);}function Dh(_x335,_x336){return _Dh.apply(this,arguments);}function _Dh(){_Dh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee198(i,e){var t;return _regenerator().w(function(_context198){while(1)switch(_context198.n){case 0:if(!(i.length===0)){_context198.n=1;break;}return _context198.a(2,[]);case 1:t=i.map(/*#__PURE__*/function(){var _ref270=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee197(s){var r,o;return _regenerator().w(function(_context197){while(1)switch(_context197.n){case 0:_context197.n=1;return Oh(s,e);case 1:r=_context197.v;o=s[y].startsWith(Lh)?K:ne;return _context197.a(2,Nh(r,o));}},_callee197);}));return function(_x367){return _ref270.apply(this,arguments);};}());_context198.n=2;return Promise.all(t);case 2:return _context198.a(2,_context198.v.filter(function(s){return s!==null;}));}},_callee198);}));return _Dh.apply(this,arguments);}function Fh(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 Uh=function Uh(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 Hh(_x337,_x338){return _Hh.apply(this,arguments);}function _Hh(){_Hh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee199(i,e){var t,s,_iterator7,_step7,r,o;return _regenerator().w(function(_context199){while(1)switch(_context199.n){case 0:t={fullAnswer:"",conversationIdSet:!1,errorMessage:""};_context199.n=1;return i.text();case 1:s=_context199.v.split(/\r?\n\r?\n/);_iterator7=_createForOfIteratorHelper(s);try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){r=_step7.value;o=Bh(r);o&&Uh(o,t,e);}}catch(err){_iterator7.e(err);}finally{_iterator7.f();}return _context199.a(2,t.errorMessage?_defineProperty({},p,t.errorMessage):_defineProperty({},h,t.fullAnswer));}},_callee199);}));return _Hh.apply(this,arguments);}var jh=function jh(i){return _defineProperty(_defineProperty({},q,ee),he,"".concat(Ce).concat(i));},$h=function $h(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);},qh=function qh(i){return be("".concat(i,"/parameters"),de,$h);};var Gh=/*#__PURE__*/function(_M33){function Gh(e){var _ref242,_this82$maxMessages;var _this82;_classCallCheck(this,Gh);var r;var t=w(e.directConnection),n=t==null?void 0:t.dify,s=(_ref242=(r=e.connect)==null?void 0:r.url)!==null&&_ref242!==void 0?_ref242:"https://api.dify.ai/v1";_this82=_callSuper(this,Gh,[e,qh(s),jh,n]),_this82.insertKeyPlaceholderText=_this82.genereteAPIKeyName("Dify"),_this82.keyHelpUrl="https://docs.dify.ai/en/use-dify/publish/developing-with-apis",_this82.permittedErrorPrefixes=[Te],_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?Os.STREAMING:Os.BLOCKING;return _this82;}_inherits(Gh,_M33);return _createClass(Gh,[{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 _callServiceAPI40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee178(e,t,n){var _this$messages11,_this83=this;var s,_t56;return _regenerator().w(function(_context178){while(1)switch(_context178.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){_context178.n=2;break;}_context178.n=1;return Dh(n,_defineProperty(_defineProperty({url:this._uploadUrl},F,this._user),"headers",this.connectSettings.headers));case 1:s=_context178.v;case 2:this.callDirectServiceServiceAPI(e,t,function(r,o){return _this83.preprocessBody(r,o,s);});case 3:return _context178.a(2);}},_callee178,this);}));function callServiceAPI(_x339,_x340,_x341){return _callServiceAPI40.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData43=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e){var _this84=this;var t;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:t=function t(n){_this84._conversationId=n;};return _context179.a(2,this._mode===Os.BLOCKING&&!this.stream?Fh(e,t):Hh(e,t));}},_callee179,this);}));function extractResultData(_x342){return _extractResultData43.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,r=e.webModel;if(r)return new bs(e);if(t){if(t.openAI)return t.openAI[Q]?new Wi(e):t.openAI.speechToText?new Gi(e):t.openAI.textToSpeech?new qi(e):t.openAI.assistant?new pr(e):t.openAI.realtime?new $i(e):t.openAI.completions?new ti(e):new ni(e);if(t.assemblyAI)return new fr(e);if(t.cohere)return new ii(e);if(t.huggingFace)return t.huggingFace.textGeneration?new ul(e):t.huggingFace.summarization?new fl(e):t.huggingFace.translation?new gl(e):t.huggingFace.fillMask?new bl(e):t.huggingFace.questionAnswer?new pl(e):t.huggingFace.audioSpeechRecognition?new dl(e):t.huggingFace.audioClassification?new cl(e):t.huggingFace.imageClassification?new ll(e):new ml(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new mr(e);if(t.azure.openAI.assistant)return new Hi(e);}if(t.azure.speechToText)return new Ki(e);if(t.azure.textToSpeech)return new Vi(e);if(t.azure.summarization)return new zi(e);if(t.azure.translation)return new Fl(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new Xs(e):t.stabilityAI.imageToImageUpscale?new Ks(e):t.stabilityAI.imageToImageMasking?new Ws(e):new Zs(e);if(t.mistral)return new gr(e);if(t.gemini)return new yr(e);if(t.claude)return new Xi(e);if(t.deepSeek)return new ih(e);if(t.miniMax)return new ch(e);if(t.openRouter)return new ss(e);if(t.kimi)return new _r(e);if(t.x)return t.x[Q]?new Yi(e):new kh(e);if(t.qwen)return new Er(e);if(t.together)return t.together[Q]?new $l(e):t.together.textToSpeech?new vl(e):new ql(e);if(t.bigModel)return t.bigModel[Q]?new Ul(e):t.bigModel.textToSpeech?new El(e):new si(e);if(t.groq)return t.groq.textToSpeech?new jl(e):new br(e);if(t.perplexity)return new Zl(e);if(t.ollama)return new Zi(e);if(t.openWebUI)return new eh(e);if(t.dify)return new Gh(e);}return n&&Object.keys(n).length>0&&!s?new vn(e):new vn(e,void 0,s||!0);}}]);}();var ln=/*#__PURE__*/function(){function ln(){_classCallCheck(this,ln);}return _createClass(ln,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e,t){var n=e.fontFamily||t;if(n&&n!==ln.DEFAULT_FONT_FAMILY)return;var s=document.getElementsByTagName("head")[0];if(!Array.from(s.getElementsByTagName("link")).some(function(o){return o.getAttribute("href")===ln.FONT_URL;})){var o=x("link");o.rel="stylesheet",o.href=ln.FONT_URL,s.appendChild(o);}}}]);}();ln.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",ln.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var Ji=ln;var Tr=/*#__PURE__*/_createClass(function Tr(){_classCallCheck(this,Tr);});Tr.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 Qi=Tr;function P(i){return function(e,t){Object.defineProperty(e,t,{});var n=e.constructor,s=t.toLocaleLowerCase();n._attributes_[s]=Qi.attibutes[i],n._attributeToProperty_[s]=t;};}var Vh="deep-chat-downwards-mode",Kh="deep-chat-upwards-mode",Jn="submit-button",Ps="loading-button",Qn="disabled-button",Qr="text-input-container-start-adjustment",eo="text-input-container-end-adjustment",to="text-input-container-start-small-adjustment",no="text-input-container-end-small-adjustment";var vr=/*#__PURE__*/function(){function vr(e){_classCallCheck(this,vr);this._isDisplayed=!1,this._elementRef=this.createIntroPanelWithChild(e),this._isDisplayed=!0;}return _createClass(vr,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e){var t=vr.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 Wh="<?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(K,n,n[T],e.name);}// WORK - image still does not scroll down when loaded
|
|
204
|
+
},{key:"createImageMessage",value:function createImageMessage(e,t,n,s,r){var o=e.createNewMessageElement("",n,s),a=!s&&r?e.scrollToFirstElement.bind(e,n,r):void 0,c=Ie.createImage(t,a);return o.bubbleElement.appendChild(c),o.bubbleElement[f].add(Ie.IMAGE_BUBBLE_CLASS),_defineProperty(_defineProperty({},y,K),"elements",o);}},{key:"createAudioElement",value:function createAudioElement(e,t){var n=x($);return n[T]=e[T],n[f].add("audio-player"),n.controls=!0,Ge.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 r=Ie.createAudioElement(t,n),o=e.createMessageElementsOnOrientation("",n,s);return o.bubbleElement.appendChild(r),o.bubbleElement[f].add(Ie.AUDIO_BUBBLE_CLASS),_defineProperty(_defineProperty(_defineProperty({},y,$),"elements",o),"audioElement",r);}},{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=Ft.createSVGElement(Wh);s[f].add("any-file-message-icon"),n.appendChild(s);var r=x();return r[f].add("any-file-message-text"),r.textContent=e.name||ne,t.appendChild(n),t.appendChild(r),Se.processContent(mn,t,e[T],r.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,n,s){var r=e.createMessageElementsOnOrientation("",n,s),o=Ie.createAnyFile(t);return r.bubbleElement[f].add(Ie.ANY_FILE_BUBBLE_CLASS),r.bubbleElement.appendChild(o),_defineProperty(_defineProperty({},y,ne),"elements",r);}},{key:"createMessages",value:function createMessages(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;return t.map(function(o,a){var c;if(o.ref&&(o=Se.removeFileRef(o)),Se.isAudioFile(o)){var l=Ie.createNewAudioMessage(e,o,n,r),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,r,s&&a===0):Ie.createNewAnyFileMessage(e,o,n,r);}).filter(function(o){return o!==void 0;});}// no overwrite previous message logic as it is complex to track which files are to be overwritten
|
|
205
|
+
},{key:"addMessages",value:function addMessages(e,t,n,s,r){Ie.createMessages(e,t,n,s,r).filter(function(a){return a!==void 0;}).forEach(function(_ref246){var a=_ref246[y],c=_ref246.elements;Se.addMessage(e,c,a,n,r);});}}]);}();Ie.IMAGE_BUBBLE_CLASS="image-message",Ie.AUDIO_BUBBLE_CLASS="audio-message",Ie.ANY_FILE_BUBBLE_CLASS="any-file-message";var ri=Ie;var nt=/*#__PURE__*/function(){function nt(){_classCallCheck(this,nt);}return _createClass(nt,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){nt.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];nt.removeElements(e.messageElementRefs,s),delete t[0][n],delete t[1][n];}},{key:"updateHTMLMessage",value:function updateHTMLMessage(e,t,n){var s,r,o;if(t[1][L])At.overwriteElements(e,n,t[1][L]);else{var a=At.create(e,n,t[0][S]),c=((r=t[1][m])==null?void 0:r[((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],r=ri.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);r.forEach(function(_ref247,v){var b=_ref247.type,_=_ref247.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,_);}),nt.removeFilesMessages(e,t),t[1][m]=r.map(function(_ref248){var b=_ref248.elements;return b;}),t[0][m]=n;}},{key:"updateTextMessage",value:function updateTextMessage(e,t,n){var s,r;if(t[1][h])e.renderText(t[1][h].bubbleElement,n,t[0][S]);else{var o=e.createElements(n,t[0][S]),a=((s=t[1][m])==null?void 0:s[0])||t[1][L];(r=a.outerContainer.parentElement)==null||r.insertBefore(o.outerContainer,a.outerContainer);var c=e.messageElementRefs.findIndex(function(l){return l===a;});e.messageElementRefs.splice(c,0,o),t[1][h]=o;}t[0][h]=n;}},{key:"isElementActive",value:function isElementActive(e){var t,n;return it.isActiveElement((t=e[h])==null?void 0:t.bubbleElement[f])||it.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(nt.isElementActive(s[1]))return console[p]("Cannot update a message that is being streamed");t[h]&&nt.updateTextMessage(e,s,t[h]),t[m]?nt.updateFileMessages(e,s,t[m]):nt.removeFilesMessages(e,s),t[L]&&nt.updateHTMLMessage(e,s,t[L]),!t[h]&&s[1][h]&&nt.removeTextHTMLMessage(e,s,h),!t[L]&&s[1][L]&&nt.removeTextHTMLMessage(e,s,L);var r=e.messageElementRefs,o=e.avatar,a=e.name;O.classifyRoleMessages(r),O.resetAllRoleElements(r,o,a);}else console[p]("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var Xh=/*#__PURE__*/function(){function Xh(){_classCallCheck(this,Xh);}return _createClass(Xh,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 r=(n=e.directConnection.openAI)==null?void 0:n.chat;if(_typeof(r)=="object"&&(s=r.tools)!=null&&s.find(function(o){return o[y]==="function";})&&!r.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)return"Please define a `url` or a `handler` property inside the [connect](".concat(X,"connect#connect-1) object.");return null;}}]);}();var it=/*#__PURE__*/function(_ot){function it(e,t,n){var _this85;_classCallCheck(this,it);var a,c;_this85=_callSuper(this,it,[e]);var s=t.permittedErrorPrefixes,r=t.demo;_this85._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this85._onClearMessages=_n.onClearMessages.bind(_this85,e),_this85._onError=_n.onError.bind(_this85,e),_this85._isLoadingMessageAllowed=it.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),r&&_this85.prepareDemo(ce.processDemo(r),e.loadHistory),_this85.addIntroductoryMessages(e,t);var o=new gs(e,_this85,t);_this85._displayServiceErrorMessages=(c=e.errorMessages)==null?void 0:c.displayServiceErrorMessages,e.getMessages=function(){return O.deepCloneMessagesWithReferences(_this85.messageToElements.map(function(_ref249){var _ref250=_slicedToArray(_ref249,1),l=_ref250[0];return l;}));},e.clearMessages=_this85.clearMessages.bind(_this85,t),e.refreshMessages=_this85.refreshTextMessages.bind(_this85,e.remarkable),e.scrollToBottom=z.scrollToBottom.bind(_this85,_this85),e.addMessage=function(l,d){_this85.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(l,d){return nt.update(_this85,l,d);},t.isWebModel()&&t.setUpMessages(_this85),e.textToSpeech&&Dn.processConfig(e.textToSpeech,function(l){_this85.textToSpeech=l;}),_this85.elementRef.onscroll=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(){var l,d;return _regenerator().w(function(_context180){while(1)switch(_context180.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 _context180.a(2);}},_callee180);}));return _this85;}_inherits(it,_ot);return _createClass(it,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1],n=ot.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&&Dt.addMessage(this,!1),s!=null&&s.full&&Dt.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=Xh.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(r,o){if(o!==0){var a=_this86.messageElementRefs[_this86.messageElementRefs.length-1].innerContainer;O.hideRoleElements(a,_this86.avatar,_this86.name);}_this86.addIntroductoryMessage(r,s);}):this.addIntroductoryMessage(n,s));}},{key:"addIntroductoryMessage",value:function addIntroductoryMessage(e,t){var s;var n;return e!=null&&e[h]?n=this.createAndAppendNewMessageElement(e[h],te):e!=null&&e[L]&&(n=At.add(this,e[L],te)),n&&(this.applyCustomStyles(n,te,!1,(s=this.messageStyles)==null?void 0:s.intro),n.outerContainer[f].add(ot.INTRO_CLASS),t&&(n.outerContainer[E].display="none")),n;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer[f].contains(ot.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 r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;e[h]!==void 0&&n[h]!==null&&(this.addNewTextMessage(e[h],e[S],t,r),!s&&this.textToSpeech&&e[S]!==F&&Dn.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])&&ri.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=At.add(this,e[L],e[S],t,n);!n&&xt.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=it.createMessageContent(e),r=(d=(l=this.textToSpeech)==null?void 0:l.audio)==null?void 0:d.displayText;typeof r=="boolean"&&!r&&delete s[h];var o=z.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(_ref252){var _ref253=_slicedToArray(_ref252,1),g=_ref253[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 r=O.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,r]);}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(gt.MESSAGE_CLASS)&&t.textContent===""||it.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.",r=this.createMessageElementsOnOrientation(s,p,n);O.hideRoleElements(r.innerContainer,this.avatar,this.name);var o=r.bubbleElement,a=r.outerContainer;o[f].add($s),this.renderText(o,s);var c=Oe.extractParticularSharedStyles(["fontSize","fontFamily"],(g=this.messageStyles)==null?void 0:g[A]);Oe.applyCustomStylesToElements(r,!1,c),Oe.applyCustomStylesToElements(r,!1,(b=this.messageStyles)==null?void 0:b[p]),n||this.appendOuterContainerElemet(a),this.textToSpeech&&Dn.speak(s,this.textToSpeech),(_=this._onError)==null||_.call(this,s),setTimeout(function(){return z.scrollToBottom(_this89);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=it.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 r=it.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,s);if(r)return r;}}}}}},{key:"removeError",value:function removeError(){this.isLastMessageError()&&O.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(vt.DOTS_CONTAINER_CLASS);var r=x();return r[f].add("loading-message-dots"),s.appendChild(r),vt.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(ot.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],r=s?At.createElements(this,s,t,!1):this.addDefaultLoadingMessage(n,t);this.appendOuterContainerElemet(r.outerContainer),r.bubbleElement[f].add(vt.BUBBLE_CLASS),this.applyCustomStyles(r,t,!1,n==null?void 0:n[R]),(g=(u=this.avatar)==null?void 0:u.getAvatarContainer(r.innerContainer))==null||g[f].add("loading-avatar-container"),!this.focusMode&&z.isScrollbarAtBottomOfElement(this.elementRef)&&z.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 vr(e),re.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee181(e,t){return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:return _context181.a(2,(this._hiddenAttachments=t,Promise.all((e||[]).map(function(n){return new Promise(function(s){if(!n[y]||n[y]===mn){var r=n[ne].name||ne;s(_defineProperty(_defineProperty({name:r},y,mn),"ref",n[ne]));}else{var _r8=new FileReader();_r8.readAsDataURL(n[ne]),_r8.onload=function(){var o=n[ne].name;s(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},T,_r8.result),"name",o),y,n[y]),"ref",n[ne]));};}});}))));}},_callee181,this);}));function addMultipleFiles(_x343,_x344){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
|
|
214
|
+
function clearMessages(e,t){var _this$messageToElemen2;var r,o,a,c;var n=[];this.messageElementRefs.forEach(function(l){it.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($s)&&l.remove();}),this.messageElementRefs=n;var s=this.messageToElements.filter(function(l){return l[1][h]&&it.isActiveElement(l[1][h].bubbleElement[f])||l[1][L]&&it.isActiveElement(l[1][L].bubbleElement[f]);});(_this$messageToElemen2=this.messageToElements).splice.apply(_this$messageToElemen2,[0,this.messageToElements.length].concat(_toConsumableArray(s))),t!==!1&&((r=this._introPanel)!=null&&r._elementRef&&this._introPanel.display(),this.addIntroductoryMessages()),(o=this.browserStorage)==null||o.clear(),(a=this.scrollButton)==null||a.clearHidden(),(c=this._onClearMessages)==null||c.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref254;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===U?!1:!!e.displayLoadingBubble:(_ref254=_typeof(e.displayLoadingBubble)===U||e.displayLoadingBubble)!==null&&_ref254!==void 0?_ref254:!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(vt.BUBBLE_CLASS)||e.contains(Dt.CLASS)||e.contains(gt.MESSAGE_CLASS):!1;}}]);}(ot);var is=/*#__PURE__*/function(){function is(){_classCallCheck(this,is);}return _createClass(is,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t[Hn].length>0&&e[f].add("text-input-inner-start-adjustment"),t[_t].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(to),t[f].add(to)):n[Pe].length===0&&n[ve].length>0&&(e[3][f].add(no),t[f].add(no));}// when submit is the only button
|
|
212
215
|
// when submit button is outside by itself - we increase the height for a better look
|
|
213
|
-
},{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,n){if(!(n[
|
|
214
|
-
},{key:"set",value:function set(e,t,n,s){!!
|
|
215
|
-
function fe(e,t,n,s){var _this90;_classCallCheck(this,fe);var c,l,d,
|
|
216
|
-
},{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,
|
|
217
|
-
},{key:"focusSiblingItem",value:function focusSiblingItem(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var r=s?t:t[n?"nextSibling":"previousSibling"];r?(t.dispatchEvent(new MouseEvent(
|
|
218
|
-
},{key:"addWindowEvents",value:function addWindowEvents(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener(
|
|
219
|
-
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var n,s,r;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===
|
|
220
|
-
function addToDropup(e,t,n,s){var r=new
|
|
221
|
-
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=
|
|
222
|
-
},{key:"addButtons",value:function addButtons(e,t,n,s){var r=Ne.generatePositionToButtons(t);return Ne.addToSideContainer(e,r),r[et].length>0&&Ne.addToDropup(e,r,n,s),r;}}]);}();var Sh="<?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>",xh="<?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",Ah="<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>",wh="<?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",Ch=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},ee,{id:"upload-images-icon",svgString:xh,dropupText:"Image"}),Cn,{id:"upload-gifs-icon",svgString:wh,dropupText:"GIF"}),$,{id:"upload-audio-icon",svgString:Ah,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:Sh,dropupText:"File"});var Ai=/*#__PURE__*/function(_gn4){function Ai(e){var _this97;_classCallCheck(this,Ai);(e==null?void 0:e.position)===et&&(e.position=ve);var t=ut.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this97=_callSuper(this,Ai,[Ai.createMicrophoneElement(),sa,e==null?void 0:e.position,t,e]),_this97.isActive=!1,_this97._innerElements=_this97.createInnerElementsForStates(_this97.customStyles),_this97.changeToDefault();return _this97;}_inherits(Ai,_gn4);return _createClass(Ai,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},w,this.createInnerElements(t,w,e)),H,this.createInnerElements(t,H,e)),Un,this.createInnerElements(t,Un,e)),bn,this.createInnerElements(t,bn,e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements[H]),this.toggleIconFilter(H),this.reapplyStateStyle(H,[w,bn]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[w]),this.toggleIconFilter(w),this.reapplyStateStyle(w,[H,bn]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements[bn]),this.toggleIconFilter("command"),this.reapplyStateStyle(bn,[H]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements[Un]),this.elementRef[m].add("".concat(Un,"-microphone")),this.reapplyStateStyle(Un,[H]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()===G)switch(e){case w:t[m].remove("active-microphone-icon","command-microphone-icon"),t[m].add("default-microphone-icon");break;case H:t[m].remove("default-microphone-icon","command-microphone-icon"),t[m].add("active-microphone-icon");break;case"command":t[m].remove("active-microphone-icon","default-microphone-icon"),t[m].add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=A();return e.id="microphone-button",e[m].add("input-button"),e;}}]);}(gn);function Th(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i["default"]:i;}var js={},qn={},Gn={},zn={},Vn={},lo;function wi(){if(lo)return Vn;lo=1,Object.defineProperty(Vn,"__esModule",{value:!0}),Vn.Text=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"capitalize",value:function capitalize(t){return t.replace(i.FIRST_CHAR_REGEX,function(n){return n.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(t){return t.replace(i.DOUBLE_LINE,"<p></p>").replace(i.ONE_LINE,"<br>");}},{key:"isCharDefined",value:function isCharDefined(t){return t!==void 0&&t!==" "&&t!==" "&&t!=="\n"&&t!=="";}},{key:"breakupIntoWordsArr",value:function breakupIntoWordsArr(t){return t.split(/(\W+)/);}}]);}();return Vn.Text=i,i.FIRST_CHAR_REGEX=/\S/,i.DOUBLE_LINE=/\n\n/g,i.ONE_LINE=/\n/g,Vn;}var ho;function ha(){if(ho)return zn;ho=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.Translate=void 0;var i=wi();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"translate",value:function translate(n,s){var r=i.Text.breakupIntoWordsArr(n);for(var o=0;o<r.length;o+=1)s[r[o]]&&(r[o]=s[r[o]]);return r.join("");}}]);}();return zn.Translate=e,zn;}var uo;function Rh(){if(uo)return Gn;uo=1,Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.WebSpeechTranscript=void 0;var i=ha();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:function extract(n,s,r){var o="";for(var a=n.resultIndex;a<n.results.length;++a){var c=n.results[a][0].transcript;r&&(c=i.Translate.translate(c,r)),n.results[a].isFinal?s+=c:o+=c;}return{interimTranscript:o,finalTranscript:s,newText:o||s};}},{key:"extractSafari",value:function extractSafari(n,s,r){var o="";for(var c=n.resultIndex;c<n.results.length;++c){var l=n.results[c][0].transcript;r&&(l=i.Translate.translate(l,r)),o+=l;}return{interimTranscript:"",finalTranscript:o,newText:o};}}]);}();return Gn.WebSpeechTranscript=e,Gn;}var Kn={},po;function Tr(){if(po)return Kn;po=1,Object.defineProperty(Kn,"__esModule",{value:!0}),Kn.Browser=void 0;var i=/*#__PURE__*/_createClass(function i(){_classCallCheck(this,i);});return Kn.Browser=i,i.IS_SAFARI=function(){return i._IS_SAFARI===void 0&&(i._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),i._IS_SAFARI;},Kn;}var Wn={},Xn={},fo;function Ih(){if(fo)return Xn;fo=1,Object.defineProperty(Xn,"__esModule",{value:!0}),Xn.EventListeners=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(t,n){return Array.isArray(t)?t.find(function(s){return n===s;}):n===t?t:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(t){var _this98=this;t.element&&i.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(i.KEY_DOWN_TIMEOUT!==null&&clearTimeout(i.KEY_DOWN_TIMEOUT),i.KEY_DOWN_TIMEOUT=setTimeout(function(){i.KEY_DOWN_TIMEOUT=null,_this98.resetRecording(t);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(t,n){this.mouseDownElement=i.getElementIfFocusedOnAvailable(t,n.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0;}},{key:"add",value:function add(t,n){var s=(n==null?void 0:n.insertInCursorLocation)===void 0||(n==null?void 0:n.insertInCursorLocation);n!=null&&n.element&&s&&(t.mouseDownEvent=i.mouseDownWindow.bind(t,n.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=i.mouseUpWindow.bind(t,n),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=i.keyDownWindow.bind(t,n),document.addEventListener("keydown",t.keyDownEvent));}},{key:"remove",value:function remove(t){document.removeEventListener("mousedown",t.mouseDownEvent),document.removeEventListener("mouseup",t.mouseUpEvent),document.removeEventListener("keydown",t.keyDownEvent);}}]);}();return Xn.EventListeners=i,i.KEY_DOWN_TIMEOUT=null,Xn;}var Zn={},mo;function Mh(){if(mo)return Zn;mo=1,Object.defineProperty(Zn,"__esModule",{value:!0}),Zn.PreResultUtils=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"process",value:function process(t,n,s,r,o){var a=r==null?void 0:r(n,s);return a?(setTimeout(function(){a.restart?t.resetRecording(o):a.stop&&t.stop();}),(a.stop||a.restart)&&a.removeNewText):!1;}}]);}();return Zn.PreResultUtils=i,Zn;}var Yn={},Jn={},go;function ua(){if(go)return Jn;go=1,Object.defineProperty(Jn,"__esModule",{value:!0}),Jn.AutoScroll=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(t,n){n&&!t.isCursorAtEnd&&(t.endPadding="",t.scrollingSpan.innerHTML=" ");}},{key:"scrollGeneric",value:function scrollGeneric(t,n){t.isCursorAtEnd?n.scrollTop=n.scrollHeight:t.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
|
|
216
|
+
},{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,n){if(!(n[Hn].length>0||n[_t].length>0)){if(n[ve].length===0&&n[Pe].length>0)return e[0][f].add(Qr),t[f].add(Qr),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(eo),t[f].add(eo),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 Gn=/*#__PURE__*/function(){function Gn(){_classCallCheck(this,Gn);}return _createClass(Gn,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var n=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===Hn?1:e===_t?2:3;}},{key:"addButton",value:function addButton(e,t,n){t[f].add(n);var s=Gn.getContainerIndex(n);e[s].appendChild(t),s===3&&t[f].add(ve);}}]);}();var so=["camera","gifs","images","audio","mixedFiles",at,"microphone"],Zh="<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(As,function(n){e.highlightedItem=n.target;}),t.addEventListener(bn,function(){e.highlightedItem=void 0;});}},{key:"addItemEvents",value:function addItemEvents(e,t,n,s){Nt.add(t,s),t.addEventListener(Y,function(){n[Y]();}),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,r=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[G])==null?void 0:u.content)==="";});c[f].contains(Ct.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(r,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 r=t.elementRef;if(t.isCustom)t.setDropupItem(e,s);else{var a=le.processStateful((n==null?void 0:n.item)||{});Me.addItemEvents(e,s,r,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 ft=Me;var fe=/*#__PURE__*/function(_wn2){// prettier-ignore
|
|
218
|
+
function fe(e,t,n,s){var _this90;_classCallCheck(this,fe);var c,l,d,u,g,b;var r=((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=Zh,a=bt.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this90=_callSuper(this,fe,[fe.createButtonElement(),o,e==null?void 0:e.position,a,((g=e==null?void 0:e[R])==null?void 0:g.button)||a&&{},r]),_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(fe,_wn2);return _createClass(fe,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="custom-icon",n=this.createInnerElements(t,A,e);return _defineProperty(_defineProperty(_defineProperty({},A,n),H,this.genStateInnerElements(t,H,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===H&&_this91.changeToActive(),t===j&&_this91.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this92=this;z.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===H||t===j)&&_this92.changeState(t);});}},{key:"changeState",value:function changeState(e,t){e===j?this.changeToDisabled(t):e===H?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(ft.TEXT_CLASS);});_n16&&Object.assign(_n16[E],e[h]);}if(e!=null&&e.iconContainer){var _n17=t.find(function(s){return s[f].contains(ft.ICON_CLASS);});_n17&&Object.assign(_n17[E],e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var n,s,r;this.elementRef=re.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((n=e==null?void 0:e[G])==null?void 0:n.content)===""||this.elementRef.appendChild(ft.createItemIcon(this[G],(s=this._menuStyles)==null?void 0:s.iconContainer)),this.elementRef.appendChild(ft.createItemText(this.dropupText,(r=this._menuStyles)==null?void 0:r[h]));}},{key:"assignDropupItemStyle",value:function assignDropupItemStyle(e,t){var s;this.elementRef.parentElement&&this._originalElementRef&&this.resetDropupItem(t),ft.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=le.processStateful((e==null?void 0:e.item)||{});Nt.add(this.elementRef,n),this.addClickListener();}},{key:"changeToDefault",value:function changeToDefault(e){var t,n,s,r,o,a;!e&&this._state===A||(this.elementRef[f].contains(ft.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[H]&&xe.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[H]),(o=this.customStyles)!=null&&o[j]&&xe.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[j]),this.reapplyStateStyle(A,[H,j])),this.elementRef[f].remove(fe.DISABLED_CONTAINER_CLASS,fe.ACTIVE_CONTAINER_CLASS),this.elementRef[f].add(fe.DEFAULT_CONTAINER_CLASS),me.removeAriaDisabled(this.elementRef),this._state=A);}},{key:"changeToActive",value:function changeToActive(e){var t,n;!e&&this._state===H||(this.elementRef[f].contains(ft.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[H],(n=this.customStyles)==null?void 0:n[H]):(this.changeElementsByState(this._innerElements[H]),this.reapplyStateStyle(H,[j,A])),this.elementRef[f].remove(fe.DISABLED_CONTAINER_CLASS,fe.DEFAULT_CONTAINER_CLASS),this.elementRef[f].add(fe.ACTIVE_CONTAINER_CLASS),me.removeAriaDisabled(this.elementRef),this._state=H);}},{key:"changeToDisabled",value:function changeToDisabled(e){var t,n,s,r,o,a;!e&&this._state===j||(this.elementRef[f].contains(ft.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[H]&&xe.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[H]),(o=this.customStyles)!=null&&o[A]&&xe.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[A]),this.reapplyStateStyle(j,[A,H])),this.elementRef[f].remove(fe.ACTIVE_CONTAINER_CLASS,fe.DEFAULT_CONTAINER_CLASS),this.elementRef[f].add(fe.DISABLED_CONTAINER_CLASS),me.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 r=this.createInnerElements(e,t,s);var o=(l=(c=s==null?void 0:s[t])==null?void 0:c[G])==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(r),_=_ns$parseSVGTextEleme5.svg,v=_ns$parseSVGTextEleme5[h],C=[];fe.addToInnerElements(C,o,g,_),fe.addToInnerElements(C,a,b,v),r=C;}return r;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[f].add("input-button",fe.BUTTON_CLASS),e;}},{key:"addToInnerElements",value:function addToInnerElements(e,t,n,s){t===void 0&&n?e.push(n.cloneNode(!0)):s&&e.push(s);}},{key:"add",value:function add(e,t){var n=e.customButtons,s=e.focusInput,r=e.dropupStyles;n==null||n.forEach(function(o,a){var c={button:new fe(o,a+1,s,r==null?void 0:r.menu)};t["".concat(fe.INDICATOR_PREFIX).concat(a+1)]=c;});}}]);}(wn);fe.INDICATOR_PREFIX="custom",fe.BUTTON_CLASS="custom-button",fe.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",fe.DEFAULT_CONTAINER_CLASS="custom-button-container-default",fe.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var fn=fe;var Yh="<?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 ys=/*#__PURE__*/function(){function ys(){_classCallCheck(this,ys);}return _createClass(ys,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var n=e.elementRef,s=t?n.children[0]:n.children[n.children.length-1];ys.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 r=s?t:t[n?"nextSibling":"previousSibling"];r?(t.dispatchEvent(new MouseEvent(bn)),r.dispatchEvent(new MouseEvent(As)),r.focus()):(t.dispatchEvent(new MouseEvent(bn)),ys.focusItemWhenOnEdge(e,n));}}]);}();var Sr=/*#__PURE__*/function(){function Sr(e,t){var _this93=this;_classCallCheck(this,Sr);var n;this._isOpen=!0,this._styles=t,this.elementRef=Sr.createElement((n=this._styles)==null?void 0:n.container),this.close(),setTimeout(function(){return _this93.addWindowEvents(e);});}return _createClass(Sr,[{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=ft.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(Y,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(Y,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,r;!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(bn))):t.key===Ee.ENTER?((s=this.highlightedItem)==null||s[Y](),(r=this.highlightedItem)==null||r.dispatchEvent(new MouseEvent(bn))):t.key===Ee.ARROW_DOWN?ys.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],!0):t.key===Ee.ARROW_UP&&ys.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[0],!1));}}],[{key:"createElement",value:function createElement(e){var t=x();return t.id=st,Object.assign(t[E],e),t;}}]);}();var hn=/*#__PURE__*/function(_wn3){function hn(e,t){var _this94;_classCallCheck(this,hn);var r,o;var n=bt.tryCreateConfig("Options",(r=t==null?void 0:t.button)==null?void 0:r.tooltip);_this94=_callSuper(this,hn,[hn.createButtonElement(),Yh,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 Sr(e,t==null?void 0:t.menu),_this94.addClickEvent(),_this94.buttonContainer=hn.createButtonContainer(),_this94.changeElementsByState(s[R]),_this94.buttonContainer.appendChild(_this94.elementRef),_this94.elementRef[f].add(hn.BUTTON_ICON_CLASS),_this94.buttonContainer.appendChild(_this94._menu.elementRef),_this94.reapplyStateStyle(R),_this94.addContainerEvents(e);return _this94;}_inherits(hn,_wn3);return _createClass(hn,[{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(As));});};}},{key:"addItem",value:function addItem(e){this._menu.addItem(e);}},{key:"addContainerEvents",value:function addContainerEvents(e){var _this96=this;e.addEventListener(Y,function(t){var n=t.target[f];!n.contains(hn.BUTTON_ICON_CLASS)&&!n.contains(fn.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;}}]);}(wn);hn.BUTTON_ICON_CLASS="dropup-button";var oi=hn;var Be=/*#__PURE__*/function(){function Be(){_classCallCheck(this,Be);}return _createClass(Be,null,[{key:"addToDropup",value:// prettier-ignore
|
|
223
|
+
function addToDropup(e,t,n,s){var r=new oi(n,s);so.forEach(function(a){var c=t[st].findIndex(function(d){return d.buttonType===a;}),l=t[st][c];l&&(r.addItem(l.button),t[st].splice(c,1));}),t[st].forEach(function(_ref258){var a=_ref258.button;return r.addItem(a);});var o=oi.getPosition(t,s);Gn.addButton(e,r.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){[Hn,_t,Pe,ve].forEach(function(s){var r=s;t[r].forEach(function(o){Gn.addButton(e,o.button.elementRef,r);});});}},{key:"setPosition",value:function setPosition(e,t,n){var s=_objectSpread(_objectSpread({},e[t]),{},{buttonType:t});n.push(s),delete e[t];}},{key:"createPositionsToButtonsObj",value:function createPositionsToButtonsObj(){return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},st,[]),Pe,[]),Hn,[]),_t,[]),ve,[]);}// prettier-ignore
|
|
224
|
+
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Be.createPositionsToButtonsObj();Object.keys(e).forEach(function(s){var o;var r=(o=e[s])==null?void 0:o.button.position;r&&Be.setPosition(e,s,t[r]);}),t[_t].length===0&&e.submit&&Be.setPosition(e,at,t[_t]),t[ve].length===0&&(e.submit?Be.setPosition(e,at,t[ve]):e.microphone?Be.setPosition(e,pt,t[ve]):e.camera?Be.setPosition(e,Fe,t[ve]):e["".concat(fn.INDICATOR_PREFIX,"1")]&&Be.setPosition(e,"".concat(fn.INDICATOR_PREFIX,"1"),t[ve])),e.submit&&Be.setPosition(e,at,t[Pe].length===0?t[Pe]:t[_t]),e.microphone&&Be.setPosition(e,pt,t[Pe].length===0?t[Pe]:t[_t]);var n=Object.keys(e);return n.length>1||t[st].length>0?(so.forEach(function(s){e[s]&&t[st].push(_objectSpread(_objectSpread({},e[s]),{},{buttonType:s}));}),n.forEach(function(s){var r=s;r.startsWith(fn.INDICATOR_PREFIX)&&e[r]&&t[st].push(_objectSpread(_objectSpread({},e[r]),{},{customType:r}));})):n.length===1&&Be.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 r=Be.generatePositionToButtons(t);return Be.addToSideContainer(e,r),r[st].length>0&&Be.addToDropup(e,r,n,s),r;}}]);}();var Jh="<?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>",Qh="<?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",ed="<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>",td="<?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",nd=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},Q,{id:"upload-images-icon",svgString:Qh,dropupText:"Image"}),Bn,{id:"upload-gifs-icon",svgString:td,dropupText:"GIF"}),$,{id:"upload-audio-icon",svgString:ed,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:Jh,dropupText:"File"});var _i=/*#__PURE__*/function(_wn4){function _i(e){var _this97;_classCallCheck(this,_i);(e==null?void 0:e.position)===st&&(e.position=ve);var t=bt.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this97=_callSuper(this,_i,[_i.createMicrophoneElement(),Po,e==null?void 0:e.position,t,e]),_this97.isActive=!1,_this97._innerElements=_this97.createInnerElementsForStates(_this97.customStyles),_this97.changeToDefault();return _this97;}_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)),H,this.createInnerElements(t,H,e)),Zn,this.createInnerElements(t,Zn,e)),Cn,this.createInnerElements(t,Cn,e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements[H]),this.toggleIconFilter(H),this.reapplyStateStyle(H,[A,Cn]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[A]),this.toggleIconFilter(A),this.reapplyStateStyle(A,[H,Cn]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements[Cn]),this.toggleIconFilter("command"),this.reapplyStateStyle(Cn,[H]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements[Zn]),this.elementRef[f].add("".concat(Zn,"-microphone")),this.reapplyStateStyle(Zn,[H]);}},{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 H: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 rt=Ds;var er=/*#__PURE__*/function(){function er(){_classCallCheck(this,er);}return _createClass(er,null,[{key:"translate",value:function translate(e,t){var n=rt.breakupIntoWordsArr(e);for(var s=0;s<n.length;s+=1)t[n[s]]&&(n[s]=t[n[s]]);return n.join("");}}]);}();var io=/*#__PURE__*/function(){function io(){_classCallCheck(this,io);}return _createClass(io,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=er.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=er.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 jo=/*#__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 _this98=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,_this98.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);}}]);}();jo.KEY_DOWN_TIMEOUT=null;var ro=jo;var sd=/*#__PURE__*/function(){function sd(){_classCallCheck(this,sd);}return _createClass(sd,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
|
|
223
226
|
// they can only safely be scrolled to the end
|
|
224
|
-
},{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(
|
|
225
|
-
},{key:"setOffsetForPrimitive",value:function setOffsetForPrimitive(t,n
|
|
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&&Yt.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 r=0;r<e.childNodes.length;r+=1){var o=e.childNodes[r];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 _a8=document.createRange();_a8.setStart(o,t-n),_a8.collapse(!0);var c=window.getSelection();return c==null||c.removeAllRanges(),c==null||c.addRange(_a8),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
|
+
},{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
|
|
226
229
|
// private static getCursorOffsetFromLeft(inputElement: HTMLInputElement, position: number) {
|
|
227
230
|
// // Get the value of the input element up to the cursor position
|
|
228
231
|
// const valueUpToCursor = inputElement.value.substring(0, position);
|
|
@@ -239,39 +242,51 @@ function addToDropup(e,t,n,s){var r=new hi(n,s);co.forEach(function(a){var c=t[e
|
|
|
239
242
|
// document.body.removeChild(tempSpan);
|
|
240
243
|
// return {left: offsetWidth, top: offsetHeight};
|
|
241
244
|
// }
|
|
242
|
-
},{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(t,n
|
|
243
|
-
|
|
245
|
+
},{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(e,t,n){var s=0;if(t.rangeCount>0){var r=t.getRangeAt(0),o=r.cloneRange();o.selectNodeContents(e),n?o.setEnd(r.startContainer,r.startOffset):o.setEnd(r.endContainer,r.endOffset),s=o.toString().length;}return s;}// for input
|
|
246
|
+
// private static insertTextAtCursor(text: string, input: HTMLInputElement) {
|
|
247
|
+
// const startPos = input.selectionStart;
|
|
248
|
+
// const endPos = input.selectionEnd;
|
|
249
|
+
// if (startPos !== null && endPos !== null) {
|
|
250
|
+
// input.value = input.value.substring(0, startPos) + text + input.value.substring(endPos);
|
|
251
|
+
// input.selectionStart = input.selectionEnd = startPos + text.length;
|
|
252
|
+
// }
|
|
253
|
+
// }
|
|
254
|
+
}]);}();var qe=/*#__PURE__*/function(){function qe(){_classCallCheck(this,qe);}return _createClass(qe,null,[{key:"processCommand",value:function processCommand(e,t){return(!t||!t.caseSensitive)&&(e=e.toLowerCase()),(t==null?void 0:t.substrings)===!1?rt.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 r=e[s];return n[s]=typeof r=="string"?qe.processCommand(r,e.settings):r,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){qe.toggleCommandModeOff(e),Je.isPrimitiveElement(s)?(s.value=n,e.isTargetInShadow||Ue.setOffsetForPrimitive(s,n.length,!0),Es.IS_SAFARI()&&e.autoScroll&&Yt.scrollSafariPrimitiveToEnd(s)):(s.textContent=n,e.isTargetInShadow||Ue.focusEndOfGeneric(s),setTimeout(function(){return Yt.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 r=n.length-1;r>=0;r-=1){var o=r,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,r){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=rt.breakupIntoWordsArr(d),g=((a=l.settings)==null?void 0:a.substrings)===!1?qe.checkIfMatchesWord:qe.checkIfMatchesSubstring;if(l.commandMode&&g(l.commandMode,d,u))return e.setInterimColorToFinal(),setTimeout(function(){return qe.toggleCommandModeOn(e);}),{doNotProcessTranscription:!1};if(!(l.commandMode&&!e.isWaitingForCommand)){if(l.stop&&g(l.stop,d,u))return qe.toggleCommandModeOff(e),setTimeout(function(){return e.stop();}),{doNotProcessTranscription:!1};if(l.pause&&g(l.pause,d,u))return qe.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),qe.toggleCommandModeOff(e),e.resetRecording(n),{doNotProcessTranscription:!0};if(l.reset&&g(l.reset,d,u))return r!==void 0&&qe.setText(e,n,r,s),{doNotProcessTranscription:!0};if(l.removeAllText&&g(l.removeAllText,d,u))return qe.setText(e,n,"",s),{doNotProcessTranscription:!0};}}}]);}();var Fn=/*#__PURE__*/function(){function Fn(){_classCallCheck(this,Fn);}return _createClass(Fn,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),r=Ue.getGenericElementCursorOffset(t,n,!1);e.isHighlighted=s!==r;}}},{key:"setState",value:function setState(e,t){document.activeElement===t&&(Je.isPrimitiveElement(t)?Fn.setStateForPrimitive(e,t):Fn.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,r=t.value;if(n&&s){var o=r.substring(0,n)+r.substring(s);t.value=o,Ue.setOffsetForPrimitive(t,n,e.autoScroll);}e.isHighlighted=!1;}}]);}();var Un=/*#__PURE__*/function(){function Un(){_classCallCheck(this,Un);}return _createClass(Un,null,[{key:"setStateForPrimitiveElement",value:function setStateForPrimitiveElement(e,t){if(document.activeElement===t&&t.selectionStart!==null){var s=t.selectionStart,r=t.value[s-1],o=t.selectionEnd===null?s:t.selectionEnd,a=t.value[o];rt.isCharDefined(r)&&(e.startPadding=" ",e.numberOfSpacesBeforeNewText=1),rt.isCharDefined(a)&&(e.endPadding=" ",e.numberOfSpacesAfterNewText=1),e.isCursorAtEnd=t.value.length===o;return;}var n=t.value[t.value.length-1];rt.isCharDefined(n)&&(e.startPadding=" ",e.numberOfSpacesBeforeNewText=1),e.isCursorAtEnd=!0;}},{key:"setStateForGenericElement",value:function setStateForGenericElement(e,t){var n,s,r;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];rt.isCharDefined(l)&&(e.startPadding=" "),rt.isCharDefined(u)&&(e.endPadding=" "),e.isCursorAtEnd=((r=t.textContent)==null?void 0:r.length)===d;return;}}var o=t.innerText.charAt(t.innerText.length-1);rt.isCharDefined(o)&&(e.startPadding=" "),e.isCursorAtEnd=!0;}},{key:"setState",value:function setState(e,t){Je.isPrimitiveElement(t)?Un.setStateForPrimitiveElement(e,t):Un.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 $o=/*#__PURE__*/function(){// this is mostly used for Azure to prevent user from stopping when it is connecting
|
|
256
|
+
function $o(){_classCallCheck(this,$o);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($o,[{key:"prepareBeforeStart",value:function prepareBeforeStart(e){var t,n;if(e!=null&&e.element)if(ro.add(this,e),Array.isArray(e.element)){var s=e.element.find(function(r){return r===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=qe.process(this._options.commands));}},{key:"prepare",value:function prepare(e){Un.setState(this,e),Fn.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:
|
|
244
257
|
// unfortunately it did not work because the service would still continue firing the intermediate and final results
|
|
245
258
|
// into the new position
|
|
246
|
-
},{key:"resetRecording",value:function resetRecording(
|
|
247
|
-
},{key:"updateElements",value:function updateElements(
|
|
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 r=rt.capitalize(t);if(this.finalTranscript===r&&e==="")return;sd.process(this,n,e==="",this._onPreResult,this._options)&&(e="",n="");var o=this.commands&&qe.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=r,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
|
|
248
261
|
// remember that padding values here contain actual text left and right
|
|
249
|
-
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
function
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
function
|
|
258
|
-
|
|
259
|
-
function
|
|
262
|
+
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(e,t,n){this.isHighlighted&&Fn.removeForPrimitive(this,e),this.primitiveTextRecorded||Un.adjustStateAfterRecodingPrimitiveElement(this,e),n&&Un.adjustSateForNoTextPrimitiveElement(this);var s=this.startPadding+this.finalTranscript+t;if(e.value=s+this.endPadding,!this.isTargetInShadow){var r=s.length+this.numberOfSpacesAfterNewText;Ue.setOffsetForPrimitive(e,r,this.autoScroll);}this.autoScroll&&Es.IS_SAFARI()&&this.isCursorAtEnd&&Yt.scrollSafariPrimitiveToEnd(e);}},{key:"updateGenericElement",value:function updateGenericElement(e,t,n){this.isHighlighted&&Fn.removeForGeneric(this,e),this.spansPopulated||Je.appendSpans(this,e);var s=(n?"":this.startPadding)+rt.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=s;var r=Yt.isRequired(this.autoScroll,e);Yt.changeStateIfNeeded(this,r);var o=rt.lineBreak(t)+(n?"":this.endPadding);this.interimSpan.innerHTML=o,Es.IS_SAFARI()&&this.insertInCursorLocation&&Ue.setOffsetForSafariGeneric(e,s.length+o.length),r&&Yt.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),ro.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 _s=/*#__PURE__*/function(_$o){function _s(){_classCallCheck(this,_s);return _callSuper(this,_s);}_inherits(_s,_$o);return _createClass(_s,[{key:"start",value:function start(e){var t;this._extractText===void 0&&(this._extractText=Es.IS_SAFARI()?io.extractSafari:io.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 _s.getAPI()?!0:(this.error("Speech Recognition is unsupported"),!1);}},{key:"instantiateService",value:function instantiateService(e){var _ref261;var t;var n=_s.getAPI();this._service=new n(),this._service.continuous=!0,this._service.interimResults=(_ref261=e==null?void 0:e.displayInterimResults)!==null&&_ref261!==void 0?_ref261:!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){Es.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;}}]);}($o);var qo=/*#__PURE__*/function(){function Us(){_classCallCheck(this,Us);}return _createClass(Us,null,[{key:"doubleClickDetector",value:function doubleClickDetector(){return Us.doubleClickPending?!0:(Us.doubleClickPending=!0,setTimeout(function(){Us.doubleClickPending=!1;},300),!1);}}]);}();qo.doubleClickPending=!1;var lt=qo;var oo=/*#__PURE__*/function(){function oo(){_classCallCheck(this,oo);}return _createClass(oo,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 Ii="https://github.com/OvidijusParsiunas/speech-to-element";var vs=/*#__PURE__*/function(){function vs(){_classCallCheck(this,vs);}return _createClass(vs,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(Ii)),!1):t.region?!0:(e("Please define a 'region' property - more info: ".concat(Ii)),!1):(e("Please provide subscription details - more info: ".concat(Ii)),!1);}},{key:"getNewSpeechConfig",value:function(){var _getNewSpeechConfig=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee182(e,t){return _regenerator().w(function(_context182){while(1)switch(_context182.n){case 0:if(!t.region){_context182.n=1;break;}return _context182.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 _context182.a(2);}},_callee182);}));function getNewSpeechConfig(_x345,_x346){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 _callee183(e,t){var n;return _regenerator().w(function(_context183){while(1)switch(_context183.n){case 0:_context183.n=1;return vs.getNewSpeechConfig(e,t);case 1:n=_context183.v;return _context183.a(2,(n&&vs.process(n,t),n));}},_callee183);}));function get(_x347,_x348){return _get2.apply(this,arguments);}return get;}()}]);}();var Go=/*#__PURE__*/function(){function Hs(){_classCallCheck(this,Hs);}return _createClass(Hs,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||Hs.DEFAULT_MS,Hs.stop(e),Hs.set(e);}},{key:"stop",value:function stop(e){e.stopTimeout&&clearTimeout(e.stopTimeout);}}]);}();Go.DEFAULT_MS=2e4;var Ns=Go;var id=/*#__PURE__*/function(){function id(){_classCallCheck(this,id);}return _createClass(id,null,[{key:"get",value:function get(e,t){return t?e.fromMicrophoneInput(t):e.fromDefaultMicrophoneInput();}}]);}();var ao=/*#__PURE__*/function(){function ao(){_classCallCheck(this,ao);}return _createClass(ao,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=er.translate(e,s)),n?{interimTranscript:"",finalTranscript:t+e,newText:e}:{interimTranscript:e,finalTranscript:t,newText:e};}}]);}();var ai=/*#__PURE__*/function(_$o2){function ai(){var _this100;_classCallCheck(this,ai);_this100=_callSuper(this,ai,arguments),_this100._newTextPadding="";return _this100;}// Unlike webspeech there is no automatic space between final results
|
|
265
|
+
_inherits(ai,_$o2);return _createClass(ai,[{key:"start",value:function start(e,t){this._newTextPadding="",this.stopTimeout===void 0&&Ns.reset(this,e==null?void 0:e.stopAfterSilenceMs),this.prepareBeforeStart(e),this.startAsync(e),t||oo.applyPrevention(this);}},{key:"startAsync",value:function(){var _startAsync=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee184(e){var t,_t57;return _regenerator().w(function(_context184){while(1)switch(_context184.n){case 0:_t57=this.validate(e);if(!_t57){_context184.n=2;break;}_context184.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 _context184.a(2);}},_callee184,this);}));function startAsync(_x349){return _startAsync.apply(this,arguments);}return startAsync;}()},{key:"validate",value:function validate(e){return ai.getAPI()?vs.validateOptions(this.error.bind(this),e):(this.moduleNotFound(),!1);}},{key:"instantiateService",value:function(){var _instantiateService=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee185(e){var t,n,s,r,_e$autoLanguage,o,a,c,l;return _regenerator().w(function(_context185){while(1)switch(_context185.n){case 0:t=ai.getAPI();n=id.get(t.AudioConfig,e.deviceId);_context185.n=1;return vs.get(t.SpeechConfig,e);case 1:s=_context185.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),r=t.SpeechRecognizer.FromConfig(s,l,n);}else r=new t.SpeechRecognizer(s,n);this.setEvents(r),this._service=r,e.retrieveToken&&this.retrieveTokenInterval(e.retrieveToken);}else this.error("Unable to contact Azure server");case 2:return _context185.a(2);}},_callee185,this);}));function instantiateService(_x350){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 _ao$extract=ao.extract(this._newTextPadding+t.result.text,this.finalTranscript,!1,this._translations),n=_ao$extract.interimTranscript,s=_ao$extract.finalTranscript,r=_ao$extract.newText;Ns.reset(this,this.stopTimeoutMS),this.updateElements(n,s,r);}// 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 _ao$extract2=ao.extract(this._newTextPadding+n.text,this.finalTranscript,!0,this._translations),s=_ao$extract2.interimTranscript,r=_ao$extract2.finalTranscript,o=_ao$extract2.newText;Ns.reset(this,this.stopTimeoutMS),this.updateElements(s,r,o),r!==""&&(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(){oo.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(),Ns.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;}}]);}($o);var Bt=/*#__PURE__*/function(){function Bt(){_classCallCheck(this,Bt);}return _createClass(Bt,null,[{key:"toggle",value:function toggle(e,t){var n,s;var r=e.toLocaleLowerCase().trim();(n=lt.service)!=null&&n.recognizing?this.stop():r==="webspeech"?Bt.startWebSpeech(t):r==="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()||(lt.service=new _s(),lt.service.start(e));}},{key:"isWebSpeechSupported",value:function isWebSpeechSupported(){return!!_s.getAPI();}},{key:"startAzure",value:function startAzure(e){var t;Bt.stop()||(t=lt.service)!=null&&t.cannotBeStopped||(lt.service=new ai(),lt.service.start(e));}},{key:"stop",value:function stop(){var e;return lt.doubleClickDetector()?!0:((e=lt.service)!=null&&e.recognizing&<.service.stop(),!1);}},{key:"endCommandMode",value:function endCommandMode(){lt.service&&qe.toggleCommandModeOff(lt.service);}}]);}();var rd=/*#__PURE__*/function(){function rd(e,t){_classCallCheck(this,rd);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(rd,[{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,Ss.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(_i2){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),r=_this103$processConfi.serviceName,o=_this103$processConfi.processedConfig;if(_this103._addErrorMessage=n,r==="webspeech"&&!Bt.isWebSpeechSupported())_this103.changeToUnsupported();else{var a=!e.textInput||!e.textInput[j];z.assignButtonEvents(_this103.elementRef,_this103.buttonClick.bind(_this103,t,a,r,o));}setTimeout(function(){_this103._validationHandler=e._validationHandler;});return _this103;}// prettier-ignore
|
|
268
|
+
_inherits(us,_i2);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:{},r=n.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_n$displayInterimResu=n.displayInterimResults)!==null&&_n$displayInterimResu!==void 0?_n$displayInterimResu:void 0,textColor:(_n$textColor=n.textColor)!==null&&_n$textColor!==void 0?_n$textColor:void 0,translations:(_n$translations=n.translations)!==null&&_n$translations!==void 0?_n$translations:void 0,commands:(_n$commands=n.commands)!==null&&_n$commands!==void 0?_n$commands:void 0,events:(_n$events=n.events)!==null&&_n$events!==void 0?_n$events:void 0},s),r),a=(l=n.commands)==null?void 0:l.submit;return a&&(o.onPreResult=function(d){return d.toLowerCase().includes(a)?(setTimeout(function(){var u;return(u=e.submit)==null?void 0:u.call(e);}),Bt.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),n.submitAfterSilence&&(this._silenceSubmit=new rd(n.submitAfterSilence,n.stopAfterSubmit)),{serviceName:us.getServiceName(n),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,n,s){var _this104=this;var r=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=r==null?void 0:r.onStart)==null||o.call(r);},onStop:function onStop(){var o,a,c;(o=_this104._validationHandler)==null||o.call(_this104),(a=_this104._silenceSubmit)==null||a.clearSilenceTimeout(),_this104.changeToDefault(),(c=r==null?void 0:r.onStop)==null||c.call(r);},onPauseTrigger:function onPauseTrigger(o){var a,c;(a=_this104._silenceSubmit)==null||a.onPause(o,e,_this104.elementRef.onclick),(c=r==null?void 0:r.onPauseTrigger)==null||c.call(r,o);},onPreResult:function onPreResult(o,a){var c;(c=r==null?void 0:r.onPreResult)==null||c.call(r,o,a);},onResult:function onResult(o,a){var c,l,d;a&&((c=_this104._validationHandler)==null||c.call(_this104)),(l=_this104._silenceSubmit)==null||l.resetSilenceTimeout(e,_this104.elementRef.onclick),(d=r==null?void 0:r.onResult)==null||d.call(r,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this104.onCommandModeTrigger(o),(a=r==null?void 0:r.onCommandModeTrigger)==null||a.call(r,o);}},s));}},{key:"onCommandModeTrigger",value:function onCommandModeTrigger(e){e?this.changeToCommandMode():this.changeToActive();}},{key:"onError",value:function onError(){this._addErrorMessage("speechToText","speech input error");}}],[{key:"getServiceName",value:function getServiceName(e){return e.azure?"azure":"webspeech";}},{key:"toggleSpeechAfterSubmit",value:function toggleSpeechAfterSubmit(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;e[Y](),t||setTimeout(function(){return e[Y]();},us.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(_i);us.MICROPHONE_RESET_TIMEOUT_MS=300;var Ss=us;var Pt=/*#__PURE__*/function(){// prettier-ignore
|
|
269
|
+
function Pt(e,t,n,s,r){var _this105=this;_classCallCheck(this,Pt);this._attachments=[],this._fileCountLimit=99,this._acceptedFormat="",this._hiddenAttachments=/* @__PURE__ */new Set(),n.maxNumberOfFiles&&(this._fileCountLimit=n.maxNumberOfFiles),this._toggleContainerDisplay=s,this._fileAttachmentsContainerRef=r,n.acceptedFormats&&(this._acceptedFormat=n.acceptedFormats),setTimeout(function(){_this105._validationHandler=e._validationHandler,_this105._onInput=t.onInput;});}return _createClass(Pt,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var n;return Pt.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=Pt.getTypeFromBlob(e);if(s===K){var r=Pt.createImageAttachment(t);this.addFileAttachment(e,K,r,n);}else if(s===$){var _r9=xs.createAudioAttachment(t);this.addFileAttachment(e,$,_r9,n);}else{var _r0=Pt.createAnyFileAttachment(e.name);this.addFileAttachment(e,mn,_r0,n);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,n,s){var a;var r=Pt.createContainer(n);if(this._attachments.length>=this._fileCountLimit){var c=this._attachments[this._attachments.length-1].removeButton;c==null||c[Y]();var l=this._fileAttachmentsContainerRef.children;this._fileAttachmentsContainerRef.insertBefore(r,l[0]);}else this._fileAttachmentsContainerRef.appendChild(r);var o={file:e,attachmentContainerElement:r,fileType:t};return s&&(o.removeButton=this.createRemoveAttachmentButton(o),r.appendChild(o.removeButton)),this._toggleContainerDisplay(!0),this._attachments.push(o),this._fileAttachmentsContainerRef.scrollTop=this._fileAttachmentsContainerRef.scrollHeight,(a=this._validationHandler)==null||a.call(this),o;}},{key:"createRemoveAttachmentButton",value:function createRemoveAttachmentButton(e){var t=x();t[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 r,o;var n=this._attachments.findIndex(function(a){return a===e;});if(n<0)return;(r=this._onInput)==null||r.call(this,!!(t!=null&&t.isTrusted));var s=this._attachments[n].attachmentContainerElement;this._attachments.splice(n,1),xs.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[Y]();}),_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[Y]();});}),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 r=n[s].trim();if(e[y]===r)return!0;if(r.startsWith(".")){var o=r.slice(1);if(e.name.endsWith(o))return!0;}else{if(e.name.endsWith(r))return!0;if(r.endsWith("/*")&&e[y].startsWith(r.slice(0,-2)))return!0;}}return!1;}},{key:"getTypeFromBlob",value:function getTypeFromBlob(e){var t=e.type;return t.startsWith(K)?K:t.startsWith($)?$:mn;}},{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"),Ge.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 kt=/*#__PURE__*/function(_Pt){// prettier-ignore
|
|
270
|
+
function kt(e,t,n,s,r){_classCallCheck(this,kt);return _callSuper(this,kt,[e,t,n,s,r]);}_inherits(kt,_Pt);return _createClass(kt,[{key:"createTimer",value:function createTimer(e,t){var _this108=this;var n=0;var s=t!==void 0&&t<kt.TIMER_LIMIT_S?t:kt.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 r=Math.floor(n/60),o=(n%60).toString().padStart(2,"0");e.textContent="".concat(r,":").concat(o);},1e3);}},{key:"createPlaceholderAudioAttachment",value:function createPlaceholderAudioAttachment(e){var t=kt.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 r=Ft.createSVGElement(ji);return r[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,r,s),t;}},{key:"addPlaceholderAudioAttachmentEvents",value:function addPlaceholderAudioAttachmentEvents(e,t,n){var _this109=this;var s=function s(){return e.replaceChildren(t);};e.addEventListener(As,s);var r=function r(){return e.replaceChildren(n);};e.addEventListener(bn,r);var o=function o(){var a;return(a=_this109.stopPlaceholderCallback)==null?void 0:a.call(_this109);};e.addEventListener(Y,o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var n=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),$,n,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
|
|
271
|
+
},{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[ne]=e,kt.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"),Ge.IS_SAFARI&&e[f].add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var n=e.parentElement?z.cloneElement(e):e,s=x($);s[T]=t;var r=Ft.createSVGElement(No);r[f].add("attachment-icon","play-icon");var o=Ft.createSVGElement(ji);o[f].add("attachment-icon","stop-icon"),n.replaceChildren(r),s.onplay=function(){n.replaceChildren(o);},s.onpause=function(){n.replaceChildren(r),s.currentTime=0;},s.onended=function(){n.replaceChildren(r);},z.assignButtonEvents(n,function(){s.paused?s.play():s.pause();});}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=kt.createAudioContainer();return kt.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][Y]();}}]);}(Pt);kt.TIMER_LIMIT_S=5999;var xs=kt;var od=/*#__PURE__*/function(){function od(){_classCallCheck(this,od);}return _createClass(od,null,[{key:"create",value:// prettier-ignore
|
|
272
|
+
function create(e,t,n,s,r,o){return o===$?new xs(e,t,n,s,r):new Pt(e,t,n,s,r);}}]);}();var Ts=/*#__PURE__*/function(){function Ts(e,t,n){_classCallCheck(this,Ts);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(Ts,[{key:"addType",value:function addType(e,t,n,s){var r=od.create(e,t,n,this.toggleContainerDisplay.bind(this),this.elementRef,s);return this._fileAttachmentsTypes.push(r),r;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=x();return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef[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 _callee187(){return _regenerator().w(function(_context187){while(1)switch(_context187.n){case 0:_context187.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref263=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee186(e){var t;return _regenerator().w(function(_context186){while(1)switch(_context186.n){case 0:return _context186.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee186);}));return function(_x351){return _ref263.apply(this,arguments);};}()));case 1:return _context187.a(2);}},_callee187,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){Ts.addFilesToType(e,this._fileAttachmentsTypes);}},{key:"hideFiles",value:function hideFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.hideAttachments();}),this.elementRef.replaceChildren(),this.toggleContainerDisplay(!1);}},{key:"removeHiddenFiles",value:function removeHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.removeAttachments();});}},{key:"readdHiddenFiles",value:function readdHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.readdAttachments();}),this.toggleContainerDisplay(!0);}},{key:"getNumberOfTypes",value:function getNumberOfTypes(){return this._fileAttachmentsTypes.length;}}],[{key:"addFilesToType",value:function addFilesToType(e,t){e.forEach(function(n){var s=new FileReader();s.readAsDataURL(n),s.onload=function(r){for(var o=0;o<t.length&&!t[o].attemptAddFile(n,r.target.result);o+=1);};});}}]);}();var ut=/*#__PURE__*/function(){function ut(e,t,n){_classCallCheck(this,ut);this._isOpen=!1,this._contentRef=ut.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=ut.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=ut.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=ut.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(ut,[{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){me.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";},ut.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?ut.createSVGButton(e):ut.createTextButton(e);return this.addButtons(s),z.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=Ft.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 r=new ut(e,["modal-content"],t[m].infoModal.containerStyle);return r.addCloseButton("OK",!1,n),r.openTextModal.bind(r,t.infoModalTextMarkUp||"");}}}]);}();ut.MODAL_CLOSE_TIMEOUT_MS=190;var dn=ut;var ci=/*#__PURE__*/function(_wn5){// prettier-ignore
|
|
274
|
+
function ci(e,t,n,s,r,o){var _this113;_classCallCheck(this,ci);var u,g,b,_,v,C,B,se,pe,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=bt.tryCreateConfig("Upload File",(v=n==null?void 0:n.button)==null?void 0:v.tooltip);_this113=_callSuper(this,ci,[ci.createButtonElement(),r,a,l,n.button,c]);var d=_this113.createInnerElementsForStates(s,_this113.customStyles);_this113._inputElement=ci.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=(B=n[m])==null?void 0:B.infoModal)==null?void 0:se.openModalOnce)===!1||(ie=(pe=n[m])==null?void 0:pe.infoModal)==null?void 0:ie.openModalOnce;return _this113;}_inherits(ci,_wn5);return _createClass(ci,[{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[Y]();}},{key:"import",value:function _import(e){Ts.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=dn.createTextModalFunc(e,t,n);this.elementRef.onclick=this[Y].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;}}]);}(wn);var Lt=/*#__PURE__*/function(){function Lt(){_classCallCheck(this,Lt);}return _createClass(Lt,null,[{key:"create",value:function create(e,t,n){var s=Lt.createElement(n);Lt.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(),Lt.display(e);},e.ondragleave=function(s){s.preventDefault(),Lt.hide(e);},e.ondragover=function(s){s.preventDefault();},e.ondrop=function(s){s.preventDefault(),Lt.uploadFile(n,s),Lt.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 sn=/*#__PURE__*/function(){function sn(){_classCallCheck(this,sn);}return _createClass(sn,null,[{key:"validate",value:// prettier-ignore
|
|
260
275
|
function validate(e,t,n,s,r,o,a){var c=n.isSubmitProgrammaticallyDisabled?!1:e(s,r,a);return c?t.changeToSubmitIcon():t.changeToDisabledIcon(),o==null||o.addInputText(s||""),c;}// prettier-ignore
|
|
261
|
-
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee188(e,t,n,s,r,o){var a,c,l;return _regenerator().w(function(_context188){while(1)switch(_context188.n){case 0:a=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context188.n=1;return n.completePlaceholders();case 1:c=n.getAllFileData(),l=c==null?void 0:c.map(function(d){return d[
|
|
262
|
-
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee189(e,t,n,s,r){var a,o;return _regenerator().w(function(_context189){while(1)switch(_context189.n){case 0:o=(a=t[
|
|
263
|
-
},{key:"attach",value:function attach(e,t,n,s,r,o){var a=e.validateInput||
|
|
264
|
-
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){
|
|
265
|
-
function
|
|
266
|
-
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,n,s,r,o,a,c,l,d;if(!((n=(t=this.customStyles)==null?void 0:t.submit)!=null&&n[G]||(o=(r=(s=this.customStyles)==null?void 0:s.loading)==null?void 0:r[G])!=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
|
|
267
|
-
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee193(e){var _this122=this;var t,r,o,a,c,n,s,_args193=arguments,_t59,_t60,_t61;return _regenerator().w(function(_context193){while(1)switch(_context193.n){case 0:t=_args193.length>1&&_args193[1]!==undefined?_args193[1]:!1;_context193.n=1;return(r=this._validationHandler)==null?void 0:r.call(this,t?e:void 0);case 1:_t59=_context193.v;_t60=!1;if(!(_t59===_t60)){_context193.n=2;break;}return _context193.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear()
|
|
268
|
-
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this123=this;this.elementRef[
|
|
269
|
-
},{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef[
|
|
270
|
-
function
|
|
271
|
-
},{key:"addButtonEvents",value:function addButtonEvents(e,t,n,s){var _this125=this;z.assignButtonEvents(e,this.capture.bind(this)),z.assignButtonEvents(t,this.stop.bind(this)),z.assignButtonEvents(n,function(){var r=_this125.getFile();r&&
|
|
272
|
-
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,n,s){var r=new
|
|
273
|
-
function addClickEvent(e,t,n,s){var r=
|
|
274
|
-
function createFileUploadComponents(e,t,n,s){var o,a,c,l;var r=new
|
|
275
|
-
}],[{key:"createPanelElement",value:function createPanelElement(e){var t=
|
|
276
|
-
},{key:"addElements",value:function addElements(e,t,n,s,r,o){z.addElements(e,t.elementRef);var a=Ln.create(),c=Ne.addButtons(a,n,s,o);fs.set(t.inputElementRef,a,r.elementRef,c),Ln.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[b]=o.map(function(l){return l[se];})),hn.onInput(e,c,r);});};}}]);}();var Mr=/*#__PURE__*/function(){function Mr(){_classCallCheck(this,Mr);}return _createClass(Mr,null,[{key:"createElements",value:function createElements(e,t,n){var s=A();s.id="chat-view";var r=!e.focusMode&&e.upwardsMode;s.classList.add(r?bh:gh);var o=new tt(e,t,n);t.websocket&&ke.createConnection(t,o);var a=new vn(e,o,t,s),c=r?o.elementRef.parentElement:o.elementRef;return z.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=Mr.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var Qh="#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 eu=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&&eu(e,t,s),s;};var P=/*#__PURE__*/function(_qi){function P(){var _this129;_classCallCheck(this,P);var e;_this129=_callSuper(this,P),_this129.getMessages=function(){return[];},_this129.submitUserMessage=function(){return console.warn(Ur("submitUserMessage"));},_this129.addMessage=function(){return console.warn(Ur("addMessage"));},_this129.updateMessage=function(){},_this129.clearMessages=function(){},_this129.focusInput=function(){return ln.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=A(),_this129._elementRef.id="container",_this129.attachShadow({mode:"open"}).appendChild(_this129._elementRef),(e=_this129.shadowRoot)==null||e.appendChild(ut.buildElement()),jt.apply(Qh,_this129.shadowRoot),setTimeout(function(){_this129._hasBeenRendered||_this129.onRender();},20);return _this129;}_inherits(P,_qi);return _createClass(P,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
|
277
|
-
},{key:"onRender",value:function onRender(){var _this$_childElement;var e;
|
|
276
|
+
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee188(e,t,n,s,r,o){var a,c,l;return _regenerator().w(function(_context188){while(1)switch(_context188.n){case 0:a=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context188.n=1;return n.completePlaceholders();case 1:c=n.getAllFileData(),l=c==null?void 0:c.map(function(d){return d[ne];});return _context188.a(2,sn.validate(e,s,r,a,l,o));}},_callee188);}));function useValidationFunc(_x352,_x353,_x354,_x355,_x356,_x357){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
|
|
277
|
+
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee189(e,t,n,s,r){var a,o;return _regenerator().w(function(_context189){while(1)switch(_context189.n){case 0:o=(a=t[m])==null?void 0:a.map(function(c){return c[ne];});return _context189.a(2,sn.validate(e,n,s,t[h],o,r,!0));}},_callee189);}));function useValidationFuncProgrammatic(_x358,_x359,_x360,_x361,_x362){return _useValidationFuncProgrammatic.apply(this,arguments);}return useValidationFuncProgrammatic;}()},{key:"validateWebsocket",value:function validateWebsocket(e,t){var n=e.websocket,s=e.connectSettings;return n&&s.url!==yt.URL&&!ke.canSendMessage(n)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
|
|
278
|
+
},{key:"attach",value:function attach(e,t,n,s,r,o){var a=e.validateInput||ce.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref265=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee190(c){var l;return _regenerator().w(function(_context190){while(1)switch(_context190.n){case 0:if(!(r.status.loadingActive||r.status.requestInProgress||!sn.validateWebsocket(t,r))){_context190.n=1;break;}return _context190.a(2,!1);case 1:l=a||t.canSendMessage;return _context190.a(2,l?c?sn.useValidationFuncProgrammatic(l,c,r,t,o):sn.useValidationFunc(l,n,s,r,t,o):null);}},_callee190);}));return function(_x363){return _ref265.apply(this,arguments);};}();}}]);}();var zo=/*#__PURE__*/function(){function zo(){_classCallCheck(this,zo);}return _createClass(zo,null,[{key:"getFileName",value:function getFileName(e,t){var n=/* @__PURE__ */new Date(),s=String(n.getHours()).padStart(2,"0"),r=String(n.getMinutes()).padStart(2,"0"),o=String(n.getSeconds()).padStart(2,"0");return"".concat(e,"-").concat(s,"-").concat(r,"-").concat(o,".").concat(t);}}]);}();var ad=/*#__PURE__*/function(_i3){function ad(e,t){var _this114;_classCallCheck(this,ad);var n,s;_this114=_callSuper(this,ad,[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,z.assignButtonEvents(_this114.elementRef,_this114.buttonClick.bind(_assertThisInitialized(_this114)));return _this114;}_inherits(ad,_i3);return _createClass(ad,[{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[Jt]();})["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=zo.getFileName(this._newFilePrefix||$,this._extension),s=new File([t],n,{type:t[y]}),r=new FileReader();r.readAsDataURL(s),r.onload=function(o){_this117._audioType.completePlaceholderAttachment(s,o.target.result);};}}]);}(_i);var cd="<?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 un=/*#__PURE__*/function(){function un(){_classCallCheck(this,un);}return _createClass(un,null,[{key:"resetSubmit",value:function resetSubmit(e,t){t?e.unsetCustomStateStyles([Ot,at]):e.unsetCustomStateStyles([Mi,Ot,at]),e.reapplyStateStyle(at);}},{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,[G,"styles",A]),e[t]=n;}// prettier-ignore
|
|
279
|
+
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){Le.setPropertyValueIfDoesNotExist(e,[at,"container",A,"backgroundColor"],""),Le.setPropertyValueIfDoesNotExist(e,[j,"container",A,"backgroundColor"],Vo),Le.setPropertyValueIfDoesNotExist(e.submit,[G,"styles",A,"filter"],""),Le.setPropertyValueIfDoesNotExist(e[j],[G,"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"),un.overwriteDefaultStyleWithSubmit(e,j);}},{key:"process",value:function process(e){var t=w(e||{});return un.overwriteDefaultStyleWithSubmit(t,Ot),un.overwriteDefaultStyleWithSubmit(t,Mi),e!=null&&e.alwaysEnabled||un.setUpDisabledButton(t),t;}}]);}();var rs=/*#__PURE__*/function(_wn6){// prettier-ignore
|
|
280
|
+
function rs(e,t,n,s,r,o){var _this118;_classCallCheck(this,rs);var a=un.process(e.submitButtonStyles),c=cd,l=bt.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=r,_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,_wn6);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=Ct.createCustomElements(at,this[G],this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(n){var s=n,r=Ct.createCustomElements(s,_this119[G],_this119.customStyles);r&&(t[s]=r);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return Ct.createCustomElements(j,this[G],this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
|
|
281
|
+
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,n,s,r,o,a,c,l,d;if(!((n=(t=this.customStyles)==null?void 0:t.submit)!=null&&n[G]||(o=(r=(s=this.customStyles)==null?void 0:s.loading)==null?void 0:r[G])!=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 _callee191(){var _this120=this;var e,t;return _regenerator().w(function(_context191){while(1)switch(_context191.n){case 0:_context191.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));}(Ge.IS_SAFARI||Ge.IS_MOBILE)&&setTimeout(function(){return yn.focusEndOfInput(_this120._textInput.inputElementRef);});case 2:return _context191.a(2);}},_callee191,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee192(e){var _this121=this;var t;return _regenerator().w(function(_context192){while(1)switch(_context192.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,Pt.getTypeFromBlob(n));})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this121.attemptSubmit(t,!0);});case 1:return _context192.a(2);}},_callee192);}));function programmaticSubmit(_x364){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 _callee193(e){var _this122=this;var t,r,o,a,c,n,s,_args193=arguments,_t59,_t60,_t61;return _regenerator().w(function(_context193){while(1)switch(_context193.n){case 0:t=_args193.length>1&&_args193[1]!==undefined?_args193[1]:!1;_context193.n=1;return(r=this._validationHandler)==null?void 0:r.call(this,t?e:void 0);case 1:_t59=_context193.v;_t60=!1;if(!(_t59===_t60)){_context193.n=2;break;}return _context193.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();Ge.IS_MOBILE&&setTimeout(function(){return _this122._textInput.inputElementRef.focus();});_t61=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t61){_context193.n=3;break;}_context193.n=3;return Gs.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context193.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);_context193.n=5;return this._serviceIO.callAPI(s,this._messages);case 5:(c=this._fileAttachments)==null||c.hideFiles();case 6:return _context193.a(2);}},_callee193,this);}));function attemptSubmit(_x365){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee194(_ref268){var e,t,n,s,_t62;return _regenerator().w(function(_context194){while(1)switch(_context194.n){case 0:e=_ref268.text,t=_ref268.files,n=_ref268.custom;s=_defineProperty(_defineProperty({},S,F),"custom",n);e&&(s[h]=e);_t62=t;if(!_t62){_context194.n=2;break;}_context194.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:s[m]=_context194.v;case 2:this._serviceIO.sessionId&&(s._sessionId=this._serviceIO.sessionId);Object.keys(s).length>0&&this._messages.addNewMessage(s);case 3:return _context194.a(2);}},_callee194,this);}));function addNewMessage(_x366){return _addNewMessage.apply(this,arguments);}return addNewMessage;}()},{key:"stopStream",value:function stopStream(){var e,t,n;(t=(e=this._serviceIO.streamHandlers).onAbort)==null||t.call(e),(n=this._stopClicked)==null||n.listener(),this._validationHandler&&this.resetSubmit(this._validationHandler);}},{key:"changeToStopIcon",value:function changeToStopIcon(){this._serviceIO.websocket||(this.elementRef[f].remove(Ps,Qn,Jn),me.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle(Mi,[Ot,at]),z.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),me.removeAriaDisabled(this.elementRef),this.elementRef[f].add(Ps),me.addAriaBusy(this.elementRef),this.reapplyStateStyle(Ot,[at]),z.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(Ps,Qn),me.removeAriaAttributes(this.elementRef),this.elementRef[f].add(Jn),this.changeElementsByState(this._innerElements.submit),un.resetSubmit(this,this.status.loadingActive),z.assignButtonEvents(this.elementRef,function(){var e;_this123.submitFromInput(),(e=_this123._microphoneButton)!=null&&e.isActive&&Ss.toggleSpeechAfterSubmit(_this123._microphoneButton.elementRef,!!_this123._stopSTTAfterSubmit),setTimeout(function(){return yn.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(Ps,Jn),me.removeAriaBusy(this.elementRef),this.elementRef[f].add(Qn),me.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements[j]),this.reapplyStateStyle(j,[at]),z.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;}}]);}(wn);var ld="<?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",hd="<?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",dd="<?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>",ud="<?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 xr=/*#__PURE__*/function(_dn){// prettier-ignore
|
|
285
|
+
function xr(e,t,n,s){var _this124;_classCallCheck(this,xr);_this124=_callSuper(this,xr,[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),r=_this124$addButtonsAn.captureButton,o=_this124$addButtonsAn.submitButton;_this124._captureButton=r,_this124._submitButton=o,_this124._captureIcon=_this124._captureButton.children[0],_this124._refreshIcon=Ft.createSVGElement(ld),_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(xr,_dn);return _createClass(xr,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=dn.createSVGButton(hd);t[f].add("modal-svg-camera-button"),t.children[0][f].add("modal-svg-camera-icon");var n=this.addCloseButton(dd,!0);n[f].add("modal-svg-close-button"),n.children[0][f].add("modal-svg-close-icon");var s=dn.createSVGButton(ud);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;z.assignButtonEvents(e,this.capture.bind(this)),z.assignButtonEvents(t,this.stop.bind(this)),z.assignButtonEvents(n,function(){var r=_this125.getFile();r&&Ts.addFilesToType([r],[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);},dn.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}),r=this._format==="image/jpeg"?"jpeg":"png",o=zo.getFileName(this._newFilePrefix||"photo",r);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[Jt]();}// prettier-ignore
|
|
287
|
+
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,n,s){var r=new xr(e,t,n,s);return r.openCameraModal.bind(r,r);}}]);}(dn);var pd="<?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 Ar=/*#__PURE__*/function(_wn7){function Ar(e,t,n){var _this128;_classCallCheck(this,Ar);var l,d,u,g,b,_;var s=ce.processPosition((l=n==null?void 0:n.button)==null?void 0:l.position),r=((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=bt.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,Ar,[Ar.createButtonElement(),pd,s,o,a,r]);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(Ar,_wn7);return _createClass(Ar,[{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 r=xr.createCameraModalFunc(e,t,n,s);z.assignButtonEvents(this.elementRef,r);}}],[{key:"createButtonElement",value:function createButtonElement(){var e=x();return e[f].add("input-button"),e;}}]);}(wn);var Mn=/*#__PURE__*/function(){function Mn(e,t,n,s){_classCallCheck(this,Mn);this.elementRef=Mn.createPanelElement(e.inputAreaStyle);var r={},o=this.createFileUploadComponents(e,n,s,r),a=new qs(e,n,o,t.browserStorage);e.speechToText&&!r.microphone&&(r.microphone={button:new Ss(e,a,t.addNewErrorMessage.bind(t))});var c=new rs(e,a,t,n,o,r);a.submit=c.submitFromInput.bind(c),sn.attach(e,n,a,o,c,t.browserStorage),e.submitUserMessage=c.programmaticSubmit.bind(c),r.submit={button:c},e.customButtons&&fn.add(e,r),Mn.addElements(this.elementRef,a,r,s,o,e.dropupStyles),Mn.assignOnInput(e,n,o,a);}return _createClass(Mn,[{key:"createFileUploadComponents",value:// prettier-ignore
|
|
289
|
+
function createFileUploadComponents(e,t,n,s){var o,a,c,l;var r=new Ts(this.elementRef,e.attachmentContainerStyle,t.demo);if(Mn.createUploadButtons(e,t,t.fileTypes||{},r,n,s),(o=t[Fe])!=null&&o[m]){var d=((a=s[Q])==null?void 0:a.fileType)||r.addType(e,t,t[Fe][m],Q);s[Fe]={button:new Ar(n,d,t[Fe])};}if((c=t.recordAudio)!=null&&c[m]){var _d2=((l=s[$])==null?void 0:l.fileType)||r.addType(e,t,t.recordAudio[m],$);s.microphone={button:new ad(_d2,t.recordAudio)};}return Lt.isEnabled(r,e.dragAndDrop)&&Lt.create(n,r,e.dragAndDrop),r;}// 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,r,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),_nd$c=nd[c],u=_nd$c.id,g=_nd$c.svgString,b=_nd$c.dropupText,_=new ci(r,d,l,u,g,b);o[c]={button:_,fileType:d};}});}// prettier-ignore
|
|
291
|
+
},{key:"addElements",value:function addElements(e,t,n,s,r,o){z.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 wr=/*#__PURE__*/function(){function wr(){_classCallCheck(this,wr);}return _createClass(wr,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?Kh:Vh);var o=new it(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 z.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=wr.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var fd="#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 md=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&&md(e,t,s),s;};var k=/*#__PURE__*/function(_Di){function k(){var _this129;_classCallCheck(this,k);var e;_this129=_callSuper(this,k),_this129.getMessages=function(){return[];},_this129.submitUserMessage=function(){return console.warn(Nr("submitUserMessage"));},_this129.addMessage=function(){return console.warn(Nr("addMessage"));},_this129.updateMessage=function(){},_this129.clearMessages=function(){},_this129.focusInput=function(){return yn.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(bt.buildElement()),Xt.apply(fd,_this129.shadowRoot),setTimeout(function(){_this129._hasBeenRendered||_this129.onRender();},20);return _this129;}_inherits(k,_Di);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;Ji.attemptAppendStyleSheetToHead(this.style,(e=this.chatStyle)==null?void 0:e.fontFamily),ce.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=zh.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(Xt.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),this.chatStyle&&!this._chatStyleApplied&&(Xt.applyChatStyle(this.chatStyle,this.shadowRoot),this._chatStyleApplied=!0),ce.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?js.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],wr.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof M&&Ne.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||_n.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){bs.chat=void 0;}}]);}(Di);N([P("object")],k.prototype,"connect");N([P("object")],k.prototype,"directConnection");N([P("object")],k.prototype,"webModel");N([P("object")],k.prototype,"requestBodyLimits");N([P("function")],k.prototype,"requestInterceptor");N([P("function")],k.prototype,"responseInterceptor");N([P("function")],k.prototype,"validateInput");N([P("function")],k.prototype,"loadHistory");N([P("object")],k.prototype,"chatStyle");N([P("object")],k.prototype,"attachmentContainerStyle");N([P("object")],k.prototype,"dropupStyles");N([P("object")],k.prototype,"inputAreaStyle");N([P("object")],k.prototype,"textInput");N([P("object")],k.prototype,"defaultInput");N([P("object")],k.prototype,"submitButtonStyles");N([P("object")],k.prototype,"customButtons");N([P("string")],k.prototype,"auxiliaryStyle");N([P("array")],k.prototype,"history");N([P("object")],k.prototype,"browserStorage");N([P("object")],k.prototype,"introMessage");N([P("object")],k.prototype,"avatars");N([P("object")],k.prototype,"names");N([P("object")],k.prototype,"displayLoadingBubble");N([P("object")],k.prototype,"errorMessages");N([P("object")],k.prototype,"messageStyles");N([P("object")],k.prototype,"textToSpeech");N([P("object")],k.prototype,"speechToText");N([P("object")],k.prototype,"images");N([P("object")],k.prototype,"gifs");N([P("object")],k.prototype,"camera");N([P("object")],k.prototype,"audio");N([P("object")],k.prototype,"microphone");N([P("object")],k.prototype,"mixedFiles");N([P("object")],k.prototype,"dragAndDrop");N([P("object")],k.prototype,"htmlWrappers");N([P("object")],k.prototype,"htmlClassUtilities");N([P("object")],k.prototype,"remarkable");N([P("object")],k.prototype,"focusMode");N([P("boolean")],k.prototype,"upwardsMode");N([P("object")],k.prototype,"scrollButton");N([P("object")],k.prototype,"hiddenMessages");N([P("number")],k.prototype,"maxVisibleMessages");N([P("function")],k.prototype,"onMessage");N([P("function")],k.prototype,"onClearMessages");N([P("function")],k.prototype,"onComponentRender");N([P("function")],k.prototype,"onInput");N([P("function")],k.prototype,"onError");N([P("object")],k.prototype,"demo");N([P("object")],k.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",k);export{k as DeepChat};
|