deep-chat-dev 9.0.299 → 9.0.301
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 +15276 -14029
- package/dist/deepChat.bundle.js +1 -1
- package/dist/deepChat.js +190 -191
- package/dist/services/assemblyAI/assemblyAIAudioIO.d.ts.map +1 -1
- package/dist/services/assemblyAI/utils/assemblyAIUtils.d.ts +1 -1
- package/dist/services/assemblyAI/utils/assemblyAIUtils.d.ts.map +1 -1
- package/dist/services/azure/azureOpenAIAssistantIO.d.ts.map +1 -1
- package/dist/services/azure/azureOpenAIChatIO.d.ts.map +1 -1
- package/dist/services/azure/azureSpeechToTextIO.d.ts.map +1 -1
- package/dist/services/azure/azureSummarizationIO.d.ts.map +1 -1
- package/dist/services/azure/azureTextToSpeechIO.d.ts.map +1 -1
- package/dist/services/azure/azureTranslationIO.d.ts.map +1 -1
- package/dist/services/azure/utils/azureOpenAIUtils.d.ts +1 -1
- package/dist/services/azure/utils/azureOpenAIUtils.d.ts.map +1 -1
- package/dist/services/azure/utils/azureUtils.d.ts +6 -5
- package/dist/services/azure/utils/azureUtils.d.ts.map +1 -1
- package/dist/services/bigModel/bigModelChatIO.d.ts.map +1 -1
- package/dist/services/bigModel/bigModelImagesIO.d.ts.map +1 -1
- package/dist/services/bigModel/bigModelTextToSpeechIO.d.ts.map +1 -1
- package/dist/services/bigModel/utils/bigModelUtils.d.ts +1 -1
- package/dist/services/bigModel/utils/bigModelUtils.d.ts.map +1 -1
- package/dist/services/claude/claudeIO.d.ts.map +1 -1
- package/dist/services/claude/utils/claudeUtils.d.ts +1 -1
- package/dist/services/claude/utils/claudeUtils.d.ts.map +1 -1
- package/dist/services/cohere/cohereChatIO.d.ts.map +1 -1
- package/dist/services/cohere/cohereIO.d.ts.map +1 -1
- package/dist/services/cohere/utils/cohereUtils.d.ts +1 -1
- package/dist/services/cohere/utils/cohereUtils.d.ts.map +1 -1
- package/dist/services/deepSeek/deepSeekIO.d.ts.map +1 -1
- package/dist/services/deepSeek/utils/deepSeekUtils.d.ts +1 -1
- package/dist/services/deepSeek/utils/deepSeekUtils.d.ts.map +1 -1
- package/dist/services/gemini/geminiIO.d.ts.map +1 -1
- package/dist/services/gemini/utils/geminiUtils.d.ts +1 -1
- package/dist/services/gemini/utils/geminiUtils.d.ts.map +1 -1
- package/dist/services/groq/groqChatIO.d.ts.map +1 -1
- package/dist/services/groq/groqTextToSpeechIO.d.ts.map +1 -1
- package/dist/services/groq/utils/groqUtils.d.ts +1 -1
- package/dist/services/groq/utils/groqUtils.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceAudioClassificationIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceAudioRecognitionIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceConversationIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceFillMaskIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceImageClassificationIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceQuestionAnswerIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceSummarizationIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceTextGenerationIO.d.ts.map +1 -1
- package/dist/services/huggingFace/huggingFaceTranslationIO.d.ts.map +1 -1
- package/dist/services/huggingFace/utils/huggingFaceUtils.d.ts +1 -1
- package/dist/services/huggingFace/utils/huggingFaceUtils.d.ts.map +1 -1
- package/dist/services/kimi/kimiIO.d.ts.map +1 -1
- package/dist/services/kimi/utils/kimiUtils.d.ts +1 -1
- package/dist/services/kimi/utils/kimiUtils.d.ts.map +1 -1
- package/dist/services/miniMax/miniMaxIO.d.ts.map +1 -1
- package/dist/services/miniMax/utils/miniMaxUtils.d.ts +1 -1
- package/dist/services/miniMax/utils/miniMaxUtils.d.ts.map +1 -1
- package/dist/services/mistral/mistralO.d.ts +1 -1
- package/dist/services/mistral/mistralO.d.ts.map +1 -1
- package/dist/services/mistral/utils/mistralUtils.d.ts +1 -1
- package/dist/services/mistral/utils/mistralUtils.d.ts.map +1 -1
- package/dist/services/ollama/ollamaIO.d.ts.map +1 -1
- package/dist/services/ollama/utils/ollamaUtils.d.ts.map +1 -1
- package/dist/services/openAI/assistant/openAIAssistantIO.d.ts.map +1 -1
- package/dist/services/openAI/assistant/openAIAssistantIOI.d.ts.map +1 -1
- package/dist/services/openAI/assistant/utils/openAIAssistantUtils.d.ts.map +1 -1
- package/dist/services/openAI/openAIChatIO.d.ts +0 -1
- package/dist/services/openAI/openAIChatIO.d.ts.map +1 -1
- package/dist/services/openAI/openAIImagesIO.d.ts.map +1 -1
- package/dist/services/openAI/openAISpeechToTextIO.d.ts.map +1 -1
- package/dist/services/openAI/openAITextToSpeechIO.d.ts.map +1 -1
- package/dist/services/openAI/realtime/openAIRealtimeIO.d.ts.map +1 -1
- package/dist/services/openAI/utils/openAIUtils.d.ts +1 -1
- package/dist/services/openAI/utils/openAIUtils.d.ts.map +1 -1
- package/dist/services/openRouter/openRouterIO.d.ts.map +1 -1
- package/dist/services/openRouter/utils/openRouterUtils.d.ts +1 -1
- package/dist/services/openRouter/utils/openRouterUtils.d.ts.map +1 -1
- package/dist/services/perplexity/perplexityIO.d.ts.map +1 -1
- package/dist/services/perplexity/utils/perplexityUtils.d.ts +1 -1
- package/dist/services/perplexity/utils/perplexityUtils.d.ts.map +1 -1
- package/dist/services/qwen/qwenIO.d.ts.map +1 -1
- package/dist/services/qwen/utils/qwenUtils.d.ts +1 -1
- package/dist/services/qwen/utils/qwenUtils.d.ts.map +1 -1
- package/dist/services/serviceIO.d.ts +1 -1
- package/dist/services/serviceIO.d.ts.map +1 -1
- package/dist/services/stabilityAI/stabilityAIIO.d.ts.map +1 -1
- package/dist/services/stabilityAI/stabilityAITextToImageIO.d.ts.map +1 -1
- package/dist/services/stabilityAI/utils/stabilityAIUtils.d.ts +1 -1
- package/dist/services/stabilityAI/utils/stabilityAIUtils.d.ts.map +1 -1
- package/dist/services/together/togetherChatIO.d.ts.map +1 -1
- package/dist/services/together/togetherImagesIO.d.ts.map +1 -1
- package/dist/services/together/togetherTextToSpeechIO.d.ts.map +1 -1
- package/dist/services/together/utils/togetherUtils.d.ts +1 -1
- package/dist/services/together/utils/togetherUtils.d.ts.map +1 -1
- package/dist/services/utils/baseServiceIO.d.ts.map +1 -1
- package/dist/services/utils/directServiceIO.d.ts +1 -0
- package/dist/services/utils/directServiceIO.d.ts.map +1 -1
- package/dist/services/utils/serviceConstants.d.ts +20 -0
- package/dist/services/utils/serviceConstants.d.ts.map +1 -0
- package/dist/services/x/utils/xUtils.d.ts +1 -1
- package/dist/services/x/utils/xUtils.d.ts.map +1 -1
- package/dist/services/x/xChatIO.d.ts.map +1 -1
- package/dist/services/x/xImagesIO.d.ts.map +1 -1
- package/dist/types/{mistralRsult.d.ts → mistralResult.d.ts} +1 -1
- package/dist/types/mistralResult.d.ts.map +1 -0
- package/dist/types/openAIInternal.d.ts +0 -4
- package/dist/types/openAIInternal.d.ts.map +1 -1
- package/dist/types/remarkable.d.ts +1 -0
- package/dist/types/remarkable.d.ts.map +1 -1
- package/dist/utils/HTTP/HTTPRequest.d.ts.map +1 -1
- package/dist/utils/HTTP/customHandler.d.ts.map +1 -1
- package/dist/utils/HTTP/requestUtils.d.ts +0 -1
- package/dist/utils/HTTP/requestUtils.d.ts.map +1 -1
- package/dist/utils/HTTP/stream.d.ts.map +1 -1
- package/dist/utils/HTTP/websocket.d.ts.map +1 -1
- package/dist/utils/consts/messageConstants.d.ts +3 -0
- package/dist/utils/consts/messageConstants.d.ts.map +1 -0
- package/dist/utils/demo/demo.d.ts.map +1 -1
- package/dist/utils/legacy/legacy.d.ts.map +1 -1
- package/dist/views/chat/input/buttons/buttonUtils.d.ts.map +1 -1
- package/dist/views/chat/input/buttons/custom/customButton.d.ts.map +1 -1
- package/dist/views/chat/input/buttons/submit/submitButton.d.ts +0 -1
- package/dist/views/chat/input/buttons/submit/submitButton.d.ts.map +1 -1
- package/dist/views/chat/input/buttons/tooltip/tooltipUtils.d.ts.map +1 -1
- package/dist/views/chat/input/fileAttachments/dragAndDrop/dragAndDrop.d.ts.map +1 -1
- package/dist/views/chat/input/input.d.ts.map +1 -1
- package/dist/views/chat/messages/history/history.d.ts.map +1 -1
- package/dist/views/chat/messages/html/htmlDeepChatElements.d.ts.map +1 -1
- package/dist/views/chat/messages/messages.d.ts.map +1 -1
- package/dist/views/chat/messages/messagesBase.d.ts +1 -0
- package/dist/views/chat/messages/messagesBase.d.ts.map +1 -1
- package/dist/views/chat/messages/utils/messageUtils.d.ts.map +1 -1
- package/dist/webModel/webModel.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/types/mistralRsult.d.ts.map +0 -1
package/dist/deepChat.js
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n6=0,F=function F(){};return{s:F,n:function n(){return _n6>=r.length?{done:!0}:{done:!1,value:r[_n6++]};},e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _wrapNativeSuper(t){var r="function"==typeof Map?new Map():void 0;return _wrapNativeSuper=function _wrapNativeSuper(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,Wrapper);}function Wrapper(){return _construct(t,arguments,_getPrototypeOf(this).constructor);}return Wrapper.prototype=Object.create(t.prototype,{constructor:{value:Wrapper,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(Wrapper,t);},_wrapNativeSuper(t);}function _construct(t,e,r){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var p=new(t.bind.apply(t,o))();return r&&_setPrototypeOf(p,r.prototype),p;}function _isNativeFunction(t){try{return-1!==Function.toString.call(t).indexOf("[native code]");}catch(n){return"function"==typeof t;}}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1;}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r;}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return;}finally{if(o)throw n;}}return a;}}function _arrayWithHoles(r){if(Array.isArray(r))return r;}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof Generator?n:Generator,u=Object.create(c.prototype);return _regeneratorDefine2(u,"_invoke",function(r,n,o){var i,c,u,f=0,p=o||[],y=!1,G={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function d(t,r){return i=t,c=0,u=e,G.n=r,a;}};function d(r,n){for(c=r,u=n,t=0;!y&&f&&!o&&t<p.length;t++){var o,i=p[t],d=G.p,l=i[2];r>3?(o=l===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,G.v=n,G.n=i[1]):d<l&&(o=r<3||i[0]>n||n>l)&&(i[4]=r,i[5]=n,G.n=l,c=0));}if(o||r>1)return a;throw y=!0,n;}return function(o,p,l){if(f>1)throw TypeError("Generator is already running");for(y&&1===p&&d(p,l),c=p,u=l;(t=c<2?e:u)||!y;){i||(c?c<3?(c>1&&(G.n=-1),d(c,u)):G.n=u:G.v=u);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0);}else 1===c&&(t=i["return"])&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e;}else if((t=(y=G.n<0)?u:r.call(n,G))!==a)break;}catch(t){i=e,c=1,u=t;}finally{f=1;}}return{value:t,done:y};};}(r,o,i),!0),u;}var a={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(_regeneratorDefine2(t={},n,function(){return this;}),t),u=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,GeneratorFunctionPrototype):(e.__proto__=GeneratorFunctionPrototype,_regeneratorDefine2(e,o,"GeneratorFunction")),e.prototype=Object.create(u),e;}return GeneratorFunction.prototype=GeneratorFunctionPrototype,_regeneratorDefine2(u,"constructor",GeneratorFunctionPrototype),_regeneratorDefine2(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName="GeneratorFunction",_regeneratorDefine2(GeneratorFunctionPrototype,o,"GeneratorFunction"),_regeneratorDefine2(u),_regeneratorDefine2(u,o,"Generator"),_regeneratorDefine2(u,n,function(){return this;}),_regeneratorDefine2(u,"toString",function(){return"[object Generator]";}),(_regenerator=function _regenerator(){return{w:i,m:f};})();}function _regeneratorDefine2(e,r,n,t){var i=Object.defineProperty;try{i({},"",{});}catch(e){i=0;}_regeneratorDefine2=function _regeneratorDefine(e,r,n,t){function o(r,n){_regeneratorDefine2(e,r,function(e){return this._invoke(r,n,e);});}r?i?i(e,r,{value:n,enumerable:!t,configurable:!t,writable:!t}):e[r]=n:(o("next",0),o("throw",1),o("return",2));},_regeneratorDefine2(e,r,n,t);}function asyncGeneratorStep(n,t,e,r,o,a,c){try{var i=n[a](c),u=i.value;}catch(n){return void e(n);}i.done?t(u):Promise.resolve(u).then(r,o);}function _asyncToGenerator(n){return function(){var t=this,e=arguments;return new Promise(function(r,o){var a=n.apply(t,e);function _next(n){asyncGeneratorStep(a,r,o,_next,_throw,"next",n);}function _throw(n){asyncGeneratorStep(a,r,o,_next,_throw,"throw",n);}_next(void 0);});};}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e;}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}var pr=/*#__PURE__*/function(){function pr(){_classCallCheck(this,pr);}return _createClass(pr,null,[{key:"render",value:function render(e,t){var s=document.createElement("div");s.id="error-view",s.innerText=t,e.replaceChildren(s);}}]);}();var Cs=/*#__PURE__*/function(){function Cs(){_classCallCheck(this,Cs);}return _createClass(Cs,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=document.createElement("div");return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,s){var i=Cs.createElements(),n={onSuccess:t,onFail:pr.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:Cs.onLoad.bind(this,i)};s.key&&s.verifyKey(s.key,n),e.replaceChildren(i);}}]);}();var N=/*#__PURE__*/function(){function N(){_classCallCheck(this,N);}return _createClass(N,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var s=Object.keys(t).reduce(function(i,n){return i[n]="",i;},{});Object.assign(e.style,s);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t.click&&N.unsetStyle(e,t.click),t.hover&&N.unsetStyle(e,t.hover);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){N.unsetActivityCSSMouseStates(e,t),t["default"]&&N.unsetStyle(e,t["default"]);}// if you want to asdd default styling - use pure css classes
|
2
|
-
},{key:"processStateful",value:function processStateful(e){var t=e["default"]||{},s=Object.assign(JSON.parse(JSON.stringify(t)),e==null?void 0:e.hover),i=Object.assign(JSON.parse(JSON.stringify(s)),e==null?void 0:e.click);return{"default":t,hover:s,click:i};}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t={"default":{},hover:{},click:{}};return e.forEach(function(s){t["default"]=Object.assign(t["default"],s["default"]),t.hover=Object.assign(t.hover,s.hover),t.click=Object.assign(t.click,s.click);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e["default"]||[]).forEach(function(s){var n;var i=s;t.style[i]&&(n=e["default"])!=null&&n[i]&&(e["default"][s]=t.style[i]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var s in t){var i=t[s];e[s]===""&&i&&(e[s]=i);}}}]);}();var
|
1
|
+
function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n6=0,F=function F(){};return{s:F,n:function n(){return _n6>=r.length?{done:!0}:{done:!1,value:r[_n6++]};},e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _wrapNativeSuper(t){var r="function"==typeof Map?new Map():void 0;return _wrapNativeSuper=function _wrapNativeSuper(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,Wrapper);}function Wrapper(){return _construct(t,arguments,_getPrototypeOf(this).constructor);}return Wrapper.prototype=Object.create(t.prototype,{constructor:{value:Wrapper,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(Wrapper,t);},_wrapNativeSuper(t);}function _construct(t,e,r){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var p=new(t.bind.apply(t,o))();return r&&_setPrototypeOf(p,r.prototype),p;}function _isNativeFunction(t){try{return-1!==Function.toString.call(t).indexOf("[native code]");}catch(n){return"function"==typeof t;}}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1;}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r;}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return;}finally{if(o)throw n;}}return a;}}function _arrayWithHoles(r){if(Array.isArray(r))return r;}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof Generator?n:Generator,u=Object.create(c.prototype);return _regeneratorDefine2(u,"_invoke",function(r,n,o){var i,c,u,f=0,p=o||[],y=!1,G={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function d(t,r){return i=t,c=0,u=e,G.n=r,a;}};function d(r,n){for(c=r,u=n,t=0;!y&&f&&!o&&t<p.length;t++){var o,i=p[t],d=G.p,l=i[2];r>3?(o=l===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,G.v=n,G.n=i[1]):d<l&&(o=r<3||i[0]>n||n>l)&&(i[4]=r,i[5]=n,G.n=l,c=0));}if(o||r>1)return a;throw y=!0,n;}return function(o,p,l){if(f>1)throw TypeError("Generator is already running");for(y&&1===p&&d(p,l),c=p,u=l;(t=c<2?e:u)||!y;){i||(c?c<3?(c>1&&(G.n=-1),d(c,u)):G.n=u:G.v=u);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0);}else 1===c&&(t=i["return"])&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e;}else if((t=(y=G.n<0)?u:r.call(n,G))!==a)break;}catch(t){i=e,c=1,u=t;}finally{f=1;}}return{value:t,done:y};};}(r,o,i),!0),u;}var a={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(_regeneratorDefine2(t={},n,function(){return this;}),t),u=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,GeneratorFunctionPrototype):(e.__proto__=GeneratorFunctionPrototype,_regeneratorDefine2(e,o,"GeneratorFunction")),e.prototype=Object.create(u),e;}return GeneratorFunction.prototype=GeneratorFunctionPrototype,_regeneratorDefine2(u,"constructor",GeneratorFunctionPrototype),_regeneratorDefine2(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName="GeneratorFunction",_regeneratorDefine2(GeneratorFunctionPrototype,o,"GeneratorFunction"),_regeneratorDefine2(u),_regeneratorDefine2(u,o,"Generator"),_regeneratorDefine2(u,n,function(){return this;}),_regeneratorDefine2(u,"toString",function(){return"[object Generator]";}),(_regenerator=function _regenerator(){return{w:i,m:f};})();}function _regeneratorDefine2(e,r,n,t){var i=Object.defineProperty;try{i({},"",{});}catch(e){i=0;}_regeneratorDefine2=function _regeneratorDefine(e,r,n,t){function o(r,n){_regeneratorDefine2(e,r,function(e){return this._invoke(r,n,e);});}r?i?i(e,r,{value:n,enumerable:!t,configurable:!t,writable:!t}):e[r]=n:(o("next",0),o("throw",1),o("return",2));},_regeneratorDefine2(e,r,n,t);}function asyncGeneratorStep(n,t,e,r,o,a,c){try{var i=n[a](c),u=i.value;}catch(n){return void e(n);}i.done?t(u):Promise.resolve(u).then(r,o);}function _asyncToGenerator(n){return function(){var t=this,e=arguments;return new Promise(function(r,o){var a=n.apply(t,e);function _next(n){asyncGeneratorStep(a,r,o,_next,_throw,"next",n);}function _throw(n){asyncGeneratorStep(a,r,o,_next,_throw,"throw",n);}_next(void 0);});};}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e;}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}var Nr=/*#__PURE__*/function(){function Nr(){_classCallCheck(this,Nr);}return _createClass(Nr,null,[{key:"render",value:function render(e,t){var s=document.createElement("div");s.id="error-view",s.innerText=t,e.replaceChildren(s);}}]);}();var Us=/*#__PURE__*/function(){function Us(){_classCallCheck(this,Us);}return _createClass(Us,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=document.createElement("div");return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,s){var i=Us.createElements(),n={onSuccess:t,onFail:Nr.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:Us.onLoad.bind(this,i)};s.key&&s.verifyKey(s.key,n),e.replaceChildren(i);}}]);}();var U=/*#__PURE__*/function(){function U(){_classCallCheck(this,U);}return _createClass(U,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var s=Object.keys(t).reduce(function(i,n){return i[n]="",i;},{});Object.assign(e.style,s);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t.click&&U.unsetStyle(e,t.click),t.hover&&U.unsetStyle(e,t.hover);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){U.unsetActivityCSSMouseStates(e,t),t["default"]&&U.unsetStyle(e,t["default"]);}// if you want to asdd default styling - use pure css classes
|
2
|
+
},{key:"processStateful",value:function processStateful(e){var t=e["default"]||{},s=Object.assign(JSON.parse(JSON.stringify(t)),e==null?void 0:e.hover),i=Object.assign(JSON.parse(JSON.stringify(s)),e==null?void 0:e.click);return{"default":t,hover:s,click:i};}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t={"default":{},hover:{},click:{}};return e.forEach(function(s){t["default"]=Object.assign(t["default"],s["default"]),t.hover=Object.assign(t.hover,s.hover),t.click=Object.assign(t.click,s.click);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e["default"]||[]).forEach(function(s){var n;var i=s;t.style[i]&&(n=e["default"])!=null&&n[i]&&(e["default"][s]=t.style[i]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var s in t){var i=t[s];e[s]===""&&i&&(e[s]=i);}}}]);}();var ft=/*#__PURE__*/function(){function ft(){_classCallCheck(this,ft);}return _createClass(ft,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==ft.DEFAULT_FONT_FAMILY)return;var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(i){return i.getAttribute("href")===ft.FONT_URL;})){var i=document.createElement("link");i.rel="stylesheet",i.href=ft.FONT_URL,t.appendChild(i);}}}]);}();ft.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",ft.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var Hs=ft;var Lt=/*#__PURE__*/function(){function Lt(){_classCallCheck(this,Lt);}return _createClass(Lt,null,[{key:"apply",value:function apply(e,t){if(t)try{Lt.applyStyleSheet(e,t);}catch(_unused){Lt.addStyleElement(e,t);}}},{key:"applyStyleSheet",value:function applyStyleSheet(e,t){var s=new CSSStyleSheet();s.replaceSync(e),t.adoptedStyleSheets.push(s);}},{key:"addStyleElement",value:function addStyleElement(e,t){var s=document.createElement("style");s.innerHTML=e,t.appendChild(s);}},{key:"applyDefaultStyleToComponent",value:function applyDefaultStyleToComponent(e,t){t&&U.applyToStyleIfNotDefined(e,t),U.applyToStyleIfNotDefined(e,Lt.DEFAULT_COMPONENT_STYLE);}}]);}();Lt.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:Hs.DEFAULT_FONT_FAMILY,fontSize:"0.9rem",backgroundColor:"white",position:"relative",// this is used to prevent inputAreaStyle background color from going beyond the container's rounded border
|
3
3
|
// it will cause issues if there are elements that are meant to be outside of the chat component and in
|
4
4
|
// that instance they should overwrite this
|
5
5
|
// this is also causing the chat to squeeze when there is no space
|
6
|
-
overflow:"hidden"};var
|
7
|
-
function add(e,t,s,i){s!==void 0&&e.addEventListener("keydown",
|
6
|
+
overflow:"hidden"};var cs=Lt;var F="service",g="text",pt=/*#__PURE__*/function(){function pt(){_classCallCheck(this,pt);}return _createClass(pt,null,[{key:"buildElement",value:function buildElement(){var e=document.createElement("div");e.classList.add("tooltip");var t=document.createElement("span");return t.classList.add("tooltip-text"),e.appendChild(t),e;}},{key:"tryCreateConfig",value:function tryCreateConfig(e,t){if(t)return typeof t=="boolean"?_defineProperty({},g,e):_defineProperty(_defineProperty(_defineProperty({},g,t.text||e),"timeout",t.timeout||0),"style",t.style);}},{key:"traverseParentUntilContainer",value:function traverseParentUntilContainer(e){var t=e;for(;t.parentElement;)t=t.parentElement;return t;}},{key:"setPosition",value:function setPosition(e,t){var i=t.getRootNode().host.getBoundingClientRect(),n=e.getBoundingClientRect(),a=t.getBoundingClientRect().width/2,l=n.left+n.width/2;t.style.left="".concat(l-a-i.left,"px"),t.style.top="".concat(n.top-36-i.top,"px");var c=t.getBoundingClientRect();c.left<i.left?t.style.left="".concat(pt.OVERFLOW_NEW_POSITION_PX,"px"):c.right>i.right&&(t.style.left="".concat(i.width-c.width-pt.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,s){return s||(s=pt.traverseParentUntilContainer(e).nextSibling),t.text&&(s.children[0].textContent=t.text),{timeout:setTimeout(function(){s.style.visibility="visible",pt.setPosition(e,s),t.style&&Object.assign(s.style,t.style);},t.timeout||0),element:s};}},{key:"hide",value:function hide(e,t){clearTimeout(e.timeout),e.element.style.visibility="hidden",t.style&&U.unsetStyle(e.element,t.style),e.element.style.left="",e.element.style.top="";}}]);}();pt.OVERFLOW_NEW_POSITION_PX=4;var Le=pt;var ps=/*#__PURE__*/_createClass(function ps(){_classCallCheck(this,ps);});ps.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),ps.IS_CHROMIUM=window.chrome,ps.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var Ye=ps;var X=/* @__PURE__ */function(r){return r.ESCAPE="Escape",r.ENTER="Enter",r.TAB="Tab",r.ARROW_UP="ArrowUp",r.ARROW_DOWN="ArrowDown",r.ARROW_RIGHT="ArrowRight",r.ARROW_LEFT="ArrowLeft",r.BACKSPACE="Backspace",r.DELETE="Delete",r.META="Meta",r.CONTROL="Control",r;}(X||{});var mt=/*#__PURE__*/function(){function mt(){_classCallCheck(this,mt);}return _createClass(mt,null,[{key:"add",value:// prettier-ignore
|
7
|
+
function add(e,t,s,i){s!==void 0&&e.addEventListener("keydown",mt.onKeyDown.bind(this,s)),e.oninput=mt.onInput.bind(this,s,i),e.addEventListener("paste",function(n){var o;n.preventDefault(),(o=n.clipboardData)!=null&&o.files.length&&t.addFilesToAnyType(Array.from(n.clipboardData.files));});}// preventing insertion early for a nicer UX
|
8
8
|
// prettier-ignore
|
9
|
-
},{key:"onKeyDown",value:function onKeyDown(e,t){var i=t.target.textContent;i&&i.length>=e&&!
|
10
|
-
function clear(){var t,s;var e=window.scrollY;this.inputElementRef.classList.contains("text-input-disabled")||(Object.assign(this.inputElementRef.style,(t=this._config.placeholder)==null?void 0:t.style),this.inputElementRef.textContent="",
|
9
|
+
},{key:"onKeyDown",value:function onKeyDown(e,t){var i=t.target.textContent;i&&i.length>=e&&!mt.PERMITTED_KEYS.has(t.key)&&!mt.isKeyCombinationPermitted(t)&&t.preventDefault();}},{key:"isKeyCombinationPermitted",value:function isKeyCombinationPermitted(e){return e.key==="a"?e.ctrlKey||e.metaKey:!1;}},{key:"onInput",value:function onInput(e,t,s){var i=s.target,n=i.textContent||"";e!==void 0&&n.length>e&&(i.textContent=n.substring(0,e),ks.focusEndOfInput(i)),t==null||t();}}]);}();mt.PERMITTED_KEYS=/* @__PURE__ */new Set([X.BACKSPACE,X.DELETE,X.ARROW_RIGHT,X.ARROW_LEFT,X.ARROW_DOWN,X.ARROW_UP,X.META,X.CONTROL,X.ENTER]);var Fi=mt;var Or=/*#__PURE__*/function(){function Or(){_classCallCheck(this,Or);}return _createClass(Or,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var s,i;e.preventDefault();var t=(s=e.clipboardData)==null?void 0:s.getData("text/plain");t&&((i=document.execCommand)==null||i.call(document,"insertText",!1,t));}}]);}();var gt=/*#__PURE__*/function(){function gt(e,t,s){var _this=this;_classCallCheck(this,gt);var n,o;this._isComposing=!1;var i=gt.processConfig(t,e.textInput);this.elementRef=gt.createContainerElement((n=i==null?void 0:i.styles)==null?void 0:n.container),this._config=i,this.inputElementRef=this.createInputElement(),this.elementRef.appendChild(this.inputElementRef),e.setPlaceholderText=this.setPlaceholderText.bind(this),e.setPlaceholderText(((o=this._config.placeholder)==null?void 0:o.text)||"Ask me anything!"),setTimeout(function(){Fi.add(_this.inputElementRef,s,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(gt,[{key:"clear",value:// this also similarly prevents scroll up
|
10
|
+
function clear(){var t,s;var e=window.scrollY;this.inputElementRef.classList.contains("text-input-disabled")||(Object.assign(this.inputElementRef.style,(t=this._config.placeholder)==null?void 0:t.style),this.inputElementRef.textContent="",ks.focusEndOfInput(this.inputElementRef),(s=this._onInput)==null||s.call(this,!1)),Ye.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(){var t,s,i,n;var e=document.createElement("div");return e.id=gt.TEXT_INPUT_ID,e.classList.add("text-input-styling"),e.role="textbox",Ye.IS_CHROMIUM&>.preventAutomaticScrollUpOnNewLine(e),typeof this._config.disabled=="boolean"&&this._config.disabled===!0?(e.contentEditable="false",e.classList.add("text-input-disabled"),e.setAttribute("aria-disabled","true")):(e.contentEditable="true",e.removeAttribute("aria-disabled"),this.addEventListeners(e)),Object.assign(e.style,(t=this._config.styles)==null?void 0:t.text),Object.assign(e.style,(s=this._config.placeholder)==null?void 0:s.style),(n=(i=this._config.placeholder)==null?void 0:i.style)!=null&&n.color||e.setAttribute("textcolor",""),e;}},{key:"removePlaceholderStyle",value:function removePlaceholderStyle(){var e,t,s,i;!this.inputElementRef.classList.contains("text-input-disabled")&&(e=this._config.placeholder)!=null&&e.style&&(U.unsetStyle(this.inputElementRef,(t=this._config.placeholder)==null?void 0:t.style),Object.assign(this.inputElementRef.style,(i=(s=this._config)==null?void 0:s.styles)==null?void 0:i.text));}},{key:"addEventListeners",value:function addEventListeners(e){var _this2=this;var t,s;(t=this._config.styles)!=null&&t.focus&&(e.onfocus=function(){var i;return Object.assign(_this2.elementRef.style,(i=_this2._config.styles)==null?void 0:i.focus);},e.onblur=this.onBlur.bind(this,this._config.styles.focus,(s=this._config.styles)==null?void 0:s.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",Or.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){U.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef.style,t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===X.ENTER&&!Ye.IS_MOBILE&&!this._isComposing&&!e.ctrlKey&&!e.shiftKey&&(e.preventDefault(),(t=this.submit)==null||t.call(this));}},{key:"onInput",value:function onInput(){var e,t;this.isTextInputEmpty()?Object.assign(this.inputElementRef.style,(e=this._config.placeholder)==null?void 0:e.style):this.removePlaceholderStyle(),(t=this._onInput)==null||t.call(this,!0);}},{key:"setPlaceholderText",value:function setPlaceholderText(e){this.inputElementRef.setAttribute("deep-chat-placeholder-text",e),this.inputElementRef.setAttribute("aria-label",e);}},{key:"isTextInputEmpty",value:function isTextInputEmpty(){return this.inputElementRef.textContent==="";}}],[{key:"processConfig",value:function processConfig(e,t){var _t$disabled,_t$placeholder,_s$text;var s;return t!==null&&t!==void 0?t:t={},(_t$disabled=t.disabled)!==null&&_t$disabled!==void 0?_t$disabled:t.disabled=e.isTextInputDisabled,(_t$placeholder=t.placeholder)!==null&&_t$placeholder!==void 0?_t$placeholder:t.placeholder={},(_s$text=(s=t.placeholder).text)!==null&&_s$text!==void 0?_s$text:s.text=e.textInputPlaceholderText,t;}},{key:"createContainerElement",value:function createContainerElement(e){var t=document.createElement("div");return t.id="text-input-container",Object.assign(t.style,e),t;}// this is is a bug fix where if the browser is scrolled down and the user types in text that creates new line
|
11
11
|
// the browser scrollbar will move up which leads to undesirable UX.
|
12
12
|
// More details in this Stack Overflow question:
|
13
13
|
// https://stackoverflow.com/questions/76285135/prevent-automatic-scroll-when-text-is-inserted-into-contenteditable-div
|
14
14
|
// prettier-ignore
|
15
|
-
},{key:"preventAutomaticScrollUpOnNewLine",value:function preventAutomaticScrollUpOnNewLine(e){var t;e.addEventListener("keydown",function(){t=window.scrollY;}),e.addEventListener("input",function(){t!==window.scrollY&&window.scrollTo({top:t});});}}]);}();
|
16
|
-
function setElementProps(e,t,s,i){var n;s!=="loading"&&(e.applyCustomStyles(t,i,!0,(n=e.messageStyles)==null?void 0:n[s]),t.bubbleElement.classList.add(
|
17
|
-
},{key:"addMessage",value:function addMessage(e,t,s,i,n){
|
15
|
+
},{key:"preventAutomaticScrollUpOnNewLine",value:function preventAutomaticScrollUpOnNewLine(e){var t;e.addEventListener("keydown",function(){t=window.scrollY;}),e.addEventListener("input",function(){t!==window.scrollY&&window.scrollTo({top:t});});}}]);}();gt.TEXT_INPUT_ID="text-input";var qs=gt;var ks=/*#__PURE__*/function(){function ks(){_classCallCheck(this,ks);}return _createClass(ks,null,[{key:"focusEndOfInput",value:function focusEndOfInput(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(t);}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(qs.TEXT_INPUT_ID));t&&(Ye.IS_SAFARI&&t.focus(),ks.focusEndOfInput(t));}}]);}();var ur="Authentication",K="Authorization",Pr="authorization",on="Unauthorized",an="Authorization header",ht="Invalid",Is="Incorrect",te="authentication_error",Ae="invalid_request_error",k="Content-Type",Dr="content-type",P="application/json",S="object",He="error",fr="completed",ee="Bearer ",z="GET",Y="POST",ln="Upload an audio file";function Cn(r){return r.charAt(0).toUpperCase()+r.slice(1);}function Br(r){return r&&JSON.stringify(r);}function cn(r,e,t,s){var i="\n".concat(Cn(e)," message: ").concat(JSON.stringify(r)," \n"),n=t?"".concat(Cn(e)," message after interceptor: ").concat(Br(s)," \n"):"";return i+n;}function Fr(r,e,t,s){return"".concat(cn(r,e,t,s),"Make sure the ").concat(e," message is using the Response format: https://deepchat.dev/docs/connect/#Response \nYou can also augment it using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor");}function Ur(r,e,t){var s="response";return"".concat(cn(r,s,e,t),"Make sure the ").concat(s," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Hr(r,e){var t="request";return"".concat(cn(r,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}var An="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor",E={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",INVALID_RESPONSE:Fr,INVALID_MODEL_REQUEST:Hr,INVALID_MODEL_RESPONSE:Ur,INVALID_STREAM_ARRAY_RESPONSE:"Multi-response arrays are not supported for streaming",INVALID_STREAM_EVENT:An,INVALID_STREAM_EVENT_MIX:"Cannot mix {text: string} and {html: string} responses.",NO_VALID_STREAM_EVENTS_SENT:"No valid stream events were sent.\n".concat(An),READABLE_STREAM_CONNECTION_ERROR:"Readable Stream connection error.",DEFINE_FUNCTION_HANDLER:"Please define a `function_handler` property inside the service config."},Ei=/*#__PURE__*/function(){function Ei(){_classCallCheck(this,Ei);}return _createClass(Ei,null,[{key:"addElements",value:function addElements(e){for(var _len=arguments.length,t=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){t[_key-1]=arguments[_key];}t.forEach(function(s){return e.appendChild(s);});}},{key:"isScrollbarAtBottomOfElement",value:function isScrollbarAtBottomOfElement(e){var t=e.scrollHeight,s=e.clientHeight,i=e.scrollTop,n=t-s;return i>=n-Ei.CODE_SNIPPET_GENERATION_JUMP;}},{key:"cloneElement",value:function cloneElement(e){var t=e.cloneNode(!0);return e.parentNode.replaceChild(t,e),t;}},{key:"scrollToBottom",value:function scrollToBottom(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;t?e.scrollTo({left:0,top:e.scrollHeight,behavior:"smooth"}):e.scrollTop=e.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}}]);}();Ei.CODE_SNIPPET_GENERATION_JUMP=0.5;var ae=Ei;var Si=/*#__PURE__*/function(){function Si(){_classCallCheck(this,Si);}return _createClass(Si,null,[{key:"speak",value:function speak(e,t){if(!t.service&&window.SpeechSynthesisUtterance){var s=new SpeechSynthesisUtterance(e);Object.assign(s,t),speechSynthesis.speak(s);}}},{key:"processConfig",value:function processConfig(e,t){var s={};setTimeout(function(){if(_typeof(e)=="object"&&(e.service&&(s.service=e.service),e.lang&&(s.lang=e.lang),e.pitch&&(s.pitch=e.pitch),e.rate&&(s.rate=e.rate),e.volume&&(s.volume=e.volume),e.voiceName)){var i=window.speechSynthesis.getVoices().find(function(n){var o;return n.name.toLocaleLowerCase()===((o=e.voiceName)==null?void 0:o.toLocaleLowerCase());});i&&(s.voice=i);}t(s);},Si.LOAD_VOICES_MS);}}]);}();Si.LOAD_VOICES_MS=200;var Dt=Si;var Nt=/*#__PURE__*/function(){function Nt(){_classCallCheck(this,Nt);}return _createClass(Nt,null,[{key:"colorToHex",value:function colorToHex(e){var t=document.createElement("div");return t.style.color=e,document.body.appendChild(t),"#".concat(window.getComputedStyle(t).color.match(/\d+/g).map(function(n){return parseInt(n).toString(16).padStart(2,"0");}).join(""));}},{key:"setDots",value:function setDots(e,t){var s,i;if((i=(s=t==null?void 0:t.styles)==null?void 0:s.bubble)!=null&&i.color){var n=Nt.colorToHex(t.styles.bubble.color);e.style.setProperty("--loading-message-color",n),e.style.setProperty("--loading-message-color-fade","".concat(n,"33"));}else e.style.setProperty("--loading-message-color","#848484"),e.style.setProperty("--loading-message-color-fade","#55555533");}},{key:"setRing",value:function setRing(e,t){var _ref3=t||{},s=_ref3.color,i=_ref3.width,n=_ref3.height,o=_ref3.margin,a=_ref3.border;if(s){var l=Nt.colorToHex(s);e.style.setProperty("--loading-history-color",l);}else e.style.setProperty("--loading-history-color","#dbdbdb");e.style.setProperty("--loading-history-height",n||"57px"),e.style.setProperty("--loading-history-width",i||"57px"),e.style.setProperty("--loading-history-margin",o||"7px"),e.style.setProperty("--loading-history-border",a||"6px solid");}}]);}();Nt.BUBBLE_CLASS="deep-chat-loading-message-bubble",Nt.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var Xe=Nt;var Se=/*#__PURE__*/function(){function Se(){_classCallCheck(this,Se);}return _createClass(Se,null,[{key:"setElementProps",value:// prettier-ignore
|
16
|
+
function setElementProps(e,t,s,i){var n;s!=="loading"&&(e.applyCustomStyles(t,i,!0,(n=e.messageStyles)==null?void 0:n[s]),t.bubbleElement.classList.add(Se.FILE_BUBBLE_CLASS));}// prettier-ignore
|
17
|
+
},{key:"addMessage",value:function addMessage(e,t,s,i,n){Se.setElementProps(e,t,s,i),n||(e.appendOuterContainerElemet(t.outerContainer),e.focusMode||(e.elementRef.scrollTop=e.elementRef.scrollHeight));}},{key:"wrapInLink",value:function wrapInLink(e,t,s){var i=document.createElement("a");return i.href=t,i.download=s||Se.DEFAULT_FILE_NAME,i.target="_blank",i.appendChild(e),i;}},{key:"isNonLinkableDataUrl",value:function isNonLinkableDataUrl(e,t){return!t.startsWith("data")||e==="image"?!1:e==="any"&&t.startsWith("data:text/javascript")||!t.startsWith("data:image")&&!t.startsWith("data:application");}},{key:"processContent",value:function processContent(e,t,s,i){return!s||Se.isNonLinkableDataUrl(e,s)?t:Se.wrapInLink(t,s,i);}},{key:"waitToLoadThenScroll",value:function waitToLoadThenScroll(e){setTimeout(function(){e.scrollTop=e.scrollHeight;},60);}},{key:"scrollDownOnImageLoad",value:function scrollDownOnImageLoad(e,t){if(e.startsWith("data"))Se.waitToLoadThenScroll(t);else try{fetch(e,{mode:"no-cors"})["catch"](function(){})["finally"](function(){Se.waitToLoadThenScroll(t);});}catch(_unused2){t.scrollTop=t.scrollHeight;}}// The strategy is to emit the actual file reference in the `onMessage` event for the user to inspect it
|
18
18
|
// But it is not actually used by anything in the chat, hence it is removed when adding a message
|
19
19
|
// after the body has been stringified and parsed - the file reference will disappear, hence this readds it
|
20
20
|
},{key:"reAddFileRefToObject",value:function reAddFileRefToObject(e,t){var s;(s=e.files)==null||s.forEach(function(i,n){var o;i.ref&&(o=t.files)!=null&&o[n]&&(t.files[n].ref=i.ref);});}// the chat does not use the actual file
|
21
|
-
},{key:"removeFileRef",value:function removeFileRef(e){var t=_objectSpread({},e);return delete t.ref,t;}},{key:"isAudioFile",value:function isAudioFile(e){var t=/\.(mp3|ogg|wav|aac|webm|4a)$/i,s=e.type,i=e.src;return s==="audio"||(i==null?void 0:i.startsWith("data:audio"))||i&&t.test(i);}},{key:"isImageFile",value:function isImageFile(e){var t=e.type,s=e.src;return t==="image"||(s==null?void 0:s.startsWith("data:image"))||s&&
|
22
|
-
},{key:"handleResponseProperty",value:function handleResponseProperty(e){return console.error("The {result: ....} response object type is deprecated since version 1.3.0."),console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console.error("The initialMessages property is deprecated since version 2.0.0."),console.error("Please change to using the history property instead: https://deepchat.dev/docs/messages/#history"),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e.file;t&&(console.error("The file property in MessageContent is deprecated since version 1.3.17."),console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"),e.files=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console.error("The validateMessageBeforeSending property is deprecated since version 1.3.24."),console.error("Please change to using validateInput: https://deepchat.dev/docs/interceptors#validateInput"),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."),console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"),{
|
23
|
-
},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)
|
24
|
-
},{key:"replaceElementWithNewClone",value:function replaceElementWithNewClone(e,t){var i;var s=(t||e).cloneNode(!0);return(i=e.parentNode)==null||i.replaceChild(s,e),s;}},{key:"tryAddWrapper",value:function tryAddWrapper(e,t,s,i){if(t&&i){var n=(s==null?void 0:s[i])||(s==null?void 0:s["default"]);if(n)return e.innerHTML=n,{contentEl:
|
25
|
-
},{key:"overwrite",value:function overwrite(e,t,s,i){var n=e.messageToElements,o=y.overwriteMessage(n,i,t,s,"html",Oe.HTML_BUBBLE_CLASS);return o&&Oe.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var n=Oe.createElements(e,t,s,i);return y.fillEmptyMessageElement(n.bubbleElement,t),te.apply(e,n.outerContainer),Y.flagHTMLUpdateClass(n.bubbleElement),e.applyCustomStyles(n,s,!1,(o=e.messageStyles)==null?void 0:o.html),n;}},{key:"add",value:function add(e,t,s,i){var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(i!=null&&i.status){var a=this.overwrite(e,t,s,e.messageElementRefs);if(a)return a;i.status=!1;}if(n&&e.messageElementRefs.length>0&&te.isTemporaryBasedOnHTML(t))return;var o=Oe.create(e,t,s,n);return n||Oe.addElement(e,o.outerContainer),o;}}]);}();Oe.HTML_BUBBLE_CLASS="html-message";var Te=Oe;var Sr=/*#__PURE__*/function(){function Sr(){_classCallCheck(this,Sr);}return _createClass(Sr,null,[{key:"katex",value:function katex(e,t,s){var a=(s||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var l=function l(u,h){var f;return((f=window.katex)==null?void 0:f.renderToString(u,_objectSpread({displayMode:h,throwOnError:!1,output:"mathml"},e)))||"";},c=function c(u,h,f){var m=!1,p=u.bMarks[h]+u.tShift[h],g=u.eMarks[h];if(p+1>g)return!1;var v=u.src.charAt(p);if(v!==a)return!1;var R=p;p=u.skipChars(p,v);var O=p-R;if(O!==2)return!1;var I=h;for(;++I,!(I>=f||(p=R=u.bMarks[I]+u.tShift[I],g=u.eMarks[I],p<g&&u.tShift[I]<u.blkIndent));)if(u.src.charAt(p)===a&&!(u.tShift[I]-u.blkIndent>=4)&&(p=u.skipChars(p,v),!(p-R<O)&&(p=u.skipSpaces(p),!(p<g)))){m=!0;break;}O=u.tShift[h],u.line=I+(m?1:0);var z=u.getLines(h+1,I,O,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:z,lines:[h,u.line],level:u.level,block:!0}),!0;},d=function d(u,h){var f=u.pos,m=u.posMax;var p=f;if(u.src.charAt(p)!==a)return!1;for(++p;p<m&&u.src.charAt(p)===a;)++p;var g=u.src.slice(f,p);if(g.length>2)return!1;var v=p;var R=0;for(;p<m;){var O=u.src.charAt(p);if(O==="{"&&(p===0||u.src.charAt(p-1)!=="\\"))R+=1;else if(O==="}"&&(p===0||u.src.charAt(p-1)!=="\\")){if(R-=1,R<0)return!1;}else if(O===a&&R===0){var I=p;var z=p+1;for(;z<m&&u.src.charAt(z)===a;)++z;if(z-I===g.length){if(!h){var xe=u.src.slice(v,I).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:xe,block:g.length>1,level:u.level});}return u.pos=z,!0;}}p+=1;}return h||(u.pending+=g),u.pos+=g.length,!0;};t.inline.ruler.push("katex",d,s),t.block.ruler.push("katex",c,s),t.renderer.rules.katex=function(u,h){return l(u[h].content,u[h].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var _s;function Wn(r){return _s=_s||document.createElement("textarea"),_s.innerHTML="&"+r+";",_s.value;}var xr=Object.prototype.hasOwnProperty;function wr(r,e){return r?xr.call(r,e):!1;}function Xn(r){var e=[].slice.call(arguments,1);return e.forEach(function(t){if(t){if(_typeof(t)!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(s){r[s]=t[s];});}}),r;}var Cr=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ls(r){return r.indexOf("\\")<0?r:r.replace(Cr,"$1");}function Yn(r){return!(r>=55296&&r<=57343||r>=64976&&r<=65007||(r&65535)===65535||(r&65535)===65534||r>=0&&r<=8||r===11||r>=14&&r<=31||r>=127&&r<=159||r>1114111);}function Ti(r){if(r>65535){r-=65536;var e=55296+(r>>10),t=56320+(r&1023);return String.fromCharCode(e,t);}return String.fromCharCode(r);}var Tr=/&([a-z#][a-z0-9]{1,31});/gi,Ar=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function Rr(r,e){var t=0,s=Wn(e);return e!==s?s:e.charCodeAt(0)===35&&Ar.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),Yn(t))?Ti(t):r;}function ut(r){return r.indexOf("&")<0?r:r.replace(Tr,Rr);}var Mr=/[&<>"]/,kr=/[&<>"]/g,Lr={"&":"&","<":"<",">":">",'"':"""};function Ir(r){return Lr[r];}function ne(r){return Mr.test(r)?r.replace(kr,Ir):r;}var b={};b.blockquote_open=function(){return"<blockquote>\n";};b.blockquote_close=function(r,e){return"</blockquote>"+pt(r,e);};b.code=function(r,e){return r[e].block?"<pre><code>"+ne(r[e].content)+"</code></pre>"+pt(r,e):"<code>"+ne(r[e].content)+"</code>";};b.fence=function(r,e,t,s,i){var n=r[e],o="",a=t.langPrefix,l="",c,d,u;if(n.params){if(c=n.params.split(/\s+/g),d=c.join(" "),wr(i.rules.fence_custom,c[0]))return i.rules.fence_custom[c[0]](r,e,t,s,i);l=ne(ut(ls(d))),o=' class="'+a+l+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[n.content].concat(c))||ne(n.content):u=ne(n.content),"<pre><code"+o+">"+u+"</code></pre>"+pt(r,e);};b.fence_custom={};b.heading_open=function(r,e){return"<h"+r[e].hLevel+">";};b.heading_close=function(r,e){return"</h"+r[e].hLevel+">\n";};b.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+pt(r,e);};b.bullet_list_open=function(){return"<ul>\n";};b.bullet_list_close=function(r,e){return"</ul>"+pt(r,e);};b.list_item_open=function(){return"<li>";};b.list_item_close=function(){return"</li>\n";};b.ordered_list_open=function(r,e){var t=r[e],s=t.order>1?' start="'+t.order+'"':"";return"<ol"+s+">\n";};b.ordered_list_close=function(r,e){return"</ol>"+pt(r,e);};b.paragraph_open=function(r,e){return r[e].tight?"":"<p>";};b.paragraph_close=function(r,e){var t=!(r[e].tight&&e&&r[e-1].type==="inline"&&!r[e-1].content);return(r[e].tight?"":"</p>")+(t?pt(r,e):"");};b.link_open=function(r,e,t){var s=r[e].title?' title="'+ne(ut(r[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+ne(r[e].href)+'"'+s+i+">";};b.link_close=function(){return"</a>";};b.image=function(r,e,t){var s=' src="'+ne(r[e].src)+'"',i=r[e].title?' title="'+ne(ut(r[e].title))+'"':"",n=' alt="'+(r[e].alt?ne(ut(ls(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+s+n+i+o+">";};b.table_open=function(){return"<table>\n";};b.table_close=function(){return"</table>\n";};b.thead_open=function(){return"<thead>\n";};b.thead_close=function(){return"</thead>\n";};b.tbody_open=function(){return"<tbody>\n";};b.tbody_close=function(){return"</tbody>\n";};b.tr_open=function(){return"<tr>";};b.tr_close=function(){return"</tr>\n";};b.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};b.th_close=function(){return"</th>";};b.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};b.td_close=function(){return"</td>";};b.strong_open=function(){return"<strong>";};b.strong_close=function(){return"</strong>";};b.em_open=function(){return"<em>";};b.em_close=function(){return"</em>";};b.del_open=function(){return"<del>";};b.del_close=function(){return"</del>";};b.ins_open=function(){return"<ins>";};b.ins_close=function(){return"</ins>";};b.mark_open=function(){return"<mark>";};b.mark_close=function(){return"</mark>";};b.sub=function(r,e){return"<sub>"+ne(r[e].content)+"</sub>";};b.sup=function(r,e){return"<sup>"+ne(r[e].content)+"</sup>";};b.hardbreak=function(r,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};b.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};b.text=function(r,e){return ne(r[e].content);};b.htmlblock=function(r,e){return r[e].content;};b.htmltag=function(r,e){return r[e].content;};b.abbr_open=function(r,e){return'<abbr title="'+ne(ut(r[e].title))+'">';};b.abbr_close=function(){return"</abbr>";};b.footnote_ref=function(r,e){var t=Number(r[e].id+1).toString(),s="fnref"+t;return r[e].subId>0&&(s+=":"+r[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+s+'">['+t+"]</a></sup>";};b.footnote_block_open=function(r,e,t){var s=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return s+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};b.footnote_block_close=function(){return"</ol>\n</section>\n";};b.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};b.footnote_close=function(){return"</li>\n";};b.footnote_anchor=function(r,e){var t=Number(r[e].id+1).toString(),s="fnref"+t;return r[e].subId>0&&(s+=":"+r[e].subId),' <a href="#'+s+'" class="footnote-backref">↩</a>';};b.dl_open=function(){return"<dl>\n";};b.dt_open=function(){return"<dt>";};b.dd_open=function(){return"<dd>";};b.dl_close=function(){return"</dl>\n";};b.dt_close=function(){return"</dt>\n";};b.dd_close=function(){return"</dd>\n";};function Zn(r,e){return++e>=r.length-2?e:r[e].type==="paragraph_open"&&r[e].tight&&r[e+1].type==="inline"&&r[e+1].content.length===0&&r[e+2].type==="paragraph_close"&&r[e+2].tight?Zn(r,e+2):e;}var pt=b.getBreak=function(e,t){return t=Zn(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function Ki(){this.rules=Xn({},b),this.getBreak=b.getBreak;}Ki.prototype.renderInline=function(r,e,t){for(var s=this.rules,i=r.length,n=0,o="";i--;)o+=s[r[n].type](r,n++,e,t,this);return o;};Ki.prototype.render=function(r,e,t){for(var s=this.rules,i=r.length,n=-1,o="";++n<i;)r[n].type==="inline"?o+=this.renderInline(r[n].children,e,t):o+=s[r[n].type](r,n,e,t,this);return o;};function ce(){this.__rules__=[],this.__cache__=null;}ce.prototype.__find__=function(r){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===r)return t;return-1;};ce.prototype.__compile__=function(){var r=this,e=[""];r.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(s){e.indexOf(s)<0&&e.push(s);});}),r.__cache__={},e.forEach(function(t){r.__cache__[t]=[],r.__rules__.forEach(function(s){s.enabled&&(t&&s.alt.indexOf(t)<0||r.__cache__[t].push(s.fn));});});};ce.prototype.at=function(r,e,t){var s=this.__find__(r),i=t||{};if(s===-1)throw new Error("Parser rule not found: "+r);this.__rules__[s].fn=e,this.__rules__[s].alt=i.alt||[],this.__cache__=null;};ce.prototype.before=function(r,e,t,s){var i=this.__find__(r),n=s||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i,0,{name:e,enabled:!0,fn:t,alt:n.alt||[]}),this.__cache__=null;};ce.prototype.after=function(r,e,t,s){var i=this.__find__(r),n=s||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i+1,0,{name:e,enabled:!0,fn:t,alt:n.alt||[]}),this.__cache__=null;};ce.prototype.push=function(r,e,t){var s=t||{};this.__rules__.push({name:r,enabled:!0,fn:e,alt:s.alt||[]}),this.__cache__=null;};ce.prototype.enable=function(r,e){r=Array.isArray(r)?r:[r],e&&this.__rules__.forEach(function(t){t.enabled=!1;}),r.forEach(function(t){var s=this.__find__(t);if(s<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[s].enabled=!0;},this),this.__cache__=null;};ce.prototype.disable=function(r){r=Array.isArray(r)?r:[r],r.forEach(function(e){var t=this.__find__(e);if(t<0)throw new Error("Rules manager: invalid rule name "+e);this.__rules__[t].enabled=!1;},this),this.__cache__=null;};ce.prototype.getRules=function(r){return this.__cache__===null&&this.__compile__(),this.__cache__[r]||[];};function Or(r){r.inlineMode?r.tokens.push({type:"inline",content:r.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):r.block.parse(r.src,r.options,r.env,r.tokens);}function mt(r,e,t,s,i){this.src=r,this.env=s,this.options=t,this.parser=e,this.tokens=i,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0;}mt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};mt.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level;};mt.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e;};mt.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0;};function cs(r,e){var t,s,i,n=-1,o=r.posMax,a=r.pos,l=r.isInLabel;if(r.isInLabel)return-1;if(r.labelUnmatchedScopes)return r.labelUnmatchedScopes--,-1;for(r.pos=e+1,r.isInLabel=!0,t=1;r.pos<o;){if(i=r.src.charCodeAt(r.pos),i===91)t++;else if(i===93&&(t--,t===0)){s=!0;break;}r.parser.skipToken(r);}return s?(n=r.pos,r.labelUnmatchedScopes=0):r.labelUnmatchedScopes=t-1,r.pos=a,r.isInLabel=l,n;}function Nr(r,e,t,s){var i,n,o,a,l,c;if(r.charCodeAt(0)!==42||r.charCodeAt(1)!==91||r.indexOf("]:")===-1||(i=new mt(r,e,t,s,[]),n=cs(i,1),n<0||r.charCodeAt(n+1)!==58))return-1;for(a=i.posMax,o=n+2;o<a&&i.src.charCodeAt(o)!==10;o++);return l=r.slice(2,n),c=r.slice(n+2,o).trim(),c.length===0?-1:(s.abbreviations||(s.abbreviations={}),_typeof(s.abbreviations[":"+l])>"u"&&(s.abbreviations[":"+l]=c),o);}function Pr(r){var e=r.tokens,t,s,i,n;if(!r.inlineMode){for(t=1,s=e.length-1;t<s;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(n=Nr(i,r.inline,r.options,r.env),!(n<0));)i=i.slice(n).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Ai(r){var e=ut(r);try{e=decodeURI(e);}catch(_unused3){}return encodeURI(e);}function Qn(r,e){var t,s,i,n=e,o=r.posMax;if(r.src.charCodeAt(e)===60){for(e++;e<o;){if(t=r.src.charCodeAt(e),t===10)return!1;if(t===62)return i=Ai(ls(r.src.slice(n+1,e))),r.parser.validateLink(i)?(r.pos=e+1,r.linkContent=i,!0):!1;if(t===92&&e+1<o){e+=2;continue;}e++;}return!1;}for(s=0;e<o&&(t=r.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue;}if(t===40&&(s++,s>1)||t===41&&(s--,s<0))break;e++;}return n===e||(i=ls(r.src.slice(n,e)),!r.parser.validateLink(i))?!1:(r.linkContent=i,r.pos=e,!0);}function er(r,e){var t,s=e,i=r.posMax,n=r.src.charCodeAt(e);if(n!==34&&n!==39&&n!==40)return!1;for(e++,n===40&&(n=41);e<i;){if(t=r.src.charCodeAt(e),t===n)return r.pos=e+1,r.linkContent=ls(r.src.slice(s+1,e)),!0;if(t===92&&e+1<i){e+=2;continue;}e++;}return!1;}function tr(r){return r.trim().replace(/\s+/g," ").toUpperCase();}function Dr(r,e,t,s){var i,n,o,a,l,c,d,u,h;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(i=new mt(r,e,t,s,[]),n=cs(i,0),n<0||r.charCodeAt(n+1)!==58))return-1;for(a=i.posMax,o=n+2;o<a&&(l=i.src.charCodeAt(o),!(l!==32&&l!==10));o++);if(!Qn(i,o))return-1;for(d=i.linkContent,o=i.pos,c=o,o=o+1;o<a&&(l=i.src.charCodeAt(o),!(l!==32&&l!==10));o++);for(o<a&&c!==o&&er(i,o)?(u=i.linkContent,o=i.pos):(u="",o=c);o<a&&i.src.charCodeAt(o)===32;)o++;return o<a&&i.src.charCodeAt(o)!==10?-1:(h=tr(r.slice(1,n)),_typeof(s.references[h])>"u"&&(s.references[h]={title:u,href:d}),o);}function Br(r){var e=r.tokens,t,s,i,n;if(r.env.references=r.env.references||{},!r.inlineMode){for(t=1,s=e.length-1;t<s;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(n=Dr(i,r.inline,r.options,r.env),!(n<0));)i=i.slice(n).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Fr(r){var e=r.tokens,t,s,i;for(s=0,i=e.length;s<i;s++)t=e[s],t.type==="inline"&&r.inline.parse(t.content,r.options,r.env,t.children);}function Ur(r){var e,t,s,i,n,o,a,l,c,d=0,u=!1,h={};if(r.env.footnotes&&(r.tokens=r.tokens.filter(function(f){return f.type==="footnote_reference_open"?(u=!0,l=[],c=f.label,!1):f.type==="footnote_reference_close"?(u=!1,h[":"+c]=l,!1):(u&&l.push(f),!u);}),!!r.env.footnotes.list)){for(o=r.env.footnotes.list,r.tokens.push({type:"footnote_block_open",level:d++}),e=0,t=o.length;e<t;e++){for(r.tokens.push({type:"footnote_open",id:e,level:d++}),o[e].tokens?(a=[],a.push({type:"paragraph_open",tight:!1,level:d++}),a.push({type:"inline",content:"",level:d,children:o[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--d})):o[e].label&&(a=h[":"+o[e].label]),r.tokens=r.tokens.concat(a),r.tokens[r.tokens.length-1].type==="paragraph_close"?n=r.tokens.pop():n=null,i=o[e].count>0?o[e].count:1,s=0;s<i;s++)r.tokens.push({type:"footnote_anchor",id:e,subId:s,level:d});n&&r.tokens.push(n),r.tokens.push({type:"footnote_close",level:--d});}r.tokens.push({type:"footnote_block_close",level:--d});}}var hn=" \n()[]'\".,!?-";function _i(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function jr(r){var e,t,s,i,n,o,a,l,c,d,u,h,f=r.tokens;if(r.env.abbreviations){for(r.env.abbrRegExp||(h="(^|["+hn.split("").map(_i).join("")+"])("+Object.keys(r.env.abbreviations).map(function(m){return m.substr(1);}).sort(function(m,p){return p.length-m.length;}).map(_i).join("|")+")($|["+hn.split("").map(_i).join("")+"])",r.env.abbrRegExp=new RegExp(h,"g")),d=r.env.abbrRegExp,t=0,s=f.length;t<s;t++)if(f[t].type==="inline"){for(i=f[t].children,e=i.length-1;e>=0;e--)if(n=i[e],n.type==="text"){for(l=0,o=n.content,d.lastIndex=0,c=n.level,a=[];u=d.exec(o);)d.lastIndex>l&&a.push({type:"text",content:o.slice(l,u.index+u[1].length),level:c}),a.push({type:"abbr_open",title:r.env.abbreviations[":"+u[2]],level:c++}),a.push({type:"text",content:u[2],level:c}),a.push({type:"abbr_close",level:--c}),l=d.lastIndex-u[3].length;a.length&&(l<o.length&&a.push({type:"text",content:o.slice(l),level:c}),f[t].children=i=[].concat(i.slice(0,e),a,i.slice(e+1)));}}}}var Hr=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,qr=/\((c|tm|r|p)\)/ig,Vr={c:"©",r:"®",p:"§",tm:"™"};function zr(r){return r.indexOf("(")<0?r:r.replace(qr,function(e,t){return Vr[t.toLowerCase()];});}function Gr(r){var e,t,s,i,n;if(r.options.typographer){for(n=r.tokens.length-1;n>=0;n--)if(r.tokens[n].type==="inline")for(i=r.tokens[n].children,e=i.length-1;e>=0;e--)t=i[e],t.type==="text"&&(s=t.content,s=zr(s),Hr.test(s)&&(s=s.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=s);}}var Kr=/['"]/,un=/['"]/g,Jr=/[-\s()\[\]]/,fn="’";function pn(r,e){return e<0||e>=r.length?!1:!Jr.test(r[e]);}function bt(r,e,t){return r.substr(0,e)+t+r.substr(e+1);}function $r(r){var e,t,s,i,n,o,a,l,c,d,u,h,f,m,p,g,v;if(r.options.typographer){for(v=[],p=r.tokens.length-1;p>=0;p--)if(r.tokens[p].type==="inline"){for(g=r.tokens[p].children,v.length=0,e=0;e<g.length;e++)if(t=g[e],!(t.type!=="text"||Kr.test(t.text))){for(a=g[e].level,f=v.length-1;f>=0&&!(v[f].level<=a);f--);v.length=f+1,s=t.content,n=0,o=s.length;e:for(;n<o&&(un.lastIndex=n,i=un.exec(s),!!i);){if(l=!pn(s,i.index-1),n=i.index+1,m=i[0]==="'",c=!pn(s,n),!c&&!l){m&&(t.content=bt(t.content,i.index,fn));continue;}if(u=!c,h=!l,h){for(f=v.length-1;f>=0&&(d=v[f],!(v[f].level<a));f--)if(d.single===m&&v[f].level===a){d=v[f],m?(g[d.token].content=bt(g[d.token].content,d.pos,r.options.quotes[2]),t.content=bt(t.content,i.index,r.options.quotes[3])):(g[d.token].content=bt(g[d.token].content,d.pos,r.options.quotes[0]),t.content=bt(t.content,i.index,r.options.quotes[1])),v.length=f;continue e;}}u?v.push({token:e,pos:i.index,single:m,level:a}):h&&m&&(t.content=bt(t.content,i.index,fn));}}}}}var Ei=[["block",Or],["abbr",Pr],["references",Br],["inline",Fr],["footnote_tail",Ur],["abbr2",jr],["replacements",Gr],["smartquotes",$r]];function sr(){this.options={},this.ruler=new ce();for(var r=0;r<Ei.length;r++)this.ruler.push(Ei[r][0],Ei[r][1]);}sr.prototype.process=function(r){var e,t,s;for(s=this.ruler.getRules(""),e=0,t=s.length;e<t;e++)s[e](r);};function gt(r,e,t,s,i){var n,o,a,l,c,d,u;for(this.src=r,this.parser=e,this.options=t,this.env=s,this.tokens=i,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,d=0,u=!1,a=l=d=0,c=o.length;l<c;l++){if(n=o.charCodeAt(l),!u)if(n===32){d++;continue;}else u=!0;(n===10||l===c-1)&&(n!==10&&l++,this.bMarks.push(a),this.eMarks.push(l),this.tShift.push(d),u=!1,d=0,a=l+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}gt.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};gt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};gt.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};gt.prototype.skipChars=function(e,t){for(var s=this.src.length;e<s&&this.src.charCodeAt(e)===t;e++);return e;};gt.prototype.skipCharsBack=function(e,t,s){if(e<=s)return e;for(;e>s;)if(t!==this.src.charCodeAt(--e))return e+1;return e;};gt.prototype.getLines=function(e,t,s,i){var n,o,a,l,c,d=e;if(e>=t)return"";if(d+1===t)return o=this.bMarks[d]+Math.min(this.tShift[d],s),a=i?this.eMarks[d]+1:this.eMarks[d],this.src.slice(o,a);for(l=new Array(t-e),n=0;d<t;d++,n++)c=this.tShift[d],c>s&&(c=s),c<0&&(c=0),o=this.bMarks[d]+c,d+1<t||i?a=this.eMarks[d]+1:a=this.eMarks[d],l[n]=this.src.slice(o,a);return l.join("");};function Wr(r,e,t){var s,i;if(r.tShift[e]-r.blkIndent<4)return!1;for(i=s=e+1;s<t;){if(r.isEmpty(s)){s++;continue;}if(r.tShift[s]-r.blkIndent>=4){s++,i=s;continue;}break;}return r.line=s,r.tokens.push({type:"code",content:r.getLines(e,i,4+r.blkIndent,!0),block:!0,lines:[e,r.line],level:r.level}),!0;}function Xr(r,e,t,s){var i,n,o,a,l,c=!1,d=r.bMarks[e]+r.tShift[e],u=r.eMarks[e];if(d+3>u||(i=r.src.charCodeAt(d),i!==126&&i!==96)||(l=d,d=r.skipChars(d,i),n=d-l,n<3)||(o=r.src.slice(d,u).trim(),o.indexOf("`")>=0))return!1;if(s)return!0;for(a=e;a++,!(a>=t||(d=l=r.bMarks[a]+r.tShift[a],u=r.eMarks[a],d<u&&r.tShift[a]<r.blkIndent));)if(r.src.charCodeAt(d)===i&&!(r.tShift[a]-r.blkIndent>=4)&&(d=r.skipChars(d,i),!(d-l<n)&&(d=r.skipSpaces(d),!(d<u)))){c=!0;break;}return n=r.tShift[e],r.line=a+(c?1:0),r.tokens.push({type:"fence",params:o,content:r.getLines(e+1,a,n,!0),lines:[e,r.line],level:r.level}),!0;}function Yr(r,e,t,s){var i,n,o,a,l,c,d,u,h,f,m,p=r.bMarks[e]+r.tShift[e],g=r.eMarks[e];if(p>g||r.src.charCodeAt(p++)!==62||r.level>=r.options.maxNesting)return!1;if(s)return!0;for(r.src.charCodeAt(p)===32&&p++,l=r.blkIndent,r.blkIndent=0,a=[r.bMarks[e]],r.bMarks[e]=p,p=p<g?r.skipSpaces(p):p,n=p>=g,o=[r.tShift[e]],r.tShift[e]=p-r.bMarks[e],u=r.parser.ruler.getRules("blockquote"),i=e+1;i<t&&(p=r.bMarks[i]+r.tShift[i],g=r.eMarks[i],!(p>=g));i++){if(r.src.charCodeAt(p++)===62){r.src.charCodeAt(p)===32&&p++,a.push(r.bMarks[i]),r.bMarks[i]=p,p=p<g?r.skipSpaces(p):p,n=p>=g,o.push(r.tShift[i]),r.tShift[i]=p-r.bMarks[i];continue;}if(n)break;for(m=!1,h=0,f=u.length;h<f;h++)if(u[h](r,i,t,!0)){m=!0;break;}if(m)break;a.push(r.bMarks[i]),o.push(r.tShift[i]),r.tShift[i]=-1337;}for(c=r.parentType,r.parentType="blockquote",r.tokens.push({type:"blockquote_open",lines:d=[e,0],level:r.level++}),r.parser.tokenize(r,e,i),r.tokens.push({type:"blockquote_close",level:--r.level}),r.parentType=c,d[1]=r.line,h=0;h<o.length;h++)r.bMarks[h+e]=a[h],r.tShift[h+e]=o[h];return r.blkIndent=l,!0;}function Zr(r,e,t,s){var i,n,o,a=r.bMarks[e],l=r.eMarks[e];if(a+=r.tShift[e],a>l||(i=r.src.charCodeAt(a++),i!==42&&i!==45&&i!==95))return!1;for(n=1;a<l;){if(o=r.src.charCodeAt(a++),o!==i&&o!==32)return!1;o===i&&n++;}return n<3?!1:(s||(r.line=e+1,r.tokens.push({type:"hr",lines:[e,r.line],level:r.level})),!0);}function mn(r,e){var t,s,i;return s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e],s>=i||(t=r.src.charCodeAt(s++),t!==42&&t!==45&&t!==43)||s<i&&r.src.charCodeAt(s)!==32?-1:s;}function gn(r,e){var t,s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e];if(s+1>=i||(t=r.src.charCodeAt(s++),t<48||t>57))return-1;for(;;){if(s>=i)return-1;if(t=r.src.charCodeAt(s++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return s<i&&r.src.charCodeAt(s)!==32?-1:s;}function Qr(r,e){var t,s,i=r.level+2;for(t=e+2,s=r.tokens.length-2;t<s;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function eo(r,e,t,s){var i,n,o,a,l,c,d,u,h,f,m,p,g,v,R,O,I,z,xe=!0,ze,re,an,vi;if((u=gn(r,e))>=0)g=!0;else if((u=mn(r,e))>=0)g=!1;else return!1;if(r.level>=r.options.maxNesting)return!1;if(p=r.src.charCodeAt(u-1),s)return!0;for(R=r.tokens.length,g?(d=r.bMarks[e]+r.tShift[e],m=Number(r.src.substr(d,u-d-1)),r.tokens.push({type:"ordered_list_open",order:m,lines:I=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:I=[e,0],level:r.level++}),i=e,O=!1,ze=r.parser.ruler.getRules("list");i<t&&(v=r.skipSpaces(u),h=r.eMarks[i],v>=h?f=1:f=v-u,f>4&&(f=1),f<1&&(f=1),n=u-r.bMarks[i]+f,r.tokens.push({type:"list_item_open",lines:z=[e,0],level:r.level++}),a=r.blkIndent,l=r.tight,o=r.tShift[e],c=r.parentType,r.tShift[e]=v-r.bMarks[e],r.blkIndent=n,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||O)&&(xe=!1),O=r.line-e>1&&r.isEmpty(r.line-1),r.blkIndent=a,r.tShift[e]=o,r.tight=l,r.parentType=c,r.tokens.push({type:"list_item_close",level:--r.level}),i=e=r.line,z[1]=i,v=r.bMarks[e],!(i>=t||r.isEmpty(i)||r.tShift[i]<r.blkIndent));){for(vi=!1,re=0,an=ze.length;re<an;re++)if(ze[re](r,i,t,!0)){vi=!0;break;}if(vi)break;if(g){if(u=gn(r,i),u<0)break;}else if(u=mn(r,i),u<0)break;if(p!==r.src.charCodeAt(u-1))break;}return r.tokens.push({type:g?"ordered_list_close":"bullet_list_close",level:--r.level}),I[1]=i,r.line=i,xe&&Qr(r,R),!0;}function to(r,e,t,s){var i,n,o,a,l,c=r.bMarks[e]+r.tShift[e],d=r.eMarks[e];if(c+4>d||r.src.charCodeAt(c)!==91||r.src.charCodeAt(c+1)!==94||r.level>=r.options.maxNesting)return!1;for(a=c+2;a<d;a++){if(r.src.charCodeAt(a)===32)return!1;if(r.src.charCodeAt(a)===93)break;}return a===c+2||a+1>=d||r.src.charCodeAt(++a)!==58?!1:(s||(a++,r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.refs||(r.env.footnotes.refs={}),l=r.src.slice(c+2,a-2),r.env.footnotes.refs[":"+l]=-1,r.tokens.push({type:"footnote_reference_open",label:l,level:r.level++}),i=r.bMarks[e],n=r.tShift[e],o=r.parentType,r.tShift[e]=r.skipSpaces(a)-a,r.bMarks[e]=a,r.blkIndent+=4,r.parentType="footnote",r.tShift[e]<r.blkIndent&&(r.tShift[e]+=r.blkIndent,r.bMarks[e]-=r.blkIndent),r.parser.tokenize(r,e,t,!0),r.parentType=o,r.blkIndent-=4,r.tShift[e]=n,r.bMarks[e]=i,r.tokens.push({type:"footnote_reference_close",level:--r.level})),!0);}function so(r,e,t,s){var i,n,o,a=r.bMarks[e]+r.tShift[e],l=r.eMarks[e];if(a>=l||(i=r.src.charCodeAt(a),i!==35||a>=l))return!1;for(n=1,i=r.src.charCodeAt(++a);i===35&&a<l&&n<=6;)n++,i=r.src.charCodeAt(++a);return n>6||a<l&&i!==32?!1:(s||(l=r.skipCharsBack(l,32,a),o=r.skipCharsBack(l,35,a),o>a&&r.src.charCodeAt(o-1)===32&&(l=o),r.line=e+1,r.tokens.push({type:"heading_open",hLevel:n,lines:[e,r.line],level:r.level}),a<l&&r.tokens.push({type:"inline",content:r.src.slice(a,l).trim(),level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"heading_close",hLevel:n,level:r.level})),!0);}function io(r,e,t){var s,i,n,o=e+1;return o>=t||r.tShift[o]<r.blkIndent||r.tShift[o]-r.blkIndent>3||(i=r.bMarks[o]+r.tShift[o],n=r.eMarks[o],i>=n)||(s=r.src.charCodeAt(i),s!==45&&s!==61)||(i=r.skipChars(i,s),i=r.skipSpaces(i),i<n)?!1:(i=r.bMarks[e]+r.tShift[e],r.line=o+1,r.tokens.push({type:"heading_open",hLevel:s===61?1:2,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:r.src.slice(i,r.eMarks[e]).trim(),level:r.level+1,lines:[e,r.line-1],children:[]}),r.tokens.push({type:"heading_close",hLevel:s===61?1:2,level:r.level}),!0);}var ir={};["article","aside","button","blockquote","body","canvas","caption","col","colgroup","dd","div","dl","dt","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","iframe","li","map","object","ol","output","p","pre","progress","script","section","style","table","tbody","td","textarea","tfoot","th","tr","thead","ul","video"].forEach(function(r){ir[r]=!0;});var no=/^<([a-zA-Z]{1,15})[\s\/>]/,ro=/^<\/([a-zA-Z]{1,15})[\s>]/;function oo(r){var e=r|32;return e>=97&&e<=122;}function ao(r,e,t,s){var i,n,o,a=r.bMarks[e],l=r.eMarks[e],c=r.tShift[e];if(a+=c,!r.options.html||c>3||a+2>=l||r.src.charCodeAt(a)!==60)return!1;if(i=r.src.charCodeAt(a+1),i===33||i===63){if(s)return!0;}else if(i===47||oo(i)){if(i===47){if(n=r.src.slice(a,l).match(ro),!n)return!1;}else if(n=r.src.slice(a,l).match(no),!n)return!1;if(ir[n[1].toLowerCase()]!==!0)return!1;if(s)return!0;}else return!1;for(o=e+1;o<r.lineMax&&!r.isEmpty(o);)o++;return r.line=o,r.tokens.push({type:"htmlblock",level:r.level,lines:[e,r.line],content:r.getLines(e,o,0,!0)}),!0;}function Si(r,e){var t=r.bMarks[e]+r.blkIndent,s=r.eMarks[e];return r.src.substr(t,s-t);}function lo(r,e,t,s){var i,n,o,a,l,c,d,u,h,f,m;if(e+2>t||(l=e+1,r.tShift[l]<r.blkIndent)||(o=r.bMarks[l]+r.tShift[l],o>=r.eMarks[l])||(i=r.src.charCodeAt(o),i!==124&&i!==45&&i!==58)||(n=Si(r,e+1),!/^[-:| ]+$/.test(n))||(c=n.split("|"),c<=2))return!1;for(u=[],a=0;a<c.length;a++){if(h=c[a].trim(),!h){if(a===0||a===c.length-1)continue;return!1;}if(!/^:?-+:?$/.test(h))return!1;h.charCodeAt(h.length-1)===58?u.push(h.charCodeAt(0)===58?"center":"right"):h.charCodeAt(0)===58?u.push("left"):u.push("");}if(n=Si(r,e).trim(),n.indexOf("|")===-1||(c=n.replace(/^\||\|$/g,"").split("|"),u.length!==c.length))return!1;if(s)return!0;for(r.tokens.push({type:"table_open",lines:f=[e,0],level:r.level++}),r.tokens.push({type:"thead_open",lines:[e,e+1],level:r.level++}),r.tokens.push({type:"tr_open",lines:[e,e+1],level:r.level++}),a=0;a<c.length;a++)r.tokens.push({type:"th_open",align:u[a],lines:[e,e+1],level:r.level++}),r.tokens.push({type:"inline",content:c[a].trim(),lines:[e,e+1],level:r.level,children:[]}),r.tokens.push({type:"th_close",level:--r.level});for(r.tokens.push({type:"tr_close",level:--r.level}),r.tokens.push({type:"thead_close",level:--r.level}),r.tokens.push({type:"tbody_open",lines:m=[e+2,0],level:r.level++}),l=e+2;l<t&&!(r.tShift[l]<r.blkIndent||(n=Si(r,l).trim(),n.indexOf("|")===-1));l++){for(c=n.replace(/^\||\|$/g,"").split("|"),r.tokens.push({type:"tr_open",level:r.level++}),a=0;a<c.length;a++)r.tokens.push({type:"td_open",align:u[a],level:r.level++}),d=c[a].substring(c[a].charCodeAt(0)===124?1:0,c[a].charCodeAt(c[a].length-1)===124?c[a].length-1:c[a].length).trim(),r.tokens.push({type:"inline",content:d,level:r.level,children:[]}),r.tokens.push({type:"td_close",level:--r.level});r.tokens.push({type:"tr_close",level:--r.level});}return r.tokens.push({type:"tbody_close",level:--r.level}),r.tokens.push({type:"table_close",level:--r.level}),f[1]=m[1]=l,r.line=l,!0;}function Es(r,e){var t,s,i=r.bMarks[e]+r.tShift[e],n=r.eMarks[e];return i>=n||(s=r.src.charCodeAt(i++),s!==126&&s!==58)||(t=r.skipSpaces(i),i===t)||t>=n?-1:t;}function co(r,e){var t,s,i=r.level+2;for(t=e+2,s=r.tokens.length-2;t<s;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function ho(r,e,t,s){var i,n,o,a,l,c,d,u,h,f,m,p,g,v;if(s)return r.ddIndent<0?!1:Es(r,e)>=0;if(d=e+1,r.isEmpty(d)&&++d>t||r.tShift[d]<r.blkIndent||(i=Es(r,d),i<0)||r.level>=r.options.maxNesting)return!1;c=r.tokens.length,r.tokens.push({type:"dl_open",lines:l=[e,0],level:r.level++}),o=e,n=d;e:for(;;){for(v=!0,g=!1,r.tokens.push({type:"dt_open",lines:[o,o],level:r.level++}),r.tokens.push({type:"inline",content:r.getLines(o,o+1,r.blkIndent,!1).trim(),level:r.level+1,lines:[o,o],children:[]}),r.tokens.push({type:"dt_close",level:--r.level});;){if(r.tokens.push({type:"dd_open",lines:a=[d,0],level:r.level++}),p=r.tight,h=r.ddIndent,u=r.blkIndent,m=r.tShift[n],f=r.parentType,r.blkIndent=r.ddIndent=r.tShift[n]+2,r.tShift[n]=i-r.bMarks[n],r.tight=!0,r.parentType="deflist",r.parser.tokenize(r,n,t,!0),(!r.tight||g)&&(v=!1),g=r.line-n>1&&r.isEmpty(r.line-1),r.tShift[n]=m,r.tight=p,r.parentType=f,r.blkIndent=u,r.ddIndent=h,r.tokens.push({type:"dd_close",level:--r.level}),a[1]=d=r.line,d>=t||r.tShift[d]<r.blkIndent)break e;if(i=Es(r,d),i<0)break;n=d;}if(d>=t||(o=d,r.isEmpty(o))||r.tShift[o]<r.blkIndent||(n=o+1,n>=t)||(r.isEmpty(n)&&n++,n>=t)||r.tShift[n]<r.blkIndent||(i=Es(r,n),i<0))break;}return r.tokens.push({type:"dl_close",level:--r.level}),l[1]=d,r.line=d,v&&co(r,c),!0;}function uo(r,e){var t,s,i,n,o,a=e+1,l;if(t=r.lineMax,a<t&&!r.isEmpty(a)){for(l=r.parser.ruler.getRules("paragraph");a<t&&!r.isEmpty(a);a++)if(!(r.tShift[a]-r.blkIndent>3)){for(i=!1,n=0,o=l.length;n<o;n++)if(l[n](r,a,t,!0)){i=!0;break;}if(i)break;}}return s=r.getLines(e,a,r.blkIndent,!1).trim(),r.line=a,s.length&&(r.tokens.push({type:"paragraph_open",tight:!1,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:s,level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"paragraph_close",tight:!1,level:r.level})),!0;}var Ss=[["code",Wr],["fences",Xr,["paragraph","blockquote","list"]],["blockquote",Yr,["paragraph","blockquote","list"]],["hr",Zr,["paragraph","blockquote","list"]],["list",eo,["paragraph","blockquote"]],["footnote",to,["paragraph"]],["heading",so,["paragraph","blockquote"]],["lheading",io],["htmlblock",ao,["paragraph","blockquote"]],["table",lo,["paragraph"]],["deflist",ho,["paragraph"]],["paragraph",uo]];function Ji(){this.ruler=new ce();for(var r=0;r<Ss.length;r++)this.ruler.push(Ss[r][0],Ss[r][1],{alt:(Ss[r][2]||[]).slice()});}Ji.prototype.tokenize=function(r,e,t){for(var s=this.ruler.getRules(""),i=s.length,n=e,o=!1,a,l;n<t&&(r.line=n=r.skipEmptyLines(n),!(n>=t||r.tShift[n]<r.blkIndent));){for(l=0;l<i&&(a=s[l](r,n,t,!1),!a);l++);if(r.tight=!o,r.isEmpty(r.line-1)&&(o=!0),n=r.line,n<t&&r.isEmpty(n)){if(o=!0,n++,n<t&&r.parentType==="list"&&r.isEmpty(n))break;r.line=n;}}};var fo=/[\n\t]/g,po=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,mo=/\u00a0/g;Ji.prototype.parse=function(r,e,t,s){var i,n=0,o=0;if(!r)return[];r=r.replace(mo," "),r=r.replace(po,"\n"),r.indexOf(" ")>=0&&(r=r.replace(fo,function(a,l){var c;return r.charCodeAt(l)===10?(n=l+1,o=0,a):(c=" ".slice((l-n-o)%4),o=l-n+1,c);})),i=new gt(r,this,e,t,s),this.tokenize(i,i.line,i.lineMax);};function go(r){switch(r){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1;}}function yo(r,e){for(var t=r.pos;t<r.posMax&&!go(r.src.charCodeAt(t));)t++;return t===r.pos?!1:(e||(r.pending+=r.src.slice(r.pos,t)),r.pos=t,!0);}function bo(r,e){var t,s,i=r.pos;if(r.src.charCodeAt(i)!==10)return!1;if(t=r.pending.length-1,s=r.posMax,!e)if(t>=0&&r.pending.charCodeAt(t)===32){if(t>=1&&r.pending.charCodeAt(t-1)===32){for(var n=t-2;n>=0;n--)if(r.pending.charCodeAt(n)!==32){r.pending=r.pending.substring(0,n+1);break;}r.push({type:"hardbreak",level:r.level});}else r.pending=r.pending.slice(0,-1),r.push({type:"softbreak",level:r.level});}else r.push({type:"softbreak",level:r.level});for(i++;i<s&&r.src.charCodeAt(i)===32;)i++;return r.pos=i,!0;}var $i=[];for(var yn=0;yn<256;yn++)$i.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){$i[r.charCodeAt(0)]=1;});function vo(r,e){var t,s=r.pos,i=r.posMax;if(r.src.charCodeAt(s)!==92)return!1;if(s++,s<i){if(t=r.src.charCodeAt(s),t<256&&$i[t]!==0)return e||(r.pending+=r.src[s]),r.pos+=2,!0;if(t===10){for(e||r.push({type:"hardbreak",level:r.level}),s++;s<i&&r.src.charCodeAt(s)===32;)s++;return r.pos=s,!0;}}return e||(r.pending+="\\"),r.pos++,!0;}function _o(r,e){var t,s,i,n,o,a=r.pos,l=r.src.charCodeAt(a);if(l!==96)return!1;for(t=a,a++,s=r.posMax;a<s&&r.src.charCodeAt(a)===96;)a++;for(i=r.src.slice(t,a),n=o=a;(n=r.src.indexOf("`",o))!==-1;){for(o=n+1;o<s&&r.src.charCodeAt(o)===96;)o++;if(o-n===i.length)return e||r.push({type:"code",content:r.src.slice(a,n).replace(/[ \n]+/g," ").trim(),block:!1,level:r.level}),r.pos=o,!0;}return e||(r.pending+=i),r.pos+=i.length,!0;}function Eo(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==126||e||o+4>=n||r.src.charCodeAt(o+1)!==126||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===126)||l===126||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===126;)s++;if(s>o+3)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===126&&r.src.charCodeAt(r.pos+1)===126&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==126&&a!==126&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"del_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"del_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function So(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==43||e||o+4>=n||r.src.charCodeAt(o+1)!==43||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===43)||l===43||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===43;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===43&&r.src.charCodeAt(r.pos+1)===43&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==43&&a!==43&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"ins_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"ins_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function xo(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==61||e||o+4>=n||r.src.charCodeAt(o+1)!==61||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===61)||l===61||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===61;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===61&&r.src.charCodeAt(r.pos+1)===61&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==61&&a!==61&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"mark_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"mark_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function bn(r){return r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122;}function vn(r,e){var t=e,s,i,n,o=!0,a=!0,l=r.posMax,c=r.src.charCodeAt(e);for(s=e>0?r.src.charCodeAt(e-1):-1;t<l&&r.src.charCodeAt(t)===c;)t++;return t>=l&&(o=!1),n=t-e,n>=4?o=a=!1:(i=t<l?r.src.charCodeAt(t):-1,(i===32||i===10)&&(o=!1),(s===32||s===10)&&(a=!1),c===95&&(bn(s)&&(o=!1),bn(i)&&(a=!1))),{can_open:o,can_close:a,delims:n};}function wo(r,e){var t,s,i,n,o,a,l,c=r.posMax,d=r.pos,u=r.src.charCodeAt(d);if(u!==95&&u!==42||e)return!1;if(l=vn(r,d),t=l.delims,!l.can_open)return r.pos+=t,e||(r.pending+=r.src.slice(d,r.pos)),!0;if(r.level>=r.options.maxNesting)return!1;for(r.pos=d+t,a=[t];r.pos<c;){if(r.src.charCodeAt(r.pos)===u){if(l=vn(r,r.pos),s=l.delims,l.can_close){for(n=a.pop(),o=s;n!==o;){if(o<n){a.push(n-o);break;}if(o-=n,a.length===0)break;r.pos+=n,n=a.pop();}if(a.length===0){t=n,i=!0;break;}r.pos+=s;continue;}l.can_open&&a.push(s),r.pos+=s;continue;}r.parser.skipToken(r);}return i?(r.posMax=r.pos,r.pos=d+t,e||((t===2||t===3)&&r.push({type:"strong_open",level:r.level++}),(t===1||t===3)&&r.push({type:"em_open",level:r.level++}),r.parser.tokenize(r),(t===1||t===3)&&r.push({type:"em_close",level:--r.level}),(t===2||t===3)&&r.push({type:"strong_close",level:--r.level})),r.pos=r.posMax+t,r.posMax=c,!0):(r.pos=d,!1);}var Co=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function To(r,e){var t,s,i=r.posMax,n=r.pos;if(r.src.charCodeAt(n)!==126||e||n+2>=i||r.level>=r.options.maxNesting)return!1;for(r.pos=n+1;r.pos<i;){if(r.src.charCodeAt(r.pos)===126){t=!0;break;}r.parser.skipToken(r);}return!t||n+1===r.pos||(s=r.src.slice(n+1,r.pos),s.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=n,!1):(r.posMax=r.pos,r.pos=n+1,e||r.push({type:"sub",level:r.level,content:s.replace(Co,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}var Ao=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Ro(r,e){var t,s,i=r.posMax,n=r.pos;if(r.src.charCodeAt(n)!==94||e||n+2>=i||r.level>=r.options.maxNesting)return!1;for(r.pos=n+1;r.pos<i;){if(r.src.charCodeAt(r.pos)===94){t=!0;break;}r.parser.skipToken(r);}return!t||n+1===r.pos||(s=r.src.slice(n+1,r.pos),s.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=n,!1):(r.posMax=r.pos,r.pos=n+1,e||r.push({type:"sup",level:r.level,content:s.replace(Ao,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}function Mo(r,e){var t,s,i,n,o,a,l,c,d=!1,u=r.pos,h=r.posMax,f=r.pos,m=r.src.charCodeAt(f);if(m===33&&(d=!0,m=r.src.charCodeAt(++f)),m!==91||r.level>=r.options.maxNesting||(t=f+1,s=cs(r,f),s<0))return!1;if(a=s+1,a<h&&r.src.charCodeAt(a)===40){for(a++;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a>=h)return!1;for(f=a,Qn(r,a)?(n=r.linkContent,a=r.pos):n="",f=a;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<h&&f!==a&&er(r,a))for(o=r.linkContent,a=r.pos;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);else o="";if(a>=h||r.src.charCodeAt(a)!==41)return r.pos=u,!1;a++;}else{if(r.linkLevel>0)return!1;for(;a<h&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<h&&r.src.charCodeAt(a)===91&&(f=a+1,a=cs(r,a),a>=0?i=r.src.slice(f,a++):a=f-1),i||(_typeof(i)>"u"&&(a=s+1),i=r.src.slice(t,s)),l=r.env.references[tr(i)],!l)return r.pos=u,!1;n=l.href,o=l.title;}return e||(r.pos=t,r.posMax=s,d?r.push({type:"image",src:n,title:o,alt:r.src.substr(t,s-t),level:r.level}):(r.push({type:"link_open",href:n,title:o,level:r.level++}),r.linkLevel++,r.parser.tokenize(r),r.linkLevel--,r.push({type:"link_close",level:--r.level}))),r.pos=a,r.posMax=h,!0;}function ko(r,e){var t,s,i,n,o=r.posMax,a=r.pos;return a+2>=o||r.src.charCodeAt(a)!==94||r.src.charCodeAt(a+1)!==91||r.level>=r.options.maxNesting||(t=a+2,s=cs(r,a+1),s<0)?!1:(e||(r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.list||(r.env.footnotes.list=[]),i=r.env.footnotes.list.length,r.pos=t,r.posMax=s,r.push({type:"footnote_ref",id:i,level:r.level}),r.linkLevel++,n=r.tokens.length,r.parser.tokenize(r),r.env.footnotes.list[i]={tokens:r.tokens.splice(n)},r.linkLevel--),r.pos=s+1,r.posMax=o,!0);}function Lo(r,e){var t,s,i,n,o=r.posMax,a=r.pos;if(a+3>o||!r.env.footnotes||!r.env.footnotes.refs||r.src.charCodeAt(a)!==91||r.src.charCodeAt(a+1)!==94||r.level>=r.options.maxNesting)return!1;for(s=a+2;s<o;s++){if(r.src.charCodeAt(s)===32||r.src.charCodeAt(s)===10)return!1;if(r.src.charCodeAt(s)===93)break;}return s===a+2||s>=o||(s++,t=r.src.slice(a+2,s-1),_typeof(r.env.footnotes.refs[":"+t])>"u")?!1:(e||(r.env.footnotes.list||(r.env.footnotes.list=[]),r.env.footnotes.refs[":"+t]<0?(i=r.env.footnotes.list.length,r.env.footnotes.list[i]={label:t,count:0},r.env.footnotes.refs[":"+t]=i):i=r.env.footnotes.refs[":"+t],n=r.env.footnotes.list[i].count,r.env.footnotes.list[i].count++,r.push({type:"footnote_ref",id:i,subId:n,level:r.level})),r.pos=s,r.posMax=o,!0);}var Io=["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"],Oo=/^<([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])?)*)>/,No=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Po(r,e){var t,s,i,n,o,a=r.pos;return r.src.charCodeAt(a)!==60||(t=r.src.slice(a),t.indexOf(">")<0)?!1:(s=t.match(No),s?Io.indexOf(s[1].toLowerCase())<0||(n=s[0].slice(1,-1),o=Ai(n),!r.parser.validateLink(n))?!1:(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:n,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=s[0].length,!0):(i=t.match(Oo),i?(n=i[0].slice(1,-1),o=Ai("mailto:"+n),r.parser.validateLink(o)?(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:n,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=i[0].length,!0):!1):!1));}function ui(r,e){return r=r.source,e=e||"",function t(s,i){return s?(i=i.source||i,r=r.replace(s,i),t):new RegExp(r,e);};}var Do=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Bo=/[^"'=<>`\x00-\x20]+/,Fo=/'[^']*'/,Uo=/"[^"]*"/,jo=ui(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Bo)("single_quoted",Fo)("double_quoted",Uo)(),Ho=ui(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Do)("attr_value",jo)(),qo=ui(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",Ho)(),Vo=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,zo=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Go=/<[?].*?[?]>/,Ko=/<![A-Z]+\s+[^>]*>/,Jo=/<!\[CDATA\[[\s\S]*?\]\]>/,$o=ui(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",qo)("close_tag",Vo)("comment",zo)("processing",Go)("declaration",Ko)("cdata",Jo)();function Wo(r){var e=r|32;return e>=97&&e<=122;}function Xo(r,e){var t,s,i,n=r.pos;return!r.options.html||(i=r.posMax,r.src.charCodeAt(n)!==60||n+2>=i)||(t=r.src.charCodeAt(n+1),t!==33&&t!==63&&t!==47&&!Wo(t))||(s=r.src.slice(n).match($o),!s)?!1:(e||r.push({type:"htmltag",content:r.src.slice(n,n+s[0].length),level:r.level}),r.pos+=s[0].length,!0);}var Yo=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Zo=/^&([a-z][a-z0-9]{1,31});/i;function Qo(r,e){var t,s,i,n=r.pos,o=r.posMax;if(r.src.charCodeAt(n)!==38)return!1;if(n+1<o){if(t=r.src.charCodeAt(n+1),t===35){if(i=r.src.slice(n).match(Yo),i)return e||(s=i[1][0].toLowerCase()==="x"?parseInt(i[1].slice(1),16):parseInt(i[1],10),r.pending+=Yn(s)?Ti(s):Ti(65533)),r.pos+=i[0].length,!0;}else if(i=r.src.slice(n).match(Zo),i){var a=Wn(i[1]);if(i[1]!==a)return e||(r.pending+=a),r.pos+=i[0].length,!0;}}return e||(r.pending+="&"),r.pos++,!0;}var xi=[["text",yo],["newline",bo],["escape",vo],["backticks",_o],["del",Eo],["ins",So],["mark",xo],["emphasis",wo],["sub",To],["sup",Ro],["links",Mo],["footnote_inline",ko],["footnote_ref",Lo],["autolink",Po],["htmltag",Xo],["entity",Qo]];function fi(){this.ruler=new ce();for(var r=0;r<xi.length;r++)this.ruler.push(xi[r][0],xi[r][1]);this.validateLink=ea;}fi.prototype.skipToken=function(r){var e=this.ruler.getRules(""),t=e.length,s=r.pos,i,n;if((n=r.cacheGet(s))>0){r.pos=n;return;}for(i=0;i<t;i++)if(e[i](r,!0)){r.cacheSet(s,r.pos);return;}r.pos++,r.cacheSet(s,r.pos);};fi.prototype.tokenize=function(r){for(var e=this.ruler.getRules(""),t=e.length,s=r.posMax,i,n;r.pos<s;){for(n=0;n<t&&(i=e[n](r,!1),!i);n++);if(i){if(r.pos>=s)break;continue;}r.pending+=r.src[r.pos++];}r.pending&&r.pushPending();};fi.prototype.parse=function(r,e,t,s){var i=new mt(r,this,e,t,s);this.tokenize(i);};function ea(r){var e=["vbscript","javascript","file","data"],t=r.trim().toLowerCase();return t=ut(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var ta={options:{html:!1,// Enable HTML tags in source
|
21
|
+
},{key:"removeFileRef",value:function removeFileRef(e){var t=_objectSpread({},e);return delete t.ref,t;}},{key:"isAudioFile",value:function isAudioFile(e){var t=/\.(mp3|ogg|wav|aac|webm|4a)$/i,s=e.type,i=e.src;return s==="audio"||(i==null?void 0:i.startsWith("data:audio"))||i&&t.test(i);}},{key:"isImageFile",value:function isImageFile(e){var t=e.type,s=e.src;return t==="image"||(s==null?void 0:s.startsWith("data:image"))||s&&Se.isImageFileExtension(s);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();Se.DEFAULT_FILE_NAME="file",Se.FILE_BUBBLE_CLASS="file-message";var Q=Se;var le=/*#__PURE__*/function(){function le(){_classCallCheck(this,le);}return _createClass(le,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var s=e.containerStyle;s&&(Object.assign(t.style,s),console.error("The containerStyle property is deprecated since version 1.3.14."),console.error("Please change to using the style property instead: https://deepchat.dev/docs/styles#style"));}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
22
|
+
},{key:"handleResponseProperty",value:function handleResponseProperty(e){return console.error("The {result: ....} response object type is deprecated since version 1.3.0."),console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console.error("The initialMessages property is deprecated since version 2.0.0."),console.error("Please change to using the history property instead: https://deepchat.dev/docs/messages/#history"),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e.file;t&&(console.error("The file property in MessageContent is deprecated since version 1.3.17."),console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"),e.files=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console.error("The validateMessageBeforeSending property is deprecated since version 1.3.24."),console.error("Please change to using validateInput: https://deepchat.dev/docs/interceptors#validateInput"),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."),console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"),_defineProperty({},g,e);}},{key:"flagHTMLUpdateClass",value:function flagHTMLUpdateClass(e){var t;(t=e.children[0])!=null&&t.classList.contains("deep-chat-update-message")&&(console.error('The "deep-chat-update-message" html class is deprecated since version 1.4.4.'),console.error("Please change to using {..., overwrite: true} object: https://deepchat.dev/docs/connect#Response"));}},{key:"processConnect",value:function processConnect(e){var t=e;t.request&&(t.connect?Object.assign(t.connect,t.request):t.connect=t.request,console.error("The request property is deprecated since version 2.0.0."),console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console.error("The stream property has been moved to the connect object in version 2.0.0."),console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var i;var s=e;s.onNewMessage&&(console.error("The onNewMessage event has been deprecated since version 2.0.0."),console.error("Please see the onMessage event: https://deepchat.dev/docs/events#onMessage"),(i=s.onNewMessage)==null||i.call(s,t)),e.dispatchEvent(new CustomEvent("new-message",{detail:t}));}},{key:"processFileConfigConnect",value:function processFileConfigConnect(e){var t=e;t.request&&(console.error("The request property in file configuration is deprecated since version 2.0.0."),console.error("Please use the connect property instead: https://deepchat.dev/docs/files"),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=JSON.parse(JSON.stringify(e)),s=t.loading;return s&&(s.outerContainer||s.innerContainer||s.bubble||s.media)&&(console.error("The loading message styles are defined using LoadingMessageStyles interface since version 2.1.0."),console.error("Check it out here: https://deepchat.dev/docs/messages/styles#LoadingMessageStyles"),t.loading={message:{styles:s}}),t;}},{key:"processDemo",value:function processDemo(e){return typeof e=="boolean"||e.displayLoadingBubble&&(console.error("The demo displayLoadingBubble property is deprecated since version 2.1.0."),console.error("Please use displayLoading instead: https://deepchat.dev/docs/modes#demo"),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,s="Please see the official documentation: https://deepchat.dev/docs/directConnection/Cohere";return t.chat&&(console.error("Cohere chat property is deprecated since version 2.2.3."),console.error(s),delete t.chat),t.textGeneration?(console.error("Cohere textGeneration is not supported since version 2.2.3."),console.error(s),delete t.textGeneration,!1):t.summarization?(console.error("Cohere summarization is not supported since version 2.2.3."),console.error(s),delete t.summarization,!1):!0;}// WORK - update link
|
23
|
+
},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==S)return;var t=e.htmlWrappers;if(t)return console.error("The htmlWrappers property has been moved to Deep Chat's base since version 2.3.0."),console.error("Check it out here: https://deepchat.dev/docs/messages/HTML#htmlWrappers"),t;}}]);}();var lt=/*#__PURE__*/function(){function lt(){_classCallCheck(this,lt);}return _createClass(lt,null,[{key:"mouseUp",value:function mouseUp(e,t){U.unsetAllCSSMouseStates(e,t),Object.assign(e.style,t["default"]),Object.assign(e.style,t.hover);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e.style,t.click);}},{key:"mouseLeave",value:function mouseLeave(e,t){U.unsetAllCSSMouseStates(e,t),Object.assign(e.style,t["default"]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e.style,t.hover);}},{key:"add",value:function add(e,t){e.addEventListener("mouseenter",lt.mouseEnter.bind(this,e,t)),e.addEventListener("mouseleave",lt.mouseLeave.bind(this,e,t)),e.addEventListener("mousedown",lt.mouseDown.bind(this,e,t)),e.addEventListener("mouseup",lt.mouseUp.bind(this,e,t));}}]);}();var qr="deep-chat-temporary-message",jr="deep-chat-suggestion-button",Ui={"deep-chat-button":{styles:{"default":{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"},hover:{backgroundColor:"#fafafa"},click:{backgroundColor:"#f1f1f1"}}}},Tn=Object.keys(Ui);var Pe=/*#__PURE__*/function(){function Pe(){_classCallCheck(this,Pe);}return _createClass(Pe,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener("click",function(){var s,i;(i=e.submitUserMessage)==null||i.call(e,_defineProperty({},g,((s=t.textContent)==null?void 0:s.trim())||""));});});}},{key:"isElementTemporary",value:function isElementTemporary(e){var t;return e?(t=e.bubbleElement.children[0])==null?void 0:t.classList.contains(qr):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return Tn.find(function(t){return e.classList.contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var s=Ui[t].events;Object.keys(s||[]).forEach(function(i){e.addEventListener(i,s==null?void 0:s[i]);});}},{key:"getProcessedStyles",value:function getProcessedStyles(e,t,s){var i=Array.from(t.classList).reduce(function(a,l){var d;var c=(d=e[l])==null?void 0:d.styles;return c&&e[l].styles&&a.push(c),a;},[]),n=Ui[s].styles;if(n){var a=JSON.parse(JSON.stringify(n));a["default"]&&U.overwriteDefaultWithAlreadyApplied(a,t),i.unshift(a);}var o=U.mergeStatefulStyles(i);return U.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,s){Tn.forEach(function(n){var o=s.getElementsByClassName(n);Array.from(o||[]).forEach(function(a){var l=Pe.getProcessedStyles(t,a,n);oe.applyStylesToElement(a,l),Pe.applyEvents(a,n);});});var i=s.getElementsByClassName(jr);Array.from(i).forEach(function(n){return Pe.applySuggestionEvent(e,n);});}}]);}();var Te=/*#__PURE__*/function(){function Te(){_classCallCheck(this,Te);}return _createClass(Te,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var s=U.processStateful(t);lt.add(e,s),Object.assign(e.style,s["default"]);}},{key:"applyEventsToElement",value:function applyEventsToElement(e,t){Object.keys(t).forEach(function(s){var i=t[s];i&&e.addEventListener(s,i);});}},{key:"applyClassUtilitiesToElement",value:function applyClassUtilitiesToElement(e,t){var s=t.events,i=t.styles;s&&Te.applyEventsToElement(e,s),i&&!Pe.doesElementContainDeepChatClass(e)&&Te.applyStylesToElement(e,i);}},{key:"applyCustomClassUtilities",value:function applyCustomClassUtilities(e,t){Object.keys(e).forEach(function(s){var i=t.getElementsByClassName(s);Array.from(i).forEach(function(n){e[s]&&Te.applyClassUtilitiesToElement(n,e[s]);});});}},{key:"apply",value:function apply(e,t){Pe.applyDeepChatUtilities(e,e.htmlClassUtilities,t),Te.applyCustomClassUtilities(e.htmlClassUtilities,t);}},{key:"traverseNodes",value:function traverseNodes(e,t){e.nodeType===Node.ELEMENT_NODE&&t.push(e.outerHTML),e.childNodes.forEach(function(s){Te.traverseNodes(s,t);});}},{key:"splitHTML",value:function splitHTML(e){var s=new DOMParser().parseFromString(e,"text/html"),i=[];return s.body.childNodes.forEach(function(n){Te.traverseNodes(n,i);}),i;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=document.createElement("div");return t.innerHTML=e,Pe.isElementTemporary({outerContainer:t,bubbleElement:t,innerContainer:t});}// useful for removing event listeners
|
24
|
+
},{key:"replaceElementWithNewClone",value:function replaceElementWithNewClone(e,t){var i;var s=(t||e).cloneNode(!0);return(i=e.parentNode)==null||i.replaceChild(s,e),s;}},{key:"tryAddWrapper",value:function tryAddWrapper(e,t,s,i){if(t&&i){var n=(s==null?void 0:s[i])||(s==null?void 0:s["default"]);if(n)return e.innerHTML=n,{contentEl:Te.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(Te.TARGET_WRAPPER_CLASS)[0]||e;}}]);}();Te.TARGET_WRAPPER_CLASS="html-wrapper";var oe=Te;var Ke=/*#__PURE__*/function(){function Ke(){_classCallCheck(this,Ke);}return _createClass(Ke,null,[{key:"addElement",value:function addElement(e,t){e.appendOuterContainerElemet(t),e.focusMode||(e.elementRef.scrollTop=e.elementRef.scrollHeight);}},{key:"createElements",value:function createElements(e,t,s,i){var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;var o=e.createMessageElementsOnOrientation("",s,i,n);o.bubbleElement.classList.add(Ke.HTML_BUBBLE_CLASS);var _oe$tryAddWrapper=oe.tryAddWrapper(o.bubbleElement,t,e._customWrappers,s),a=_oe$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,s){s.bubbleElement.innerHTML=t,oe.apply(e,s.outerContainer),le.flagHTMLUpdateClass(s.bubbleElement);}// prettier-ignore
|
25
|
+
},{key:"overwrite",value:function overwrite(e,t,s,i){var n=e.messageToElements,o=b.overwriteMessage(n,i,t,s,"html",Ke.HTML_BUBBLE_CLASS);return o&&Ke.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var n=Ke.createElements(e,t,s,i);return b.fillEmptyMessageElement(n.bubbleElement,t),oe.apply(e,n.outerContainer),le.flagHTMLUpdateClass(n.bubbleElement),e.applyCustomStyles(n,s,!1,(o=e.messageStyles)==null?void 0:o.html),n;}},{key:"add",value:function add(e,t,s,i){var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(i!=null&&i.status){var a=this.overwrite(e,t,s,e.messageElementRefs);if(a)return a;i.status=!1;}if(n&&e.messageElementRefs.length>0&&oe.isTemporaryBasedOnHTML(t))return;var o=Ke.create(e,t,s,n);return n||Ke.addElement(e,o.outerContainer),o;}}]);}();Ke.HTML_BUBBLE_CLASS="html-message";var De=Ke;var Vr=/*#__PURE__*/function(){function Vr(){_classCallCheck(this,Vr);}return _createClass(Vr,null,[{key:"katex",value:function katex(e,t,s){var a=(s||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var l=function l(h,u){var f;return((f=window.katex)==null?void 0:f.renderToString(h,_objectSpread({displayMode:u,throwOnError:!1,output:"mathml"},e)))||"";},c=function c(h,u,f){var m=!1,p=h.bMarks[u]+h.tShift[u],y=h.eMarks[u];if(p+1>y)return!1;var _=h.src.charAt(p);if(_!==a)return!1;var I=p;p=h.skipChars(p,_);var D=p-I;if(D!==2)return!1;var B=u;for(;++B,!(B>=f||(p=I=h.bMarks[B]+h.tShift[B],y=h.eMarks[B],p<y&&h.tShift[B]<h.blkIndent));)if(h.src.charAt(p)===a&&!(h.tShift[B]-h.blkIndent>=4)&&(p=h.skipChars(p,_),!(p-I<D)&&(p=h.skipSpaces(p),!(p<y)))){m=!0;break;}D=h.tShift[u],h.line=B+(m?1:0);var se=h.getLines(u+1,B,D,!0).replace(/[ \n]+/g," ").trim();return h.tokens.push({type:"katex",params:null,content:se,lines:[u,h.line],level:h.level,block:!0}),!0;},d=function d(h,u){var f=h.pos,m=h.posMax;var p=f;if(h.src.charAt(p)!==a)return!1;for(++p;p<m&&h.src.charAt(p)===a;)++p;var y=h.src.slice(f,p);if(y.length>2)return!1;var _=p;var I=0;for(;p<m;){var D=h.src.charAt(p);if(D==="{"&&(p===0||h.src.charAt(p-1)!=="\\"))I+=1;else if(D==="}"&&(p===0||h.src.charAt(p-1)!=="\\")){if(I-=1,I<0)return!1;}else if(D===a&&I===0){var B=p;var se=p+1;for(;se<m&&h.src.charAt(se)===a;)++se;if(se-B===y.length){if(!u){var st=h.src.slice(_,B).replace(/[ \n]+/g," ").trim();h.push({type:"katex",content:st,block:y.length>1,level:h.level});}return h.pos=se,!0;}}p+=1;}return u||(h.pending+=y),h.pos+=y.length,!0;};t.inline.ruler.push("katex",d,s),t.block.ruler.push("katex",c,s),t.renderer.rules.katex=function(h,u){return l(h[u].content,h[u].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var Os;function pr(r){return Os=Os||document.createElement("textarea"),Os.innerHTML="&"+r+";",Os.value;}var Kr=Object.prototype.hasOwnProperty;function zr(r,e){return r?Kr.call(r,e):!1;}function mr(r){var e=[].slice.call(arguments,1);return e.forEach(function(t){if(t){if(_typeof(t)!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(s){r[s]=t[s];});}}),r;}var Gr=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function _s(r){return r.indexOf("\\")<0?r:r.replace(Gr,"$1");}function gr(r){return!(r>=55296&&r<=57343||r>=64976&&r<=65007||(r&65535)===65535||(r&65535)===65534||r>=0&&r<=8||r===11||r>=14&&r<=31||r>=127&&r<=159||r>1114111);}function Hi(r){if(r>65535){r-=65536;var e=55296+(r>>10),t=56320+(r&1023);return String.fromCharCode(e,t);}return String.fromCharCode(r);}var Jr=/&([a-z#][a-z0-9]{1,31});/gi,$r=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function Wr(r,e){var t=0,s=pr(e);return e!==s?s:e.charCodeAt(0)===35&&$r.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),gr(t))?Hi(t):r;}function wt(r){return r.indexOf("&")<0?r:r.replace(Jr,Wr);}var Xr=/[&<>"]/,Yr=/[&<>"]/g,Zr={"&":"&","<":"<",">":">",'"':"""};function Qr(r){return Zr[r];}function pe(r){return Xr.test(r)?r.replace(Yr,Qr):r;}var v={};v.blockquote_open=function(){return"<blockquote>\n";};v.blockquote_close=function(r,e){return"</blockquote>"+At(r,e);};v.code=function(r,e){return r[e].block?"<pre><code>"+pe(r[e].content)+"</code></pre>"+At(r,e):"<code>"+pe(r[e].content)+"</code>";};v.fence=function(r,e,t,s,i){var n=r[e],o="",a=t.langPrefix,l="",c,d,h;if(n.params){if(c=n.params.split(/\s+/g),d=c.join(" "),zr(i.rules.fence_custom,c[0]))return i.rules.fence_custom[c[0]](r,e,t,s,i);l=pe(wt(_s(d))),o=' class="'+a+l+'"';}return t.highlight?h=t.highlight.apply(t.highlight,[n.content].concat(c))||pe(n.content):h=pe(n.content),"<pre><code"+o+">"+h+"</code></pre>"+At(r,e);};v.fence_custom={};v.heading_open=function(r,e){return"<h"+r[e].hLevel+">";};v.heading_close=function(r,e){return"</h"+r[e].hLevel+">\n";};v.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+At(r,e);};v.bullet_list_open=function(){return"<ul>\n";};v.bullet_list_close=function(r,e){return"</ul>"+At(r,e);};v.list_item_open=function(){return"<li>";};v.list_item_close=function(){return"</li>\n";};v.ordered_list_open=function(r,e){var t=r[e],s=t.order>1?' start="'+t.order+'"':"";return"<ol"+s+">\n";};v.ordered_list_close=function(r,e){return"</ol>"+At(r,e);};v.paragraph_open=function(r,e){return r[e].tight?"":"<p>";};v.paragraph_close=function(r,e){var t=!(r[e].tight&&e&&r[e-1].type==="inline"&&!r[e-1].content);return(r[e].tight?"":"</p>")+(t?At(r,e):"");};v.link_open=function(r,e,t){var s=r[e].title?' title="'+pe(wt(r[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+pe(r[e].href)+'"'+s+i+">";};v.link_close=function(){return"</a>";};v.image=function(r,e,t){var s=' src="'+pe(r[e].src)+'"',i=r[e].title?' title="'+pe(wt(r[e].title))+'"':"",n=' alt="'+(r[e].alt?pe(wt(_s(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+s+n+i+o+">";};v.table_open=function(){return"<table>\n";};v.table_close=function(){return"</table>\n";};v.thead_open=function(){return"<thead>\n";};v.thead_close=function(){return"</thead>\n";};v.tbody_open=function(){return"<tbody>\n";};v.tbody_close=function(){return"</tbody>\n";};v.tr_open=function(){return"<tr>";};v.tr_close=function(){return"</tr>\n";};v.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};v.th_close=function(){return"</th>";};v.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};v.td_close=function(){return"</td>";};v.strong_open=function(){return"<strong>";};v.strong_close=function(){return"</strong>";};v.em_open=function(){return"<em>";};v.em_close=function(){return"</em>";};v.del_open=function(){return"<del>";};v.del_close=function(){return"</del>";};v.ins_open=function(){return"<ins>";};v.ins_close=function(){return"</ins>";};v.mark_open=function(){return"<mark>";};v.mark_close=function(){return"</mark>";};v.sub=function(r,e){return"<sub>"+pe(r[e].content)+"</sub>";};v.sup=function(r,e){return"<sup>"+pe(r[e].content)+"</sup>";};v.hardbreak=function(r,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};v.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};v.text=function(r,e){return pe(r[e].content);};v.htmlblock=function(r,e){return r[e].content;};v.htmltag=function(r,e){return r[e].content;};v.abbr_open=function(r,e){return'<abbr title="'+pe(wt(r[e].title))+'">';};v.abbr_close=function(){return"</abbr>";};v.footnote_ref=function(r,e){var t=Number(r[e].id+1).toString(),s="fnref"+t;return r[e].subId>0&&(s+=":"+r[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+s+'">['+t+"]</a></sup>";};v.footnote_block_open=function(r,e,t){var s=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return s+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};v.footnote_block_close=function(){return"</ol>\n</section>\n";};v.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};v.footnote_close=function(){return"</li>\n";};v.footnote_anchor=function(r,e){var t=Number(r[e].id+1).toString(),s="fnref"+t;return r[e].subId>0&&(s+=":"+r[e].subId),' <a href="#'+s+'" class="footnote-backref">↩</a>';};v.dl_open=function(){return"<dl>\n";};v.dt_open=function(){return"<dt>";};v.dd_open=function(){return"<dd>";};v.dl_close=function(){return"</dl>\n";};v.dt_close=function(){return"</dt>\n";};v.dd_close=function(){return"</dd>\n";};function yr(r,e){return++e>=r.length-2?e:r[e].type==="paragraph_open"&&r[e].tight&&r[e+1].type==="inline"&&r[e+1].content.length===0&&r[e+2].type==="paragraph_close"&&r[e+2].tight?yr(r,e+2):e;}var At=v.getBreak=function(e,t){return t=yr(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function dn(){this.rules=mr({},v),this.getBreak=v.getBreak;}dn.prototype.renderInline=function(r,e,t){for(var s=this.rules,i=r.length,n=0,o="";i--;)o+=s[r[n].type](r,n++,e,t,this);return o;};dn.prototype.render=function(r,e,t){for(var s=this.rules,i=r.length,n=-1,o="";++n<i;)r[n].type==="inline"?o+=this.renderInline(r[n].children,e,t):o+=s[r[n].type](r,n,e,t,this);return o;};function _e(){this.__rules__=[],this.__cache__=null;}_e.prototype.__find__=function(r){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===r)return t;return-1;};_e.prototype.__compile__=function(){var r=this,e=[""];r.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(s){e.indexOf(s)<0&&e.push(s);});}),r.__cache__={},e.forEach(function(t){r.__cache__[t]=[],r.__rules__.forEach(function(s){s.enabled&&(t&&s.alt.indexOf(t)<0||r.__cache__[t].push(s.fn));});});};_e.prototype.at=function(r,e,t){var s=this.__find__(r),i=t||{};if(s===-1)throw new Error("Parser rule not found: "+r);this.__rules__[s].fn=e,this.__rules__[s].alt=i.alt||[],this.__cache__=null;};_e.prototype.before=function(r,e,t,s){var i=this.__find__(r),n=s||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i,0,{name:e,enabled:!0,fn:t,alt:n.alt||[]}),this.__cache__=null;};_e.prototype.after=function(r,e,t,s){var i=this.__find__(r),n=s||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i+1,0,{name:e,enabled:!0,fn:t,alt:n.alt||[]}),this.__cache__=null;};_e.prototype.push=function(r,e,t){var s=t||{};this.__rules__.push({name:r,enabled:!0,fn:e,alt:s.alt||[]}),this.__cache__=null;};_e.prototype.enable=function(r,e){r=Array.isArray(r)?r:[r],e&&this.__rules__.forEach(function(t){t.enabled=!1;}),r.forEach(function(t){var s=this.__find__(t);if(s<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[s].enabled=!0;},this),this.__cache__=null;};_e.prototype.disable=function(r){r=Array.isArray(r)?r:[r],r.forEach(function(e){var t=this.__find__(e);if(t<0)throw new Error("Rules manager: invalid rule name "+e);this.__rules__[t].enabled=!1;},this),this.__cache__=null;};_e.prototype.getRules=function(r){return this.__cache__===null&&this.__compile__(),this.__cache__[r]||[];};function eo(r){r.inlineMode?r.tokens.push({type:"inline",content:r.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):r.block.parse(r.src,r.options,r.env,r.tokens);}function Tt(r,e,t,s,i){this.src=r,this.env=s,this.options=t,this.parser=e,this.tokens=i,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0;}Tt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};Tt.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level;};Tt.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e;};Tt.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0;};function Es(r,e){var t,s,i,n=-1,o=r.posMax,a=r.pos,l=r.isInLabel;if(r.isInLabel)return-1;if(r.labelUnmatchedScopes)return r.labelUnmatchedScopes--,-1;for(r.pos=e+1,r.isInLabel=!0,t=1;r.pos<o;){if(i=r.src.charCodeAt(r.pos),i===91)t++;else if(i===93&&(t--,t===0)){s=!0;break;}r.parser.skipToken(r);}return s?(n=r.pos,r.labelUnmatchedScopes=0):r.labelUnmatchedScopes=t-1,r.pos=a,r.isInLabel=l,n;}function to(r,e,t,s){var i,n,o,a,l,c;if(r.charCodeAt(0)!==42||r.charCodeAt(1)!==91||r.indexOf("]:")===-1||(i=new Tt(r,e,t,s,[]),n=Es(i,1),n<0||r.charCodeAt(n+1)!==58))return-1;for(a=i.posMax,o=n+2;o<a&&i.src.charCodeAt(o)!==10;o++);return l=r.slice(2,n),c=r.slice(n+2,o).trim(),c.length===0?-1:(s.abbreviations||(s.abbreviations={}),_typeof(s.abbreviations[":"+l])>"u"&&(s.abbreviations[":"+l]=c),o);}function so(r){var e=r.tokens,t,s,i,n;if(!r.inlineMode){for(t=1,s=e.length-1;t<s;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(n=to(i,r.inline,r.options,r.env),!(n<0));)i=i.slice(n).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function qi(r){var e=wt(r);try{e=decodeURI(e);}catch(_unused3){}return encodeURI(e);}function br(r,e){var t,s,i,n=e,o=r.posMax;if(r.src.charCodeAt(e)===60){for(e++;e<o;){if(t=r.src.charCodeAt(e),t===10)return!1;if(t===62)return i=qi(_s(r.src.slice(n+1,e))),r.parser.validateLink(i)?(r.pos=e+1,r.linkContent=i,!0):!1;if(t===92&&e+1<o){e+=2;continue;}e++;}return!1;}for(s=0;e<o&&(t=r.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue;}if(t===40&&(s++,s>1)||t===41&&(s--,s<0))break;e++;}return n===e||(i=_s(r.src.slice(n,e)),!r.parser.validateLink(i))?!1:(r.linkContent=i,r.pos=e,!0);}function vr(r,e){var t,s=e,i=r.posMax,n=r.src.charCodeAt(e);if(n!==34&&n!==39&&n!==40)return!1;for(e++,n===40&&(n=41);e<i;){if(t=r.src.charCodeAt(e),t===n)return r.pos=e+1,r.linkContent=_s(r.src.slice(s+1,e)),!0;if(t===92&&e+1<i){e+=2;continue;}e++;}return!1;}function _r(r){return r.trim().replace(/\s+/g," ").toUpperCase();}function io(r,e,t,s){var i,n,o,a,l,c,d,h,u;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(i=new Tt(r,e,t,s,[]),n=Es(i,0),n<0||r.charCodeAt(n+1)!==58))return-1;for(a=i.posMax,o=n+2;o<a&&(l=i.src.charCodeAt(o),!(l!==32&&l!==10));o++);if(!br(i,o))return-1;for(d=i.linkContent,o=i.pos,c=o,o=o+1;o<a&&(l=i.src.charCodeAt(o),!(l!==32&&l!==10));o++);for(o<a&&c!==o&&vr(i,o)?(h=i.linkContent,o=i.pos):(h="",o=c);o<a&&i.src.charCodeAt(o)===32;)o++;return o<a&&i.src.charCodeAt(o)!==10?-1:(u=_r(r.slice(1,n)),_typeof(s.references[u])>"u"&&(s.references[u]={title:h,href:d}),o);}function no(r){var e=r.tokens,t,s,i,n;if(r.env.references=r.env.references||{},!r.inlineMode){for(t=1,s=e.length-1;t<s;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(n=io(i,r.inline,r.options,r.env),!(n<0));)i=i.slice(n).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function ro(r){var e=r.tokens,t,s,i;for(s=0,i=e.length;s<i;s++)t=e[s],t.type==="inline"&&r.inline.parse(t.content,r.options,r.env,t.children);}function oo(r){var e,t,s,i,n,o,a,l,c,d=0,h=!1,u={};if(r.env.footnotes&&(r.tokens=r.tokens.filter(function(f){return f.type==="footnote_reference_open"?(h=!0,l=[],c=f.label,!1):f.type==="footnote_reference_close"?(h=!1,u[":"+c]=l,!1):(h&&l.push(f),!h);}),!!r.env.footnotes.list)){for(o=r.env.footnotes.list,r.tokens.push({type:"footnote_block_open",level:d++}),e=0,t=o.length;e<t;e++){for(r.tokens.push({type:"footnote_open",id:e,level:d++}),o[e].tokens?(a=[],a.push({type:"paragraph_open",tight:!1,level:d++}),a.push({type:"inline",content:"",level:d,children:o[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--d})):o[e].label&&(a=u[":"+o[e].label]),r.tokens=r.tokens.concat(a),r.tokens[r.tokens.length-1].type==="paragraph_close"?n=r.tokens.pop():n=null,i=o[e].count>0?o[e].count:1,s=0;s<i;s++)r.tokens.push({type:"footnote_anchor",id:e,subId:s,level:d});n&&r.tokens.push(n),r.tokens.push({type:"footnote_close",level:--d});}r.tokens.push({type:"footnote_block_close",level:--d});}}var Rn=" \n()[]'\".,!?-";function Oi(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function ao(r){var e,t,s,i,n,o,a,l,c,d,h,u,f=r.tokens;if(r.env.abbreviations){for(r.env.abbrRegExp||(u="(^|["+Rn.split("").map(Oi).join("")+"])("+Object.keys(r.env.abbreviations).map(function(m){return m.substr(1);}).sort(function(m,p){return p.length-m.length;}).map(Oi).join("|")+")($|["+Rn.split("").map(Oi).join("")+"])",r.env.abbrRegExp=new RegExp(u,"g")),d=r.env.abbrRegExp,t=0,s=f.length;t<s;t++)if(f[t].type==="inline"){for(i=f[t].children,e=i.length-1;e>=0;e--)if(n=i[e],n.type==="text"){for(l=0,o=n.content,d.lastIndex=0,c=n.level,a=[];h=d.exec(o);)d.lastIndex>l&&a.push({type:"text",content:o.slice(l,h.index+h[1].length),level:c}),a.push({type:"abbr_open",title:r.env.abbreviations[":"+h[2]],level:c++}),a.push({type:"text",content:h[2],level:c}),a.push({type:"abbr_close",level:--c}),l=d.lastIndex-h[3].length;a.length&&(l<o.length&&a.push({type:"text",content:o.slice(l),level:c}),f[t].children=i=[].concat(i.slice(0,e),a,i.slice(e+1)));}}}}var lo=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,co=/\((c|tm|r|p)\)/ig,ho={c:"©",r:"®",p:"§",tm:"™"};function uo(r){return r.indexOf("(")<0?r:r.replace(co,function(e,t){return ho[t.toLowerCase()];});}function fo(r){var e,t,s,i,n;if(r.options.typographer){for(n=r.tokens.length-1;n>=0;n--)if(r.tokens[n].type==="inline")for(i=r.tokens[n].children,e=i.length-1;e>=0;e--)t=i[e],t.type==="text"&&(s=t.content,s=uo(s),lo.test(s)&&(s=s.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=s);}}var po=/['"]/,Mn=/['"]/g,mo=/[-\s()\[\]]/,kn="’";function In(r,e){return e<0||e>=r.length?!1:!mo.test(r[e]);}function kt(r,e,t){return r.substr(0,e)+t+r.substr(e+1);}function go(r){var e,t,s,i,n,o,a,l,c,d,h,u,f,m,p,y,_;if(r.options.typographer){for(_=[],p=r.tokens.length-1;p>=0;p--)if(r.tokens[p].type==="inline"){for(y=r.tokens[p].children,_.length=0,e=0;e<y.length;e++)if(t=y[e],!(t.type!=="text"||po.test(t.text))){for(a=y[e].level,f=_.length-1;f>=0&&!(_[f].level<=a);f--);_.length=f+1,s=t.content,n=0,o=s.length;e:for(;n<o&&(Mn.lastIndex=n,i=Mn.exec(s),!!i);){if(l=!In(s,i.index-1),n=i.index+1,m=i[0]==="'",c=!In(s,n),!c&&!l){m&&(t.content=kt(t.content,i.index,kn));continue;}if(h=!c,u=!l,u){for(f=_.length-1;f>=0&&(d=_[f],!(_[f].level<a));f--)if(d.single===m&&_[f].level===a){d=_[f],m?(y[d.token].content=kt(y[d.token].content,d.pos,r.options.quotes[2]),t.content=kt(t.content,i.index,r.options.quotes[3])):(y[d.token].content=kt(y[d.token].content,d.pos,r.options.quotes[0]),t.content=kt(t.content,i.index,r.options.quotes[1])),_.length=f;continue e;}}h?_.push({token:e,pos:i.index,single:m,level:a}):u&&m&&(t.content=kt(t.content,i.index,kn));}}}}}var Pi=[["block",eo],["abbr",so],["references",no],["inline",ro],["footnote_tail",oo],["abbr2",ao],["replacements",fo],["smartquotes",go]];function Er(){this.options={},this.ruler=new _e();for(var r=0;r<Pi.length;r++)this.ruler.push(Pi[r][0],Pi[r][1]);}Er.prototype.process=function(r){var e,t,s;for(s=this.ruler.getRules(""),e=0,t=s.length;e<t;e++)s[e](r);};function Rt(r,e,t,s,i){var n,o,a,l,c,d,h;for(this.src=r,this.parser=e,this.options=t,this.env=s,this.tokens=i,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,d=0,h=!1,a=l=d=0,c=o.length;l<c;l++){if(n=o.charCodeAt(l),!h)if(n===32){d++;continue;}else h=!0;(n===10||l===c-1)&&(n!==10&&l++,this.bMarks.push(a),this.eMarks.push(l),this.tShift.push(d),h=!1,d=0,a=l+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}Rt.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};Rt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};Rt.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};Rt.prototype.skipChars=function(e,t){for(var s=this.src.length;e<s&&this.src.charCodeAt(e)===t;e++);return e;};Rt.prototype.skipCharsBack=function(e,t,s){if(e<=s)return e;for(;e>s;)if(t!==this.src.charCodeAt(--e))return e+1;return e;};Rt.prototype.getLines=function(e,t,s,i){var n,o,a,l,c,d=e;if(e>=t)return"";if(d+1===t)return o=this.bMarks[d]+Math.min(this.tShift[d],s),a=i?this.eMarks[d]+1:this.eMarks[d],this.src.slice(o,a);for(l=new Array(t-e),n=0;d<t;d++,n++)c=this.tShift[d],c>s&&(c=s),c<0&&(c=0),o=this.bMarks[d]+c,d+1<t||i?a=this.eMarks[d]+1:a=this.eMarks[d],l[n]=this.src.slice(o,a);return l.join("");};function yo(r,e,t){var s,i;if(r.tShift[e]-r.blkIndent<4)return!1;for(i=s=e+1;s<t;){if(r.isEmpty(s)){s++;continue;}if(r.tShift[s]-r.blkIndent>=4){s++,i=s;continue;}break;}return r.line=s,r.tokens.push({type:"code",content:r.getLines(e,i,4+r.blkIndent,!0),block:!0,lines:[e,r.line],level:r.level}),!0;}function bo(r,e,t,s){var i,n,o,a,l,c=!1,d=r.bMarks[e]+r.tShift[e],h=r.eMarks[e];if(d+3>h||(i=r.src.charCodeAt(d),i!==126&&i!==96)||(l=d,d=r.skipChars(d,i),n=d-l,n<3)||(o=r.src.slice(d,h).trim(),o.indexOf("`")>=0))return!1;if(s)return!0;for(a=e;a++,!(a>=t||(d=l=r.bMarks[a]+r.tShift[a],h=r.eMarks[a],d<h&&r.tShift[a]<r.blkIndent));)if(r.src.charCodeAt(d)===i&&!(r.tShift[a]-r.blkIndent>=4)&&(d=r.skipChars(d,i),!(d-l<n)&&(d=r.skipSpaces(d),!(d<h)))){c=!0;break;}return n=r.tShift[e],r.line=a+(c?1:0),r.tokens.push({type:"fence",params:o,content:r.getLines(e+1,a,n,!0),lines:[e,r.line],level:r.level}),!0;}function vo(r,e,t,s){var i,n,o,a,l,c,d,h,u,f,m,p=r.bMarks[e]+r.tShift[e],y=r.eMarks[e];if(p>y||r.src.charCodeAt(p++)!==62||r.level>=r.options.maxNesting)return!1;if(s)return!0;for(r.src.charCodeAt(p)===32&&p++,l=r.blkIndent,r.blkIndent=0,a=[r.bMarks[e]],r.bMarks[e]=p,p=p<y?r.skipSpaces(p):p,n=p>=y,o=[r.tShift[e]],r.tShift[e]=p-r.bMarks[e],h=r.parser.ruler.getRules("blockquote"),i=e+1;i<t&&(p=r.bMarks[i]+r.tShift[i],y=r.eMarks[i],!(p>=y));i++){if(r.src.charCodeAt(p++)===62){r.src.charCodeAt(p)===32&&p++,a.push(r.bMarks[i]),r.bMarks[i]=p,p=p<y?r.skipSpaces(p):p,n=p>=y,o.push(r.tShift[i]),r.tShift[i]=p-r.bMarks[i];continue;}if(n)break;for(m=!1,u=0,f=h.length;u<f;u++)if(h[u](r,i,t,!0)){m=!0;break;}if(m)break;a.push(r.bMarks[i]),o.push(r.tShift[i]),r.tShift[i]=-1337;}for(c=r.parentType,r.parentType="blockquote",r.tokens.push({type:"blockquote_open",lines:d=[e,0],level:r.level++}),r.parser.tokenize(r,e,i),r.tokens.push({type:"blockquote_close",level:--r.level}),r.parentType=c,d[1]=r.line,u=0;u<o.length;u++)r.bMarks[u+e]=a[u],r.tShift[u+e]=o[u];return r.blkIndent=l,!0;}function _o(r,e,t,s){var i,n,o,a=r.bMarks[e],l=r.eMarks[e];if(a+=r.tShift[e],a>l||(i=r.src.charCodeAt(a++),i!==42&&i!==45&&i!==95))return!1;for(n=1;a<l;){if(o=r.src.charCodeAt(a++),o!==i&&o!==32)return!1;o===i&&n++;}return n<3?!1:(s||(r.line=e+1,r.tokens.push({type:"hr",lines:[e,r.line],level:r.level})),!0);}function Ln(r,e){var t,s,i;return s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e],s>=i||(t=r.src.charCodeAt(s++),t!==42&&t!==45&&t!==43)||s<i&&r.src.charCodeAt(s)!==32?-1:s;}function Nn(r,e){var t,s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e];if(s+1>=i||(t=r.src.charCodeAt(s++),t<48||t>57))return-1;for(;;){if(s>=i)return-1;if(t=r.src.charCodeAt(s++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return s<i&&r.src.charCodeAt(s)!==32?-1:s;}function Eo(r,e){var t,s,i=r.level+2;for(t=e+2,s=r.tokens.length-2;t<s;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function So(r,e,t,s){var i,n,o,a,l,c,d,h,u,f,m,p,y,_,I,D,B,se,st=!0,it,me,wn,Ni;if((h=Nn(r,e))>=0)y=!0;else if((h=Ln(r,e))>=0)y=!1;else return!1;if(r.level>=r.options.maxNesting)return!1;if(p=r.src.charCodeAt(h-1),s)return!0;for(I=r.tokens.length,y?(d=r.bMarks[e]+r.tShift[e],m=Number(r.src.substr(d,h-d-1)),r.tokens.push({type:"ordered_list_open",order:m,lines:B=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:B=[e,0],level:r.level++}),i=e,D=!1,it=r.parser.ruler.getRules("list");i<t&&(_=r.skipSpaces(h),u=r.eMarks[i],_>=u?f=1:f=_-h,f>4&&(f=1),f<1&&(f=1),n=h-r.bMarks[i]+f,r.tokens.push({type:"list_item_open",lines:se=[e,0],level:r.level++}),a=r.blkIndent,l=r.tight,o=r.tShift[e],c=r.parentType,r.tShift[e]=_-r.bMarks[e],r.blkIndent=n,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||D)&&(st=!1),D=r.line-e>1&&r.isEmpty(r.line-1),r.blkIndent=a,r.tShift[e]=o,r.tight=l,r.parentType=c,r.tokens.push({type:"list_item_close",level:--r.level}),i=e=r.line,se[1]=i,_=r.bMarks[e],!(i>=t||r.isEmpty(i)||r.tShift[i]<r.blkIndent));){for(Ni=!1,me=0,wn=it.length;me<wn;me++)if(it[me](r,i,t,!0)){Ni=!0;break;}if(Ni)break;if(y){if(h=Nn(r,i),h<0)break;}else if(h=Ln(r,i),h<0)break;if(p!==r.src.charCodeAt(h-1))break;}return r.tokens.push({type:y?"ordered_list_close":"bullet_list_close",level:--r.level}),B[1]=i,r.line=i,st&&Eo(r,I),!0;}function xo(r,e,t,s){var i,n,o,a,l,c=r.bMarks[e]+r.tShift[e],d=r.eMarks[e];if(c+4>d||r.src.charCodeAt(c)!==91||r.src.charCodeAt(c+1)!==94||r.level>=r.options.maxNesting)return!1;for(a=c+2;a<d;a++){if(r.src.charCodeAt(a)===32)return!1;if(r.src.charCodeAt(a)===93)break;}return a===c+2||a+1>=d||r.src.charCodeAt(++a)!==58?!1:(s||(a++,r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.refs||(r.env.footnotes.refs={}),l=r.src.slice(c+2,a-2),r.env.footnotes.refs[":"+l]=-1,r.tokens.push({type:"footnote_reference_open",label:l,level:r.level++}),i=r.bMarks[e],n=r.tShift[e],o=r.parentType,r.tShift[e]=r.skipSpaces(a)-a,r.bMarks[e]=a,r.blkIndent+=4,r.parentType="footnote",r.tShift[e]<r.blkIndent&&(r.tShift[e]+=r.blkIndent,r.bMarks[e]-=r.blkIndent),r.parser.tokenize(r,e,t,!0),r.parentType=o,r.blkIndent-=4,r.tShift[e]=n,r.bMarks[e]=i,r.tokens.push({type:"footnote_reference_close",level:--r.level})),!0);}function wo(r,e,t,s){var i,n,o,a=r.bMarks[e]+r.tShift[e],l=r.eMarks[e];if(a>=l||(i=r.src.charCodeAt(a),i!==35||a>=l))return!1;for(n=1,i=r.src.charCodeAt(++a);i===35&&a<l&&n<=6;)n++,i=r.src.charCodeAt(++a);return n>6||a<l&&i!==32?!1:(s||(l=r.skipCharsBack(l,32,a),o=r.skipCharsBack(l,35,a),o>a&&r.src.charCodeAt(o-1)===32&&(l=o),r.line=e+1,r.tokens.push({type:"heading_open",hLevel:n,lines:[e,r.line],level:r.level}),a<l&&r.tokens.push({type:"inline",content:r.src.slice(a,l).trim(),level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"heading_close",hLevel:n,level:r.level})),!0);}function Co(r,e,t){var s,i,n,o=e+1;return o>=t||r.tShift[o]<r.blkIndent||r.tShift[o]-r.blkIndent>3||(i=r.bMarks[o]+r.tShift[o],n=r.eMarks[o],i>=n)||(s=r.src.charCodeAt(i),s!==45&&s!==61)||(i=r.skipChars(i,s),i=r.skipSpaces(i),i<n)?!1:(i=r.bMarks[e]+r.tShift[e],r.line=o+1,r.tokens.push({type:"heading_open",hLevel:s===61?1:2,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:r.src.slice(i,r.eMarks[e]).trim(),level:r.level+1,lines:[e,r.line-1],children:[]}),r.tokens.push({type:"heading_close",hLevel:s===61?1:2,level:r.level}),!0);}var Sr={};["article","aside","button","blockquote","body","canvas","caption","col","colgroup","dd","div","dl","dt","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","iframe","li","map","object","ol","output","p","pre","progress","script","section","style","table","tbody","td","textarea","tfoot","th","tr","thead","ul","video"].forEach(function(r){Sr[r]=!0;});var Ao=/^<([a-zA-Z]{1,15})[\s\/>]/,To=/^<\/([a-zA-Z]{1,15})[\s>]/;function Ro(r){var e=r|32;return e>=97&&e<=122;}function Mo(r,e,t,s){var i,n,o,a=r.bMarks[e],l=r.eMarks[e],c=r.tShift[e];if(a+=c,!r.options.html||c>3||a+2>=l||r.src.charCodeAt(a)!==60)return!1;if(i=r.src.charCodeAt(a+1),i===33||i===63){if(s)return!0;}else if(i===47||Ro(i)){if(i===47){if(n=r.src.slice(a,l).match(To),!n)return!1;}else if(n=r.src.slice(a,l).match(Ao),!n)return!1;if(Sr[n[1].toLowerCase()]!==!0)return!1;if(s)return!0;}else return!1;for(o=e+1;o<r.lineMax&&!r.isEmpty(o);)o++;return r.line=o,r.tokens.push({type:"htmlblock",level:r.level,lines:[e,r.line],content:r.getLines(e,o,0,!0)}),!0;}function Di(r,e){var t=r.bMarks[e]+r.blkIndent,s=r.eMarks[e];return r.src.substr(t,s-t);}function ko(r,e,t,s){var i,n,o,a,l,c,d,h,u,f,m;if(e+2>t||(l=e+1,r.tShift[l]<r.blkIndent)||(o=r.bMarks[l]+r.tShift[l],o>=r.eMarks[l])||(i=r.src.charCodeAt(o),i!==124&&i!==45&&i!==58)||(n=Di(r,e+1),!/^[-:| ]+$/.test(n))||(c=n.split("|"),c<=2))return!1;for(h=[],a=0;a<c.length;a++){if(u=c[a].trim(),!u){if(a===0||a===c.length-1)continue;return!1;}if(!/^:?-+:?$/.test(u))return!1;u.charCodeAt(u.length-1)===58?h.push(u.charCodeAt(0)===58?"center":"right"):u.charCodeAt(0)===58?h.push("left"):h.push("");}if(n=Di(r,e).trim(),n.indexOf("|")===-1||(c=n.replace(/^\||\|$/g,"").split("|"),h.length!==c.length))return!1;if(s)return!0;for(r.tokens.push({type:"table_open",lines:f=[e,0],level:r.level++}),r.tokens.push({type:"thead_open",lines:[e,e+1],level:r.level++}),r.tokens.push({type:"tr_open",lines:[e,e+1],level:r.level++}),a=0;a<c.length;a++)r.tokens.push({type:"th_open",align:h[a],lines:[e,e+1],level:r.level++}),r.tokens.push({type:"inline",content:c[a].trim(),lines:[e,e+1],level:r.level,children:[]}),r.tokens.push({type:"th_close",level:--r.level});for(r.tokens.push({type:"tr_close",level:--r.level}),r.tokens.push({type:"thead_close",level:--r.level}),r.tokens.push({type:"tbody_open",lines:m=[e+2,0],level:r.level++}),l=e+2;l<t&&!(r.tShift[l]<r.blkIndent||(n=Di(r,l).trim(),n.indexOf("|")===-1));l++){for(c=n.replace(/^\||\|$/g,"").split("|"),r.tokens.push({type:"tr_open",level:r.level++}),a=0;a<c.length;a++)r.tokens.push({type:"td_open",align:h[a],level:r.level++}),d=c[a].substring(c[a].charCodeAt(0)===124?1:0,c[a].charCodeAt(c[a].length-1)===124?c[a].length-1:c[a].length).trim(),r.tokens.push({type:"inline",content:d,level:r.level,children:[]}),r.tokens.push({type:"td_close",level:--r.level});r.tokens.push({type:"tr_close",level:--r.level});}return r.tokens.push({type:"tbody_close",level:--r.level}),r.tokens.push({type:"table_close",level:--r.level}),f[1]=m[1]=l,r.line=l,!0;}function Ps(r,e){var t,s,i=r.bMarks[e]+r.tShift[e],n=r.eMarks[e];return i>=n||(s=r.src.charCodeAt(i++),s!==126&&s!==58)||(t=r.skipSpaces(i),i===t)||t>=n?-1:t;}function Io(r,e){var t,s,i=r.level+2;for(t=e+2,s=r.tokens.length-2;t<s;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2);}function Lo(r,e,t,s){var i,n,o,a,l,c,d,h,u,f,m,p,y,_;if(s)return r.ddIndent<0?!1:Ps(r,e)>=0;if(d=e+1,r.isEmpty(d)&&++d>t||r.tShift[d]<r.blkIndent||(i=Ps(r,d),i<0)||r.level>=r.options.maxNesting)return!1;c=r.tokens.length,r.tokens.push({type:"dl_open",lines:l=[e,0],level:r.level++}),o=e,n=d;e:for(;;){for(_=!0,y=!1,r.tokens.push({type:"dt_open",lines:[o,o],level:r.level++}),r.tokens.push({type:"inline",content:r.getLines(o,o+1,r.blkIndent,!1).trim(),level:r.level+1,lines:[o,o],children:[]}),r.tokens.push({type:"dt_close",level:--r.level});;){if(r.tokens.push({type:"dd_open",lines:a=[d,0],level:r.level++}),p=r.tight,u=r.ddIndent,h=r.blkIndent,m=r.tShift[n],f=r.parentType,r.blkIndent=r.ddIndent=r.tShift[n]+2,r.tShift[n]=i-r.bMarks[n],r.tight=!0,r.parentType="deflist",r.parser.tokenize(r,n,t,!0),(!r.tight||y)&&(_=!1),y=r.line-n>1&&r.isEmpty(r.line-1),r.tShift[n]=m,r.tight=p,r.parentType=f,r.blkIndent=h,r.ddIndent=u,r.tokens.push({type:"dd_close",level:--r.level}),a[1]=d=r.line,d>=t||r.tShift[d]<r.blkIndent)break e;if(i=Ps(r,d),i<0)break;n=d;}if(d>=t||(o=d,r.isEmpty(o))||r.tShift[o]<r.blkIndent||(n=o+1,n>=t)||(r.isEmpty(n)&&n++,n>=t)||r.tShift[n]<r.blkIndent||(i=Ps(r,n),i<0))break;}return r.tokens.push({type:"dl_close",level:--r.level}),l[1]=d,r.line=d,_&&Io(r,c),!0;}function No(r,e){var t,s,i,n,o,a=e+1,l;if(t=r.lineMax,a<t&&!r.isEmpty(a)){for(l=r.parser.ruler.getRules("paragraph");a<t&&!r.isEmpty(a);a++)if(!(r.tShift[a]-r.blkIndent>3)){for(i=!1,n=0,o=l.length;n<o;n++)if(l[n](r,a,t,!0)){i=!0;break;}if(i)break;}}return s=r.getLines(e,a,r.blkIndent,!1).trim(),r.line=a,s.length&&(r.tokens.push({type:"paragraph_open",tight:!1,lines:[e,r.line],level:r.level}),r.tokens.push({type:"inline",content:s,level:r.level+1,lines:[e,r.line],children:[]}),r.tokens.push({type:"paragraph_close",tight:!1,level:r.level})),!0;}var Ds=[["code",yo],["fences",bo,["paragraph","blockquote","list"]],["blockquote",vo,["paragraph","blockquote","list"]],["hr",_o,["paragraph","blockquote","list"]],["list",So,["paragraph","blockquote"]],["footnote",xo,["paragraph"]],["heading",wo,["paragraph","blockquote"]],["lheading",Co],["htmlblock",Mo,["paragraph","blockquote"]],["table",ko,["paragraph"]],["deflist",Lo,["paragraph"]],["paragraph",No]];function hn(){this.ruler=new _e();for(var r=0;r<Ds.length;r++)this.ruler.push(Ds[r][0],Ds[r][1],{alt:(Ds[r][2]||[]).slice()});}hn.prototype.tokenize=function(r,e,t){for(var s=this.ruler.getRules(""),i=s.length,n=e,o=!1,a,l;n<t&&(r.line=n=r.skipEmptyLines(n),!(n>=t||r.tShift[n]<r.blkIndent));){for(l=0;l<i&&(a=s[l](r,n,t,!1),!a);l++);if(r.tight=!o,r.isEmpty(r.line-1)&&(o=!0),n=r.line,n<t&&r.isEmpty(n)){if(o=!0,n++,n<t&&r.parentType==="list"&&r.isEmpty(n))break;r.line=n;}}};var Oo=/[\n\t]/g,Po=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,Do=/\u00a0/g;hn.prototype.parse=function(r,e,t,s){var i,n=0,o=0;if(!r)return[];r=r.replace(Do," "),r=r.replace(Po,"\n"),r.indexOf(" ")>=0&&(r=r.replace(Oo,function(a,l){var c;return r.charCodeAt(l)===10?(n=l+1,o=0,a):(c=" ".slice((l-n-o)%4),o=l-n+1,c);})),i=new Rt(r,this,e,t,s),this.tokenize(i,i.line,i.lineMax);};function Bo(r){switch(r){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1;}}function Fo(r,e){for(var t=r.pos;t<r.posMax&&!Bo(r.src.charCodeAt(t));)t++;return t===r.pos?!1:(e||(r.pending+=r.src.slice(r.pos,t)),r.pos=t,!0);}function Uo(r,e){var t,s,i=r.pos;if(r.src.charCodeAt(i)!==10)return!1;if(t=r.pending.length-1,s=r.posMax,!e)if(t>=0&&r.pending.charCodeAt(t)===32){if(t>=1&&r.pending.charCodeAt(t-1)===32){for(var n=t-2;n>=0;n--)if(r.pending.charCodeAt(n)!==32){r.pending=r.pending.substring(0,n+1);break;}r.push({type:"hardbreak",level:r.level});}else r.pending=r.pending.slice(0,-1),r.push({type:"softbreak",level:r.level});}else r.push({type:"softbreak",level:r.level});for(i++;i<s&&r.src.charCodeAt(i)===32;)i++;return r.pos=i,!0;}var un=[];for(var On=0;On<256;On++)un.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){un[r.charCodeAt(0)]=1;});function Ho(r,e){var t,s=r.pos,i=r.posMax;if(r.src.charCodeAt(s)!==92)return!1;if(s++,s<i){if(t=r.src.charCodeAt(s),t<256&&un[t]!==0)return e||(r.pending+=r.src[s]),r.pos+=2,!0;if(t===10){for(e||r.push({type:"hardbreak",level:r.level}),s++;s<i&&r.src.charCodeAt(s)===32;)s++;return r.pos=s,!0;}}return e||(r.pending+="\\"),r.pos++,!0;}function qo(r,e){var t,s,i,n,o,a=r.pos,l=r.src.charCodeAt(a);if(l!==96)return!1;for(t=a,a++,s=r.posMax;a<s&&r.src.charCodeAt(a)===96;)a++;for(i=r.src.slice(t,a),n=o=a;(n=r.src.indexOf("`",o))!==-1;){for(o=n+1;o<s&&r.src.charCodeAt(o)===96;)o++;if(o-n===i.length)return e||r.push({type:"code",content:r.src.slice(a,n).replace(/[ \n]+/g," ").trim(),block:!1,level:r.level}),r.pos=o,!0;}return e||(r.pending+=i),r.pos+=i.length,!0;}function jo(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==126||e||o+4>=n||r.src.charCodeAt(o+1)!==126||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===126)||l===126||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===126;)s++;if(s>o+3)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===126&&r.src.charCodeAt(r.pos+1)===126&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==126&&a!==126&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"del_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"del_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function Vo(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==43||e||o+4>=n||r.src.charCodeAt(o+1)!==43||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===43)||l===43||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===43;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===43&&r.src.charCodeAt(r.pos+1)===43&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==43&&a!==43&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"ins_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"ins_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function Ko(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==61||e||o+4>=n||r.src.charCodeAt(o+1)!==61||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===61)||l===61||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===61;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===61&&r.src.charCodeAt(r.pos+1)===61&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==61&&a!==61&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"mark_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"mark_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function Pn(r){return r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122;}function Dn(r,e){var t=e,s,i,n,o=!0,a=!0,l=r.posMax,c=r.src.charCodeAt(e);for(s=e>0?r.src.charCodeAt(e-1):-1;t<l&&r.src.charCodeAt(t)===c;)t++;return t>=l&&(o=!1),n=t-e,n>=4?o=a=!1:(i=t<l?r.src.charCodeAt(t):-1,(i===32||i===10)&&(o=!1),(s===32||s===10)&&(a=!1),c===95&&(Pn(s)&&(o=!1),Pn(i)&&(a=!1))),{can_open:o,can_close:a,delims:n};}function zo(r,e){var t,s,i,n,o,a,l,c=r.posMax,d=r.pos,h=r.src.charCodeAt(d);if(h!==95&&h!==42||e)return!1;if(l=Dn(r,d),t=l.delims,!l.can_open)return r.pos+=t,e||(r.pending+=r.src.slice(d,r.pos)),!0;if(r.level>=r.options.maxNesting)return!1;for(r.pos=d+t,a=[t];r.pos<c;){if(r.src.charCodeAt(r.pos)===h){if(l=Dn(r,r.pos),s=l.delims,l.can_close){for(n=a.pop(),o=s;n!==o;){if(o<n){a.push(n-o);break;}if(o-=n,a.length===0)break;r.pos+=n,n=a.pop();}if(a.length===0){t=n,i=!0;break;}r.pos+=s;continue;}l.can_open&&a.push(s),r.pos+=s;continue;}r.parser.skipToken(r);}return i?(r.posMax=r.pos,r.pos=d+t,e||((t===2||t===3)&&r.push({type:"strong_open",level:r.level++}),(t===1||t===3)&&r.push({type:"em_open",level:r.level++}),r.parser.tokenize(r),(t===1||t===3)&&r.push({type:"em_close",level:--r.level}),(t===2||t===3)&&r.push({type:"strong_close",level:--r.level})),r.pos=r.posMax+t,r.posMax=c,!0):(r.pos=d,!1);}var Go=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Jo(r,e){var t,s,i=r.posMax,n=r.pos;if(r.src.charCodeAt(n)!==126||e||n+2>=i||r.level>=r.options.maxNesting)return!1;for(r.pos=n+1;r.pos<i;){if(r.src.charCodeAt(r.pos)===126){t=!0;break;}r.parser.skipToken(r);}return!t||n+1===r.pos||(s=r.src.slice(n+1,r.pos),s.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=n,!1):(r.posMax=r.pos,r.pos=n+1,e||r.push({type:"sub",level:r.level,content:s.replace(Go,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}var $o=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Wo(r,e){var t,s,i=r.posMax,n=r.pos;if(r.src.charCodeAt(n)!==94||e||n+2>=i||r.level>=r.options.maxNesting)return!1;for(r.pos=n+1;r.pos<i;){if(r.src.charCodeAt(r.pos)===94){t=!0;break;}r.parser.skipToken(r);}return!t||n+1===r.pos||(s=r.src.slice(n+1,r.pos),s.match(/(^|[^\\])(\\\\)*\s/))?(r.pos=n,!1):(r.posMax=r.pos,r.pos=n+1,e||r.push({type:"sup",level:r.level,content:s.replace($o,"$1")}),r.pos=r.posMax+1,r.posMax=i,!0);}function Xo(r,e){var t,s,i,n,o,a,l,c,d=!1,h=r.pos,u=r.posMax,f=r.pos,m=r.src.charCodeAt(f);if(m===33&&(d=!0,m=r.src.charCodeAt(++f)),m!==91||r.level>=r.options.maxNesting||(t=f+1,s=Es(r,f),s<0))return!1;if(a=s+1,a<u&&r.src.charCodeAt(a)===40){for(a++;a<u&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a>=u)return!1;for(f=a,br(r,a)?(n=r.linkContent,a=r.pos):n="",f=a;a<u&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<u&&f!==a&&vr(r,a))for(o=r.linkContent,a=r.pos;a<u&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);else o="";if(a>=u||r.src.charCodeAt(a)!==41)return r.pos=h,!1;a++;}else{if(r.linkLevel>0)return!1;for(;a<u&&(c=r.src.charCodeAt(a),!(c!==32&&c!==10));a++);if(a<u&&r.src.charCodeAt(a)===91&&(f=a+1,a=Es(r,a),a>=0?i=r.src.slice(f,a++):a=f-1),i||(_typeof(i)>"u"&&(a=s+1),i=r.src.slice(t,s)),l=r.env.references[_r(i)],!l)return r.pos=h,!1;n=l.href,o=l.title;}return e||(r.pos=t,r.posMax=s,d?r.push({type:"image",src:n,title:o,alt:r.src.substr(t,s-t),level:r.level}):(r.push({type:"link_open",href:n,title:o,level:r.level++}),r.linkLevel++,r.parser.tokenize(r),r.linkLevel--,r.push({type:"link_close",level:--r.level}))),r.pos=a,r.posMax=u,!0;}function Yo(r,e){var t,s,i,n,o=r.posMax,a=r.pos;return a+2>=o||r.src.charCodeAt(a)!==94||r.src.charCodeAt(a+1)!==91||r.level>=r.options.maxNesting||(t=a+2,s=Es(r,a+1),s<0)?!1:(e||(r.env.footnotes||(r.env.footnotes={}),r.env.footnotes.list||(r.env.footnotes.list=[]),i=r.env.footnotes.list.length,r.pos=t,r.posMax=s,r.push({type:"footnote_ref",id:i,level:r.level}),r.linkLevel++,n=r.tokens.length,r.parser.tokenize(r),r.env.footnotes.list[i]={tokens:r.tokens.splice(n)},r.linkLevel--),r.pos=s+1,r.posMax=o,!0);}function Zo(r,e){var t,s,i,n,o=r.posMax,a=r.pos;if(a+3>o||!r.env.footnotes||!r.env.footnotes.refs||r.src.charCodeAt(a)!==91||r.src.charCodeAt(a+1)!==94||r.level>=r.options.maxNesting)return!1;for(s=a+2;s<o;s++){if(r.src.charCodeAt(s)===32||r.src.charCodeAt(s)===10)return!1;if(r.src.charCodeAt(s)===93)break;}return s===a+2||s>=o||(s++,t=r.src.slice(a+2,s-1),_typeof(r.env.footnotes.refs[":"+t])>"u")?!1:(e||(r.env.footnotes.list||(r.env.footnotes.list=[]),r.env.footnotes.refs[":"+t]<0?(i=r.env.footnotes.list.length,r.env.footnotes.list[i]={label:t,count:0},r.env.footnotes.refs[":"+t]=i):i=r.env.footnotes.refs[":"+t],n=r.env.footnotes.list[i].count,r.env.footnotes.list[i].count++,r.push({type:"footnote_ref",id:i,subId:n,level:r.level})),r.pos=s,r.posMax=o,!0);}var Qo=["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"],ea=/^<([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])?)*)>/,ta=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function sa(r,e){var t,s,i,n,o,a=r.pos;return r.src.charCodeAt(a)!==60||(t=r.src.slice(a),t.indexOf(">")<0)?!1:(s=t.match(ta),s?Qo.indexOf(s[1].toLowerCase())<0||(n=s[0].slice(1,-1),o=qi(n),!r.parser.validateLink(n))?!1:(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:n,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=s[0].length,!0):(i=t.match(ea),i?(n=i[0].slice(1,-1),o=qi("mailto:"+n),r.parser.validateLink(o)?(e||(r.push({type:"link_open",href:o,level:r.level}),r.push({type:"text",content:n,level:r.level+1}),r.push({type:"link_close",level:r.level})),r.pos+=i[0].length,!0):!1):!1));}function Ai(r,e){return r=r.source,e=e||"",function t(s,i){return s?(i=i.source||i,r=r.replace(s,i),t):new RegExp(r,e);};}var ia=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,na=/[^"'=<>`\x00-\x20]+/,ra=/'[^']*'/,oa=/"[^"]*"/,aa=Ai(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",na)("single_quoted",ra)("double_quoted",oa)(),la=Ai(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",ia)("attr_value",aa)(),ca=Ai(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",la)(),da=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,ha=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,ua=/<[?].*?[?]>/,fa=/<![A-Z]+\s+[^>]*>/,pa=/<!\[CDATA\[[\s\S]*?\]\]>/,ma=Ai(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",ca)("close_tag",da)("comment",ha)("processing",ua)("declaration",fa)("cdata",pa)();function ga(r){var e=r|32;return e>=97&&e<=122;}function ya(r,e){var t,s,i,n=r.pos;return!r.options.html||(i=r.posMax,r.src.charCodeAt(n)!==60||n+2>=i)||(t=r.src.charCodeAt(n+1),t!==33&&t!==63&&t!==47&&!ga(t))||(s=r.src.slice(n).match(ma),!s)?!1:(e||r.push({type:"htmltag",content:r.src.slice(n,n+s[0].length),level:r.level}),r.pos+=s[0].length,!0);}var ba=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,va=/^&([a-z][a-z0-9]{1,31});/i;function _a(r,e){var t,s,i,n=r.pos,o=r.posMax;if(r.src.charCodeAt(n)!==38)return!1;if(n+1<o){if(t=r.src.charCodeAt(n+1),t===35){if(i=r.src.slice(n).match(ba),i)return e||(s=i[1][0].toLowerCase()==="x"?parseInt(i[1].slice(1),16):parseInt(i[1],10),r.pending+=gr(s)?Hi(s):Hi(65533)),r.pos+=i[0].length,!0;}else if(i=r.src.slice(n).match(va),i){var a=pr(i[1]);if(i[1]!==a)return e||(r.pending+=a),r.pos+=i[0].length,!0;}}return e||(r.pending+="&"),r.pos++,!0;}var Bi=[["text",Fo],["newline",Uo],["escape",Ho],["backticks",qo],["del",jo],["ins",Vo],["mark",Ko],["emphasis",zo],["sub",Jo],["sup",Wo],["links",Xo],["footnote_inline",Yo],["footnote_ref",Zo],["autolink",sa],["htmltag",ya],["entity",_a]];function Ti(){this.ruler=new _e();for(var r=0;r<Bi.length;r++)this.ruler.push(Bi[r][0],Bi[r][1]);this.validateLink=Ea;}Ti.prototype.skipToken=function(r){var e=this.ruler.getRules(""),t=e.length,s=r.pos,i,n;if((n=r.cacheGet(s))>0){r.pos=n;return;}for(i=0;i<t;i++)if(e[i](r,!0)){r.cacheSet(s,r.pos);return;}r.pos++,r.cacheSet(s,r.pos);};Ti.prototype.tokenize=function(r){for(var e=this.ruler.getRules(""),t=e.length,s=r.posMax,i,n;r.pos<s;){for(n=0;n<t&&(i=e[n](r,!1),!i);n++);if(i){if(r.pos>=s)break;continue;}r.pending+=r.src[r.pos++];}r.pending&&r.pushPending();};Ti.prototype.parse=function(r,e,t,s){var i=new Tt(r,this,e,t,s);this.tokenize(i);};function Ea(r){var e=["vbscript","javascript","file","data"],t=r.trim().toLowerCase();return t=wt(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var Sa={options:{html:!1,// Enable HTML tags in source
|
26
26
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
27
27
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
28
28
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
@@ -36,7 +36,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
36
36
|
// function (/*str, lang*/) { return ''; }
|
37
37
|
//
|
38
38
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
39
|
-
},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}},
|
39
|
+
},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}},xa={options:{html:!1,// Enable HTML tags in source
|
40
40
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
41
41
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
42
42
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
@@ -51,7 +51,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
51
51
|
//
|
52
52
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
53
53
|
},components:{// Don't restrict core/block/inline rules
|
54
|
-
core:{},block:{},inline:{}}},
|
54
|
+
core:{},block:{},inline:{}}},wa={options:{html:!0,// Enable HTML tags in source
|
55
55
|
xhtmlOut:!0,// Use '/' to close single tags (<br />)
|
56
56
|
breaks:!1,// Convert '\n' in paragraphs into <br>
|
57
57
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
@@ -65,149 +65,148 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
|
|
65
65
|
// function (/*str, lang*/) { return ''; }
|
66
66
|
//
|
67
67
|
highlight:null,maxNesting:20// Internal protection, recursion limit
|
68
|
-
},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}},
|
68
|
+
},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}},Ca={"default":Sa,full:xa,commonmark:wa};function xr(r,e,t){this.src=e,this.env=t,this.options=r.options,this.tokens=[],this.inlineMode=!1,this.inline=r.inline,this.block=r.block,this.renderer=r.renderer,this.typographer=r.typographer;}function Be(r,e){typeof r!="string"&&(e=r,r="default"),e&&e.linkify!=null&&console.warn("linkify option is removed. Use linkify plugin instead:\n\nimport Remarkable from 'remarkable';\nimport linkify from 'remarkable/linkify';\nnew Remarkable().use(linkify)\n"),this.inline=new Ti(),this.block=new hn(),this.core=new Er(),this.renderer=new dn(),this.ruler=new _e(),this.options={},this.configure(Ca[r]),this.set(e||{});}Be.prototype.set=function(r){mr(this.options,r);};Be.prototype.configure=function(r){var e=this;if(!r)throw new Error("Wrong `remarkable` preset, check name/content");r.options&&e.set(r.options),r.components&&Object.keys(r.components).forEach(function(t){r.components[t].rules&&e[t].ruler.enable(r.components[t].rules,!0);});};Be.prototype.use=function(r,e){return r(this,e),this;};Be.prototype.parse=function(r,e){var t=new xr(this,r,e);return this.core.process(t),t.tokens;};Be.prototype.render=function(r,e){return e=e||{},this.renderer.render(this.parse(r,e),this.options,e);};Be.prototype.parseInline=function(r,e){var t=new xr(this,r,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};Be.prototype.renderInline=function(r,e){return e=e||{},this.renderer.render(this.parseInline(r,e),this.options,e);};var yt=/*#__PURE__*/function(){function yt(){_classCallCheck(this,yt);}return _createClass(yt,null,[{key:"addPlugins",value:function addPlugins(e,t){var s=window.remarkable_plugins;if(s&&s.forEach(function(i){e.use(i.plugin,i.options);}),t!=null&&t.math){window.katex||console.warn("window.katex not found, use chatElementRef.refreshMessages to re-render messages");var i=_typeof(t.math)=="object"?t.math.delimiter:"",n=_typeof(t.math)=="object"&&t.math.options?t.math.options:{};e.use(Vr.katex.bind(this,n),{delimiter:i});}}},{key:"instantiate",value:function instantiate(e){if(e)return new Be(_objectSpread(_objectSpread({},yt.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new Be({highlight:function highlight(s,i){if(i&&t.getLanguage(i))try{return t.highlight(s,{language:i}).value;}catch(_unused4){console.error("failed to setup the highlight dependency");}try{return t.highlightAuto(s).value;}catch(_unused5){console.error("failed to automatically highlight messages");}return"";},html:!1,// Enable HTML tags in source
|
69
69
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
70
70
|
breaks:!0,// Convert '\n' in paragraphs into <br>
|
71
71
|
langPrefix:"language-",// CSS language prefix for fenced blocks
|
72
72
|
linkTarget:"_blank",// set target to open in a new tab
|
73
73
|
typographer:!0// Enable smartypants and other sweet transforms
|
74
|
-
});}else return new
|
75
|
-
};var
|
76
|
-
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i,n){var o;n&&e["default"]!==n?
|
77
|
-
},{key:"extractParticularSharedStyles",value:function extractParticularSharedStyles(e,t){if(!(t!=null&&t.shared))return;var s=t.shared,i={outerContainer:{},innerContainer:{},bubble:{},media:{}};return e.forEach(function(n){var o,a,l,c;i.outerContainer[n]=((o=s.outerContainer)==null?void 0:o[n])||"",i.innerContainer[n]=((a=s.innerContainer)==null?void 0:a[n])||"",i.bubble[n]=((l=s.bubble)==null?void 0:l[n])||"",i.media[n]=((c=s.media)==null?void 0:c[n])||"";}),i;}}]);}();var hs=/*#__PURE__*/function(){function hs(){_classCallCheck(this,hs);}return _createClass(hs,null,[{key:"onMessage",value:function onMessage(e,t,s){var n;var i=JSON.parse(JSON.stringify({message:t,isHistory:s,isInitial:s}));K.reAddFileRefToObject(t,i.message),(n=e.onMessage)==null||n.call(e,i),e.dispatchEvent(new CustomEvent("message",{detail:i})),Y.fireOnNewMessage(e,i);}},{key:"onClearMessages",value:function onClearMessages(e){var t;(t=e.onClearMessages)==null||t.call(e),e.dispatchEvent(new CustomEvent("clear-messages"));}},{key:"onRender",value:function onRender(e){var t;(t=e.onComponentRender)==null||t.call(e,e),e.dispatchEvent(new CustomEvent("render",{detail:e}));}},{key:"onInput",value:function onInput(e,t,s){var n,o;var i=JSON.parse(JSON.stringify({content:t,isUser:s}));t.files&&K.reAddFileRefToObject({files:(n=t.files)==null?void 0:n.map(function(a){return{ref:a};})},i.content),(o=e.onInput)==null||o.call(e,i),e.dispatchEvent(new CustomEvent("input",{detail:i}));}},{key:"onError",value:function onError(e,t){var s;(s=e.onError)==null||s.call(e,t),e.dispatchEvent(new CustomEvent("error",{detail:t}));}}]);}();var q=/*#__PURE__*/function(){function q(){_classCallCheck(this,q);}return _createClass(q,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=document.createElement("div");return e.classList.add("loading-history"),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e;}},{key:"apply",value:function apply(e,t,s){Ue.setRing(t.bubbleElement,s==null?void 0:s.bubble),s!=null&&s.bubble&&(s=JSON.parse(JSON.stringify(s)),delete s.bubble),e.applyCustomStyles(t,"history",!1,s);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var o,a,l,c,d,u,h,f;e.bubbleElement.classList.add(q.CLASS);var i=s?q.FULL_VIEW_CLASS:q.SMALL_CLASS;e.outerContainer.classList.add(i);var n=s?(c=(l=(a=(o=t.messageStyles)==null?void 0:o.loading)==null?void 0:a.history)==null?void 0:l.full)==null?void 0:c.styles:(f=(h=(u=(d=t.messageStyles)==null?void 0:d.loading)==null?void 0:u.history)==null?void 0:h.small)==null?void 0:f.styles;q.apply(t,e,n),t.elementRef.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",y.AI_ROLE),s=t.bubbleElement,i=q.generateLoadingRingElement();return s.appendChild(i),t;}},{key:"addMessage",value:function addMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var n,o,a,l;var s=(l=(a=(o=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:o.history)==null?void 0:a.full)==null?void 0:l.html,i=s?Te.createElements(e,s,y.AI_ROLE,!0,!0):q.createDefaultElements(e);return q.addLoadHistoryMessage(i,e,t),y.softRemRoleElements(i.innerContainer,e.avatar,e.name),i;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var s,i,n,o,a,l,c,d;if(t!=null&&t.outerContainer.classList.contains(q.FULL_VIEW_CLASS)){t.outerContainer.classList.replace(q.FULL_VIEW_CLASS,q.SMALL_CLASS);var u=(o=(n=(i=(s=e.messageStyles)==null?void 0:s.loading)==null?void 0:i.history)==null?void 0:n.small)==null?void 0:o.styles;u&&q.apply(e,t,u);var h=(d=(c=(l=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:l.history)==null?void 0:c.small)==null?void 0:d.html;return h&&(t.bubbleElement.innerHTML=h),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];q.tryChangeViewToSmall(e,t)||q.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();q.CLASS="loading-history-message",q.FULL_VIEW_CLASS="loading-history-message-full-view",q.SMALL_CLASS="loading-history-message-small";var He=q;var is=/*#__PURE__*/function(){function is(){_classCallCheck(this,is);}return _createClass(is,null,[{key:"setFade",value:function setFade(e,t){e.style.transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(is.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e,t){var s;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:e.style.opacity="0";s=typeof t=="number"?t:is.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(i){setTimeout(function(){return i();},s);});case 1:e.style.opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();is.DEFAULT_FADE_MS=500;var Rs=is;var _n="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",Ri="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 rr=/*#__PURE__*/function(){function rr(e){_classCallCheck(this,rr);this.className=e;}return _createClass(rr,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e).style).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e).style.visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e).classList.add("role-hidden");}}]);}();var Le=/*#__PURE__*/function(_rr){function Le(e){var _this3;_classCallCheck(this,Le);_this3=_callSuper(this,Le,["avatar-container"]),_this3._avatars=e;return _this3;}_inherits(Le,_rr);return _createClass(Le,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var s=typeof this._avatars=="boolean"?void 0:this._avatars,i=this.createAvatar(t,s),n=this.getPosition(t,s);i.classList.add(n==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(n==="left"?"beforebegin":"afterend",i);}},{key:"createAvatar",value:function createAvatar(e,t){var n,o,a,l,c;var s=document.createElement("img");e===y.USER_ROLE?(s.src=((n=t==null?void 0:t.user)==null?void 0:n.src)||((o=t==null?void 0:t["default"])==null?void 0:o.src)||Ri,s.onerror=Le.errorFallback.bind(this,Ri)):(s.src=((a=t==null?void 0:t[e])==null?void 0:a.src)||((l=t==null?void 0:t.ai)==null?void 0:l.src)||((c=t==null?void 0:t["default"])==null?void 0:c.src)||_n,s.onerror=Le.errorFallback.bind(this,_n)),s.classList.add("avatar"),s.alt="".concat(e," avatar");var i=document.createElement("div");return i.classList.add(this.className),i.appendChild(s),t&&Le.applyCustomStyles(i,s,t,e),i;}},{key:"getPosition",value:function getPosition(e,t){var i,n,o,a,l,c;var s=(n=(i=t==null?void 0:t[e])==null?void 0:i.styles)==null?void 0:n.position;return e!==y.USER_ROLE&&(s!==null&&s!==void 0?s:s=(a=(o=t==null?void 0:t.ai)==null?void 0:o.styles)==null?void 0:a.position),s!==null&&s!==void 0?s:s=(c=(l=t==null?void 0:t["default"])==null?void 0:l.styles)==null?void 0:c.position,s!==null&&s!==void 0?s:s=e===y.USER_ROLE?"right":"left",s;}}],[{key:"errorFallback",value:function errorFallback(e,t){var s=t.target;s.onerror=null,s.src=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,s){Object.assign(e.style,s.container),Object.assign(t.style,s.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){var n,o,a,l;if((n=s["default"])!=null&&n.styles&&Le.applyCustomStylesToElements(e,t,s["default"].styles),i===y.USER_ROLE)(o=s.user)!=null&&o.styles&&Le.applyCustomStylesToElements(e,t,s.user.styles);else{(a=s.ai)!=null&&a.styles&&Le.applyCustomStylesToElements(e,t,s.ai.styles);var c=(l=s[i])==null?void 0:l.styles;c&&Le.applyCustomStylesToElements(e,t,c);}}}]);}(rr);var Zt=/*#__PURE__*/function(_rr2){function Zt(e){var _this4;_classCallCheck(this,Zt);_this4=_callSuper(this,Zt,["name"]),_this4._names=e;return _this4;}_inherits(Zt,_rr2);return _createClass(Zt,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var s=typeof this._names=="boolean"?{}:this._names,i=this.createName(t,s),n=Zt.getPosition(t,s);i.classList.add(n==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(n==="left"?"beforebegin":"afterend",i);}},{key:"createName",value:function createName(e,t){var s=document.createElement("div");return s.classList.add(this.className),s.textContent=Zt.getNameText(e,t),Zt.applyStyle(s,e,t),s;}}],[{key:"getPosition",value:function getPosition(e,t){var i,n,o;var s=(i=t==null?void 0:t[e])==null?void 0:i.position;return e!==y.USER_ROLE&&(s!==null&&s!==void 0?s:s=(n=t==null?void 0:t.ai)==null?void 0:n.position),s!==null&&s!==void 0?s:s=(o=t==null?void 0:t["default"])==null?void 0:o.position,s!==null&&s!==void 0?s:s=e===y.USER_ROLE?"right":"left",s;}},{key:"applyStyle",value:function applyStyle(e,t,s){var i,n,o,a;Object.assign(e.style,(i=s["default"])==null?void 0:i.style),t===y.USER_ROLE?Object.assign(e.style,(n=s.user)==null?void 0:n.style):(Object.assign(e.style,(o=s.ai)==null?void 0:o.style),Object.assign(e.style,(a=s[t])==null?void 0:a.style));}},{key:"getNameText",value:function getNameText(e,t){var s,i,n,o,a,l;return e===y.USER_ROLE?((s=t.user)==null?void 0:s.text)||((i=t["default"])==null?void 0:i.text)||"User":e===y.AI_ROLE?((n=t.ai)==null?void 0:n.text)||((o=t["default"])==null?void 0:o.text)||"AI":((a=t[e])==null?void 0:a.text)||((l=t["default"])==null?void 0:l.text)||e;}}]);}(rr);var se=/*#__PURE__*/function(){function se(e){var _this5=this;_classCallCheck(this,se);var t,s;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.elementRef=se.createContainerElement(),this.messageStyles=Y.processMessageStyles(e.messageStyles),this._remarkable=ds.createNew(e.remarkable),e.avatars&&(this.avatar=new Le(e.avatars)),e.names&&(this.name=new Zt(e.names)),e.browserStorage&&(this.browserStorage=new ra(e.browserStorage)),this._onMessage=hs.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),this.focusMode=e.focusMode,this.focusMode||(this._lastGroupMessagesElement=document.createElement("div")),typeof this.focusMode!="boolean"&&(t=this.focusMode)!=null&&t.fade&&Rs.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||Y.processStreamHTMLWrappers((s=e.connect)==null?void 0:s.stream),setTimeout(function(){_this5.submitUserMessage=e.submitUserMessage;});}return _createClass(se,[{key:"addNewTextMessage",value:function addNewTextMessage(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(s!=null&&s.status){var o=this.overwriteText(t,e,this.messageElementRefs);if(o)return o;s.status=!1;}var n=i?this.createAndPrependNewMessageElement(e,t,i):this.createAndAppendNewMessageElement(e,t);return n.bubbleElement.classList.add(se.TEXT_BUBBLE_CLASS),this.applyCustomStyles(n,t,!1),y.fillEmptyMessageElement(n.bubbleElement,e),n;}// prettier-ignore
|
78
|
-
},{key:"overwriteText",value:function overwriteText(e,t,s){var i=
|
74
|
+
});}else return new Be(yt.DEFAULT_PROPERTIES);}},{key:"createNew",value:function createNew(e){var t=yt.instantiate(e);return yt.addPlugins(t,e),t.inline.validateLink=function(){return!0;},t;}}]);}();yt.DEFAULT_PROPERTIES={breaks:!0,linkTarget:"_blank"// set target to open in a new tab
|
75
|
+
};var Ss=yt;var Aa=/*#__PURE__*/function(){function Aa(e){_classCallCheck(this,Aa);this.storageKey="deep-chat-storage",this.maxMessages=1e3,_typeof(e)=="object"&&(e.key&&(this.storageKey=e.key),e.maxMessages&&(this.maxMessages=e.maxMessages),e.clear=this.clear.bind(this));}return _createClass(Aa,[{key:"get",value:function get(){var e=localStorage.getItem(this.storageKey);return e?JSON.parse(e):[];}},{key:"addMessages",value:function addMessages(e){var t=e.length-this.maxMessages;t<0&&(t=0);var s=e.slice(t,e.length);localStorage.setItem(this.storageKey,JSON.stringify(s));}},{key:"clear",value:function clear(){localStorage.removeItem(this.storageKey);}}]);}();var he=/*#__PURE__*/function(){function he(){_classCallCheck(this,he);}return _createClass(he,null,[{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,s){if(s&&(Object.assign(e.outerContainer.style,s.outerContainer),Object.assign(e.innerContainer.style,s.innerContainer),Object.assign(e.bubbleElement.style,s.bubble),t)){var i=e.bubbleElement.children[0],n=i.tagName.toLocaleLowerCase()!=="a"?i:i.children[0];Object.assign(n.style,s.media);}}},{key:"applySideStyles",value:function applySideStyles(e,t,s,i){i&&(he.applyCustomStylesToElements(e,s,i.shared),t===b.USER_ROLE?he.applyCustomStylesToElements(e,s,i.user):(he.applyCustomStylesToElements(e,s,i.ai),he.applyCustomStylesToElements(e,s,i[t])));}},{key:"isElementsStyles",value:function isElementsStyles(e){return!!(e.outerContainer||e.innerContainer||e.bubble||e.media);}// prettier-ignore
|
76
|
+
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i,n){var o;n&&e["default"]!==n?he.isElementsStyles(n)?(he.applyCustomStylesToElements(t,i,(o=e["default"])==null?void 0:o.shared),he.applyCustomStylesToElements(t,i,n)):(he.applySideStyles(t,s,i,e["default"]),he.applySideStyles(t,s,i,n)):he.applySideStyles(t,s,i,e["default"]);}// prettier-ignore
|
77
|
+
},{key:"extractParticularSharedStyles",value:function extractParticularSharedStyles(e,t){if(!(t!=null&&t.shared))return;var s=t.shared,i={outerContainer:{},innerContainer:{},bubble:{},media:{}};return e.forEach(function(n){var o,a,l,c;i.outerContainer[n]=((o=s.outerContainer)==null?void 0:o[n])||"",i.innerContainer[n]=((a=s.innerContainer)==null?void 0:a[n])||"",i.bubble[n]=((l=s.bubble)==null?void 0:l[n])||"",i.media[n]=((c=s.media)==null?void 0:c[n])||"";}),i;}}]);}();var xs=/*#__PURE__*/function(){function xs(){_classCallCheck(this,xs);}return _createClass(xs,null,[{key:"onMessage",value:function onMessage(e,t,s){var n;var i=JSON.parse(JSON.stringify({message:t,isHistory:s,isInitial:s}));Q.reAddFileRefToObject(t,i.message),(n=e.onMessage)==null||n.call(e,i),e.dispatchEvent(new CustomEvent("message",{detail:i})),le.fireOnNewMessage(e,i);}},{key:"onClearMessages",value:function onClearMessages(e){var t;(t=e.onClearMessages)==null||t.call(e),e.dispatchEvent(new CustomEvent("clear-messages"));}},{key:"onRender",value:function onRender(e){var t;(t=e.onComponentRender)==null||t.call(e,e),e.dispatchEvent(new CustomEvent("render",{detail:e}));}},{key:"onInput",value:function onInput(e,t,s){var n,o;var i=JSON.parse(JSON.stringify({content:t,isUser:s}));t.files&&Q.reAddFileRefToObject({files:(n=t.files)==null?void 0:n.map(function(a){return{ref:a};})},i.content),(o=e.onInput)==null||o.call(e,i),e.dispatchEvent(new CustomEvent("input",{detail:i}));}},{key:"onError",value:function onError(e,t){var s;(s=e.onError)==null||s.call(e,t),e.dispatchEvent(new CustomEvent("error",{detail:t}));}}]);}();var W=/*#__PURE__*/function(){function W(){_classCallCheck(this,W);}return _createClass(W,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=document.createElement("div");return e.classList.add("loading-history"),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e.appendChild(document.createElement("div")),e;}},{key:"apply",value:function apply(e,t,s){Xe.setRing(t.bubbleElement,s==null?void 0:s.bubble),s!=null&&s.bubble&&(s=JSON.parse(JSON.stringify(s)),delete s.bubble),e.applyCustomStyles(t,"history",!1,s);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var o,a,l,c,d,h,u,f;e.bubbleElement.classList.add(W.CLASS);var i=s?W.FULL_VIEW_CLASS:W.SMALL_CLASS;e.outerContainer.classList.add(i);var n=s?(c=(l=(a=(o=t.messageStyles)==null?void 0:o.loading)==null?void 0:a.history)==null?void 0:l.full)==null?void 0:c.styles:(f=(u=(h=(d=t.messageStyles)==null?void 0:d.loading)==null?void 0:h.history)==null?void 0:u.small)==null?void 0:f.styles;W.apply(t,e,n),t.elementRef.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",b.AI_ROLE),s=t.bubbleElement,i=W.generateLoadingRingElement();return s.appendChild(i),t;}},{key:"addMessage",value:function addMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var n,o,a,l;var s=(l=(a=(o=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:o.history)==null?void 0:a.full)==null?void 0:l.html,i=s?De.createElements(e,s,b.AI_ROLE,!0,!0):W.createDefaultElements(e);return W.addLoadHistoryMessage(i,e,t),b.softRemRoleElements(i.innerContainer,e.avatar,e.name),i;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var s,i,n,o,a,l,c,d;if(t!=null&&t.outerContainer.classList.contains(W.FULL_VIEW_CLASS)){t.outerContainer.classList.replace(W.FULL_VIEW_CLASS,W.SMALL_CLASS);var h=(o=(n=(i=(s=e.messageStyles)==null?void 0:s.loading)==null?void 0:i.history)==null?void 0:n.small)==null?void 0:o.styles;h&&W.apply(e,t,h);var u=(d=(c=(l=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:l.history)==null?void 0:c.small)==null?void 0:d.html;return u&&(t.bubbleElement.innerHTML=u),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];W.tryChangeViewToSmall(e,t)||W.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();W.CLASS="loading-history-message",W.FULL_VIEW_CLASS="loading-history-message-full-view",W.SMALL_CLASS="loading-history-message-small";var Ze=W;var ms=/*#__PURE__*/function(){function ms(){_classCallCheck(this,ms);}return _createClass(ms,null,[{key:"setFade",value:function setFade(e,t){e.style.transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(ms.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e,t){var s;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:e.style.opacity="0";s=typeof t=="number"?t:ms.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(i){setTimeout(function(){return i();},s);});case 1:e.style.opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();ms.DEFAULT_FADE_MS=500;var js=ms;var Bn="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 wr=/*#__PURE__*/function(){function wr(e){_classCallCheck(this,wr);this.className=e;}return _createClass(wr,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e).style).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e).style.visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e).classList.add("role-hidden");}}]);}();var je=/*#__PURE__*/function(_wr){function je(e){var _this3;_classCallCheck(this,je);_this3=_callSuper(this,je,["avatar-container"]),_this3._avatars=e;return _this3;}_inherits(je,_wr);return _createClass(je,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var s=typeof this._avatars=="boolean"?void 0:this._avatars,i=this.createAvatar(t,s),n=this.getPosition(t,s);i.classList.add(n==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(n==="left"?"beforebegin":"afterend",i);}},{key:"createAvatar",value:function createAvatar(e,t){var n,o,a,l,c;var s=document.createElement("img");e===b.USER_ROLE?(s.src=((n=t==null?void 0:t.user)==null?void 0:n.src)||((o=t==null?void 0:t["default"])==null?void 0:o.src)||ji,s.onerror=je.errorFallback.bind(this,ji)):(s.src=((a=t==null?void 0:t[e])==null?void 0:a.src)||((l=t==null?void 0:t.ai)==null?void 0:l.src)||((c=t==null?void 0:t["default"])==null?void 0:c.src)||Bn,s.onerror=je.errorFallback.bind(this,Bn)),s.classList.add("avatar"),s.alt="".concat(e," avatar");var i=document.createElement("div");return i.classList.add(this.className),i.appendChild(s),t&&je.applyCustomStyles(i,s,t,e),i;}},{key:"getPosition",value:function getPosition(e,t){var i,n,o,a,l,c;var s=(n=(i=t==null?void 0:t[e])==null?void 0:i.styles)==null?void 0:n.position;return e!==b.USER_ROLE&&(s!==null&&s!==void 0?s:s=(a=(o=t==null?void 0:t.ai)==null?void 0:o.styles)==null?void 0:a.position),s!==null&&s!==void 0?s:s=(c=(l=t==null?void 0:t["default"])==null?void 0:l.styles)==null?void 0:c.position,s!==null&&s!==void 0?s:s=e===b.USER_ROLE?"right":"left",s;}}],[{key:"errorFallback",value:function errorFallback(e,t){var s=t.target;s.onerror=null,s.src=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,s){Object.assign(e.style,s.container),Object.assign(t.style,s.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){var n,o,a,l;if((n=s["default"])!=null&&n.styles&&je.applyCustomStylesToElements(e,t,s["default"].styles),i===b.USER_ROLE)(o=s.user)!=null&&o.styles&&je.applyCustomStylesToElements(e,t,s.user.styles);else{(a=s.ai)!=null&&a.styles&&je.applyCustomStylesToElements(e,t,s.ai.styles);var c=(l=s[i])==null?void 0:l.styles;c&&je.applyCustomStylesToElements(e,t,c);}}}]);}(wr);var ds=/*#__PURE__*/function(_wr2){function ds(e){var _this4;_classCallCheck(this,ds);_this4=_callSuper(this,ds,["name"]),_this4._names=e;return _this4;}_inherits(ds,_wr2);return _createClass(ds,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var s=typeof this._names=="boolean"?{}:this._names,i=this.createName(t,s),n=ds.getPosition(t,s);i.classList.add(n==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(n==="left"?"beforebegin":"afterend",i);}},{key:"createName",value:function createName(e,t){var s=document.createElement("div");return s.classList.add(this.className),s.textContent=ds.getNameText(e,t),ds.applyStyle(s,e,t),s;}}],[{key:"getPosition",value:function getPosition(e,t){var i,n,o;var s=(i=t==null?void 0:t[e])==null?void 0:i.position;return e!==b.USER_ROLE&&(s!==null&&s!==void 0?s:s=(n=t==null?void 0:t.ai)==null?void 0:n.position),s!==null&&s!==void 0?s:s=(o=t==null?void 0:t["default"])==null?void 0:o.position,s!==null&&s!==void 0?s:s=e===b.USER_ROLE?"right":"left",s;}},{key:"applyStyle",value:function applyStyle(e,t,s){var i,n,o,a;Object.assign(e.style,(i=s["default"])==null?void 0:i.style),t===b.USER_ROLE?Object.assign(e.style,(n=s.user)==null?void 0:n.style):(Object.assign(e.style,(o=s.ai)==null?void 0:o.style),Object.assign(e.style,(a=s[t])==null?void 0:a.style));}},{key:"getNameText",value:function getNameText(e,t){var s,i,n,o,a,l;return e===b.USER_ROLE?((s=t.user)==null?void 0:s.text)||((i=t["default"])==null?void 0:i.text)||"User":e===b.AI_ROLE?((n=t.ai)==null?void 0:n.text)||((o=t["default"])==null?void 0:o.text)||"AI":((a=t[e])==null?void 0:a.text)||((l=t["default"])==null?void 0:l.text)||e;}}]);}(wr);var ue=/*#__PURE__*/function(){function ue(e){var _this5=this;_classCallCheck(this,ue);var t,s,i;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.elementRef=ue.createContainerElement(),this.messageStyles=le.processMessageStyles(e.messageStyles),this._remarkable=Ss.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new je(e.avatars)),e.names&&(this.name=new ds(e.names)),e.browserStorage&&(this.browserStorage=new Aa(e.browserStorage)),this._onMessage=xs.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),this.focusMode=e.focusMode,this.focusMode||(this._lastGroupMessagesElement=document.createElement("div")),typeof this.focusMode!="boolean"&&(s=this.focusMode)!=null&&s.fade&&js.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||le.processStreamHTMLWrappers((i=e.connect)==null?void 0:i.stream),setTimeout(function(){_this5.submitUserMessage=e.submitUserMessage;});}return _createClass(ue,[{key:"addNewTextMessage",value:function addNewTextMessage(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(s!=null&&s.status){var o=this.overwriteText(t,e,this.messageElementRefs);if(o)return o;s.status=!1;}var n=i?this.createAndPrependNewMessageElement(e,t,i):this.createAndAppendNewMessageElement(e,t);return n.bubbleElement.classList.add(ue.TEXT_BUBBLE_CLASS),this.applyCustomStyles(n,t,!1),b.fillEmptyMessageElement(n.bubbleElement,e),n;}// prettier-ignore
|
78
|
+
},{key:"overwriteText",value:function overwriteText(e,t,s){var i=b.overwriteMessage(this.messageToElements,s,t,e,"text",ue.TEXT_BUBBLE_CLASS);return i&&this.renderText(i.bubbleElement,t,e),i;}},{key:"createAndAppendNewMessageElement",value:function createAndAppendNewMessageElement(e,t){return this.focusMode?this.appendNewMessageElementFocusMode(e,t):this.createAndAppendNewMessageElementDefault(e,t);}},{key:"appendNewMessageElementFocusMode",value:function appendNewMessageElementFocusMode(e,t){var i;var s=this.createNewMessageElement(e,t);if(this.appendOuterContainerElemet(s.outerContainer,t),t==="user"){var n=typeof this.focusMode!="boolean"&&((i=this.focusMode)==null?void 0:i.scroll);ae.scrollToBottom(this.elementRef,n);}return s;}},{key:"createNewGroupElementFocusMode",value:function createNewGroupElementFocusMode(){var t;(t=this._lastGroupMessagesElement)==null||t.classList.remove(ue.LAST_GROUP_MESSAGES_ACTIVE);var e=document.createElement("div");this._lastGroupMessagesElement&&e.classList.add(ue.LAST_GROUP_MESSAGES_ACTIVE),this._lastGroupMessagesElement=e;}},{key:"createAndAppendNewMessageElementDefault",value:function createAndAppendNewMessageElementDefault(e,t){var _this6=this;var s=this.createNewMessageElement(e,t);return this.appendOuterContainerElemet(s.outerContainer),setTimeout(function(){return ae.scrollToBottom(_this6.elementRef);}),s;}},{key:"appendOuterContainerElemet",value:function appendOuterContainerElemet(e,t){var s;this.focusMode&&(t==="user"||!this._lastGroupMessagesElement)&&this.createNewGroupElementFocusMode(),(s=this._lastGroupMessagesElement)==null||s.appendChild(e),this.elementRef.appendChild(this._lastGroupMessagesElement);}},{key:"createAndPrependNewMessageElement",value:function createAndPrependNewMessageElement(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var n=this.createNewMessageElement(e,t,s,i);if(s&&(o=this.elementRef.firstChild)!=null&&o.classList.contains(ue.INTRO_CLASS)){this.elementRef.firstChild.insertAdjacentElement("afterend",n.outerContainer);var a=this.messageElementRefs[0];this.messageElementRefs[0]=this.messageElementRefs[1],this.messageElementRefs[1]=a;}else this.elementRef.insertBefore(n.outerContainer,this.elementRef.firstChild);return n;}},{key:"createMessageElementsOnOrientation",value:function createMessageElementsOnOrientation(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;return s?this.createAndPrependNewMessageElement(e,t,s,i):this.createNewMessageElement(e,t,s,i);}},{key:"createNewMessageElement",value:function createNewMessageElement(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;i||(o=this._introPanel)==null||o.hide();var n=this.messageElementRefs[this.messageElementRefs.length-1];return Ze.changeFullViewToSmall(this),!s&&ue.isTemporaryElement(n)&&(this.revealRoleElementsIfTempRemoved(n,t),this.removeLastMessage()),this.createMessageElements(e,t,s);}// this can be tested by having an ai message, then a temp ai message with html that submits new user message:
|
79
79
|
// https://github.com/OvidijusParsiunas/deep-chat/issues/258
|
80
80
|
// prettier-ignore
|
81
|
-
},{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&
|
82
|
-
function addInnerContainerElements(e,t,s){var i=this.messageElementRefs[this.messageElementRefs.length-1];return
|
83
|
-
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){e&&this.messageStyles&&
|
84
|
-
},{key:"renderText",value:function renderText(e,t,s){var
|
85
|
-
},{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this7=this;this._remarkable=
|
81
|
+
},{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&Pe.isElementTemporary(e)){var s=this.messageElementRefs[this.messageElementRefs.length-2];s&&this.messageToElements.length>0&&!e.bubbleElement.classList.contains(b.getRoleClass(t))&&b.revealRoleElements(s.innerContainer,this.avatar,this.name);}}},{key:"createElements",value:function createElements(e,t){var s=ue.createBaseElements(t),i=s.outerContainer,n=s.innerContainer,o=s.bubbleElement;return i.appendChild(n),this.addInnerContainerElements(o,e,t),s;}},{key:"createMessageElements",value:function createMessageElements(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var i=this.createElements(e,t);return b.updateRefArr(this.messageElementRefs,i,s),b.classifyRoleMessages(this.messageElementRefs,t),i;}},{key:"addInnerContainerElements",value:// prettier-ignore
|
82
|
+
function addInnerContainerElements(e,t,s){var i=this.messageElementRefs[this.messageElementRefs.length-1];return b.areOuterContainerClassRolesSame(s,i)&&!this.isLastMessageError()&&b.hideRoleElements(i.innerContainer,this.avatar,this.name),e.classList.add("message-bubble",b.getRoleClass(s),s===b.USER_ROLE?"user-message-text":"ai-message-text"),this.renderText(e,t,s),b.addRoleElements(e,s,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
|
83
|
+
},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,s,i){e&&this.messageStyles&&he.applyCustomStyles(this.messageStyles,e,t,s,i);}},{key:"removeMessage",value:function removeMessage(e){e.outerContainer.remove();var t=this.messageElementRefs.findIndex(function(s){return s===e;});this.messageElementRefs.splice(t,1);}},{key:"removeLastMessage",value:function removeLastMessage(){this.messageElementRefs[this.messageElementRefs.length-1].outerContainer.remove(),this.messageElementRefs.pop();}},{key:"isLastMessageError",value:function isLastMessageError(){var e;return(e=b.getLastMessageBubbleElement(this.elementRef))==null?void 0:e.classList.contains(b.ERROR_MESSAGE_TEXT_CLASS);}},{key:"sendClientUpdate",value:function sendClientUpdate(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s;(s=this._onMessage)==null||s.call(this,e,t);}// role is optional to not add wrapper to error
|
84
|
+
},{key:"renderText",value:function renderText(e,t,s){var _oe$tryAddWrapper2=oe.tryAddWrapper(e,t,this._customWrappers,s),i=_oe$tryAddWrapper2.contentEl,n=_oe$tryAddWrapper2.wrapper;n&&oe.apply(this,e),i.innerHTML=this._remarkable.render(t),this._applyHTMLToRemarkable&&oe.apply(this,i),i.innerText.trim().length===0&&i.children.length>0&&i.children[0].tagName!=="P"&&(i.innerText=t);}// this is mostly used for enabling highlight.js to highlight code if it downloads later
|
85
|
+
},{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this7=this;this._remarkable=Ss.createNew(e),this.messageToElements.forEach(function(t){t[1].text&&t[0].text&&_this7.renderText(t[1].text.bubbleElement,t[0].text,t[0].role);});}}],[{key:"createContainerElement",value:function createContainerElement(){var e=document.createElement("div");return e.id="messages",e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return ue.isLoadingMessage(e)||Pe.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=document.createElement("div"),s=document.createElement("div");s.classList.add("inner-message-container"),t.appendChild(s),t.classList.add("outer-message-container"),t.classList.add(b.buildRoleOuterContainerClass(e));var i=document.createElement("div");return i.classList.add("message-bubble"),s.appendChild(i),{outerContainer:t,innerContainer:s,bubbleElement:i};}},{key:"createMessageContent",value:function createMessageContent(e){var t=e.text,s=e.files,i=e.html,n=e.custom,o=e._sessionId,a=e.role,l={role:a||b.AI_ROLE};return t&&(l.text=t),s&&(l.files=s),i&&(l.html=i),!t&&!s&&!i&&(l.text=""),n&&(l.custom=n),o&&(l._sessionId=o),l;}},{key:"isLoadingMessage",value:function isLoadingMessage(e){return e==null?void 0:e.bubbleElement.classList.contains(Xe.BUBBLE_CLASS);}}]);}();ue.TEXT_BUBBLE_CLASS="text-message",ue.INTRO_CLASS="deep-chat-intro",ue.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var we=ue;var A=/*#__PURE__*/function(){function A(){_classCallCheck(this,A);}return _createClass(A,null,[{key:"getLastElementsByClass",value:function getLastElementsByClass(e,t,s){var _loop=function _loop(){var n=e[i];if(n.bubbleElement.classList.contains(t[0])&&!t.slice(1).find(function(a){return!n.bubbleElement.classList.contains(a);}))if(s){if(!s.find(function(l){return n.bubbleElement.classList.contains(l);}))return{v:n};}else return{v:n};},_ret;for(var i=e.length-1;i>=0;i-=1){_ret=_loop();if(_ret)return _ret.v;}}},{key:"getLastMessage",value:function getLastMessage(e,t,s){for(var i=e.length-1;i>=0;i-=1)if(e[i][0].role===t)if(s){if(e[i][0][s])return e[i][0];}else return e[i][0];}},{key:"getLastTextToElement",value:function getLastTextToElement(e,t){for(var s=e.length-1;s>=0;s-=1)if(e[s][0]===t)return e[s];}// IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message
|
86
86
|
// and if messages have custom roles, it will still look to update the last 'ai' role message
|
87
87
|
// prettier-ignore
|
88
|
-
},{key:"overwriteMessage",value:function overwriteMessage(e,t,s,i,n,o){var a=
|
89
|
-
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e.classList.add(
|
90
|
-
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var s=t?
|
88
|
+
},{key:"overwriteMessage",value:function overwriteMessage(e,t,s,i,n,o){var a=A.getLastElementsByClass(t,[A.getRoleClass(i),o],[Xe.BUBBLE_CLASS]),l=A.getLastMessage(e,i,n);return l&&(l[n]=s),a;}},{key:"getRoleClass",value:function getRoleClass(e){return"".concat(e,"-message");}// makes sure the bubble has dimensions when there is no text
|
89
|
+
},{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e.classList.add(A.EMPTY_MESSAGE_CLASS),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e.classList.contains(A.EMPTY_MESSAGE_CLASS)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,s,i;return Array.from(((i=(s=(t=A.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:s[0])==null?void 0:i.children)||[]).find(function(n){return n.classList.contains("message-bubble");});}},{key:"getLastMessageElement",value:function getLastMessageElement(e){var s;var t=(s=e.children[e.children.length-1])==null?void 0:s.children;return t==null?void 0:t[t.length-1];}},{key:"addRoleElements",value:function addRoleElements(e,t,s,i){s==null||s.addBesideBubble(e,t),i==null||i.addBesideBubble(e,t);}},{key:"hideRoleElements",value:function hideRoleElements(e,t,s){t==null||t.tryHide(e),s==null||s.tryHide(e);}},{key:"revealRoleElements",value:function revealRoleElements(e,t,s){t==null||t.tryReveal(e),s==null||s.tryReveal(e);}},{key:"softRemRoleElements",value:function softRemRoleElements(e,t,s){t==null||t.trySoftRem(e),s==null||s.trySoftRem(e);}},{key:"updateRefArr",value:function updateRefArr(e,t,s){s?e.unshift(t):e.push(t);}},{key:"buildRoleOuterContainerClass",value:function buildRoleOuterContainerClass(e){return"".concat(A.OUTER_CONTAINER_CLASS_ROLE_PREFIX).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$cla;e.outerContainer.classList.remove(A.POSITION_TOP_MESSAGE_CLASS,A.POSITION_MIDDLE_MESSAGE_CLASS,A.POSITION_BOTTOM_MESSAGE_CLASS),(_e$outerContainer$cla=e.outerContainer.classList).add.apply(_e$outerContainer$cla,_toConsumableArray(t));}},{key:"getNumberOfElements",value:function getNumberOfElements(e){var t=0;return e.text!==void 0&&(t+=1),e.html!==void 0&&(t+=1),e.files&&(t+=e.files.length),t;}},{key:"filterdMessageElements",value:function filterdMessageElements(e,t){return e.filter(function(s){return s.bubbleElement.classList.contains(t);});}},{key:"findMessageElements",value:function findMessageElements(e,t){return e.find(function(s){return s.bubbleElement.classList.contains(t);});}},{key:"generateMessageBodyElements",value:function generateMessageBodyElements(e,t){var s={};return e.text&&(s.text=A.findMessageElements(t,we.TEXT_BUBBLE_CLASS)),e.html&&(s.html=A.findMessageElements(t,De.HTML_BUBBLE_CLASS)),e.files&&(s.files=A.filterdMessageElements(t,Q.FILE_BUBBLE_CLASS)),s;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var i=A.getNumberOfElements(e),n=s?t.slice(0,i):t.slice(t.length-i);return A.generateMessageBodyElements(e,n);}// if role not present - traverse all, if present - traverse last messages
|
90
|
+
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var s=t?A.buildRoleOuterContainerClass(t):void 0;for(var i=e.length-1;i>=0;i-=1){if(t||(s=Array.from(e[i].outerContainer.classList).find(function(h){return h.startsWith(A.OUTER_CONTAINER_CLASS_ROLE_PREFIX);})),!s)continue;var n=e[i],o=n.outerContainer.classList.contains(s),a=e[i-1],l=e[i+1],c=a==null?void 0:a.outerContainer.classList.contains(s),d=l==null?void 0:l.outerContainer.classList.contains(s);if(o)!c&&d?A.addNewPositionClasses(n,[A.POSITION_TOP_MESSAGE_CLASS]):c&&d?A.addNewPositionClasses(n,[A.POSITION_MIDDLE_MESSAGE_CLASS]):c&&!d?A.addNewPositionClasses(n,[A.POSITION_BOTTOM_MESSAGE_CLASS]):!c&&!d&&A.addNewPositionClasses(n,[A.POSITION_TOP_MESSAGE_CLASS,A.POSITION_BOTTOM_MESSAGE_CLASS]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer.classList).find(function(i){return i.startsWith(A.OUTER_CONTAINER_CLASS_ROLE_PREFIX);})===A.buildRoleOuterContainerClass(e):!1;}},{key:"resetAllRoleElements",value:function resetAllRoleElements(e,t,s){if(!t&&!s)return;var i="";e.forEach(function(n,o){n.bubbleElement.classList.contains(A.ERROR_MESSAGE_TEXT_CLASS)||A.revealRoleElements(n.innerContainer,t,s);var a=Array.from(n.outerContainer.classList).find(function(l){return l.startsWith(A.OUTER_CONTAINER_CLASS_ROLE_PREFIX);});i===a&&A.hideRoleElements(e[o-1].innerContainer,t,s),i=a;});}// this is a workaround to prevent JSON.parse(JSON.stringify()) from removing the files' 'ref' property values
|
91
91
|
// and 'custom' property value if it is not shallow copyable
|
92
92
|
// note - structuredClone can fix this but it doesn't have good legacy compatibility
|
93
|
-
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return
|
94
|
-
},{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,s,i){e.bubbleElement.innerHTML=i,this._targetWrapper=
|
95
|
-
},{key:"endStreamAfterFileDownloaded",value:function(){var _endStreamAfterFileDownloaded=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e,t){var _yield$t,s,i;return _regenerator().w(function(_context2){while(1)switch(_context2.n){case 0:this._endStreamAfterOperation=!0;_context2.n=1;return t();case 1:_yield$t=_context2.v;s=_yield$t.text;i=_yield$t.files;s&&this.updateBasedOnType(s,"text",!0),this._endStreamAfterOperation=!1,this.finaliseStreamedMessage(),i&&e.addNewMessage({files:i});case 2:return _context2.a(2);}},_callee2,this);}));function endStreamAfterFileDownloaded(_x3,_x4){return _endStreamAfterFileDownloaded.apply(this,arguments);}return endStreamAfterFileDownloaded;}()}]);}();
|
93
|
+
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return A.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!==S)return e;if(Array.isArray(e))return e.map(function(s){return A.processMessageContent(s);});var t={};return Object.entries(e).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),s=_ref6[0],i=_ref6[1];s==="ref"&&i instanceof File||s==="custom"?t[s]=i:i!==null&&_typeof(i)===S?t[s]=A.processMessageContent(i):t[s]=i;}),t;}}]);}();A.AI_ROLE="ai",A.USER_ROLE="user",A.ERROR_MESSAGE_TEXT_CLASS="error-message-text",A.OUTER_CONTAINER_CLASS_ROLE_PREFIX="deep-chat-outer-container-role-",A.EMPTY_MESSAGE_CLASS="empty-message",A.POSITION_TOP_MESSAGE_CLASS="deep-chat-top-message",A.POSITION_MIDDLE_MESSAGE_CLASS="deep-chat-middle-message",A.POSITION_BOTTOM_MESSAGE_CLASS="deep-chat-bottom-message";var b=A;var ze=/*#__PURE__*/function(){function ze(e,t){_classCallCheck(this,ze);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialText="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(ze,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e.text)===void 0&&(e==null?void 0:e.html)===void 0)return console.error(E.INVALID_STREAM_EVENT);e!=null&&e.custom&&this._message&&(this._message.custom=e.custom);var t=(e==null?void 0:e.text)||(e==null?void 0:e.html)||"",s=ae.isScrollbarAtBottomOfElement(this._messages.elementRef),i=(e==null?void 0:e.text)!==void 0?"text":"html";if(!this._elements&&!this._message)this.setInitialState(i,t,e==null?void 0:e.role);else{if(this._streamType!==i)return console.error(E.INVALID_STREAM_EVENT_MIX);this.updateBasedOnType(t,i,e==null?void 0:e.overwrite);}s&&ae.scrollToBottom(this._messages.elementRef);}},{key:"setInitialState",value:function setInitialState(e,t,s){var o,a;this._streamType=e,s!==null&&s!==void 0?s:s=b.AI_ROLE;var i=((o=this._messages._customWrappers)==null?void 0:o[s])||((a=this._messages._customWrappers)==null?void 0:a["default"]),n=i?"":t;this._elements=e==="text"?this._messages.addNewTextMessage(n,s):De.add(this._messages,n,s),this._elements&&(this._elements.bubbleElement.classList.add(ze.MESSAGE_CLASS),this._activeMessageRole=s,this._message=_defineProperty({role:this._activeMessageRole},e,n),this._messages.messageToElements.push([this._message,_defineProperty({},e,this._elements)]),i&&this.setTargetWrapperIfNeeded(this._elements,t,this._streamType,i));}// not using existing htmlUtils htmlWrappers logic to be able to stream html
|
94
|
+
},{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,s,i){e.bubbleElement.innerHTML=i,this._targetWrapper=oe.getTargetWrapper(e.bubbleElement),this._elements&&oe.apply(this._messages,this._elements.bubbleElement),this.updateBasedOnType(t,s);}},{key:"updateBasedOnType",value:function updateBasedOnType(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var o;var i=this._targetWrapper||((o=this._elements)==null?void 0:o.bubbleElement);this._partialRender||b.unfillEmptyMessageElement(i,e),(t==="text"?this.updateText:this.updateHTML).bind(this)(e,i,s);}},{key:"updateText",value:function updateText(e,t,s){this._message&&(this._message.text=s?e:this._message.text+e,this._partialRender&&this.isNewPartialRenderParagraph(t,s)&&this.partialRenderNewParagraph(t),this._partialBubble?this.partialRenderBubbleUpdate(e):this._messages.renderText(t,this._message.text));}},{key:"isNewPartialRenderParagraph",value:function isNewPartialRenderParagraph(e,t){var s;return t?(e.innerHTML="",!0):this._partialBubble?this._partialText&&this.shouldCreateNewParagraph(this._partialText):((s=this._message)==null?void 0:s.text)&&this.shouldCreateNewParagraph(this._message.text);}},{key:"shouldCreateNewParagraph",value:function shouldCreateNewParagraph(e){var t=e.indexOf(ze.PARTIAL_RENDER_TEXT_MARK);return t===-1?!1:!e.substring(t+ze.PARTIAL_RENDER_TEXT_MARK.length).startsWith("---");}},{key:"partialRenderNewParagraph",value:function partialRenderNewParagraph(e){this._partialText="",this._partialBubble=document.createElement("div"),this._partialBubble.classList.add("partial-render-message"),e.appendChild(this._partialBubble);}},{key:"partialRenderBubbleUpdate",value:function partialRenderBubbleUpdate(e){this._partialText+=e,this._messages.renderText(this._partialBubble,this._partialText);}},{key:"updateHTML",value:function updateHTML(e,t,s){if(this._message)if(s)this._message.html=e,t.innerHTML=e;else{var i=document.createElement("span");i.innerHTML=e,t.appendChild(i),this._message.html=(t==null?void 0:t.innerHTML)||"";}}},{key:"finaliseStreamedMessage",value:function finaliseStreamedMessage(){var e,t;if(!(this._endStreamAfterOperation||!this._message)&&!(this._fileAdded&&!this._elements)){if(!this._elements)throw Error(E.NO_VALID_STREAM_EVENTS_SENT);(e=this._elements.bubbleElement)!=null&&e.classList.contains(ze.MESSAGE_CLASS)&&(this._streamType==="text"?this._messages.textToSpeech&&Dt.speak(this._message.text||"",this._messages.textToSpeech):this._streamType==="html"&&this._elements&&oe.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement.classList.remove(ze.MESSAGE_CLASS),this._message&&(this._messages.sendClientUpdate(we.createMessageContent(this._message),!1),(t=this._messages.browserStorage)==null||t.addMessages(this._messages.messageToElements.map(function(_ref8){var _ref9=_slicedToArray(_ref8,1),s=_ref9[0];return s;}))),this._hasStreamEnded=!0);}}},{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,s,i;return _regenerator().w(function(_context2){while(1)switch(_context2.n){case 0:this._endStreamAfterOperation=!0;_context2.n=1;return t();case 1:_yield$t=_context2.v;s=_yield$t.text;i=_yield$t.files;s&&this.updateBasedOnType(s,"text",!0),this._endStreamAfterOperation=!1,this.finaliseStreamedMessage(),i&&e.addNewMessage({files:i});case 2:return _context2.a(2);}},_callee2,this);}));function endStreamAfterFileDownloaded(_x3,_x4){return _endStreamAfterFileDownloaded.apply(this,arguments);}return endStreamAfterFileDownloaded;}()}]);}();ze.MESSAGE_CLASS="streamed-message",ze.PARTIAL_RENDER_TEXT_MARK="\n\n";var Fe=ze;var M=/*#__PURE__*/function(){function M(){_classCallCheck(this,M);}return _createClass(M,null,[{key:"tempRemoveContentHeader",value:// need to pass stringifyBody boolean separately as binding is throwing an error for some reason
|
96
96
|
// prettier-ignore
|
97
|
-
function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,s){var i,n,_t2;return _regenerator().w(function(_context3){while(1)switch(_context3.p=_context3.n){case 0:if(e!=null&&e.headers){_context3.n=1;break;}throw new Error("Request settings have not been set up");case 1:i=e.headers[
|
98
|
-
},{key:"fetch",value:function(_fetch){function fetch(_x5,_x6,_x7,_x8){return _fetch.apply(this,arguments);}fetch.toString=function(){return _fetch.toString();};return fetch;}(function(e,t,s,i){var o,a;var n={method:((o=e.connectSettings)==null?void 0:o.method)||
|
99
|
-
},{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e,t){var s,i,_s$displayError,n,_s$useRI,o,a,l,c,d,_args5=arguments,_t4;return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:s=_args5.length>2&&_args5[2]!==undefined?_args5[2]:{};i=s.io,_s$displayError=s.displayError,n=_s$displayError===void 0?!0:_s$displayError,_s$useRI=s.useRI,o=_s$useRI===void 0?!0:_s$useRI;if(i!=null&&i.extractResultData){_context5.n=1;break;}return _context5.a(2,t);case 1:a=o?i.deepChat.responseInterceptor:void 0;_context5.n=2;return a==null?void 0:a(t);case 2:_t4=_context5.v;if(_t4){_context5.n=3;break;}_t4=t;case 3:l=_t4;_context5.n=4;return i.extractResultData(l);case 4:c=_context5.v;if(!(!c||_typeof(c)!="object"&&!Array.isArray(c))){_context5.n=5;break;}if(n){d=
|
100
|
-
function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,s){var i,n,
|
101
|
-
},{key:"handleReadableStream",value:function handleReadableStream(e,t,s,i,n,o){var
|
102
|
-
},{key:"handleEventStream",value:function handleEventStream(e,t,s,i,n,o){var d;var _e$streamHandlers2=e.streamHandlers,a=_e$streamHandlers2.onOpen,l=_e$streamHandlers2.onClose,c=
|
103
|
-
onopen:function onopen(
|
104
|
-
},{key:"handleMessage",value:function handleMessage(e,t,s,i,n){var o;(o=e.extractResultData)==null||o.call(e,i,n).then(function(a){
|
105
|
-
},{key:"handleError",value:function handleError(e,t,s){var i;t.isLastMessageError()||(i=e.extractResultData)==null||i.call(e,s).then(function(){
|
106
|
-
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,s,i){var n,o,_o2,a,_o3,_a2;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:n=t;_context1.n=1;return
|
97
|
+
function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,s){var i,n,_t2;return _regenerator().w(function(_context3){while(1)switch(_context3.p=_context3.n){case 0:if(e!=null&&e.headers){_context3.n=1;break;}throw new Error("Request settings have not been set up");case 1:i=e.headers[k];delete e.headers[k];_context3.p=2;_context3.n=3;return t(s);case 3:n=_context3.v;_context3.n=5;break;case 4:_context3.p=4;_t2=_context3.v;throw e.headers[k]=i,_t2;case 5:return _context3.a(2,(e.headers[k]=i,n));}},_callee3,null,[[2,4]]);}));function tempRemoveContentHeader(_x9,_x0,_x1){return _tempRemoveContentHeader.apply(this,arguments);}return tempRemoveContentHeader;}()},{key:"displayError",value:function displayError(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"Service error, please try again.";if(console.error(t),_typeof(t)===S)return t instanceof Error?e.addNewErrorMessage(F,t.message):Array.isArray(t)||typeof t.error=="string"?e.addNewErrorMessage(F,t):Object.keys(t).length===0?e.addNewErrorMessage(F,s):e.addNewErrorMessage(F,JSON.stringify(t));e.addNewErrorMessage(F,t);}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
98
|
+
},{key:"fetch",value:function(_fetch){function fetch(_x5,_x6,_x7,_x8){return _fetch.apply(this,arguments);}fetch.toString=function(){return _fetch.toString();};return fetch;}(function(e,t,s,i){var o,a;var n={method:((o=e.connectSettings)==null?void 0:o.method)||Y,headers:t};return n.method!==z&&(n.body=s?JSON.stringify(i):i),e.connectSettings.credentials&&(n.credentials=e.connectSettings.credentials),fetch(((a=e.connectSettings)==null?void 0:a.url)||e.url||"",n);})},{key:"processResponseByType",value:function processResponseByType(e){var t=e.headers.get("content-type");return t!=null&&t.includes(P)?e.json():t!=null&&t.includes("text/plain")||!t?e:e.blob();}},{key:"processRequestInterceptor",value:function(){var _processRequestInterceptor=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(e,t){var o,s,i,n,_t3;return _regenerator().w(function(_context4){while(1)switch(_context4.n){case 0:_context4.n=1;return(o=e.requestInterceptor)==null?void 0:o.call(e,t);case 1:_t3=_context4.v;if(_t3){_context4.n=2;break;}_t3=t;case 2:s=_t3;i=s;n=s;return _context4.a(2,{body:i.body,headers:i.headers,error:n.error});}},_callee4);}));function processRequestInterceptor(_x10,_x11){return _processRequestInterceptor.apply(this,arguments);}return processRequestInterceptor;}()},{key:"validateResponseFormat",value:function validateResponseFormat(e,t){if(!e)return!1;var s=Array.isArray(e)?e:[e];return t&&s.length>1?(console.error(E.INVALID_STREAM_ARRAY_RESPONSE),!1):!s.find(function(n){return _typeof(n)!="object"||!(typeof n.error=="string"||typeof n.text=="string"||typeof n.html=="string"||Array.isArray(n.files));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,s){e.addNewErrorMessage(F,t),s==null||s();}// prettier-ignore
|
99
|
+
},{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e,t){var s,i,_s$displayError,n,_s$useRI,o,a,l,c,d,_args5=arguments,_t4;return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:s=_args5.length>2&&_args5[2]!==undefined?_args5[2]:{};i=s.io,_s$displayError=s.displayError,n=_s$displayError===void 0?!0:_s$displayError,_s$useRI=s.useRI,o=_s$useRI===void 0?!0:_s$useRI;if(i!=null&&i.extractResultData){_context5.n=1;break;}return _context5.a(2,t);case 1:a=o?i.deepChat.responseInterceptor:void 0;_context5.n=2;return a==null?void 0:a(t);case 2:_t4=_context5.v;if(_t4){_context5.n=3;break;}_t4=t;case 3:l=_t4;_context5.n=4;return i.extractResultData(l);case 4:c=_context5.v;if(!(!c||_typeof(c)!="object"&&!Array.isArray(c))){_context5.n=5;break;}if(n){d=E.INVALID_RESPONSE(t,"response",!!a,l);M.displayError(e,d);}return _context5.a(2);case 5:return _context5.a(2,c);}},_callee5);}));function basicResponseProcessing(_x12,_x13){return _basicResponseProcessing.apply(this,arguments);}return basicResponseProcessing;}()}]);}();function Ta(_x14,_x15){return _Ta.apply(this,arguments);}function _Ta(){_Ta=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee186(r,e){var t,s;return _regenerator().w(function(_context186){while(1)switch(_context186.n){case 0:t=r.getReader();case 1:_context186.n=2;return t.read();case 2:if((s=_context186.v).done){_context186.n=4;break;}e(s.value);case 3:_context186.n=1;break;case 4:return _context186.a(2);}},_callee186);}));return _Ta.apply(this,arguments);}function Ra(r){var e,t,s,i=!1;return function(o){e===void 0?(e=o,t=0,s=-1):e=ka(e,o);var a=e.length;var l=0;for(;t<a;){i&&(e[t]===10&&(l=++t),i=!1);var c=-1;for(;t<a&&c===-1;++t)switch(e[t]){case 58:s===-1&&(s=t-l);break;case 13:i=!0;case 10:c=t;break;}if(c===-1)break;r(e.subarray(l,c),s),l=t,s=-1;}l===a?e=void 0:l!==0&&(e=e.subarray(l),t-=l);};}function Ma(r,e,t){var s=Fn();var i=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(s),s=Fn();else if(a>0){var l=i.decode(o.subarray(0,a)),c=a+(o[a+1]===32?2:1),d=i.decode(o.subarray(c));switch(l){case"data":s.data=s.data?s.data+"\n"+d:d;break;case"event":s.event=d;break;case"id":r(s.id=d);break;case"retry":var h=parseInt(d,10);isNaN(h)||e(s.retry=h);break;}}};}function ka(r,e){var t=new Uint8Array(r.length+e.length);return t.set(r),t.set(e,r.length),t;}function Fn(){return{data:"",event:"",id:"",retry:void 0};}var Ia=function Ia(r,e){var t={};for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&e.indexOf(s)<0&&(t[s]=r[s]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,s=Object.getOwnPropertySymbols(r);i<s.length;i++)e.indexOf(s[i])<0&&Object.prototype.propertyIsEnumerable.call(r,s[i])&&(t[s[i]]=r[s[i]]);return t;};var Vi="text/event-stream",La=1e3,Un="last-event-id";function Na(r,e){var t=e.signal,s=e.headers,i=e.onopen,n=e.onmessage,o=e.onclose,a=e.onerror,l=e.openWhenHidden,c=e.fetch,d=Ia(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(h,u){var f=Object.assign({},s);f.accept||(f.accept=Vi);var m;function p(){m.abort(),document.hidden||se();}l||document.addEventListener("visibilitychange",p);var y=La,_=0;function I(){document.removeEventListener("visibilitychange",p),window.clearTimeout(_),m.abort();}t==null||t.addEventListener("abort",function(){I(),h();});var D=c!==null&&c!==void 0?c:window.fetch,B=i!==null&&i!==void 0?i:Oa;function se(){return _se.apply(this,arguments);}function _se(){_se=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var st,it,me,_t5;return _regenerator().w(function(_context6){while(1)switch(_context6.p=_context6.n){case 0:m=new AbortController();_context6.p=1;_context6.n=2;return D(r,Object.assign(Object.assign({},d),{headers:f,signal:m.signal}));case 2:it=_context6.v;_context6.n=3;return B(it);case 3:_context6.n=4;return Ta(it.body,Ra(Ma(function(me){me?f[Un]=me:delete f[Un];},function(me){y=me;},n)));case 4:o==null||o();I();h();_context6.n=6;break;case 5:_context6.p=5;_t5=_context6.v;if(!m.signal.aborted)try{me=(st=a==null?void 0:a(_t5))!==null&&st!==void 0?st:y;window.clearTimeout(_),_=window.setTimeout(se,me);}catch(me){I(),u(me);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _se.apply(this,arguments);}se();});}function Oa(r){var e=r.headers.get("content-type");if(!(e!=null&&e.startsWith(Vi)))throw new Error("Expected content-type to be ".concat(Vi,", Actual: ").concat(e));}var x=/*#__PURE__*/function(){function x(){_classCallCheck(this,x);}return _createClass(x,null,[{key:"request",value:// prettier-ignore
|
100
|
+
function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,s){var i,n,u,f,m,p,y,o,_yield$M$processReque,a,l,c,d,h,_args7=arguments;return _regenerator().w(function(_context7){while(1)switch(_context7.n){case 0:i=_args7.length>3&&_args7[3]!==undefined?_args7[3]:!0;n=_args7.length>4&&_args7[4]!==undefined?_args7[4]:!1;o={body:t,headers:(u=e.connectSettings)==null?void 0:u.headers};_context7.n=1;return M.processRequestInterceptor(e.deepChat,o);case 1:_yield$M$processReque=_context7.v;a=_yield$M$processReque.body;l=_yield$M$processReque.headers;c=_yield$M$processReque.error;if(!c){_context7.n=2;break;}return _context7.a(2,M.onInterceptorError(s,c,e.streamHandlers.onClose));case 2:if(!((f=e.connectSettings)!=null&&f.handler)){_context7.n=3;break;}return _context7.a(2,Ie.stream(e,a,s));case 3:if(!(((m=e.connectSettings)==null?void 0:m.url)===Ne.URL)){_context7.n=4;break;}return _context7.a(2,Ne.requestStream(s,e));case 4:d=new Fe(s,e.stream),h={method:((p=e.connectSettings)==null?void 0:p.method)||Y,headers:l,credentials:(y=e.connectSettings)==null?void 0:y.credentials,body:i?JSON.stringify(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?x.handleReadableStream(e,s,d,h,n,a):x.handleEventStream(e,s,d,h,n,a),d));}},_callee7);}));function request(_x16,_x17,_x18){return _request.apply(this,arguments);}return request;}()// prettier-ignore
|
101
|
+
},{key:"handleReadableStream",value:function handleReadableStream(e,t,s,i,n,o){var d;var _e$streamHandlers=e.streamHandlers,a=_e$streamHandlers.onOpen,l=_e$streamHandlers.onClose;var c=!1;fetch(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",i).then(/*#__PURE__*/function(){var _ref0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(h){var p,y,u,f,m,_yield$u$read,_,I,D,B,se,_t6;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(h.body){_context8.n=1;break;}throw new Error(E.READABLE_STREAM_CONNECTION_ERROR);case 1:u=h.body.getReader(),f=new TextDecoder();a();m=!1;case 2:if(!(!m&&!c)){_context8.n=8;break;}_context8.n=3;return u.read();case 3:_yield$u$read=_context8.v;_=_yield$u$read.value;I=_yield$u$read.done;if(!(m=I,m)){_context8.n=4;break;}x.handleClose(e,s,l,n);_context8.n=7;break;case 4:D=f.decode(_,{stream:!0});_context8.n=5;return(y=(p=e.deepChat).responseInterceptor)==null?void 0:y.call(p,D);case 5:_t6=_context8.v;if(_t6){_context8.n=6;break;}_t6=D;case 6:B=_t6;se=_typeof(B)=="object"?B:_defineProperty({},g,D);x.handleMessage(e,t,s,se,o);case 7:_context8.n=2;break;case 8:return _context8.a(2);}},_callee8);}));return function(_x19){return _ref0.apply(this,arguments);};}())["catch"](function(h){x.handleError(e,t,h);}),e.streamHandlers.onAbort=function(){s.finaliseStreamedMessage(),e.streamHandlers.onClose(),c=!0;};}// prettier-ignore
|
102
|
+
},{key:"handleEventStream",value:function handleEventStream(e,t,s,i,n,o){var d;var _e$streamHandlers2=e.streamHandlers,a=_e$streamHandlers2.onOpen,l=_e$streamHandlers2.onClose,c=new AbortController();e.streamHandlers.onAbort=function(){s.finaliseStreamedMessage(),e.streamHandlers.onClose(),c.abort();},Na(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",_objectSpread(_objectSpread({},i),{},{openWhenHidden:!0,// keep stream open when browser tab not open
|
103
|
+
onopen:function onopen(h){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(){return _regenerator().w(function(_context9){while(1)switch(_context9.n){case 0:if(!h.ok){_context9.n=1;break;}return _context9.a(2,a());case 1:_context9.n=2;return M.processResponseByType(h);case 2:throw _context9.v;case 3:return _context9.a(2);}},_callee9);}))();},onmessage:function onmessage(h){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(){var u,f,m,p,_t7;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(JSON.stringify(h.data)!==JSON.stringify("[DONE]"))){_context0.n=3;break;}try{m=JSON.parse(h.data);}catch(_unused6){m={};}_context0.n=1;return(f=(u=e.deepChat).responseInterceptor)==null?void 0:f.call(u,m);case 1:_t7=_context0.v;if(_t7){_context0.n=2;break;}_t7=m;case 2:p=_t7;x.handleMessage(e,t,s,p,o);case 3:return _context0.a(2);}},_callee0);}))();},onerror:function onerror(h){throw l(),h;},onclose:function onclose(){x.handleClose(e,s,l,n);},signal:c.signal}))["catch"](function(h){x.handleError(e,t,h);});}//prettier-ignore
|
104
|
+
},{key:"handleMessage",value:function handleMessage(e,t,s,i,n){var o;(o=e.extractResultData)==null||o.call(e,i,n).then(function(a){x.upsertContent(t,s.upsertStreamedMessage.bind(s),s,a),t.removeError();})["catch"](function(a){t.isLastMessageError()||M.displayError(t,a);});}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
105
|
+
},{key:"handleError",value:function handleError(e,t,s){var i;t.isLastMessageError()||(i=e.extractResultData)==null||i.call(e,s).then(function(){M.displayError(t,s);})["catch"](function(n){M.displayError(t,n);});}},{key:"handleClose",value:function handleClose(e,t,s,i){if(e.asyncCallInProgress){e.asyncCallInProgress=!1;return;}try{t.finaliseStreamedMessage(),s();}catch(n){if(!i)throw n;}}// io is only passed for demo to simulate a real stream
|
106
|
+
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,s,i){var n,o,_o2,a,_o3,_a2;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:n=t;_context1.n=1;return M.basicResponseProcessing(e,s,{io:i,useRI:!1});case 1:if(_context1.v){_context1.n=2;break;}return _context1.a(2,t.onClose());case 2:if(!(Array.isArray(s)&&(s=s[0]),s.files)){_context1.n=4;break;}_context1.n=3;return M.basicResponseProcessing(e,{files:s.files},{io:i});case 3:o=_context1.v;e.addNewMessage(_objectSpread({sendUpdate:!1,ignoreText:!0},o),!1);case 4:if(s.text){t.onOpen();_o2=s.text.split(""),a=new Fe(e,i==null?void 0:i.stream);x.populateMessages(e,_o2,a,n,"text",0,i);}if(s.html){t.onOpen();_o3=oe.splitHTML(s.html);_o3.length===0&&(_o3=s.html.split(""));_a2=new Fe(e,i==null?void 0:i.stream);x.populateMessages(e,_o3,_a2,n,"html",0,i);}s.error&&(M.displayError(e,s.error),t.onClose());case 5:return _context1.a(2);}},_callee1);}));function simulate(_x20,_x21,_x22,_x23){return _simulate.apply(this,arguments);}return simulate;}()// prettier-ignore
|
107
107
|
// io is only passed for demo to simulate a real stream
|
108
|
-
},{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,s,i,n,o,a){var l,d,c,_t8;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:l=t[o];if(!l){_context10.n=5;break;}_context10.p=1;_context10.n=2;return
|
109
|
-
},{key:"request",value:function request(e,t){var s=
|
110
|
-
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var s=
|
111
|
-
},{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,s,i){if(!i)return;var n=e.stream.simulation;if(typeof n=="string"){var _s$o;var o=i.role||
|
112
|
-
},{key:"stream",value:function stream(e,t,s){var u
|
113
|
-
},{key:"websocket",value:function websocket(e,t){var _this9=this;var l,c;var s={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=s;var i=function i(){t.removeError(),s.isOpen=!0;},n=function n(){s.isOpen=!1;},o=/*#__PURE__*/function(){var
|
114
|
-
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,s){var i,u,
|
115
|
-
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,s){var i,f,m,p,n,_yield$
|
116
|
-
},{key:"verifyKey",value:function verifyKey(e,t,s,i,n,o,a,l,c){if(e==="")return o(
|
108
|
+
},{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,s,i,n,o,a){var l,d,c,_t8;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:l=t[o];if(!l){_context10.n=5;break;}_context10.p=1;_context10.n=2;return M.basicResponseProcessing(e,_defineProperty({},n,l),{io:a});case 2:d=_context10.v;x.upsertContent(e,s.upsertStreamedMessage.bind(s),s,d),e.removeError();_context10.n=4;break;case 3:_context10.p=3;_t8=_context10.v;e.isLastMessageError()||M.displayError(e,_t8);case 4:c=setTimeout(function(){x.populateMessages(e,t,s,i,n,o+1,a);},i.simulationInterim||6);i.abortStream.abort=function(){x.abort(c,s,i.onClose);};_context10.n=6;break;case 5:s.finaliseStreamedMessage(),i.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 x.isSimulation(e)&&t&&(t.text||t.html);}},{key:"abort",value:function abort(e,t,s){clearTimeout(e),t.finaliseStreamedMessage(),s();}},{key:"upsertContent",value:function upsertContent(e,t,s,i){if(i&&Array.isArray(i)&&(i=i[0]),i!=null&&i.text||i!=null&&i.html){var n=t(i);s!==null&&s!==void 0?s:s=n||void 0;}if(i!=null&&i.files&&(e.addNewMessage({files:i.files}),s==null||s.markFileAdded()),i!=null&&i.error)throw i.error;}}]);}();var bt=/*#__PURE__*/function(){function bt(){_classCallCheck(this,bt);}return _createClass(bt,null,[{key:"generateResponse",value:function generateResponse(e){var t=e[e.length-1][0];if(t.files&&t.files.length>0){if(t.files.length>1)return"These are interesting files!";var s=t.files[0];return s.src&&s.src.startsWith("data:image/gif")?"That is a nice gif!":s.type==="image"?"That is a nice image!":s.type==="audio"?"I like the sound of that!":"That is an interesting file!";}if(t.text){if(t.text.charAt(t.text.length-1)==="?")return"I'm sorry but I can't answer that question...";if(t.text.includes("updog"))return"What's updog?";}return"Hi there! This is a demo response!";}},{key:"getCustomResponse",value:function getCustomResponse(e,t){return typeof e=="function"?e(t):e;}},{key:"getResponse",value:function getResponse(_ref10){var e=_ref10.customDemoResponse,t=_ref10.messageToElements;return e?bt.getCustomResponse(e,t[t.length-1][0]):_defineProperty({},g,bt.generateResponse(t));}// timeout is used to simulate a timeout for a response to come back
|
109
|
+
},{key:"request",value:function request(e,t){var s=bt.getResponse(t);setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(){var i,n,o;return _regenerator().w(function(_context11){while(1)switch(_context11.n){case 0:_context11.n=1;return M.basicResponseProcessing(t,s,{io:e});case 1:i=_context11.v;if(i){_context11.n=2;break;}return _context11.a(2,e.completionsHandlers.onFinish());case 2:n=Array.isArray(i)?i:[i],o=n.find(function(a){return typeof a.error=="string";});o?(t.addNewErrorMessage(F,o.error),e.completionsHandlers.onFinish()):x.isSimulatable(e.stream,i)?x.simulate(t,e.streamHandlers,i):(n.forEach(function(a){return t.addNewMessage(a);}),e.completionsHandlers.onFinish());case 3:return _context11.a(2);}},_callee11);})),400);}// timeout is used to simulate a timeout for a response to come back
|
110
|
+
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var s=bt.getResponse(e);x.simulate(e,t.streamHandlers,s,t);},400);}}]);}();bt.URL="deep-chat-demo";var Ne=bt;var ne=/*#__PURE__*/function(){function ne(){_classCallCheck(this,ne);}return _createClass(ne,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(!ne.isElementPresentInDOM(e.deepChat))return;var s=e.connectSettings.websocket;if(s){if(e.connectSettings.handler)return Ie.websocket(e,t);try{var i=typeof s!="boolean"?s:void 0,n=new WebSocket(e.connectSettings.url||"",i);e.websocket=n,e.websocket.onopen=function(){var o,a;t.removeError(),e.websocket&&_typeof(e.websocket)===S&&ne.assignListeners(e,n,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console.error(o),ne.retryConnection(e,t);};}catch(i){console.error(i),ne.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var s,i;(i=(s=e.deepChat)._validationHandler)==null||i.call(s),ne.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage(F,"Connection error"),setTimeout(function(){ne.createConnection(e,t);},5e3));}},{key:"assignListeners",value:function assignListeners(e,t,s){var _this8=this;var i={};t.onmessage=/*#__PURE__*/function(){var _ref13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(n){var o,a,l,c,_l2,_c,_t9;return _regenerator().w(function(_context12){while(1)switch(_context12.p=_context12.n){case 0:if(!e.extractResultData){_context12.n=8;break;}_context12.p=1;o=JSON.parse(n.data);_context12.n=2;return M.basicResponseProcessing(s,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(E.INVALID_RESPONSE(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!x.isSimulation(e.stream)){_context12.n=4;break;}l=ne.stream.bind(_this8,e,s,i),c=i[o.role||b.AI_ROLE];x.upsertContent(s,l,c,a);_context12.n=6;break;case 4:_l2=Array.isArray(a)?a:[a],_c=_l2.find(function(d){return typeof d.error=="string";});if(!_c){_context12.n=5;break;}throw _c.error;case 5:_l2.forEach(function(d){return s.addNewMessage(d);});case 6:_context12.n=8;break;case 7:_context12.p=7;_t9=_context12.v;M.displayError(s,_t9,"Error in server message");case 8:return _context12.a(2);}},_callee12,null,[[1,7]]);}));return function(_x31){return _ref13.apply(this,arguments);};}(),t.onclose=function(){var n,o;console.error("Connection closed"),s.isLastMessageError()||s.addNewErrorMessage(F,"Connection error"),e.stream&&((o=(n=e.streamHandlers).onAbort)==null||o.call(n)),ne.createConnection(e,s);};}},{key:"sendWebsocket",value:function(){var _sendWebsocket=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e,t,s){var i,d,h,n,o,_yield$M$processReque2,a,l,c,_args13=arguments;return _regenerator().w(function(_context13){while(1)switch(_context13.n){case 0:i=_args13.length>3&&_args13[3]!==undefined?_args13[3]:!0;if(!(((d=e.connectSettings)==null?void 0:d.url)===Ne.URL)){_context13.n=1;break;}return _context13.a(2,Ne.request(e,s));case 1:n=e.websocket;if(!(!n||n==="pending")){_context13.n=2;break;}return _context13.a(2);case 2:o={body:t,headers:(h=e.connectSettings)==null?void 0:h.headers};_context13.n=3;return M.processRequestInterceptor(e.deepChat,o);case 3:_yield$M$processReque2=_context13.v;a=_yield$M$processReque2.body;l=_yield$M$processReque2.error;if(!l){_context13.n=4;break;}return _context13.a(2,s.addNewErrorMessage(F,l));case 4:if(ne.isWebSocket(n)){_context13.n=5;break;}return _context13.a(2,n.newUserMessage.listener(a));case 5:c=i?JSON.stringify(a):a;n.readyState===void 0||n.readyState!==n.OPEN?(console.error("Connection is not open"),s.isLastMessageError()||s.addNewErrorMessage(F,"Connection error")):(n.send(JSON.stringify(c)),e.completionsHandlers.onFinish());case 6:return _context13.a(2);}},_callee13);}));function sendWebsocket(_x32,_x33,_x34){return _sendWebsocket.apply(this,arguments);}return sendWebsocket;}()},{key:"canSendMessage",value:function canSendMessage(e){return e?e==="pending"?!1:ne.isWebSocket(e)?e.readyState!==void 0&&e.readyState===e.OPEN:e.isOpen:!0;}// if false then it is the internal websocket handler
|
111
|
+
},{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,s,i){if(!i)return;var n=e.stream.simulation;if(typeof n=="string"){var _s$o;var o=i.role||b.AI_ROLE,a=s[o];i.text===n||i.html===n?(a==null||a.finaliseStreamedMessage(),delete s[o]):((_s$o=s[o])!==null&&_s$o!==void 0?_s$o:s[o]=new Fe(t,e.stream),s[o].upsertStreamedMessage(i));}else x.simulate(t,e.streamHandlers,i);}}]);}();var Ie=/*#__PURE__*/function(){function Ie(){_classCallCheck(this,Ie);}return _createClass(Ie,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(e,t,s){var a,l,i,n,o;return _regenerator().w(function(_context15){while(1)switch(_context15.n){case 0:i=!0;n=/*#__PURE__*/function(){var _ref14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(c){var d,h,u;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(i){_context14.n=1;break;}return _context14.a(2);case 1:i=!1;_context14.n=2;return M.basicResponseProcessing(s,c,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console.error(E.INVALID_RESPONSE(c,"server",!!e.deepChat.responseInterceptor,d)),s.addNewErrorMessage(F,"Error in server message"),e.completionsHandlers.onFinish();else{h=Array.isArray(d)?d:[d],u=h.find(function(f){return typeof f.error=="string";});u?(console.error(u.error),s.addNewErrorMessage(F,u.error),e.completionsHandlers.onFinish()):x.isSimulatable(e.stream,d)?x.simulate(s,e.streamHandlers,d):(h.forEach(function(f){return s.addNewMessage(f);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function n(_x38){return _ref14.apply(this,arguments);};}(),o=Ie.generateOptionalSignals();(l=(a=e.connectSettings).handler)==null||l.call(a,t,_objectSpread(_objectSpread({},o),{},{onResponse:n}));case 1:return _context15.a(2);}},_callee15);}));function request(_x35,_x36,_x37){return _request2.apply(this,arguments);}return request;}()},{key:"attemptToFinaliseStream",value:function attemptToFinaliseStream(e,t){try{var s=t.messageElementRefs[t.messageElementRefs.length-1];we.isLoadingMessage(s)?t.removeLastMessage():e.finaliseStreamedMessage();}catch(s){console.error(s),t.addNewErrorMessage(F,s);}}// prettier-ignore
|
112
|
+
},{key:"stream",value:function stream(e,t,s){var h,u;var i=!0,n=!1;var o=new Fe(s,e.stream),a=function a(){n||!i||(e.streamHandlers.onOpen(),n=!0);},l=function l(){i&&(Ie.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1);},c=/*#__PURE__*/function(){var _ref15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(f){var m,p;return _regenerator().w(function(_context16){while(1)switch(_context16.n){case 0:if(i){_context16.n=1;break;}return _context16.a(2);case 1:_context16.n=2;return M.basicResponseProcessing(s,f,{io:e,displayError:!1});case 2:m=_context16.v;if(m)m.error?(Ie.streamError(m.error,o,e,s),i=!1):x.upsertContent(s,o.upsertStreamedMessage.bind(o),o,m);else{p=E.INVALID_RESPONSE(f,"server",!!e.deepChat.responseInterceptor,m);Ie.streamError(p,o,e,s),i=!1;}case 3:return _context16.a(2);}},_callee16);}));return function c(_x39){return _ref15.apply(this,arguments);};}();e.streamHandlers.onAbort=function(){Ie.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1;};var d=Ie.generateOptionalSignals();(u=(h=e.connectSettings).handler)==null||u.call(h,t,_objectSpread(_objectSpread({},d),{},{onOpen:a,onResponse:c,onClose:l,stopClicked:e.streamHandlers.stopClicked}));}},{key:"streamError",value:function streamError(e,t,s,i){console.error(e),t.finaliseStreamedMessage(),i.addNewErrorMessage(F,e),s.streamHandlers.onClose();}// prettier-ignore
|
113
|
+
},{key:"websocket",value:function websocket(e,t){var _this9=this;var l,c;var s={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=s;var i=function i(){t.removeError(),s.isOpen=!0;},n=function n(){s.isOpen=!1;},o=/*#__PURE__*/function(){var _ref16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(d){var h,u,f,m,p,y;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:_context17.n=1;return M.basicResponseProcessing(t,d,{io:e,displayError:!1});case 1:h=_context17.v;if(!h)console.error(E.INVALID_RESPONSE(d,"server",!!e.deepChat.responseInterceptor,h)),t.addNewErrorMessage(F,"Error in server message");else{u=Array.isArray(h)?h:[h],f=u.find(function(m){return typeof m.error=="string";});if(f)console.error(f.error),t.isLastMessageError()||t.addNewErrorMessage(F,f.error);else if(x.isSimulation(e.stream)){m=h,p=ne.stream.bind(_this9,e,t,s.roleToStream),y=s.roleToStream[m.role||b.AI_ROLE];x.upsertContent(t,p,y,m);}else u.forEach(function(m){return t.addNewMessage(m);});}case 2:return _context17.a(2);}},_callee17);}));return function o(_x40){return _ref16.apply(this,arguments);};}(),a=Ie.generateOptionalSignals();(c=(l=e.connectSettings).handler)==null||c.call(l,void 0,_objectSpread(_objectSpread({},a),{},{onOpen:i,onResponse:o,onClose:n,newUserMessage:s.newUserMessage}));}},{key:"generateOptionalSignals",value:function generateOptionalSignals(){return{onClose:function onClose(){},onOpen:function onOpen(){},stopClicked:{listener:function listener(){}},newUserMessage:{listener:function listener(){}}};}}]);}();var w=/*#__PURE__*/function(){function w(){_classCallCheck(this,w);}return _createClass(w,null,[{key:"request",value:// prettier-ignore
|
114
|
+
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,s){var i,h,u,f,n,_yield$M$processReque3,o,a,l,c,d,_args19=arguments;return _regenerator().w(function(_context19){while(1)switch(_context19.n){case 0:i=_args19.length>3&&_args19[3]!==undefined?_args19[3]:!0;n={body:t,headers:(h=e.connectSettings)==null?void 0:h.headers};_context19.n=1;return M.processRequestInterceptor(e.deepChat,n);case 1:_yield$M$processReque3=_context19.v;o=_yield$M$processReque3.body;a=_yield$M$processReque3.headers;l=_yield$M$processReque3.error;c=e.completionsHandlers.onFinish;if(!l){_context19.n=2;break;}return _context19.a(2,M.onInterceptorError(s,l,c));case 2:if(!((u=e.connectSettings)!=null&&u.handler)){_context19.n=3;break;}return _context19.a(2,Ie.request(e,o,s));case 3:if(!(((f=e.connectSettings)==null?void 0:f.url)===Ne.URL)){_context19.n=4;break;}return _context19.a(2,Ne.request(e,s));case 4:d=!0;M.fetch(e,a,i,o).then(function(m){return d=!!m.ok,m;}).then(function(m){return M.processResponseByType(m);}).then(/*#__PURE__*/function(){var _ref17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(m){var _,I,p,y,_t0;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(I=(_=e.deepChat).responseInterceptor)==null?void 0:I.call(_,m);case 2:_t0=_context18.v;if(_t0){_context18.n=3;break;}_t0=m;case 3:p=_t0;_context18.n=4;return e.extractResultData(p,o);case 4:y=_context18.v;if(d){_context18.n=5;break;}throw m;case 5:if(!(!y||_typeof(y)!==S&&!Array.isArray(y))){_context18.n=6;break;}throw Error(E.INVALID_RESPONSE(m,"response",!!e.deepChat.responseInterceptor,p));case 6:if(!y.error){_context18.n=7;break;}throw y.error;case 7:if(!e.asyncCallInProgress){_context18.n=8;break;}e.asyncCallInProgress=!1;return _context18.a(2);case 8:x.isSimulatable(e.stream,y)?x.simulate(s,e.streamHandlers,y):((Array.isArray(y)?y:[y]).forEach(function(B){return s.addNewMessage(B);}),c());case 9:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref17.apply(this,arguments);};}())["catch"](function(m){M.displayError(s,m),c();});case 5:return _context19.a(2);}},_callee19);}));function request(_x41,_x42,_x43){return _request3.apply(this,arguments);}return request;}()},{key:"executePollRequest",value:function executePollRequest(e,t,s,i){var n=e.completionsHandlers.onFinish;fetch(t,s).then(function(o){return o.json();}).then(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(o){var l,c,a,_t1,_t10;return _regenerator().w(function(_context20){while(1)switch(_context20.n){case 0:if(e.extractPollResultData){_context20.n=1;break;}return _context20.a(2);case 1:_t1=e;_context20.n=2;return(c=(l=e.deepChat).responseInterceptor)==null?void 0:c.call(l,o);case 2:_t10=_context20.v;if(_t10){_context20.n=3;break;}_t10=o;case 3:_context20.n=4;return _t1.extractPollResultData.call(_t1,_t10);case 4:a=_context20.v;a.timeoutMS?setTimeout(function(){w.executePollRequest(e,t,s,i);},a.timeoutMS):x.isSimulatable(e.stream,a)?x.simulate(i,e.streamHandlers,a):(i.addNewMessage(a),n());case 5:return _context20.a(2);}},_callee20);}));return function(_x45){return _ref18.apply(this,arguments);};}())["catch"](function(o){M.displayError(i,o),n();});}// prettier-ignore
|
115
|
+
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,s){var i,f,m,p,n,_yield$M$processReque4,o,a,l,c,d,h,u,_args21=arguments;return _regenerator().w(function(_context21){while(1)switch(_context21.n){case 0:i=_args21.length>3&&_args21[3]!==undefined?_args21[3]:!0;n={body:t,headers:(f=e.connectSettings)==null?void 0:f.headers};_context21.n=1;return M.processRequestInterceptor(e.deepChat,n);case 1:_yield$M$processReque4=_context21.v;o=_yield$M$processReque4.body;a=_yield$M$processReque4.headers;l=_yield$M$processReque4.error;if(!l){_context21.n=2;break;}return _context21.a(2,M.onInterceptorError(s,l));case 2:c=((m=e.connectSettings)==null?void 0:m.url)||e.url||"",d=((p=e.connectSettings)==null?void 0:p.method)||Y,h=i?JSON.stringify(o):o,u={method:d,body:h,headers:a};e.connectSettings.credentials&&(u.credentials=e.connectSettings.credentials),w.executePollRequest(e,c,u,s);case 3:return _context21.a(2);}},_callee21);}));function poll(_x46,_x47,_x48){return _poll.apply(this,arguments);}return poll;}()// prettier-ignore
|
116
|
+
},{key:"verifyKey",value:function verifyKey(e,t,s,i,n,o,a,l,c){if(e==="")return o(E.INVALID_KEY);a(),fetch(t,{method:i,headers:s,body:c||null}).then(function(d){return M.processResponseByType(d);}).then(function(d){l(d,e,n,o);})["catch"](function(d){o(E.CONNECTION_FAILED),console.error(d);});}}]);}();var nt=/*#__PURE__*/function(){function nt(e,t,s){_classCallCheck(this,nt);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,s.fetchHistory&&this.fetchHistory(s.fetchHistory),e.loadHistory&&this.setupLoadHistoryOnScroll(e.loadHistory),this.setupInitialHistory(e);}return _createClass(nt,[{key:"fetchHistory",value:function(){var _fetchHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(e){var _this0=this;var t,s;return _regenerator().w(function(_context22){while(1)switch(_context22.n){case 0:t=Ze.addMessage(this._messages);_context22.n=1;return e();case 1:s=_context22.v;this._messages.removeMessage(t),nt.displayIntroMessages(this._messages.messageElementRefs),s.forEach(function(i){return _this0._messages.addAnyMessage(i,!0);}),setTimeout(function(){return ae.scrollToBottom(_this0._messages.elementRef);},0);case 2:return _context22.a(2);}},_callee22,this);}));function fetchHistory(_x49){return _fetchHistory.apply(this,arguments);}return fetchHistory;}()},{key:"processLoadedHistory",value:function processLoadedHistory(e){var _this1=this;var a;var _this$_messages=this._messages,t=_this$_messages.messageElementRefs,s=_this$_messages.messageToElements,i=_this$_messages.elementRef,n=(a=t.find(function(l){return!l.outerContainer.classList.contains(we.INTRO_CLASS);}))==null?void 0:a.outerContainer,o=i.scrollTop;e==null||e.reverse().map(function(l){var c=_this1._messages.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!0}),!0,!0);if(c){var d=b.generateMessageBody(c,t,!0);s.unshift([c,d]);}return c;}).filter(function(l){return!!l;}).reverse().forEach(function(l){return _this1._messages.sendClientUpdate(l,!0);}),n&&(i.scrollTop=o+n.offsetTop-40);}},{key:"populateMessages",value:function populateMessages(e,t){this._messages.removeMessage(e),this._isPaginationComplete=t.findIndex(function(a){return!a;})<0;var s=t.filter(function(a){return!!a;});this.processLoadedHistory(s);var _this$_messages2=this._messages,i=_this$_messages2.messageElementRefs,n=_this$_messages2.avatar,o=_this$_messages2.name;b.resetAllRoleElements(i,n,o);}},{key:"setupLoadHistoryOnScroll",value:function(){var _setupLoadHistoryOnScroll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(e){var _this10=this;return _regenerator().w(function(_context24){while(1)switch(_context24.n){case 0:this._messages.elementRef.onscroll=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23(){var t,s,_t11;return _regenerator().w(function(_context23){while(1)switch(_context23.p=_context23.n){case 0:if(!(!_this10._isLoading&&!_this10._isPaginationComplete&&_this10._messages.elementRef.scrollTop===0)){_context23.n=4;break;}_this10._isLoading=!0;t=Ze.addMessage(_this10._messages,!1);_context23.p=1;_context23.n=2;return e(_this10._index++);case 2:s=_context23.v;_this10.populateMessages(t,s),_this10._isLoading=!1;_context23.n=4;break;case 3:_context23.p=3;_t11=_context23.v;_this10._messages.removeMessage(t),_this10._isPaginationComplete=!0,_this10._messages.addNewErrorMessage(F,nt.FAILED_ERROR_MESSAGE,!0),console.error(_t11);case 4:return _context23.a(2);}},_callee23,null,[[1,3]]);}));case 1:return _context24.a(2);}},_callee24,this);}));function setupLoadHistoryOnScroll(_x50){return _setupLoadHistoryOnScroll.apply(this,arguments);}return setupLoadHistoryOnScroll;}()},{key:"populateInitialHistory",value:function populateInitialHistory(e){var _this11=this;e.forEach(function(t){le.processHistoryFile(t),_this11._messages.addAnyMessage(t,!0);});}},{key:"loadInitialHistory",value:function(){var _loadInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(e){var _this12=this;var t,s,i,_t12;return _regenerator().w(function(_context25){while(1)switch(_context25.p=_context25.n){case 0:this._isLoading=!0;t=Ze.addMessage(this._messages);_context25.p=1;_context25.n=2;return e(this._index++);case 2:s=_context25.v;i=this._messages.elementRef.scrollTop;this.populateMessages(t,s),i===0&&setTimeout(function(){return ae.scrollToBottom(_this12._messages.elementRef);},0);_context25.n=4;break;case 3:_context25.p=3;_t12=_context25.v;this._messages.removeMessage(t),this._isPaginationComplete=!0,this._messages.addNewErrorMessage(F,nt.FAILED_ERROR_MESSAGE,!0),console.error(_t12);case 4:nt.displayIntroMessages(this._messages.messageElementRefs),this._isLoading=!1;case 5:return _context25.a(2);}},_callee25,this,[[1,3]]);}));function loadInitialHistory(_x51){return _loadInitialHistory.apply(this,arguments);}return loadInitialHistory;}()},{key:"setupInitialHistory",value:function(){var _setupInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(e){var s,t;return _regenerator().w(function(_context26){while(1)switch(_context26.n){case 0:e.loadHistory&&this.loadInitialHistory(e.loadHistory);t=e.history||le.processHistory(e)||((s=this._messages.browserStorage)==null?void 0:s.get());t&&(this.populateInitialHistory(t),this._index+=1);case 1:return _context26.a(2);}},_callee26,this);}));function setupInitialHistory(_x52){return _setupInitialHistory.apply(this,arguments);}return setupInitialHistory;}()}],[{key:"addErrorPrefix",value:function addErrorPrefix(e){var _e$permittedErrorPref;(_e$permittedErrorPref=e.permittedErrorPrefixes)!==null&&_e$permittedErrorPref!==void 0?_e$permittedErrorPref:e.permittedErrorPrefixes=[],e.permittedErrorPrefixes.push(nt.FAILED_ERROR_MESSAGE);}},{key:"displayIntroMessages",value:function displayIntroMessages(e){for(var t=0;t<e.length;t+=1){var s=e[0];if(s.outerContainer.classList.contains(we.INTRO_CLASS))s.outerContainer.style.display="";else break;}}}]);}();nt.FAILED_ERROR_MESSAGE="Failed to load history";var ws=nt;var G=/*#__PURE__*/function(){function G(){_classCallCheck(this,G);}return _createClass(G,null,[{key:"getCharacterLimitMessages",value:function getCharacterLimitMessages(e,t){var n;if(t===-1)return e;var s=0,i=e.length-1;for(i;i>=0;i-=1){var o=(n=e[i])==null?void 0:n.text;if(o!==void 0&&(s+=o.length,s>t)){e[i].text=o.substring(0,o.length-(s-t));break;}}return e.slice(Math.max(i,0));}},{key:"getMaxMessages",value:function getMaxMessages(e,t){return e.slice(Math.max(e.length-t,0));}// if maxMessages is not defined we send all messages
|
117
117
|
// if maxMessages above 0 we send that number
|
118
118
|
// if maxMessages 0 or below we send only what is in the request
|
119
|
-
},{key:"processMessages",value:function processMessages(e,t,s){return t!==void 0?t>0&&(e=
|
120
|
-
function parseConfig(e,t,s,i){var o;var n={files:t};if(_typeof(i)=="object"){
|
119
|
+
},{key:"processMessages",value:function processMessages(e,t,s){return t!==void 0?t>0&&(e=G.getMaxMessages(e,t)):e=[e[e.length-1]],e=JSON.parse(JSON.stringify(e)),s===void 0?e:G.getCharacterLimitMessages(e,s);}}]);}();var $=/*#__PURE__*/function(){function $(){_classCallCheck(this,$);}return _createClass($,null,[{key:"parseConfig",value:// prettier-ignore
|
120
|
+
function parseConfig(e,t,s,i){var o;var n={files:t};if(_typeof(i)=="object"){le.processFileConfigConnect(i);var a=i.files,l=i.connect,c=i.button;a&&(a.infoModal&&(n.files.infoModal=a.infoModal,(o=a.infoModal)!=null&&o.textMarkDown&&(n.infoModalTextMarkUp=s.render(a.infoModal.textMarkDown))),a.acceptedFormats&&(n.files.acceptedFormats=a.acceptedFormats),a.maxNumberOfFiles&&(n.files.maxNumberOfFiles=a.maxNumberOfFiles)),n.button=c,l&&(l.headers||l.method||l.url||l.credentials||e.headers||e.method||e.url||e.credentials)&&(n.connect={url:(l==null?void 0:l.url)||e.url,method:(l==null?void 0:l.method)||e.method,headers:(l==null?void 0:l.headers)||e.headers,credentials:(l==null?void 0:l.credentials)||e.credentials});}return n;}},{key:"processMixedFiles",value:function processMixedFiles(e,t,s){if(s){var i={acceptedFormats:""};e.fileTypes.mixedFiles=$.parseConfig(e.connectSettings,i,t,s);}}// needs to be set after audio to overwrite maxNumberOfFiles
|
121
121
|
// prettier-ignore
|
122
|
-
},{key:"processMicrophone",value:function processMicrophone(e,t,s,i){var _l$files,
|
123
|
-
},{key:"processAudioConfig",value:function processAudioConfig(e,t,s,i){if(!s&&!i)return;var o=_objectSpread({acceptedFormats:"audio/*"},(i==null?void 0:i.files)||{});e.fileTypes.audio
|
124
|
-
},{key:"processGifConfig",value:function processGifConfig(e,t,s,i){if(!s&&!i)return;var o=_objectSpread({acceptedFormats:"image/gif"},(i==null?void 0:i.files)||{});e.fileTypes.gifs
|
122
|
+
},{key:"processMicrophone",value:function processMicrophone(e,t,s,i){var _l$files,_u$maxNumberOfFiles;var a,l,c,d,h,u;var o=_objectSpread({acceptedFormats:"audio/*"},((a=e.fileTypes.audio)==null?void 0:a.files)||{});s&&(navigator.mediaDevices.getUserMedia!==void 0?(e.recordAudio=$.parseConfig(e.connectSettings,o,t,s),_typeof(s)=="object"&&s.files&&((_l$files=(l=e.recordAudio).files)!==null&&_l$files!==void 0?_l$files:l.files={},e.recordAudio.files.format=(c=s.files)==null?void 0:c.format,e.recordAudio.files.maxDurationSeconds=(d=s.files)==null?void 0:d.maxDurationSeconds,(h=e.fileTypes.audio)!=null&&h.files&&((_u$maxNumberOfFiles=(u=e.fileTypes.audio.files).maxNumberOfFiles)!==null&&_u$maxNumberOfFiles!==void 0?_u$maxNumberOfFiles:u.maxNumberOfFiles=s.files.maxNumberOfFiles))):i||(e.fileTypes.audio=$.parseConfig(e.connectSettings,o,t,s)));}// prettier-ignore
|
123
|
+
},{key:"processAudioConfig",value:function processAudioConfig(e,t,s,i){if(!s&&!i)return;var o=_objectSpread({acceptedFormats:"audio/*"},(i==null?void 0:i.files)||{});e.fileTypes.audio=$.parseConfig(e.connectSettings,o,t,s);}// prettier-ignore
|
124
|
+
},{key:"processGifConfig",value:function processGifConfig(e,t,s,i){if(!s&&!i)return;var o=_objectSpread({acceptedFormats:"image/gif"},(i==null?void 0:i.files)||{});e.fileTypes.gifs=$.parseConfig(e.connectSettings,o,t,s);}// needs to be set after images to overwrite maxNumberOfFiles
|
125
125
|
// prettier-ignore
|
126
|
-
},{key:"processCamera",value:function processCamera(e,t,s,i){var _l$files2;var a,l,c,d;var o=_objectSpread({acceptedFormats:"image/*"},((a=e.fileTypes.images)==null?void 0:a.files)||{});s&&(navigator.mediaDevices.getUserMedia!==void 0?(e.camera
|
127
|
-
},{key:"processImagesConfig",value:function processImagesConfig(e,t,s,i){if(!s&&!i)return;var o=_objectSpread({acceptedFormats:"image/*"},(i==null?void 0:i.files)||{});e.fileTypes.images
|
128
|
-
},{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$files,_s$acceptedFormats,_i$maxNumberOfFiles;var s,i;e&&((_e$files=e.files)!==null&&_e$files!==void 0?_e$files:e.files={},(_s$acceptedFormats=(s=e.files).acceptedFormats)!==null&&_s$acceptedFormats!==void 0?_s$acceptedFormats:s.acceptedFormats=t,(_i$maxNumberOfFiles=(i=e.files).maxNumberOfFiles)!==null&&_i$maxNumberOfFiles!==void 0?_i$maxNumberOfFiles:i.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,s){
|
129
|
-
},{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(e,t){var i,s,n;return _regenerator().w(function(_context31){while(1)switch(_context31.n){case 0:if(this.connectSettings){_context31.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=
|
130
|
-
function
|
131
|
-
},{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,s=_this$_keyVerificatio.url,i=_this$_keyVerificatio.method,n=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,l=_this$_keyVerificatio.augmentUrl,c=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(l==null?void 0:l(e))||s;
|
132
|
-
function
|
133
|
-
function constructPropertyAccessors(e,t){var s;Object.defineProperty(this,t||e,{get:function get(){return s;},set:function set(o){s=o,t?this[e]=o:
|
134
|
-
function changeVisibility(e,t,s,i){i.target.id===
|
135
|
-
},{key:"create",value:function create(e){var t=document.createElement("div");t.id="visibility-icon-container";var s=
|
126
|
+
},{key:"processCamera",value:function processCamera(e,t,s,i){var _l$files2;var a,l,c,d;var o=_objectSpread({acceptedFormats:"image/*"},((a=e.fileTypes.images)==null?void 0:a.files)||{});s&&(navigator.mediaDevices.getUserMedia!==void 0?(e.camera=$.parseConfig(e.connectSettings,o,t,s),_typeof(s)=="object"&&(e.camera.modalContainerStyle=s.modalContainerStyle,s.files&&((_l$files2=(l=e.camera).files)!==null&&_l$files2!==void 0?_l$files2:l.files={},e.camera.files.format=(c=s.files)==null?void 0:c.format,e.camera.files.dimensions=(d=s.files)==null?void 0:d.dimensions))):i||(e.fileTypes.images=$.parseConfig(e.connectSettings,o,t,s)));}// prettier-ignore
|
127
|
+
},{key:"processImagesConfig",value:function processImagesConfig(e,t,s,i){if(!s&&!i)return;var o=_objectSpread({acceptedFormats:"image/*"},(i==null?void 0:i.files)||{});e.fileTypes.images=$.parseConfig(e.connectSettings,o,t,s);}// default for direct service
|
128
|
+
},{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$files,_s$acceptedFormats,_i$maxNumberOfFiles;var s,i;e&&((_e$files=e.files)!==null&&_e$files!==void 0?_e$files:e.files={},(_s$acceptedFormats=(s=e.files).acceptedFormats)!==null&&_s$acceptedFormats!==void 0?_s$acceptedFormats:s.acceptedFormats=t,(_i$maxNumberOfFiles=(i=e.files).maxNumberOfFiles)!==null&&_i$maxNumberOfFiles!==void 0?_i$maxNumberOfFiles:i.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,s){$.populateDefaultFileIO(s==null?void 0:s.audio,".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),$.populateDefaultFileIO(s==null?void 0:s.images,".png,.jpg");var i=Ss.createNew(e.remarkable);$.processImagesConfig(t,i,e.images,s==null?void 0:s.images),$.processCamera(t,i,e.camera,e.images),$.processGifConfig(t,i,e.gifs,s==null?void 0:s.gifs),$.processAudioConfig(t,i,e.audio,s==null?void 0:s.audio),$.processMicrophone(t,i,e.microphone,e.audio),$.processMixedFiles(t,i,e.mixedFiles);}}]);}();var Ct=/*#__PURE__*/function(){function Ct(e,t,s){var _a$url;_classCallCheck(this,Ct);var i,n,o,a,l;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=Ct.canSendMessage,this.connectSettings={},this.fileTypes={},this.completionsHandlers={},this.streamHandlers={},this.deepChat=e,this.demo=s,Object.assign(this.rawBody,(i=e.connect)==null?void 0:i.additionalBodyProps),this.totalMessagesMaxCharLength=(n=e==null?void 0:e.requestBodyLimits)==null?void 0:n.totalMessagesMaxCharLength,this.maxMessages=(o=e==null?void 0:e.requestBodyLimits)==null?void 0:o.maxMessages,$.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=Ne.URL),this.connectSettings.websocket&&ne.setup(this),this.stream=((l=this.deepChat.connect)==null?void 0:l.stream)||le.checkForStream(this.deepChat),e.loadHistory&&ws.addErrorPrefix(this);}return _createClass(Ct,[{key:"verifyKey",value:function verifyKey(e,t){}},{key:"getServiceIOByType",value:function getServiceIOByType(e){if(e.type.startsWith("audio")&&this.fileTypes.audio)return this.fileTypes.audio;if(e.type.startsWith("image")){if(this.fileTypes.gifs&&e.type.endsWith("/gif"))return this.fileTypes.gifs;if(this.fileTypes.images)return this.fileTypes.images;if(this.camera)return this.camera;}return this.fileTypes.mixedFiles;}},{key:"request",value:function(){var _request4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(e,t){var s,_args27=arguments;return _regenerator().w(function(_context27){while(1)switch(_context27.n){case 0:s=_args27.length>2&&_args27[2]!==undefined?_args27[2]:!0;return _context27.a(2,this.stream&&!x.isSimulation(this.stream)?x.request(this,e,t,s):w.request(this,e,t,s));}},_callee27,this);}));function request(_x53,_x54){return _request4.apply(this,arguments);}return request;}()},{key:"callAPIWithText",value:function(){var _callAPIWithText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(e,t){var _o$headers,_a$k;var n,o,a,l,s,i;return _regenerator().w(function(_context28){while(1)switch(_context28.n){case 0:s=_objectSpread({messages:t},this.rawBody);i=!1;(n=this.connectSettings.headers)!=null&&n[k]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$k=(a=this.connectSettings.headers)[k])!==null&&_a$k!==void 0?_a$k:a[k]=P,i=!0);_context28.n=1;return this.request(s,e);case 1:i&&((l=this.connectSettings.headers)==null||delete l[k]);case 2:return _context28.a(2);}},_callee28,this);}));function callAPIWithText(_x55,_x56){return _callAPIWithText.apply(this,arguments);}return callAPIWithText;}()},{key:"callApiWithFiles",value:function(){var _callApiWithFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(e,t,s){var i,n,o;return _regenerator().w(function(_context29){while(1)switch(_context29.n){case 0:i=Ct.createCustomFormDataBody(this.rawBody,t,s),n=this.connectSettings,o=this.getServiceIOByType(s[0]);this.connectSettings=(o==null?void 0:o.connect)||this.connectSettings;_context29.n=1;return this.request(i,e,!1);case 1:this.connectSettings=n;case 2:return _context29.a(2);}},_callee29,this);}));function callApiWithFiles(_x57,_x58,_x59){return _callApiWithFiles.apply(this,arguments);}return callApiWithFiles;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(e,t,s){return _regenerator().w(function(_context30){while(1)switch(_context30.n){case 0:s?this.callApiWithFiles(e,t,s):this.callAPIWithText(e,t);case 1:return _context30.a(2);}},_callee30,this);}));function callServiceAPI(_x60,_x61,_x62){return _callServiceAPI.apply(this,arguments);}return callServiceAPI;}()// prettier-ignore
|
129
|
+
},{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(e,t){var i,s,n;return _regenerator().w(function(_context31){while(1)switch(_context31.n){case 0:if(this.connectSettings){_context31.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=G.processMessages(t.messageToElements.map(function(_ref20){var _ref21=_slicedToArray(_ref20,1),n=_ref21[0];return n;}),this.maxMessages,this.totalMessagesMaxCharLength);if(this.connectSettings.websocket&&(!this.connectSettings.handler||this.connectSettings.url!==Ne.URL)){n=_objectSpread({messages:s},this.rawBody);e.files&&(i=this.getServiceIOByType(e.files[0]))!=null&&i.connect?this.callApiWithFiles(t,s,e.files):ne.sendWebsocket(this,n,t,!1);}else this.callServiceAPI(t,s,e.files);case 2:return _context31.a(2);}},_callee31,this);}));function callAPI(_x63,_x64){return _callAPI.apply(this,arguments);}return callAPI;}()},{key:"extractResultData",value:function(){var _extractResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(e){return _regenerator().w(function(_context32){while(1)switch(_context32.n){case 0:if(!e.result){_context32.n=1;break;}return _context32.a(2,le.handleResponseProperty(e));case 1:if(!M.validateResponseFormat(e,!!this.stream)){_context32.n=2;break;}return _context32.a(2,e);case 2:return _context32.a(2);}},_callee32,this);}));function extractResultData(_x65){return _extractResultData.apply(this,arguments);}return extractResultData;}()},{key:"isDirectConnection",value:function isDirectConnection(){return!1;}},{key:"isWebModel",value:function isWebModel(){return!1;}},{key:"isCustomView",value:function isCustomView(){return!1;}}],[{key:"canSendMessage",value:function canSendMessage(e,t,s){return s?!0:!!(e&&e.trim()!=="")||!!(t&&t.length>0);}},{key:"createCustomFormDataBody",value:function createCustomFormDataBody(e,t,s){var i=new FormData();s.forEach(function(a){return i.append("files",a);}),Object.keys(e).forEach(function(a){return i.append(a,String(e[a]));});var n=0;t.slice(0,t.length-1).forEach(function(a){i.append("message".concat(n+=1),JSON.stringify(a));});var o=t[t.length-1];return o.text&&(delete o.files,i.append("message".concat(n+=1),JSON.stringify(o))),i;}}]);}();var L=/*#__PURE__*/function(_Ct){// prettier-ignore
|
130
|
+
function L(e,t,s,i,n){var _this13;_classCallCheck(this,L);var o;_this13=_callSuper(this,L,[e,n]),_this13.insertKeyPlaceholderText="API Key",_this13.keyHelpUrl="",_this13.asyncCallInProgress=!1,Object.assign(_this13.rawBody,(o=e.connect)==null?void 0:o.additionalBodyProps),_this13._keyVerificationDetails=t,_this13._buildHeadersFunc=s,i&&_this13.setApiKeyProperties(i),_this13.connectSettings=_this13.buildConnectSettings(_this13.key||"",e.connect);return _this13;}_inherits(L,_Ct);return _createClass(L,[{key:"setApiKeyProperties",value:function setApiKeyProperties(e){this.key=e.key,e.validateKeyProperty&&(this.validateKeyProperty=e.validateKeyProperty);}},{key:"buildConnectSettings",value:function buildConnectSettings(e,t){var _s$headers;var s=t!==null&&t!==void 0?t:{};return(_s$headers=s.headers)!==null&&_s$headers!==void 0?_s$headers:s.headers={},Object.assign(s.headers,this._buildHeadersFunc(e)),s;}},{key:"keyAuthenticated",value:function keyAuthenticated(e,t){this.connectSettings=this.buildConnectSettings(t,this.connectSettings),this.key=t,e();}// prettier-ignore
|
131
|
+
},{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,s=_this$_keyVerificatio.url,i=_this$_keyVerificatio.method,n=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,l=_this$_keyVerificatio.augmentUrl,c=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(l==null?void 0:l(e))||s;w.verifyKey(e,d,c,i,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,n,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}},{key:"callToolFunction",value:function(){var _callToolFunction=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(e,t){var n,o,s,a,l,_t13,_t14;return _regenerator().w(function(_context33){while(1)switch(_context33.n){case 0:this.asyncCallInProgress=!0;_context33.n=1;return e(t);case 1:s=_context33.v;if(Array.isArray(s)){_context33.n=6;break;}if(!s.text){_context33.n=5;break;}a=_defineProperty({},g,s.text);_context33.n=2;return(o=(n=this.deepChat).responseInterceptor)==null?void 0:o.call(n,a);case 2:_t13=_context33.v;if(_t13){_context33.n=3;break;}_t13=a;case 3:l=_t13;if(!Array.isArray(l)){_context33.n=4;break;}throw Error("Function tool response interceptor cannot return an array");case 4:return _context33.a(2,{processedResponse:l});case 5:throw Error("Function tool response must be an array or contain a text property");case 6:_context33.n=7;return Promise.all(s);case 7:_t14=_context33.v;return _context33.a(2,{responses:_t14});}},_callee33,this);}));function callToolFunction(_x66,_x67){return _callToolFunction.apply(this,arguments);}return callToolFunction;}()},{key:"makeAnotherRequest",value:function makeAnotherRequest(e,t){try{return t&&(this.stream?x.request(this,e,t):w.request(this,e,t)),_defineProperty({},g,"");}catch(s){throw this.asyncCallInProgress=!1,s;}}},{key:"genereteAPIKeyName",value:function genereteAPIKeyName(e){return"".concat(e," API Key");}}]);}(Ct);var Vs=/*#__PURE__*/function(){function Vs(){_classCallCheck(this,Vs);}return _createClass(Vs,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?Vs.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,Vs.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var Ge=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
|
132
|
+
function Ge(){var _this14;_classCallCheck(this,Ge);_this14=_callSuper(this,Ge),_this14._waitingToRender_=!1,_this14._propUpdated_=!1,Object.keys(Ge._attributeToProperty_).forEach(function(e){var t=Ge._attributeToProperty_[e];_this14.constructPropertyAccessors(t),_this14.hasOwnProperty(e)||_this14.constructPropertyAccessors(t,e);});return _this14;}_inherits(Ge,_HTMLElement);return _createClass(Ge,[{key:"constructPropertyAccessors",value:// need to be called here as accessors need to be set for the class instance
|
133
|
+
function constructPropertyAccessors(e,t){var s;Object.defineProperty(this,t||e,{get:function get(){return s;},set:function set(o){s=o,t?this[e]=o:Vs.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,s){if(t===s)return;var i=Ge._attributes_[e](s),n=Ge._attributeToProperty_[e];this[n]=i;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(Ge._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));Ge._attributes_={},Ge._attributeToProperty_={};var Ki=Ge;var Pa="<?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",Da="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path id=\"path6686\" inkscape:connector-curvature=\"0\" d=\"M779.843,599.925c0,95.331-80.664,172.612-180.169,172.612\n\t\t\tc-99.504,0-180.168-77.281-180.168-172.612c0-95.332,80.664-172.612,180.168-172.612\n\t\t\tC699.179,427.312,779.843,504.594,779.843,599.925z M600,240.521c-103.025,0.457-209.814,25.538-310.904,73.557\n\t\t\tc-75.058,37.122-148.206,89.496-211.702,154.141C46.208,501.218,6.431,549,0,599.981c0.76,44.161,48.13,98.669,77.394,131.763\n\t\t\tc59.543,62.106,130.786,113.018,211.702,154.179c94.271,45.751,198.616,72.092,310.904,73.557\n\t\t\tc103.123-0.464,209.888-25.834,310.866-73.557c75.058-37.122,148.243-89.534,211.74-154.179\n\t\t\tc31.185-32.999,70.962-80.782,77.394-131.763c-0.76-44.161-48.13-98.671-77.394-131.764\n\t\t\tc-59.543-62.106-130.824-112.979-211.74-154.141C816.644,268.36,712.042,242.2,600,240.521z M599.924,329.769\n\t\t\tc156.119,0,282.675,120.994,282.675,270.251c0,149.256-126.556,270.25-282.675,270.25S317.249,749.275,317.249,600.02\n\t\t\tC317.249,450.763,443.805,329.769,599.924,329.769L599.924,329.769z\"/>\n</svg>\n";var Qe=/*#__PURE__*/function(){function Qe(){_classCallCheck(this,Qe);}return _createClass(Qe,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var rt=/*#__PURE__*/function(){function rt(){_classCallCheck(this,rt);}return _createClass(rt,null,[{key:"changeVisibility",value:// prettier-ignore
|
134
|
+
function changeVisibility(e,t,s,i){i.target.id===rt.VISIBLE_ICON_ID?(t.style.display="none",s.style.display="block",e.type="password"):(t.style.display="block",s.style.display="none",e.type="text");}},{key:"createIconElement",value:function createIconElement(e,t){var s=Qe.createSVGElement(e);return s.id=t,s.classList.add("visibility-icon"),s;}// prettier-ignore
|
135
|
+
},{key:"create",value:function create(e){var t=document.createElement("div");t.id="visibility-icon-container";var s=rt.createIconElement(Da,rt.VISIBLE_ICON_ID);s.style.display="none",t.appendChild(s);var i=rt.createIconElement(Pa,"not-visible-icon");return t.appendChild(i),t.onclick=rt.changeVisibility.bind(this,e,s,i),t;}}]);}();rt.VISIBLE_ICON_ID="visible-icon";var zi=rt;var ce=/*#__PURE__*/function(){function ce(){_classCallCheck(this,ce);}return _createClass(ce,null,[{key:"createCautionText",value:function createCautionText(){var e=document.createElement("a");return e.classList.add("insert-key-input-help-text"),e.innerText="Please exercise CAUTION when inserting your API key outside of deepchat.dev or localhost!!",e;}},{key:"createHelpLink",value:function createHelpLink(e){var t=document.createElement("a");return t.classList.add("insert-key-input-help-text"),t.href=e,t.innerText="Find more info here",t.target="_blank",t;}},{key:"createFailText",value:function createFailText(){var e=document.createElement("div");return e.id="insert-key-input-invalid-text",e.style.display="none",e;}},{key:"createHelpTextContainer",value:function createHelpTextContainer(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var s=document.createElement("div");s.id="insert-key-help-text-container";var i=document.createElement("div");i.id="insert-key-help-text-contents";var n=ce.createFailText();if(i.appendChild(n),e){var o=ce.createHelpLink(e);i.appendChild(o);}if(t===!0){var _o4=ce.createCautionText();i.appendChild(_o4);}return s.appendChild(i),{helpTextContainerElement:s,failTextElement:n};}},{key:"onFail",value:function onFail(e,t,s,i){e.classList.replace("insert-key-input-valid","insert-key-input-invalid"),s.innerText=i,s.style.display="block",t.innerText="Start",e.classList.remove("loading");}},{key:"onLoad",value:function onLoad(e,t){e.classList.add("loading"),t.innerHTML='<div id="loading-key"></div>';}// prettier-ignore
|
136
136
|
},{key:"verifyKey",value:function verifyKey(e,t,s){var i=e.value.trim();s.verifyKey(i,t);}// prettier-ignore
|
137
|
-
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,s,i,n){var o={onSuccess:i,onFail:
|
138
|
-
},{key:"createContents",value:function createContents(e,t){var d;var s=document.createElement("div");s.id="insert-key-contents";var i=
|
139
|
-
},{key:"setUpInitial",value:function setUpInitial(e,t,s,i){var n=(t==null?void 0:t.downloadClass)||
|
140
|
-
},{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,s,i){var n=(t==null?void 0:t.exportFilesClass)||
|
137
|
+
},{key:"addVerificationEvents",value:function addVerificationEvents(e,t,s,i,n){var o={onSuccess:i,onFail:ce.onFail.bind(this,e,t,s),onLoad:ce.onLoad.bind(this,e,t)},a=ce.verifyKey.bind(this,e,o,n);t.onclick=a,e.onkeydown=function(l){!e.classList.contains("loading")&&l.key===X.ENTER&&a();};}},{key:"createStartButton",value:function createStartButton(){var e=document.createElement("div");return e.id="start-button",e.innerText="Start",e;}},{key:"onInputFocus",value:function onInputFocus(e){e.target.classList.replace("insert-key-input-invalid","insert-key-input-valid");}},{key:"createInput",value:function createInput(e){var t=document.createElement("div");t.id="insert-key-input-container";var s=document.createElement("input");return s.id="insert-key-input",s.placeholder=e||"API Key",s.type="password",s.classList.add("insert-key-input-valid"),s.onfocus=ce.onInputFocus,t.appendChild(s),t;}// prettier-ignore
|
138
|
+
},{key:"createContents",value:function createContents(e,t){var d;var s=document.createElement("div");s.id="insert-key-contents";var i=ce.createInput(t.insertKeyPlaceholderText),n=i.children[0],o=zi.create(n);i.appendChild(o),s.appendChild(i);var a=ce.createStartButton(),_ce$createHelpTextCon=ce.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),l=_ce$createHelpTextCon.helpTextContainerElement,c=_ce$createHelpTextCon.failTextElement;return s.appendChild(a),s.appendChild(l),ce.addVerificationEvents(n,a,c,e,t),s;}},{key:"createElements",value:function createElements(e,t){var s=document.createElement("div");s.id="insert-key-view";var i=ce.createContents(e,t);return s.appendChild(i),s;}},{key:"render",value:function render(e,t,s){var i=ce.createElements(t,s);e.replaceChildren(i);}}]);}();var ge=/*#__PURE__*/function(){function ge(){_classCallCheck(this,ge);}return _createClass(ge,null,[{key:"enableButtons",value:function enableButtons(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;window.webLLM?(e&&(e.disabled=!1),t&&(t.disabled=!1)):s<Cs.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return ge.enableButtons(e,t,s+1);},250);}// prettier-ignore
|
139
|
+
},{key:"setUpInitial",value:function setUpInitial(e,t,s,i){var n=(t==null?void 0:t.downloadClass)||ge.DOWNLOAD_BUTTON_CLASS,o=(t==null?void 0:t.uploadClass)||ge.UPLOAD_BUTTON_CLASS,a=(t==null?void 0:t.fileInputClass)||ge.FILE_INPUT_CLASS;return setTimeout(function(){var l=s==null?void 0:s.getElementsByClassName(n)[0],c=s==null?void 0:s.getElementsByClassName(a)[0],d=s==null?void 0:s.getElementsByClassName(o)[0];l&&(l.onclick=function(){return e();}),c&&(c.onchange=function(){c.files&&c.files.length>0&&e(c.files);}),d&&(d.onclick=function(){return c.click();}),(l||d)&&ge.enableButtons(l,d);}),(t==null?void 0:t.initialHtml)||"<div>\n Download or upload a web model that will run entirely on your browser: <br/> \n <button disabled class=\"".concat(n," deep-chat-button deep-chat-web-model-button\">Download</button>\n ").concat(i?"":"<input type=\"file\" class=\"".concat(a,"\" hidden multiple />\n <button disabled class=\"").concat(o," deep-chat-button deep-chat-web-model-button\">Upload</button>"),"\n </div>");}},{key:"exportFile",value:function exportFile(e){var t=document.createElement("a"),s=4;var _loop2=function _loop2(i){setTimeout(function(){var n=i*s;for(var o=n;o<Math.min(n+s,e.length);o+=1){var a=URL.createObjectURL(e[o]);t.href=a,t.download=e[o].name,document.body.appendChild(t),t.click(),URL.revokeObjectURL(a);}},500*i);};for(var i=0;i<e.length/s;i+=1){_loop2(i);}}// prettier-ignore
|
140
|
+
},{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,s,i){var n=(t==null?void 0:t.exportFilesClass)||ge.EXPORT_BUTTON_CLASS;return setTimeout(function(){var o=s==null?void 0:s.getElementsByClassName(n)[0];o&&(o.onclick=function(){return ge.exportFile(e);});}),(t==null?void 0:t.afterLoadHtml)||"<div>\n Model loaded successfully and has been cached for future requests.\n ".concat(i?"":"<br/> <button style=\"margin-top: 5px\" class=\"".concat(n," deep-chat-button\">Export</button>"),"\n </div>");}}]);}();ge.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",ge.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",ge.FILE_INPUT_CLASS="deep-chat-file-input",ge.EXPORT_BUTTON_CLASS="deep-chat-export-button";var Ks=ge;var Hn={model_list:[// Llama-2
|
141
141
|
{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f32_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f32_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:9109.03,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:6749.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:4618.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-13b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-13b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-13b-chat-hf/Llama-2-13b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:11814.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-70b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-70b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-70b-chat-hf/Llama-2-70b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:43729.05,low_resource_required:!1,required_features:["shader-f16"]},// RedPajama
|
142
142
|
{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f16_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f16_1-ctx2k-webgpu.wasm",vram_required_MB:2972.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f32_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f32_1-ctx2k-webgpu.wasm",vram_required_MB:3928.09,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f16_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:2041.09,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f32_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:2558.09,low_resource_required:!0},// Mistral variants
|
143
143
|
{model_url:"https://huggingface.co/mlc-ai/WizardMath-7B-V1.1-q4f16_1-MLC/resolve/main/",local_id:"WizardMath-7B-V1.1-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Mistral-7B-Instruct-v0.2-q4f16_1-MLC/resolve/main/",local_id:"Mistral-7B-Instruct-v0.2-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/OpenHermes-2.5-Mistral-7B-q4f16_1-MLC/resolve/main/",local_id:"OpenHermes-2.5-Mistral-7B-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/NeuralHermes-2.5-Mistral-7B-q4f16_1-MLC/resolve/main/",local_id:"NeuralHermes-2.5-Mistral-7B-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},// TinyLlama
|
144
|
-
{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f16-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f16",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f16-ctx2k-webgpu.wasm",vram_required_MB:5063.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f32-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f32",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f32-ctx2k-webgpu.wasm",vram_required_MB:5394.53,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:899.11,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f32_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:992.11,low_resource_required:!0}],use_web_worker:!0},
|
145
|
-
_inherits(
|
146
|
-
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=
|
147
|
-
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(e,t){var _this19=this;var o,a,l,c,d,u,
|
148
|
-
};}// prettier-ignore
|
149
|
-
|
150
|
-
function
|
151
|
-
|
152
|
-
function
|
153
|
-
},{key:"
|
154
|
-
|
155
|
-
|
156
|
-
function
|
157
|
-
},{key:"callServiceAPI",value:function(){var
|
158
|
-
|
159
|
-
|
160
|
-
},{key:"preprocessBody",value:function preprocessBody(e,t){var _s$options;var s=JSON.parse(JSON.stringify(e)),i=this.processMessages(t);if(i)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:{past_user_inputs:i.past_user_inputs,generated_responses:i.generated_responses,text:i.mostRecentMessageText}},s);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57(e){return _regenerator().w(function(_context57){while(1)switch(_context57.n){case 0:if(!e.error){_context57.n=1;break;}throw e.error;case 1:return _context57.a(2,{text:e.generated_text||""});}},_callee57);}));function extractResultData(_x113){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Ns=/*#__PURE__*/function(_pi3){function Ns(e){var _this28;_classCallCheck(this,Ns);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this28=_callSuper(this,Ns,[e,ke.buildKeyVerificationDetails(),ke.buildHeaders,s,i]),_this28.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this28.textInputPlaceholderText="Describe image changes",_this28.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI: Image to Image</b></div>\n <p>Upload an image to create a new one with the changes you have described.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var n=(o=t.stabilityAI)==null?void 0:o.imageToImage;_typeof(n)=="object"&&(n.engine_id&&(_this28.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/text-to-image")),n.weight!==void 0&&n.weight!==null&&(_this28._imageWeight=n.weight),Ns.cleanConfig(n),Object.assign(_this28.rawBody,n)),_this28.canSendMessage=Ns.canSendFileTextMessage;return _this28;}_inherits(Ns,_pi3);return _createClass(Ns,[{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("init_image",t),s&&s!==""&&i.append("text_prompts[0][text]",s),this._imageWeight!==void 0&&this._imageWeight!==null&&i.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i.get("weight")===void 0&&i.append("weight",String(1)),i;}// prettier-ignore
|
161
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58(e,t,s){var o,a,i,n;return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(this.connectSettings){_context58.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context58.n=2;break;}throw new Error("Image was not found");case 2:i=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim(),n=this.createFormDataBody(this.rawBody,s[0],i);S.tempRemoveContentHeader(this.connectSettings,x.request.bind(this,this,n,e),!1);case 3:return _context58.a(2);}},_callee58,this);}));function callServiceAPI(_x114,_x115,_x116){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e.message){_context59.n=1;break;}throw e.message;case 1:return _context59.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Rt).concat(s.base64),type:"image"};})});}},_callee59);}));function extractResultData(_x117){return _extractResultData8.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(pi);var xa=/*#__PURE__*/function(_Ve6){function xa(e){_classCallCheck(this,xa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,xa,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,s]);}_inherits(xa,_Ve6);return _createClass(xa,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){var t;return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(!e.error){_context60.n=1;break;}throw e.error;case 1:return _context60.a(2,{text:((t=e[0])==null?void 0:t.translation_text)||""});}},_callee60);}));function extractResultData(_x118){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Ps=/*#__PURE__*/function(_pi4){function Ps(e){var _this29;_classCallCheck(this,Ps);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI;_this29=_callSuper(this,Ps,[e,ke.buildKeyVerificationDetails(),ke.buildHeaders,s]),_this29.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this29.textInputPlaceholderText="Describe an image",_this29.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI: Text to Image</b></div>\n <p>Insert text to generate an image.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var i=(n=t.stabilityAI)==null?void 0:n.textToImage;_typeof(i)=="object"&&(i.engine_id&&(_this29.url="https://api.stability.ai/v1/generation/".concat(i.engine_id,"/text-to-image")),i.weight!==void 0&&i.weight!==null&&(_this29._imageWeight=i.weight),Ps.cleanConfig(i),Object.assign(_this29.rawBody,i)),_this29.canSendMessage=Ps.canSendTextMessage;return _this29;}_inherits(Ps,_pi4);return _createClass(Ps,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i={text:t};return this._imageWeight&&(i.weight=this._imageWeight),s.text_prompts=[i],s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e,t){var s;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(this.connectSettings){_context61.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t[t.length-1].text);x.request(this,s,e);case 2:return _context61.a(2);}},_callee61,this);}));function callServiceAPI(_x119,_x120){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e){return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(!e.message){_context62.n=1;break;}throw e.message;case 1:return _context62.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Rt).concat(s.base64),type:"image"};})});}},_callee62);}));function extractResultData(_x121){return _extractResultData0.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendTextMessage",value:function canSendTextMessage(e){return!!(e&&e.trim()!=="");}}]);}(pi);var wa=/*#__PURE__*/function(_Ve7){function wa(e){var _this30;_classCallCheck(this,wa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.fillMask,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this30=_callSuper(this,wa,[e,"The goal of life is [MASK].","bert-base-uncased",t,s]),_this30.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Hugging Face</b></div>\n <p>Insert a sentence with the word [MASK] and the model will try to fill it for you. E.g. I want [MASK].</p>\n <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>",_this30.permittedErrorPrefixes=["Authorization header","No mask_token"];return _this30;}_inherits(wa,_Ve7);return _createClass(wa,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e){var t;return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:if(!e.error){_context63.n=1;break;}throw e.error;case 1:return _context63.a(2,{text:((t=e[0])==null?void 0:t.sequence)||""});}},_callee63);}));function extractResultData(_x122){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(Ve);var Ye=/*#__PURE__*/function(){function Ye(){_classCallCheck(this,Ye);}return _createClass(Ye,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message==="Unauthorized"?i(_.INVALID_KEY):i(_.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://open.bigmodel.cn/api/paas/v4/models",method:"GET",handleVerificationResult:Ye.handleVerificationResult};}}]);}();var Ca=/*#__PURE__*/function(_M3){function Ca(e){var _o$model,_a$voice;var _this31;_classCallCheck(this,Ca);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this31=_callSuper(this,Ca,[e,Ye.buildKeyVerificationDetails(),Ye.buildHeaders,s]),_this31.insertKeyPlaceholderText="BigModel API Key",_this31.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this31.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this31.permittedErrorPrefixes=["Authorization","authentication_error"];var i=(n=t.bigModel)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&(_this31.cleanConfig(i),Object.assign(_this31.rawBody,i)),(_o$model=(o=_this31.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this31.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this31;}_inherits(Ca,_M3);return _createClass(Ca,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e,t){var s;return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:if(this.connectSettings){_context64.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context64.n=2;return x.request(this,s,e);case 2:return _context64.a(2,_context64.v);}},_callee64,this);}));function callServiceAPI(_x123,_x124){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){var t;return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context65.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee65);}));function extractResultData(_x125){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ze=/*#__PURE__*/function(){function Ze(){_classCallCheck(this,Ze);}return _createClass(Ze,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message==="Unauthorized"?i(_.INVALID_KEY):i(_.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.together.xyz/v1/models",method:"GET",handleVerificationResult:Ze.handleVerificationResult};}}]);}();var Ta=/*#__PURE__*/function(_M4){function Ta(e){var _o$model2,_a$voice2;var _this32;_classCallCheck(this,Ta);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this32=_callSuper(this,Ta,[e,Ze.buildKeyVerificationDetails(),Ze.buildHeaders,s]),_this32.insertKeyPlaceholderText="Together AI API Key",_this32.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this32.url="https://api.together.xyz/v1/audio/speech",_this32.permittedErrorPrefixes=["invalid_request_error","authentication_error"];var i=(n=t.together)==null?void 0:n.textToSpeech;_typeof(i)=="object"&&(_this32.cleanConfig(i),Object.assign(_this32.rawBody,i)),(_o$model2=(o=_this32.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this32.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this32;}_inherits(Ta,_M4);return _createClass(Ta,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e,t){var s;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(this.connectSettings){_context66.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context66.n=2;return x.request(this,s,e);case 2:return _context66.a(2,_context66.v);}},_callee66,this);}));function callServiceAPI(_x126,_x127){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e){var t;return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context67.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee67);}));function extractResultData(_x128){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(M);var rs=/*#__PURE__*/function(){function rs(){_classCallCheck(this,rs);}return _createClass(rs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}// prettier-ignore
|
162
|
-
},{key:"
|
163
|
-
},{key:"
|
164
|
-
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(e,t,s,i,n){var c,d,o,a,l,_t23;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:a=s.getFilesPrefix,l=s.getFilesPostfix;_t23=t.length>0;if(!_t23){_context72.n=2;break;}_context72.n=1;return ae.getFiles(e,t,a,l);case 1:o=_context72.v;(c=n==null?void 0:n.text)!=null&&c.value&&o.forEach(function(u,h){var m;if(!u.src)return;var f=t[h].path;(m=n==null?void 0:n.text)!=null&&m.value&&f&&(n.text.value=n.text.value.replace(f,u.src));});case 2:return _context72.a(2,(d=n==null?void 0:n.text)!=null&&d.value?{text:n.text.value,role:i}:{files:o,role:i});}},_callee72);}));function getFilesAndNewText(_x141,_x142,_x143,_x144,_x145){return _getFilesAndNewText.apply(this,arguments);}return getFilesAndNewText;}()// Noticed an issue where text contains a sandbox hyperlink to a csv, but no annotation provided
|
144
|
+
{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f16-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f16",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f16-ctx2k-webgpu.wasm",vram_required_MB:5063.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f32-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f32",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f32-ctx2k-webgpu.wasm",vram_required_MB:5394.53,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:899.11,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f32_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:992.11,low_resource_required:!0}],use_web_worker:!0},N=/*#__PURE__*/function(_Ct2){function N(e){var _this15;_classCallCheck(this,N);var t,s;_this15=_callSuper(this,N,[e]),_this15._isModelLoaded=!1,_this15._isModelLoading=!1,_this15._loadOnFirstMessage=!1,_this15._webModel={},_this15.permittedErrorPrefixes=[N.MULTIPLE_MODELS_ERROR,N.WEB_LLM_NOT_FOUND_ERROR,N.GENERIC_ERROR],_this15._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this15._webModel=e.webModel),(t=_this15._webModel.load)!=null&&t.clearCache&&N.clearAllCache(),_this15.findModelInWindow(e),_this15.canSendMessage=_this15.canSubmit.bind(_assertThisInitialized(_this15)),_this15._chatEl=(s=e.shadowRoot)==null?void 0:s.children[0],e.history&&N.setUpHistory(_this15._conversationHistory,e.history);return _this15;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
|
145
|
+
_inherits(N,_Ct2);return _createClass(N,[{key:"setUpMessages",value:function setUpMessages(e){var _this16=this;this._messages=e,this._removeIntro=function(){e.removeIntroductoryMessage(),_this16._removeIntro=void 0;};}},{key:"findModelInWindow",value:function findModelInWindow(e){var _this17=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var s;window.webLLM?this.configureInit(this.shouldAddIntroMessage(e.introMessage)):t>N.MODULE_SEARCH_LIMIT_S?((s=this._messages)==null||s.addNewErrorMessage(F,N.WEB_LLM_NOT_FOUND_ERROR),console.error("The deep-chat-web-llm module has not been attached to the window object. Please see the following guide:"),console.error("https://deepchat.dev/examples/externalModules")):setTimeout(function(){return _this17.findModelInWindow(e,t+1);},1e3);}},{key:"shouldAddIntroMessage",value:function shouldAddIntroMessage(e){var t;return!e&&this._webModel&&((t=this._webModel.introMessage)==null?void 0:t.displayed)!==!1;}},{key:"scrollToTop",value:function scrollToTop(e){var _this18=this;var t;((t=this._webModel.introMessage)==null?void 0:t.autoScroll)!==!1&&setTimeout(function(){var s,i;(s=_this18._messages)!=null&&s.elementRef&&ae.scrollToTop((i=_this18._messages)==null?void 0:i.elementRef);},e);}// prettier-ignore
|
146
|
+
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Ks.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:b.AI_ROLE,html:t,sendUpdate:!1};}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(e){var t;return _regenerator().w(function(_context34){while(1)switch(_context34.n){case 0:t=this._webModel.load;if(!t){_context34.n=2;break;}if(!t.onInit){_context34.n=1;break;}this.init();return _context34.a(2);case 1:if(!t.onMessage){_context34.n=2;break;}this._loadOnFirstMessage=!0;return _context34.a(2);case 2:e||this.init();case 3:return _context34.a(2);}},_callee34,this);}));function configureInit(_x68){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(e){var s,t,_t15;return _regenerator().w(function(_context35){while(1)switch(_context35.n){case 0:(s=this._messages)==null||s.removeError();t=this.attemptToCreateChat();_t15=t;if(!_t15){_context35.n=1;break;}_context35.n=1;return this.loadModel(t,e);case 1:return _context35.a(2);}},_callee35,this);}));function init(_x69){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var t;if(N.chat){(t=this._messages)==null||t.addNewErrorMessage(F,N.MULTIPLE_MODELS_ERROR),console.error(N.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return Hn.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var s;var e=N.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=JSON.parse(JSON.stringify(Hn));if(this._webModel.urls){var i=t.model_list.find(function(n){return n.local_id=e;});i&&(this._webModel.urls.model&&(i.model_url=this._webModel.urls.model),this._webModel.urls.wasm&&(i.model_lib_url=this._webModel.urls.wasm));}return(s=this._webModel.load)!=null&&s.skipCache&&(t.use_cache=!1),{model:e,appConfig:t};}// prettier-ignore
|
147
|
+
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(e,t){var _this19=this;var o,a,l,c,d,h,u,s,i,n,_this$getConfig,f,m,p,_f,_t16;return _regenerator().w(function(_context36){while(1)switch(_context36.p=_context36.n){case 0:this.scrollToTop(),N.chat=e,this._isModelLoading=!0;s=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;i=function i(f){var m;(m=_this19._messages)==null||m.addNewMessage({html:"<div>".concat(f.text,"</div>"),overwrite:!0,sendUpdate:!1}),s&&(setTimeout(function(){var p;return ae.scrollToBottom((p=_this19._messages)==null?void 0:p.elementRef);}),s=!1);};N.chat.setInitProgressCallback(i);_context36.p=1;_this$getConfig=this.getConfig(),f=_this$getConfig.model,m=_this$getConfig.appConfig,p={};this._webModel.instruction&&(p.conv_config={system:this._webModel.instruction});this._conversationHistory.length>0&&(p.conversation_history=this._conversationHistory);_context36.n=2;return N.chat.reload(f,p,m,t);case 2:n=_context36.v;_context36.n=4;break;case 3:_context36.p=3;_t16=_context36.v;return _context36.a(2,this.unloadChat(_t16));case 4:if((l=(a=this.deepChat)._validationHandler)==null||l.call(a),(c=this._webModel.introMessage)!=null&&c.removeAfterLoad)this._webModel.introMessage.displayed===!1?(h=this._messages)==null||h.removeLastMessage():(u=this._removeIntro)==null||u.call(this);else{_f=Ks.setUpAfterLoad(n,this._webModel.introMessage,this._chatEl,!!this._webModel.worker);(d=this._messages)==null||d.addNewMessage({html:_f,overwrite:!0,sendUpdate:!1});}this._isModelLoaded=!0,this._isModelLoading=!1;case 5:return _context36.a(2);}},_callee36,this,[[1,3]]);}));function loadModel(_x70,_x71){return _loadModel.apply(this,arguments);}return loadModel;}()},{key:"unloadChat",value:function(){var _unloadChat=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e){var t,_t17;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:(t=this._messages)==null||t.addNewErrorMessage(F,N.GENERIC_ERROR);console.error(e);this._isModelLoaded=!1;this._isModelLoading=!1;_t17=N.chat;if(!_t17){_context37.n=2;break;}_context37.n=1;return N.chat.unload();case 1:N.chat=void 0;case 2:return _context37.a(2);}},_callee37,this);}));function unloadChat(_x72){return _unloadChat.apply(this,arguments);}return unloadChat;}()},{key:"immediateResp",value:function(){var _immediateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(e,t,s){var i,n,_t18,_t19,_t20;return _regenerator().w(function(_context38){while(1)switch(_context38.n){case 0:_t18=_defineProperty;_t19={};_t20=g;_context38.n=1;return s.generate(t,void 0,0);case 1:i=_t18(_t19,_t20,_context38.v);_context38.n=2;return N.processResponse(this.deepChat,e,i);case 2:n=_context38.v;n&&n.forEach(function(o){return e.addNewMessage(o);}),this.completionsHandlers.onFinish();case 3:return _context38.a(2);}},_callee38,this);}));function immediateResp(_x73,_x74,_x75){return _immediateResp.apply(this,arguments);}return immediateResp;}()},{key:"streamResp",value:function(){var _streamResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(e,t,s){var _this20=this;var i;return _regenerator().w(function(_context40){while(1)switch(_context40.n){case 0:this.streamHandlers.onAbort=function(){s.interruptGenerate();},this.streamHandlers.onOpen();i=new Fe(e);_context40.n=1;return s.generate(t,/*#__PURE__*/function(){var _ref23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(n,o){var a;return _regenerator().w(function(_context39){while(1)switch(_context39.n){case 0:_context39.n=1;return N.processResponse(_this20.deepChat,e,_defineProperty({},g,o));case 1:a=_context39.v;a&&i.upsertStreamedMessage(_defineProperty(_defineProperty({},g,a[0].text),"overwrite",!0));case 2:return _context39.a(2);}},_callee39);}));return function(_x79,_x80){return _ref23.apply(this,arguments);};}());case 1:i.finaliseStreamedMessage();this.streamHandlers.onClose();case 2:return _context40.a(2);}},_callee40,this);}));function streamResp(_x76,_x77,_x78){return _streamResp.apply(this,arguments);}return streamResp;}()},{key:"generateRespByType",value:function(){var _generateRespByType=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(e,t,s,i){var n,_t21;return _regenerator().w(function(_context41){while(1)switch(_context41.p=_context41.n){case 0:_context41.p=0;if(!s){_context41.n=2;break;}_context41.n=1;return this.streamResp(e,t,i);case 1:_context41.n=3;break;case 2:_context41.n=3;return this.immediateResp(e,t,i);case 3:_context41.n=5;break;case 4:_context41.p=4;_t21=_context41.v;(n=this._messages)==null||n.addNewErrorMessage(F),console.log(_t21);case 5:return _context41.a(2);}},_callee41,this,[[0,4]]);}));function generateRespByType(_x81,_x82,_x83,_x84){return _generateRespByType.apply(this,arguments);}return generateRespByType;}()},{key:"generateResp",value:function(){var _generateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(e,t,s){var i,_yield$M$processReque5,n,o,a,l,c;return _regenerator().w(function(_context42){while(1)switch(_context42.n){case 0:i=t[t.length-1].text;_context42.n=1;return M.processRequestInterceptor(this.deepChat,{body:_defineProperty({},g,i)});case 1:_yield$M$processReque5=_context42.v;n=_yield$M$processReque5.body;o=_yield$M$processReque5.error;a=!!this.stream;try{if(o)M.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!n||!n.text){l=E.INVALID_MODEL_REQUEST({body:n},!1);console.error(l);c=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;M.onInterceptorError(e,l,c);}else this.generateRespByType(e,n.text,!!this.stream,s);}catch(l){this.unloadChat(l);}case 2:return _context42.a(2);}},_callee42,this);}));function generateResp(_x85,_x86,_x87){return _generateResp.apply(this,arguments);}return generateResp;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43(e,t){var s,i;return _regenerator().w(function(_context43){while(1)switch(_context43.n){case 0:if(this._isModelLoaded){_context43.n=3;break;}if(!this._loadOnFirstMessage){_context43.n=2;break;}_context43.n=1;return this.init();case 1:_context43.n=3;break;case 2:return _context43.a(2);case 3:!N.chat||this._isModelLoading||((s=this._webModel.introMessage)!=null&&s.removeAfterMessage&&((i=this._removeIntro)==null||i.call(this)),e.addLoadingMessage(),this.generateResp(e,t,N.chat));case 4:return _context43.a(2);}},_callee43,this);}));function callServiceAPI(_x88,_x89){return _callServiceAPI2.apply(this,arguments);}return callServiceAPI;}()},{key:"canSubmit",value:function canSubmit(e){return!(e!=null&&e.trim())||this._isModelLoading?!1:this._loadOnFirstMessage?!0:!!this._isModelLoaded;}},{key:"isWebModel",value:function isWebModel(){return!0;}}],[{key:"setUpHistory",value:function setUpHistory(e,t){t.forEach(function(s,i){if(s.role===b.USER_ROLE&&s.text){var n=t[i+1];n!=null&&n.text&&n.role!==b.USER_ROLE&&e.push([s.text,n.text]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44(e,t,s){var a,l,i,n,o,d,_t22;return _regenerator().w(function(_context44){while(1)switch(_context44.n){case 0:_context44.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,s);case 1:_t22=_context44.v;if(_t22){_context44.n=2;break;}_t22=s;case 2:i=_t22;if(!((l=e.connect)!=null&&l.stream&&Array.isArray(i)&&i.length>1)){_context44.n=3;break;}console.error(E.INVALID_STREAM_ARRAY_RESPONSE);return _context44.a(2);case 3:n=Array.isArray(i)?i:[i],o=n.find(function(c){return typeof c.error=="string";});if(!o){_context44.n=4;break;}M.displayError(t,new Error(o.error));return _context44.a(2);case 4:if(!n.find(function(d){return!d||!d.text;})){_context44.n=5;break;}d=E.INVALID_MODEL_RESPONSE(s,!!e.responseInterceptor,i);M.displayError(t,new Error(d));return _context44.a(2);case 5:return _context44.a(2,n);}},_callee44);}));function processResponse(_x90,_x91,_x92){return _processResponse.apply(this,arguments);}return processResponse;}()},{key:"clearAllCache",value:function clearAllCache(){N.clearCache("webllm/model"),N.clearCache("webllm/wasm");}},{key:"clearCache",value:function clearCache(e){caches.open(e).then(function(t){t.keys().then(function(s){s.forEach(function(i){t["delete"](i);});});});}}]);}(Ct);N.GENERIC_ERROR="Error, please check the [troubleshooting](https://deepchat.dev/docs/webModel#troubleshooting) section of documentation for help.",N.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",N.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",N.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",N.MODULE_SEARCH_LIMIT_S=5;var Cs=N;var zs=/*#__PURE__*/function(){function zs(){_classCallCheck(this,zs);}return _createClass(zs,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}// prettier-ignore
|
148
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;Array.isArray(n.error)&&n.error[0]==="Error in `parameters`: field required"?s(t):i(E.INVALID_KEY);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api-inference.huggingface.co/models/gpt2",method:Y,handleVerificationResult:zs.handleVerificationResult};}}]);}();var gs=/*#__PURE__*/function(_L){// prettier-ignore
|
149
|
+
function gs(e,t,s,i,n,o){var _this21;_classCallCheck(this,gs);_this21=_callSuper(this,gs,[e,zs.buildKeyVerificationDetails(),zs.buildHeaders,n,o]),_this21.insertKeyPlaceholderText="Hugging Face Token",_this21.keyHelpUrl="https://huggingface.co/settings/tokens",_this21.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Hugging Face</b></div>\n <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>",_this21.permittedErrorPrefixes=[an],_this21.url="".concat(gs.URL_PREFIX).concat(s),_this21.textInputPlaceholderText=t,_typeof(i)=="object"&&(i.model&&(_this21.url="".concat(gs.URL_PREFIX).concat(i.model)),i.options&&(_this21.rawBody.options=i.options),i.parameters&&(_this21.rawBody.parameters=i.parameters));return _this21;}// prettier-ignore
|
150
|
+
_inherits(gs,_L);return _createClass(gs,[{key:"preprocessBody",value:function preprocessBody(e,t,s){var _i$options;var i=JSON.parse(JSON.stringify(e)),n=t[t.length-1].text;if(n)return(_i$options=i.options)!==null&&_i$options!==void 0?_i$options:i.options={},i.options.wait_for_model=!0,_objectSpread({inputs:n},i);}},{key:"callServiceAPI",value:function(){var _callServiceAPI3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45(e,t,s){var i;return _regenerator().w(function(_context45){while(1)switch(_context45.n){case 0:if(this.connectSettings){_context45.n=1;break;}throw new Error("Request settings have not been set up");case 1:i=this.preprocessBody(this.rawBody,t,s);w.request(this,i,e);case 2:return _context45.a(2);}},_callee45,this);}));function callServiceAPI(_x93,_x94,_x95){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(L);gs.URL_PREFIX="https://api-inference.huggingface.co/models/";var et=gs;var Ls=/*#__PURE__*/function(_et){// prettier-ignore
|
151
|
+
function Ls(e,t,s,i,n,o){var _this22;_classCallCheck(this,Ls);_this22=_callSuper(this,Ls,[e,t,s,i,n,o]),_this22.isTextInputDisabled=!0,_this22.canSendMessage=Ls.canSendFile;return _this22;}_inherits(Ls,_et);return _createClass(Ls,[{key:"preprocessBody",value:function preprocessBody(e,t,s){return s[0];}// prettier-ignore
|
152
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46(e,t,s){return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:if(this.connectSettings){_context46.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context46.n=2;break;}throw new Error("No file was added");case 2:w.poll(this,s[0],e,!1);case 3:return _context46.a(2);}},_callee46,this);}));function callServiceAPI(_x96,_x97,_x98){return _callServiceAPI4.apply(this,arguments);}return callServiceAPI;}()}],[{key:"canSendFile",value:function canSendFile(e,t){return!!(t!=null&&t[0]);}}]);}(et);var Ba=/*#__PURE__*/function(_Ls){// prettier-ignore
|
153
|
+
function Ba(e){_classCallCheck(this,Ba);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.audioClassification,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ba,[e,"Attach an audio file","ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,s,{audio:{}}]);}_inherits(Ba,_Ls);return _createClass(Ba,[{key:"extractPollResultData",value:function(){var _extractPollResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e){var t;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:if(!e.estimated_time){_context47.n=1;break;}return _context47.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context47.n=2;break;}throw e.error;case 2:return _context47.a(2,_defineProperty({},g,((t=e[0])==null?void 0:t.label)||""));}},_callee47);}));function extractPollResultData(_x99){return _extractPollResultData.apply(this,arguments);}return extractPollResultData;}()}]);}(Ls);var Fa=/*#__PURE__*/function(_Ls2){function Fa(e){_classCallCheck(this,Fa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.imageClassification,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Fa,[e,"Attach an image file","google/vit-base-patch16-224",t,s,{images:{}}]);}_inherits(Fa,_Ls2);return _createClass(Fa,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48(e){var t;return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:if(!e.estimated_time){_context48.n=1;break;}return _context48.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context48.n=2;break;}throw e.error;case 2:return _context48.a(2,_defineProperty({},g,((t=e[0])==null?void 0:t.label)||""));}},_callee48);}));function extractPollResultData(_x100){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(Ls);var Ht="data:image/png;base64,";var qe=/*#__PURE__*/function(){function qe(){_classCallCheck(this,qe);}return _createClass(qe,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}// prettier-ignore
|
154
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.message?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.stability.ai/v1/engines/list",method:z,handleVerificationResult:qe.handleVerificationResult};}}]);}();var Ri=/*#__PURE__*/function(_L2){// prettier-ignore
|
155
|
+
function Ri(e,t,s,i,n){var _this23;_classCallCheck(this,Ri);_this23=_callSuper(this,Ri,[e,t,s,i,n]),_this23.insertKeyPlaceholderText=_this23.genereteAPIKeyName("Stability AI"),_this23.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this23.permittedErrorPrefixes=[Is,"invalid_"];return _this23;}_inherits(Ri,_L2);return _createClass(Ri);}(L);var Gs=/*#__PURE__*/function(_Ri){function Gs(e){var _this24;_classCallCheck(this,Gs);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this24=_callSuper(this,Gs,[e,qe.buildKeyVerificationDetails(),qe.buildHeaders,s,i]),_this24.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",_this24.textInputPlaceholderText="Describe image changes",_this24.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI</b></div>\n <div style=\"width: 100%; text-align: center; margin-left: -10px; margin-top: 5px\"><b>Image to Image Upscale</b></div>\n <p>Upload an image to generate a new one with higher resolution.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var n=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageUpscale;_typeof(n)=="object"&&(n.engine_id&&(_this24.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/image-to-image/upscale")),Gs.cleanConfig(n),Object.assign(_this24.rawBody,n)),_this24.canSendMessage=Gs.canSendFileMessage;return _this24;}_inherits(Gs,_Ri);return _createClass(Gs,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var s=new FormData();return s.append("image",t),Object.keys(e).forEach(function(i){s.append(i,String(e[i]));}),s;}// prettier-ignore
|
156
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49(e,t,s){var i;return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(this.connectSettings){_context49.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context49.n=2;break;}throw new Error("Image was not found");case 2:i=this.createFormDataBody(this.rawBody,s[0]);M.tempRemoveContentHeader(this.connectSettings,w.request.bind(this,this,i,e),!1);case 3:return _context49.a(2);}},_callee49,this);}));function callServiceAPI(_x101,_x102,_x103){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(e){return _regenerator().w(function(_context50){while(1)switch(_context50.n){case 0:if(!e.message){_context50.n=1;break;}throw e.message;case 1:return _context50.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Ht).concat(s.base64),type:"image"};})});}},_callee50);}));function extractResultData(_x104){return _extractResultData2.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id;}},{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}}]);}(Ri);var Js=/*#__PURE__*/function(_Ri2){function Js(e){var _this25;_classCallCheck(this,Js);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};_this25=_callSuper(this,Js,[e,qe.buildKeyVerificationDetails(),qe.buildHeaders,s,i]),_this25.url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",_this25._maskSource="MASK_IMAGE_WHITE",_this25.textInputPlaceholderText="Describe image changes",_this25.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI</b></div>\n <div style=\"width: 100%; text-align: center; margin-left: -10px; margin-top: 5px\"><b>Image to Image Masking</b></div>\n <p>Upload an image, its mask image to create a new one based on the changes you have described for the mask area.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var n=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageMasking;_typeof(n)=="object"&&(n.engine_id&&(_this25.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/image-to-image/masking")),n.weight!==void 0&&n.weight!==null&&(_this25._imageWeight=n.weight),n.mask_source!==void 0&&n.mask_source!==null&&(_this25._maskSource=n.mask_source),Js.cleanConfig(n),Object.assign(_this25.rawBody,n)),_this25.canSendMessage=Js.canSendFileTextMessage;return _this25;}_inherits(Js,_Ri2);return _createClass(Js,[{key:"createFormDataBody",value:function createFormDataBody(e,t,s,i){var n=new FormData();return n.append("init_image",t),n.append("mask_source",String(this._maskSource)),n.append("mask_image",s),i&&i!==""&&n.append("text_prompts[0][text]",i),this._imageWeight!==void 0&&this._imageWeight!==null&&n.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(o){n.append(o,String(e[o]));}),n.get("weight")===void 0&&n.append("weight",String(1)),n;}// prettier-ignore
|
157
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e,t,s){var o,a,i,n;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(this.connectSettings){_context51.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!(!s||!s[0]||!s[1])){_context51.n=2;break;}throw new Error("Image was not found");case 2:i=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim(),n=this.createFormDataBody(this.rawBody,s[0],s[1],i);M.tempRemoveContentHeader(this.connectSettings,w.request.bind(this,this,n,e),!1);case 3:return _context51.a(2);}},_callee51,this);}));function callServiceAPI(_x105,_x106,_x107){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e){return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(!e.message){_context52.n=1;break;}throw e.message;case 1:return _context52.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Ht).concat(s.base64),type:"image"};})});}},_callee52);}));function extractResultData(_x108){return _extractResultData3.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(Ri);var Ua=/*#__PURE__*/function(_Ls3){function Ua(e){_classCallCheck(this,Ua);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.audioSpeechRecognition,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ua,[e,"Attach an audio file","facebook/wav2vec2-large-960h-lv60-self",t,s,{audio:{}}]);}_inherits(Ua,_Ls3);return _createClass(Ua,[{key:"extractPollResultData",value:function(){var _extractPollResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e){return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(!e.estimated_time){_context53.n=1;break;}return _context53.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context53.n=2;break;}throw e.error;case 2:return _context53.a(2,_defineProperty({},g,e.text||""));}},_callee53);}));function extractPollResultData(_x109){return _extractPollResultData3.apply(this,arguments);}return extractPollResultData;}()}]);}(Ls);var Ha=/*#__PURE__*/function(_et2){function Ha(e){_classCallCheck(this,Ha);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.textGeneration,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ha,[e,"Once upon a time","gpt2",t,s]);}_inherits(Ha,_et2);return _createClass(Ha,[{key:"extractResultData",value:function(){var _extractResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54(e){var t;return _regenerator().w(function(_context54){while(1)switch(_context54.n){case 0:if(!e.error){_context54.n=1;break;}throw e.error;case 1:return _context54.a(2,_defineProperty({},g,((t=e[0])==null?void 0:t.generated_text)||""));}},_callee54);}));function extractResultData(_x110){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(et);var qa=/*#__PURE__*/function(_et3){function qa(e){var _this26;_classCallCheck(this,qa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.questionAnswer,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this26=_callSuper(this,qa,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,s]),_this26.permittedErrorPrefixes=[an,"Error in"],_this26._context=t.context;return _this26;}_inherits(qa,_et3);return _createClass(qa,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return{inputs:{question:s,context:this._context,options:{wait_for_model:!0}}};}},{key:"extractResultData",value:function(){var _extractResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(e){return _regenerator().w(function(_context55){while(1)switch(_context55.n){case 0:if(!e.error){_context55.n=1;break;}throw e.error;case 1:return _context55.a(2,_defineProperty({},g,e.answer||""));}},_callee55);}));function extractResultData(_x111){return _extractResultData5.apply(this,arguments);}return extractResultData;}()}]);}(et);var ja=/*#__PURE__*/function(_et4){function ja(e){_classCallCheck(this,ja);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.summarization,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,ja,[e,"Insert text to summarize","facebook/bart-large-cnn",t,s]);}_inherits(ja,_et4);return _createClass(ja,[{key:"extractResultData",value:function(){var _extractResultData6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56(e){var t;return _regenerator().w(function(_context56){while(1)switch(_context56.n){case 0:if(!e.error){_context56.n=1;break;}throw e.error;case 1:return _context56.a(2,_defineProperty({},g,((t=e[0])==null?void 0:t.summary_text)||""));}},_callee56);}));function extractResultData(_x112){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(et);var Va=/*#__PURE__*/function(_et5){function Va(e){var _this27$maxMessages;var _this27;_classCallCheck(this,Va);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.conversation,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this27=_callSuper(this,Va,[e,"Ask me anything!","facebook/blenderbot-400M-distill",t,s]),(_this27$maxMessages=_this27.maxMessages)!==null&&_this27$maxMessages!==void 0?_this27$maxMessages:_this27.maxMessages=-1;return _this27;}// prettier-ignore
|
158
|
+
_inherits(Va,_et5);return _createClass(Va,[{key:"processMessages",value:function processMessages(e){var t=e.filter(function(a){return a.text;}),s=t[t.length-1].text,i=t.slice(0,t.length-1);if(!s)return;var n=i.filter(function(a){return a.role==="user";}).map(function(a){return a.text;}),o=i.filter(function(a){return a.role==="ai";}).map(function(a){return a.text;});return{past_user_inputs:n,generated_responses:o,mostRecentMessageText:s};}// prettier-ignore
|
159
|
+
},{key:"preprocessBody",value:function preprocessBody(e,t){var _s$options;var s=JSON.parse(JSON.stringify(e)),i=this.processMessages(t);if(i)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:_defineProperty({past_user_inputs:i.past_user_inputs,generated_responses:i.generated_responses},g,i.mostRecentMessageText)},s);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57(e){return _regenerator().w(function(_context57){while(1)switch(_context57.n){case 0:if(!e.error){_context57.n=1;break;}throw e.error;case 1:return _context57.a(2,_defineProperty({},g,e.generated_text||""));}},_callee57);}));function extractResultData(_x113){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(et);var $s=/*#__PURE__*/function(_Ri3){function $s(e){var _this28;_classCallCheck(this,$s);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this28=_callSuper(this,$s,[e,qe.buildKeyVerificationDetails(),qe.buildHeaders,s,i]),_this28.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this28.textInputPlaceholderText="Describe image changes",_this28.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI: Image to Image</b></div>\n <p>Upload an image to create a new one with the changes you have described.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var n=(o=t.stabilityAI)==null?void 0:o.imageToImage;_typeof(n)=="object"&&(n.engine_id&&(_this28.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/text-to-image")),n.weight!==void 0&&n.weight!==null&&(_this28._imageWeight=n.weight),$s.cleanConfig(n),Object.assign(_this28.rawBody,n)),_this28.canSendMessage=$s.canSendFileTextMessage;return _this28;}_inherits($s,_Ri3);return _createClass($s,[{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("init_image",t),s&&s!==""&&i.append("text_prompts[0][text]",s),this._imageWeight!==void 0&&this._imageWeight!==null&&i.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i.get("weight")===void 0&&i.append("weight",String(1)),i;}// prettier-ignore
|
160
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58(e,t,s){var o,a,i,n;return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(this.connectSettings){_context58.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s){_context58.n=2;break;}throw new Error("Image was not found");case 2:i=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim(),n=this.createFormDataBody(this.rawBody,s[0],i);M.tempRemoveContentHeader(this.connectSettings,w.request.bind(this,this,n,e),!1);case 3:return _context58.a(2);}},_callee58,this);}));function callServiceAPI(_x114,_x115,_x116){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e.message){_context59.n=1;break;}throw e.message;case 1:return _context59.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Ht).concat(s.base64),type:"image"};})});}},_callee59);}));function extractResultData(_x117){return _extractResultData8.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(Ri);var Ka=/*#__PURE__*/function(_et6){function Ka(e){_classCallCheck(this,Ka);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ka,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,s]);}_inherits(Ka,_et6);return _createClass(Ka,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){var t;return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(!e.error){_context60.n=1;break;}throw e.error;case 1:return _context60.a(2,_defineProperty({},g,((t=e[0])==null?void 0:t.translation_text)||""));}},_callee60);}));function extractResultData(_x118){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(et);var Ws=/*#__PURE__*/function(_Ri4){function Ws(e){var _this29;_classCallCheck(this,Ws);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI;_this29=_callSuper(this,Ws,[e,qe.buildKeyVerificationDetails(),qe.buildHeaders,s]),_this29.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this29.textInputPlaceholderText="Describe an image",_this29.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI: Text to Image</b></div>\n <p>Insert text to generate an image.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var i=(n=t.stabilityAI)==null?void 0:n.textToImage;_typeof(i)=="object"&&(i.engine_id&&(_this29.url="https://api.stability.ai/v1/generation/".concat(i.engine_id,"/text-to-image")),i.weight!==void 0&&i.weight!==null&&(_this29._imageWeight=i.weight),Ws.cleanConfig(i),Object.assign(_this29.rawBody,i)),_this29.canSendMessage=Ws.canSendTextMessage;return _this29;}_inherits(Ws,_Ri4);return _createClass(Ws,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=_defineProperty({},g,t);return this._imageWeight&&(i.weight=this._imageWeight),s.text_prompts=[i],s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e,t){var s;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(this.connectSettings){_context61.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t[t.length-1].text);w.request(this,s,e);case 2:return _context61.a(2);}},_callee61,this);}));function callServiceAPI(_x119,_x120){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e){return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(!e.message){_context62.n=1;break;}throw e.message;case 1:return _context62.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(Ht).concat(s.base64),type:"image"};})});}},_callee62);}));function extractResultData(_x121){return _extractResultData0.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendTextMessage",value:function canSendTextMessage(e){return!!(e&&e.trim()!=="");}}]);}(Ri);var za=/*#__PURE__*/function(_et7){function za(e){var _this30;_classCallCheck(this,za);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.fillMask,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this30=_callSuper(this,za,[e,"The goal of life is [MASK].","bert-base-uncased",t,s]),_this30.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Hugging Face</b></div>\n <p>Insert a sentence with the word [MASK] and the model will try to fill it for you. E.g. I want [MASK].</p>\n <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>",_this30.permittedErrorPrefixes=[an,"No mask_token"];return _this30;}_inherits(za,_et7);return _createClass(za,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e){var t;return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:if(!e.error){_context63.n=1;break;}throw e.error;case 1:return _context63.a(2,_defineProperty({},g,((t=e[0])==null?void 0:t.sequence)||""));}},_callee63);}));function extractResultData(_x122){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(et);var ct=/*#__PURE__*/function(){function ct(){_classCallCheck(this,ct);}return _createClass(ct,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},k,P),K,"".concat(ee).concat(e));}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message===on?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://open.bigmodel.cn/api/paas/v4/models",method:z,handleVerificationResult:ct.handleVerificationResult};}}]);}();var Ga=/*#__PURE__*/function(_L3){function Ga(e){var _o$model,_a$voice;var _this31;_classCallCheck(this,Ga);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this31=_callSuper(this,Ga,[e,ct.buildKeyVerificationDetails(),ct.buildHeaders,s]),_this31.insertKeyPlaceholderText=_this31.genereteAPIKeyName("BigModel"),_this31.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this31.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this31.permittedErrorPrefixes=[K,te];var i=(n=t.bigModel)==null?void 0:n.textToSpeech;_typeof(i)===S&&(_this31.cleanConfig(i),Object.assign(_this31.rawBody,i)),(_o$model=(o=_this31.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this31.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this31;}_inherits(Ga,_L3);return _createClass(Ga,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e,t){var s;return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:if(this.connectSettings){_context64.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context64.n=2;return w.request(this,s,e);case 2:return _context64.a(2,_context64.v);}},_callee64,this);}));function callServiceAPI(_x123,_x124){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){var t;return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context65.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee65);}));function extractResultData(_x125){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(L);var dt=/*#__PURE__*/function(){function dt(){_classCallCheck(this,dt);}return _createClass(dt,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},k,P),K,"".concat(ee).concat(e));}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message===on?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.together.xyz/v1/models",method:z,handleVerificationResult:dt.handleVerificationResult};}}]);}();var Ja=/*#__PURE__*/function(_L4){function Ja(e){var _o$model2,_a$voice2;var _this32;_classCallCheck(this,Ja);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this32=_callSuper(this,Ja,[e,dt.buildKeyVerificationDetails(),dt.buildHeaders,s]),_this32.insertKeyPlaceholderText=_this32.genereteAPIKeyName("Together AI"),_this32.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this32.url="https://api.together.xyz/v1/audio/speech",_this32.permittedErrorPrefixes=[Ae,te];var i=(n=t.together)==null?void 0:n.textToSpeech;_typeof(i)===S&&(_this32.cleanConfig(i),Object.assign(_this32.rawBody,i)),(_o$model2=(o=_this32.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this32.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this32;}_inherits(Ja,_L4);return _createClass(Ja,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e,t){var s;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(this.connectSettings){_context66.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context66.n=2;return w.request(this,s,e);case 2:return _context66.a(2,_context66.v);}},_callee66,this);}));function callServiceAPI(_x126,_x127){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e){var t;return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context67.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee67);}));function extractResultData(_x128){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(L);var ys=/*#__PURE__*/function(){function ys(){_classCallCheck(this,ys);}return _createClass(ys,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}// prettier-ignore
|
161
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.openai.com/v1/models",method:z,handleVerificationResult:ys.handleVerificationResult};}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
162
|
+
},{key:"directFetch",value:function(){var _directFetch=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e,t,s){var i,n,_args68=arguments;return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:i=_args68.length>3&&_args68[3]!==undefined?_args68[3]:!0;e.connectSettings.method=s;_context68.n=1;return M.fetch(e,e.connectSettings.headers,i,t).then(function(o){return M.processResponseByType(o);});case 1:n=_context68.v;if(!n.error){_context68.n=2;break;}throw n.error.message;case 2:return _context68.a(2,n);}},_callee68);}));function directFetch(_x129,_x130,_x131){return _directFetch.apply(this,arguments);}return directFetch;}()}]);}();ys.FUNCTION_TOOL_RESP_ERROR="Response object must either be {response: string}[] for each individual function or {text: string} for a direct response, see https://deepchat.dev/docs/directConnection/OpenAI#FunctionHandler.",ys.FUNCTION_TOOL_RESP_ARR_ERROR="Arrays are not accepted in handler responses";var V=ys;var ye=/*#__PURE__*/function(){function ye(){_classCallCheck(this,ye);}return _createClass(ye,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(e,t,s,i){var n,o,a,l,_t23;return _regenerator().w(function(_context70){while(1)switch(_context70.p=_context70.n){case 0:n=e.connectSettings.headers;if(n){_context70.n=1;break;}return _context70.a(2);case 1:e.url=i;o=n[k];delete n[k];a=s.map(/*#__PURE__*/function(){var _ref38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee69(l){var c;return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:c=new FormData();return _context69.a(2,(c.append("purpose","assistants"),c.append("file",l),new Promise(function(d){d(V.directFetch(e,c,Y,!1));})));}},_callee69);}));return function(_x136){return _ref38.apply(this,arguments);};}());_context70.p=2;_context70.n=3;return Promise.all(a);case 3:l=_context70.v.map(function(c){return{id:c.id,name:c.filename};});return _context70.a(2,(n[k]=o,l));case 4:_context70.p=4;_t23=_context70.v;throw n[k]=o,M.displayError(t,_t23),e.completionsHandlers.onFinish(),_t23;case 5:return _context70.a(2);}},_callee70,null,[[2,4]]);}));function storeFiles(_x132,_x133,_x134,_x135){return _storeFiles.apply(this,arguments);}return storeFiles;}()},{key:"getType",value:function getType(e,t){var s=e[t].path;return!s||s.endsWith("png")?"image":"any";}},{key:"getFiles",value:function(){var _getFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(e,t,s,i){var n,a;return _regenerator().w(function(_context71){while(1)switch(_context71.n){case 0:n=t.map(function(_ref39){var l=_ref39.fileId;return e.url="".concat(s).concat(l).concat(i),new Promise(function(c){c(V.directFetch(e,void 0,"GET",!1));});});_context71.n=1;return Promise.all(n);case 1:a=_context71.v.map(function(l,c){return new Promise(function(d){var h=new FileReader();h.readAsDataURL(l),h.onload=function(u){d({src:u.target.result,name:t[c].name,type:ye.getType(t,c)});};});});_context71.n=2;return Promise.all(a);case 2:return _context71.a(2,_context71.v);}},_callee71);}));function getFiles(_x137,_x138,_x139,_x140){return _getFiles.apply(this,arguments);}return getFiles;}()},{key:"getFileName",value:function getFileName(e){var t=e.split("/");return t[t.length-1];}// prettier-ignore
|
163
|
+
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(e,t,s,i,n){var c,d,o,a,l,_t24;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:a=s.getFilesPrefix,l=s.getFilesPostfix;_t24=t.length>0;if(!_t24){_context72.n=2;break;}_context72.n=1;return ye.getFiles(e,t,a,l);case 1:o=_context72.v;(c=n==null?void 0:n.text)!=null&&c.value&&o.forEach(function(h,u){var m;if(!h.src)return;var f=t[u].path;(m=n==null?void 0:n.text)!=null&&m.value&&f&&(n.text.value=n.text.value.replace(f,h.src));});case 2:return _context72.a(2,(d=n==null?void 0:n.text)!=null&&d.value?_defineProperty(_defineProperty({},g,n.text.value),"role",i):{files:o,role:i});}},_callee72);}));function getFilesAndNewText(_x141,_x142,_x143,_x144,_x145){return _getFilesAndNewText.apply(this,arguments);}return getFilesAndNewText;}()// Noticed an issue where text contains a sandbox hyperlink to a csv, but no annotation provided
|
165
164
|
// To reproduce use the following text:
|
166
165
|
// give example data for a csv and create a suitable bar chart for it with a link
|
167
166
|
// Don't think it can be fixed and it is something on OpenAI side of things
|
168
167
|
// prettier-ignore
|
169
|
-
},{key:"getFileDetails",value:function getFileDetails(e,t){var i;var s=[];return(i=t==null?void 0:t.text)!=null&&i.value&&e.content.forEach(function(n){var o,a;(a=(o=n.text)==null?void 0:o.annotations)==null||a.forEach(function(l){var c;l.text&&l.text.startsWith("sandbox:")&&(c=l.file_path)!=null&&c.file_id&&s.push({path:l.text,fileId:l.file_path.file_id,name:
|
170
|
-
},{key:"getFilesAndText",value:function(){var _getFilesAndText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73(e,t,s,i){var n;return _regenerator().w(function(_context73){while(1)switch(_context73.n){case 0:n=
|
168
|
+
},{key:"getFileDetails",value:function getFileDetails(e,t){var i;var s=[];return(i=t==null?void 0:t.text)!=null&&i.value&&e.content.forEach(function(n){var o,a;(a=(o=n.text)==null?void 0:o.annotations)==null||a.forEach(function(l){var c;l.text&&l.text.startsWith("sandbox:")&&(c=l.file_path)!=null&&c.file_id&&s.push({path:l.text,fileId:l.file_path.file_id,name:ye.getFileName(l.text)});});}),t!=null&&t.image_file&&s.push({fileId:t.image_file.file_id}),s;}// prettier-ignore
|
169
|
+
},{key:"getFilesAndText",value:function(){var _getFilesAndText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73(e,t,s,i){var n;return _regenerator().w(function(_context73){while(1)switch(_context73.n){case 0:n=ye.getFileDetails(t,i);_context73.n=1;return ye.getFilesAndNewText(e,n,s,t.role,i);case 1:return _context73.a(2,_context73.v);}},_callee73);}));function getFilesAndText(_x146,_x147,_x148,_x149){return _getFilesAndText.apply(this,arguments);}return getFilesAndText;}()},{key:"parseResult",value:function parseResult(e,t){var s=[];if(t)s=e.data;else for(var i=0;i<e.data.length;i+=1){var n=e.data[i];if(n.role==="assistant")s.push(n);else break;}return s.reverse();}// test this using this prompt and it should give 2 text mesages and a file:
|
171
170
|
// "give example data for a csv and create a suitable bar chart"
|
172
|
-
},{key:"parseMessages",value:function parseMessages(e,t,s){var i=[];return t.forEach(/*#__PURE__*/function(){var
|
173
|
-
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(e,t,s,i){var n;return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:n=
|
174
|
-
function $e(e,t,s,i,n,o){var _this33;_classCallCheck(this,$e);if(_this33=_callSuper(this,$e,[e,i,n,o]),_this33.insertKeyPlaceholderText="OpenAI API Key",_this33.keyHelpUrl="https://platform.openai.com/account/api-keys",_this33.url="",_this33.permittedErrorPrefixes=["Incorrect","Please send text",us.FAILED_ERROR_MESSAGE],_this33.shouldFetchHistory=!1,_this33._searchedForThreadId=!1,_this33._config={},_this33._newAssistantDetails={model:"gpt-4"},_this33._waitingForStreamResponse=!1,_this33._isSSEStream=!1,_this33.urlSegments=s,_typeof(t)=="object"){_this33._config=t;var _this33$_config=_this33._config,a=_this33$_config.new_assistant,l=_this33$_config.thread_id,c=_this33$_config.load_thread_history;Object.assign(_this33._newAssistantDetails,a),l&&(_this33.sessionId=l),c&&(_this33.shouldFetchHistory=!0);}_this33.maxMessages=1,_this33._isSSEStream=!!(_this33.stream&&(_typeof(_this33.stream)!="object"||!_this33.stream.simulation));return _this33;}_inherits($e,_M5);return _createClass($e,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(){var _this34=this;var e,_t24;return _regenerator().w(function(_context78){while(1)switch(_context78.p=_context78.n){case 0:setTimeout(function(){return _this34.deepChat.disableSubmitButton();},2);_context78.p=1;_context78.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context78.v;return _context78.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context78.p=3;_t24=_context78.v;return _context78.a(2,[{error:"Failed to fetch history"}]);}},_callee78,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processMessage",value:function processMessage(e,t){var s=this.totalMessagesMaxCharLength||-1,i=U.getCharacterLimitMessages(e,s)[0];if(t&&t.length>0){var n=this.filesToolType;if(typeof this.filesToolType=="function"){var a=this.filesToolType(t.map(function(_ref22){var l=_ref22.name;return l;}));a==="code_interpreter"||a==="file_search"||a==="images"?n=a:(console.error("Tool type \"".concat(a,"\" is not valid")),console.error('Expected "code_interpreter" or "file_search" or "images". Going to default to "images"'));}if(n==="file_search")return $e.processAttachmentsMessage(i,t,"file_search");if(n==="code_interpreter")return $e.processAttachmentsMessage(i,t,"code_interpreter");if(t.find(function(_ref23){var a=_ref23.name;return!K.isImageFileExtension(a);}))console.error("The uploaded files contained a non-image file"),console.error('Make sure only images can be uploaded or define a "code_interpreter" or "file_search" value in the "files_tool_type" property'),console.warn('Make sure your existing assistant supports these "tools" or specify them in the "new_assistant" property');else{var _a3=$e.processImageMessage(i,t);if(_a3)return _a3;}}return{content:i.text||"",role:"user"};}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,s){var i=JSON.parse(JSON.stringify(e)),n=this.processMessage(t,s);return i.thread={messages:[n]},i;}},{key:"callService",value:function callService(e,t,s){if(this._messages=e,this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/messages").concat(this.urlSegments.createMessagePostfix);var i=this.processMessage(t,s);x.request(this,i,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _i2=this.createNewThreadMessages(this.rawBody,t,s);this._isSSEStream?this.createStreamRun(_i2):x.request(this,_i2,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,s){var _n$assistant_id;var n,i,_t25,_t26;return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context79.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!((_n$assistant_id=(n=this.rawBody).assistant_id)!==null&&_n$assistant_id!==void 0)){_context79.n=2;break;}_n$assistant_id;_context79.n=5;break;case 2:_t25=this._config.assistant_id;if(_t25){_context79.n=4;break;}_context79.n=3;return this.createNewAssistant();case 3:_t25=_context79.v;case 4:n.assistant_id=_t25;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!s){_context79.n=7;break;}_context79.n=6;return Ie.storeFiles(this,e,s,this.urlSegments.storeFiles);case 6:_t26=_context79.v;_context79.n=8;break;case 7:_t26=void 0;case 8:i=_t26;this.connectSettings.method="POST",this.callService(e,t,i);case 9:return _context79.a(2);}},_callee79,this);}));function callServiceAPI(_x159,_x160,_x161){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(){var e,_t27;return _regenerator().w(function(_context80){while(1)switch(_context80.p=_context80.n){case 0:_context80.p=0;this.url=this.urlSegments.newAssistantUrl;_context80.n=1;return F.directFetch(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),"POST");case 1:e=_context80.v;return _context80.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context80.p=2;_t27=_context80.v;console.error(_t27),console.error("Failed to create a new assistant");case 3:return _context80.a(2);}},_callee80,this,[[0,2]]);}));function createNewAssistant(){return _createNewAssistant.apply(this,arguments);}return createNewAssistant;}()},{key:"searchPreviousMessagesForThreadId",value:function searchPreviousMessagesForThreadId(e){var t=e.find(function(_ref24){var _ref25=_slicedToArray(_ref24,1),s=_ref25[0];return s._sessionId;});t&&(this.sessionId=t[0]._sessionId),this._searchedForThreadId=!0;}},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(e){var i,t,s;return _regenerator().w(function(_context81){while(1)switch(_context81.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context81.n=2;break;}_context81.n=1;return this.handleStream(e);case 1:return _context81.a(2,_context81.v);case 2:if(!e.error){_context81.n=3;break;}throw e.error.message.startsWith(Ie.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e.error.message;case 3:this.asyncCallInProgress=!0;_context81.n=4;return this.assignThreadAndRun(e);case 4:t="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs/").concat(this.run_id).concat(this.urlSegments.threadsPosfix),s={method:"GET",headers:(i=this.connectSettings)==null?void 0:i.headers};return _context81.a(2,(x.executePollRequest(this,t,s,this._messages),{text:""}));}},_callee81,this);}));function extractResultData(_x162){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(e){var t;return _regenerator().w(function(_context82){while(1)switch(_context82.n){case 0:if(!this.sessionId){_context82.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context82.n=1;return F.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),"POST");case 1:t=_context82.v;this.run_id=t.id;_context82.n=3;break;case 2:this.sessionId=e.thread_id,this.run_id=e.id,this._messages&&this._messages.messageToElements.length>0&&(this._messages.messageToElements[this._messages.messageToElements.length-1][0]._sessionId=this.sessionId);case 3:return _context82.a(2);}},_callee82,this);}));function assignThreadAndRun(_x163){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(e){var t,i,n,s,_args83=arguments,_t28;return _regenerator().w(function(_context83){while(1)switch(_context83.n){case 0:t=_args83.length>1&&_args83[1]!==undefined?_args83[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context83.n=1;return F.directFetch(this,{},"GET");case 1:s=_context83.v;_t28=!t&&this.deepChat.responseInterceptor;if(!_t28){_context83.n=3;break;}_context83.n=2;return(n=(i=this.deepChat).responseInterceptor)==null?void 0:n.call(i,s);case 2:s=_context83.v;case 3:return _context83.a(2,Ie.processAPIMessages(this,s,t,this.urlSegments));}},_callee83,this);}));function getThreadMessages(_x164){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(e){var _this35=this;var n,t,s,o,_o$shift,a,l,i;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:t=e.status,s=e.required_action;if(!(t==="queued"||t==="in_progress")){_context84.n=1;break;}return _context84.a(2,{timeoutMS:$e.POLLING_TIMEOUT_MS});case 1:if(!(t==="completed"&&this._messages)){_context84.n=3;break;}_context84.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context84.v;_o$shift=o.shift();a=_o$shift.text;l=_o$shift.files;return _context84.a(2,(setTimeout(function(){o.forEach(function(c){return _this35.deepChat.addMessage(c);});}),{text:a,_sessionId:this.sessionId,files:l}));case 3:i=(n=s==null?void 0:s.submit_tool_outputs)==null?void 0:n.tool_calls;if(!(t==="requires_action"&&i)){_context84.n=5;break;}_context84.n=4;return this.handleTools(i);case 4:return _context84.a(2,_context84.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context84.a(2);}},_callee84,this);}));function extractPollResultData(_x165){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
|
175
|
-
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var t,s,i,n,o,a;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:if(this.functionHandler){_context85.n=1;break;}throw Error(
|
176
|
-
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var t,s,i,n,o,a,l,c,
|
171
|
+
},{key:"parseMessages",value:function parseMessages(e,t,s){var i=[];return t.forEach(/*#__PURE__*/function(){var _ref41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee75(n){return _regenerator().w(function(_context75){while(1)switch(_context75.n){case 0:n.content.filter(function(o){return!!o.text||!!o.image_file;}).sort(function(o){return o.text?-1:o.image_file?1:0;}).forEach(/*#__PURE__*/function(){var _ref42=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee74(o){return _regenerator().w(function(_context74){while(1)switch(_context74.n){case 0:i.push(ye.getFilesAndText(e,n,s,o));case 1:return _context74.a(2);}},_callee74);}));return function(_x151){return _ref42.apply(this,arguments);};}());case 1:return _context75.a(2);}},_callee75);}));return function(_x150){return _ref41.apply(this,arguments);};}()),Promise.all(i);}},{key:"processStreamMessages",value:function(){var _processStreamMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee76(e,t,s){return _regenerator().w(function(_context76){while(1)switch(_context76.n){case 0:return _context76.a(2,ye.parseMessages(e,[{content:t,role:"assistant"}],s));}},_callee76);}));function processStreamMessages(_x152,_x153,_x154){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
|
172
|
+
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(e,t,s,i){var n;return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:n=ye.parseResult(t,s);return _context77.a(2,ye.parseMessages(e,n,i));}},_callee77);}));function processAPIMessages(_x155,_x156,_x157,_x158){return _processAPIMessages.apply(this,arguments);}return processAPIMessages;}()}]);}();ye.FILES_WITH_TEXT_ERROR="content with type `text` must have `text` values",ye.FUNCTION_TOOL_RESP_ERROR="Response must contain an array of strings for each individual function/tool_call, see https://deepchat.dev/docs/directConnection/OpenAI/#assistant-functions.";var Ve=ye;var ot=/*#__PURE__*/function(_L5){// prettier-ignore
|
173
|
+
function ot(e,t,s,i,n,o){var _this33;_classCallCheck(this,ot);if(_this33=_callSuper(this,ot,[e,i,n,o]),_this33.insertKeyPlaceholderText=_this33.genereteAPIKeyName("OpenAI"),_this33.keyHelpUrl="https://platform.openai.com/account/api-keys",_this33.url="",_this33.permittedErrorPrefixes=[Is,"Please send text",ws.FAILED_ERROR_MESSAGE],_this33.shouldFetchHistory=!1,_this33._searchedForThreadId=!1,_this33._config={},_this33._newAssistantDetails={model:"gpt-4"},_this33._waitingForStreamResponse=!1,_this33._isSSEStream=!1,_this33.urlSegments=s,_typeof(t)=="object"){_this33._config=t;var _this33$_config=_this33._config,a=_this33$_config.new_assistant,l=_this33$_config.thread_id,c=_this33$_config.load_thread_history;Object.assign(_this33._newAssistantDetails,a),l&&(_this33.sessionId=l),c&&(_this33.shouldFetchHistory=!0);}_this33.maxMessages=1,_this33._isSSEStream=!!(_this33.stream&&(_typeof(_this33.stream)!="object"||!_this33.stream.simulation));return _this33;}_inherits(ot,_L5);return _createClass(ot,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(){var _this34=this;var e,_t25;return _regenerator().w(function(_context78){while(1)switch(_context78.p=_context78.n){case 0:setTimeout(function(){return _this34.deepChat.disableSubmitButton();},2);_context78.p=1;_context78.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context78.v;return _context78.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context78.p=3;_t25=_context78.v;return _context78.a(2,[_defineProperty({},He,"Failed to fetch history")]);}},_callee78,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processMessage",value:function processMessage(e,t){var s=this.totalMessagesMaxCharLength||-1,i=G.getCharacterLimitMessages(e,s)[0];if(t&&t.length>0){var n=this.filesToolType;if(typeof this.filesToolType=="function"){var a=this.filesToolType(t.map(function(_ref44){var l=_ref44.name;return l;}));a==="code_interpreter"||a==="file_search"||a==="images"?n=a:(console.error("Tool type \"".concat(a,"\" is not valid")),console.error('Expected "code_interpreter" or "file_search" or "images". Going to default to "images"'));}if(n==="file_search")return ot.processAttachmentsMessage(i,t,"file_search");if(n==="code_interpreter")return ot.processAttachmentsMessage(i,t,"code_interpreter");if(t.find(function(_ref45){var a=_ref45.name;return!Q.isImageFileExtension(a);}))console.error("The uploaded files contained a non-image file"),console.error('Make sure only images can be uploaded or define a "code_interpreter" or "file_search" value in the "files_tool_type" property'),console.warn('Make sure your existing assistant supports these "tools" or specify them in the "new_assistant" property');else{var _a4=ot.processImageMessage(i,t);if(_a4)return _a4;}}return{content:i.text||"",role:"user"};}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,s){var i=JSON.parse(JSON.stringify(e)),n=this.processMessage(t,s);return i.thread={messages:[n]},i;}},{key:"callService",value:function callService(e,t,s){if(this._messages=e,this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/messages").concat(this.urlSegments.createMessagePostfix);var i=this.processMessage(t,s);w.request(this,i,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _i4=this.createNewThreadMessages(this.rawBody,t,s);this._isSSEStream?this.createStreamRun(_i4):w.request(this,_i4,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,s){var _n$assistant_id;var n,i,_t26,_t27;return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context79.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!((_n$assistant_id=(n=this.rawBody).assistant_id)!==null&&_n$assistant_id!==void 0)){_context79.n=2;break;}_n$assistant_id;_context79.n=5;break;case 2:_t26=this._config.assistant_id;if(_t26){_context79.n=4;break;}_context79.n=3;return this.createNewAssistant();case 3:_t26=_context79.v;case 4:n.assistant_id=_t26;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!s){_context79.n=7;break;}_context79.n=6;return Ve.storeFiles(this,e,s,this.urlSegments.storeFiles);case 6:_t27=_context79.v;_context79.n=8;break;case 7:_t27=void 0;case 8:i=_t27;this.connectSettings.method=Y,this.callService(e,t,i);case 9:return _context79.a(2);}},_callee79,this);}));function callServiceAPI(_x159,_x160,_x161){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(){var e,_t28;return _regenerator().w(function(_context80){while(1)switch(_context80.p=_context80.n){case 0:_context80.p=0;this.url=this.urlSegments.newAssistantUrl;_context80.n=1;return V.directFetch(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),Y);case 1:e=_context80.v;return _context80.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context80.p=2;_t28=_context80.v;console.error(_t28),console.error("Failed to create a new assistant");case 3:return _context80.a(2);}},_callee80,this,[[0,2]]);}));function createNewAssistant(){return _createNewAssistant.apply(this,arguments);}return createNewAssistant;}()},{key:"searchPreviousMessagesForThreadId",value:function searchPreviousMessagesForThreadId(e){var t=e.find(function(_ref46){var _ref47=_slicedToArray(_ref46,1),s=_ref47[0];return s._sessionId;});t&&(this.sessionId=t[0]._sessionId),this._searchedForThreadId=!0;}},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(e){var i,t,s;return _regenerator().w(function(_context81){while(1)switch(_context81.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context81.n=2;break;}_context81.n=1;return this.handleStream(e);case 1:return _context81.a(2,_context81.v);case 2:if(!e.error){_context81.n=3;break;}throw e.error.message.startsWith(Ve.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e.error.message;case 3:this.asyncCallInProgress=!0;_context81.n=4;return this.assignThreadAndRun(e);case 4:t="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs/").concat(this.run_id).concat(this.urlSegments.threadsPosfix),s={method:z,headers:(i=this.connectSettings)==null?void 0:i.headers};return _context81.a(2,(w.executePollRequest(this,t,s,this._messages),_defineProperty({},g,"")));}},_callee81,this);}));function extractResultData(_x162){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(e){var t;return _regenerator().w(function(_context82){while(1)switch(_context82.n){case 0:if(!this.sessionId){_context82.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context82.n=1;return V.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),Y);case 1:t=_context82.v;this.run_id=t.id;_context82.n=3;break;case 2:this.sessionId=e.thread_id,this.run_id=e.id,this._messages&&this._messages.messageToElements.length>0&&(this._messages.messageToElements[this._messages.messageToElements.length-1][0]._sessionId=this.sessionId);case 3:return _context82.a(2);}},_callee82,this);}));function assignThreadAndRun(_x163){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(e){var t,i,n,s,_args83=arguments,_t29;return _regenerator().w(function(_context83){while(1)switch(_context83.n){case 0:t=_args83.length>1&&_args83[1]!==undefined?_args83[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context83.n=1;return V.directFetch(this,{},z);case 1:s=_context83.v;_t29=!t&&this.deepChat.responseInterceptor;if(!_t29){_context83.n=3;break;}_context83.n=2;return(n=(i=this.deepChat).responseInterceptor)==null?void 0:n.call(i,s);case 2:s=_context83.v;case 3:return _context83.a(2,Ve.processAPIMessages(this,s,t,this.urlSegments));}},_callee83,this);}));function getThreadMessages(_x164){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(e){var _this35=this;var n,t,s,o,_o$shift,a,l,i;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:t=e.status,s=e.required_action;if(!(t==="queued"||t==="in_progress")){_context84.n=1;break;}return _context84.a(2,{timeoutMS:ot.POLLING_TIMEOUT_MS});case 1:if(!(t===fr&&this._messages)){_context84.n=3;break;}_context84.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context84.v;_o$shift=o.shift();a=_o$shift.text;l=_o$shift.files;return _context84.a(2,(setTimeout(function(){o.forEach(function(c){return _this35.deepChat.addMessage(c);});}),{text:a,_sessionId:this.sessionId,files:l}));case 3:i=(n=s==null?void 0:s.submit_tool_outputs)==null?void 0:n.tool_calls;if(!(t==="requires_action"&&i)){_context84.n=5;break;}_context84.n=4;return this.handleTools(i);case 4:return _context84.a(2,_context84.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context84.a(2);}},_callee84,this);}));function extractPollResultData(_x165){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
|
174
|
+
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var t,s,i,n,o,a;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:if(this.functionHandler){_context85.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:t=e.map(function(l){return{name:l["function"].name,arguments:l["function"].arguments};});_context85.n=2;return this.functionHandler(t);case 2:s=_context85.v;if(!(!Array.isArray(s)||e.length!==s.length)){_context85.n=3;break;}throw Error(Ve.FUNCTION_TOOL_RESP_ERROR);case 3:_context85.n=4;return Promise.all(s);case 4:i=_context85.v;if(!i.find(function(l){return typeof l!="string";})){_context85.n=5;break;}throw Error(Ve.FUNCTION_TOOL_RESP_ERROR);case 5:n=i.map(function(l,c){return{tool_call_id:e[c].id,output:l};}),o="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId),a="/runs/".concat(this.run_id,"/submit_tool_outputs").concat(this.urlSegments.threadsPosfix);this.url="".concat(o).concat(a);if(!this._isSSEStream){_context85.n=7;break;}_context85.n=6;return this.createStreamRun({tool_outputs:n});case 6:_context85.n=8;break;case 7:_context85.n=8;return V.directFetch(this,{tool_outputs:n},Y);case 8:return _context85.a(2,{timeoutMS:ot.POLLING_TIMEOUT_MS});}},_callee85,this);}));function handleTools(_x166){return _handleTools.apply(this,arguments);}return handleTools;}()},{key:"handleStream",value:function(){var _handleStream=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){var s,i,t,n;return _regenerator().w(function(_context86){while(1)switch(_context86.n){case 0:t=(i=(s=e.required_action)==null?void 0:s.submit_tool_outputs)==null?void 0:i.tool_calls;if(!(e.status==="requires_action"&&t)){_context86.n=2;break;}this.run_id=e.id;_context86.n=1;return this.handleTools(t);case 1:return _context86.a(2,_context86.v);case 2:if(!this._waitingForStreamResponse){_context86.n=3;break;}return _context86.a(2,this.parseStreamResult(e));case 3:if(this._isSSEStream&&this.sessionId){this.asyncCallInProgress=!0,this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);n=JSON.parse(JSON.stringify(this.rawBody));this.createStreamRun(n);}return _context86.a(2,_defineProperty({},g,""));}},_callee86,this);}));function handleStream(_x167){return _handleStream.apply(this,arguments);}return handleStream;}()// prettier-ignore
|
175
|
+
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var t,s,i,n,o,a,l,c,_a5,_l3;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:if(!(e.content&&e.content.length>0&&this._messages)){_context87.n=1;break;}a=e.content.find(function(l){return l.text;});if(!((t=a==null?void 0:a.text)!=null&&t.annotations&&a.text.annotations.length>0)){_context87.n=1;break;}l=e.content.find(function(d){return!!d.text;})||e.content[0],c=Ve.getFilesAndText.bind(this,this,{role:"assistant",content:e.content},this.urlSegments,l);return _context87.a(2,((s=this._messageStream)==null||s.endStreamAfterFileDownloaded(this._messages,c),_defineProperty({},g,"")));case 1:if(!((i=e.delta)!=null&&i.content)){_context87.n=4;break;}if(!(e.delta.content.length>1)){_context87.n=3;break;}_a5=e.delta.content.find(function(l){return l.text;});if(!((n=_a5==null?void 0:_a5.text)!=null&&n.annotations&&_a5.text.annotations.length===0)){_context87.n=3;break;}_context87.n=2;return Ve.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_l3=_context87.v;return _context87.a(2,_defineProperty(_defineProperty({},g,_l3[0].text),"files",_l3[1].files));case 3:return _context87.a(2,_defineProperty({},g,(o=e.delta.content[0].text)==null?void 0:o.value));case 4:return _context87.a(2,(!this.sessionId&&e.thread_id&&(this.sessionId=e.thread_id),_defineProperty({},g,"")));}},_callee87,this);}));function parseStreamResult(_x168){return _parseStreamResult.apply(this,arguments);}return parseStreamResult;}()// https://platform.openai.com/docs/api-reference/assistants-streaming
|
177
176
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
178
|
-
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context88.n=1;return
|
179
|
-
function
|
180
|
-
},{key:"setEvents",value:function setEvents(e){this.elementRef.onmousedown=this.buttonMouseDown.bind(this,e),this.elementRef.onmouseup=this.buttonMouseUp.bind(this,e),this.elementRef.onmouseenter=this.buttonMouseEnter.bind(this,e),this.elementRef.onmouseleave=this.buttonMouseLeave.bind(this,e);}},{key:"unsetCustomStateStyles",value:function unsetCustomStateStyles(e){if(this.customStyles)for(var t=0;t<e.length;t+=1){var _s2=e[t],i=_s2&&this.customStyles[_s2];i&&
|
181
|
-
},{key:"assignPropertyFromOneToAnother",value:function assignPropertyFromOneToAnother(e,t,s){var _t$e;(_t$e=t[e])!==null&&_t$e!==void 0?_t$e:t[e]={},Object.assign(t[e],s==null?void 0:s[e]);}}]);}();var
|
182
|
-
function setUpView(e,t){e.style.display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(){var i,e,t,s;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:e=(i=this._deepChat.directConnection)==null?void 0:i.openAI;if(e){_context89.n=1;break;}return _context89.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context89.n=2;break;}return _context89.a(2);case 2:s=this.key||e.key;(t.fetchEphemeralKey||s)&&t.autoStart&&(this.changeToUnavailable(),this.displayLoading()),this.fetchEphemeralKey(t.autoStart);case 3:return _context89.a(2);}},_callee89,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var o,t,s,i,n,a,_t29,_t30,_t31;return _regenerator().w(function(_context90){while(1)switch(_context90.p=_context90.n){case 0:t=(o=this._deepChat.directConnection)==null?void 0:o.openAI,s=_typeof(t==null?void 0:t.realtime)=="object"?t==null?void 0:t.realtime.fetchEphemeralKey:void 0,i=t==null?void 0:t.realtime,n=this.key||t.key;if(!(_typeof(i)=="object")){_context90.n=8;break;}if(this._ephemeralKey){_context90.n=7;break;}_context90.p=1;if(!s){_context90.n=3;break;}a=s();a.then&&(this._retrievingEphemeralKey=a);_context90.n=2;return a;case 2:this._ephemeralKey=_context90.v;_context90.n=5;break;case 3:_t29=n;if(!_t29){_context90.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(n);_context90.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context90.v;case 5:_context90.n=7;break;case 6:_context90.p=6;_t30=_context90.v;this.displayFailedToRetrieveEphemeralKey(_t30);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context90.n=12;break;case 8:if(!n){_context90.n=12;break;}_context90.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(n);_context90.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context90.v;e&&this.init(this._ephemeralKey);_context90.n=12;break;case 11:_context90.p=11;_t31=_context90.v;this.displayFailedToRetrieveEphemeralKey(_t31);case 12:return _context90.a(2);}},_callee90,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x170){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:_context91.n=1;return fetch("https://api.openai.com/v1/realtime/sessions",{method:"POST",body:JSON.stringify(this.rawBody),headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)}});case 1:_context91.n=2;return _context91.v.json();case 2:return _context91.a(2,_context91.v.client_secret.value);}},_callee91,this);}));function getEphemeralKey(_x171){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this40=this;return{updateConfig:function updateConfig(e){var t;(t=_this40._dc)==null||t.send(JSON.stringify({type:"session.update",session:e}));},sendMessage:function sendMessage(e,t){var s=t||"system",n={role:s,type:"message",content:[{type:s==="system"||s==="user"?"input_text":"text",text:e}]};_this40.sendMessage(n);}};}},{key:"createContainer",value:function createContainer(){var e=document.createElement("div");return e.id="deep-chat-openai-realtime-container",e.appendChild(this.createAvatarContainer()),e.appendChild(this.createButtonsContainer()),e.appendChild(this.createError()),e;}},{key:"createAvatarContainer",value:function createAvatarContainer(){var t,s;var e=document.createElement("div");return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e.style,(s=(t=this._avatarConfig)==null?void 0:t.styles)==null?void 0:s.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var i;var e=document.createElement("div");e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e.style,(i=this._buttonsConfig)==null?void 0:i.container),this._microphoneButton=this.createMicophoneButton();var t=L.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var s=L.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(s),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this41=this;var t;var e=new Bs((t=this._buttonsConfig)==null?void 0:t.microphone);return e.elementRef.classList.add(L.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),e.elementRef.onclick=function(){e.isActive?(_this41.toggleMicorphone(!0),e.elementRef.classList.replace(L.MICROPHONE_ACTIVE,L.BUTTON_DEFAULT),e.changeToDefault(),_this41._isMuted=!1):(_this41.toggleMicorphone(!1),e.elementRef.classList.replace(L.BUTTON_DEFAULT,L.MICROPHONE_ACTIVE),B.removeAriaAttributes(e.elementRef),e.changeToActive(),_this41._isMuted=!0);},e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(s){return s.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this42=this;var t;var e=new Bs((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef.classList.add(L.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),e.elementRef.onclick=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(){var s,i,_t32,_t33;return _regenerator().w(function(_context92){while(1)switch(_context92.p=_context92.n){case 0:if(!e.isActive){_context92.n=1;break;}e.changeToDefault(),_this42.stop();_context92.n=9;break;case 1:_context92.p=1;if(!_this42._ephemeralKey){_context92.n=3;break;}_this42.displayLoading();_context92.n=2;return _this42.init(_this42._ephemeralKey);case 2:_context92.n=7;break;case 3:if(!_this42._retrievingEphemeralKey){_context92.n=6;break;}_this42.displayLoading();_context92.n=4;return _this42._retrievingEphemeralKey;case 4:i=_context92.v;_t32=(s=_this42._toggleButton)!=null&&s.isActive;if(!_t32){_context92.n=5;break;}_context92.n=5;return _this42.init(i);case 5:_context92.n=7;break;case 6:_this42.displayLoading();_context92.n=7;return _this42.fetchEphemeralKey(!0);case 7:_context92.n=9;break;case 8:_context92.p=8;_t33=_context92.v;console.error("Failed to start conversation:",_t33),_this42.displayError(),_this42.hideLoading();case 9:return _context92.a(2);}},_callee92,null,[[1,8]]);})),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(e){var _this43=this;var t,s,i,n,o,a,l,c,_t36,_t37,_t38,_t39;return _regenerator().w(function(_context95){while(1)switch(_context95.p=_context95.n){case 0:t=new RTCPeerConnection();this._pc=t;s=document.createElement("audio");s.autoplay=!0;i=new AudioContext(),n=i.createAnalyser();n.fftSize=256;o=new Uint8Array(n.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(a){var l,_t34;return _regenerator().w(function(_context93){while(1)switch(_context93.n){case 0:if(!a.streams[0]){_context93.n=2;break;}s.srcObject=a.streams[0];l=i.createMediaStreamSource(a.streams[0]);_t34=i.state==="suspended";if(!_t34){_context93.n=1;break;}_context93.n=1;return i.resume();case 1:l.connect(n);_this43.monitorFrequencies(n,o);_context93.n=3;break;case 2:console.error("No streams found in the ontrack event."),_this43.displayError();case 3:return _context93.a(2);}},_callee93);}));return function(_x173){return _ref30.apply(this,arguments);};}();_context95.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var l;t===_this43._pc&&(_this43._mediaStream=a,(l=_this43._pc)==null||l.addTrack(_this43._mediaStream.getTracks()[0]),_this43._isMuted&&_this43.toggleMicorphone(!1));})["catch"](function(a){console.error("Error accessing microphone:",a),_this43.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(a){var c,d,u,l,f,m,p,_t35;return _regenerator().w(function(_context94){while(1)switch(_context94.p=_context94.n){case 0:l=JSON.parse(a.data);if(!(l.type==="session.created")){_context94.n=1;break;}_this43.removeUnavailable(),_this43._toggleButton&&(B.removeAriaAttributes(_this43._toggleButton.elementRef),_this43._toggleButton.changeToActive()),(d=(c=_this43._events)==null?void 0:c.started)==null||d.call(c),_this43._deepChat.dispatchEvent(new CustomEvent(Fs.SESSION_STARTED)),_this43.hideLoading();_context94.n=7;break;case 1:if(!(l.type==="response.done")){_context94.n=6;break;}f=(u=JSON.parse(a.data).response.output)==null?void 0:u[0];if(!((f==null?void 0:f.type)==="function_call")){_context94.n=5;break;}m=f.name,p=f.call_id;_context94.p=2;_context94.n=3;return _this43.handleTool(m,f.arguments,p);case 3:_context94.n=5;break;case 4:_context94.p=4;_t35=_context94.v;_this43.stopOnError(_t35);case 5:_context94.n=7;break;case 6:l.type==="error"?_this43.stopOnError(l.error.message):l.type==="invalid_request_error"?_this43.stopOnError(l.message):l.type;case 7:return _context94.a(2);}},_callee94,null,[[2,4]]);}));return function(_x174){return _ref31.apply(this,arguments);};}());_context95.p=2;_context95.n=3;return this._pc.createOffer();case 3:a=_context95.v;_t36=t!==this._pc;if(_t36){_context95.n=5;break;}_context95.n=4;return this._pc.setLocalDescription(a);case 4:_t36=t!==this._pc;case 5:if(!_t36){_context95.n=6;break;}return _context95.a(2);case 6:_context95.n=7;return fetch("https://api.openai.com/v1/realtime",{method:"POST",body:a.sdp,headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/sdp"}});case 7:l=_context95.v;if(!(t!==this._pc)){_context95.n=8;break;}return _context95.a(2);case 8:_context95.n=9;return l.text();case 9:_t37=_context95.v;c={type:"answer",sdp:_t37};_t38=t!==this._pc;if(_t38){_context95.n=11;break;}_context95.n=10;return this._pc.setRemoteDescription(c);case 10:_t38=t!==this._pc;case 11:if(!_t38){_context95.n=12;break;}return _context95.a(2);case 12:_context95.n=14;break;case 13:_context95.p=13;_t39=_context95.v;console.error(_t39),this.displayError();case 14:return _context95.a(2);}},_callee95,this,[[2,13]]);}));function init(_x172){return _init2.apply(this,arguments);}return init;}()// there is a bug where sometimes upon refreshing the browser too many times the frequencyData is all 0s
|
177
|
+
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context88.n=1;return x.request(this,e,this._messages,!0,!0);case 1:this._messageStream=_context88.v;case 2:return _context88.a(2);}},_callee88,this);}));function createStreamRun(_x169){return _createStreamRun.apply(this,arguments);}return createStreamRun;}()}],[{key:"processImageMessage",value:function processImageMessage(e,t){var s=t==null?void 0:t.filter(function(i){return Q.isImageFileExtension(i.name);}).map(function(i){return{type:"image_file",image_file:{file_id:i.id}};});if(s&&s.length>0)return e.text&&e.text.length>0&&s.push(_defineProperty({type:"text"},g,e.text)),{content:s,role:"user"};}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,s){return{attachments:t.map(function(n){return{tools:[{type:s}],file_id:n.id};}),content:[_defineProperty({type:"text"},g,e.text)],role:"user"};}}]);}(L);ot.POLLING_TIMEOUT_MS=500;var Xs=ot;var fn=/*#__PURE__*/function(_Xs){function fn(e){var _a$headers,_l$OpenAIBeta;var _this36;_classCallCheck(this,fn);var o,a,l,c,d;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.openAI,i=(o=t.openAI)==null?void 0:o.assistant,n=fn.buildUrlSegments(i);if(_this36=_callSuper(this,fn,[e,i,n,V.buildKeyVerificationDetails(),V.buildHeaders,s]),(_a$headers=(a=_this36.connectSettings).headers)!==null&&_a$headers!==void 0?_a$headers:a.headers={},(_l$OpenAIBeta=(l=_this36.connectSettings.headers)["OpenAI-Beta"])!==null&&_l$OpenAIBeta!==void 0?_l$OpenAIBeta:l["OpenAI-Beta"]="assistants=v2",_this36.shouldFetchHistory&&_this36.sessionId&&(_this36.fetchHistory=_this36.fetchHistoryFunc.bind(_assertThisInitialized(_this36))),_typeof(i)===S){var _ref55=(d=(c=e.directConnection)==null?void 0:c.openAI)==null?void 0:d.assistant,h=_ref55.function_handler,u=_ref55.files_tool_type;h&&(_this36.functionHandler=h),u&&(_this36.filesToolType=u);}return _this36;}_inherits(fn,_Xs);return _createClass(fn,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||"https://api.openai.com/v1";return{threadsPrefix:"".concat(t,"/threads"),threadsPosfix:"",newAssistantUrl:"".concat(t,"/assistants"),createMessagePostfix:"",listMessagesPostfix:"order=desc",storeFiles:"".concat(t,"/files"),getFilesPrefix:"".concat(t,"/files/"),getFilesPostfix:"/content"};}}]);}(Xs);var Sn=/*#__PURE__*/function(){function Sn(){_classCallCheck(this,Sn);}return _createClass(Sn,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty({"api-key":e},k,P);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(e){return{url:"".concat(e.endpoint,"/openai/models?api-version=").concat(e.version),method:z,handleVerificationResult:V.handleVerificationResult};}},{key:"validateURLDetails",value:function validateURLDetails(e){var t=e.endpoint,s=e.version,i=e.deploymentId;return t&&s&&i;}}]);}();Sn.URL_DETAILS_ERROR_MESSAGE="Please define the Azure URL Details. [More Information](https://deepchat.dev/docs/directConnection/Azure)";var Ce=Sn;var Ot=/*#__PURE__*/function(_Xs2){function Ot(e){var _y$headers;var _this37;_classCallCheck(this,Ot);var c,d,h,u,f,m,p,y;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.azure,i=(c=t.azure)==null?void 0:c.openAI,n=(i==null?void 0:i.urlDetails)||{},o="".concat((d=i==null?void 0:i.urlDetails)==null?void 0:d.endpoint,"/openai/"),a="?api-version=".concat((h=i==null?void 0:i.urlDetails)==null?void 0:h.version),l={threadsPrefix:"".concat(o).concat(Ot.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(Ot.NEW_ASSISTANT_RESOURCE).concat(a),createMessagePostfix:a,listMessagesPostfix:"order=desc&api-version=".concat((u=i==null?void 0:i.urlDetails)==null?void 0:u.version),storeFiles:"".concat(o,"files").concat(a),getFilesPrefix:"".concat(o,"files/"),getFilesPostfix:"/content".concat(a)};if(_this37=_callSuper(this,Ot,[e,i==null?void 0:i.assistant,l,Ce.buildKeyVerificationDetails(n),Ce.buildHeaders,s]),_this37.permittedErrorPrefixes=[Ce.URL_DETAILS_ERROR_MESSAGE],_this37.insertKeyPlaceholderText=_this37.genereteAPIKeyName("Azure OpenAI"),_this37.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",_this37.isTextInputDisabled=!1,_typeof(i==null?void 0:i.assistant)===S){var _ref57=(p=(m=(f=e.directConnection)==null?void 0:f.azure)==null?void 0:m.openAI)==null?void 0:p.assistant,_=_ref57.function_handler,I=_ref57.files_tool_type;_&&(_this37.functionHandler=_),I&&(_this37.filesToolType=I);}Ce.validateURLDetails(n)?(_y$headers=(y=_this37.connectSettings).headers)!==null&&_y$headers!==void 0?_y$headers:y.headers={}:(_this37.isTextInputDisabled=!0,_this37.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,Ce.URL_DETAILS_ERROR_MESSAGE));}));return _this37;}_inherits(Ot,_Xs2);return _createClass(Ot);}(Xs);Ot.THREAD_RESOURCE="threads",Ot.NEW_ASSISTANT_RESOURCE="assistants";var Gi=Ot;var j=/*#__PURE__*/function(){function j(){_classCallCheck(this,j);}return _createClass(j,null,[{key:"addAttributes",value:function addAttributes(e){e.role="button",e.setAttribute("tabindex","0");}},{key:"addAriaBusy",value:function addAriaBusy(e){e.setAttribute("aria-busy","true");}},{key:"removeAriaBusy",value:function removeAriaBusy(e){e.removeAttribute("aria-busy");}},{key:"addAriaDisabled",value:function addAriaDisabled(e){e.setAttribute("aria-disabled","true");}},{key:"removeAriaDisabled",value:function removeAriaDisabled(e){e.removeAttribute("aria-disabled");}},{key:"removeAriaAttributes",value:function removeAriaAttributes(e){j.removeAriaBusy(e),j.removeAriaDisabled(e);}}]);}();var Cr="<?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",be=/*#__PURE__*/function(){function be(){_classCallCheck(this,be);}return _createClass(be,null,[{key:"createTextElement",value:function createTextElement(e){var t=document.createElement("div");return t.classList.add(be.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,s,i){s?e.push(Qe.createSVGElement(s)):s!==""&&i&&e.push(t);}},{key:"createCustomElements",value:function createCustomElements(e,t,s){var l,c;var i=s==null?void 0:s[e],n=(l=i==null?void 0:i.text)==null?void 0:l.content,o=(c=i==null?void 0:i.svg)==null?void 0:c.content,a=[];return be.tryAddSVGElement(a,t,o,n),n&&a.push(be.createTextElement(n)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e.classList.remove(be.INPUT_BUTTON_SVG_CLASS,be.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(s){return s.classList.contains(be.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e.classList.add(be.INPUT_BUTTON_SVG_TEXT_CLASS):e.classList.add(be.INPUT_BUTTON_SVG_CLASS);}}]);}();be.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",be.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",be.INPUT_BUTTON_SVG_CLASS="input-button-svg";var Ue=be;var hs=/*#__PURE__*/function(){function hs(){_classCallCheck(this,hs);}return _createClass(hs,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return _defineProperty({svg:e.find(function(t){return t.tagName.toLowerCase()==="svg";})},g,e.find(function(t){return t.tagName.toLowerCase()==="div";}));}}]);}();var J=/*#__PURE__*/function(){function J(){_classCallCheck(this,J);}return _createClass(J,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var n,o;t.container&&U.unsetAllCSSMouseStates(e,t.container);var _hs$parseSVGTextEleme=hs.parseSVGTextElements(Array.from(e.children)),s=_hs$parseSVGTextEleme.svg,i=_hs$parseSVGTextEleme.text;(n=t.svg)!=null&&n.styles&&s&&U.unsetAllCSSMouseStates(s,t.svg.styles),(o=t.text)!=null&&o.styles&&i&&U.unsetAllCSSMouseStates(i,t.text.styles);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var n,o;t.container&&U.unsetActivityCSSMouseStates(e,t.container);var _hs$parseSVGTextEleme2=hs.parseSVGTextElements(Array.from(e.children)),s=_hs$parseSVGTextEleme2.svg,i=_hs$parseSVGTextEleme2.text;(n=t.svg)!=null&&n.styles&&s&&U.unsetActivityCSSMouseStates(s,t.svg.styles),(o=t.text)!=null&&o.styles&&i&&U.unsetActivityCSSMouseStates(i,t.text.styles);}},{key:"setElementsCSS",value:function setElementsCSS(e,t,s){var o,a,l,c,d;Object.assign(e.style,(o=t.container)==null?void 0:o[s]);var _hs$parseSVGTextEleme3=hs.parseSVGTextElements(Array.from(e.children)),i=_hs$parseSVGTextEleme3.svg,n=_hs$parseSVGTextEleme3.text;i&&Object.assign(i.style,(l=(a=t.svg)==null?void 0:a.styles)==null?void 0:l[s]),n&&Object.assign(n.style,(d=(c=t.text)==null?void 0:c.styles)==null?void 0:d[s]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,s){J.setElementsCSS(e,t,"default"),s!=="default"&&(J.setElementsCSS(e,t,"hover"),s!=="hover"&&J.setElementsCSS(e,t,"click"));}}]);}();var Mt=/*#__PURE__*/function(){// prettier-ignore
|
178
|
+
function Mt(e,t,s,i,n,o){_classCallCheck(this,Mt);this._mouseState={state:"default"},this.isCustom=!1,j.addAttributes(e),this.elementRef=e,this.svg=Qe.createSVGElement(t),this.customStyles=n,this.position=s,this._tooltipSettings=i,this.dropupText=o;}return _createClass(Mt,[{key:"buttonMouseLeave",value:function buttonMouseLeave(e){var t;this._mouseState.state="default",((t=this._activeTooltip)==null?void 0:t.element.style.visibility)==="visible"&&this._tooltipSettings&&Le.hide(this._activeTooltip,this._tooltipSettings),e&&(J.unsetAllCSS(this.elementRef,e),J.setElementsCSS(this.elementRef,e,"default"));}},{key:"buttonMouseEnter",value:function buttonMouseEnter(e){var t;this._mouseState.state="hover",this._tooltipSettings&&(this._activeTooltip=Le.display(this.elementRef,this._tooltipSettings,(t=this._activeTooltip)==null?void 0:t.element)),e&&J.setElementsCSS(this.elementRef,e,"hover");}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&J.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state="click",e&&J.setElementsCSS(this.elementRef,e,"click");}// be careful not to use onclick as that is used for button functionality
|
179
|
+
},{key:"setEvents",value:function setEvents(e){this.elementRef.onmousedown=this.buttonMouseDown.bind(this,e),this.elementRef.onmouseup=this.buttonMouseUp.bind(this,e),this.elementRef.onmouseenter=this.buttonMouseEnter.bind(this,e),this.elementRef.onmouseleave=this.buttonMouseLeave.bind(this,e);}},{key:"unsetCustomStateStyles",value:function unsetCustomStateStyles(e){if(this.customStyles)for(var t=0;t<e.length;t+=1){var _s2=e[t],i=_s2&&this.customStyles[_s2];i&&J.unsetActionCSS(this.elementRef,i);}}},{key:"reapplyStateStyle",value:function reapplyStateStyle(e,t){if(!this.customStyles)return;t&&this.unsetCustomStateStyles(t);var s=this.customStyles[e];s&&J.setElementCssUpToState(this.elementRef,s,this._mouseState.state),this.setEvents(s);}},{key:"changeElementsByState",value:function changeElementsByState(e){var _this$elementRef;(_this$elementRef=this.elementRef).replaceChildren.apply(_this$elementRef,_toConsumableArray(e)),Ue.reassignClassBasedOnChildren(this.elementRef,e);}},{key:"buildDefaultIconElement",value:function buildDefaultIconElement(e){var t=this.svg.cloneNode(!0);return t.id=e,[t];}},{key:"createInnerElements",value:function createInnerElements(e,t,s){var i=Ue.createCustomElements(t,this.svg,s);if(i&&i.length>0){if(this.position==="dropup-menu"){var n=this.svg.cloneNode(!0);n.id=i[0]===this.svg?e:"dropup-menu-item-icon-element-custom",i[0]=n;}return i;}return this.buildDefaultIconElement(e);}}]);}();var xi=/*#__PURE__*/function(_Mt){function xi(e){var _this38;_classCallCheck(this,xi);var s,i;var t=((i=(s=e==null?void 0:e["default"])==null?void 0:s.svg)==null?void 0:i.content)||xi.EMPTY_SVG;_this38=_callSuper(this,xi,[document.createElement("div"),t,void 0,void 0,e]),_this38.isActive=!1,_this38._innerElements=_this38.createInnerElementsForStates(_this38.customStyles),_this38.changeToDefault();return _this38;}_inherits(xi,_Mt);return _createClass(xi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{"default":this.createInnerButtonElements("default",e),active:this.createInnerButtonElements("active",e),unavailable:this.createInnerButtonElements("unavailable",e)};}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return Ue.createCustomElements(e,this.svg,t)||[this.svg];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef.classList.replace(Ue.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements.active),this.reapplyStateStyle("active",["unavailable","default"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,s,i;this.changeState(this._innerElements["default"]),(e=this.customStyles)!=null&&e.active&&J.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(s=this.customStyles)!=null&&s.unavailable&&J.unsetAllCSS(this.elementRef,(i=this.customStyles)==null?void 0:i.unavailable),this.reapplyStateStyle("default",["active","unavailable"]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,s,i;this.changeState(this._innerElements.unavailable),(e=this.customStyles)!=null&&e.active&&J.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(s=this.customStyles)!=null&&s["default"]&&J.unsetAllCSS(this.elementRef,(i=this.customStyles)==null?void 0:i["default"]),this.reapplyStateStyle("unavailable",["default","active"]),this.isActive=!1;}}]);}(Mt);xi.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var Ys=xi;var re=/*#__PURE__*/function(){function re(){_classCallCheck(this,re);}return _createClass(re,null,[{key:"setPropertyValueIfDoesNotExist",value:function setPropertyValueIfDoesNotExist(e,t,s){var _e$i,_e$i2;var i=t[0];t.length===1?(_e$i=e[i])!==null&&_e$i!==void 0?_e$i:e[i]=s:((_e$i2=e[i])!==null&&_e$i2!==void 0?_e$i2:e[i]={},t.shift(),re.setPropertyValueIfDoesNotExist(e[i],t,s));}},{key:"setPropertyValue",value:function setPropertyValue(e,t,s){var _e$i3;var i=t[0];t.length===1?e[i]=s:((_e$i3=e[i])!==null&&_e$i3!==void 0?_e$i3:e[i]={},t.shift(),re.setPropertyValue(e[i],t,s));}},{key:"getObjectValue",value:function getObjectValue(e,t){var s=t[0],i=e[s];return i===void 0||t.length===1?i:re.getObjectValue(i,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,s){var i=re.getObjectValue(t,s);if(i){var n=_objectSpread(_objectSpread({},i),re.getObjectValue(e,s)||{});re.setPropertyValue(e,s,n);}}},{key:"isJson",value:function isJson(e){try{return JSON.stringify(e),!0;}catch(_unused8){return!1;}}// prettier-ignore
|
180
|
+
},{key:"assignPropertyFromOneToAnother",value:function assignPropertyFromOneToAnother(e,t,s){var _t$e;(_t$e=t[e])!==null&&_t$e!==void 0?_t$e:t[e]={},Object.assign(t[e],s==null?void 0:s[e]);}}]);}();var wi=/*#__PURE__*/_createClass(function wi(){_classCallCheck(this,wi);});wi.SESSION_STARTED="sts-session-started",wi.SESSION_STOPPED="sts-session-stopped";var Zs=wi;var Ar="<?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>",O=/*#__PURE__*/function(_L6){function O(e){var _l$model;var _this39;_classCallCheck(this,O);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=O.getKey(e);_this39=_callSuper(this,O,[e,V.buildKeyVerificationDetails(),V.buildHeaders,{key:s}]),_this39.insertKeyPlaceholderText=_this39.genereteAPIKeyName("OpenAI"),_this39.keyHelpUrl="https://platform.openai.com/account/api-keys",_this39._microphoneButton=null,_this39._toggleButton=null,_this39._errorElement=null,_this39._loadingElement=null,_this39._pc=null,_this39._mediaStream=null,_this39._isMuted=!1;var i=(n=t.openAI)==null?void 0:n.realtime;if(_typeof(i)===S){_this39._avatarConfig=i.avatar,_this39._ephemeralKey=i.ephemeralKey,_this39._errorConfig=i.error,_this39._loadingConfig=i.loading,Object.assign(_this39.rawBody,i.config);var c=(a=(o=e.directConnection)==null?void 0:o.openAI)==null?void 0:a.realtime,_ref59=c.config||{},d=_ref59.function_handler;d&&(_this39._functionHandler=d),_this39._events=i.events,c.methods=_this39.generateMethods();}(_l$model=(l=_this39.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="gpt-4o-realtime-preview-2025-06-03",_this39._avatarConfig=O.buildAvatarConfig(i),_this39._buttonsConfig=O.buildButtonsConfig(i),_this39._avatarEl=O.createAvatar(_this39._avatarConfig),_this39._containerEl=_this39.createContainer(),_this39._deepChat=e;return _this39;}_inherits(O,_L6);return _createClass(O,[{key:"setUpView",value:// called after API key was inserted
|
181
|
+
function setUpView(e,t){e.style.display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(){var i,e,t,s;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:e=(i=this._deepChat.directConnection)==null?void 0:i.openAI;if(e){_context89.n=1;break;}return _context89.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context89.n=2;break;}return _context89.a(2);case 2:s=this.key||e.key;(t.fetchEphemeralKey||s)&&t.autoStart&&(this.changeToUnavailable(),this.displayLoading()),this.fetchEphemeralKey(t.autoStart);case 3:return _context89.a(2);}},_callee89,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var o,t,s,i,n,a,_t30,_t31,_t32;return _regenerator().w(function(_context90){while(1)switch(_context90.p=_context90.n){case 0:t=(o=this._deepChat.directConnection)==null?void 0:o.openAI,s=_typeof(t==null?void 0:t.realtime)=="object"?t==null?void 0:t.realtime.fetchEphemeralKey:void 0,i=t==null?void 0:t.realtime,n=this.key||t.key;if(!(_typeof(i)=="object")){_context90.n=8;break;}if(this._ephemeralKey){_context90.n=7;break;}_context90.p=1;if(!s){_context90.n=3;break;}a=s();a.then&&(this._retrievingEphemeralKey=a);_context90.n=2;return a;case 2:this._ephemeralKey=_context90.v;_context90.n=5;break;case 3:_t30=n;if(!_t30){_context90.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(n);_context90.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context90.v;case 5:_context90.n=7;break;case 6:_context90.p=6;_t31=_context90.v;this.displayFailedToRetrieveEphemeralKey(_t31);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context90.n=12;break;case 8:if(!n){_context90.n=12;break;}_context90.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(n);_context90.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context90.v;e&&this.init(this._ephemeralKey);_context90.n=12;break;case 11:_context90.p=11;_t32=_context90.v;this.displayFailedToRetrieveEphemeralKey(_t32);case 12:return _context90.a(2);}},_callee90,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x170){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:_context91.n=1;return fetch("https://api.openai.com/v1/realtime/sessions",{method:Y,body:JSON.stringify(this.rawBody),headers:_defineProperty(_defineProperty({},k,P),K,"".concat(ee).concat(e))});case 1:_context91.n=2;return _context91.v.json();case 2:return _context91.a(2,_context91.v.client_secret.value);}},_callee91,this);}));function getEphemeralKey(_x171){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this40=this;return{updateConfig:function updateConfig(e){var t;(t=_this40._dc)==null||t.send(JSON.stringify({type:"session.update",session:e}));},sendMessage:function sendMessage(e,t){var s=t||"system",n={role:s,type:"message",content:[{type:s==="system"||s==="user"?"input_text":"text",text:e}]};_this40.sendMessage(n);}};}},{key:"createContainer",value:function createContainer(){var e=document.createElement("div");return e.id="deep-chat-openai-realtime-container",e.appendChild(this.createAvatarContainer()),e.appendChild(this.createButtonsContainer()),e.appendChild(this.createError()),e;}},{key:"createAvatarContainer",value:function createAvatarContainer(){var t,s;var e=document.createElement("div");return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e.style,(s=(t=this._avatarConfig)==null?void 0:t.styles)==null?void 0:s.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var i;var e=document.createElement("div");e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e.style,(i=this._buttonsConfig)==null?void 0:i.container),this._microphoneButton=this.createMicophoneButton();var t=O.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var s=O.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(s),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this41=this;var t;var e=new Ys((t=this._buttonsConfig)==null?void 0:t.microphone);return e.elementRef.classList.add(O.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),e.elementRef.onclick=function(){e.isActive?(_this41.toggleMicorphone(!0),e.elementRef.classList.replace(O.MICROPHONE_ACTIVE,O.BUTTON_DEFAULT),e.changeToDefault(),_this41._isMuted=!1):(_this41.toggleMicorphone(!1),e.elementRef.classList.replace(O.BUTTON_DEFAULT,O.MICROPHONE_ACTIVE),j.removeAriaAttributes(e.elementRef),e.changeToActive(),_this41._isMuted=!0);},e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(s){return s.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this42=this;var t;var e=new Ys((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef.classList.add(O.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),e.elementRef.onclick=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(){var s,i,_t33,_t34;return _regenerator().w(function(_context92){while(1)switch(_context92.p=_context92.n){case 0:if(!e.isActive){_context92.n=1;break;}e.changeToDefault(),_this42.stop();_context92.n=9;break;case 1:_context92.p=1;if(!_this42._ephemeralKey){_context92.n=3;break;}_this42.displayLoading();_context92.n=2;return _this42.init(_this42._ephemeralKey);case 2:_context92.n=7;break;case 3:if(!_this42._retrievingEphemeralKey){_context92.n=6;break;}_this42.displayLoading();_context92.n=4;return _this42._retrievingEphemeralKey;case 4:i=_context92.v;_t33=(s=_this42._toggleButton)!=null&&s.isActive;if(!_t33){_context92.n=5;break;}_context92.n=5;return _this42.init(i);case 5:_context92.n=7;break;case 6:_this42.displayLoading();_context92.n=7;return _this42.fetchEphemeralKey(!0);case 7:_context92.n=9;break;case 8:_context92.p=8;_t34=_context92.v;console.error("Failed to start conversation:",_t34),_this42.displayError(),_this42.hideLoading();case 9:return _context92.a(2);}},_callee92,null,[[1,8]]);})),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(e){var _this43=this;var t,s,i,n,o,a,l,c,_t37,_t38,_t39,_t40;return _regenerator().w(function(_context95){while(1)switch(_context95.p=_context95.n){case 0:t=new RTCPeerConnection();this._pc=t;s=document.createElement("audio");s.autoplay=!0;i=new AudioContext(),n=i.createAnalyser();n.fftSize=256;o=new Uint8Array(n.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref61=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(a){var l,_t35;return _regenerator().w(function(_context93){while(1)switch(_context93.n){case 0:if(!a.streams[0]){_context93.n=2;break;}s.srcObject=a.streams[0];l=i.createMediaStreamSource(a.streams[0]);_t35=i.state==="suspended";if(!_t35){_context93.n=1;break;}_context93.n=1;return i.resume();case 1:l.connect(n);_this43.monitorFrequencies(n,o);_context93.n=3;break;case 2:console.error("No streams found in the ontrack event."),_this43.displayError();case 3:return _context93.a(2);}},_callee93);}));return function(_x173){return _ref61.apply(this,arguments);};}();_context95.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var l;t===_this43._pc&&(_this43._mediaStream=a,(l=_this43._pc)==null||l.addTrack(_this43._mediaStream.getTracks()[0]),_this43._isMuted&&_this43.toggleMicorphone(!1));})["catch"](function(a){console.error("Error accessing microphone:",a),_this43.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref62=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(a){var c,d,h,l,f,m,p,_t36;return _regenerator().w(function(_context94){while(1)switch(_context94.p=_context94.n){case 0:l=JSON.parse(a.data);if(!(l.type==="session.created")){_context94.n=1;break;}_this43.removeUnavailable(),_this43._toggleButton&&(j.removeAriaAttributes(_this43._toggleButton.elementRef),_this43._toggleButton.changeToActive()),(d=(c=_this43._events)==null?void 0:c.started)==null||d.call(c),_this43._deepChat.dispatchEvent(new CustomEvent(Zs.SESSION_STARTED)),_this43.hideLoading();_context94.n=7;break;case 1:if(!(l.type==="response.done")){_context94.n=6;break;}f=(h=JSON.parse(a.data).response.output)==null?void 0:h[0];if(!((f==null?void 0:f.type)==="function_call")){_context94.n=5;break;}m=f.name,p=f.call_id;_context94.p=2;_context94.n=3;return _this43.handleTool(m,f.arguments,p);case 3:_context94.n=5;break;case 4:_context94.p=4;_t36=_context94.v;_this43.stopOnError(_t36);case 5:_context94.n=7;break;case 6:l.type===He?_this43.stopOnError(l.error.message):l.type===Ae?_this43.stopOnError(l.message):l.type;case 7:return _context94.a(2);}},_callee94,null,[[2,4]]);}));return function(_x174){return _ref62.apply(this,arguments);};}());_context95.p=2;_context95.n=3;return this._pc.createOffer();case 3:a=_context95.v;_t37=t!==this._pc;if(_t37){_context95.n=5;break;}_context95.n=4;return this._pc.setLocalDescription(a);case 4:_t37=t!==this._pc;case 5:if(!_t37){_context95.n=6;break;}return _context95.a(2);case 6:_context95.n=7;return fetch("https://api.openai.com/v1/realtime",{method:Y,body:a.sdp,headers:_defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,"application/sdp")});case 7:l=_context95.v;if(!(t!==this._pc)){_context95.n=8;break;}return _context95.a(2);case 8:_context95.n=9;return l.text();case 9:_t38=_context95.v;c={type:"answer",sdp:_t38};_t39=t!==this._pc;if(_t39){_context95.n=11;break;}_context95.n=10;return this._pc.setRemoteDescription(c);case 10:_t39=t!==this._pc;case 11:if(!_t39){_context95.n=12;break;}return _context95.a(2);case 12:_context95.n=14;break;case 13:_context95.p=13;_t40=_context95.v;console.error(_t40),this.displayError();case 14:return _context95.a(2);}},_callee95,this,[[2,13]]);}));function init(_x172){return _init2.apply(this,arguments);}return init;}()// there is a bug where sometimes upon refreshing the browser too many times the frequencyData is all 0s
|
183
182
|
// in such instance please wait and refresh at a later time
|
184
|
-
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this44=this;var s=function(_s3){function s(){return _s3.apply(this,arguments);}s.toString=function(){return _s3.toString();};return s;}(function(){var c;e.getByteFrequencyData(t);var i=t.reduce(function(d,
|
185
|
-
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(e,t,s){var i,n;return _regenerator().w(function(_context96){while(1)switch(_context96.n){case 0:if(this._functionHandler){_context96.n=1;break;}throw Error(
|
186
|
-
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify({type:"conversation.item.create",item:e});this._dc.send(t);var s={type:"response.create"};this._dc.send(JSON.stringify(s));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var s=t==null?void 0:t.realtime;if(_typeof(s)=="object"&&(s.ephemeralKey||s.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?JSON.parse(JSON.stringify(e.avatar)):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$microphone,_o$default,_a$svg,_l$content,_t$toggle,
|
187
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t,s){var o,i,n;return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context99.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context99.n=2;break;}throw new Error("No file was added");case 2:this.url=this.connectSettings.url||this._service_url;i=this.preprocessBody(this.rawBody,t),n=
|
188
|
-
},{key:"handleSpeechVerificationResult",value:function handleSpeechVerificationResult(e,t,s,i){e.error?i(
|
189
|
-
},{key:"handleLanguageVerificationResult",value:function handleLanguageVerificationResult(e,t,s,i){var o;((o=e.error)==null?void 0:o.code)==="401"?i(
|
190
|
-
},{key:"handleTranslationVerificationResult",value:function handleTranslationVerificationResult(e,t,s,i){e.json().then(function(o){!Array.isArray(o)&&o.error.code===401e3?i(
|
191
|
-
function
|
192
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this47.permittedErrorPrefixes=["Access"];return _this47;}_inherits(
|
193
|
-
"Please define the azure endpoint. [More Information](https://deepchat.dev/docs/directConnection/Azure#Summarization)";var
|
194
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(
|
195
|
-
function
|
196
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal";return _this50;}_inherits(
|
197
|
-
function
|
198
|
-
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",
|
199
|
-
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#TextToSpeech)";var
|
200
|
-
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",
|
201
|
-
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#SpeechToText)";var
|
202
|
-
function
|
203
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this53.url="",_this53.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this53;}_inherits(
|
183
|
+
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this44=this;var s=function(_s3){function s(){return _s3.apply(this,arguments);}s.toString=function(){return _s3.toString();};return s;}(function(){var c;e.getByteFrequencyData(t);var i=t.reduce(function(d,h){return d+h;},0),n=t.length*255,o=i/n*100,a=1,l=a+o/100*(((c=_this44._avatarConfig)==null?void 0:c.maxScale)-a);_this44._avatarEl.style.transform="scale(".concat(l,")"),requestAnimationFrame(s);});s();}},{key:"stopOnError",value:function stopOnError(e){this.stop(),console.error(e),this.displayError();}},{key:"stop",value:function stop(){var e,t,s;(e=this._mediaStream)==null||e.getTracks().forEach(function(i){return i.stop();}),this._mediaStream=null,this._pc&&(this._pc.close(),this._pc=null,(s=(t=this._events)==null?void 0:t.stopped)==null||s.call(t),this._deepChat.dispatchEvent(new CustomEvent(Zs.SESSION_STOPPED)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&O.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&O.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&O.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&O.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&O.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&O.removeButtonUnavailable(this._toggleButton);}},{key:"createError",value:function createError(){var t;var e=document.createElement("div");return e.id="deep-chat-openai-realtime-error",Object.assign(e.style,(t=this._errorConfig)==null?void 0:t.style),this._errorElement=e,e;}},{key:"displayFailedToRetrieveEphemeralKey",value:function displayFailedToRetrieveEphemeralKey(e){console.error("Failed to retrieve ephemeral key"),console.error(e),this.displayError();}},{key:"displayError",value:function displayError(){var e;this._errorElement&&(this._errorElement.style.display="block",this._errorElement.textContent=((e=this._errorConfig)==null?void 0:e.text)||"Error",this.changeToUnavailable()),this.hideLoading();}},{key:"createLoading",value:function createLoading(){var t,s;var e=document.createElement("div");return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t.html&&(this._loadingElement.innerHTML=this._loadingConfig.html),Object.assign(e.style,(s=this._loadingConfig)==null?void 0:s.style),e.style.display="none",e;}},{key:"displayLoading",value:function displayLoading(){var e,t,s;this._toggleButton&&(this._toggleButton.changeToActive(),this._toggleButton.elementRef.classList.add(O.BUTTON_LOADING),j.removeAriaDisabled(this._toggleButton.elementRef),j.addAriaBusy(this._toggleButton.elementRef)),(typeof((e=this._loadingConfig)==null?void 0:e.display)!="boolean"||this._loadingConfig.display)&&this._loadingElement&&(this._loadingElement.style.display="block",(t=this._loadingConfig)!=null&&t.html||(this._loadingElement.textContent=((s=this._loadingConfig)==null?void 0:s.text)||"Loading"));}},{key:"hideLoading",value:function hideLoading(){this._toggleButton&&(this._toggleButton.elementRef.classList.remove(O.BUTTON_LOADING),j.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement.style.display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
|
184
|
+
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(e,t,s){var i,n;return _regenerator().w(function(_context96){while(1)switch(_context96.n){case 0:if(this._functionHandler){_context96.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:_context96.n=2;return this._functionHandler({name:e,arguments:t});case 2:i=_context96.v;if(!(_typeof(i)!="object"||!re.isJson(i))){_context96.n=3;break;}throw Error('The `function_handler` response must be a JSON object, e.g. {response: "My response"}');case 3:n={type:"function_call_output",call_id:s,output:JSON.stringify(i)};this.sendMessage(n);case 4:return _context96.a(2);}},_callee96,this);}));function handleTool(_x175,_x176,_x177){return _handleTool.apply(this,arguments);}return handleTool;}()// https://platform.openai.com/docs/api-reference/realtime-client-events/conversation/item/create
|
185
|
+
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify({type:"conversation.item.create",item:e});this._dc.send(t);var s={type:"response.create"};this._dc.send(JSON.stringify(s));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var s=t==null?void 0:t.realtime;if(_typeof(s)=="object"&&(s.ephemeralKey||s.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?JSON.parse(JSON.stringify(e.avatar)):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$microphone,_o$default,_a$svg,_l$content,_t$toggle,_u$default,_f$svg,_m$content,_p$active,_y$svg,_$content;var s,i,n,o,a,l,c,d,h,u,f,m,p,y,_;var t=_typeof(e)=="object"&&e.buttons?JSON.parse(JSON.stringify(e.buttons)):{};return(n=(i=(s=t.microphone)==null?void 0:s["default"])==null?void 0:i.text)!=null&&n.content||((_t$microphone=t.microphone)!==null&&_t$microphone!==void 0?_t$microphone:t.microphone={},(_o$default=(o=t.microphone)["default"])!==null&&_o$default!==void 0?_o$default:o["default"]={},(_a$svg=(a=t.microphone["default"]).svg)!==null&&_a$svg!==void 0?_a$svg:a.svg={},(_l$content=(l=t.microphone["default"].svg).content)!==null&&_l$content!==void 0?_l$content:l.content=Cr),(h=(d=(c=t.toggle)==null?void 0:c["default"])==null?void 0:d.text)!=null&&h.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_u$default=(u=t.toggle)["default"])!==null&&_u$default!==void 0?_u$default:u["default"]={},(_f$svg=(f=t.toggle["default"]).svg)!==null&&_f$svg!==void 0?_f$svg:f.svg={},(_m$content=(m=t.toggle["default"].svg).content)!==null&&_m$content!==void 0?_m$content:m.content=Ar,(_p$active=(p=t.toggle).active)!==null&&_p$active!==void 0?_p$active:p.active={},(_y$svg=(y=t.toggle.active).svg)!==null&&_y$svg!==void 0?_y$svg:y.svg={},(_$content=(_=t.toggle.active.svg).content)!==null&&_$content!==void 0?_$content:_.content=Ji),t;}},{key:"createAvatar",value:function createAvatar(e){var s;var t=document.createElement("img");return t.id="deep-chat-openai-realtime-avatar",Object.assign(t.style,(s=e==null?void 0:e.styles)==null?void 0:s.image),t.src=(e==null?void 0:e.src)||ji,t;}},{key:"createButtonContainer",value:function createButtonContainer(e){var t=document.createElement("div");return t.classList.add("deep-chat-openai-realtime-button-container"),t.appendChild(e),t;}},{key:"changeButtonToUnavailable",value:function changeButtonToUnavailable(e){e.elementRef.classList.add(O.UNAVAILABLE),j.removeAriaBusy(e.elementRef),j.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){O.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){j.removeAriaDisabled(e.elementRef),e.elementRef.classList.remove(O.UNAVAILABLE);}}]);}(L);O.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",O.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",O.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",O.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var $i=O;var Pt=/*#__PURE__*/function(_L7){function Pt(e){var _o$model3,_a$voice3;var _this45;_classCallCheck(this,Pt);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this45=_callSuper(this,Pt,[e,V.buildKeyVerificationDetails(),V.buildHeaders,s]),_this45.insertKeyPlaceholderText=_this45.genereteAPIKeyName("OpenAI"),_this45.keyHelpUrl="https://platform.openai.com/account/api-keys",_this45.url="https://api.openai.com/v1/audio/speech",_this45.permittedErrorPrefixes=[ht],_this45.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI : Text To Speech</b></div>\n <p>Generate an audio file based on your text input.</p>\n <p>Click <a href=\"https://platform.openai.com/docs/guides/text-to-speech\" target=\"_blank\">here</a>\n for more information.</p>";var i=(n=t==null?void 0:t.openAI)==null?void 0:n.textToSpeech;_typeof(i)===S&&Object.assign(_this45.rawBody,i),(_o$model3=(o=_this45.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=Pt.DEFAULT_MODEL,(_a$voice3=(a=_this45.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=Pt.DEFAULT_VOIDE,_this45.textInputPlaceholderText="Insert text to generate audio",_this45.rawBody.response_format="mp3";return _this45;}_inherits(Pt,_L7);return _createClass(Pt,[{key:"preprocessBody",value:function preprocessBody(e,t){var n,o;var s=JSON.parse(JSON.stringify(e)),i=(o=(n=t[t.length-1])==null?void 0:n.text)==null?void 0:o.trim();return i&&i!==""&&(s.input=i),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(e,t){var i,s;return _regenerator().w(function(_context97){while(1)switch(_context97.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context97.n=1;break;}throw new Error("Request settings have not been set up");case 1:this.url=this.connectSettings.url||this.url;s=this.preprocessBody(this.rawBody,t);w.request(this,s,e);case 2:return _context97.a(2);}},_callee97,this);}));function callServiceAPI(_x178,_x179){return _callServiceAPI10.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(e){return _regenerator().w(function(_context98){while(1)switch(_context98.n){case 0:if(!(e instanceof Blob)){_context98.n=1;break;}return _context98.a(2,new Promise(function(t){var s=new FileReader();s.readAsDataURL(e),s.onload=function(i){t({files:[{src:i.target.result,type:"audio"}]});};}));case 1:if(!e.error){_context98.n=2;break;}throw e.error.message;case 2:return _context98.a(2,_defineProperty({},He,He));}},_callee98);}));function extractResultData(_x180){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(L);Pt.DEFAULT_MODEL="tts-1",Pt.DEFAULT_VOIDE="alloy";var Wi=Pt;var Re=/*#__PURE__*/function(_L8){function Re(e){var _o$model4;var _this46;_classCallCheck(this,Re);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this46=_callSuper(this,Re,[e,V.buildKeyVerificationDetails(),V.buildHeaders,s,{audio:{}}]),_this46.insertKeyPlaceholderText=_this46.genereteAPIKeyName("OpenAI"),_this46.keyHelpUrl="https://platform.openai.com/account/api-keys",_this46.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI : Speech To Text</b></div>\n <p><b>Upload an audio file</b> to transcribe it into text. You can optionally provide text to guide the audio\n processing.\n <p>Click <a href=\"https://platform.openai.com/docs/guides/speech-to-text\" target=\"_blank\">here</a> for more info.</p>",_this46.url="",_this46.permittedErrorPrefixes=[ht],_this46.textInputPlaceholderText=ln,_this46._service_url=Re.AUDIO_TRANSCRIPTIONS_URL;var i=(n=t==null?void 0:t.openAI)==null?void 0:n.audio;_typeof(i)=="object"&&(_this46.processConfig(i),Re.cleanConfig(i),Object.assign(_this46.rawBody,i)),(_o$model4=(o=_this46.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=Re.DEFAULT_MODEL,_this46.rawBody.response_format="json",_this46.canSendMessage=Re.canSendFileMessage;return _this46;}_inherits(Re,_L8);return _createClass(Re,[{key:"processConfig",value:function processConfig(e){e!=null&&e.type&&e.type==="translation"&&(this._service_url=Re.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var n,o;var s=JSON.parse(JSON.stringify(e)),i=(o=(n=t[t.length-1])==null?void 0:n.text)==null?void 0:o.trim();return i&&i!==""&&(s.prompt=i),s;}// prettier-ignore
|
186
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t,s){var o,i,n;return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context99.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context99.n=2;break;}throw new Error("No file was added");case 2:this.url=this.connectSettings.url||this._service_url;i=this.preprocessBody(this.rawBody,t),n=Re.createFormDataBody(i,s[0]);M.tempRemoveContentHeader(this.connectSettings,w.request.bind(this,this,n,e),!1);case 3:return _context99.a(2);}},_callee99,this);}));function callServiceAPI(_x181,_x182,_x183){return _callServiceAPI11.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee100(e){return _regenerator().w(function(_context100){while(1)switch(_context100.n){case 0:if(!e.error){_context100.n=1;break;}throw e.error.message;case 1:return _context100.a(2,_defineProperty({},g,e.text));}},_callee100);}));function extractResultData(_x184){return _extractResultData14.apply(this,arguments);}return extractResultData;}()}],[{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.type;}},{key:"createFormDataBody",value:function createFormDataBody(e,t){var s=new FormData();return s.append("file",t),Object.keys(e).forEach(function(i){s.append(i,String(e[i]));}),s;}}]);}(L);Re.AUDIO_TRANSCRIPTIONS_URL="https://api.openai.com/v1/audio/transcriptions",Re.AUDIO_TRANSLATIONS_URL="https://api.openai.com/v1/audio/translations",Re.DEFAULT_MODEL="whisper-1";var Xi=Re;var ve=/*#__PURE__*/function(){function ve(){_classCallCheck(this,ve);}return _createClass(ve,null,[{key:"buildTextToSpeechHeaders",value:function buildTextToSpeechHeaders(e,t){return _defineProperty(_defineProperty(_defineProperty({},ve.SUBSCRIPTION_KEY_NAME,t),k,"application/ssml+xml"),"X-Microsoft-OutputFormat",e);}},{key:"buildSpeechToTextHeaders",value:function buildSpeechToTextHeaders(e){return _defineProperty(_defineProperty({},ve.SUBSCRIPTION_KEY_NAME,e),"Accept",P);}// prettier-ignore
|
187
|
+
},{key:"handleSpeechVerificationResult",value:function handleSpeechVerificationResult(e,t,s,i){e.error?i(E.INVALID_KEY):s(t);}},{key:"buildSpeechKeyVerificationDetails",value:function buildSpeechKeyVerificationDetails(e){return{url:"https://".concat(e,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:Y,createHeaders:function createHeaders(t){return _defineProperty({},ve.SUBSCRIPTION_KEY_NAME,"".concat(t));},handleVerificationResult:ve.handleSpeechVerificationResult};}},{key:"buildSummarizationHeader",value:function buildSummarizationHeader(e){return _defineProperty(_defineProperty({},ve.SUBSCRIPTION_KEY_NAME,e),k,P);}// prettier-ignore
|
188
|
+
},{key:"handleLanguageVerificationResult",value:function handleLanguageVerificationResult(e,t,s,i){var o;((o=e.error)==null?void 0:o.code)==="401"?i(E.INVALID_KEY):s(t);}},{key:"buildLanguageKeyVerificationDetails",value:function buildLanguageKeyVerificationDetails(e){return{url:"".concat(e,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:Y,createHeaders:function createHeaders(t){return _defineProperty({},ve.SUBSCRIPTION_KEY_NAME,"".concat(t));},handleVerificationResult:ve.handleLanguageVerificationResult};}// prettier-ignore
|
189
|
+
},{key:"handleTranslationVerificationResult",value:function handleTranslationVerificationResult(e,t,s,i){e.json().then(function(o){!Array.isArray(o)&&o.error.code===401e3?i(E.INVALID_KEY):s(t);});}},{key:"buildTranslationKeyVerificationDetails",value:function buildTranslationKeyVerificationDetails(e){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:Y,createHeaders:function createHeaders(t){return ve.buildTranslationHeaders(e,t);},handleVerificationResult:ve.handleTranslationVerificationResult};}},{key:"buildTranslationHeaders",value:function buildTranslationHeaders(e,t){var s=_defineProperty(_defineProperty({},ve.SUBSCRIPTION_KEY_NAME,t),k,P);return e&&(s["Ocp-Apim-Subscription-Region"]=e),s;}}]);}();ve.SUBSCRIPTION_KEY_NAME="Ocp-Apim-Subscription-Key";var tt=ve;var $a=/*#__PURE__*/function(_L9){// prettier-ignore
|
190
|
+
function $a(e,t,s,i,n){var _this47;_classCallCheck(this,$a);_this47=_callSuper(this,$a,[e,tt.buildLanguageKeyVerificationDetails(s),t,i,n]),_this47.insertKeyPlaceholderText="Azure Language Subscription Key",_this47.keyHelpUrl=// eslint-disable-next-line max-len
|
191
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this47.permittedErrorPrefixes=["Access"];return _this47;}_inherits($a,_L9);return _createClass($a);}(L);var bs=/*#__PURE__*/function(_$a){function bs(e){var _a$language;var _this48;_classCallCheck(this,bs);var i,n,o,a;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.summarization,s=(o=e.directConnection)==null?void 0:o.azure;_this48=_callSuper(this,bs,[e,tt.buildSummarizationHeader,t.endpoint,s]),_this48.permittedErrorPrefixes=[bs.ENDPOINT_ERROR_MESSAGE],_this48.url="",_this48.textInputPlaceholderText="Insert text to summarize",_this48.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this48.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this48.rawBody,t),_this48.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this48.isTextInputDisabled=!0,_this48.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,bs.ENDPOINT_ERROR_MESSAGE));}));return _this48;}_inherits(bs,_$a);return _createClass(bs,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return{analysisInput:{documents:[_defineProperty({id:"1",language:e.language},g,s)]},tasks:[{kind:"ExtractiveSummarization"}]};}},{key:"callServiceAPI",value:function(){var _callServiceAPI12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e,t){var s;return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if(this.connectSettings){_context101.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);w.request(this,s,e),this.messages=e;case 2:return _context101.a(2);}},_callee101,this);}));function callServiceAPI(_x185,_x186){return _callServiceAPI12.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(e){var t,_s5,i;return _regenerator().w(function(_context102){while(1)switch(_context102.n){case 0:if(!e.error){_context102.n=1;break;}throw e.error.message;case 1:if(this.messages&&this.completionsHandlers){this.asyncCallInProgress=!0;_s5=e.headers.get("operation-location"),i={method:z,headers:(t=this.connectSettings)==null?void 0:t.headers};w.executePollRequest(this,_s5,i,this.messages);}return _context102.a(2,_defineProperty({},g,""));}},_callee102,this);}));function extractResultData(_x187){return _extractResultData15.apply(this,arguments);}return extractResultData;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103(e){var t,_iterator,_step,_s6;return _regenerator().w(function(_context103){while(1)switch(_context103.n){case 0:if(!e.error){_context103.n=1;break;}throw e.error;case 1:if(!(e.status==="running"||e.status==="notStarted")){_context103.n=2;break;}return _context103.a(2,{timeoutMS:2e3});case 2:if(!(e.errors.length>0)){_context103.n=3;break;}throw e.errors[0];case 3:if(!(e.tasks.items[0].results.errors.length>0)){_context103.n=4;break;}throw e.tasks.items[0].results.errors[0];case 4:t="";_iterator=_createForOfIteratorHelper(e.tasks.items[0].results.documents[0].sentences);try{for(_iterator.s();!(_step=_iterator.n()).done;){_s6=_step.value;t+=_s6.text;}}catch(err){_iterator.e(err);}finally{_iterator.f();}return _context103.a(2,_defineProperty({},g,t||""));}},_callee103);}));function extractPollResultData(_x188){return _extractPollResultData5.apply(this,arguments);}return extractPollResultData;}()}]);}($a);bs.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
192
|
+
"Please define the azure endpoint. [More Information](https://deepchat.dev/docs/directConnection/Azure#Summarization)";var Yi=bs;var us=/*#__PURE__*/function(){function us(){_classCallCheck(this,us);}return _createClass(us,null,[{key:"poll",value:function(){var _poll2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(e,t){var s,a,l,d,_t41;return _regenerator().w(function(_context104){while(1)switch(_context104.n){case 0:s=_defineProperty(_defineProperty({},Pr,e),Dr,P);_t41="https://api.assemblyai.com/v2/transcript/";_context104.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:Y,body:JSON.stringify({audio_url:t}),headers:s});case 1:_context104.n=2;return _context104.v.json();case 2:a=_t41.concat.call(_t41,_context104.v.id);case 3:if(l){_context104.n=9;break;}_context104.n=4;return fetch(a,{headers:s});case 4:_context104.n=5;return _context104.v.json();case 5:d=_context104.v;if(!(d.status===fr)){_context104.n=6;break;}l=d;_context104.n=8;break;case 6:if(!(d.status===He)){_context104.n=7;break;}throw new Error("Transcription failed: ".concat(d.error));case 7:_context104.n=8;return new Promise(function(h){return setTimeout(h,3e3);});case 8:_context104.n=3;break;case 9:return _context104.a(2,l);}},_callee104);}));function poll(_x189,_x190){return _poll2.apply(this,arguments);}return poll;}()},{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,e),k,"application/octet-stream");}// prettier-ignore
|
193
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.assemblyai.com/v2/upload",method:Y,handleVerificationResult:us.handleVerificationResult};}}]);}();var pn=/*#__PURE__*/function(_L0){function pn(e){var _this49;_classCallCheck(this,pn);var s;var t=(s=e.directConnection)==null?void 0:s.assemblyAI;_this49=_callSuper(this,pn,[e,us.buildKeyVerificationDetails(),us.buildHeaders,t,{audio:{}}]),_this49.insertKeyPlaceholderText=_this49.genereteAPIKeyName("AssemblyAI"),_this49.keyHelpUrl="https://www.assemblyai.com/app/account",_this49.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>AssemblyAI Audio</b></div>\n <p><b>Upload an audio file</b> to transcribe it into text.\n <p>\n Click <a href=\"https://www.assemblyai.com/docs/Guides/transcribing_an_audio_file#get-started\"\n target=\"_blank\">here</a> for more info.\n </p>",_this49.url="https://api.assemblyai.com/v2/upload",_this49.isTextInputDisabled=!0,_this49.textInputPlaceholderText=ln,_this49.permittedErrorPrefixes=[ur,ht],_this49.canSendMessage=pn.canFileSendMessage;return _this49;}_inherits(pn,_L0);return _createClass(pn,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e,t,s){var i;return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context105.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context105.n=2;break;}throw new Error("No file was added");case 2:w.request(this,s[0],e,!1);case 3:return _context105.a(2);}},_callee105,this);}));function callServiceAPI(_x191,_x192,_x193){return _callServiceAPI13.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(e){var i,n,t,s;return _regenerator().w(function(_context106){while(1)switch(_context106.n){case 0:if(!e.error){_context106.n=1;break;}throw e.error;case 1:t=(n=(i=this.connectSettings)==null?void 0:i.headers)==null?void 0:n[K];_context106.n=2;return us.poll(t,e.upload_url);case 2:s=_context106.v;return _context106.a(2,_defineProperty({},g,s.text));}},_callee106,this);}));function extractResultData(_x194){return _extractResultData16.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(L);var Tr=/*#__PURE__*/function(_L1){// prettier-ignore
|
194
|
+
function Tr(e,t,s,i,n){var _this50;_classCallCheck(this,Tr);_this50=_callSuper(this,Tr,[e,tt.buildSpeechKeyVerificationDetails(s),t,i,n]),_this50.insertKeyPlaceholderText="Azure Speech Subscription Key",_this50.keyHelpUrl=// eslint-disable-next-line max-len
|
195
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal";return _this50;}_inherits(Tr,_L1);return _createClass(Tr);}(L);var vt=/*#__PURE__*/function(_Tr){// prettier-ignore
|
196
|
+
function vt(e){var _a$lang,_l$name,_c$gender;var _this51;_classCallCheck(this,vt);var i,n,o,a,l,c;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.textToSpeech,s=(o=e.directConnection)==null?void 0:o.azure;_this51=_callSuper(this,vt,[e,tt.buildTextToSpeechHeaders.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,s]),_this51.permittedErrorPrefixes=[vt.REGION_ERROR_MESSAGE],_this51.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Azure Text To Speech</b></div>\n <p>Insert text to synthesize it to audio.\n <p>\n Click <a href=\"".concat(vt.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this51.isTextInputDisabled=!1,_this51.url="",t.region?(Object.assign(_this51.rawBody,t),(_a$lang=(a=_this51.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_l$name=(l=_this51.rawBody).name)!==null&&_l$name!==void 0?_l$name:l.name="en-US-JennyNeural",(_c$gender=(c=_this51.rawBody).gender)!==null&&_c$gender!==void 0?_c$gender:c.gender="Female",_this51.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this51.isTextInputDisabled=!0,_this51.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,vt.REGION_ERROR_MESSAGE));}));return _this51;}_inherits(vt,_Tr);return _createClass(vt,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return"<speak version='1.0' xml:lang='".concat(e.lang,"'>\n <voice xml:lang='").concat(e.lang,"' xml:gender='").concat(e.gender,"' name='").concat(e.name,"'>\n ").concat(s,"\n </voice>\n </speak>");}},{key:"callServiceAPI",value:function(){var _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(e,t){var s;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:if(this.connectSettings){_context107.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);w.request(this,s,e,!1);case 2:return _context107.a(2);}},_callee107,this);}));function callServiceAPI(_x195,_x196){return _callServiceAPI14.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(e){return _regenerator().w(function(_context108){while(1)switch(_context108.n){case 0:return _context108.a(2,new Promise(function(t){var s=new FileReader();s.readAsDataURL(e),s.onload=function(i){t({files:[{src:i.target.result,type:"audio"}]});};}));}},_callee108);}));function extractResultData(_x197){return _extractResultData17.apply(this,arguments);}return extractResultData;}()}]);}(Tr);vt.HELP_LINK=// eslint-disable-next-line max-len
|
197
|
+
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",vt.REGION_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
198
|
+
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#TextToSpeech)";var Zi=vt;var at=/*#__PURE__*/function(_Tr2){function at(e){var _this52;_classCallCheck(this,at);var n,o,a;var t=(o=(n=e.directConnection)==null?void 0:n.azure)==null?void 0:o.speechToText,s=(a=e.directConnection)==null?void 0:a.azure,i={audio:{files:{acceptedFormats:".wav,.ogg"}}};if(_this52=_callSuper(this,at,[e,tt.buildSpeechToTextHeaders,t.region,s,i]),_this52.permittedErrorPrefixes=[at.REGION_ERROR_MESSAGE],_this52.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Azure Speech To Text</b></div>\n <p><b>Upload a .wav or .ogg audio file</b> to transcribe it into text.\n <p>\n Click <a href=\"".concat(at.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this52.url="",_this52.isTextInputDisabled=!0,_this52.textInputPlaceholderText=ln,!t.region)_this52.isTextInputDisabled=!0,_this52.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,at.REGION_ERROR_MESSAGE));});else{_this52.canSendMessage=at.canFileSendMessage;var l=t.lang||"en-US";_this52.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(l,"&format=detailed"),_this52.recordAudio=void 0;}return _this52;}_inherits(at,_Tr2);return _createClass(at,[{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e,t,s){var i,n;return _regenerator().w(function(_context109){while(1)switch(_context109.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context109.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(s!=null&&s[0]){_context109.n=2;break;}throw new Error("No file was added");case 2:(n=this.connectSettings)!=null&&n.headers&&(this.connectSettings.headers["Content-Type"]=s[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),w.request(this,s[0],e,!1);case 3:return _context109.a(2);}},_callee109,this);}));function callServiceAPI(_x198,_x199,_x200){return _callServiceAPI15.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(e){return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:if(!e.error){_context110.n=1;break;}throw e.error;case 1:return _context110.a(2,_defineProperty({},g,e.DisplayText||""));}},_callee110);}));function extractResultData(_x201){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(Tr);at.HELP_LINK=// eslint-disable-next-line max-len
|
199
|
+
"https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",at.REGION_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
200
|
+
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#SpeechToText)";var Qi=at;var Wa=/*#__PURE__*/function(_L10){// prettier-ignore
|
201
|
+
function Wa(e){var _this53;_classCallCheck(this,Wa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.azure;_this53=_callSuper(this,Wa,[e,tt.buildTranslationKeyVerificationDetails(t.region),tt.buildTranslationHeaders.bind({},t==null?void 0:t.region),s]),_this53.insertKeyPlaceholderText="Azure Translate Subscription Key",_this53.keyHelpUrl=// eslint-disable-next-line max-len
|
202
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this53.url="",_this53.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this53;}_inherits(Wa,_L10);return _createClass(Wa,[{key:"preprocessBody",value:function preprocessBody(e){var t=e[e.length-1].text;if(t)return[{Text:t}];}},{key:"callServiceAPI",value:function(){var _callServiceAPI16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e,t){var s;return _regenerator().w(function(_context111){while(1)switch(_context111.n){case 0:if(this.connectSettings){_context111.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(t);w.request(this,s,e);case 2:return _context111.a(2);}},_callee111,this);}));function callServiceAPI(_x202,_x203){return _callServiceAPI16.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(e){var t;return _regenerator().w(function(_context112){while(1)switch(_context112.n){case 0:if(!Array.isArray(e)){_context112.n=1;break;}return _context112.a(2,_defineProperty({},g,((t=e[0].translations)==null?void 0:t[0].text)||""));case 1:throw e.error;case 2:return _context112.a(2);}},_callee112);}));function extractResultData(_x204){return _extractResultData19.apply(this,arguments);}return extractResultData;}()}]);}(L);var Xa=/*#__PURE__*/function(_L11){function Xa(e){var _o$model5;var _this54;_classCallCheck(this,Xa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this54=_callSuper(this,Xa,[e,ct.buildKeyVerificationDetails(),ct.buildHeaders,s]),_this54.insertKeyPlaceholderText=_this54.genereteAPIKeyName("BigModel"),_this54.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this54.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this54.permittedErrorPrefixes=[K,te];var i=(n=t.bigModel)==null?void 0:n.images;_typeof(i)===S&&(_this54.cleanConfig(i),Object.assign(_this54.rawBody,i)),(_o$model5=(o=_this54.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this54;}_inherits(Xa,_L11);return _createClass(Xa,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t[t.length-1];return s.prompt=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113(e,t){var s;return _regenerator().w(function(_context113){while(1)switch(_context113.n){case 0:if(this.connectSettings){_context113.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context113.n=2;return w.request(this,s,e);case 2:return _context113.a(2,_context113.v);}},_callee113,this);}));function callServiceAPI(_x205,_x206){return _callServiceAPI17.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee114(e){return _regenerator().w(function(_context114){while(1)switch(_context114.n){case 0:return _context114.a(2,{files:e.data.map(function(s){return s!=null&&s.url?{src:s.url,type:"image"}:{src:"",type:"image"};})});}},_callee114);}));function extractResultData(_x207){return _extractResultData20.apply(this,arguments);}return extractResultData;}()}]);}(L);var Bt=/*#__PURE__*/function(){function Bt(){_classCallCheck(this,Bt);}return _createClass(Bt,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},k,P),K,"".concat(ee).concat(e));}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message===on?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.groq.com/openai/v1/models",method:z,handleVerificationResult:Bt.handleVerificationResult};}}]);}();var Ya=/*#__PURE__*/function(_L12){function Ya(e){var _o$model6,_a$voice4,_l$response_format;var _this55;_classCallCheck(this,Ya);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this55=_callSuper(this,Ya,[e,Bt.buildKeyVerificationDetails(),Bt.buildHeaders,s]),_this55.insertKeyPlaceholderText=_this55.genereteAPIKeyName("Groq"),_this55.keyHelpUrl="https://console.groq.com/keys",_this55.url="https://api.groq.com/openai/v1/audio/speech",_this55.permittedErrorPrefixes=[ht,"property"];var i=(n=t.groq)==null?void 0:n.textToSpeech;_typeof(i)===S&&(_this55.cleanConfig(i),Object.assign(_this55.rawBody,i)),(_o$model6=(o=_this55.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this55.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_l$response_format=(l=_this55.rawBody).response_format)!==null&&_l$response_format!==void 0?_l$response_format:l.response_format="mp3";return _this55;}_inherits(Ya,_L12);return _createClass(Ya,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t[t.length-1];return s.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(e,t){var s;return _regenerator().w(function(_context115){while(1)switch(_context115.n){case 0:if(this.connectSettings){_context115.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context115.n=2;return w.request(this,s,e);case 2:return _context115.a(2,_context115.v);}},_callee115,this);}));function callServiceAPI(_x208,_x209){return _callServiceAPI18.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee116(e){var t,s;return _regenerator().w(function(_context116){while(1)switch(_context116.n){case 0:t=this.rawBody.response_format||"mp3",s=new Blob([e],{type:"audio/".concat(t)});return _context116.a(2,{files:[{src:URL.createObjectURL(s),type:"audio"}]});}},_callee116,this);}));function extractResultData(_x210){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(L);var Za=/*#__PURE__*/function(_L13){function Za(e){var _o$model7;var _this56;_classCallCheck(this,Za);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this56=_callSuper(this,Za,[e,dt.buildKeyVerificationDetails(),dt.buildHeaders,s]),_this56.insertKeyPlaceholderText=_this56.genereteAPIKeyName("Together AI"),_this56.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this56.url="https://api.together.xyz/v1/images/generations",_this56.permittedErrorPrefixes=[Ae,te];var i=(n=t.together)==null?void 0:n.images;_typeof(i)===S&&(_this56.cleanConfig(i),Object.assign(_this56.rawBody,i)),(_o$model7=(o=_this56.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this56;}_inherits(Za,_L13);return _createClass(Za,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t[t.length-1];return s.prompt=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee117(e,t){var s;return _regenerator().w(function(_context117){while(1)switch(_context117.n){case 0:if(this.connectSettings){_context117.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t);_context117.n=2;return w.request(this,s,e);case 2:return _context117.a(2,_context117.v);}},_callee117,this);}));function callServiceAPI(_x211,_x212){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee118(e){return _regenerator().w(function(_context118){while(1)switch(_context118.n){case 0:return _context118.a(2,{files:e.data.map(function(s){return s!=null&&s.url?{src:s.url,type:"image"}:s!=null&&s.b64_json?{src:"data:image/png;base64,".concat(s.b64_json),type:"image"}:{src:"",type:"image"};})});}},_callee118);}));function extractResultData(_x213){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(L);var As=/*#__PURE__*/function(_L14){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
|
204
203
|
// prettier-ignore
|
205
|
-
function
|
204
|
+
function As(e,t,s,i,n){var _this57$maxMessages,_p$model;var _this57;_classCallCheck(this,As);var h,u,f,m,p;var o=JSON.parse(JSON.stringify(e.directConnection)),a=t||V.buildKeyVerificationDetails(),l=s||V.buildHeaders,c=i||o.openAI;_this57=_callSuper(this,As,[e,a,l,c]),_this57.insertKeyPlaceholderText=_this57.genereteAPIKeyName("OpenAI"),_this57.keyHelpUrl="https://platform.openai.com/account/api-keys",_this57.url="https://api.openai.com/v1/chat/completions",_this57.permittedErrorPrefixes=[Is],_this57._systemMessage="";var d=n||((h=o.openAI)==null?void 0:h.chat);if(_typeof(d)===S){d.system_prompt&&(_this57._systemMessage=d.system_prompt);var y=(m=(f=(u=e.directConnection)==null?void 0:u.openAI)==null?void 0:f.chat)==null?void 0:m.function_handler;y&&(_this57._functionHandler=y),_this57.cleanConfig(d),Object.assign(_this57.rawBody,d);}(_this57$maxMessages=_this57.maxMessages)!==null&&_this57$maxMessages!==void 0?_this57$maxMessages:_this57.maxMessages=-1,(_p$model=(p=_this57.rawBody).model)!==null&&_p$model!==void 0?_p$model:p.model="gpt-4o";return _this57;}_inherits(As,_L14);return _createClass(As,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler;}// mention that microphone is not supported because the outputted base64 is not accepted
|
206
205
|
// use speech to speech instead
|
207
206
|
// give allowed regex example for audio format rules
|
208
207
|
},{key:"preprocessBody",value:// prettier-ignore
|
209
|
-
function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.stringify(e)),i=(o=s.modalities)==null?void 0:o.includes("audio"),n=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.content.length:-1).map(function(a){return{content:lt.getContent(a,i),role:a.role===y.USER_ROLE?"user":"assistant"};});return t.find(function(a){return a.files&&a.files.length>0;})&&((_s$max_tokens=s.max_tokens)!==null&&_s$max_tokens!==void 0?_s$max_tokens:s.max_tokens=300),s.messages=[this._systemMessage].concat(_toConsumableArray(n)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e,t){var _this$_messages3;var s,i;return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:if(this.connectSettings){_context119.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages3=this._messages)!==null&&_this$_messages3!==void 0?_this$_messages3:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context119.a(2);}},_callee119,this);}));function callServiceAPI(_x214,_x215){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee120(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:if(!e.error){_context120.n=1;break;}throw e.error.message;case 1:if(!((i=(s=e.choices)==null?void 0:s[0])!=null&&i.delta)){_context120.n=2;break;}return _context120.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(n=e.choices)==null?void 0:n[0])!=null&&o.message)){_context120.n=5;break;}if(!e.choices[0].message.tool_calls){_context120.n=3;break;}return _context120.a(2,this.handleTools(e.choices[0].message,t));case 3:if(!((a=e.choices[0].message)!=null&&a.audio)){_context120.n=4;break;}c=this.deepChat.textToSpeech,d=_typeof(c)=="object"&&typeof((l=c==null?void 0:c.service)==null?void 0:l.displayText)=="boolean";return _context120.a(2,{files:[{src:"data:audio/wav;base64,".concat(e.choices[0].message.audio.data),type:"audio"}],text:d?e.choices[0].message.audio.transcript:void 0});case 4:return _context120.a(2,{text:e.choices[0].message.content});case 5:return _context120.a(2,{text:""});}},_callee120,this);}));function extractResultData(_x216,_x217){return _extractResultData23.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e,t){var _this58=this;var s,i,n;return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context121.n=1;break;}n={tool_calls:this._streamToolCalls};return _context121.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this58._streamToolCalls&&(_this58._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context121.a(2,{text:(s==null?void 0:s.content)||""});}},_callee121,this);}));function extractStreamResult(_x218,_x219){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e,t){var s,i,_yield$this$callToolF,n,o;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context122.n=1;break;}throw Error(_.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context122.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF=_context122.v;n=_yield$this$callToolF.responses;o=_yield$this$callToolF.processedResponse;if(!o){_context122.n=3;break;}return _context122.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref32){var a=_ref32.response;return typeof a!="string";})&&i.length===n.length)){_context122.n=4;break;}return _context122.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error(F.FUNCTION_TOOL_RESP_ERROR);case 5:return _context122.a(2);}},_callee122,this);}));function handleTools(_x220,_x221){return _handleTools2.apply(this,arguments);}return handleTools;}()}],[{key:"generateSystemMessage",value:function generateSystemMessage(e){return{role:"system",content:e};}},{key:"getFileContent",value:function getFileContent(e,t){return e.map(function(i){var n,o,a;if(i.type==="audio"&&t){var l=(n=i.src)==null?void 0:n.split(",")[1],c=((a=(o=i.src)==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1])||"wav";return{type:"input_audio",input_audio:{data:l,format:c}};}return{type:"image_url",image_url:{url:i.src}};});}},{key:"getContent",value:function getContent(e,t){if(e.files&&e.files.length>0){var _s6=lt.getFileContent(e.files,t);return e.text&&e.text.trim().length>0&&_s6.unshift({type:"text",text:e.text}),_s6;}return e.text;}}]);}(M);var Yi=/*#__PURE__*/function(_lt){function Yi(e){var _this59;_classCallCheck(this,Yi);var o,a,l,c,d,u,h;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.azure,i=((a=(o=t.azure)==null?void 0:o.openAI)==null?void 0:a.urlDetails)||{},n=(c=(l=t.azure)==null?void 0:l.openAI)==null?void 0:c.chat;if(_this59=_callSuper(this,Yi,[e,pe.buildKeyVerificationDetails(i),pe.buildHeaders,s,n]),_this59.permittedErrorPrefixes=[pe.URL_DETAILS_ERROR_MESSAGE],_this59.isTextInputDisabled=!1,_typeof(n)=="object"){var _ref33=(h=(u=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:u.openAI)==null?void 0:h.chat,f=_ref33.function_handler;f&&(_this59._functionHandler=f);}pe.validateURLDetails(i)?_this59.url=Yi.buildURL(i):(_this59.isTextInputDisabled=!0,_this59.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage({error:pe.URL_DETAILS_ERROR_MESSAGE});}));return _this59;}_inherits(Yi,_lt);return _createClass(Yi,null,[{key:"buildURL",value:function buildURL(e){var t=e.endpoint,s=e.deploymentId,i=e.version;return"".concat(t,"/openai/deployments/").concat(s,"/chat/completions?api-version=").concat(i);}}]);}(lt);var Us=/*#__PURE__*/function(_M15){function Us(e){var _this60$maxMessages,_c$model;var _this60;_classCallCheck(this,Us);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this60=_callSuper(this,Us,[e,Ye.buildKeyVerificationDetails(),Ye.buildHeaders,s]),_this60.insertKeyPlaceholderText="BigModel API Key",_this60.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this60.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this60.permittedErrorPrefixes=["Authorization","authentication_error"],_this60._systemMessage="You are a helpful assistant.";var i=(n=t.bigModel)==null?void 0:n.chat;if(_typeof(i)=="object"){i.system_prompt&&(_this60._systemMessage=i.system_prompt);var d=(l=(a=(o=e.directConnection)==null?void 0:o.bigModel)==null?void 0:a.chat)==null?void 0:l.function_handler;d&&(_this60._functionHandler=d),_this60.cleanConfig(i),Object.assign(_this60.rawBody,i);}(_this60$maxMessages=_this60.maxMessages)!==null&&_this60$maxMessages!==void 0?_this60$maxMessages:_this60.maxMessages=-1,(_c$model=(c=_this60.rawBody).model)!==null&&_c$model!==void 0?_c$model:c.model="glm-4.5";return _this60;}_inherits(Us,_M15);return _createClass(Us,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Us.getContent(n),role:n.role==="ai"?"assistant":"user"};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e,t){var _this$_messages4;var s,i;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:if(this.connectSettings){_context123.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages4=this._messages)!==null&&_this$_messages4!==void 0?_this$_messages4:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context123.a(2);}},_callee123,this);}));function callServiceAPI(_x222,_x223){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e,t){var _s7;return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:if(!e.error){_context124.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context124.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context124.n=2;break;}return _context124.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context124.n=3;break;}_s7=e.choices[0].message;return _context124.a(2,_s7.tool_calls?this.handleTools({tool_calls:_s7.tool_calls},t):{text:_s7.content});case 3:return _context124.a(2,{text:""});}},_callee124,this);}));function extractResultData(_x224,_x225){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(e,t){var o,a,l,c,s,i,n,d;return _regenerator().w(function(_context125){while(1)switch(_context125.n){case 0:s=e.delta,i=e.finish_reason,n=(o=this._messages)==null?void 0:o.messageToElements[this._messages.messageToElements.length-2];if(!((n==null?void 0:n[0].role)==="ai"&&((a=n==null?void 0:n[0].text)==null?void 0:a.replace(/\n/g,"").trim().length)===0&&((l=this._messages)==null||l.removeMessage(n[1].text),(c=this._messages)==null||c.messageToElements.splice(this._messages.messageToElements.length-2,1)),i==="tool_calls")){_context125.n=2;break;}if(!s.tool_calls){_context125.n=1;break;}d={tool_calls:s.tool_calls};return _context125.a(2,this.handleTools(d,t));case 1:return _context125.a(2,{text:(s==null?void 0:s.content)||""});case 2:return _context125.a(2,{text:(s==null?void 0:s.content)||""});}},_callee125,this);}));function extractStreamResult(_x226,_x227){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(e,t){var s,i,_yield$this$callToolF2,n,o;return _regenerator().w(function(_context126){while(1)switch(_context126.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context126.n=1;break;}throw Error(_.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context126.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF2=_context126.v;n=_yield$this$callToolF2.responses;o=_yield$this$callToolF2.processedResponse;if(!o){_context126.n=3;break;}return _context126.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref34){var a=_ref34.response;return typeof a!="string";})&&i.length===n.length)){_context126.n=4;break;}return _context126.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context126.a(2);}},_callee126,this);}));function handleTools(_x228,_x229){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t.type==="image"?{type:"image_url",image_url:{url:t.src||""}}:{type:"file",file_url:{url:t.src||""}};});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=Us.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t;}return e.text||"";}}]);}(M);var Ia=/*#__PURE__*/function(_M16){function Ia(e){var _this61$maxMessages,_o$model8;var _this61;_classCallCheck(this,Ia);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this61=_callSuper(this,Ia,[e,Ze.buildKeyVerificationDetails(),Ze.buildHeaders,s]),_this61.insertKeyPlaceholderText="Together AI API Key",_this61.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this61.url="https://api.together.xyz/v1/chat/completions",_this61.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this61._systemMessage="You are a helpful assistant.";var i=(n=t.together)==null?void 0:n.chat;_typeof(i)=="object"&&(i.system_prompt&&(_this61._systemMessage=i.system_prompt),_this61.cleanConfig(i),Object.assign(_this61.rawBody,i)),(_this61$maxMessages=_this61.maxMessages)!==null&&_this61$maxMessages!==void 0?_this61$maxMessages:_this61.maxMessages=-1,(_o$model8=(o=_this61.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this61;}_inherits(Ia,_M16);return _createClass(Ia,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role==="ai"?"assistant":n.role};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var s,i;return _regenerator().w(function(_context127){while(1)switch(_context127.n){case 0:if(this.connectSettings){_context127.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context127.a(2);}},_callee127,this);}));function callServiceAPI(_x230,_x231){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e){return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:if(!e.error){_context128.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context128.n=3;break;}if(!(e.choices[0].message!==void 0)){_context128.n=2;break;}return _context128.a(2,{text:e.choices[0].message.content});case 2:if(!(e.choices[0].delta!==void 0)){_context128.n=3;break;}return _context128.a(2,{text:e.choices[0].delta.content});case 3:return _context128.a(2,{text:""});}},_callee128);}));function extractResultData(_x232){return _extractResultData25.apply(this,arguments);}return extractResultData;}()}]);}(M);var be=/*#__PURE__*/function(_M17){function be(e){var _this62;_classCallCheck(this,be);var o;var t=e.directConnection,s=t==null?void 0:t.openAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};_this62=_callSuper(this,be,[e,F.buildKeyVerificationDetails(),F.buildHeaders,s,i]),_this62.insertKeyPlaceholderText="OpenAI API Key",_this62.keyHelpUrl="https://platform.openai.com/account/api-keys",_this62.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI DALL\xB7E</b></div>\n <p><b>Insert text</b> to generate an image.</p>\n <p><b>Upload 1</b> PNG image to generate its variation and optionally insert text to specify the change.</p>\n <p><b>Upload 2</b> PNG images where the second is a copy of the first with a transparent area where the edit should\n take place and text to specify the edit.</p>\n <p>Click <a href=\"https://platform.openai.com/docs/guides/images/introduction\" target=\"_blank\">here</a>\n for more info.</p>",_this62.url="",_this62.permittedErrorPrefixes=["Incorrect","Invalid input image"];var n=(o=t==null?void 0:t.openAI)==null?void 0:o.images;if(_this62.camera){var a=_typeof(n)=="object"&&n.size?Number.parseInt(n.size):1024;_this62.camera.files={dimensions:{width:a,height:a}};}_typeof(n)=="object"&&Object.assign(_this62.rawBody,n),_this62.canSendMessage=be.canFileSendMessage;return _this62;}_inherits(be,_M17);return _createClass(be,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}// prettier-ignore
|
210
|
-
},{key:"callApiWithImage",value:function callApiWithImage(e,t,s){var o,a;var i;var n=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim();if(s[1]||n&&n!==""){this.url=
|
208
|
+
function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.stringify(e)),i=(o=s.modalities)==null?void 0:o.includes("audio"),n=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(a){return{content:As.getContent(a,i),role:a.role===b.USER_ROLE?"user":"assistant"};});return t.find(function(a){return a.files&&a.files.length>0;})&&((_s$max_tokens=s.max_tokens)!==null&&_s$max_tokens!==void 0?_s$max_tokens:s.max_tokens=300),this._systemMessage&&n.unshift({role:"system",content:this._systemMessage}),s.messages=n,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e,t){var _this$_messages3;var s,i;return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:if(this.connectSettings){_context119.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages3=this._messages)!==null&&_this$_messages3!==void 0?_this$_messages3:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context119.a(2);}},_callee119,this);}));function callServiceAPI(_x214,_x215){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee120(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:if(!e.error){_context120.n=1;break;}throw e.error.message;case 1:if(!((i=(s=e.choices)==null?void 0:s[0])!=null&&i.delta)){_context120.n=2;break;}return _context120.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(n=e.choices)==null?void 0:n[0])!=null&&o.message)){_context120.n=5;break;}if(!e.choices[0].message.tool_calls){_context120.n=3;break;}return _context120.a(2,this.handleTools(e.choices[0].message,t));case 3:if(!((a=e.choices[0].message)!=null&&a.audio)){_context120.n=4;break;}c=this.deepChat.textToSpeech,d=_typeof(c)=="object"&&typeof((l=c==null?void 0:c.service)==null?void 0:l.displayText)=="boolean";return _context120.a(2,_defineProperty({files:[{src:"data:audio/wav;base64,".concat(e.choices[0].message.audio.data),type:"audio"}]},g,d?e.choices[0].message.audio.transcript:void 0));case 4:return _context120.a(2,_defineProperty({},g,e.choices[0].message.content));case 5:return _context120.a(2,_defineProperty({},g,""));}},_callee120,this);}));function extractResultData(_x216,_x217){return _extractResultData23.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e,t){var _this58=this;var s,i,n;return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context121.n=1;break;}n={tool_calls:this._streamToolCalls};return _context121.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this58._streamToolCalls&&(_this58._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context121.a(2,_defineProperty({},g,(s==null?void 0:s.content)||""));}},_callee121,this);}));function extractStreamResult(_x218,_x219){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e,t){var s,i,_yield$this$callToolF,n,o;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context122.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context122.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF=_context122.v;n=_yield$this$callToolF.responses;o=_yield$this$callToolF.processedResponse;if(!o){_context122.n=3;break;}return _context122.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref82){var a=_ref82.response;return typeof a!="string";})&&i.length===n.length)){_context122.n=4;break;}return _context122.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error(V.FUNCTION_TOOL_RESP_ERROR);case 5:return _context122.a(2);}},_callee122,this);}));function handleTools(_x220,_x221){return _handleTools2.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e,t){return e.map(function(i){var n,o,a;if(i.type==="audio"&&t){var l=(n=i.src)==null?void 0:n.split(",")[1],c=((a=(o=i.src)==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1])||"wav";return{type:"input_audio",input_audio:{data:l,format:c}};}return{type:"image_url",image_url:{url:i.src}};});}},{key:"getContent",value:function getContent(e,t){if(e.files&&e.files.length>0){var _s8=As.getFileContent(e.files,t);return e.text&&e.text.trim().length>0&&_s8.unshift(_defineProperty({type:"text"},g,e.text)),_s8;}return e.text;}}]);}(L);var mn=/*#__PURE__*/function(_As){function mn(e){var _this59;_classCallCheck(this,mn);var o,a,l,c,d,h,u;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.azure,i=((a=(o=t.azure)==null?void 0:o.openAI)==null?void 0:a.urlDetails)||{},n=(c=(l=t.azure)==null?void 0:l.openAI)==null?void 0:c.chat;if(_this59=_callSuper(this,mn,[e,Ce.buildKeyVerificationDetails(i),Ce.buildHeaders,s,n]),_this59.permittedErrorPrefixes=[Ce.URL_DETAILS_ERROR_MESSAGE],_this59.isTextInputDisabled=!1,_typeof(n)===S){var _ref83=(u=(h=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:h.openAI)==null?void 0:u.chat,f=_ref83.function_handler;f&&(_this59._functionHandler=f);}Ce.validateURLDetails(i)?_this59.url=mn.buildURL(i):(_this59.isTextInputDisabled=!0,_this59.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,Ce.URL_DETAILS_ERROR_MESSAGE));}));return _this59;}_inherits(mn,_As);return _createClass(mn,null,[{key:"buildURL",value:function buildURL(e){var t=e.endpoint,s=e.deploymentId,i=e.version;return"".concat(t,"/openai/deployments/").concat(s,"/chat/completions?api-version=").concat(i);}}]);}(As);var Qs=/*#__PURE__*/function(_L15){function Qs(e){var _this60$maxMessages,_c$model;var _this60;_classCallCheck(this,Qs);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this60=_callSuper(this,Qs,[e,ct.buildKeyVerificationDetails(),ct.buildHeaders,s]),_this60.insertKeyPlaceholderText=_this60.genereteAPIKeyName("BigModel"),_this60.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this60.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this60.permittedErrorPrefixes=[K,te],_this60._systemMessage="";var i=(n=t.bigModel)==null?void 0:n.chat;if(_typeof(i)===S){i.system_prompt&&(_this60._systemMessage=i.system_prompt);var d=(l=(a=(o=e.directConnection)==null?void 0:o.bigModel)==null?void 0:a.chat)==null?void 0:l.function_handler;d&&(_this60._functionHandler=d),_this60.cleanConfig(i),Object.assign(_this60.rawBody,i);}(_this60$maxMessages=_this60.maxMessages)!==null&&_this60$maxMessages!==void 0?_this60$maxMessages:_this60.maxMessages=-1,(_c$model=(c=_this60.rawBody).model)!==null&&_c$model!==void 0?_c$model:c.model="glm-4.5";return _this60;}_inherits(Qs,_L15);return _createClass(Qs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Qs.getContent(n),role:n.role==="ai"?"assistant":"user"};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e,t){var _this$_messages4;var s,i;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:if(this.connectSettings){_context123.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages4=this._messages)!==null&&_this$_messages4!==void 0?_this$_messages4:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context123.a(2);}},_callee123,this);}));function callServiceAPI(_x222,_x223){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e,t){var _s9;return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:if(!e.error){_context124.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context124.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context124.n=2;break;}return _context124.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context124.n=3;break;}_s9=e.choices[0].message;return _context124.a(2,_s9.tool_calls?this.handleTools({tool_calls:_s9.tool_calls},t):_defineProperty({},g,_s9.content));case 3:return _context124.a(2,_defineProperty({},g,""));}},_callee124,this);}));function extractResultData(_x224,_x225){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(e,t){var o,a,l,c,s,i,n,d;return _regenerator().w(function(_context125){while(1)switch(_context125.n){case 0:s=e.delta,i=e.finish_reason,n=(o=this._messages)==null?void 0:o.messageToElements[this._messages.messageToElements.length-2];if(!((n==null?void 0:n[0].role)==="ai"&&((a=n==null?void 0:n[0].text)==null?void 0:a.replace(/\n/g,"").trim().length)===0&&((l=this._messages)==null||l.removeMessage(n[1].text),(c=this._messages)==null||c.messageToElements.splice(this._messages.messageToElements.length-2,1)),i==="tool_calls")){_context125.n=2;break;}if(!s.tool_calls){_context125.n=1;break;}d={tool_calls:s.tool_calls};return _context125.a(2,this.handleTools(d,t));case 1:return _context125.a(2,_defineProperty({},g,(s==null?void 0:s.content)||""));case 2:return _context125.a(2,_defineProperty({},g,(s==null?void 0:s.content)||""));}},_callee125,this);}));function extractStreamResult(_x226,_x227){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(e,t){var s,i,_yield$this$callToolF2,n,o;return _regenerator().w(function(_context126){while(1)switch(_context126.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context126.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context126.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF2=_context126.v;n=_yield$this$callToolF2.responses;o=_yield$this$callToolF2.processedResponse;if(!o){_context126.n=3;break;}return _context126.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref88){var a=_ref88.response;return typeof a!="string";})&&i.length===n.length)){_context126.n=4;break;}return _context126.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context126.a(2);}},_callee126,this);}));function handleTools(_x228,_x229){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t.type==="image"?{type:"image_url",image_url:{url:t.src||""}}:{type:"file",file_url:{url:t.src||""}};});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=Qs.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},g,e.text)),t;}return e.text||"";}}]);}(L);var Qa=/*#__PURE__*/function(_L16){function Qa(e){var _this61$maxMessages,_o$model8;var _this61;_classCallCheck(this,Qa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this61=_callSuper(this,Qa,[e,dt.buildKeyVerificationDetails(),dt.buildHeaders,s]),_this61.insertKeyPlaceholderText=_this61.genereteAPIKeyName("Together AI"),_this61.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this61.url="https://api.together.xyz/v1/chat/completions",_this61.permittedErrorPrefixes=[Ae,te],_this61._systemMessage="";var i=(n=t.together)==null?void 0:n.chat;_typeof(i)===S&&(i.system_prompt&&(_this61._systemMessage=i.system_prompt),_this61.cleanConfig(i),Object.assign(_this61.rawBody,i)),(_this61$maxMessages=_this61.maxMessages)!==null&&_this61$maxMessages!==void 0?_this61$maxMessages:_this61.maxMessages=-1,(_o$model8=(o=_this61.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this61;}_inherits(Qa,_L16);return _createClass(Qa,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role==="ai"?"assistant":n.role};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var s,i;return _regenerator().w(function(_context127){while(1)switch(_context127.n){case 0:if(this.connectSettings){_context127.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context127.a(2);}},_callee127,this);}));function callServiceAPI(_x230,_x231){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e){return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:if(!e.error){_context128.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context128.n=3;break;}if(!(e.choices[0].message!==void 0)){_context128.n=2;break;}return _context128.a(2,_defineProperty({},g,e.choices[0].message.content));case 2:if(!(e.choices[0].delta!==void 0)){_context128.n=3;break;}return _context128.a(2,_defineProperty({},g,e.choices[0].delta.content));case 3:return _context128.a(2,_defineProperty({},g,""));}},_callee128);}));function extractResultData(_x232){return _extractResultData25.apply(this,arguments);}return extractResultData;}()}]);}(L);var Me=/*#__PURE__*/function(_L17){function Me(e){var _this62;_classCallCheck(this,Me);var o;var t=e.directConnection,s=t==null?void 0:t.openAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};_this62=_callSuper(this,Me,[e,V.buildKeyVerificationDetails(),V.buildHeaders,s,i]),_this62.insertKeyPlaceholderText=_this62.genereteAPIKeyName("OpenAI"),_this62.keyHelpUrl="https://platform.openai.com/account/api-keys",_this62.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI DALL\xB7E</b></div>\n <p><b>Insert text</b> to generate an image.</p>\n <p><b>Upload 1</b> PNG image to generate its variation and optionally insert text to specify the change.</p>\n <p><b>Upload 2</b> PNG images where the second is a copy of the first with a transparent area where the edit should\n take place and text to specify the edit.</p>\n <p>Click <a href=\"https://platform.openai.com/docs/guides/images/introduction\" target=\"_blank\">here</a>\n for more info.</p>",_this62.url="",_this62.permittedErrorPrefixes=[Is,"Invalid input image"];var n=(o=t==null?void 0:t.openAI)==null?void 0:o.images;if(_this62.camera){var a=_typeof(n)=="object"&&n.size?Number.parseInt(n.size):1024;_this62.camera.files={dimensions:{width:a,height:a}};}_typeof(n)===S&&Object.assign(_this62.rawBody,n),_this62.canSendMessage=Me.canFileSendMessage;return _this62;}_inherits(Me,_L17);return _createClass(Me,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}// prettier-ignore
|
209
|
+
},{key:"callApiWithImage",value:function callApiWithImage(e,t,s){var o,a;var i;var n=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim();if(s[1]||n&&n!==""){this.url=Me.IMAGE_EDIT_URL;var l=this.preprocessBody(this.rawBody,n);i=Me.createFormDataBody(l,s[0],s[1]);}else this.url=Me.IMAGE_VARIATIONS_URL,i=Me.createFormDataBody(this.rawBody,s[0]);M.tempRemoveContentHeader(this.connectSettings,w.request.bind(this,this,i,e),!1);}},{key:"callServiceAPI",value:function(){var _callServiceAPI23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e,t,s){var i,n;return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context129.n=1;break;}throw new Error("Request settings have not been set up");case 1:if(!(s!=null&&s[0])){_context129.n=2;break;}this.callApiWithImage(e,t,s);_context129.n=4;break;case 2:if(this.connectSettings){_context129.n=3;break;}throw new Error("Request settings have not been set up");case 3:this.url=Me.IMAGE_GENERATION_URL;n=this.preprocessBody(this.rawBody,t[t.length-1].text);w.request(this,n,e);case 4:return _context129.a(2);}},_callee129,this);}));function callServiceAPI(_x233,_x234,_x235){return _callServiceAPI23.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(e){return _regenerator().w(function(_context130){while(1)switch(_context130.n){case 0:if(!e.error){_context130.n=1;break;}throw e.error.message;case 1:return _context130.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(Ht).concat(s.b64_json),type:"image"};})});}},_callee130);}));function extractResultData(_x236){return _extractResultData26.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
|
211
210
|
// 1 image:
|
212
211
|
// - With text - edits image based on the text
|
213
212
|
// - No text - creates a variation of the image
|
@@ -216,42 +215,42 @@ function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.strin
|
|
216
215
|
// Add text to describe the required modification.
|
217
216
|
// Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
|
218
217
|
// `;
|
219
|
-
}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("image",t),s&&i.append("mask",s),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i;}}]);}(
|
220
|
-
},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t){var s,i,_yield$this$callToolF3,n,o;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context134.n=1;break;}throw Error(
|
221
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){typeof e.message=="string"?i(_.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.cohere.ai/v1/models",method:"GET",handleVerificationResult:Hs.handleVerificationResult};}}]);}();var Oa=/*#__PURE__*/function(_M19){function Oa(e,t,s,i,n){var _this65;_classCallCheck(this,Oa);_this65=_callSuper(this,Oa,[e,Hs.buildKeyVerificationDetails(),Hs.buildHeaders,n]),_this65.insertKeyPlaceholderText="Cohere API Key",_this65.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this65.permittedErrorPrefixes=["invalid"],_this65.url=t,_this65.textInputPlaceholderText=s,i&&_typeof(i)=="object"&&Object.assign(_this65.rawBody,i);return _this65;}_inherits(Oa,_M19);return _createClass(Oa);}(M);var qs=/*#__PURE__*/function(_Oa){function qs(e){var _this66$maxMessages;var _this66;_classCallCheck(this,qs);var s=JSON.parse(JSON.stringify(e.directConnection)).cohere;if(_this66=_callSuper(this,qs,[e,"https://api.cohere.com/v2/chat","Ask me anything!",{},s]),_typeof(s)=="object"){var i=Y.processCohere(s);_this66.canSendMessage=function(){return i;},_this66.cleanConfig(s),Object.assign(_this66.rawBody,s);}(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1;return _this66;}_inherits(qs,_Oa);return _createClass(qs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t.filter(function(n){return n.text;});return s.messages=i.map(function(n){return{role:n.role==="ai"?"assistant":"user",content:n.text};}),s.model=s.model||"command-a-03-2025",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e,t){var s,i;return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:if(this.connectSettings){_context135.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,this.stream={readable:!0},E.request(this,s,e)):x.request(this,s,e);case 2:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x245,_x246){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e){var t,s,i,n;return _regenerator().w(function(_context136){while(1)switch(_context136.n){case 0:if(!(typeof e.message=="string")){_context136.n=1;break;}throw e.message;case 1:if(!(this.stream&&e.text)){_context136.n=2;break;}n=qs.parseBundledEvents(e.text);return _context136.a(2,{text:qs.aggregateBundledEventsText(n)});case 2:if(!("message"in e&&(i=(s=(t=e.message)==null?void 0:t.content)==null?void 0:s[0])!=null&&i.text)){_context136.n=3;break;}return _context136.a(2,{text:e.message.content[0].text});case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context136.a(2);}},_callee136,this);}));function extractResultData(_x247){return _extractResultData28.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),s=[];var _iterator2=_createForOfIteratorHelper(t),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var i=_step2.value;if(i.trim())try{var n=JSON.parse(i);s.push(n);}catch(n){console.error("Failed to parse line:",i,n);}}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return s;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var s,i,n;return t.type==="content-delta"&&((n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text);}).map(function(t){var s,i,n;return(n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text;}).join("");}}]);}(Oa);var Vs=/*#__PURE__*/function(){function Vs(){_classCallCheck(this,Vs);}return _createClass(Vs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(_.INVALID_KEY):i(_.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:"GET",handleVerificationResult:Vs.handleVerificationResult};}}]);}();var Na=/*#__PURE__*/function(_M20){function Na(e){var _this67$maxMessages,_i$model,_n$temperature,_o$max_tokens;var _this67;_classCallCheck(this,Na);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).deepSeek;_this67=_callSuper(this,Na,[e,Vs.buildKeyVerificationDetails(),Vs.buildHeaders,s]),_this67.insertKeyPlaceholderText="DeepSeek API Key",_this67.keyHelpUrl="https://platform.deepseek.com/api_keys",_this67.url="https://api.deepseek.com/v1/chat/completions",_this67.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this67._systemMessage="You are a helpful assistant.",_typeof(s)=="object"&&(s.system_prompt&&(_this67._systemMessage=s.system_prompt),_this67.cleanConfig(s),Object.assign(_this67.rawBody,s)),(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1,(_i$model=(i=_this67.rawBody).model)!==null&&_i$model!==void 0?_i$model:i.model="deepseek-chat",(_n$temperature=(n=_this67.rawBody).temperature)!==null&&_n$temperature!==void 0?_n$temperature:n.temperature=1,(_o$max_tokens=(o=_this67.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this67;}_inherits(Na,_M20);return _createClass(Na,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e,t){var s,i;return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:if(this.connectSettings){_context137.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context137.a(2);}},_callee137,this);}));function callServiceAPI(_x248,_x249){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(e){var t;return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:if(!e.error){_context138.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context138.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context138.n=2;break;}return _context138.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context138.n=3;break;}return _context138.a(2,{text:t.message.content});case 3:return _context138.a(2,{text:""});}},_callee138);}));function extractResultData(_x250){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(M);var zs=/*#__PURE__*/function(){function zs(){_classCallCheck(this,zs);}return _createClass(zs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.error?i(_.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.perplexity.ai/chat/completions",method:"POST",handleVerificationResult:zs.handleVerificationResult};}}]);}();var Pa=/*#__PURE__*/function(_M21){function Pa(e){var _this68$maxMessages,_i$model2;var _this68;_classCallCheck(this,Pa);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).perplexity;_this68=_callSuper(this,Pa,[e,zs.buildKeyVerificationDetails(),zs.buildHeaders,s]),_this68.insertKeyPlaceholderText="Perplexity API Key",_this68.keyHelpUrl="https://www.perplexity.ai/settings/api",_this68.url="https://api.perplexity.ai/chat/completions",_this68.permittedErrorPrefixes=["Invalid","Authentication","Permission denied"],_this68._systemMessage="You are a helpful assistant.",_typeof(s)=="object"&&(s.system_prompt&&(_this68._systemMessage=s.system_prompt),_this68.cleanConfig(s),Object.assign(_this68.rawBody,s)),(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_i$model2=(i=_this68.rawBody).model)!==null&&_i$model2!==void 0?_i$model2:i.model="sonar";return _this68;}_inherits(Pa,_M21);return _createClass(Pa,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(e,t){var s,i;return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:if(this.connectSettings){_context139.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context139.a(2);}},_callee139,this);}));function callServiceAPI(_x251,_x252){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e){var t;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:if(!e.error){_context140.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context140.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context140.n=2;break;}return _context140.a(2,{text:t.delta.content});case 2:if(!(t.message&&t.message.content)){_context140.n=3;break;}return _context140.a(2,{text:t.message.content});case 3:return _context140.a(2,{text:""});}},_callee140);}));function extractResultData(_x253){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(M);var Gs=/*#__PURE__*/function(){function Gs(){_classCallCheck(this,Gs);}return _createClass(Gs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var o;((o=e.base_resp)==null?void 0:o.status_code)===1004?i(_.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.minimax.io/v1/files/delete",method:"POST",handleVerificationResult:Gs.handleVerificationResult};}}]);}();var Da=/*#__PURE__*/function(_M22){function Da(e){var _this69$maxMessages,_i$model3;var _this69;_classCallCheck(this,Da);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).miniMax;_this69=_callSuper(this,Da,[e,Gs.buildKeyVerificationDetails(),Gs.buildHeaders,s]),_this69.insertKeyPlaceholderText="MiniMax API Key",_this69.keyHelpUrl="https://www.minimaxi.com",_this69.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this69.permittedErrorPrefixes=["invalid_request_error","authentication_error","insufficient balance"],_this69._systemMessage="You are a helpful assistant.",_typeof(s)=="object"&&(s.system_prompt&&(_this69._systemMessage=s.system_prompt),_this69.cleanConfig(s),Object.assign(_this69.rawBody,s)),(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_i$model3=(i=_this69.rawBody).model)!==null&&_i$model3!==void 0?_i$model3:i.model="MiniMax-M1";return _this69;}_inherits(Da,_M22);return _createClass(Da,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){var s,i;return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:if(this.connectSettings){_context141.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context141.a(2);}},_callee141,this);}));function callServiceAPI(_x254,_x255){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e){var t,_s8;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:if(!e.error){_context142.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context142.n=3;break;}_s8=e.choices[0];if(!(_s8.delta&&_s8.delta.content)){_context142.n=2;break;}return _context142.a(2,{text:_s8.delta.content});case 2:if(!(_s8.message&&_s8.message.content)){_context142.n=3;break;}return _context142.a(2,{text:_s8.message.content});case 3:if(!(typeof((t=e.base_resp)==null?void 0:t.status_code)=="number"&&e.base_resp.status_code>0)){_context142.n=4;break;}throw e.base_resp.status_msg;case 4:return _context142.a(2,{text:""});}},_callee142);}));function extractResultData(_x256){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(M);var Ks=/*#__PURE__*/function(){function Ks(){_classCallCheck(this,Ks);}return _createClass(Ks,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json",accept:"application/json"};}// prettier-ignore
|
222
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.detail?i(
|
223
|
-
},{key:"handleTools",value:function(){var _handleTools5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){var s,i,_yield$this$callToolF4,n,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(
|
224
|
-
},{key:"handleTools",value:function(){var _handleTools6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){var s,i,_yield$this$callToolF5,n,o;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context150.n=1;break;}throw Error(
|
225
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var o;var n=e;n.error?n.error.code===403||(o=n.error.message)!=null&&o.includes("API key")?i(
|
226
|
-
},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){var e="https://generativelanguage.googleapis.com/v1beta/models?key=";return{url:e,augmentUrl:function augmentUrl(t){return"".concat(e).concat(t);},method:
|
227
|
-
function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=
|
228
|
-
},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:if(!e.error){_context152.n=1;break;}throw e.error.message||"Gemini API Error";case 1:if(!((n=(i=(s=e.candidates)==null?void 0:s[0])==null?void 0:i.content)!=null&&n.parts)){_context152.n=3;break;}a=e.candidates[0].content.parts,l=a.find(function(u){return u.functionCall;});if(!(l!=null&&l.functionCall)){_context152.n=2;break;}return _context152.a(2,this.handleTools([l.functionCall],t));case 2:c=a.find(function(u){return u.text;}),d=a.find(function(u){var h;return((h=u.inlineData)==null?void 0:h.mimeType)==="image/png";});return _context152.a(2,{text:(c==null?void 0:c.text)||"",files:(o=d==null?void 0:d.inlineData)!=null&&o.data?[{src:"data:image/png;base64,".concat(d.inlineData.data)}]:[]});case 3:return _context152.a(2,{text:""});}},_callee152,this);}));function extractResultData(_x275,_x276){return _extractResultData34.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var s,i,_yield$this$callToolF6,n,o,a,l;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:if(!(!e||!t||!this._functionHandler)){_context153.n=1;break;}throw Error(_.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.map(function(l){return{name:l.name,arguments:JSON.stringify(l.args)};});_context153.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF6=_context153.v;n=_yield$this$callToolF6.responses;o=_yield$this$callToolF6.processedResponse;if(!o){_context153.n=3;break;}return _context153.a(2,o);case 3:a={parts:e.map(function(l){return{functionCall:{name:l.name,args:l.args}};}),role:"model"};if(!(s.contents.push(a),!n.find(function(_ref39){var l=_ref39.response;return typeof l!="string";})&&i.length===n.length)){_context153.n=4;break;}l={parts:n.map(function(c,d){return{functionResponse:{name:e[d].name,response:{result:c.response}}};}),role:"user"};return _context153.a(2,(s.contents.push(l),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context153.a(2);}},_callee153,this);}));function handleTools(_x277,_x278){return _handleTools7.apply(this,arguments);}return handleTools;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e.text&&e.text.trim().length>0&&t.push({text:e.text}),e.files&&e.files.length>0&&e.files.forEach(function(s){if(s.src&&s.src.includes("data:")){var _s$src$split=s.src.split(","),_s$src$split2=_slicedToArray(_s$src$split,2),i=_s$src$split2[0],n=_s$src$split2[1];t.push({inlineData:{mimeType:i.replace("data:","").replace(";base64",""),data:n}});}}),{parts:t,role:e.role===y.USER_ROLE?"user":"model"};}}]);}(M);var Xs=/*#__PURE__*/function(){function Xs(){_classCallCheck(this,Xs);}return _createClass(Xs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{"x-api-key":e,"Content-Type":"application/json","anthropic-version":"2023-06-01","anthropic-dangerous-direct-browser-access":"true"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(_.INVALID_KEY):i(_.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/models",method:"GET",handleVerificationResult:Xs.handleVerificationResult};}}]);}();var Ys=/*#__PURE__*/function(_M26){function Ys(e){var _this74$maxMessages,_o$model1,_a$max_tokens2;var _this74;_classCallCheck(this,Ys);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).claude;if(_this74=_callSuper(this,Ys,[e,Xs.buildKeyVerificationDetails(),Xs.buildHeaders,s]),_this74.insertKeyPlaceholderText="Claude API Key",_this74.keyHelpUrl="https://console.anthropic.com/settings/keys",_this74.url="https://api.anthropic.com/v1/messages",_this74.permittedErrorPrefixes=["authentication_error","invalid_request_error"],_this74._streamToolCalls={type:"tool_use",id:"",name:"",input:""},_this74._systemMessage="You are a helpful assistant.",_typeof(s)=="object"){s.system_prompt&&(_this74._systemMessage=s.system_prompt);var l=(n=(i=e.directConnection)==null?void 0:i.claude)==null?void 0:n.function_handler;l&&(_this74._functionHandler=l),_this74.cleanConfig(s),Object.assign(_this74.rawBody,s);}(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_o$model1=(o=_this74.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="claude-3-5-sonnet-20241022",(_a$max_tokens2=(a=_this74.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this74;}_inherits(Ys,_M26);return _createClass(Ys,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Ys.getContent(n),role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=i,this._systemMessage&&(s.system=this._systemMessage),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var _this$_messages9;var s,i;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:if(this.connectSettings){_context154.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages9=this._messages)!==null&&_this$_messages9!==void 0?_this$_messages9:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context154.a(2);}},_callee154,this);}));function callServiceAPI(_x279,_x280){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e,t){var s,i,n,o,a;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:if(!e.error){_context155.n=1;break;}throw e.error.message;case 1:if(!(e.content&&e.content.length>0)){_context155.n=3;break;}o=e.content.find(function(l){return l.type==="tool_use";});if(!o){_context155.n=2;break;}return _context155.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(l){return l.type==="text";});if(!a){_context155.n=3;break;}return _context155.a(2,{text:a.text});case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context155.n=4;break;}return _context155.a(2,{text:e.delta.text||""});case 4:if(!(e.type==="content_block_start"&&((s=e.content_block)==null?void 0:s.type)==="tool_use")){_context155.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context155.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((i=e.delta)==null?void 0:i.type)==="input_json_delta")){_context155.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context155.n=7;break;case 6:if(!(e.type==="message_delta"&&((n=e.delta)==null?void 0:n.stop_reason)==="tool_use")){_context155.n=7;break;}return _context155.a(2,(this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t)));case 7:return _context155.a(2,{text:""});}},_callee155,this);}));function extractResultData(_x281,_x282){return _extractResultData35.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var s,i,_yield$this$callToolF7,n,o,a,l;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(!(!e||!t||!this._functionHandler)){_context156.n=1;break;}throw Error(_.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.map(function(l){return{name:l.name,arguments:JSON.stringify(l.input)};});_context156.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF7=_context156.v;n=_yield$this$callToolF7.responses;o=_yield$this$callToolF7.processedResponse;if(!o){_context156.n=3;break;}return _context156.a(2,o);case 3:a=e.map(function(l){return{type:"tool_use",id:l.id,name:l.name,input:l.input};});if(!(s.messages.push({role:"assistant",content:a}),!n.find(function(_ref40){var l=_ref40.response;return typeof l!="string";})&&i.length===n.length)){_context156.n=4;break;}l=n.map(function(c,d){return{type:"tool_result",tool_use_id:e[d].id,content:c.response};});return _context156.a(2,(s.messages.push({role:"user",content:l}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context156.a(2);}},_callee156,this);}));function handleTools(_x283,_x284){return _handleTools8.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var s,i,n;if(t.type==="image"){var o=(s=t.src)==null?void 0:s.split(",")[1];return{type:"image",source:{type:"base64",media_type:((n=(i=t.src)==null?void 0:i.match(/data:([^;]+)/))==null?void 0:n[1])||"image/jpeg",data:o||""}};}return{type:"text",text:"[Unsupported file type: ".concat(t.type,"]")};});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=Ys.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t;}return e.text||"";}}]);}(M);var wn=/*#__PURE__*/function(){function wn(){_classCallCheck(this,wn);}return _createClass(wn,null,[{key:"buildHeaders",value:function buildHeaders(){return{};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"",method:"GET",handleVerificationResult:function handleVerificationResult(){}};}}]);}();var Zs=/*#__PURE__*/function(_M27){function Zs(e){var _this75$maxMessages,_l$model2,_c$stream;var _this75;_classCallCheck(this,Zs);var o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=wn.buildKeyVerificationDetails(),i=wn.buildHeaders;_this75=_callSuper(this,Zs,[e,s,i,{key:"placeholder"}]),_this75.insertKeyPlaceholderText="",_this75.keyHelpUrl="",_this75.validateKeyProperty=!1,_this75.url="http://localhost:11434/api/chat",_this75.permittedErrorPrefixes=["Error"];var n=t.ollama;if(_typeof(n)=="object"){n.system&&(_this75._systemMessage=Zs.generateSystemMessage(n.system));var d=(a=(o=e.directConnection)==null?void 0:o.ollama)==null?void 0:a.function_handler;d&&(_this75._functionHandler=d),_this75.cleanConfig(n),Object.assign(_this75.rawBody,n);}(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1,(_l$model2=(l=_this75.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="llama3.2",(_c$stream=(c=_this75.rawBody).stream)!==null&&_c$stream!==void 0?_c$stream:c.stream=!1;return _this75;}_inherits(Zs,_M27);return _createClass(Zs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system,delete e.function_handler;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemMessage)==null?void 0:n.content.length)||0):-1).map(function(o){var a={content:o.text||"",role:o.role===y.USER_ROLE?"user":"assistant"};if(o.files&&o.files.length>0){var l=Zs.getImageData(o.files);l.length>0&&(a.images=l);}return a;});return s.messages=_toConsumableArray(i),this._systemMessage&&s.messages.unshift(this._systemMessage),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var _this$_messages0;var s,i;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(this.connectSettings){_context157.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages0=this._messages)!==null&&_this$_messages0!==void 0?_this$_messages0:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,this.stream={readable:!0},E.request(this,s,e)):x.request(this,s,e);case 2:return _context157.a(2);}},_callee157,this);}));function callServiceAPI(_x285,_x286){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){var s,i,n;return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:if(!e.error){_context158.n=1;break;}throw e.error.message;case 1:if(!e.text){_context158.n=2;break;}n=JSON.parse(e.text);return _context158.a(2,(s=n.message)!=null&&s.tool_calls?this.handleTools({tool_calls:n.message.tool_calls},t):{text:((i=n.message)==null?void 0:i.content)||""});case 2:return _context158.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):{text:e.message.content||""}:{text:""});}},_callee158,this);}));function extractResultData(_x287,_x288){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e,t){var s,i,_yield$this$callToolF8,n,o;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context159.n=1;break;}throw Error(_.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:JSON.stringify(a["function"].arguments)};});_context159.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF8=_context159.v;n=_yield$this$callToolF8.responses;o=_yield$this$callToolF8.processedResponse;if(!o){_context159.n=3;break;}return _context159.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:""}),!n.find(function(_ref41){var a=_ref41.response;return typeof a!="string";})&&i.length===n.length)){_context159.n=4;break;}return _context159.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context159.a(2);}},_callee159,this);}));function handleTools(_x289,_x290){return _handleTools9.apply(this,arguments);}return handleTools;}()}],[{key:"generateSystemMessage",value:function generateSystemMessage(e){return{role:"system",content:e};}},{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t.type==="image";}).map(function(t){var i;return((i=t.src)==null?void 0:i.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(M);var Tt=/*#__PURE__*/function(){function Tt(){_classCallCheck(this,Tt);}return _createClass(Tt,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"||n.error.type==="invalid_request_error"?i(_.INVALID_KEY):i(_.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.x.ai/v1/models",method:"GET",handleVerificationResult:Tt.handleVerificationResult};}}]);}();var hi=/*#__PURE__*/function(_M28){function hi(e){var _o$model10;var _this76;_classCallCheck(this,hi);var n,o;var t=e.directConnection,s=t==null?void 0:t.x;_this76=_callSuper(this,hi,[e,Tt.buildKeyVerificationDetails(),Tt.buildHeaders,s]),_this76.insertKeyPlaceholderText="X API Key",_this76.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this76.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>X Image Generation</b></div>\n <p><b>Insert text</b> to generate an image.</p>\n <p>Click <a target=\"_blank\" href=\"https://docs.x.ai/docs/api-reference#image-generations\" target=\"_blank\">\n here</a> for more info.</p>",_this76.url=hi.IMAGE_GENERATION_URL,_this76.permittedErrorPrefixes=["invalid_request_error","authentication_error"];var i=(n=t==null?void 0:t.x)==null?void 0:n.images;_typeof(i)=="object"&&Object.assign(_this76.rawBody,i),(_o$model10=(o=_this76.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="grok-2-image";return _this76;}_inherits(hi,_M28);return _createClass(hi,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e,t){var i,s;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context160.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t[t.length-1].text);x.request(this,s,e);case 2:return _context160.a(2);}},_callee160,this);}));function callServiceAPI(_x291,_x292){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e){return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(!e.error){_context161.n=1;break;}throw e.error.message;case 1:return _context161.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(Rt).concat(s.b64_json),type:"image"};})});}},_callee161);}));function extractResultData(_x293){return _extractResultData37.apply(this,arguments);}return extractResultData;}()}]);}(M);hi.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Hi=hi;var Qs=/*#__PURE__*/function(){function Qs(){_classCallCheck(this,Qs);}return _createClass(Qs,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="invalid_request_error"?i(_.INVALID_KEY):i(_.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",method:"GET",handleVerificationResult:Qs.handleVerificationResult};}}]);}();var ei=/*#__PURE__*/function(_M29){function ei(e){var _this77$maxMessages,_o$model11;var _this77;_classCallCheck(this,ei);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).qwen;if(_this77=_callSuper(this,ei,[e,Qs.buildKeyVerificationDetails(),Qs.buildHeaders,s]),_this77.insertKeyPlaceholderText="Qwen API Key",_this77.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this77.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this77.permittedErrorPrefixes=["No static","The model","Incorrect"],_this77._systemMessage="You are a helpful assistant.",_typeof(s)=="object"){s.system_prompt&&(_this77._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.qwen)==null?void 0:n.function_handler;a&&(_this77._functionHandler=a),_this77.cleanConfig(s),Object.assign(_this77.rawBody,s);}(_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="qwen-plus";return _this77;}_inherits(ei,_M29);return _createClass(ei,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:ei.getContent(n),role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){var _this$_messages1;var s,i;return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:if(this.connectSettings){_context162.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages1=this._messages)!==null&&_this$_messages1!==void 0?_this$_messages1:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context162.a(2);}},_callee162,this);}));function callServiceAPI(_x294,_x295){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee163(e,t){var _s0;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:if(!e.error){_context163.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context163.n=3;break;}_s0=e.choices[0];if(!_s0.delta){_context163.n=2;break;}return _context163.a(2,this.extractStreamResult(_s0,t));case 2:if(!_s0.message){_context163.n=3;break;}return _context163.a(2,_s0.message.tool_calls?this.handleTools({tool_calls:_s0.message.tool_calls},t):{text:_s0.message.content||""});case 3:return _context163.a(2,{text:""});}},_callee163,this);}));function extractResultData(_x296,_x297){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var _this78=this;var s,i,n;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context164.n=1;break;}n={tool_calls:this._streamToolCalls};return _context164.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this78._streamToolCalls&&(_this78._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context164.a(2,{text:(s==null?void 0:s.content)||""});}},_callee164,this);}));function extractStreamResult(_x298,_x299){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){var s,i,_yield$this$callToolF9,n,o;return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context165.n=1;break;}throw Error(_.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context165.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF9=_context165.v;n=_yield$this$callToolF9.responses;o=_yield$this$callToolF9.processedResponse;if(!o){_context165.n=3;break;}return _context165.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref42){var a=_ref42.response;return typeof a!="string";})&&i.length===n.length)){_context165.n=4;break;}return _context165.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context165.a(2);}},_callee165,this);}));function handleTools(_x300,_x301){return _handleTools0.apply(this,arguments);}return handleTools;}()}],[{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type==="image";}).map(function(t){return{type:"image_url",image_url:{url:t.src||""}};}).filter(function(t){return t.image_url.url.length>0;});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=ei.getImageContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t.length>0?t:e.text||"";}return e.text||"";}}]);}(M);var ti=/*#__PURE__*/function(){function ti(){_classCallCheck(this,ti);}return _createClass(ti,null,[{key:"buildHeaders",value:function buildHeaders(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"};}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type==="authentication_error"?i(_.INVALID_KEY):i(_.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:"GET",handleVerificationResult:ti.handleVerificationResult};}}]);}();var si=/*#__PURE__*/function(_M30){function si(e){var _this79$maxMessages,_o$model12;var _this79;_classCallCheck(this,si);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).kimi;if(_this79=_callSuper(this,si,[e,ti.buildKeyVerificationDetails(),ti.buildHeaders,s]),_this79.insertKeyPlaceholderText="Kimi AI API Key",_this79.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this79.url="https://api.moonshot.ai/v1/chat/completions",_this79.permittedErrorPrefixes=["Invalid","Not found"],_this79._systemMessage="You are Kimi, a helpful assistant created by Moonshot AI.",_typeof(s)=="object"){s.system_prompt&&(_this79._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.kimi)==null?void 0:n.function_handler;a&&(_this79._functionHandler=a),_this79.cleanConfig(s),Object.assign(_this79.rawBody,s);}(_this79$maxMessages=_this79.maxMessages)!==null&&_this79$maxMessages!==void 0?_this79$maxMessages:_this79.maxMessages=-1,(_o$model12=(o=_this79.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="moonshot-v1-8k";return _this79;}_inherits(si,_M30);return _createClass(si,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:si.getContent(n),role:n.role===y.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee166(e,t){var _this$_messages10;var s,i;return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:if(this.connectSettings){_context166.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages10=this._messages)!==null&&_this$_messages10!==void 0?_this$_messages10:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context166.a(2);}},_callee166,this);}));function callServiceAPI(_x302,_x303){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e,t){var _s1;return _regenerator().w(function(_context167){while(1)switch(_context167.n){case 0:if(!e.error){_context167.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context167.n=3;break;}_s1=e.choices[0];if(!_s1.delta){_context167.n=2;break;}return _context167.a(2,this.extractStreamResult(_s1,t));case 2:if(!_s1.message){_context167.n=3;break;}return _context167.a(2,_s1.message.tool_calls?this.handleTools({tool_calls:_s1.message.tool_calls},t):{text:_s1.message.content||""});case 3:return _context167.a(2,{text:""});}},_callee167,this);}));function extractResultData(_x304,_x305){return _extractResultData39.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){var _this80=this;var s,i,n;return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context168.n=1;break;}n={tool_calls:this._streamToolCalls};return _context168.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this80._streamToolCalls&&(_this80._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context168.a(2,{text:(s==null?void 0:s.content)||""});}},_callee168,this);}));function extractStreamResult(_x306,_x307){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e,t){var s,i,_yield$this$callToolF0,n,o;return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context169.n=1;break;}throw Error(_.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context169.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF0=_context169.v;n=_yield$this$callToolF0.responses;o=_yield$this$callToolF0.processedResponse;if(!o){_context169.n=3;break;}return _context169.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref43){var a=_ref43.response;return typeof a!="string";})&&i.length===n.length)){_context169.n=4;break;}return _context169.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context169.a(2);}},_callee169,this);}));function handleTools(_x308,_x309){return _handleTools1.apply(this,arguments);}return handleTools;}()}],[{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type==="image";}).map(function(t){return{type:"image_url",image_url:{url:t.src||""}};}).filter(function(t){return t.image_url.url.length>0;});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=si.getImageContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t.length>0?t:e.text||"";}return e.text||"";}}]);}(M);var Ba=/*#__PURE__*/function(_M31){function Ba(e){var _this81$maxMessages,_o$model13;var _this81;_classCallCheck(this,Ba);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.x;_this81=_callSuper(this,Ba,[e,Tt.buildKeyVerificationDetails(),Tt.buildHeaders,s]),_this81.insertKeyPlaceholderText="X API Key",_this81.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this81.url="https://api.x.ai/v1/chat/completions",_this81.permittedErrorPrefixes=["invalid_request_error","authentication_error"],_this81._systemMessage="You are a helpful assistant.";var i=(n=t.x)==null?void 0:n.chat;_typeof(i)=="object"&&(i.system_prompt&&(_this81._systemMessage=i.system_prompt),_this81.cleanConfig(i),Object.assign(_this81.rawBody,i)),(_this81$maxMessages=_this81.maxMessages)!==null&&_this81$maxMessages!==void 0?_this81$maxMessages:_this81.maxMessages=-1,(_o$model13=(o=_this81.rawBody).model)!==null&&_o$model13!==void 0?_o$model13:o.model="grok-3-latest";return _this81;}_inherits(Ba,_M31);return _createClass(Ba,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=U.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:o.text||"",role:o.role===y.USER_ROLE?"user":"assistant"};}),n={role:"system",content:this._systemMessage};return s.messages=[n].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e,t){var s,i;return _regenerator().w(function(_context170){while(1)switch(_context170.n){case 0:if(this.connectSettings){_context170.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!="object"||!i.simulation)||s.stream?(s.stream=!0,E.request(this,s,e)):x.request(this,s,e);case 2:return _context170.a(2);}},_callee170,this);}));function callServiceAPI(_x310,_x311){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(e){var t,s,i,n,o;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:if(!e.error){_context171.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context171.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context171.a(2,(s=o==null?void 0:o.delta)!=null&&s.content?{text:o.delta.content}:{text:""});case 2:return _context171.a(2,e.object==="chat.completion"&&(n=(i=e.choices)==null?void 0:i[0])!=null&&n.message?{text:e.choices[0].message.content||""}:{text:""});}},_callee171);}));function extractResultData(_x312){return _extractResultData40.apply(this,arguments);}return extractResultData;}()}]);}(M);var Fa=/*#__PURE__*/function(){function Fa(){_classCallCheck(this,Fa);}return _createClass(Fa,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
|
229
|
-
function create(e){var t=e.directConnection,s=e.connect,i=e.demo,n=e.webModel;if(n)return new
|
230
|
-
},{key:"createImageMessage",value:function createImageMessage(e,t,s,i){var n=
|
231
|
-
},{key:"addMessages",value:function addMessages(e,t,s,i){
|
232
|
-
},{key:"updateFileMessages",value:function updateFileMessages(e,t,s){var u
|
233
|
-
},{key:"update",value:function update(e,t,s){var i=e.messageToElements[s];if(i){if(
|
234
|
-
_inherits(
|
235
|
-
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this83=this;e!=null&&e.shadowRoot&&(this._introMessage=e.introMessage);var s=this._introMessage;t!=null&&t.isWebModel()&&(s!==null&&s!==void 0?s:s=t.getIntroMessage(s));var i=!(e!=null&&e.history)&&!!(e!=null&&e.loadHistory||t!=null&&t.fetchHistory);s&&(Array.isArray(s)?s.forEach(function(n,o){if(o!==0){var a=_this83.messageElementRefs[_this83.messageElementRefs.length-1].innerContainer;
|
236
|
-
},{key:"addNewMessage",value:function addNewMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var a,l,c,d;e.role!==
|
237
|
-
},{key:"removeMessageOnError",value:function removeMessageOnError(){var e=this.messageElementRefs[this.messageElementRefs.length-1],t=e==null?void 0:e.bubbleElement;(t!=null&&t.classList.contains(
|
238
|
-
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this84=this;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var c,d,u,
|
239
|
-
},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var o,a,l,c,d,
|
240
|
-
function clearMessages(e,t){var _this$messageToElemen;var n,o,a;var s=[];this.messageElementRefs.forEach(function(l){
|
218
|
+
}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("image",t),s&&i.append("mask",s),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i;}}]);}(L);Me.IMAGE_GENERATION_URL="https://api.openai.com/v1/images/generations",Me.IMAGE_VARIATIONS_URL="https://api.openai.com/v1/images/variations",Me.IMAGE_EDIT_URL="https://api.openai.com/v1/images/edits";var en=Me;var ei=/*#__PURE__*/function(){function ei(){_classCallCheck(this,ei);}return _createClass(ei,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://openrouter.ai/api/v1/generation",method:z,handleVerificationResult:ei.handleVerificationResult};}}]);}();var fs=/*#__PURE__*/function(_L18){function fs(e){var _this63$maxMessages,_o$model9,_a$max_tokens;var _this63;_classCallCheck(this,fs);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).openRouter;if(_this63=_callSuper(this,fs,[e,ei.buildKeyVerificationDetails(),ei.buildHeaders,s]),_this63.insertKeyPlaceholderText=_this63.genereteAPIKeyName("OpenRouter"),_this63.keyHelpUrl="https://openrouter.ai/keys",_this63.url="https://openrouter.ai/api/v1/chat/completions",_this63.permittedErrorPrefixes=[Ae,te],_this63._systemMessage="",_typeof(s)===S){s.system_prompt&&(_this63._systemMessage=s.system_prompt);var l=(n=(i=e.directConnection)==null?void 0:i.openRouter)==null?void 0:n.function_handler;l&&(_this63._functionHandler=l),_this63.cleanConfig(s),Object.assign(_this63.rawBody,s);}(_this63$maxMessages=_this63.maxMessages)!==null&&_this63$maxMessages!==void 0?_this63$maxMessages:_this63.maxMessages=-1,(_o$model9=(o=_this63.rawBody).model)!==null&&_o$model9!==void 0?_o$model9:o.model="openai/gpt-4o",(_a$max_tokens=(a=_this63.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=1e3;return _this63;}_inherits(fs,_L18);return _createClass(fs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:fs.getContent(o),role:o.role===b.USER_ROLE?"user":"assistant"};}),n=[];return this._systemMessage&&n.push({role:"system",content:this._systemMessage}),n.push.apply(n,_toConsumableArray(i)),s.messages=n,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(e,t){var _this$_messages5;var s,i;return _regenerator().w(function(_context131){while(1)switch(_context131.n){case 0:if(this.connectSettings){_context131.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages5=this._messages)!==null&&_this$_messages5!==void 0?_this$_messages5:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context131.a(2);}},_callee131,this);}));function callServiceAPI(_x237,_x238){return _callServiceAPI24.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee132(e,t){var s,i,n,o,a,l,_a6,_l4;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:if(!e.error){_context132.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context132.n=4;break;}a=(s=e.choices)==null?void 0:s[0];if(!(a!=null&&a.delta)){_context132.n=2;break;}return _context132.a(2,this.extractStreamResult(a,t));case 2:if(!((i=e.message)!=null&&i.images)){_context132.n=3;break;}l=e.message.images.map(function(c){return{src:c.image_url.url};});return _context132.a(2,_defineProperty(_defineProperty({},g,e.message.content||""),"files",l));case 3:return _context132.a(2,_defineProperty({},g,""));case 4:if(!(e.object==="chat.completion")){_context132.n=6;break;}_a6=(n=e.choices)==null?void 0:n[0];if(!(_a6!=null&&_a6.message)){_context132.n=6;break;}if(!_a6.message.tool_calls){_context132.n=5;break;}return _context132.a(2,this.handleTools({tool_calls:_a6.message.tool_calls},t));case 5:_l4=((o=_a6.message.images)==null?void 0:o.map(function(c){return{src:c.image_url.url};}))||[];return _context132.a(2,_defineProperty(_defineProperty({},g,_a6.message.content||""),"files",_l4));case 6:return _context132.a(2,_defineProperty({},g,""));}},_callee132,this);}));function extractResultData(_x239,_x240){return _extractResultData27.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var _this64=this;var s,i,n,_n2;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:s=e.delta,i=e.finish_reason;if(!(s!=null&&s.images)){_context133.n=1;break;}n=s.images.map(function(o){return{src:o.image_url.url};});return _context133.a(2,_defineProperty(_defineProperty({},g,s.content||""),"files",n));case 1:if(!(i==="tool_calls")){_context133.n=2;break;}_n2={tool_calls:this._streamToolCalls};return _context133.a(2,(this._streamToolCalls=void 0,this.handleTools(_n2,t)));case 2:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this64._streamToolCalls&&(_this64._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 3:return _context133.a(2,_defineProperty({},g,(s==null?void 0:s.content)||""));}},_callee133,this);}));function extractStreamResult(_x241,_x242){return _extractStreamResult3.apply(this,arguments);}return extractStreamResult;}()// https://openrouter.ai/docs/features/tool-calling
|
219
|
+
},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t){var s,i,_yield$this$callToolF3,n,o;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context134.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context134.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF3=_context134.v;n=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context134.n=3;break;}return _context134.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref99){var a=_ref99.response;return typeof a!="string";})&&i.length===n.length)){_context134.n=4;break;}return _context134.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context134.a(2);}},_callee134,this);}));function handleTools(_x243,_x244){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type==="image";}).map(function(t){return{type:"image_url",image_url:{url:t.src||""}};}).filter(function(t){return t.image_url.url.length>0;});}},{key:"getAudioContent",value:function getAudioContent(e){return e.filter(function(t){return t.type==="audio";}).map(function(t){var n,o,a;var s=(n=t.src)==null?void 0:n.split(",")[1],i=(a=(o=t.src)==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return{type:"input_audio",input_audio:{data:s||"",format:i==="wav"||i==="mp3"?i:"mp3"}};}).filter(function(t){return t.input_audio.data.length>0;});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=[].concat(_toConsumableArray(fs.getImageContent(e.files)),_toConsumableArray(fs.getAudioContent(e.files)));return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},g,e.text)),t.length>0?t:e.text||"";}return e.text||"";}}]);}(L);var ti=/*#__PURE__*/function(){function ti(){_classCallCheck(this,ti);}return _createClass(ti,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.error?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.perplexity.ai/chat/completions",method:Y,handleVerificationResult:ti.handleVerificationResult};}}]);}();var el=/*#__PURE__*/function(_L19){function el(e){var _this65$maxMessages,_i$model;var _this65;_classCallCheck(this,el);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).perplexity;_this65=_callSuper(this,el,[e,ti.buildKeyVerificationDetails(),ti.buildHeaders,s]),_this65.insertKeyPlaceholderText=_this65.genereteAPIKeyName("Perplexity"),_this65.keyHelpUrl="https://www.perplexity.ai/settings/api",_this65.url="https://api.perplexity.ai/chat/completions",_this65.permittedErrorPrefixes=[ht,ur,"Permission denied"],_this65._systemMessage="",_typeof(s)===S&&(s.system_prompt&&(_this65._systemMessage=s.system_prompt),_this65.cleanConfig(s),Object.assign(_this65.rawBody,s)),(_this65$maxMessages=_this65.maxMessages)!==null&&_this65$maxMessages!==void 0?_this65$maxMessages:_this65.maxMessages=-1,(_i$model=(i=_this65.rawBody).model)!==null&&_i$model!==void 0?_i$model:i.model="sonar";return _this65;}_inherits(el,_L19);return _createClass(el,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e,t){var s,i;return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:if(this.connectSettings){_context135.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x245,_x246){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e){var t;return _regenerator().w(function(_context136){while(1)switch(_context136.n){case 0:if(!e.error){_context136.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context136.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context136.n=2;break;}return _context136.a(2,_defineProperty({},g,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context136.n=3;break;}return _context136.a(2,_defineProperty({},g,t.message.content));case 3:return _context136.a(2,_defineProperty({},g,""));}},_callee136);}));function extractResultData(_x247){return _extractResultData28.apply(this,arguments);}return extractResultData;}()}]);}(L);var si=/*#__PURE__*/function(){function si(){_classCallCheck(this,si);}return _createClass(si,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P),"accept",P);}// prettier-ignore
|
220
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){typeof e.message=="string"?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.cohere.ai/v1/models",method:z,handleVerificationResult:si.handleVerificationResult};}}]);}();var tl=/*#__PURE__*/function(_L20){function tl(e,t,s,i,n){var _this66;_classCallCheck(this,tl);_this66=_callSuper(this,tl,[e,si.buildKeyVerificationDetails(),si.buildHeaders,n]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("Cohere"),_this66.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this66.permittedErrorPrefixes=["invalid"],_this66.url=t,_this66.textInputPlaceholderText=s,i&&_typeof(i)===S&&Object.assign(_this66.rawBody,i);return _this66;}_inherits(tl,_L20);return _createClass(tl);}(L);var ii=/*#__PURE__*/function(_tl){function ii(e){var _this67$maxMessages;var _this67;_classCallCheck(this,ii);var s=JSON.parse(JSON.stringify(e.directConnection)).cohere;if(_this67=_callSuper(this,ii,[e,"https://api.cohere.com/v2/chat","Ask me anything!",{},s]),_typeof(s)===S){var i=le.processCohere(s);_this67.canSendMessage=function(){return i;},_this67.cleanConfig(s),Object.assign(_this67.rawBody,s);}(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1;return _this67;}_inherits(ii,_tl);return _createClass(ii,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t.filter(function(n){return n.text;});return s.messages=i.map(function(n){return{role:n.role==="ai"?"assistant":"user",content:n.text};}),s.model=s.model||"command-a-03-2025",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e,t){var s,i;return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:if(this.connectSettings){_context137.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,this.stream={readable:!0},x.request(this,s,e)):w.request(this,s,e);case 2:return _context137.a(2);}},_callee137,this);}));function callServiceAPI(_x248,_x249){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(e){var t,s,i,n;return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:if(!(typeof e.message=="string")){_context138.n=1;break;}throw e.message;case 1:if(!(this.stream&&e.text)){_context138.n=2;break;}n=ii.parseBundledEvents(e.text);return _context138.a(2,{text:ii.aggregateBundledEventsText(n)});case 2:if(!("message"in e&&(i=(s=(t=e.message)==null?void 0:t.content)==null?void 0:s[0])!=null&&i.text)){_context138.n=3;break;}return _context138.a(2,_defineProperty({},g,e.message.content[0].text));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context138.a(2);}},_callee138,this);}));function extractResultData(_x250){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),s=[];var _iterator2=_createForOfIteratorHelper(t),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var i=_step2.value;if(i.trim())try{var n=JSON.parse(i);s.push(n);}catch(n){console.error("Failed to parse line:",i,n);}}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return s;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var s,i,n;return t.type==="content-delta"&&((n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text);}).map(function(t){var s,i,n;return(n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text;}).join("");}}]);}(tl);var ni=/*#__PURE__*/function(){function ni(){_classCallCheck(this,ni);}return _createClass(ni,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:z,handleVerificationResult:ni.handleVerificationResult};}}]);}();var sl=/*#__PURE__*/function(_L21){function sl(e){var _this68$maxMessages,_i$model2,_n$temperature,_o$max_tokens;var _this68;_classCallCheck(this,sl);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).deepSeek;_this68=_callSuper(this,sl,[e,ni.buildKeyVerificationDetails(),ni.buildHeaders,s]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("DeepSeek"),_this68.keyHelpUrl="https://platform.deepseek.com/api_keys",_this68.url="https://api.deepseek.com/v1/chat/completions",_this68.permittedErrorPrefixes=[Ae,te],_this68._systemMessage="",_typeof(s)===S&&(s.system_prompt&&(_this68._systemMessage=s.system_prompt),_this68.cleanConfig(s),Object.assign(_this68.rawBody,s)),(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_i$model2=(i=_this68.rawBody).model)!==null&&_i$model2!==void 0?_i$model2:i.model="deepseek-chat",(_n$temperature=(n=_this68.rawBody).temperature)!==null&&_n$temperature!==void 0?_n$temperature:n.temperature=1,(_o$max_tokens=(o=_this68.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this68;}_inherits(sl,_L21);return _createClass(sl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(e,t){var s,i;return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:if(this.connectSettings){_context139.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context139.a(2);}},_callee139,this);}));function callServiceAPI(_x251,_x252){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e){var t;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:if(!e.error){_context140.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context140.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context140.n=2;break;}return _context140.a(2,_defineProperty({},g,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context140.n=3;break;}return _context140.a(2,_defineProperty({},g,t.message.content));case 3:return _context140.a(2,_defineProperty({},g,""));}},_callee140);}));function extractResultData(_x253){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(L);var ri=/*#__PURE__*/function(){function ri(){_classCallCheck(this,ri);}return _createClass(ri,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var o;((o=e.base_resp)==null?void 0:o.status_code)===1004?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.minimax.io/v1/files/delete",method:Y,handleVerificationResult:ri.handleVerificationResult};}}]);}();var il=/*#__PURE__*/function(_L22){function il(e){var _this69$maxMessages,_i$model3;var _this69;_classCallCheck(this,il);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).miniMax;_this69=_callSuper(this,il,[e,ri.buildKeyVerificationDetails(),ri.buildHeaders,s]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("MiniMax"),_this69.keyHelpUrl="https://www.minimaxi.com",_this69.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this69.permittedErrorPrefixes=[Ae,te,"insufficient balance"],_this69._systemMessage="",_typeof(s)===S&&(s.system_prompt&&(_this69._systemMessage=s.system_prompt),_this69.cleanConfig(s),Object.assign(_this69.rawBody,s)),(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_i$model3=(i=_this69.rawBody).model)!==null&&_i$model3!==void 0?_i$model3:i.model="MiniMax-M1";return _this69;}_inherits(il,_L22);return _createClass(il,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){var s,i;return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:if(this.connectSettings){_context141.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context141.a(2);}},_callee141,this);}));function callServiceAPI(_x254,_x255){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e){var t,_s0;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:if(!e.error){_context142.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context142.n=3;break;}_s0=e.choices[0];if(!(_s0.delta&&_s0.delta.content)){_context142.n=2;break;}return _context142.a(2,_defineProperty({},g,_s0.delta.content));case 2:if(!(_s0.message&&_s0.message.content)){_context142.n=3;break;}return _context142.a(2,_defineProperty({},g,_s0.message.content));case 3:if(!(typeof((t=e.base_resp)==null?void 0:t.status_code)=="number"&&e.base_resp.status_code>0)){_context142.n=4;break;}throw e.base_resp.status_msg;case 4:return _context142.a(2,_defineProperty({},g,""));}},_callee142);}));function extractResultData(_x256){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(L);var oi=/*#__PURE__*/function(){function oi(){_classCallCheck(this,oi);}return _createClass(oi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P),"accept",P);}// prettier-ignore
|
221
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.detail?i(E.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.mistral.ai/v1/models",method:z,handleVerificationResult:oi.handleVerificationResult};}}]);}();var ai=/*#__PURE__*/function(_L23){function ai(e){var _this70$maxMessages,_o$model0;var _this70;_classCallCheck(this,ai);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).mistral;if(_this70=_callSuper(this,ai,[e,oi.buildKeyVerificationDetails(),oi.buildHeaders,s]),_this70.insertKeyPlaceholderText=_this70.genereteAPIKeyName("Mistral"),_this70.keyHelpUrl="https://console.mistral.ai/api-keys/",_this70.url="https://api.mistral.ai/v1/chat/completions",_this70.permittedErrorPrefixes=[ht],_this70._systemMessage="",_typeof(s)===S){s.system_prompt&&(_this70._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.mistral)==null?void 0:n.function_handler;a&&(_this70._functionHandler=a),_this70.cleanConfig(s),Object.assign(_this70.rawBody,s);}(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_o$model0=(o=_this70.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="mistral-small-latest";return _this70;}_inherits(ai,_L23);return _createClass(ai,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{role:n.role==="ai"?"assistant":"user",content:ai.getContent(n)};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e,t){var _this$_messages6;var s,i;return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:if(this.connectSettings){_context143.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages6=this._messages)!==null&&_this$_messages6!==void 0?_this$_messages6:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context143.a(2);}},_callee143,this);}));function callServiceAPI(_x257,_x258){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){var _s1;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:if(!e.message){_context144.n=1;break;}throw e.message;case 1:if(!e.error){_context144.n=2;break;}throw e.error.message;case 2:if(!(e.choices&&e.choices.length>0)){_context144.n=4;break;}_s1=e.choices[0];if(!_s1.delta){_context144.n=3;break;}return _context144.a(2,this.extractStreamResult(_s1,t));case 3:if(!_s1.message){_context144.n=4;break;}return _context144.a(2,_s1.message.tool_calls?this.handleTools({tool_calls:_s1.message.tool_calls},t):_defineProperty({},g,_s1.message.content||""));case 4:return _context144.a(2,_defineProperty({},g,""));}},_callee144,this);}));function extractResultData(_x259,_x260){return _extractResultData32.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var s,i,n;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls"&&s!=null&&s.tool_calls)){_context145.n=1;break;}n={tool_calls:s.tool_calls};return _context145.a(2,this.handleTools(n,t));case 1:return _context145.a(2,_defineProperty({},g,(s==null?void 0:s.content)||""));}},_callee145,this);}));function extractStreamResult(_x261,_x262){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()// https://docs.mistral.ai/api/#tag/chat/operation/chat_completion_v1_chat_completions_post
|
222
|
+
},{key:"handleTools",value:function(){var _handleTools5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){var s,i,_yield$this$callToolF4,n,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(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context146.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF4=_context146.v;n=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context146.n=3;break;}return _context146.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref118){var a=_ref118.response;return typeof a!="string";})&&i.length===n.length)){_context146.n=4;break;}return _context146.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context146.a(2);}},_callee146,this);}));function handleTools(_x263,_x264){return _handleTools5.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t.type==="image"?{type:"image_url",image_url:t.src||""}:_defineProperty({type:"text"},g,"[Unsupported file type: ".concat(t.type,"]"));});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=ai.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},g,e.text)),t;}return e.text||"";}}]);}(L);var li=/*#__PURE__*/function(_L24){function li(e){var _this71$maxMessages,_c$model2;var _this71;_classCallCheck(this,li);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this71=_callSuper(this,li,[e,Bt.buildKeyVerificationDetails(),Bt.buildHeaders,s]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("Groq"),_this71.keyHelpUrl="https://console.groq.com/keys",_this71.url="https://api.groq.com/openai/v1/chat/completions",_this71.permittedErrorPrefixes=[ht,"property"],_this71._systemMessage="";var i=(n=t.groq)==null?void 0:n.chat;if(_typeof(i)===S){i.system_prompt&&(_this71._systemMessage=i.system_prompt);var d=(l=(a=(o=e.directConnection)==null?void 0:o.groq)==null?void 0:a.chat)==null?void 0:l.function_handler;d&&(_this71._functionHandler=d),_this71.cleanConfig(i),Object.assign(_this71.rawBody,i);}(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_c$model2=(c=_this71.rawBody).model)!==null&&_c$model2!==void 0?_c$model2:c.model="llama-3.3-70b-versatile";return _this71;}_inherits(li,_L24);return _createClass(li,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:li.getContent(n),role:n.role==="ai"?"assistant":n.role};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){var _this$_messages7;var s,i;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(this.connectSettings){_context147.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages7=this._messages)!==null&&_this$_messages7!==void 0?_this$_messages7:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context147.a(2);}},_callee147,this);}));function callServiceAPI(_x265,_x266){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e,t){var s,i,n,o;return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:if(!e.error){_context148.n=1;break;}throw e.error.message;case 1:return _context148.a(2,(i=(s=e.choices)==null?void 0:s[0])!=null&&i.delta?this.extractStreamResult(e.choices[0],t):(o=(n=e.choices)==null?void 0:n[0])!=null&&o.message?e.choices[0].message.tool_calls?this.handleTools(e.choices[0].message,t):_defineProperty({},g,e.choices[0].message.content||""):_defineProperty({},g,""));}},_callee148,this);}));function extractResultData(_x267,_x268){return _extractResultData33.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e,t){var _this72=this;var s,i,n;return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context149.n=1;break;}n={tool_calls:this._streamToolCalls};return _context149.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this72._streamToolCalls&&(_this72._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context149.a(2,_defineProperty({},g,(s==null?void 0:s.content)||""));}},_callee149,this);}));function extractStreamResult(_x269,_x270){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()// https://console.groq.com/docs/tool-use
|
223
|
+
},{key:"handleTools",value:function(){var _handleTools6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){var s,i,_yield$this$callToolF5,n,o;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context150.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context150.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF5=_context150.v;n=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context150.n=3;break;}return _context150.a(2,o);case 3:if(!(s.messages=s.messages.slice(s.messages.length-1),this._systemMessage&&s.messages.unshift({role:"system",content:this._systemMessage}),s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref123){var a=_ref123.response;return typeof a!="string";})&&i.length===n.length)){_context150.n=4;break;}return _context150.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context150.a(2);}},_callee150,this);}));function handleTools(_x271,_x272){return _handleTools6.apply(this,arguments);}return handleTools;}()}],[{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type==="image";}).map(function(t){return{type:"image_url",image_url:{url:t.src||""}};}).filter(function(t){return t.image_url.url.length>0;});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=li.getImageContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},g,e.text)),t.length>0?t:e.text||"";}return e.text||"";}}]);}(L);var ci=/*#__PURE__*/function(){function ci(){_classCallCheck(this,ci);}return _createClass(ci,null,[{key:"buildHeaders",value:function buildHeaders(){return _defineProperty({},k,P);}// prettier-ignore
|
224
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var o;var n=e;n.error?n.error.code===403||(o=n.error.message)!=null&&o.includes("API key")?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}// https://ai.google.dev/api/models#method:-models.list
|
225
|
+
},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){var e="https://generativelanguage.googleapis.com/v1beta/models?key=";return{url:e,augmentUrl:function augmentUrl(t){return"".concat(e).concat(t);},method:z,handleVerificationResult:ci.handleVerificationResult};}}]);}();var gn=/*#__PURE__*/function(_L25){function gn(e){var _this73$maxMessages;var _this73;_classCallCheck(this,gn);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).gemini;if(_this73=_callSuper(this,gn,[e,ci.buildKeyVerificationDetails(),ci.buildHeaders,s]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("Gemini"),_this73.keyHelpUrl="https://aistudio.google.com/app/apikey",_this73.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent",_this73.url="",_this73.permittedErrorPrefixes=["API_KEY_INVALID"],_typeof(s)===S){s.systemInstruction&&(_this73._systemInstruction=s.systemInstruction);var _ref125=(i=e.directConnection)==null?void 0:i.gemini,n=_ref125.function_handler;n&&(_this73._functionHandler=n),s.model&&(_this73.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(s.model,":generateContent")),_this73.cleanConfig(s);}Object.assign(_this73.rawBody,s),(_this73$maxMessages=_this73.maxMessages)!==null&&_this73$maxMessages!==void 0?_this73$maxMessages:_this73.maxMessages=-1;return _this73;}_inherits(gn,_L25);return _createClass(gn,[{key:"cleanConfig",value:function cleanConfig(e){delete e.systemInstruction,delete e.function_handler,delete e.model,delete e.key;}},{key:"preprocessBody",value:// prettier-ignore
|
226
|
+
function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemInstruction)==null?void 0:n.length)||0):-1).map(function(o){return gn.getContent(o);});return s.contents=i,this._systemInstruction&&(s.systemInstruction={parts:[_defineProperty({},g,this._systemInstruction)]}),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e,t){var _this$_messages8;var s,i;return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:if(this.connectSettings){_context151.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages8=this._messages)!==null&&_this$_messages8!==void 0?_this$_messages8:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),x.request(this,s,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),w.request(this,s,e));case 2:return _context151.a(2);}},_callee151,this);}));function callServiceAPI(_x273,_x274){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()// https://ai.google.dev/gemini-api/docs/function-calling?example=weather
|
227
|
+
},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:if(!e.error){_context152.n=1;break;}throw e.error.message||"Gemini API Error";case 1:if(!((n=(i=(s=e.candidates)==null?void 0:s[0])==null?void 0:i.content)!=null&&n.parts)){_context152.n=3;break;}a=e.candidates[0].content.parts,l=a.find(function(h){return h.functionCall;});if(!(l!=null&&l.functionCall)){_context152.n=2;break;}return _context152.a(2,this.handleTools([l.functionCall],t));case 2:c=a.find(function(h){return h.text;}),d=a.find(function(h){var u;return((u=h.inlineData)==null?void 0:u.mimeType)==="image/png";});return _context152.a(2,_defineProperty(_defineProperty({},g,(c==null?void 0:c.text)||""),"files",(o=d==null?void 0:d.inlineData)!=null&&o.data?[{src:"data:image/png;base64,".concat(d.inlineData.data)}]:[]));case 3:return _context152.a(2,_defineProperty({},g,""));}},_callee152,this);}));function extractResultData(_x275,_x276){return _extractResultData34.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var s,i,_yield$this$callToolF6,n,o,a,l;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:if(!(!e||!t||!this._functionHandler)){_context153.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.map(function(l){return{name:l.name,arguments:JSON.stringify(l.args)};});_context153.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF6=_context153.v;n=_yield$this$callToolF6.responses;o=_yield$this$callToolF6.processedResponse;if(!o){_context153.n=3;break;}return _context153.a(2,o);case 3:a={parts:e.map(function(l){return{functionCall:{name:l.name,args:l.args}};}),role:"model"};if(!(s.contents.push(a),!n.find(function(_ref129){var l=_ref129.response;return typeof l!="string";})&&i.length===n.length)){_context153.n=4;break;}l={parts:n.map(function(c,d){return{functionResponse:{name:e[d].name,response:{result:c.response}}};}),role:"user"};return _context153.a(2,(s.contents.push(l),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context153.a(2);}},_callee153,this);}));function handleTools(_x277,_x278){return _handleTools7.apply(this,arguments);}return handleTools;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e.text&&e.text.trim().length>0&&t.push(_defineProperty({},g,e.text)),e.files&&e.files.length>0&&e.files.forEach(function(s){if(s.src&&s.src.includes("data:")){var _s$src$split=s.src.split(","),_s$src$split2=_slicedToArray(_s$src$split,2),i=_s$src$split2[0],n=_s$src$split2[1];t.push({inlineData:{mimeType:i.replace("data:","").replace(";base64",""),data:n}});}}),{parts:t,role:e.role===b.USER_ROLE?"user":"model"};}}]);}(L);var di=/*#__PURE__*/function(){function di(){_classCallCheck(this,di);}return _createClass(di,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":e},k,P),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/models",method:z,handleVerificationResult:di.handleVerificationResult};}}]);}();var hi=/*#__PURE__*/function(_L26){function hi(e){var _this74$maxMessages,_o$model1,_a$max_tokens2;var _this74;_classCallCheck(this,hi);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).claude;if(_this74=_callSuper(this,hi,[e,di.buildKeyVerificationDetails(),di.buildHeaders,s]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Claude"),_this74.keyHelpUrl="https://console.anthropic.com/settings/keys",_this74.url="https://api.anthropic.com/v1/messages",_this74.permittedErrorPrefixes=[te,Ae],_this74._streamToolCalls={type:"tool_use",id:"",name:"",input:""},_this74._systemMessage="",_typeof(s)===S){s.system_prompt&&(_this74._systemMessage=s.system_prompt);var l=(n=(i=e.directConnection)==null?void 0:i.claude)==null?void 0:n.function_handler;l&&(_this74._functionHandler=l),_this74.cleanConfig(s),Object.assign(_this74.rawBody,s);}(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_o$model1=(o=_this74.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="claude-3-5-sonnet-20241022",(_a$max_tokens2=(a=_this74.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this74;}_inherits(hi,_L26);return _createClass(hi,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:hi.getContent(n),role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=i,this._systemMessage&&(s.system=this._systemMessage),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var _this$_messages9;var s,i;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:if(this.connectSettings){_context154.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages9=this._messages)!==null&&_this$_messages9!==void 0?_this$_messages9:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context154.a(2);}},_callee154,this);}));function callServiceAPI(_x279,_x280){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e,t){var s,i,n,o,a;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:if(!e.error){_context155.n=1;break;}throw e.error.message;case 1:if(!(e.content&&e.content.length>0)){_context155.n=3;break;}o=e.content.find(function(l){return l.type==="tool_use";});if(!o){_context155.n=2;break;}return _context155.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(l){return l.type==="text";});if(!a){_context155.n=3;break;}return _context155.a(2,_defineProperty({},g,a.text));case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context155.n=4;break;}return _context155.a(2,_defineProperty({},g,e.delta.text||""));case 4:if(!(e.type==="content_block_start"&&((s=e.content_block)==null?void 0:s.type)==="tool_use")){_context155.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context155.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((i=e.delta)==null?void 0:i.type)==="input_json_delta")){_context155.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context155.n=7;break;case 6:if(!(e.type==="message_delta"&&((n=e.delta)==null?void 0:n.stop_reason)==="tool_use")){_context155.n=7;break;}return _context155.a(2,(this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t)));case 7:return _context155.a(2,_defineProperty({},g,""));}},_callee155,this);}));function extractResultData(_x281,_x282){return _extractResultData35.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var s,i,_yield$this$callToolF7,n,o,a,l;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(!(!e||!t||!this._functionHandler)){_context156.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.map(function(l){return{name:l.name,arguments:JSON.stringify(l.input)};});_context156.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF7=_context156.v;n=_yield$this$callToolF7.responses;o=_yield$this$callToolF7.processedResponse;if(!o){_context156.n=3;break;}return _context156.a(2,o);case 3:a=e.map(function(l){return{type:"tool_use",id:l.id,name:l.name,input:l.input};});if(!(s.messages.push({role:"assistant",content:a}),!n.find(function(_ref134){var l=_ref134.response;return typeof l!="string";})&&i.length===n.length)){_context156.n=4;break;}l=n.map(function(c,d){return{type:"tool_result",tool_use_id:e[d].id,content:c.response};});return _context156.a(2,(s.messages.push({role:"user",content:l}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context156.a(2);}},_callee156,this);}));function handleTools(_x283,_x284){return _handleTools8.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var s,i,n;if(t.type==="image"){var o=(s=t.src)==null?void 0:s.split(",")[1];return{type:"image",source:{type:"base64",media_type:((n=(i=t.src)==null?void 0:i.match(/data:([^;]+)/))==null?void 0:n[1])||"image/jpeg",data:o||""}};}return _defineProperty({type:"text"},g,"[Unsupported file type: ".concat(t.type,"]"));});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=hi.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},g,e.text)),t;}return e.text||"";}}]);}(L);var qn=/*#__PURE__*/function(){function qn(){_classCallCheck(this,qn);}return _createClass(qn,null,[{key:"buildHeaders",value:function buildHeaders(){return{};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"",method:z,handleVerificationResult:function handleVerificationResult(){}};}}]);}();var ui=/*#__PURE__*/function(_L27){function ui(e){var _this75$maxMessages,_l$model2,_c$stream;var _this75;_classCallCheck(this,ui);var o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=qn.buildKeyVerificationDetails(),i=qn.buildHeaders;_this75=_callSuper(this,ui,[e,s,i,{key:"placeholder"}]),_this75.insertKeyPlaceholderText="",_this75.keyHelpUrl="",_this75.validateKeyProperty=!1,_this75.url="http://localhost:11434/api/chat",_this75.permittedErrorPrefixes=["Error"];var n=t.ollama;if(_typeof(n)===S){n.system&&(_this75._systemMessage=ui.generateSystemMessage(n.system));var d=(a=(o=e.directConnection)==null?void 0:o.ollama)==null?void 0:a.function_handler;d&&(_this75._functionHandler=d),_this75.cleanConfig(n),Object.assign(_this75.rawBody,n);}(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1,(_l$model2=(l=_this75.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="llama3.2",(_c$stream=(c=_this75.rawBody).stream)!==null&&_c$stream!==void 0?_c$stream:c.stream=!1;return _this75;}_inherits(ui,_L27);return _createClass(ui,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system,delete e.function_handler;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemMessage)==null?void 0:n.content.length)||0):-1).map(function(o){var a={content:o.text||"",role:o.role===b.USER_ROLE?"user":"assistant"};if(o.files&&o.files.length>0){var l=ui.getImageData(o.files);l.length>0&&(a.images=l);}return a;});return s.messages=_toConsumableArray(i),this._systemMessage&&s.messages.unshift(this._systemMessage),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var _this$_messages0;var s,i;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(this.connectSettings){_context157.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages0=this._messages)!==null&&_this$_messages0!==void 0?_this$_messages0:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,this.stream={readable:!0},x.request(this,s,e)):w.request(this,s,e);case 2:return _context157.a(2);}},_callee157,this);}));function callServiceAPI(_x285,_x286){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){var s,i,n;return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:if(!e.error){_context158.n=1;break;}throw e.error.message;case 1:if(!e.text){_context158.n=2;break;}n=JSON.parse(e.text);return _context158.a(2,(s=n.message)!=null&&s.tool_calls?this.handleTools({tool_calls:n.message.tool_calls},t):_defineProperty({},g,((i=n.message)==null?void 0:i.content)||""));case 2:return _context158.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},g,e.message.content||""):_defineProperty({},g,""));}},_callee158,this);}));function extractResultData(_x287,_x288){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e,t){var s,i,_yield$this$callToolF8,n,o;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context159.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:JSON.stringify(a["function"].arguments)};});_context159.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF8=_context159.v;n=_yield$this$callToolF8.responses;o=_yield$this$callToolF8.processedResponse;if(!o){_context159.n=3;break;}return _context159.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:""}),!n.find(function(_ref139){var a=_ref139.response;return typeof a!="string";})&&i.length===n.length)){_context159.n=4;break;}return _context159.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context159.a(2);}},_callee159,this);}));function handleTools(_x289,_x290){return _handleTools9.apply(this,arguments);}return handleTools;}()}],[{key:"generateSystemMessage",value:function generateSystemMessage(e){return{role:"system",content:e};}},{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t.type==="image";}).map(function(t){var i;return((i=t.src)==null?void 0:i.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(L);var Ft=/*#__PURE__*/function(){function Ft(){_classCallCheck(this,Ft);}return _createClass(Ft,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty({Authorization:"".concat(ee).concat(e)},k,P);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te||n.error.type===Ae?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.x.ai/v1/models",method:z,handleVerificationResult:Ft.handleVerificationResult};}}]);}();var Ci=/*#__PURE__*/function(_L28){function Ci(e){var _o$model10;var _this76;_classCallCheck(this,Ci);var n,o;var t=e.directConnection,s=t==null?void 0:t.x;_this76=_callSuper(this,Ci,[e,Ft.buildKeyVerificationDetails(),Ft.buildHeaders,s]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("X"),_this76.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this76.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>X Image Generation</b></div>\n <p><b>Insert text</b> to generate an image.</p>\n <p>Click <a target=\"_blank\" href=\"https://docs.x.ai/docs/api-reference#image-generations\" target=\"_blank\">\n here</a> for more info.</p>",_this76.url=Ci.IMAGE_GENERATION_URL,_this76.permittedErrorPrefixes=[Ae,te];var i=(n=t==null?void 0:t.x)==null?void 0:n.images;_typeof(i)===S&&Object.assign(_this76.rawBody,i),(_o$model10=(o=_this76.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="grok-2-image";return _this76;}_inherits(Ci,_L28);return _createClass(Ci,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e));return t&&t!==""&&(s.prompt=t),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e,t){var i,s;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context160.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t[t.length-1].text);w.request(this,s,e);case 2:return _context160.a(2);}},_callee160,this);}));function callServiceAPI(_x291,_x292){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e){return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(!e.error){_context161.n=1;break;}throw e.error.message;case 1:return _context161.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(Ht).concat(s.b64_json),type:"image"};})});}},_callee161);}));function extractResultData(_x293){return _extractResultData37.apply(this,arguments);}return extractResultData;}()}]);}(L);Ci.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var tn=Ci;var fi=/*#__PURE__*/function(){function fi(){_classCallCheck(this,fi);}return _createClass(fi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===Ae?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",method:z,handleVerificationResult:fi.handleVerificationResult};}}]);}();var pi=/*#__PURE__*/function(_L29){function pi(e){var _this77$maxMessages,_o$model11;var _this77;_classCallCheck(this,pi);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).qwen;if(_this77=_callSuper(this,pi,[e,fi.buildKeyVerificationDetails(),fi.buildHeaders,s]),_this77.insertKeyPlaceholderText=_this77.genereteAPIKeyName("Qwen"),_this77.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this77.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this77.permittedErrorPrefixes=["No static","The model",Is],_this77._systemMessage="",_typeof(s)===S){s.system_prompt&&(_this77._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.qwen)==null?void 0:n.function_handler;a&&(_this77._functionHandler=a),_this77.cleanConfig(s),Object.assign(_this77.rawBody,s);}(_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="qwen-plus";return _this77;}_inherits(pi,_L29);return _createClass(pi,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:pi.getContent(n),role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){var _this$_messages1;var s,i;return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:if(this.connectSettings){_context162.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages1=this._messages)!==null&&_this$_messages1!==void 0?_this$_messages1:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context162.a(2);}},_callee162,this);}));function callServiceAPI(_x294,_x295){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee163(e,t){var _s10;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:if(!e.error){_context163.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context163.n=3;break;}_s10=e.choices[0];if(!_s10.delta){_context163.n=2;break;}return _context163.a(2,this.extractStreamResult(_s10,t));case 2:if(!_s10.message){_context163.n=3;break;}return _context163.a(2,_s10.message.tool_calls?this.handleTools({tool_calls:_s10.message.tool_calls},t):_defineProperty({},g,_s10.message.content||""));case 3:return _context163.a(2,_defineProperty({},g,""));}},_callee163,this);}));function extractResultData(_x296,_x297){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var _this78=this;var s,i,n;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context164.n=1;break;}n={tool_calls:this._streamToolCalls};return _context164.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this78._streamToolCalls&&(_this78._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context164.a(2,_defineProperty({},g,(s==null?void 0:s.content)||""));}},_callee164,this);}));function extractStreamResult(_x298,_x299){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){var s,i,_yield$this$callToolF9,n,o;return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context165.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context165.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF9=_context165.v;n=_yield$this$callToolF9.responses;o=_yield$this$callToolF9.processedResponse;if(!o){_context165.n=3;break;}return _context165.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref145){var a=_ref145.response;return typeof a!="string";})&&i.length===n.length)){_context165.n=4;break;}return _context165.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context165.a(2);}},_callee165,this);}));function handleTools(_x300,_x301){return _handleTools0.apply(this,arguments);}return handleTools;}()}],[{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type==="image";}).map(function(t){return{type:"image_url",image_url:{url:t.src||""}};}).filter(function(t){return t.image_url.url.length>0;});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=pi.getImageContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},g,e.text)),t.length>0?t:e.text||"";}return e.text||"";}}]);}(L);var mi=/*#__PURE__*/function(){function mi(){_classCallCheck(this,mi);}return _createClass(mi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(ee).concat(e)),k,P);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(E.INVALID_KEY):i(E.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:z,handleVerificationResult:mi.handleVerificationResult};}}]);}();var gi=/*#__PURE__*/function(_L30){function gi(e){var _this79$maxMessages,_o$model12;var _this79;_classCallCheck(this,gi);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).kimi;if(_this79=_callSuper(this,gi,[e,mi.buildKeyVerificationDetails(),mi.buildHeaders,s]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("Kimi"),_this79.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this79.url="https://api.moonshot.ai/v1/chat/completions",_this79.permittedErrorPrefixes=[ht,"Not found"],_this79._systemMessage="You are Kimi, a helpful assistant created by Moonshot AI.",_typeof(s)===S){s.system_prompt&&(_this79._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.kimi)==null?void 0:n.function_handler;a&&(_this79._functionHandler=a),_this79.cleanConfig(s),Object.assign(_this79.rawBody,s);}(_this79$maxMessages=_this79.maxMessages)!==null&&_this79$maxMessages!==void 0?_this79$maxMessages:_this79.maxMessages=-1,(_o$model12=(o=_this79.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="moonshot-v1-8k";return _this79;}_inherits(gi,_L30);return _createClass(gi,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:gi.getContent(n),role:n.role===b.USER_ROLE?"user":"assistant"};});return s.messages=[{role:"system",content:this._systemMessage}].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee166(e,t){var _this$_messages10;var s,i;return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:if(this.connectSettings){_context166.n=1;break;}throw new Error("Request settings have not been set up");case 1:(_this$_messages10=this._messages)!==null&&_this$_messages10!==void 0?_this$_messages10:this._messages=e;s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context166.a(2);}},_callee166,this);}));function callServiceAPI(_x302,_x303){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e,t){var _s11;return _regenerator().w(function(_context167){while(1)switch(_context167.n){case 0:if(!e.error){_context167.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context167.n=3;break;}_s11=e.choices[0];if(!_s11.delta){_context167.n=2;break;}return _context167.a(2,this.extractStreamResult(_s11,t));case 2:if(!_s11.message){_context167.n=3;break;}return _context167.a(2,_s11.message.tool_calls?this.handleTools({tool_calls:_s11.message.tool_calls},t):_defineProperty({},g,_s11.message.content||""));case 3:return _context167.a(2,_defineProperty({},g,""));}},_callee167,this);}));function extractResultData(_x304,_x305){return _extractResultData39.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){var _this80=this;var s,i,n;return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls")){_context168.n=1;break;}n={tool_calls:this._streamToolCalls};return _context168.a(2,(this._streamToolCalls=void 0,this.handleTools(n,t)));case 1:s!=null&&s.tool_calls&&(this._streamToolCalls?s.tool_calls.forEach(function(n,o){_this80._streamToolCalls&&(_this80._streamToolCalls[o]["function"].arguments+=n["function"].arguments);}):this._streamToolCalls=s.tool_calls);case 2:return _context168.a(2,_defineProperty({},g,(s==null?void 0:s.content)||""));}},_callee168,this);}));function extractStreamResult(_x306,_x307){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()},{key:"handleTools",value:function(){var _handleTools1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e,t){var s,i,_yield$this$callToolF0,n,o;return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context169.n=1;break;}throw Error(E.DEFINE_FUNCTION_HANDLER);case 1:s=JSON.parse(JSON.stringify(t));i=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context169.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF0=_context169.v;n=_yield$this$callToolF0.responses;o=_yield$this$callToolF0.processedResponse;if(!o){_context169.n=3;break;}return _context169.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!n.find(function(_ref150){var a=_ref150.response;return typeof a!="string";})&&i.length===n.length)){_context169.n=4;break;}return _context169.a(2,(n.forEach(function(a,l){var d;var c=(d=e.tool_calls)==null?void 0:d[l];s==null||s.messages.push({role:"tool",tool_call_id:c==null?void 0:c.id,name:c==null?void 0:c["function"].name,content:a.response});}),this.makeAnotherRequest(s,this._messages)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context169.a(2);}},_callee169,this);}));function handleTools(_x308,_x309){return _handleTools1.apply(this,arguments);}return handleTools;}()}],[{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t.type==="image";}).map(function(t){return{type:"image_url",image_url:{url:t.src||""}};}).filter(function(t){return t.image_url.url.length>0;});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=gi.getImageContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},g,e.text)),t.length>0?t:e.text||"";}return e.text||"";}}]);}(L);var nl=/*#__PURE__*/function(_L31){function nl(e){var _this81$maxMessages,_o$model13;var _this81;_classCallCheck(this,nl);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.x;_this81=_callSuper(this,nl,[e,Ft.buildKeyVerificationDetails(),Ft.buildHeaders,s]),_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=[Ae,te],_this81._systemMessage="";var i=(n=t.x)==null?void 0:n.chat;_typeof(i)===S&&(i.system_prompt&&(_this81._systemMessage=i.system_prompt),_this81.cleanConfig(i),Object.assign(_this81.rawBody,i)),(_this81$maxMessages=_this81.maxMessages)!==null&&_this81$maxMessages!==void 0?_this81$maxMessages:_this81.maxMessages=-1,(_o$model13=(o=_this81.rawBody).model)!==null&&_o$model13!==void 0?_o$model13:o.model="grok-3-latest";return _this81;}_inherits(nl,_L31);return _createClass(nl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=G.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:o.text||"",role:o.role===b.USER_ROLE?"user":"assistant"};}),n={role:"system",content:this._systemMessage};return s.messages=[n].concat(_toConsumableArray(i)),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e,t){var s,i;return _regenerator().w(function(_context170){while(1)switch(_context170.n){case 0:if(this.connectSettings){_context170.n=1;break;}throw new Error("Request settings have not been set up");case 1:s=this.preprocessBody(this.rawBody,t),i=this.stream;i&&(_typeof(i)!==S||!i.simulation)||s.stream?(s.stream=!0,x.request(this,s,e)):w.request(this,s,e);case 2:return _context170.a(2);}},_callee170,this);}));function callServiceAPI(_x310,_x311){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(e){var t,s,i,n,o;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:if(!e.error){_context171.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context171.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context171.a(2,(s=o==null?void 0:o.delta)!=null&&s.content?_defineProperty({},g,o.delta.content):_defineProperty({},g,""));case 2:return _context171.a(2,e.object==="chat.completion"&&(n=(i=e.choices)==null?void 0:i[0])!=null&&n.message?_defineProperty({},g,e.choices[0].message.content||""):_defineProperty({},g,""));}},_callee171);}));function extractResultData(_x312){return _extractResultData40.apply(this,arguments);}return extractResultData;}()}]);}(L);var rl=/*#__PURE__*/function(){function rl(){_classCallCheck(this,rl);}return _createClass(rl,null,[{key:"create",value:// this should only be called when no _activeService is set or is demo as otherwise we don't want to reconnect
|
228
|
+
function create(e){var t=e.directConnection,s=e.connect,i=e.demo,n=e.webModel;if(n)return new Cs(e);if(t){if(t.openAI)return t.openAI.images?new en(e):t.openAI.speechToText?new Xi(e):t.openAI.textToSpeech?new Wi(e):t.openAI.assistant?new fn(e):t.openAI.realtime?new $i(e):new As(e);if(t.assemblyAI)return new pn(e);if(t.cohere)return new ii(e);if(t.huggingFace)return t.huggingFace.textGeneration?new Ha(e):t.huggingFace.summarization?new ja(e):t.huggingFace.translation?new Ka(e):t.huggingFace.fillMask?new za(e):t.huggingFace.questionAnswer?new qa(e):t.huggingFace.audioSpeechRecognition?new Ua(e):t.huggingFace.audioClassification?new Ba(e):t.huggingFace.imageClassification?new Fa(e):new Va(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new mn(e);if(t.azure.openAI.assistant)return new Gi(e);}if(t.azure.speechToText)return new Qi(e);if(t.azure.textToSpeech)return new Zi(e);if(t.azure.summarization)return new Yi(e);if(t.azure.translation)return new Wa(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new $s(e):t.stabilityAI.imageToImageUpscale?new Gs(e):t.stabilityAI.imageToImageMasking?new Js(e):new Ws(e);if(t.mistral)return new ai(e);if(t.gemini)return new gn(e);if(t.claude)return new hi(e);if(t.deepSeek)return new sl(e);if(t.miniMax)return new il(e);if(t.openRouter)return new fs(e);if(t.kimi)return new gi(e);if(t.x)return t.x.images?new tn(e):new nl(e);if(t.qwen)return new pi(e);if(t.together)return t.together.images?new Za(e):t.together.textToSpeech?new Ja(e):new Qa(e);if(t.bigModel)return t.bigModel.images?new Xa(e):t.bigModel.textToSpeech?new Ga(e):new Qs(e);if(t.groq)return t.groq.textToSpeech?new Ya(e):new li(e);if(t.perplexity)return new el(e);if(t.ollama)return new ui(e);}return s&&Object.keys(s).length>0&&!i?new Ct(e):new Ct(e,void 0,i||!0);}}]);}();var xn=/*#__PURE__*/_createClass(function xn(){_classCallCheck(this,xn);});xn.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 sn=xn;function T(r){return function(e,t){Object.defineProperty(e,t,{});var s=e.constructor,i=t.toLocaleLowerCase();s._attributes_[i]=sn.attibutes[r],s._attributeToProperty_[i]=t;};}var yi=/*#__PURE__*/function(){function yi(e,t,s){_classCallCheck(this,yi);this._isDisplayed=!1,e?(this._elementRef=this.createIntroPanelWithChild(e,s),this._isDisplayed=!0):t&&(this._elementRef=this.createInternalIntroPanel(t,s),this._isDisplayed=!0);}return _createClass(yi,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e,t){var s=yi.createIntroPanel(t);return e.style.display==="none"&&(e.style.display="block"),s.appendChild(e),s;}},{key:"createInternalIntroPanel",value:function createInternalIntroPanel(e,t){var s=yi.createIntroPanel(t);return s.id="internal-intro-panel",s.innerHTML=e,s;}},{key:"hide",value:function hide(){this._isDisplayed&&this._elementRef&&(this._elementRef.style.display="none",this._isDisplayed=!1);}},{key:"display",value:function display(){!this._isDisplayed&&this._elementRef&&(this._elementRef.style.display="",this._isDisplayed=!0);}}],[{key:"createIntroPanel",value:function createIntroPanel(e){var t=document.createElement("div");return t.classList.add("intro-panel"),Object.assign(t.style,e),t;}}]);}();var ol="<?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,s){var i=new Image();return i.src=e.src,s&&Q.scrollDownOnImageLoad(i.src,t),Q.processContent("image",i,i.src,e.name);}// WORK - image still does not scroll down when loaded
|
229
|
+
},{key:"createImageMessage",value:function createImageMessage(e,t,s,i){var n=ie.createImage(t,e.elementRef,!i&&!e.focusMode),o=e.createNewMessageElement("",s);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(ie.IMAGE_BUBBLE_CLASS),{type:"image",elements:o};}},{key:"createAudioElement",value:function createAudioElement(e,t){var s=document.createElement("audio");return s.src=e.src,s.classList.add("audio-player"),s.controls=!0,Ye.IS_SAFARI&&(s.classList.add("audio-player-safari"),s.classList.add(t===b.USER_ROLE?"audio-player-safari-right":"audio-player-safari-left")),s;}},{key:"autoPlayAudio",value:function autoPlayAudio(e){e.addEventListener("loadeddata",function(){e.play()["catch"](function(t){console.warn("Auto-play failed:",t);});});}},{key:"createNewAudioMessage",value:function createNewAudioMessage(e,t,s,i){var n=ie.createAudioElement(t,s),o=e.createMessageElementsOnOrientation("",s,i);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(ie.AUDIO_BUBBLE_CLASS),{type:"audio",elements:o,audioElement:n};}},{key:"createAnyFile",value:function createAnyFile(e){var t=document.createElement("div");t.classList.add("any-file-message-contents");var s=document.createElement("div");s.classList.add("any-file-message-icon-container");var i=Qe.createSVGElement(ol);i.classList.add("any-file-message-icon"),s.appendChild(i);var n=document.createElement("div");return n.classList.add("any-file-message-text"),n.textContent=e.name||Q.DEFAULT_FILE_NAME,t.appendChild(s),t.appendChild(n),Q.processContent("any",t,e.src,n.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,s,i){var n=e.createMessageElementsOnOrientation("",s,i),o=ie.createAnyFile(t);return n.bubbleElement.classList.add(ie.ANY_FILE_BUBBLE_CLASS),n.bubbleElement.appendChild(o),{type:"file",elements:n};}},{key:"createMessages",value:function createMessages(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;return t.map(function(n){var o;if(n.ref&&(n=Q.removeFileRef(n)),Q.isAudioFile(n)){var a=ie.createNewAudioMessage(e,n,s,i),l=(o=e.textToSpeech)==null?void 0:o.service;return l&&(l.autoPlay&&ie.autoPlayAudio(a.audioElement),typeof l.displayAudio=="boolean"&&!l.displayAudio)?void 0:a;}return Q.isImageFile(n)?ie.createImageMessage(e,n,s,i):ie.createNewAnyFileMessage(e,n,s,i);}).filter(function(n){return n!==void 0;});}// no overwrite previous message logic as it is complex to track which files are to be overwritten
|
230
|
+
},{key:"addMessages",value:function addMessages(e,t,s,i){ie.createMessages(e,t,s,i).filter(function(o){return o!==void 0;}).forEach(function(_ref155){var o=_ref155.type,a=_ref155.elements;Q.addMessage(e,a,o,s,i);});}}]);}();ie.IMAGE_BUBBLE_CLASS="image-message",ie.AUDIO_BUBBLE_CLASS="audio-message",ie.ANY_FILE_BUBBLE_CLASS="any-file-message";var bi=ie;var Ee=/*#__PURE__*/function(){function Ee(){_classCallCheck(this,Ee);}return _createClass(Ee,null,[{key:"removeElements",value:function removeElements(e,t){if(!t)return;var s=e.findIndex(function(i){return i===t;});e.splice(s,1),t==null||t.outerContainer.remove();}},{key:"removeFilesMessages",value:function removeFilesMessages(e,t){var s;(s=t[1].files)==null||s.forEach(function(i){Ee.removeElements(e.messageElementRefs,i);}),delete t[0].files,delete t[1].files;}},{key:"removeTextHTMLMessage",value:function removeTextHTMLMessage(e,t,s){var i=t[1][s];Ee.removeElements(e.messageElementRefs,i),delete t[0][s],delete t[1][s];}},{key:"updateHTMLMessage",value:function updateHTMLMessage(e,t,s){var i,n,o;if(t[1].html)De.overwriteElements(e,s,t[1].html);else{var a=De.create(e,s,t[0].role),l=((n=t[1].files)==null?void 0:n[((i=t[1].files)==null?void 0:i.length)-1])||t[1].text,c=l.outerContainer.nextSibling;(o=c==null?void 0:c.parentElement)==null||o.insertBefore(a.outerContainer,c),e.messageElementRefs.splice(e.messageElementRefs.length-1,1);var d=e.messageElementRefs.findIndex(function(h){return h===l;});e.messageElementRefs.splice(d+1,0,a),t[1].html=a;}t[0].html=s;}// finds beforeElement, creates new elements, remove old and adds new ones
|
231
|
+
},{key:"updateFileMessages",value:function updateFileMessages(e,t,s){var h,u;var i=t[0].role,n=bi.createMessages(e,s,i),o=t[1].html,a=((u=t[1].files)==null?void 0:u[((h=t[1].files)==null?void 0:h.length)-1])||t[1].text,l=o||a;var c=e.messageElementRefs.findIndex(function(f){return f===l;});a&&(c+=1);var d=(o==null?void 0:o.outerContainer)||(a==null?void 0:a.outerContainer.nextSibling);n.forEach(function(_ref156,p){var f=_ref156.type,m=_ref156.elements;var y;Q.setElementProps(e,m,f,i),(y=d.parentElement)==null||y.insertBefore(m.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(c+p,0,m);}),Ee.removeFilesMessages(e,t),t[1].files=n.map(function(_ref157){var f=_ref157.elements;return f;}),t[0].files=s;}},{key:"updateTextMessage",value:function updateTextMessage(e,t,s){var i,n;if(t[1].text)e.renderText(t[1].text.bubbleElement,s,t[0].role);else{var o=e.createElements(s,t[0].role),a=((i=t[1].files)==null?void 0:i[0])||t[1].html;(n=a.outerContainer.parentElement)==null||n.insertBefore(o.outerContainer,a.outerContainer);var l=e.messageElementRefs.findIndex(function(c){return c===a;});e.messageElementRefs.splice(l,0,o),t[1].text=o;}t[0].text=s;}},{key:"isElementActive",value:function isElementActive(e){var t,s;return xe.isActiveElement((t=e.text)==null?void 0:t.bubbleElement.classList)||xe.isActiveElement((s=e.html)==null?void 0:s.bubbleElement.classList);}// note that overwrite and 'deep-chat-temporary-message' are used to remove a message
|
232
|
+
},{key:"update",value:function update(e,t,s){var i=e.messageToElements[s];if(i){if(Ee.isElementActive(i[1]))return console.error("Cannot update a message that is being streamed");t.text&&Ee.updateTextMessage(e,i,t.text),t.files?Ee.updateFileMessages(e,i,t.files):Ee.removeFilesMessages(e,i),t.html&&Ee.updateHTMLMessage(e,i,t.html),!t.text&&i[1].text&&Ee.removeTextHTMLMessage(e,i,"text"),!t.html&&i[1].html&&Ee.removeTextHTMLMessage(e,i,"html");var n=e.messageElementRefs,o=e.avatar,a=e.name;b.classifyRoleMessages(n),b.resetAllRoleElements(n,o,a);}else console.error("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var al=/*#__PURE__*/function(){function al(){_classCallCheck(this,al);}return _createClass(al,null,[{key:"getText",value:function getText(e,t){var s;if(!e.directConnection&&!e.connect&&!e.webModel&&!e.demo)return"Connect to any API using the [connect](https://deepchat.dev/docs/connect#connect-1) property or a popular service via [directConnection](https://deepchat.dev/docs/directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](https://deepchat.dev/docs/webModel).\n To get started checkout the [Start](https://deepchat.dev/start) page and live code [examples](https://deepchat.dev/examples/frameworks).\n To remove this message set the [demo](https://deepchat.dev/docs/modes#demo) property to true.";if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](https://deepchat.dev/docs/directConnection/#directConnection) object.";var i=(s=e.directConnection.openAI)==null?void 0:s.chat;if(_typeof(i)=="object"&&i.tools&&!i.function_handler)return"Please define the `function_handler` property inside the openAI [chat](https://deepchat.dev/docs/directConnection/openAI#Chat) object.";}else if(e.connect&&!e.connect.url&&!e.connect.handler)return"Please define a `url` or a `handler` property inside the [connect](https://deepchat.dev/docs/connect#connect-1) object.";return null;}}]);}();var xe=/*#__PURE__*/function(_we){function xe(e,t,s){var _this82;_classCallCheck(this,xe);var a,l;_this82=_callSuper(this,xe,[e]);var i=t.permittedErrorPrefixes,n=t.introPanelMarkUp,o=t.demo;_this82._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this82._onClearMessages=xs.onClearMessages.bind(_this82,e),_this82._onError=xs.onError.bind(_this82,e),_this82._isLoadingMessageAllowed=xe.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this82.setLoadingToggle.bind(_this82)),_this82._permittedErrorPrefixes=i,_this82.addSetupMessageIfNeeded(e,t)||_this82.populateIntroPanel(s,n,e.introPanelStyle),o&&_this82.prepareDemo(le.processDemo(o),e.loadHistory),_this82.addIntroductoryMessages(e,t),new ws(e,_this82,t),_this82._displayServiceErrorMessages=(l=e.errorMessages)==null?void 0:l.displayServiceErrorMessages,e.getMessages=function(){return b.deepCloneMessagesWithReferences(_this82.messageToElements.map(function(_ref158){var _ref159=_slicedToArray(_ref158,1),c=_ref159[0];return c;}));},e.clearMessages=_this82.clearMessages.bind(_this82,t),e.refreshMessages=_this82.refreshTextMessages.bind(_this82,e.remarkable),e.scrollToBottom=ae.scrollToBottom.bind(_this82,_this82.elementRef),e.addMessage=function(c,d){_this82.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(c,d){return Ee.update(_this82,c,d);},t.isWebModel()&&t.setUpMessages(_this82),e.textToSpeech&&Dt.processConfig(e.textToSpeech,function(c){_this82.textToSpeech=c;});return _this82;}// WORK - document how to display loading with toggle after user message via onMessage
|
233
|
+
_inherits(xe,_we);return _createClass(xe,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1];!e&&we.isLoadingMessage(t)?(this.removeLastMessage(),delete this._activeLoadingConfig):(this._activeLoadingConfig&&this.removeLastMessage(),this._activeLoadingConfig=e||{},this.addLoadingMessage(!0));}},{key:"prepareDemo",value:function prepareDemo(e,t){var s;if(_typeof(e)=="object"){if(!t&&e.displayLoading){var i=e.displayLoading.history;i!=null&&i.small&&Ze.addMessage(this,!1),i!=null&&i.full&&Ze.addMessage(this);}e.displayErrors&&(e.displayErrors["default"]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage(F,""),e.displayErrors.speechToText&&this.addNewErrorMessage("speechToText","")),(s=e.displayLoading)!=null&&s.message&&this.addLoadingMessage(),e.response&&(this.customDemoResponse=e.response);}}},{key:"addSetupMessageIfNeeded",value:function addSetupMessageIfNeeded(e,t){var s=al.getText(e,t);if(s){var i=this.createAndAppendNewMessageElement(s,b.AI_ROLE);this.applyCustomStyles(i,b.AI_ROLE,!1);}return!!s;}// WORK - const file for deep chat classes
|
234
|
+
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this83=this;e!=null&&e.shadowRoot&&(this._introMessage=e.introMessage);var s=this._introMessage;t!=null&&t.isWebModel()&&(s!==null&&s!==void 0?s:s=t.getIntroMessage(s));var i=!(e!=null&&e.history)&&!!(e!=null&&e.loadHistory||t!=null&&t.fetchHistory);s&&(Array.isArray(s)?s.forEach(function(n,o){if(o!==0){var a=_this83.messageElementRefs[_this83.messageElementRefs.length-1].innerContainer;b.hideRoleElements(a,_this83.avatar,_this83.name);}_this83.addIntroductoryMessage(n,i);}):this.addIntroductoryMessage(s,i));}},{key:"addIntroductoryMessage",value:function addIntroductoryMessage(e,t){var i;var s;return e!=null&&e.text?s=this.createAndAppendNewMessageElement(e.text,b.AI_ROLE):e!=null&&e.html&&(s=De.add(this,e.html,b.AI_ROLE)),s&&(this.applyCustomStyles(s,b.AI_ROLE,!1,(i=this.messageStyles)==null?void 0:i.intro),s.outerContainer.classList.add(we.INTRO_CLASS),t&&(s.outerContainer.style.display="none")),s;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer.classList.contains(we.INTRO_CLASS)&&(e.outerContainer.remove(),this.messageElementRefs.shift());}},{key:"addAnyMessage",value:function addAnyMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;return e.error?this.addNewErrorMessage(F,e.error,s):this.addNewMessage(e,t,s);}},{key:"tryAddTextMessage",value:function tryAddTextMessage(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;!s.ignoreText&&e.text!==void 0&&s.text!==null&&(this.addNewTextMessage(e.text,e.role,t,n),!i&&this.textToSpeech&&e.role!==b.USER_ROLE&&Dt.speak(e.text,this.textToSpeech));}},{key:"tryAddFileMessages",value:function tryAddFileMessages(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;e.files&&Array.isArray(e.files)&&bi.addMessages(this,e.files,e.role,t);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e.html!==void 0&&e.html!==null){var i=De.add(this,e.html,e.role,t,s);!s&&Pe.isElementTemporary(i)&&delete e.html;}}// this should not be activated by streamed messages
|
235
|
+
},{key:"addNewMessage",value:function addNewMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var a,l,c,d;e.role!==b.USER_ROLE&&((a=this._hiddenAttachments)==null||a.removeHiddenFiles());var i=xe.createMessageContent(e),n=(c=(l=this.textToSpeech)==null?void 0:l.service)==null?void 0:c.displayText;typeof n=="boolean"&&!n&&delete i.text;var o={status:e.overwrite};return s?(this.tryAddHTMLMessage(i,o,s),this.tryAddFileMessages(i,s),this.tryAddTextMessage(i,o,e,t,s)):(this.tryAddTextMessage(i,o,e,t,s),this.tryAddFileMessages(i,s),this.tryAddHTMLMessage(i,o,s)),this.isValidMessageContent(i)&&!s&&(this.updateStateOnMessage(i,e.overwrite,e.sendUpdate,t),t||(d=this.browserStorage)==null||d.addMessages(this.messageToElements.map(function(_ref160){var _ref161=_slicedToArray(_ref160,1),h=_ref161[0];return h;}))),this._activeLoadingConfig&&this.addLoadingMessage(!1),i;}},{key:"isValidMessageContent",value:function isValidMessageContent(e){return e.text||e.html||e.files&&e.files.length>0;}},{key:"updateStateOnMessage",value:function updateStateOnMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(!t){var n=b.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,n]);}s&&this.sendClientUpdate(e,i);}// prettier-ignore
|
236
|
+
},{key:"removeMessageOnError",value:function removeMessageOnError(){var e=this.messageElementRefs[this.messageElementRefs.length-1],t=e==null?void 0:e.bubbleElement;(t!=null&&t.classList.contains(Fe.MESSAGE_CLASS)&&t.textContent===""||xe.isTemporaryElement(e))&&this.removeLastMessage();}// prettier-ignore
|
237
|
+
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this84=this;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var c,d,h,u,f,m;(c=this._hiddenAttachments)==null||c.readdHiddenFiles(),this.removeMessageOnError();var i=this.getPermittedMessage(t)||((d=this._errorMessageOverrides)==null?void 0:d[e])||((h=this._errorMessageOverrides)==null?void 0:h["default"])||"Error, please try again.",n=this.createMessageElementsOnOrientation(i,"error",s);b.hideRoleElements(n.innerContainer,this.avatar,this.name);var o=n.bubbleElement,a=n.outerContainer;o.classList.add(b.ERROR_MESSAGE_TEXT_CLASS),this.renderText(o,i);var l=he.extractParticularSharedStyles(["fontSize","fontFamily"],(u=this.messageStyles)==null?void 0:u["default"]);he.applyCustomStylesToElements(n,!1,l),he.applyCustomStylesToElements(n,!1,(f=this.messageStyles)==null?void 0:f.error),s||this.appendOuterContainerElemet(a),this.textToSpeech&&Dt.speak(i,this.textToSpeech),(m=this._onError)==null||m.call(this,i),setTimeout(function(){return ae.scrollToBottom(_this84.elementRef);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=xe.extractErrorMessages(e);for(var _s12=0;_s12<t.length;_s12+=1){var i=t[_s12];if(typeof i=="string"){if(this._displayServiceErrorMessages)return i;if(this._permittedErrorPrefixes){var n=xe.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,i);if(n)return n;}}}}}},{key:"removeError",value:function removeError(){this.isLastMessageError()&&b.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:b.AI_ROLE;var s=this.createMessageElements("",t),i=s.bubbleElement;s.bubbleElement.classList.add(Xe.DOTS_CONTAINER_CLASS);var n=document.createElement("div");return n.classList.add("loading-message-dots"),i.appendChild(n),Xe.setDots(i,e),s;}// prettier-ignore
|
238
|
+
},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var o,a,l,c,d,h;if(we.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((o=this._activeLoadingConfig)==null?void 0:o.role)||b.AI_ROLE,s=((a=this._activeLoadingConfig)==null?void 0:a.style)||((c=(l=this.messageStyles)==null?void 0:l.loading)==null?void 0:c.message),i=s==null?void 0:s.html,n=i?De.createElements(this,i,t,!1):this.addDefaultLoadingMessage(s,t);this.appendOuterContainerElemet(n.outerContainer),n.bubbleElement.classList.add(Xe.BUBBLE_CLASS),this.applyCustomStyles(n,t,!1,s==null?void 0:s.styles),(h=(d=this.avatar)==null?void 0:d.getAvatarContainer(n.innerContainer))==null||h.classList.add("loading-avatar-container"),this.focusMode||ae.scrollToBottom(this.elementRef);}},{key:"populateIntroPanel",value:function populateIntroPanel(e,t,s){(e||t)&&(this._introPanel=new yi(e,t,s),this._introPanel._elementRef&&(oe.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef)));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_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._hiddenAttachments=t,Promise.all((e||[]).map(function(s){return new Promise(function(i){if(!s.type||s.type==="any"){var n=s.file.name||Q.DEFAULT_FILE_NAME;i({name:n,type:"any",ref:s.file});}else{var _n3=new FileReader();_n3.readAsDataURL(s.file),_n3.onload=function(){i({src:_n3.result,type:s.type,ref:s.file});};}});}))));}},_callee172,this);}));function addMultipleFiles(_x313,_x314){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
|
239
|
+
function clearMessages(e,t){var _this$messageToElemen;var n,o,a;var s=[];this.messageElementRefs.forEach(function(l){xe.isActiveElement(l.bubbleElement.classList)?s.push(l):l.outerContainer.remove();}),Array.from(this.elementRef.children).forEach(function(l){var d;var c=(d=l.children[0])==null?void 0:d.children[0];c!=null&&c.classList.contains(b.ERROR_MESSAGE_TEXT_CLASS)&&l.remove();}),this.messageElementRefs=s;var i=this.messageToElements.filter(function(l){return l[1].text&&xe.isActiveElement(l[1].text.bubbleElement.classList)||l[1].html&&xe.isActiveElement(l[1].html.bubbleElement.classList);});(_this$messageToElemen=this.messageToElements).splice.apply(_this$messageToElemen,[0,this.messageToElements.length].concat(_toConsumableArray(i))),t!==!1&&((n=this._introPanel)!=null&&n._elementRef&&this._introPanel.display(),this.addIntroductoryMessages()),(o=this.browserStorage)==null||o.clear(),(a=this._onClearMessages)==null||a.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref162;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===S?!1:!!e.displayLoadingBubble:(_ref162=_typeof(e.displayLoadingBubble)===S||e.displayLoadingBubble)!==null&&_ref162!==void 0?_ref162:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _s13=0;_s13<e.length;_s13+=1)if(t.startsWith(e[_s13]))return t;}},{key:"extractErrorMessages",value:function extractErrorMessages(e){return Array.isArray(e)?e:e instanceof Error?[e.message]:typeof e=="string"?[e]:_typeof(e)=="object"&&e.error?[e.error]:[];}},{key:"isActiveElement",value:function isActiveElement(e){return e?e.contains(Xe.BUBBLE_CLASS)||e.contains(Ze.CLASS)||e.contains(Fe.MESSAGE_CLASS):!1;}}]);}(we);var Z=/*#__PURE__*/function(){function Z(){_classCallCheck(this,Z);}return _createClass(Z,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t["inside-left"].length>0&&e.classList.add("text-input-inner-left-adjustment"),t["inside-right"].length>0&&e.classList.add("text-input-inner-right-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,s){s["outside-right"].length===0&&s["outside-left"].length>0?(e[0].classList.add(Z.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS),t.classList.add(Z.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS)):s["outside-left"].length===0&&s["outside-right"].length>0&&(e[3].classList.add(Z.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS),t.classList.add(Z.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS));}// when submit is the only button
|
241
240
|
// when submit button is outside by itself - we increase the height for a better look
|
242
|
-
},{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,s){if(!(s["inside-left"].length>0||s["inside-right"].length>0)){if(s["outside-right"].length===0&&s["outside-left"].length>0)return e[0].classList.add(
|
243
|
-
},{key:"set",value:function set(e,t,s,i){!!
|
244
|
-
function
|
245
|
-
},{key:"setDropupItem",value:function setDropupItem(e){this.elementRef=e,this._originalElementRef=e.cloneNode(!0),this.changeState(this._state,!0);}},{key:"genStateInnerElements",value:function genStateInnerElements(e,t,s,i){var l,c,d,
|
241
|
+
},{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,s){if(!(s["inside-left"].length>0||s["inside-right"].length>0)){if(s["outside-right"].length===0&&s["outside-left"].length>0)return e[0].classList.add(Z.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),t.classList.add(Z.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),s["outside-left"].map(function(i){return i.button.elementRef.classList.add("submit-button-enlarged");});if(s["outside-left"].length===0&&s["outside-right"].length>0)return e[3].classList.add(Z.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),t.classList.add(Z.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),s["outside-right"].map(function(i){return i.button.elementRef.classList.add("submit-button-enlarged");});}}// prettier-ignore
|
242
|
+
},{key:"set",value:function set(e,t,s,i){!!Z.adjustOutsideSubmit(t,s,i)||Z.adjustForOutsideButton(t,s,i),Z.adjustInputPadding(e,i);}}]);}();Z.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment",Z.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment",Z.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment",Z.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var nn=Z;var Ut=/*#__PURE__*/function(){function Ut(){_classCallCheck(this,Ut);}return _createClass(Ut,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var s=document.createElement("div");return s.classList.add("input-button-container"),(t===0||t===3)&&s.classList.add("outer-button-container"),(t===1||t===2)&&s.classList.add("inner-button-container"),s;});}},{key:"add",value:function add(e,t){e.insertBefore(t[1],e.firstChild),e.insertBefore(t[0],e.firstChild),e.appendChild(t[2]),e.appendChild(t[3]);}},{key:"getContainerIndex",value:function getContainerIndex(e){return e==="outside-left"?0:e==="inside-left"?1:e==="inside-right"?2:3;}},{key:"addButton",value:function addButton(e,t,s){t.classList.add(s);var i=Ut.getContainerIndex(s);e[i].appendChild(t),i===3&&t.classList.add("outside-right");}}]);}();var jn=["camera","gifs","images","audio","mixedFiles","submit","microphone"],ll="<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",fe=/*#__PURE__*/function(){function fe(){_classCallCheck(this,fe);}return _createClass(fe,null,[{key:"addItemEvents",value:function addItemEvents(e,t,s,i){lt.add(t,i),t.addEventListener("click",function(){s.click();}),t.addEventListener("mouseenter",function(n){e.highlightedItem=n.target;}),t.addEventListener("mouseleave",function(){e.highlightedItem=void 0;});}},{key:"createItemText",value:function createItemText(e,t){var s=document.createElement("div");return Object.assign(s.style,t),s.classList.add(fe.TEXT_CLASS),s.textContent=e||"File",s;}},{key:"createItemIcon",value:function createItemIcon(e,t){var s=document.createElement("div");return Object.assign(s.style,t),s.classList.add(fe.ICON_CLASS),s.appendChild(e),s;}},{key:"populateItem",value:function populateItem(e,t,s){var i=e.elementRef,n=e.dropupText,o=e.svg,a=e.customStyles,l=i.children[0],c=a&&Object.values(a).find(function(d){var h;return((h=d.svg)==null?void 0:h.content)==="";});l.classList.contains(Ue.INPUT_BUTTON_INNER_TEXT_CLASS)?(c||t.appendChild(fe.createItemIcon(o,s==null?void 0:s.iconContainer)),t.appendChild(fe.createItemText(l.textContent,s==null?void 0:s.text))):(c||t.appendChild(fe.createItemIcon(i.children[0],s==null?void 0:s.iconContainer)),t.appendChild(fe.createItemText(n,s==null?void 0:s.text)));}},{key:"createItem",value:function createItem(e,t,s){var o;var i=document.createElement("div");Object.assign(i.style,(o=s==null?void 0:s.item)==null?void 0:o["default"]),fe.populateItem(t,i,s),i.classList.add(fe.MENU_ITEM_CLASS);var n=t.elementRef;if(t.isCustom)t.setDropupItem(i);else{var a=U.processStateful((s==null?void 0:s.item)||{});fe.addItemEvents(e,i,n,a);}return i;}}]);}();fe.MENU_ITEM_CLASS="dropup-menu-item",fe.TEXT_CLASS="dropup-menu-item-text",fe.ICON_CLASS="dropup-menu-item-icon";var Oe=fe;var H=/*#__PURE__*/function(_Mt2){// prettier-ignore
|
243
|
+
function H(e,t,s,i){var _this85;_classCallCheck(this,H);var l,c,d,h,u,f;var n=((h=(d=(c=(l=e==null?void 0:e.styles)==null?void 0:l.button)==null?void 0:c["default"])==null?void 0:d.text)==null?void 0:h.content)||"Custom ".concat(t),o=ll,a=Le.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this85=_callSuper(this,H,[H.createButtonElement(),o,e==null?void 0:e.position,a,((u=e==null?void 0:e.styles)==null?void 0:u.button)||a&&{},n]),_this85._state="default",_this85.isCustom=!0,_this85._innerElements=_this85.createInnerElementsForStates(_this85.customStyles),_this85._menuStyles=i,_this85._onClick=e.onClick,_this85._dropupStyles=(f=e.styles)==null?void 0:f.dropup,_this85.setSetState(e),_this85.addClickListener(s),_this85.changeState(e.initialState,!0);return _this85;}_inherits(H,_Mt2);return _createClass(H,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="custom-icon",s=this.createInnerElements(t,"default",e);return{"default":s,active:this.genStateInnerElements(t,"active",s,e),disabled:this.genStateInnerElements(t,"disabled",s,e)};}},{key:"setSetState",value:function setSetState(e){var _this86=this;e.setState=function(t){t==="default"&&_this86.changeToDefault(),t==="active"&&_this86.changeToActive(),t==="disabled"&&_this86.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this87=this;this.elementRef.addEventListener("click",function(){var s;var t=(s=_this87._onClick)==null?void 0:s.call(_this87,_this87._state);e==null||e(),(t==="default"||t==="active"||t==="disabled")&&_this87.changeState(t);});}},{key:"changeState",value:function changeState(e,t){e==="disabled"?this.changeToDisabled(t):e==="active"?this.changeToActive(t):this.changeToDefault(t);}},{key:"applyDropupContentStyles",value:function applyDropupContentStyles(e){var t=Array.from(this.elementRef.children);if(e!=null&&e.text){var _s14=t.find(function(i){return i.classList.contains(Oe.TEXT_CLASS);});_s14&&Object.assign(_s14.style,e.text);}if(e!=null&&e.iconContainer){var _s15=t.find(function(i){return i.classList.contains(Oe.ICON_CLASS);});_s15&&Object.assign(_s15.style,e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var s,i,n;this.elementRef=oe.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((s=e==null?void 0:e.svg)==null?void 0:s.content)===""||this.elementRef.appendChild(Oe.createItemIcon(this.svg,(i=this._menuStyles)==null?void 0:i.iconContainer)),this.elementRef.appendChild(Oe.createItemText(this.dropupText,(n=this._menuStyles)==null?void 0:n.text));}},{key:"assignDropupItemStyle",value:function assignDropupItemStyle(e,t){var i;this.elementRef.parentElement&&this._originalElementRef&&this.resetDropupItem(t),this.applyDropupContentStyles(e),Object.assign(this.elementRef.style,(i=e==null?void 0:e.item)==null?void 0:i["default"]);var s=U.processStateful((e==null?void 0:e.item)||{});lt.add(this.elementRef,s),this.addClickListener();}},{key:"changeToDefault",value:function changeToDefault(e){var t,s,i,n,o,a;!e&&this._state==="default"||(this.elementRef.classList.contains(Oe.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t["default"],(s=this.customStyles)==null?void 0:s["default"]):(this.changeElementsByState(this._innerElements["default"]),(i=this.customStyles)!=null&&i.active&&J.unsetAllCSS(this.elementRef,(n=this.customStyles)==null?void 0:n.active),(o=this.customStyles)!=null&&o.disabled&&J.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a.disabled),this.reapplyStateStyle("default",["active","disabled"])),this.elementRef.classList.remove(H.DISABLED_CONTAINER_CLASS,H.ACTIVE_CONTAINER_CLASS),this.elementRef.classList.add(H.DEFAULT_CONTAINER_CLASS),j.removeAriaDisabled(this.elementRef),this._state="default");}},{key:"changeToActive",value:function changeToActive(e){var t,s;!e&&this._state==="active"||(this.elementRef.classList.contains(Oe.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t.active,(s=this.customStyles)==null?void 0:s.active):(this.changeElementsByState(this._innerElements.active),this.reapplyStateStyle("active",["disabled","default"])),this.elementRef.classList.remove(H.DISABLED_CONTAINER_CLASS,H.DEFAULT_CONTAINER_CLASS),this.elementRef.classList.add(H.ACTIVE_CONTAINER_CLASS),j.removeAriaDisabled(this.elementRef),this._state="active");}},{key:"changeToDisabled",value:function changeToDisabled(e){var t,s,i,n,o,a;!e&&this._state==="disabled"||(this.elementRef.classList.contains(Oe.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t.disabled,(s=this.customStyles)==null?void 0:s.disabled):(this.changeElementsByState(this._innerElements.disabled),(i=this.customStyles)!=null&&i.active&&J.unsetAllCSS(this.elementRef,(n=this.customStyles)==null?void 0:n.active),(o=this.customStyles)!=null&&o["default"]&&J.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a["default"]),this.reapplyStateStyle("disabled",["default","active"])),this.elementRef.classList.remove(H.ACTIVE_CONTAINER_CLASS,H.DEFAULT_CONTAINER_CLASS),this.elementRef.classList.add(H.DISABLED_CONTAINER_CLASS),j.addAriaDisabled(this.elementRef),this._state="disabled");}// called after class is initialised
|
244
|
+
},{key:"setDropupItem",value:function setDropupItem(e){this.elementRef=e,this._originalElementRef=e.cloneNode(!0),this.changeState(this._state,!0);}},{key:"genStateInnerElements",value:function genStateInnerElements(e,t,s,i){var l,c,d,h;var n=this.createInnerElements(e,t,i);var o=(c=(l=i==null?void 0:i[t])==null?void 0:l.svg)==null?void 0:c.content,a=(h=(d=i==null?void 0:i[t])==null?void 0:d.text)==null?void 0:h.content;if(o===void 0||a===void 0){var _hs$parseSVGTextEleme4=hs.parseSVGTextElements(s),u=_hs$parseSVGTextEleme4.svg,f=_hs$parseSVGTextEleme4[g],_hs$parseSVGTextEleme5=hs.parseSVGTextElements(n),m=_hs$parseSVGTextEleme5.svg,p=_hs$parseSVGTextEleme5[g],y=[];H.addToInnerElements(y,o,u,m),H.addToInnerElements(y,a,f,p),n=y;}return n;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button",H.BUTTON_CLASS),e;}},{key:"addToInnerElements",value:function addToInnerElements(e,t,s,i){t===void 0&&s?e.push(s.cloneNode(!0)):i&&e.push(i);}},{key:"add",value:function add(e,t){var s=e.customButtons,i=e.focusInput,n=e.dropupStyles;s==null||s.forEach(function(o,a){var l={button:new H(o,a+1,i,n==null?void 0:n.menu)};t["".concat(H.INDICATOR_PREFIX).concat(a+1)]=l;});}}]);}(Mt);H.INDICATOR_PREFIX="custom",H.BUTTON_CLASS="custom-button",H.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",H.DEFAULT_CONTAINER_CLASS="custom-button-container-default",H.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var xt=H;var cl="<?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 Ts=/*#__PURE__*/function(){function Ts(){_classCallCheck(this,Ts);}return _createClass(Ts,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var s=t?e.children[0]:e.children[e.children.length-1];Ts.focusSiblingItem(s,e,t,!0);}// isEdgeItem means is it a start or end item
|
246
245
|
// prettier-ignore
|
247
|
-
},{key:"focusSiblingItem",value:function focusSiblingItem(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var n=i?e:e[s?"nextSibling":"previousSibling"];n?(e.dispatchEvent(new MouseEvent("mouseleave")),n.dispatchEvent(new MouseEvent("mouseenter"))):(e.dispatchEvent(new MouseEvent("mouseleave")),
|
246
|
+
},{key:"focusSiblingItem",value:function focusSiblingItem(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var n=i?e:e[s?"nextSibling":"previousSibling"];n?(e.dispatchEvent(new MouseEvent("mouseleave")),n.dispatchEvent(new MouseEvent("mouseenter"))):(e.dispatchEvent(new MouseEvent("mouseleave")),Ts.focusItemWhenOnEdge(t,s));}}]);}();var yn=/*#__PURE__*/function(){function yn(e,t){var _this88=this;_classCallCheck(this,yn);var s;this._isOpen=!0,this._styles=t,this.elementRef=yn.createElement((s=this._styles)==null?void 0:s.container),this.close(),setTimeout(function(){return _this88.addWindowEvents(e);});}return _createClass(yn,[{key:"open",value:function open(){this.elementRef.style.display="block",this._isOpen=!0;}},{key:"close",value:function close(){this._isOpen&&(this.elementRef.style.display="none",this._isOpen=!1);}},{key:"toggle",value:function toggle(){this._isOpen?this.close():this.open();}},{key:"addItem",value:function addItem(e){var t=Oe.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
|
248
247
|
},{key:"addWindowEvents",value:function addWindowEvents(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener("click",this.clickEvent),this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent);}},{key:"windowClick",value:function windowClick(e,t){var s;!e.isConnected&&this.clickEvent?window.removeEventListener("click",this.clickEvent):e.parentElement!==((s=t.target.shadowRoot)==null?void 0:s.children[0])&&this.close();}// prettier-ignore
|
249
|
-
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var s,i,n;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===
|
250
|
-
function addToDropup(e,t,s,i){var n=new
|
251
|
-
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=
|
252
|
-
},{key:"addButtons",value:function addButtons(e,t,s,i){var n=Q.generatePositionToButtons(t);return Q.addToSideContainer(e,n),n["dropup-menu"].length>0&&Q.addToDropup(e,n,s,i),n;}}]);}();var Va="<?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>",za="<?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",Ga="<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>",Ka="<?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",Ja={images:{id:"upload-images-icon",svgString:za,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:Ka,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:Ga,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:Va,dropupText:"File"}};var mi=/*#__PURE__*/function(_yt4){function mi(e){var _this91;_classCallCheck(this,mi);(e==null?void 0:e.position)==="dropup-menu"&&(e.position="outside-right");var t=Ee.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this91=_callSuper(this,mi,[mi.createMicrophoneElement(),or,e==null?void 0:e.position,t,e]),_this91.isActive=!1,_this91._innerElements=_this91.createInnerElementsForStates(_this91.customStyles),_this91.changeToDefault();return _this91;}_inherits(mi,_yt4);return _createClass(mi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return{"default":this.createInnerElements(t,"default",e),active:this.createInnerElements(t,"active",e),unsupported:this.createInnerElements(t,"unsupported",e),commandMode:this.createInnerElements(t,"commandMode",e)};}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements.active),this.toggleIconFilter("active"),this.reapplyStateStyle("active",["default","commandMode"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements["default"]),this.toggleIconFilter("default"),this.reapplyStateStyle("default",["active","commandMode"]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements.commandMode),this.toggleIconFilter("command"),this.reapplyStateStyle("commandMode",["active"]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements.unsupported),this.elementRef.classList.add("unsupported-microphone"),this.reapplyStateStyle("unsupported",["active"]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()==="svg")switch(e){case"default":t.classList.remove("active-microphone-icon","command-microphone-icon"),t.classList.add("default-microphone-icon");break;case"active":t.classList.remove("default-microphone-icon","command-microphone-icon"),t.classList.add("active-microphone-icon");break;case"command":t.classList.remove("active-microphone-icon","default-microphone-icon"),t.classList.add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=document.createElement("div");return e.id="microphone-button",e.classList.add("input-button"),e;}}]);}(yt);function $a(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r["default"]:r;}var xs={},Mt={},kt={},Lt={},It={},Tn;function gi(){if(Tn)return It;Tn=1,Object.defineProperty(It,"__esModule",{value:!0}),It.Text=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"capitalize",value:function capitalize(t){return t.replace(r.FIRST_CHAR_REGEX,function(s){return s.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(t){return t.replace(r.DOUBLE_LINE,"<p></p>").replace(r.ONE_LINE,"<br>");}},{key:"isCharDefined",value:function isCharDefined(t){return t!==void 0&&t!==" "&&t!==" "&&t!=="\n"&&t!=="";}},{key:"breakupIntoWordsArr",value:function breakupIntoWordsArr(t){return t.split(/(\W+)/);}}]);}();return It.Text=r,r.FIRST_CHAR_REGEX=/\S/,r.DOUBLE_LINE=/\n\n/g,r.ONE_LINE=/\n/g,It;}var An;function cr(){if(An)return Lt;An=1,Object.defineProperty(Lt,"__esModule",{value:!0}),Lt.Translate=void 0;var r=gi();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"translate",value:function translate(s,i){var n=r.Text.breakupIntoWordsArr(s);for(var o=0;o<n.length;o+=1)i[n[o]]&&(n[o]=i[n[o]]);return n.join("");}}]);}();return Lt.Translate=e,Lt;}var Rn;function Wa(){if(Rn)return kt;Rn=1,Object.defineProperty(kt,"__esModule",{value:!0}),kt.WebSpeechTranscript=void 0;var r=cr();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:function extract(s,i,n){var o="";for(var a=s.resultIndex;a<s.results.length;++a){var l=s.results[a][0].transcript;n&&(l=r.Translate.translate(l,n)),s.results[a].isFinal?i+=l:o+=l;}return{interimTranscript:o,finalTranscript:i,newText:o||i};}},{key:"extractSafari",value:function extractSafari(s,i,n){var o="";for(var l=s.resultIndex;l<s.results.length;++l){var c=s.results[l][0].transcript;n&&(c=r.Translate.translate(c,n)),o+=c;}return{interimTranscript:"",finalTranscript:o,newText:o};}}]);}();return kt.WebSpeechTranscript=e,kt;}var Ot={},Mn;function en(){if(Mn)return Ot;Mn=1,Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.Browser=void 0;var r=/*#__PURE__*/_createClass(function r(){_classCallCheck(this,r);});return Ot.Browser=r,r.IS_SAFARI=function(){return r._IS_SAFARI===void 0&&(r._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),r._IS_SAFARI;},Ot;}var Nt={},Pt={},kn;function Xa(){if(kn)return Pt;kn=1,Object.defineProperty(Pt,"__esModule",{value:!0}),Pt.EventListeners=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(t,s){return Array.isArray(t)?t.find(function(i){return s===i;}):s===t?t:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(t){var _this92=this;t.element&&r.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(r.KEY_DOWN_TIMEOUT!==null&&clearTimeout(r.KEY_DOWN_TIMEOUT),r.KEY_DOWN_TIMEOUT=setTimeout(function(){r.KEY_DOWN_TIMEOUT=null,_this92.resetRecording(t);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(t,s){this.mouseDownElement=r.getElementIfFocusedOnAvailable(t,s.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0;}},{key:"add",value:function add(t,s){var i=(s==null?void 0:s.insertInCursorLocation)===void 0||(s==null?void 0:s.insertInCursorLocation);s!=null&&s.element&&i&&(t.mouseDownEvent=r.mouseDownWindow.bind(t,s.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=r.mouseUpWindow.bind(t,s),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=r.keyDownWindow.bind(t,s),document.addEventListener("keydown",t.keyDownEvent));}},{key:"remove",value:function remove(t){document.removeEventListener("mousedown",t.mouseDownEvent),document.removeEventListener("mouseup",t.mouseUpEvent),document.removeEventListener("keydown",t.keyDownEvent);}}]);}();return Pt.EventListeners=r,r.KEY_DOWN_TIMEOUT=null,Pt;}var Dt={},Ln;function Ya(){if(Ln)return Dt;Ln=1,Object.defineProperty(Dt,"__esModule",{value:!0}),Dt.PreResultUtils=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"process",value:function process(t,s,i,n,o){var a=n==null?void 0:n(s,i);return a?(setTimeout(function(){a.restart?t.resetRecording(o):a.stop&&t.stop();}),(a.stop||a.restart)&&a.removeNewText):!1;}}]);}();return Dt.PreResultUtils=r,Dt;}var Bt={},Ft={},In;function dr(){if(In)return Ft;In=1,Object.defineProperty(Ft,"__esModule",{value:!0}),Ft.AutoScroll=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(t,s){s&&!t.isCursorAtEnd&&(t.endPadding="",t.scrollingSpan.innerHTML=" ");}},{key:"scrollGeneric",value:function scrollGeneric(t,s){t.isCursorAtEnd?s.scrollTop=s.scrollHeight:t.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
|
248
|
+
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var s,i,n;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===X.ESCAPE?(this.close(),(s=this.highlightedItem)==null||s.dispatchEvent(new MouseEvent("mouseleave"))):t.key===X.ENTER?((i=this.highlightedItem)==null||i.click(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===X.ARROW_DOWN?Ts.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===X.ARROW_UP&&Ts.focusSiblingItem(this.highlightedItem||this.elementRef.children[0],this.elementRef,!1));}}],[{key:"createElement",value:function createElement(e){var t=document.createElement("div");return t.id="dropup-menu",Object.assign(t.style,e),t;}}]);}();var _t=/*#__PURE__*/function(_Mt3){function _t(e,t){var _this89;_classCallCheck(this,_t);var n,o;var s=Le.tryCreateConfig("Options",(n=t==null?void 0:t.button)==null?void 0:n.tooltip);_this89=_callSuper(this,_t,[_t.createButtonElement(),cl,void 0,s,{styles:(o=t==null?void 0:t.button)==null?void 0:o.styles}]);var i=_this89.createInnerElementsForStates(_this89.customStyles);_this89._menu=new yn(e,t==null?void 0:t.menu),_this89.addClickEvent(),_this89.buttonContainer=_t.createButtonContainer(),_this89.changeElementsByState(i.styles),_this89.buttonContainer.appendChild(_this89.elementRef),_this89.elementRef.classList.add(_t.BUTTON_ICON_CLASS),_this89.buttonContainer.appendChild(_this89._menu.elementRef),_this89.reapplyStateStyle("styles"),_this89.addContainerEvents(e);return _this89;}_inherits(_t,_Mt3);return _createClass(_t,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("dropup-icon","styles",e)};}},{key:"addClickEvent",value:function addClickEvent(){this.elementRef.onclick=this._menu.toggle.bind(this._menu);}},{key:"addItem",value:function addItem(e){this._menu.addItem(e);}},{key:"addContainerEvents",value:function addContainerEvents(e){var _this90=this;e.addEventListener("click",function(t){var s=t.target.classList;!s.contains(_t.BUTTON_ICON_CLASS)&&!s.contains(xt.DISABLED_CONTAINER_CLASS)&&_this90._menu.close();});}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}},{key:"createButtonContainer",value:function createButtonContainer(){var e=document.createElement("div");return e.id="dropup-container",e;}},{key:"getPosition",value:function getPosition(e,t){var s,i;return(s=t==null?void 0:t.button)!=null&&s.position?(i=t==null?void 0:t.button)==null?void 0:i.position:e["outside-left"].length>0&&e["outside-right"].length===0?"outside-right":"outside-left";}}]);}(Mt);_t.BUTTON_ICON_CLASS="dropup-button";var vi=_t;var de=/*#__PURE__*/function(){function de(){_classCallCheck(this,de);}return _createClass(de,null,[{key:"addToDropup",value:// prettier-ignore
|
249
|
+
function addToDropup(e,t,s,i){var n=new vi(s,i);jn.forEach(function(a){var l=t["dropup-menu"].findIndex(function(d){return d.buttonType===a;}),c=t["dropup-menu"][l];c&&(n.addItem(c.button),t["dropup-menu"].splice(l,1));}),t["dropup-menu"].forEach(function(_ref163){var a=_ref163.button;return n.addItem(a);});var o=vi.getPosition(t,i);Ut.addButton(e,n.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){["inside-left","inside-right","outside-left","outside-right"].forEach(function(i){var n=i;t[n].forEach(function(o){Ut.addButton(e,o.button.elementRef,n);});});}},{key:"setPosition",value:function setPosition(e,t,s){var i=_objectSpread(_objectSpread({},e[t]),{},{buttonType:t});s.push(i),delete e[t];}},{key:"createPositionsToButtonsObj",value:function createPositionsToButtonsObj(){return{"dropup-menu":[],"outside-left":[],"inside-left":[],"inside-right":[],"outside-right":[]};}// prettier-ignore
|
250
|
+
},{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=de.createPositionsToButtonsObj();Object.keys(e).forEach(function(i){var o;var n=(o=e[i])==null?void 0:o.button.position;n&&de.setPosition(e,i,t[n]);}),t["inside-right"].length===0&&e.submit&&de.setPosition(e,"submit",t["inside-right"]),t["outside-right"].length===0&&(e.submit?de.setPosition(e,"submit",t["outside-right"]):e.microphone?de.setPosition(e,"microphone",t["outside-right"]):e.camera?de.setPosition(e,"camera",t["outside-right"]):e["".concat(xt.INDICATOR_PREFIX,"1")]&&de.setPosition(e,"".concat(xt.INDICATOR_PREFIX,"1"),t["outside-right"])),e.submit&&de.setPosition(e,"submit",t["outside-left"].length===0?t["outside-left"]:t["inside-right"]),e.microphone&&de.setPosition(e,"microphone",t["outside-left"].length===0?t["outside-left"]:t["inside-right"]);var s=Object.keys(e);return s.length>1||t["dropup-menu"].length>0?(jn.forEach(function(i){e[i]&&t["dropup-menu"].push(_objectSpread(_objectSpread({},e[i]),{},{buttonType:i}));}),s.forEach(function(i){var n=i;n.startsWith(xt.INDICATOR_PREFIX)&&e[n]&&t["dropup-menu"].push(_objectSpread(_objectSpread({},e[n]),{},{customType:n}));})):s.length===1&&de.setPosition(e,s[0],t["outside-right"].length===0?t["outside-right"]:t["outside-left"]),t;}// prettier-ignore
|
251
|
+
},{key:"addButtons",value:function addButtons(e,t,s,i){var n=de.generatePositionToButtons(t);return de.addToSideContainer(e,n),n["dropup-menu"].length>0&&de.addToDropup(e,n,s,i),n;}}]);}();var dl="<?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>",hl="<?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",ul="<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>",fl="<?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",pl={images:{id:"upload-images-icon",svgString:hl,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:fl,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:ul,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:dl,dropupText:"File"}};var Mi=/*#__PURE__*/function(_Mt4){function Mi(e){var _this91;_classCallCheck(this,Mi);(e==null?void 0:e.position)==="dropup-menu"&&(e.position="outside-right");var t=Le.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this91=_callSuper(this,Mi,[Mi.createMicrophoneElement(),Cr,e==null?void 0:e.position,t,e]),_this91.isActive=!1,_this91._innerElements=_this91.createInnerElementsForStates(_this91.customStyles),_this91.changeToDefault();return _this91;}_inherits(Mi,_Mt4);return _createClass(Mi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return{"default":this.createInnerElements(t,"default",e),active:this.createInnerElements(t,"active",e),unsupported:this.createInnerElements(t,"unsupported",e),commandMode:this.createInnerElements(t,"commandMode",e)};}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements.active),this.toggleIconFilter("active"),this.reapplyStateStyle("active",["default","commandMode"]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements["default"]),this.toggleIconFilter("default"),this.reapplyStateStyle("default",["active","commandMode"]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements.commandMode),this.toggleIconFilter("command"),this.reapplyStateStyle("commandMode",["active"]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements.unsupported),this.elementRef.classList.add("unsupported-microphone"),this.reapplyStateStyle("unsupported",["active"]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()==="svg")switch(e){case"default":t.classList.remove("active-microphone-icon","command-microphone-icon"),t.classList.add("default-microphone-icon");break;case"active":t.classList.remove("default-microphone-icon","command-microphone-icon"),t.classList.add("active-microphone-icon");break;case"command":t.classList.remove("active-microphone-icon","default-microphone-icon"),t.classList.add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=document.createElement("div");return e.id="microphone-button",e.classList.add("input-button"),e;}}]);}(Mt);function ml(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r["default"]:r;}var Bs={},qt={},jt={},Vt={},Kt={},Vn;function ki(){if(Vn)return Kt;Vn=1,Object.defineProperty(Kt,"__esModule",{value:!0}),Kt.Text=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"capitalize",value:function capitalize(t){return t.replace(r.FIRST_CHAR_REGEX,function(s){return s.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(t){return t.replace(r.DOUBLE_LINE,"<p></p>").replace(r.ONE_LINE,"<br>");}},{key:"isCharDefined",value:function isCharDefined(t){return t!==void 0&&t!==" "&&t!==" "&&t!=="\n"&&t!=="";}},{key:"breakupIntoWordsArr",value:function breakupIntoWordsArr(t){return t.split(/(\W+)/);}}]);}();return Kt.Text=r,r.FIRST_CHAR_REGEX=/\S/,r.DOUBLE_LINE=/\n\n/g,r.ONE_LINE=/\n/g,Kt;}var Kn;function Rr(){if(Kn)return Vt;Kn=1,Object.defineProperty(Vt,"__esModule",{value:!0}),Vt.Translate=void 0;var r=ki();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"translate",value:function translate(s,i){var n=r.Text.breakupIntoWordsArr(s);for(var o=0;o<n.length;o+=1)i[n[o]]&&(n[o]=i[n[o]]);return n.join("");}}]);}();return Vt.Translate=e,Vt;}var zn;function gl(){if(zn)return jt;zn=1,Object.defineProperty(jt,"__esModule",{value:!0}),jt.WebSpeechTranscript=void 0;var r=Rr();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:function extract(s,i,n){var o="";for(var a=s.resultIndex;a<s.results.length;++a){var l=s.results[a][0].transcript;n&&(l=r.Translate.translate(l,n)),s.results[a].isFinal?i+=l:o+=l;}return{interimTranscript:o,finalTranscript:i,newText:o||i};}},{key:"extractSafari",value:function extractSafari(s,i,n){var o="";for(var l=s.resultIndex;l<s.results.length;++l){var c=s.results[l][0].transcript;n&&(c=r.Translate.translate(c,n)),o+=c;}return{interimTranscript:"",finalTranscript:o,newText:o};}}]);}();return jt.WebSpeechTranscript=e,jt;}var zt={},Gn;function bn(){if(Gn)return zt;Gn=1,Object.defineProperty(zt,"__esModule",{value:!0}),zt.Browser=void 0;var r=/*#__PURE__*/_createClass(function r(){_classCallCheck(this,r);});return zt.Browser=r,r.IS_SAFARI=function(){return r._IS_SAFARI===void 0&&(r._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),r._IS_SAFARI;},zt;}var Gt={},Jt={},Jn;function yl(){if(Jn)return Jt;Jn=1,Object.defineProperty(Jt,"__esModule",{value:!0}),Jt.EventListeners=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(t,s){return Array.isArray(t)?t.find(function(i){return s===i;}):s===t?t:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(t){var _this92=this;t.element&&r.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(r.KEY_DOWN_TIMEOUT!==null&&clearTimeout(r.KEY_DOWN_TIMEOUT),r.KEY_DOWN_TIMEOUT=setTimeout(function(){r.KEY_DOWN_TIMEOUT=null,_this92.resetRecording(t);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(t,s){this.mouseDownElement=r.getElementIfFocusedOnAvailable(t,s.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0;}},{key:"add",value:function add(t,s){var i=(s==null?void 0:s.insertInCursorLocation)===void 0||(s==null?void 0:s.insertInCursorLocation);s!=null&&s.element&&i&&(t.mouseDownEvent=r.mouseDownWindow.bind(t,s.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=r.mouseUpWindow.bind(t,s),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=r.keyDownWindow.bind(t,s),document.addEventListener("keydown",t.keyDownEvent));}},{key:"remove",value:function remove(t){document.removeEventListener("mousedown",t.mouseDownEvent),document.removeEventListener("mouseup",t.mouseUpEvent),document.removeEventListener("keydown",t.keyDownEvent);}}]);}();return Jt.EventListeners=r,r.KEY_DOWN_TIMEOUT=null,Jt;}var $t={},$n;function bl(){if($n)return $t;$n=1,Object.defineProperty($t,"__esModule",{value:!0}),$t.PreResultUtils=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"process",value:function process(t,s,i,n,o){var a=n==null?void 0:n(s,i);return a?(setTimeout(function(){a.restart?t.resetRecording(o):a.stop&&t.stop();}),(a.stop||a.restart)&&a.removeNewText):!1;}}]);}();return $t.PreResultUtils=r,$t;}var Wt={},Xt={},Wn;function Mr(){if(Wn)return Xt;Wn=1,Object.defineProperty(Xt,"__esModule",{value:!0}),Xt.AutoScroll=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(t,s){s&&!t.isCursorAtEnd&&(t.endPadding="",t.scrollingSpan.innerHTML=" ");}},{key:"scrollGeneric",value:function scrollGeneric(t,s){t.isCursorAtEnd?s.scrollTop=s.scrollHeight:t.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
|
253
252
|
// they can only safely be scrolled to the end
|
254
|
-
},{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(t){t.scrollLeft=t.scrollWidth,t.scrollTop=t.scrollHeight;}},{key:"isElementOverflown",value:function isElementOverflown(t){return t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;}},{key:"isRequired",value:function isRequired(t,s){return t&&r.isElementOverflown(s);}}]);}();return
|
253
|
+
},{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(t){t.scrollLeft=t.scrollWidth,t.scrollTop=t.scrollHeight;}},{key:"isElementOverflown",value:function isElementOverflown(t){return t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;}},{key:"isRequired",value:function isRequired(t,s){return t&&r.isElementOverflown(s);}}]);}();return Xt.AutoScroll=r,Xt;}var Yt={},Xn;function Ii(){if(Xn)return Yt;Xn=1,Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.Elements=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"isPrimitiveElement",value:function isPrimitiveElement(t){return t.tagName==="INPUT"||t.tagName==="TEXTAREA";}},{key:"createInterimSpan",value:function createInterimSpan(){var t=document.createElement("span");return t.style.color="grey",t.style.pointerEvents="none",t;}},{key:"createGenericSpan",value:function createGenericSpan(){var t=document.createElement("span");return t.style.pointerEvents="none",t;}},{key:"appendSpans",value:function appendSpans(t,s){if(t.spansPopulated=!0,t.insertInCursorLocation&&document.activeElement===s){var i=window.getSelection();if(i!=null&&i.focusNode){var n=i.getRangeAt(0);n.insertNode(t.scrollingSpan),n.insertNode(t.interimSpan),n.insertNode(t.finalSpan),n.collapse(!1),i.removeAllRanges(),i.addRange(n);return;}}s.appendChild(t.finalSpan),s.appendChild(t.interimSpan),s.appendChild(t.scrollingSpan);}},{key:"applyCustomColors",value:function applyCustomColors(t,s){s.interim&&(t.interimSpan.style.color=s.interim),s["final"]&&(t.finalSpan.style.color=s["final"]);}},{key:"isInsideShadowDOM",value:function isInsideShadowDOM(t){return t.getRootNode()instanceof ShadowRoot;}}]);}();return Yt.Elements=r,Yt;}var Zt={},Yn;function Li(){if(Yn)return Zt;Yn=1,Object.defineProperty(Zt,"__esModule",{value:!0}),Zt.Cursor=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"setOffsetForGeneric",value:function setOffsetForGeneric(t,s){var i=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var n=0;for(var o=0;o<t.childNodes.length;o+=1){var a=t.childNodes[o];if(a.childNodes.length>0){var l=r.setOffsetForGeneric(a,s,i);if(l===-1)return-1;i+=l;}else if(a.textContent!==null){if(i+a.textContent.length>s){var _l5=document.createRange();_l5.setStart(a,s-i),_l5.collapse(!0);var c=window.getSelection();return c==null||c.removeAllRanges(),c==null||c.addRange(_l5),t.focus(),-1;}i+=a.textContent.length,n+=a.textContent.length;}}return n;}},{key:"focusEndOfGeneric",value:function focusEndOfGeneric(t){var s=document.createRange();s.selectNodeContents(t),s.collapse(!1);var i=window.getSelection();i&&(i.removeAllRanges(),i.addRange(s));}},{key:"setOffsetForSafariGeneric",value:function setOffsetForSafariGeneric(t,s){var i=window.getSelection();if(i){var n=r.getGenericElementCursorOffset(t,i,!0);r.setOffsetForGeneric(t,n+s);}}// set to automatically scroll to cursor (scroll does not work in Safari)
|
255
254
|
},{key:"setOffsetForPrimitive",value:function setOffsetForPrimitive(t,s,i){i&&t.blur(),t.setSelectionRange(s,s),t.focus();}// Scroll Input in Safari - does not work for TextArea and uses span which can have a different style
|
256
255
|
// private static getCursorOffsetFromLeft(inputElement: HTMLInputElement, position: number) {
|
257
256
|
// // Get the value of the input element up to the cursor position
|
@@ -269,39 +268,39 @@ function addToDropup(e,t,s,i){var n=new ri(s,i);Cn.forEach(function(a){var l=t["
|
|
269
268
|
// document.body.removeChild(tempSpan);
|
270
269
|
// return {left: offsetWidth, top: offsetHeight};
|
271
270
|
// }
|
272
|
-
},{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(t,s,i){var n=0;if(s.rangeCount>0){var o=s.getRangeAt(0),a=o.cloneRange();a.selectNodeContents(t),i?a.setEnd(o.startContainer,o.startOffset):a.setEnd(o.endContainer,o.endOffset),n=a.toString().length;}return n;}}]);}();return
|
273
|
-
},{key:"execCommand",value:function execCommand(a,l,c,d,
|
271
|
+
},{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(t,s,i){var n=0;if(s.rangeCount>0){var o=s.getRangeAt(0),a=o.cloneRange();a.selectNodeContents(t),i?a.setEnd(o.startContainer,o.startOffset):a.setEnd(o.endContainer,o.endOffset),n=a.toString().length;}return n;}}]);}();return Zt.Cursor=r,Zt;}var Zn;function kr(){if(Zn)return Wt;Zn=1,Object.defineProperty(Wt,"__esModule",{value:!0}),Wt.CommandUtils=void 0;var r=Mr(),e=Ii(),t=bn(),s=Li(),i=ki();var n=/*#__PURE__*/function(){function n(){_classCallCheck(this,n);}return _createClass(n,null,[{key:"processCommand",value:function processCommand(a,l){return(!l||!l.caseSensitive)&&(a=a.toLowerCase()),(l==null?void 0:l.substrings)===!1?i.Text.breakupIntoWordsArr(a):a;}},{key:"process",value:function process(a){var l;return((l=a.settings)===null||l===void 0?void 0:l.caseSensitive)===!0?a:Object.keys(a).reduce(function(d,h){var u=a[h];return d[h]=typeof u=="string"?n.processCommand(u,a.settings):u,d;},{});}},{key:"toggleCommandModeOn",value:function toggleCommandModeOn(a){var l;a.isWaitingForCommand=!0,(l=a.onCommandModeTrigger)===null||l===void 0||l.call(a,!0);}},{key:"toggleCommandModeOff",value:function toggleCommandModeOff(a){var l;a.isWaitingForCommand&&((l=a.onCommandModeTrigger)===null||l===void 0||l.call(a,!1),a.isWaitingForCommand=!1);}},{key:"setText",value:function setText(a,l,c,d){n.toggleCommandModeOff(a),e.Elements.isPrimitiveElement(d)?(d.value=c,a.isTargetInShadow||s.Cursor.setOffsetForPrimitive(d,c.length,!0),t.Browser.IS_SAFARI()&&a.autoScroll&&r.AutoScroll.scrollSafariPrimitiveToEnd(d)):(d.textContent=c,a.isTargetInShadow||s.Cursor.focusEndOfGeneric(d),setTimeout(function(){return r.AutoScroll.scrollGeneric(a,d);})),a.resetRecording(l);}},{key:"checkIfMatchesSubstring",value:function checkIfMatchesSubstring(a,l){return l.includes(a);}},{key:"checkIfMatchesWord",value:function checkIfMatchesWord(a,l,c){var d=a;for(var h=c.length-1;h>=0;h-=1){var u=h,f=d.length-1;for(;c[u]===d[f]&&f>=0;)u-=1,f-=1;if(f<0)return!0;}return!1;}// prettier-ignore
|
272
|
+
},{key:"execCommand",value:function execCommand(a,l,c,d,h){var u,f,m;var p=a.commands;if(!p||!d||!c)return;var y=((u=p.settings)===null||u===void 0?void 0:u.caseSensitive)===!0?l:l.toLowerCase(),_=i.Text.breakupIntoWordsArr(y),I=((f=p.settings)===null||f===void 0?void 0:f.substrings)===!1?n.checkIfMatchesWord:n.checkIfMatchesSubstring;if(p.commandMode&&I(p.commandMode,y,_))return a.setInterimColorToFinal(),setTimeout(function(){return n.toggleCommandModeOn(a);}),{doNotProcessTranscription:!1};if(!(p.commandMode&&!a.isWaitingForCommand)){if(p.stop&&I(p.stop,y,_))return n.toggleCommandModeOff(a),setTimeout(function(){return a.stop();}),{doNotProcessTranscription:!1};if(p.pause&&I(p.pause,y,_))return n.toggleCommandModeOff(a),a.setInterimColorToFinal(),setTimeout(function(){var D;a.isPaused=!0,(D=a.onPauseTrigger)===null||D===void 0||D.call(a,!0);}),{doNotProcessTranscription:!1};if(p.resume&&I(p.resume,y,_))return a.isPaused=!1,(m=a.onPauseTrigger)===null||m===void 0||m.call(a,!1),n.toggleCommandModeOff(a),a.resetRecording(c),{doNotProcessTranscription:!0};if(p.reset&&I(p.reset,y,_))return h!==void 0&&n.setText(a,c,h,d),{doNotProcessTranscription:!0};if(p.removeAllText&&I(p.removeAllText,y,_))return n.setText(a,c,"",d),{doNotProcessTranscription:!0};}}}]);}();return Wt.CommandUtils=n,Wt;}var Qt={},Qn;function vl(){if(Qn)return Qt;Qn=1,Object.defineProperty(Qt,"__esModule",{value:!0}),Qt.Highlight=void 0;var r=Ii(),e=Li();var t=/*#__PURE__*/function(){function t(){_classCallCheck(this,t);}return _createClass(t,null,[{key:"setStateForPrimitive",value:function setStateForPrimitive(i,n){var o,a;n.selectionStart!==null&&(o=n.selectionStart),n.selectionEnd!==null&&(a=n.selectionEnd),i.isHighlighted=o!==a;}},{key:"setStateForGeneric",value:function setStateForGeneric(i,n){var o=window.getSelection();if(o!=null&&o.focusNode){var a=e.Cursor.getGenericElementCursorOffset(n,o,!0),l=e.Cursor.getGenericElementCursorOffset(n,o,!1);i.isHighlighted=a!==l;}}},{key:"setState",value:function setState(i,n){document.activeElement===n&&(r.Elements.isPrimitiveElement(n)?t.setStateForPrimitive(i,n):t.setStateForGeneric(i,n));}},{key:"removeForGeneric",value:function removeForGeneric(i,n){var o=window.getSelection();if(o){var a=e.Cursor.getGenericElementCursorOffset(n,o,!0);o.deleteFromDocument(),e.Cursor.setOffsetForGeneric(n,a),i.isHighlighted=!1;}}},{key:"removeForPrimitive",value:function removeForPrimitive(i,n){var o=n.selectionStart,a=n.selectionEnd,l=n.value;if(o&&a){var c=l.substring(0,o)+l.substring(a);n.value=c,e.Cursor.setOffsetForPrimitive(n,o,i.autoScroll);}i.isHighlighted=!1;}}]);}();return Qt.Highlight=t,Qt;}var es={},er;function _l(){if(er)return es;er=1,Object.defineProperty(es,"__esModule",{value:!0}),es.Padding=void 0;var r=Ii(),e=Li(),t=ki();var s=/*#__PURE__*/function(){function s(){_classCallCheck(this,s);}return _createClass(s,null,[{key:"setStateForPrimitiveElement",value:function setStateForPrimitiveElement(n,o){if(document.activeElement===o&&o.selectionStart!==null){var l=o.selectionStart,c=o.value[l-1],d=o.selectionEnd===null?l:o.selectionEnd,h=o.value[d];t.Text.isCharDefined(c)&&(n.startPadding=" ",n.numberOfSpacesBeforeNewText=1),t.Text.isCharDefined(h)&&(n.endPadding=" ",n.numberOfSpacesAfterNewText=1),n.isCursorAtEnd=o.value.length===d;return;}var a=o.value[o.value.length-1];t.Text.isCharDefined(a)&&(n.startPadding=" ",n.numberOfSpacesBeforeNewText=1),n.isCursorAtEnd=!0;}},{key:"setStateForGenericElement",value:function setStateForGenericElement(n,o){var a,l,c;if(document.activeElement===o){var h=window.getSelection();if(h!=null&&h.focusNode){var u=e.Cursor.getGenericElementCursorOffset(o,h,!0),f=(a=o.textContent)===null||a===void 0?void 0:a[u-1],m=e.Cursor.getGenericElementCursorOffset(o,h,!1),p=(l=o.textContent)===null||l===void 0?void 0:l[m];t.Text.isCharDefined(f)&&(n.startPadding=" "),t.Text.isCharDefined(p)&&(n.endPadding=" "),n.isCursorAtEnd=((c=o.textContent)===null||c===void 0?void 0:c.length)===m;return;}}var d=o.innerText.charAt(o.innerText.length-1);t.Text.isCharDefined(d)&&(n.startPadding=" "),n.isCursorAtEnd=!0;}},{key:"setState",value:function setState(n,o){r.Elements.isPrimitiveElement(o)?s.setStateForPrimitiveElement(n,o):s.setStateForGenericElement(n,o);}},{key:"adjustStateAfterRecodingPrimitiveElement",value:function adjustStateAfterRecodingPrimitiveElement(n,o){if(n.primitiveTextRecorded=!0,n.insertInCursorLocation&&document.activeElement===o&&(o.selectionEnd!==null&&(n.endPadding=n.endPadding+o.value.slice(o.selectionEnd)),o.selectionStart!==null)){n.startPadding=o.value.slice(0,o.selectionStart)+n.startPadding;return;}n.startPadding=o.value+n.startPadding;}},{key:"adjustSateForNoTextPrimitiveElement",value:function adjustSateForNoTextPrimitiveElement(n){n.numberOfSpacesBeforeNewText===1&&(n.startPadding=n.startPadding.substring(0,n.startPadding.length-1),n.numberOfSpacesBeforeNewText=0),n.numberOfSpacesAfterNewText===1&&(n.endPadding=n.endPadding.substring(1),n.numberOfSpacesAfterNewText=0);}}]);}();return es.Padding=s,es;}var tr;function Ir(){if(tr)return Gt;tr=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.Speech=void 0;var r=yl(),e=bl(),t=kr(),s=Mr(),i=vl(),n=Ii(),o=_l(),a=bn(),l=Li(),c=ki();var d=/*#__PURE__*/function(){function d(){_classCallCheck(this,d);this.finalTranscript="",this.interimSpan=n.Elements.createInterimSpan(),this.finalSpan=n.Elements.createGenericSpan(),this.scrollingSpan=n.Elements.createGenericSpan(),this.isCursorAtEnd=!1,this.spansPopulated=!1,this.startPadding="",this.endPadding="",this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.recognizing=!1,this._displayInterimResults=!0,this.insertInCursorLocation=!0,this.autoScroll=!0,this.isRestarting=!1,this.isPaused=!1,this.isWaitingForCommand=!1,this.isTargetInShadow=!1,this.cannotBeStopped=!1,this.resetState();}return _createClass(d,[{key:"prepareBeforeStart",value:function prepareBeforeStart(u){var f,m;if(u!=null&&u.element)if(r.EventListeners.add(this,u),Array.isArray(u.element)){var y=u.element.find(function(_){return _===document.activeElement;})||u.element[0];if(!y)return;this.prepare(y);}else this.prepare(u.element);(u==null?void 0:u.displayInterimResults)!==void 0&&(this._displayInterimResults=u.displayInterimResults),u!=null&&u.textColor&&(this._finalTextColor=(f=u==null?void 0:u.textColor)===null||f===void 0?void 0:f["final"],n.Elements.applyCustomColors(this,u.textColor)),(u==null?void 0:u.insertInCursorLocation)!==void 0&&(this.insertInCursorLocation=u.insertInCursorLocation),(u==null?void 0:u.autoScroll)!==void 0&&(this.autoScroll=u.autoScroll),this._onResult=u==null?void 0:u.onResult,this._onPreResult=u==null?void 0:u.onPreResult,this._onStart=u==null?void 0:u.onStart,this._onStop=u==null?void 0:u.onStop,this._onError=u==null?void 0:u.onError,this.onCommandModeTrigger=u==null?void 0:u.onCommandModeTrigger,this.onPauseTrigger=u==null?void 0:u.onPauseTrigger,this._options=u,!((m=this._options)===null||m===void 0)&&m.commands&&(this.commands=t.CommandUtils.process(this._options.commands));}},{key:"prepare",value:function prepare(u){o.Padding.setState(this,u),i.Highlight.setState(this,u),this.isTargetInShadow=n.Elements.isInsideShadowDOM(u),n.Elements.isPrimitiveElement(u)?(this._primitiveElement=u,this._originalText=this._primitiveElement.value):(this._genericElement=u,this._originalText=this._genericElement.textContent);}// there was an attempt to optimize this by not having to restart the service and just reset state:
|
274
273
|
// unfortunately it did not work because the service would still continue firing the intermediate and final results
|
275
274
|
// into the new position
|
276
|
-
},{key:"resetRecording",value:function resetRecording(
|
277
|
-
},{key:"updateElements",value:function updateElements(
|
275
|
+
},{key:"resetRecording",value:function resetRecording(u){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(u,!0);}// prettier-ignore
|
276
|
+
},{key:"updateElements",value:function updateElements(u,f,m){var p;var y=c.Text.capitalize(f);if(this.finalTranscript===y&&u==="")return;e.PreResultUtils.process(this,m,u==="",this._onPreResult,this._options)&&(u="",m="");var _=this.commands&&t.CommandUtils.execCommand(this,m,this._options,this._primitiveElement||this._genericElement,this._originalText);if(_){if(_.doNotProcessTranscription)return;u="",m="";}if(this.isPaused||this.isWaitingForCommand)return;(p=this._onResult)===null||p===void 0||p.call(this,m,u===""),this.finalTranscript=y,this._displayInterimResults||(u="");var I=this.finalTranscript===""&&u==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,u,I):this._genericElement&&this.updateGenericElement(this._genericElement,u,I);}// prettier-ignore
|
278
277
|
// remember that padding values here contain actual text left and right
|
279
|
-
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(
|
280
|
-
function extract(s,i,n,o){return o&&(s=r.Translate.translate(s,o)),n?{interimTranscript:"",finalTranscript:i+s,newText:s}:{interimTranscript:s,finalTranscript:i,newText:s};}}]);}();return
|
281
|
-
},{key:"onRecognizing",value:function onRecognizing(l,c){if(this._stopping)return;var _i$AzureTranscript$ex=i.AzureTranscript.extract(this._newTextPadding+c.result.text,this.finalTranscript,!1,this._translations),d=_i$AzureTranscript$ex.interimTranscript,
|
282
|
-
},{key:"onRecognized",value:function onRecognized(l,c){var d=c.result;switch(d.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(d.text&&!this._stopping){var _i$AzureTranscript$ex2=i.AzureTranscript.extract(this._newTextPadding+d.text,this.finalTranscript,!0,this._translations),
|
283
|
-
_inherits(
|
284
|
-
function
|
285
|
-
function
|
286
|
-
},{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var s=this._activePlaceholderAttachment;s&&(s.file=e,
|
287
|
-
function create(e,t,s,i,n,o){return o==="audio"?new
|
288
|
-
return _createClass(
|
289
|
-
function
|
278
|
+
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(u,f,m){this.isHighlighted&&i.Highlight.removeForPrimitive(this,u),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,u),m&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var p=this.startPadding+this.finalTranscript+f;if(u.value=p+this.endPadding,!this.isTargetInShadow){var y=p.length+this.numberOfSpacesAfterNewText;l.Cursor.setOffsetForPrimitive(u,y,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&s.AutoScroll.scrollSafariPrimitiveToEnd(u);}},{key:"updateGenericElement",value:function updateGenericElement(u,f,m){this.isHighlighted&&i.Highlight.removeForGeneric(this,u),this.spansPopulated||n.Elements.appendSpans(this,u);var p=(m?"":this.startPadding)+c.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=p;var y=s.AutoScroll.isRequired(this.autoScroll,u);s.AutoScroll.changeStateIfNeeded(this,y);var _=c.Text.lineBreak(f)+(m?"":this.endPadding);this.interimSpan.innerHTML=_,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&l.Cursor.setOffsetForSafariGeneric(u,p.length+_.length),y&&s.AutoScroll.scrollGeneric(this,u),m&&(this.scrollingSpan.innerHTML="");}},{key:"finalise",value:function finalise(u){this._genericElement&&(u?(this.finalSpan=n.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=n.Elements.createInterimSpan(),this.scrollingSpan=n.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),r.EventListeners.remove(this);}},{key:"setInterimColorToFinal",value:function setInterimColorToFinal(){this.interimSpan.style.color=this._finalTextColor||"black";}},{key:"resetState",value:function resetState(u){this._primitiveElement=void 0,this._genericElement=void 0,this.finalTranscript="",this.finalSpan.innerHTML="",this.interimSpan.innerHTML="",this.scrollingSpan.innerHTML="",this.startPadding="",this.endPadding="",this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,u||(this.stopTimeout=void 0);}},{key:"setStateOnStart",value:function setStateOnStart(){var u;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(u=this._onStart)===null||u===void 0||u.call(this);}},{key:"setStateOnStop",value:function setStateOnStop(){var u;this.recognizing=!1,this.isRestarting||(u=this._onStop)===null||u===void 0||u.call(this);}},{key:"setStateOnError",value:function setStateOnError(u){var f;(f=this._onError)===null||f===void 0||f.call(this,u),this.recognizing=!1;}}]);}();return Gt.Speech=d,Gt;}var sr;function El(){if(sr)return qt;sr=1,Object.defineProperty(qt,"__esModule",{value:!0}),qt.WebSpeech=void 0;var r=gl(),e=bn(),t=Ir();var s=/*#__PURE__*/function(_t$Speech){function s(){_classCallCheck(this,s);return _callSuper(this,s);}_inherits(s,_t$Speech);return _createClass(s,[{key:"start",value:function start(n){var o;this._extractText===void 0&&(this._extractText=e.Browser.IS_SAFARI()?r.WebSpeechTranscript.extractSafari:r.WebSpeechTranscript.extract),this.validate()&&(this.prepareBeforeStart(n),this.instantiateService(n),(o=this._service)===null||o===void 0||o.start(),this._translations=n==null?void 0:n.translations);}},{key:"validate",value:function validate(){return s.getAPI()?!0:(this.error("Speech Recognition is unsupported"),!1);}},{key:"instantiateService",value:function instantiateService(n){var o,a;var l=s.getAPI();this._service=new l(),this._service.continuous=!0,this._service.interimResults=(o=n==null?void 0:n.displayInterimResults)!==null&&o!==void 0?o:!0,this._service.lang=((a=n==null?void 0:n.language)===null||a===void 0?void 0:a.trim())||"en-US",this.setEvents();}},{key:"setEvents",value:function setEvents(){var _this93=this;this._service&&(this._service.onstart=function(){_this93.setStateOnStart();},this._service.onerror=function(n){e.Browser.IS_SAFARI()&&n.message==="Another request is started"||n.error==="aborted"&&_this93.isRestarting||n.error!=="no-speech"&&_this93.error(n.message||n.error);},this._service.onaudioend=function(){_this93.setStateOnStop();},this._service.onend=function(){_this93._stopping=!1;},this._service.onresult=function(n){if(_typeof(n.results)>"u"&&_this93._service)_this93._service.onend=null,_this93._service.stop();else if(_this93._extractText&&!_this93._stopping){var _this93$_extractText=_this93._extractText(n,_this93.finalTranscript,_this93._translations),o=_this93$_extractText.interimTranscript,a=_this93$_extractText.finalTranscript,l=_this93$_extractText.newText;_this93.updateElements(o,a,l);}});}},{key:"stop",value:function stop(n){var o;this._stopping=!0,(o=this._service)===null||o===void 0||o.stop(),this.finalise(n);}},{key:"error",value:function error(n){console.error(n),this.setStateOnError(n),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.webkitSpeechRecognition||window.SpeechRecognition;}}]);}(t.Speech);return qt.WebSpeech=s,qt;}var ts={},ir;function Sl(){if(ir)return ts;ir=1,Object.defineProperty(ts,"__esModule",{value:!0}),ts.GlobalState=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"doubleClickDetector",value:function doubleClickDetector(){return r.doubleClickPending?!0:(r.doubleClickPending=!0,setTimeout(function(){r.doubleClickPending=!1;},300),!1);}}]);}();return ts.GlobalState=r,r.doubleClickPending=!1,ts;}var ss={},is={},nr;function xl(){if(nr)return is;nr=1,Object.defineProperty(is,"__esModule",{value:!0}),is.PreventConnectionStop=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"applyPrevention",value:function applyPrevention(t){clearTimeout(t._manualConnectionStopPrevention),t.cannotBeStopped=!0,t._manualConnectionStopPrevention=setTimeout(function(){t.cannotBeStopped=!1;},800);}},{key:"clearPrevention",value:function clearPrevention(t){clearTimeout(t._manualConnectionStopPrevention),t.cannotBeStopped=!1;}}]);}();return is.PreventConnectionStop=r,is;}var ns={},rs={},rr;function wl(){return rr||(rr=1,Object.defineProperty(rs,"__esModule",{value:!0}),rs.README_URL=void 0,rs.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),rs;}var or;function Cl(){if(or)return ns;or=1,Object.defineProperty(ns,"__esModule",{value:!0}),ns.AzureSpeechConfig=void 0;var r=wl();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"validateOptions",value:function validateOptions(s,i){return i?!i.subscriptionKey&&!i.token&&!i.retrieveToken?(s("Please define a 'subscriptionKey', 'token' or 'retrieveToken' property - more info: ".concat(r.README_URL)),!1):i.region?!0:(s("Please define a 'region' property - more info: ".concat(r.README_URL)),!1):(s("Please provide subscription details - more info: ".concat(r.README_URL)),!1);}},{key:"getNewSpeechConfig",value:function(){var _getNewSpeechConfig=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(s,i){return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:if(!i.region){_context173.n=1;break;}return _context173.a(2,i.subscriptionKey?s.fromSubscription(i.subscriptionKey.trim(),i.region.trim()):i.token?s.fromAuthorizationToken(i.token.trim(),i.region.trim()):i.retrieveToken?i.retrieveToken().then(function(n){return i.region?s.fromAuthorizationToken((n==null?void 0:n.trim())||"",i.region.trim()):null;})["catch"](function(n){return console.error(n),null;}):null);case 1:return _context173.a(2);}},_callee173);}));function getNewSpeechConfig(_x315,_x316){return _getNewSpeechConfig.apply(this,arguments);}return getNewSpeechConfig;}()},{key:"process",value:function process(s,i){i.endpointId&&(s.endpointId=i.endpointId.trim()),i.language&&(s.speechRecognitionLanguage=i.language.trim());}},{key:"get",value:function(){var _get=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(s,i){var n;return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:_context174.n=1;return e.getNewSpeechConfig(s,i);case 1:n=_context174.v;return _context174.a(2,(n&&e.process(n,i),n));}},_callee174);}));function get(_x317,_x318){return _get.apply(this,arguments);}return get;}()}]);}();return ns.AzureSpeechConfig=e,ns;}var os={},ar;function Al(){if(ar)return os;ar=1,Object.defineProperty(os,"__esModule",{value:!0}),os.StopTimeout=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"set",value:function set(t){t.stopTimeout=setTimeout(function(){return t.stop();},t.stopTimeoutMS);}},{key:"reset",value:function reset(t,s){t.stopTimeoutMS=s||r.DEFAULT_MS,r.stop(t),r.set(t);}},{key:"stop",value:function stop(t){t.stopTimeout&&clearTimeout(t.stopTimeout);}}]);}();return os.StopTimeout=r,r.DEFAULT_MS=2e4,os;}var as={},lr;function Tl(){if(lr)return as;lr=1,Object.defineProperty(as,"__esModule",{value:!0}),as.AzureAudioConfig=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"get",value:function get(t,s){return s?t.fromMicrophoneInput(s):t.fromDefaultMicrophoneInput();}}]);}();return as.AzureAudioConfig=r,as;}var ls={},cr;function Rl(){if(cr)return ls;cr=1,Object.defineProperty(ls,"__esModule",{value:!0}),ls.AzureTranscript=void 0;var r=Rr();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:// newText is used to only send new text in onResult as finalTranscript is continuously accumulated
|
279
|
+
function extract(s,i,n,o){return o&&(s=r.Translate.translate(s,o)),n?{interimTranscript:"",finalTranscript:i+s,newText:s}:{interimTranscript:s,finalTranscript:i,newText:s};}}]);}();return ls.AzureTranscript=e,ls;}var dr;function Ml(){if(dr)return ss;dr=1,Object.defineProperty(ss,"__esModule",{value:!0}),ss.Azure=void 0;var r=xl(),e=Cl(),t=Al(),s=Tl(),i=Rl(),n=Ir();var o=/*#__PURE__*/function(_n$Speech){function o(){var _this94;_classCallCheck(this,o);_this94=_callSuper(this,o,arguments),_this94._newTextPadding="";return _this94;}_inherits(o,_n$Speech);return _createClass(o,[{key:"start",value:function start(l,c){this._newTextPadding="",this.stopTimeout===void 0&&t.StopTimeout.reset(this,l==null?void 0:l.stopAfterSilenceMs),this.prepareBeforeStart(l),this.startAsync(l),c||r.PreventConnectionStop.applyPrevention(this);}},{key:"startAsync",value:function(){var _startAsync=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(l){var c,_t42;return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:_t42=this.validate(l);if(!_t42){_context175.n=2;break;}_context175.n=1;return this.instantiateService(l);case 1:this._translations=l==null?void 0:l.translations;(c=this._service)===null||c===void 0||c.startContinuousRecognitionAsync(function(){},this.error);case 2:return _context175.a(2);}},_callee175,this);}));function startAsync(_x319){return _startAsync.apply(this,arguments);}return startAsync;}()},{key:"validate",value:function validate(l){return o.getAPI()?e.AzureSpeechConfig.validateOptions(this.error.bind(this),l):(this.moduleNotFound(),!1);}},{key:"instantiateService",value:function(){var _instantiateService=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee176(l){var c,d,h,u,_l$autoLanguage,f,m,p,y;return _regenerator().w(function(_context176){while(1)switch(_context176.n){case 0:c=o.getAPI();d=s.AzureAudioConfig.get(c.AudioConfig,l.deviceId);_context176.n=1;return e.AzureSpeechConfig.get(c.SpeechConfig,l);case 1:h=_context176.v;if(h){if(l.autoLanguage&&l.autoLanguage.languages.length>0){_l$autoLanguage=l.autoLanguage,f=_l$autoLanguage.type,m=_l$autoLanguage.languages,p=m.slice(0,f==="Continuous"?10:4),y=c.AutoDetectSourceLanguageConfig.fromLanguages(p);f==="Continuous"&&(y.mode=1),u=c.SpeechRecognizer.FromConfig(h,y,d);}else u=new c.SpeechRecognizer(h,d);this.setEvents(u),this._service=u,l.retrieveToken&&this.retrieveTokenInterval(l.retrieveToken);}else this.error("Unable to contact Azure server");case 2:return _context176.a(2);}},_callee176,this);}));function instantiateService(_x320){return _instantiateService.apply(this,arguments);}return instantiateService;}()},{key:"setEvents",value:function setEvents(l){l.recognizing=this.onRecognizing.bind(this),l.recognized=this.onRecognized.bind(this),l.sessionStarted=this.onSessionStarted.bind(this),l.canceled=this.onCanceled.bind(this),l.sessionStopped=this.onSessionStopped.bind(this);}// prettier-ignore
|
280
|
+
},{key:"onRecognizing",value:function onRecognizing(l,c){if(this._stopping)return;var _i$AzureTranscript$ex=i.AzureTranscript.extract(this._newTextPadding+c.result.text,this.finalTranscript,!1,this._translations),d=_i$AzureTranscript$ex.interimTranscript,h=_i$AzureTranscript$ex.finalTranscript,u=_i$AzureTranscript$ex.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(d,h,u);}// prettier-ignore
|
281
|
+
},{key:"onRecognized",value:function onRecognized(l,c){var d=c.result;switch(d.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(d.text&&!this._stopping){var _i$AzureTranscript$ex2=i.AzureTranscript.extract(this._newTextPadding+d.text,this.finalTranscript,!0,this._translations),h=_i$AzureTranscript$ex2.interimTranscript,u=_i$AzureTranscript$ex2.finalTranscript,f=_i$AzureTranscript$ex2.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(h,u,f),u!==""&&(this._newTextPadding=" ");}break;}}},{key:"onCanceled",value:function onCanceled(l,c){c.reason===window.SpeechSDK.CancellationReason.Error&&this.error(c.errorDetails);}},{key:"onSessionStarted",value:function onSessionStarted(){r.PreventConnectionStop.clearPrevention(this),this.setStateOnStart();}},{key:"onSessionStopped",value:function onSessionStopped(){this._retrieveTokenInterval||clearInterval(this._retrieveTokenInterval),this._stopping=!1,this.setStateOnStop();}},{key:"retrieveTokenInterval",value:function retrieveTokenInterval(l){var _this95=this;this._retrieveTokenInterval=setInterval(function(){l==null||l().then(function(c){_this95._service&&(_this95._service.authorizationToken=(c==null?void 0:c.trim())||"");})["catch"](function(c){_this95.error(c);});},1e4);}},{key:"stop",value:function stop(l){var c;!l&&this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),this._stopping=!0,(c=this._service)===null||c===void 0||c.stopContinuousRecognitionAsync(),t.StopTimeout.stop(this),this.finalise(l);}},{key:"moduleNotFound",value:function moduleNotFound(){console.error("speech recognition module not found:"),console.error("please install the 'microsoft-cognitiveservices-speech-sdk' npm package or add a script tag: <script src=\"https://aka.ms/csspeech/jsbrowserpackageraw\"></script>"),this.setStateOnError("speech recognition module not found");}},{key:"error",value:function error(l){this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),console.error(l),this.setStateOnError(l),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.SpeechSDK;}}]);}(n.Speech);return ss.Azure=o,ss;}var hr;function kl(){if(hr)return Bs;hr=1,Object.defineProperty(Bs,"__esModule",{value:!0});var r=El(),e=kr(),t=Sl(),s=Ml();var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"toggle",value:function toggle(o,a){var l,c;var d=o.toLocaleLowerCase().trim();!((l=t.GlobalState.service)===null||l===void 0)&&l.recognizing?this.stop():d==="webspeech"?i.startWebSpeech(a):d==="azure"?i.startAzure(a):(console.error("service not found - must be either 'webspeech' or 'azure'"),(c=a==null?void 0:a.onError)===null||c===void 0||c.call(a,"service not found - must be either 'webspeech' or 'azure'"));}},{key:"startWebSpeech",value:function startWebSpeech(o){i.stop()||(t.GlobalState.service=new r.WebSpeech(),t.GlobalState.service.start(o));}},{key:"isWebSpeechSupported",value:function isWebSpeechSupported(){return!!r.WebSpeech.getAPI();}},{key:"startAzure",value:function startAzure(o){var a;i.stop()||!((a=t.GlobalState.service)===null||a===void 0)&&a.cannotBeStopped||(t.GlobalState.service=new s.Azure(),t.GlobalState.service.start(o));}},{key:"stop",value:function stop(){var o;return t.GlobalState.doubleClickDetector()?!0:(!((o=t.GlobalState.service)===null||o===void 0)&&o.recognizing&&t.GlobalState.service.stop(),!1);}},{key:"endCommandMode",value:function endCommandMode(){t.GlobalState.service&&e.CommandUtils.toggleCommandModeOff(t.GlobalState.service);}}]);}();return Bs["default"]=i,Bs;}var Il=kl();var Fs=/* @__PURE__ */ml(Il);var Ll=/*#__PURE__*/function(){function Ll(e,t){_classCallCheck(this,Ll);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(Ll,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this96=this;this._silenceTimeout=setTimeout(function(){var s;(s=e.submit)==null||s.call(e),Fs.stop(),_this96._stop||setTimeout(t,Rs.MICROPHONE_RESET_TIMEOUT_MS);},this._silenceMS);}},{key:"clearSilenceTimeout",value:function clearSilenceTimeout(){this._silenceTimeout&&clearTimeout(this._silenceTimeout);}},{key:"resetSilenceTimeout",value:function resetSilenceTimeout(e,t){this.clearSilenceTimeout(),this.setSilenceTimeout(e,t);}},{key:"onPause",value:function onPause(e,t,s){e?this.resetSilenceTimeout(t,s):this.clearSilenceTimeout();}}]);}();var vs=/*#__PURE__*/function(_Mi){function vs(e,t,s){var _this97;_classCallCheck(this,vs);var i=_typeof(e.speechToText)=="object"?e.speechToText:{};_this97=_callSuper(this,vs,[i==null?void 0:i.button]);var _this97$processConfig=_this97.processConfiguration(t,e.speechToText),n=_this97$processConfig.serviceName,o=_this97$processConfig.processedConfig;if(_this97._addErrorMessage=s,n==="webspeech"&&!Fs.isWebSpeechSupported())_this97.changeToUnsupported();else{var a=!e.textInput||!e.textInput.disabled;_this97.elementRef.onclick=_this97.buttonClick.bind(_this97,t,a,n,o);}setTimeout(function(){_this97._validationHandler=e._validationHandler;});return _this97;}// prettier-ignore
|
282
|
+
_inherits(vs,_Mi);return _createClass(vs,[{key:"processConfiguration",value:function processConfiguration(e,t){var _s$displayInterimResu,_s$textColor,_s$translations,_s$commands,_s$events;var c;var s=_typeof(t)=="object"?t:{},i=_typeof(s.webSpeech)=="object"?s.webSpeech:{},n=s.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_s$displayInterimResu=s.displayInterimResults)!==null&&_s$displayInterimResu!==void 0?_s$displayInterimResu:void 0,textColor:(_s$textColor=s.textColor)!==null&&_s$textColor!==void 0?_s$textColor:void 0,translations:(_s$translations=s.translations)!==null&&_s$translations!==void 0?_s$translations:void 0,commands:(_s$commands=s.commands)!==null&&_s$commands!==void 0?_s$commands:void 0,events:(_s$events=s.events)!==null&&_s$events!==void 0?_s$events:void 0},i),n),a=(c=s.commands)==null?void 0:c.submit;return a&&(o.onPreResult=function(d){return d.toLowerCase().includes(a)?(setTimeout(function(){var h;return(h=e.submit)==null?void 0:h.call(e);}),Fs.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),s.submitAfterSilence&&(this._silenceSubmit=new Ll(s.submitAfterSilence,s.stopAfterSubmit)),{serviceName:vs.getServiceName(s),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,s,i){var _this98=this;var n=i==null?void 0:i.events;e.removePlaceholderStyle(),Fs.toggle(s,_objectSpread({insertInCursorLocation:!1,element:t?e.inputElementRef:void 0,onError:function onError(){var o;_this98.onError(),(o=_this98._silenceSubmit)==null||o.clearSilenceTimeout();},onStart:function onStart(){var o;_this98.changeToActive(),(o=n==null?void 0:n.onStart)==null||o.call(n);},onStop:function onStop(){var o,a,l;(o=_this98._validationHandler)==null||o.call(_this98),(a=_this98._silenceSubmit)==null||a.clearSilenceTimeout(),_this98.changeToDefault(),(l=n==null?void 0:n.onStop)==null||l.call(n);},onPauseTrigger:function onPauseTrigger(o){var a,l;(a=_this98._silenceSubmit)==null||a.onPause(o,e,_this98.elementRef.onclick),(l=n==null?void 0:n.onPauseTrigger)==null||l.call(n,o);},onPreResult:function onPreResult(o,a){var l;(l=n==null?void 0:n.onPreResult)==null||l.call(n,o,a);},onResult:function onResult(o,a){var l,c,d;a&&((l=_this98._validationHandler)==null||l.call(_this98)),(c=_this98._silenceSubmit)==null||c.resetSilenceTimeout(e,_this98.elementRef.onclick),(d=n==null?void 0:n.onResult)==null||d.call(n,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this98.onCommandModeTrigger(o),(a=n==null?void 0:n.onCommandModeTrigger)==null||a.call(n,o);}},i));}},{key:"onCommandModeTrigger",value:function onCommandModeTrigger(e){e?this.changeToCommandMode():this.changeToActive();}},{key:"onError",value:function onError(){this._addErrorMessage("speechToText","speech input error");}}],[{key:"getServiceName",value:function getServiceName(e){return e.azure?"azure":"webspeech";}},{key:"toggleSpeechAfterSubmit",value:function toggleSpeechAfterSubmit(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;e.click(),t||setTimeout(function(){return e.click();},vs.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(Mi);vs.MICROPHONE_RESET_TIMEOUT_MS=300;var Rs=vs;var We=/*#__PURE__*/function(){// prettier-ignore
|
283
|
+
function We(e,t,s,i,n){var _this99=this;_classCallCheck(this,We);this._attachments=[],this._fileCountLimit=99,this._acceptedFormat="",this._hiddenAttachments=/* @__PURE__ */new Set(),s.maxNumberOfFiles&&(this._fileCountLimit=s.maxNumberOfFiles),this._toggleContainerDisplay=i,this._fileAttachmentsContainerRef=n,s.acceptedFormats&&(this._acceptedFormat=s.acceptedFormats),setTimeout(function(){_this99._validationHandler=e._validationHandler,_this99._onInput=t.onInput;});}return _createClass(We,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var s;return We.isFileTypeValid(e,this._acceptedFormat)?(this.addAttachmentBasedOnType(e,t,!0),(s=this._onInput)==null||s.call(this,!0),!0):!1;}},{key:"addAttachmentBasedOnType",value:function addAttachmentBasedOnType(e,t,s){var i=We.getTypeFromBlob(e);if(i==="image"){var n=We.createImageAttachment(t);this.addFileAttachment(e,"image",n,s);}else if(i==="audio"){var _n4=Ms.createAudioAttachment(t);this.addFileAttachment(e,"audio",_n4,s);}else{var _n5=We.createAnyFileAttachment(e.name);this.addFileAttachment(e,"any",_n5,s);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,s,i){var a;var n=We.createContainer(s);if(this._attachments.length>=this._fileCountLimit){var l=this._attachments[this._attachments.length-1].removeButton;l==null||l.click();var c=this._fileAttachmentsContainerRef.children;this._fileAttachmentsContainerRef.insertBefore(n,c[0]);}else this._fileAttachmentsContainerRef.appendChild(n);var o={file:e,attachmentContainerElement:n,fileType:t};return i&&(o.removeButton=this.createRemoveAttachmentButton(o),n.appendChild(o.removeButton)),this._toggleContainerDisplay(!0),this._attachments.push(o),this._fileAttachmentsContainerRef.scrollTop=this._fileAttachmentsContainerRef.scrollHeight,(a=this._validationHandler)==null||a.call(this),o;}},{key:"createRemoveAttachmentButton",value:function createRemoveAttachmentButton(e){var t=document.createElement("div");t.classList.add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var s=document.createElement("div");return s.classList.add("x-icon"),s.innerText="×",t.appendChild(s),t;}},{key:"removeAttachment",value:function removeAttachment(e,t){var n,o;(n=this._onInput)==null||n.call(this,!!(t!=null&&t.isTrusted));var s=this._attachments.findIndex(function(a){return a===e;}),i=this._attachments[s].attachmentContainerElement;this._attachments.splice(s,1),Ms.stopAttachmentPlayback(i),i.remove(),this._toggleContainerDisplay(!1),(o=this._validationHandler)==null||o.call(this);}},{key:"getFiles",value:function getFiles(){return Array.from(this._attachments).map(function(e){return{file:e.file,type:e.fileType};});}},{key:"hideAttachments",value:function hideAttachments(){var _this100=this;this._hiddenAttachments.clear(),this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t.click();}),_this100._hiddenAttachments.add(e);});}},{key:"removeAttachments",value:function removeAttachments(){this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t.click();});}),this._hiddenAttachments.clear();}},{key:"readdAttachments",value:function readdAttachments(){var _this101=this;var e;Array.from(this._hiddenAttachments).forEach(function(t){_this101._fileAttachmentsContainerRef.appendChild(t.attachmentContainerElement),_this101._attachments.push(t);}),(e=this._onInput)==null||e.call(this,!1),this._hiddenAttachments.clear();}}],[{key:"isFileTypeValid",value:function isFileTypeValid(e,t){if(t==="")return!0;var s=t.split(",");for(var i=0;i<s.length;i++){var n=s[i].trim();if(e.type===n)return!0;if(n.startsWith(".")){var o=n.slice(1);if(e.name.endsWith(o))return!0;}else{if(e.name.endsWith(n))return!0;if(n.endsWith("/*")&&e.type.startsWith(n.slice(0,-2)))return!0;}}return!1;}},{key:"getTypeFromBlob",value:function getTypeFromBlob(e){var t=e.type;return t.startsWith("image")?"image":t.startsWith("audio")?"audio":"any";}},{key:"createImageAttachment",value:function createImageAttachment(e){var t=new Image();return t.src=e,t.classList.add("image-attachment"),t;}},{key:"createAnyFileAttachment",value:function createAnyFileAttachment(e){var t=document.createElement("div");t.classList.add("border-bound-attachment"),Ye.IS_SAFARI&&t.classList.add("border-bound-attachment-safari");var s=document.createElement("div");s.classList.add("any-file-attachment-text");var i=document.createElement("div");return i.classList.add("file-attachment-text-container"),i.appendChild(s),s.textContent=e,t.appendChild(i),t;}},{key:"createContainer",value:function createContainer(e){var t=document.createElement("div");return t.classList.add("file-attachment"),t.appendChild(e),t;}}]);}();var Je=/*#__PURE__*/function(_We){// prettier-ignore
|
284
|
+
function Je(e,t,s,i,n){_classCallCheck(this,Je);return _callSuper(this,Je,[e,t,s,i,n]);}_inherits(Je,_We);return _createClass(Je,[{key:"createTimer",value:function createTimer(e,t){var _this102=this;var s=0;var i=t!==void 0&&t<Je.TIMER_LIMIT_S?t:Je.TIMER_LIMIT_S;return setInterval(function(){var a;s+=1,s===i&&((a=_this102.stopPlaceholderCallback)==null||a.call(_this102),_this102.clearTimer()),s===600&&e.classList.add("audio-placeholder-text-4-digits");var n=Math.floor(s/60),o=(s%60).toString().padStart(2,"0");e.textContent="".concat(n,":").concat(o);},1e3);}},{key:"createPlaceholderAudioAttachment",value:function createPlaceholderAudioAttachment(e){var t=Je.createAudioContainer(),s=document.createElement("div");s.classList.add("audio-placeholder-text-3-digits");var i=document.createElement("div");i.classList.add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),i.appendChild(s);var n=Qe.createSVGElement(Ji);return n.classList.add("attachment-icon","stop-icon","not-removable-attachment-icon"),s.textContent="0:00",this._activePlaceholderTimer=this.createTimer(s,e),t.appendChild(i),this.addPlaceholderAudioAttachmentEvents(t,n,i),t;}},{key:"addPlaceholderAudioAttachmentEvents",value:function addPlaceholderAudioAttachmentEvents(e,t,s){var _this103=this;var i=function i(){return e.replaceChildren(t);};e.addEventListener("mouseenter",i);var n=function n(){return e.replaceChildren(s);};e.addEventListener("mouseleave",n);var o=function o(){var a;return(a=_this103.stopPlaceholderCallback)==null?void 0:a.call(_this103);};e.addEventListener("click",o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var s=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),"audio",s,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
|
285
|
+
},{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var s=this._activePlaceholderAttachment;s&&(s.file=e,Je.addAudioElements(s.attachmentContainerElement.children[0],t),s.removeButton=this.createRemoveAttachmentButton(s),s.attachmentContainerElement.appendChild(s.removeButton),this._activePlaceholderAttachment=void 0,this.clearTimer());}},{key:"removePlaceholderAttachment",value:function removePlaceholderAttachment(){this._activePlaceholderAttachment&&(this.removeAttachment(this._activePlaceholderAttachment),this._activePlaceholderAttachment=void 0,this.clearTimer());}},{key:"clearTimer",value:function clearTimer(){this._activePlaceholderTimer!==void 0&&(clearInterval(this._activePlaceholderTimer),this._activePlaceholderTimer=void 0,this.stopPlaceholderCallback=void 0);}}],[{key:"createAudioContainer",value:function createAudioContainer(){var e=document.createElement("div");return e.classList.add("border-bound-attachment","audio-attachment-icon-container"),Ye.IS_SAFARI&&e.classList.add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var s=e.parentElement?ae.cloneElement(e):e,i=document.createElement("audio");i.src=t;var n=Qe.createSVGElement(Ar);n.classList.add("attachment-icon","play-icon");var o=Qe.createSVGElement(Ji);o.classList.add("attachment-icon","stop-icon"),s.replaceChildren(n),i.onplay=function(){s.replaceChildren(o);},i.onpause=function(){s.replaceChildren(n),i.currentTime=0;},i.onended=function(){s.replaceChildren(n);},s.onclick=function(){i.paused?i.play():i.pause();};}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=Je.createAudioContainer();return Je.addAudioElements(t,e),t;}},{key:"stopAttachmentPlayback",value:function stopAttachmentPlayback(e){var t,s,i;(i=(s=(t=e.children[0])==null?void 0:t.children)==null?void 0:s[0])!=null&&i.classList.contains("stop-icon")&&e.children[0].click();}}]);}(We);Je.TIMER_LIMIT_S=5999;var Ms=Je;var Nl=/*#__PURE__*/function(){function Nl(){_classCallCheck(this,Nl);}return _createClass(Nl,null,[{key:"create",value:// prettier-ignore
|
286
|
+
function create(e,t,s,i,n,o){return o==="audio"?new Ms(e,t,s,i,n):new We(e,t,s,i,n);}}]);}();var Ns=/*#__PURE__*/function(){function Ns(e,t,s){_classCallCheck(this,Ns);this._fileAttachmentsTypes=[],this.elementRef=this.createAttachmentContainer();var i=_typeof(s)=="object"&&!!s.displayFileAttachmentContainer;this.toggleContainerDisplay(i),e.appendChild(this.elementRef),t&&Object.assign(this.elementRef.style,t);}// prettier-ignore
|
287
|
+
return _createClass(Ns,[{key:"addType",value:function addType(e,t,s,i){var n=Nl.create(e,t,s,this.toggleContainerDisplay.bind(this),this.elementRef,i);return this._fileAttachmentsTypes.push(n),n;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=document.createElement("div");return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef.style.display="block":this.elementRef.children.length===0&&(this.elementRef.style.display="none");}},{key:"getAllFileData",value:function getAllFileData(){var e=this._fileAttachmentsTypes.map(function(t){return t.getFiles();}).flat();return e.length>0?e:void 0;}},{key:"completePlaceholders",value:function(){var _completePlaceholders=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee178(){return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:_context178.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref164=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee177(e){var t;return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:return _context177.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee177);}));return function(_x321){return _ref164.apply(this,arguments);};}()));case 1:return _context178.a(2);}},_callee178,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){Ns.addFilesToType(e,this._fileAttachmentsTypes);}},{key:"hideFiles",value:function hideFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.hideAttachments();}),this.elementRef.replaceChildren(),this.toggleContainerDisplay(!1);}},{key:"removeHiddenFiles",value:function removeHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.removeAttachments();});}},{key:"readdHiddenFiles",value:function readdHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.readdAttachments();}),this.toggleContainerDisplay(!0);}},{key:"getNumberOfTypes",value:function getNumberOfTypes(){return this._fileAttachmentsTypes.length;}}],[{key:"addFilesToType",value:function addFilesToType(e,t){e.forEach(function(s){var i=new FileReader();i.readAsDataURL(s),i.onload=function(n){for(var o=0;o<t.length&&!t[o].attemptAddFile(s,n.target.result);o+=1);};});}}]);}();var ke=/*#__PURE__*/function(){function ke(e,t,s){_classCallCheck(this,ke);this._isOpen=!1,this._contentRef=ke.createModalContent(t,s==null?void 0:s.backgroundColor),this._buttonPanel=ke.createButtonPanel(s==null?void 0:s.backgroundColor),this._elementRef=ke.createContainer(this._contentRef,s),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=ke.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(ke,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this104=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){j.addAttributes(t),_this104._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this105=this;this._elementRef.classList.remove("show-modal"),this._elementRef.classList.add("hide-modal"),this._backgroundPanelRef.classList.remove("show-modal-background"),this._backgroundPanelRef.classList.add("hide-modal-background"),this._isOpen=!1,setTimeout(function(){_this105._elementRef.style.display="none",_this105._backgroundPanelRef.style.display="none";},ke.MODAL_CLOSE_TIMEOUT_MS);}},{key:"displayModalElements",value:function displayModalElements(){this._elementRef.style.display="flex",this._elementRef.classList.remove("hide-modal"),this._elementRef.classList.add("show-modal"),this._backgroundPanelRef.style.display="block",this._backgroundPanelRef.classList.remove("hide-modal-background"),this._backgroundPanelRef.classList.add("show-modal-background"),this._isOpen=!0;}},{key:"openTextModal",value:function openTextModal(e){this._contentRef.innerHTML=e,this.displayModalElements();}},{key:"addCloseButton",value:function addCloseButton(e,t,s){var _this106=this;var i=t?ke.createSVGButton(e):ke.createTextButton(e);return this.addButtons(i),i.onclick=function(){_this106.close(),setTimeout(function(){s==null||s();},140);},i;}},{key:"addWindowEvents",value:function addWindowEvents(e){this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent);}},{key:"windowKeyDown",value:function windowKeyDown(e,t){var s,i;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===X.ESCAPE?(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)):t.key===X.ENTER&&(this.close(),(i=this.extensionCloseCallback)==null||i.call(this)));}}],[{key:"createContainer",value:function createContainer(e,t){var s=document.createElement("div");return s.classList.add("modal"),s.appendChild(e),t&&delete t.backgroundColor,Object.assign(s.style,t),s;}},{key:"createModalContent",value:function createModalContent(e,t){var _s$classList;var s=document.createElement("div");return(_s$classList=s.classList).add.apply(_s$classList,_toConsumableArray(e)),t&&(s.style.backgroundColor=t),document.createElement("div").appendChild(s),s;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=document.createElement("div");return t.classList.add("modal-button-panel"),e&&(t.style.backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=document.createElement("div");return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=document.createElement("div");return t.classList.add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=document.createElement("div");t.classList.add("modal-button","modal-svg-button");var s=Qe.createSVGElement(e);return s.classList.add("modal-svg-button-icon"),t.appendChild(s),t;}},{key:"createTextModalFunc",value:function createTextModalFunc(e,t,s){var i;if(_typeof(t)=="object"&&(i=t.files)!=null&&i.infoModal){var n=new ke(e,["modal-content"],t.files.infoModal.containerStyle);return n.addCloseButton("OK",!1,s),n.openTextModal.bind(n,t.infoModalTextMarkUp||"");}}}]);}();ke.MODAL_CLOSE_TIMEOUT_MS=190;var Et=ke;var _i=/*#__PURE__*/function(_Mt5){// prettier-ignore
|
288
|
+
function _i(e,t,s,i,n,o){var _this107;_classCallCheck(this,_i);var h,u,f,m,p,y,_,I,D,B;var a=(h=s==null?void 0:s.button)==null?void 0:h.position,l=((m=(f=(u=s==null?void 0:s.button)==null?void 0:u.styles)==null?void 0:f.text)==null?void 0:m.content)||o,c=Le.tryCreateConfig("Upload File",(p=s==null?void 0:s.button)==null?void 0:p.tooltip);_this107=_callSuper(this,_i,[_i.createButtonElement(),n,a,c,s.button,l]);var d=_this107.createInnerElementsForStates(i,_this107.customStyles);_this107._inputElement=_i.createInputElement((y=s==null?void 0:s.files)==null?void 0:y.acceptedFormats),_this107.addClickEvent(e,s),_this107.changeElementsByState(d.styles),_this107.reapplyStateStyle("styles"),_this107._fileAttachmentsType=t,_this107._openModalOnce=((I=(_=s.files)==null?void 0:_.infoModal)==null?void 0:I.openModalOnce)===!1||(B=(D=s.files)==null?void 0:D.infoModal)==null?void 0:B.openModalOnce;return _this107;}_inherits(_i,_Mt5);return _createClass(_i,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e,t){return{styles:this.createInnerElements(e,"styles",t)};}},{key:"triggerImportPrompt",value:function triggerImportPrompt(e){e.onchange=this["import"].bind(this,e),e.click();}},{key:"import",value:function _import(e){Ns.addFilesToType(Array.from(e.files||[]),[this._fileAttachmentsType]),e.value="";}},{key:"addClickEvent",value:function addClickEvent(e,t){var s=this.triggerImportPrompt.bind(this,this._inputElement),i=Et.createTextModalFunc(e,t,s);this.elementRef.onclick=this.click.bind(this,i);}},{key:"click",value:function click(e){e&&(this._openModalOnce===void 0||this._openModalOnce===!0)?(e(),this._openModalOnce===!0&&(this._openModalOnce=!1)):this.triggerImportPrompt(this._inputElement);}}],[{key:"createInputElement",value:function createInputElement(e){var t=document.createElement("input");return t.type="file",t.accept=e||"",t.hidden=!0,t.multiple=!0,t;}},{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}}]);}(Mt);var $e=/*#__PURE__*/function(){function $e(){_classCallCheck(this,$e);}return _createClass($e,null,[{key:"create",value:function create(e,t,s){var i=$e.createElement(s);$e.addEvents(i,e,t),e.appendChild(i);}},{key:"createElement",value:function createElement(e){var t=document.createElement("div");return t.id="drag-and-drop",_typeof(e)===S&&Object.assign(t.style,e),t;}},{key:"addEvents",value:function addEvents(e,t,s){t.ondragenter=function(i){i.preventDefault(),$e.display(e);},e.ondragleave=function(i){i.preventDefault(),$e.hide(e);},e.ondragover=function(i){i.preventDefault();},e.ondrop=function(i){i.preventDefault(),$e.uploadFile(s,i),$e.hide(e);};}},{key:"uploadFile",value:function uploadFile(e,t){var i;var s=(i=t.dataTransfer)==null?void 0:i.files;s&&e.addFilesToAnyType(Array.from(s));}},{key:"display",value:function display(e){e.style.display="block";}},{key:"hide",value:function hide(e){e.style.display="none";}},{key:"isEnabled",value:function isEnabled(e,t){return t!==void 0&&t===!1?!1:!!t||e.getNumberOfTypes()>0;}}]);}();var ut=/*#__PURE__*/function(){function ut(){_classCallCheck(this,ut);}return _createClass(ut,null,[{key:"validate",value:// prettier-ignore
|
290
289
|
function validate(e,t,s,i,n){var o=e(s,i,n);return o?t.changeToSubmitIcon():t.changeToDisabledIcon(),o;}// prettier-ignore
|
291
|
-
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e,t,s,i){var n,o,a;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:n=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context179.n=1;return s.completePlaceholders();case 1:o=s.getAllFileData(),a=o==null?void 0:o.map(function(l){return l.file;});return _context179.a(2,
|
292
|
-
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(e,t,s){var n,i;return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:i=(n=t.files)==null?void 0:n.map(function(o){return o.file;});return _context180.a(2,
|
293
|
-
},{key:"attach",value:function attach(e,t,s,i,n){var o=e.validateInput||
|
294
|
-
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){
|
295
|
-
function
|
296
|
-
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,s,i,n,o,a,l,c,d;if(!((s=(t=this.customStyles)==null?void 0:t.submit)!=null&&s.svg||(o=(n=(i=this.customStyles)==null?void 0:i.loading)==null?void 0:n.svg)!=null&&o.content||(c=(l=(a=this.customStyles)==null?void 0:a.loading)==null?void 0:l.text)!=null&&c.content)&&(e.displayLoadingBubble===void 0||e.displayLoadingBubble===!0)){var
|
297
|
-
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee184(e){var t,n,o,a,l,s,i,_args184=arguments,_t44,_t45,_t46;return _regenerator().w(function(_context184){while(1)switch(_context184.n){case 0:t=_args184.length>1&&_args184[1]!==undefined?_args184[1]:!1;_context184.n=1;return(n=this._validationHandler)==null?void 0:n.call(this,t?e:void 0);case 1:_t44=_context184.v;_t45=!1;if(!(_t44===_t45)){_context184.n=2;break;}return _context184.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();_t46=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t46){_context184.n=3;break;}_context184.n=3;return
|
298
|
-
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this115=this;this.elementRef.classList.contains(
|
299
|
-
},{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef.classList.contains(
|
300
|
-
function
|
301
|
-
},{key:"addButtonEvents",value:function addButtonEvents(e,t,s,i){var _this117=this;e.onclick=function(){_this117.capture();},t.addEventListener("click",this.stop.bind(this)),s.onclick=function(){var n=_this117.getFile();n&&
|
302
|
-
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,s,i){var n=new
|
303
|
-
function addClickEvent(e,t,s,i){var n=
|
304
|
-
function createFileUploadComponents(e,t,s,i){var o,a,l,c;var n=new
|
305
|
-
}],[{key:"createPanelElement",value:function createPanelElement(e){var t=document.createElement("div");return t.id="input",Object.assign(t.style,e),t;}},{key:"createUploadButtons",value:function createUploadButtons(e,t,s,i,n,o){Object.keys(s).forEach(function(a){var l=a,c=s[l];if(c.files){var d=i.addType(e,t,c.files,l),
|
306
|
-
},{key:"addElements",value:function addElements(e,t,s,i,n,o){X.addElements(e,t.elementRef);var a=At.create(),l=Q.addButtons(a,s,i,o);Vi.set(t.inputElementRef,a,n.elementRef,l),At.add(e,a);}},{key:"assignOnInput",value:function assignOnInput(e,t,s,i){t.onInput=function(n){setTimeout(function(){var o=s.getAllFileData(),l={text:i.inputElementRef.innerText.trim()};o&&(l.files=o.map(function(c){return c.file;})),hs.onInput(e,l,n);});};}}]);}();var nn=/*#__PURE__*/function(){function nn(){_classCallCheck(this,nn);}return _createClass(nn,null,[{key:"createElements",value:function createElements(e,t,s){var i=document.createElement("div");i.id="chat-view";var n=new ue(e,t,s);t.websocket&&$.createConnection(t,n);var o=new vt(e,n,t,i);return X.addElements(i,n.elementRef,o.elementRef),i;}},{key:"render",value:function render(e,t,s,i){var n=nn.createElements(e,s,i);t.replaceChildren(n),s.isCustomView()&&s.setUpView(n,t);}}]);}();var _l="#validate-property-key-view{height:100%;position:relative;display:flex;justify-content:center;align-items:center;padding:8px}#loading-validate-key-property{display:inline-block;width:50px;height:50px}#loading-validate-key-property:after{content:\" \";display:block;width:38px;height:38px;margin:1px;border-radius:50%;border:5px solid #5fb2ff;border-color:#5fb2ff transparent #5fb2ff transparent;animation:loading-spinner 1.4s linear infinite}#deep-chat-openai-realtime-container{height:100%;width:100%}#deep-chat-openai-realtime-avatar-container{height:60%;width:100%;display:flex;justify-content:center;align-items:center}#deep-chat-openai-realtime-avatar{border-radius:50%;height:110px;border:1px solid rgb(215,215,215);padding:8px;-webkit-user-select:none;user-select:none;margin-top:20px}#deep-chat-openai-realtime-buttons-container{height:40%;display:flex;position:relative}.deep-chat-openai-realtime-button-container{height:100%;width:50%;display:flex;justify-content:center;align-items:center}.deep-chat-openai-realtime-button{width:70px;height:70px;border-radius:50%;display:flex;justify-content:center;align-items:center;cursor:pointer}.deep-chat-openai-realtime-button-default{background-color:#e3e3e3}.deep-chat-openai-realtime-button-default:hover{background-color:#d4d4d4}.deep-chat-openai-realtime-button-default:active{background-color:#c5c5c5}.deep-chat-openai-realtime-button-loading{opacity:.7;pointer-events:none}.deep-chat-openai-realtime-microphone-active{background-color:#ffe7e7}.deep-chat-openai-realtime-microphone-active:hover{background-color:#ffdede}.deep-chat-openai-realtime-microphone-active:active{background-color:#ffd2d2}.deep-chat-openai-realtime-microphone>*{height:30px;width:30px}.deep-chat-openai-realtime-microphone-active>*{filter:brightness(0) saturate(100%) invert(35%) sepia(60%) saturate(1360%) hue-rotate(325deg) brightness(95%) contrast(92%)}.deep-chat-openai-realtime-toggle>*{height:32px;width:32px;padding-left:3px;filter:brightness(0) saturate(100%) invert(22%) sepia(0%) saturate(4537%) hue-rotate(208deg) brightness(105%) contrast(91%)}.deep-chat-openai-realtime-button-unavailable{opacity:.45;pointer-events:none}#deep-chat-openai-realtime-error{color:red;position:absolute;top:calc(50% + 40px);left:50%;transform:translate(-50%,-50%);font-size:17px}#deep-chat-openai-realtime-loading{position:absolute;font-size:15px;top:50%;left:50%;transform:translate(-50%,-50%)}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;top:44%;left:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-right:2.7em;width:calc(100% - 80px)}#insert-key-input{padding:.3em 1.7em .3em .3em;border-width:1px;border-style:solid;border-radius:3px;width:100%;font-size:inherit}.insert-key-input-valid{border-color:gray}.insert-key-input-invalid{border-color:red}#visibility-icon-container{position:relative;float:right;cursor:pointer;-webkit-user-select:none;user-select:none}.visibility-icon{filter:brightness(0) saturate(100%) invert(63%) sepia(1%) saturate(9%) hue-rotate(43deg) brightness(98%) contrast(92%);position:absolute;right:-1.7em;top:-1.43em}#visible-icon{top:-1.4em}.visibility-icon:hover{filter:unset}.visibility-icon>*{pointer-events:none}#start-button{border:1px solid grey;color:#454545;border-radius:4px;width:3em;display:flex;justify-content:center;align-items:center;cursor:pointer;padding:.28em .3em;-webkit-user-select:none;user-select:none;background-color:#fff}#start-button:hover{background-color:#f2f2f2}#start-button:active{background-color:#d2d2d2}#insert-key-help-text-container{width:100%;position:absolute;margin-top:32px;margin-bottom:20px}#insert-key-help-text-contents{width:100%;position:absolute}#insert-key-input-invalid-text{display:block;margin-top:1em;margin-bottom:.5em;color:red}.insert-key-input-help-text{display:block;margin-top:16px}#loading-key{display:inline-block;width:16px;height:16px}#loading-key:after{content:\" \";display:block;width:11px;height:11px;margin:1px;border-radius:50%;border:2px solid #0084ff;border-color:#0084ff transparent #0084ff transparent;animation:loading-spinner 1.2s linear infinite}#error-view{color:red;font-size:1.2em;line-height:1.3em;margin-top:-5px;text-align:center;height:100%;display:flex;justify-content:center;align-items:center;padding-left:8px;padding-right:8px}@keyframes loading-spinner{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.intro-panel{position:absolute;display:flex;justify-content:center;right:0;bottom:0;left:0;margin:auto;height:fit-content;top:-2.5em}#internal-intro-panel{width:250px;height:min-content;display:block;border-radius:5px;overflow:auto;border:1px solid rgb(203,203,203);padding:10px;max-height:calc(100% - 6.8em)}#internal-intro-panel>p{margin-block-start:.8em;margin-block-end:.8em}pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!\n Theme: a11y-dark\n Author: @ericwbailey\n Maintainer: @ericwbailey\n\n Based on the Tomorrow Night Eighties theme: https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css\n*/.hljs{background:#2b2b2b;color:#f8f8f2}.hljs-comment,.hljs-quote{color:#d4d0ab}.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#ffa07a}.hljs-built_in,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#f5ab35}.hljs-attribute{color:gold}.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#abe338}.hljs-section,.hljs-title{color:#00e0e0}.hljs-keyword,.hljs-selector-tag{color:#dcc6e0}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}@media screen and (-ms-high-contrast: active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}}#messages{overflow:auto}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-left:auto;margin-right:auto;width:calc(97.5% - 24px);max-width:100%}.message-bubble{margin-top:10px;word-wrap:break-word;width:fit-content;max-width:60%;border-radius:10px;padding:.42em .55em;height:fit-content;line-height:1.26em}.user-message-text{color:#fff;background-color:#0084ff;margin-right:0;margin-left:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-left:0;margin-right:auto}.deep-chat-last-group-messages-active{height:100%}.loading-history-message-full-view{position:absolute;height:70%;width:100%;display:flex;align-items:center}.loading-history-message-small{height:20px;margin-bottom:30px}.loading-history-message-small>div>div{scale:.6}.loading-history-message{margin-top:0;width:100%;max-width:100%;display:flex;justify-content:center;background-color:unset}.loading-history{width:70px}.loading-history div{position:absolute;width:var(--loading-history-width);height:var(--loading-history-height);margin:var(--loading-history-margin);border:var(--loading-history-border);border-radius:50%;animation:loading-spinner 1.2s cubic-bezier(.5,0,.5,1) infinite;border-color:var(--loading-history-color) transparent transparent transparent}.loading-history div:nth-child(1){animation-delay:-.45s}.loading-history div:nth-child(2){animation-delay:-.3s}.loading-history div:nth-child(3){animation-delay:-.15s}.html-message{max-width:unset}.error-message-text{margin:14px auto 10px;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%}.deep-chat-loading-message-dots-container{width:1em;padding:.6em .75em .6em 1.3em}.loading-message-dots{position:relative;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite linear alternate;animation-delay:.5s}.loading-message-dots:before,.loading-message-dots:after{content:\"\";display:inline-block;position:absolute;top:0}.loading-message-dots:before{left:-.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:0s}.loading-message-dots:after{left:.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:1s}@keyframes loading-message-dots{0%{background-color:var(--loading-message-color)}50%,to{background-color:var(--loading-message-color-fade)}}.message-bubble>p:first-child,.message-bubble>.partial-render-message>p:first-child,.html-wrapper>p:first-child{margin-top:0}.message-bubble>p:last-child,.message-bubble>.partial-render-message:last-child>p,.html-wrapper>p:last-child{margin-bottom:0}pre{overflow:auto;display:block;word-break:break-all;word-wrap:break-word;border-radius:7px;background:#2b2b2b;color:#f8f8f2;margin-top:.8em;margin-bottom:.8em;padding:.6em;font-size:.9em;line-height:1.5em}.image-message{padding:0;display:flex;background-color:#ddd}.image-message>*,.image-message>*>*{width:100%;border-radius:8px;display:flex}.audio-message{width:60%;max-width:300px;height:2.2em;max-height:54px;padding:0;background-color:unset}.audio-player{width:100%;height:100%}.audio-player-safari{height:fit-content;width:40px}.audio-player-safari-left{float:left}.audio-player-safari-right{float:right}.any-file-message{padding:1px}.any-file-message-contents{display:flex}.any-file-message-icon-container{width:1.3em;min-width:1.3em;position:relative;border-radius:4px;margin-left:6px;margin-right:2px}.any-file-message-icon{background-color:#fff;border-radius:4px;position:absolute;width:1em;height:1.25em;padding:1px;margin-top:auto;margin-bottom:auto;top:0;bottom:0}.any-file-message-text{padding-top:5px;overflow-wrap:anywhere;padding-bottom:5px;padding-right:7px}.message-bubble>a{color:inherit}.left-item-position{margin-right:10px}.right-item-position{margin-left:10px}.role-hidden{display:none}.avatar{padding-top:5px;width:1.5em;height:1.5em;border-radius:1px}.avatar-container{margin-top:9px}.name{margin-top:16px;font-size:15px}#drag-and-drop{position:absolute;display:none;z-index:10;height:calc(100% - 10px);width:calc(100% - 10px);background-color:#70c6ff4d;border:5px dashed #6dafff}#file-attachment-container{position:absolute;height:3.6em;width:calc(80% - 4px);top:-2.5em;border-radius:5px;overflow:auto;text-align:left;background-color:#d7d7d73b;padding-left:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-right:.6em;margin-bottom:.44em;margin-top:4px;position:relative;background-color:#fff;border-radius:5px}.image-attachment{width:100%;height:100%;object-fit:cover;border-radius:5px}.border-bound-attachment{width:calc(100% - 2px);height:calc(100% - 2px);border:1px solid #c3c3c3;border-radius:5px;overflow:hidden}.border-bound-attachment-safari{width:calc(100% - 1px);height:calc(100% - 1px)}.audio-attachment-icon-container{cursor:pointer}.audio-attachment-icon-container:hover{background-color:#f8f8f8}.attachment-icon{left:0;right:0;bottom:0;top:2px;margin:auto;position:absolute;width:25px;-webkit-user-select:none;user-select:none}.not-removable-attachment-icon{top:0;right:0;bottom:0;left:0}.play-icon{filter:brightness(0) saturate(100%) invert(17%) sepia(0%) saturate(1392%) hue-rotate(67deg) brightness(98%) contrast(97%)}.stop-icon{filter:brightness(0) saturate(100%) invert(29%) sepia(90%) saturate(1228%) hue-rotate(198deg) brightness(93%) contrast(98%)}.audio-placeholder-text-3-digits{padding-left:.26rem}.audio-placeholder-text-4-digits{padding-left:.1rem}.any-file-attachment{padding:2px 0}.file-attachment-text-container{position:absolute;width:inherit;display:flex;align-items:center;height:100%;top:-1px}.audio-placeholder-text-3-digits-container{padding-top:1px;cursor:default}.any-file-attachment-text{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;padding-left:.13em;margin-left:auto;margin-right:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;right:-5px;position:absolute;display:flex;justify-content:center;cursor:pointer;-webkit-user-select:none;user-select:none}.remove-file-attachment-button:hover{background-color:#e4e4e4}.remove-file-attachment-button:active{background-color:#d7d7d7}.x-icon{color:#4e4e4e;top:-.075em;position:relative;font-size:1.05em}.modal{display:none;flex-direction:column;align-items:center;justify-content:center;position:absolute;width:80%;max-width:420px;max-height:80%;margin:auto;top:0;right:0;bottom:0;left:0;z-index:3}.modal-content{border-top:1px solid rgb(217,217,217);border-left:1px solid rgb(217,217,217);border-right:1px solid rgb(217,217,217);border-top-left-radius:inherit;border-top-right-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-left:1em;margin-right:1em}.modal-content>ul{margin-right:1em}.modal-button-panel{height:3.3em;border:1px solid;border-color:rgb(223,223,223) rgb(217,217,217) rgb(217,217,217);border-bottom-left-radius:inherit;border-bottom-right-radius:inherit;background-color:#fff;text-align:center;justify-content:center;display:flex;width:100%}.modal-button{min-width:2.5em;text-align:center;color:#fff;border-radius:5px;padding:.4em .4em .3em;height:1.25em;background-color:#3279b2;top:0;bottom:0;cursor:pointer;-webkit-user-select:none;user-select:none;margin:auto .31em}.modal-button:hover{background-color:#276da7}.modal-button:active{background-color:#1b5687}.modal-svg-button{padding:0 0 2px;width:2em;height:1.8em}.modal-svg-button-icon{width:100%;height:100%;filter:brightness(0) saturate(100%) invert(100%) sepia(15%) saturate(4%) hue-rotate(346deg) brightness(101%) contrast(102%)}#modal-background-panel{position:absolute;width:100%;height:100%;background-color:#00000042;z-index:2;display:none}.show-modal-background{animation:fadeInBackground .3s ease-in-out}@keyframes fadeInBackground{0%{opacity:0}to{opacity:1}}.show-modal{animation:fadeInModal .3s ease-in-out}@keyframes fadeInModal{0%{opacity:0;scale:.95}to{opacity:1;scale:1}}.hide-modal-background{animation:fadeOutBackground .2s ease-in-out}@keyframes fadeOutBackground{0%{opacity:1}to{opacity:0}}.hide-modal{animation:fadeOutModal .2s ease-in-out}@keyframes fadeOutModal{0%{opacity:1;scale:1}to{opacity:0;scale:.95}}.modal-camera-content{overflow:hidden;text-align:center;border:unset;height:100%;background-color:#2a2a2a;display:flex;justify-content:center}.camera-modal-canvas{max-width:100%;max-height:100%;margin-top:auto;margin-bottom:auto}.modal-svg-submit-button{background-color:green}.modal-svg-submit-button:hover{background-color:#007500}.modal-svg-submit-button:active{background-color:#006500}.modal-svg-submit-disabled{pointer-events:none;background-color:#747474}.modal-svg-close-button{height:1.56em;padding-top:.37em;padding-bottom:0;background-color:#c13e3e}.modal-svg-close-button:hover{background-color:#b43434}.modal-svg-close-button:active{background-color:#972929}.modal-svg-close-icon{width:80%;height:80%}.modal-svg-camera-button{height:1.6em;padding-top:.38em;padding-bottom:0}.modal-svg-camera-icon{height:76%}.modal-svg-refresh-icon{height:105%}.modal-svg-refresh-button{height:1.66em;padding-top:.11em;padding-bottom:.21em}.input-button-container{position:relative;z-index:1}.inside-right{position:absolute;right:calc(10% + .35em);bottom:.85em}.inside-left{position:absolute;left:calc(10% + .35em);bottom:.85em}.outside-left{position:absolute;right:calc(11px - .55em);bottom:.88em}.outside-right{position:absolute;left:calc(11px - .55em);bottom:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;left:.11em;bottom:.08em;filter:brightness(0) saturate(100%) invert(43%) sepia(0%) saturate(740%) hue-rotate(77deg) brightness(99%) contrast(92%)}#upload-gifs-icon{position:absolute;pointer-events:none;width:1.5em;height:1.48em;left:.07em;bottom:.08em;filter:brightness(0) saturate(100%) invert(49%) sepia(0%) saturate(2586%) hue-rotate(12deg) brightness(93%) contrast(90%)}#upload-audio-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.17em;bottom:.2em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%);transform:scaleX(.95)}#camera-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.23em;bottom:.2em;filter:brightness(0) saturate(100%) invert(52%) sepia(0%) saturate(161%) hue-rotate(164deg) brightness(91%) contrast(92%);transform:scaleX(.95)}#upload-mixed-files-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.25em;bottom:.2em;filter:brightness(0) saturate(100%) invert(53%) sepia(0%) saturate(36%) hue-rotate(74deg) brightness(98%) contrast(93%);transform:scaleX(.95)}#interim-text{color:gray}#microphone-button{padding-top:.5px}.outer-button-container>#microphone-button{padding-bottom:1px}#microphone-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.25em;bottom:.25em}.default-microphone-icon{filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%)}.active-microphone-icon{filter:brightness(0) saturate(100%) invert(10%) sepia(97%) saturate(7495%) hue-rotate(0deg) brightness(101%) contrast(107%);border-radius:10px}.command-microphone-icon{filter:brightness(0) saturate(100%) invert(42%) sepia(96%) saturate(1067%) hue-rotate(77deg) brightness(99%) contrast(102%)}.unsupported-microphone{display:none}#submit-icon{height:100%;filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%);width:1.21em}#stop-icon{background-color:#acacac;position:absolute;width:.95em;height:.95em;left:.35em;bottom:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-right:.3em;margin-left:.3em}.loading-submit-button{position:relative;left:calc(-9990px + .275em);width:.22em;height:.22em;border-radius:5px;background-color:#848484;color:#848484;box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484;animation:loading-submit-button 1.5s infinite linear;bottom:-.75em}@keyframes loading-submit-button{0%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}16.667%{box-shadow:9990px -6px #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}33.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}50%{box-shadow:9990px 0 #848484,calc(9990px + .44em) -6px 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}66.667%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}83.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) -6px 0 0 #848484}to{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}}.tooltip{position:absolute;visibility:hidden;z-index:1;pointer-events:none;padding:5px 7px;background-color:#333;border-radius:5px;width:max-content}.tooltip-text{color:#fff;font-size:13px}.input-button{border-radius:4px;cursor:pointer;margin-bottom:.2em;-webkit-user-select:none;user-select:none}.input-button-svg{width:1.65em;height:1.65em}.input-button-svg-text{padding:1px;height:1.65em;display:flex}.input-button-svg-text>svg{padding:.22rem}.input-button-svg-text>div{margin-left:2px}.input-button:hover,.input-button:focus-visible{background-color:#9c9c9c2e}.input-button:active{background-color:#9c9c9c5e}.input-button:active:not(:hover){background-color:transparent}.loading-button{cursor:auto}.loading-button:hover{background-color:unset}.text-button{filter:unset!important;display:flex;justify-content:center;align-items:center;margin-left:4px;margin-right:4px;height:1.6em;width:max-content}#custom-icon{height:100%;width:1.2em}.custom-button-container-default{color:#505050}.custom-button-container-default>.dropup-menu-item-icon{color:unset}.custom-button-container-default>svg{filter:brightness(0) saturate(100%) invert(39%) sepia(1%) saturate(0%) hue-rotate(83deg) brightness(93%) contrast(90%)}.custom-button-container-default>.dropup-menu-item-icon>svg{position:absolute;left:.2em}.custom-button-container-active{background-color:#edf7ff;color:#0285ff}.custom-button-container-active:hover,.custom-button-container-active:focus-visible{background-color:#def0ff}.custom-button-container-active:active{background-color:#d2eaff}.custom-button-container-active>svg{filter:brightness(0) saturate(100%) invert(32%) sepia(34%) saturate(4196%) hue-rotate(196deg) brightness(107%) contrast(104%)}.custom-button-container-disabled{color:#aeaeae;cursor:auto}.custom-button-container-disabled>div{pointer-events:none}.custom-button-container-disabled:hover,.custom-button-container-disabled:focus-visible{background-color:transparent}.custom-button-container-disabled:active{background-color:transparent}.custom-button-container-disabled>svg{filter:brightness(0) saturate(100%) invert(67%) sepia(0%) saturate(818%) hue-rotate(28deg) brightness(102%) contrast(100%)}#text-input-container{background-color:#fff;width:80%;display:flex;border:1px solid #0000001a;border-radius:5px;margin-top:.8em;margin-bottom:.8em;box-shadow:#959da533 0 1px 12px;overflow-y:auto;max-height:200px;position:relative}.text-input-container-left-adjustment{margin-left:1.5em}.text-input-container-right-adjustment{margin-right:1.5em}.text-input-container-left-small-adjustment{margin-left:1.1em}.text-input-container-left-small-adjustment>.outside-left{right:calc(14px - .55em)}.text-input-container-right-small-adjustment{margin-right:1.1em}.text-input-container-right-small-adjustment>.outside-right{left:calc(14px - .55em)}#text-input{text-align:left;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-left-adjustment{padding-left:2.2em}.text-input-inner-right-adjustment{padding-right:2em}.text-input-disabled{pointer-events:none;-webkit-user-select:none;user-select:none}[contenteditable]:empty:before{content:attr(deep-chat-placeholder-text);pointer-events:none}[contenteditable][textcolor]:empty:before{color:gray}.outside-right>#dropup-menu,.inside-right>#dropup-menu{right:0}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;left:.265em;bottom:.43em;filter:brightness(0) saturate(100%) invert(54%) sepia(0%) saturate(724%) hue-rotate(6deg) brightness(92%) contrast(90%)}.dropup-button>*{pointer-events:none}#dropup-menu{background-color:#fff;position:absolute;transform:translateY(-100%);border-radius:5px;z-index:1;top:-.49em;box-shadow:#0003 -1px 2px 10px,#0000001a 0 2px 4px;cursor:pointer;-webkit-user-select:none;user-select:none}.dropup-menu-item{height:1.4em;padding:.28em .84em .28em .35em;display:flex;position:relative}.dropup-menu-item:hover,.dropup-menu-item:focus-visible{background-color:#f3f3f3}.dropup-menu-item:active{background-color:#ebebeb}.dropup-menu-item:active:not(:hover){background-color:transparent}.dropup-menu-item:first-child{padding-top:.49em;border-top-left-radius:inherit;border-top-right-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-bottom-left-radius:inherit;border-bottom-right-radius:inherit}.dropup-menu-item-icon{width:1.39em;position:relative}.dropup-menu-item-icon>svg{bottom:0!important;top:0!important;margin-bottom:auto;margin-top:auto}#dropup-menu-item-icon-element-custom{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.28em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%)}.dropup-menu-item-text{margin-left:.56em;margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-left:auto;margin-right:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;display:grid;grid-template-columns:100%}::-webkit-scrollbar{width:9px;height:9px}::-webkit-scrollbar-thumb{background-color:#d0d0d0;border-radius:5px}::-webkit-scrollbar-track{background-color:#f2f2f2}.deep-chat-web-model-button{margin-top:10px;margin-bottom:5px;margin-left:1px}:host{all:initial;display:table-cell}#container{height:inherit;width:inherit;overflow:hidden}";var El=Object.defineProperty,A=function A(r,e,t,s){for(var i=void 0,n=r.length-1,o;n>=0;n--)(o=r[n])&&(i=o(e,t,i)||i);return i&&El(e,t,i),i;};var w=/*#__PURE__*/function(_ki){function w(){var _this121;_classCallCheck(this,w);var e;_this121=_callSuper(this,w),_this121.getMessages=function(){return[];},_this121.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.");},_this121.addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.");},_this121.updateMessage=function(){},_this121.clearMessages=function(){},_this121.focusInput=function(){return ys.focusFromParentElement(_this121._elementRef);},_this121.refreshMessages=function(){},_this121.scrollToBottom=function(){},_this121.disableSubmitButton=function(){},_this121.setPlaceholderText=function(){},_this121._hasBeenRendered=!1,_this121._auxiliaryStyleApplied=!1,_this121._elementRef=document.createElement("div"),_this121._elementRef.id="container",_this121.attachShadow({mode:"open"}).appendChild(_this121._elementRef),(e=_this121.shadowRoot)==null||e.appendChild(Ee.buildElement()),Yt.apply(_l,_this121.shadowRoot),setTimeout(function(){_this121._hasBeenRendered||_this121.onRender();},20);return _this121;}_inherits(w,_ki);return _createClass(w,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
307
|
-
},{key:"onRender",value:function onRender(){var _this$_childElement;
|
290
|
+
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e,t,s,i){var n,o,a;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:n=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context179.n=1;return s.completePlaceholders();case 1:o=s.getAllFileData(),a=o==null?void 0:o.map(function(l){return l.file;});return _context179.a(2,ut.validate(e,i,n,a));}},_callee179);}));function useValidationFunc(_x322,_x323,_x324,_x325){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
|
291
|
+
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(e,t,s){var n,i;return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:i=(n=t.files)==null?void 0:n.map(function(o){return o.file;});return _context180.a(2,ut.validate(e,s,t.text,i,!0));}},_callee180);}));function useValidationFuncProgrammatic(_x326,_x327,_x328){return _useValidationFuncProgrammatic.apply(this,arguments);}return useValidationFuncProgrammatic;}()},{key:"validateWebsocket",value:function validateWebsocket(e,t){var s=e.websocket,i=e.connectSettings;return s&&i.url!==Ne.URL&&!ne.canSendMessage(s)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
|
292
|
+
},{key:"attach",value:function attach(e,t,s,i,n){var o=e.validateInput||le.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref165=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee181(a){var l;return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:if(!(n.status.loadingActive||n.status.requestInProgress||t.isSubmitProgrammaticallyDisabled===!0||!ut.validateWebsocket(t,n))){_context181.n=1;break;}return _context181.a(2,!1);case 1:l=o||t.canSendMessage;return _context181.a(2,l?a?ut.useValidationFuncProgrammatic(l,a,n):ut.useValidationFunc(l,s,i,n):null);}},_callee181);}));return function(_x329){return _ref165.apply(this,arguments);};}();}}]);}();var Lr=/*#__PURE__*/function(){function Lr(){_classCallCheck(this,Lr);}return _createClass(Lr,null,[{key:"getFileName",value:function getFileName(e,t){var s=/* @__PURE__ */new Date(),i=String(s.getHours()).padStart(2,"0"),n=String(s.getMinutes()).padStart(2,"0"),o=String(s.getSeconds()).padStart(2,"0");return"".concat(e,"-").concat(i,"-").concat(n,"-").concat(o,".").concat(t);}}]);}();var Ol=/*#__PURE__*/function(_Mi2){function Ol(e,t){var _this108;_classCallCheck(this,Ol);var s,i;_this108=_callSuper(this,Ol,[t.button]),_this108._waitingForBrowserApproval=!1,_this108._audioType=e,_this108._extension=((s=t.files)==null?void 0:s.format)||"mp3",_this108._maxDurationSeconds=(i=t.files)==null?void 0:i.maxDurationSeconds,_this108.elementRef.onclick=_this108.buttonClick.bind(_assertThisInitialized(_this108));return _this108;}_inherits(Ol,_Mi2);return _createClass(Ol,[{key:"buttonClick",value:function buttonClick(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()));}},{key:"stop",value:function stop(){var _this109=this;return new Promise(function(e){var t,s;_this109.changeToDefault(),(t=_this109._mediaRecorder)==null||t.stop(),(s=_this109._mediaStream)==null||s.getTracks().forEach(function(i){return i.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this110=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this110.changeToActive(),_this110._mediaRecorder=new MediaRecorder(e),_this110._audioType.addPlaceholderAttachment(_this110.stop.bind(_this110),_this110._maxDurationSeconds),_this110._mediaStream=e,_this110._mediaRecorder.addEventListener("dataavailable",function(t){_this110.createFile(t);}),_this110._mediaRecorder.start();})["catch"](function(e){console.error(e),_this110.stop();})["finally"](function(){_this110._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this111=this;var t=new Blob([e.data],{type:"audio/".concat(this._extension)}),s=Lr.getFileName(this._newFilePrefix||"audio",this._extension),i=new File([t],s,{type:t.type}),n=new FileReader();n.readAsDataURL(i),n.onload=function(o){_this111._audioType.completePlaceholderAttachment(i,o.target.result);};}}]);}(Mi);var Pl="<?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 St=/*#__PURE__*/function(){function St(){_classCallCheck(this,St);}return _createClass(St,null,[{key:"resetSubmit",value:function resetSubmit(e,t){t?e.unsetCustomStateStyles(["loading","submit"]):e.unsetCustomStateStyles(["stop","loading","submit"]),e.reapplyStateStyle("submit");}},{key:"overwriteDefaultStyleWithSubmit",value:function overwriteDefaultStyleWithSubmit(e,t){if(!e.submit)return;var s=JSON.parse(JSON.stringify(e[t]||{}));re.overwritePropertyObjectFromAnother(s,e.submit,["container","default"]),re.overwritePropertyObjectFromAnother(s,e.submit,["text","styles","default"]),re.overwritePropertyObjectFromAnother(s,e.submit,["svg","styles","default"]),e[t]=s;}// prettier-ignore
|
293
|
+
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){re.setPropertyValueIfDoesNotExist(e,["submit","container","default","backgroundColor"],""),re.setPropertyValueIfDoesNotExist(e,["disabled","container","default","backgroundColor"],"unset"),re.setPropertyValueIfDoesNotExist(e.submit,["svg","styles","default","filter"],""),re.setPropertyValueIfDoesNotExist(e.disabled,["svg","styles","default","filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),re.setPropertyValueIfDoesNotExist(e.disabled,["text","styles","default","color"],"grey"),St.overwriteDefaultStyleWithSubmit(e,"disabled");}},{key:"process",value:function process(e){var t=JSON.parse(JSON.stringify(e||{}));return St.overwriteDefaultStyleWithSubmit(t,"loading"),St.overwriteDefaultStyleWithSubmit(t,"stop"),e!=null&&e.alwaysEnabled||St.setUpDisabledButton(t),t;}}]);}();var q=/*#__PURE__*/function(_Mt6){// prettier-ignore
|
294
|
+
function q(e,t,s,i,n,o){var _this112;_classCallCheck(this,q);var a=St.process(e.submitButtonStyles),l=Pl,c=Le.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this112=_callSuper(this,q,[q.createButtonContainerElement(),l,a==null?void 0:a.position,c,a]),_this112._isSVGLoadingIconOverriden=!1,_this112.status={requestInProgress:!1,loadingActive:!1},_this112._messages=s,_this112._textInput=t,_this112._fileAttachments=n,_this112._innerElements=_this112.createInnerElementsForStates(),_this112._stopClicked={listener:function listener(){}},_this112._serviceIO=i,_this112._alwaysEnabled=!!(a!=null&&a.alwaysEnabled),e.disableSubmitButton=_this112.disableSubmitButton.bind(_assertThisInitialized(_this112),i),_this112.attemptOverwriteLoadingStyle(e),o.microphone&&_this112.setUpSpeechToText(o.microphone.button,e.speechToText),setTimeout(function(){var d;_this112._validationHandler=e._validationHandler,_this112.assignHandlers(_this112._validationHandler),(d=_this112._validationHandler)==null||d.call(_assertThisInitialized(_this112));});return _this112;}_inherits(q,_Mt6);return _createClass(q,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(){var _this$createCustomEle=this.createCustomElements(),e=_this$createCustomEle.submit,t=_this$createCustomEle.loading,s=_this$createCustomEle.stop;return{submit:e,loading:t||[q.createLoadingIconElement()],stop:s||[q.createStopIconElement()],disabled:this.createDisabledIconElement(e)};}},{key:"createCustomElements",value:function createCustomElements(){var _this113=this;var e=Ue.createCustomElements("submit",this.svg,this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(s){var i=s,n=Ue.createCustomElements(i,_this113.svg,_this113.customStyles);n&&(t[i]=n);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return Ue.createCustomElements("disabled",this.svg,this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
|
295
|
+
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,s,i,n,o,a,l,c,d;if(!((s=(t=this.customStyles)==null?void 0:t.submit)!=null&&s.svg||(o=(n=(i=this.customStyles)==null?void 0:i.loading)==null?void 0:n.svg)!=null&&o.content||(c=(l=(a=this.customStyles)==null?void 0:a.loading)==null?void 0:l.text)!=null&&c.content)&&(e.displayLoadingBubble===void 0||e.displayLoadingBubble===!0)){var h=document.createElement("style");h.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(h),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 _callee182(){var e,t;return _regenerator().w(function(_context182){while(1)switch(_context182.n){case 0:_context182.n=1;return this._fileAttachments.completePlaceholders();case 1:e=this._fileAttachments.getAllFileData();if(this._textInput.isTextInputEmpty())this.attemptSubmit(_defineProperty(_defineProperty({},g,""),"files",e));else{t=this._textInput.inputElementRef.innerText.trim();this.attemptSubmit(_defineProperty(_defineProperty({},g,t),"files",e));}case 2:return _context182.a(2);}},_callee182,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee183(e){var _this114=this;var t;return _regenerator().w(function(_context183){while(1)switch(_context183.n){case 0:typeof e=="string"&&(e=le.processSubmitUserMessage(e));t=_defineProperty({},g,e.text);e.files&&(t.files=Array.from(e.files).map(function(s){return{file:s,type:We.getTypeFromBlob(s)};})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this114.attemptSubmit(t,!0);});case 1:return _context183.a(2);}},_callee183);}));function programmaticSubmit(_x330){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
|
296
|
+
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee184(e){var t,n,o,a,l,s,i,_args184=arguments,_t44,_t45,_t46;return _regenerator().w(function(_context184){while(1)switch(_context184.n){case 0:t=_args184.length>1&&_args184[1]!==undefined?_args184[1]:!1;_context184.n=1;return(n=this._validationHandler)==null?void 0:n.call(this,t?e:void 0);case 1:_t44=_context184.v;_t45=!1;if(!(_t44===_t45)){_context184.n=2;break;}return _context184.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();_t46=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t46){_context184.n=3;break;}_context184.n=3;return js.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context184.n=4;return this.addNewMessage(e);case 4:this._serviceIO.isWebModel()||this._messages.addLoadingMessage();s=(a=e.files)==null?void 0:a.map(function(c){return c.file;}),i=_defineProperty(_defineProperty({},g,e.text===""?void 0:e.text),"files",s);_context184.n=5;return this._serviceIO.callAPI(i,this._messages);case 5:(l=this._fileAttachments)==null||l.hideFiles();case 6:return _context184.a(2);}},_callee184,this);}));function attemptSubmit(_x331){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee185(_ref166){var e,t,s,i,_t47;return _regenerator().w(function(_context185){while(1)switch(_context185.n){case 0:e=_ref166.text,t=_ref166.files,s=_ref166.custom;i={role:b.USER_ROLE,custom:s};e&&(i.text=e);_t47=t;if(!_t47){_context185.n=2;break;}_context185.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:i.files=_context185.v;case 2:this._serviceIO.sessionId&&(i._sessionId=this._serviceIO.sessionId);Object.keys(i).length>0&&this._messages.addNewMessage(i);case 3:return _context185.a(2);}},_callee185,this);}));function addNewMessage(_x332){return _addNewMessage.apply(this,arguments);}return addNewMessage;}()},{key:"stopStream",value:function stopStream(){var e,t,s;(t=(e=this._serviceIO.streamHandlers).onAbort)==null||t.call(e),(s=this._stopClicked)==null||s.listener(),this._validationHandler&&this.resetSubmit(this._validationHandler);}},{key:"changeToStopIcon",value:function changeToStopIcon(){this._serviceIO.websocket||(this.elementRef.classList.remove(q.LOADING_CLASS,q.DISABLED_CLASS,q.SUBMIT_CLASS),j.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle("stop",["loading","submit"]),this.elementRef.onclick=this.stopStream.bind(this),this.status.loadingActive=!1);}},{key:"changeToLoadingIcon",value:function changeToLoadingIcon(){this._serviceIO.websocket||(this._isSVGLoadingIconOverriden||this.changeElementsByState(this._innerElements.loading),this.elementRef.classList.remove(q.SUBMIT_CLASS,q.DISABLED_CLASS),j.removeAriaDisabled(this.elementRef),this.elementRef.classList.add(q.LOADING_CLASS),j.addAriaBusy(this.elementRef),this.reapplyStateStyle("loading",["submit"]),this.elementRef.onclick=function(){},this.status.requestInProgress=!0,this.status.loadingActive=!0);}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
|
297
|
+
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this115=this;this.elementRef.classList.contains(q.SUBMIT_CLASS)||(this.elementRef.classList.remove(q.LOADING_CLASS,q.DISABLED_CLASS),j.removeAriaAttributes(this.elementRef),this.elementRef.classList.add(q.SUBMIT_CLASS),this.changeElementsByState(this._innerElements.submit),St.resetSubmit(this,this.status.loadingActive),this.elementRef.onclick=function(){var e;_this115.submitFromInput(),(e=_this115._microphoneButton)!=null&&e.isActive&&Rs.toggleSpeechAfterSubmit(_this115._microphoneButton.elementRef,!!_this115._stopSTTAfterSubmit);});}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
|
298
|
+
},{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef.classList.contains(q.DISABLED_CLASS)||(this.elementRef.classList.remove(q.LOADING_CLASS,q.SUBMIT_CLASS),j.removeAriaBusy(this.elementRef),this.elementRef.classList.add(q.DISABLED_CLASS),j.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements.disabled),this.reapplyStateStyle("disabled",["submit"]),this.elementRef.onclick=function(){});}},{key:"disableSubmitButton",value:function disableSubmitButton(e,t){var s;e.isSubmitProgrammaticallyDisabled=t!==!1,!(this.status.requestInProgress||this.status.loadingActive)&&(t===!1?(s=this._validationHandler)==null||s.call(this):this.changeToDisabledIcon(!0));}}],[{key:"createButtonContainerElement",value:function createButtonContainerElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=document.createElement("div");return e.classList.add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=document.createElement("div");return e.id="stop-icon",e;}}]);}(Mt);q.SUBMIT_CLASS="submit-button",q.LOADING_CLASS="loading-button",q.DISABLED_CLASS="disabled-button";var rn=q;var Dl="<?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",Bl="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M0 16q0 3.264 1.28 6.208t3.392 5.12 5.12 3.424 6.208 1.248 6.208-1.248 5.12-3.424 3.392-5.12 1.28-6.208-1.28-6.208-3.392-5.12-5.088-3.392-6.24-1.28q-3.264 0-6.208 1.28t-5.12 3.392-3.392 5.12-1.28 6.208zM4 16q0-3.264 1.6-6.016t4.384-4.352 6.016-1.632 6.016 1.632 4.384 4.352 1.6 6.016-1.6 6.048-4.384 4.352-6.016 1.6-6.016-1.6-4.384-4.352-1.6-6.048z\"></path>\n</svg>\n",Fl="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 1024 1024\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M195.2 195.2a64 64 0 0 1 90.496 0L512 421.504 738.304 195.2a64 64 0 0 1 90.496 90.496L602.496 512 828.8 738.304a64 64 0 0 1-90.496 90.496L512 602.496 285.696 828.8a64 64 0 0 1-90.496-90.496L421.504 512 195.2 285.696a64 64 0 0 1 0-90.496z\"/>\n</svg>",Ul="<?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 vn=/*#__PURE__*/function(_Et){// prettier-ignore
|
299
|
+
function vn(e,t,s,i){var _this116;_classCallCheck(this,vn);_this116=_callSuper(this,vn,[e,["modal-content","modal-camera-content"],s]),_this116._stopped=!1,_this116._format="image/png",_this116._canvas=document.createElement("canvas"),_this116._canvas.classList.add("camera-modal-canvas");var _this116$addButtonsAn=_this116.addButtonsAndTheirEvents(t),n=_this116$addButtonsAn.captureButton,o=_this116$addButtonsAn.submitButton;_this116._captureButton=n,_this116._submitButton=o,_this116._captureIcon=_this116._captureButton.children[0],_this116._refreshIcon=Qe.createSVGElement(Dl),_this116._refreshIcon.classList.add("modal-svg-button-icon","modal-svg-refresh-icon"),(i==null?void 0:i.format)==="jpeg"&&(_this116._format="image/jpeg"),i!=null&&i.dimensions&&(_this116._dimensions=i.dimensions),_this116._contentRef.appendChild(_this116._canvas),_this116.extensionCloseCallback=_this116.stop;return _this116;}_inherits(vn,_Et);return _createClass(vn,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=Et.createSVGButton(Bl);t.classList.add("modal-svg-camera-button"),t.children[0].classList.add("modal-svg-camera-icon");var s=this.addCloseButton(Fl,!0);s.classList.add("modal-svg-close-button"),s.children[0].classList.add("modal-svg-close-icon");var i=Et.createSVGButton(Ul);return i.classList.add("modal-svg-submit-button"),this.addButtons(t,i),this.addButtonEvents(t,s,i,e),{captureButton:t,submitButton:i};}// prettier-ignore
|
300
|
+
},{key:"addButtonEvents",value:function addButtonEvents(e,t,s,i){var _this117=this;e.onclick=function(){_this117.capture();},t.addEventListener("click",this.stop.bind(this)),s.onclick=function(){var n=_this117.getFile();n&&Ns.addFilesToType([n],[i]),_this117.stop(),_this117.close();};}},{key:"stop",value:function stop(){var _this118=this;this._mediaStream&&this._mediaStream.getTracks().forEach(function(e){return e.stop();}),this._stopped=!0,setTimeout(function(){_this118._captureButton.replaceChildren(_this118._captureIcon),_this118._captureButton.classList.replace("modal-svg-refresh-button","modal-svg-camera-button");var e=_this118._canvas.getContext("2d");e==null||e.clearRect(0,0,_this118._canvas.width,_this118._canvas.height);},Et.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this119=this;this._dataURL=void 0,this._submitButton.classList.add("modal-svg-submit-disabled"),this._stopped=!1,navigator.mediaDevices.getUserMedia({video:this._dimensions||!0}).then(function(e){if(_this119._mediaStream=e,!_this119.isOpen())return _this119.stop();var t=document.createElement("video");t.srcObject=e,t.play(),requestAnimationFrame(_this119.updateCanvas.bind(_this119,t,_this119._canvas));})["catch"](function(e){console.error(e),_this119.stop(),_this119.close();});}},{key:"capture",value:function capture(){this._dataURL?(this._captureButton.replaceChildren(this._captureIcon),this._captureButton.classList.replace("modal-svg-refresh-button","modal-svg-camera-button"),this._submitButton.classList.add("modal-svg-submit-disabled"),this._dataURL=void 0):(this._captureButton.replaceChildren(this._refreshIcon),this._captureButton.classList.replace("modal-svg-camera-button","modal-svg-refresh-button"),this._submitButton.classList.remove("modal-svg-submit-disabled"),this._dataURL=this._canvas.toDataURL());}},{key:"getFile",value:function getFile(){if(this._dataURL){var e=atob(this._dataURL.split(",")[1]),t=new Array(e.length);for(var a=0;a<e.length;a++)t[a]=e.charCodeAt(a);var _s16=new Uint8Array(t),i=new Blob([_s16],{type:this._format}),n=this._format==="image/jpeg"?"jpeg":"png",o=Lr.getFileName(this._newFilePrefix||"photo",n);return new File([i],o,{type:i.type});}}},{key:"updateCanvas",value:function updateCanvas(e,t){if(!this._stopped){if(!this._dataURL){t.width=e.videoWidth,t.height=e.videoHeight;var _s17=t.getContext("2d");_s17==null||_s17.drawImage(e,0,0,t.width,t.height);}requestAnimationFrame(this.updateCanvas.bind(this,e,t));}}},{key:"openCameraModal",value:function openCameraModal(e){this.displayModalElements(),e.start();}// prettier-ignore
|
301
|
+
}],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,s,i){var n=new vn(e,t,s,i);return n.openCameraModal.bind(n,n);}}]);}(Et);var Hl="<?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 _n=/*#__PURE__*/function(_Mt7){function _n(e,t,s){var _this120;_classCallCheck(this,_n);var c,d,h,u,f,m;var i=(c=s==null?void 0:s.button)==null?void 0:c.position,n=((u=(h=(d=s==null?void 0:s.button)==null?void 0:d.styles)==null?void 0:h.text)==null?void 0:u.content)||"Photo",o=Le.tryCreateConfig("Camera",(f=s==null?void 0:s.button)==null?void 0:f.tooltip),a=((m=s==null?void 0:s.button)==null?void 0:m.styles)||{};_this120=_callSuper(this,_n,[_n.createButtonElement(),Hl,i,o,a,n]);var l=_this120.createInnerElementsForStates(_this120.customStyles);s&&_this120.addClickEvent(e,t,s.modalContainerStyle,s.files),_this120.changeElementsByState(l.styles),_this120.reapplyStateStyle("styles");return _this120;}_inherits(_n,_Mt7);return _createClass(_n,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("camera-icon","styles",e)};}},{key:"addClickEvent",value:// prettier-ignore
|
302
|
+
function addClickEvent(e,t,s,i){var n=vn.createCameraModalFunc(e,t,s,i);this.elementRef.onclick=n;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button"),e;}}]);}(Mt);var It=/*#__PURE__*/function(){function It(e,t,s,i){_classCallCheck(this,It);this.elementRef=It.createPanelElement(e.inputAreaStyle);var n={},o=this.createFileUploadComponents(e,s,i,n),a=new qs(e,s,o);e.speechToText&&!n.microphone&&(n.microphone={button:new Rs(e,a,t.addNewErrorMessage.bind(t))});var l=new rn(e,a,t,s,o,n);a.submit=l.submitFromInput.bind(l),ut.attach(e,s,a,o,l),e.submitUserMessage=l.programmaticSubmit.bind(l),n.submit={button:l},e.customButtons&&xt.add(e,n),It.addElements(this.elementRef,a,n,i,o,e.dropupStyles),It.assignOnInput(e,s,o,a);}return _createClass(It,[{key:"createFileUploadComponents",value:// prettier-ignore
|
303
|
+
function createFileUploadComponents(e,t,s,i){var o,a,l,c;var n=new Ns(this.elementRef,e.attachmentContainerStyle,t.demo);if(It.createUploadButtons(e,t,t.fileTypes||{},n,s,i),(o=t.camera)!=null&&o.files){var d=((a=i.images)==null?void 0:a.fileType)||n.addType(e,t,t.camera.files,"images");i.camera={button:new _n(s,d,t.camera)};}if((l=t.recordAudio)!=null&&l.files){var _d=((c=i.audio)==null?void 0:c.fileType)||n.addType(e,t,t.recordAudio.files,"audio");i.microphone={button:new Ol(_d,t.recordAudio)};}return $e.isEnabled(n,e.dragAndDrop)&&$e.create(s,n,e.dragAndDrop),n;}// prettier-ignore
|
304
|
+
}],[{key:"createPanelElement",value:function createPanelElement(e){var t=document.createElement("div");return t.id="input",Object.assign(t.style,e),t;}},{key:"createUploadButtons",value:function createUploadButtons(e,t,s,i,n,o){Object.keys(s).forEach(function(a){var l=a,c=s[l];if(c.files){var d=i.addType(e,t,c.files,l),_pl$l=pl[l],h=_pl$l.id,u=_pl$l.svgString,f=_pl$l.dropupText,m=new _i(n,d,c,h,u,f);o[l]={button:m,fileType:d};}});}// prettier-ignore
|
305
|
+
},{key:"addElements",value:function addElements(e,t,s,i,n,o){ae.addElements(e,t.elementRef);var a=Ut.create(),l=de.addButtons(a,s,i,o);nn.set(t.inputElementRef,a,n.elementRef,l),Ut.add(e,a);}},{key:"assignOnInput",value:function assignOnInput(e,t,s,i){t.onInput=function(n){setTimeout(function(){var o=s.getAllFileData(),a=i.inputElementRef.innerText.trim(),l=_defineProperty({},g,a);o&&(l.files=o.map(function(c){return c.file;})),xs.onInput(e,l,n);});};}}]);}();var En=/*#__PURE__*/function(){function En(){_classCallCheck(this,En);}return _createClass(En,null,[{key:"createElements",value:function createElements(e,t,s){var i=document.createElement("div");i.id="chat-view";var n=new xe(e,t,s);t.websocket&&ne.createConnection(t,n);var o=new It(e,n,t,i);return ae.addElements(i,n.elementRef,o.elementRef),i;}},{key:"render",value:function render(e,t,s,i){var n=En.createElements(e,s,i);t.replaceChildren(n),s.isCustomView()&&s.setUpView(n,t);}}]);}();var ql="#validate-property-key-view{height:100%;position:relative;display:flex;justify-content:center;align-items:center;padding:8px}#loading-validate-key-property{display:inline-block;width:50px;height:50px}#loading-validate-key-property:after{content:\" \";display:block;width:38px;height:38px;margin:1px;border-radius:50%;border:5px solid #5fb2ff;border-color:#5fb2ff transparent #5fb2ff transparent;animation:loading-spinner 1.4s linear infinite}#deep-chat-openai-realtime-container{height:100%;width:100%}#deep-chat-openai-realtime-avatar-container{height:60%;width:100%;display:flex;justify-content:center;align-items:center}#deep-chat-openai-realtime-avatar{border-radius:50%;height:110px;border:1px solid rgb(215,215,215);padding:8px;-webkit-user-select:none;user-select:none;margin-top:20px}#deep-chat-openai-realtime-buttons-container{height:40%;display:flex;position:relative}.deep-chat-openai-realtime-button-container{height:100%;width:50%;display:flex;justify-content:center;align-items:center}.deep-chat-openai-realtime-button{width:70px;height:70px;border-radius:50%;display:flex;justify-content:center;align-items:center;cursor:pointer}.deep-chat-openai-realtime-button-default{background-color:#e3e3e3}.deep-chat-openai-realtime-button-default:hover{background-color:#d4d4d4}.deep-chat-openai-realtime-button-default:active{background-color:#c5c5c5}.deep-chat-openai-realtime-button-loading{opacity:.7;pointer-events:none}.deep-chat-openai-realtime-microphone-active{background-color:#ffe7e7}.deep-chat-openai-realtime-microphone-active:hover{background-color:#ffdede}.deep-chat-openai-realtime-microphone-active:active{background-color:#ffd2d2}.deep-chat-openai-realtime-microphone>*{height:30px;width:30px}.deep-chat-openai-realtime-microphone-active>*{filter:brightness(0) saturate(100%) invert(35%) sepia(60%) saturate(1360%) hue-rotate(325deg) brightness(95%) contrast(92%)}.deep-chat-openai-realtime-toggle>*{height:32px;width:32px;padding-left:3px;filter:brightness(0) saturate(100%) invert(22%) sepia(0%) saturate(4537%) hue-rotate(208deg) brightness(105%) contrast(91%)}.deep-chat-openai-realtime-button-unavailable{opacity:.45;pointer-events:none}#deep-chat-openai-realtime-error{color:red;position:absolute;top:calc(50% + 40px);left:50%;transform:translate(-50%,-50%);font-size:17px}#deep-chat-openai-realtime-loading{position:absolute;font-size:15px;top:50%;left:50%;transform:translate(-50%,-50%)}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;top:44%;left:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-right:2.7em;width:calc(100% - 80px)}#insert-key-input{padding:.3em 1.7em .3em .3em;border-width:1px;border-style:solid;border-radius:3px;width:100%;font-size:inherit}.insert-key-input-valid{border-color:gray}.insert-key-input-invalid{border-color:red}#visibility-icon-container{position:relative;float:right;cursor:pointer;-webkit-user-select:none;user-select:none}.visibility-icon{filter:brightness(0) saturate(100%) invert(63%) sepia(1%) saturate(9%) hue-rotate(43deg) brightness(98%) contrast(92%);position:absolute;right:-1.7em;top:-1.43em}#visible-icon{top:-1.4em}.visibility-icon:hover{filter:unset}.visibility-icon>*{pointer-events:none}#start-button{border:1px solid grey;color:#454545;border-radius:4px;width:3em;display:flex;justify-content:center;align-items:center;cursor:pointer;padding:.28em .3em;-webkit-user-select:none;user-select:none;background-color:#fff}#start-button:hover{background-color:#f2f2f2}#start-button:active{background-color:#d2d2d2}#insert-key-help-text-container{width:100%;position:absolute;margin-top:32px;margin-bottom:20px}#insert-key-help-text-contents{width:100%;position:absolute}#insert-key-input-invalid-text{display:block;margin-top:1em;margin-bottom:.5em;color:red}.insert-key-input-help-text{display:block;margin-top:16px}#loading-key{display:inline-block;width:16px;height:16px}#loading-key:after{content:\" \";display:block;width:11px;height:11px;margin:1px;border-radius:50%;border:2px solid #0084ff;border-color:#0084ff transparent #0084ff transparent;animation:loading-spinner 1.2s linear infinite}#error-view{color:red;font-size:1.2em;line-height:1.3em;margin-top:-5px;text-align:center;height:100%;display:flex;justify-content:center;align-items:center;padding-left:8px;padding-right:8px}@keyframes loading-spinner{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.intro-panel{position:absolute;display:flex;justify-content:center;right:0;bottom:0;left:0;margin:auto;height:fit-content;top:-2.5em}#internal-intro-panel{width:250px;height:min-content;display:block;border-radius:5px;overflow:auto;border:1px solid rgb(203,203,203);padding:10px;max-height:calc(100% - 6.8em)}#internal-intro-panel>p{margin-block-start:.8em;margin-block-end:.8em}pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!\n Theme: a11y-dark\n Author: @ericwbailey\n Maintainer: @ericwbailey\n\n Based on the Tomorrow Night Eighties theme: https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css\n*/.hljs{background:#2b2b2b;color:#f8f8f2}.hljs-comment,.hljs-quote{color:#d4d0ab}.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#ffa07a}.hljs-built_in,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#f5ab35}.hljs-attribute{color:gold}.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#abe338}.hljs-section,.hljs-title{color:#00e0e0}.hljs-keyword,.hljs-selector-tag{color:#dcc6e0}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}@media screen and (-ms-high-contrast: active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}}#messages{overflow:auto}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-left:auto;margin-right:auto;width:calc(97.5% - 24px);max-width:100%}.message-bubble{margin-top:10px;word-wrap:break-word;width:fit-content;max-width:60%;border-radius:10px;padding:.42em .55em;height:fit-content;line-height:1.26em}.user-message-text{color:#fff;background-color:#0084ff;margin-right:0;margin-left:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-left:0;margin-right:auto}.deep-chat-last-group-messages-active{height:100%}.loading-history-message-full-view{position:absolute;height:70%;width:100%;display:flex;align-items:center}.loading-history-message-small{height:20px;margin-bottom:30px}.loading-history-message-small>div>div{scale:.6}.loading-history-message{margin-top:0;width:100%;max-width:100%;display:flex;justify-content:center;background-color:unset}.loading-history{width:70px}.loading-history div{position:absolute;width:var(--loading-history-width);height:var(--loading-history-height);margin:var(--loading-history-margin);border:var(--loading-history-border);border-radius:50%;animation:loading-spinner 1.2s cubic-bezier(.5,0,.5,1) infinite;border-color:var(--loading-history-color) transparent transparent transparent}.loading-history div:nth-child(1){animation-delay:-.45s}.loading-history div:nth-child(2){animation-delay:-.3s}.loading-history div:nth-child(3){animation-delay:-.15s}.html-message{max-width:unset}.error-message-text{margin:14px auto 10px;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%}.deep-chat-loading-message-dots-container{width:1em;padding:.6em .75em .6em 1.3em}.loading-message-dots{position:relative;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite linear alternate;animation-delay:.5s}.loading-message-dots:before,.loading-message-dots:after{content:\"\";display:inline-block;position:absolute;top:0}.loading-message-dots:before{left:-.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:0s}.loading-message-dots:after{left:.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:1s}@keyframes loading-message-dots{0%{background-color:var(--loading-message-color)}50%,to{background-color:var(--loading-message-color-fade)}}.message-bubble>p:first-child,.message-bubble>.partial-render-message>p:first-child,.html-wrapper>p:first-child{margin-top:0}.message-bubble>p:last-child,.message-bubble>.partial-render-message:last-child>p,.html-wrapper>p:last-child{margin-bottom:0}pre{overflow:auto;display:block;word-break:break-all;word-wrap:break-word;border-radius:7px;background:#2b2b2b;color:#f8f8f2;margin-top:.8em;margin-bottom:.8em;padding:.6em;font-size:.9em;line-height:1.5em}.image-message{padding:0;display:flex;background-color:#ddd}.image-message>*,.image-message>*>*{width:100%;border-radius:8px;display:flex}.audio-message{width:60%;max-width:300px;height:2.2em;max-height:54px;padding:0;background-color:unset}.audio-player{width:100%;height:100%}.audio-player-safari{height:fit-content;width:40px}.audio-player-safari-left{float:left}.audio-player-safari-right{float:right}.any-file-message{padding:1px}.any-file-message-contents{display:flex}.any-file-message-icon-container{width:1.3em;min-width:1.3em;position:relative;border-radius:4px;margin-left:6px;margin-right:2px}.any-file-message-icon{background-color:#fff;border-radius:4px;position:absolute;width:1em;height:1.25em;padding:1px;margin-top:auto;margin-bottom:auto;top:0;bottom:0}.any-file-message-text{padding-top:5px;overflow-wrap:anywhere;padding-bottom:5px;padding-right:7px}.message-bubble>a{color:inherit}.left-item-position{margin-right:10px}.right-item-position{margin-left:10px}.role-hidden{display:none}.avatar{padding-top:5px;width:1.5em;height:1.5em;border-radius:1px}.avatar-container{margin-top:9px}.name{margin-top:16px;font-size:15px}#drag-and-drop{position:absolute;display:none;z-index:10;height:calc(100% - 10px);width:calc(100% - 10px);background-color:#70c6ff4d;border:5px dashed #6dafff}#file-attachment-container{position:absolute;height:3.6em;width:calc(80% - 4px);top:-2.5em;border-radius:5px;overflow:auto;text-align:left;background-color:#d7d7d73b;padding-left:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-right:.6em;margin-bottom:.44em;margin-top:4px;position:relative;background-color:#fff;border-radius:5px}.image-attachment{width:100%;height:100%;object-fit:cover;border-radius:5px}.border-bound-attachment{width:calc(100% - 2px);height:calc(100% - 2px);border:1px solid #c3c3c3;border-radius:5px;overflow:hidden}.border-bound-attachment-safari{width:calc(100% - 1px);height:calc(100% - 1px)}.audio-attachment-icon-container{cursor:pointer}.audio-attachment-icon-container:hover{background-color:#f8f8f8}.attachment-icon{left:0;right:0;bottom:0;top:2px;margin:auto;position:absolute;width:25px;-webkit-user-select:none;user-select:none}.not-removable-attachment-icon{top:0;right:0;bottom:0;left:0}.play-icon{filter:brightness(0) saturate(100%) invert(17%) sepia(0%) saturate(1392%) hue-rotate(67deg) brightness(98%) contrast(97%)}.stop-icon{filter:brightness(0) saturate(100%) invert(29%) sepia(90%) saturate(1228%) hue-rotate(198deg) brightness(93%) contrast(98%)}.audio-placeholder-text-3-digits{padding-left:.26rem}.audio-placeholder-text-4-digits{padding-left:.1rem}.any-file-attachment{padding:2px 0}.file-attachment-text-container{position:absolute;width:inherit;display:flex;align-items:center;height:100%;top:-1px}.audio-placeholder-text-3-digits-container{padding-top:1px;cursor:default}.any-file-attachment-text{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;padding-left:.13em;margin-left:auto;margin-right:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;right:-5px;position:absolute;display:flex;justify-content:center;cursor:pointer;-webkit-user-select:none;user-select:none}.remove-file-attachment-button:hover{background-color:#e4e4e4}.remove-file-attachment-button:active{background-color:#d7d7d7}.x-icon{color:#4e4e4e;top:-.075em;position:relative;font-size:1.05em}.modal{display:none;flex-direction:column;align-items:center;justify-content:center;position:absolute;width:80%;max-width:420px;max-height:80%;margin:auto;top:0;right:0;bottom:0;left:0;z-index:3}.modal-content{border-top:1px solid rgb(217,217,217);border-left:1px solid rgb(217,217,217);border-right:1px solid rgb(217,217,217);border-top-left-radius:inherit;border-top-right-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-left:1em;margin-right:1em}.modal-content>ul{margin-right:1em}.modal-button-panel{height:3.3em;border:1px solid;border-color:rgb(223,223,223) rgb(217,217,217) rgb(217,217,217);border-bottom-left-radius:inherit;border-bottom-right-radius:inherit;background-color:#fff;text-align:center;justify-content:center;display:flex;width:100%}.modal-button{min-width:2.5em;text-align:center;color:#fff;border-radius:5px;padding:.4em .4em .3em;height:1.25em;background-color:#3279b2;top:0;bottom:0;cursor:pointer;-webkit-user-select:none;user-select:none;margin:auto .31em}.modal-button:hover{background-color:#276da7}.modal-button:active{background-color:#1b5687}.modal-svg-button{padding:0 0 2px;width:2em;height:1.8em}.modal-svg-button-icon{width:100%;height:100%;filter:brightness(0) saturate(100%) invert(100%) sepia(15%) saturate(4%) hue-rotate(346deg) brightness(101%) contrast(102%)}#modal-background-panel{position:absolute;width:100%;height:100%;background-color:#00000042;z-index:2;display:none}.show-modal-background{animation:fadeInBackground .3s ease-in-out}@keyframes fadeInBackground{0%{opacity:0}to{opacity:1}}.show-modal{animation:fadeInModal .3s ease-in-out}@keyframes fadeInModal{0%{opacity:0;scale:.95}to{opacity:1;scale:1}}.hide-modal-background{animation:fadeOutBackground .2s ease-in-out}@keyframes fadeOutBackground{0%{opacity:1}to{opacity:0}}.hide-modal{animation:fadeOutModal .2s ease-in-out}@keyframes fadeOutModal{0%{opacity:1;scale:1}to{opacity:0;scale:.95}}.modal-camera-content{overflow:hidden;text-align:center;border:unset;height:100%;background-color:#2a2a2a;display:flex;justify-content:center}.camera-modal-canvas{max-width:100%;max-height:100%;margin-top:auto;margin-bottom:auto}.modal-svg-submit-button{background-color:green}.modal-svg-submit-button:hover{background-color:#007500}.modal-svg-submit-button:active{background-color:#006500}.modal-svg-submit-disabled{pointer-events:none;background-color:#747474}.modal-svg-close-button{height:1.56em;padding-top:.37em;padding-bottom:0;background-color:#c13e3e}.modal-svg-close-button:hover{background-color:#b43434}.modal-svg-close-button:active{background-color:#972929}.modal-svg-close-icon{width:80%;height:80%}.modal-svg-camera-button{height:1.6em;padding-top:.38em;padding-bottom:0}.modal-svg-camera-icon{height:76%}.modal-svg-refresh-icon{height:105%}.modal-svg-refresh-button{height:1.66em;padding-top:.11em;padding-bottom:.21em}.input-button-container{position:relative;z-index:1}.inside-right{position:absolute;right:calc(10% + .35em);bottom:.85em}.inside-left{position:absolute;left:calc(10% + .35em);bottom:.85em}.outside-left{position:absolute;right:calc(11px - .55em);bottom:.88em}.outside-right{position:absolute;left:calc(11px - .55em);bottom:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;left:.11em;bottom:.08em;filter:brightness(0) saturate(100%) invert(43%) sepia(0%) saturate(740%) hue-rotate(77deg) brightness(99%) contrast(92%)}#upload-gifs-icon{position:absolute;pointer-events:none;width:1.5em;height:1.48em;left:.07em;bottom:.08em;filter:brightness(0) saturate(100%) invert(49%) sepia(0%) saturate(2586%) hue-rotate(12deg) brightness(93%) contrast(90%)}#upload-audio-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.17em;bottom:.2em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%);transform:scaleX(.95)}#camera-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.23em;bottom:.2em;filter:brightness(0) saturate(100%) invert(52%) sepia(0%) saturate(161%) hue-rotate(164deg) brightness(91%) contrast(92%);transform:scaleX(.95)}#upload-mixed-files-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.25em;bottom:.2em;filter:brightness(0) saturate(100%) invert(53%) sepia(0%) saturate(36%) hue-rotate(74deg) brightness(98%) contrast(93%);transform:scaleX(.95)}#interim-text{color:gray}#microphone-button{padding-top:.5px}.outer-button-container>#microphone-button{padding-bottom:1px}#microphone-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.25em;bottom:.25em}.default-microphone-icon{filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%)}.active-microphone-icon{filter:brightness(0) saturate(100%) invert(10%) sepia(97%) saturate(7495%) hue-rotate(0deg) brightness(101%) contrast(107%);border-radius:10px}.command-microphone-icon{filter:brightness(0) saturate(100%) invert(42%) sepia(96%) saturate(1067%) hue-rotate(77deg) brightness(99%) contrast(102%)}.unsupported-microphone{display:none}#submit-icon{height:100%;filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%);width:1.21em}#stop-icon{background-color:#acacac;position:absolute;width:.95em;height:.95em;left:.35em;bottom:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-right:.3em;margin-left:.3em}.loading-submit-button{position:relative;left:calc(-9990px + .275em);width:.22em;height:.22em;border-radius:5px;background-color:#848484;color:#848484;box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484;animation:loading-submit-button 1.5s infinite linear;bottom:-.75em}@keyframes loading-submit-button{0%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}16.667%{box-shadow:9990px -6px #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}33.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}50%{box-shadow:9990px 0 #848484,calc(9990px + .44em) -6px 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}66.667%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}83.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) -6px 0 0 #848484}to{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}}.tooltip{position:absolute;visibility:hidden;z-index:1;pointer-events:none;padding:5px 7px;background-color:#333;border-radius:5px;width:max-content}.tooltip-text{color:#fff;font-size:13px}.input-button{border-radius:4px;cursor:pointer;margin-bottom:.2em;-webkit-user-select:none;user-select:none}.input-button-svg{width:1.65em;height:1.65em}.input-button-svg-text{padding:1px;height:1.65em;display:flex}.input-button-svg-text>svg{padding:.22rem}.input-button-svg-text>div{margin-left:2px}.input-button:hover,.input-button:focus-visible{background-color:#9c9c9c2e}.input-button:active{background-color:#9c9c9c5e}.input-button:active:not(:hover){background-color:transparent}.loading-button{cursor:auto}.loading-button:hover{background-color:unset}.text-button{filter:unset!important;display:flex;justify-content:center;align-items:center;margin-left:4px;margin-right:4px;height:1.6em;width:max-content}#custom-icon{height:100%;width:1.2em}.custom-button-container-default{color:#505050}.custom-button-container-default>.dropup-menu-item-icon{color:unset}.custom-button-container-default>svg{filter:brightness(0) saturate(100%) invert(39%) sepia(1%) saturate(0%) hue-rotate(83deg) brightness(93%) contrast(90%)}.custom-button-container-default>.dropup-menu-item-icon>svg{position:absolute;left:.2em}.custom-button-container-active{background-color:#edf7ff;color:#0285ff}.custom-button-container-active:hover,.custom-button-container-active:focus-visible{background-color:#def0ff}.custom-button-container-active:active{background-color:#d2eaff}.custom-button-container-active>svg{filter:brightness(0) saturate(100%) invert(32%) sepia(34%) saturate(4196%) hue-rotate(196deg) brightness(107%) contrast(104%)}.custom-button-container-disabled{color:#aeaeae;cursor:auto}.custom-button-container-disabled>div{pointer-events:none}.custom-button-container-disabled:hover,.custom-button-container-disabled:focus-visible{background-color:transparent}.custom-button-container-disabled:active{background-color:transparent}.custom-button-container-disabled>svg{filter:brightness(0) saturate(100%) invert(67%) sepia(0%) saturate(818%) hue-rotate(28deg) brightness(102%) contrast(100%)}#text-input-container{background-color:#fff;width:80%;display:flex;border:1px solid #0000001a;border-radius:5px;margin-top:.8em;margin-bottom:.8em;box-shadow:#959da533 0 1px 12px;overflow-y:auto;max-height:200px;position:relative}.text-input-container-left-adjustment{margin-left:1.5em}.text-input-container-right-adjustment{margin-right:1.5em}.text-input-container-left-small-adjustment{margin-left:1.1em}.text-input-container-left-small-adjustment>.outside-left{right:calc(14px - .55em)}.text-input-container-right-small-adjustment{margin-right:1.1em}.text-input-container-right-small-adjustment>.outside-right{left:calc(14px - .55em)}#text-input{text-align:left;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-left-adjustment{padding-left:2.2em}.text-input-inner-right-adjustment{padding-right:2em}.text-input-disabled{pointer-events:none;-webkit-user-select:none;user-select:none}[contenteditable]:empty:before{content:attr(deep-chat-placeholder-text);pointer-events:none}[contenteditable][textcolor]:empty:before{color:gray}.outside-right>#dropup-menu,.inside-right>#dropup-menu{right:0}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;left:.265em;bottom:.43em;filter:brightness(0) saturate(100%) invert(54%) sepia(0%) saturate(724%) hue-rotate(6deg) brightness(92%) contrast(90%)}.dropup-button>*{pointer-events:none}#dropup-menu{background-color:#fff;position:absolute;transform:translateY(-100%);border-radius:5px;z-index:1;top:-.49em;box-shadow:#0003 -1px 2px 10px,#0000001a 0 2px 4px;cursor:pointer;-webkit-user-select:none;user-select:none}.dropup-menu-item{height:1.4em;padding:.28em .84em .28em .35em;display:flex;position:relative}.dropup-menu-item:hover,.dropup-menu-item:focus-visible{background-color:#f3f3f3}.dropup-menu-item:active{background-color:#ebebeb}.dropup-menu-item:active:not(:hover){background-color:transparent}.dropup-menu-item:first-child{padding-top:.49em;border-top-left-radius:inherit;border-top-right-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-bottom-left-radius:inherit;border-bottom-right-radius:inherit}.dropup-menu-item-icon{width:1.39em;position:relative}.dropup-menu-item-icon>svg{bottom:0!important;top:0!important;margin-bottom:auto;margin-top:auto}#dropup-menu-item-icon-element-custom{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.28em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%)}.dropup-menu-item-text{margin-left:.56em;margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-left:auto;margin-right:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;display:grid;grid-template-columns:100%}::-webkit-scrollbar{width:9px;height:9px}::-webkit-scrollbar-thumb{background-color:#d0d0d0;border-radius:5px}::-webkit-scrollbar-track{background-color:#f2f2f2}.deep-chat-web-model-button{margin-top:10px;margin-bottom:5px;margin-left:1px}:host{all:initial;display:table-cell}#container{height:inherit;width:inherit;overflow:hidden}";var jl=Object.defineProperty,R=function R(r,e,t,s){for(var i=void 0,n=r.length-1,o;n>=0;n--)(o=r[n])&&(i=o(e,t,i)||i);return i&&jl(e,t,i),i;};var C=/*#__PURE__*/function(_Ki){function C(){var _this121;_classCallCheck(this,C);var e;_this121=_callSuper(this,C),_this121.getMessages=function(){return[];},_this121.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.");},_this121.addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.");},_this121.updateMessage=function(){},_this121.clearMessages=function(){},_this121.focusInput=function(){return ks.focusFromParentElement(_this121._elementRef);},_this121.refreshMessages=function(){},_this121.scrollToBottom=function(){},_this121.disableSubmitButton=function(){},_this121.setPlaceholderText=function(){},_this121._hasBeenRendered=!1,_this121._auxiliaryStyleApplied=!1,_this121._elementRef=document.createElement("div"),_this121._elementRef.id="container",_this121.attachShadow({mode:"open"}).appendChild(_this121._elementRef),(e=_this121.shadowRoot)==null||e.appendChild(Le.buildElement()),cs.apply(ql,_this121.shadowRoot),setTimeout(function(){_this121._hasBeenRendered||_this121.onRender();},20);return _this121;}_inherits(C,_Ki);return _createClass(C,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
306
|
+
},{key:"onRender",value:function onRender(){var _this$_childElement;Hs.attemptAppendStyleSheetToHead(this.style),le.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=rl.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(cs.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),cs.applyDefaultStyleToComponent(this.style,this.chatStyle),le.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?Us.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof L)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],En.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof L&&ce.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||xs.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){Cs.chat=void 0;}}]);}(Ki);R([T("object")],C.prototype,"connect");R([T("object")],C.prototype,"directConnection");R([T("object")],C.prototype,"webModel");R([T("object")],C.prototype,"requestBodyLimits");R([T("function")],C.prototype,"requestInterceptor");R([T("function")],C.prototype,"responseInterceptor");R([T("function")],C.prototype,"validateInput");R([T("function")],C.prototype,"loadHistory");R([T("object")],C.prototype,"chatStyle");R([T("object")],C.prototype,"attachmentContainerStyle");R([T("object")],C.prototype,"dropupStyles");R([T("object")],C.prototype,"inputAreaStyle");R([T("object")],C.prototype,"textInput");R([T("object")],C.prototype,"submitButtonStyles");R([T("object")],C.prototype,"customButtons");R([T("string")],C.prototype,"auxiliaryStyle");R([T("array")],C.prototype,"history");R([T("object")],C.prototype,"browserStorage");R([T("object")],C.prototype,"introMessage");R([T("object")],C.prototype,"avatars");R([T("object")],C.prototype,"names");R([T("object")],C.prototype,"displayLoadingBubble");R([T("object")],C.prototype,"errorMessages");R([T("object")],C.prototype,"messageStyles");R([T("object")],C.prototype,"textToSpeech");R([T("object")],C.prototype,"speechToText");R([T("object")],C.prototype,"images");R([T("object")],C.prototype,"gifs");R([T("object")],C.prototype,"camera");R([T("object")],C.prototype,"audio");R([T("object")],C.prototype,"microphone");R([T("object")],C.prototype,"mixedFiles");R([T("object")],C.prototype,"dragAndDrop");R([T("object")],C.prototype,"introPanelStyle");R([T("object")],C.prototype,"htmlWrappers");R([T("object")],C.prototype,"htmlClassUtilities");R([T("object")],C.prototype,"remarkable");R([T("object")],C.prototype,"focusMode");R([T("function")],C.prototype,"onMessage");R([T("function")],C.prototype,"onClearMessages");R([T("function")],C.prototype,"onComponentRender");R([T("function")],C.prototype,"onInput");R([T("function")],C.prototype,"onError");R([T("object")],C.prototype,"demo");R([T("object")],C.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",C);export{C as DeepChat};
|