jodit-pro
Version:
PRO Version of Jodit Editor
21 lines (20 loc) • 156 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 r},handleToolDenial:function(){return a}});var i=s(79078),n=s(82758);async function r(e,t,s,i,n){let r=s.getPendingToolCalls().find(t=>t.id===e);if(!r)return null;let a=i.grantPermission(r.name,t),o=s.getCurrentConversation();return o&&(o.permissions.push(a),await n.save(o)),s.removePendingToolCall(e),{...r,status:"approved"}}async function a(e,t,s,n){let r=s.getPendingToolCalls().find(e=>e.id===t);if(!r)return;let a=s.getCurrentConversation();if(!a)return;let o=a.messages.findIndex(e=>{var s;return null==(s=e.toolCalls)?void 0:s.find(e=>e.id===t)});if(-1===o)return;let l=a.messages[o],c={...r,result:{error:"Tool call denied by user."},status:"denied"},h=(0,i.updateToolCallInMessage)(l,c),u=[...a.messages];u[o]=h,a={...a,messages:u,updated:Date.now()},s.setCurrentConversation(a),await n.save(a),e.e.fire("toolCallDenied.ai-assistant-pro",r),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),r=s(44526),a=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:u}=(0,r.resolveBlock)(e,{selector:l,index:o,requireExactlyOne:!0});try{var d;let t=e.createInside.div();t.innerHTML=c;let s=t.firstChild;if(!s||!a.Dom.isElement(s))throw Error("Invalid HTML: must contain at least one element");return null==(d=h.parentNode)||d.replaceChild(s,h),e.synchronizeValues(),{success:!0,message:`Block ${u} replaced successfully`}}catch(e){throw Error(`Failed to replace block ${u}: ${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),r=s(65478),a=s(67510),o=s(12234),l=s(62357);class c extends a.UIElement{className(){return"UIDialogSettings"}setParentView(e){var t,s;return null==(t=this.modelSelect)||t.setParentView(e),null==(s=this.temperatureInput)||s.setParentView(e),super.setParentView(e)}async build(){var e,t,s,i,n;let r=this.container,a=this.getConversation().options||{};if(this.options.dialogSettings.models&&this.options.dialogSettings.models.length>0){let s=this.parseModels(this.options.dialogSettings.models),i=null!=(e=null!=(t=a.model)?t:this.state.defaultModel)?e:s[0].value;this.modelSelect=new o.UISelect(this.j,{label:"Model",name:"model",value:i,options:s,onChange:this.onModelChange.bind(this)}),r.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:null!=(s=null!=(i=a.temperature)?i:this.state.defaultTemperature)?s:.5,onChange:this.onTemperatureChange.bind(this)});let e=this.temperatureInput.nativeInput;e&&e.setAttribute("step",String(null!=(n=this.options.dialogSettings.temperature.step)?n:.1)),r.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=String(this.state.defaultTemperature))}destruct(){var e;null==(e=this.modelSelect)||e.destruct(),super.destruct()}constructor(e,t,s,n,r){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=r,this.modelSelect=null,this.temperatureInput=null,this.build()}}(0,n.__decorate)([(0,r.watch)("state.defaultModel")],c.prototype,"onDefaultModelChange",null),(0,n.__decorate)([(0,r.watch)("state.defaultTemperature")],c.prototype,"onDefaultTemperatureChange",null),c=(0,n.__decorate)([r.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 r}});var i=s(2748);let n=new WeakMap;class r{static install(e,t,s={}){this.remove(e);let{panelHeight:i=250,containerClassName:r,toolbarSelector:a=".jodit-toolbar__box",gap:o=16}=s,l=e.j.c.div("jodit-flight-position");r&&l.classList.add(r),l.style.setProperty("--flight-panel-height",`${i}px`),l.appendChild(e.container),document.body.appendChild(l);let c={toolbarSelector:a,gap:o},h=()=>{this.updatePosition(l,t,c)},u=new ResizeObserver(h);u.observe(t),window.addEventListener("scroll",h,{passive:!0}),window.addEventListener("resize",h,{passive:!0}),n.set(e,{container:l,anchor:t,onScroll:h,resizeObserver:u,options:c}),this.updatePosition(l,t,c)}static updatePosition(e,t,s){let{toolbarSelector:i,gap:n}=s,r=t.getBoundingClientRect(),a=window.innerHeight,o=e.offsetHeight||250;e.style.left=`${r.left}px`,e.style.width=`${r.width}px`;let l=t.querySelector(i),c=l?l.getBoundingClientRect().bottom:r.top,h=r.bottom-c,u=r.bottom<=a;o<=h?u?(e.style.top="auto",e.style.bottom=`${a-r.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);if(t){if(window.removeEventListener("scroll",t.onScroll),window.removeEventListener("resize",t.onScroll),t.resizeObserver.disconnect(),e.container.parentNode===t.container){var s;null==(s=t.container.parentNode)||s.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 r}});var i=s(6689),n=s(44526);async function r(e,t,s){let{element:r,attributes:a,remove:o,blockIndex:l,selector:c}=t;if((0,i.throwIfAborted)(s),!r&&!a)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 r&&(t.element=r),a&&(t.attributes=a),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 r of e){if(this.isAutoDenied(r.name)){n.push({...r,status:"denied"});continue}if(this.isAutoApproved(r.name)){s.push({...r,status:"approved"});continue}let e=this.checkPermission(r.name,t);e&&e.granted?s.push({...r,status:"approved"}):this.requiresPermission(r.name)?(this.jodit.e.fire("permissionRequested.ai-assistant-pro",r.name),i.push({...r,status:"pending"})):s.push({...r,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 r},createStorageProvider:function(){return a},generateConversationId:function(){return o},generateMessageId:function(){return l}});var i=s(82749),n=s(97333);class r{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 i=await this.getAllKeys(),n=[],r=null==e?void 0:e.toLowerCase().trim();for(let e of i){var t,s;let i=await this.get(e);if(i){if(r){let e=null==(s=i.title)?void 0:s.toLowerCase().includes(r),t=!e&&i.messages.some(e=>e.content.toLowerCase().includes(r));if(!e&&!t)continue}n.push({id:i.id,title:null!=(t=i.title)?t:"",created:i.created,updated:i.updated,messageCount:i.messages.length})}}return n.sort((e,t)=>t.updated-e.updated),n}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((null==t?void 0:t.name)==="QuotaExceededError"||(null==t?void 0:t.code)===22||(null==t?void 0: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: ${(null==t?void 0: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 a(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 r}});var i=s(6689),n=s(22732);async function r(e,t,s){let{start:r,end:a,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!==a?Math.min(a,c):c,u=Math.max(0,Math.min("number"==typeof r?r:0,c));return(u>0||c>h)&&(l=l.substring(u,h)),{html:l,length:c,start:u,end:h}}},36142:function(e,t,s){"use strict";s.d(t,{execute:function(){return r}});var i=s(6689),n=s(49459);async function r(e,t,s){let r=(0,n.requireString)(t,"html"),{collapseToEnd:a}=t;(0,i.throwIfAborted)(s);try{if(e.s.restore(),e.s.insertHTML(r),a){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 r}});var i=s(6689),n=s(49459);async function r(e,t,s){let r=(0,n.requireString)(t,"html",{allowEmpty:!0}),{replace:a}=t;if(!r.trim())return{success:!0,message:"Nothing to insert: HTML is empty"};(0,i.throwIfAborted)(s);try{return e.s.focus(),a&&!e.s.isCollapsed()&&e.s.remove(),e.s.insertHTML(r),e.synchronizeValues(),{success:!0,message:`Inserted ${r.length} characters of HTML`}}catch(e){throw Error(`Failed to insert HTML: ${(null==e?void 0: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 r=s(86449),a=s(21020),o=s(46166),l=s(62895),c=s(55487),h=s(27769),u=s(58579),d=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 a.PermissionManager(this.j,this.toolRegistry)}get apiClient(){return new r.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)(d),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((null==e?void 0: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,u.loadInitialData)(this.j,this.storage,this.stateManager)}setupEventListeners(){this.j.e.on("selectConversation.ai-assistant-pro",async e=>{try{await this.__loadData(),await (0,u.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,u.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,u.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,u.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=>{var t;return null==(t=e.toolCalls)?void 0:t.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:String(e))}}),this.j.e.on("denyToolCall.ai-assistant-pro",async e=>{await this.__loadData(),await (0,u.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,u.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:r}=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,r).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,u.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:r;return this.stateManager.state.panelWidth=t,this.stateManager.state.panelHeight=s,!0}})),this.j.currentPlace.slots[i].appendChild(this.mainPanel.container),(0,u.resizeInPanelView)(this.j,i,n,r)}}__onResizeInPanelView(){let{displayMode:e,panelWidth:t,panelHeight:s}=this.stateManager.state;(0,u.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(){var e;let t=this.stateManager.state;return this.storage.saveGlobalSettings({displayMode:t.displayMode,panelWidth:t.panelWidth,panelHeight:t.panelHeight,theme:t.theme,defaultModel:t.defaultModel,defaultTemperature:t.defaultTemperature,currentConversationId:null==(e=t.currentConversation)?void 0:e.id,...this.j.o.aiAssistantPro.persistOpenState?{isOpen:t.isOpen}:{}})}async closeAssistant(){this.stateManager.isOpen()&&(await this.__loadData(),this.stateManager.close(),this.__closeInContainer())}async addCurrentSelectionToContext(){await this.__loadData();let e=(0,u.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 r=this.j.s.isCollapsed()?this.j.value:this.j.s.html;if(!r)return;let a=(null==n?void 0:n.aiCommonPrefixPrompt)||"",o=(null==n?void 0:n.aiCommonSuffixPrompt)||"",l=`${a}${t}${o}
${r}`.trim();s?await this.__executeQuickCommandSilent(l,r):await this.__executeQuickCommandWithPanel(l,i)}async __executeQuickCommandSilent(e,t){await this.__loadData(),this.j.progressbar.show().progress(100);try{let t=(0,u.createUserMessage)(e),s=(0,u.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,u.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,u.createNewConversation)(this.j,this.state.defaultModel,this.state.defaultTemperature),this.stateManager.setCurrentConversation(t));let i=null;e.trim()&&(i=(0,u.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:String(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 r=(0,u.findParentMessageId)(n),[a]=await Promise.all([this.apiClient.sendRequest(n.id,n.messages,r,this.stateManager.getSelectionContexts(),n.options),this.storage.save(n)]);if("stream"===a.mode){let e=await (0,u.processStreamingResponse)(this.stateManager,a,n);t=e.aiMessage,s=e.index,n=e.conversation}else{let e=(0,u.processFinalResponse)(a,n);t=e.aiMessage,s=e.index,n=e.conversation}n=await (0,u.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,u.deleteConversationWithCleanup)(this.j,e,this.storage,this.stateManager,this.permissionManager)}async searchConversations(e){await this.__loadData(),await (0,u.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:r,needsPermission:a}=this.permissionManager.filterToolCalls(n,s.permissions);for(let s of(this.stateManager.setPendingToolCalls(a),r))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,u.executeToolCall)(this.j,t,this.toolRegistry),r=i.messages.findIndex(t=>t.id===e);if(-1===r)return;let a=i.messages[r],o=i.messages.slice();o[r]=(0,u.updateToolCallInMessage)(a,n),i={...i,messages:o,updated:Date.now()},this.stateManager.setCurrentConversation(i),(0,u.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),r={...t,messages:n,updatedAt:Date.now()};this.stateManager.setCurrentConversation(r),await this.storage.save(r),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(){var e,t,s,i,n,r,a,o;this.__closeFlightMode(),null==(e=(0,g.cached)(this,"toolRegistry"))||e.destruct(),null==(t=(0,g.cached)(this,"permissionManager"))||t.destruct(),null==(s=(0,g.cached)(this,"apiClient"))||s.destruct(),null==(i=(0,g.cached)(this,"stateManager"))||i.destruct(),null==(n=(0,g.cached)(this,"mainPanel"))||n.destruct(),null==(r=(0,g.cached)(this,"dialog"))||r.destruct(),null==(o=(0,g.cached)(this,"storage"))||null==(a=o.close)||a.call(o)}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:r=!1}={}){let a=null!=t,o=null!=s;if(r&&a===o)throw Error("Either index or selector must be provided, but not both");if(!a&&!o)throw Error("Block identifier is required");if(a){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),r=n.length,a=new Uint8Array(r);for(let e=0;r>e;e++)a[e]=n.charCodeAt(e);return new File([new Blob([a],{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),r=s(68365),a=s(63227),o=s(86563),l=s(93677),c=s(48705),h=s(55885),u=s(65478),d=s(2748),p=s(67510),g=s(62843);class m extends p.UIElement{className(){return"UIMainPanel"}setParentView(e){var t,s,i,n,r,a;return null==(t=this.welcomeScreen)||t.setParentView(e),null==(s=this.conversationList)||s.setParentView(e),null==(i=this.messageList)||i.setParentView(e),null==(n=this.inputArea)||n.setParentView(e),null==(r=this.permissionRequest)||r.setParentView(e),null==(a=this.settingsButton)||a.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 r.UIConversationList(this.j,this.options),this.messageList=new o.UIMessageList(this.j,this.options),this.inputArea=new a.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){var s;null==(s=this.settingsButton)||s.update();let i=this.getElm("header-title");this.setMod("view",e);let n=this.isFlightMode();switch(e){case"welcome":i.textContent=this.j.i18n("AI Assistant"),d.Dom.safeRemove(this.conversationList.container),d.Dom.safeRemove(this.messageList.container),this.content.appendChild(this.welcomeScreen.container),this.inputArea.focus();break;case"conversationList":i.textContent=this.j.i18n("AI Assistant"),d.Dom.safeRemove(this.welcomeScreen.container),d.Dom.safeRemove(this.messageList.container),this.conversationList.container.isConnected||this.content.appendChild(this.conversationList.container);break;case"conversation":i.textContent=n?this.j.i18n("AI Assistant"):(null==t?void 0:t.title)||this.j.i18n("Conversation"),d.Dom.safeRemove(this.welcomeScreen.container),d.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(){var e,t,s,i,n,r;null==(e=this.welcomeScreen)||e.destruct(),null==(t=this.conversationList)||t.destruct(),null==(s=this.messageList)||s.destruct(),null==(i=this.inputArea)||i.destruct(),null==(n=this.permissionRequest)||n.destruct(),null==(r=this.settingsButton)||r.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,u.hook)("ready")],m.prototype,"afterRender",null),(0,n.__decorate)([(0,u.watch)(["state.currentView","state.currentConversation"])],m.prototype,"__onChangeView",null),(0,n.__decorate)([(0,u.watch)("state.currentConversation")],m.prototype,"onChangeCurrentConversation",null),(0,n.__decorate)([(0,u.watch)("state.conversations")],m.prototype,"onChangeConversations",null),(0,n.__decorate)([(0,u.watch)("state.selectionContexts")],m.prototype,"onChangeSelectionContexts",null),(0,n.__decorate)([(0,u.watch)("state.isLoading")],m.prototype,"onChangeLoading",null),(0,n.__decorate)([(0,u.watch)("state.pendingToolCalls")],m.prototype,"onChangePendingToolCalls",null),m=(0,n.__decorate)([u.component],m)},51359:function(e,t,s){"use strict";s.d(t,{UIMessageListItem:function(){return u}});var i=s(82749),n=s(31635),r=s(81835),a=s(65478),o=s(67510),l=s(62843),c=s(62405),h=s(80870);class u 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 r.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 r=this.j.c.div(this.getFullElName("tool-status"));r.textContent=this.getToolStatusText(e.status||"unknown"),s.appendChild(i),s.appendChild(n),s.appendChild(r),t.appendChild(s);let a=this.createExpandableSection("Arguments",JSON.stringify(e.arguments||{},null,2));if(t.appendChild(a),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