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