jodit-pro
Version:
PRO Version of Jodit Editor
8 lines • 265 kB
JavaScript
/*!
* jodit-pro - PRO Version of Jodit Editor
* Author: Chupurnov Valerii <chupurnov@gmail.com>
* Version: v4.9.27
* Url: https://xdsoft.net/jodit/pro/
* License(s): SEE LICENSE IN LICENSE.md
*/
!function(e,u){if("object"==typeof exports&&"object"==typeof module)module.exports=u();else if("function"==typeof define&&define.amd)define([],u);else{var t=u();for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(self,function(){return(self.webpackChunkjodit_pro=self.webpackChunkjodit_pro||[]).push([[830],{473:function(e,u,t){"use strict";t.d(u,{handleBackToList:function(){return d},handleConversationSearch:function(){return p},handleConversationSelect:function(){return h},handleToolApproval:function(){return c},handleToolDenial:function(){return F}});var n=t(77688),r=t(56075),i=t(11886),s=t(94899),a=t(62361),o=t(79078),l=t(82758);function c(e,u,t,s,o){return(0,n._)(function(){var n,l,c;return(0,a._)(this,function(a){switch(a.label){case 0:if(!(n=t.getPendingToolCalls().find(function(u){return u.id===e})))return[2,null];if(l=s.grantPermission(n.name,u),!(c=t.getCurrentConversation()))return[3,2];return c.permissions.push(l),[4,o.save(c)];case 1:a.sent(),a.label=2;case 2:return t.removePendingToolCall(e),[2,(0,i._)((0,r._)({},n),{status:"approved"})]}})})()}function F(e,u,t,l){return(0,n._)(function(){var n,c,F,h,d,p,A;return(0,a._)(this,function(a){switch(a.label){case 0:if(!(n=t.getPendingToolCalls().find(function(e){return e.id===u}))||!(c=t.getCurrentConversation())||-1===(F=c.messages.findIndex(function(e){var t;return null==(t=e.toolCalls)?void 0:t.find(function(e){return e.id===u})})))return[2];return h=c.messages[F],d=(0,i._)((0,r._)({},n),{result:{error:"Tool call denied by user."},status:"denied"}),p=(0,o.updateToolCallInMessage)(h,d),(A=(0,s._)(c.messages))[F]=p,c=(0,i._)((0,r._)({},c),{messages:A,updated:Date.now()}),t.setCurrentConversation(c),[4,l.save(c)];case 1:return a.sent(),e.e.fire("toolCallDenied.ai-assistant-pro",n),t.removePendingToolCall(u),[2]}})})()}function h(e,u,t){return(0,n._)(function(){var n;return(0,a._)(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,3,4]),t.setLoading(!0),[4,u.get(e)];case 1:if(!(n=i.sent()))throw Error("Conversation not found: "+e);return t.setCurrentConversation((0,r._)({},n)),[3,4];case 2:return i.sent(),l.IS_PROD,[3,4];case 3:return t.setLoading(!1),[7];case 4:return[2]}})})()}function d(e,u){return(0,n._)(function(){var t;return(0,a._)(this,function(n){switch(n.label){case 0:u.setView("conversationList"),n.label=1;case 1:return n.trys.push([1,,3,4]),u.setLoading(!0),[4,e.list().catch(function(){return[]})];case 2:return t=n.sent(),u.setConversations(t),[3,4];case 3:return u.setLoading(!1),[7];case 4:return[2]}})})()}function p(e,u,t){return(0,n._)(function(){var n;return(0,a._)(this,function(r){switch(r.label){case 0:t.setLoading(!0),r.label=1;case 1:return r.trys.push([1,,3,4]),[4,u.list(e||void 0)];case 2:return n=r.sent(),t.setConversations(n),t.setView("conversationList"),[3,4];case 3:return t.setLoading(!1),[7];case 4:return[2]}})})()}},2020:function(e,u,t){"use strict";var n=t(56075),r=t(11886),i=t(96675),s=t(3091);u.default=(0,r._)((0,n._)({},i),{execute:s.execute})},2868:function(e,u,t){"use strict";function n(e,u){return null!=u&&"u">typeof Symbol&&u[Symbol.hasInstance]||null!=u&&"u">typeof Symbol&&u[Symbol.hasInstance]?!!u[Symbol.hasInstance](e):e instanceof u}t.d(u,{_:function(){return n}})},3091:function(e,u,t){"use strict";t.d(u,{execute:function(){return l}});var n=t(77688),r=t(62361),i=t(6689),s=t(49459),a=t(44526),o=t(22732);function l(e,u,t){return(0,n._)(function(){var n,l,c,F,h,d,p,A,f;return(0,r._)(this,function(r){if(n=u.index,l=u.selector,c=(0,s.requireString)(u,"html"),(0,i.throwIfAborted)(t),void 0===n&&!l||void 0!==n&&l)throw Error("Either index or selector must be provided, but not both");h=(F=(0,a.resolveBlock)(e,{selector:l,index:n,requireExactlyOne:!0})).element,d=F.identifier;try{if((A=e.createInside.div()).innerHTML=c,!(f=A.firstChild)||!o.Dom.isElement(f))throw Error("Invalid HTML: must contain at least one element");return null==(p=h.parentNode)||p.replaceChild(f,h),e.synchronizeValues(),[2,{success:!0,message:"Block ".concat(d," replaced successfully")}]}catch(e){throw Error("Failed to replace block ".concat(d,": ").concat(e.message))}})})()}},5618:function(e,u,t){"use strict";var n=t(56075),r=t(11886),i=t(93809),s=t(28157);u.default=(0,r._)((0,n._)({},i),{execute:s.execute})},6689:function(e,u,t){"use strict";t.d(u,{throwIfAborted:function(){return r}});var n=t(93661);function r(e){if(e.aborted)throw(0,n.abort)()}},11886:function(e,u,t){"use strict";function n(e,u){return u=null!=u?u:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(u)):(function(e){var u=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);u.push.apply(u,t)}return u})(Object(u)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(u,t))}),e}t.d(u,{_:function(){return n}})},12570:function(e,u,t){"use strict";var n=t(56075),r=t(11886),i=t(62553),s=t(56293);u.default=(0,r._)((0,n._)({},i),{execute:s.execute})},15927:function(e,u,t){"use strict";function n(e){if(e.s.isCollapsed())return null;var u=e.s.html,t=e.s.range;return{html:u,rangeInfo:{startContainer:t.startContainer.nodeName,startOffset:t.startOffset,endContainer:t.endContainer.nodeName,endOffset:t.endOffset}}}t.d(u,{getCurrentSelectionContext:function(){return n}})},16015:function(e,u,t){"use strict";t.d(u,{UIDialogSettings:function(){return v}});var n=t(77688),r=t(80294),i=t(20616),s=t(67709),a=t(82749),o=t(54816),l=t(84669),c=t(18766),F=t(56075),h=t(11886),d=t(61200),p=t(31635),A=t(62361),f=t(65478),C=t(67510),E=t(12234),D=t(62357),v=function(e){function u(e,t,n,s,o){var l;return(0,i._)(this,u),l=(0,r._)(this,u,[e]),(0,a._)(l,"getConversation",void 0),(0,a._)(l,"updateConversation",void 0),(0,a._)(l,"state",void 0),(0,a._)(l,"options",void 0),(0,a._)(l,"modelSelect",void 0),(0,a._)(l,"temperatureInput",void 0),l.getConversation=t,l.updateConversation=n,l.state=s,l.options=o,l.modelSelect=null,l.temperatureInput=null,l.build(),l}return(0,c._)(u,e),(0,s._)(u,[{key:"className",value:function(){return"UIDialogSettings"}},{key:"setParentView",value:function(e){var t,n;return null==(t=this.modelSelect)||t.setParentView(e),null==(n=this.temperatureInput)||n.setParentView(e),(0,o._)((0,l._)(u.prototype),"setParentView",this).call(this,e)}},{key:"build",value:function(){return(0,n._)(function(){var e,u,t,n,r,i,s,a,o,l;return(0,A._)(this,function(c){return e=this.container,u=this.getConversation().options||{},this.options.dialogSettings.models&&this.options.dialogSettings.models.length>0&&(r=this.parseModels(this.options.dialogSettings.models),i=null!=(t=null!=(n=u.model)?n:this.state.defaultModel)?t:r[0].value,this.modelSelect=new E.UISelect(this.j,{label:"Model",name:"model",value:i,options:r,onChange:this.onModelChange.bind(this)}),e.appendChild(this.modelSelect.container)),this.options.dialogSettings.temperature&&(this.temperatureInput=new D.UIRange(this.j,{label:"Temperature",name:"temperature",min:this.options.dialogSettings.temperature.min,max:this.options.dialogSettings.temperature.max,value:null!=(s=null!=(a=u.temperature)?a:this.state.defaultTemperature)?s:.5,onChange:this.onTemperatureChange.bind(this)}),(o=this.temperatureInput.nativeInput)&&o.setAttribute("step",String(null!=(l=this.options.dialogSettings.temperature.step)?l:.1)),e.appendChild(this.temperatureInput.container)),[2]})}).call(this)}},{key:"parseModels",value:function(e){return 0===e.length?[]:"object"===(0,d._)(e[0])&&"title"in e[0]?e.map(function(e){return{text:e.title,value:e.value}}):e.map(function(e){return{text:e,value:e}})}},{key:"onModelChange",value:function(){return(0,n._)(function(){var e;return(0,A._)(this,function(u){return this.modelSelect&&(e=this.modelSelect.value,this.updateConversation({options:(0,h._)((0,F._)({},this.getConversation().options),{model:e})}),this.state.defaultModel=e),[2]})}).call(this)}},{key:"onTemperatureChange",value:function(){return(0,n._)(function(){var e;return(0,A._)(this,function(u){return this.temperatureInput&&(e=parseFloat(this.temperatureInput.value),this.updateConversation({options:(0,h._)((0,F._)({},this.getConversation().options),{temperature:e})}),this.state.defaultTemperature=e),[2]})}).call(this)}},{key:"onDefaultModelChange",value:function(){this.modelSelect&&this.state.defaultModel&&(this.modelSelect.value=this.state.defaultModel)}},{key:"onDefaultTemperatureChange",value:function(){this.temperatureInput&&void 0!==this.state.defaultTemperature&&(this.temperatureInput.value=String(this.state.defaultTemperature))}},{key:"destruct",value:function(){var e;null==(e=this.modelSelect)||e.destruct(),(0,o._)((0,l._)(u.prototype),"destruct",this).call(this)}}]),u}(C.UIElement);(0,p.__decorate)([(0,f.watch)("state.defaultModel")],v.prototype,"onDefaultModelChange",null),(0,p.__decorate)([(0,f.watch)("state.defaultTemperature")],v.prototype,"onDefaultTemperatureChange",null),v=(0,p.__decorate)([f.component],v)},16745:function(e,u,t){"use strict";var n=t(56075),r=t(11886),i=t(56732),s=t(39592);u.default=(0,r._)((0,n._)({},i),{execute:s.execute})},18549:function(e,u,t){"use strict";t.d(u,{UIFlightPosition:function(){return a}});var n=t(20616),r=t(67709),i=t(2748),s=new WeakMap,a=function(){function e(){(0,n._)(this,e)}return(0,r._)(e,null,[{key:"install",value:function(e,u){var t=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.remove(e);var r=n.panelHeight,i=n.containerClassName,a=n.toolbarSelector,o=n.gap,l=e.j.c.div("jodit-flight-position");i&&l.classList.add(i),l.style.setProperty("--flight-panel-height","".concat(void 0===r?250:r,"px")),l.appendChild(e.container),document.body.appendChild(l);var c={toolbarSelector:void 0===a?".jodit-toolbar__box":a,gap:void 0===o?16:o},F=function(){t.updatePosition(l,u,c)},h=new ResizeObserver(F);h.observe(u),window.addEventListener("scroll",F,{passive:!0}),window.addEventListener("resize",F,{passive:!0}),s.set(e,{container:l,anchor:u,onScroll:F,resizeObserver:h,options:c}),this.updatePosition(l,u,c)}},{key:"updatePosition",value:function(e,u,t){var n=t.toolbarSelector,r=t.gap,i=u.getBoundingClientRect(),s=window.innerHeight,a=e.offsetHeight||250;e.style.left="".concat(i.left,"px"),e.style.width="".concat(i.width,"px");var o=u.querySelector(n),l=o?o.getBoundingClientRect().bottom:i.top,c=i.bottom-l,F=i.bottom<=s;a<=c?F?(e.style.top="auto",e.style.bottom="".concat(s-i.bottom+r,"px")):(e.style.top="auto",e.style.bottom="".concat(r,"px")):(e.style.bottom="auto",e.style.top="".concat(l,"px"))}},{key:"remove",value:function(e){var u,t=s.get(e);t&&(window.removeEventListener("scroll",t.onScroll),window.removeEventListener("resize",t.onScroll),t.resizeObserver.disconnect(),e.container.parentNode===t.container&&(null==(u=t.container.parentNode)||u.insertBefore(e.container,t.container)),i.Dom.safeRemove(t.container),s.delete(e))}},{key:"isInstalled",value:function(e){return s.has(e)}},{key:"setPanelHeight",value:function(e,u){var t=s.get(e);t&&t.container.style.setProperty("--flight-panel-height","".concat(u,"px"))}},{key:"refresh",value:function(e){var u=s.get(e);u&&this.updatePosition(u.container,u.anchor,u.options)}}]),e}()},19127:function(e,u,t){"use strict";t.d(u,{execute:function(){return l}});var n=t(77688),r=t(56075),i=t(11886),s=t(62361),a=t(6689),o=t(44526);function l(e,u,t){return(0,n._)(function(){var n,l,c,F,h,d,p;return(0,s._)(this,function(s){if(n=u.element,l=u.attributes,c=u.remove,F=u.blockIndex,h=u.selector,(0,a.throwIfAborted)(t),!n&&!l)throw Error('Either "element" or "attributes" must be provided');if(e.s.restore(),(void 0!==F||h)&&(d=(0,o.resolveBlock)(e,{selector:h,index:F}).element,e.s.select(d)),e.s.isCollapsed())throw Error("No selection found. Please select text to format");try{return p={},n&&(p.element=n),l&&(p.attributes=l),c?e.s.commitStyle((0,i._)((0,r._)({},p),{mode:"remove"})):e.s.commitStyle(p),e.synchronizeValues(),[2,{success:!0,message:c?"Formatting removed successfully":"Formatting applied successfully"}]}catch(e){throw Error("Failed to ".concat(c?"remove":"apply"," formatting: ").concat(e.message))}})})()}},21020:function(e,u,t){"use strict";t.d(u,{PermissionManager:function(){return o}});var n=t(20616),r=t(67709),i=t(82749),s=t(56075),a=t(11886),o=function(){function e(u,t){(0,n._)(this,e),(0,i._)(this,"jodit",void 0),(0,i._)(this,"toolRegistry",void 0),(0,i._)(this,"permanentPermissions",void 0),(0,i._)(this,"PERMANENT_PERMISSIONS_KEY",void 0),this.jodit=u,this.toolRegistry=t,this.permanentPermissions=new Map,this.PERMANENT_PERMISSIONS_KEY="jodit-permissions.ai-assistant-pro",this.loadPermanentPermissions()}return(0,r._)(e,[{key:"requiresPermission",value:function(e){var u=this.jodit.o.aiAssistantPro,t=u.autoApproveTools;if(u.alwaysDenyTools.includes(e))return!0;if(t.includes(e))return!1;var n=this.toolRegistry.getTool(e);return!n||n.requiresPermission}},{key:"isAutoDenied",value:function(e){return this.jodit.o.aiAssistantPro.alwaysDenyTools.includes(e)}},{key:"isAutoApproved",value:function(e){return this.jodit.o.aiAssistantPro.autoApproveTools.includes(e)}},{key:"checkPermission",value:function(e,u){if(this.isAutoApproved(e))return{toolName:e,granted:!0,grantedAt:Date.now(),scope:"once"};if(this.isAutoDenied(e))return null;var t=this.permanentPermissions.get(e);return t&&t.granted?t:u.find(function(u){return u.toolName===e&&u.granted})||null}},{key:"grantPermission",value:function(e,u){var t={toolName:e,granted:!0,grantedAt:Date.now(),scope:u};return"forever"===u&&(this.permanentPermissions.set(e,t),this.savePermanentPermissions()),t}},{key:"denyPermission",value:function(e){return{toolName:e,granted:!1,grantedAt:Date.now(),scope:"once"}}},{key:"filterToolCalls",value:function(e,u){var t=[],n=[],r=[],i=!0,o=!1,l=void 0;try{for(var c,F=e[Symbol.iterator]();!(i=(c=F.next()).done);i=!0){var h=c.value;if(this.isAutoDenied(h.name)){r.push((0,a._)((0,s._)({},h),{status:"denied"}));continue}if(this.isAutoApproved(h.name)){t.push((0,a._)((0,s._)({},h),{status:"approved"}));continue}var d=this.checkPermission(h.name,u);d&&d.granted?t.push((0,a._)((0,s._)({},h),{status:"approved"})):this.requiresPermission(h.name)?(this.jodit.e.fire("permissionRequested.ai-assistant-pro",h.name),n.push((0,a._)((0,s._)({},h),{status:"pending"}))):t.push((0,a._)((0,s._)({},h),{status:"approved"}))}}catch(e){o=!0,l=e}finally{try{i||null==F.return||F.return()}finally{if(o)throw l}}return{approved:t,needsPermission:n,denied:r}}},{key:"clearConversationPermissions",value:function(e){}},{key:"loadPermanentPermissions",value:function(){var e=this;try{var u=localStorage.getItem(this.PERMANENT_PERMISSIONS_KEY);u&&JSON.parse(u).forEach(function(u){"forever"===u.scope&&u.granted&&e.permanentPermissions.set(u.toolName,u)})}catch(e){}}},{key:"savePermanentPermissions",value:function(){try{var e=Array.from(this.permanentPermissions.values());localStorage.setItem(this.PERMANENT_PERMISSIONS_KEY,JSON.stringify(e))}catch(e){}}},{key:"clearPermanentPermissions",value:function(){this.permanentPermissions.clear(),localStorage.removeItem(this.PERMANENT_PERMISSIONS_KEY)}},{key:"getPermanentPermissions",value:function(){return Array.from(this.permanentPermissions.values())}},{key:"revokePermanentPermission",value:function(e){this.permanentPermissions.delete(e),this.savePermanentPermissions()}},{key:"destruct",value:function(){this.permanentPermissions.clear()}}]),e}()},21064:function(e,u,t){"use strict";t.d(u,{WebStorageConversationStorage:function(){return c},createStorageProvider:function(){return F},generateConversationId:function(){return h},generateMessageId:function(){return d}});var n=t(77688),r=t(20616),i=t(67709),s=t(82749),a=t(56075),o=t(62361),l=t(97333),c=function(){function e(u,t){(0,r._)(this,e),(0,s._)(this,"storage",void 0),(0,s._)(this,"maxConversations",void 0),this.storage=u,this.maxConversations=t}return(0,i._)(e,[{key:"close",value:function(){return this.storage.close()}},{key:"getConversationKey",value:function(e){return"conv:".concat(e)}},{key:"getAllKeys",value:function(){return(0,n._)(function(){var e;return(0,o._)(this,function(u){switch(u.label){case 0:return[4,this.storage.get("__conversation_index__")];case 1:if((e=u.sent())&&Array.isArray(e))return[2,e];return[2,[]]}})}).call(this)}},{key:"updateIndex",value:function(e){return(0,n._)(function(){return(0,o._)(this,function(u){switch(u.label){case 0:return[4,this.storage.set("__conversation_index__",e)];case 1:return u.sent(),[2]}})}).call(this)}},{key:"addToIndex",value:function(e){return(0,n._)(function(){var u;return(0,o._)(this,function(t){switch(t.label){case 0:return[4,this.getAllKeys()];case 1:if((u=t.sent()).includes(e))return[3,3];return u.push(e),[4,this.updateIndex(u)];case 2:t.sent(),t.label=3;case 3:return[2]}})}).call(this)}},{key:"removeFromIndex",value:function(e){return(0,n._)(function(){var u;return(0,o._)(this,function(t){switch(t.label){case 0:return[4,this.getAllKeys()];case 1:return u=t.sent().filter(function(u){return u!==e}),[4,this.updateIndex(u)];case 2:return t.sent(),[2]}})}).call(this)}},{key:"list",value:function(e){return(0,n._)(function(){var u,t,n,r,i,s,a,l,c,F,h,d,p,A,f;return(0,o._)(this,function(o){switch(o.label){case 0:return o.trys.push([0,10,,11]),[4,this.getAllKeys()];case 1:u=o.sent(),t=[],n=null==e?void 0:e.toLowerCase().trim(),r=!0,i=!1,s=void 0,o.label=2;case 2:o.trys.push([2,7,8,9]),a=u[Symbol.iterator](),o.label=3;case 3:if(r=(l=a.next()).done)return[3,6];return c=l.value,[4,this.get(c)];case 4:if(!(h=o.sent())||n&&(A=!(p=null==(d=h.title)?void 0:d.toLowerCase().includes(n))&&h.messages.some(function(e){return e.content.toLowerCase().includes(n)}),!p&&!A))return[3,5];t.push({id:h.id,title:null!=(F=h.title)?F:"",created:h.created,updated:h.updated,messageCount:h.messages.length}),o.label=5;case 5:return r=!0,[3,3];case 6:return[3,9];case 7:return f=o.sent(),i=!0,s=f,[3,9];case 8:try{r||null==a.return||a.return()}finally{if(i)throw s}return[7];case 9:return t.sort(function(e,u){return u.updated-e.updated}),[2,t];case 10:return o.sent(),[2,[]];case 11:return[2]}})}).call(this)}},{key:"get",value:function(e){return(0,n._)(function(){var u;return(0,o._)(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),u=this.getConversationKey(e),[4,this.storage.get(u)];case 1:return[2,t.sent()||null];case 2:return t.sent(),[2,null];case 3:return[2]}})}).call(this)}},{key:"save",value:function(e){return(0,n._)(function(){var u,t,n,r;return(0,o._)(this,function(i){switch(i.label){case 0:if(i.trys.push([0,6,,15]),0===e.messages.length)throw Error("Conversation must have at least one message.");return[4,this.getAllKeys()];case 1:if(!((u=i.sent()).length>=this.maxConversations&&!u.includes(e.id)))return[3,3];return[4,this.evictOldest()];case 2:i.sent(),i.label=3;case 3:return t=this.getConversationKey(e.id),[4,this.storage.set(t,e)];case 4:return i.sent(),[4,this.addToIndex(e.id)];case 5:return i.sent(),[3,15];case 6:if((null==(n=i.sent())?void 0:n.name)!=="QuotaExceededError"&&(null==n?void 0:n.code)!==22&&(null==n?void 0:n.code)!==1014)return[3,13];return[4,this.evictOldest()];case 7:i.sent(),i.label=8;case 8:return i.trys.push([8,11,,12]),r=this.getConversationKey(e.id),[4,this.storage.set(r,e)];case 9:return i.sent(),[4,this.addToIndex(e.id)];case 10:return i.sent(),[3,12];case 11:throw i.sent(),Error("Storage quota exceeded. Please delete some conversations.");case 12:return[3,14];case 13:throw Error("Failed to save conversation: ".concat((null==n?void 0:n.message)||"Unknown error"));case 14:return[3,15];case 15:return[2]}})}).call(this)}},{key:"delete",value:function(e){return(0,n._)(function(){var u;return(0,o._)(this,function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),u=this.getConversationKey(e),[4,this.storage.delete(u)];case 1:return t.sent(),[4,this.removeFromIndex(e)];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}})}).call(this)}},{key:"clear",value:function(){return(0,n._)(function(){var e,u,t,n,r,i,s,a,l;return(0,o._)(this,function(o){switch(o.label){case 0:return o.trys.push([0,11,,12]),[4,this.getAllKeys()];case 1:e=o.sent(),u=!0,t=!1,n=void 0,o.label=2;case 2:o.trys.push([2,7,8,9]),r=e[Symbol.iterator](),o.label=3;case 3:if(u=(i=r.next()).done)return[3,6];return s=i.value,a=this.getConversationKey(s),[4,this.storage.delete(a)];case 4:o.sent(),o.label=5;case 5:return u=!0,[3,3];case 6:return[3,9];case 7:return l=o.sent(),t=!0,n=l,[3,9];case 8:try{u||null==r.return||r.return()}finally{if(t)throw n}return[7];case 9:return[4,this.updateIndex([])];case 10:case 11:return o.sent(),[3,12];case 12:return[2]}})}).call(this)}},{key:"evictOldest",value:function(){return(0,n._)(function(){var e,u;return(0,o._)(this,function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),[4,this.list()];case 1:if(0===(e=t.sent()).length)return[2];return e.sort(function(e,u){return e.updated-u.updated}),u=e[0],[4,this.delete(u.id)];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}})}).call(this)}},{key:"getGlobalSettings",value:function(){return(0,n._)(function(){return(0,o._)(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.storage.get("global-settings")];case 1:return[2,e.sent()||null];case 2:return e.sent(),[2,null];case 3:return[2]}})}).call(this)}},{key:"saveGlobalSettings",value:function(e){return(0,n._)(function(){var u,t;return(0,o._)(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,this.getGlobalSettings()];case 1:return u=n.sent(),t=(0,a._)({},u,e),[4,this.storage.set("global-settings",t)];case 2:return n.sent(),[3,4];case 3:throw n.sent(),Error("Failed to save global settings");case 4:return[2]}})}).call(this)}}]),e}();function F(e,u){return l.AsyncStorage.makeStorage(e,u)}function h(){return"conv_".concat(Date.now(),"_").concat(Math.random().toString(36).substring(2,11))}function d(){return"msg_".concat(Date.now(),"_").concat(Math.random().toString(36).substring(2,11))}},26612:function(e){e.exports={"AI Assistant":"AI Assistant","AI Assistant Pro":"AI Assistant Pro","Welcome to AI Assistant":"Welcome to AI Assistant","Start your first conversation":"Start your first conversation","Tip: Select text in editor to add context":"Tip: Select text in editor to add context","New Chat":"New Chat","Search conversations...":"Search conversations...","No conversations yet":"No conversations yet","Ask me anything...":"Ask me anything...","Ask a follow-up...":"Ask a follow-up...","Reply...":"Reply...","Type your message...":"Type your message...",Send:"Send",Cancel:"Cancel",Retry:"Retry",Insert:"Insert",Copy:"Copy",Edit:"Edit",Delete:"Delete",New:"New",Back:"Back","Permission Required":"Permission Required",Approve:"Approve",Deny:"Deny",Once:"Once","This conversation":"This conversation",Always:"Always","The AI wants to execute:":"The AI wants to execute:","This will modify your document content.":"This will modify your document content.","Executing...":"Executing...","Completed successfully":"Completed successfully",Failed:"Failed","Pending approval":"Pending approval","Denied by user":"Denied by user","Tool Result":"Tool Result","Tool Execution Error":"Tool Execution Error",Context:"Context",Contexts:"Contexts","Add to AI Context":"Add to AI Context",Remove:"Remove","Clear all":"Clear all","An error occurred":"An error occurred","Request failed":"Request failed","Connection error":"Connection error","AI Assistant is not configured":"AI Assistant is not configured","Thinking...":"Thinking...","Generating response...":"Generating response...",insertHTML:"Insert HTML",readDocument:"Read Document",readBlock:"Read Block",replaceInDocument:"Replace in Document",replaceInBlock:"Replace in Block",getSelection:"Get Selection","Just now":"Just now",Conversation:"Conversation","New Conversation":"New Conversation",Yesterday:"Yesterday","Delete conversation":"Delete conversation","Are you sure you want to delete this conversation?":"Are you sure you want to delete this conversation?","Failed to delete conversation":"Failed to delete conversation"}},27769:function(e,u,t){"use strict";t.d(u,{UIMainPanel:function(){return n.UIMainPanel}});var n=t(51251)},28157:function(e,u,t){"use strict";t.d(u,{execute:function(){return a}});var n=t(77688),r=t(62361),i=t(6689),s=t(22732);function a(e,u,t){return(0,n._)(function(){var n,a,o,l,c,F,h,d,p;return(0,r._)(this,function(r){if(n=u.start,a=u.end,o=u.aroundSelection,(0,i.throwIfAborted)(t),c=(l=e.value).length,F="number"==typeof n?n:0,o&&!e.s.isCollapsed()){for(h=e.s.range.commonAncestorContainer;h&&h!==e.editor;){if(s.Dom.isElement(h)&&h.parentNode===e.editor){l=h.outerHTML;break}h=h.parentNode}return[2,{html:l,length:c}]}return d=void 0!==a?Math.min(a,c):c,((p=Math.max(0,Math.min(F,c)))>0||c>d)&&(l=l.substring(p,d)),[2,{html:l,length:c,start:p,end:d}]})})()}},36142:function(e,u,t){"use strict";t.d(u,{execute:function(){return a}});var n=t(77688),r=t(62361),i=t(6689),s=t(49459);function a(e,u,t){return(0,n._)(function(){var n,a,o;return(0,r._)(this,function(r){n=(0,s.requireString)(u,"html"),a=u.collapseToEnd,(0,i.throwIfAborted)(t);try{return e.s.restore(),e.s.insertHTML(n),a&&((o=e.s.range).collapse(!1),e.s.selectRange(o)),e.e.fire("change"),[2,{success:!0,message:"Selection replaced successfully"}]}catch(e){throw Error("Failed to replace selection: ".concat(e.message))}})})()}},39296:function(e,u,t){"use strict";var n=t(56075),r=t(11886),i=t(73943),s=t(19127);u.default=(0,r._)((0,n._)({},i),{execute:s.execute})},39592:function(e,u,t){"use strict";t.d(u,{execute:function(){return a}});var n=t(77688),r=t(62361),i=t(6689),s=t(49459);function a(e,u,t){return(0,n._)(function(){var n,a;return(0,r._)(this,function(r){if(n=(0,s.requireString)(u,"html",{allowEmpty:!0}),a=u.replace,!n.trim())return[2,{success:!0,message:"Nothing to insert: HTML is empty"}];(0,i.throwIfAborted)(t);try{return e.s.focus(),a&&!e.s.isCollapsed()&&e.s.remove(),e.s.insertHTML(n),e.synchronizeValues(),[2,{success:!0,message:"Inserted ".concat(n.length," characters of HTML")}]}catch(e){throw Error("Failed to insert HTML: ".concat((null==e?void 0:e.message)||"Unknown error"))}})})()}},41810:function(e,u,t){"use strict";t.r(u),t.d(u,{aiAssistantPro:function(){return T}});var n=t(77688),r=t(80294),i=t(20616),s=t(67709),a=t(82749),o=t(18766),l=t(2868),c=t(56075),F=t(11886),h=t(43284),d=t(94899),p=t(23078),A=t(31635),f=t(62361);t(66645);var C=t(86449),E=t(21020),D=t(46166),v=t(62895),g=t(55487),m=t(27769),B=t(80960),y=t(63805),k=t(82758),_=t(65478),b=t(580),x=t(21537),w=t(50911),S=t(2692),I=t(18549),M=t(54747),T=function(e){function u(){var e;return(0,i._)(this,u),e=(0,r._)(this,u,arguments),(0,a._)(e,"buttons",[{name:"aiAssistantPro",group:"insert"},{name:"aiCommandsPro",group:"insert"}]),(0,a._)(e,"__initedPromise",null),(0,a._)(e,"__openedMode",null),e}return(0,o._)(u,e),(0,s._)(u,[{key:"state",get:function(){return this.stateManager.state}},{key:"toolRegistry",get:function(){return new g.ToolRegistry(this.j)}},{key:"permissionManager",get:function(){return new E.PermissionManager(this.j,this.toolRegistry)}},{key:"apiClient",get:function(){return new C.APIClient(this.j,this.toolRegistry)}},{key:"storage",get:function(){var e=this.j.o.aiAssistantPro,u=e.storage,t=e.storageKey,n=e.maxConversations;if("string"==typeof u){var r=(0,v.createStorageProvider)(u,t);return new v.WebStorageConversationStorage(r,n)}return u}},{key:"stateManager",get:function(){return new D.StateManager(this.j)}},{key:"mainPanel",get:function(){var e=this;return new m.UIMainPanel(this.j,this.stateManager.state,this.j.o.aiAssistantPro,function(u){var t=e.stateManager.getCurrentConversation();t&&e.stateManager.setCurrentConversation((0,c._)({},t,u))})}},{key:"dialog",get:function(){var e=this,u=this.j.dlg({resizable:this.j.o.aiAssistantPro.resizable,eventEmmiter:this.j.e});return u.e.on(u,"afterClose",function(){e.j.e.fire("closeAIAssistantPro.ai-assistant-pro")}),u}},{key:"afterInit",value:function(){var e=this;(0,b.extendLang)(y),this.setupEventListeners(),this.j.async.promise(function(u){var t=e.j.o.aiAssistantPro,n=t.initiallyOpened,r=t.persistOpenState,i=n;r?e.storage.getGlobalSettings().then(function(u){if((null==u?void 0:u.isOpen)!=null&&(i=u.isOpen),i)return e.openAssistant()}).catch(function(){return null}).finally(function(){return u(void 0)}):u(void 0)}).catch(function(){return null})}},{key:"__loadData",value:function(){var e=this;return this.__initedPromise?this.__initedPromise:this.isDestructed?Promise.reject():(this.__initedPromise=this.j.async.promise(function(u){e.loadInitialData().then(u)}).catch(function(){return null}),this.__initedPromise)}},{key:"loadInitialData",value:function(){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:return this.mainPanel.setMod("ready",!0),[4,(0,B.loadInitialData)(this.j,this.storage,this.stateManager)];case 1:return e.sent(),[2]}})}).call(this)}},{key:"setupEventListeners",value:function(){var e=this;this.j.e.on("selectConversation.ai-assistant-pro",function(u){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,this.__loadData()];case 1:return e.sent(),[4,(0,B.handleConversationSelect)(u,this.storage,this.stateManager)];case 2:return e.sent(),[3,4];case 3:return e.sent(),k.IS_PROD,[3,4];case 4:return[2]}})}).call(e)}),this.j.e.on("newConversation.ai-assistant-pro",function(){return(0,n._)(function(){var e;return(0,f._)(this,function(u){switch(u.label){case 0:return[4,this.__loadData()];case 1:return u.sent(),e=(0,B.createNewConversation)(this.j,this.state.defaultModel,this.state.defaultTemperature),this.stateManager.setCurrentConversation(e),[2]}})}).call(e)}),this.j.e.on("deleteConversation.ai-assistant-pro",function(u){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:return[4,this.__loadData()];case 1:return e.sent(),[4,this.deleteConversation(u)];case 2:return e.sent(),[2]}})}).call(e)}),this.j.e.on("backToList.ai-assistant-pro",function(){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:return[4,this.__loadData()];case 1:return e.sent(),[4,(0,B.handleBackToList)(this.storage,this.stateManager)];case 2:return e.sent(),[2]}})}).call(e)}),this.j.e.on("removeContext.ai-assistant-pro",function(u){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:return[4,this.__loadData()];case 1:return e.sent(),this.stateManager.removeSelectionContext(u),[2]}})}).call(e)}),this.j.e.on("approveToolCall.ai-assistant-pro",function(u,t){return(0,n._)(function(){var e,n,r,i;return(0,f._)(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),[4,this.__loadData()];case 1:return s.sent(),[4,(0,B.handleToolApproval)(u,t,this.stateManager,this.permissionManager,this.storage)];case 2:if(!(e=s.sent()))return[3,4];if(!(n=this.stateManager.getCurrentConversation())||!(r=n.messages.find(function(u){var t;return null==(t=u.toolCalls)?void 0:t.some(function(u){return u.id===e.id})})))return[2];return[4,this.executeToolCall(r.id,e)];case 3:s.sent(),s.label=4;case 4:return[3,6];case 5:if(i=s.sent(),(0,x.isAbortError)(i))return[2];return this.stateManager.setError((0,l._)(i,Error)?i.message:String(i)),[3,6];case 6:return[2]}})}).call(e)}),this.j.e.on("denyToolCall.ai-assistant-pro",function(u){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:return[4,this.__loadData()];case 1:return e.sent(),[4,(0,B.handleToolDenial)(this.j,u,this.stateManager,this.storage)];case 2:return e.sent(),[2]}})}).call(e)}),this.j.e.on("abortRequest.ai-assistant-pro",function(){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:return[4,this.__loadData()];case 1:return e.sent(),this.apiClient.abort(),this.stateManager.setLoading(!1),[2]}})}).call(e)})}},{key:"__applyTheme",value:function(){(0,B.applyTheme)(this.j,this.stateManager.state.theme,this.stateManager.state.displayMode,this.mainPanel.container,this.dialog)}},{key:"openAssistant",value:function(){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:if(!this.stateManager.isOpen())return[3,2];return this.stateManager.close(),[4,this.__closeInContainer()];case 1:return e.sent(),[2];case 2:return[4,this.__loadData()];case 3:if(e.sent(),this.isDestructed)return[2];return this.stateManager.open(),[4,this.__openInContainer()];case 4:return e.sent(),this.j.o.aiAssistantPro.includeSelectionByDefault&&!this.j.s.isCollapsed()&&this.addCurrentSelectionToContext(),[2]}})}).call(this)}},{key:"__openInContainer",value:function(){return(0,n._)(function(){var e,u,t,n,r,i,s,a,o,l;return(0,f._)(this,function(c){switch(e=this,t=(u=this.j.o.aiAssistantPro).resizable,n=u.allowClose,r=u.flightPanelHeight,a=void 0===(s=(i=this.stateManager.state).displayMode)?"right":s,o=i.panelWidth,l=i.panelHeight,this.__applyTheme(),this.mainPanel.setMod("displayMode",a),this.mainPanel.setMod("allowClose",n),this.mainPanel.setParentView("dialog"===a||"flight"===a?this.dialog:this.j),this.__openedMode=a,a){case"dialog":this.dialog.setSize(o,l).open().setContent(this.mainPanel.container);break;case"flight":I.UIFlightPosition.install(this.mainPanel,this.j.container,{panelHeight:r,containerClassName:this.getFullElName("flight-container")});break;default:t&&(M.UIResize.remove(this.mainPanel),M.UIResize.install(this.mainPanel,(0,B.invertMode)(a),{handleClassName:this.getFullElName("ai-assistent-resize-handle"),onResize:function(u){var t=u.newSize,n="left"===a||"right"===a?t:o,r="top"===a||"bottom"===a?t:l;return e.stateManager.state.panelWidth=n,e.stateManager.state.panelHeight=r,!0}})),this.j.currentPlace.slots[a].appendChild(this.mainPanel.container),(0,B.resizeInPanelView)(this.j,a,o,l)}return[2]})}).call(this)}},{key:"__onResizeInPanelView",value:function(){var e=this.stateManager.state,u=e.displayMode,t=e.panelWidth,n=e.panelHeight;(0,B.resizeInPanelView)(this.j,u,t,n)}},{key:"__closeInContainer",value:function(){return(0,n._)(function(){var e;return(0,f._)(this,function(u){switch(u.label){case 0:return[4,this.stateManager.state];case 1:switch(e=u.sent().displayMode,this.__openedMode!==e&&"dialog"===this.__openedMode&&this.dialog.close(),this.__openedMode!==e&&"flight"===this.__openedMode&&this.__closeFlightMode(),e){case"dialog":this.dialog.close();break;case"flight":this.__closeFlightMode();break;default:this.mainPanel.container.remove()}return[2]}})}).call(this)}},{key:"__closeFlightMode",value:function(){I.UIFlightPosition.remove(this.mainPanel)}},{key:"__onSavedStateChange",value:function(){var e,u=this.stateManager.state;return this.storage.saveGlobalSettings((0,c._)({displayMode:u.displayMode,panelWidth:u.panelWidth,panelHeight:u.panelHeight,theme:u.theme,defaultModel:u.defaultModel,defaultTemperature:u.defaultTemperature,currentConversationId:null==(e=u.currentConversation)?void 0:e.id},this.j.o.aiAssistantPro.persistOpenState?{isOpen:u.isOpen}:{}))}},{key:"closeAssistant",value:function(){return(0,n._)(function(){return(0,f._)(this,function(e){switch(e.label){case 0:if(!this.stateManager.isOpen())return[2];return[4,this.__loadData()];case 1:return e.sent(),this.stateManager.close(),this.__closeInContainer(),[2]}})}).call(this)}},{key:"addCurrentSelectionToContext",value:function(){return(0,n._)(function(){var e;return(0,f._)(this,function(u){switch(u.label){case 0:return[4,this.__loadData()];case 1:return u.sent(),(e=(0,B.getCurrentSelectionContext)(this.j))&&this.stateManager.addSelectionContext(e),[2]}})}).call(this)}},{key:"executeQuickCommand",value:function(e){return(0,n._)(function(){var u,t,n,r,i,s,a,o,l;return(0,f._)(this,function(c){switch(c.label){case 0:if(t=(u=this.j.o.aiAssistantPro).quickCommandsSilentMode,n=u.quickCommandsDisplayMode,(r=this.j.o.aiAssistant)&&r[e]&&(0,x.isString)(r[e])&&(i=r[e]),!i)return this.j.e.fire("error","Command not found: ".concat(e)),[2];if(!(s=this.j.s.isCollapsed()?this.j.value:this.j.s.html))return[2];if(a=(null==r?void 0:r.aiCommonPrefixPrompt)||"",o=(null==r?void 0:r.aiCommonSuffixPrompt)||"",l="".concat(a).concat(i).concat(o,"\n\n").concat(s).trim(),!t)return[3,2];return[4,this.__executeQuickCommandSilent(l,s)];case 1:return c.sent(),[3,4];case 2:return[4,this.__executeQuickCommandWithPanel(l,n)];case 3:c.sent(),c.label=4;case 4:return[2]}})}).call(this)}},{key:"__executeQuickCommandSilent",value:function(e,u){return(0,n._)(function(){var u,t,n,r,i;return(0,f._)(this,function(s){switch(s.label){case 0:return[4,this.__loadData()];case 1:s.sent(),this.j.progressbar.show().progress(100),s.label=2;case 2:return s.trys.push([2,4,5,6]),u=(0,B.createUserMessage)(e),t=(0,B.createNewConversation)(this.j,this.state.defaultModel,this.state.defaultTemperature,[u]),[4,this.apiClient.sendRequest(t.id,t.messages,null,[],t.options)];case 3:return"final"===(n=s.sent()).mode&&(r=n.response.content)&&this.j.s.insertHTML(r),[3,6];case 4:return i=s.sent(),(0,x.isAbortError)(i)||this.j.e.fire("error",i),[3,6];case 5:return this.j.progressbar.hide(),[7];case 6:return[2]}})}).call(this)}},{key:"__executeQuickCommandWithPanel",value:function(e,u){return(0,n._)(function(){var t,n;return(0,f._)(this,function(r){switch(r.label){case 0:return[4,this.__loadData()];case 1:if(r.sent(),t=this.stateManager.state.displayMode,this.stateManager.state.displayMode=u,(n=(0,B.getCurrentSelectionContext)(this.j))&&this.stateManager.addSelectionContext(n),this.stateManager.isOpen())return[3,3];return[4,this.openAssistant()];case 2:r.sent(),r.label=3;case 3:return[4,this.sendMessage(e)];case 4:return r.sent(),this.stateManager.state.displayMode=t,[2]}})}).call(this)}},{key:"sendMessage",value:function(e){return(0,n._)(function(){var u,t,n,r,i,s,a;return(0,f._)(this,function(o){switch(o.label){case 0:return[4,this.__loadData()];case 1:if(o.sent(),u=this.stateManager.getCurrentConversation(),!((t=this.stateManager.getEditingMessageId())&&u)||-1===(n=u.messages.findIndex(function(e){return e.id===t})))return[3,3];return r=u.messages.slice(0,n),i=(0,F._)((0,c._)({},u),{messages:r,updatedAt:Date.now()}),this.stateManager.setCurrentConversation(i),[4,this.storage.save(i)];case 2:o.sent(),this.stateManager.clearEditingMessage(),u=i,o.label=3;case 3:u||(u=(0,B.createNewConversation)(this.j,this.state.defaultModel,this.state.defaultTemperature),this.stateManager.setCurrentConversation(u)),s=null,e.trim()&&(s=(0,B.createUserMessage)(e),u.title||(u=(0,F._)((0,c._)({},u),{title:e})),u=(0,F._)((0,c._)({},u),{updated:Date.now(),messages:(0,d._)(u.messages).concat([s])})),this.stateManager.setCurrentConversation((0,c._)({},u)),s&&this.j.e.fire("messageSent.ai-assistant-pro",s),this.stateManager.setLoading(!0),this.stateManager.clearError(),o.label=4;case 4:return o.trys.push([4,6,7,8]),[4,this.sendRequestToAI(0)];case 5:return o.sent(),this.stateManager.clearSelectionContexts(),[3,8];case 6:if(a=o.sent(),(0,x.isAbortError)(a))return[2];return this.stateManager.setError((0,l._)(a,Error)?a.message:String(a)),[3,8];case 7:return this.stateManager.setLoading(!1),[7];case 8:return[2]}})}).call(this)}},{key:"sendRequestToAI",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return(0,n._)(function(){var u,t,n,r,i,s,a,o;return(0,f._)(this,function(l){switch(l.label){case 0:if(e>=(u=this.j.o.aiAssistantPro.maxRecursionToolCallDepth))throw Error("Max recursion depth ".concat(u," reached for tool calls"));if(!(t=this.stateManager.getCurrentConversation()))return[2];return n=(0,B.findParentMessageId)(t),[4,Promise.all([this.apiClient.sendRequest(t.id,t.messages,n,this.stateManager.getSelectionContexts(),t.options),this.storage.save(t)])];case 1:if("stream"!==(r=h._.apply(void 0,[l.sent(),1])[0]).mode)return[3,3];return[4,(0,B.processStreamingResponse)(this.stateManager,r,t)];case 2:return i=(a=l.sent()).aiMessage,s=a.index,t=a.conversation,[3,4];case 3:i=(o=(0,B.processFinalResponse)(r,t)).aiMessage,s=o.index,t=o.conversation,l.label=4;case 4:return[4,(0,B.processArtifacts)(this.j,i,t,s)];case 5:return t=l.sent(),this.j.e.fire("messageReceived.ai-assistant-pro",i),this.stateManager.setCurrentConversation((0,c._)({},t)),[4,this.storage.save(t)];case 6:return l.sent(),[4,this.handleToolCalls(i.id,e)];case 7:return l.sent(),[2]}})}).call(this)}},{key:"deleteConversation",value:function(e){return(0,n._)(function(){return(0,f._)(this,function(u){switch(u.label){case 0:return[4,this.__loadData()];case 1:return u.sent(),[4,(0,B.deleteConversationWithCleanup)(this.j,e,this.storage,this.stateManager,this.permissionManager)];case 2:return u.sent(),[2]}})}).call(this)}},{key:"searchConversations",value:function(e){return(0,n._)(function(){return(0,f._)(this,function(u){switch(u.label){case 0:return[4,this.__loadData()];case 1:return u.sent(),[4,(0,B.handleConversationSearch)(e,this.storage,this.stateManager)];case 2:return u.sent(),[2]}})}).call(this)}},{key:"handleToolCalls",value:function(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(0,n._)(function(){var t,n,r,i,s,a,o,l,c,F,h,d,p;return(0,f._)(this,function(A){switch(A.label){case 0:if(!(t=this.stateManager.getCurrentConversation())||!(n=t.messages.find(function(u){return u.id===e}))||!(r=n.toolCalls)||0===r.length)return[2];return[4,this.__loadData()];case 1:A.sent(),s=(i=this.permissionManager.filterToolCalls(r,t.permissions)).approved,a=i.needsPermission,this.stateManager.setPendingToolCalls(a),o=!0,l=!1,c=void 0,A.label=2;case 2:A.trys.push([2,7,8,9]),F=s[Symbol.iterator](),A.label=3;case 3:if(o=(h=F.next()).done)return[3,6];return d=h.value,[4,this.executeToolCall(e,d,u)];case 4:A.sent(),A.label=5;case 5:return o=!0,[3,3];case 6:return[3,9];case 7:return p=A.sent(),l=!0,c=p,[3,9];case 8:try{o||null==F.return||F.return()}finally{if(l)throw c}return[7];case 9:return[2]}})}).call(this)}},{key:"executeToolCall",value:function(e,u){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return(0,n._)(function(){var n,r,i,s,a;return(0,f._)(this,function(o){switch(o.label){case 0:return[4,this.__loadData()];case 1:if(o.sent(),!(n=this.stateManager.getCurrentConversation()))return[2];return[4,(0,B.executeToolCall)(this.j,u,this.toolRegistry)];case 2:if(r=o.sent(),-1===(i=n.messages.findIndex(function(u){return u.id===e})))return[2];if(s=n.messages[i],(a=n.messages.slice())[i]=(0,B.updateToolCallInMessage)(s,r),n=(0,F._)((0,c._)({},n),{messages:a,updated:Date.now()}),this.stateManager.setCurrentConversation(n),!(0,B.areAllToolCallsExecuted)(n))return[3,4];return[4,this.sendRequestToAI(t+1)];case 3:o.sent(),o.label=4;case 4:return[2]}})}).call(this)}},{key:"copyMessage",value:function(e){return(0,n._)(function(){var u,t;return(0,f._)(this,function(n){switch(n.label){case 0:if(!(u=this.stateManager.getCurrentConversation())||!(t=u.messages.find(function(u){return u.id===e})))return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,navigator.clipboard.writeText(t.content)];case 2:return n.sent(),this.j.message.success("Message copied to clipboard"),[3,4];case 3:return n.sent(),this.j.e.fire("error",Error("Failed to copy message")),[3,4];case 4:return[2]}})}).call(this)}},{key:"restartFromMessage",value:function(e){return(0,n._)(function(){var u,t,n,r,i;return(0,f._)(this,function(s){switch(s.label){case 0:if(!(u=this.stateManager.getCurrentConversation())||-1===(t=u.messages.findIndex(function(u){return u.id===e}))||"user"!==(n=u.messages[t]).role)return[2];return[4,this.__loadData()];case 1:return s.sent(),r=u.messages.slice(0,t),i=(0,F._)((0,c._)({},u),{messages:r,updatedAt:Date.now()}),this.stateManager.setCurrentConversation(i),[4,this.storage.save(i)];case 2:return s.sent(),[4,this.sendMessage(n.content)];case 3:return s.sent(),[2]}})}).call(this)}},{key:"editMessage",value:function(e){return(0,n._)(function(){var u,t;return(0,f._)(this,function(n){return(u=this.stateManager.getCurrentConversation())&&(t=u.messages.find(function(u){return u.id===e}))&&"user"===t.role&&(this.stateManager.setEditingMessageId(e),this.mainPanel.inputArea.setValue(t.content),this.mainPanel.inputArea.focus()),[2]})}).call(this)}},{key:"cancelEditMessage",value:function(){this.stateManager.isEditingMessage()&&(this.stateManager.clearEditingMessage(),this.mainPanel.inputArea.setValue(""))}},{key:"deleteMessage",value:function(e){return(0,n._)(function(){var u,t,n;return(0,f._)(this,function(r){switch(r.label){case 0:return[4,this.__loadData()];case 1:if(r.sent(),!(u=this.stateManager.getCurrentConversation())||-1===u.messages.findIndex(function(u){return u.id===e}))return[2];return t=u.messages.filter(function(u){return u.id!==e}),n=(0,F._)((0,c._)({},u),{messages:t,updatedAt:Date.now()}),this.stateManager.setCurrentConversation(n),[4,this.storage.save(n)];case 2:return r.sent(),[2]}})}).call(this)}},{key:"beforeDestruct",value:function(){var e,u,t,n,r,i,s,a;this.__closeFlightMode(),null==(e=(0,_.cached)(this,"toolRegistry"))||e.destruct(),null==(u=(0,_.cached)(this,"permissionManager"))||u.destruct(),null==(t=(0,_.cached)(this,"apiClient"))||t.destruct(),null==(n=(0,_.cached)(this,"stateManager"))||n.destruct(),null==(r=(0,_.cached)(this,"mainPanel"))||r.destruct(),null==(i=(0,_.cached)(this,"dialog"))||i.destruct(),null==(a=(0,_.cached)(this,"storage"))||null==(s=a.close)||s.call(a)}}]),u}((0,p._)(w.Plugin));(0,a._)(T,"requires",["license"]),(0,A.__decorate)([_.cache],T.prototype,"toolRegistry",null),(0,A.__decorate)([_.cache],T.prototype,"permissionManager",null),(0,A.__decorate)([_.cache],T.prototype,"apiClient",null),(0,A.__decorate)([_.cache],T.prototype,"storage",null),(0,A.__decorate)([_.cache],T.prototype,"stateManager",null),(0,A.__decorate)([_.cache],T.prototype,"mainPanel",null),(0,A.__decorate)([_.cache],T.prototype,"dialog",null),(0,A.__decorate)([(0,_.watch)("state.theme")],T.prototype,"__applyTheme",null),(0,A.__decorate)([(0,_.watch)(":openAIAssistantPro.ai-assistant-pro")],T.prototype,"openAssistant",null),(0,A.__decorate)([(0,_.watch)([":resize","state.panelWidth","state.panelHeight"])],T.prototype,"__onResizeInPanelView",null),(0,A.__decorate)([(0,_.watch)(["state.isOpen","state.displayMode","state.panelWidth","state.panelHeight","state.theme","state.defaultModel","state.defaultTemperature","state.currentConversation"]),(0,_.debounce)()],T.prototype,"__onSavedStateChange",null),(0,A.__decorate)([(0,_.watch)(":closeAIAssistantPro.ai-assistant-pro")],T.prototype,"closeAssistant",null),(0,A.__decorate)([(0,_.watch)(":addContextToAIAssistant.ai-assistant-pro")],T.prototype,"addCurrentSelectionToContext",null),(0,A.__decorate)([(0,_.watch)(":executeQuickCommand.ai-assistant-pro")],T.prototype,"executeQuickCommand",null),(0,A.__decorate)([(0,_.watch)(":sendMessage.ai-assistant-pro")],T.prototype,"sendMessage",null),(0,A.__decorate)([(0,_.watch)(":searchConversations.ai-assistant-pro")],T.prototype,"searchConversations",null),(0,A.__decorate)([(0,_.watch)(":copyMessage.ai-assistant-pro")],T.prototype,"copyMessage",null),(0,A.__decorate)([(0,_.watch)(":restartFromMessage.ai-assistant-pro")],T.prototype,"restartFromMessage",null),(0,A.__decorate)([(0,_.watch)(":editMessage.ai-assistant-pro")],T.prototype,"editMessage",null),(0,A.__decorate)([(0,_.watch)(":cancelEditMessage.ai-assistant-pro")],T.prototype,"cancelEditMessage",null),(0,A.__decorate)([(0,_.watch)(":deleteMessage.ai-assistant-pro")],T.prototype,"deleteMessage",null),T=(0,A.__decorate)([_.component],T),S.JoditPro.plugins.add("aiAssistantPro",T)},44526:function(e,u,t){"use strict";t.d(u,{resolveBlock:function(){return r}});var n=t(22732);function r(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=u.selector,r=u.index,i=u.requireExactlyOne,s=null!=t,a=null!=r;if(void 0!==i&&i&&s===a)throw Error("Either index or selector must be provided, but not both");if(!s&&!a)throw Error("Block identifier is required");if(s){if("string"!=typeof t)throw Error("Selector must be a string");var o=e.editor.querySelector(t);if(!o)throw Error('No element found matching selector "'.concat(t,'"'));if(!n.Dom.isElement(o))throw Error('Selector "'.concat(t,'" does not point to an element node'));return{element:o,identifier:'with selector "'.concat(t,'"')}}if("number"!=typeof r)throw Error("Block index must be a number");var l=Array.from(e.editor.children);if(r<0||r>=l.length)throw Error("Block index ".concat(r," is out of range. Document has ").concat(l.length," blocks"));var c=l[r];if(!n.Dom.isElement(c))throw Error("Block at index ".concat(r," is not a valid element"));return{element:c,identifier:"at index ".concat(r)}}},46166:function(e,u,t){"use strict";t.d(u,{StateManager:function(){return l}});var n=t(20616),r=t(67709),i=t(82749),s=t(56075),a=t(11886),o=t(94899),l=function(){function e(u){(0,n._)(this,e),(0,i._)(this,"jodit",void 0),(0,i._)(this,"state",void 0),this.jodit=u,this.state=this.createInitialState()}return(0,r._)(e,[{key:"createInitialState",value:function(){return{isOpen:!1,currentView:"welcome",currentConversation:null,conversations:[],isLoading:!1,error:null,pendingToolCalls:[],selectionContexts:[],abortController:null,editingMessageId:null,theme:this.jodit.o.aiAssistantPro.theme||"parent",displayMode:this.jodit.o.aiAssistantPro.displayMode,panelWidth:this.jodit.o.aiAssistantPro.panelWidth,panelHeight:this.jodit.o.aiAssistantPro.panelHeight,defaultModel:this.jodit.o.aiAssistantPro.defaultModel,defaultTemperature:this.jodit.o.aiAssistantPro.defaultTemperature}}},{key:"open",value:function(){this.state.isOpen=!0,this.jodit.e.fire("open.ai-assistant-pro",this.state.currentConversation)}},{key:"close",value:function(){this.state.isOpen=!1,this.jodit.e.fire("close.ai-assistant-pro")}},{key:"isOpen",value:function(){return this.state.isOpen}},{key:"setView",value:function(e){this.state.currentView=e,this.jodit.e.fire("viewChanged.ai-assistant-pro",e)}},{key:"getView",value:function(){return this.state.currentView}},{key:"setConversations",value:function(e){this.state.