deep-chat-dev 9.0.302 → 9.0.303

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/dist/deepChat.js CHANGED
@@ -157,7 +157,7 @@ function Ai(e,t,s,i,n){var _this23;_classCallCheck(this,Ai);_this23=_callSuper(t
157
157
  },{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,q.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(Ht).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 _this26;_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;_this26=_callSuper(this,ja,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,s]),_this26.permittedErrorPrefixes=[nn,"Error in"],_this26._context=t.context;return _this26;}_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 _this27$maxMessages;var _this27;_classCallCheck(this,Va);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.huggingFace)==null?void 0:n.conversation,s=(o=e.directConnection)==null?void 0:o.huggingFace;_this27=_callSuper(this,Va,[e,"Ask me anything!","facebook/blenderbot-400M-distill",t,s]),(_this27$maxMessages=_this27.maxMessages)!==null&&_this27$maxMessages!==void 0?_this27$maxMessages:_this27.maxMessages=-1;return _this27;}// prettier-ignore
158
158
  _inherits(Va,_et5);return _createClass(Va,[{key:"processMessages",value:function processMessages(e){var t=e.filter(function(a){return a.text;}),s=t[t.length-1].text,i=t.slice(0,t.length-1);if(!s)return;var n=i.filter(function(a){return a.role==="user";}).map(function(a){return a.text;}),o=i.filter(function(a){return a.role==="ai";}).map(function(a){return a.text;});return{past_user_inputs:n,generated_responses:o,mostRecentMessageText:s};}// prettier-ignore
159
159
  },{key:"preprocessBody",value:function preprocessBody(e,t){var _s$options;var s=JSON.parse(JSON.stringify(e)),i=this.processMessages(t);if(i)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:_defineProperty({past_user_inputs:i.past_user_inputs,generated_responses:i.generated_responses},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 _this28;_classCallCheck(this,$s);var o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.stabilityAI,i={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this28=_callSuper(this,$s,[e,je.buildKeyVerificationDetails(),je.buildHeaders,s,i]),_this28.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this28.textInputPlaceholderText="Describe image changes",_this28.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Stability AI: Image to Image</b></div>\n <p>Upload an image to create a new one with the changes you have described.</p>\n <p>Click <a href=\"https://platform.stability.ai/\" target=\"_blank\">here</a> for more info.</p>";var n=(o=t.stabilityAI)==null?void 0:o.imageToImage;_typeof(n)=="object"&&(n.engine_id&&(_this28.url="https://api.stability.ai/v1/generation/".concat(n.engine_id,"/text-to-image")),n.weight!==void 0&&n.weight!==null&&(_this28._imageWeight=n.weight),$s.cleanConfig(n),Object.assign(_this28.rawBody,n)),_this28.canSendMessage=$s.canSendFileTextMessage;return _this28;}_inherits($s,_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
160
- },{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,q.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(Ht).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,je.buildKeyVerificationDetails(),je.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);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(Ht).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,O),G,"".concat(ee).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:K,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=[G,te];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));}},_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,O),G,"".concat(ee).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:K,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,te];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));}},_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 ys=/*#__PURE__*/function(){function ys(){_classCallCheck(this,ys);}return _createClass(ys,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O);}// prettier-ignore
160
+ },{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,q.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(Ht).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,je.buildKeyVerificationDetails(),je.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(Ht).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,O),G,"".concat(ee).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:K,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=[G,te];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,O),G,"".concat(ee).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:K,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,te];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 ys=/*#__PURE__*/function(){function ys(){_classCallCheck(this,ys);}return _createClass(ys,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O);}// prettier-ignore
161
161
  },{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:K,handleVerificationResult:ys.handleVerificationResult};}// eslint-disable-next-line @typescript-eslint/no-explicit-any
162
162
  },{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;}()}]);}();ys.FUNCTION_TOOL_RESP_ERROR="Response object must either be {response: string}[] for each individual function or {text: string} for a direct response, see https://deepchat.dev/docs/directConnection/OpenAI#FunctionHandler.",ys.FUNCTION_TOOL_RESP_ARR_ERROR="Arrays are not accepted in handler responses";var V=ys;var ye=/*#__PURE__*/function(){function ye(){_classCallCheck(this,ye);}return _createClass(ye,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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(V.directFetch(e,c,Y,!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(V.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
163
163
  },{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
@@ -182,30 +182,30 @@ function setUpView(e,t){e.style.display="none",t.appendChild(this._containerEl),
182
182
  // in such instance please wait and refresh at a later time
183
183
  },{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this44=this;var s=function(_s3){function s(){return _s3.apply(this,arguments);}s.toString=function(){return _s3.toString();};return s;}(function(){var c;e.getByteFrequencyData(t);var i=t.reduce(function(d,u){return d+u;},0),n=t.length*255,o=i/n*100,a=1,l=a+o/100*(((c=_this44._avatarConfig)==null?void 0:c.maxScale)-a);_this44._avatarEl.style.transform="scale(".concat(l,")"),requestAnimationFrame(s);});s();}},{key:"stopOnError",value:function stopOnError(e){this.stop(),console.error(e),this.displayError();}},{key:"stop",value:function stop(){var e,t,s;(e=this._mediaStream)==null||e.getTracks().forEach(function(i){return i.stop();}),this._mediaStream=null,this._pc&&(this._pc.close(),this._pc=null,(s=(t=this._events)==null?void 0:t.stopped)==null||s.call(t),this._deepChat.dispatchEvent(new CustomEvent(Zs.SESSION_STOPPED)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&N.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&N.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&N.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&N.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&N.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&N.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(N.BUTTON_LOADING),j.removeAriaDisabled(this._toggleButton.elementRef),j.addAriaBusy(this._toggleButton.elementRef)),(typeof((e=this._loadingConfig)==null?void 0:e.display)!="boolean"||this._loadingConfig.display)&&this._loadingElement&&(this._loadingElement.style.display="block",(t=this._loadingConfig)!=null&&t.html||(this._loadingElement.textContent=((s=this._loadingConfig)==null?void 0:s.text)||"Loading"));}},{key:"hideLoading",value:function hideLoading(){this._toggleButton&&(this._toggleButton.elementRef.classList.remove(N.BUTTON_LOADING),j.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement.style.display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
184
184
  },{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"||!re.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
185
- },{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify({type:"conversation.item.create",item:e});this._dc.send(t);var s={type:"response.create"};this._dc.send(JSON.stringify(s));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var s=t==null?void 0:t.realtime;if(_typeof(s)=="object"&&(s.ephemeralKey||s.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?JSON.parse(JSON.stringify(e.avatar)):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$microphone,_o$default,_a$svg,_l$content,_t$toggle,_h$default,_f$svg,_m$content,_p$active,_g$svg,_$content;var s,i,n,o,a,l,c,d,u,h,f,m,p,g,_;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={},(_$content=(_=t.toggle.active.svg).content)!==null&&_$content!==void 0?_$content:_.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(N.UNAVAILABLE),j.removeAriaBusy(e.elementRef),j.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){N.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){j.removeAriaDisabled(e.elementRef),e.elementRef.classList.remove(N.UNAVAILABLE);}}]);}(k);N.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",N.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",N.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",N.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var Gi=N;var Pt=/*#__PURE__*/function(_k7){function Pt(e){var _o$model3,_a$voice3;var _this45;_classCallCheck(this,Pt);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this45=_callSuper(this,Pt,[e,V.buildKeyVerificationDetails(),V.buildHeaders,s]),_this45.insertKeyPlaceholderText=_this45.genereteAPIKeyName("OpenAI"),_this45.keyHelpUrl="https://platform.openai.com/account/api-keys",_this45.url="https://api.openai.com/v1/audio/speech",_this45.permittedErrorPrefixes=[ht],_this45.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI : Text To Speech</b></div>\n <p>Generate an audio file based on your text input.</p>\n <p>Click <a href=\"https://platform.openai.com/docs/guides/text-to-speech\" target=\"_blank\">here</a>\n for more information.</p>";var i=(n=t==null?void 0:t.openAI)==null?void 0:n.textToSpeech;_typeof(i)===T&&Object.assign(_this45.rawBody,i),(_o$model3=(o=_this45.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=Pt.DEFAULT_MODEL,(_a$voice3=(a=_this45.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=Pt.DEFAULT_VOIDE,_this45.textInputPlaceholderText="Insert text to generate audio",_this45.rawBody.response_format="mp3";return _this45;}_inherits(Pt,_k7);return _createClass(Pt,[{key:"preprocessBody",value:function preprocessBody(e,t){var n,o;var s=JSON.parse(JSON.stringify(e)),i=(o=(n=t[t.length-1])==null?void 0:n.text)==null?void 0:o.trim();return i&&i!==""&&(s.input=i),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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);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({},He,He));}},_callee101);}));function extractResultData(_x196){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(k);Pt.DEFAULT_MODEL="tts-1",Pt.DEFAULT_VOIDE="alloy";var Ki=Pt;var Re=/*#__PURE__*/function(_k8){function Re(e){var _o$model4;var _this46;_classCallCheck(this,Re);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this46=_callSuper(this,Re,[e,V.buildKeyVerificationDetails(),V.buildHeaders,s,{audio:{}}]),_this46.insertKeyPlaceholderText=_this46.genereteAPIKeyName("OpenAI"),_this46.keyHelpUrl="https://platform.openai.com/account/api-keys",_this46.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI : Speech To Text</b></div>\n <p><b>Upload an audio file</b> to transcribe it into text. You can optionally provide text to guide the audio\n processing.\n <p>Click <a href=\"https://platform.openai.com/docs/guides/speech-to-text\" target=\"_blank\">here</a> for more info.</p>",_this46.url="",_this46.permittedErrorPrefixes=[ht],_this46.textInputPlaceholderText=rn,_this46._service_url=Re.AUDIO_TRANSCRIPTIONS_URL;var i=(n=t==null?void 0:t.openAI)==null?void 0:n.audio;_typeof(i)=="object"&&(_this46.processConfig(i),Re.cleanConfig(i),Object.assign(_this46.rawBody,i)),(_o$model4=(o=_this46.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=Re.DEFAULT_MODEL,_this46.rawBody.response_format="json",_this46.canSendMessage=Re.canSendFileMessage;return _this46;}_inherits(Re,_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
185
+ },{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=JSON.stringify({type:"conversation.item.create",item:e});this._dc.send(t);var s={type:"response.create"};this._dc.send(JSON.stringify(s));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var s=t==null?void 0:t.realtime;if(_typeof(s)=="object"&&(s.ephemeralKey||s.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?JSON.parse(JSON.stringify(e.avatar)):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$microphone,_o$default,_a$svg,_l$content,_t$toggle,_h$default,_f$svg,_m$content,_p$active,_g$svg,_$content;var s,i,n,o,a,l,c,d,u,h,f,m,p,g,_;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={},(_$content=(_=t.toggle.active.svg).content)!==null&&_$content!==void 0?_$content:_.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(N.UNAVAILABLE),j.removeAriaBusy(e.elementRef),j.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){N.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){j.removeAriaDisabled(e.elementRef),e.elementRef.classList.remove(N.UNAVAILABLE);}}]);}(k);N.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",N.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",N.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",N.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var Gi=N;var Pt=/*#__PURE__*/function(_k7){function Pt(e){var _o$model3,_a$voice3;var _this45;_classCallCheck(this,Pt);var n,o,a;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this45=_callSuper(this,Pt,[e,V.buildKeyVerificationDetails(),V.buildHeaders,s]),_this45.insertKeyPlaceholderText=_this45.genereteAPIKeyName("OpenAI"),_this45.keyHelpUrl="https://platform.openai.com/account/api-keys",_this45.url="https://api.openai.com/v1/audio/speech",_this45.permittedErrorPrefixes=[ht],_this45.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI : Text To Speech</b></div>\n <p>Generate an audio file based on your text input.</p>\n <p>Click <a href=\"https://platform.openai.com/docs/guides/text-to-speech\" target=\"_blank\">here</a>\n for more information.</p>";var i=(n=t==null?void 0:t.openAI)==null?void 0:n.textToSpeech;_typeof(i)===T&&Object.assign(_this45.rawBody,i),(_o$model3=(o=_this45.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=Pt.DEFAULT_MODEL,(_a$voice3=(a=_this45.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=Pt.DEFAULT_VOIDE,_this45.textInputPlaceholderText="Insert text to generate audio",_this45.rawBody.response_format="mp3";return _this45;}_inherits(Pt,_k7);return _createClass(Pt,[{key:"preprocessBody",value:function preprocessBody(e,t){var n,o;var s=JSON.parse(JSON.stringify(e)),i=(o=(n=t[t.length-1])==null?void 0:n.text)==null?void 0:o.trim();return i&&i!==""&&(s.input=i),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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({},He,He));}},_callee101);}));function extractResultData(_x196){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(k);Pt.DEFAULT_MODEL="tts-1",Pt.DEFAULT_VOIDE="alloy";var Ki=Pt;var Re=/*#__PURE__*/function(_k8){function Re(e){var _o$model4;var _this46;_classCallCheck(this,Re);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t==null?void 0:t.openAI;_this46=_callSuper(this,Re,[e,V.buildKeyVerificationDetails(),V.buildHeaders,s,{audio:{}}]),_this46.insertKeyPlaceholderText=_this46.genereteAPIKeyName("OpenAI"),_this46.keyHelpUrl="https://platform.openai.com/account/api-keys",_this46.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>OpenAI : Speech To Text</b></div>\n <p><b>Upload an audio file</b> to transcribe it into text. You can optionally provide text to guide the audio\n processing.\n <p>Click <a href=\"https://platform.openai.com/docs/guides/speech-to-text\" target=\"_blank\">here</a> for more info.</p>",_this46.url="",_this46.permittedErrorPrefixes=[ht],_this46.textInputPlaceholderText=rn,_this46._service_url=Re.AUDIO_TRANSCRIPTIONS_URL;var i=(n=t==null?void 0:t.openAI)==null?void 0:n.audio;_typeof(i)=="object"&&(_this46.processConfig(i),Re.cleanConfig(i),Object.assign(_this46.rawBody,i)),(_o$model4=(o=_this46.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=Re.DEFAULT_MODEL,_this46.rawBody.response_format="json",_this46.canSendMessage=Re.canSendFileMessage;return _this46;}_inherits(Re,_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
186
186
  },{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,q.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",O);}// prettier-ignore
187
187
  },{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:Y,createHeaders:function createHeaders(t){return _defineProperty({},ve.SUBSCRIPTION_KEY_NAME,"".concat(t));},handleVerificationResult:ve.handleSpeechVerificationResult};}},{key:"buildSummarizationHeader",value:function buildSummarizationHeader(e){return _defineProperty(_defineProperty({},ve.SUBSCRIPTION_KEY_NAME,e),R,O);}// prettier-ignore
188
188
  },{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:Y,createHeaders:function createHeaders(t){return _defineProperty({},ve.SUBSCRIPTION_KEY_NAME,"".concat(t));},handleVerificationResult:ve.handleLanguageVerificationResult};}// prettier-ignore
189
189
  },{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:Y,createHeaders:function createHeaders(t){return ve.buildTranslationHeaders(e,t);},handleVerificationResult:ve.handleTranslationVerificationResult};}},{key:"buildTranslationHeaders",value:function buildTranslationHeaders(e,t){var s=_defineProperty(_defineProperty({},ve.SUBSCRIPTION_KEY_NAME,t),R,O);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
190
190
  function $a(e,t,s,i,n){var _this47;_classCallCheck(this,$a);_this47=_callSuper(this,$a,[e,tt.buildLanguageKeyVerificationDetails(s),t,i,n]),_this47.insertKeyPlaceholderText="Azure Language Subscription Key",_this47.keyHelpUrl=// eslint-disable-next-line max-len
191
- "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this47.permittedErrorPrefixes=["Access"];return _this47;}_inherits($a,_k9);return _createClass($a);}(k);var bs=/*#__PURE__*/function(_$a){function bs(e){var _a$language;var _this48;_classCallCheck(this,bs);var i,n,o,a;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.summarization,s=(o=e.directConnection)==null?void 0:o.azure;_this48=_callSuper(this,bs,[e,tt.buildSummarizationHeader,t.endpoint,s]),_this48.permittedErrorPrefixes=[bs.ENDPOINT_ERROR_MESSAGE],_this48.url="",_this48.textInputPlaceholderText="Insert text to summarize",_this48.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this48.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this48.rawBody,t),_this48.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this48.isTextInputDisabled=!0,_this48.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,bs.ENDPOINT_ERROR_MESSAGE));}));return _this48;}_inherits(bs,_$a);return _createClass(bs,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return{analysisInput:{documents:[_defineProperty({id:"1",language:e.language},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),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,_s5,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;_s5=e.headers.get("operation-location"),i={method:K,headers:(t=this.connectSettings)==null?void 0:t.headers};q.executePollRequest(this,_s5,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,_s6;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;){_s6=_step.value;t+=_s6.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);bs.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
191
+ "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this47.permittedErrorPrefixes=["Access"];return _this47;}_inherits($a,_k9);return _createClass($a);}(k);var bs=/*#__PURE__*/function(_$a){function bs(e){var _a$language;var _this48;_classCallCheck(this,bs);var i,n,o,a;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.summarization,s=(o=e.directConnection)==null?void 0:o.azure;_this48=_callSuper(this,bs,[e,tt.buildSummarizationHeader,t.endpoint,s]),_this48.permittedErrorPrefixes=[bs.ENDPOINT_ERROR_MESSAGE],_this48.url="",_this48.textInputPlaceholderText="Insert text to summarize",_this48.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this48.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this48.rawBody,t),_this48.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this48.isTextInputDisabled=!0,_this48.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,bs.ENDPOINT_ERROR_MESSAGE));}));return _this48;}_inherits(bs,_$a);return _createClass(bs,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return{analysisInput:{documents:[_defineProperty({id:"1",language:e.language},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,_s5,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;_s5=e.headers.get("operation-location"),i={method:K,headers:(t=this.connectSettings)==null?void 0:t.headers};q.executePollRequest(this,_s5,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,_s6;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;){_s6=_step.value;t+=_s6.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);bs.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
192
192
  "Please define the azure endpoint. [More Information](https://deepchat.dev/docs/directConnection/Azure#Summarization)";var Ji=bs;var us=/*#__PURE__*/function(){function us(){_classCallCheck(this,us);}return _createClass(us,null,[{key:"poll",value:function(){var _poll2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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,O);_t41="https://api.assemblyai.com/v2/transcript/";_context107.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:Y,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===He)){_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({},G,e),R,"application/octet-stream");}// prettier-ignore
193
193
  },{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:Y,handleVerificationResult:us.handleVerificationResult};}}]);}();var dn=/*#__PURE__*/function(_k0){function dn(e){var _this49;_classCallCheck(this,dn);var s;var t=(s=e.directConnection)==null?void 0:s.assemblyAI;_this49=_callSuper(this,dn,[e,us.buildKeyVerificationDetails(),us.buildHeaders,t,{audio:{}}]),_this49.insertKeyPlaceholderText=_this49.genereteAPIKeyName("AssemblyAI"),_this49.keyHelpUrl="https://www.assemblyai.com/app/account",_this49.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>AssemblyAI Audio</b></div>\n <p><b>Upload an audio file</b> to transcribe it into text.\n <p>\n Click <a href=\"https://www.assemblyai.com/docs/Guides/transcribing_an_audio_file#get-started\"\n target=\"_blank\">here</a> for more info.\n </p>",_this49.url="https://api.assemblyai.com/v2/upload",_this49.isTextInputDisabled=!0,_this49.textInputPlaceholderText=rn,_this49.permittedErrorPrefixes=[ur,ht],_this49.canSendMessage=dn.canFileSendMessage;return _this49;}_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:q.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[G];_context109.n=2;return us.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
194
194
  function Tr(e,t,s,i,n){var _this50;_classCallCheck(this,Tr);_this50=_callSuper(this,Tr,[e,tt.buildSpeechKeyVerificationDetails(s),t,i,n]),_this50.insertKeyPlaceholderText="Azure Speech Subscription Key",_this50.keyHelpUrl=// eslint-disable-next-line max-len
195
195
  "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal";return _this50;}_inherits(Tr,_k1);return _createClass(Tr);}(k);var vt=/*#__PURE__*/function(_Tr){// prettier-ignore
196
- function vt(e){var _a$lang,_l$name,_c$gender;var _this51;_classCallCheck(this,vt);var i,n,o,a,l,c;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.textToSpeech,s=(o=e.directConnection)==null?void 0:o.azure;_this51=_callSuper(this,vt,[e,tt.buildTextToSpeechHeaders.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,s]),_this51.permittedErrorPrefixes=[vt.REGION_ERROR_MESSAGE],_this51.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Azure Text To Speech</b></div>\n <p>Insert text to synthesize it to audio.\n <p>\n Click <a href=\"".concat(vt.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this51.isTextInputDisabled=!1,_this51.url="",t.region?(Object.assign(_this51.rawBody,t),(_a$lang=(a=_this51.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_l$name=(l=_this51.rawBody).name)!==null&&_l$name!==void 0?_l$name:l.name="en-US-JennyNeural",(_c$gender=(c=_this51.rawBody).gender)!==null&&_c$gender!==void 0?_c$gender:c.gender="Female",_this51.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this51.isTextInputDisabled=!0,_this51.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,vt.REGION_ERROR_MESSAGE));}));return _this51;}_inherits(vt,_Tr);return _createClass(vt,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return"<speak version='1.0' xml:lang='".concat(e.lang,"'>\n <voice xml:lang='").concat(e.lang,"' xml:gender='").concat(e.gender,"' name='").concat(e.name,"'>\n ").concat(s,"\n </voice>\n </speak>");}},{key:"callServiceAPI",value:function(){var _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(e,t){return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody,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
196
+ function vt(e){var _a$lang,_l$name,_c$gender;var _this51;_classCallCheck(this,vt);var i,n,o,a,l,c;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.textToSpeech,s=(o=e.directConnection)==null?void 0:o.azure;_this51=_callSuper(this,vt,[e,tt.buildTextToSpeechHeaders.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,s]),_this51.permittedErrorPrefixes=[vt.REGION_ERROR_MESSAGE],_this51.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Azure Text To Speech</b></div>\n <p>Insert text to synthesize it to audio.\n <p>\n Click <a href=\"".concat(vt.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this51.isTextInputDisabled=!1,_this51.url="",t.region?(Object.assign(_this51.rawBody,t),(_a$lang=(a=_this51.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_l$name=(l=_this51.rawBody).name)!==null&&_l$name!==void 0?_l$name:l.name="en-US-JennyNeural",(_c$gender=(c=_this51.rawBody).gender)!==null&&_c$gender!==void 0?_c$gender:c.gender="Female",_this51.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this51.isTextInputDisabled=!0,_this51.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,vt.REGION_ERROR_MESSAGE));}));return _this51;}_inherits(vt,_Tr);return _createClass(vt,[{key:"preprocessBody",value:function preprocessBody(e,t){var s=t[t.length-1].text;if(s)return"<speak version='1.0' xml:lang='".concat(e.lang,"'>\n <voice xml:lang='").concat(e.lang,"' xml:gender='").concat(e.gender,"' name='").concat(e.name,"'>\n ").concat(s,"\n </voice>\n </speak>");}},{key:"callServiceAPI",value:function(){var _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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
197
197
  "https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",vt.REGION_ERROR_MESSAGE=// eslint-disable-next-line max-len
198
198
  "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 _this52;_classCallCheck(this,at);var n,o,a;var t=(o=(n=e.directConnection)==null?void 0:n.azure)==null?void 0:o.speechToText,s=(a=e.directConnection)==null?void 0:a.azure,i={audio:{files:{acceptedFormats:".wav,.ogg"}}};if(_this52=_callSuper(this,at,[e,tt.buildSpeechToTextHeaders,t.region,s,i]),_this52.permittedErrorPrefixes=[at.REGION_ERROR_MESSAGE],_this52.introPanelMarkUp="\n <div style=\"width: 100%; text-align: center; margin-left: -10px\"><b>Azure Speech To Text</b></div>\n <p><b>Upload a .wav or .ogg audio file</b> to transcribe it into text.\n <p>\n Click <a href=\"".concat(at.HELP_LINK,"\" target=\"_blank\">here</a> for more info.\n </p>"),_this52.url="",_this52.isTextInputDisabled=!0,_this52.textInputPlaceholderText=rn,!t.region)_this52.isTextInputDisabled=!0,_this52.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},He,at.REGION_ERROR_MESSAGE));});else{_this52.canSendMessage=at.canFileSendMessage;var l=t.lang||"en-US";_this52.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(l,"&format=detailed"),_this52.recordAudio=void 0;}return _this52;}_inherits(at,_Tr2);return _createClass(at,[{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _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"),q.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
199
199
  "https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",at.REGION_ERROR_MESSAGE=// eslint-disable-next-line max-len
200
200
  "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
201
201
  function Wa(e){var _this53;_classCallCheck(this,Wa);var i,n,o;var t=(n=(i=e.directConnection)==null?void 0:i.azure)==null?void 0:n.translation,s=(o=e.directConnection)==null?void 0:o.azure;_this53=_callSuper(this,Wa,[e,tt.buildTranslationKeyVerificationDetails(t.region),tt.buildTranslationHeaders.bind({},t==null?void 0:t.region),s]),_this53.insertKeyPlaceholderText="Azure Translate Subscription Key",_this53.keyHelpUrl=// eslint-disable-next-line max-len
202
- "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this53.url="",_this53.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this53;}_inherits(Wa,_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);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 _this54;_classCallCheck(this,Xa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this54=_callSuper(this,Xa,[e,ct.buildKeyVerificationDetails(),ct.buildHeaders,s]),_this54.insertKeyPlaceholderText=_this54.genereteAPIKeyName("BigModel"),_this54.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this54.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this54.permittedErrorPrefixes=[G,te];var i=(n=t.bigModel)==null?void 0:n.images;_typeof(i)===T&&(_this54.cleanConfig(i),Object.assign(_this54.rawBody,i)),(_o$model5=(o=_this54.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this54;}_inherits(Xa,_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));}},_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 Bt=/*#__PURE__*/function(){function Bt(){_classCallCheck(this,Bt);}return _createClass(Bt,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},R,O),G,"".concat(ee).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:K,handleVerificationResult:Bt.handleVerificationResult};}}]);}();var Ya=/*#__PURE__*/function(_k12){function Ya(e){var _o$model6,_a$voice4,_l$response_format;var _this55;_classCallCheck(this,Ya);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this55=_callSuper(this,Ya,[e,Bt.buildKeyVerificationDetails(),Bt.buildHeaders,s]),_this55.insertKeyPlaceholderText=_this55.genereteAPIKeyName("Groq"),_this55.keyHelpUrl="https://console.groq.com/keys",_this55.url="https://api.groq.com/openai/v1/audio/speech",_this55.permittedErrorPrefixes=[ht,"property"];var i=(n=t.groq)==null?void 0:n.textToSpeech;_typeof(i)===T&&(_this55.cleanConfig(i),Object.assign(_this55.rawBody,i)),(_o$model6=(o=_this55.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this55.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_l$response_format=(l=_this55.rawBody).response_format)!==null&&_l$response_format!==void 0?_l$response_format:l.response_format="mp3";return _this55;}_inherits(Ya,_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));}},_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 _this56;_classCallCheck(this,Za);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this56=_callSuper(this,Za,[e,dt.buildKeyVerificationDetails(),dt.buildHeaders,s]),_this56.insertKeyPlaceholderText=_this56.genereteAPIKeyName("Together AI"),_this56.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this56.url="https://api.together.xyz/v1/images/generations",_this56.permittedErrorPrefixes=[we,te];var i=(n=t.together)==null?void 0:n.images;_typeof(i)===T&&(_this56.cleanConfig(i),Object.assign(_this56.rawBody,i)),(_o$model7=(o=_this56.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this56;}_inherits(Za,_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));}},_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
202
+ "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this53.url="",_this53.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this53;}_inherits(Wa,_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 _this54;_classCallCheck(this,Xa);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.bigModel;_this54=_callSuper(this,Xa,[e,ct.buildKeyVerificationDetails(),ct.buildHeaders,s]),_this54.insertKeyPlaceholderText=_this54.genereteAPIKeyName("BigModel"),_this54.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this54.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this54.permittedErrorPrefixes=[G,te];var i=(n=t.bigModel)==null?void 0:n.images;_typeof(i)===T&&(_this54.cleanConfig(i),Object.assign(_this54.rawBody,i)),(_o$model5=(o=_this54.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this54;}_inherits(Xa,_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 Bt=/*#__PURE__*/function(){function Bt(){_classCallCheck(this,Bt);}return _createClass(Bt,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},R,O),G,"".concat(ee).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:K,handleVerificationResult:Bt.handleVerificationResult};}}]);}();var Ya=/*#__PURE__*/function(_k12){function Ya(e){var _o$model6,_a$voice4,_l$response_format;var _this55;_classCallCheck(this,Ya);var n,o,a,l;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this55=_callSuper(this,Ya,[e,Bt.buildKeyVerificationDetails(),Bt.buildHeaders,s]),_this55.insertKeyPlaceholderText=_this55.genereteAPIKeyName("Groq"),_this55.keyHelpUrl="https://console.groq.com/keys",_this55.url="https://api.groq.com/openai/v1/audio/speech",_this55.permittedErrorPrefixes=[ht,"property"];var i=(n=t.groq)==null?void 0:n.textToSpeech;_typeof(i)===T&&(_this55.cleanConfig(i),Object.assign(_this55.rawBody,i)),(_o$model6=(o=_this55.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this55.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_l$response_format=(l=_this55.rawBody).response_format)!==null&&_l$response_format!==void 0?_l$response_format:l.response_format="mp3";return _this55;}_inherits(Ya,_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 _this56;_classCallCheck(this,Za);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.together;_this56=_callSuper(this,Za,[e,dt.buildKeyVerificationDetails(),dt.buildHeaders,s]),_this56.insertKeyPlaceholderText=_this56.genereteAPIKeyName("Together AI"),_this56.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this56.url="https://api.together.xyz/v1/images/generations",_this56.permittedErrorPrefixes=[we,te];var i=(n=t.together)==null?void 0:n.images;_typeof(i)===T&&(_this56.cleanConfig(i),Object.assign(_this56.rawBody,i)),(_o$model7=(o=_this56.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this56;}_inherits(Za,_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
203
203
  // prettier-ignore
204
204
  function ws(e,t,s,i,n){var _this57$maxMessages,_p$model;var _this57;_classCallCheck(this,ws);var u,h,f,m,p;var o=JSON.parse(JSON.stringify(e.directConnection)),a=t||V.buildKeyVerificationDetails(),l=s||V.buildHeaders,c=i||o.openAI;_this57=_callSuper(this,ws,[e,a,l,c]),_this57.insertKeyPlaceholderText=_this57.genereteAPIKeyName("OpenAI"),_this57.keyHelpUrl="https://platform.openai.com/account/api-keys",_this57.url="https://api.openai.com/v1/chat/completions",_this57.permittedErrorPrefixes=[ks],_this57._systemMessage="";var d=n||((u=o.openAI)==null?void 0:u.chat);if(_typeof(d)===T){d.system_prompt&&(_this57._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&&(_this57._functionHandler=g),_this57.cleanConfig(d),Object.assign(_this57.rawBody,d);}(_this57$maxMessages=_this57.maxMessages)!==null&&_this57$maxMessages!==void 0?_this57$maxMessages:_this57.maxMessages=-1,(_p$model=(p=_this57.rawBody).model)!==null&&_p$model!==void 0?_p$model:p.model="gpt-4o";return _this57;}_inherits(ws,_k14);return _createClass(ws,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler;}// mention that microphone is not supported because the outputted base64 is not accepted
205
205
  // use speech to speech instead
206
206
  // give allowed regex example for audio format rules
207
207
  },{key:"preprocessBody",value:// prettier-ignore
208
- function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.stringify(e)),i=(o=s.modalities)==null?void 0:o.includes("audio"),n=z.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,{});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 _s8=ws.getFileContent(e.files,t);return e.text&&e.text.trim().length>0&&_s8.unshift(_defineProperty({type:"text"},y,e.text)),_s8;}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({},He,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$model;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=[G,te],_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$model=(c=_this59.rawBody).model)!==null&&_c$model!==void 0?_c$model: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=z.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,{});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 _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,te],_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=z.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,{});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,V.buildKeyVerificationDetails(),V.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
208
+ function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.stringify(e)),i=(o=s.modalities)==null?void 0:o.includes("audio"),n=z.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 _s8=ws.getFileContent(e.files,t);return e.text&&e.text.trim().length>0&&_s8.unshift(_defineProperty({type:"text"},y,e.text)),_s8;}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({},He,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$model;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=[G,te],_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$model=(c=_this59.rawBody).model)!==null&&_c$model!==void 0?_c$model: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=z.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 _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,te],_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=z.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,V.buildKeyVerificationDetails(),V.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
209
  },{key:"callApiWithImage",value:function callApiWithImage(e,t,s){var o,a;var i;var n=(a=(o=t[t.length-1])==null?void 0:o.text)==null?void 0:a.trim();if(s[1]||n&&n!==""){this.url=Me.IMAGE_EDIT_URL;var l=this.preprocessBody(this.rawBody,n);i=Me.createFormDataBody(l,s[0],s[1]);}else this.url=Me.IMAGE_VARIATIONS_URL,i=Me.createFormDataBody(this.rawBody,s[0]);w.tempRemoveContentHeader(this.connectSettings,q.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);q.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(Ht).concat(s.b64_json),type:"image"};})});}},_callee131);}));function extractResultData(_x248){return _extractResultData26.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
210
210
  // 1 image:
211
211
  // - With text - edits image based on the text
@@ -215,15 +215,15 @@ function preprocessBody(e,t){var _s$max_tokens;var o;var s=JSON.parse(JSON.strin
215
215
  // Add text to describe the required modification.
216
216
  // Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
217
217
  // `;
218
- }],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("image",t),s&&i.append("mask",s),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i;}}]);}(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({},G,"".concat(ee).concat(e)),R,O);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://openrouter.ai/api/v1/key",method:K,handleVerificationResult:ei.handleVerificationResult};}}]);}();var fs=/*#__PURE__*/function(_k18){function fs(e){var _this62$maxMessages,_o$model9,_a$max_tokens;var _this62;_classCallCheck(this,fs);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).openRouter;if(_this62=_callSuper(this,fs,[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,te],_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(fs,_k18);return _createClass(fs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=z.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:fs.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,{});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,_a6,_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;}_a6=(n=e.choices)==null?void 0:n[0];if(!(_a6!=null&&_a6.message)){_context133.n=6;break;}if(!_a6.message.tool_calls){_context133.n=5;break;}return _context133.a(2,this.handleToolsGeneric({tool_calls:_a6.message.tool_calls},this._functionHandler,this._messages,t));case 5:_l4=((o=_a6.message.images)==null?void 0:o.map(function(c){return{src:c.image_url.url};}))||[];return _context133.a(2,_defineProperty(_defineProperty({},y,_a6.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(fs.getImageContent(e.files)),_toConsumableArray(fs.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({},G,"".concat(ee).concat(e)),R,O);}},{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:Y,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=z.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,{});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(_defineProperty({},G,"".concat(ee).concat(e)),R,O),"accept",O);}// prettier-ignore
219
- },{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:K,handleVerificationResult:si.handleVerificationResult};}}]);}();var tl=/*#__PURE__*/function(_k20){function tl(e,t,s,i,n){var _this64;_classCallCheck(this,tl);_this64=_callSuper(this,tl,[e,si.buildKeyVerificationDetails(),si.buildHeaders,n]),_this64.insertKeyPlaceholderText=_this64.genereteAPIKeyName("Cohere"),_this64.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this64.permittedErrorPrefixes=["invalid"],_this64.url=t,_this64.textInputPlaceholderText=s,i&&_typeof(i)===T&&Object.assign(_this64.rawBody,i);return _this64;}_inherits(tl,_k20);return _createClass(tl);}(k);var ii=/*#__PURE__*/function(_tl){function ii(e){var _this65$maxMessages;var _this65;_classCallCheck(this,ii);var s=JSON.parse(JSON.stringify(e.directConnection)).cohere;if(_this65=_callSuper(this,ii,[e,"https://api.cohere.com/v2/chat","Ask me anything!",{},s]),_typeof(s)===T){var i=le.processCohere(s);_this65.canSendMessage=function(){return i;},_this65.cleanConfig(s),Object.assign(_this65.rawBody,s);}(_this65$maxMessages=_this65.maxMessages)!==null&&_this65$maxMessages!==void 0?_this65$maxMessages:_this65.maxMessages=-1;return _this65;}_inherits(ii,_tl);return _createClass(ii,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t.filter(function(n){return n.text;});return s.messages=i.map(function(n){return{role:n.role==="ai"?"assistant":"user",content:n.text};}),s.model=s.model||"command-a-03-2025",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e,t){return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody,{readable:!0});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,s,i,n;return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:if(!(typeof e.message=="string")){_context138.n=1;break;}throw e.message;case 1:if(!(this.stream&&e.text)){_context138.n=2;break;}n=ii.parseBundledEvents(e.text);return _context138.a(2,{text:ii.aggregateBundledEventsText(n)});case 2:if(!("message"in e&&(i=(s=(t=e.message)==null?void 0:t.content)==null?void 0:s[0])!=null&&i.text)){_context138.n=3;break;}return _context138.a(2,_defineProperty({},y,e.message.content[0].text));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context138.a(2);}},_callee138,this);}));function extractResultData(_x260){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),s=[];var _iterator2=_createForOfIteratorHelper(t),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var i=_step2.value;if(i.trim())try{var n=JSON.parse(i);s.push(n);}catch(n){console.error("Failed to parse line:",i,n);}}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return s;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var s,i,n;return t.type==="content-delta"&&((n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text);}).map(function(t){var s,i,n;return(n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text;}).join("");}}]);}(tl);var ni=/*#__PURE__*/function(){function ni(){_classCallCheck(this,ni);}return _createClass(ni,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:K,handleVerificationResult:ni.handleVerificationResult};}}]);}();var sl=/*#__PURE__*/function(_k21){function sl(e){var _this66$maxMessages,_i$model2,_n$temperature,_o$max_tokens;var _this66;_classCallCheck(this,sl);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).deepSeek;_this66=_callSuper(this,sl,[e,ni.buildKeyVerificationDetails(),ni.buildHeaders,s]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("DeepSeek"),_this66.keyHelpUrl="https://platform.deepseek.com/api_keys",_this66.url="https://api.deepseek.com/v1/chat/completions",_this66.permittedErrorPrefixes=[we,te],_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$model2=(i=_this66.rawBody).model)!==null&&_i$model2!==void 0?_i$model2:i.model="deepseek-chat",(_n$temperature=(n=_this66.rawBody).temperature)!==null&&_n$temperature!==void 0?_n$temperature:n.temperature=1,(_o$max_tokens=(o=_this66.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;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=z.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,{});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;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:if(!e.error){_context140.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context140.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context140.n=2;break;}return _context140.a(2,_defineProperty({},y,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context140.n=3;break;}return _context140.a(2,_defineProperty({},y,t.message.content));case 3:return _context140.a(2,_defineProperty({},y,""));}},_callee140);}));function extractResultData(_x263){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(k);var ri=/*#__PURE__*/function(){function ri(){_classCallCheck(this,ri);}return _createClass(ri,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O);}},{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
220
- },{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.minimax.io/v1/files/delete",method:Y,handleVerificationResult:ri.handleVerificationResult};}}]);}();var il=/*#__PURE__*/function(_k22){function il(e){var _this67$maxMessages,_i$model3;var _this67;_classCallCheck(this,il);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).miniMax;_this67=_callSuper(this,il,[e,ri.buildKeyVerificationDetails(),ri.buildHeaders,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("MiniMax"),_this67.keyHelpUrl="https://www.minimaxi.com",_this67.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this67.permittedErrorPrefixes=[we,te,"insufficient balance"],_this67._systemMessage="",_typeof(s)===T&&(s.system_prompt&&(_this67._systemMessage=s.system_prompt),_this67.cleanConfig(s),Object.assign(_this67.rawBody,s)),(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1,(_i$model3=(i=_this67.rawBody).model)!==null&&_i$model3!==void 0?_i$model3:i.model="MiniMax-M1";return _this67;}_inherits(il,_k22);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=z.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 _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody,{});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){var t,_s0;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:if(!e.error){_context142.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context142.n=3;break;}_s0=e.choices[0];if(!(_s0.delta&&_s0.delta.content)){_context142.n=2;break;}return _context142.a(2,_defineProperty({},y,_s0.delta.content));case 2:if(!(_s0.message&&_s0.message.content)){_context142.n=3;break;}return _context142.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)){_context142.n=4;break;}throw e.base_resp.status_msg;case 4:return _context142.a(2,_defineProperty({},y,""));}},_callee142);}));function extractResultData(_x266){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(k);var oi=/*#__PURE__*/function(){function oi(){_classCallCheck(this,oi);}return _createClass(oi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O),"accept",O);}// prettier-ignore
221
- },{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:K,handleVerificationResult:oi.handleVerificationResult};}}]);}();var un=/*#__PURE__*/function(_k23){function un(e){var _this68$maxMessages,_o$model0;var _this68;_classCallCheck(this,un);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).mistral;if(_this68=_callSuper(this,un,[e,oi.buildKeyVerificationDetails(),oi.buildHeaders,s]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("Mistral"),_this68.keyHelpUrl="https://console.mistral.ai/api-keys/",_this68.url="https://api.mistral.ai/v1/chat/completions",_this68.permittedErrorPrefixes=[ht],_this68._systemMessage="",_typeof(s)===T){s.system_prompt&&(_this68._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.mistral)==null?void 0:n.function_handler;a&&(_this68._functionHandler=a),_this68.cleanConfig(s),Object.assign(_this68.rawBody,s);}(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_o$model0=(o=_this68.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="mistral-small-latest";return _this68;}_inherits(un,_k23);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=z.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 _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e,t){var _this$_messages6;return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:(_this$_messages6=this._messages)!==null&&_this$_messages6!==void 0?_this$_messages6:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody,{});case 1:return _context143.a(2);}},_callee143,this);}));function callServiceAPI(_x267,_x268){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){var _s1;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:if(!e.message){_context144.n=1;break;}throw e.message;case 1:if(!e.error){_context144.n=2;break;}throw e.error.message;case 2:if(!(e.choices&&e.choices.length>0)){_context144.n=4;break;}_s1=e.choices[0];if(!_s1.delta){_context144.n=3;break;}return _context144.a(2,this.extractStreamResult(_s1,t));case 3:if(!_s1.message){_context144.n=4;break;}return _context144.a(2,_s1.message.tool_calls?this.handleToolsGeneric({tool_calls:_s1.message.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s1.message.content||""));case 4:return _context144.a(2,_defineProperty({},y,""));}},_callee144,this);}));function extractResultData(_x269,_x270){return _extractResultData32.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var s,i,n;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls"&&s!=null&&s.tool_calls)){_context145.n=1;break;}n={tool_calls:s.tool_calls};return _context145.a(2,this.handleToolsGeneric(n,this._functionHandler,this._messages,t));case 1:return _context145.a(2,_defineProperty({},y,(s==null?void 0:s.content)||""));}},_callee145,this);}));function extractStreamResult(_x271,_x272){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(_k24){function fn(e){var _this69$maxMessages,_c$model2;var _this69;_classCallCheck(this,fn);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this69=_callSuper(this,fn,[e,Bt.buildKeyVerificationDetails(),Bt.buildHeaders,s]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Groq"),_this69.keyHelpUrl="https://console.groq.com/keys",_this69.url="https://api.groq.com/openai/v1/chat/completions",_this69.permittedErrorPrefixes=[ht,"property"],_this69._systemMessage="";var i=(n=t.groq)==null?void 0:n.chat;if(_typeof(i)===T){i.system_prompt&&(_this69._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&&(_this69._functionHandler=d),_this69.cleanConfig(i),Object.assign(_this69.rawBody,i);}(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_c$model2=(c=_this69.rawBody).model)!==null&&_c$model2!==void 0?_c$model2:c.model="llama-3.3-70b-versatile";return _this69;}_inherits(fn,_k24);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=z.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 _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){var _this$_messages7;return _regenerator().w(function(_context146){while(1)switch(_context146.n){case 0:(_this$_messages7=this._messages)!==null&&_this$_messages7!==void 0?_this$_messages7:this._messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody,{});case 1:return _context146.a(2);}},_callee146,this);}));function callServiceAPI(_x273,_x274){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){var s,i,n,o;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(!e.error){_context147.n=1;break;}throw e.error.message;case 1:return _context147.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,""));}},_callee147,this);}));function extractResultData(_x275,_x276){return _extractResultData33.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
218
+ }],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,s){var i=new FormData();return i.append("image",t),s&&i.append("mask",s),Object.keys(e).forEach(function(n){i.append(n,String(e[n]));}),i;}}]);}(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({},G,"".concat(ee).concat(e)),R,O);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://openrouter.ai/api/v1/key",method:K,handleVerificationResult:ei.handleVerificationResult};}}]);}();var fs=/*#__PURE__*/function(_k18){function fs(e){var _this62$maxMessages,_o$model9,_a$max_tokens;var _this62;_classCallCheck(this,fs);var i,n,o,a;var s=JSON.parse(JSON.stringify(e.directConnection)).openRouter;if(_this62=_callSuper(this,fs,[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,te],_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(fs,_k18);return _createClass(fs,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.function_handler,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=z.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.length:-1).map(function(o){return{content:fs.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,_a6,_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;}_a6=(n=e.choices)==null?void 0:n[0];if(!(_a6!=null&&_a6.message)){_context133.n=6;break;}if(!_a6.message.tool_calls){_context133.n=5;break;}return _context133.a(2,this.handleToolsGeneric({tool_calls:_a6.message.tool_calls},this._functionHandler,this._messages,t));case 5:_l4=((o=_a6.message.images)==null?void 0:o.map(function(c){return{src:c.image_url.url};}))||[];return _context133.a(2,_defineProperty(_defineProperty({},y,_a6.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(fs.getImageContent(e.files)),_toConsumableArray(fs.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({},G,"".concat(ee).concat(e)),R,O);}},{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:Y,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=z.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(_defineProperty({},G,"".concat(ee).concat(e)),R,O),"accept",O);}// prettier-ignore
219
+ },{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:K,handleVerificationResult:si.handleVerificationResult};}}]);}();var tl=/*#__PURE__*/function(_k20){function tl(e,t,s,i,n){var _this64;_classCallCheck(this,tl);_this64=_callSuper(this,tl,[e,si.buildKeyVerificationDetails(),si.buildHeaders,n]),_this64.insertKeyPlaceholderText=_this64.genereteAPIKeyName("Cohere"),_this64.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this64.permittedErrorPrefixes=["invalid"],_this64.url=t,_this64.textInputPlaceholderText=s,i&&_typeof(i)===T&&Object.assign(_this64.rawBody,i);return _this64;}_inherits(tl,_k20);return _createClass(tl);}(k);var ii=/*#__PURE__*/function(_tl){function ii(e){var _this65$maxMessages;var _this65;_classCallCheck(this,ii);var s=JSON.parse(JSON.stringify(e.directConnection)).cohere;if(_this65=_callSuper(this,ii,[e,"https://api.cohere.com/v2/chat","Ask me anything!",{},s]),_typeof(s)===T){var i=le.processCohere(s);_this65.canSendMessage=function(){return i;},_this65.cleanConfig(s),Object.assign(_this65.rawBody,s);}(_this65$maxMessages=_this65.maxMessages)!==null&&_this65$maxMessages!==void 0?_this65$maxMessages:_this65.maxMessages=-1;return _this65;}_inherits(ii,_tl);return _createClass(ii,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=t.filter(function(n){return n.text;});return s.messages=i.map(function(n){return{role:n.role==="ai"?"assistant":"user",content:n.text};}),s.model=s.model||"command-a-03-2025",s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e,t){return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});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,s,i,n;return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:if(!(typeof e.message=="string")){_context138.n=1;break;}throw e.message;case 1:if(!(this.stream&&e.text)){_context138.n=2;break;}n=ii.parseBundledEvents(e.text);return _context138.a(2,{text:ii.aggregateBundledEventsText(n)});case 2:if(!("message"in e&&(i=(s=(t=e.message)==null?void 0:t.content)==null?void 0:s[0])!=null&&i.text)){_context138.n=3;break;}return _context138.a(2,_defineProperty({},y,e.message.content[0].text));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context138.a(2);}},_callee138,this);}));function extractResultData(_x260){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),s=[];var _iterator2=_createForOfIteratorHelper(t),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var i=_step2.value;if(i.trim())try{var n=JSON.parse(i);s.push(n);}catch(n){console.error("Failed to parse line:",i,n);}}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return s;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var s,i,n;return t.type==="content-delta"&&((n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text);}).map(function(t){var s,i,n;return(n=(i=(s=t.delta)==null?void 0:s.message)==null?void 0:i.content)==null?void 0:n.text;}).join("");}}]);}(tl);var ni=/*#__PURE__*/function(){function ni(){_classCallCheck(this,ni);}return _createClass(ni,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.deepseek.com/models",method:K,handleVerificationResult:ni.handleVerificationResult};}}]);}();var sl=/*#__PURE__*/function(_k21){function sl(e){var _this66$maxMessages,_i$model2,_n$temperature,_o$max_tokens;var _this66;_classCallCheck(this,sl);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).deepSeek;_this66=_callSuper(this,sl,[e,ni.buildKeyVerificationDetails(),ni.buildHeaders,s]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("DeepSeek"),_this66.keyHelpUrl="https://platform.deepseek.com/api_keys",_this66.url="https://api.deepseek.com/v1/chat/completions",_this66.permittedErrorPrefixes=[we,te],_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$model2=(i=_this66.rawBody).model)!==null&&_i$model2!==void 0?_i$model2:i.model="deepseek-chat",(_n$temperature=(n=_this66.rawBody).temperature)!==null&&_n$temperature!==void 0?_n$temperature:n.temperature=1,(_o$max_tokens=(o=_this66.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;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=z.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;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:if(!e.error){_context140.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context140.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context140.n=2;break;}return _context140.a(2,_defineProperty({},y,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context140.n=3;break;}return _context140.a(2,_defineProperty({},y,t.message.content));case 3:return _context140.a(2,_defineProperty({},y,""));}},_callee140);}));function extractResultData(_x263){return _extractResultData30.apply(this,arguments);}return extractResultData;}()}]);}(k);var ri=/*#__PURE__*/function(){function ri(){_classCallCheck(this,ri);}return _createClass(ri,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O);}},{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
220
+ },{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.minimax.io/v1/files/delete",method:Y,handleVerificationResult:ri.handleVerificationResult};}}]);}();var il=/*#__PURE__*/function(_k22){function il(e){var _this67$maxMessages,_i$model3;var _this67;_classCallCheck(this,il);var i;var s=JSON.parse(JSON.stringify(e.directConnection)).miniMax;_this67=_callSuper(this,il,[e,ri.buildKeyVerificationDetails(),ri.buildHeaders,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("MiniMax"),_this67.keyHelpUrl="https://www.minimaxi.com",_this67.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this67.permittedErrorPrefixes=[we,te,"insufficient balance"],_this67._systemMessage="",_typeof(s)===T&&(s.system_prompt&&(_this67._systemMessage=s.system_prompt),_this67.cleanConfig(s),Object.assign(_this67.rawBody,s)),(_this67$maxMessages=_this67.maxMessages)!==null&&_this67$maxMessages!==void 0?_this67$maxMessages:_this67.maxMessages=-1,(_i$model3=(i=_this67.rawBody).model)!==null&&_i$model3!==void 0?_i$model3:i.model="MiniMax-M1";return _this67;}_inherits(il,_k22);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=z.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 _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context141.a(2);}},_callee141,this);}));function callServiceAPI(_x264,_x265){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e){var t,_s0;return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:if(!e.error){_context142.n=1;break;}throw e.error.message;case 1:if(!(e.choices&&e.choices.length>0)){_context142.n=3;break;}_s0=e.choices[0];if(!(_s0.delta&&_s0.delta.content)){_context142.n=2;break;}return _context142.a(2,_defineProperty({},y,_s0.delta.content));case 2:if(!(_s0.message&&_s0.message.content)){_context142.n=3;break;}return _context142.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)){_context142.n=4;break;}throw e.base_resp.status_msg;case 4:return _context142.a(2,_defineProperty({},y,""));}},_callee142);}));function extractResultData(_x266){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(k);var oi=/*#__PURE__*/function(){function oi(){_classCallCheck(this,oi);}return _createClass(oi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O),"accept",O);}// prettier-ignore
221
+ },{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:K,handleVerificationResult:oi.handleVerificationResult};}}]);}();var un=/*#__PURE__*/function(_k23){function un(e){var _this68$maxMessages,_o$model0;var _this68;_classCallCheck(this,un);var i,n,o;var s=JSON.parse(JSON.stringify(e.directConnection)).mistral;if(_this68=_callSuper(this,un,[e,oi.buildKeyVerificationDetails(),oi.buildHeaders,s]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("Mistral"),_this68.keyHelpUrl="https://console.mistral.ai/api-keys/",_this68.url="https://api.mistral.ai/v1/chat/completions",_this68.permittedErrorPrefixes=[ht],_this68._systemMessage="",_typeof(s)===T){s.system_prompt&&(_this68._systemMessage=s.system_prompt);var a=(n=(i=e.directConnection)==null?void 0:i.mistral)==null?void 0:n.function_handler;a&&(_this68._functionHandler=a),_this68.cleanConfig(s),Object.assign(_this68.rawBody,s);}(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_o$model0=(o=_this68.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="mistral-small-latest";return _this68;}_inherits(un,_k23);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=z.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 _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e,t){var _this$_messages6;return _regenerator().w(function(_context143){while(1)switch(_context143.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 _context143.a(2);}},_callee143,this);}));function callServiceAPI(_x267,_x268){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){var _s1;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:if(!e.message){_context144.n=1;break;}throw e.message;case 1:if(!e.error){_context144.n=2;break;}throw e.error.message;case 2:if(!(e.choices&&e.choices.length>0)){_context144.n=4;break;}_s1=e.choices[0];if(!_s1.delta){_context144.n=3;break;}return _context144.a(2,this.extractStreamResult(_s1,t));case 3:if(!_s1.message){_context144.n=4;break;}return _context144.a(2,_s1.message.tool_calls?this.handleToolsGeneric({tool_calls:_s1.message.tool_calls},this._functionHandler,this._messages,t):_defineProperty({},y,_s1.message.content||""));case 4:return _context144.a(2,_defineProperty({},y,""));}},_callee144,this);}));function extractResultData(_x269,_x270){return _extractResultData32.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var s,i,n;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:s=e.delta,i=e.finish_reason;if(!(i==="tool_calls"&&s!=null&&s.tool_calls)){_context145.n=1;break;}n={tool_calls:s.tool_calls};return _context145.a(2,this.handleToolsGeneric(n,this._functionHandler,this._messages,t));case 1:return _context145.a(2,_defineProperty({},y,(s==null?void 0:s.content)||""));}},_callee145,this);}));function extractStreamResult(_x271,_x272){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(_k24){function fn(e){var _this69$maxMessages,_c$model2;var _this69;_classCallCheck(this,fn);var n,o,a,l,c;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.groq;_this69=_callSuper(this,fn,[e,Bt.buildKeyVerificationDetails(),Bt.buildHeaders,s]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Groq"),_this69.keyHelpUrl="https://console.groq.com/keys",_this69.url="https://api.groq.com/openai/v1/chat/completions",_this69.permittedErrorPrefixes=[ht,"property"],_this69._systemMessage="";var i=(n=t.groq)==null?void 0:n.chat;if(_typeof(i)===T){i.system_prompt&&(_this69._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&&(_this69._functionHandler=d),_this69.cleanConfig(i),Object.assign(_this69.rawBody,i);}(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_c$model2=(c=_this69.rawBody).model)!==null&&_c$model2!==void 0?_c$model2:c.model="llama-3.3-70b-versatile";return _this69;}_inherits(fn,_k24);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=z.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 _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){var _this$_messages7;return _regenerator().w(function(_context146){while(1)switch(_context146.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 _context146.a(2);}},_callee146,this);}));function callServiceAPI(_x273,_x274){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){var s,i,n,o;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(!e.error){_context147.n=1;break;}throw e.error.message;case 1:return _context147.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,""));}},_callee147,this);}));function extractResultData(_x275,_x276){return _extractResultData33.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
222
222
  },{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e,t){return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:return _context148.a(2,this.extractStreamResultWToolsGeneric(this,e,this._functionHandler,this._messages,t));}},_callee148,this);}));function extractStreamResult(_x277,_x278){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var ai=/*#__PURE__*/function(){function ai(){_classCallCheck(this,ai);}return _createClass(ai,null,[{key:"buildHeaders",value:function buildHeaders(){return _defineProperty({},R,O);}// prettier-ignore
223
223
  },{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var o;var n=e;n.error?n.error.code===403||(o=n.error.message)!=null&&o.includes("API key")?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}// https://ai.google.dev/api/models#method:-models.list
224
224
  },{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){var e="https://generativelanguage.googleapis.com/v1beta/models?key=";return{url:e,augmentUrl:function augmentUrl(t){return"".concat(e).concat(t);},method:K,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.systemInstruction&&(_this70._systemInstruction=s.systemInstruction);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.systemInstruction,delete e.function_handler,delete e.model,delete e.key;}},{key:"preprocessBody",value:// prettier-ignore
225
225
  function preprocessBody(e,t){var n;var s=JSON.parse(JSON.stringify(e)),i=z.getCharacterLimitMessages(t,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-(((n=this._systemInstruction)==null?void 0:n.length)||0):-1).map(function(o){return pn.getContent(o);});return s.contents=i,this._systemInstruction&&(s.systemInstruction={parts:[_defineProperty({},y,this._systemInstruction)]}),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),q.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
226
- },{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,O),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/models",method:K,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=[te,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=z.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,{});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:K,handleVerificationResult:function handleVerificationResult(){}};}}]);}();var di=/*#__PURE__*/function(_k27){function di(e){var _this72$maxMessages,_l$model2,_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$model2=(l=_this72.rawBody).model)!==null&&_l$model2!==void 0?_l$model2: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=z.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,{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 Ft=/*#__PURE__*/function(){function Ft(){_classCallCheck(this,Ft);}return _createClass(Ft,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty({Authorization:"".concat(ee).concat(e)},R,O);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te||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:K,handleVerificationResult:Ft.handleVerificationResult};}}]);}();var _i=/*#__PURE__*/function(_k28){function _i(e){var _o$model10;var _this73;_classCallCheck(this,_i);var n,o;var t=e.directConnection,s=t==null?void 0:t.x;_this73=_callSuper(this,_i,[e,Ft.buildKeyVerificationDetails(),Ft.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=_i.IMAGE_GENERATION_URL,_this73.permittedErrorPrefixes=[we,te];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(_i,_k28);return _createClass(_i,[{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);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(Ht).concat(s.b64_json),type:"image"};})});}},_callee159);}));function extractResultData(_x299){return _extractResultData37.apply(this,arguments);}return extractResultData;}()}]);}(k);_i.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Yi=_i;var hi=/*#__PURE__*/function(){function hi(){_classCallCheck(this,hi);}return _createClass(hi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O);}},{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:K,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=z.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,{});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({},G,"".concat(ee).concat(e)),R,O);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:K,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=z.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,{});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 nl=/*#__PURE__*/function(_k31){function nl(e){var _this76$maxMessages,_o$model13;var _this76;_classCallCheck(this,nl);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.x;_this76=_callSuper(this,nl,[e,Ft.buildKeyVerificationDetails(),Ft.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,te],_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(nl,_k31);return _createClass(nl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=z.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,{});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 rl=/*#__PURE__*/function(){function rl(){_classCallCheck(this,rl);}return _createClass(rl,null,[{key:"create",value:// this should only be called when no _activeService is set or is demo as otherwise we don't want to reconnect
226
+ },{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,O),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.anthropic.com/v1/models",method:K,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=[te,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=z.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:K,handleVerificationResult:function handleVerificationResult(){}};}}]);}();var di=/*#__PURE__*/function(_k27){function di(e){var _this72$maxMessages,_l$model2,_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$model2=(l=_this72.rawBody).model)!==null&&_l$model2!==void 0?_l$model2: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=z.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 Ft=/*#__PURE__*/function(){function Ft(){_classCallCheck(this,Ft);}return _createClass(Ft,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty({Authorization:"".concat(ee).concat(e)},R,O);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te||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:K,handleVerificationResult:Ft.handleVerificationResult};}}]);}();var _i=/*#__PURE__*/function(_k28){function _i(e){var _o$model10;var _this73;_classCallCheck(this,_i);var n,o;var t=e.directConnection,s=t==null?void 0:t.x;_this73=_callSuper(this,_i,[e,Ft.buildKeyVerificationDetails(),Ft.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=_i.IMAGE_GENERATION_URL,_this73.permittedErrorPrefixes=[we,te];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(_i,_k28);return _createClass(_i,[{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(Ht).concat(s.b64_json),type:"image"};})});}},_callee159);}));function extractResultData(_x299){return _extractResultData37.apply(this,arguments);}return extractResultData;}()}]);}(k);_i.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var Yi=_i;var hi=/*#__PURE__*/function(){function hi(){_classCallCheck(this,hi);}return _createClass(hi,null,[{key:"buildHeaders",value:function buildHeaders(e){return _defineProperty(_defineProperty({},G,"".concat(ee).concat(e)),R,O);}},{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:K,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=z.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({},G,"".concat(ee).concat(e)),R,O);}},{key:"handleVerificationResult",value:function handleVerificationResult(e,t,s,i){var n=e;n.error?n.error.type===te?i(b.INVALID_KEY):i(b.CONNECTION_FAILED):s(t);}},{key:"buildKeyVerificationDetails",value:function buildKeyVerificationDetails(){return{url:"https://api.moonshot.ai/v1/models",method:K,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=z.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 nl=/*#__PURE__*/function(_k31){function nl(e){var _this76$maxMessages,_o$model13;var _this76;_classCallCheck(this,nl);var n,o;var t=JSON.parse(JSON.stringify(e.directConnection)),s=t.x;_this76=_callSuper(this,nl,[e,Ft.buildKeyVerificationDetails(),Ft.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,te],_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(nl,_k31);return _createClass(nl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.system_prompt,delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var s=JSON.parse(JSON.stringify(e)),i=z.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 rl=/*#__PURE__*/function(){function rl(){_classCallCheck(this,rl);}return _createClass(rl,null,[{key:"create",value:// this should only be called when no _activeService is set or is demo as otherwise we don't want to reconnect
227
227
  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 ii(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 sl(e);if(t.miniMax)return new il(e);if(t.openRouter)return new fs(e);if(t.kimi)return new gn(e);if(t.x)return t.x.images?new Yi(e):new nl(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 Ct(e):new Ct(e,void 0,i||!0);}}]);}();var xn=/*#__PURE__*/_createClass(function xn(){_classCallCheck(this,xn);});xn.attibutes={string:function string(e){return e;},number:function number(e){return parseFloat(e);},"boolean":function boolean(e){return e==="true";},object:function object(e){return JSON.parse(e);},array:function array(e){return JSON.parse(e);},"function":function _function(e){return new Function("return ".concat(e))();}};var 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 ol="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n\t viewBox=\"50 30 420 450\" xml:space=\"preserve\">\n<g filter=\"brightness(0) saturate(100%) invert(16%) sepia(0%) saturate(1942%) hue-rotate(215deg) brightness(99%) contrast(93%)\">\n\t<g>\n\t\t<path d=\"M447.933,103.629c-0.034-3.076-1.224-6.09-3.485-8.352L352.683,3.511c-0.004-0.004-0.007-0.005-0.011-0.008\n\t\t\tC350.505,1.338,347.511,0,344.206,0H89.278C75.361,0,64.04,11.32,64.04,25.237v461.525c0,13.916,11.32,25.237,25.237,25.237\n\t\t\th333.444c13.916,0,25.237-11.32,25.237-25.237V103.753C447.96,103.709,447.937,103.672,447.933,103.629z M356.194,40.931\n\t\t\tl50.834,50.834h-49.572c-0.695,0-1.262-0.567-1.262-1.262V40.931z M423.983,486.763c0,0.695-0.566,1.261-1.261,1.261H89.278\n\t\t\tc-0.695,0-1.261-0.566-1.261-1.261V25.237c0-0.695,0.566-1.261,1.261-1.261h242.94v66.527c0,13.916,11.322,25.239,25.239,25.239\n\t\t\th66.527V486.763z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,164.014H149.912c-6.62,0-11.988,5.367-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.368,11.988-11.988C374.076,169.381,368.707,164.014,362.088,164.014z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,236.353H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.368,11.988-11.988C374.076,241.721,368.707,236.353,362.088,236.353z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,308.691H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.367,11.988-11.988C374.076,314.06,368.707,308.691,362.088,308.691z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M256,381.031H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988H256\n\t\t\tc6.62,0,11.988-5.367,11.988-11.988C267.988,386.398,262.62,381.031,256,381.031z\"/>\n\t</g>\n</g>\n</svg>",ie=/*#__PURE__*/function(){function ie(){_classCallCheck(this,ie);}return _createClass(ie,null,[{key:"createImage",value:function createImage(e,t,s){var i=new Image();return i.src=e.src,s&&Q.scrollDownOnImageLoad(i.src,t),Q.processContent("image",i,i.src,e.name);}// WORK - image still does not scroll down when loaded
228
228
  },{key:"createImageMessage",value:function createImageMessage(e,t,s,i){var n=ie.createImage(t,e.elementRef,!i&&!e.focusMode),o=e.createNewMessageElement("",s);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(ie.IMAGE_BUBBLE_CLASS),{type:"image",elements:o};}},{key:"createAudioElement",value:function createAudioElement(e,t){var s=document.createElement("audio");return s.src=e.src,s.classList.add("audio-player"),s.controls=!0,Ye.IS_SAFARI&&(s.classList.add("audio-player-safari"),s.classList.add(t===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=ie.createAudioElement(t,s),o=e.createMessageElementsOnOrientation("",s,i);return o.bubbleElement.appendChild(n),o.bubbleElement.classList.add(ie.AUDIO_BUBBLE_CLASS),{type:"audio",elements:o,audioElement:n};}},{key:"createAnyFile",value:function createAnyFile(e){var t=document.createElement("div");t.classList.add("any-file-message-contents");var s=document.createElement("div");s.classList.add("any-file-message-icon-container");var i=Qe.createSVGElement(ol);i.classList.add("any-file-message-icon"),s.appendChild(i);var n=document.createElement("div");return n.classList.add("any-file-message-text"),n.textContent=e.name||Q.DEFAULT_FILE_NAME,t.appendChild(s),t.appendChild(n),Q.processContent("any",t,e.src,n.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,s,i){var n=e.createMessageElementsOnOrientation("",s,i),o=ie.createAnyFile(t);return n.bubbleElement.classList.add(ie.ANY_FILE_BUBBLE_CLASS),n.bubbleElement.appendChild(o),{type:"file",elements:n};}},{key:"createMessages",value:function createMessages(e,t,s){var i=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;return t.map(function(n){var o;if(n.ref&&(n=Q.removeFileRef(n)),Q.isAudioFile(n)){var a=ie.createNewAudioMessage(e,n,s,i),l=(o=e.textToSpeech)==null?void 0:o.service;return l&&(l.autoPlay&&ie.autoPlayAudio(a.audioElement),typeof l.displayAudio=="boolean"&&!l.displayAudio)?void 0:a;}return Q.isImageFile(n)?ie.createImageMessage(e,n,s,i):ie.createNewAnyFileMessage(e,n,s,i);}).filter(function(n){return n!==void 0;});}// no overwrite previous message logic as it is complex to track which files are to be overwritten
229
229
  },{key:"addMessages",value:function addMessages(e,t,s,i){ie.createMessages(e,t,s,i).filter(function(o){return o!==void 0;}).forEach(function(_ref145){var o=_ref145.type,a=_ref145.elements;Q.addMessage(e,a,o,s,i);});}}]);}();ie.IMAGE_BUBBLE_CLASS="image-message",ie.AUDIO_BUBBLE_CLASS="audio-message",ie.ANY_FILE_BUBBLE_CLASS="any-file-message";var pi=ie;var _e=/*#__PURE__*/function(){function _e(){_classCallCheck(this,_e);}return _createClass(_e,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){_e.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];_e.removeElements(e.messageElementRefs,i),delete t[0][s],delete t[1][s];}},{key:"updateHTMLMessage",value:function updateHTMLMessage(e,t,s){var i,n,o;if(t[1].html)De.overwriteElements(e,s,t[1].html);else{var a=De.create(e,s,t[0].role),l=((n=t[1].files)==null?void 0:n[((i=t[1].files)==null?void 0:i.length)-1])||t[1].text,c=l.outerContainer.nextSibling;(o=c==null?void 0:c.parentElement)==null||o.insertBefore(a.outerContainer,c),e.messageElementRefs.splice(e.messageElementRefs.length-1,1);var d=e.messageElementRefs.findIndex(function(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