jodit-pro
Version:
PRO Version of Jodit Editor
21 lines (20 loc) • 150 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,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var i in s)("object"==typeof exports?exports:e)[i]=s[i]}}(self,function(){return(self.webpackChunkjodit_pro=self.webpackChunkjodit_pro||[]).push([[830],{473:function(e,t,s){"use strict";s.d(t,{handleBackToList:function(){return l},handleConversationSearch:function(){return c},handleConversationSelect:function(){return o},handleToolApproval:function(){return a},handleToolDenial:function(){return r}});var i=s(79078),n=s(82758);async function a(e,t,s,i,n){let a=s.getPendingToolCalls().find(t=>t.id===e);if(!a)return null;let r=i.grantPermission(a.name,t),o=s.getCurrentConversation();return o&&(o.permissions.push(r),await n.save(o)),s.removePendingToolCall(e),{...a,status:"approved"}}async function r(e,t,s,n){let a=s.getPendingToolCalls().find(e=>e.id===t);if(!a)return;let r=s.getCurrentConversation();if(!r)return;let o=r.messages.findIndex(e=>e.toolCalls?.find(e=>e.id===t));if(-1===o)return;let l=r.messages[o],c={...a,result:{error:"Tool call denied by user."},status:"denied"},h=(0,i.updateToolCallInMessage)(l,c),d=[...r.messages];d[o]=h,r={...r,messages:d,updated:Date.now()},s.setCurrentConversation(r),await n.save(r),e.e.fire("toolCallDenied.ai-assistant-pro",a),s.removePendingToolCall(t)}async function o(e,t,s){try{s.setLoading(!0);let i=await t.get(e);if(!i)throw Error("Conversation not found: "+e);s.setCurrentConversation({...i})}catch(e){n.IS_PROD}finally{s.setLoading(!1)}}async function l(e,t){t.setView("conversationList");try{t.setLoading(!0);let s=await e.list().catch(()=>[]);t.setConversations(s)}finally{t.setLoading(!1)}}async function c(e,t,s){s.setLoading(!0);try{let i=await t.list(e||void 0);s.setConversations(i),s.setView("conversationList")}finally{s.setLoading(!1)}}},2020:function(e,t,s){"use strict";var i=s(96675),n=s(3091);t.default={...i,execute:n.execute}},3091:function(e,t,s){"use strict";s.d(t,{execute:function(){return o}});var i=s(6689),n=s(49459),a=s(44526),r=s(22732);async function o(e,t,s){let{index:o,selector:l}=t,c=(0,n.requireString)(t,"html");if((0,i.throwIfAborted)(s),void 0===o&&!l||void 0!==o&&l)throw Error("Either index or selector must be provided, but not both");let{element:h,identifier:d}=(0,a.resolveBlock)(e,{selector:l,index:o,requireExactlyOne:!0});try{let t=e.createInside.div();t.innerHTML=c;let s=t.firstChild;if(!s||!r.Dom.isElement(s))throw Error("Invalid HTML: must contain at least one element");return h.parentNode?.replaceChild(s,h),e.synchronizeValues(),{success:!0,message:`Block ${d} replaced successfully`}}catch(e){throw Error(`Failed to replace block ${d}: ${e.message}`)}}},5618:function(e,t,s){"use strict";var i=s(93809),n=s(28157);t.default={...i,execute:n.execute}},6689:function(e,t,s){"use strict";s.d(t,{throwIfAborted:function(){return n}});var i=s(93661);function n(e){if(e.aborted)throw(0,i.abort)()}},12570:function(e,t,s){"use strict";var i=s(62553),n=s(56293);t.default={...i,execute:n.execute}},15927:function(e,t,s){"use strict";function i(e){if(e.s.isCollapsed())return null;let t=e.s.html,s=e.s.range;return{html:t,rangeInfo:{startContainer:s.startContainer.nodeName,startOffset:s.startOffset,endContainer:s.endContainer.nodeName,endOffset:s.endOffset}}}s.d(t,{getCurrentSelectionContext:function(){return i}})},16015:function(e,t,s){"use strict";s.d(t,{UIDialogSettings:function(){return c}});var i=s(82749),n=s(31635),a=s(65478),r=s(67510),o=s(12234),l=s(62357);class c extends r.UIElement{className(){return"UIDialogSettings"}setParentView(e){return this.modelSelect?.setParentView(e),this.temperatureInput?.setParentView(e),super.setParentView(e)}async build(){let e=this.container,t=this.getConversation().options||{};if(this.options.dialogSettings.models&&this.options.dialogSettings.models.length>0){let s=this.parseModels(this.options.dialogSettings.models),i=t.model??this.state.defaultModel??s[0].value;this.modelSelect=new o.UISelect(this.j,{label:"Model",name:"model",value:i,options:s,onChange:this.onModelChange.bind(this)}),e.appendChild(this.modelSelect.container)}if(this.options.dialogSettings.temperature){this.temperatureInput=new l.UIRange(this.j,{label:"Temperature",name:"temperature",min:this.options.dialogSettings.temperature.min,max:this.options.dialogSettings.temperature.max,value:t.temperature??this.state.defaultTemperature??.5,onChange:this.onTemperatureChange.bind(this)});let s=this.temperatureInput.nativeInput;s&&s.setAttribute("step",(this.options.dialogSettings.temperature.step??.1)+""),e.appendChild(this.temperatureInput.container)}}parseModels(e){return 0===e.length?[]:"object"==typeof e[0]&&"title"in e[0]?e.map(e=>({text:e.title,value:e.value})):e.map(e=>({text:e,value:e}))}async onModelChange(){if(!this.modelSelect)return;let e=this.modelSelect.value;this.updateConversation({options:{...this.getConversation().options,model:e}}),this.state.defaultModel=e}async onTemperatureChange(){if(!this.temperatureInput)return;let e=parseFloat(this.temperatureInput.value);this.updateConversation({options:{...this.getConversation().options,temperature:e}}),this.state.defaultTemperature=e}onDefaultModelChange(){this.modelSelect&&this.state.defaultModel&&(this.modelSelect.value=this.state.defaultModel)}onDefaultTemperatureChange(){this.temperatureInput&&void 0!==this.state.defaultTemperature&&(this.temperatureInput.value=this.state.defaultTemperature+"")}destruct(){this.modelSelect?.destruct(),super.destruct()}constructor(e,t,s,n,a){super(e),(0,i._)(this,"getConversation",void 0),(0,i._)(this,"updateConversation",void 0),(0,i._)(this,"state",void 0),(0,i._)(this,"options",void 0),(0,i._)(this,"modelSelect",void 0),(0,i._)(this,"temperatureInput",void 0),this.getConversation=t,this.updateConversation=s,this.state=n,this.options=a,this.modelSelect=null,this.temperatureInput=null,this.build()}}(0,n.__decorate)([(0,a.watch)("state.defaultModel")],c.prototype,"onDefaultModelChange",null),(0,n.__decorate)([(0,a.watch)("state.defaultTemperature")],c.prototype,"onDefaultTemperatureChange",null),c=(0,n.__decorate)([a.component],c)},16745:function(e,t,s){"use strict";var i=s(56732),n=s(39592);t.default={...i,execute:n.execute}},18549:function(e,t,s){"use strict";s.d(t,{UIFlightPosition:function(){return a}});var i=s(2748);let n=new WeakMap;class a{static install(e,t,s={}){this.remove(e);let{panelHeight:i=250,containerClassName:a,toolbarSelector:r=".jodit-toolbar__box",gap:o=16}=s,l=e.j.c.div("jodit-flight-position");a&&l.classList.add(a),l.style.setProperty("--flight-panel-height",`${i}px`),l.appendChild(e.container),document.body.appendChild(l);let c={toolbarSelector:r,gap:o},h=()=>{this.updatePosition(l,t,c)},d=new ResizeObserver(h);d.observe(t),window.addEventListener("scroll",h,{passive:!0}),window.addEventListener("resize",h,{passive:!0}),n.set(e,{container:l,anchor:t,onScroll:h,resizeObserver:d,options:c}),this.updatePosition(l,t,c)}static updatePosition(e,t,s){let{toolbarSelector:i,gap:n}=s,a=t.getBoundingClientRect(),r=window.innerHeight,o=e.offsetHeight||250;e.style.left=`${a.left}px`,e.style.width=`${a.width}px`;let l=t.querySelector(i),c=l?l.getBoundingClientRect().bottom:a.top,h=a.bottom-c,d=a.bottom<=r;o<=h?d?(e.style.top="auto",e.style.bottom=`${r-a.bottom+n}px`):(e.style.top="auto",e.style.bottom=`${n}px`):(e.style.bottom="auto",e.style.top=`${c}px`)}static remove(e){let t=n.get(e);t&&(window.removeEventListener("scroll",t.onScroll),window.removeEventListener("resize",t.onScroll),t.resizeObserver.disconnect(),e.container.parentNode===t.container&&t.container.parentNode?.insertBefore(e.container,t.container),i.Dom.safeRemove(t.container),n.delete(e))}static isInstalled(e){return n.has(e)}static setPanelHeight(e,t){let s=n.get(e);s&&s.container.style.setProperty("--flight-panel-height",`${t}px`)}static refresh(e){let t=n.get(e);t&&this.updatePosition(t.container,t.anchor,t.options)}}},19127:function(e,t,s){"use strict";s.d(t,{execute:function(){return a}});var i=s(6689),n=s(44526);async function a(e,t,s){let{element:a,attributes:r,remove:o,blockIndex:l,selector:c}=t;if((0,i.throwIfAborted)(s),!a&&!r)throw Error('Either "element" or "attributes" must be provided');if(e.s.restore(),void 0!==l||c){let{element:t}=(0,n.resolveBlock)(e,{selector:c,index:l});e.s.select(t)}if(e.s.isCollapsed())throw Error("No selection found. Please select text to format");try{let t={};return a&&(t.element=a),r&&(t.attributes=r),o?e.s.commitStyle({...t,mode:"remove"}):e.s.commitStyle(t),e.synchronizeValues(),{success:!0,message:o?"Formatting removed successfully":"Formatting applied successfully"}}catch(e){throw Error(`Failed to ${o?"remove":"apply"} formatting: ${e.message}`)}}},21020:function(e,t,s){"use strict";s.d(t,{PermissionManager:function(){return n}});var i=s(82749);class n{requiresPermission(e){let{autoApproveTools:t,alwaysDenyTools:s}=this.jodit.o.aiAssistantPro;if(s.includes(e))return!0;if(t.includes(e))return!1;let i=this.toolRegistry.getTool(e);return!i||i.requiresPermission}isAutoDenied(e){let{alwaysDenyTools:t}=this.jodit.o.aiAssistantPro;return t.includes(e)}isAutoApproved(e){let{autoApproveTools:t}=this.jodit.o.aiAssistantPro;return t.includes(e)}checkPermission(e,t){if(this.isAutoApproved(e))return{toolName:e,granted:!0,grantedAt:Date.now(),scope:"once"};if(this.isAutoDenied(e))return null;let s=this.permanentPermissions.get(e);return s&&s.granted?s:t.find(t=>t.toolName===e&&t.granted)||null}grantPermission(e,t){let s={toolName:e,granted:!0,grantedAt:Date.now(),scope:t};return"forever"===t&&(this.permanentPermissions.set(e,s),this.savePermanentPermissions()),s}denyPermission(e){return{toolName:e,granted:!1,grantedAt:Date.now(),scope:"once"}}filterToolCalls(e,t){let s=[],i=[],n=[];for(let a of e){if(this.isAutoDenied(a.name)){n.push({...a,status:"denied"});continue}if(this.isAutoApproved(a.name)){s.push({...a,status:"approved"});continue}let e=this.checkPermission(a.name,t);e&&e.granted?s.push({...a,status:"approved"}):this.requiresPermission(a.name)?(this.jodit.e.fire("permissionRequested.ai-assistant-pro",a.name),i.push({...a,status:"pending"})):s.push({...a,status:"approved"})}return{approved:s,needsPermission:i,denied:n}}clearConversationPermissions(e){}loadPermanentPermissions(){try{let e=localStorage.getItem(this.PERMANENT_PERMISSIONS_KEY);e&&JSON.parse(e).forEach(e=>{"forever"===e.scope&&e.granted&&this.permanentPermissions.set(e.toolName,e)})}catch(e){}}savePermanentPermissions(){try{let e=Array.from(this.permanentPermissions.values());localStorage.setItem(this.PERMANENT_PERMISSIONS_KEY,JSON.stringify(e))}catch(e){}}clearPermanentPermissions(){this.permanentPermissions.clear(),localStorage.removeItem(this.PERMANENT_PERMISSIONS_KEY)}getPermanentPermissions(){return Array.from(this.permanentPermissions.values())}revokePermanentPermission(e){this.permanentPermissions.delete(e),this.savePermanentPermissions()}destruct(){this.permanentPermissions.clear()}constructor(e,t){(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=e,this.toolRegistry=t,this.permanentPermissions=new Map,this.PERMANENT_PERMISSIONS_KEY="jodit-permissions.ai-assistant-pro",this.loadPermanentPermissions()}}},21064:function(e,t,s){"use strict";s.d(t,{WebStorageConversationStorage:function(){return a},createStorageProvider:function(){return r},generateConversationId:function(){return o},generateMessageId:function(){return l}});var i=s(82749),n=s(97333);class a{close(){return this.storage.close()}getConversationKey(e){return"conv:"+e}async getAllKeys(){let e=await this.storage.get("__conversation_index__");return e&&Array.isArray(e)?e:[]}async updateIndex(e){await this.storage.set("__conversation_index__",e)}async addToIndex(e){let t=await this.getAllKeys();t.includes(e)||(t.push(e),await this.updateIndex(t))}async removeFromIndex(e){let t=(await this.getAllKeys()).filter(t=>t!==e);await this.updateIndex(t)}async list(e){try{let t=await this.getAllKeys(),s=[],i=e?.toLowerCase().trim();for(let e of t){let t=await this.get(e);if(t){if(i){let e=t.title?.toLowerCase().includes(i),s=!e&&t.messages.some(e=>e.content.toLowerCase().includes(i));if(!e&&!s)continue}s.push({id:t.id,title:t.title??"",created:t.created,updated:t.updated,messageCount:t.messages.length})}}return s.sort((e,t)=>t.updated-e.updated),s}catch(e){return[]}}async get(e){try{let t=this.getConversationKey(e);return await this.storage.get(t)||null}catch(e){return null}}async save(e){try{if(0===e.messages.length)throw Error("Conversation must have at least one message.");let t=await this.getAllKeys();t.length>=this.maxConversations&&!t.includes(e.id)&&await this.evictOldest();let s=this.getConversationKey(e.id);await this.storage.set(s,e),await this.addToIndex(e.id)}catch(t){if(t?.name==="QuotaExceededError"||t?.code===22||t?.code===1014){await this.evictOldest();try{let t=this.getConversationKey(e.id);await this.storage.set(t,e),await this.addToIndex(e.id)}catch(e){throw Error("Storage quota exceeded. Please delete some conversations.")}}else throw Error("Failed to save conversation: "+(t?.message||"Unknown error"))}}async delete(e){try{let t=this.getConversationKey(e);await this.storage.delete(t),await this.removeFromIndex(e)}catch(e){}}async clear(){try{for(let e of(await this.getAllKeys())){let t=this.getConversationKey(e);await this.storage.delete(t)}await this.updateIndex([])}catch(e){}}async evictOldest(){try{let e=await this.list();if(0===e.length)return;e.sort((e,t)=>e.updated-t.updated);let t=e[0];await this.delete(t.id)}catch(e){}}async getGlobalSettings(){try{return await this.storage.get("global-settings")||null}catch(e){return null}}async saveGlobalSettings(e){try{let t={...await this.getGlobalSettings(),...e};await this.storage.set("global-settings",t)}catch(e){throw Error("Failed to save global settings")}}constructor(e,t){(0,i._)(this,"storage",void 0),(0,i._)(this,"maxConversations",void 0),this.storage=e,this.maxConversations=t}}function r(e,t){return n.AsyncStorage.makeStorage(e,t)}function o(){return`conv_${Date.now()}_${Math.random().toString(36).substring(2,11)}`}function l(){return`msg_${Date.now()}_${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,t,s){"use strict";s.d(t,{UIMainPanel:function(){return i.UIMainPanel}});var i=s(51251)},28157:function(e,t,s){"use strict";s.d(t,{execute:function(){return a}});var i=s(6689),n=s(22732);async function a(e,t,s){let{start:a,end:r,aroundSelection:o}=t;(0,i.throwIfAborted)(s);let l=e.value,c=l.length;if(o&&!e.s.isCollapsed()){let t=e.s.range.commonAncestorContainer;for(;t&&t!==e.editor;){if(n.Dom.isElement(t)&&t.parentNode===e.editor){l=t.outerHTML;break}t=t.parentNode}return{html:l,length:c}}let h=void 0!==r?Math.min(r,c):c,d=Math.max(0,Math.min("number"==typeof a?a:0,c));return(d>0||c>h)&&(l=l.substring(d,h)),{html:l,length:c,start:d,end:h}}},36142:function(e,t,s){"use strict";s.d(t,{execute:function(){return a}});var i=s(6689),n=s(49459);async function a(e,t,s){let a=(0,n.requireString)(t,"html"),{collapseToEnd:r}=t;(0,i.throwIfAborted)(s);try{if(e.s.restore(),e.s.insertHTML(a),r){let t=e.s.range;t.collapse(!1),e.s.selectRange(t)}return e.e.fire("change"),{success:!0,message:"Selection replaced successfully"}}catch(e){throw Error("Failed to replace selection: "+e.message)}}},39296:function(e,t,s){"use strict";var i=s(73943),n=s(19127);t.default={...i,execute:n.execute}},39592:function(e,t,s){"use strict";s.d(t,{execute:function(){return a}});var i=s(6689),n=s(49459);async function a(e,t,s){let a=(0,n.requireString)(t,"html",{allowEmpty:!0}),{replace:r}=t;if(!a.trim())return{success:!0,message:"Nothing to insert: HTML is empty"};(0,i.throwIfAborted)(s);try{return e.s.focus(),r&&!e.s.isCollapsed()&&e.s.remove(),e.s.insertHTML(a),e.synchronizeValues(),{success:!0,message:`Inserted ${a.length} characters of HTML`}}catch(e){throw Error("Failed to insert HTML: "+(e?.message||"Unknown error"))}}},41810:function(e,t,s){"use strict";s.r(t),s.d(t,{aiAssistantPro:function(){return y}});var i=s(82749),n=s(31635);s(66645);var a=s(86449),r=s(21020),o=s(46166),l=s(62895),c=s(55487),h=s(27769),d=s(58579),u=s(63805),p=s(82758),g=s(65478),m=s(580),f=s(21537),v=s(50911),w=s(2692),C=s(18549),x=s(54747);class y extends v.Plugin{get state(){return this.stateManager.state}get toolRegistry(){return new c.ToolRegistry(this.j)}get permissionManager(){return new r.PermissionManager(this.j,this.toolRegistry)}get apiClient(){return new a.APIClient(this.j,this.toolRegistry)}get storage(){let{storage:e,storageKey:t,maxConversations:s}=this.j.o.aiAssistantPro;if("string"==typeof e){let i=(0,l.createStorageProvider)(e,t);return new l.WebStorageConversationStorage(i,s)}return e}get stateManager(){return new o.StateManager(this.j)}get mainPanel(){return new h.UIMainPanel(this.j,this.stateManager.state,this.j.o.aiAssistantPro,e=>{let t=this.stateManager.getCurrentConversation();t&&this.stateManager.setCurrentConversation({...t,...e})})}get dialog(){let e=this.j.dlg({resizable:this.j.o.aiAssistantPro.resizable,eventEmmiter:this.j.e});return e.e.on(e,"afterClose",()=>{this.j.e.fire("closeAIAssistantPro.ai-assistant-pro")}),e}afterInit(){(0,m.extendLang)(u),this.setupEventListeners(),this.j.async.promise(e=>{let{initiallyOpened:t,persistOpenState:s}=this.j.o.aiAssistantPro,i=t;s?this.storage.getGlobalSettings().then(e=>{if(e?.isOpen!=null&&(i=e.isOpen),i)return this.openAssistant()}).catch(()=>null).finally(()=>e(void 0)):e(void 0)}).catch(()=>null)}__loadData(){return this.__initedPromise?this.__initedPromise:this.isDestructed?Promise.reject():(this.__initedPromise=this.j.async.promise(e=>{this.loadInitialData().then(e)}).catch(()=>null),this.__initedPromise)}async loadInitialData(){this.mainPanel.setMod("ready",!0),await (0,d.loadInitialData)(this.j,this.storage,this.stateManager)}setupEventListeners(){this.j.e.on("selectConversation.ai-assistant-pro",async e=>{try{await this.__loadData(),await (0,d.handleConversationSelect)(e,this.storage,this.stateManager)}catch(e){p.IS_PROD}}),this.j.e.on("newConversation.ai-assistant-pro",async()=>{await this.__loadData();let e=(0,d.createNewConversation)(this.j,this.state.defaultModel,this.state.defaultTemperature);this.stateManager.setCurrentConversation(e)}),this.j.e.on("deleteConversation.ai-assistant-pro",async e=>{await this.__loadData(),await this.deleteConversation(e)}),this.j.e.on("backToList.ai-assistant-pro",async()=>{await this.__loadData(),await (0,d.handleBackToList)(this.storage,this.stateManager)}),this.j.e.on("removeContext.ai-assistant-pro",async e=>{await this.__loadData(),this.stateManager.removeSelectionContext(e)}),this.j.e.on("approveToolCall.ai-assistant-pro",async(e,t)=>{try{await this.__loadData();let s=await (0,d.handleToolApproval)(e,t,this.stateManager,this.permissionManager,this.storage);if(s){let e=this.stateManager.getCurrentConversation();if(!e)return;let t=e.messages.find(e=>e.toolCalls?.some(e=>e.id===s.id));if(!t)return;await this.executeToolCall(t.id,s)}}catch(e){if((0,f.isAbortError)(e))return;this.stateManager.setError(e instanceof Error?e.message:e+"")}}),this.j.e.on("denyToolCall.ai-assistant-pro",async e=>{await this.__loadData(),await (0,d.handleToolDenial)(this.j,e,this.stateManager,this.storage)}),this.j.e.on("abortRequest.ai-assistant-pro",async()=>{await this.__loadData(),this.apiClient.abort(),this.stateManager.setLoading(!1)})}__applyTheme(){(0,d.applyTheme)(this.j,this.stateManager.state.theme,this.stateManager.state.displayMode,this.mainPanel.container,this.dialog)}async openAssistant(){if(this.stateManager.isOpen()){this.stateManager.close(),await this.__closeInContainer();return}await this.__loadData(),this.isDestructed||(this.stateManager.open(),await this.__openInContainer(),this.j.o.aiAssistantPro.includeSelectionByDefault&&!this.j.s.isCollapsed()&&this.addCurrentSelectionToContext())}async __openInContainer(){let{resizable:e,allowClose:t,flightPanelHeight:s}=this.j.o.aiAssistantPro,{displayMode:i="right",panelWidth:n,panelHeight:a}=this.stateManager.state;switch(this.__applyTheme(),this.mainPanel.setMod("displayMode",i),this.mainPanel.setMod("allowClose",t),this.mainPanel.setParentView("dialog"===i||"flight"===i?this.dialog:this.j),this.__openedMode=i,i){case"dialog":this.dialog.setSize(n,a).open().setContent(this.mainPanel.container);break;case"flight":C.UIFlightPosition.install(this.mainPanel,this.j.container,{panelHeight:s,containerClassName:this.getFullElName("flight-container")});break;default:e&&(x.UIResize.remove(this.mainPanel),x.UIResize.install(this.mainPanel,(0,d.invertMode)(i),{handleClassName:this.getFullElName("ai-assistent-resize-handle"),onResize:({newSize:e})=>{let t="left"===i||"right"===i?e:n,s="top"===i||"bottom"===i?e:a;return this.stateManager.state.panelWidth=t,this.stateManager.state.panelHeight=s,!0}})),this.j.currentPlace.slots[i].appendChild(this.mainPanel.container),(0,d.resizeInPanelView)(this.j,i,n,a)}}__onResizeInPanelView(){let{displayMode:e,panelWidth:t,panelHeight:s}=this.stateManager.state;(0,d.resizeInPanelView)(this.j,e,t,s)}async __closeInContainer(){let{displayMode:e}=await this.stateManager.state;switch(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()}}__closeFlightMode(){C.UIFlightPosition.remove(this.mainPanel)}__onSavedStateChange(){let e=this.stateManager.state;return this.storage.saveGlobalSettings({displayMode:e.displayMode,panelWidth:e.panelWidth,panelHeight:e.panelHeight,theme:e.theme,defaultModel:e.defaultModel,defaultTemperature:e.defaultTemperature,currentConversationId:e.currentConversation?.id,...this.j.o.aiAssistantPro.persistOpenState?{isOpen:e.isOpen}:{}})}async closeAssistant(){this.stateManager.isOpen()&&(await this.__loadData(),this.stateManager.close(),this.__closeInContainer())}async addCurrentSelectionToContext(){await this.__loadData();let e=(0,d.getCurrentSelectionContext)(this.j);e&&this.stateManager.addSelectionContext(e)}async executeQuickCommand(e){let t,{quickCommandsSilentMode:s,quickCommandsDisplayMode:i}=this.j.o.aiAssistantPro,n=this.j.o.aiAssistant;if(n&&n[e]&&(0,f.isString)(n[e])&&(t=n[e]),!t)return void this.j.e.fire("error","Command not found: "+e);let a=this.j.s.isCollapsed()?this.j.value:this.j.s.html;if(!a)return;let r=n?.aiCommonPrefixPrompt||"",o=n?.aiCommonSuffixPrompt||"",l=`${r}${t}${o}
${a}`.trim();s?await this.__executeQuickCommandSilent(l,a):await this.__executeQuickCommandWithPanel(l,i)}async __executeQuickCommandSilent(e,t){await this.__loadData(),this.j.progressbar.show().progress(100);try{let t=(0,d.createUserMessage)(e),s=(0,d.createNewConversation)(this.j,this.state.defaultModel,this.state.defaultTemperature,[t]),i=await this.apiClient.sendRequest(s.id,s.messages,null,[],s.options);if("final"===i.mode){let e=i.response.content;e&&this.j.s.insertHTML(e)}}catch(e){(0,f.isAbortError)(e)||this.j.e.fire("error",e)}finally{this.j.progressbar.hide()}}async __executeQuickCommandWithPanel(e,t){await this.__loadData();let s=this.stateManager.state.displayMode;this.stateManager.state.displayMode=t;let i=(0,d.getCurrentSelectionContext)(this.j);i&&this.stateManager.addSelectionContext(i),this.stateManager.isOpen()||await this.openAssistant(),await this.sendMessage(e),this.stateManager.state.displayMode=s}async sendMessage(e){await this.__loadData();let t=this.stateManager.getCurrentConversation(),s=this.stateManager.getEditingMessageId();if(s&&t){let e=t.messages.findIndex(e=>e.id===s);if(-1!==e){let s=t.messages.slice(0,e),i={...t,messages:s,updatedAt:Date.now()};this.stateManager.setCurrentConversation(i),await this.storage.save(i),this.stateManager.clearEditingMessage(),t=i}}t||(t=(0,d.createNewConversation)(this.j,this.state.defaultModel,this.state.defaultTemperature),this.stateManager.setCurrentConversation(t));let i=null;e.trim()&&(i=(0,d.createUserMessage)(e),t.title||(t={...t,title:e}),t={...t,updated:Date.now(),messages:[...t.messages,i]}),this.stateManager.setCurrentConversation({...t}),i&&this.j.e.fire("messageSent.ai-assistant-pro",i),this.stateManager.setLoading(!0),this.stateManager.clearError();try{await this.sendRequestToAI(0),this.stateManager.clearSelectionContexts()}catch(e){if((0,f.isAbortError)(e))return;this.stateManager.setError(e instanceof Error?e.message:e+"")}finally{this.stateManager.setLoading(!1)}}async sendRequestToAI(e=0){let t,s,i=this.j.o.aiAssistantPro.maxRecursionToolCallDepth;if(e>=i)throw Error(`Max recursion depth ${i} reached for tool calls`);let n=this.stateManager.getCurrentConversation();if(!n)return;let a=(0,d.findParentMessageId)(n),[r]=await Promise.all([this.apiClient.sendRequest(n.id,n.messages,a,this.stateManager.getSelectionContexts(),n.options),this.storage.save(n)]);if("stream"===r.mode){let e=await (0,d.processStreamingResponse)(this.stateManager,r,n);t=e.aiMessage,s=e.index,n=e.conversation}else{let e=(0,d.processFinalResponse)(r,n);t=e.aiMessage,s=e.index,n=e.conversation}n=await (0,d.processArtifacts)(this.j,t,n,s),this.j.e.fire("messageReceived.ai-assistant-pro",t),this.stateManager.setCurrentConversation({...n}),await this.storage.save(n),await this.handleToolCalls(t.id,e)}async deleteConversation(e){await this.__loadData(),await (0,d.deleteConversationWithCleanup)(this.j,e,this.storage,this.stateManager,this.permissionManager)}async searchConversations(e){await this.__loadData(),await (0,d.handleConversationSearch)(e,this.storage,this.stateManager)}async handleToolCalls(e,t=0){let s=this.stateManager.getCurrentConversation();if(!s)return;let i=s.messages.find(t=>t.id===e);if(!i)return;let n=i.toolCalls;if(!n||0===n.length)return;await this.__loadData();let{approved:a,needsPermission:r}=this.permissionManager.filterToolCalls(n,s.permissions);for(let s of(this.stateManager.setPendingToolCalls(r),a))await this.executeToolCall(e,s,t)}async executeToolCall(e,t,s=0){await this.__loadData();let i=this.stateManager.getCurrentConversation();if(!i)return;let n=await (0,d.executeToolCall)(this.j,t,this.toolRegistry),a=i.messages.findIndex(t=>t.id===e);if(-1===a)return;let r=i.messages[a],o=i.messages.slice();o[a]=(0,d.updateToolCallInMessage)(r,n),i={...i,messages:o,updated:Date.now()},this.stateManager.setCurrentConversation(i),(0,d.areAllToolCallsExecuted)(i)&&await this.sendRequestToAI(s+1)}async copyMessage(e){let t=this.stateManager.getCurrentConversation();if(!t)return;let s=t.messages.find(t=>t.id===e);if(s)try{await navigator.clipboard.writeText(s.content),this.j.message.success("Message copied to clipboard")}catch(e){this.j.e.fire("error",Error("Failed to copy message"))}}async restartFromMessage(e){let t=this.stateManager.getCurrentConversation();if(!t)return;let s=t.messages.findIndex(t=>t.id===e);if(-1===s)return;let i=t.messages[s];if("user"!==i.role)return;await this.__loadData();let n=t.messages.slice(0,s),a={...t,messages:n,updatedAt:Date.now()};this.stateManager.setCurrentConversation(a),await this.storage.save(a),await this.sendMessage(i.content)}async editMessage(e){let t=this.stateManager.getCurrentConversation();if(!t)return;let s=t.messages.find(t=>t.id===e);s&&"user"===s.role&&(this.stateManager.setEditingMessageId(e),this.mainPanel.inputArea.setValue(s.content),this.mainPanel.inputArea.focus())}cancelEditMessage(){this.stateManager.isEditingMessage()&&(this.stateManager.clearEditingMessage(),this.mainPanel.inputArea.setValue(""))}async deleteMessage(e){await this.__loadData();let t=this.stateManager.getCurrentConversation();if(!t||-1===t.messages.findIndex(t=>t.id===e))return;let s=t.messages.filter(t=>t.id!==e),i={...t,messages:s,updatedAt:Date.now()};this.stateManager.setCurrentConversation(i),await this.storage.save(i)}beforeDestruct(){this.__closeFlightMode(),(0,g.cached)(this,"toolRegistry")?.destruct(),(0,g.cached)(this,"permissionManager")?.destruct(),(0,g.cached)(this,"apiClient")?.destruct(),(0,g.cached)(this,"stateManager")?.destruct(),(0,g.cached)(this,"mainPanel")?.destruct(),(0,g.cached)(this,"dialog")?.destruct(),(0,g.cached)(this,"storage")?.close?.()}constructor(...e){super(...e),(0,i._)(this,"buttons",[{name:"aiAssistantPro",group:"insert"},{name:"aiCommandsPro",group:"insert"}]),(0,i._)(this,"__initedPromise",null),(0,i._)(this,"__openedMode",null)}}(0,i._)(y,"requires",["license"]),(0,n.__decorate)([g.cache],y.prototype,"toolRegistry",null),(0,n.__decorate)([g.cache],y.prototype,"permissionManager",null),(0,n.__decorate)([g.cache],y.prototype,"apiClient",null),(0,n.__decorate)([g.cache],y.prototype,"storage",null),(0,n.__decorate)([g.cache],y.prototype,"stateManager",null),(0,n.__decorate)([g.cache],y.prototype,"mainPanel",null),(0,n.__decorate)([g.cache],y.prototype,"dialog",null),(0,n.__decorate)([(0,g.watch)("state.theme")],y.prototype,"__applyTheme",null),(0,n.__decorate)([(0,g.watch)(":openAIAssistantPro.ai-assistant-pro")],y.prototype,"openAssistant",null),(0,n.__decorate)([(0,g.watch)([":resize","state.panelWidth","state.panelHeight"])],y.prototype,"__onResizeInPanelView",null),(0,n.__decorate)([(0,g.watch)(["state.isOpen","state.displayMode","state.panelWidth","state.panelHeight","state.theme","state.defaultModel","state.defaultTemperature","state.currentConversation"]),(0,g.debounce)()],y.prototype,"__onSavedStateChange",null),(0,n.__decorate)([(0,g.watch)(":closeAIAssistantPro.ai-assistant-pro")],y.prototype,"closeAssistant",null),(0,n.__decorate)([(0,g.watch)(":addContextToAIAssistant.ai-assistant-pro")],y.prototype,"addCurrentSelectionToContext",null),(0,n.__decorate)([(0,g.watch)(":executeQuickCommand.ai-assistant-pro")],y.prototype,"executeQuickCommand",null),(0,n.__decorate)([(0,g.watch)(":sendMessage.ai-assistant-pro")],y.prototype,"sendMessage",null),(0,n.__decorate)([(0,g.watch)(":searchConversations.ai-assistant-pro")],y.prototype,"searchConversations",null),(0,n.__decorate)([(0,g.watch)(":copyMessage.ai-assistant-pro")],y.prototype,"copyMessage",null),(0,n.__decorate)([(0,g.watch)(":restartFromMessage.ai-assistant-pro")],y.prototype,"restartFromMessage",null),(0,n.__decorate)([(0,g.watch)(":editMessage.ai-assistant-pro")],y.prototype,"editMessage",null),(0,n.__decorate)([(0,g.watch)(":cancelEditMessage.ai-assistant-pro")],y.prototype,"cancelEditMessage",null),(0,n.__decorate)([(0,g.watch)(":deleteMessage.ai-assistant-pro")],y.prototype,"deleteMessage",null),y=(0,n.__decorate)([g.component],y),w.JoditPro.plugins.add("aiAssistantPro",y)},44526:function(e,t,s){"use strict";s.d(t,{resolveBlock:function(){return n}});var i=s(22732);function n(e,{selector:t,index:s,requireExactlyOne:a=!1}={}){let r=null!=t,o=null!=s;if(a&&r===o)throw Error("Either index or selector must be provided, but not both");if(!r&&!o)throw Error("Block identifier is required");if(r){if("string"!=typeof t)throw Error("Selector must be a string");let s=e.editor.querySelector(t);if(!s)throw Error(`No element found matching selector "${t}"`);if(!i.Dom.isElement(s))throw Error(`Selector "${t}" does not point to an element node`);return{element:s,identifier:`with selector "${t}"`}}if("number"!=typeof s)throw Error("Block index must be a number");let l=Array.from(e.editor.children);if(s<0||s>=l.length)throw Error(`Block index ${s} is out of range. Document has ${l.length} blocks`);let c=l[s];if(!i.Dom.isElement(c))throw Error(`Block at index ${s} is not a valid element`);return{element:c,identifier:"at index "+s}}},46166:function(e,t,s){"use strict";s.d(t,{StateManager:function(){return n}});var i=s(82749);class n{createInitialState(){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}}open(){this.state.isOpen=!0,this.jodit.e.fire("open.ai-assistant-pro",this.state.currentConversation)}close(){this.state.isOpen=!1,this.jodit.e.fire("close.ai-assistant-pro")}isOpen(){return this.state.isOpen}setView(e){this.state.currentView=e,this.jodit.e.fire("viewChanged.ai-assistant-pro",e)}getView(){return this.state.currentView}setConversations(e){this.state.conversations=e}setSavedState(e){e.theme&&(this.state.theme=e.theme),e.displayMode&&(this.state.displayMode=e.displayMode),e.panelWidth&&(this.state.panelWidth=e.panelWidth),e.panelHeight&&(this.state.panelHeight=e.panelHeight),e.defaultModel&&(this.state.defaultModel=e.defaultModel),e.defaultTemperature&&(this.state.defaultTemperature=e.defaultTemperature)}getConversations(){return this.state.conversations}setCurrentConversation(e){if(this.state.currentConversation===e)throw Error("Conversation is already current");this.state.currentConversation=e||null,e&&(this.setView("conversation"),this.jodit.e.fire("conversationSwitched.ai-assistant-pro",e))}getCurrentConversation(){return this.state.currentConversation}removeConversation(e){let t=this.state.conversations.filter(t=>t.id!==e);this.setConversations(t)}setLoading(e){this.state.isLoading=e}isLoading(){return this.state.isLoading}setError(e){this.state.error=e,e&&this.jodit.e.fire("error.ai-assistant-pro",Error(e))}getError(){return this.state.error}clearError(){this.setError(null)}setPendingToolCalls(e){this.state.pendingToolCalls=e}getPendingToolCalls(){return this.state.pendingToolCalls}addPendingToolCall(e){let t=[...this.state.pendingToolCalls,e];this.setPendingToolCalls(t)}removePendingToolCall(e){let t=this.state.pendingToolCalls.filter(t=>t.id!==e);this.setPendingToolCalls(t)}updateToolCallStatus(e,t){let s=this.state.pendingToolCalls.map(s=>s.id===e?{...s,status:t}:s);this.setPendingToolCalls(s)}setSelectionContexts(e){this.state.selectionContexts=e}getSelectionContexts(){return this.state.selectionContexts}addSelectionContext(e){let{maxContextRanges:t}=this.jodit.o.aiAssistantPro,s=[...this.state.selectionContexts,e];s.length>t&&(s=s.slice(-t)),this.setSelectionContexts(s),this.jodit.e.fire("contextAdded.ai-assistant-pro",e)}removeSelectionContext(e){let t=this.state.selectionContexts.filter((t,s)=>s!==e);this.setSelectionContexts(t),this.jodit.e.fire("contextRemoved.ai-assistant-pro",e)}clearSelectionContexts(){this.setSelectionContexts([])}setAbortController(e){this.state.abortController=e}getAbortController(){return this.state.abortController}setEditingMessageId(e){this.state.editingMessageId=e}getEditingMessageId(){return this.state.editingMessageId}isEditingMessage(){return null!=this.state.editingMessageId}clearEditingMessage(){this.setEditingMessageId(null)}reset(){this.state=this.createInitialState()}destruct(){this.state.abortController&&this.state.abortController.abort(),this.reset()}constructor(e){(0,i._)(this,"jodit",void 0),(0,i._)(this,"state",void 0),this.jodit=e,this.state=this.createInitialState()}}},47373:function(e,t,s){"use strict";function i(e,t,s="image/png"){let n=atob(e),a=n.length,r=new Uint8Array(a);for(let e=0;a>e;e++)r[e]=n.charCodeAt(e);return new File([new Blob([r],{type:s})],t,{type:s})}s.d(t,{base64ToFile:function(){return i}})},48705:function(e,t,s){"use strict";s.d(t,{UISettingsButton:function(){return i.UISettingsButton}});var i=s(76697)},49459:function(e,t,s){"use strict";function i(e,t,s={}){let n=e[t];if("string"!=typeof n||!s.allowEmpty&&""===n)throw Error(`Parameter "${t}" is required and must be a${s.allowEmpty?"":" non-empty"} string`);return n}s.d(t,{requireString:function(){return i}})},51251:function(e,t,s){"use strict";s.d(t,{UIMainPanel:function(){return m}});var i=s(82749),n=s(31635),a=s(68365),r=s(63227),o=s(86563),l=s(93677),c=s(48705),h=s(55885),d=s(65478),u=s(2748),p=s(67510),g=s(62843);class m extends p.UIElement{className(){return"UIMainPanel"}setParentView(e){return this.welcomeScreen?.setParentView(e),this.conversationList?.setParentView(e),this.messageList?.setParentView(e),this.inputArea?.setParentView(e),this.permissionRequest?.setParentView(e),this.settingsButton?.setParentView(e),super.setParentView(e)}render(){return`<div class="&__container">
<div class="&__header">
<div class="&__header-left"></div>
<div class="&__header-title"></div>
<div class="&__header-right"></div>
</div>
<div class="&__content"></div>
<div class="&__loading-overlay">
<div class="&__loading-spinner"></div>
</div>
<div class="&__footer"></div>
</div>`}addResize(){}afterRender(){this.content=this.getElm("content"),this.createComponents(),this.createHeaderButtons(),this.__updateView("welcome")}async __onChangeView(){this.__updateView(this.state.currentView,this.state.currentConversation)}createComponents(){this.welcomeScreen=new h.UIWelcomeScreen(this.j),this.conversationList=new a.UIConversationList(this.j,this.options),this.messageList=new o.UIMessageList(this.j,this.options),this.inputArea=new r.UIInputArea(this.j,this.options),this.getElm("footer").appendChild(this.inputArea.container)}createHeaderButtons(){let e=this.getElm("header-left"),t=this.getElm("header-right"),s=new g.UIButton(this.j,{icon:{name:"angle-left"},size:"small",variant:"initial"});s.container.classList.add(this.getFullElName("back-button")),this.j.e.on(s,"click",()=>{this.j.e.fire("backToList.ai-assistant-pro")}),e.appendChild(s.container);let i=new g.UIButton(this.j,{icon:{name:"plus"},size:"small",tooltip:"New chat",variant:"initial"});if(i.container.classList.add(this.getFullElName("new-button")),this.j.e.on(i,"click",()=>{this.j.e.fire("newConversation.ai-assistant-pro")}),t.appendChild(i.container),this.shouldShowSettings()&&(this.settingsButton=new c.UISettingsButton(this.j,this.state,this.options,()=>this.state.currentConversation,this.updateConversation),this.settingsButton.container.classList.add(this.getFullElName("settings-button")),t.appendChild(this.settingsButton.container)),"dialog"===this.mods.displayMode||!1===this.mods.allowClose)return;let n=new g.UIButton(this.j,{icon:{name:"cancel"},size:"small",tooltip:"Close",variant:"initial"});n.container.classList.add(this.getFullElName("close-button")),this.j.e.on(n,"click",()=>{this.j.e.fire("closeAIAssistantPro.ai-assistant-pro")}),t.appendChild(n.container)}isFlightMode(){return"flight"===this.mods.displayMode}shouldShowSettings(){let e=this.options,t=e.allowEditDisplayMode||e.allowEditPanelWidth,s=e.allowEditDialogSettings;return t||s}__updateView(e,t=null){this.settingsButton?.update();let s=this.getElm("header-title");this.setMod("view",e);let i=this.isFlightMode();switch(e){case"welcome":s.textContent=this.j.i18n("AI Assistant"),u.Dom.safeRemove(this.conversationList.container),u.Dom.safeRemove(this.messageList.container),this.content.appendChild(this.welcomeScreen.container),this.inputArea.focus();break;case"conversationList":s.textContent=this.j.i18n("AI Assistant"),u.Dom.safeRemove(this.welcomeScreen.container),u.Dom.safeRemove(this.messageList.container),this.conversationList.container.isConnected||this.content.appendChild(this.conversationList.container);break;case"conversation":s.textContent=i?this.j.i18n("AI Assistant"):t?.title||this.j.i18n("Conversation"),u.Dom.safeRemove(this.welcomeScreen.container),u.Dom.safeRemove(this.conversationList.container),this.messageList.container.isConnected||this.content.appendChild(this.messageList.container),t&&this.messageList.setMessages(t.messages),this.inputArea.focus()}}onChangeCurrentConversation(){let{currentConversation:e}=this.state;e&&(this.conversationList.setActiveConversation(e.id),this.messageList.setMessages(e.messages))}onChangeConversations(){this.conversationList.setConversations(this.state.conversations)}onChangeSelectionContexts(){this.inputArea.setContexts(this.state.selectionContexts)}onChangeLoading(){this.inputArea.setLoading(this.state.isLoading)}onChangePendingToolCalls(){this.state.pendingToolCalls&&this.state.pendingToolCalls.length>0?this.showPermissionRequest(this.state.pendingToolCalls[0]):this.hidePermissionRequest()}showPermissionRequest(e){this.permissionRequest||(this.permissionRequest=new l.UIPermissionRequest(this.j,this.options)),this.permissionRequest.setToolCall(e);let t=this.getElm("footer");t.contains(this.permissionRequest.container)||t.insertBefore(this.permissionRequest.container,this.inputArea.container)}hidePermissionRequest(){this.permissionRequest&&this.permissionRequest.container.parentNode&&this.permissionRequest.container.parentNode.removeChild(this.permissionRequest.container)}destruct(){this.welcomeScreen?.destruct(),this.conversationList?.destruct(),this.messageList?.destruct(),this.inputArea?.destruct(),this.permissionRequest?.destruct(),this.settingsButton?.destruct(),super.destruct()}constructor(e,t,s,n){super(e),(0,i._)(this,"state",void 0),(0,i._)(this,"options",void 0),(0,i._)(this,"updateConversation",void 0),(0,i._)(this,"permissionRequest",void 0),(0,i._)(this,"settingsButton",void 0),(0,i._)(this,"content",void 0),this.state=t,this.options=s,this.updateConversation=n,this.permissionRequest=null,this.settingsButton=null}}(0,n.__decorate)([(0,d.hook)("ready")],m.prototype,"afterRender",null),(0,n.__decorate)([(0,d.watch)(["state.currentView","state.currentConversation"])],m.prototype,"__onChangeView",null),(0,n.__decorate)([(0,d.watch)("state.currentConversation")],m.prototype,"onChangeCurrentConversation",null),(0,n.__decorate)([(0,d.watch)("state.conversations")],m.prototype,"onChangeConversations",null),(0,n.__decorate)([(0,d.watch)("state.selectionContexts")],m.prototype,"onChangeSelectionContexts",null),(0,n.__decorate)([(0,d.watch)("state.isLoading")],m.prototype,"onChangeLoading",null),(0,n.__decorate)([(0,d.watch)("state.pendingToolCalls")],m.prototype,"onChangePendingToolCalls",null),m=(0,n.__decorate)([d.component],m)},51359:function(e,t,s){"use strict";s.d(t,{UIMessageListItem:function(){return d}});var i=s(82749),n=s(31635),a=s(81835),r=s(65478),o=s(67510),l=s(62843),c=s(62405),h=s(80870);class d extends o.UIElement{className(){return"UIMessageListItem"}render(){return`<div class="${this.getFullElName("message")}"></div>`}onReady(){this.updateContent(),this.contextMenu=new h.ContextMenu(this.j)}updateContent(){let e=this.container;e.innerHTML="",e.setAttribute("data-message-id",this.message.id),e.setAttribute("data-role",this.message.role);let t=this.j.c.div(this.getFullElName("message-bubble"));t.classList.add(this.getFullElName("message-bubble",this.message.role,!0));let s=this.j.c.div(this.getFullElName("message-content"));if(s.innerHTML=this.formatMessageContent(this.message.content),t.appendChild(s),this.opts.showTimestamps){let e=this.j.c.div(this.getFullElName("message-timestamp"));e.textContent=this.formatTimestamp(this.message.timestamp),t.appendChild(e)}let i=this.j.c.div(this.getFullElName("message-actions"));if(this.renderActionsButton(i),t.appendChild(i),e.appendChild(t),this.message.toolCalls&&this.message.toolCalls.length>0){let t=this.j.c.div(this.getFullElName("tool-calls"));e.appendChild(t),this.message.toolCalls.forEach(e=>{let s=this.createToolCallElement(e);t.appendChild(s)})}this.message.artifacts&&this.message.artifacts.length>0&&this.renderArtifacts()}renderActionsButton(e){let t=this.opts;(t.showCopyMessageAction||t.showRestartMessageAction||t.showEditMessageAction||t.showDeleteMessageAction)&&(this.actionsButton=new l.UIButton(this.j,{icon:{name:"dots"},tooltip:"Message actions",name:"messageActions",size:"tiny"}),this.actionsButton.onAction(e=>{this.showActionsMenu(e)}),e.appendChild(this.actionsButton.container))}showActionsMenu(e){if(!this.contextMenu||!this.actionsButton)return;let t=this.j,s=t.o.aiAssistantPro,i=[];s.showCopyMessageAction&&i.push({title:"Copy message",icon:"copy",exec:()=>{this.j.e.fire("copyMessage.ai-assistant-pro",this.message.id)}}),"user"===this.message.role&&(s.showRestartMessageAction&&i.push({title:"Restart from here",icon:"update",exec:()=>{this.j.e.fire("restartFromMessage.ai-assistant-pro",this.message.id)}}),s.showEditMessageAction&&i.push({title:"Edit message",icon:"pencil",exec:()=>{this.j.e.fire("editMessage.ai-assistant-pro",this.message.id)}})),s.showDeleteMessageAction&&i.push({title:"Delete message",icon:"bin",exec:()=>{t.confirm("Are you sure you want to delete this message?","Delete message",e=>{e&&this.j.e.fire("deleteMessage.ai-assistant-pro",this.message.id)})}});let n=this.actionsButton.container.getBoundingClientRect();this.contextMenu.show(n.left,n.bottom,i),e.stopPropagation()}renderArtifacts(){if(!this.message.artifacts||0===this.message.artifacts.length)return;let e=this.j.c.div(this.getFullElName("artifacts"));this.container.appendChild(e),this.artifactGroup||(this.artifactGroup=new c.UIGroup(this.j),this.artifactGroup.container.className="jodit-ui-artifact-group"),this.artifactGroup.clear(),this.message.artifacts.forEach(e=>{let t=new a.UIArtifact(this.j,e);this.artifactGroup.append(t)}),e.appendChild(this.artifactGroup.container)}createToolCallElement(e){let t=this.j.c.div(this.getFullElName("tool-call"));t.setAttribute("data-tool-id",e.id),t.setAttribute("data-status",e.status);let s=this.j.c.div(this.getFullElName("tool-header")),i=this.j.c.div(this.getFullElName("tool-icon"));i.classList.add(this.getFullElName("tool-icon",e.status,!0)),i.textContent="⚡";let n=this.j.c.div(this.getFullElName("tool-name"));n.textContent=this.j.i18n(e.name);let a=this.j.c.div(this.getFullElName("tool-status"));a.textContent=this.getToolStatusText(e.status||"unknown"),s.appendChild(i),s.appendChild(n),s.appendChild(a),t.appendChild(s);let r=this.createExpandableSection("Arguments",JSON.stringify(e.arguments||{},null,2));if(t.appendChild(r),e.result){let s=e.result.error?"Error: "+e.result.error:e.result.result||"",i=this.createExpandableSection("Result","string"==typeof s?s:JSON.stringify(s,null,2));t.appendChild(i)}return t}createExpandableSection(e,t){let s=this.j.c.div(this.getFullElName("tool-expandable")),i=this.j.c.element("button",{type:"button",class:this.getFullElName("tool-expandable-toggle")});i.textContent="▶ "+this.j.i18n(e);let n=this.j.c.element("pre",{class:this.getFullElName("tool-expandable-content")});return n.textContent=t,n.style.display="none",this.j.e.on(i,"click",()=>{"none"!==n.style.display?(n.style.display="none",i.textContent="▶ "+this.j.i18n(e)):(n.style.display="block",i.textContent="▼ "+this.j.i18n(e))}),s.appendChild(i),s.appendChild(n),s}getToolStatusText(e){return({pending:"⏳",approved:"✓",denied:"✕",executing:"⚡",executed:"✓",error:"⚠"})[e]||"●"}formatMessageContent(e){return(0,this.opts.formatMessageContent)(e,this.message.role,this.j.i18n.bind(this.j))}formatTimestamp(e){return(0,this.opts.formatTimestamp)(e,this.j.i18n.bind(this.j))}updateMessage(e){this.message=e,this.updateContent()}destruct(){this.actionsButton?.destruct(),this.contextMenu?.destruct(),this.artifactGroup?.destruct(),super.destruct()}constructor(e,t,s){super(e),(0,i._)(this,"message",void 0),(0,i._)(this,"opts",void 0),(0,i._)(this,"artifactGroup",void 0),(0,i._)(this,"actionsButton",void 0),(0,i._)(this,"contextMenu",void 0),this.message=t,this.opts=s,this.artifactGroup=null,this.actionsButton=null,this.contextMenu=null}}(0,n.__decorate)([(0,r.hook)("ready")],d.prototype,"onReady",null),d=(0,n.__decorate)([r.component],d)},52826:function(e,t,s){"use strict";s.r(t),s.d(t,{description:function(){return n},name:function(){return i},parameters:function(){return