deep-chat-dev 9.0.307 → 9.0.309
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 +12754 -12778
- package/dist/deepChat.bundle.js +1 -1
- package/dist/deepChat.js +80 -83
- package/dist/services/openAI/openAIChatIO.d.ts.map +1 -1
- package/dist/views/chat/messages/messages.d.ts.map +1 -1
- package/dist/views/chat/messages/messagesBase.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/deepChat.js
CHANGED
@@ -3,7 +3,7 @@ function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Sym
|
|
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 ds=Ot;var
|
6
|
+
overflow:"hidden"};var ds=Ot;var F="service",y="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({},y,e):_defineProperty(_defineProperty(_defineProperty({},y,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 ms=/*#__PURE__*/_createClass(function ms(){_classCallCheck(this,ms);});ms.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),ms.IS_CHROMIUM=window.chrome,ms.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var Ye=ms;var Y=/* @__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;}(Y||{});var mt=/*#__PURE__*/function(){function mt(){_classCallCheck(this,mt);}return _createClass(mt,null,[{key:"add",value:// prettier-ignore
|
7
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
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),Is.focusEndOfInput(i)),t==null||t();}}]);}();mt.PERMITTED_KEYS=/* @__PURE__ */new Set([Y.BACKSPACE,Y.DELETE,Y.ARROW_RIGHT,Y.ARROW_LEFT,Y.ARROW_DOWN,Y.ARROW_UP,Y.META,Y.CONTROL,Y.ENTER]);var Ni=mt;var Nr=/*#__PURE__*/function(){function Nr(){_classCallCheck(this,Nr);}return _createClass(Nr,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var s,i;e.preventDefault();var t=(s=e.clipboardData)==null?void 0:s.getData("text/plain");t&&((i=document.execCommand)==null||i.call(document,"insertText",!1,t));}}]);}();var 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(){Ni.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
|
@@ -15,16 +15,16 @@ function clear(){var t,s;var e=window.scrollY;this.inputElementRef.classList.con
|
|
15
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 js=gt;var Is=/*#__PURE__*/function(){function Is(){_classCallCheck(this,Is);}return _createClass(Is,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(js.TEXT_INPUT_ID));t&&(Ye.IS_SAFARI&&t.focus(),Is.focusEndOfInput(t));}}]);}();function Cn(r){return r.charAt(0).toUpperCase()+r.slice(1);}function Pr(r){return r&&JSON.stringify(r);}function tn(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(Pr(s)," \n"):"";return i+n;}function Dr(r,e,t,s){return"".concat(tn(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 Br(r,e,t){var s="response";return"".concat(tn(r,s,e,t),"Make sure the ").concat(s," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Fr(r,e){var t="request";return"".concat(tn(r,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}var wn="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",b={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",REQUEST_SETTINGS_ERROR:"Request settings have not been set up",NO_FILE_ADDED_ERROR:"No file was added",IMAGE_NOT_FOUND_ERROR:"Image was not found",INVALID_RESPONSE:Dr,INVALID_MODEL_REQUEST:Fr,INVALID_MODEL_RESPONSE:Br,INVALID_STREAM_ARRAY_RESPONSE:"Multi-response arrays are not supported for streaming",INVALID_STREAM_EVENT:wn,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(wn),READABLE_STREAM_CONNECTION_ERROR:"Readable Stream connection error.",DEFINE_FUNCTION_HANDLER:"Please define a `function_handler` property inside the service config."},ur="Authentication",K="Authorization",Ur="authorization",sn="Unauthorized",nn="Authorization header",ht="Invalid",ks="Incorrect",ie="authentication_error",we="invalid_request_error",R="Content-Type",Hr="content-type",N="application/json",T="object",je="error",fr="completed",se="Bearer ",z="GET",Z="POST",rn="Upload an audio file",yi=/*#__PURE__*/function(){function yi(){_classCallCheck(this,yi);}return _createClass(yi,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-yi.CODE_SNIPPET_GENERATION_JUMP;}},{key:"cloneElement",value:function cloneElement(e){var t=e.cloneNode(!0);return e.parentNode.replaceChild(t,e),t;}// check safari
|
16
16
|
// show only the top of the new message if there is overflow and scroll far enough not to lose user message
|
17
17
|
// can prevent further scroll in streams
|
18
|
-
},{key:"scrollToBottom",value:function scrollToBottom(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s=arguments.length>2?arguments[2]:undefined;s?e.scrollTo({left:0,top:s.offsetTop}):t?e.scrollTo({left:0,top:e.scrollHeight,behavior:"smooth"}):e.scrollTop=e.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}}]);}();yi.CODE_SNIPPET_GENERATION_JUMP=0.5;var
|
18
|
+
},{key:"scrollToBottom",value:function scrollToBottom(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var s=arguments.length>2?arguments[2]:undefined;s?e.scrollTo({left:0,top:s.offsetTop}):t?e.scrollTo({left:0,top:e.scrollHeight,behavior:"smooth"}):e.scrollTop=e.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}}]);}();yi.CODE_SNIPPET_GENERATION_JUMP=0.5;var B=yi;var bi=/*#__PURE__*/function(){function bi(){_classCallCheck(this,bi);}return _createClass(bi,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);},bi.LOAD_VOICES_MS);}}]);}();bi.LOAD_VOICES_MS=200;var Bt=bi;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
|
19
19
|
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
|
20
|
-
},{key:"addMessage",value:function addMessage(e,t,s,i,n,o){Se.setElementProps(e,t,s,i),n||(e.appendOuterContainerElemet(t.outerContainer),!e.focusMode&&o&&
|
20
|
+
},{key:"addMessage",value:function addMessage(e,t,s,i,n,o){Se.setElementProps(e,t,s,i),n||(e.appendOuterContainerElemet(t.outerContainer),!e.focusMode&&o&&B.scrollToBottom(e.elementRef,!1,t.outerContainer));}},{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,t){setTimeout(function(){B.scrollToBottom(e,!1,t);},60);}},{key:"scrollDownOnImageLoad",value:function scrollDownOnImageLoad(e,t,s){if(e.startsWith("data"))Se.waitToLoadThenScroll(s,t);else try{fetch(e,{mode:"no-cors"})["catch"](function(){})["finally"](function(){Se.waitToLoadThenScroll(s,t);});}catch(_unused2){B.scrollToBottom(t,!1,s);}}// The strategy is to emit the actual file reference in the `onMessage` event for the user to inspect it
|
21
21
|
// But it is not actually used by anything in the chat, hence it is removed when adding a message
|
22
22
|
// after the body has been stringified and parsed - the file reference will disappear, hence this readds it
|
23
23
|
},{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
|
24
24
|
},{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 ee=Se;var te=/*#__PURE__*/function(){function te(){_classCallCheck(this,te);}return _createClass(te,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
|
25
25
|
},{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({},y,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
|
26
26
|
},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==T)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;}},{key:"processFocusMode",value:function processFocusMode(e){return!e||typeof e=="boolean"||e.scroll&&(console.error("The scroll property in focusMode has been changed to smoothScroll since version 2.3.0."),console.error("Check it out here: https://deepchat.dev/docs/modes#focusMode"),e.smoothScroll=!0),e;}}]);}();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 jr="deep-chat-temporary-message",qr="deep-chat-suggestion-button",Pi={"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(Pi);var De=/*#__PURE__*/function(){function De(){_classCallCheck(this,De);}return _createClass(De,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({},y,((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(jr):!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=Pi[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=Pi[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=De.getProcessedStyles(t,a,n);le.applyStylesToElement(a,l),De.applyEvents(a,n);});});var i=s.getElementsByClassName(qr);Array.from(i).forEach(function(n){return De.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&&!De.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){De.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,De.isElementTemporary({outerContainer:t,bubbleElement:t,innerContainer:t});}// useful for removing event listeners
|
27
|
-
},{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 le=Te;var Ke=/*#__PURE__*/function(){function Ke(){_classCallCheck(this,Ke);}return _createClass(Ke,null,[{key:"addElement",value:function addElement(e,t,s){var i=
|
27
|
+
},{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 le=Te;var Ke=/*#__PURE__*/function(){function Ke(){_classCallCheck(this,Ke);}return _createClass(Ke,null,[{key:"addElement",value:function addElement(e,t,s){var i=B.isScrollbarAtBottomOfElement(e.elementRef);e.appendOuterContainerElemet(t),!e.focusMode&&s&&i&&B.scrollToBottom(e.elementRef,!1,t);}},{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 _le$tryAddWrapper=le.tryAddWrapper(o.bubbleElement,t,e._customWrappers,s),a=_le$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,s){s.bubbleElement.innerHTML=t,le.apply(e,s.outerContainer),te.flagHTMLUpdateClass(s.bubbleElement);}// prettier-ignore
|
28
28
|
},{key:"overwrite",value:function overwrite(e,t,s,i){var n=e.messageToElements,o=v.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 v.fillEmptyMessageElement(n.bubbleElement,t),le.apply(e,n.outerContainer),te.flagHTMLUpdateClass(n.bubbleElement),e.applyCustomStyles(n,s,!1,(o=e.messageStyles)==null?void 0:o.html),n;}// prettier-ignore
|
29
29
|
},{key:"add",value:function add(e,t,s,i,n){var o=arguments.length>5&&arguments[5]!==undefined?arguments[5]:!1;if(n!=null&&n.status){var l=this.overwrite(e,t,s,e.messageElementRefs);if(l)return l;n.status=!1;}if(o&&e.messageElementRefs.length>0&&le.isTemporaryBasedOnHTML(t))return;var a=Ke.create(e,t,s,o);return o||Ke.addElement(e,a.outerContainer,i),a;}}]);}();Ke.HTML_BUBBLE_CLASS="html-message";var Be=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(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 E=u.src.charAt(p);if(E!==a)return!1;var I=p;p=u.skipChars(p,E);var P=p-I;if(P!==2)return!1;var D=h;for(;++D,!(D>=f||(p=I=u.bMarks[D]+u.tShift[D],g=u.eMarks[D],p<g&&u.tShift[D]<u.blkIndent));)if(u.src.charAt(p)===a&&!(u.tShift[D]-u.blkIndent>=4)&&(p=u.skipChars(p,E),!(p-I<P)&&(p=u.skipSpaces(p),!(p<g)))){m=!0;break;}P=u.tShift[h],u.line=D+(m?1:0);var ne=u.getLines(h+1,D,P,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:ne,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 E=p;var I=0;for(;p<m;){var P=u.src.charAt(p);if(P==="{"&&(p===0||u.src.charAt(p-1)!=="\\"))I+=1;else if(P==="}"&&(p===0||u.src.charAt(p-1)!=="\\")){if(I-=1,I<0)return!1;}else if(P===a&&I===0){var D=p;var ne=p+1;for(;ne<m&&u.src.charAt(ne)===a;)++ne;if(ne-D===g.length){if(!h){var st=u.src.slice(E,D).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:st,block:g.length>1,level:u.level});}return u.pos=ne,!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 Ns;function pr(r){return Ns=Ns||document.createElement("textarea"),Ns.innerHTML="&"+r+";",Ns.value;}var Gr=Object.prototype.hasOwnProperty;function Kr(r,e){return r?Gr.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 zr=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Es(r){return r.indexOf("\\")<0?r:r.replace(zr,"$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 Di(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))?Di(t):r;}function At(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 _={};_.blockquote_open=function(){return"<blockquote>\n";};_.blockquote_close=function(r,e){return"</blockquote>"+Tt(r,e);};_.code=function(r,e){return r[e].block?"<pre><code>"+pe(r[e].content)+"</code></pre>"+Tt(r,e):"<code>"+pe(r[e].content)+"</code>";};_.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(" "),Kr(i.rules.fence_custom,c[0]))return i.rules.fence_custom[c[0]](r,e,t,s,i);l=pe(At(Es(d))),o=' class="'+a+l+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[n.content].concat(c))||pe(n.content):u=pe(n.content),"<pre><code"+o+">"+u+"</code></pre>"+Tt(r,e);};_.fence_custom={};_.heading_open=function(r,e){return"<h"+r[e].hLevel+">";};_.heading_close=function(r,e){return"</h"+r[e].hLevel+">\n";};_.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+Tt(r,e);};_.bullet_list_open=function(){return"<ul>\n";};_.bullet_list_close=function(r,e){return"</ul>"+Tt(r,e);};_.list_item_open=function(){return"<li>";};_.list_item_close=function(){return"</li>\n";};_.ordered_list_open=function(r,e){var t=r[e],s=t.order>1?' start="'+t.order+'"':"";return"<ol"+s+">\n";};_.ordered_list_close=function(r,e){return"</ol>"+Tt(r,e);};_.paragraph_open=function(r,e){return r[e].tight?"":"<p>";};_.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?Tt(r,e):"");};_.link_open=function(r,e,t){var s=r[e].title?' title="'+pe(At(r[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+pe(r[e].href)+'"'+s+i+">";};_.link_close=function(){return"</a>";};_.image=function(r,e,t){var s=' src="'+pe(r[e].src)+'"',i=r[e].title?' title="'+pe(At(r[e].title))+'"':"",n=' alt="'+(r[e].alt?pe(At(Es(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+s+n+i+o+">";};_.table_open=function(){return"<table>\n";};_.table_close=function(){return"</table>\n";};_.thead_open=function(){return"<thead>\n";};_.thead_close=function(){return"</thead>\n";};_.tbody_open=function(){return"<tbody>\n";};_.tbody_close=function(){return"</tbody>\n";};_.tr_open=function(){return"<tr>";};_.tr_close=function(){return"</tr>\n";};_.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};_.th_close=function(){return"</th>";};_.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};_.td_close=function(){return"</td>";};_.strong_open=function(){return"<strong>";};_.strong_close=function(){return"</strong>";};_.em_open=function(){return"<em>";};_.em_close=function(){return"</em>";};_.del_open=function(){return"<del>";};_.del_close=function(){return"</del>";};_.ins_open=function(){return"<ins>";};_.ins_close=function(){return"</ins>";};_.mark_open=function(){return"<mark>";};_.mark_close=function(){return"</mark>";};_.sub=function(r,e){return"<sub>"+pe(r[e].content)+"</sub>";};_.sup=function(r,e){return"<sup>"+pe(r[e].content)+"</sup>";};_.hardbreak=function(r,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};_.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};_.text=function(r,e){return pe(r[e].content);};_.htmlblock=function(r,e){return r[e].content;};_.htmltag=function(r,e){return r[e].content;};_.abbr_open=function(r,e){return'<abbr title="'+pe(At(r[e].title))+'">';};_.abbr_close=function(){return"</abbr>";};_.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>";};_.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";};_.footnote_block_close=function(){return"</ol>\n</section>\n";};_.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};_.footnote_close=function(){return"</li>\n";};_.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>';};_.dl_open=function(){return"<dl>\n";};_.dt_open=function(){return"<dt>";};_.dd_open=function(){return"<dd>";};_.dl_close=function(){return"</dl>\n";};_.dt_close=function(){return"</dt>\n";};_.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 Tt=_.getBreak=function(e,t){return t=yr(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function on(){this.rules=mr({},_),this.getBreak=_.getBreak;}on.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;};on.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 Rt(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;}Rt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};Rt.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level;};Rt.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e;};Rt.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0;};function Ss(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 Rt(r,e,t,s,[]),n=Ss(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 Bi(r){var e=At(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=Bi(Es(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=Es(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=Es(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,u,h;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(i=new Rt(r,e,t,s,[]),n=Ss(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)?(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=_r(r.slice(1,n)),_typeof(s.references[h])>"u"&&(s.references[h]={title:u,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,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 Rn=" \n()[]'\".,!?-";function Ii(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function ao(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="(^|["+Rn.split("").map(Ii).join("")+"])("+Object.keys(r.env.abbreviations).map(function(m){return m.substr(1);}).sort(function(m,p){return p.length-m.length;}).map(Ii).join("|")+")($|["+Rn.split("").map(Ii).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 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()\[\]]/,In="’";function kn(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,u,h,f,m,p,g,E;if(r.options.typographer){for(E=[],p=r.tokens.length-1;p>=0;p--)if(r.tokens[p].type==="inline"){for(g=r.tokens[p].children,E.length=0,e=0;e<g.length;e++)if(t=g[e],!(t.type!=="text"||po.test(t.text))){for(a=g[e].level,f=E.length-1;f>=0&&!(E[f].level<=a);f--);E.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=!kn(s,i.index-1),n=i.index+1,m=i[0]==="'",c=!kn(s,n),!c&&!l){m&&(t.content=kt(t.content,i.index,In));continue;}if(u=!c,h=!l,h){for(f=E.length-1;f>=0&&(d=E[f],!(E[f].level<a));f--)if(d.single===m&&E[f].level===a){d=E[f],m?(g[d.token].content=kt(g[d.token].content,d.pos,r.options.quotes[2]),t.content=kt(t.content,i.index,r.options.quotes[3])):(g[d.token].content=kt(g[d.token].content,d.pos,r.options.quotes[0]),t.content=kt(t.content,i.index,r.options.quotes[1])),E.length=f;continue e;}}u?E.push({token:e,pos:i.index,single:m,level:a}):h&&m&&(t.content=kt(t.content,i.index,In));}}}}}var ki=[["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<ki.length;r++)this.ruler.push(ki[r][0],ki[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 Mt(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;}Mt.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};Mt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};Mt.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};Mt.prototype.skipChars=function(e,t){for(var s=this.src.length;e<s&&this.src.charCodeAt(e)===t;e++);return e;};Mt.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;};Mt.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],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 vo(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 _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 On(r,e){var t,s=r.bMarks[e]+r.tShift[e],i=r.eMarks[e];if(s+1>=i||(t=r.src.charCodeAt(s++),t<48||t>57))return-1;for(;;){if(s>=i)return-1;if(t=r.src.charCodeAt(s++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return s<i&&r.src.charCodeAt(s)!==32?-1:s;}function 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,u,h,f,m,p,g,E,I,P,D,ne,st=!0,it,me,An,Mi;if((u=On(r,e))>=0)g=!0;else if((u=Ln(r,e))>=0)g=!1;else return!1;if(r.level>=r.options.maxNesting)return!1;if(p=r.src.charCodeAt(u-1),s)return!0;for(I=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:D=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:D=[e,0],level:r.level++}),i=e,P=!1,it=r.parser.ruler.getRules("list");i<t&&(E=r.skipSpaces(u),h=r.eMarks[i],E>=h?f=1:f=E-u,f>4&&(f=1),f<1&&(f=1),n=u-r.bMarks[i]+f,r.tokens.push({type:"list_item_open",lines:ne=[e,0],level:r.level++}),a=r.blkIndent,l=r.tight,o=r.tShift[e],c=r.parentType,r.tShift[e]=E-r.bMarks[e],r.blkIndent=n,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||P)&&(st=!1),P=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,ne[1]=i,E=r.bMarks[e],!(i>=t||r.isEmpty(i)||r.tShift[i]<r.blkIndent));){for(Mi=!1,me=0,An=it.length;me<An;me++)if(it[me](r,i,t,!0)){Mi=!0;break;}if(Mi)break;if(g){if(u=On(r,i),u<0)break;}else if(u=Ln(r,i),u<0)break;if(p!==r.src.charCodeAt(u-1))break;}return r.tokens.push({type:g?"ordered_list_close":"bullet_list_close",level:--r.level}),D[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 Ao(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 wo=/^<([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(wo),!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 Li(r,e){var t=r.bMarks[e]+r.blkIndent,s=r.eMarks[e];return r.src.substr(t,s-t);}function Io(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=Li(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=Li(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=Li(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 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 ko(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,u,h,f,m,p,g,E;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(E=!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)&&(E=!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=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,E&&ko(r,c),!0;}function Oo(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",Ao,["paragraph","blockquote"]],["lheading",Co],["htmlblock",Mo,["paragraph","blockquote"]],["table",Io,["paragraph"]],["deflist",Lo,["paragraph"]],["paragraph",Oo]];function an(){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()});}an.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 No=/[\n\t]/g,Po=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,Do=/\u00a0/g;an.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(No,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 Mt(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 ln=[];for(var Nn=0;Nn<256;Nn++)ln.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){ln[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&&ln[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 jo(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 qo(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 Go(r,e){var t,s,i,n=r.posMax,o=r.pos,a,l;if(r.src.charCodeAt(o)!==61||e||o+4>=n||r.src.charCodeAt(o+1)!==61||r.level>=r.options.maxNesting||(a=o>0?r.src.charCodeAt(o-1):-1,l=r.src.charCodeAt(o+2),a===61)||l===61||l===32||l===10)return!1;for(s=o+2;s<n&&r.src.charCodeAt(s)===61;)s++;if(s!==o+2)return r.pos+=s-o,e||(r.pending+=r.src.slice(o,s)),!0;for(r.pos=o+2,i=1;r.pos+1<n;){if(r.src.charCodeAt(r.pos)===61&&r.src.charCodeAt(r.pos+1)===61&&(a=r.src.charCodeAt(r.pos-1),l=r.pos+2<n?r.src.charCodeAt(r.pos+2):-1,l!==61&&a!==61&&(a!==32&&a!==10?i--:l!==32&&l!==10&&i++,i<=0))){t=!0;break;}r.parser.skipToken(r);}return t?(r.posMax=r.pos,r.pos=o+2,e||(r.push({type:"mark_open",level:r.level++}),r.parser.tokenize(r),r.push({type:"mark_close",level:--r.level})),r.pos=r.posMax+2,r.posMax=n,!0):(r.pos=o,!1);}function 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 Ko(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=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)===u){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 zo=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/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(zo,"$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,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=Ss(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,br(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&&vr(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=Ss(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=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 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=Ss(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=Bi(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=Bi("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 Si(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=Si(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",na)("single_quoted",ra)("double_quoted",oa)(),la=Si(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",ia)("attr_value",aa)(),ca=Si(/<[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=Si(/^(?: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)?Di(s):Di(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 Oi=[["text",Fo],["newline",Uo],["escape",Ho],["backticks",jo],["del",qo],["ins",Vo],["mark",Go],["emphasis",Ko],["sub",Jo],["sup",Wo],["links",Xo],["footnote_inline",Yo],["footnote_ref",Zo],["autolink",sa],["htmltag",ya],["entity",_a]];function xi(){this.ruler=new _e();for(var r=0;r<Oi.length;r++)this.ruler.push(Oi[r][0],Oi[r][1]);this.validateLink=Ea;}xi.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);};xi.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();};xi.prototype.parse=function(r,e,t,s){var i=new Rt(r,this,e,t,s);this.tokenize(i);};function Ea(r){var e=["vbscript","javascript","file","data"],t=r.trim().toLowerCase();return t=At(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var Sa={options:{html:!1,// Enable HTML tags in source
|
30
30
|
xhtmlOut:!1,// Use '/' to close single tags (<br />)
|
@@ -79,14 +79,14 @@ typographer:!0// Enable smartypants and other sweet transforms
|
|
79
79
|
};var xs=yt;var wa=/*#__PURE__*/function(){function wa(e){_classCallCheck(this,wa);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(wa,[{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===v.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
|
80
80
|
},{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
|
81
81
|
},{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 Ct=/*#__PURE__*/function(){function Ct(){_classCallCheck(this,Ct);}return _createClass(Ct,null,[{key:"onMessage",value:function onMessage(e,t,s){var n;var i=JSON.parse(JSON.stringify({message:t,isHistory:s,isInitial:s}));ee.reAddFileRefToObject(t,i.message),(n=e.onMessage)==null||n.call(e,i),e.dispatchEvent(new CustomEvent("message",{detail:i})),te.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&&ee.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 X=/*#__PURE__*/function(){function X(){_classCallCheck(this,X);}return _createClass(X,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,u,h,f;e.bubbleElement.classList.add(X.CLASS);var i=s?X.FULL_VIEW_CLASS:X.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;X.apply(t,e,n),t.elementRef.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",v.AI_ROLE),s=t.bubbleElement,i=X.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?Be.createElements(e,s,v.AI_ROLE,!0,!0):X.createDefaultElements(e);return X.addLoadHistoryMessage(i,e,t),v.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(X.FULL_VIEW_CLASS)){t.outerContainer.classList.replace(X.FULL_VIEW_CLASS,X.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&&X.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];X.tryChangeViewToSmall(e,t)||X.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();X.CLASS="loading-history-message",X.FULL_VIEW_CLASS="loading-history-message-full-view",X.SMALL_CLASS="loading-history-message-small";var Ze=X;var gs=/*#__PURE__*/function(){function gs(){_classCallCheck(this,gs);}return _createClass(gs,null,[{key:"setFade",value:function setFade(e,t){e.style.transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(gs.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:gs.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;}()}]);}();gs.DEFAULT_FADE_MS=500;var qs=gs;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",Fi="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAMAAAC/MqoPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAADNQTFRF////9vX18vLy/Pz86enp4+Li2tnZ1tbWzczM+fn57Ozs4N/f09LS0M/P5uXl7+/v3dzcwtncCAAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAZNSURBVHja7d3bdtsqEABQYABZSLH9/3+ZpnUsIcF5iOM6PfElNoMHMfPQdq3GmL0GkLhEUqLaUExnOtOZznSmM53pTGc605nOdKYznelMZzrTmV4LXSqllKyJDkob26xWq8Zae/iH0QoWTm9d1xur4WuypQJtTd+5dqn0VjcxzNO5/57mEBvdLo8Oron6aseWOjYOFkVvjQs3DmgyONMuht52EfztP+4hdu0i6LCO808/M8c1lE/fuPGej41uUzgdtoO/75N+2ELJ9I3b3//hPXbiMenm3pR/Jt4USgcLBIp4Bh10gqKVhvLo0klCxeSky96nKcj3siw6pJIL4XsoiQ7apyvMY/V3HHrSRioLopvEhSpTCn2TPEuwKYMOIX0tAxRBf/Hpa+lfSqBv9gi1FPsNfTrMAiVmIE/vJhz61FGnQxRIEYE4vfNYdN8Rp6MlHaHotHTn8ejekaZPAjEmyvQWdZFTtYTpXqCGJ0zvcek9Yfoel76nS0ffv1NMp1ca+pkgyfRCGind4L7OWWc605l+cxjsyhqy9AGbPpClc1/nvl5VX0c/3Alk6RU3+Am7shNZ+h6bvidLr7jBB+zKBrL0irOOudmIUDzTmf5gIP+iEuXtRuTVaEmY/oZLfyNMrzjryPc0gerMTdpVg0tvjJUU6bLPcGOoUv46SLL6Wi8yhLf06C7TUyekI0efRaaYqdFltkeNpPumRPSMDxgBYvSM035FrKAmH72hRW99PrpvSdEHkTEGUvSsK3yKVDkuJ92RohcZaehzzirPpOg+J92Tolfc4Cumx5xVXpGiZ34+ICX6W84qv5GiR5NPbiIpOv6BCoSvSkTX+eiaGP092zINvBOj4x8mSf9FqejvNo/cvpOji19ZbmviL0GPLsYMFzgzCor0+Bv/ePDvSJKOb9dJ5UlnbnEHiHgzv6cdTpJOWuc/u3FEucLDOL75xGtBiefrcwgoC9NDSH/jkH6pAuXmBqPQ9HSUPVdZBH1GGOrMXAQdYxcKZfxAoK+KKBKFLosoEoX+u4giUehz8jlcnAuhp78I46yDYNAd+QLR6K+pr+yvxdBTHyVDubQh0UfSxaHSd0lbvNkVRE87JGOtc+PQd2QLQ6fHhJkKsSh6yg13tO08JPprsgrrXWH0dJd2vH1MLPprot4eXoujpzrdhngiD40ek2y92lggPcnWa8qN1Yz0BFuvZhRl0uOfR0v4Ewuli/Bg4Qr3lArqGdndQ3UPO1EunXYwnelMZzrTmc50pjOd6UxnOtOZznSmM53pTGf6kuj6oedFKV0s3fX6sX1S3bsi6a4PD7+/YAqYeBw6pIB/4qEgOqxdSPbGiim4NRRCbzs3Jj0L4UfXtQXQVRfn5IdA/Bw7RZzurEV6EtdsLeGXkIPuA+K1UoVeA0l62zmN/LqfSSft9KkepmoRuvi3nd5uKNFB9zbbXEANqdr941XO0NJx2v2jdJenpf+/3bvn0ts16ph+sd6hX7dPo2+2cZzE02Ia43bzDHqr+2Evnhz74ZHU30ffbKOeng1/NPV30Ns1gYQnSP2P6e65Pfxc6h02XZqXQCjhJ6kPL6bFo4NrGvAU4UII4SE2P1vQuZkuOxckVfehisF1MjUddN/MZBN+kvq5uf0O/xa66gyNS9ktMWlz44rO1Z8C19i5FPdHzPamXn+F3hryPfxMr78+4F+kq22kO6Rf6fUQt+puuustyWv4rbG3l/duztFB96GYoe1cTBdXMr+nw9qVM6ZfxOvzezff0nXi/ZOndvrR6Zvpm0c3h6nhdb+5iS7tsIim/qXZD9+97/Jf+rpZ5BET1ayv0GUzLhEuhBBjIy/RdVPgndutIRt9nt7p5cKFEEJ3Z+jQFDZL+XnMDXxHB73gxn5s9Kc3d3/pFciFkN/QTSXHJpX5l66gDrkQoP6hL3xsPw39la4qOiV8tH78XeSbue6N9mvWa6J/ybpc1CT1Wnh5Qq9meP8IOKH3ddH7E/ri1iYux/SXDrXR4UiPdck/wUpU+FtPf6/orja6O9KL3l56LOvVxe5Ib2qjN0d6Vbex4ghWlU3bPqI90If66MNng680FNpbJijH6kCvaF3uMzQ3+IrpFerV4Y9dffQdN3im10ivbuImhD3Qq5u4HdZkua8znelMZ/pS4z9CPVKkxowNxgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wMy0yN1QxNTo0NToxNSswMDowMN1xSg4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDMtMjdUMTU6NDU6MTUrMDA6MDCsLPKyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAABJRU5ErkJggg==";var Ar=/*#__PURE__*/function(){function Ar(e){_classCallCheck(this,Ar);this.className=e;}return _createClass(Ar,[{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 Ve=/*#__PURE__*/function(_Ar){function Ve(e){var _this3;_classCallCheck(this,Ve);_this3=_callSuper(this,Ve,["avatar-container"]),_this3._avatars=e;return _this3;}_inherits(Ve,_Ar);return _createClass(Ve,[{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===v.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)||Fi,s.onerror=Ve.errorFallback.bind(this,Fi)):(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=Ve.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&&Ve.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!==v.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===v.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&&Ve.applyCustomStylesToElements(e,t,s["default"].styles),i===v.USER_ROLE)(o=s.user)!=null&&o.styles&&Ve.applyCustomStylesToElements(e,t,s.user.styles);else{(a=s.ai)!=null&&a.styles&&Ve.applyCustomStylesToElements(e,t,s.ai.styles);var c=(l=s[i])==null?void 0:l.styles;c&&Ve.applyCustomStylesToElements(e,t,c);}}}]);}(Ar);var hs=/*#__PURE__*/function(_Ar2){function hs(e){var _this4;_classCallCheck(this,hs);_this4=_callSuper(this,hs,["name"]),_this4._names=e;return _this4;}_inherits(hs,_Ar2);return _createClass(hs,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var s=typeof this._names=="boolean"?{}:this._names,i=this.createName(t,s),n=hs.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=hs.getNameText(e,t),hs.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!==v.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===v.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===v.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===v.USER_ROLE?((s=t.user)==null?void 0:s.text)||((i=t["default"])==null?void 0:i.text)||"User":e===v.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;}}]);}(Ar);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=te.processMessageStyles(e.messageStyles),this._remarkable=xs.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new Ve(e.avatars)),e.names&&(this.name=new hs(e.names)),e.browserStorage&&(this.browserStorage=new wa(e.browserStorage)),this._onMessage=Ct.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),this.focusMode=te.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=document.createElement("div")),typeof this.focusMode!="boolean"&&(s=this.focusMode)!=null&&s.fade&&qs.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||te.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),v.fillEmptyMessageElement(n.bubbleElement,e),n;}// prettier-ignore
|
82
|
-
},{key:"overwriteText",value:function overwriteText(e,t,s){var i=v.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.smoothScroll);
|
82
|
+
},{key:"overwriteText",value:function overwriteText(e,t,s){var i=v.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 _this6=this;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.smoothScroll);n?setTimeout(function(){B.scrollToBottom(_this6.elementRef,n);}):B.scrollToBottom(this.elementRef);}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 _this7=this;var s=this.createNewMessageElement(e,t),i=B.isScrollbarAtBottomOfElement(this.elementRef);return this.appendOuterContainerElemet(s.outerContainer),setTimeout(function(){t==="user"?B.scrollToBottom(_this7.elementRef):i&&B.scrollToBottom(_this7.elementRef,!1,s.outerContainer);}),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:
|
83
83
|
// https://github.com/OvidijusParsiunas/deep-chat/issues/258
|
84
84
|
// prettier-ignore
|
85
85
|
},{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&De.isElementTemporary(e)){var s=this.messageElementRefs[this.messageElementRefs.length-2];s&&this.messageToElements.length>0&&!e.bubbleElement.classList.contains(v.getRoleClass(t))&&v.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 v.updateRefArr(this.messageElementRefs,i,s),v.classifyRoleMessages(this.messageElementRefs,t),i;}},{key:"addInnerContainerElements",value:// prettier-ignore
|
86
86
|
function addInnerContainerElements(e,t,s){var i=this.messageElementRefs[this.messageElementRefs.length-1];return v.areOuterContainerClassRolesSame(s,i)&&!this.isLastMessageError()&&v.hideRoleElements(i.innerContainer,this.avatar,this.name),e.classList.add("message-bubble",v.getRoleClass(s),s===v.USER_ROLE?"user-message-text":"ai-message-text"),this.renderText(e,t,s),v.addRoleElements(e,s,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
|
87
87
|
},{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=v.getLastMessageBubbleElement(this.elementRef))==null?void 0:e.classList.contains(v.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
|
88
88
|
},{key:"renderText",value:function renderText(e,t,s){var _le$tryAddWrapper2=le.tryAddWrapper(e,t,this._customWrappers,s),i=_le$tryAddWrapper2.contentEl,n=_le$tryAddWrapper2.wrapper;n&&le.apply(this,e),i.innerHTML=this._remarkable.render(t),this._applyHTMLToRemarkable&&le.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
|
89
|
-
},{key:"refreshTextMessages",value:function refreshTextMessages(e){var
|
89
|
+
},{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this8=this;this._remarkable=xs.createNew(e),this.messageToElements.forEach(function(t){t[1].text&&t[0].text&&_this8.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)||De.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(v.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||v.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 Ae=ue;var x=/*#__PURE__*/function(){function x(){_classCallCheck(this,x);}return _createClass(x,null,[{key:"getLastElementsByClass",value:function getLastElementsByClass(e,t,s){var _loop=function _loop(){var n=e[i];if(n.bubbleElement.classList.contains(t[0])&&!t.slice(1).find(function(a){return!n.bubbleElement.classList.contains(a);}))if(s){if(!s.find(function(l){return n.bubbleElement.classList.contains(l);}))return{v:n};}else return{v:n};},_ret;for(var i=e.length-1;i>=0;i-=1){_ret=_loop();if(_ret)return _ret.v;}}},{key:"getLastMessage",value:function getLastMessage(e,t,s){for(var i=e.length-1;i>=0;i-=1)if(e[i][0].role===t)if(s){if(e[i][0][s])return e[i][0];}else return e[i][0];}},{key:"getLastTextToElement",value:function getLastTextToElement(e,t){for(var s=e.length-1;s>=0;s-=1)if(e[s][0]===t)return e[s];}// IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message
|
90
90
|
// and if messages have custom roles, it will still look to update the last 'ai' role message
|
91
91
|
// prettier-ignore
|
92
92
|
},{key:"overwriteMessage",value:function overwriteMessage(e,t,s,i,n,o){var a=x.getLastElementsByClass(t,[x.getRoleClass(i),o],[Xe.BUBBLE_CLASS]),l=x.getLastMessage(e,i,n);return l&&(l[n]=s),a;}},{key:"getRoleClass",value:function getRoleClass(e){return"".concat(e,"-message");}// makes sure the bubble has dimensions when there is no text
|
@@ -94,12 +94,12 @@ function addInnerContainerElements(e,t,s){var i=this.messageElementRefs[this.mes
|
|
94
94
|
},{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var s=t?x.buildRoleOuterContainerClass(t):void 0;for(var i=e.length-1;i>=0;i-=1){if(t||(s=Array.from(e[i].outerContainer.classList).find(function(u){return u.startsWith(x.OUTER_CONTAINER_CLASS_ROLE_PREFIX);})),!s)continue;var n=e[i],o=n.outerContainer.classList.contains(s),a=e[i-1],l=e[i+1],c=a==null?void 0:a.outerContainer.classList.contains(s),d=l==null?void 0:l.outerContainer.classList.contains(s);if(o)!c&&d?x.addNewPositionClasses(n,[x.POSITION_TOP_MESSAGE_CLASS]):c&&d?x.addNewPositionClasses(n,[x.POSITION_MIDDLE_MESSAGE_CLASS]):c&&!d?x.addNewPositionClasses(n,[x.POSITION_BOTTOM_MESSAGE_CLASS]):!c&&!d&&x.addNewPositionClasses(n,[x.POSITION_TOP_MESSAGE_CLASS,x.POSITION_BOTTOM_MESSAGE_CLASS]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer.classList).find(function(i){return i.startsWith(x.OUTER_CONTAINER_CLASS_ROLE_PREFIX);})===x.buildRoleOuterContainerClass(e):!1;}},{key:"resetAllRoleElements",value:function resetAllRoleElements(e,t,s){if(!t&&!s)return;var i="";e.forEach(function(n,o){n.bubbleElement.classList.contains(x.ERROR_MESSAGE_TEXT_CLASS)||x.revealRoleElements(n.innerContainer,t,s);var a=Array.from(n.outerContainer.classList).find(function(l){return l.startsWith(x.OUTER_CONTAINER_CLASS_ROLE_PREFIX);});i===a&&x.hideRoleElements(e[o-1].innerContainer,t,s),i=a;});}// this is a workaround to prevent JSON.parse(JSON.stringify()) from removing the files' 'ref' property values
|
95
95
|
// and 'custom' property value if it is not shallow copyable
|
96
96
|
// note - structuredClone can fix this but it doesn't have good legacy compatibility
|
97
|
-
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return x.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!==T)return e;if(Array.isArray(e))return e.map(function(s){return x.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)===T?t[s]=x.processMessageContent(i):t[s]=i;}),t;}}]);}();x.AI_ROLE="ai",x.USER_ROLE="user",x.ERROR_MESSAGE_TEXT_CLASS="error-message-text",x.OUTER_CONTAINER_CLASS_ROLE_PREFIX="deep-chat-outer-container-role-",x.EMPTY_MESSAGE_CLASS="empty-message",x.POSITION_TOP_MESSAGE_CLASS="deep-chat-top-message",x.POSITION_MIDDLE_MESSAGE_CLASS="deep-chat-middle-message",x.POSITION_BOTTOM_MESSAGE_CLASS="deep-chat-bottom-message";var v=x;var Ne=/*#__PURE__*/function(){function Ne(e,t){_classCallCheck(this,Ne);this.allowScroll=!0,this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialText="",this._messages=e,Ne.isFocusModeScrollAllowed(this._messages.focusMode)&&(this.allowScroll=!1),_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(Ne,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e.text)===void 0&&(e==null?void 0:e.html)===void 0)return console.error(b.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=
|
97
|
+
},{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return x.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!==T)return e;if(Array.isArray(e))return e.map(function(s){return x.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)===T?t[s]=x.processMessageContent(i):t[s]=i;}),t;}}]);}();x.AI_ROLE="ai",x.USER_ROLE="user",x.ERROR_MESSAGE_TEXT_CLASS="error-message-text",x.OUTER_CONTAINER_CLASS_ROLE_PREFIX="deep-chat-outer-container-role-",x.EMPTY_MESSAGE_CLASS="empty-message",x.POSITION_TOP_MESSAGE_CLASS="deep-chat-top-message",x.POSITION_MIDDLE_MESSAGE_CLASS="deep-chat-middle-message",x.POSITION_BOTTOM_MESSAGE_CLASS="deep-chat-bottom-message";var v=x;var Ne=/*#__PURE__*/function(){function Ne(e,t){_classCallCheck(this,Ne);this.allowScroll=!0,this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialText="",this._messages=e,Ne.isFocusModeScrollAllowed(this._messages.focusMode)&&(this.allowScroll=!1),_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(Ne,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e.text)===void 0&&(e==null?void 0:e.html)===void 0)return console.error(b.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=B.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(b.INVALID_STREAM_EVENT_MIX);this.updateBasedOnType(t,i,e==null?void 0:e.overwrite);}s&&this.allowScroll&&B.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=v.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):Be.add(this._messages,n,s,!0),this._elements&&(this._elements.bubbleElement.classList.add(Ne.MESSAGE_CLASS),this._activeMessageRole=s,this._message=_defineProperty({role:this._activeMessageRole},e,n),this._messages.messageToElements.push([this._message,_defineProperty({},e,this._elements)]),i&&this.setTargetWrapperIfNeeded(this._elements,t,this._streamType,i));}// not using existing htmlUtils htmlWrappers logic to be able to stream html
|
98
98
|
},{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,s,i){e.bubbleElement.innerHTML=i,this._targetWrapper=le.getTargetWrapper(e.bubbleElement),this._elements&&le.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||v.unfillEmptyMessageElement(i,e),(t==="text"?this.updateText:this.updateHTML).bind(this)(e,i,s);}},{key:"updateText",value:function updateText(e,t,s){this._message&&(this._message.text=s?e:this._message.text+e,this._partialRender&&this.isNewPartialRenderParagraph(t,s)&&this.partialRenderNewParagraph(t),this._partialBubble?this.partialRenderBubbleUpdate(e):this._messages.renderText(t,this._message.text));}},{key:"isNewPartialRenderParagraph",value:function isNewPartialRenderParagraph(e,t){var s;return t?(e.innerHTML="",!0):this._partialBubble?this._partialText&&this.shouldCreateNewParagraph(this._partialText):((s=this._message)==null?void 0:s.text)&&this.shouldCreateNewParagraph(this._message.text);}},{key:"shouldCreateNewParagraph",value:function shouldCreateNewParagraph(e){var t=e.indexOf(Ne.PARTIAL_RENDER_TEXT_MARK);return t===-1?!1:!e.substring(t+Ne.PARTIAL_RENDER_TEXT_MARK.length).startsWith("---");}},{key:"partialRenderNewParagraph",value:function partialRenderNewParagraph(e){this._partialText="",this._partialBubble=document.createElement("div"),this._partialBubble.classList.add("partial-render-message"),e.appendChild(this._partialBubble);}},{key:"partialRenderBubbleUpdate",value:function partialRenderBubbleUpdate(e){this._partialText+=e,this._messages.renderText(this._partialBubble,this._partialText);}},{key:"updateHTML",value:function updateHTML(e,t,s){if(this._message)if(s)this._message.html=e,t.innerHTML=e;else{var i=document.createElement("span");i.innerHTML=e,t.appendChild(i),this._message.html=(t==null?void 0:t.innerHTML)||"";}}},{key:"finaliseStreamedMessage",value:function finaliseStreamedMessage(){var e,t;if(!(this._endStreamAfterOperation||!this._message)&&!(this._fileAdded&&!this._elements)){if(!this._elements)throw Error(b.NO_VALID_STREAM_EVENTS_SENT);(e=this._elements.bubbleElement)!=null&&e.classList.contains(Ne.MESSAGE_CLASS)&&(this._streamType==="text"?this._messages.textToSpeech&&Bt.speak(this._message.text||"",this._messages.textToSpeech):this._streamType==="html"&&this._elements&&le.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement.classList.remove(Ne.MESSAGE_CLASS),this._message&&(this._messages.sendClientUpdate(Ae.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
|
99
99
|
},{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;}()}],[{key:"isFocusModeScrollAllowed",value:function isFocusModeScrollAllowed(e){return _typeof(e)=="object"&&typeof e.streamAutoScroll=="boolean"&&!e.streamAutoScroll;}}]);}();Ne.MESSAGE_CLASS="streamed-message",Ne.PARTIAL_RENDER_TEXT_MARK="\n\n";var Ue=Ne;var w=/*#__PURE__*/function(){function w(){_classCallCheck(this,w);}return _createClass(w,null,[{key:"tempRemoveContentHeader",value:// need to pass stringifyBody boolean separately as binding is throwing an error for some reason
|
100
100
|
// prettier-ignore
|
101
|
-
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(b.REQUEST_SETTINGS_ERROR);case 1:i=e.headers[R];delete e.headers[R];_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[R]=i,_t2;case 5:return _context3.a(2,(e.headers[R]=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)===T)return t instanceof Error?e.addNewErrorMessage(
|
102
|
-
},{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)||Z,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(N)?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(b.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(
|
101
|
+
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(b.REQUEST_SETTINGS_ERROR);case 1:i=e.headers[R];delete e.headers[R];_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[R]=i,_t2;case 5:return _context3.a(2,(e.headers[R]=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)===T)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
|
102
|
+
},{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)||Z,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(N)?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(b.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
|
103
103
|
},{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=b.INVALID_RESPONSE(t,"response",!!a,l);w.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 _callee182(r,e){var t,s;return _regenerator().w(function(_context182){while(1)switch(_context182.n){case 0:t=r.getReader();case 1:_context182.n=2;return t.read();case 2:if((s=_context182.v).done){_context182.n=4;break;}e(s.value);case 3:_context182.n=1;break;case 4:return _context182.a(2);}},_callee182);}));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=Ia(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 u=parseInt(d,10);isNaN(u)||e(s.retry=u);break;}}};}function Ia(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 ka=function ka(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 Ui="text/event-stream",La=1e3,Un="last-event-id";function Oa(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=ka(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(u,h){var f=Object.assign({},s);f.accept||(f.accept=Ui);var m;function p(){m.abort(),document.hidden||ne();}l||document.addEventListener("visibilitychange",p);var g=La,E=0;function I(){document.removeEventListener("visibilitychange",p),window.clearTimeout(E),m.abort();}t==null||t.addEventListener("abort",function(){I(),u();});var P=c!==null&&c!==void 0?c:window.fetch,D=i!==null&&i!==void 0?i:Na;function ne(){return _ne.apply(this,arguments);}function _ne(){_ne=_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 P(r,Object.assign(Object.assign({},d),{headers:f,signal:m.signal}));case 2:it=_context6.v;_context6.n=3;return D(it);case 3:_context6.n=4;return Ta(it.body,Ra(Ma(function(me){me?f[Un]=me:delete f[Un];},function(me){g=me;},n)));case 4:o==null||o();I();u();_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:g;window.clearTimeout(E),E=window.setTimeout(ne,me);}catch(me){I(),h(me);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _ne.apply(this,arguments);}ne();});}function Na(r){var e=r.headers.get("content-type");if(!(e!=null&&e.startsWith(Ui)))throw new Error("Expected content-type to be ".concat(Ui,", Actual: ").concat(e));}var M=/*#__PURE__*/function(){function M(){_classCallCheck(this,M);}return _createClass(M,null,[{key:"request",value:// prettier-ignore
|
104
104
|
function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,s){var i,n,h,f,m,p,g,o,_yield$w$processReque,a,l,c,d,u,_args7=arguments;return _regenerator().w(function(_context7){while(1)switch(_context7.n){case 0:i=_args7.length>3&&_args7[3]!==undefined?_args7[3]:!0;n=_args7.length>4&&_args7[4]!==undefined?_args7[4]:!1;o={body:t,headers:(h=e.connectSettings)==null?void 0:h.headers};_context7.n=1;return w.processRequestInterceptor(e.deepChat,o);case 1:_yield$w$processReque=_context7.v;a=_yield$w$processReque.body;l=_yield$w$processReque.headers;c=_yield$w$processReque.error;if(!c){_context7.n=2;break;}return _context7.a(2,w.onInterceptorError(s,c,e.streamHandlers.onClose));case 2:if(!((f=e.connectSettings)!=null&&f.handler)){_context7.n=3;break;}return _context7.a(2,ke.stream(e,a,s));case 3:if(!(((m=e.connectSettings)==null?void 0:m.url)===Oe.URL)){_context7.n=4;break;}return _context7.a(2,Oe.requestStream(s,e));case 4:d=new Ue(s,e.stream),u={method:((p=e.connectSettings)==null?void 0:p.method)||Z,headers:l,credentials:(g=e.connectSettings)==null?void 0:g.credentials,body:i?JSON.stringify(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?M.handleReadableStream(e,s,d,u,n,a):M.handleEventStream(e,s,d,u,n,a),d));}},_callee7);}));function request(_x16,_x17,_x18){return _request.apply(this,arguments);}return request;}()// prettier-ignore
|
105
105
|
},{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(u){var p,g,h,f,m,_yield$h$read,E,I,P,D,ne,_t6;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(u.body){_context8.n=1;break;}throw new Error(b.READABLE_STREAM_CONNECTION_ERROR);case 1:h=u.body.getReader(),f=new TextDecoder();a();m=!1;case 2:if(!(!m&&!c)){_context8.n=8;break;}_context8.n=3;return h.read();case 3:_yield$h$read=_context8.v;E=_yield$h$read.value;I=_yield$h$read.done;if(!(m=I,m)){_context8.n=4;break;}M.handleClose(e,s,l,n);_context8.n=7;break;case 4:P=f.decode(E,{stream:!0});_context8.n=5;return(g=(p=e.deepChat).responseInterceptor)==null?void 0:g.call(p,P);case 5:_t6=_context8.v;if(_t6){_context8.n=6;break;}_t6=P;case 6:D=_t6;ne=_typeof(D)=="object"?D:_defineProperty({},y,P);M.handleMessage(e,t,s,ne,o);case 7:_context8.n=2;break;case 8:return _context8.a(2);}},_callee8);}));return function(_x19){return _ref0.apply(this,arguments);};}())["catch"](function(u){M.handleError(e,t,u);}),e.streamHandlers.onAbort=function(){s.finaliseStreamedMessage(),e.streamHandlers.onClose(),c=!0;};}// prettier-ignore
|
@@ -110,14 +110,14 @@ onopen:function onopen(u){return _asyncToGenerator(/*#__PURE__*/_regenerator().m
|
|
110
110
|
},{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,s,i){var n,_n2,o,_n3,_o2;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:_context1.n=1;return w.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 w.basicResponseProcessing(e,{files:s.files},{io:i});case 3:n=_context1.v;e.addNewMessage(_objectSpread({sendUpdate:!1},n),!1);case 4:if(s.text){t.onOpen();_n2=s.text.split(""),o=new Ue(e,i==null?void 0:i.stream);M.populateMessages(e,_n2,o,t,"text",0,i);}if(s.html){t.onOpen();_n3=le.splitHTML(s.html);_n3.length===0&&(_n3=s.html.split(""));_o2=new Ue(e,i==null?void 0:i.stream);M.populateMessages(e,_n3,_o2,t,"html",0,i);}s.error&&(w.displayError(e,s.error),t.onClose()),t.onAbort=function(){t.onClose();};case 5:return _context1.a(2);}},_callee1);}));function simulate(_x20,_x21,_x22,_x23){return _simulate.apply(this,arguments);}return simulate;}()// prettier-ignore
|
111
111
|
// io is only passed for demo to simulate a real stream
|
112
112
|
},{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 w.basicResponseProcessing(e,_defineProperty({},n,l),{io:a});case 2:d=_context10.v;M.upsertContent(e,s.upsertStreamedMessage.bind(s),s,d),e.removeError();_context10.n=4;break;case 3:_context10.p=3;_t8=_context10.v;e.isLastMessageError()||w.displayError(e,_t8);case 4:c=setTimeout(function(){M.populateMessages(e,t,s,i,n,o+1,a);},i.simulationInterim||6);i.onAbort=function(){M.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 M.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({},y,bt.generateResponse(t));}// timeout is used to simulate a timeout for a response to come back
|
113
|
-
},{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 w.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(
|
114
|
-
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var s=bt.getResponse(e);M.simulate(e,t.streamHandlers,s,t);},400);}}]);}();bt.URL="deep-chat-demo";var Oe=bt;var oe=/*#__PURE__*/function(){function oe(){_classCallCheck(this,oe);}return _createClass(oe,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(!oe.isElementPresentInDOM(e.deepChat))return;var s=e.connectSettings.websocket;if(s){if(e.connectSettings.handler)return ke.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)===T&&oe.assignListeners(e,n,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console.error(o),oe.retryConnection(e,t);};}catch(i){console.error(i),oe.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var s,i;(i=(s=e.deepChat)._validationHandler)==null||i.call(s),oe.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage(
|
115
|
-
},{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||v.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 Ue(t,e.stream),s[o].upsertStreamedMessage(i));}else M.simulate(t,e.streamHandlers,i);}}]);}();var ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,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,u,h;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(i){_context14.n=1;break;}return _context14.a(2);case 1:i=!1;_context14.n=2;return w.basicResponseProcessing(s,c,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console.error(b.INVALID_RESPONSE(c,"server",!!e.deepChat.responseInterceptor,d)),s.addNewErrorMessage(
|
116
|
-
},{key:"stream",value:function stream(e,t,s){var u,h;var i=!0,n=!1;var o=new Ue(s,e.stream),a=function a(){n||!i||(e.streamHandlers.onOpen(),n=!0);},l=function l(){i&&(ke.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 w.basicResponseProcessing(s,f,{io:e,displayError:!1});case 2:m=_context16.v;if(m)m.error?(ke.streamError(m.error,o,e,s),i=!1):M.upsertContent(s,o.upsertStreamedMessage.bind(o),o,m);else{p=b.INVALID_RESPONSE(f,"server",!!e.deepChat.responseInterceptor,m);ke.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(){ke.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1;};var d=ke.generateOptionalSignals();(h=(u=e.connectSettings).handler)==null||h.call(u,t,_objectSpread(_objectSpread({},d),{},{onOpen:a,onResponse:c,onClose:l,stopClicked:e.streamHandlers.stopClicked}));}},{key:"streamError",value:function streamError(e,t,s,i){console.error(e),t.finaliseStreamedMessage(),i.addNewErrorMessage(
|
117
|
-
},{key:"websocket",value:function websocket(e,t){var
|
113
|
+
},{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 w.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()):M.isSimulatable(e.stream,i)?M.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
|
114
|
+
},{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var s=bt.getResponse(e);M.simulate(e,t.streamHandlers,s,t);},400);}}]);}();bt.URL="deep-chat-demo";var Oe=bt;var oe=/*#__PURE__*/function(){function oe(){_classCallCheck(this,oe);}return _createClass(oe,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(!oe.isElementPresentInDOM(e.deepChat))return;var s=e.connectSettings.websocket;if(s){if(e.connectSettings.handler)return ke.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)===T&&oe.assignListeners(e,n,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console.error(o),oe.retryConnection(e,t);};}catch(i){console.error(i),oe.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var s,i;(i=(s=e.deepChat)._validationHandler)==null||i.call(s),oe.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage(F,"Connection error"),setTimeout(function(){oe.createConnection(e,t);},5e3));}},{key:"assignListeners",value:function assignListeners(e,t,s){var _this9=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 w.basicResponseProcessing(s,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(b.INVALID_RESPONSE(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!M.isSimulation(e.stream)){_context12.n=4;break;}l=oe.stream.bind(_this9,e,s,i),c=i[o.role||v.AI_ROLE];M.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;w.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)),oe.createConnection(e,s);};}},{key:"sendWebsocket",value:function(){var _sendWebsocket=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e,t,s){var i,d,u,n,o,_yield$w$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)===Oe.URL)){_context13.n=1;break;}return _context13.a(2,Oe.request(e,s));case 1:n=e.websocket;if(!(!n||n==="pending")){_context13.n=2;break;}return _context13.a(2);case 2:o={body:t,headers:(u=e.connectSettings)==null?void 0:u.headers};_context13.n=3;return w.processRequestInterceptor(e.deepChat,o);case 3:_yield$w$processReque2=_context13.v;a=_yield$w$processReque2.body;l=_yield$w$processReque2.error;if(!l){_context13.n=4;break;}return _context13.a(2,s.addNewErrorMessage(F,l));case 4:if(oe.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:oe.isWebSocket(e)?e.readyState!==void 0&&e.readyState===e.OPEN:e.isOpen:!0;}// if false then it is the internal websocket handler
|
115
|
+
},{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||v.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 Ue(t,e.stream),s[o].upsertStreamedMessage(i));}else M.simulate(t,e.streamHandlers,i);}}]);}();var ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,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,u,h;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(i){_context14.n=1;break;}return _context14.a(2);case 1:i=!1;_context14.n=2;return w.basicResponseProcessing(s,c,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console.error(b.INVALID_RESPONSE(c,"server",!!e.deepChat.responseInterceptor,d)),s.addNewErrorMessage(F,"Error in server message"),e.completionsHandlers.onFinish();else{u=Array.isArray(d)?d:[d],h=u.find(function(f){return typeof f.error=="string";});h?(console.error(h.error),s.addNewErrorMessage(F,h.error),e.completionsHandlers.onFinish()):M.isSimulatable(e.stream,d)?M.simulate(s,e.streamHandlers,d):(u.forEach(function(f){return s.addNewMessage(f);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function n(_x38){return _ref14.apply(this,arguments);};}(),o=ke.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];Ae.isLoadingMessage(s)?t.removeLastMessage():e.finaliseStreamedMessage();}catch(s){console.error(s),t.addNewErrorMessage(F,s);}}// prettier-ignore
|
116
|
+
},{key:"stream",value:function stream(e,t,s){var u,h;var i=!0,n=!1;var o=new Ue(s,e.stream),a=function a(){n||!i||(e.streamHandlers.onOpen(),n=!0);},l=function l(){i&&(ke.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 w.basicResponseProcessing(s,f,{io:e,displayError:!1});case 2:m=_context16.v;if(m)m.error?(ke.streamError(m.error,o,e,s),i=!1):M.upsertContent(s,o.upsertStreamedMessage.bind(o),o,m);else{p=b.INVALID_RESPONSE(f,"server",!!e.deepChat.responseInterceptor,m);ke.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(){ke.attemptToFinaliseStream(o,s),e.streamHandlers.onClose(),i=!1;};var d=ke.generateOptionalSignals();(h=(u=e.connectSettings).handler)==null||h.call(u,t,_objectSpread(_objectSpread({},d),{},{onOpen:a,onResponse:c,onClose:l,stopClicked:e.streamHandlers.stopClicked}));}},{key:"streamError",value:function streamError(e,t,s,i){console.error(e),t.finaliseStreamedMessage(),i.addNewErrorMessage(F,e),s.streamHandlers.onClose();}// prettier-ignore
|
117
|
+
},{key:"websocket",value:function websocket(e,t){var _this0=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 u,h,f,m,p,g;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:_context17.n=1;return w.basicResponseProcessing(t,d,{io:e,displayError:!1});case 1:u=_context17.v;if(!u)console.error(b.INVALID_RESPONSE(d,"server",!!e.deepChat.responseInterceptor,u)),t.addNewErrorMessage(F,"Error in server message");else{h=Array.isArray(u)?u:[u],f=h.find(function(m){return typeof m.error=="string";});if(f)console.error(f.error),t.isLastMessageError()||t.addNewErrorMessage(F,f.error);else if(M.isSimulation(e.stream)){m=u,p=oe.stream.bind(_this0,e,t,s.roleToStream),g=s.roleToStream[m.role||v.AI_ROLE];M.upsertContent(t,p,g,m);}else h.forEach(function(m){return t.addNewMessage(m);});}case 2:return _context17.a(2);}},_callee17);}));return function o(_x40){return _ref16.apply(this,arguments);};}(),a=ke.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 V=/*#__PURE__*/function(){function V(){_classCallCheck(this,V);}return _createClass(V,null,[{key:"request",value:// prettier-ignore
|
118
118
|
function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,s){var i,u,h,f,n,_yield$w$processReque3,o,a,l,c,d,_args19=arguments;return _regenerator().w(function(_context19){while(1)switch(_context19.n){case 0:i=_args19.length>3&&_args19[3]!==undefined?_args19[3]:!0;n={body:t,headers:(u=e.connectSettings)==null?void 0:u.headers};_context19.n=1;return w.processRequestInterceptor(e.deepChat,n);case 1:_yield$w$processReque3=_context19.v;o=_yield$w$processReque3.body;a=_yield$w$processReque3.headers;l=_yield$w$processReque3.error;c=e.completionsHandlers.onFinish;if(!l){_context19.n=2;break;}return _context19.a(2,w.onInterceptorError(s,l,c));case 2:if(!((h=e.connectSettings)!=null&&h.handler)){_context19.n=3;break;}return _context19.a(2,ke.request(e,o,s));case 3:if(!(((f=e.connectSettings)==null?void 0:f.url)===Oe.URL)){_context19.n=4;break;}return _context19.a(2,Oe.request(e,s));case 4:d=!0;w.fetch(e,a,i,o).then(function(m){return d=!!m.ok,m;}).then(function(m){return w.processResponseByType(m);}).then(/*#__PURE__*/function(){var _ref17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(m){var E,I,p,g,_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=e.deepChat).responseInterceptor)==null?void 0:I.call(E,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:g=_context18.v;if(d){_context18.n=5;break;}throw m;case 5:if(!(!g||_typeof(g)!==T&&!Array.isArray(g))){_context18.n=6;break;}throw Error(b.INVALID_RESPONSE(m,"response",!!e.deepChat.responseInterceptor,p));case 6:if(!g.error){_context18.n=7;break;}throw g.error;case 7:if(!e.asyncCallInProgress){_context18.n=8;break;}e.asyncCallInProgress=!1;return _context18.a(2);case 8:M.isSimulatable(e.stream,g)?M.simulate(s,e.streamHandlers,g):((Array.isArray(g)?g:[g]).forEach(function(D){return s.addNewMessage(D);}),c());case 9:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref17.apply(this,arguments);};}())["catch"](function(m){w.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(){V.executePollRequest(e,t,s,i);},a.timeoutMS):M.isSimulatable(e.stream,a)?M.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){w.displayError(i,o),n();});}// prettier-ignore
|
119
119
|
},{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,s){var i,f,m,p,n,_yield$w$processReque4,o,a,l,c,d,u,h,_args21=arguments;return _regenerator().w(function(_context21){while(1)switch(_context21.n){case 0:i=_args21.length>3&&_args21[3]!==undefined?_args21[3]:!0;n={body:t,headers:(f=e.connectSettings)==null?void 0:f.headers};_context21.n=1;return w.processRequestInterceptor(e.deepChat,n);case 1:_yield$w$processReque4=_context21.v;o=_yield$w$processReque4.body;a=_yield$w$processReque4.headers;l=_yield$w$processReque4.error;if(!l){_context21.n=2;break;}return _context21.a(2,w.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)||Z,u=i?JSON.stringify(o):o,h={method:d,body:u,headers:a};e.connectSettings.credentials&&(h.credentials=e.connectSettings.credentials),V.executePollRequest(e,c,h,s);case 3:return _context21.a(2);}},_callee21);}));function poll(_x46,_x47,_x48){return _poll.apply(this,arguments);}return poll;}()// prettier-ignore
|
120
|
-
},{key:"verifyKey",value:function verifyKey(e,t,s,i,n,o,a,l,c){if(e==="")return o(b.INVALID_KEY);a(),fetch(t,{method:i,headers:s,body:c||null}).then(function(d){return w.processResponseByType(d);}).then(function(d){l(d,e,n,o);})["catch"](function(d){o(b.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
|
120
|
+
},{key:"verifyKey",value:function verifyKey(e,t,s,i,n,o,a,l,c){if(e==="")return o(b.INVALID_KEY);a(),fetch(t,{method:i,headers:s,body:c||null}).then(function(d){return w.processResponseByType(d);}).then(function(d){l(d,e,n,o);})["catch"](function(d){o(b.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 _this1=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 _this1._messages.addAnyMessage(i,!0);}),setTimeout(function(){return B.scrollToBottom(_this1._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 _this10=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(Ae.INTRO_CLASS);}))==null?void 0:a.outerContainer,o=i.scrollTop;e==null||e.reverse().map(function(l){var c=_this10._messages.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!0}),!0,!0);if(c){var d=v.generateMessageBody(c,t,!0);s.unshift([c,d]);}return c;}).filter(function(l){return!!l;}).reverse().forEach(function(l){return _this10._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;v.resetAllRoleElements(i,n,o);}},{key:"setupLoadHistoryOnScroll",value:function(){var _setupLoadHistoryOnScroll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(e){var _this11=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(!(!_this11._isLoading&&!_this11._isPaginationComplete&&_this11._messages.elementRef.scrollTop===0)){_context23.n=4;break;}_this11._isLoading=!0;t=Ze.addMessage(_this11._messages,!1);_context23.p=1;_context23.n=2;return e(_this11._index++);case 2:s=_context23.v;_this11.populateMessages(t,s),_this11._isLoading=!1;_context23.n=4;break;case 3:_context23.p=3;_t11=_context23.v;_this11._messages.removeMessage(t),_this11._isPaginationComplete=!0,_this11._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 _this12=this;e.forEach(function(t){te.processHistoryFile(t),_this12._messages.addAnyMessage(t,!0);});}},{key:"loadInitialHistory",value:function(){var _loadInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(e){var _this13=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 B.scrollToBottom(_this13._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||te.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(Ae.INTRO_CLASS))s.outerContainer.style.display="";else break;}}}]);}();nt.FAILED_ERROR_MESSAGE="Failed to load history";var As=nt;var J=/*#__PURE__*/function(){function J(){_classCallCheck(this,J);}return _createClass(J,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
|
121
121
|
// if maxMessages above 0 we send that number
|
122
122
|
// if maxMessages 0 or below we send only what is in the request
|
123
123
|
},{key:"processMessages",value:function processMessages(e,t,s){return t!==void 0?t>0&&(e=J.getMaxMessages(e,t)):e=[e[e.length-1]],e=JSON.parse(JSON.stringify(e)),s===void 0?e:J.getCharacterLimitMessages(e,s);}}]);}();var W=/*#__PURE__*/function(){function W(){_classCallCheck(this,W);}return _createClass(W,null,[{key:"parseConfig",value:// prettier-ignore
|
@@ -131,9 +131,9 @@ function parseConfig(e,t,s,i){var o;var n={files:t};if(_typeof(i)=="object"){te.
|
|
131
131
|
},{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=W.parseConfig(e.connectSettings,o,t,s);}// default for direct service
|
132
132
|
},{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){W.populateDefaultFileIO(s==null?void 0:s.audio,".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),W.populateDefaultFileIO(s==null?void 0:s.images,".png,.jpg");var i=xs.createNew(e.remarkable);W.processImagesConfig(t,i,e.images,s==null?void 0:s.images),W.processCamera(t,i,e.camera,e.images),W.processGifConfig(t,i,e.gifs,s==null?void 0:s.gifs),W.processAudioConfig(t,i,e.audio,s==null?void 0:s.audio),W.processMicrophone(t,i,e.microphone,e.audio),W.processMixedFiles(t,i,e.mixedFiles);}}]);}();var wt=/*#__PURE__*/function(){function wt(e,t,s){var _a$url;_classCallCheck(this,wt);var i,n,o,a,l;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=wt.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,W.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=Oe.URL),this.connectSettings.websocket&&oe.setup(this),this.stream=((l=this.deepChat.connect)==null?void 0:l.stream)||te.checkForStream(this.deepChat),e.loadHistory&&As.addErrorPrefix(this);}return _createClass(wt,[{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&&!M.isSimulation(this.stream)?M.request(this,e,t,s):V.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$R;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[R]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$R=(a=this.connectSettings.headers)[R])!==null&&_a$R!==void 0?_a$R:a[R]=N,i=!0);_context28.n=1;return this.request(s,e);case 1:i&&((l=this.connectSettings.headers)==null||delete l[R]);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=wt.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
|
133
133
|
},{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(b.REQUEST_SETTINGS_ERROR);case 1:s=J.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!==Oe.URL)){n=_objectSpread({messages:s},this.rawBody);e.files&&(i=this.getServiceIOByType(e.files[0]))!=null&&i.connect?this.callApiWithFiles(t,s,e.files):oe.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,te.handleResponseProperty(e));case 1:if(!w.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 k=/*#__PURE__*/function(_wt){// prettier-ignore
|
134
|
-
function k(e,t,s,i,n){var
|
134
|
+
function k(e,t,s,i,n){var _this14;_classCallCheck(this,k);var o;_this14=_callSuper(this,k,[e,n]),_this14.insertKeyPlaceholderText="API Key",_this14.keyHelpUrl="",_this14.asyncCallInProgress=!1,Object.assign(_this14.rawBody,(o=e.connect)==null?void 0:o.additionalBodyProps),_this14._keyVerificationDetails=t,_this14._buildHeadersFunc=s,i&&_this14.setApiKeyProperties(i),_this14.connectSettings=_this14.buildConnectSettings(_this14.key||"",e.connect);return _this14;}_inherits(k,_wt);return _createClass(k,[{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
|
135
135
|
},{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;V.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:"callDirectServiceServiceAPI",value:function(){var _callDirectServiceServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(e,t,s,i,n){var o,a;return _regenerator().w(function(_context33){while(1)switch(_context33.n){case 0:if(this.connectSettings){_context33.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:o=s(this.rawBody,t),a=i?this.stream:!1;if(!(a&&(_typeof(a)!==T||!a.simulation)||o.stream)){_context33.n=2;break;}o.stream=!0,i!=null&&i.readable&&(this.stream={readable:!0}),M.request(this,o,e);_context33.n=4;break;case 2:_context33.n=3;return V.request(this,o,e,n);case 3:return _context33.a(2,_context33.v);case 4:return _context33.a(2);}},_callee33,this);}));function callDirectServiceServiceAPI(_x66,_x67,_x68,_x69,_x70){return _callDirectServiceServiceAPI.apply(this,arguments);}return callDirectServiceServiceAPI;}()},{key:"callToolFunction",value:function(){var _callToolFunction=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(e,t){var n,o,s,a,l,_t13,_t14;return _regenerator().w(function(_context34){while(1)switch(_context34.n){case 0:this.asyncCallInProgress=!0;_context34.n=1;return e(t);case 1:s=_context34.v;if(Array.isArray(s)){_context34.n=6;break;}if(!s.text){_context34.n=5;break;}a=_defineProperty({},y,s.text);_context34.n=2;return(o=(n=this.deepChat).responseInterceptor)==null?void 0:o.call(n,a);case 2:_t13=_context34.v;if(_t13){_context34.n=3;break;}_t13=a;case 3:l=_t13;if(!Array.isArray(l)){_context34.n=4;break;}throw Error("Function tool response interceptor cannot return an array");case 4:return _context34.a(2,{processedResponse:l});case 5:throw Error("Function tool response must be an array or contain a text property");case 6:_context34.n=7;return Promise.all(s);case 7:_t14=_context34.v;return _context34.a(2,{responses:_t14});}},_callee34,this);}));function callToolFunction(_x71,_x72){return _callToolFunction.apply(this,arguments);}return callToolFunction;}()},{key:"makeAnotherRequest",value:function makeAnotherRequest(e,t){try{return t&&(this.stream?M.request(this,e,t):V.request(this,e,t)),_defineProperty({},y,"");}catch(s){throw this.asyncCallInProgress=!1,s;}}},{key:"genereteAPIKeyName",value:function genereteAPIKeyName(e){return"".concat(e," API Key");}},{key:"extractStreamResultWToolsGeneric",value:function(){var _extractStreamResultWToolsGeneric=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(e,t,s,i,n,o){var a,l,c;return _regenerator().w(function(_context35){while(1)switch(_context35.n){case 0:a=t.delta,l=t.finish_reason;if(!(l==="tool_calls")){_context35.n=1;break;}c={tool_calls:e._streamToolCalls};return _context35.a(2,(e._streamToolCalls=void 0,this.handleToolsGeneric(c,s,i,n,o)));case 1:a!=null&&a.tool_calls&&(e._streamToolCalls?a.tool_calls.forEach(function(c,d){e._streamToolCalls&&(e._streamToolCalls[d]["function"].arguments+=c["function"].arguments);}):e._streamToolCalls=a.tool_calls);case 2:return _context35.a(2,_defineProperty({},y,(a==null?void 0:a.content)||""));}},_callee35,this);}));function extractStreamResultWToolsGeneric(_x73,_x74,_x75,_x76,_x77,_x78){return _extractStreamResultWToolsGeneric.apply(this,arguments);}return extractStreamResultWToolsGeneric;}()},{key:"handleToolsGeneric",value:function(){var _handleToolsGeneric=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(e,t,s,i,n){var o,a,_yield$this$callToolF,l,c;return _regenerator().w(function(_context36){while(1)switch(_context36.n){case 0:if(!(!e.tool_calls||!i||!t)){_context36.n=1;break;}throw Error(b.DEFINE_FUNCTION_HANDLER);case 1:o=JSON.parse(JSON.stringify(i));a=e.tool_calls.map(function(d){return{name:d["function"].name,arguments:d["function"].arguments};});_context36.n=2;return this.callToolFunction(t,a);case 2:_yield$this$callToolF=_context36.v;l=_yield$this$callToolF.responses;c=_yield$this$callToolF.processedResponse;if(!c){_context36.n=3;break;}return _context36.a(2,c);case 3:if(!(n&&(o.messages=o.messages.slice(o.messages.length-1),n.message&&o.messages.unshift({role:"system",content:n.message})),o.messages.push({tool_calls:e.tool_calls,role:"assistant",content:null}),!l.find(function(_ref24){var d=_ref24.response;return typeof d!="string";})&&a.length===l.length)){_context36.n=4;break;}return _context36.a(2,(l.forEach(function(d,u){var f;var h=(f=e.tool_calls)==null?void 0:f[u];o==null||o.messages.push({role:"tool",tool_call_id:h==null?void 0:h.id,name:h==null?void 0:h["function"].name,content:d.response});}),this.makeAnotherRequest(o,s)));case 4:throw Error("Function tool response must be an array or contain a text property");case 5:return _context36.a(2);}},_callee36,this);}));function handleToolsGeneric(_x79,_x80,_x81,_x82,_x83){return _handleToolsGeneric.apply(this,arguments);}return handleToolsGeneric;}()}],[{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:"getTextWImagesContent",value:function getTextWImagesContent(e){if(e.files&&e.files.length>0){var t=this.getImageContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},y,e.text)),t.length>0?t:e.text||"";}return e.text||"";}},{key:"getTextWFilesContent",value:function getTextWFilesContent(e,t){if(e.files&&e.files.length>0){var s=t(e.files);return e.text&&e.text.trim().length>0&&s.unshift(_defineProperty({type:"text"},y,e.text)),s;}return e.text||"";}}]);}(wt);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 ze=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
|
136
|
-
function ze(){var
|
136
|
+
function ze(){var _this15;_classCallCheck(this,ze);_this15=_callSuper(this,ze),_this15._waitingToRender_=!1,_this15._propUpdated_=!1,Object.keys(ze._attributeToProperty_).forEach(function(e){var t=ze._attributeToProperty_[e];_this15.constructPropertyAccessors(t),_this15.hasOwnProperty(e)||_this15.constructPropertyAccessors(t,e);});return _this15;}_inherits(ze,_HTMLElement);return _createClass(ze,[{key:"constructPropertyAccessors",value:// need to be called here as accessors need to be set for the class instance
|
137
137
|
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=ze._attributes_[e](s),n=ze._attributeToProperty_[e];this[n]=i;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(ze._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));ze._attributes_={},ze._attributeToProperty_={};var Hi=ze;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
|
138
138
|
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
|
139
139
|
},{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 ji=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 _o3=ce.createCautionText();i.appendChild(_o3);}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
|
@@ -145,23 +145,23 @@ function changeVisibility(e,t,s,i){i.target.id===rt.VISIBLE_ICON_ID?(t.style.dis
|
|
145
145
|
{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
|
146
146
|
{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
|
147
147
|
{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
|
148
|
-
{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},L=/*#__PURE__*/function(_wt2){function L(e){var
|
149
|
-
_inherits(L,_wt2);return _createClass(L,[{key:"setUpMessages",value:function setUpMessages(e){var
|
150
|
-
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Gs.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:v.AI_ROLE,html:t,sendUpdate:!1};}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e){var t;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:t=this._webModel.load;if(!t){_context37.n=2;break;}if(!t.onInit){_context37.n=1;break;}this.init();return _context37.a(2);case 1:if(!t.onMessage){_context37.n=2;break;}this._loadOnFirstMessage=!0;return _context37.a(2);case 2:e||this.init();case 3:return _context37.a(2);}},_callee37,this);}));function configureInit(_x84){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(e){var s,t,_t15;return _regenerator().w(function(_context38){while(1)switch(_context38.n){case 0:(s=this._messages)==null||s.removeError();t=this.attemptToCreateChat();_t15=t;if(!_t15){_context38.n=1;break;}_context38.n=1;return this.loadModel(t,e);case 1:return _context38.a(2);}},_callee38,this);}));function init(_x85){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var t;if(L.chat){(t=this._messages)==null||t.addNewErrorMessage(
|
151
|
-
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(e,t){var
|
148
|
+
{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},L=/*#__PURE__*/function(_wt2){function L(e){var _this16;_classCallCheck(this,L);var t,s;_this16=_callSuper(this,L,[e]),_this16._isModelLoaded=!1,_this16._isModelLoading=!1,_this16._loadOnFirstMessage=!1,_this16._webModel={},_this16.permittedErrorPrefixes=[L.MULTIPLE_MODELS_ERROR,L.WEB_LLM_NOT_FOUND_ERROR,L.GENERIC_ERROR],_this16._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this16._webModel=e.webModel),(t=_this16._webModel.load)!=null&&t.clearCache&&L.clearAllCache(),_this16.findModelInWindow(e),_this16.canSendMessage=_this16.canSubmit.bind(_assertThisInitialized(_this16)),_this16._chatEl=(s=e.shadowRoot)==null?void 0:s.children[0],e.history&&L.setUpHistory(_this16._conversationHistory,e.history);return _this16;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
|
149
|
+
_inherits(L,_wt2);return _createClass(L,[{key:"setUpMessages",value:function setUpMessages(e){var _this17=this;this._messages=e,this._removeIntro=function(){e.removeIntroductoryMessage(),_this17._removeIntro=void 0;};}},{key:"findModelInWindow",value:function findModelInWindow(e){var _this18=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var s;window.webLLM?this.configureInit(this.shouldAddIntroMessage(e.introMessage)):t>L.MODULE_SEARCH_LIMIT_S?((s=this._messages)==null||s.addNewErrorMessage(F,L.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 _this18.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 _this19=this;var t;((t=this._webModel.introMessage)==null?void 0:t.autoScroll)!==!1&&setTimeout(function(){var s,i;(s=_this19._messages)!=null&&s.elementRef&&B.scrollToTop((i=_this19._messages)==null?void 0:i.elementRef);},e);}// prettier-ignore
|
150
|
+
},{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Gs.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:v.AI_ROLE,html:t,sendUpdate:!1};}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e){var t;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:t=this._webModel.load;if(!t){_context37.n=2;break;}if(!t.onInit){_context37.n=1;break;}this.init();return _context37.a(2);case 1:if(!t.onMessage){_context37.n=2;break;}this._loadOnFirstMessage=!0;return _context37.a(2);case 2:e||this.init();case 3:return _context37.a(2);}},_callee37,this);}));function configureInit(_x84){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(e){var s,t,_t15;return _regenerator().w(function(_context38){while(1)switch(_context38.n){case 0:(s=this._messages)==null||s.removeError();t=this.attemptToCreateChat();_t15=t;if(!_t15){_context38.n=1;break;}_context38.n=1;return this.loadModel(t,e);case 1:return _context38.a(2);}},_callee38,this);}));function init(_x85){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var t;if(L.chat){(t=this._messages)==null||t.addNewErrorMessage(F,L.MULTIPLE_MODELS_ERROR),console.error(L.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=L.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
|
151
|
+
},{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(e,t){var _this20=this;var o,a,l,c,d,u,h,s,i,n,_this$getConfig,f,m,p,_f,_t16;return _regenerator().w(function(_context39){while(1)switch(_context39.p=_context39.n){case 0:this.scrollToTop(),L.chat=e,this._isModelLoading=!0;s=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;i=function i(f){var m;(m=_this20._messages)==null||m.addNewMessage({html:"<div>".concat(f.text,"</div>"),overwrite:!0,sendUpdate:!1}),s&&(setTimeout(function(){var p;return B.scrollToBottom((p=_this20._messages)==null?void 0:p.elementRef);}),s=!1);};L.chat.setInitProgressCallback(i);_context39.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);_context39.n=2;return L.chat.reload(f,p,m,t);case 2:n=_context39.v;_context39.n=4;break;case 3:_context39.p=3;_t16=_context39.v;return _context39.a(2,this.unloadChat(_t16));case 4:if((l=(a=this.deepChat)._validationHandler)==null||l.call(a),(c=this._webModel.introMessage)!=null&&c.removeAfterLoad)this._webModel.introMessage.displayed===!1?(u=this._messages)==null||u.removeLastMessage():(h=this._removeIntro)==null||h.call(this);else{_f=Gs.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 _context39.a(2);}},_callee39,this,[[1,3]]);}));function loadModel(_x86,_x87){return _loadModel.apply(this,arguments);}return loadModel;}()},{key:"unloadChat",value:function(){var _unloadChat=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(e){var t,_t17;return _regenerator().w(function(_context40){while(1)switch(_context40.n){case 0:(t=this._messages)==null||t.addNewErrorMessage(F,L.GENERIC_ERROR);console.error(e);this._isModelLoaded=!1;this._isModelLoading=!1;_t17=L.chat;if(!_t17){_context40.n=2;break;}_context40.n=1;return L.chat.unload();case 1:L.chat=void 0;case 2:return _context40.a(2);}},_callee40,this);}));function unloadChat(_x88){return _unloadChat.apply(this,arguments);}return unloadChat;}()},{key:"immediateResp",value:function(){var _immediateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(e,t,s){var i,n,_t18,_t19,_t20;return _regenerator().w(function(_context41){while(1)switch(_context41.n){case 0:_t18=_defineProperty;_t19={};_t20=y;_context41.n=1;return s.generate(t,void 0,0);case 1:i=_t18(_t19,_t20,_context41.v);_context41.n=2;return L.processResponse(this.deepChat,e,i);case 2:n=_context41.v;n&&n.forEach(function(o){return e.addNewMessage(o);}),this.completionsHandlers.onFinish();case 3:return _context41.a(2);}},_callee41,this);}));function immediateResp(_x89,_x90,_x91){return _immediateResp.apply(this,arguments);}return immediateResp;}()},{key:"streamResp",value:function(){var _streamResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43(e,t,s){var _this21=this;var i;return _regenerator().w(function(_context43){while(1)switch(_context43.n){case 0:this.streamHandlers.onAbort=function(){s.interruptGenerate();},this.streamHandlers.onOpen();i=new Ue(e);_context43.n=1;return s.generate(t,/*#__PURE__*/function(){var _ref25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(n,o){var a;return _regenerator().w(function(_context42){while(1)switch(_context42.n){case 0:_context42.n=1;return L.processResponse(_this21.deepChat,e,_defineProperty({},y,o));case 1:a=_context42.v;a&&i.upsertStreamedMessage(_defineProperty(_defineProperty({},y,a[0].text),"overwrite",!0));case 2:return _context42.a(2);}},_callee42);}));return function(_x95,_x96){return _ref25.apply(this,arguments);};}());case 1:i.finaliseStreamedMessage();this.streamHandlers.onClose();case 2:return _context43.a(2);}},_callee43,this);}));function streamResp(_x92,_x93,_x94){return _streamResp.apply(this,arguments);}return streamResp;}()},{key:"generateRespByType",value:function(){var _generateRespByType=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44(e,t,s,i){var n,_t21;return _regenerator().w(function(_context44){while(1)switch(_context44.p=_context44.n){case 0:_context44.p=0;if(!s){_context44.n=2;break;}_context44.n=1;return this.streamResp(e,t,i);case 1:_context44.n=3;break;case 2:_context44.n=3;return this.immediateResp(e,t,i);case 3:_context44.n=5;break;case 4:_context44.p=4;_t21=_context44.v;(n=this._messages)==null||n.addNewErrorMessage(F),console.log(_t21);case 5:return _context44.a(2);}},_callee44,this,[[0,4]]);}));function generateRespByType(_x97,_x98,_x99,_x100){return _generateRespByType.apply(this,arguments);}return generateRespByType;}()},{key:"generateResp",value:function(){var _generateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45(e,t,s){var i,_yield$w$processReque5,n,o,a,l,c;return _regenerator().w(function(_context45){while(1)switch(_context45.n){case 0:i=t[t.length-1].text;_context45.n=1;return w.processRequestInterceptor(this.deepChat,{body:_defineProperty({},y,i)});case 1:_yield$w$processReque5=_context45.v;n=_yield$w$processReque5.body;o=_yield$w$processReque5.error;a=!!this.stream;try{if(o)w.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!n||!n.text){l=b.INVALID_MODEL_REQUEST({body:n},!1);console.error(l);c=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;w.onInterceptorError(e,l,c);}else this.generateRespByType(e,n.text,!!this.stream,s);}catch(l){this.unloadChat(l);}case 2:return _context45.a(2);}},_callee45,this);}));function generateResp(_x101,_x102,_x103){return _generateResp.apply(this,arguments);}return generateResp;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46(e,t){var s,i;return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:if(this._isModelLoaded){_context46.n=3;break;}if(!this._loadOnFirstMessage){_context46.n=2;break;}_context46.n=1;return this.init();case 1:_context46.n=3;break;case 2:return _context46.a(2);case 3:!L.chat||this._isModelLoading||((s=this._webModel.introMessage)!=null&&s.removeAfterMessage&&((i=this._removeIntro)==null||i.call(this)),e.addLoadingMessage(),this.generateResp(e,t,L.chat));case 4:return _context46.a(2);}},_callee46,this);}));function callServiceAPI(_x104,_x105){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===v.USER_ROLE&&s.text){var n=t[i+1];n!=null&&n.text&&n.role!==v.USER_ROLE&&e.push([s.text,n.text]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e,t,s){var a,l,i,n,o,d,_t22;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:_context47.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,s);case 1:_t22=_context47.v;if(_t22){_context47.n=2;break;}_t22=s;case 2:i=_t22;if(!((l=e.connect)!=null&&l.stream&&Array.isArray(i)&&i.length>1)){_context47.n=3;break;}console.error(b.INVALID_STREAM_ARRAY_RESPONSE);return _context47.a(2);case 3:n=Array.isArray(i)?i:[i],o=n.find(function(c){return typeof c.error=="string";});if(!o){_context47.n=4;break;}w.displayError(t,new Error(o.error));return _context47.a(2);case 4:if(!n.find(function(d){return!d||!d.text;})){_context47.n=5;break;}d=b.INVALID_MODEL_RESPONSE(s,!!e.responseInterceptor,i);w.displayError(t,new Error(d));return _context47.a(2);case 5:return _context47.a(2,n);}},_callee47);}));function processResponse(_x106,_x107,_x108){return _processResponse.apply(this,arguments);}return processResponse;}()},{key:"clearAllCache",value:function clearAllCache(){L.clearCache("webllm/model"),L.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);});});});}}]);}(wt);L.GENERIC_ERROR="Error, please check the [troubleshooting](https://deepchat.dev/docs/webModel#troubleshooting) section of documentation for help.",L.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",L.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",L.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",L.MODULE_SEARCH_LIMIT_S=5;var Cs=L;var Ks=/*#__PURE__*/function(){function Ks(){_classCallCheck(this,Ks);}return _createClass(Ks,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}// prettier-ignore
|
152
152
|
},{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(b.INVALID_KEY);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api-inference.huggingface.co/models/gpt2",method:Z,handleVerificationResult:Ks.handleVerificationResult};}}]);}();var ys=/*#__PURE__*/function(_k){// prettier-ignore
|
153
|
-
function ys(e,t,s,i,n,o){var
|
153
|
+
function ys(e,t,s,i,n,o){var _this22;_classCallCheck(this,ys);_this22=_callSuper(this,ys,[e,Ks.buildKeyVerificationDetails(),Ks.buildHeaders,n,o]),_this22.insertKeyPlaceholderText="Hugging Face Token",_this22.keyHelpUrl="https://huggingface.co/settings/tokens",_this22.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>",_this22.permittedErrorPrefixes=[nn],_this22.url="".concat(ys.URL_PREFIX).concat(s),_this22.textInputPlaceholderText=t,_typeof(i)=="object"&&(i.model&&(_this22.url="".concat(ys.URL_PREFIX).concat(i.model)),i.options&&(_this22.rawBody.options=i.options),i.parameters&&(_this22.rawBody.parameters=i.parameters));return _this22;}// prettier-ignore
|
154
154
|
_inherits(ys,_k);return _createClass(ys,[{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 _callee48(e,t,s){var i;return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:if(this.connectSettings){_context48.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:i=this.preprocessBody(this.rawBody,t,s);V.request(this,i,e);case 2:return _context48.a(2);}},_callee48,this);}));function callServiceAPI(_x109,_x110,_x111){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(k);ys.URL_PREFIX="https://api-inference.huggingface.co/models/";var et=ys;var Ls=/*#__PURE__*/function(_et){// prettier-ignore
|
155
|
-
function Ls(e,t,s,i,n,o){var
|
155
|
+
function Ls(e,t,s,i,n,o){var _this23;_classCallCheck(this,Ls);_this23=_callSuper(this,Ls,[e,t,s,i,n,o]),_this23.isTextInputDisabled=!0,_this23.canSendMessage=Ls.canSendFile;return _this23;}_inherits(Ls,_et);return _createClass(Ls,[{key:"preprocessBody",value:function preprocessBody(e,t,s){return s[0];}// prettier-ignore
|
156
156
|
},{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49(e,t,s){return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(this.connectSettings){_context49.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(s!=null&&s[0]){_context49.n=2;break;}throw new Error(b.NO_FILE_ADDED_ERROR);case 2:V.poll(this,s[0],e,!1);case 3:return _context49.a(2);}},_callee49,this);}));function callServiceAPI(_x112,_x113,_x114){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
|
157
157
|
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 _callee50(e){var t;return _regenerator().w(function(_context50){while(1)switch(_context50.n){case 0:if(!e.estimated_time){_context50.n=1;break;}return _context50.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context50.n=2;break;}throw e.error;case 2:return _context50.a(2,_defineProperty({},y,((t=e[0])==null?void 0:t.label)||""));}},_callee50);}));function extractPollResultData(_x115){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 _callee51(e){var t;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(!e.estimated_time){_context51.n=1;break;}return _context51.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context51.n=2;break;}throw e.error;case 2:return _context51.a(2,_defineProperty({},y,((t=e[0])==null?void 0:t.label)||""));}},_callee51);}));function extractPollResultData(_x116){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(Ls);var jt="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(se).concat(e)),R,N);}// prettier-ignore
|
158
158
|
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.message?i(b.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.stability.ai/v1/engines/list",method:z,handleVerificationResult:qe.handleVerificationResult};}}]);}();var Ai=/*#__PURE__*/function(_k2){// prettier-ignore
|
159
|
-
function Ai(e,t,s,i,n){var
|
160
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e,t,s){var i;return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(this.connectSettings){_context52.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(s){_context52.n=2;break;}throw new Error(b.IMAGE_NOT_FOUND_ERROR);case 2:i=this.createFormDataBody(this.rawBody,s[0]);w.tempRemoveContentHeader(this.connectSettings,V.request.bind(this,this,i,e),!1);case 3:return _context52.a(2);}},_callee52,this);}));function callServiceAPI(_x117,_x118,_x119){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e){return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(!e.message){_context53.n=1;break;}throw e.message;case 1:return _context53.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(jt).concat(s.base64),type:"image"};})});}},_callee53);}));function extractResultData(_x120){return _extractResultData2.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id;}},{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}}]);}(Ai);var Js=/*#__PURE__*/function(_Ai2){function Js(e){var
|
161
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54(e,t,s){var o,a,i,n;return _regenerator().w(function(_context54){while(1)switch(_context54.n){case 0:if(this.connectSettings){_context54.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(!(!s||!s[0]||!s[1])){_context54.n=2;break;}throw new Error(b.IMAGE_NOT_FOUND_ERROR);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);w.tempRemoveContentHeader(this.connectSettings,V.request.bind(this,this,n,e),!1);case 3:return _context54.a(2);}},_callee54,this);}));function callServiceAPI(_x121,_x122,_x123){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(e){return _regenerator().w(function(_context55){while(1)switch(_context55.n){case 0:if(!e.message){_context55.n=1;break;}throw e.message;case 1:return _context55.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(jt).concat(s.base64),type:"image"};})});}},_callee55);}));function extractResultData(_x124){return _extractResultData3.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(Ai);var 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 _callee56(e){return _regenerator().w(function(_context56){while(1)switch(_context56.n){case 0:if(!e.estimated_time){_context56.n=1;break;}return _context56.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context56.n=2;break;}throw e.error;case 2:return _context56.a(2,_defineProperty({},y,e.text||""));}},_callee56);}));function extractPollResultData(_x125){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 _callee57(e){var t;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({},y,((t=e[0])==null?void 0:t.generated_text)||""));}},_callee57);}));function extractResultData(_x126){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(et);var ja=/*#__PURE__*/function(_et3){function ja(e){var
|
159
|
+
function Ai(e,t,s,i,n){var _this24;_classCallCheck(this,Ai);_this24=_callSuper(this,Ai,[e,t,s,i,n]),_this24.insertKeyPlaceholderText=_this24.genereteAPIKeyName("Stability AI"),_this24.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this24.permittedErrorPrefixes=[ks,"invalid_"];return _this24;}_inherits(Ai,_k2);return _createClass(Ai);}(k);var zs=/*#__PURE__*/function(_Ai){function zs(e){var _this25;_classCallCheck(this,zs);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this25=_callSuper(this,zs,[e,qe.buildKeyVerificationDetails(),qe.buildHeaders,s,i]),_this25.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",_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 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&&(_this25.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/image-to-image/upscale")),zs.cleanConfig(n),Object.assign(_this25.rawBody,n)),_this25.canSendMessage=zs.canSendFileMessage;return _this25;}_inherits(zs,_Ai);return _createClass(zs,[{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
|
160
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e,t,s){var i;return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(this.connectSettings){_context52.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(s){_context52.n=2;break;}throw new Error(b.IMAGE_NOT_FOUND_ERROR);case 2:i=this.createFormDataBody(this.rawBody,s[0]);w.tempRemoveContentHeader(this.connectSettings,V.request.bind(this,this,i,e),!1);case 3:return _context52.a(2);}},_callee52,this);}));function callServiceAPI(_x117,_x118,_x119){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e){return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(!e.message){_context53.n=1;break;}throw e.message;case 1:return _context53.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(jt).concat(s.base64),type:"image"};})});}},_callee53);}));function extractResultData(_x120){return _extractResultData2.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id;}},{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}}]);}(Ai);var Js=/*#__PURE__*/function(_Ai2){function Js(e){var _this26;_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}}};_this26=_callSuper(this,Js,[e,qe.buildKeyVerificationDetails(),qe.buildHeaders,s,i]),_this26.url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",_this26._maskSource="MASK_IMAGE_WHITE",_this26.textInputPlaceholderText="Describe image changes",_this26.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&&(_this26.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/image-to-image/masking")),n.weight!==void 0&&n.weight!==null&&(_this26._imageWeight=n.weight),n.mask_source!==void 0&&n.mask_source!==null&&(_this26._maskSource=n.mask_source),Js.cleanConfig(n),Object.assign(_this26.rawBody,n)),_this26.canSendMessage=Js.canSendFileTextMessage;return _this26;}_inherits(Js,_Ai2);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
|
161
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54(e,t,s){var o,a,i,n;return _regenerator().w(function(_context54){while(1)switch(_context54.n){case 0:if(this.connectSettings){_context54.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(!(!s||!s[0]||!s[1])){_context54.n=2;break;}throw new Error(b.IMAGE_NOT_FOUND_ERROR);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);w.tempRemoveContentHeader(this.connectSettings,V.request.bind(this,this,n,e),!1);case 3:return _context54.a(2);}},_callee54,this);}));function callServiceAPI(_x121,_x122,_x123){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(e){return _regenerator().w(function(_context55){while(1)switch(_context55.n){case 0:if(!e.message){_context55.n=1;break;}throw e.message;case 1:return _context55.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(jt).concat(s.base64),type:"image"};})});}},_callee55);}));function extractResultData(_x124){return _extractResultData3.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(Ai);var 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 _callee56(e){return _regenerator().w(function(_context56){while(1)switch(_context56.n){case 0:if(!e.estimated_time){_context56.n=1;break;}return _context56.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e.error){_context56.n=2;break;}throw e.error;case 2:return _context56.a(2,_defineProperty({},y,e.text||""));}},_callee56);}));function extractPollResultData(_x125){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 _callee57(e){var t;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({},y,((t=e[0])==null?void 0:t.generated_text)||""));}},_callee57);}));function extractResultData(_x126){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(et);var ja=/*#__PURE__*/function(_et3){function ja(e){var _this27;_classCallCheck(this,ja);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;_this27=_callSuper(this,ja,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,s]),_this27.permittedErrorPrefixes=[nn,"Error in"],_this27._context=t.context;return _this27;}_inherits(ja,_et3);return _createClass(ja,[{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 _callee58(e){return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(!e.error){_context58.n=1;break;}throw e.error;case 1:return _context58.a(2,_defineProperty({},y,e.answer||""));}},_callee58);}));function extractResultData(_x127){return _extractResultData5.apply(this,arguments);}return extractResultData;}()}]);}(et);var qa=/*#__PURE__*/function(_et4){function qa(e){_classCallCheck(this,qa);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,qa,[e,"Insert text to summarize","facebook/bart-large-cnn",t,s]);}_inherits(qa,_et4);return _createClass(qa,[{key:"extractResultData",value:function(){var _extractResultData6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){var t;return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e.error){_context59.n=1;break;}throw e.error;case 1:return _context59.a(2,_defineProperty({},y,((t=e[0])==null?void 0:t.summary_text)||""));}},_callee59);}));function extractResultData(_x128){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(et);var Va=/*#__PURE__*/function(_et5){function Va(e){var _this28$maxMessages;var _this28;_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;_this28=_callSuper(this,Va,[e,"Ask me anything!","facebook/blenderbot-400M-distill",t,s]),(_this28$maxMessages=_this28.maxMessages)!==null&&_this28$maxMessages!==void 0?_this28$maxMessages:_this28.maxMessages=-1;return _this28;}// prettier-ignore
|
162
162
|
_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
|
163
|
-
},{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},y,i.mostRecentMessageText)},s);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){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({},y,e.generated_text||""));}},_callee60);}));function extractResultData(_x129){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(et);var $s=/*#__PURE__*/function(_Ai3){function $s(e){var
|
164
|
-
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e,t,s){var o,a,i,n;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(this.connectSettings){_context61.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(s){_context61.n=2;break;}throw new Error(b.IMAGE_NOT_FOUND_ERROR);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);w.tempRemoveContentHeader(this.connectSettings,V.request.bind(this,this,n,e),!1);case 3:return _context61.a(2);}},_callee61,this);}));function callServiceAPI(_x130,_x131,_x132){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_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(jt).concat(s.base64),type:"image"};})});}},_callee62);}));function extractResultData(_x133){return _extractResultData8.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(Ai);var Ga=/*#__PURE__*/function(_et6){function Ga(e){_classCallCheck(this,Ga);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ga,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,s]);}_inherits(Ga,_et6);return _createClass(Ga,[{key:"extractResultData",value:function(){var _extractResultData9=_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({},y,((t=e[0])==null?void 0:t.translation_text)||""));}},_callee63);}));function extractResultData(_x134){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(et);var Ws=/*#__PURE__*/function(_Ai4){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,_Ai4);return _createClass(Ws,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text,i=JSON.parse(JSON.stringify(e)),n=_defineProperty({},y,s);return this._imageWeight&&(n.weight=this._imageWeight),i.text_prompts=[n],i;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e,t){return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context64.a(2);}},_callee64,this);}));function callServiceAPI(_x135,_x136){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:if(!e.message){_context65.n=1;break;}throw e.message;case 1:return _context65.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(jt).concat(s.base64),type:"image"};})});}},_callee65);}));function extractResultData(_x137){return _extractResultData0.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendTextMessage",value:function canSendTextMessage(e){return!!(e&&e.trim()!=="");}}]);}(Ai);var Ka=/*#__PURE__*/function(_et7){function Ka(e){var _this30;_classCallCheck(this,Ka);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,Ka,[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=[nn,"No mask_token"];return _this30;}_inherits(Ka,_et7);return _createClass(Ka,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e){var t;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(!e.error){_context66.n=1;break;}throw e.error;case 1:return _context66.a(2,_defineProperty({},y,((t=e[0])==null?void 0:t.sequence)||""));}},_callee66);}));function extractResultData(_x138){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({},R,N),K,"".concat(se).concat(e));}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message===sn?i(b.INVALID_KEY):i(b.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 za=/*#__PURE__*/function(_k3){function za(e){var _o$model,_a$voice;var _this31;_classCallCheck(this,za);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this31=_callSuper(this,za,[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,ie];var i=(n=t.bigModel)==null?void 0:n.textToSpeech;_typeof(i)===T&&(_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(za,_k3);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.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e,t){return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:return _context67.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee67,this);}));function callServiceAPI(_x139,_x140){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e){var t;return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context68.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee68);}));function extractResultData(_x141){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(k);var dt=/*#__PURE__*/function(){function dt(){_classCallCheck(this,dt);}return _createClass(dt,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},R,N),K,"".concat(se).concat(e));}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message===sn?i(b.INVALID_KEY):i(b.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(_k4){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=[we,ie];var i=(n=t.together)==null?void 0:n.textToSpeech;_typeof(i)===T&&(_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,_k4);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 _callee69(e,t){return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:return _context69.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee69,this);}));function callServiceAPI(_x142,_x143){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(e){var t;return _regenerator().w(function(_context70){while(1)switch(_context70.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context70.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee70);}));function extractResultData(_x144){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(k);var bs=/*#__PURE__*/function(){function bs(){_classCallCheck(this,bs);}return _createClass(bs,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}// prettier-ignore
|
163
|
+
},{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},y,i.mostRecentMessageText)},s);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){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({},y,e.generated_text||""));}},_callee60);}));function extractResultData(_x129){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(et);var $s=/*#__PURE__*/function(_Ai3){function $s(e){var _this29;_classCallCheck(this,$s);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this29=_callSuper(this,$s,[e,qe.buildKeyVerificationDetails(),qe.buildHeaders,s,i]),_this29.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this29.textInputPlaceholderText="Describe image changes",_this29.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&&(_this29.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/text-to-image")),n.weight!==void 0&&n.weight!==null&&(_this29._imageWeight=n.weight),$s.cleanConfig(n),Object.assign(_this29.rawBody,n)),_this29.canSendMessage=$s.canSendFileTextMessage;return _this29;}_inherits($s,_Ai3);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
|
164
|
+
},{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e,t,s){var o,a,i,n;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(this.connectSettings){_context61.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(s){_context61.n=2;break;}throw new Error(b.IMAGE_NOT_FOUND_ERROR);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);w.tempRemoveContentHeader(this.connectSettings,V.request.bind(this,this,n,e),!1);case 3:return _context61.a(2);}},_callee61,this);}));function callServiceAPI(_x130,_x131,_x132){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_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(jt).concat(s.base64),type:"image"};})});}},_callee62);}));function extractResultData(_x133){return _extractResultData8.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(Ai);var Ga=/*#__PURE__*/function(_et6){function Ga(e){_classCallCheck(this,Ga);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ga,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,s]);}_inherits(Ga,_et6);return _createClass(Ga,[{key:"extractResultData",value:function(){var _extractResultData9=_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({},y,((t=e[0])==null?void 0:t.translation_text)||""));}},_callee63);}));function extractResultData(_x134){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(et);var Ws=/*#__PURE__*/function(_Ai4){function Ws(e){var _this30;_classCallCheck(this,Ws);var n;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI;_this30=_callSuper(this,Ws,[e,qe.buildKeyVerificationDetails(),qe.buildHeaders,s]),_this30.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this30.textInputPlaceholderText="Describe an image",_this30.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&&(_this30.url="https://api.stability.ai/v1/generation/".concat(i.engine_id,"/text-to-image")),i.weight!==void 0&&i.weight!==null&&(_this30._imageWeight=i.weight),Ws.cleanConfig(i),Object.assign(_this30.rawBody,i)),_this30.canSendMessage=Ws.canSendTextMessage;return _this30;}_inherits(Ws,_Ai4);return _createClass(Ws,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text,i=JSON.parse(JSON.stringify(e)),n=_defineProperty({},y,s);return this._imageWeight&&(n.weight=this._imageWeight),i.text_prompts=[n],i;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e,t){return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context64.a(2);}},_callee64,this);}));function callServiceAPI(_x135,_x136){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:if(!e.message){_context65.n=1;break;}throw e.message;case 1:return _context65.a(2,{files:e.artifacts.map(function(s){return{src:"".concat(jt).concat(s.base64),type:"image"};})});}},_callee65);}));function extractResultData(_x137){return _extractResultData0.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendTextMessage",value:function canSendTextMessage(e){return!!(e&&e.trim()!=="");}}]);}(Ai);var Ka=/*#__PURE__*/function(_et7){function Ka(e){var _this31;_classCallCheck(this,Ka);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.fillMask,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this31=_callSuper(this,Ka,[e,"The goal of life is [MASK].","bert-base-uncased",t,s]),_this31.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Hugging Face</b></div>\n <p>Insert a sentence with the word [MASK] and the model will try to fill it for you. E.g. I want [MASK].</p>\n <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>",_this31.permittedErrorPrefixes=[nn,"No mask_token"];return _this31;}_inherits(Ka,_et7);return _createClass(Ka,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e){var t;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(!e.error){_context66.n=1;break;}throw e.error;case 1:return _context66.a(2,_defineProperty({},y,((t=e[0])==null?void 0:t.sequence)||""));}},_callee66);}));function extractResultData(_x138){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({},R,N),K,"".concat(se).concat(e));}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message===sn?i(b.INVALID_KEY):i(b.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 za=/*#__PURE__*/function(_k3){function za(e){var _o$model,_a$voice;var _this32;_classCallCheck(this,za);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this32=_callSuper(this,za,[e,ct.buildKeyVerificationDetails(),ct.buildHeaders,s]),_this32.insertKeyPlaceholderText=_this32.genereteAPIKeyName("BigModel"),_this32.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this32.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this32.permittedErrorPrefixes=[K,ie];var i=(n=t.bigModel)==null?void 0:n.textToSpeech;_typeof(i)===T&&(_this32.cleanConfig(i),Object.assign(_this32.rawBody,i)),(_o$model=(o=_this32.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this32.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this32;}_inherits(za,_k3);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.input=(i==null?void 0:i.text)||"",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e,t){return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:return _context67.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee67,this);}));function callServiceAPI(_x139,_x140){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e){var t;return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context68.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee68);}));function extractResultData(_x141){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(k);var dt=/*#__PURE__*/function(){function dt(){_classCallCheck(this,dt);}return _createClass(dt,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},R,N),K,"".concat(se).concat(e));}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message===sn?i(b.INVALID_KEY):i(b.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(_k4){function Ja(e){var _o$model2,_a$voice2;var _this33;_classCallCheck(this,Ja);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this33=_callSuper(this,Ja,[e,dt.buildKeyVerificationDetails(),dt.buildHeaders,s]),_this33.insertKeyPlaceholderText=_this33.genereteAPIKeyName("Together AI"),_this33.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this33.url="https://api.together.xyz/v1/audio/speech",_this33.permittedErrorPrefixes=[we,ie];var i=(n=t.together)==null?void 0:n.textToSpeech;_typeof(i)===T&&(_this33.cleanConfig(i),Object.assign(_this33.rawBody,i)),(_o$model2=(o=_this33.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this33.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this33;}_inherits(Ja,_k4);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 _callee69(e,t){return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:return _context69.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee69,this);}));function callServiceAPI(_x142,_x143){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(e){var t;return _regenerator().w(function(_context70){while(1)switch(_context70.n){case 0:t=new Blob([e],{type:"audio/mpeg"});return _context70.a(2,{files:[{src:URL.createObjectURL(t),type:"audio"}]});}},_callee70);}));function extractResultData(_x144){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(k);var bs=/*#__PURE__*/function(){function bs(){_classCallCheck(this,bs);}return _createClass(bs,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}// prettier-ignore
|
165
165
|
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.openai.com/v1/models",method:z,handleVerificationResult:bs.handleVerificationResult};}// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
166
166
|
},{key:"directFetch",value:function(){var _directFetch=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(e,t,s){var i,n,_args71=arguments;return _regenerator().w(function(_context71){while(1)switch(_context71.n){case 0:i=_args71.length>3&&_args71[3]!==undefined?_args71[3]:!0;e.connectSettings.method=s;_context71.n=1;return w.fetch(e,e.connectSettings.headers,i,t).then(function(o){return w.processResponseByType(o);});case 1:n=_context71.v;if(!n.error){_context71.n=2;break;}throw n.error.message;case 2:return _context71.a(2,n);}},_callee71);}));function directFetch(_x145,_x146,_x147){return _directFetch.apply(this,arguments);}return directFetch;}()}]);}();bs.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.",bs.FUNCTION_TOOL_RESP_ARR_ERROR="Arrays are not accepted in handler responses";var G=bs;var ye=/*#__PURE__*/function(){function ye(){_classCallCheck(this,ye);}return _createClass(ye,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73(e,t,s,i){var n,o,a,l,_t23;return _regenerator().w(function(_context73){while(1)switch(_context73.p=_context73.n){case 0:n=e.connectSettings.headers;if(n){_context73.n=1;break;}return _context73.a(2);case 1:e.url=i;o=n[R];delete n[R];a=s.map(/*#__PURE__*/function(){var _ref40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(l){var c;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:c=new FormData();return _context72.a(2,(c.append("purpose","assistants"),c.append("file",l),new Promise(function(d){d(G.directFetch(e,c,Z,!1));})));}},_callee72);}));return function(_x152){return _ref40.apply(this,arguments);};}());_context73.p=2;_context73.n=3;return Promise.all(a);case 3:l=_context73.v.map(function(c){return{id:c.id,name:c.filename};});return _context73.a(2,(n[R]=o,l));case 4:_context73.p=4;_t23=_context73.v;throw n[R]=o,w.displayError(t,_t23),e.completionsHandlers.onFinish(),_t23;case 5:return _context73.a(2);}},_callee73,null,[[2,4]]);}));function storeFiles(_x148,_x149,_x150,_x151){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 _callee74(e,t,s,i){var n,a;return _regenerator().w(function(_context74){while(1)switch(_context74.n){case 0:n=t.map(function(_ref41){var l=_ref41.fileId;return e.url="".concat(s).concat(l).concat(i),new Promise(function(c){c(G.directFetch(e,void 0,"GET",!1));});});_context74.n=1;return Promise.all(n);case 1:a=_context74.v.map(function(l,c){return new Promise(function(d){var u=new FileReader();u.readAsDataURL(l),u.onload=function(h){d({src:h.target.result,name:t[c].name,type:ye.getType(t,c)});};});});_context74.n=2;return Promise.all(a);case 2:return _context74.a(2,_context74.v);}},_callee74);}));function getFiles(_x153,_x154,_x155,_x156){return _getFiles.apply(this,arguments);}return getFiles;}()},{key:"getFileName",value:function getFileName(e){var t=e.split("/");return t[t.length-1];}// prettier-ignore
|
167
167
|
},{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee75(e,t,s,i,n){var c,d,o,a,l,_t24;return _regenerator().w(function(_context75){while(1)switch(_context75.n){case 0:a=s.getFilesPrefix,l=s.getFilesPostfix;_t24=t.length>0;if(!_t24){_context75.n=2;break;}_context75.n=1;return ye.getFiles(e,t,a,l);case 1:o=_context75.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 _context75.a(2,(d=n==null?void 0:n.text)!=null&&d.value?_defineProperty(_defineProperty({},y,n.text.value),"role",i):{files:o,role:i});}},_callee75);}));function getFilesAndNewText(_x157,_x158,_x159,_x160,_x161){return _getFilesAndNewText.apply(this,arguments);}return getFilesAndNewText;}()// Noticed an issue where text contains a sandbox hyperlink to a csv, but no annotation provided
|
@@ -174,43 +174,40 @@ _inherits(Va,_et5);return _createClass(Va,[{key:"processMessages",value:function
|
|
174
174
|
// "give example data for a csv and create a suitable bar chart"
|
175
175
|
},{key:"parseMessages",value:function parseMessages(e,t,s){var i=[];return t.forEach(/*#__PURE__*/function(){var _ref43=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(n){return _regenerator().w(function(_context78){while(1)switch(_context78.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 _ref44=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(o){return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:i.push(ye.getFilesAndText(e,n,s,o));case 1:return _context77.a(2);}},_callee77);}));return function(_x167){return _ref44.apply(this,arguments);};}());case 1:return _context78.a(2);}},_callee78);}));return function(_x166){return _ref43.apply(this,arguments);};}()),Promise.all(i);}},{key:"processStreamMessages",value:function(){var _processStreamMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,s){return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:return _context79.a(2,ye.parseMessages(e,[{content:t,role:"assistant"}],s));}},_callee79);}));function processStreamMessages(_x168,_x169,_x170){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
|
176
176
|
},{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(e,t,s,i){var n;return _regenerator().w(function(_context80){while(1)switch(_context80.n){case 0:n=ye.parseResult(t,s);return _context80.a(2,ye.parseMessages(e,n,i));}},_callee80);}));function processAPIMessages(_x171,_x172,_x173,_x174){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 Ge=ye;var ot=/*#__PURE__*/function(_k5){// prettier-ignore
|
177
|
-
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=[ks,"Please send text",As.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,_k5);return _createClass(ot,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(){var _this34=this;var e,_t25;return _regenerator().w(function(_context81){while(1)switch(_context81.p=_context81.n){case 0:setTimeout(function(){return _this34.deepChat.disableSubmitButton();},2);_context81.p=1;_context81.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context81.v;return _context81.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context81.p=3;_t25=_context81.v;return _context81.a(2,[_defineProperty({},je,"Failed to fetch history")]);}},_callee81,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=J.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(_ref46){var l=_ref46.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(_ref47){var a=_ref47.name;return!ee.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=ot.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);V.request(this,i,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _i3=this.createNewThreadMessages(this.rawBody,t,s);this._isSSEStream?this.createStreamRun(_i3):V.request(this,_i3,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(e,t,s){var _n$assistant_id;var n,i,_t26,_t27;return _regenerator().w(function(_context82){while(1)switch(_context82.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context82.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(!((_n$assistant_id=(n=this.rawBody).assistant_id)!==null&&_n$assistant_id!==void 0)){_context82.n=2;break;}_n$assistant_id;_context82.n=5;break;case 2:_t26=this._config.assistant_id;if(_t26){_context82.n=4;break;}_context82.n=3;return this.createNewAssistant();case 3:_t26=_context82.v;case 4:n.assistant_id=_t26;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!s){_context82.n=7;break;}_context82.n=6;return Ge.storeFiles(this,e,s,this.urlSegments.storeFiles);case 6:_t27=_context82.v;_context82.n=8;break;case 7:_t27=void 0;case 8:i=_t27;this.connectSettings.method=Z,this.callService(e,t,i);case 9:return _context82.a(2);}},_callee82,this);}));function callServiceAPI(_x175,_x176,_x177){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(){var e,_t28;return _regenerator().w(function(_context83){while(1)switch(_context83.p=_context83.n){case 0:_context83.p=0;this.url=this.urlSegments.newAssistantUrl;_context83.n=1;return G.directFetch(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),Z);case 1:e=_context83.v;return _context83.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context83.p=2;_t28=_context83.v;console.error(_t28),console.error("Failed to create a new assistant");case 3:return _context83.a(2);}},_callee83,this,[[0,2]]);}));function createNewAssistant(){return _createNewAssistant.apply(this,arguments);}return createNewAssistant;}()},{key:"searchPreviousMessagesForThreadId",value:function searchPreviousMessagesForThreadId(e){var t=e.find(function(_ref48){var _ref49=_slicedToArray(_ref48,1),s=_ref49[0];return s._sessionId;});t&&(this.sessionId=t[0]._sessionId),this._searchedForThreadId=!0;}},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(e){var i,t,s;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context84.n=2;break;}_context84.n=1;return this.handleStream(e);case 1:return _context84.a(2,_context84.v);case 2:if(!e.error){_context84.n=3;break;}throw e.error.message.startsWith(Ge.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e.error.message;case 3:this.asyncCallInProgress=!0;_context84.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 _context84.a(2,(V.executePollRequest(this,t,s,this._messages),_defineProperty({},y,"")));}},_callee84,this);}));function extractResultData(_x178){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var t;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:if(!this.sessionId){_context85.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context85.n=1;return G.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),Z);case 1:t=_context85.v;this.run_id=t.id;_context85.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 _context85.a(2);}},_callee85,this);}));function assignThreadAndRun(_x179){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){var t,i,n,s,_args86=arguments,_t29;return _regenerator().w(function(_context86){while(1)switch(_context86.n){case 0:t=_args86.length>1&&_args86[1]!==undefined?_args86[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context86.n=1;return G.directFetch(this,{},z);case 1:s=_context86.v;_t29=!t&&this.deepChat.responseInterceptor;if(!_t29){_context86.n=3;break;}_context86.n=2;return(n=(i=this.deepChat).responseInterceptor)==null?void 0:n.call(i,s);case 2:s=_context86.v;case 3:return _context86.a(2,Ge.processAPIMessages(this,s,t,this.urlSegments));}},_callee86,this);}));function getThreadMessages(_x180){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var _this35=this;var n,t,s,o,_o$shift,a,l,i;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:t=e.status,s=e.required_action;if(!(t==="queued"||t==="in_progress")){_context87.n=1;break;}return _context87.a(2,{timeoutMS:ot.POLLING_TIMEOUT_MS});case 1:if(!(t===fr&&this._messages)){_context87.n=3;break;}_context87.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context87.v;_o$shift=o.shift();a=_o$shift.text;l=_o$shift.files;return _context87.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)){_context87.n=5;break;}_context87.n=4;return this.handleTools(i);case 4:return _context87.a(2,_context87.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context87.a(2);}},_callee87,this);}));function extractPollResultData(_x181){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
|
177
|
+
function ot(e,t,s,i,n,o){var _this34;_classCallCheck(this,ot);if(_this34=_callSuper(this,ot,[e,i,n,o]),_this34.insertKeyPlaceholderText=_this34.genereteAPIKeyName("OpenAI"),_this34.keyHelpUrl="https://platform.openai.com/account/api-keys",_this34.url="",_this34.permittedErrorPrefixes=[ks,"Please send text",As.FAILED_ERROR_MESSAGE],_this34.shouldFetchHistory=!1,_this34._searchedForThreadId=!1,_this34._config={},_this34._newAssistantDetails={model:"gpt-4"},_this34._waitingForStreamResponse=!1,_this34._isSSEStream=!1,_this34.urlSegments=s,_typeof(t)=="object"){_this34._config=t;var _this34$_config=_this34._config,a=_this34$_config.new_assistant,l=_this34$_config.thread_id,c=_this34$_config.load_thread_history;Object.assign(_this34._newAssistantDetails,a),l&&(_this34.sessionId=l),c&&(_this34.shouldFetchHistory=!0);}_this34.maxMessages=1,_this34._isSSEStream=!!(_this34.stream&&(_typeof(_this34.stream)!="object"||!_this34.stream.simulation));return _this34;}_inherits(ot,_k5);return _createClass(ot,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(){var _this35=this;var e,_t25;return _regenerator().w(function(_context81){while(1)switch(_context81.p=_context81.n){case 0:setTimeout(function(){return _this35.deepChat.disableSubmitButton();},2);_context81.p=1;_context81.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context81.v;return _context81.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context81.p=3;_t25=_context81.v;return _context81.a(2,[_defineProperty({},je,"Failed to fetch history")]);}},_callee81,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=J.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(_ref46){var l=_ref46.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(_ref47){var a=_ref47.name;return!ee.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=ot.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);V.request(this,i,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _i3=this.createNewThreadMessages(this.rawBody,t,s);this._isSSEStream?this.createStreamRun(_i3):V.request(this,_i3,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(e,t,s){var _n$assistant_id;var n,i,_t26,_t27;return _regenerator().w(function(_context82){while(1)switch(_context82.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context82.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(!((_n$assistant_id=(n=this.rawBody).assistant_id)!==null&&_n$assistant_id!==void 0)){_context82.n=2;break;}_n$assistant_id;_context82.n=5;break;case 2:_t26=this._config.assistant_id;if(_t26){_context82.n=4;break;}_context82.n=3;return this.createNewAssistant();case 3:_t26=_context82.v;case 4:n.assistant_id=_t26;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!s){_context82.n=7;break;}_context82.n=6;return Ge.storeFiles(this,e,s,this.urlSegments.storeFiles);case 6:_t27=_context82.v;_context82.n=8;break;case 7:_t27=void 0;case 8:i=_t27;this.connectSettings.method=Z,this.callService(e,t,i);case 9:return _context82.a(2);}},_callee82,this);}));function callServiceAPI(_x175,_x176,_x177){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(){var e,_t28;return _regenerator().w(function(_context83){while(1)switch(_context83.p=_context83.n){case 0:_context83.p=0;this.url=this.urlSegments.newAssistantUrl;_context83.n=1;return G.directFetch(this,JSON.parse(JSON.stringify(this._newAssistantDetails)),Z);case 1:e=_context83.v;return _context83.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context83.p=2;_t28=_context83.v;console.error(_t28),console.error("Failed to create a new assistant");case 3:return _context83.a(2);}},_callee83,this,[[0,2]]);}));function createNewAssistant(){return _createNewAssistant.apply(this,arguments);}return createNewAssistant;}()},{key:"searchPreviousMessagesForThreadId",value:function searchPreviousMessagesForThreadId(e){var t=e.find(function(_ref48){var _ref49=_slicedToArray(_ref48,1),s=_ref49[0];return s._sessionId;});t&&(this.sessionId=t[0]._sessionId),this._searchedForThreadId=!0;}},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(e){var i,t,s;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context84.n=2;break;}_context84.n=1;return this.handleStream(e);case 1:return _context84.a(2,_context84.v);case 2:if(!e.error){_context84.n=3;break;}throw e.error.message.startsWith(Ge.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e.error.message;case 3:this.asyncCallInProgress=!0;_context84.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 _context84.a(2,(V.executePollRequest(this,t,s,this._messages),_defineProperty({},y,"")));}},_callee84,this);}));function extractResultData(_x178){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var t;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:if(!this.sessionId){_context85.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context85.n=1;return G.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),Z);case 1:t=_context85.v;this.run_id=t.id;_context85.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 _context85.a(2);}},_callee85,this);}));function assignThreadAndRun(_x179){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){var t,i,n,s,_args86=arguments,_t29;return _regenerator().w(function(_context86){while(1)switch(_context86.n){case 0:t=_args86.length>1&&_args86[1]!==undefined?_args86[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context86.n=1;return G.directFetch(this,{},z);case 1:s=_context86.v;_t29=!t&&this.deepChat.responseInterceptor;if(!_t29){_context86.n=3;break;}_context86.n=2;return(n=(i=this.deepChat).responseInterceptor)==null?void 0:n.call(i,s);case 2:s=_context86.v;case 3:return _context86.a(2,Ge.processAPIMessages(this,s,t,this.urlSegments));}},_callee86,this);}));function getThreadMessages(_x180){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var _this36=this;var n,t,s,o,_o$shift,a,l,i;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:t=e.status,s=e.required_action;if(!(t==="queued"||t==="in_progress")){_context87.n=1;break;}return _context87.a(2,{timeoutMS:ot.POLLING_TIMEOUT_MS});case 1:if(!(t===fr&&this._messages)){_context87.n=3;break;}_context87.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context87.v;_o$shift=o.shift();a=_o$shift.text;l=_o$shift.files;return _context87.a(2,(setTimeout(function(){o.forEach(function(c){return _this36.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)){_context87.n=5;break;}_context87.n=4;return this.handleTools(i);case 4:return _context87.a(2,_context87.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context87.a(2);}},_callee87,this);}));function extractPollResultData(_x181){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
|
178
178
|
},{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){var t,s,i,n,o,a;return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:if(this.functionHandler){_context88.n=1;break;}throw Error(b.DEFINE_FUNCTION_HANDLER);case 1:t=e.map(function(l){return{name:l["function"].name,arguments:l["function"].arguments};});_context88.n=2;return this.functionHandler(t);case 2:s=_context88.v;if(!(!Array.isArray(s)||e.length!==s.length)){_context88.n=3;break;}throw Error(Ge.FUNCTION_TOOL_RESP_ERROR);case 3:_context88.n=4;return Promise.all(s);case 4:i=_context88.v;if(!i.find(function(l){return typeof l!="string";})){_context88.n=5;break;}throw Error(Ge.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){_context88.n=7;break;}_context88.n=6;return this.createStreamRun({tool_outputs:n});case 6:_context88.n=8;break;case 7:_context88.n=8;return G.directFetch(this,{tool_outputs:n},Z);case 8:return _context88.a(2,{timeoutMS:ot.POLLING_TIMEOUT_MS});}},_callee88,this);}));function handleTools(_x182){return _handleTools.apply(this,arguments);}return handleTools;}()},{key:"handleStream",value:function(){var _handleStream=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(e){var s,i,t,n;return _regenerator().w(function(_context89){while(1)switch(_context89.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)){_context89.n=2;break;}this.run_id=e.id;_context89.n=1;return this.handleTools(t);case 1:return _context89.a(2,_context89.v);case 2:if(!this._waitingForStreamResponse){_context89.n=3;break;}return _context89.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 _context89.a(2,_defineProperty({},y,""));}},_callee89,this);}));function handleStream(_x183){return _handleStream.apply(this,arguments);}return handleStream;}()// prettier-ignore
|
179
179
|
},{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var t,s,i,n,o,a,l,c,_a4,_l3;return _regenerator().w(function(_context90){while(1)switch(_context90.n){case 0:if(!(e.content&&e.content.length>0&&this._messages)){_context90.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)){_context90.n=1;break;}l=e.content.find(function(d){return!!d.text;})||e.content[0],c=Ge.getFilesAndText.bind(this,this,{role:"assistant",content:e.content},this.urlSegments,l);return _context90.a(2,((s=this._messageStream)==null||s.endStreamAfterFileDownloaded(this._messages,c),_defineProperty({},y,"")));case 1:if(!((i=e.delta)!=null&&i.content)){_context90.n=4;break;}if(!(e.delta.content.length>1)){_context90.n=3;break;}_a4=e.delta.content.find(function(l){return l.text;});if(!((n=_a4==null?void 0:_a4.text)!=null&&n.annotations&&_a4.text.annotations.length===0)){_context90.n=3;break;}_context90.n=2;return Ge.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_l3=_context90.v;return _context90.a(2,_defineProperty(_defineProperty({},y,_l3[0].text),"files",_l3[1].files));case 3:return _context90.a(2,_defineProperty({},y,(o=e.delta.content[0].text)==null?void 0:o.value));case 4:return _context90.a(2,(!this.sessionId&&e.thread_id&&(this.sessionId=e.thread_id),_defineProperty({},y,"")));}},_callee90,this);}));function parseStreamResult(_x184){return _parseStreamResult.apply(this,arguments);}return parseStreamResult;}()// https://platform.openai.com/docs/api-reference/assistants-streaming
|
180
180
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
181
|
-
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context91.n=1;return M.request(this,e,this._messages,!0,!0);case 1:this._messageStream=_context91.v;case 2:return _context91.a(2);}},_callee91,this);}));function createStreamRun(_x185){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 ee.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"},y,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"},y,e.text)],role:"user"};}}]);}(k);ot.POLLING_TIMEOUT_MS=500;var Xs=ot;var cn=/*#__PURE__*/function(_Xs){function cn(e){var _a$headers,_l$OpenAIBeta;var
|
181
|
+
},{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context91.n=1;return M.request(this,e,this._messages,!0,!0);case 1:this._messageStream=_context91.v;case 2:return _context91.a(2);}},_callee91,this);}));function createStreamRun(_x185){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 ee.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"},y,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"},y,e.text)],role:"user"};}}]);}(k);ot.POLLING_TIMEOUT_MS=500;var Xs=ot;var cn=/*#__PURE__*/function(_Xs){function cn(e){var _a$headers,_l$OpenAIBeta;var _this37;_classCallCheck(this,cn);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=cn.buildUrlSegments(i);if(_this37=_callSuper(this,cn,[e,i,n,G.buildKeyVerificationDetails(),G.buildHeaders,s]),(_a$headers=(a=_this37.connectSettings).headers)!==null&&_a$headers!==void 0?_a$headers:a.headers={},(_l$OpenAIBeta=(l=_this37.connectSettings.headers)["OpenAI-Beta"])!==null&&_l$OpenAIBeta!==void 0?_l$OpenAIBeta:l["OpenAI-Beta"]="assistants=v2",_this37.shouldFetchHistory&&_this37.sessionId&&(_this37.fetchHistory=_this37.fetchHistoryFunc.bind(_assertThisInitialized(_this37))),_typeof(i)===T){var _ref57=(d=(c=e.directConnection)==null?void 0:c.openAI)==null?void 0:d.assistant,u=_ref57.function_handler,h=_ref57.files_tool_type;u&&(_this37.functionHandler=u),h&&(_this37.filesToolType=h);}return _this37;}_inherits(cn,_Xs);return _createClass(cn,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},R,N);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(e){return{url:"".concat(e.endpoint,"/openai/models?api-version=").concat(e.version),method:z,handleVerificationResult:G.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 Pt=/*#__PURE__*/function(_Xs2){function Pt(e){var _g$headers;var _this38;_classCallCheck(this,Pt);var c,d,u,h,f,m,p,g;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.azure,i=(c=t.azure)==null?void 0:c.openAI,n=(i==null?void 0:i.urlDetails)||{},o="".concat((d=i==null?void 0:i.urlDetails)==null?void 0:d.endpoint,"/openai/"),a="?api-version=".concat((u=i==null?void 0:i.urlDetails)==null?void 0:u.version),l={threadsPrefix:"".concat(o).concat(Pt.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(Pt.NEW_ASSISTANT_RESOURCE).concat(a),createMessagePostfix:a,listMessagesPostfix:"order=desc&api-version=".concat((h=i==null?void 0:i.urlDetails)==null?void 0:h.version),storeFiles:"".concat(o,"files").concat(a),getFilesPrefix:"".concat(o,"files/"),getFilesPostfix:"/content".concat(a)};if(_this38=_callSuper(this,Pt,[e,i==null?void 0:i.assistant,l,Ce.buildKeyVerificationDetails(n),Ce.buildHeaders,s]),_this38.permittedErrorPrefixes=[Ce.URL_DETAILS_ERROR_MESSAGE],_this38.insertKeyPlaceholderText=_this38.genereteAPIKeyName("Azure OpenAI"),_this38.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",_this38.isTextInputDisabled=!1,_typeof(i==null?void 0:i.assistant)===T){var _ref59=(p=(m=(f=e.directConnection)==null?void 0:f.azure)==null?void 0:m.openAI)==null?void 0:p.assistant,E=_ref59.function_handler,I=_ref59.files_tool_type;E&&(_this38.functionHandler=E),I&&(_this38.filesToolType=I);}Ce.validateURLDetails(n)?(_g$headers=(g=_this38.connectSettings).headers)!==null&&_g$headers!==void 0?_g$headers:g.headers={}:(_this38.isTextInputDisabled=!0,_this38.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},je,Ce.URL_DETAILS_ERROR_MESSAGE));}));return _this38;}_inherits(Pt,_Xs2);return _createClass(Pt);}(Xs);Pt.THREAD_RESOURCE="threads",Pt.NEW_ASSISTANT_RESOURCE="assistants";var qi=Pt;var q=/*#__PURE__*/function(){function q(){_classCallCheck(this,q);}return _createClass(q,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){q.removeAriaBusy(e),q.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 He=be;var us=/*#__PURE__*/function(){function us(){_classCallCheck(this,us);}return _createClass(us,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return _defineProperty({svg:e.find(function(t){return t.tagName.toLowerCase()==="svg";})},y,e.find(function(t){return t.tagName.toLowerCase()==="div";}));}}]);}();var $=/*#__PURE__*/function(){function $(){_classCallCheck(this,$);}return _createClass($,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var n,o;t.container&&U.unsetAllCSSMouseStates(e,t.container);var _us$parseSVGTextEleme=us.parseSVGTextElements(Array.from(e.children)),s=_us$parseSVGTextEleme.svg,i=_us$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 _us$parseSVGTextEleme2=us.parseSVGTextElements(Array.from(e.children)),s=_us$parseSVGTextEleme2.svg,i=_us$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 _us$parseSVGTextEleme3=us.parseSVGTextElements(Array.from(e.children)),i=_us$parseSVGTextEleme3.svg,n=_us$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){$.setElementsCSS(e,t,"default"),s!=="default"&&($.setElementsCSS(e,t,"hover"),s!=="hover"&&$.setElementsCSS(e,t,"click"));}}]);}();var It=/*#__PURE__*/function(){// prettier-ignore
|
182
182
|
function It(e,t,s,i,n,o){_classCallCheck(this,It);this._mouseState={state:"default"},this.isCustom=!1,q.addAttributes(e),this.elementRef=e,this.svg=Qe.createSVGElement(t),this.customStyles=n,this.position=s,this._tooltipSettings=i,this.dropupText=o;}return _createClass(It,[{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&&($.unsetAllCSS(this.elementRef,e),$.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&&$.setElementsCSS(this.elementRef,e,"hover");}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&$.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state="click",e&&$.setElementsCSS(this.elementRef,e,"click");}// be careful not to use onclick as that is used for button functionality
|
183
|
-
},{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&&$.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&&$.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)),He.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=He.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 vi=/*#__PURE__*/function(_It){function vi(e){var
|
184
|
-
},{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 _i=/*#__PURE__*/_createClass(function _i(){_classCallCheck(this,_i);});_i.SESSION_STARTED="sts-session-started",_i.SESSION_STOPPED="sts-session-stopped";var Zs=_i;var wr="<?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>",Vi="<?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(_k6){function O(e){var _c$model;var
|
183
|
+
},{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&&$.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&&$.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)),He.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=He.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 vi=/*#__PURE__*/function(_It){function vi(e){var _this39;_classCallCheck(this,vi);var s,i;var t=((i=(s=e==null?void 0:e["default"])==null?void 0:s.svg)==null?void 0:i.content)||vi.EMPTY_SVG;_this39=_callSuper(this,vi,[document.createElement("div"),t,void 0,void 0,e]),_this39.isActive=!1,_this39._innerElements=_this39.createInnerElementsForStates(_this39.customStyles),_this39.changeToDefault();return _this39;}_inherits(vi,_It);return _createClass(vi,[{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 He.createCustomElements(e,this.svg,t)||[this.svg];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef.classList.replace(He.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&&$.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(s=this.customStyles)!=null&&s.unavailable&&$.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&&$.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t.active),(s=this.customStyles)!=null&&s["default"]&&$.unsetAllCSS(this.elementRef,(i=this.customStyles)==null?void 0:i["default"]),this.reapplyStateStyle("unavailable",["default","active"]),this.isActive=!1;}}]);}(It);vi.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var Ys=vi;var ae=/*#__PURE__*/function(){function ae(){_classCallCheck(this,ae);}return _createClass(ae,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(),ae.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(),ae.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:ae.getObjectValue(i,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,s){var i=ae.getObjectValue(t,s);if(i){var n=_objectSpread(_objectSpread({},i),ae.getObjectValue(e,s)||{});ae.setPropertyValue(e,s,n);}}},{key:"isJson",value:function isJson(e){try{return JSON.stringify(e),!0;}catch(_unused8){return!1;}}// prettier-ignore
|
184
|
+
},{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 _i=/*#__PURE__*/_createClass(function _i(){_classCallCheck(this,_i);});_i.SESSION_STARTED="sts-session-started",_i.SESSION_STOPPED="sts-session-stopped";var Zs=_i;var wr="<?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>",Vi="<?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(_k6){function O(e){var _c$model;var _this40;_classCallCheck(this,O);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=O.getKey(e);_this40=_callSuper(this,O,[e,G.buildKeyVerificationDetails(),G.buildHeaders,{key:s}]),_this40.insertKeyPlaceholderText=_this40.genereteAPIKeyName("OpenAI"),_this40.keyHelpUrl="https://platform.openai.com/account/api-keys",_this40._microphoneButton=null,_this40._toggleButton=null,_this40._errorElement=null,_this40._loadingElement=null,_this40._pc=null,_this40._mediaStream=null,_this40._isMuted=!1;var i=(n=t.openAI)==null?void 0:n.realtime;if(_typeof(i)===T){_this40._avatarConfig=i.avatar,_this40._ephemeralKey=i.ephemeralKey,_this40._errorConfig=i.error,_this40._loadingConfig=i.loading,Object.assign(_this40.rawBody,i.config);var d=(a=(o=e.directConnection)==null?void 0:o.openAI)==null?void 0:a.realtime,_ref61=d.config||{},u=_ref61.function_handler;u&&(_this40._functionHandler=u),_this40._events=i.events,d.methods=_this40.generateMethods(),_this40.setInputAudioTranscribe(e,(l=d.config)==null?void 0:l.input_audio_transcription);}(_c$model=(c=_this40.rawBody).model)!==null&&_c$model!==void 0?_c$model:c.model="gpt-4o-realtime-preview-2025-06-03",_this40._avatarConfig=O.buildAvatarConfig(i),_this40._buttonsConfig=O.buildButtonsConfig(i),_this40._avatarEl=O.createAvatar(_this40._avatarConfig),_this40._containerEl=_this40.createContainer(),_this40._deepChat=e;return _this40;}_inherits(O,_k6);return _createClass(O,[{key:"setInputAudioTranscribe",value:// https://community.openai.com/t/unable-to-access-user-audio-transcript-in-realtime-api/1001570/3
|
185
185
|
function setInputAudioTranscribe(e,t){if(t){var _s3="whisper-1";_typeof(t)=="object"?this.rawBody.input_audio_transcription={model:t.model||_s3,language:t.language,prompt:t.prompt}:this.rawBody.input_audio_transcription={model:_s3};}else e.onMessage&&(console.warn("To get user audio transcription, set `input_audio_transcription` in the `realtime` config."),console.warn("See: https://deepchat.dev/docs/directConnection/OpenAI/OpenAIRealtime#OpenAIRealtimeConfig"));}// called after API key was inserted
|
186
|
-
},{key:"setUpView",value: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 _callee92(){var i,e,t,s;return _regenerator().w(function(_context92){while(1)switch(_context92.n){case 0:e=(i=this._deepChat.directConnection)==null?void 0:i.openAI;if(e){_context92.n=1;break;}return _context92.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context92.n=2;break;}return _context92.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 _context92.a(2);}},_callee92,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(e){var o,t,s,i,n,a,_t30,_t31,_t32;return _regenerator().w(function(_context93){while(1)switch(_context93.p=_context93.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")){_context93.n=8;break;}if(this._ephemeralKey){_context93.n=7;break;}_context93.p=1;if(!s){_context93.n=3;break;}a=s();a.then&&(this._retrievingEphemeralKey=a);_context93.n=2;return a;case 2:this._ephemeralKey=_context93.v;_context93.n=5;break;case 3:_t30=n;if(!_t30){_context93.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(n);_context93.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context93.v;case 5:_context93.n=7;break;case 6:_context93.p=6;_t31=_context93.v;this.displayFailedToRetrieveEphemeralKey(_t31);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context93.n=12;break;case 8:if(!n){_context93.n=12;break;}_context93.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(n);_context93.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context93.v;e&&this.init(this._ephemeralKey);_context93.n=12;break;case 11:_context93.p=11;_t32=_context93.v;this.displayFailedToRetrieveEphemeralKey(_t32);case 12:return _context93.a(2);}},_callee93,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x186){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(e){return _regenerator().w(function(_context94){while(1)switch(_context94.n){case 0:_context94.n=1;return fetch("https://api.openai.com/v1/realtime/sessions",{method:Z,body:JSON.stringify(this.rawBody),headers:_defineProperty(_defineProperty({},R,N),K,"".concat(se).concat(e))});case 1:_context94.n=2;return _context94.v.json();case 2:return _context94.a(2,_context94.v.client_secret.value);}},_callee94,this);}));function getEphemeralKey(_x187){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),q.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 _callee95(){var s,i,_t33,_t34;return _regenerator().w(function(_context95){while(1)switch(_context95.p=_context95.n){case 0:if(!e.isActive){_context95.n=1;break;}e.changeToDefault(),_this42.stop();_context95.n=9;break;case 1:_context95.p=1;if(!_this42._ephemeralKey){_context95.n=3;break;}_this42.displayLoading();_context95.n=2;return _this42.init(_this42._ephemeralKey);case 2:_context95.n=7;break;case 3:if(!_this42._retrievingEphemeralKey){_context95.n=6;break;}_this42.displayLoading();_context95.n=4;return _this42._retrievingEphemeralKey;case 4:i=_context95.v;_t33=(s=_this42._toggleButton)!=null&&s.isActive;if(!_t33){_context95.n=5;break;}_context95.n=5;return _this42.init(i);case 5:_context95.n=7;break;case 6:_this42.displayLoading();_context95.n=7;return _this42.fetchEphemeralKey(!0);case 7:_context95.n=9;break;case 8:_context95.p=8;_t34=_context95.v;console.error("Failed to start conversation:",_t34),_this42.displayError(),_this42.hideLoading();case 9:return _context95.a(2);}},_callee95,null,[[1,8]]);})),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(e){var _this43=this;var t,s,i,n,o,a,l,c,_t37,_t38,_t39,_t40;return _regenerator().w(function(_context98){while(1)switch(_context98.p=_context98.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 _ref63=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(a){var l,_t35;return _regenerator().w(function(_context96){while(1)switch(_context96.n){case 0:if(!a.streams[0]){_context96.n=2;break;}s.srcObject=a.streams[0];l=i.createMediaStreamSource(a.streams[0]);_t35=i.state==="suspended";if(!_t35){_context96.n=1;break;}_context96.n=1;return i.resume();case 1:l.connect(n);_this43.monitorFrequencies(n,o);_context96.n=3;break;case 2:console.error("No streams found in the ontrack event."),_this43.displayError();case 3:return _context96.a(2);}},_callee96);}));return function(_x189){return _ref63.apply(this,arguments);};}();_context98.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 _ref64=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(a){var c,d,u,l,f,m,p,_t36;return _regenerator().w(function(_context97){while(1)switch(_context97.p=_context97.n){case 0:l=JSON.parse(a.data);if(!(l.type==="session.created")){_context97.n=1;break;}_this43.removeUnavailable(),_this43._toggleButton&&(q.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();_context97.n=7;break;case 1:if(!(l.type==="response.done")){_context97.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")){_context97.n=5;break;}m=f.name,p=f.call_id;_context97.p=2;_context97.n=3;return _this43.handleTool(m,f.arguments,p);case 3:_context97.n=5;break;case 4:_context97.p=4;_t36=_context97.v;_this43.stopOnError(_t36);case 5:_context97.n=7;break;case 6:l.type===je?_this43.stopOnError(l.error.message):l.type===we?_this43.stopOnError(l.message):l.type==="response.audio_transcript.delta"||(l.type==="response.audio_transcript.done"?l.transcript&&Ct.onMessage(_this43._deepChat,{role:"ai",text:l.transcript},!1):l.type==="conversation.item.input_audio_transcription.completed"&&l.transcript&&Ct.onMessage(_this43._deepChat,{role:"user",text:l.transcript},!1));case 7:return _context97.a(2);}},_callee97,null,[[2,4]]);}));return function(_x190){return _ref64.apply(this,arguments);};}());_context98.p=2;_context98.n=3;return this._pc.createOffer();case 3:a=_context98.v;_t37=t!==this._pc;if(_t37){_context98.n=5;break;}_context98.n=4;return this._pc.setLocalDescription(a);case 4:_t37=t!==this._pc;case 5:if(!_t37){_context98.n=6;break;}return _context98.a(2);case 6:_context98.n=7;return fetch("https://api.openai.com/v1/realtime",{method:Z,body:a.sdp,headers:_defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,"application/sdp")});case 7:l=_context98.v;if(!(t!==this._pc)){_context98.n=8;break;}return _context98.a(2);case 8:_context98.n=9;return l.text();case 9:_t38=_context98.v;c={type:"answer",sdp:_t38};_t39=t!==this._pc;if(_t39){_context98.n=11;break;}_context98.n=10;return this._pc.setRemoteDescription(c);case 10:_t39=t!==this._pc;case 11:if(!_t39){_context98.n=12;break;}return _context98.a(2);case 12:_context98.n=14;break;case 13:_context98.p=13;_t40=_context98.v;console.error(_t40),this.displayError();case 14:return _context98.a(2);}},_callee98,this,[[2,13]]);}));function init(_x188){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
|
186
|
+
},{key:"setUpView",value: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 _callee92(){var i,e,t,s;return _regenerator().w(function(_context92){while(1)switch(_context92.n){case 0:e=(i=this._deepChat.directConnection)==null?void 0:i.openAI;if(e){_context92.n=1;break;}return _context92.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context92.n=2;break;}return _context92.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 _context92.a(2);}},_callee92,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(e){var o,t,s,i,n,a,_t30,_t31,_t32;return _regenerator().w(function(_context93){while(1)switch(_context93.p=_context93.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")){_context93.n=8;break;}if(this._ephemeralKey){_context93.n=7;break;}_context93.p=1;if(!s){_context93.n=3;break;}a=s();a.then&&(this._retrievingEphemeralKey=a);_context93.n=2;return a;case 2:this._ephemeralKey=_context93.v;_context93.n=5;break;case 3:_t30=n;if(!_t30){_context93.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(n);_context93.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context93.v;case 5:_context93.n=7;break;case 6:_context93.p=6;_t31=_context93.v;this.displayFailedToRetrieveEphemeralKey(_t31);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context93.n=12;break;case 8:if(!n){_context93.n=12;break;}_context93.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(n);_context93.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context93.v;e&&this.init(this._ephemeralKey);_context93.n=12;break;case 11:_context93.p=11;_t32=_context93.v;this.displayFailedToRetrieveEphemeralKey(_t32);case 12:return _context93.a(2);}},_callee93,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x186){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(e){return _regenerator().w(function(_context94){while(1)switch(_context94.n){case 0:_context94.n=1;return fetch("https://api.openai.com/v1/realtime/sessions",{method:Z,body:JSON.stringify(this.rawBody),headers:_defineProperty(_defineProperty({},R,N),K,"".concat(se).concat(e))});case 1:_context94.n=2;return _context94.v.json();case 2:return _context94.a(2,_context94.v.client_secret.value);}},_callee94,this);}));function getEphemeralKey(_x187){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this41=this;return{updateConfig:function updateConfig(e){var t;(t=_this41._dc)==null||t.send(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}]};_this41.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 _this42=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?(_this42.toggleMicorphone(!0),e.elementRef.classList.replace(O.MICROPHONE_ACTIVE,O.BUTTON_DEFAULT),e.changeToDefault(),_this42._isMuted=!1):(_this42.toggleMicorphone(!1),e.elementRef.classList.replace(O.BUTTON_DEFAULT,O.MICROPHONE_ACTIVE),q.removeAriaAttributes(e.elementRef),e.changeToActive(),_this42._isMuted=!0);},e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(s){return s.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this43=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 _callee95(){var s,i,_t33,_t34;return _regenerator().w(function(_context95){while(1)switch(_context95.p=_context95.n){case 0:if(!e.isActive){_context95.n=1;break;}e.changeToDefault(),_this43.stop();_context95.n=9;break;case 1:_context95.p=1;if(!_this43._ephemeralKey){_context95.n=3;break;}_this43.displayLoading();_context95.n=2;return _this43.init(_this43._ephemeralKey);case 2:_context95.n=7;break;case 3:if(!_this43._retrievingEphemeralKey){_context95.n=6;break;}_this43.displayLoading();_context95.n=4;return _this43._retrievingEphemeralKey;case 4:i=_context95.v;_t33=(s=_this43._toggleButton)!=null&&s.isActive;if(!_t33){_context95.n=5;break;}_context95.n=5;return _this43.init(i);case 5:_context95.n=7;break;case 6:_this43.displayLoading();_context95.n=7;return _this43.fetchEphemeralKey(!0);case 7:_context95.n=9;break;case 8:_context95.p=8;_t34=_context95.v;console.error("Failed to start conversation:",_t34),_this43.displayError(),_this43.hideLoading();case 9:return _context95.a(2);}},_callee95,null,[[1,8]]);})),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(e){var _this44=this;var t,s,i,n,o,a,l,c,_t37,_t38,_t39,_t40;return _regenerator().w(function(_context98){while(1)switch(_context98.p=_context98.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 _ref63=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(a){var l,_t35;return _regenerator().w(function(_context96){while(1)switch(_context96.n){case 0:if(!a.streams[0]){_context96.n=2;break;}s.srcObject=a.streams[0];l=i.createMediaStreamSource(a.streams[0]);_t35=i.state==="suspended";if(!_t35){_context96.n=1;break;}_context96.n=1;return i.resume();case 1:l.connect(n);_this44.monitorFrequencies(n,o);_context96.n=3;break;case 2:console.error("No streams found in the ontrack event."),_this44.displayError();case 3:return _context96.a(2);}},_callee96);}));return function(_x189){return _ref63.apply(this,arguments);};}();_context98.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var l;t===_this44._pc&&(_this44._mediaStream=a,(l=_this44._pc)==null||l.addTrack(_this44._mediaStream.getTracks()[0]),_this44._isMuted&&_this44.toggleMicorphone(!1));})["catch"](function(a){console.error("Error accessing microphone:",a),_this44.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref64=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(a){var c,d,u,l,f,m,p,_t36;return _regenerator().w(function(_context97){while(1)switch(_context97.p=_context97.n){case 0:l=JSON.parse(a.data);if(!(l.type==="session.created")){_context97.n=1;break;}_this44.removeUnavailable(),_this44._toggleButton&&(q.removeAriaAttributes(_this44._toggleButton.elementRef),_this44._toggleButton.changeToActive()),(d=(c=_this44._events)==null?void 0:c.started)==null||d.call(c),_this44._deepChat.dispatchEvent(new CustomEvent(Zs.SESSION_STARTED)),_this44.hideLoading();_context97.n=7;break;case 1:if(!(l.type==="response.done")){_context97.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")){_context97.n=5;break;}m=f.name,p=f.call_id;_context97.p=2;_context97.n=3;return _this44.handleTool(m,f.arguments,p);case 3:_context97.n=5;break;case 4:_context97.p=4;_t36=_context97.v;_this44.stopOnError(_t36);case 5:_context97.n=7;break;case 6:l.type===je?_this44.stopOnError(l.error.message):l.type===we?_this44.stopOnError(l.message):l.type==="response.audio_transcript.delta"||(l.type==="response.audio_transcript.done"?l.transcript&&Ct.onMessage(_this44._deepChat,{role:"ai",text:l.transcript},!1):l.type==="conversation.item.input_audio_transcription.completed"&&l.transcript&&Ct.onMessage(_this44._deepChat,{role:"user",text:l.transcript},!1));case 7:return _context97.a(2);}},_callee97,null,[[2,4]]);}));return function(_x190){return _ref64.apply(this,arguments);};}());_context98.p=2;_context98.n=3;return this._pc.createOffer();case 3:a=_context98.v;_t37=t!==this._pc;if(_t37){_context98.n=5;break;}_context98.n=4;return this._pc.setLocalDescription(a);case 4:_t37=t!==this._pc;case 5:if(!_t37){_context98.n=6;break;}return _context98.a(2);case 6:_context98.n=7;return fetch("https://api.openai.com/v1/realtime",{method:Z,body:a.sdp,headers:_defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,"application/sdp")});case 7:l=_context98.v;if(!(t!==this._pc)){_context98.n=8;break;}return _context98.a(2);case 8:_context98.n=9;return l.text();case 9:_t38=_context98.v;c={type:"answer",sdp:_t38};_t39=t!==this._pc;if(_t39){_context98.n=11;break;}_context98.n=10;return this._pc.setRemoteDescription(c);case 10:_t39=t!==this._pc;case 11:if(!_t39){_context98.n=12;break;}return _context98.a(2);case 12:_context98.n=14;break;case 13:_context98.p=13;_t40=_context98.v;console.error(_t40),this.displayError();case 14:return _context98.a(2);}},_callee98,this,[[2,13]]);}));function init(_x188){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
|
187
187
|
// in such instance please wait and refresh at a later time
|
188
|
-
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var
|
188
|
+
},{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this45=this;var s=function(_s4){function s(){return _s4.apply(this,arguments);}s.toString=function(){return _s4.toString();};return s;}(function(){var c;e.getByteFrequencyData(t);var i=t.reduce(function(d,u){return d+u;},0),n=t.length*255,o=i/n*100,a=1,l=a+o/100*(((c=_this45._avatarConfig)==null?void 0:c.maxScale)-a);_this45._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),q.removeAriaDisabled(this._toggleButton.elementRef),q.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),q.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement.style.display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
|
189
189
|
},{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t,s){var i,n;return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:if(this._functionHandler){_context99.n=1;break;}throw Error(b.DEFINE_FUNCTION_HANDLER);case 1:_context99.n=2;return this._functionHandler({name:e,arguments:t});case 2:i=_context99.v;if(!(_typeof(i)!="object"||!ae.isJson(i))){_context99.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 _context99.a(2);}},_callee99,this);}));function handleTool(_x191,_x192,_x193){return _handleTool.apply(this,arguments);}return handleTool;}()// https://platform.openai.com/docs/api-reference/realtime-client-events/conversation/item/create
|
190
|
-
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify({type:"conversation.item.create",item:e});this._dc.send(t);var s={type:"response.create"};this._dc.send(JSON.stringify(s));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var s=t==null?void 0:t.realtime;if(_typeof(s)=="object"&&(s.ephemeralKey||s.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?JSON.parse(JSON.stringify(e.avatar)):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$microphone,_o$default,_a$svg,_l$content,_t$toggle,_h$default,_f$svg,_m$content,_p$active,_g$svg,_E$content;var s,i,n,o,a,l,c,d,u,h,f,m,p,g,E;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),(u=(d=(c=t.toggle)==null?void 0:c["default"])==null?void 0:d.text)!=null&&u.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_h$default=(h=t.toggle)["default"])!==null&&_h$default!==void 0?_h$default:h["default"]={},(_f$svg=(f=t.toggle["default"]).svg)!==null&&_f$svg!==void 0?_f$svg:f.svg={},(_m$content=(m=t.toggle["default"].svg).content)!==null&&_m$content!==void 0?_m$content:m.content=wr,(_p$active=(p=t.toggle).active)!==null&&_p$active!==void 0?_p$active:p.active={},(_g$svg=(g=t.toggle.active).svg)!==null&&_g$svg!==void 0?_g$svg:g.svg={},(_E$content=(E=t.toggle.active.svg).content)!==null&&_E$content!==void 0?_E$content:E.content=Vi),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)||Fi,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),q.removeAriaBusy(e.elementRef),q.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){O.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){q.removeAriaDisabled(e.elementRef),e.elementRef.classList.remove(O.UNAVAILABLE);}}]);}(k);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 Gi=O;var Dt=/*#__PURE__*/function(_k7){function Dt(e){var _o$model3,_a$voice3;var
|
190
|
+
},{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify({type:"conversation.item.create",item:e});this._dc.send(t);var s={type:"response.create"};this._dc.send(JSON.stringify(s));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var s=t==null?void 0:t.realtime;if(_typeof(s)=="object"&&(s.ephemeralKey||s.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?JSON.parse(JSON.stringify(e.avatar)):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$microphone,_o$default,_a$svg,_l$content,_t$toggle,_h$default,_f$svg,_m$content,_p$active,_g$svg,_E$content;var s,i,n,o,a,l,c,d,u,h,f,m,p,g,E;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),(u=(d=(c=t.toggle)==null?void 0:c["default"])==null?void 0:d.text)!=null&&u.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_h$default=(h=t.toggle)["default"])!==null&&_h$default!==void 0?_h$default:h["default"]={},(_f$svg=(f=t.toggle["default"]).svg)!==null&&_f$svg!==void 0?_f$svg:f.svg={},(_m$content=(m=t.toggle["default"].svg).content)!==null&&_m$content!==void 0?_m$content:m.content=wr,(_p$active=(p=t.toggle).active)!==null&&_p$active!==void 0?_p$active:p.active={},(_g$svg=(g=t.toggle.active).svg)!==null&&_g$svg!==void 0?_g$svg:g.svg={},(_E$content=(E=t.toggle.active.svg).content)!==null&&_E$content!==void 0?_E$content:E.content=Vi),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)||Fi,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),q.removeAriaBusy(e.elementRef),q.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){O.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){q.removeAriaDisabled(e.elementRef),e.elementRef.classList.remove(O.UNAVAILABLE);}}]);}(k);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 Gi=O;var Dt=/*#__PURE__*/function(_k7){function Dt(e){var _o$model3,_a$voice3;var _this46;_classCallCheck(this,Dt);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this46=_callSuper(this,Dt,[e,G.buildKeyVerificationDetails(),G.buildHeaders,s]),_this46.insertKeyPlaceholderText=_this46.genereteAPIKeyName("OpenAI"),_this46.keyHelpUrl="https://platform.openai.com/account/api-keys",_this46.url="https://api.openai.com/v1/audio/speech",_this46.permittedErrorPrefixes=[ht],_this46.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)===T&&Object.assign(_this46.rawBody,i),(_o$model3=(o=_this46.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=Dt.DEFAULT_MODEL,(_a$voice3=(a=_this46.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=Dt.DEFAULT_VOIDE,_this46.textInputPlaceholderText="Insert text to generate audio",_this46.rawBody.response_format="mp3";return _this46;}_inherits(Dt,_k7);return _createClass(Dt,[{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 _callee100(e,t){return _regenerator().w(function(_context100){while(1)switch(_context100.n){case 0:this.url=this.connectSettings.url||this.url,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context100.a(2);}},_callee100,this);}));function callServiceAPI(_x194,_x195){return _callServiceAPI10.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e){return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if(!(e instanceof Blob)){_context101.n=1;break;}return _context101.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){_context101.n=2;break;}throw e.error.message;case 2:return _context101.a(2,_defineProperty({},je,je));}},_callee101);}));function extractResultData(_x196){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(k);Dt.DEFAULT_MODEL="tts-1",Dt.DEFAULT_VOIDE="alloy";var Ki=Dt;var Re=/*#__PURE__*/function(_k8){function Re(e){var _o$model4;var _this47;_classCallCheck(this,Re);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this47=_callSuper(this,Re,[e,G.buildKeyVerificationDetails(),G.buildHeaders,s,{audio:{}}]),_this47.insertKeyPlaceholderText=_this47.genereteAPIKeyName("OpenAI"),_this47.keyHelpUrl="https://platform.openai.com/account/api-keys",_this47.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>",_this47.url="",_this47.permittedErrorPrefixes=[ht],_this47.textInputPlaceholderText=rn,_this47._service_url=Re.AUDIO_TRANSCRIPTIONS_URL;var i=(n=t==null?void 0:t.openAI)==null?void 0:n.audio;_typeof(i)=="object"&&(_this47.processConfig(i),Re.cleanConfig(i),Object.assign(_this47.rawBody,i)),(_o$model4=(o=_this47.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=Re.DEFAULT_MODEL,_this47.rawBody.response_format="json",_this47.canSendMessage=Re.canSendFileMessage;return _this47;}_inherits(Re,_k8);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
|
191
191
|
},{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(e,t,s){var o,i,n;return _regenerator().w(function(_context102){while(1)switch(_context102.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context102.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(s!=null&&s[0]){_context102.n=2;break;}throw new Error(b.NO_FILE_ADDED_ERROR);case 2:this.url=this.connectSettings.url||this._service_url;i=this.preprocessBody(this.rawBody,t),n=Re.createFormDataBody(i,s[0]);w.tempRemoveContentHeader(this.connectSettings,V.request.bind(this,this,n,e),!1);case 3:return _context102.a(2);}},_callee102,this);}));function callServiceAPI(_x197,_x198,_x199){return _callServiceAPI11.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103(e){return _regenerator().w(function(_context103){while(1)switch(_context103.n){case 0:if(!e.error){_context103.n=1;break;}throw e.error.message;case 1:return _context103.a(2,_defineProperty({},y,e.text));}},_callee103);}));function extractResultData(_x200){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;}}]);}(k);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 zi=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),R,"application/ssml+xml"),"X-Microsoft-OutputFormat",e);}},{key:"buildSpeechToTextHeaders",value:function buildSpeechToTextHeaders(e){return _defineProperty(_defineProperty({},ve.SUBSCRIPTION_KEY_NAME,e),"Accept",N);}// prettier-ignore
|
192
192
|
},{key:"handleSpeechVerificationResult",value:function handleSpeechVerificationResult(e,t,s,i){e.error?i(b.INVALID_KEY):s(t);}},{key:"buildSpeechKeyVerificationDetails",value:function buildSpeechKeyVerificationDetails(e){return{url:"https://".concat(e,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:Z,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),R,N);}// prettier-ignore
|
193
193
|
},{key:"handleLanguageVerificationResult",value:function handleLanguageVerificationResult(e,t,s,i){var o;((o=e.error)==null?void 0:o.code)==="401"?i(b.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:Z,createHeaders:function createHeaders(t){return _defineProperty({},ve.SUBSCRIPTION_KEY_NAME,"".concat(t));},handleVerificationResult:ve.handleLanguageVerificationResult};}// prettier-ignore
|
194
194
|
},{key:"handleTranslationVerificationResult",value:function handleTranslationVerificationResult(e,t,s,i){e.json().then(function(o){!Array.isArray(o)&&o.error.code===401e3?i(b.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:Z,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),R,N);return e&&(s["Ocp-Apim-Subscription-Region"]=e),s;}}]);}();ve.SUBSCRIPTION_KEY_NAME="Ocp-Apim-Subscription-Key";var tt=ve;var $a=/*#__PURE__*/function(_k9){// prettier-ignore
|
195
|
-
function $a(e,t,s,i,n){var
|
196
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",
|
195
|
+
function $a(e,t,s,i,n){var _this48;_classCallCheck(this,$a);_this48=_callSuper(this,$a,[e,tt.buildLanguageKeyVerificationDetails(s),t,i,n]),_this48.insertKeyPlaceholderText="Azure Language Subscription Key",_this48.keyHelpUrl=// eslint-disable-next-line max-len
|
196
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this48.permittedErrorPrefixes=["Access"];return _this48;}_inherits($a,_k9);return _createClass($a);}(k);var vs=/*#__PURE__*/function(_$a){function vs(e){var _a$language;var _this49;_classCallCheck(this,vs);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;_this49=_callSuper(this,vs,[e,tt.buildSummarizationHeader,t.endpoint,s]),_this49.permittedErrorPrefixes=[vs.ENDPOINT_ERROR_MESSAGE],_this49.url="",_this49.textInputPlaceholderText="Insert text to summarize",_this49.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this49.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this49.rawBody,t),_this49.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this49.isTextInputDisabled=!0,_this49.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},je,vs.ENDPOINT_ERROR_MESSAGE));}));return _this49;}_inherits(vs,_$a);return _createClass(vs,[{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},y,s)]},tasks:[{kind:"ExtractiveSummarization"}]};}},{key:"callServiceAPI",value:function(){var _callServiceAPI12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(e,t){return _regenerator().w(function(_context104){while(1)switch(_context104.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)),this.messages=e;case 1:return _context104.a(2);}},_callee104,this);}));function callServiceAPI(_x201,_x202){return _callServiceAPI12.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e){var t,_s6,i;return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:if(!e.error){_context105.n=1;break;}throw e.error.message;case 1:if(this.messages&&this.completionsHandlers){this.asyncCallInProgress=!0;_s6=e.headers.get("operation-location"),i={method:z,headers:(t=this.connectSettings)==null?void 0:t.headers};V.executePollRequest(this,_s6,i,this.messages);}return _context105.a(2,_defineProperty({},y,""));}},_callee105,this);}));function extractResultData(_x203){return _extractResultData15.apply(this,arguments);}return extractResultData;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(e){var t,_iterator,_step,_s7;return _regenerator().w(function(_context106){while(1)switch(_context106.n){case 0:if(!e.error){_context106.n=1;break;}throw e.error;case 1:if(!(e.status==="running"||e.status==="notStarted")){_context106.n=2;break;}return _context106.a(2,{timeoutMS:2e3});case 2:if(!(e.errors.length>0)){_context106.n=3;break;}throw e.errors[0];case 3:if(!(e.tasks.items[0].results.errors.length>0)){_context106.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;){_s7=_step.value;t+=_s7.text;}}catch(err){_iterator.e(err);}finally{_iterator.f();}return _context106.a(2,_defineProperty({},y,t||""));}},_callee106);}));function extractPollResultData(_x204){return _extractPollResultData5.apply(this,arguments);}return extractPollResultData;}()}]);}($a);vs.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
|
197
197
|
"Please define the azure endpoint. [More Information](https://deepchat.dev/docs/directConnection/Azure#Summarization)";var Ji=vs;var fs=/*#__PURE__*/function(){function fs(){_classCallCheck(this,fs);}return _createClass(fs,null,[{key:"poll",value:function(){var _poll2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(e,t){var s,a,l,d,_t41;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:s=_defineProperty(_defineProperty({},Ur,e),Hr,N);_t41="https://api.assemblyai.com/v2/transcript/";_context107.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:Z,body:JSON.stringify({audio_url:t}),headers:s});case 1:_context107.n=2;return _context107.v.json();case 2:a=_t41.concat.call(_t41,_context107.v.id);case 3:if(l){_context107.n=9;break;}_context107.n=4;return fetch(a,{headers:s});case 4:_context107.n=5;return _context107.v.json();case 5:d=_context107.v;if(!(d.status===fr)){_context107.n=6;break;}l=d;_context107.n=8;break;case 6:if(!(d.status===je)){_context107.n=7;break;}throw new Error("Transcription failed: ".concat(d.error));case 7:_context107.n=8;return new Promise(function(u){return setTimeout(u,3e3);});case 8:_context107.n=3;break;case 9:return _context107.a(2,l);}},_callee107);}));function poll(_x205,_x206){return _poll2.apply(this,arguments);}return poll;}()},{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,e),R,"application/octet-stream");}// prettier-ignore
|
198
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.assemblyai.com/v2/upload",method:Z,handleVerificationResult:fs.handleVerificationResult};}}]);}();var dn=/*#__PURE__*/function(_k0){function dn(e){var
|
199
|
-
function Tr(e,t,s,i,n){var
|
200
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal";return
|
201
|
-
function vt(e){var _a$lang,_l$name,_c$gender;var
|
198
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.code==="invalid_api_key"?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.assemblyai.com/v2/upload",method:Z,handleVerificationResult:fs.handleVerificationResult};}}]);}();var dn=/*#__PURE__*/function(_k0){function dn(e){var _this50;_classCallCheck(this,dn);var s;var t=(s=e.directConnection)==null?void 0:s.assemblyAI;_this50=_callSuper(this,dn,[e,fs.buildKeyVerificationDetails(),fs.buildHeaders,t,{audio:{}}]),_this50.insertKeyPlaceholderText=_this50.genereteAPIKeyName("AssemblyAI"),_this50.keyHelpUrl="https://www.assemblyai.com/app/account",_this50.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>",_this50.url="https://api.assemblyai.com/v2/upload",_this50.isTextInputDisabled=!0,_this50.textInputPlaceholderText=rn,_this50.permittedErrorPrefixes=[ur,ht],_this50.canSendMessage=dn.canFileSendMessage;return _this50;}_inherits(dn,_k0);return _createClass(dn,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(e,t,s){var i;return _regenerator().w(function(_context108){while(1)switch(_context108.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context108.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(s!=null&&s[0]){_context108.n=2;break;}throw new Error(b.NO_FILE_ADDED_ERROR);case 2:V.request(this,s[0],e,!1);case 3:return _context108.a(2);}},_callee108,this);}));function callServiceAPI(_x207,_x208,_x209){return _callServiceAPI13.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e){var i,n,t,s;return _regenerator().w(function(_context109){while(1)switch(_context109.n){case 0:if(!e.error){_context109.n=1;break;}throw e.error;case 1:t=(n=(i=this.connectSettings)==null?void 0:i.headers)==null?void 0:n[K];_context109.n=2;return fs.poll(t,e.upload_url);case 2:s=_context109.v;return _context109.a(2,_defineProperty({},y,s.text));}},_callee109,this);}));function extractResultData(_x210){return _extractResultData16.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(k);var Tr=/*#__PURE__*/function(_k1){// prettier-ignore
|
199
|
+
function Tr(e,t,s,i,n){var _this51;_classCallCheck(this,Tr);_this51=_callSuper(this,Tr,[e,tt.buildSpeechKeyVerificationDetails(s),t,i,n]),_this51.insertKeyPlaceholderText="Azure Speech Subscription Key",_this51.keyHelpUrl=// eslint-disable-next-line max-len
|
200
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal";return _this51;}_inherits(Tr,_k1);return _createClass(Tr);}(k);var vt=/*#__PURE__*/function(_Tr){// prettier-ignore
|
201
|
+
function vt(e){var _a$lang,_l$name,_c$gender;var _this52;_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;_this52=_callSuper(this,vt,[e,tt.buildTextToSpeechHeaders.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,s]),_this52.permittedErrorPrefixes=[vt.REGION_ERROR_MESSAGE],_this52.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>"),_this52.isTextInputDisabled=!1,_this52.url="",t.region?(Object.assign(_this52.rawBody,t),(_a$lang=(a=_this52.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_l$name=(l=_this52.rawBody).name)!==null&&_l$name!==void 0?_l$name:l.name="en-US-JennyNeural",(_c$gender=(c=_this52.rawBody).gender)!==null&&_c$gender!==void 0?_c$gender:c.gender="Female",_this52.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this52.isTextInputDisabled=!0,_this52.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},je,vt.REGION_ERROR_MESSAGE));}));return _this52;}_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 _callee110(e,t){return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),void 0,!1);case 1:return _context110.a(2);}},_callee110,this);}));function callServiceAPI(_x211,_x212){return _callServiceAPI14.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e){return _regenerator().w(function(_context111){while(1)switch(_context111.n){case 0:return _context111.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"}]});};}));}},_callee111);}));function extractResultData(_x213){return _extractResultData17.apply(this,arguments);}return extractResultData;}()}]);}(Tr);vt.HELP_LINK=// eslint-disable-next-line max-len
|
202
202
|
"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
|
203
|
-
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#TextToSpeech)";var $i=vt;var at=/*#__PURE__*/function(_Tr2){function at(e){var
|
203
|
+
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#TextToSpeech)";var $i=vt;var at=/*#__PURE__*/function(_Tr2){function at(e){var _this53;_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(_this53=_callSuper(this,at,[e,tt.buildSpeechToTextHeaders,t.region,s,i]),_this53.permittedErrorPrefixes=[at.REGION_ERROR_MESSAGE],_this53.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>"),_this53.url="",_this53.isTextInputDisabled=!0,_this53.textInputPlaceholderText=rn,!t.region)_this53.isTextInputDisabled=!0,_this53.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},je,at.REGION_ERROR_MESSAGE));});else{_this53.canSendMessage=at.canFileSendMessage;var l=t.lang||"en-US";_this53.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(l,"&format=detailed"),_this53.recordAudio=void 0;}return _this53;}_inherits(at,_Tr2);return _createClass(at,[{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(e,t,s){var i,n;return _regenerator().w(function(_context112){while(1)switch(_context112.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context112.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(s!=null&&s[0]){_context112.n=2;break;}throw new Error(b.NO_FILE_ADDED_ERROR);case 2:(n=this.connectSettings)!=null&&n.headers&&(this.connectSettings.headers[R]=s[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),V.request(this,s[0],e,!1);case 3:return _context112.a(2);}},_callee112,this);}));function callServiceAPI(_x214,_x215,_x216){return _callServiceAPI15.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113(e){return _regenerator().w(function(_context113){while(1)switch(_context113.n){case 0:if(!e.error){_context113.n=1;break;}throw e.error;case 1:return _context113.a(2,_defineProperty({},y,e.DisplayText||""));}},_callee113);}));function extractResultData(_x217){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
|
204
204
|
"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
|
205
205
|
"Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#SpeechToText)";var Wi=at;var Wa=/*#__PURE__*/function(_k10){// prettier-ignore
|
206
|
-
function Wa(e){var
|
207
|
-
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",
|
206
|
+
function Wa(e){var _this54;_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;_this54=_callSuper(this,Wa,[e,tt.buildTranslationKeyVerificationDetails(t.region),tt.buildTranslationHeaders.bind({},t==null?void 0:t.region),s]),_this54.insertKeyPlaceholderText="Azure Translate Subscription Key",_this54.keyHelpUrl=// eslint-disable-next-line max-len
|
207
|
+
"https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this54.url="",_this54.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this54;}_inherits(Wa,_k10);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 _callee114(e,t){return _regenerator().w(function(_context114){while(1)switch(_context114.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context114.a(2);}},_callee114,this);}));function callServiceAPI(_x218,_x219){return _callServiceAPI16.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(e){var t;return _regenerator().w(function(_context115){while(1)switch(_context115.n){case 0:if(!Array.isArray(e)){_context115.n=1;break;}return _context115.a(2,_defineProperty({},y,((t=e[0].translations)==null?void 0:t[0].text)||""));case 1:throw e.error;case 2:return _context115.a(2);}},_callee115);}));function extractResultData(_x220){return _extractResultData19.apply(this,arguments);}return extractResultData;}()}]);}(k);var Xa=/*#__PURE__*/function(_k11){function Xa(e){var _o$model5;var _this55;_classCallCheck(this,Xa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this55=_callSuper(this,Xa,[e,ct.buildKeyVerificationDetails(),ct.buildHeaders,s]),_this55.insertKeyPlaceholderText=_this55.genereteAPIKeyName("BigModel"),_this55.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this55.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this55.permittedErrorPrefixes=[K,ie];var i=(n=t.bigModel)==null?void 0:n.images;_typeof(i)===T&&(_this55.cleanConfig(i),Object.assign(_this55.rawBody,i)),(_o$model5=(o=_this55.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this55;}_inherits(Xa,_k11);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 _callee116(e,t){return _regenerator().w(function(_context116){while(1)switch(_context116.n){case 0:return _context116.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee116,this);}));function callServiceAPI(_x221,_x222){return _callServiceAPI17.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee117(e){return _regenerator().w(function(_context117){while(1)switch(_context117.n){case 0:return _context117.a(2,{files:e.data.map(function(s){return s!=null&&s.url?{src:s.url,type:"image"}:{src:"",type:"image"};})});}},_callee117);}));function extractResultData(_x223){return _extractResultData20.apply(this,arguments);}return extractResultData;}()}]);}(k);var Ft=/*#__PURE__*/function(){function Ft(){_classCallCheck(this,Ft);}return _createClass(Ft,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},R,N),K,"".concat(se).concat(e));}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.message===sn?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.groq.com/openai/v1/models",method:z,handleVerificationResult:Ft.handleVerificationResult};}}]);}();var Ya=/*#__PURE__*/function(_k12){function Ya(e){var _o$model6,_a$voice4,_l$response_format;var _this56;_classCallCheck(this,Ya);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this56=_callSuper(this,Ya,[e,Ft.buildKeyVerificationDetails(),Ft.buildHeaders,s]),_this56.insertKeyPlaceholderText=_this56.genereteAPIKeyName("Groq"),_this56.keyHelpUrl="https://console.groq.com/keys",_this56.url="https://api.groq.com/openai/v1/audio/speech",_this56.permittedErrorPrefixes=[ht,"property"];var i=(n=t.groq)==null?void 0:n.textToSpeech;_typeof(i)===T&&(_this56.cleanConfig(i),Object.assign(_this56.rawBody,i)),(_o$model6=(o=_this56.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this56.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_l$response_format=(l=_this56.rawBody).response_format)!==null&&_l$response_format!==void 0?_l$response_format:l.response_format="mp3";return _this56;}_inherits(Ya,_k12);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 _callee118(e,t){return _regenerator().w(function(_context118){while(1)switch(_context118.n){case 0:return _context118.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee118,this);}));function callServiceAPI(_x224,_x225){return _callServiceAPI18.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e){var t,s;return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:t=this.rawBody.response_format||"mp3",s=new Blob([e],{type:"audio/".concat(t)});return _context119.a(2,{files:[{src:URL.createObjectURL(s),type:"audio"}]});}},_callee119,this);}));function extractResultData(_x226){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(k);var Za=/*#__PURE__*/function(_k13){function Za(e){var _o$model7;var _this57;_classCallCheck(this,Za);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this57=_callSuper(this,Za,[e,dt.buildKeyVerificationDetails(),dt.buildHeaders,s]),_this57.insertKeyPlaceholderText=_this57.genereteAPIKeyName("Together AI"),_this57.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this57.url="https://api.together.xyz/v1/images/generations",_this57.permittedErrorPrefixes=[we,ie];var i=(n=t.together)==null?void 0:n.images;_typeof(i)===T&&(_this57.cleanConfig(i),Object.assign(_this57.rawBody,i)),(_o$model7=(o=_this57.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this57;}_inherits(Za,_k13);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 _callee120(e,t){return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:return _context120.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee120,this);}));function callServiceAPI(_x227,_x228){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e){return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:return _context121.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"};})});}},_callee121);}));function extractResultData(_x229){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(k);var ws=/*#__PURE__*/function(_k14){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
|
208
208
|
// prettier-ignore
|
209
|
-
function ws(e,t,s,i,n){var
|
210
|
-
// use speech to speech instead
|
211
|
-
// give allowed regex example for audio format rules
|
212
|
-
},{key:"preprocessBody",value:// prettier-ignore
|
213
|
-
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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(a){return{content:ws.getContent(a,i),role:a.role===v.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 _callee122(e,t){var _this$_messages3;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:(_this$_messages3=this._messages)!==null&&_this$_messages3!==void 0?_this$_messages3:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context122.a(2);}},_callee122,this);}));function callServiceAPI(_x230,_x231){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:if(!e.error){_context123.n=1;break;}throw e.error.message;case 1:if(!((i=(s=e.choices)==null?void 0:s[0])!=null&&i.delta)){_context123.n=2;break;}return _context123.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(n=e.choices)==null?void 0:n[0])!=null&&o.message)){_context123.n=5;break;}if(!e.choices[0].message.tool_calls){_context123.n=3;break;}return _context123.a(2,this.handleToolsGeneric(e.choices[0].message,this._functionHandler,this._messages,t));case 3:if(!((a=e.choices[0].message)!=null&&a.audio)){_context123.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 _context123.a(2,_defineProperty({files:[{src:"data:audio/wav;base64,".concat(e.choices[0].message.audio.data),type:"audio"}]},y,d?e.choices[0].message.audio.transcript:void 0));case 4:return _context123.a(2,_defineProperty({},y,e.choices[0].message.content));case 5:return _context123.a(2,_defineProperty({},y,""));}},_callee123,this);}));function extractResultData(_x232,_x233){return _extractResultData23.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e,t){return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:return _context124.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee124,this);}));function extractStreamResult(_x234,_x235){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()}],[{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 _s9=ws.getFileContent(e.files,t);return e.text&&e.text.trim().length>0&&_s9.unshift(_defineProperty({type:"text"},y,e.text)),_s9;}return e.text;}}]);}(k);var hn=/*#__PURE__*/function(_ws){function hn(e){var _this58;_classCallCheck(this,hn);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(_this58=_callSuper(this,hn,[e,Ce.buildKeyVerificationDetails(i),Ce.buildHeaders,s,n]),_this58.permittedErrorPrefixes=[Ce.URL_DETAILS_ERROR_MESSAGE],_this58.isTextInputDisabled=!1,_typeof(n)===T){var _ref83=(h=(u=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:u.openAI)==null?void 0:h.chat,f=_ref83.function_handler;f&&(_this58._functionHandler=f);}Ce.validateURLDetails(i)?_this58.url=hn.buildURL(i):(_this58.isTextInputDisabled=!0,_this58.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},je,Ce.URL_DETAILS_ERROR_MESSAGE));}));return _this58;}_inherits(hn,_ws);return _createClass(hn,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);}}]);}(ws);var Qs=/*#__PURE__*/function(_k15){function Qs(e){var _this59$maxMessages,_c$model2;var _this59;_classCallCheck(this,Qs);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this59=_callSuper(this,Qs,[e,ct.buildKeyVerificationDetails(),ct.buildHeaders,s]),_this59.insertKeyPlaceholderText=_this59.genereteAPIKeyName("BigModel"),_this59.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this59.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this59.permittedErrorPrefixes=[K,ie],_this59._systemMessage="";var i=(n=t.bigModel)==null?void 0:n.chat;if(_typeof(i)===T){i.system_prompt&&(_this59._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&&(_this59._functionHandler=d),_this59.cleanConfig(i),Object.assign(_this59.rawBody,i);}(_this59$maxMessages=_this59.maxMessages)!==null&&_this59$maxMessages!==void 0?_this59$maxMessages:_this59.maxMessages=-1,(_c$model2=(c=_this59.rawBody).model)!==null&&_c$model2!==void 0?_c$model2:c.model="glm-4.5";return _this59;}_inherits(Qs,_k15);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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Qs.getTextWFilesContent(n,Qs.getFileContent),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 _callee125(e,t){var _this$_messages4;return _regenerator().w(function(_context125){while(1)switch(_context125.n){case 0:(_this$_messages4=this._messages)!==null&&_this$_messages4!==void 0?_this$_messages4:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context125.a(2);}},_callee125,this);}));function callServiceAPI(_x236,_x237){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(e,t){var _s0;return _regenerator().w(function(_context126){while(1)switch(_context126.n){case 0:if(!e.error){_context126.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context126.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context126.n=2;break;}return _context126.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context126.n=3;break;}_s0=e.choices[0].message;return _context126.a(2,_s0.tool_calls?this.handleToolsGeneric({tool_calls:_s0.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s0.content));case 3:return _context126.a(2,_defineProperty({},y,""));}},_callee126,this);}));function extractResultData(_x238,_x239){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var o,a,l,c,s,i,n,d;return _regenerator().w(function(_context127){while(1)switch(_context127.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")){_context127.n=2;break;}if(!s.tool_calls){_context127.n=1;break;}d={tool_calls:s.tool_calls};return _context127.a(2,this.handleToolsGeneric(d,this._functionHandler,this._messages,t));case 1:return _context127.a(2,_defineProperty({},y,(s==null?void 0:s.content)||""));case 2:return _context127.a(2,_defineProperty({},y,(s==null?void 0:s.content)||""));}},_callee127,this);}));function extractStreamResult(_x240,_x241){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()}],[{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||""}};});}}]);}(k);var Qa=/*#__PURE__*/function(_k16){function Qa(e){var _this60$maxMessages,_o$model8;var _this60;_classCallCheck(this,Qa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this60=_callSuper(this,Qa,[e,dt.buildKeyVerificationDetails(),dt.buildHeaders,s]),_this60.insertKeyPlaceholderText=_this60.genereteAPIKeyName("Together AI"),_this60.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this60.url="https://api.together.xyz/v1/chat/completions",_this60.permittedErrorPrefixes=[we,ie],_this60._systemMessage="";var i=(n=t.together)==null?void 0:n.chat;_typeof(i)===T&&(i.system_prompt&&(_this60._systemMessage=i.system_prompt),_this60.cleanConfig(i),Object.assign(_this60.rawBody,i)),(_this60$maxMessages=_this60.maxMessages)!==null&&_this60$maxMessages!==void 0?_this60$maxMessages:_this60.maxMessages=-1,(_o$model8=(o=_this60.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this60;}_inherits(Qa,_k16);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=J.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 _callee128(e,t){return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context128.a(2);}},_callee128,this);}));function callServiceAPI(_x242,_x243){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e){return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:if(!e.error){_context129.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context129.n=3;break;}if(!(e.choices[0].message!==void 0)){_context129.n=2;break;}return _context129.a(2,_defineProperty({},y,e.choices[0].message.content));case 2:if(!(e.choices[0].delta!==void 0)){_context129.n=3;break;}return _context129.a(2,_defineProperty({},y,e.choices[0].delta.content));case 3:return _context129.a(2,_defineProperty({},y,""));}},_callee129);}));function extractResultData(_x244){return _extractResultData25.apply(this,arguments);}return extractResultData;}()}]);}(k);var Me=/*#__PURE__*/function(_k17){function Me(e){var _this61;_classCallCheck(this,Me);var o;var t=e.directConnection,s=t==null?void 0:t.openAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};_this61=_callSuper(this,Me,[e,G.buildKeyVerificationDetails(),G.buildHeaders,s,i]),_this61.insertKeyPlaceholderText=_this61.genereteAPIKeyName("OpenAI"),_this61.keyHelpUrl="https://platform.openai.com/account/api-keys",_this61.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>",_this61.url="",_this61.permittedErrorPrefixes=[ks,"Invalid input image"];var n=(o=t==null?void 0:t.openAI)==null?void 0:o.images;if(_this61.camera){var a=_typeof(n)=="object"&&n.size?Number.parseInt(n.size):1024;_this61.camera.files={dimensions:{width:a,height:a}};}_typeof(n)===T&&Object.assign(_this61.rawBody,n),_this61.canSendMessage=Me.canFileSendMessage;return _this61;}_inherits(Me,_k17);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
|
+
function ws(e,t,s,i,n){var _this58$maxMessages,_p$model;var _this58;_classCallCheck(this,ws);var u,h,f,m,p;var o=JSON.parse(JSON.stringify(e.directConnection)),a=t||G.buildKeyVerificationDetails(),l=s||G.buildHeaders,c=i||o.openAI;_this58=_callSuper(this,ws,[e,a,l,c]),_this58.insertKeyPlaceholderText=_this58.genereteAPIKeyName("OpenAI"),_this58.keyHelpUrl="https://platform.openai.com/account/api-keys",_this58.url="https://api.openai.com/v1/chat/completions",_this58.permittedErrorPrefixes=[ks,"Invalid value"],_this58._systemMessage="";var d=n||((u=o.openAI)==null?void 0:u.chat);if(_typeof(d)===T){d.system_prompt&&(_this58._systemMessage=d.system_prompt);var g=(m=(f=(h=e.directConnection)==null?void 0:h.openAI)==null?void 0:f.chat)==null?void 0:m.function_handler;g&&(_this58._functionHandler=g),_this58.cleanConfig(d),Object.assign(_this58.rawBody,d);}(_this58$maxMessages=_this58.maxMessages)!==null&&_this58$maxMessages!==void 0?_this58$maxMessages:_this58.maxMessages=-1,(_p$model=(p=_this58.rawBody).model)!==null&&_p$model!==void 0?_p$model:p.model="gpt-4o";return _this58;}_inherits(ws,_k14);return _createClass(ws,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler;}},{key:"preprocessBody",value:// prettier-ignore
|
210
|
+
function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:ws.getContent(n),role:n.role===v.USER_ROLE?"user":"assistant"};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e,t){var _this$_messages3;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:(_this$_messages3=this._messages)!==null&&_this$_messages3!==void 0?_this$_messages3:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context122.a(2);}},_callee122,this);}));function callServiceAPI(_x230,_x231){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:if(!e.error){_context123.n=1;break;}throw e.error.message;case 1:if(!((i=(s=e.choices)==null?void 0:s[0])!=null&&i.delta)){_context123.n=2;break;}return _context123.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(n=e.choices)==null?void 0:n[0])!=null&&o.message)){_context123.n=5;break;}if(!e.choices[0].message.tool_calls){_context123.n=3;break;}return _context123.a(2,this.handleToolsGeneric(e.choices[0].message,this._functionHandler,this._messages,t));case 3:if(!((a=e.choices[0].message)!=null&&a.audio)){_context123.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 _context123.a(2,_defineProperty({files:[{src:"data:audio/wav;base64,".concat(e.choices[0].message.audio.data),type:"audio"}]},y,d?e.choices[0].message.audio.transcript:void 0));case 4:return _context123.a(2,_defineProperty({},y,e.choices[0].message.content));case 5:return _context123.a(2,_defineProperty({},y,""));}},_callee123,this);}));function extractResultData(_x232,_x233){return _extractResultData23.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e,t){return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:return _context124.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee124,this);}));function extractStreamResult(_x234,_x235){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(s){var i,n,o;if(s.type==="audio"){var a=(i=s.src)==null?void 0:i.split(",")[1],l=((o=(n=s.name)==null?void 0:n.split(".").pop())==null?void 0:o.toLowerCase())||"wav";return{type:"input_audio",input_audio:{data:a,format:l}};}return{type:"image_url",image_url:{url:s.src}};});}},{key:"getContent",value:function getContent(e){if(e.files&&e.files.length>0){var t=ws.getFileContent(e.files);return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},y,e.text)),t;}return e.text;}}]);}(k);var hn=/*#__PURE__*/function(_ws){function hn(e){var _this59;_classCallCheck(this,hn);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,hn,[e,Ce.buildKeyVerificationDetails(i),Ce.buildHeaders,s,n]),_this59.permittedErrorPrefixes=[Ce.URL_DETAILS_ERROR_MESSAGE],_this59.isTextInputDisabled=!1,_typeof(n)===T){var _ref83=(h=(u=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:u.openAI)==null?void 0:h.chat,f=_ref83.function_handler;f&&(_this59._functionHandler=f);}Ce.validateURLDetails(i)?_this59.url=hn.buildURL(i):(_this59.isTextInputDisabled=!0,_this59.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},je,Ce.URL_DETAILS_ERROR_MESSAGE));}));return _this59;}_inherits(hn,_ws);return _createClass(hn,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);}}]);}(ws);var Qs=/*#__PURE__*/function(_k15){function Qs(e){var _this60$maxMessages,_c$model2;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,ie],_this60._systemMessage="";var i=(n=t.bigModel)==null?void 0:n.chat;if(_typeof(i)===T){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$model2=(c=_this60.rawBody).model)!==null&&_c$model2!==void 0?_c$model2:c.model="glm-4.5";return _this60;}_inherits(Qs,_k15);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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:Qs.getTextWFilesContent(n,Qs.getFileContent),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 _callee125(e,t){var _this$_messages4;return _regenerator().w(function(_context125){while(1)switch(_context125.n){case 0:(_this$_messages4=this._messages)!==null&&_this$_messages4!==void 0?_this$_messages4:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context125.a(2);}},_callee125,this);}));function callServiceAPI(_x236,_x237){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(e,t){var _s9;return _regenerator().w(function(_context126){while(1)switch(_context126.n){case 0:if(!e.error){_context126.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context126.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context126.n=2;break;}return _context126.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context126.n=3;break;}_s9=e.choices[0].message;return _context126.a(2,_s9.tool_calls?this.handleToolsGeneric({tool_calls:_s9.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s9.content));case 3:return _context126.a(2,_defineProperty({},y,""));}},_callee126,this);}));function extractResultData(_x238,_x239){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var o,a,l,c,s,i,n,d;return _regenerator().w(function(_context127){while(1)switch(_context127.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")){_context127.n=2;break;}if(!s.tool_calls){_context127.n=1;break;}d={tool_calls:s.tool_calls};return _context127.a(2,this.handleToolsGeneric(d,this._functionHandler,this._messages,t));case 1:return _context127.a(2,_defineProperty({},y,(s==null?void 0:s.content)||""));case 2:return _context127.a(2,_defineProperty({},y,(s==null?void 0:s.content)||""));}},_callee127,this);}));function extractStreamResult(_x240,_x241){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()}],[{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||""}};});}}]);}(k);var Qa=/*#__PURE__*/function(_k16){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=[we,ie],_this61._systemMessage="";var i=(n=t.together)==null?void 0:n.chat;_typeof(i)===T&&(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,_k16);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=J.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 _callee128(e,t){return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context128.a(2);}},_callee128,this);}));function callServiceAPI(_x242,_x243){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e){return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:if(!e.error){_context129.n=1;break;}throw e.error.message;case 1:if(!(e.choices.length>0)){_context129.n=3;break;}if(!(e.choices[0].message!==void 0)){_context129.n=2;break;}return _context129.a(2,_defineProperty({},y,e.choices[0].message.content));case 2:if(!(e.choices[0].delta!==void 0)){_context129.n=3;break;}return _context129.a(2,_defineProperty({},y,e.choices[0].delta.content));case 3:return _context129.a(2,_defineProperty({},y,""));}},_callee129);}));function extractResultData(_x244){return _extractResultData25.apply(this,arguments);}return extractResultData;}()}]);}(k);var Me=/*#__PURE__*/function(_k17){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,G.buildKeyVerificationDetails(),G.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=[ks,"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)===T&&Object.assign(_this62.rawBody,n),_this62.canSendMessage=Me.canFileSendMessage;return _this62;}_inherits(Me,_k17);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
|
214
211
|
},{key:"callApiWithImage",value:function callApiWithImage(e,t,s){var o,a;var i;var n=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim();if(s[1]||n&&n!==""){this.url=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]);w.tempRemoveContentHeader(this.connectSettings,V.request.bind(this,this,i,e),!1);}},{key:"callServiceAPI",value:function(){var _callServiceAPI23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(e,t,s){var i,n;return _regenerator().w(function(_context130){while(1)switch(_context130.n){case 0:if((i=this.connectSettings)!=null&&i.headers){_context130.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 1:if(!(s!=null&&s[0])){_context130.n=2;break;}this.callApiWithImage(e,t,s);_context130.n=4;break;case 2:if(this.connectSettings){_context130.n=3;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);case 3:this.url=Me.IMAGE_GENERATION_URL;n=this.preprocessBody(this.rawBody,t[t.length-1].text);V.request(this,n,e);case 4:return _context130.a(2);}},_callee130,this);}));function callServiceAPI(_x245,_x246,_x247){return _callServiceAPI23.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(e){return _regenerator().w(function(_context131){while(1)switch(_context131.n){case 0:if(!e.error){_context131.n=1;break;}throw e.error.message;case 1:return _context131.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(jt).concat(s.b64_json),type:"image"};})});}},_callee131);}));function extractResultData(_x248){return _extractResultData26.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
|
215
212
|
// 1 image:
|
216
213
|
// - With text - edits image based on the text
|
@@ -220,39 +217,39 @@ function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.strin
|
|
220
217
|
// Add text to describe the required modification.
|
221
218
|
// Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
|
222
219
|
// `;
|
223
|
-
}],[{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;}}]);}(k);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 Xi=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(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===ie?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://openrouter.ai/api/v1/key",method:z,handleVerificationResult:ei.handleVerificationResult};}}]);}();var ps=/*#__PURE__*/function(_k18){function ps(e){var _this62$maxMessages,_o$model9,_a$max_tokens;var _this62;_classCallCheck(this,ps);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).openRouter;if(_this62=_callSuper(this,ps,[e,ei.buildKeyVerificationDetails(),ei.buildHeaders,s]),_this62.insertKeyPlaceholderText=_this62.genereteAPIKeyName("OpenRouter"),_this62.keyHelpUrl="https://openrouter.ai/keys",_this62.url="https://openrouter.ai/api/v1/chat/completions",_this62.permittedErrorPrefixes=[we,ie],_this62._systemMessage="",_typeof(s)===T){s.system_prompt&&(_this62._systemMessage=s.system_prompt);var l=(n=(i=e.directConnection)==null?void 0:i.openRouter)==null?void 0:n.function_handler;l&&(_this62._functionHandler=l),_this62.cleanConfig(s),Object.assign(_this62.rawBody,s);}(_this62$maxMessages=_this62.maxMessages)!==null&&_this62$maxMessages!==void 0?_this62$maxMessages:_this62.maxMessages=-1,(_o$model9=(o=_this62.rawBody).model)!==null&&_o$model9!==void 0?_o$model9:o.model="openai/gpt-4o",(_a$max_tokens=(a=_this62.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=1e3;return _this62;}_inherits(ps,_k18);return _createClass(ps,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:ps.getContent(o),role:o.role===v.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 _callee132(e,t){var _this$_messages5;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:(_this$_messages5=this._messages)!==null&&_this$_messages5!==void 0?_this$_messages5:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context132.a(2);}},_callee132,this);}));function callServiceAPI(_x249,_x250){return _callServiceAPI24.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var s,i,n,o,a,l,_a5,_l4;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:if(!e.error){_context133.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context133.n=4;break;}a=(s=e.choices)==null?void 0:s[0];if(!(a!=null&&a.delta)){_context133.n=2;break;}return _context133.a(2,this.extractStreamResult(a,t));case 2:if(!((i=e.message)!=null&&i.images)){_context133.n=3;break;}l=e.message.images.map(function(c){return{src:c.image_url.url};});return _context133.a(2,_defineProperty(_defineProperty({},y,e.message.content||""),"files",l));case 3:return _context133.a(2,_defineProperty({},y,""));case 4:if(!(e.object==="chat.completion")){_context133.n=6;break;}_a5=(n=e.choices)==null?void 0:n[0];if(!(_a5!=null&&_a5.message)){_context133.n=6;break;}if(!_a5.message.tool_calls){_context133.n=5;break;}return _context133.a(2,this.handleToolsGeneric({tool_calls:_a5.message.tool_calls},this._functionHandler,this._messages,t));case 5:_l4=((o=_a5.message.images)==null?void 0:o.map(function(c){return{src:c.image_url.url};}))||[];return _context133.a(2,_defineProperty(_defineProperty({},y,_a5.message.content||""),"files",_l4));case 6:return _context133.a(2,_defineProperty({},y,""));}},_callee133,this);}));function extractResultData(_x251,_x252){return _extractResultData27.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t){var s,i;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:s=e.delta;if(!(s!=null&&s.images)){_context134.n=1;break;}i=s.images.map(function(n){return{src:n.image_url.url};});return _context134.a(2,_defineProperty(_defineProperty({},y,s.content||""),"files",i));case 1:return _context134.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee134,this);}));function extractStreamResult(_x253,_x254){return _extractStreamResult3.apply(this,arguments);}return extractStreamResult;}()}],[{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(ps.getImageContent(e.files)),_toConsumableArray(ps.getAudioContent(e.files)));return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},y,e.text)),t.length>0?t:e.text||"";}return e.text||"";}}]);}(k);var ti=/*#__PURE__*/function(){function ti(){_classCallCheck(this,ti);}return _createClass(ti,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.error?i(b.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.perplexity.ai/chat/completions",method:Z,handleVerificationResult:ti.handleVerificationResult};}}]);}();var el=/*#__PURE__*/function(_k19){function el(e){var _this63$maxMessages,_i$model;var _this63;_classCallCheck(this,el);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).perplexity;_this63=_callSuper(this,el,[e,ti.buildKeyVerificationDetails(),ti.buildHeaders,s]),_this63.insertKeyPlaceholderText=_this63.genereteAPIKeyName("Perplexity"),_this63.keyHelpUrl="https://www.perplexity.ai/settings/api",_this63.url="https://api.perplexity.ai/chat/completions",_this63.permittedErrorPrefixes=[ht,ur,"Permission denied"],_this63._systemMessage="",_typeof(s)===T&&(s.system_prompt&&(_this63._systemMessage=s.system_prompt),_this63.cleanConfig(s),Object.assign(_this63.rawBody,s)),(_this63$maxMessages=_this63.maxMessages)!==null&&_this63$maxMessages!==void 0?_this63$maxMessages:_this63.maxMessages=-1,(_i$model=(i=_this63.rawBody).model)!==null&&_i$model!==void 0?_i$model:i.model="sonar";return _this63;}_inherits(el,_k19);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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===v.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){return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x255,_x256){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({},y,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context136.n=3;break;}return _context136.a(2,_defineProperty({},y,t.message.content));case 3:return _context136.a(2,_defineProperty({},y,""));}},_callee136);}));function extractResultData(_x257){return _extractResultData28.apply(this,arguments);}return extractResultData;}()}]);}(k);var si=/*#__PURE__*/function(){function si(){_classCallCheck(this,si);}return _createClass(si,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===ie?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:z,handleVerificationResult:si.handleVerificationResult};}}]);}();var tl=/*#__PURE__*/function(_k20){function tl(e){var _this64$maxMessages,_i$model2,_n$temperature,_o$max_tokens;var _this64;_classCallCheck(this,tl);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).deepSeek;_this64=_callSuper(this,tl,[e,si.buildKeyVerificationDetails(),si.buildHeaders,s]),_this64.insertKeyPlaceholderText=_this64.genereteAPIKeyName("DeepSeek"),_this64.keyHelpUrl="https://platform.deepseek.com/api_keys",_this64.url="https://api.deepseek.com/v1/chat/completions",_this64.permittedErrorPrefixes=[we,ie],_this64._systemMessage="",_typeof(s)===T&&(s.system_prompt&&(_this64._systemMessage=s.system_prompt),_this64.cleanConfig(s),Object.assign(_this64.rawBody,s)),(_this64$maxMessages=_this64.maxMessages)!==null&&_this64$maxMessages!==void 0?_this64$maxMessages:_this64.maxMessages=-1,(_i$model2=(i=_this64.rawBody).model)!==null&&_i$model2!==void 0?_i$model2:i.model="deepseek-chat",(_n$temperature=(n=_this64.rawBody).temperature)!==null&&_n$temperature!==void 0?_n$temperature:n.temperature=1,(_o$max_tokens=(o=_this64.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this64;}_inherits(tl,_k20);return _createClass(tl,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===v.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){return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context137.a(2);}},_callee137,this);}));function callServiceAPI(_x258,_x259){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,_defineProperty({},y,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context138.n=3;break;}return _context138.a(2,_defineProperty({},y,t.message.content));case 3:return _context138.a(2,_defineProperty({},y,""));}},_callee138);}));function extractResultData(_x260){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(k);var ii=/*#__PURE__*/function(){function ii(){_classCallCheck(this,ii);}return _createClass(ii,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var o;((o=e.base_resp)==null?void 0:o.status_code)===1004?i(b.INVALID_KEY):s(t);}// WORK - similar
|
224
|
-
},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.minimax.io/v1/files/delete",method:Z,handleVerificationResult:ii.handleVerificationResult};}}]);}();var sl=/*#__PURE__*/function(_k21){function sl(e){var
|
225
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.detail?i(b.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.mistral.ai/v1/models",method:z,handleVerificationResult:ni.handleVerificationResult};}}]);}();var un=/*#__PURE__*/function(_k22){function un(e){var
|
220
|
+
}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("image",t),s&&i.append("mask",s),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i;}}]);}(k);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 Xi=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(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===ie?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://openrouter.ai/api/v1/key",method:z,handleVerificationResult:ei.handleVerificationResult};}}]);}();var ps=/*#__PURE__*/function(_k18){function ps(e){var _this63$maxMessages,_o$model9,_a$max_tokens;var _this63;_classCallCheck(this,ps);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).openRouter;if(_this63=_callSuper(this,ps,[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=[we,ie],_this63._systemMessage="",_typeof(s)===T){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(ps,_k18);return _createClass(ps,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:ps.getContent(o),role:o.role===v.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 _callee132(e,t){var _this$_messages5;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:(_this$_messages5=this._messages)!==null&&_this$_messages5!==void 0?_this$_messages5:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context132.a(2);}},_callee132,this);}));function callServiceAPI(_x249,_x250){return _callServiceAPI24.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var s,i,n,o,a,l,_a5,_l4;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:if(!e.error){_context133.n=1;break;}throw e.error.message;case 1:if(!(e.object==="chat.completion.chunk")){_context133.n=4;break;}a=(s=e.choices)==null?void 0:s[0];if(!(a!=null&&a.delta)){_context133.n=2;break;}return _context133.a(2,this.extractStreamResult(a,t));case 2:if(!((i=e.message)!=null&&i.images)){_context133.n=3;break;}l=e.message.images.map(function(c){return{src:c.image_url.url};});return _context133.a(2,_defineProperty(_defineProperty({},y,e.message.content||""),"files",l));case 3:return _context133.a(2,_defineProperty({},y,""));case 4:if(!(e.object==="chat.completion")){_context133.n=6;break;}_a5=(n=e.choices)==null?void 0:n[0];if(!(_a5!=null&&_a5.message)){_context133.n=6;break;}if(!_a5.message.tool_calls){_context133.n=5;break;}return _context133.a(2,this.handleToolsGeneric({tool_calls:_a5.message.tool_calls},this._functionHandler,this._messages,t));case 5:_l4=((o=_a5.message.images)==null?void 0:o.map(function(c){return{src:c.image_url.url};}))||[];return _context133.a(2,_defineProperty(_defineProperty({},y,_a5.message.content||""),"files",_l4));case 6:return _context133.a(2,_defineProperty({},y,""));}},_callee133,this);}));function extractResultData(_x251,_x252){return _extractResultData27.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t){var s,i;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:s=e.delta;if(!(s!=null&&s.images)){_context134.n=1;break;}i=s.images.map(function(n){return{src:n.image_url.url};});return _context134.a(2,_defineProperty(_defineProperty({},y,s.content||""),"files",i));case 1:return _context134.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee134,this);}));function extractStreamResult(_x253,_x254){return _extractStreamResult3.apply(this,arguments);}return extractStreamResult;}()}],[{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(ps.getImageContent(e.files)),_toConsumableArray(ps.getAudioContent(e.files)));return e.text&&e.text.trim().length>0&&t.unshift(_defineProperty({type:"text"},y,e.text)),t.length>0?t:e.text||"";}return e.text||"";}}]);}(k);var ti=/*#__PURE__*/function(){function ti(){_classCallCheck(this,ti);}return _createClass(ti,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.error?i(b.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.perplexity.ai/chat/completions",method:Z,handleVerificationResult:ti.handleVerificationResult};}}]);}();var el=/*#__PURE__*/function(_k19){function el(e){var _this64$maxMessages,_i$model;var _this64;_classCallCheck(this,el);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).perplexity;_this64=_callSuper(this,el,[e,ti.buildKeyVerificationDetails(),ti.buildHeaders,s]),_this64.insertKeyPlaceholderText=_this64.genereteAPIKeyName("Perplexity"),_this64.keyHelpUrl="https://www.perplexity.ai/settings/api",_this64.url="https://api.perplexity.ai/chat/completions",_this64.permittedErrorPrefixes=[ht,ur,"Permission denied"],_this64._systemMessage="",_typeof(s)===T&&(s.system_prompt&&(_this64._systemMessage=s.system_prompt),_this64.cleanConfig(s),Object.assign(_this64.rawBody,s)),(_this64$maxMessages=_this64.maxMessages)!==null&&_this64$maxMessages!==void 0?_this64$maxMessages:_this64.maxMessages=-1,(_i$model=(i=_this64.rawBody).model)!==null&&_i$model!==void 0?_i$model:i.model="sonar";return _this64;}_inherits(el,_k19);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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===v.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){return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x255,_x256){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({},y,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context136.n=3;break;}return _context136.a(2,_defineProperty({},y,t.message.content));case 3:return _context136.a(2,_defineProperty({},y,""));}},_callee136);}));function extractResultData(_x257){return _extractResultData28.apply(this,arguments);}return extractResultData;}()}]);}(k);var si=/*#__PURE__*/function(){function si(){_classCallCheck(this,si);}return _createClass(si,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===ie?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:z,handleVerificationResult:si.handleVerificationResult};}}]);}();var tl=/*#__PURE__*/function(_k20){function tl(e){var _this65$maxMessages,_i$model2,_n$temperature,_o$max_tokens;var _this65;_classCallCheck(this,tl);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).deepSeek;_this65=_callSuper(this,tl,[e,si.buildKeyVerificationDetails(),si.buildHeaders,s]),_this65.insertKeyPlaceholderText=_this65.genereteAPIKeyName("DeepSeek"),_this65.keyHelpUrl="https://platform.deepseek.com/api_keys",_this65.url="https://api.deepseek.com/v1/chat/completions",_this65.permittedErrorPrefixes=[we,ie],_this65._systemMessage="",_typeof(s)===T&&(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$model2=(i=_this65.rawBody).model)!==null&&_i$model2!==void 0?_i$model2:i.model="deepseek-chat",(_n$temperature=(n=_this65.rawBody).temperature)!==null&&_n$temperature!==void 0?_n$temperature:n.temperature=1,(_o$max_tokens=(o=_this65.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this65;}_inherits(tl,_k20);return _createClass(tl,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===v.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){return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context137.a(2);}},_callee137,this);}));function callServiceAPI(_x258,_x259){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,_defineProperty({},y,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context138.n=3;break;}return _context138.a(2,_defineProperty({},y,t.message.content));case 3:return _context138.a(2,_defineProperty({},y,""));}},_callee138);}));function extractResultData(_x260){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(k);var ii=/*#__PURE__*/function(){function ii(){_classCallCheck(this,ii);}return _createClass(ii,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var o;((o=e.base_resp)==null?void 0:o.status_code)===1004?i(b.INVALID_KEY):s(t);}// WORK - similar
|
221
|
+
},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.minimax.io/v1/files/delete",method:Z,handleVerificationResult:ii.handleVerificationResult};}}]);}();var sl=/*#__PURE__*/function(_k21){function sl(e){var _this66$maxMessages,_i$model3;var _this66;_classCallCheck(this,sl);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).miniMax;_this66=_callSuper(this,sl,[e,ii.buildKeyVerificationDetails(),ii.buildHeaders,s]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("MiniMax"),_this66.keyHelpUrl="https://www.minimaxi.com",_this66.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this66.permittedErrorPrefixes=[we,ie,"insufficient balance"],_this66._systemMessage="",_typeof(s)===T&&(s.system_prompt&&(_this66._systemMessage=s.system_prompt),_this66.cleanConfig(s),Object.assign(_this66.rawBody,s)),(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1,(_i$model3=(i=_this66.rawBody).model)!==null&&_i$model3!==void 0?_i$model3:i.model="MiniMax-M1";return _this66;}_inherits(sl,_k21);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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:n.text||"",role:n.role===v.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){return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context139.a(2);}},_callee139,this);}));function callServiceAPI(_x261,_x262){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e){var t,_s0;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;}_s0=e.choices[0];if(!(_s0.delta&&_s0.delta.content)){_context140.n=2;break;}return _context140.a(2,_defineProperty({},y,_s0.delta.content));case 2:if(!(_s0.message&&_s0.message.content)){_context140.n=3;break;}return _context140.a(2,_defineProperty({},y,_s0.message.content));case 3:if(!(typeof((t=e.base_resp)==null?void 0:t.status_code)=="number"&&e.base_resp.status_code>0)){_context140.n=4;break;}throw e.base_resp.status_msg;case 4:return _context140.a(2,_defineProperty({},y,""));}},_callee140);}));function extractResultData(_x263){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(k);var ni=/*#__PURE__*/function(){function ni(){_classCallCheck(this,ni);}return _createClass(ni,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N),"accept",N);}// prettier-ignore
|
222
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){e.detail?i(b.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.mistral.ai/v1/models",method:z,handleVerificationResult:ni.handleVerificationResult};}}]);}();var un=/*#__PURE__*/function(_k22){function un(e){var _this67$maxMessages,_o$model0;var _this67;_classCallCheck(this,un);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).mistral;if(_this67=_callSuper(this,un,[e,ni.buildKeyVerificationDetails(),ni.buildHeaders,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("Mistral"),_this67.keyHelpUrl="https://console.mistral.ai/api-keys/",_this67.url="https://api.mistral.ai/v1/chat/completions",_this67.permittedErrorPrefixes=[ht],_this67._systemMessage="",_typeof(s)===T){s.system_prompt&&(_this67._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.mistral)==null?void 0:n.function_handler;a&&(_this67._functionHandler=a),_this67.cleanConfig(s),Object.assign(_this67.rawBody,s);}(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1,(_o$model0=(o=_this67.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="mistral-small-latest";return _this67;}_inherits(un,_k22);return _createClass(un,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{role:n.role==="ai"?"assistant":"user",content:k.getTextWFilesContent(n,un.getFileContent)};});return this._systemMessage&&i.unshift({role:"system",content:this._systemMessage}),s.messages=i,s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){var _this$_messages6;return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:(_this$_messages6=this._messages)!==null&&_this$_messages6!==void 0?_this$_messages6:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context141.a(2);}},_callee141,this);}));function callServiceAPI(_x264,_x265){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e,t){var _s1;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:if(!e.message){_context142.n=1;break;}throw e.message;case 1:if(!e.error){_context142.n=2;break;}throw e.error.message;case 2:if(!(e.choices&&e.choices.length>0)){_context142.n=4;break;}_s1=e.choices[0];if(!_s1.delta){_context142.n=3;break;}return _context142.a(2,this.extractStreamResult(_s1,t));case 3:if(!_s1.message){_context142.n=4;break;}return _context142.a(2,_s1.message.tool_calls?this.handleToolsGeneric({tool_calls:_s1.message.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s1.message.content||""));case 4:return _context142.a(2,_defineProperty({},y,""));}},_callee142,this);}));function extractResultData(_x266,_x267){return _extractResultData31.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e,t){var s,i,n;return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls"&&s!=null&&s.tool_calls)){_context143.n=1;break;}n={tool_calls:s.tool_calls};return _context143.a(2,this.handleToolsGeneric(n,this._functionHandler,this._messages,t));case 1:return _context143.a(2,_defineProperty({},y,(s==null?void 0:s.content)||""));}},_callee143,this);}));function extractStreamResult(_x268,_x269){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()}],[{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"},y,"[Unsupported file type: ".concat(t.type,"]"));});}}]);}(k);var fn=/*#__PURE__*/function(_k23){function fn(e){var _this68$maxMessages,_c$model3;var _this68;_classCallCheck(this,fn);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this68=_callSuper(this,fn,[e,Ft.buildKeyVerificationDetails(),Ft.buildHeaders,s]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("Groq"),_this68.keyHelpUrl="https://console.groq.com/keys",_this68.url="https://api.groq.com/openai/v1/chat/completions",_this68.permittedErrorPrefixes=[ht,"property"],_this68._systemMessage="";var i=(n=t.groq)==null?void 0:n.chat;if(_typeof(i)===T){i.system_prompt&&(_this68._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&&(_this68._functionHandler=d),_this68.cleanConfig(i),Object.assign(_this68.rawBody,i);}(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_c$model3=(c=_this68.rawBody).model)!==null&&_c$model3!==void 0?_c$model3:c.model="llama-3.3-70b-versatile";return _this68;}_inherits(fn,_k23);return _createClass(fn,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:fn.getTextWImagesContent(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 _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){var _this$_messages7;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:(_this$_messages7=this._messages)!==null&&_this$_messages7!==void 0?_this$_messages7:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context144.a(2);}},_callee144,this);}));function callServiceAPI(_x270,_x271){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var s,i,n,o;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:if(!e.error){_context145.n=1;break;}throw e.error.message;case 1:return _context145.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.handleToolsGeneric(e.choices[0].message,this._functionHandler,this._messages,t,{message:this._systemMessage}):_defineProperty({},y,e.choices[0].message.content||""):_defineProperty({},y,""));}},_callee145,this);}));function extractResultData(_x272,_x273){return _extractResultData32.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
|
226
223
|
},{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){return _regenerator().w(function(_context146){while(1)switch(_context146.n){case 0:return _context146.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee146,this);}));function extractStreamResult(_x274,_x275){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var ri=/*#__PURE__*/function(){function ri(){_classCallCheck(this,ri);}return _createClass(ri,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N),"accept",N);}// prettier-ignore
|
227
|
-
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){typeof e.message=="string"?i(b.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.cohere.ai/v1/models",method:z,handleVerificationResult:ri.handleVerificationResult};}}]);}();var oi=/*#__PURE__*/function(_k24){function oi(e){var
|
224
|
+
},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){typeof e.message=="string"?i(b.INVALID_KEY):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.cohere.ai/v1/models",method:z,handleVerificationResult:ri.handleVerificationResult};}}]);}();var oi=/*#__PURE__*/function(_k24){function oi(e){var _this69$maxMessages,_i$model4;var _this69;_classCallCheck(this,oi);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).cohere;if(_this69=_callSuper(this,oi,[e,ri.buildKeyVerificationDetails(),ri.buildHeaders,s]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Cohere"),_this69.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this69.permittedErrorPrefixes=["invalid"],_this69.url="https://api.cohere.com/v2/chat",_typeof(s)===T){var n=te.processCohere(s);_this69.canSendMessage=function(){return n;},_this69.cleanConfig(s),Object.assign(_this69.rawBody,s);}(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_i$model4=(i=_this69.rawBody).model)!==null&&_i$model4!==void 0?_i$model4:i.model="command-a-03-2025";return _this69;}_inherits(oi,_k24);return _createClass(oi,[{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;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context147.a(2);}},_callee147,this);}));function callServiceAPI(_x276,_x277){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e){var t,s,i,n;return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:if(!(typeof e.message=="string")){_context148.n=1;break;}throw e.message;case 1:if(!(this.stream&&e.text)){_context148.n=2;break;}n=oi.parseBundledEvents(e.text);return _context148.a(2,{text:oi.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)){_context148.n=3;break;}return _context148.a(2,_defineProperty({},y,e.message.content[0].text));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context148.a(2);}},_callee148,this);}));function extractResultData(_x278){return _extractResultData33.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("");}}]);}(k);var ai=/*#__PURE__*/function(){function ai(){_classCallCheck(this,ai);}return _createClass(ai,null,[{key:"buildHeaders",value:function buildHeaders(){return _defineProperty({},R,N);}// prettier-ignore
|
228
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(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}// https://ai.google.dev/api/models#method:-models.list
|
229
|
-
},{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:ai.handleVerificationResult};}}]);}();var pn=/*#__PURE__*/function(_k25){function pn(e){var
|
226
|
+
},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){var e="https://generativelanguage.googleapis.com/v1beta/models?key=";return{url:e,augmentUrl:function augmentUrl(t){return"".concat(e).concat(t);},method:z,handleVerificationResult:ai.handleVerificationResult};}}]);}();var pn=/*#__PURE__*/function(_k25){function pn(e){var _this70$maxMessages;var _this70;_classCallCheck(this,pn);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).gemini;if(_this70=_callSuper(this,pn,[e,ai.buildKeyVerificationDetails(),ai.buildHeaders,s]),_this70.insertKeyPlaceholderText=_this70.genereteAPIKeyName("Gemini"),_this70.keyHelpUrl="https://aistudio.google.com/app/apikey",_this70.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent",_this70.url="",_this70.permittedErrorPrefixes=["API_KEY_INVALID"],_typeof(s)===T){s.system_prompt&&(_this70._systemPrompt=s.system_prompt);var _ref119=(i=e.directConnection)==null?void 0:i.gemini,n=_ref119.function_handler;n&&(_this70._functionHandler=n),s.model&&(_this70.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(s.model,":generateContent")),_this70.cleanConfig(s);}Object.assign(_this70.rawBody,s),(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1;return _this70;}_inherits(pn,_k25);return _createClass(pn,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.model,delete e.key;}},{key:"preprocessBody",value:// prettier-ignore
|
230
227
|
function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemPrompt)==null?void 0:n.length)||0):-1).map(function(o){return pn.getContent(o);});return s.contents=i,this._systemPrompt&&(s.systemInstruction={parts:[_defineProperty({},y,this._systemPrompt)]}),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e,t){var _this$_messages8;var s,i;return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:if(this.connectSettings){_context149.n=1;break;}throw new Error(b.REQUEST_SETTINGS_ERROR);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)!==T||!i.simulation)||s.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),M.request(this,s,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),V.request(this,s,e));case 2:return _context149.a(2);}},_callee149,this);}));function callServiceAPI(_x279,_x280){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()// https://ai.google.dev/gemini-api/docs/function-calling?example=weather
|
231
|
-
},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:if(!e.error){_context150.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)){_context150.n=3;break;}a=e.candidates[0].content.parts,l=a.find(function(u){return u.functionCall;});if(!(l!=null&&l.functionCall)){_context150.n=2;break;}return _context150.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 _context150.a(2,_defineProperty(_defineProperty({},y,(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 _context150.a(2,_defineProperty({},y,""));}},_callee150,this);}));function extractResultData(_x281,_x282){return _extractResultData34.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e,t){var s,i,_yield$this$callToolF2,n,o,a,l;return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:if(!(!e||!t||!this._functionHandler)){_context151.n=1;break;}throw Error(b.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)};});_context151.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF2=_context151.v;n=_yield$this$callToolF2.responses;o=_yield$this$callToolF2.processedResponse;if(!o){_context151.n=3;break;}return _context151.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(_ref123){var l=_ref123.response;return typeof l!="string";})&&i.length===n.length)){_context151.n=4;break;}l={parts:n.map(function(c,d){return{functionResponse:{name:e[d].name,response:{result:c.response}}};}),role:"user"};return _context151.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 _context151.a(2);}},_callee151,this);}));function handleTools(_x283,_x284){return _handleTools2.apply(this,arguments);}return handleTools;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e.text&&e.text.trim().length>0&&t.push(_defineProperty({},y,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===v.USER_ROLE?"user":"model"};}}]);}(k);var li=/*#__PURE__*/function(){function li(){_classCallCheck(this,li);}return _createClass(li,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":e},R,N),"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===ie?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/models",method:z,handleVerificationResult:li.handleVerificationResult};}}]);}();var ci=/*#__PURE__*/function(_k26){function ci(e){var _this70$maxMessages,_o$model1,_a$max_tokens2;var _this70;_classCallCheck(this,ci);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).claude;if(_this70=_callSuper(this,ci,[e,li.buildKeyVerificationDetails(),li.buildHeaders,s]),_this70.insertKeyPlaceholderText=_this70.genereteAPIKeyName("Claude"),_this70.keyHelpUrl="https://console.anthropic.com/settings/keys",_this70.url="https://api.anthropic.com/v1/messages",_this70.permittedErrorPrefixes=[ie,we],_this70._streamToolCalls={type:"tool_use",id:"",name:"",input:""},_this70._systemMessage="",_typeof(s)===T){s.system_prompt&&(_this70._systemMessage=s.system_prompt);var l=(n=(i=e.directConnection)==null?void 0:i.claude)==null?void 0:n.function_handler;l&&(_this70._functionHandler=l),_this70.cleanConfig(s),Object.assign(_this70.rawBody,s);}(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_o$model1=(o=_this70.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="claude-3-5-sonnet-20241022",(_a$max_tokens2=(a=_this70.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this70;}_inherits(ci,_k26);return _createClass(ci,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:ci.getTextWFilesContent(n,ci.getFileContent),role:n.role===v.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 _callee152(e,t){var _this$_messages9;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:(_this$_messages9=this._messages)!==null&&_this$_messages9!==void 0?_this$_messages9:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context152.a(2);}},_callee152,this);}));function callServiceAPI(_x285,_x286){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var s,i,n,o,a;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:if(!e.error){_context153.n=1;break;}throw e.error.message;case 1:if(!(e.content&&e.content.length>0)){_context153.n=3;break;}o=e.content.find(function(l){return l.type==="tool_use";});if(!o){_context153.n=2;break;}return _context153.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(l){return l.type==="text";});if(!a){_context153.n=3;break;}return _context153.a(2,_defineProperty({},y,a.text));case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context153.n=4;break;}return _context153.a(2,_defineProperty({},y,e.delta.text||""));case 4:if(!(e.type==="content_block_start"&&((s=e.content_block)==null?void 0:s.type)==="tool_use")){_context153.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context153.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((i=e.delta)==null?void 0:i.type)==="input_json_delta")){_context153.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context153.n=7;break;case 6:if(!(e.type==="message_delta"&&((n=e.delta)==null?void 0:n.stop_reason)==="tool_use")){_context153.n=7;break;}return _context153.a(2,(this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t)));case 7:return _context153.a(2,_defineProperty({},y,""));}},_callee153,this);}));function extractResultData(_x287,_x288){return _extractResultData35.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var s,i,_yield$this$callToolF3,n,o,a,l;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:if(!(!e||!t||!this._functionHandler)){_context154.n=1;break;}throw Error(b.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)};});_context154.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF3=_context154.v;n=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context154.n=3;break;}return _context154.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(_ref128){var l=_ref128.response;return typeof l!="string";})&&i.length===n.length)){_context154.n=4;break;}l=n.map(function(c,d){return{type:"tool_result",tool_use_id:e[d].id,content:c.response};});return _context154.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 _context154.a(2);}},_callee154,this);}));function handleTools(_x289,_x290){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var s,i,n;if(t.type==="image"){var o=(s=t.src)==null?void 0:s.split(",")[1];return{type:"image",source:{type:"base64",media_type:((n=(i=t.src)==null?void 0:i.match(/data:([^;]+)/))==null?void 0:n[1])||"image/jpeg",data:o||""}};}return _defineProperty({type:"text"},y,"[Unsupported file type: ".concat(t.type,"]"));});}}]);}(k);var jn=/*#__PURE__*/function(){function jn(){_classCallCheck(this,jn);}return _createClass(jn,null,[{key:"buildHeaders",value:function buildHeaders(){return{};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"",method:z,handleVerificationResult:function handleVerificationResult(){}};}}]);}();var di=/*#__PURE__*/function(_k27){function di(e){var _this71$maxMessages,_l$model,_c$stream;var _this71;_classCallCheck(this,di);var o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=jn.buildKeyVerificationDetails(),i=jn.buildHeaders;_this71=_callSuper(this,di,[e,s,i,{key:"placeholder"}]),_this71.insertKeyPlaceholderText="",_this71.keyHelpUrl="",_this71.validateKeyProperty=!1,_this71.url="http://localhost:11434/api/chat",_this71.permittedErrorPrefixes=["Error"];var n=t.ollama;if(_typeof(n)===T){n.system&&(_this71._systemMessage=di.generateSystemMessage(n.system));var d=(a=(o=e.directConnection)==null?void 0:o.ollama)==null?void 0:a.function_handler;d&&(_this71._functionHandler=d),_this71.cleanConfig(n),Object.assign(_this71.rawBody,n);}(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_l$model=(l=_this71.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="llama3.2",(_c$stream=(c=_this71.rawBody).stream)!==null&&_c$stream!==void 0?_c$stream:c.stream=!1;return _this71;}_inherits(di,_k27);return _createClass(di,[{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=J.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===v.USER_ROLE?"user":"assistant"};if(o.files&&o.files.length>0){var l=di.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 _callee155(e,t){var _this$_messages0;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:(_this$_messages0=this._messages)!==null&&_this$_messages0!==void 0?_this$_messages0:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context155.a(2);}},_callee155,this);}));function callServiceAPI(_x291,_x292){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var s,i,n;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(!e.error){_context156.n=1;break;}throw e.error.message;case 1:if(!e.text){_context156.n=2;break;}n=JSON.parse(e.text);return _context156.a(2,(s=n.message)!=null&&s.tool_calls?this.handleTools({tool_calls:n.message.tool_calls},t):_defineProperty({},y,((i=n.message)==null?void 0:i.content)||""));case 2:return _context156.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},y,e.message.content||""):_defineProperty({},y,""));}},_callee156,this);}));function extractResultData(_x293,_x294){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var s,i,_yield$this$callToolF4,n,o;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context157.n=1;break;}throw Error(b.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)};});_context157.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF4=_context157.v;n=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context157.n=3;break;}return _context157.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:""}),!n.find(function(_ref133){var a=_ref133.response;return typeof a!="string";})&&i.length===n.length)){_context157.n=4;break;}return _context157.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 _context157.a(2);}},_callee157,this);}));function handleTools(_x295,_x296){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"generateSystemMessage",value:function generateSystemMessage(e){return{role:"system",content:e};}},{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t.type==="image";}).map(function(t){var i;return((i=t.src)==null?void 0:i.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(k);var Ut=/*#__PURE__*/function(){function Ut(){_classCallCheck(this,Ut);}return _createClass(Ut,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty({Authorization:"".concat(se).concat(e)},R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===ie||n.error.type===we?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.x.ai/v1/models",method:z,handleVerificationResult:Ut.handleVerificationResult};}}]);}();var Ei=/*#__PURE__*/function(_k28){function Ei(e){var _o$model10;var _this72;_classCallCheck(this,Ei);var n,o;var t=e.directConnection,s=t==null?void 0:t.x;_this72=_callSuper(this,Ei,[e,Ut.buildKeyVerificationDetails(),Ut.buildHeaders,s]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("X"),_this72.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this72.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>",_this72.url=Ei.IMAGE_GENERATION_URL,_this72.permittedErrorPrefixes=[we,ie];var i=(n=t==null?void 0:t.x)==null?void 0:n.images;_typeof(i)===T&&Object.assign(_this72.rawBody,i),(_o$model10=(o=_this72.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="grok-2-image";return _this72;}_inherits(Ei,_k28);return _createClass(Ei,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text,i=JSON.parse(JSON.stringify(e));return s&&s!==""&&(i.prompt=s),i;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context158.a(2);}},_callee158,this);}));function callServiceAPI(_x297,_x298){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e){return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(!e.error){_context159.n=1;break;}throw e.error.message;case 1:return _context159.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(jt).concat(s.b64_json),type:"image"};})});}},_callee159);}));function extractResultData(_x299){return _extractResultData37.apply(this,arguments);}return extractResultData;}()}]);}(k);Ei.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Yi=Ei;var hi=/*#__PURE__*/function(){function hi(){_classCallCheck(this,hi);}return _createClass(hi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===we?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",method:z,handleVerificationResult:hi.handleVerificationResult};}}]);}();var mn=/*#__PURE__*/function(_k29){function mn(e){var _this73$maxMessages,_o$model11;var _this73;_classCallCheck(this,mn);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).qwen;if(_this73=_callSuper(this,mn,[e,hi.buildKeyVerificationDetails(),hi.buildHeaders,s]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("Qwen"),_this73.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this73.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this73.permittedErrorPrefixes=["No static","The model",ks],_this73._systemMessage="",_typeof(s)===T){s.system_prompt&&(_this73._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.qwen)==null?void 0:n.function_handler;a&&(_this73._functionHandler=a),_this73.cleanConfig(s),Object.assign(_this73.rawBody,s);}(_this73$maxMessages=_this73.maxMessages)!==null&&_this73$maxMessages!==void 0?_this73$maxMessages:_this73.maxMessages=-1,(_o$model11=(o=_this73.rawBody).model)!==null&&_o$model11!==void 0?_o$model11:o.model="qwen-plus";return _this73;}_inherits(mn,_k29);return _createClass(mn,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:mn.getTextWImagesContent(n),role:n.role===v.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 _callee160(e,t){var _this$_messages1;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:(_this$_messages1=this._messages)!==null&&_this$_messages1!==void 0?_this$_messages1:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context160.a(2);}},_callee160,this);}));function callServiceAPI(_x300,_x301){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var _s11;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:if(!(e.choices&&e.choices.length>0)){_context161.n=3;break;}_s11=e.choices[0];if(!_s11.delta){_context161.n=2;break;}return _context161.a(2,this.extractStreamResult(_s11,t));case 2:if(!_s11.message){_context161.n=3;break;}return _context161.a(2,_s11.message.tool_calls?this.handleToolsGeneric({tool_calls:_s11.message.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s11.message.content||""));case 3:return _context161.a(2,_defineProperty({},y,""));}},_callee161,this);}));function extractResultData(_x302,_x303){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:return _context162.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee162,this);}));function extractStreamResult(_x304,_x305){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var ui=/*#__PURE__*/function(){function ui(){_classCallCheck(this,ui);}return _createClass(ui,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===ie?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:z,handleVerificationResult:ui.handleVerificationResult};}}]);}();var gn=/*#__PURE__*/function(_k30){function gn(e){var _this74$maxMessages,_o$model12;var _this74;_classCallCheck(this,gn);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).kimi;if(_this74=_callSuper(this,gn,[e,ui.buildKeyVerificationDetails(),ui.buildHeaders,s]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Kimi"),_this74.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this74.url="https://api.moonshot.ai/v1/chat/completions",_this74.permittedErrorPrefixes=[ht,"Not found"],_this74._systemMessage="You are Kimi, a helpful assistant created by Moonshot AI.",_typeof(s)===T){s.system_prompt&&(_this74._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.kimi)==null?void 0:n.function_handler;a&&(_this74._functionHandler=a),_this74.cleanConfig(s),Object.assign(_this74.rawBody,s);}(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_o$model12=(o=_this74.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="moonshot-v1-8k";return _this74;}_inherits(gn,_k30);return _createClass(gn,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:gn.getTextWImagesContent(n),role:n.role===v.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 _callee163(e,t){var _this$_messages10;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:(_this$_messages10=this._messages)!==null&&_this$_messages10!==void 0?_this$_messages10:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context163.a(2);}},_callee163,this);}));function callServiceAPI(_x306,_x307){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var _s12;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:if(!e.error){_context164.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context164.n=3;break;}_s12=e.choices[0];if(!_s12.delta){_context164.n=2;break;}return _context164.a(2,this.extractStreamResult(_s12,t));case 2:if(!_s12.message){_context164.n=3;break;}return _context164.a(2,_s12.message.tool_calls?this.handleToolsGeneric({tool_calls:_s12.message.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s12.message.content||""));case 3:return _context164.a(2,_defineProperty({},y,""));}},_callee164,this);}));function extractResultData(_x308,_x309){return _extractResultData39.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:return _context165.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee165,this);}));function extractStreamResult(_x310,_x311){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var il=/*#__PURE__*/function(_k31){function il(e){var _this75$maxMessages,_o$model13;var _this75;_classCallCheck(this,il);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.x;_this75=_callSuper(this,il,[e,Ut.buildKeyVerificationDetails(),Ut.buildHeaders,s]),_this75.insertKeyPlaceholderText=_this75.genereteAPIKeyName("X"),_this75.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this75.url="https://api.x.ai/v1/chat/completions",_this75.permittedErrorPrefixes=[we,ie],_this75._systemMessage="";var i=(n=t.x)==null?void 0:n.chat;_typeof(i)===T&&(i.system_prompt&&(_this75._systemMessage=i.system_prompt),_this75.cleanConfig(i),Object.assign(_this75.rawBody,i)),(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1,(_o$model13=(o=_this75.rawBody).model)!==null&&_o$model13!==void 0?_o$model13:o.model="grok-3-latest";return _this75;}_inherits(il,_k31);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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:o.text||"",role:o.role===v.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 _callee166(e,t){return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context166.a(2);}},_callee166,this);}));function callServiceAPI(_x312,_x313){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e){var t,s,i,n,o;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.object==="chat.completion.chunk")){_context167.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context167.a(2,(s=o==null?void 0:o.delta)!=null&&s.content?_defineProperty({},y,o.delta.content):_defineProperty({},y,""));case 2:return _context167.a(2,e.object==="chat.completion"&&(n=(i=e.choices)==null?void 0:i[0])!=null&&n.message?_defineProperty({},y,e.choices[0].message.content||""):_defineProperty({},y,""));}},_callee167);}));function extractResultData(_x314){return _extractResultData40.apply(this,arguments);}return extractResultData;}()}]);}(k);var nl=/*#__PURE__*/function(){function nl(){_classCallCheck(this,nl);}return _createClass(nl,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
|
+
},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){var s,i,n,o,a,l,c,d;return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:if(!e.error){_context150.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)){_context150.n=3;break;}a=e.candidates[0].content.parts,l=a.find(function(u){return u.functionCall;});if(!(l!=null&&l.functionCall)){_context150.n=2;break;}return _context150.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 _context150.a(2,_defineProperty(_defineProperty({},y,(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 _context150.a(2,_defineProperty({},y,""));}},_callee150,this);}));function extractResultData(_x281,_x282){return _extractResultData34.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e,t){var s,i,_yield$this$callToolF2,n,o,a,l;return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:if(!(!e||!t||!this._functionHandler)){_context151.n=1;break;}throw Error(b.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)};});_context151.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF2=_context151.v;n=_yield$this$callToolF2.responses;o=_yield$this$callToolF2.processedResponse;if(!o){_context151.n=3;break;}return _context151.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(_ref123){var l=_ref123.response;return typeof l!="string";})&&i.length===n.length)){_context151.n=4;break;}l={parts:n.map(function(c,d){return{functionResponse:{name:e[d].name,response:{result:c.response}}};}),role:"user"};return _context151.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 _context151.a(2);}},_callee151,this);}));function handleTools(_x283,_x284){return _handleTools2.apply(this,arguments);}return handleTools;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e.text&&e.text.trim().length>0&&t.push(_defineProperty({},y,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===v.USER_ROLE?"user":"model"};}}]);}(k);var li=/*#__PURE__*/function(){function li(){_classCallCheck(this,li);}return _createClass(li,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":e},R,N),"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===ie?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/models",method:z,handleVerificationResult:li.handleVerificationResult};}}]);}();var ci=/*#__PURE__*/function(_k26){function ci(e){var _this71$maxMessages,_o$model1,_a$max_tokens2;var _this71;_classCallCheck(this,ci);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).claude;if(_this71=_callSuper(this,ci,[e,li.buildKeyVerificationDetails(),li.buildHeaders,s]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("Claude"),_this71.keyHelpUrl="https://console.anthropic.com/settings/keys",_this71.url="https://api.anthropic.com/v1/messages",_this71.permittedErrorPrefixes=[ie,we],_this71._streamToolCalls={type:"tool_use",id:"",name:"",input:""},_this71._systemMessage="",_typeof(s)===T){s.system_prompt&&(_this71._systemMessage=s.system_prompt);var l=(n=(i=e.directConnection)==null?void 0:i.claude)==null?void 0:n.function_handler;l&&(_this71._functionHandler=l),_this71.cleanConfig(s),Object.assign(_this71.rawBody,s);}(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_o$model1=(o=_this71.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="claude-3-5-sonnet-20241022",(_a$max_tokens2=(a=_this71.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this71;}_inherits(ci,_k26);return _createClass(ci,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:ci.getTextWFilesContent(n,ci.getFileContent),role:n.role===v.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 _callee152(e,t){var _this$_messages9;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:(_this$_messages9=this._messages)!==null&&_this$_messages9!==void 0?_this$_messages9:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context152.a(2);}},_callee152,this);}));function callServiceAPI(_x285,_x286){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var s,i,n,o,a;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:if(!e.error){_context153.n=1;break;}throw e.error.message;case 1:if(!(e.content&&e.content.length>0)){_context153.n=3;break;}o=e.content.find(function(l){return l.type==="tool_use";});if(!o){_context153.n=2;break;}return _context153.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(l){return l.type==="text";});if(!a){_context153.n=3;break;}return _context153.a(2,_defineProperty({},y,a.text));case 3:if(!(e.type==="content_block_delta"&&e.delta&&e.delta.type==="text_delta")){_context153.n=4;break;}return _context153.a(2,_defineProperty({},y,e.delta.text||""));case 4:if(!(e.type==="content_block_start"&&((s=e.content_block)==null?void 0:s.type)==="tool_use")){_context153.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context153.n=7;break;case 5:if(!(e.type==="content_block_delta"&&((i=e.delta)==null?void 0:i.type)==="input_json_delta")){_context153.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context153.n=7;break;case 6:if(!(e.type==="message_delta"&&((n=e.delta)==null?void 0:n.stop_reason)==="tool_use")){_context153.n=7;break;}return _context153.a(2,(this._streamToolCalls.input=JSON.parse(this._streamToolCalls.input),this.handleTools([this._streamToolCalls],t)));case 7:return _context153.a(2,_defineProperty({},y,""));}},_callee153,this);}));function extractResultData(_x287,_x288){return _extractResultData35.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var s,i,_yield$this$callToolF3,n,o,a,l;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:if(!(!e||!t||!this._functionHandler)){_context154.n=1;break;}throw Error(b.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)};});_context154.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF3=_context154.v;n=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context154.n=3;break;}return _context154.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(_ref128){var l=_ref128.response;return typeof l!="string";})&&i.length===n.length)){_context154.n=4;break;}l=n.map(function(c,d){return{type:"tool_result",tool_use_id:e[d].id,content:c.response};});return _context154.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 _context154.a(2);}},_callee154,this);}));function handleTools(_x289,_x290){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var s,i,n;if(t.type==="image"){var o=(s=t.src)==null?void 0:s.split(",")[1];return{type:"image",source:{type:"base64",media_type:((n=(i=t.src)==null?void 0:i.match(/data:([^;]+)/))==null?void 0:n[1])||"image/jpeg",data:o||""}};}return _defineProperty({type:"text"},y,"[Unsupported file type: ".concat(t.type,"]"));});}}]);}(k);var jn=/*#__PURE__*/function(){function jn(){_classCallCheck(this,jn);}return _createClass(jn,null,[{key:"buildHeaders",value:function buildHeaders(){return{};}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"",method:z,handleVerificationResult:function handleVerificationResult(){}};}}]);}();var di=/*#__PURE__*/function(_k27){function di(e){var _this72$maxMessages,_l$model,_c$stream;var _this72;_classCallCheck(this,di);var o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=jn.buildKeyVerificationDetails(),i=jn.buildHeaders;_this72=_callSuper(this,di,[e,s,i,{key:"placeholder"}]),_this72.insertKeyPlaceholderText="",_this72.keyHelpUrl="",_this72.validateKeyProperty=!1,_this72.url="http://localhost:11434/api/chat",_this72.permittedErrorPrefixes=["Error"];var n=t.ollama;if(_typeof(n)===T){n.system&&(_this72._systemMessage=di.generateSystemMessage(n.system));var d=(a=(o=e.directConnection)==null?void 0:o.ollama)==null?void 0:a.function_handler;d&&(_this72._functionHandler=d),_this72.cleanConfig(n),Object.assign(_this72.rawBody,n);}(_this72$maxMessages=_this72.maxMessages)!==null&&_this72$maxMessages!==void 0?_this72$maxMessages:_this72.maxMessages=-1,(_l$model=(l=_this72.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="llama3.2",(_c$stream=(c=_this72.rawBody).stream)!==null&&_c$stream!==void 0?_c$stream:c.stream=!1;return _this72;}_inherits(di,_k27);return _createClass(di,[{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=J.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===v.USER_ROLE?"user":"assistant"};if(o.files&&o.files.length>0){var l=di.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 _callee155(e,t){var _this$_messages0;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:(_this$_messages0=this._messages)!==null&&_this$_messages0!==void 0?_this$_messages0:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context155.a(2);}},_callee155,this);}));function callServiceAPI(_x291,_x292){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var s,i,n;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(!e.error){_context156.n=1;break;}throw e.error.message;case 1:if(!e.text){_context156.n=2;break;}n=JSON.parse(e.text);return _context156.a(2,(s=n.message)!=null&&s.tool_calls?this.handleTools({tool_calls:n.message.tool_calls},t):_defineProperty({},y,((i=n.message)==null?void 0:i.content)||""));case 2:return _context156.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},y,e.message.content||""):_defineProperty({},y,""));}},_callee156,this);}));function extractResultData(_x293,_x294){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){var s,i,_yield$this$callToolF4,n,o;return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:if(!(!e.tool_calls||!t||!this._functionHandler)){_context157.n=1;break;}throw Error(b.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)};});_context157.n=2;return this.callToolFunction(this._functionHandler,i);case 2:_yield$this$callToolF4=_context157.v;n=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context157.n=3;break;}return _context157.a(2,o);case 3:if(!(s.messages.push({tool_calls:e.tool_calls,role:"assistant",content:""}),!n.find(function(_ref133){var a=_ref133.response;return typeof a!="string";})&&i.length===n.length)){_context157.n=4;break;}return _context157.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 _context157.a(2);}},_callee157,this);}));function handleTools(_x295,_x296){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"generateSystemMessage",value:function generateSystemMessage(e){return{role:"system",content:e};}},{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t.type==="image";}).map(function(t){var i;return((i=t.src)==null?void 0:i.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(k);var Ut=/*#__PURE__*/function(){function Ut(){_classCallCheck(this,Ut);}return _createClass(Ut,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty({Authorization:"".concat(se).concat(e)},R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===ie||n.error.type===we?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.x.ai/v1/models",method:z,handleVerificationResult:Ut.handleVerificationResult};}}]);}();var Ei=/*#__PURE__*/function(_k28){function Ei(e){var _o$model10;var _this73;_classCallCheck(this,Ei);var n,o;var t=e.directConnection,s=t==null?void 0:t.x;_this73=_callSuper(this,Ei,[e,Ut.buildKeyVerificationDetails(),Ut.buildHeaders,s]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("X"),_this73.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this73.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>",_this73.url=Ei.IMAGE_GENERATION_URL,_this73.permittedErrorPrefixes=[we,ie];var i=(n=t==null?void 0:t.x)==null?void 0:n.images;_typeof(i)===T&&Object.assign(_this73.rawBody,i),(_o$model10=(o=_this73.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="grok-2-image";return _this73;}_inherits(Ei,_k28);return _createClass(Ei,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text,i=JSON.parse(JSON.stringify(e));return s&&s!==""&&(i.prompt=s),i;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context158.a(2);}},_callee158,this);}));function callServiceAPI(_x297,_x298){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e){return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(!e.error){_context159.n=1;break;}throw e.error.message;case 1:return _context159.a(2,{files:e.data.map(function(s){return s.url?{src:s.url,type:"image"}:{src:"".concat(jt).concat(s.b64_json),type:"image"};})});}},_callee159);}));function extractResultData(_x299){return _extractResultData37.apply(this,arguments);}return extractResultData;}()}]);}(k);Ei.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Yi=Ei;var hi=/*#__PURE__*/function(){function hi(){_classCallCheck(this,hi);}return _createClass(hi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===we?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",method:z,handleVerificationResult:hi.handleVerificationResult};}}]);}();var mn=/*#__PURE__*/function(_k29){function mn(e){var _this74$maxMessages,_o$model11;var _this74;_classCallCheck(this,mn);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).qwen;if(_this74=_callSuper(this,mn,[e,hi.buildKeyVerificationDetails(),hi.buildHeaders,s]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Qwen"),_this74.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this74.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this74.permittedErrorPrefixes=["No static","The model",ks],_this74._systemMessage="",_typeof(s)===T){s.system_prompt&&(_this74._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.qwen)==null?void 0:n.function_handler;a&&(_this74._functionHandler=a),_this74.cleanConfig(s),Object.assign(_this74.rawBody,s);}(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_o$model11=(o=_this74.rawBody).model)!==null&&_o$model11!==void 0?_o$model11:o.model="qwen-plus";return _this74;}_inherits(mn,_k29);return _createClass(mn,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:mn.getTextWImagesContent(n),role:n.role===v.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 _callee160(e,t){var _this$_messages1;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:(_this$_messages1=this._messages)!==null&&_this$_messages1!==void 0?_this$_messages1:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context160.a(2);}},_callee160,this);}));function callServiceAPI(_x300,_x301){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var _s10;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:if(!(e.choices&&e.choices.length>0)){_context161.n=3;break;}_s10=e.choices[0];if(!_s10.delta){_context161.n=2;break;}return _context161.a(2,this.extractStreamResult(_s10,t));case 2:if(!_s10.message){_context161.n=3;break;}return _context161.a(2,_s10.message.tool_calls?this.handleToolsGeneric({tool_calls:_s10.message.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s10.message.content||""));case 3:return _context161.a(2,_defineProperty({},y,""));}},_callee161,this);}));function extractResultData(_x302,_x303){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:return _context162.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee162,this);}));function extractStreamResult(_x304,_x305){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var ui=/*#__PURE__*/function(){function ui(){_classCallCheck(this,ui);}return _createClass(ui,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},K,"".concat(se).concat(e)),R,N);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===ie?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:z,handleVerificationResult:ui.handleVerificationResult};}}]);}();var gn=/*#__PURE__*/function(_k30){function gn(e){var _this75$maxMessages,_o$model12;var _this75;_classCallCheck(this,gn);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).kimi;if(_this75=_callSuper(this,gn,[e,ui.buildKeyVerificationDetails(),ui.buildHeaders,s]),_this75.insertKeyPlaceholderText=_this75.genereteAPIKeyName("Kimi"),_this75.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this75.url="https://api.moonshot.ai/v1/chat/completions",_this75.permittedErrorPrefixes=[ht,"Not found"],_this75._systemMessage="You are Kimi, a helpful assistant created by Moonshot AI.",_typeof(s)===T){s.system_prompt&&(_this75._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.kimi)==null?void 0:n.function_handler;a&&(_this75._functionHandler=a),_this75.cleanConfig(s),Object.assign(_this75.rawBody,s);}(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1,(_o$model12=(o=_this75.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="moonshot-v1-8k";return _this75;}_inherits(gn,_k30);return _createClass(gn,[{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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(n){return{content:gn.getTextWImagesContent(n),role:n.role===v.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 _callee163(e,t){var _this$_messages10;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:(_this$_messages10=this._messages)!==null&&_this$_messages10!==void 0?_this$_messages10:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context163.a(2);}},_callee163,this);}));function callServiceAPI(_x306,_x307){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var _s11;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:if(!e.error){_context164.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context164.n=3;break;}_s11=e.choices[0];if(!_s11.delta){_context164.n=2;break;}return _context164.a(2,this.extractStreamResult(_s11,t));case 2:if(!_s11.message){_context164.n=3;break;}return _context164.a(2,_s11.message.tool_calls?this.handleToolsGeneric({tool_calls:_s11.message.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s11.message.content||""));case 3:return _context164.a(2,_defineProperty({},y,""));}},_callee164,this);}));function extractResultData(_x308,_x309){return _extractResultData39.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:return _context165.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee165,this);}));function extractStreamResult(_x310,_x311){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var il=/*#__PURE__*/function(_k31){function il(e){var _this76$maxMessages,_o$model13;var _this76;_classCallCheck(this,il);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.x;_this76=_callSuper(this,il,[e,Ut.buildKeyVerificationDetails(),Ut.buildHeaders,s]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("X"),_this76.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this76.url="https://api.x.ai/v1/chat/completions",_this76.permittedErrorPrefixes=[we,ie],_this76._systemMessage="";var i=(n=t.x)==null?void 0:n.chat;_typeof(i)===T&&(i.system_prompt&&(_this76._systemMessage=i.system_prompt),_this76.cleanConfig(i),Object.assign(_this76.rawBody,i)),(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1,(_o$model13=(o=_this76.rawBody).model)!==null&&_o$model13!==void 0?_o$model13:o.model="grok-3-latest";return _this76;}_inherits(il,_k31);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=J.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:o.text||"",role:o.role===v.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 _callee166(e,t){return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context166.a(2);}},_callee166,this);}));function callServiceAPI(_x312,_x313){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e){var t,s,i,n,o;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.object==="chat.completion.chunk")){_context167.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context167.a(2,(s=o==null?void 0:o.delta)!=null&&s.content?_defineProperty({},y,o.delta.content):_defineProperty({},y,""));case 2:return _context167.a(2,e.object==="chat.completion"&&(n=(i=e.choices)==null?void 0:i[0])!=null&&n.message?_defineProperty({},y,e.choices[0].message.content||""):_defineProperty({},y,""));}},_callee167);}));function extractResultData(_x314){return _extractResultData40.apply(this,arguments);}return extractResultData;}()}]);}(k);var nl=/*#__PURE__*/function(){function nl(){_classCallCheck(this,nl);}return _createClass(nl,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
|
232
229
|
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 Xi(e):t.openAI.speechToText?new zi(e):t.openAI.textToSpeech?new Ki(e):t.openAI.assistant?new cn(e):t.openAI.realtime?new Gi(e):new ws(e);if(t.assemblyAI)return new dn(e);if(t.cohere)return new oi(e);if(t.huggingFace)return t.huggingFace.textGeneration?new Ha(e):t.huggingFace.summarization?new qa(e):t.huggingFace.translation?new Ga(e):t.huggingFace.fillMask?new Ka(e):t.huggingFace.questionAnswer?new ja(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 hn(e);if(t.azure.openAI.assistant)return new qi(e);}if(t.azure.speechToText)return new Wi(e);if(t.azure.textToSpeech)return new $i(e);if(t.azure.summarization)return new Ji(e);if(t.azure.translation)return new Wa(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new $s(e):t.stabilityAI.imageToImageUpscale?new zs(e):t.stabilityAI.imageToImageMasking?new Js(e):new Ws(e);if(t.mistral)return new un(e);if(t.gemini)return new pn(e);if(t.claude)return new ci(e);if(t.deepSeek)return new tl(e);if(t.miniMax)return new sl(e);if(t.openRouter)return new ps(e);if(t.kimi)return new gn(e);if(t.x)return t.x.images?new Yi(e):new il(e);if(t.qwen)return new mn(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 za(e):new Qs(e);if(t.groq)return t.groq.textToSpeech?new Ya(e):new fn(e);if(t.perplexity)return new el(e);if(t.ollama)return new di(e);}return s&&Object.keys(s).length>0&&!i?new wt(e):new wt(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 Zi=xn;function A(r){return function(e,t){Object.defineProperty(e,t,{});var s=e.constructor,i=t.toLocaleLowerCase();s._attributes_[i]=Zi.attibutes[r],s._attributeToProperty_[i]=t;};}var fi=/*#__PURE__*/function(){function fi(e,t,s){_classCallCheck(this,fi);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(fi,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e,t){var s=fi.createIntroPanel(t);return e.style.display==="none"&&(e.style.display="block"),s.appendChild(e),s;}},{key:"createInternalIntroPanel",value:function createInternalIntroPanel(e,t){var s=fi.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 rl="<?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>",re=/*#__PURE__*/function(){function re(){_classCallCheck(this,re);}return _createClass(re,null,[{key:"createImage",value:function createImage(e,t,s,i){var n=new Image();return n.src=e.src,i&&ee.scrollDownOnImageLoad(n.src,t,s),ee.processContent("image",n,n.src,e.name);}// WORK - image still does not scroll down when loaded
|
233
230
|
},{key:"createImageMessage",value:function createImageMessage(e,t,s,i,n){var o=e.createNewMessageElement("",s),a=!i&&!e.focusMode&&n,l=re.createImage(t,e.elementRef,o.outerContainer,a);return o.bubbleElement.appendChild(l),o.bubbleElement.classList.add(re.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===v.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=re.createAudioElement(t,s),o=e.createMessageElementsOnOrientation("",s,i);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(re.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(rl);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||ee.DEFAULT_FILE_NAME,t.appendChild(s),t.appendChild(n),ee.processContent("any",t,e.src,n.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,s,i){var n=e.createMessageElementsOnOrientation("",s,i),o=re.createAnyFile(t);return n.bubbleElement.classList.add(re.ANY_FILE_BUBBLE_CLASS),n.bubbleElement.appendChild(o),{type:"file",elements:n};}},{key:"createMessages",value:function createMessages(e,t,s,i){var n=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;return t.map(function(o,a){var l;if(o.ref&&(o=ee.removeFileRef(o)),ee.isAudioFile(o)){var c=re.createNewAudioMessage(e,o,s,n),d=(l=e.textToSpeech)==null?void 0:l.service;return d&&(d.autoPlay&&re.autoPlayAudio(c.audioElement),typeof d.displayAudio=="boolean"&&!d.displayAudio)?void 0:c;}return ee.isImageFile(o)?re.createImageMessage(e,o,s,n,i&&a===0):re.createNewAnyFileMessage(e,o,s,n);}).filter(function(o){return o!==void 0;});}// no overwrite previous message logic as it is complex to track which files are to be overwritten
|
234
|
-
},{key:"addMessages",value:function addMessages(e,t,s,i,n){var o=!i&&
|
231
|
+
},{key:"addMessages",value:function addMessages(e,t,s,i,n){var o=!i&&B.isScrollbarAtBottomOfElement(e.elementRef);re.createMessages(e,t,s,o,n).filter(function(l){return l!==void 0;}).forEach(function(_ref145,d){var l=_ref145.type,c=_ref145.elements;var u=d===0&&o;ee.addMessage(e,c,l,s,n,u);});}}]);}();re.IMAGE_BUBBLE_CLASS="image-message",re.AUDIO_BUBBLE_CLASS="audio-message",re.ANY_FILE_BUBBLE_CLASS="any-file-message";var pi=re;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)Be.overwriteElements(e,s,t[1].html);else{var a=Be.create(e,s,t[0].role),l=((n=t[1].files)==null?void 0:n[((i=t[1].files)==null?void 0:i.length)-1])||t[1].text,c=l.outerContainer.nextSibling;(o=c==null?void 0:c.parentElement)==null||o.insertBefore(a.outerContainer,c),e.messageElementRefs.splice(e.messageElementRefs.length-1,1);var d=e.messageElementRefs.findIndex(function(u){return u===l;});e.messageElementRefs.splice(d+1,0,a),t[1].html=a;}t[0].html=s;}// finds beforeElement, creates new elements, remove old and adds new ones
|
235
232
|
},{key:"updateFileMessages",value:function updateFileMessages(e,t,s){var u,h;var i=t[0].role,n=pi.createMessages(e,s,i,!!t[1].text),o=t[1].html,a=((h=t[1].files)==null?void 0:h[((u=t[1].files)==null?void 0:u.length)-1])||t[1].text,l=o||a;var c=e.messageElementRefs.findIndex(function(f){return f===l;});a&&(c+=1);var d=(o==null?void 0:o.outerContainer)||(a==null?void 0:a.outerContainer.nextSibling);n.forEach(function(_ref146,p){var f=_ref146.type,m=_ref146.elements;var g;ee.setElementProps(e,m,f,i),(g=d.parentElement)==null||g.insertBefore(m.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(c+p,0,m);}),Ee.removeFilesMessages(e,t),t[1].files=n.map(function(_ref147){var f=_ref147.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
|
236
|
-
},{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;v.classifyRoleMessages(n),v.resetAllRoleElements(n,o,a);}else console.error("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var ol=/*#__PURE__*/function(){function ol(){_classCallCheck(this,ol);}return _createClass(ol,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(_Ae){function xe(e,t,s){var
|
237
|
-
_inherits(xe,_Ae);return _createClass(xe,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1];!e&&Ae.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(
|
238
|
-
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var
|
233
|
+
},{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;v.classifyRoleMessages(n),v.resetAllRoleElements(n,o,a);}else console.error("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var ol=/*#__PURE__*/function(){function ol(){_classCallCheck(this,ol);}return _createClass(ol,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(_Ae){function xe(e,t,s){var _this77;_classCallCheck(this,xe);var a,l;_this77=_callSuper(this,xe,[e]);var i=t.permittedErrorPrefixes,n=t.introPanelMarkUp,o=t.demo;_this77._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this77._onClearMessages=Ct.onClearMessages.bind(_this77,e),_this77._onError=Ct.onError.bind(_this77,e),_this77._isLoadingMessageAllowed=xe.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this77.setLoadingToggle.bind(_this77)),_this77._permittedErrorPrefixes=i,_this77.addSetupMessageIfNeeded(e,t)||_this77.populateIntroPanel(s,n,e.introPanelStyle),o&&_this77.prepareDemo(te.processDemo(o),e.loadHistory),_this77.addIntroductoryMessages(e,t),new As(e,_this77,t),_this77._displayServiceErrorMessages=(l=e.errorMessages)==null?void 0:l.displayServiceErrorMessages,e.getMessages=function(){return v.deepCloneMessagesWithReferences(_this77.messageToElements.map(function(_ref148){var _ref149=_slicedToArray(_ref148,1),c=_ref149[0];return c;}));},e.clearMessages=_this77.clearMessages.bind(_this77,t),e.refreshMessages=_this77.refreshTextMessages.bind(_this77,e.remarkable),e.scrollToBottom=B.scrollToBottom.bind(_this77,_this77.elementRef),e.addMessage=function(c,d){_this77.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(c,d){return Ee.update(_this77,c,d);},t.isWebModel()&&t.setUpMessages(_this77),e.textToSpeech&&Bt.processConfig(e.textToSpeech,function(c){_this77.textToSpeech=c;});return _this77;}// WORK - document how to display loading with toggle after user message via onMessage
|
234
|
+
_inherits(xe,_Ae);return _createClass(xe,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1];!e&&Ae.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=ol.getText(e,t);if(s){var i=this.createAndAppendNewMessageElement(s,v.AI_ROLE);this.applyCustomStyles(i,v.AI_ROLE,!1);}return!!s;}// WORK - const file for deep chat classes
|
235
|
+
},{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this78=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=_this78.messageElementRefs[_this78.messageElementRefs.length-1].innerContainer;v.hideRoleElements(a,_this78.avatar,_this78.name);}_this78.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,v.AI_ROLE):e!=null&&e.html&&(s=Be.add(this,e.html,v.AI_ROLE,!1)),s&&(this.applyCustomStyles(s,v.AI_ROLE,!1,(i=this.messageStyles)==null?void 0:i.intro),s.outerContainer.classList.add(Ae.INTRO_CLASS),t&&(s.outerContainer.style.display="none")),s;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer.classList.contains(Ae.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!==v.USER_ROLE&&Bt.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)&&pi.addMessages(this,e.files,e.role,!!e.text,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=!e.text&&(!e.files||e.files.length===0),n=Be.add(this,e.html,e.role,i,t,s);!s&&De.isElementTemporary(n)&&delete e.html;}}// this should not be activated by streamed messages
|
239
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!==v.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(_ref150){var _ref151=_slicedToArray(_ref150,1),u=_ref151[0];return u;}))),this._activeLoadingConfig&&this.addLoadingMessage(!1),i;}},{key:"isValidMessageContent",value:function isValidMessageContent(e){return e.text||e.html||e.files&&e.files.length>0;}},{key:"updateStateOnMessage",value:function updateStateOnMessage(e,t){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(!t){var n=v.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,n]);}s&&this.sendClientUpdate(e,i);}// prettier-ignore
|
240
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(Ue.MESSAGE_CLASS)&&t.textContent===""||xe.isTemporaryElement(e))&&this.removeLastMessage();}// prettier-ignore
|
241
|
-
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var
|
242
|
-
},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,l,c,d,u,h;if(Ae.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((a=this._activeLoadingConfig)==null?void 0:a.role)||v.AI_ROLE,s=((l=this._activeLoadingConfig)==null?void 0:l.style)||((d=(c=this.messageStyles)==null?void 0:c.loading)==null?void 0:d.message),i=s==null?void 0:s.html,n=i?Be.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=(u=this.avatar)==null?void 0:u.getAvatarContainer(n.innerContainer))==null||h.classList.add("loading-avatar-container"),!this.focusMode&&
|
243
|
-
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(v.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 _ref152;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===T?!1:!!e.displayLoadingBubble:(_ref152=_typeof(e.displayLoadingBubble)===T||e.displayLoadingBubble)!==null&&_ref152!==void 0?_ref152:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var
|
238
|
+
},{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this79=this;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var c,d,u,h,f,m;(c=this._hiddenAttachments)==null||c.readdHiddenFiles(),this.removeMessageOnError();var i=this.getPermittedMessage(t)||((d=this._errorMessageOverrides)==null?void 0:d[e])||((u=this._errorMessageOverrides)==null?void 0:u["default"])||"Error, please try again.",n=this.createMessageElementsOnOrientation(i,"error",s);v.hideRoleElements(n.innerContainer,this.avatar,this.name);var o=n.bubbleElement,a=n.outerContainer;o.classList.add(v.ERROR_MESSAGE_TEXT_CLASS),this.renderText(o,i);var l=he.extractParticularSharedStyles(["fontSize","fontFamily"],(h=this.messageStyles)==null?void 0:h["default"]);he.applyCustomStylesToElements(n,!1,l),he.applyCustomStylesToElements(n,!1,(f=this.messageStyles)==null?void 0:f.error),s||this.appendOuterContainerElemet(a),this.textToSpeech&&Bt.speak(i,this.textToSpeech),(m=this._onError)==null||m.call(this,i),setTimeout(function(){return B.scrollToBottom(_this79.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()&&v.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:v.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
|
239
|
+
},{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,l,c,d,u,h;if(Ae.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((a=this._activeLoadingConfig)==null?void 0:a.role)||v.AI_ROLE,s=((l=this._activeLoadingConfig)==null?void 0:l.style)||((d=(c=this.messageStyles)==null?void 0:c.loading)==null?void 0:d.message),i=s==null?void 0:s.html,n=i?Be.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=(u=this.avatar)==null?void 0:u.getAvatarContainer(n.innerContainer))==null||h.classList.add("loading-avatar-container"),!this.focusMode&&B.isScrollbarAtBottomOfElement(this.elementRef)&&B.scrollToBottom(this.elementRef);}},{key:"populateIntroPanel",value:function populateIntroPanel(e,t,s){(e||t)&&(this._introPanel=new fi(e,t,s),this._introPanel._elementRef&&(le.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef)));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:return _context168.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||ee.DEFAULT_FILE_NAME;i({name:n,type:"any",ref:s.file});}else{var _n5=new FileReader();_n5.readAsDataURL(s.file),_n5.onload=function(){var o=s.file.name;i({src:_n5.result,name:o,type:s.type,ref:s.file});};}});}))));}},_callee168,this);}));function addMultipleFiles(_x315,_x316){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
|
240
|
+
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(v.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 _ref152;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===T?!1:!!e.displayLoadingBubble:(_ref152=_typeof(e.displayLoadingBubble)===T||e.displayLoadingBubble)!==null&&_ref152!==void 0?_ref152:!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(Ue.MESSAGE_CLASS):!1;}}]);}(Ae);var Q=/*#__PURE__*/function(){function Q(){_classCallCheck(this,Q);}return _createClass(Q,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(Q.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS),t.classList.add(Q.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS)):s["outside-left"].length===0&&s["outside-right"].length>0&&(e[3].classList.add(Q.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS),t.classList.add(Q.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS));}// when submit is the only button
|
244
241
|
// when submit button is outside by itself - we increase the height for a better look
|
245
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(Q.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),t.classList.add(Q.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(Q.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),t.classList.add(Q.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),s["outside-right"].map(function(i){return i.button.elementRef.classList.add("submit-button-enlarged");});}}// prettier-ignore
|
246
243
|
},{key:"set",value:function set(e,t,s,i){!!Q.adjustOutsideSubmit(t,s,i)||Q.adjustForOutsideButton(t,s,i),Q.adjustInputPadding(e,i);}}]);}();Q.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment",Q.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment",Q.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment",Q.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var Qi=Q;var Ht=/*#__PURE__*/function(){function Ht(){_classCallCheck(this,Ht);}return _createClass(Ht,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=Ht.getContainerIndex(s);e[i].appendChild(t),i===3&&t.classList.add("outside-right");}}]);}();var qn=["camera","gifs","images","audio","mixedFiles","submit","microphone"],al="<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 u;return((u=d.svg)==null?void 0:u.content)==="";});l.classList.contains(He.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 Pe=fe;var H=/*#__PURE__*/function(_It2){// prettier-ignore
|
247
|
-
function H(e,t,s,i){var
|
244
|
+
function H(e,t,s,i){var _this80;_classCallCheck(this,H);var l,c,d,u,h,f;var n=((u=(d=(c=(l=e==null?void 0:e.styles)==null?void 0:l.button)==null?void 0:c["default"])==null?void 0:d.text)==null?void 0:u.content)||"Custom ".concat(t),o=al,a=Le.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this80=_callSuper(this,H,[H.createButtonElement(),o,e==null?void 0:e.position,a,((h=e==null?void 0:e.styles)==null?void 0:h.button)||a&&{},n]),_this80._state="default",_this80.isCustom=!0,_this80._innerElements=_this80.createInnerElementsForStates(_this80.customStyles),_this80._menuStyles=i,_this80._onClick=e.onClick,_this80._dropupStyles=(f=e.styles)==null?void 0:f.dropup,_this80.setSetState(e),_this80.addClickListener(s),_this80.changeState(e.initialState,!0);return _this80;}_inherits(H,_It2);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 _this81=this;e.setState=function(t){t==="default"&&_this81.changeToDefault(),t==="active"&&_this81.changeToActive(),t==="disabled"&&_this81.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this82=this;this.elementRef.addEventListener("click",function(){var s;var t=(s=_this82._onClick)==null?void 0:s.call(_this82,_this82._state);e==null||e(),(t==="default"||t==="active"||t==="disabled")&&_this82.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(Pe.TEXT_CLASS);});_s14&&Object.assign(_s14.style,e.text);}if(e!=null&&e.iconContainer){var _s15=t.find(function(i){return i.classList.contains(Pe.ICON_CLASS);});_s15&&Object.assign(_s15.style,e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var s,i,n;this.elementRef=le.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((s=e==null?void 0:e.svg)==null?void 0:s.content)===""||this.elementRef.appendChild(Pe.createItemIcon(this.svg,(i=this._menuStyles)==null?void 0:i.iconContainer)),this.elementRef.appendChild(Pe.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(Pe.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&&$.unsetAllCSS(this.elementRef,(n=this.customStyles)==null?void 0:n.active),(o=this.customStyles)!=null&&o.disabled&&$.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),q.removeAriaDisabled(this.elementRef),this._state="default");}},{key:"changeToActive",value:function changeToActive(e){var t,s;!e&&this._state==="active"||(this.elementRef.classList.contains(Pe.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),q.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(Pe.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&&$.unsetAllCSS(this.elementRef,(n=this.customStyles)==null?void 0:n.active),(o=this.customStyles)!=null&&o["default"]&&$.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),q.addAriaDisabled(this.elementRef),this._state="disabled");}// called after class is initialised
|
248
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,u;var n=this.createInnerElements(e,t,i);var o=(c=(l=i==null?void 0:i[t])==null?void 0:l.svg)==null?void 0:c.content,a=(u=(d=i==null?void 0:i[t])==null?void 0:d.text)==null?void 0:u.content;if(o===void 0||a===void 0){var _us$parseSVGTextEleme4=us.parseSVGTextElements(s),h=_us$parseSVGTextEleme4.svg,f=_us$parseSVGTextEleme4[y],_us$parseSVGTextEleme5=us.parseSVGTextElements(n),m=_us$parseSVGTextEleme5.svg,p=_us$parseSVGTextEleme5[y],g=[];H.addToInnerElements(g,o,h,m),H.addToInnerElements(g,a,f,p),n=g;}return n;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=document.createElement("div");return e.classList.add("input-button",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;});}}]);}(It);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 ll="<?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
|
249
246
|
// prettier-ignore
|
250
|
-
},{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
|
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")),Ts.focusItemWhenOnEdge(t,s));}}]);}();var yn=/*#__PURE__*/function(){function yn(e,t){var _this83=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 _this83.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=Pe.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
|
251
248
|
},{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
|
252
|
-
},{key:"windowKeyDown",value:function windowKeyDown(e,t){var s,i,n;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===Y.ESCAPE?(this.close(),(s=this.highlightedItem)==null||s.dispatchEvent(new MouseEvent("mouseleave"))):t.key===Y.ENTER?((i=this.highlightedItem)==null||i.click(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===Y.ARROW_DOWN?Ts.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===Y.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(_It3){function _t(e,t){var
|
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===Y.ESCAPE?(this.close(),(s=this.highlightedItem)==null||s.dispatchEvent(new MouseEvent("mouseleave"))):t.key===Y.ENTER?((i=this.highlightedItem)==null||i.click(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===Y.ARROW_DOWN?Ts.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===Y.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(_It3){function _t(e,t){var _this84;_classCallCheck(this,_t);var n,o;var s=Le.tryCreateConfig("Options",(n=t==null?void 0:t.button)==null?void 0:n.tooltip);_this84=_callSuper(this,_t,[_t.createButtonElement(),ll,void 0,s,{styles:(o=t==null?void 0:t.button)==null?void 0:o.styles}]);var i=_this84.createInnerElementsForStates(_this84.customStyles);_this84._menu=new yn(e,t==null?void 0:t.menu),_this84.addClickEvent(),_this84.buttonContainer=_t.createButtonContainer(),_this84.changeElementsByState(i.styles),_this84.buttonContainer.appendChild(_this84.elementRef),_this84.elementRef.classList.add(_t.BUTTON_ICON_CLASS),_this84.buttonContainer.appendChild(_this84._menu.elementRef),_this84.reapplyStateStyle("styles"),_this84.addContainerEvents(e);return _this84;}_inherits(_t,_It3);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 _this85=this;e.addEventListener("click",function(t){var s=t.target.classList;!s.contains(_t.BUTTON_ICON_CLASS)&&!s.contains(xt.DISABLED_CONTAINER_CLASS)&&_this85._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";}}]);}(It);_t.BUTTON_ICON_CLASS="dropup-button";var mi=_t;var de=/*#__PURE__*/function(){function de(){_classCallCheck(this,de);}return _createClass(de,null,[{key:"addToDropup",value:// prettier-ignore
|
253
250
|
function addToDropup(e,t,s,i){var n=new mi(s,i);qn.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(_ref153){var a=_ref153.button;return n.addItem(a);});var o=mi.getPosition(t,i);Ht.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){Ht.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
|
254
251
|
},{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?(qn.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
|
255
|
-
},{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 cl="<?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>",dl="<?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",hl="<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>",ul="<?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",fl={images:{id:"upload-images-icon",svgString:dl,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:ul,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:hl,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:cl,dropupText:"File"}};var Ci=/*#__PURE__*/function(_It4){function Ci(e){var _this85;_classCallCheck(this,Ci);(e==null?void 0:e.position)==="dropup-menu"&&(e.position="outside-right");var t=Le.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this85=_callSuper(this,Ci,[Ci.createMicrophoneElement(),Cr,e==null?void 0:e.position,t,e]),_this85.isActive=!1,_this85._innerElements=_this85.createInnerElementsForStates(_this85.customStyles),_this85.changeToDefault();return _this85;}_inherits(Ci,_It4);return _createClass(Ci,[{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;}}]);}(It);function pl(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r["default"]:r;}var Bs={},qt={},Vt={},Gt={},Kt={},Vn;function wi(){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 Gn;function Rr(){if(Gn)return Gt;Gn=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.Translate=void 0;var r=wi();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 Gt.Translate=e,Gt;}var Kn;function ml(){if(Kn)return Vt;Kn=1,Object.defineProperty(Vt,"__esModule",{value:!0}),Vt.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 Vt.WebSpeechTranscript=e,Vt;}var zt={},zn;function bn(){if(zn)return zt;zn=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 Jt={},$t={},Jn;function gl(){if(Jn)return $t;Jn=1,Object.defineProperty($t,"__esModule",{value:!0}),$t.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 _this86=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,_this86.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 $t.EventListeners=r,r.KEY_DOWN_TIMEOUT=null,$t;}var Wt={},$n;function yl(){if($n)return Wt;$n=1,Object.defineProperty(Wt,"__esModule",{value:!0}),Wt.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 Wt.PreResultUtils=r,Wt;}var Xt={},Yt={},Wn;function Mr(){if(Wn)return Yt;Wn=1,Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.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
|
252
|
+
},{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 cl="<?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>",dl="<?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",hl="<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>",ul="<?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",fl={images:{id:"upload-images-icon",svgString:dl,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:ul,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:hl,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:cl,dropupText:"File"}};var Ci=/*#__PURE__*/function(_It4){function Ci(e){var _this86;_classCallCheck(this,Ci);(e==null?void 0:e.position)==="dropup-menu"&&(e.position="outside-right");var t=Le.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this86=_callSuper(this,Ci,[Ci.createMicrophoneElement(),Cr,e==null?void 0:e.position,t,e]),_this86.isActive=!1,_this86._innerElements=_this86.createInnerElementsForStates(_this86.customStyles),_this86.changeToDefault();return _this86;}_inherits(Ci,_It4);return _createClass(Ci,[{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;}}]);}(It);function pl(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r["default"]:r;}var Bs={},qt={},Vt={},Gt={},Kt={},Vn;function wi(){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 Gn;function Rr(){if(Gn)return Gt;Gn=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.Translate=void 0;var r=wi();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 Gt.Translate=e,Gt;}var Kn;function ml(){if(Kn)return Vt;Kn=1,Object.defineProperty(Vt,"__esModule",{value:!0}),Vt.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 Vt.WebSpeechTranscript=e,Vt;}var zt={},zn;function bn(){if(zn)return zt;zn=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 Jt={},$t={},Jn;function gl(){if(Jn)return $t;Jn=1,Object.defineProperty($t,"__esModule",{value:!0}),$t.EventListeners=void 0;var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(t,s){return Array.isArray(t)?t.find(function(i){return s===i;}):s===t?t:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(t){var _this87=this;t.element&&r.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(r.KEY_DOWN_TIMEOUT!==null&&clearTimeout(r.KEY_DOWN_TIMEOUT),r.KEY_DOWN_TIMEOUT=setTimeout(function(){r.KEY_DOWN_TIMEOUT=null,_this87.resetRecording(t);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(t,s){this.mouseDownElement=r.getElementIfFocusedOnAvailable(t,s.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0;}},{key:"add",value:function add(t,s){var i=(s==null?void 0:s.insertInCursorLocation)===void 0||(s==null?void 0:s.insertInCursorLocation);s!=null&&s.element&&i&&(t.mouseDownEvent=r.mouseDownWindow.bind(t,s.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=r.mouseUpWindow.bind(t,s),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=r.keyDownWindow.bind(t,s),document.addEventListener("keydown",t.keyDownEvent));}},{key:"remove",value:function remove(t){document.removeEventListener("mousedown",t.mouseDownEvent),document.removeEventListener("mouseup",t.mouseUpEvent),document.removeEventListener("keydown",t.keyDownEvent);}}]);}();return $t.EventListeners=r,r.KEY_DOWN_TIMEOUT=null,$t;}var Wt={},$n;function yl(){if($n)return Wt;$n=1,Object.defineProperty(Wt,"__esModule",{value:!0}),Wt.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 Wt.PreResultUtils=r,Wt;}var Xt={},Yt={},Wn;function Mr(){if(Wn)return Yt;Wn=1,Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.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
|
256
253
|
// they can only safely be scrolled to the end
|
257
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 Yt.AutoScroll=r,Yt;}var Zt={},Xn;function Ti(){if(Xn)return Zt;Xn=1,Object.defineProperty(Zt,"__esModule",{value:!0}),Zt.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 Zt.Elements=r,Zt;}var Qt={},Yn;function Ri(){if(Yn)return Qt;Yn=1,Object.defineProperty(Qt,"__esModule",{value:!0}),Qt.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)
|
258
255
|
},{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
|
@@ -279,32 +276,32 @@ function addToDropup(e,t,s,i){var n=new mi(s,i);qn.forEach(function(a){var l=t["
|
|
279
276
|
},{key:"resetRecording",value:function resetRecording(h){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(h,!0);}// prettier-ignore
|
280
277
|
},{key:"updateElements",value:function updateElements(h,f,m){var p;var g=c.Text.capitalize(f);if(this.finalTranscript===g&&h==="")return;e.PreResultUtils.process(this,m,h==="",this._onPreResult,this._options)&&(h="",m="");var E=this.commands&&t.CommandUtils.execCommand(this,m,this._options,this._primitiveElement||this._genericElement,this._originalText);if(E){if(E.doNotProcessTranscription)return;h="",m="";}if(this.isPaused||this.isWaitingForCommand)return;(p=this._onResult)===null||p===void 0||p.call(this,m,h===""),this.finalTranscript=g,this._displayInterimResults||(h="");var I=this.finalTranscript===""&&h==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,h,I):this._genericElement&&this.updateGenericElement(this._genericElement,h,I);}// prettier-ignore
|
281
278
|
// remember that padding values here contain actual text left and right
|
282
|
-
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(h,f,m){this.isHighlighted&&i.Highlight.removeForPrimitive(this,h),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,h),m&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var p=this.startPadding+this.finalTranscript+f;if(h.value=p+this.endPadding,!this.isTargetInShadow){var g=p.length+this.numberOfSpacesAfterNewText;l.Cursor.setOffsetForPrimitive(h,g,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&s.AutoScroll.scrollSafariPrimitiveToEnd(h);}},{key:"updateGenericElement",value:function updateGenericElement(h,f,m){this.isHighlighted&&i.Highlight.removeForGeneric(this,h),this.spansPopulated||n.Elements.appendSpans(this,h);var p=(m?"":this.startPadding)+c.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=p;var g=s.AutoScroll.isRequired(this.autoScroll,h);s.AutoScroll.changeStateIfNeeded(this,g);var E=c.Text.lineBreak(f)+(m?"":this.endPadding);this.interimSpan.innerHTML=E,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&l.Cursor.setOffsetForSafariGeneric(h,p.length+E.length),g&&s.AutoScroll.scrollGeneric(this,h),m&&(this.scrollingSpan.innerHTML="");}},{key:"finalise",value:function finalise(h){this._genericElement&&(h?(this.finalSpan=n.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=n.Elements.createInterimSpan(),this.scrollingSpan=n.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),r.EventListeners.remove(this);}},{key:"setInterimColorToFinal",value:function setInterimColorToFinal(){this.interimSpan.style.color=this._finalTextColor||"black";}},{key:"resetState",value:function resetState(h){this._primitiveElement=void 0,this._genericElement=void 0,this.finalTranscript="",this.finalSpan.innerHTML="",this.interimSpan.innerHTML="",this.scrollingSpan.innerHTML="",this.startPadding="",this.endPadding="",this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,h||(this.stopTimeout=void 0);}},{key:"setStateOnStart",value:function setStateOnStart(){var h;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(h=this._onStart)===null||h===void 0||h.call(this);}},{key:"setStateOnStop",value:function setStateOnStop(){var h;this.recognizing=!1,this.isRestarting||(h=this._onStop)===null||h===void 0||h.call(this);}},{key:"setStateOnError",value:function setStateOnError(h){var f;(f=this._onError)===null||f===void 0||f.call(this,h),this.recognizing=!1;}}]);}();return Jt.Speech=d,Jt;}var sr;function _l(){if(sr)return qt;sr=1,Object.defineProperty(qt,"__esModule",{value:!0}),qt.WebSpeech=void 0;var r=ml(),e=bn(),t=kr();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
|
283
|
-
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 cs.AzureTranscript=e,cs;}var dr;function Rl(){if(dr)return is;dr=1,Object.defineProperty(is,"__esModule",{value:!0}),is.Azure=void 0;var r=Sl(),e=Al(),t=Cl(),s=wl(),i=Tl(),n=kr();var o=/*#__PURE__*/function(_n$Speech){function o(){var
|
279
|
+
},{key:"updatePrimitiveElement",value:function updatePrimitiveElement(h,f,m){this.isHighlighted&&i.Highlight.removeForPrimitive(this,h),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,h),m&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var p=this.startPadding+this.finalTranscript+f;if(h.value=p+this.endPadding,!this.isTargetInShadow){var g=p.length+this.numberOfSpacesAfterNewText;l.Cursor.setOffsetForPrimitive(h,g,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&s.AutoScroll.scrollSafariPrimitiveToEnd(h);}},{key:"updateGenericElement",value:function updateGenericElement(h,f,m){this.isHighlighted&&i.Highlight.removeForGeneric(this,h),this.spansPopulated||n.Elements.appendSpans(this,h);var p=(m?"":this.startPadding)+c.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=p;var g=s.AutoScroll.isRequired(this.autoScroll,h);s.AutoScroll.changeStateIfNeeded(this,g);var E=c.Text.lineBreak(f)+(m?"":this.endPadding);this.interimSpan.innerHTML=E,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&l.Cursor.setOffsetForSafariGeneric(h,p.length+E.length),g&&s.AutoScroll.scrollGeneric(this,h),m&&(this.scrollingSpan.innerHTML="");}},{key:"finalise",value:function finalise(h){this._genericElement&&(h?(this.finalSpan=n.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=n.Elements.createInterimSpan(),this.scrollingSpan=n.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),r.EventListeners.remove(this);}},{key:"setInterimColorToFinal",value:function setInterimColorToFinal(){this.interimSpan.style.color=this._finalTextColor||"black";}},{key:"resetState",value:function resetState(h){this._primitiveElement=void 0,this._genericElement=void 0,this.finalTranscript="",this.finalSpan.innerHTML="",this.interimSpan.innerHTML="",this.scrollingSpan.innerHTML="",this.startPadding="",this.endPadding="",this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,h||(this.stopTimeout=void 0);}},{key:"setStateOnStart",value:function setStateOnStart(){var h;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(h=this._onStart)===null||h===void 0||h.call(this);}},{key:"setStateOnStop",value:function setStateOnStop(){var h;this.recognizing=!1,this.isRestarting||(h=this._onStop)===null||h===void 0||h.call(this);}},{key:"setStateOnError",value:function setStateOnError(h){var f;(f=this._onError)===null||f===void 0||f.call(this,h),this.recognizing=!1;}}]);}();return Jt.Speech=d,Jt;}var sr;function _l(){if(sr)return qt;sr=1,Object.defineProperty(qt,"__esModule",{value:!0}),qt.WebSpeech=void 0;var r=ml(),e=bn(),t=kr();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 _this88=this;this._service&&(this._service.onstart=function(){_this88.setStateOnStart();},this._service.onerror=function(n){e.Browser.IS_SAFARI()&&n.message==="Another request is started"||n.error==="aborted"&&_this88.isRestarting||n.error!=="no-speech"&&_this88.error(n.message||n.error);},this._service.onaudioend=function(){_this88.setStateOnStop();},this._service.onend=function(){_this88._stopping=!1;},this._service.onresult=function(n){if(_typeof(n.results)>"u"&&_this88._service)_this88._service.onend=null,_this88._service.stop();else if(_this88._extractText&&!_this88._stopping){var _this88$_extractText=_this88._extractText(n,_this88.finalTranscript,_this88._translations),o=_this88$_extractText.interimTranscript,a=_this88$_extractText.finalTranscript,l=_this88$_extractText.newText;_this88.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 ss={},ir;function El(){if(ir)return ss;ir=1,Object.defineProperty(ss,"__esModule",{value:!0}),ss.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 ss.GlobalState=r,r.doubleClickPending=!1,ss;}var is={},ns={},nr;function Sl(){if(nr)return ns;nr=1,Object.defineProperty(ns,"__esModule",{value:!0}),ns.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 ns.PreventConnectionStop=r,ns;}var rs={},os={},rr;function xl(){return rr||(rr=1,Object.defineProperty(os,"__esModule",{value:!0}),os.README_URL=void 0,os.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),os;}var or;function Al(){if(or)return rs;or=1,Object.defineProperty(rs,"__esModule",{value:!0}),rs.AzureSpeechConfig=void 0;var r=xl();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 _callee169(s,i){return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:if(!i.region){_context169.n=1;break;}return _context169.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 _context169.a(2);}},_callee169);}));function getNewSpeechConfig(_x317,_x318){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 _callee170(s,i){var n;return _regenerator().w(function(_context170){while(1)switch(_context170.n){case 0:_context170.n=1;return e.getNewSpeechConfig(s,i);case 1:n=_context170.v;return _context170.a(2,(n&&e.process(n,i),n));}},_callee170);}));function get(_x319,_x320){return _get.apply(this,arguments);}return get;}()}]);}();return rs.AzureSpeechConfig=e,rs;}var as={},ar;function Cl(){if(ar)return as;ar=1,Object.defineProperty(as,"__esModule",{value:!0}),as.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 as.StopTimeout=r,r.DEFAULT_MS=2e4,as;}var ls={},lr;function wl(){if(lr)return ls;lr=1,Object.defineProperty(ls,"__esModule",{value:!0}),ls.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 ls.AzureAudioConfig=r,ls;}var cs={},cr;function Tl(){if(cr)return cs;cr=1,Object.defineProperty(cs,"__esModule",{value:!0}),cs.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
|
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 cs.AzureTranscript=e,cs;}var dr;function Rl(){if(dr)return is;dr=1,Object.defineProperty(is,"__esModule",{value:!0}),is.Azure=void 0;var r=Sl(),e=Al(),t=Cl(),s=wl(),i=Tl(),n=kr();var o=/*#__PURE__*/function(_n$Speech){function o(){var _this89;_classCallCheck(this,o);_this89=_callSuper(this,o,arguments),_this89._newTextPadding="";return _this89;}_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 _callee171(l){var c,_t42;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:_t42=this.validate(l);if(!_t42){_context171.n=2;break;}_context171.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 _context171.a(2);}},_callee171,this);}));function startAsync(_x321){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 _callee172(l){var c,d,u,h,_l$autoLanguage,f,m,p,g;return _regenerator().w(function(_context172){while(1)switch(_context172.n){case 0:c=o.getAPI();d=s.AzureAudioConfig.get(c.AudioConfig,l.deviceId);_context172.n=1;return e.AzureSpeechConfig.get(c.SpeechConfig,l);case 1:u=_context172.v;if(u){if(l.autoLanguage&&l.autoLanguage.languages.length>0){_l$autoLanguage=l.autoLanguage,f=_l$autoLanguage.type,m=_l$autoLanguage.languages,p=m.slice(0,f==="Continuous"?10:4),g=c.AutoDetectSourceLanguageConfig.fromLanguages(p);f==="Continuous"&&(g.mode=1),h=c.SpeechRecognizer.FromConfig(u,g,d);}else h=new c.SpeechRecognizer(u,d);this.setEvents(h),this._service=h,l.retrieveToken&&this.retrieveTokenInterval(l.retrieveToken);}else this.error("Unable to contact Azure server");case 2:return _context172.a(2);}},_callee172,this);}));function instantiateService(_x322){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
|
284
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,u=_i$AzureTranscript$ex.finalTranscript,h=_i$AzureTranscript$ex.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(d,u,h);}// prettier-ignore
|
285
|
-
},{key:"onRecognized",value:function onRecognized(l,c){var d=c.result;switch(d.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(d.text&&!this._stopping){var _i$AzureTranscript$ex2=i.AzureTranscript.extract(this._newTextPadding+d.text,this.finalTranscript,!0,this._translations),u=_i$AzureTranscript$ex2.interimTranscript,h=_i$AzureTranscript$ex2.finalTranscript,f=_i$AzureTranscript$ex2.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(u,h,f),h!==""&&(this._newTextPadding=" ");}break;}}},{key:"onCanceled",value:function onCanceled(l,c){c.reason===window.SpeechSDK.CancellationReason.Error&&this.error(c.errorDetails);}},{key:"onSessionStarted",value:function onSessionStarted(){r.PreventConnectionStop.clearPrevention(this),this.setStateOnStart();}},{key:"onSessionStopped",value:function onSessionStopped(){this._retrieveTokenInterval||clearInterval(this._retrieveTokenInterval),this._stopping=!1,this.setStateOnStop();}},{key:"retrieveTokenInterval",value:function retrieveTokenInterval(l){var
|
286
|
-
_inherits(_s,_Ci);return _createClass(_s,[{key:"processConfiguration",value:function processConfiguration(e,t){var _s$displayInterimResu,_s$textColor,_s$translations,_s$commands,_s$events;var c;var s=_typeof(t)=="object"?t:{},i=_typeof(s.webSpeech)=="object"?s.webSpeech:{},n=s.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_s$displayInterimResu=s.displayInterimResults)!==null&&_s$displayInterimResu!==void 0?_s$displayInterimResu:void 0,textColor:(_s$textColor=s.textColor)!==null&&_s$textColor!==void 0?_s$textColor:void 0,translations:(_s$translations=s.translations)!==null&&_s$translations!==void 0?_s$translations:void 0,commands:(_s$commands=s.commands)!==null&&_s$commands!==void 0?_s$commands:void 0,events:(_s$events=s.events)!==null&&_s$events!==void 0?_s$events:void 0},i),n),a=(c=s.commands)==null?void 0:c.submit;return a&&(o.onPreResult=function(d){return d.toLowerCase().includes(a)?(setTimeout(function(){var u;return(u=e.submit)==null?void 0:u.call(e);}),Fs.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),s.submitAfterSilence&&(this._silenceSubmit=new kl(s.submitAfterSilence,s.stopAfterSubmit)),{serviceName:_s.getServiceName(s),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,s,i){var
|
287
|
-
function We(e,t,s,i,n){var
|
288
|
-
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
|
289
|
-
},{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?
|
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),u=_i$AzureTranscript$ex2.interimTranscript,h=_i$AzureTranscript$ex2.finalTranscript,f=_i$AzureTranscript$ex2.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(u,h,f),h!==""&&(this._newTextPadding=" ");}break;}}},{key:"onCanceled",value:function onCanceled(l,c){c.reason===window.SpeechSDK.CancellationReason.Error&&this.error(c.errorDetails);}},{key:"onSessionStarted",value:function onSessionStarted(){r.PreventConnectionStop.clearPrevention(this),this.setStateOnStart();}},{key:"onSessionStopped",value:function onSessionStopped(){this._retrieveTokenInterval||clearInterval(this._retrieveTokenInterval),this._stopping=!1,this.setStateOnStop();}},{key:"retrieveTokenInterval",value:function retrieveTokenInterval(l){var _this90=this;this._retrieveTokenInterval=setInterval(function(){l==null||l().then(function(c){_this90._service&&(_this90._service.authorizationToken=(c==null?void 0:c.trim())||"");})["catch"](function(c){_this90.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 is.Azure=o,is;}var hr;function Ml(){if(hr)return Bs;hr=1,Object.defineProperty(Bs,"__esModule",{value:!0});var r=_l(),e=Ir(),t=El(),s=Rl();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=Ml();var Fs=/* @__PURE__ */pl(Il);var kl=/*#__PURE__*/function(){function kl(e,t){_classCallCheck(this,kl);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(kl,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this91=this;this._silenceTimeout=setTimeout(function(){var s;(s=e.submit)==null||s.call(e),Fs.stop(),_this91._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 _s=/*#__PURE__*/function(_Ci){function _s(e,t,s){var _this92;_classCallCheck(this,_s);var i=_typeof(e.speechToText)=="object"?e.speechToText:{};_this92=_callSuper(this,_s,[i==null?void 0:i.button]);var _this92$processConfig=_this92.processConfiguration(t,e.speechToText),n=_this92$processConfig.serviceName,o=_this92$processConfig.processedConfig;if(_this92._addErrorMessage=s,n==="webspeech"&&!Fs.isWebSpeechSupported())_this92.changeToUnsupported();else{var a=!e.textInput||!e.textInput.disabled;_this92.elementRef.onclick=_this92.buttonClick.bind(_this92,t,a,n,o);}setTimeout(function(){_this92._validationHandler=e._validationHandler;});return _this92;}// prettier-ignore
|
283
|
+
_inherits(_s,_Ci);return _createClass(_s,[{key:"processConfiguration",value:function processConfiguration(e,t){var _s$displayInterimResu,_s$textColor,_s$translations,_s$commands,_s$events;var c;var s=_typeof(t)=="object"?t:{},i=_typeof(s.webSpeech)=="object"?s.webSpeech:{},n=s.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_s$displayInterimResu=s.displayInterimResults)!==null&&_s$displayInterimResu!==void 0?_s$displayInterimResu:void 0,textColor:(_s$textColor=s.textColor)!==null&&_s$textColor!==void 0?_s$textColor:void 0,translations:(_s$translations=s.translations)!==null&&_s$translations!==void 0?_s$translations:void 0,commands:(_s$commands=s.commands)!==null&&_s$commands!==void 0?_s$commands:void 0,events:(_s$events=s.events)!==null&&_s$events!==void 0?_s$events:void 0},i),n),a=(c=s.commands)==null?void 0:c.submit;return a&&(o.onPreResult=function(d){return d.toLowerCase().includes(a)?(setTimeout(function(){var u;return(u=e.submit)==null?void 0:u.call(e);}),Fs.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),s.submitAfterSilence&&(this._silenceSubmit=new kl(s.submitAfterSilence,s.stopAfterSubmit)),{serviceName:_s.getServiceName(s),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,s,i){var _this93=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;_this93.onError(),(o=_this93._silenceSubmit)==null||o.clearSilenceTimeout();},onStart:function onStart(){var o;_this93.changeToActive(),(o=n==null?void 0:n.onStart)==null||o.call(n);},onStop:function onStop(){var o,a,l;(o=_this93._validationHandler)==null||o.call(_this93),(a=_this93._silenceSubmit)==null||a.clearSilenceTimeout(),_this93.changeToDefault(),(l=n==null?void 0:n.onStop)==null||l.call(n);},onPauseTrigger:function onPauseTrigger(o){var a,l;(a=_this93._silenceSubmit)==null||a.onPause(o,e,_this93.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=_this93._validationHandler)==null||l.call(_this93)),(c=_this93._silenceSubmit)==null||c.resetSilenceTimeout(e,_this93.elementRef.onclick),(d=n==null?void 0:n.onResult)==null||d.call(n,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this93.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();},_s.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(Ci);_s.MICROPHONE_RESET_TIMEOUT_MS=300;var Rs=_s;var We=/*#__PURE__*/function(){// prettier-ignore
|
284
|
+
function We(e,t,s,i,n){var _this94=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(){_this94._validationHandler=e._validationHandler,_this94._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 _n6=Ms.createAudioAttachment(t);this.addFileAttachment(e,"audio",_n6,s);}else{var _n7=We.createAnyFileAttachment(e.name);this.addFileAttachment(e,"any",_n7,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 _this95=this;this._hiddenAttachments.clear(),this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t.click();}),_this95._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 _this96=this;var e;Array.from(this._hiddenAttachments).forEach(function(t){_this96._fileAttachmentsContainerRef.appendChild(t.attachmentContainerElement),_this96._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
|
285
|
+
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 _this97=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=_this97.stopPlaceholderCallback)==null||a.call(_this97),_this97.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(Vi);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 _this98=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=_this98.stopPlaceholderCallback)==null?void 0:a.call(_this98);};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
|
286
|
+
},{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?B.cloneElement(e):e,i=document.createElement("audio");i.src=t;var n=Qe.createSVGElement(wr);n.classList.add("attachment-icon","play-icon");var o=Qe.createSVGElement(Vi);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 Ll=/*#__PURE__*/function(){function Ll(){_classCallCheck(this,Ll);}return _createClass(Ll,null,[{key:"create",value:// prettier-ignore
|
290
287
|
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 Os=/*#__PURE__*/function(){function Os(e,t,s){_classCallCheck(this,Os);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
|
291
|
-
return _createClass(Os,[{key:"addType",value:function addType(e,t,s,i){var n=Ll.create(e,t,s,this.toggleContainerDisplay.bind(this),this.elementRef,i);return this._fileAttachmentsTypes.push(n),n;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=document.createElement("div");return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef.style.display="block":this.elementRef.children.length===0&&(this.elementRef.style.display="none");}},{key:"getAllFileData",value:function getAllFileData(){var e=this._fileAttachmentsTypes.map(function(t){return t.getFiles();}).flat();return e.length>0?e:void 0;}},{key:"completePlaceholders",value:function(){var _completePlaceholders=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(){return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:_context174.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref154=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e){var t;return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:return _context173.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee173);}));return function(_x323){return _ref154.apply(this,arguments);};}()));case 1:return _context174.a(2);}},_callee174,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){Os.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 Ie=/*#__PURE__*/function(){function Ie(e,t,s){_classCallCheck(this,Ie);this._isOpen=!1,this._contentRef=Ie.createModalContent(t,s==null?void 0:s.backgroundColor),this._buttonPanel=Ie.createButtonPanel(s==null?void 0:s.backgroundColor),this._elementRef=Ie.createContainer(this._contentRef,s),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=Ie.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(Ie,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var
|
292
|
-
function gi(e,t,s,i,n,o){var
|
288
|
+
return _createClass(Os,[{key:"addType",value:function addType(e,t,s,i){var n=Ll.create(e,t,s,this.toggleContainerDisplay.bind(this),this.elementRef,i);return this._fileAttachmentsTypes.push(n),n;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=document.createElement("div");return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef.style.display="block":this.elementRef.children.length===0&&(this.elementRef.style.display="none");}},{key:"getAllFileData",value:function getAllFileData(){var e=this._fileAttachmentsTypes.map(function(t){return t.getFiles();}).flat();return e.length>0?e:void 0;}},{key:"completePlaceholders",value:function(){var _completePlaceholders=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(){return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:_context174.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref154=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e){var t;return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:return _context173.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee173);}));return function(_x323){return _ref154.apply(this,arguments);};}()));case 1:return _context174.a(2);}},_callee174,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){Os.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 Ie=/*#__PURE__*/function(){function Ie(e,t,s){_classCallCheck(this,Ie);this._isOpen=!1,this._contentRef=Ie.createModalContent(t,s==null?void 0:s.backgroundColor),this._buttonPanel=Ie.createButtonPanel(s==null?void 0:s.backgroundColor),this._elementRef=Ie.createContainer(this._contentRef,s),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=Ie.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(Ie,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this99=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){q.addAttributes(t),_this99._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this100=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(){_this100._elementRef.style.display="none",_this100._backgroundPanelRef.style.display="none";},Ie.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 _this101=this;var i=t?Ie.createSVGButton(e):Ie.createTextButton(e);return this.addButtons(i),i.onclick=function(){_this101.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===Y.ESCAPE?(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)):t.key===Y.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 Ie(e,["modal-content"],t.files.infoModal.containerStyle);return n.addCloseButton("OK",!1,s),n.openTextModal.bind(n,t.infoModalTextMarkUp||"");}}}]);}();Ie.MODAL_CLOSE_TIMEOUT_MS=190;var Et=Ie;var gi=/*#__PURE__*/function(_It5){// prettier-ignore
|
289
|
+
function gi(e,t,s,i,n,o){var _this102;_classCallCheck(this,gi);var u,h,f,m,p,g,E,I,P,D;var a=(u=s==null?void 0:s.button)==null?void 0:u.position,l=((m=(f=(h=s==null?void 0:s.button)==null?void 0:h.styles)==null?void 0:f.text)==null?void 0:m.content)||o,c=Le.tryCreateConfig("Upload File",(p=s==null?void 0:s.button)==null?void 0:p.tooltip);_this102=_callSuper(this,gi,[gi.createButtonElement(),n,a,c,s.button,l]);var d=_this102.createInnerElementsForStates(i,_this102.customStyles);_this102._inputElement=gi.createInputElement((g=s==null?void 0:s.files)==null?void 0:g.acceptedFormats),_this102.addClickEvent(e,s),_this102.changeElementsByState(d.styles),_this102.reapplyStateStyle("styles"),_this102._fileAttachmentsType=t,_this102._openModalOnce=((I=(E=s.files)==null?void 0:E.infoModal)==null?void 0:I.openModalOnce)===!1||(D=(P=s.files)==null?void 0:P.infoModal)==null?void 0:D.openModalOnce;return _this102;}_inherits(gi,_It5);return _createClass(gi,[{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){Os.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;}}]);}(It);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)===T&&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
|
293
290
|
function validate(e,t,s,i,n){var o=e(s,i,n);return o?t.changeToSubmitIcon():t.changeToDisabledIcon(),o;}// prettier-ignore
|
294
291
|
},{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(e,t,s,i){var n,o,a;return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:n=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context175.n=1;return s.completePlaceholders();case 1:o=s.getAllFileData(),a=o==null?void 0:o.map(function(l){return l.file;});return _context175.a(2,ut.validate(e,i,n,a));}},_callee175);}));function useValidationFunc(_x324,_x325,_x326,_x327){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
|
295
292
|
},{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee176(e,t,s){var n,i;return _regenerator().w(function(_context176){while(1)switch(_context176.n){case 0:i=(n=t.files)==null?void 0:n.map(function(o){return o.file;});return _context176.a(2,ut.validate(e,s,t.text,i,!0));}},_callee176);}));function useValidationFuncProgrammatic(_x328,_x329,_x330){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!==Oe.URL&&!oe.canSendMessage(s)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
|
296
|
-
},{key:"attach",value:function attach(e,t,s,i,n){var o=e.validateInput||te.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref155=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee177(a){var l;return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:if(!(n.status.loadingActive||n.status.requestInProgress||t.isSubmitProgrammaticallyDisabled===!0||!ut.validateWebsocket(t,n))){_context177.n=1;break;}return _context177.a(2,!1);case 1:l=o||t.canSendMessage;return _context177.a(2,l?a?ut.useValidationFuncProgrammatic(l,a,n):ut.useValidationFunc(l,s,i,n):null);}},_callee177);}));return function(_x331){return _ref155.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(_Ci2){function Ol(e,t){var
|
293
|
+
},{key:"attach",value:function attach(e,t,s,i,n){var o=e.validateInput||te.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref155=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee177(a){var l;return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:if(!(n.status.loadingActive||n.status.requestInProgress||t.isSubmitProgrammaticallyDisabled===!0||!ut.validateWebsocket(t,n))){_context177.n=1;break;}return _context177.a(2,!1);case 1:l=o||t.canSendMessage;return _context177.a(2,l?a?ut.useValidationFuncProgrammatic(l,a,n):ut.useValidationFunc(l,s,i,n):null);}},_callee177);}));return function(_x331){return _ref155.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(_Ci2){function Ol(e,t){var _this103;_classCallCheck(this,Ol);var s,i;_this103=_callSuper(this,Ol,[t.button]),_this103._waitingForBrowserApproval=!1,_this103._audioType=e,_this103._extension=((s=t.files)==null?void 0:s.format)||"mp3",_this103._maxDurationSeconds=(i=t.files)==null?void 0:i.maxDurationSeconds,_this103.elementRef.onclick=_this103.buttonClick.bind(_assertThisInitialized(_this103));return _this103;}_inherits(Ol,_Ci2);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 _this104=this;return new Promise(function(e){var t,s;_this104.changeToDefault(),(t=_this104._mediaRecorder)==null||t.stop(),(s=_this104._mediaStream)==null||s.getTracks().forEach(function(i){return i.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this105=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this105.changeToActive(),_this105._mediaRecorder=new MediaRecorder(e),_this105._audioType.addPlaceholderAttachment(_this105.stop.bind(_this105),_this105._maxDurationSeconds),_this105._mediaStream=e,_this105._mediaRecorder.addEventListener("dataavailable",function(t){_this105.createFile(t);}),_this105._mediaRecorder.start();})["catch"](function(e){console.error(e),_this105.stop();})["finally"](function(){_this105._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this106=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){_this106._audioType.completePlaceholderAttachment(i,o.target.result);};}}]);}(Ci);var Nl="<?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]||{}));ae.overwritePropertyObjectFromAnother(s,e.submit,["container","default"]),ae.overwritePropertyObjectFromAnother(s,e.submit,["text","styles","default"]),ae.overwritePropertyObjectFromAnother(s,e.submit,["svg","styles","default"]),e[t]=s;}// prettier-ignore
|
297
294
|
},{key:"setUpDisabledButton",value:function setUpDisabledButton(e){ae.setPropertyValueIfDoesNotExist(e,["submit","container","default","backgroundColor"],""),ae.setPropertyValueIfDoesNotExist(e,["disabled","container","default","backgroundColor"],"unset"),ae.setPropertyValueIfDoesNotExist(e.submit,["svg","styles","default","filter"],""),ae.setPropertyValueIfDoesNotExist(e.disabled,["svg","styles","default","filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),ae.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 j=/*#__PURE__*/function(_It6){// prettier-ignore
|
298
|
-
function j(e,t,s,i,n,o){var
|
299
|
-
},{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,s,i,n,o,a,l,c,d;if(!((s=(t=this.customStyles)==null?void 0:t.submit)!=null&&s.svg||(o=(n=(i=this.customStyles)==null?void 0:i.loading)==null?void 0:n.svg)!=null&&o.content||(c=(l=(a=this.customStyles)==null?void 0:a.loading)==null?void 0:l.text)!=null&&c.content)&&(e.displayLoadingBubble===void 0||e.displayLoadingBubble===!0)){var u=document.createElement("style");u.textContent="\n .loading-button > * {\n filter: brightness(0) saturate(100%) invert(72%) sepia(0%) saturate(3044%) hue-rotate(322deg) brightness(100%)\n contrast(96%) !important;\n }",(d=e.shadowRoot)==null||d.appendChild(u),this._isSVGLoadingIconOverriden=!0;}}},{key:"assignHandlers",value:function assignHandlers(e){this._serviceIO.completionsHandlers={onFinish:this.resetSubmit.bind(this,e)},this._serviceIO.streamHandlers={onOpen:this.changeToStopIcon.bind(this),onClose:this.resetSubmit.bind(this,e),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 _callee178(){var e,t;return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:_context178.n=1;return this._fileAttachments.completePlaceholders();case 1:e=this._fileAttachments.getAllFileData();if(this._textInput.isTextInputEmpty())this.attemptSubmit(_defineProperty(_defineProperty({},y,""),"files",e));else{t=this._textInput.inputElementRef.innerText.trim();this.attemptSubmit(_defineProperty(_defineProperty({},y,t),"files",e));}case 2:return _context178.a(2);}},_callee178,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e){var
|
295
|
+
function j(e,t,s,i,n,o){var _this107;_classCallCheck(this,j);var a=St.process(e.submitButtonStyles),l=Nl,c=Le.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this107=_callSuper(this,j,[j.createButtonContainerElement(),l,a==null?void 0:a.position,c,a]),_this107._isSVGLoadingIconOverriden=!1,_this107.status={requestInProgress:!1,loadingActive:!1},_this107._messages=s,_this107._textInput=t,_this107._fileAttachments=n,_this107._innerElements=_this107.createInnerElementsForStates(),_this107._stopClicked={listener:function listener(){}},_this107._serviceIO=i,_this107._alwaysEnabled=!!(a!=null&&a.alwaysEnabled),e.disableSubmitButton=_this107.disableSubmitButton.bind(_assertThisInitialized(_this107),i),_this107.attemptOverwriteLoadingStyle(e),o.microphone&&_this107.setUpSpeechToText(o.microphone.button,e.speechToText),setTimeout(function(){var d;_this107._validationHandler=e._validationHandler,_this107.assignHandlers(_this107._validationHandler),(d=_this107._validationHandler)==null||d.call(_assertThisInitialized(_this107));});return _this107;}_inherits(j,_It6);return _createClass(j,[{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||[j.createLoadingIconElement()],stop:s||[j.createStopIconElement()],disabled:this.createDisabledIconElement(e)};}},{key:"createCustomElements",value:function createCustomElements(){var _this108=this;var e=He.createCustomElements("submit",this.svg,this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(s){var i=s,n=He.createCustomElements(i,_this108.svg,_this108.customStyles);n&&(t[i]=n);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return He.createCustomElements("disabled",this.svg,this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
|
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 u=document.createElement("style");u.textContent="\n .loading-button > * {\n filter: brightness(0) saturate(100%) invert(72%) sepia(0%) saturate(3044%) hue-rotate(322deg) brightness(100%)\n contrast(96%) !important;\n }",(d=e.shadowRoot)==null||d.appendChild(u),this._isSVGLoadingIconOverriden=!0;}}},{key:"assignHandlers",value:function assignHandlers(e){this._serviceIO.completionsHandlers={onFinish:this.resetSubmit.bind(this,e)},this._serviceIO.streamHandlers={onOpen:this.changeToStopIcon.bind(this),onClose:this.resetSubmit.bind(this,e),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 _callee178(){var e,t;return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:_context178.n=1;return this._fileAttachments.completePlaceholders();case 1:e=this._fileAttachments.getAllFileData();if(this._textInput.isTextInputEmpty())this.attemptSubmit(_defineProperty(_defineProperty({},y,""),"files",e));else{t=this._textInput.inputElementRef.innerText.trim();this.attemptSubmit(_defineProperty(_defineProperty({},y,t),"files",e));}case 2:return _context178.a(2);}},_callee178,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e){var _this109=this;var t;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:typeof e=="string"&&(e=te.processSubmitUserMessage(e));t=_defineProperty({},y,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 _this109.attemptSubmit(t,!0);});case 1:return _context179.a(2);}},_callee179);}));function programmaticSubmit(_x332){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
|
300
297
|
},{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(e){var t,n,o,a,l,s,i,_args180=arguments,_t44,_t45,_t46;return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:t=_args180.length>1&&_args180[1]!==undefined?_args180[1]:!1;_context180.n=1;return(n=this._validationHandler)==null?void 0:n.call(this,t?e:void 0);case 1:_t44=_context180.v;_t45=!1;if(!(_t44===_t45)){_context180.n=2;break;}return _context180.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();_t46=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t46){_context180.n=3;break;}_context180.n=3;return qs.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context180.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({},y,e.text===""?void 0:e.text),"files",s);_context180.n=5;return this._serviceIO.callAPI(i,this._messages);case 5:(l=this._fileAttachments)==null||l.hideFiles();case 6:return _context180.a(2);}},_callee180,this);}));function attemptSubmit(_x333){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee181(_ref156){var e,t,s,i,_t47;return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:e=_ref156.text,t=_ref156.files,s=_ref156.custom;i={role:v.USER_ROLE,custom:s};e&&(i.text=e);_t47=t;if(!_t47){_context181.n=2;break;}_context181.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:i.files=_context181.v;case 2:this._serviceIO.sessionId&&(i._sessionId=this._serviceIO.sessionId);Object.keys(i).length>0&&this._messages.addNewMessage(i);case 3:return _context181.a(2);}},_callee181,this);}));function addNewMessage(_x334){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(j.LOADING_CLASS,j.DISABLED_CLASS,j.SUBMIT_CLASS),q.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(j.SUBMIT_CLASS,j.DISABLED_CLASS),q.removeAriaDisabled(this.elementRef),this.elementRef.classList.add(j.LOADING_CLASS),q.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
|
301
|
-
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var
|
298
|
+
},{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this110=this;this.elementRef.classList.contains(j.SUBMIT_CLASS)||(this.elementRef.classList.remove(j.LOADING_CLASS,j.DISABLED_CLASS),q.removeAriaAttributes(this.elementRef),this.elementRef.classList.add(j.SUBMIT_CLASS),this.changeElementsByState(this._innerElements.submit),St.resetSubmit(this,this.status.loadingActive),this.elementRef.onclick=function(){var e;_this110.submitFromInput(),(e=_this110._microphoneButton)!=null&&e.isActive&&Rs.toggleSpeechAfterSubmit(_this110._microphoneButton.elementRef,!!_this110._stopSTTAfterSubmit);});}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
|
302
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(j.DISABLED_CLASS)||(this.elementRef.classList.remove(j.LOADING_CLASS,j.SUBMIT_CLASS),q.removeAriaBusy(this.elementRef),this.elementRef.classList.add(j.DISABLED_CLASS),q.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;}}]);}(It);j.SUBMIT_CLASS="submit-button",j.LOADING_CLASS="loading-button",j.DISABLED_CLASS="disabled-button";var en=j;var Pl="<?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",Dl="<?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",Bl="<?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>",Fl="<?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
|
303
|
-
function vn(e,t,s,i){var
|
304
|
-
},{key:"addButtonEvents",value:function addButtonEvents(e,t,s,i){var
|
305
|
-
}],[{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 Ul="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"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(_It7){function _n(e,t,s){var
|
300
|
+
function vn(e,t,s,i){var _this111;_classCallCheck(this,vn);_this111=_callSuper(this,vn,[e,["modal-content","modal-camera-content"],s]),_this111._stopped=!1,_this111._format="image/png",_this111._canvas=document.createElement("canvas"),_this111._canvas.classList.add("camera-modal-canvas");var _this111$addButtonsAn=_this111.addButtonsAndTheirEvents(t),n=_this111$addButtonsAn.captureButton,o=_this111$addButtonsAn.submitButton;_this111._captureButton=n,_this111._submitButton=o,_this111._captureIcon=_this111._captureButton.children[0],_this111._refreshIcon=Qe.createSVGElement(Pl),_this111._refreshIcon.classList.add("modal-svg-button-icon","modal-svg-refresh-icon"),(i==null?void 0:i.format)==="jpeg"&&(_this111._format="image/jpeg"),i!=null&&i.dimensions&&(_this111._dimensions=i.dimensions),_this111._contentRef.appendChild(_this111._canvas),_this111.extensionCloseCallback=_this111.stop;return _this111;}_inherits(vn,_Et);return _createClass(vn,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=Et.createSVGButton(Dl);t.classList.add("modal-svg-camera-button"),t.children[0].classList.add("modal-svg-camera-icon");var s=this.addCloseButton(Bl,!0);s.classList.add("modal-svg-close-button"),s.children[0].classList.add("modal-svg-close-icon");var i=Et.createSVGButton(Fl);return i.classList.add("modal-svg-submit-button"),this.addButtons(t,i),this.addButtonEvents(t,s,i,e),{captureButton:t,submitButton:i};}// prettier-ignore
|
301
|
+
},{key:"addButtonEvents",value:function addButtonEvents(e,t,s,i){var _this112=this;e.onclick=function(){_this112.capture();},t.addEventListener("click",this.stop.bind(this)),s.onclick=function(){var n=_this112.getFile();n&&Os.addFilesToType([n],[i]),_this112.stop(),_this112.close();};}},{key:"stop",value:function stop(){var _this113=this;this._mediaStream&&this._mediaStream.getTracks().forEach(function(e){return e.stop();}),this._stopped=!0,setTimeout(function(){_this113._captureButton.replaceChildren(_this113._captureIcon),_this113._captureButton.classList.replace("modal-svg-refresh-button","modal-svg-camera-button");var e=_this113._canvas.getContext("2d");e==null||e.clearRect(0,0,_this113._canvas.width,_this113._canvas.height);},Et.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this114=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(_this114._mediaStream=e,!_this114.isOpen())return _this114.stop();var t=document.createElement("video");t.srcObject=e,t.play(),requestAnimationFrame(_this114.updateCanvas.bind(_this114,t,_this114._canvas));})["catch"](function(e){console.error(e),_this114.stop(),_this114.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
|
302
|
+
}],[{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 Ul="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"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(_It7){function _n(e,t,s){var _this115;_classCallCheck(this,_n);var c,d,u,h,f,m;var i=(c=s==null?void 0:s.button)==null?void 0:c.position,n=((h=(u=(d=s==null?void 0:s.button)==null?void 0:d.styles)==null?void 0:u.text)==null?void 0:h.content)||"Photo",o=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)||{};_this115=_callSuper(this,_n,[_n.createButtonElement(),Ul,i,o,a,n]);var l=_this115.createInnerElementsForStates(_this115.customStyles);s&&_this115.addClickEvent(e,t,s.modalContainerStyle,s.files),_this115.changeElementsByState(l.styles),_this115.reapplyStateStyle("styles");return _this115;}_inherits(_n,_It7);return _createClass(_n,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return{styles:this.createInnerElements("camera-icon","styles",e)};}},{key:"addClickEvent",value:// prettier-ignore
|
306
303
|
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;}}]);}(It);var Lt=/*#__PURE__*/function(){function Lt(e,t,s,i){_classCallCheck(this,Lt);this.elementRef=Lt.createPanelElement(e.inputAreaStyle);var n={},o=this.createFileUploadComponents(e,s,i,n),a=new js(e,s,o);e.speechToText&&!n.microphone&&(n.microphone={button:new Rs(e,a,t.addNewErrorMessage.bind(t))});var l=new en(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),Lt.addElements(this.elementRef,a,n,i,o,e.dropupStyles),Lt.assignOnInput(e,s,o,a);}return _createClass(Lt,[{key:"createFileUploadComponents",value:// prettier-ignore
|
307
304
|
function createFileUploadComponents(e,t,s,i){var o,a,l,c;var n=new Os(this.elementRef,e.attachmentContainerStyle,t.demo);if(Lt.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
|
308
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),_fl$l=fl[l],u=_fl$l.id,h=_fl$l.svgString,f=_fl$l.dropupText,m=new gi(n,d,c,u,h,f);o[l]={button:m,fileType:d};}});}// prettier-ignore
|
309
|
-
},{key:"addElements",value:function addElements(e,t,s,i,n,o){F.addElements(e,t.elementRef);var a=Ht.create(),l=de.addButtons(a,s,i,o);Qi.set(t.inputElementRef,a,n.elementRef,l),Ht.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({},y,a);o&&(l.files=o.map(function(c){return c.file;})),Ct.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&&oe.createConnection(t,n);var o=new Lt(e,n,t,i);return F.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 Hl="#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,C=function C(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 S=/*#__PURE__*/function(_Hi){function S(){var _this115;_classCallCheck(this,S);var e;_this115=_callSuper(this,S),_this115.getMessages=function(){return[];},_this115.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.");},_this115.addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.");},_this115.updateMessage=function(){},_this115.clearMessages=function(){},_this115.focusInput=function(){return Is.focusFromParentElement(_this115._elementRef);},_this115.refreshMessages=function(){},_this115.scrollToBottom=function(){},_this115.disableSubmitButton=function(){},_this115.setPlaceholderText=function(){},_this115._hasBeenRendered=!1,_this115._auxiliaryStyleApplied=!1,_this115._elementRef=document.createElement("div"),_this115._elementRef.id="container",_this115.attachShadow({mode:"open"}).appendChild(_this115._elementRef),(e=_this115.shadowRoot)==null||e.appendChild(Le.buildElement()),ds.apply(Hl,_this115.shadowRoot),setTimeout(function(){_this115._hasBeenRendered||_this115.onRender();},20);return _this115;}_inherits(S,_Hi);return _createClass(S,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
306
|
+
},{key:"addElements",value:function addElements(e,t,s,i,n,o){B.addElements(e,t.elementRef);var a=Ht.create(),l=de.addButtons(a,s,i,o);Qi.set(t.inputElementRef,a,n.elementRef,l),Ht.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({},y,a);o&&(l.files=o.map(function(c){return c.file;})),Ct.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&&oe.createConnection(t,n);var o=new Lt(e,n,t,i);return B.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 Hl="#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;overflow-anchor:none}.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,C=function C(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 S=/*#__PURE__*/function(_Hi){function S(){var _this116;_classCallCheck(this,S);var e;_this116=_callSuper(this,S),_this116.getMessages=function(){return[];},_this116.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.");},_this116.addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.");},_this116.updateMessage=function(){},_this116.clearMessages=function(){},_this116.focusInput=function(){return Is.focusFromParentElement(_this116._elementRef);},_this116.refreshMessages=function(){},_this116.scrollToBottom=function(){},_this116.disableSubmitButton=function(){},_this116.setPlaceholderText=function(){},_this116._hasBeenRendered=!1,_this116._auxiliaryStyleApplied=!1,_this116._elementRef=document.createElement("div"),_this116._elementRef.id="container",_this116.attachShadow({mode:"open"}).appendChild(_this116._elementRef),(e=_this116.shadowRoot)==null||e.appendChild(Le.buildElement()),ds.apply(Hl,_this116.shadowRoot),setTimeout(function(){_this116._hasBeenRendered||_this116.onRender();},20);return _this116;}_inherits(S,_Hi);return _createClass(S,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
|
310
307
|
},{key:"onRender",value:function onRender(){var _this$_childElement;Hs.attemptAppendStyleSheetToHead(this.style),te.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=nl.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(ds.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),ds.applyDefaultStyleToComponent(this.style,this.chatStyle),te.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?Us.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof k)||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 k&&ce.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||Ct.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){Cs.chat=void 0;}}]);}(Hi);C([A("object")],S.prototype,"connect");C([A("object")],S.prototype,"directConnection");C([A("object")],S.prototype,"webModel");C([A("object")],S.prototype,"requestBodyLimits");C([A("function")],S.prototype,"requestInterceptor");C([A("function")],S.prototype,"responseInterceptor");C([A("function")],S.prototype,"validateInput");C([A("function")],S.prototype,"loadHistory");C([A("object")],S.prototype,"chatStyle");C([A("object")],S.prototype,"attachmentContainerStyle");C([A("object")],S.prototype,"dropupStyles");C([A("object")],S.prototype,"inputAreaStyle");C([A("object")],S.prototype,"textInput");C([A("object")],S.prototype,"submitButtonStyles");C([A("object")],S.prototype,"customButtons");C([A("string")],S.prototype,"auxiliaryStyle");C([A("array")],S.prototype,"history");C([A("object")],S.prototype,"browserStorage");C([A("object")],S.prototype,"introMessage");C([A("object")],S.prototype,"avatars");C([A("object")],S.prototype,"names");C([A("object")],S.prototype,"displayLoadingBubble");C([A("object")],S.prototype,"errorMessages");C([A("object")],S.prototype,"messageStyles");C([A("object")],S.prototype,"textToSpeech");C([A("object")],S.prototype,"speechToText");C([A("object")],S.prototype,"images");C([A("object")],S.prototype,"gifs");C([A("object")],S.prototype,"camera");C([A("object")],S.prototype,"audio");C([A("object")],S.prototype,"microphone");C([A("object")],S.prototype,"mixedFiles");C([A("object")],S.prototype,"dragAndDrop");C([A("object")],S.prototype,"introPanelStyle");C([A("object")],S.prototype,"htmlWrappers");C([A("object")],S.prototype,"htmlClassUtilities");C([A("object")],S.prototype,"remarkable");C([A("object")],S.prototype,"focusMode");C([A("function")],S.prototype,"onMessage");C([A("function")],S.prototype,"onClearMessages");C([A("function")],S.prototype,"onComponentRender");C([A("function")],S.prototype,"onInput");C([A("function")],S.prototype,"onError");C([A("object")],S.prototype,"demo");C([A("object")],S.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",S);export{S as DeepChat};
|