diff --git a/api/__init__.py b/api/__init__.py index 87a467e2..a82ce6cb 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -1121,7 +1121,7 @@ class LoLLMsAPI(LollmsApplication): ASCIIColors.blue(f"Your personal data is stored here :",end="") ASCIIColors.green(f"{self.lollms_paths.personal_path}") - def audio_callback(self, output): + def audio_callback(self, text): if self.summoned: client_id = 0 self.cancel_gen = False @@ -1153,7 +1153,7 @@ class LoLLMsAPI(LollmsApplication): parent_message_id=self.message_id ) - ASCIIColors.green("Starting message generation by "+self.personality.name) + ASCIIColors.green("Starting message generation by " + self.personality.name) self.connections[client_id]['generation_thread'] = threading.Thread(target=self.start_message_generation, args=(message, message.id, client_id)) self.connections[client_id]['generation_thread'].start() @@ -1219,7 +1219,7 @@ class LoLLMsAPI(LollmsApplication): mounted_personalities.append(personality) if self.config.enable_voice_service and self.config.auto_read and len(personality.audio_samples)>0: try: - from lollms.audio_gen_modules.lollms_xtts import LollmsXTTS + from lollms.services.xtts.lollms_xtts import LollmsXTTS if self.tts is None: self.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent.parent/"voices") except: @@ -2122,7 +2122,7 @@ class LoLLMsAPI(LollmsApplication): if self.config.enable_voice_service and self.config.auto_read and len(self.personality.audio_samples)>0: try: self.process_chunk("Generating voice output",MSG_TYPE.MSG_TYPE_STEP_START,client_id=client_id) - from lollms.audio_gen_modules.lollms_xtts import LollmsXTTS + from lollms.services.xtts.lollms_xtts import LollmsXTTS if self.tts is None: self.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent.parent/"voices") language = convert_language_name(self.personality.language) diff --git a/app.py b/app.py index 1872025a..5b821809 100644 --- a/app.py +++ b/app.py @@ -475,7 +475,7 @@ try: def install_sd(self): try: self.ShowBlockingMessage("Installing SD api server\nPlease stand by") - from lollms.image_gen_modules.lollms_sd import install_sd + from lollms.services.sd.lollms_sd import install_sd install_sd() self.HideBlockingMessage() return jsonify({"status":True}) @@ -752,7 +752,7 @@ try: def text2Audio(self): # Get the JSON data from the POST request. try: - from lollms.audio_gen_modules.lollms_xtts import LollmsXTTS + from lollms.services.xtts.lollms_xtts import LollmsXTTS if self.tts is None: self.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent/"voices") except: @@ -766,7 +766,7 @@ try: voice = "main_voice" self.info("Starting to build voice") try: - from lollms.audio_gen_modules.lollms_xtts import LollmsXTTS + from lollms.services.xtts.lollms_xtts import LollmsXTTS if self.tts is None: self.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent/"voices") language = self.config.current_language# convert_language_name() @@ -1883,9 +1883,6 @@ try: category = data['category'] name = data['folder'] - - - package_path = f"{category}/{name}" if category=="custom_personalities": package_full_path = self.lollms_paths.custom_personalities_path/f"{name}" diff --git a/endpoints/lollms_xtts.py b/endpoints/lollms_xtts.py index 822cf204..ad3a1312 100644 --- a/endpoints/lollms_xtts.py +++ b/endpoints/lollms_xtts.py @@ -68,7 +68,7 @@ async def text2Audio(request: Request): data = (await request.json()) # Get the JSON data from the POST request. try: - from lollms.audio_gen_modules.lollms_xtts import LollmsXTTS + from lollms.services.xtts.lollms_xtts import LollmsXTTS if lollmsElfServer.tts is None: lollmsElfServer.tts = LollmsXTTS(lollmsElfServer, voice_samples_path=Path(__file__).parent/"voices") except: @@ -82,7 +82,7 @@ async def text2Audio(request: Request): voice = "main_voice" lollmsElfServer.info("Starting to build voice") try: - from lollms.audio_gen_modules.lollms_xtts import LollmsXTTS + from lollms.services.xtts.lollms_xtts import LollmsXTTS if lollmsElfServer.tts is None: lollmsElfServer.tts = LollmsXTTS(lollmsElfServer, voice_samples_path=Path(__file__).parent/"voices") language = lollmsElfServer.config.current_language# convert_language_name() diff --git a/events/lollms_discussion_events.py b/events/lollms_discussion_events.py index d69ca732..2895893a 100644 --- a/events/lollms_discussion_events.py +++ b/events/lollms_discussion_events.py @@ -36,7 +36,10 @@ lollmsElfServer = LOLLMSWebUI.get_instance() # ----------------------------------- events ----------------------------------------- def add_events(sio:socketio): @sio.on('new_discussion') - async def new_discussion(sid, data): + async def new_discussion(sid, data): + if lollmsElfServer.personality is None: + lollmsElfServer.error("Please select a personality first") + return ASCIIColors.yellow("New descussion requested") client_id = sid title = data["title"] diff --git a/lollms_core b/lollms_core index c86dbe7e..25334549 160000 --- a/lollms_core +++ b/lollms_core @@ -1 +1 @@ -Subproject commit c86dbe7e598d764143a280cbdccf81d5ddd553d7 +Subproject commit 25334549ec740f5ad332160a8738f3d63c477c50 diff --git a/lollms_webui.py b/lollms_webui.py index 3588dd48..1759c0e1 100644 --- a/lollms_webui.py +++ b/lollms_webui.py @@ -135,8 +135,8 @@ class LOLLMSWebUI(LOLLMSElfServer): callback=callback, socketio=socketio ) - self.app_name = "LOLLMSWebUI" - self.version= lollms_webui_version + self.app_name:str = "LOLLMSWebUI" + self.version:str = lollms_webui_version self.busy = False @@ -335,7 +335,7 @@ class LOLLMSWebUI(LOLLMSElfServer): os.system(f"python {restart_script}") sys.exit(0) - def audio_callback(self, output): + def audio_callback(self, text): if self.summoned: client_id = 0 self.cancel_gen = False @@ -433,7 +433,7 @@ class LOLLMSWebUI(LOLLMSElfServer): mounted_personalities.append(personality) if self.config.enable_voice_service and self.config.auto_read and len(personality.audio_samples)>0: try: - from lollms.audio_gen_modules.lollms_xtts import LollmsXTTS + from lollms.services.xtts.lollms_xtts import LollmsXTTS if self.tts is None: self.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent.parent/"voices") except: @@ -721,7 +721,7 @@ class LOLLMSWebUI(LOLLMSElfServer): # Check if there are document files to add to the prompt documentation = "" - history = "" + knowledge = "" # boosting information @@ -782,15 +782,15 @@ class LOLLMSWebUI(LOLLMSElfServer): documentation += "\n!@>important information: Use the documentation data to answer the user questions. If the data is not present in the documentation, please tell the user that the information he is asking for does not exist in the documentation section. It is strictly forbidden to give the user an answer without having actual proof from the documentation." except: self.warning("Couldn't add documentation to the context. Please verify the vector database") - # Check if there is discussion history to add to the prompt + # Check if there is discussion knowledge to add to the prompt if self.config.use_discussions_history and self.long_term_memory is not None: - if history=="": - history="!@>previous discussions:\n" + if knowledge=="": + knowledge="!@>knowledge:\n" try: docs, sorted_similarities = self.long_term_memory.recover_text(current_message.content, top_k=self.config.data_vectorization_nb_chunks) for i,(doc, infos) in enumerate(zip(docs, sorted_similarities)): - history += f"!@>previous discussion {i}:\n!@>discussion title:\n{infos[0]}\ndiscussion content:\n{doc}" + knowledge += f"!@>knowledge {i}:\n!@>title:\n{infos[0]}\ncontent:\n{doc}" except: self.warning("Couldn't add long term memory information to the context. Please verify the vector database") # Add information about the user user_description="" @@ -810,9 +810,9 @@ class LOLLMSWebUI(LOLLMSElfServer): tokens_documentation = [] n_doc_tk = 0 - # Tokenize the history text and calculate its number of tokens - if len(history)>0: - tokens_history = self.model.tokenize(history) + # Tokenize the knowledge text and calculate its number of tokens + if len(knowledge)>0: + tokens_history = self.model.tokenize(knowledge) n_history_tk = len(tokens_history) else: tokens_history = [] @@ -828,7 +828,7 @@ class LOLLMSWebUI(LOLLMSElfServer): n_user_description_tk = 0 - # Calculate the total number of tokens between conditionning, documentation, and history + # Calculate the total number of tokens between conditionning, documentation, and knowledge total_tokens = n_cond_tk + n_doc_tk + n_history_tk + n_user_description_tk + n_positive_boost + n_negative_boost + n_force_language # Calculate the available space for the messages @@ -902,9 +902,11 @@ class LOLLMSWebUI(LOLLMSElfServer): for i in range(len(full_message_list)-1): message_tokens = full_message_list[i] discussion_messages += self.model.detokenize(message_tokens) + + ai_prefix = self.model.detokenize(full_message_list[-1]) # Build the final prompt by concatenating the conditionning and discussion messages - prompt_data = conditionning + documentation + history + user_description + discussion_messages + positive_boost + negative_boost + force_language + self.model.detokenize(full_message_list[-1]) + prompt_data = conditionning + documentation + knowledge + user_description + discussion_messages + positive_boost + negative_boost + force_language + ai_prefix # Tokenize the prompt data tokens = self.model.tokenize(prompt_data) @@ -916,18 +918,32 @@ class LOLLMSWebUI(LOLLMSElfServer): ASCIIColors.bold("DOC") ASCIIColors.yellow(documentation) ASCIIColors.bold("HISTORY") - ASCIIColors.yellow(history) + ASCIIColors.yellow(knowledge) ASCIIColors.bold("DISCUSSION") ASCIIColors.hilight(discussion_messages,"!@>",ASCIIColors.color_yellow,ASCIIColors.color_bright_red,False) ASCIIColors.bold("Final prompt") ASCIIColors.hilight(prompt_data,"!@>",ASCIIColors.color_yellow,ASCIIColors.color_bright_red,False) ASCIIColors.info(f"prompt size:{len(tokens)} tokens") - ASCIIColors.info(f"available space after doc and history:{available_space} tokens") + ASCIIColors.info(f"available space after doc and knowledge:{available_space} tokens") self.info(f"Tokens summary:\nPrompt size:{len(tokens)}\nTo generate:{available_space}",10) + # Details + context_details = { + "conditionning":conditionning, + "documentation":documentation, + "knowledge":knowledge, + "user_description":user_description, + "discussion_messages":discussion_messages, + "positive_boost":positive_boost, + "negative_boost":negative_boost, + "force_language":force_language, + "ai_prefix":ai_prefix + + } + # Return the prepared query, original message content, and tokenized query - return prompt_data, current_message.content, tokens + return prompt_data, current_message.content, tokens, context_details def get_discussion_to(self, client_id, message_id=-1): @@ -1215,12 +1231,12 @@ class LOLLMSWebUI(LOLLMSElfServer): return True - def generate(self, full_prompt, prompt, n_predict, client_id, callback=None): + def generate(self, full_prompt, prompt, context_details, n_predict, client_id, callback=None): if self.personality.processor is not None: ASCIIColors.info("Running workflow") try: self.personality.callback = callback - self.personality.processor.run_workflow( prompt, full_prompt, callback) + self.personality.processor.run_workflow( prompt, full_prompt, callback, context_details) except Exception as ex: trace_exception(ex) # Catch the exception and get the traceback as a list of strings @@ -1329,14 +1345,15 @@ class LOLLMSWebUI(LOLLMSElfServer): self.socketio.sleep(0.01) # prepare query and reception - self.discussion_messages, self.current_message, tokens = self.prepare_query(client_id, message_id, is_continue, n_tokens=self.config.min_n_predict, generation_type=generation_type) + self.discussion_messages, self.current_message, tokens, context_details = self.prepare_query(client_id, message_id, is_continue, n_tokens=self.config.min_n_predict, generation_type=generation_type) self.prepare_reception(client_id) self.generating = True self.connections[client_id]["processing"]=True try: self.generate( self.discussion_messages, - self.current_message, + self.current_message, + context_details=context_details, n_predict = self.config.ctx_size-len(tokens)-1, client_id=client_id, callback=partial(self.process_chunk,client_id = client_id) @@ -1344,7 +1361,7 @@ class LOLLMSWebUI(LOLLMSElfServer): if self.config.enable_voice_service and self.config.auto_read and len(self.personality.audio_samples)>0: try: self.process_chunk("Generating voice output",MSG_TYPE.MSG_TYPE_STEP_START,client_id=client_id) - from lollms.audio_gen_modules.lollms_xtts import LollmsXTTS + from lollms.services.xtts.lollms_xtts import LollmsXTTS if self.tts is None: self.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent.parent/"voices") language = convert_language_name(self.personality.language) diff --git a/new_app.py b/new_app.py index d0d789bf..8f4e0702 100644 --- a/new_app.py +++ b/new_app.py @@ -76,6 +76,7 @@ if __name__ == "__main__": from endpoints.lollms_user import router as lollms_user_router from endpoints.lollms_advanced import router as lollms_advanced_router from endpoints.chat_bar import router as chat_bar_router + from endpoints.lollms_xtts import router as lollms_xtts_add_router @@ -106,6 +107,8 @@ if __name__ == "__main__": app.include_router(lollms_user_router) app.include_router(lollms_advanced_router) app.include_router(chat_bar_router) + app.include_router(lollms_xtts_add_router) + diff --git a/scripts/linux/linux_install.sh b/scripts/linux/linux_install.sh index 92eafa3a..3ea9fe83 100644 --- a/scripts/linux/linux_install.sh +++ b/scripts/linux/linux_install.sh @@ -98,7 +98,7 @@ if [ -d "lollms-webui" ]; then cd lollms-webui || exit 1 git pull git submodule update --init --recursive - cd lollms-core + cd lollms_core pip install -e . cd .. cd utilities/safe_store diff --git a/scripts/linux/linux_install_use_your_own_conda.sh b/scripts/linux/linux_install_use_your_own_conda.sh index b0787966..ba0cd77b 100644 --- a/scripts/linux/linux_install_use_your_own_conda.sh +++ b/scripts/linux/linux_install_use_your_own_conda.sh @@ -51,7 +51,7 @@ if [ -d "lollms-webui" ]; then git pull git submodule update --init --recursive cd - cd lollms-core + cd lollms_core pip install -e . cd .. cd utilities/safe_store diff --git a/scripts/macos/macos_install.sh b/scripts/macos/macos_install.sh index d14411e4..4dc5a061 100644 --- a/scripts/macos/macos_install.sh +++ b/scripts/macos/macos_install.sh @@ -115,7 +115,7 @@ if [ -d "lollms-webui" ]; then cd lollms-webui || exit 1 git pull git submodule update --init --recursive - cd lollms-core + cd lollms_core pip install -e . cd .. cd utilities/safe_store diff --git a/scripts/windows/win_install.bat b/scripts/windows/win_install.bat index 47af9aa5..b22498d0 100644 --- a/scripts/windows/win_install.bat +++ b/scripts/windows/win_install.bat @@ -88,7 +88,7 @@ if exist lollms-webui\ ( git pull git submodule update --init --recursive cd - cd lollms-core + cd lollms_core pip install -e . cd .. cd utilities\safe_store diff --git a/web/dist/assets/index-cb8d1b46.js b/web/dist/assets/index-c7401936.js similarity index 99% rename from web/dist/assets/index-cb8d1b46.js rename to web/dist/assets/index-c7401936.js index f0abd6cb..461133a5 100644 --- a/web/dist/assets/index-cb8d1b46.js +++ b/web/dist/assets/index-c7401936.js @@ -3849,4 +3849,4 @@ void main() { Please check that you don't accidentally use the same token twice to register two different handlers for the same event/hook.`),this.unsubscribe(e)),this.listenerMap.set(e,t),this._listeners.push(t)}unsubscribe(e){if(this.listenerMap.has(e)){const t=this.listenerMap.get(e);this.listenerMap.delete(e);const i=this._listeners.indexOf(t);i>=0&&this._listeners.splice(i,1)}}registerProxy(e,t){this.proxyMap.has(e)&&(console.warn(`Already subscribed. Unsubscribing for you. Please check that you don't accidentally use the same token twice to register two different proxies for the same event/hook.`),this.unregisterProxy(e)),this.proxyMap.set(e,t),this.proxies.push(t)}unregisterProxy(e){if(!this.proxyMap.has(e))return;const t=this.proxyMap.get(e);this.proxyMap.delete(e);const i=this.proxies.indexOf(t);i>=0&&this.proxies.splice(i,1)}}class Vt extends Zr{constructor(e){super(),this.entity=e}emit(e){this.listeners.forEach(t=>t(e,this.entity))}}class Mn extends Zr{constructor(e){super(),this.entity=e}emit(e){let t=!1;const i=()=>[t=!0];for(const s of Array.from(this.listeners.values()))if(s(e,i,this.entity),t)return{prevented:!0};return{prevented:!1}}}class qO extends Zr{execute(e,t){let i=e;for(const s of this.listeners)i=s(i,t);return i}}class ii extends qO{constructor(e){super(),this.entity=e}execute(e){return super.execute(e,this.entity)}}class q1t extends Zr{constructor(e){super(),this.entity=e}execute(e){const t=[];for(const i of this.listeners)t.push(i(e,this.entity));return t}}function Fi(){const n=Symbol(),e=new Map,t=new Set,i=(l,c)=>{c instanceof Zr&&c.registerProxy(n,()=>{var d,u;return(u=(d=e.get(l))===null||d===void 0?void 0:d.listeners)!==null&&u!==void 0?u:[]})},s=l=>{const c=new Zr;e.set(l,c),t.forEach(d=>i(l,d[l]))},r=l=>{t.add(l);for(const c of e.keys())i(c,l[c])},o=l=>{for(const c of e.keys())l[c]instanceof Zr&&l[c].unregisterProxy(n);t.delete(l)},a=()=>{t.forEach(l=>o(l)),e.clear()};return new Proxy({},{get(l,c){return c==="addTarget"?r:c==="removeTarget"?o:c==="destroy"?a:typeof c!="string"||c.startsWith("_")?l[c]:(e.has(c)||s(c),e.get(c))}})}class cR{constructor(e,t){if(this.destructed=!1,this.events={destruct:new Vt(this)},!e||!t)throw new Error("Cannot initialize connection with null/undefined for 'from' or 'to' values");this.id=Cs(),this.from=e,this.to=t,this.from.connectionCount++,this.to.connectionCount++}destruct(){this.events.destruct.emit(),this.from.connectionCount--,this.to.connectionCount--,this.destructed=!0}}class YO{constructor(e,t){if(!e||!t)throw new Error("Cannot initialize connection with null/undefined for 'from' or 'to' values");this.id=Cs(),this.from=e,this.to=t}}function Zg(n,e){return Object.fromEntries(Object.entries(n).map(([t,i])=>[t,e(i)]))}class $O{constructor(){this._title="",this.id=Cs(),this.events={loaded:new Vt(this),beforeAddInput:new Mn(this),addInput:new Vt(this),beforeRemoveInput:new Mn(this),removeInput:new Vt(this),beforeAddOutput:new Mn(this),addOutput:new Vt(this),beforeRemoveOutput:new Mn(this),removeOutput:new Vt(this),beforeTitleChanged:new Mn(this),titleChanged:new Vt(this),update:new Vt(this)},this.hooks={beforeLoad:new ii(this),afterSave:new ii(this)}}get graph(){return this.graphInstance}get title(){return this._title}set title(e){this.events.beforeTitleChanged.emit(e).prevented||(this._title=e,this.events.titleChanged.emit(e))}addInput(e,t){return this.addInterface("input",e,t)}addOutput(e,t){return this.addInterface("output",e,t)}removeInput(e){return this.removeInterface("input",e)}removeOutput(e){return this.removeInterface("output",e)}registerGraph(e){this.graphInstance=e}load(e){this.hooks.beforeLoad.execute(e),this.id=e.id,this._title=e.title,Object.entries(e.inputs).forEach(([t,i])=>{this.inputs[t]&&(this.inputs[t].load(i),this.inputs[t].nodeId=this.id)}),Object.entries(e.outputs).forEach(([t,i])=>{this.outputs[t]&&(this.outputs[t].load(i),this.outputs[t].nodeId=this.id)}),this.events.loaded.emit(this)}save(){const e=Zg(this.inputs,s=>s.save()),t=Zg(this.outputs,s=>s.save()),i={type:this.type,id:this.id,title:this.title,inputs:e,outputs:t};return this.hooks.afterSave.execute(i)}onPlaced(){}onDestroy(){}initializeIo(){Object.entries(this.inputs).forEach(([e,t])=>this.initializeIntf("input",e,t)),Object.entries(this.outputs).forEach(([e,t])=>this.initializeIntf("output",e,t))}initializeIntf(e,t,i){i.isInput=e==="input",i.nodeId=this.id,i.events.setValue.subscribe(this,()=>this.events.update.emit({type:e,name:t,intf:i}))}addInterface(e,t,i){const s=e==="input"?this.events.beforeAddInput:this.events.beforeAddOutput,r=e==="input"?this.events.addInput:this.events.addOutput,o=e==="input"?this.inputs:this.outputs;return s.emit(i).prevented?!1:(o[t]=i,this.initializeIntf(e,t,i),r.emit(i),!0)}removeInterface(e,t){const i=e==="input"?this.events.beforeRemoveInput:this.events.beforeRemoveOutput,s=e==="input"?this.events.removeInput:this.events.removeOutput,r=e==="input"?this.inputs[t]:this.outputs[t];if(!r||i.emit(r).prevented)return!1;if(r.connectionCount>0)if(this.graphInstance)this.graphInstance.connections.filter(a=>a.from===r||a.to===r).forEach(a=>{this.graphInstance.removeConnection(a)});else throw new Error("Interface is connected, but no graph instance is specified. Unable to delete interface");return r.events.setValue.unsubscribe(this),e==="input"?delete this.inputs[t]:delete this.outputs[t],s.emit(r),!0}}let WO=class extends $O{load(e){super.load(e)}save(){return super.save()}};function Hb(n){return class extends WO{constructor(){var e,t;super(),this.type=n.type,this.inputs={},this.outputs={},this.calculate=n.calculate?(i,s)=>n.calculate.call(this,i,s):void 0,this._title=(e=n.title)!==null&&e!==void 0?e:n.type,this.executeFactory("input",n.inputs),this.executeFactory("output",n.outputs),(t=n.onCreate)===null||t===void 0||t.call(this)}onPlaced(){var e;(e=n.onPlaced)===null||e===void 0||e.call(this)}onDestroy(){var e;(e=n.onDestroy)===null||e===void 0||e.call(this)}executeFactory(e,t){Object.keys(t||{}).forEach(i=>{const s=t[i]();e==="input"?this.addInput(i,s):this.addOutput(i,s)})}}}class pn{set connectionCount(e){this._connectionCount=e,this.events.setConnectionCount.emit(e)}get connectionCount(){return this._connectionCount}set value(e){this.events.beforeSetValue.emit(e).prevented||(this._value=e,this.events.setValue.emit(e))}get value(){return this._value}constructor(e,t){this.id=Cs(),this.nodeId="",this.port=!0,this.hidden=!1,this.events={setConnectionCount:new Vt(this),beforeSetValue:new Mn(this),setValue:new Vt(this),updated:new Vt(this)},this.hooks={load:new ii(this),save:new ii(this)},this._connectionCount=0,this.name=e,this._value=t}load(e){this.id=e.id,this.templateId=e.templateId,this.value=e.value,this.hooks.load.execute(e)}save(){const e={id:this.id,templateId:this.templateId,value:this.value};return this.hooks.save.execute(e)}setComponent(e){return this.component=e,this}setPort(e){return this.port=e,this}setHidden(e){return this.hidden=e,this}use(e,...t){return e(this,...t),this}}const Ra="__baklava_SubgraphInputNode",Aa="__baklava_SubgraphOutputNode";class KO extends WO{constructor(){super(),this.graphInterfaceId=Cs()}onPlaced(){super.onPlaced(),this.initializeIo()}save(){return{...super.save(),graphInterfaceId:this.graphInterfaceId}}load(e){super.load(e),this.graphInterfaceId=e.graphInterfaceId}}class jO extends KO{constructor(){super(...arguments),this.type=Ra,this.inputs={name:new pn("Name","Input")},this.outputs={placeholder:new pn("Value",void 0)}}static isGraphInputNode(e){return e.type===Ra}}class QO extends KO{constructor(){super(...arguments),this.type=Aa,this.inputs={name:new pn("Name","Output"),placeholder:new pn("Value",void 0)},this.outputs={output:new pn("Output",void 0).setHidden(!0)},this.calculate=({placeholder:e})=>({output:e})}static isGraphOutputNode(e){return e.type===Aa}}class mc{get nodes(){return this._nodes}get connections(){return this._connections}get loading(){return this._loading}get destroying(){return this._destroying}get inputs(){return this.nodes.filter(t=>t.type===Ra).map(t=>({id:t.graphInterfaceId,name:t.inputs.name.value,nodeId:t.id,nodeInterfaceId:t.outputs.placeholder.id}))}get outputs(){return this.nodes.filter(t=>t.type===Aa).map(t=>({id:t.graphInterfaceId,name:t.inputs.name.value,nodeId:t.id,nodeInterfaceId:t.outputs.output.id}))}constructor(e,t){this.id=Cs(),this.activeTransactions=0,this._nodes=[],this._connections=[],this._loading=!1,this._destroying=!1,this.events={beforeAddNode:new Mn(this),addNode:new Vt(this),beforeRemoveNode:new Mn(this),removeNode:new Vt(this),beforeAddConnection:new Mn(this),addConnection:new Vt(this),checkConnection:new Mn(this),beforeRemoveConnection:new Mn(this),removeConnection:new Vt(this)},this.hooks={save:new ii(this),load:new ii(this),checkConnection:new q1t(this)},this.nodeEvents=Fi(),this.nodeHooks=Fi(),this.connectionEvents=Fi(),this.editor=e,this.template=t,e.registerGraph(this)}addNode(e){if(!this.events.beforeAddNode.emit(e).prevented)return this.nodeEvents.addTarget(e.events),this.nodeHooks.addTarget(e.hooks),e.registerGraph(this),this._nodes.push(e),e=this.nodes.find(t=>t.id===e.id),e.onPlaced(),this.events.addNode.emit(e),e}removeNode(e){if(this.nodes.includes(e)){if(this.events.beforeRemoveNode.emit(e).prevented)return;const t=[...Object.values(e.inputs),...Object.values(e.outputs)];this.connections.filter(i=>t.includes(i.from)||t.includes(i.to)).forEach(i=>this.removeConnection(i)),this._nodes.splice(this.nodes.indexOf(e),1),this.events.removeNode.emit(e),e.onDestroy(),this.nodeEvents.removeTarget(e.events),this.nodeHooks.removeTarget(e.hooks)}}addConnection(e,t){const i=this.checkConnection(e,t);if(!i.connectionAllowed||this.events.beforeAddConnection.emit({from:e,to:t}).prevented)return;for(const r of i.connectionsInDanger){const o=this.connections.find(a=>a.id===r.id);o&&this.removeConnection(o)}const s=new cR(i.dummyConnection.from,i.dummyConnection.to);return this.internalAddConnection(s),s}removeConnection(e){if(this.connections.includes(e)){if(this.events.beforeRemoveConnection.emit(e).prevented)return;e.destruct(),this._connections.splice(this.connections.indexOf(e),1),this.events.removeConnection.emit(e),this.connectionEvents.removeTarget(e.events)}}checkConnection(e,t){if(!e||!t)return{connectionAllowed:!1};const i=this.findNodeById(e.nodeId),s=this.findNodeById(t.nodeId);if(i&&s&&i===s)return{connectionAllowed:!1};if(e.isInput&&!t.isInput){const a=e;e=t,t=a}if(e.isInput||!t.isInput)return{connectionAllowed:!1};if(this.connections.some(a=>a.from===e&&a.to===t))return{connectionAllowed:!1};if(this.events.checkConnection.emit({from:e,to:t}).prevented)return{connectionAllowed:!1};const r=this.hooks.checkConnection.execute({from:e,to:t});if(r.some(a=>!a.connectionAllowed))return{connectionAllowed:!1};const o=Array.from(new Set(r.flatMap(a=>a.connectionsInDanger)));return{connectionAllowed:!0,dummyConnection:new YO(e,t),connectionsInDanger:o}}findNodeInterface(e){for(const t of this.nodes){for(const i in t.inputs){const s=t.inputs[i];if(s.id===e)return s}for(const i in t.outputs){const s=t.outputs[i];if(s.id===e)return s}}}findNodeById(e){return this.nodes.find(t=>t.id===e)}load(e){try{this._loading=!0;const t=[];for(let i=this.connections.length-1;i>=0;i--)this.removeConnection(this.connections[i]);for(let i=this.nodes.length-1;i>=0;i--)this.removeNode(this.nodes[i]);this.id=e.id;for(const i of e.nodes){const s=this.editor.nodeTypes.get(i.type);if(!s){t.push(`Node type ${i.type} is not registered`);continue}const r=new s.type;this.addNode(r),r.load(i)}for(const i of e.connections){const s=this.findNodeInterface(i.from),r=this.findNodeInterface(i.to);if(s)if(r){const o=new cR(s,r);o.id=i.id,this.internalAddConnection(o)}else{t.push(`Could not find interface with id ${i.to}`);continue}else{t.push(`Could not find interface with id ${i.from}`);continue}}return this.hooks.load.execute(e),t}finally{this._loading=!1}}save(){const e={id:this.id,nodes:this.nodes.map(t=>t.save()),connections:this.connections.map(t=>({id:t.id,from:t.from.id,to:t.to.id})),inputs:this.inputs,outputs:this.outputs};return this.hooks.save.execute(e)}destroy(){this._destroying=!0;for(const e of this.nodes)this.removeNode(e);this.editor.unregisterGraph(this)}internalAddConnection(e){this.connectionEvents.addTarget(e.events),this._connections.push(e),this.events.addConnection.emit(e)}}const Jl="__baklava_GraphNode-";function wa(n){return Jl+n.id}function Y1t(n){return class extends $O{constructor(){super(...arguments),this.type=wa(n),this.inputs={},this.outputs={},this.template=n,this.calculate=async(t,i)=>{var s;if(!this.subgraph)throw new Error(`GraphNode ${this.id}: calculate called without subgraph being initialized`);if(!i.engine||typeof i.engine!="object")throw new Error(`GraphNode ${this.id}: calculate called but no engine provided in context`);const r=i.engine.getInputValues(this.subgraph);for(const l of this.subgraph.inputs)r.set(l.nodeInterfaceId,t[l.id]);const o=await i.engine.runGraph(this.subgraph,r,i.globalValues),a={};for(const l of this.subgraph.outputs)a[l.id]=(s=o.get(l.nodeId))===null||s===void 0?void 0:s.get("output");return a._calculationResults=o,a}}get title(){return this._title}set title(t){this.template.name=t}load(t){if(!this.subgraph)throw new Error("Cannot load a graph node without a graph");if(!this.template)throw new Error("Unable to load graph node without graph template");this.subgraph.load(t.graphState),super.load(t)}save(){if(!this.subgraph)throw new Error("Cannot save a graph node without a graph");return{...super.save(),graphState:this.subgraph.save()}}onPlaced(){this.template.events.updated.subscribe(this,()=>this.initialize()),this.template.events.nameChanged.subscribe(this,t=>{this._title=t}),this.initialize()}onDestroy(){var t;this.template.events.updated.unsubscribe(this),this.template.events.nameChanged.unsubscribe(this),(t=this.subgraph)===null||t===void 0||t.destroy()}initialize(){this.subgraph&&this.subgraph.destroy(),this.subgraph=this.template.createGraph(),this._title=this.template.name,this.updateInterfaces(),this.events.update.emit(null)}updateInterfaces(){if(!this.subgraph)throw new Error("Trying to update interfaces without graph instance");for(const t of this.subgraph.inputs)t.id in this.inputs?this.inputs[t.id].name=t.name:this.addInput(t.id,new pn(t.name,void 0));for(const t of Object.keys(this.inputs))this.subgraph.inputs.some(i=>i.id===t)||this.removeInput(t);for(const t of this.subgraph.outputs)t.id in this.outputs?this.outputs[t.id].name=t.name:this.addOutput(t.id,new pn(t.name,void 0));for(const t of Object.keys(this.outputs))this.subgraph.outputs.some(i=>i.id===t)||this.removeOutput(t);this.addOutput("_calculationResults",new pn("_calculationResults",void 0).setHidden(!0))}}}class ep{static fromGraph(e,t){return new ep(e.save(),t)}get name(){return this._name}set name(e){this._name=e,this.events.nameChanged.emit(e);const t=this.editor.nodeTypes.get(wa(this));t&&(t.title=e)}get inputs(){return this.nodes.filter(t=>t.type===Ra).map(t=>({id:t.graphInterfaceId,name:t.inputs.name.value,nodeId:t.id,nodeInterfaceId:t.outputs.placeholder.id}))}get outputs(){return this.nodes.filter(t=>t.type===Aa).map(t=>({id:t.graphInterfaceId,name:t.inputs.name.value,nodeId:t.id,nodeInterfaceId:t.outputs.output.id}))}constructor(e,t){this.id=Cs(),this._name="Subgraph",this.events={nameChanged:new Vt(this),updated:new Vt(this)},this.hooks={beforeLoad:new ii(this),afterSave:new ii(this)},this.editor=t,e.id&&(this.id=e.id),e.name&&(this._name=e.name),this.update(e)}update(e){this.nodes=e.nodes,this.connections=e.connections,this.events.updated.emit()}save(){return{id:this.id,name:this.name,nodes:this.nodes,connections:this.connections,inputs:this.inputs,outputs:this.outputs}}createGraph(e){const t=new Map,i=h=>{const m=Cs();return t.set(h,m),m},s=h=>{const m=t.get(h);if(!m)throw new Error(`Unable to create graph from template: Could not map old id ${h} to new id`);return m},r=h=>Zg(h,m=>({id:i(m.id),templateId:m.id,value:m.value})),o=this.nodes.map(h=>({...h,id:i(h.id),inputs:r(h.inputs),outputs:r(h.outputs)})),a=this.connections.map(h=>({id:i(h.id),from:s(h.from),to:s(h.to)})),l=this.inputs.map(h=>({id:h.id,name:h.name,nodeId:s(h.nodeId),nodeInterfaceId:s(h.nodeInterfaceId)})),c=this.outputs.map(h=>({id:h.id,name:h.name,nodeId:s(h.nodeId),nodeInterfaceId:s(h.nodeInterfaceId)})),d={id:Cs(),nodes:o,connections:a,inputs:l,outputs:c};return e||(e=new mc(this.editor)),e.load(d).forEach(h=>console.warn(h)),e.template=this,e}}class $1t{get nodeTypes(){return this._nodeTypes}get graph(){return this._graph}get graphTemplates(){return this._graphTemplates}get graphs(){return this._graphs}get loading(){return this._loading}constructor(){this.events={loaded:new Vt(this),beforeRegisterNodeType:new Mn(this),registerNodeType:new Vt(this),beforeUnregisterNodeType:new Mn(this),unregisterNodeType:new Vt(this),beforeAddGraphTemplate:new Mn(this),addGraphTemplate:new Vt(this),beforeRemoveGraphTemplate:new Mn(this),removeGraphTemplate:new Vt(this),registerGraph:new Vt(this),unregisterGraph:new Vt(this)},this.hooks={save:new ii(this),load:new ii(this)},this.graphTemplateEvents=Fi(),this.graphTemplateHooks=Fi(),this.graphEvents=Fi(),this.graphHooks=Fi(),this.nodeEvents=Fi(),this.nodeHooks=Fi(),this.connectionEvents=Fi(),this._graphs=new Set,this._nodeTypes=new Map,this._graph=new mc(this),this._graphTemplates=[],this._loading=!1,this.registerNodeType(jO),this.registerNodeType(QO)}registerNodeType(e,t){var i,s;if(this.events.beforeRegisterNodeType.emit({type:e,options:t}).prevented)return;const r=new e;this._nodeTypes.set(r.type,{type:e,category:(i=t==null?void 0:t.category)!==null&&i!==void 0?i:"default",title:(s=t==null?void 0:t.title)!==null&&s!==void 0?s:r.title}),this.events.registerNodeType.emit({type:e,options:t})}unregisterNodeType(e){const t=typeof e=="string"?e:new e().type;if(this.nodeTypes.has(t)){if(this.events.beforeUnregisterNodeType.emit(t).prevented)return;this._nodeTypes.delete(t),this.events.unregisterNodeType.emit(t)}}addGraphTemplate(e){if(this.events.beforeAddGraphTemplate.emit(e).prevented)return;this._graphTemplates.push(e),this.graphTemplateEvents.addTarget(e.events),this.graphTemplateHooks.addTarget(e.hooks);const t=Y1t(e);this.registerNodeType(t,{category:"Subgraphs",title:e.name}),this.events.addGraphTemplate.emit(e)}removeGraphTemplate(e){if(this.graphTemplates.includes(e)){if(this.events.beforeRemoveGraphTemplate.emit(e).prevented)return;const t=wa(e);for(const i of[this.graph,...this.graphs.values()]){const s=i.nodes.filter(r=>r.type===t);for(const r of s)i.removeNode(r)}this.unregisterNodeType(t),this._graphTemplates.splice(this._graphTemplates.indexOf(e),1),this.graphTemplateEvents.removeTarget(e.events),this.graphTemplateHooks.removeTarget(e.hooks),this.events.removeGraphTemplate.emit(e)}}registerGraph(e){this.graphEvents.addTarget(e.events),this.graphHooks.addTarget(e.hooks),this.nodeEvents.addTarget(e.nodeEvents),this.nodeHooks.addTarget(e.nodeHooks),this.connectionEvents.addTarget(e.connectionEvents),this.events.registerGraph.emit(e),this._graphs.add(e)}unregisterGraph(e){this.graphEvents.removeTarget(e.events),this.graphHooks.removeTarget(e.hooks),this.nodeEvents.removeTarget(e.nodeEvents),this.nodeHooks.removeTarget(e.nodeHooks),this.connectionEvents.removeTarget(e.connectionEvents),this.events.unregisterGraph.emit(e),this._graphs.delete(e)}load(e){try{this._loading=!0,e=this.hooks.load.execute(e),e.graphTemplates.forEach(i=>{const s=new ep(i,this);this.addGraphTemplate(s)});const t=this._graph.load(e.graph);return this.events.loaded.emit(),t.forEach(i=>console.warn(i)),t}finally{this._loading=!1}}save(){const e={graph:this.graph.save(),graphTemplates:this.graphTemplates.map(t=>t.save())};return this.hooks.save.execute(e)}}function W1t(n,e){const t=new Map;e.graphs.forEach(i=>{i.nodes.forEach(s=>t.set(s.id,s))}),n.forEach((i,s)=>{const r=t.get(s);r&&i.forEach((o,a)=>{const l=r.outputs[a];l&&(l.value=o)})})}class XO extends Error{constructor(){super("Cycle detected")}}function K1t(n){return typeof n=="string"}function ZO(n,e){const t=new Map,i=new Map,s=new Map;let r,o;if(n instanceof mc)r=n.nodes,o=n.connections;else{if(!e)throw new Error("Invalid argument value: expected array of connections");r=n,o=e}r.forEach(c=>{Object.values(c.inputs).forEach(d=>t.set(d.id,c.id)),Object.values(c.outputs).forEach(d=>t.set(d.id,c.id))}),r.forEach(c=>{const d=o.filter(h=>h.from&&t.get(h.from.id)===c.id),u=new Set(d.map(h=>t.get(h.to.id)).filter(K1t));i.set(c.id,u),s.set(c,d)});const a=r.slice();o.forEach(c=>{const d=a.findIndex(u=>t.get(c.to.id)===u.id);d>=0&&a.splice(d,1)});const l=[];for(;a.length>0;){const c=a.pop();l.push(c);const d=i.get(c.id);for(;d.size>0;){const u=d.values().next().value;if(d.delete(u),Array.from(i.values()).every(h=>!h.has(u))){const h=r.find(m=>m.id===u);a.push(h)}}}if(Array.from(i.values()).some(c=>c.size>0))throw new XO;return{calculationOrder:l,connectionsFromNode:s,interfaceIdToNodeId:t}}function j1t(n,e){try{return ZO(n,e),!1}catch(t){if(t instanceof XO)return!0;throw t}}var Hn;(function(n){n.Running="Running",n.Idle="Idle",n.Paused="Paused",n.Stopped="Stopped"})(Hn||(Hn={}));class Q1t{get status(){return this.isRunning?Hn.Running:this.internalStatus}constructor(e){this.editor=e,this.events={beforeRun:new Mn(this),afterRun:new Vt(this),statusChange:new Vt(this),beforeNodeCalculation:new Vt(this),afterNodeCalculation:new Vt(this)},this.hooks={gatherCalculationData:new ii(this),transferData:new qO},this.recalculateOrder=!0,this.internalStatus=Hn.Stopped,this.isRunning=!1,this.editor.nodeEvents.update.subscribe(this,(t,i)=>{i.graph&&!i.graph.loading&&i.graph.activeTransactions===0&&this.internalOnChange(i,t??void 0)}),this.editor.graphEvents.addNode.subscribe(this,(t,i)=>{this.recalculateOrder=!0,!i.loading&&i.activeTransactions===0&&this.internalOnChange()}),this.editor.graphEvents.removeNode.subscribe(this,(t,i)=>{this.recalculateOrder=!0,!i.loading&&i.activeTransactions===0&&this.internalOnChange()}),this.editor.graphEvents.addConnection.subscribe(this,(t,i)=>{this.recalculateOrder=!0,!i.loading&&i.activeTransactions===0&&this.internalOnChange()}),this.editor.graphEvents.removeConnection.subscribe(this,(t,i)=>{this.recalculateOrder=!0,!i.loading&&i.activeTransactions===0&&this.internalOnChange()}),this.editor.graphHooks.checkConnection.subscribe(this,t=>this.checkConnection(t.from,t.to))}start(){this.internalStatus===Hn.Stopped&&(this.internalStatus=Hn.Idle,this.events.statusChange.emit(this.status))}pause(){this.internalStatus===Hn.Idle&&(this.internalStatus=Hn.Paused,this.events.statusChange.emit(this.status))}resume(){this.internalStatus===Hn.Paused&&(this.internalStatus=Hn.Idle,this.events.statusChange.emit(this.status))}stop(){(this.internalStatus===Hn.Idle||this.internalStatus===Hn.Paused)&&(this.internalStatus=Hn.Stopped,this.events.statusChange.emit(this.status))}async runOnce(e,...t){if(this.events.beforeRun.emit(e).prevented)return null;try{this.isRunning=!0,this.events.statusChange.emit(this.status),this.recalculateOrder&&this.calculateOrder();const i=await this.execute(e,...t);return this.events.afterRun.emit(i),i}finally{this.isRunning=!1,this.events.statusChange.emit(this.status)}}checkConnection(e,t){if(e.templateId){const r=this.findInterfaceByTemplateId(this.editor.graph.nodes,e.templateId);if(!r)return{connectionAllowed:!0,connectionsInDanger:[]};e=r}if(t.templateId){const r=this.findInterfaceByTemplateId(this.editor.graph.nodes,t.templateId);if(!r)return{connectionAllowed:!0,connectionsInDanger:[]};t=r}const i=new YO(e,t);let s=this.editor.graph.connections.slice();return t.allowMultipleConnections||(s=s.filter(r=>r.to!==t)),s.push(i),j1t(this.editor.graph.nodes,s)?{connectionAllowed:!1,connectionsInDanger:[]}:{connectionAllowed:!0,connectionsInDanger:t.allowMultipleConnections?[]:this.editor.graph.connections.filter(r=>r.to===t)}}calculateOrder(){this.recalculateOrder=!0}async calculateWithoutData(...e){const t=this.hooks.gatherCalculationData.execute(void 0);return await this.runOnce(t,...e)}validateNodeCalculationOutput(e,t){if(typeof t!="object")throw new Error(`Invalid calculation return value from node ${e.id} (type ${e.type})`);Object.keys(e.outputs).forEach(i=>{if(!(i in t))throw new Error(`Calculation return value from node ${e.id} (type ${e.type}) is missing key "${i}"`)})}internalOnChange(e,t){this.internalStatus===Hn.Idle&&this.onChange(this.recalculateOrder,e,t)}findInterfaceByTemplateId(e,t){for(const i of e)for(const s of[...Object.values(i.inputs),...Object.values(i.outputs)])if(s.templateId===t)return s;return null}}class X1t extends Q1t{constructor(e){super(e),this.order=new Map}start(){super.start(),this.recalculateOrder=!0,this.calculateWithoutData()}async runGraph(e,t,i){this.order.has(e.id)||this.order.set(e.id,ZO(e));const{calculationOrder:s,connectionsFromNode:r}=this.order.get(e.id),o=new Map;for(const a of s){const l={};Object.entries(a.inputs).forEach(([d,u])=>{l[d]=this.getInterfaceValue(t,u.id)}),this.events.beforeNodeCalculation.emit({inputValues:l,node:a});let c;if(a.calculate)c=await a.calculate(l,{globalValues:i,engine:this});else{c={};for(const[d,u]of Object.entries(a.outputs))c[d]=this.getInterfaceValue(t,u.id)}this.validateNodeCalculationOutput(a,c),this.events.afterNodeCalculation.emit({outputValues:c,node:a}),o.set(a.id,new Map(Object.entries(c))),r.has(a)&&r.get(a).forEach(d=>{var u;const h=(u=Object.entries(a.outputs).find(([,f])=>f.id===d.from.id))===null||u===void 0?void 0:u[0];if(!h)throw new Error(`Could not find key for interface ${d.from.id} This is likely a Baklava internal issue. Please report it on GitHub.`);const m=this.hooks.transferData.execute(c[h],d);d.to.allowMultipleConnections?t.has(d.to.id)?t.get(d.to.id).push(m):t.set(d.to.id,[m]):t.set(d.to.id,m)})}return o}async execute(e){this.recalculateOrder&&(this.order.clear(),this.recalculateOrder=!1);const t=this.getInputValues(this.editor.graph);return await this.runGraph(this.editor.graph,t,e)}getInputValues(e){const t=new Map;for(const i of e.nodes)Object.values(i.inputs).forEach(s=>{s.connectionCount===0&&t.set(s.id,s.value)}),i.calculate||Object.values(i.outputs).forEach(s=>{t.set(s.id,s.value)});return t}onChange(e){this.recalculateOrder=e||this.recalculateOrder,this.calculateWithoutData()}getInterfaceValue(e,t){if(!e.has(t))throw new Error(`Could not find value for interface ${t} -This is likely a Baklava internal issue. Please report it on GitHub.`);return e.get(t)}}let Jg=null;function Z1t(n){Jg=n}function yi(){if(!Jg)throw new Error("providePlugin() must be called before usePlugin()");return{viewModel:Jg}}function Ui(){const{viewModel:n}=yi();return{graph:kd(n.value,"displayedGraph"),switchGraph:n.value.switchGraph}}function JO(n){const{graph:e}=Ui(),t=dt(null),i=dt(null);return{dragging:et(()=>!!t.value),onPointerDown:l=>{t.value={x:l.pageX,y:l.pageY},i.value={x:n.value.x,y:n.value.y}},onPointerMove:l=>{if(t.value){const c=l.pageX-t.value.x,d=l.pageY-t.value.y;n.value.x=i.value.x+c/e.value.scaling,n.value.y=i.value.y+d/e.value.scaling}},onPointerUp:()=>{t.value=null,i.value=null}}}function eI(n,e,t){if(!e.template)return!1;if(wa(e.template)===t)return!0;const i=n.graphTemplates.find(r=>wa(r)===t);return i?i.nodes.filter(r=>r.type.startsWith(Jl)).some(r=>eI(n,e,r.type)):!1}function tI(n){return et(()=>{const e=Array.from(n.value.editor.nodeTypes.entries()),t=new Set(e.map(([,s])=>s.category)),i=[];for(const s of t.values()){let r=e.filter(([,o])=>o.category===s);n.value.displayedGraph.template?r=r.filter(([o])=>!eI(n.value.editor,n.value.displayedGraph,o)):r=r.filter(([o])=>![Ra,Aa].includes(o)),r.length>0&&i.push({name:s,nodeTypes:Object.fromEntries(r)})}return i.sort((s,r)=>s.name==="default"?-1:r.name==="default"||s.name>r.name?1:-1),i})}function nI(){const{graph:n}=Ui();return{transform:(t,i)=>{const s=t/n.value.scaling-n.value.panning.x,r=i/n.value.scaling-n.value.panning.y;return[s,r]}}}function J1t(){const{graph:n}=Ui();let e=[],t=-1,i={x:0,y:0};const s=et(()=>n.value.panning),r=JO(s),o=et(()=>({"transform-origin":"0 0",transform:`scale(${n.value.scaling}) translate(${n.value.panning.x}px, ${n.value.panning.y}px)`})),a=(m,f,b)=>{const E=[m/n.value.scaling-n.value.panning.x,f/n.value.scaling-n.value.panning.y],g=[m/b-n.value.panning.x,f/b-n.value.panning.y],S=[g[0]-E[0],g[1]-E[1]];n.value.panning.x+=S[0],n.value.panning.y+=S[1],n.value.scaling=b},l=m=>{m.preventDefault();let f=m.deltaY;m.deltaMode===1&&(f*=32);const b=n.value.scaling*(1-f/3e3);a(m.offsetX,m.offsetY,b)},c=()=>({ax:e[0].clientX,ay:e[0].clientY,bx:e[1].clientX,by:e[1].clientY});return{styles:o,...r,onPointerDown:m=>{if(e.push(m),r.onPointerDown(m),e.length===2){const{ax:f,ay:b,bx:E,by:g}=c();i={x:f+(E-f)/2,y:b+(g-b)/2}}},onPointerMove:m=>{for(let f=0;f0){const C=n.value.scaling*(1+(T-t)/500);a(i.x,i.y,C)}t=T}else r.onPointerMove(m)},onPointerUp:m=>{e=e.filter(f=>f.pointerId!==m.pointerId),t=-1,r.onPointerUp()},onMouseWheel:l}}var _i=(n=>(n[n.NONE=0]="NONE",n[n.ALLOWED=1]="ALLOWED",n[n.FORBIDDEN=2]="FORBIDDEN",n))(_i||{});const iI=Symbol();function eRt(){const{graph:n}=Ui(),e=dt(null),t=dt(null),i=a=>{e.value&&(e.value.mx=a.offsetX/n.value.scaling-n.value.panning.x,e.value.my=a.offsetY/n.value.scaling-n.value.panning.y)},s=()=>{if(t.value){if(e.value)return;const a=n.value.connections.find(l=>l.to===t.value);t.value.isInput&&a?(e.value={status:_i.NONE,from:a.from},n.value.removeConnection(a)):e.value={status:_i.NONE,from:t.value},e.value.mx=void 0,e.value.my=void 0}},r=()=>{if(e.value&&t.value){if(e.value.from===t.value)return;n.value.addConnection(e.value.from,e.value.to)}e.value=null},o=a=>{if(t.value=a??null,a&&e.value){e.value.to=a;const l=n.value.checkConnection(e.value.from,e.value.to);if(e.value.status=l.connectionAllowed?_i.ALLOWED:_i.FORBIDDEN,l.connectionAllowed){const c=l.connectionsInDanger.map(d=>d.id);n.value.connections.forEach(d=>{c.includes(d.id)&&(d.isInDanger=!0)})}}else!a&&e.value&&(e.value.to=void 0,e.value.status=_i.NONE,n.value.connections.forEach(l=>{l.isInDanger=!1}))};return Qo(iI,{temporaryConnection:e,hoveredOver:o}),{temporaryConnection:e,onMouseMove:i,onMouseDown:s,onMouseUp:r,hoveredOver:o}}function tRt(n){const e=dt(!1),t=dt(0),i=dt(0),s=tI(n),{transform:r}=nI(),o=et(()=>{let d=[];const u={};for(const m of s.value){const f=Object.entries(m.nodeTypes).map(([b,E])=>({label:E.title,value:"addNode:"+b}));m.name==="default"?d=f:u[m.name]=f}const h=[...Object.entries(u).map(([m,f])=>({label:m,submenu:f}))];return h.length>0&&d.length>0&&h.push({isDivider:!0}),h.push(...d),h}),a=et(()=>n.value.settings.contextMenu.additionalItems.length===0?o.value:[{label:"Add node",submenu:o.value},...n.value.settings.contextMenu.additionalItems.map(d=>"isDivider"in d||"submenu"in d?d:{label:d.label,value:"command:"+d.command,disabled:!n.value.commandHandler.canExecuteCommand(d.command)})]);function l(d){e.value=!0,t.value=d.offsetX,i.value=d.offsetY}function c(d){if(d.startsWith("addNode:")){const u=d.substring(8),h=n.value.editor.nodeTypes.get(u);if(!h)return;const m=jn(new h.type);n.value.displayedGraph.addNode(m);const[f,b]=r(t.value,i.value);m.position.x=f,m.position.y=b}else if(d.startsWith("command:")){const u=d.substring(8);n.value.commandHandler.canExecuteCommand(u)&&n.value.commandHandler.executeCommand(u)}}return{show:e,x:t,y:i,items:a,open:l,onClick:c}}const nRt=ln({setup(){const{viewModel:n}=yi(),{graph:e}=Ui();return{styles:et(()=>{const i=n.value.settings.background,s=e.value.panning.x*e.value.scaling,r=e.value.panning.y*e.value.scaling,o=e.value.scaling*i.gridSize,a=o/i.gridDivision,l=`${o}px ${o}px, ${o}px ${o}px`,c=e.value.scaling>i.subGridVisibleThreshold?`, ${a}px ${a}px, ${a}px ${a}px`:"";return{backgroundPosition:`left ${s}px top ${r}px`,backgroundSize:`${l} ${c}`}})}}}),cn=(n,e)=>{const t=n.__vccOpts||n;for(const[i,s]of e)t[i]=s;return t};function iRt(n,e,t,i,s,r){return O(),D("div",{class:"background",style:Xt(n.styles)},null,4)}const sRt=cn(nRt,[["render",iRt]]);function rRt(n){return wR()?(zI(n),!0):!1}function qb(n){return typeof n=="function"?n():vt(n)}const sI=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const oRt=Object.prototype.toString,aRt=n=>oRt.call(n)==="[object Object]",Od=()=>{},lRt=cRt();function cRt(){var n,e;return sI&&((n=window==null?void 0:window.navigator)==null?void 0:n.userAgent)&&(/iP(ad|hone|od)/.test(window.navigator.userAgent)||((e=window==null?void 0:window.navigator)==null?void 0:e.maxTouchPoints)>2&&/iPad|Macintosh/.test(window==null?void 0:window.navigator.userAgent))}function dRt(n,e,t=!1){return e.reduce((i,s)=>(s in n&&(!t||n[s]!==void 0)&&(i[s]=n[s]),i),{})}function uRt(n,e={}){if(!un(n))return TM(n);const t=Array.isArray(n.value)?Array.from({length:n.value.length}):{};for(const i in n.value)t[i]=yM(()=>({get(){return n.value[i]},set(s){var r;if((r=qb(e.replaceRef))!=null?r:!0)if(Array.isArray(n.value)){const a=[...n.value];a[i]=s,n.value=a}else{const a={...n.value,[i]:s};Object.setPrototypeOf(a,Object.getPrototypeOf(n.value)),n.value=a}else n.value[i]=s}}));return t}function bl(n){var e;const t=qb(n);return(e=t==null?void 0:t.$el)!=null?e:t}const Yb=sI?window:void 0;function Ml(...n){let e,t,i,s;if(typeof n[0]=="string"||Array.isArray(n[0])?([t,i,s]=n,e=Yb):[e,t,i,s]=n,!e)return Od;Array.isArray(t)||(t=[t]),Array.isArray(i)||(i=[i]);const r=[],o=()=>{r.forEach(d=>d()),r.length=0},a=(d,u,h,m)=>(d.addEventListener(u,h,m),()=>d.removeEventListener(u,h,m)),l=Bn(()=>[bl(e),qb(s)],([d,u])=>{if(o(),!d)return;const h=aRt(u)?{...u}:u;r.push(...t.flatMap(m=>i.map(f=>a(d,m,f,h))))},{immediate:!0,flush:"post"}),c=()=>{l(),o()};return rRt(c),c}let dR=!1;function rI(n,e,t={}){const{window:i=Yb,ignore:s=[],capture:r=!0,detectIframe:o=!1}=t;if(!i)return Od;lRt&&!dR&&(dR=!0,Array.from(i.document.body.children).forEach(h=>h.addEventListener("click",Od)),i.document.documentElement.addEventListener("click",Od));let a=!0;const l=h=>s.some(m=>{if(typeof m=="string")return Array.from(i.document.querySelectorAll(m)).some(f=>f===h.target||h.composedPath().includes(f));{const f=bl(m);return f&&(h.target===f||h.composedPath().includes(f))}}),d=[Ml(i,"click",h=>{const m=bl(n);if(!(!m||m===h.target||h.composedPath().includes(m))){if(h.detail===0&&(a=!l(h)),!a){a=!0;return}e(h)}},{passive:!0,capture:r}),Ml(i,"pointerdown",h=>{const m=bl(n);a=!l(h)&&!!(m&&!h.composedPath().includes(m))},{passive:!0}),o&&Ml(i,"blur",h=>{setTimeout(()=>{var m;const f=bl(n);((m=i.document.activeElement)==null?void 0:m.tagName)==="IFRAME"&&!(f!=null&&f.contains(i.document.activeElement))&&e(h)},0)})].filter(Boolean);return()=>d.forEach(h=>h())}const oI={x:0,y:0,pointerId:0,pressure:0,tiltX:0,tiltY:0,width:0,height:0,twist:0,pointerType:null},pRt=Object.keys(oI);function _Rt(n={}){const{target:e=Yb}=n,t=dt(!1),i=dt(n.initialValue||{});Object.assign(i.value,oI,i.value);const s=r=>{t.value=!0,!(n.pointerTypes&&!n.pointerTypes.includes(r.pointerType))&&(i.value=dRt(r,pRt,!1))};if(e){const r={passive:!0};Ml(e,["pointerdown","pointermove","pointerup"],s,r),Ml(e,"pointerleave",()=>t.value=!1,r)}return{...uRt(i),isInside:t}}const hRt=["onMouseenter","onMouseleave","onClick"],fRt={class:"flex-fill"},mRt={key:0,class:"__submenu-icon",style:{"line-height":"1em"}},gRt=_("svg",{width:"13",height:"13",viewBox:"-60 120 250 250"},[_("path",{d:"M160.875 279.5625 L70.875 369.5625 L70.875 189.5625 L160.875 279.5625 Z",stroke:"none",fill:"white"})],-1),ERt=[gRt],$b=ln({__name:"ContextMenu",props:{modelValue:{type:Boolean},items:{},x:{default:0},y:{default:0},isNested:{type:Boolean,default:!1},isFlipped:{default:()=>({x:!1,y:!1})},flippable:{type:Boolean,default:!1}},emits:["update:modelValue","click"],setup(n,{emit:e}){const t=n,i=e;let s=null;const r=dt(null),o=dt(-1),a=dt(0),l=dt({x:!1,y:!1}),c=et(()=>t.flippable&&(l.value.x||t.isFlipped.x)),d=et(()=>t.flippable&&(l.value.y||t.isFlipped.y)),u=et(()=>{const S={};return t.isNested||(S.top=(d.value?t.y-a.value:t.y)+"px",S.left=t.x+"px"),S}),h=et(()=>({"--flipped-x":c.value,"--flipped-y":d.value,"--nested":t.isNested})),m=et(()=>t.items.map(S=>({...S,hover:!1})));Bn([()=>t.y,()=>t.items],()=>{var S,y,T,C;a.value=t.items.length*30;const x=((y=(S=r.value)==null?void 0:S.parentElement)==null?void 0:y.offsetWidth)??0,w=((C=(T=r.value)==null?void 0:T.parentElement)==null?void 0:C.offsetHeight)??0;l.value.x=!t.isNested&&t.x>x*.75,l.value.y=!t.isNested&&t.y+a.value>w-20}),rI(r,()=>{t.modelValue&&i("update:modelValue",!1)});const f=S=>{!S.submenu&&S.value&&(i("click",S.value),i("update:modelValue",!1))},b=S=>{i("click",S),o.value=-1,t.isNested||i("update:modelValue",!1)},E=(S,y)=>{t.items[y].submenu&&(o.value=y,s!==null&&(clearTimeout(s),s=null))},g=(S,y)=>{t.items[y].submenu&&(s=window.setTimeout(()=>{o.value=-1,s=null},200))};return(S,y)=>{const T=_t("ContextMenu",!0);return O(),Ot(ws,{name:"slide-fade"},{default:ot(()=>[xe(_("div",{ref_key:"el",ref:r,class:He(["baklava-context-menu",h.value]),style:Xt(u.value)},[(O(!0),D($e,null,lt(m.value,(C,x)=>(O(),D($e,null,[C.isDivider?(O(),D("div",{key:`d-${x}`,class:"divider"})):(O(),D("div",{key:`i-${x}`,class:He(["item",{submenu:!!C.submenu,"--disabled":!!C.disabled}]),onMouseenter:w=>E(w,x),onMouseleave:w=>g(w,x),onClick:Te(w=>f(C),["stop","prevent"])},[_("div",fRt,he(C.label),1),C.submenu?(O(),D("div",mRt,ERt)):j("",!0),C.submenu?(O(),Ot(T,{key:1,"model-value":o.value===x,items:C.submenu,"is-nested":!0,"is-flipped":{x:c.value,y:d.value},flippable:S.flippable,onClick:b},null,8,["model-value","items","is-flipped","flippable"])):j("",!0)],42,hRt))],64))),256))],6),[[At,S.modelValue]])]),_:1})}}}),bRt={},SRt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"16",height:"16",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},vRt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),yRt=_("circle",{cx:"12",cy:"12",r:"1"},null,-1),TRt=_("circle",{cx:"12",cy:"19",r:"1"},null,-1),xRt=_("circle",{cx:"12",cy:"5",r:"1"},null,-1),CRt=[vRt,yRt,TRt,xRt];function RRt(n,e){return O(),D("svg",SRt,CRt)}const aI=cn(bRt,[["render",RRt]]),ARt=["id"],wRt={key:0,class:"__tooltip"},NRt={key:2,class:"align-middle"},uR=ln({__name:"NodeInterface",props:{node:{},intf:{}},setup(n){const e=(E,g=100)=>{const S=E!=null&&E.toString?E.toString():"";return S.length>g?S.slice(0,g)+"...":S},t=n,{viewModel:i}=yi(),{hoveredOver:s,temporaryConnection:r}=Ii(iI),o=dt(null),a=et(()=>t.intf.connectionCount>0),l=dt(!1),c=et(()=>i.value.settings.displayValueOnHover&&l.value),d=et(()=>({"--input":t.intf.isInput,"--output":!t.intf.isInput,"--connected":a.value})),u=et(()=>t.intf.component&&(!t.intf.isInput||!t.intf.port||t.intf.connectionCount===0)),h=()=>{l.value=!0,s(t.intf)},m=()=>{l.value=!1,s(void 0)},f=()=>{o.value&&i.value.hooks.renderInterface.execute({intf:t.intf,el:o.value})},b=()=>{const E=i.value.displayedGraph.sidebar;E.nodeId=t.node.id,E.optionName=t.intf.name,E.visible=!0};return Ms(f),nc(f),(E,g)=>{var S;return O(),D("div",{id:E.intf.id,ref_key:"el",ref:o,class:He(["baklava-node-interface",d.value])},[E.intf.port?(O(),D("div",{key:0,class:He(["__port",{"--selected":((S=vt(r))==null?void 0:S.from)===E.intf}]),onPointerover:h,onPointerout:m},[Nn(E.$slots,"portTooltip",{showTooltip:c.value},()=>[c.value===!0?(O(),D("span",wRt,he(e(E.intf.value)),1)):j("",!0)])],34)):j("",!0),u.value?(O(),Ot(Tu(E.intf.component),{key:1,modelValue:E.intf.value,"onUpdate:modelValue":g[0]||(g[0]=y=>E.intf.value=y),node:E.node,intf:E.intf,onOpenSidebar:b},null,40,["modelValue","node","intf"])):(O(),D("span",NRt,he(E.intf.name),1))],10,ARt)}}}),ORt=["id","data-node-type"],IRt={class:"__title-label"},MRt={class:"__menu"},DRt={class:"__outputs"},LRt={class:"__inputs"},kRt=ln({__name:"Node",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag"],setup(n,{emit:e}){const t=n,i=e,{viewModel:s}=yi(),{graph:r,switchGraph:o}=Ui(),a=dt(null),l=dt(!1),c=dt(""),d=dt(null),u=dt(!1),h=dt(!1),m=et(()=>{const P=[{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return t.node.type.startsWith(Jl)&&P.push({value:"editSubgraph",label:"Edit Subgraph"}),P}),f=et(()=>({"--selected":t.selected,"--dragging":t.dragging,"--two-column":!!t.node.twoColumn})),b=et(()=>{var P,U;return{top:`${((P=t.node.position)==null?void 0:P.y)??0}px`,left:`${((U=t.node.position)==null?void 0:U.x)??0}px`,"--width":`${t.node.width??s.value.settings.nodes.defaultWidth}px`}}),E=et(()=>Object.values(t.node.inputs).filter(P=>!P.hidden)),g=et(()=>Object.values(t.node.outputs).filter(P=>!P.hidden)),S=()=>{i("select")},y=P=>{t.selected||S(),i("start-drag",P)},T=()=>{h.value=!0},C=async P=>{var U;switch(P){case"delete":r.value.removeNode(t.node);break;case"rename":c.value=t.node.title,l.value=!0,await Fe(),(U=d.value)==null||U.focus();break;case"editSubgraph":o(t.node.template);break}},x=()=>{t.node.title=c.value,l.value=!1},w=()=>{a.value&&s.value.hooks.renderNode.execute({node:t.node,el:a.value})},R=P=>{u.value=!0,P.preventDefault()},v=P=>{if(!u.value)return;const U=t.node.width+P.movementX/r.value.scaling,Y=s.value.settings.nodes.minWidth,L=s.value.settings.nodes.maxWidth;t.node.width=Math.max(Y,Math.min(L,U))},A=()=>{u.value=!1};return Ms(()=>{w(),window.addEventListener("mousemove",v),window.addEventListener("mouseup",A)}),nc(w),La(()=>{window.removeEventListener("mousemove",v),window.removeEventListener("mouseup",A)}),(P,U)=>(O(),D("div",{id:P.node.id,ref_key:"el",ref:a,class:He(["baklava-node",f.value]),style:Xt(b.value),"data-node-type":P.node.type,onPointerdown:S},[vt(s).settings.nodes.resizable?(O(),D("div",{key:0,class:"__resize-handle",onMousedown:R},null,32)):j("",!0),Nn(P.$slots,"title",{},()=>[_("div",{class:"__title",onPointerdown:Te(y,["self","stop"])},[l.value?xe((O(),D("input",{key:1,ref_key:"renameInputEl",ref:d,"onUpdate:modelValue":U[1]||(U[1]=Y=>c.value=Y),type:"text",class:"baklava-input",placeholder:"Node Name",onBlur:x,onKeydown:mr(x,["enter"])},null,544)),[[Xe,c.value]]):(O(),D($e,{key:0},[_("div",IRt,he(P.node.title),1),_("div",MRt,[Ie(aI,{class:"--clickable",onClick:T}),Ie($b,{modelValue:h.value,"onUpdate:modelValue":U[0]||(U[0]=Y=>h.value=Y),x:0,y:0,items:m.value,onClick:C},null,8,["modelValue","items"])])],64))],32)]),Nn(P.$slots,"content",{},()=>[_("div",{class:"__content",onKeydown:U[2]||(U[2]=mr(Te(()=>{},["stop"]),["delete"]))},[_("div",DRt,[(O(!0),D($e,null,lt(g.value,Y=>Nn(P.$slots,"nodeInterface",{key:Y.id,type:"output",node:P.node,intf:Y},()=>[Ie(uR,{node:P.node,intf:Y},null,8,["node","intf"])])),128))]),_("div",LRt,[(O(!0),D($e,null,lt(E.value,Y=>Nn(P.$slots,"nodeInterface",{key:Y.id,type:"input",node:P.node,intf:Y},()=>[Ie(uR,{node:P.node,intf:Y},null,8,["node","intf"])])),128))])],32)])],46,ORt))}}),PRt=ln({props:{x1:{type:Number,required:!0},y1:{type:Number,required:!0},x2:{type:Number,required:!0},y2:{type:Number,required:!0},state:{type:Number,default:_i.NONE},isTemporary:{type:Boolean,default:!1}},setup(n){const{viewModel:e}=yi(),{graph:t}=Ui(),i=(o,a)=>{const l=(o+t.value.panning.x)*t.value.scaling,c=(a+t.value.panning.y)*t.value.scaling;return[l,c]},s=et(()=>{const[o,a]=i(n.x1,n.y1),[l,c]=i(n.x2,n.y2);if(e.value.settings.useStraightConnections)return`M ${o} ${a} L ${l} ${c}`;{const d=.3*Math.abs(o-l);return`M ${o} ${a} C ${o+d} ${a}, ${l-d} ${c}, ${l} ${c}`}}),r=et(()=>({"--temporary":n.isTemporary,"--allowed":n.state===_i.ALLOWED,"--forbidden":n.state===_i.FORBIDDEN}));return{d:s,classes:r}}}),URt=["d"];function FRt(n,e,t,i,s,r){return O(),D("path",{class:He(["baklava-connection",n.classes]),d:n.d},null,10,URt)}const lI=cn(PRt,[["render",FRt]]);function BRt(n){return document.getElementById(n.id)}function Na(n){const e=document.getElementById(n.id),t=e==null?void 0:e.getElementsByClassName("__port");return{node:(e==null?void 0:e.closest(".baklava-node"))??null,interface:e,port:t&&t.length>0?t[0]:null}}const GRt=ln({components:{"connection-view":lI},props:{connection:{type:Object,required:!0}},setup(n){const{graph:e}=Ui();let t;const i=dt({x1:0,y1:0,x2:0,y2:0}),s=et(()=>n.connection.isInDanger?_i.FORBIDDEN:_i.NONE),r=et(()=>{var c;return(c=e.value.findNodeById(n.connection.from.nodeId))==null?void 0:c.position}),o=et(()=>{var c;return(c=e.value.findNodeById(n.connection.to.nodeId))==null?void 0:c.position}),a=c=>c.node&&c.interface&&c.port?[c.node.offsetLeft+c.interface.offsetLeft+c.port.offsetLeft+c.port.clientWidth/2,c.node.offsetTop+c.interface.offsetTop+c.port.offsetTop+c.port.clientHeight/2]:[0,0],l=()=>{const c=Na(n.connection.from),d=Na(n.connection.to);c.node&&d.node&&(t||(t=new ResizeObserver(()=>{l()}),t.observe(c.node),t.observe(d.node)));const[u,h]=a(c),[m,f]=a(d);i.value={x1:u,y1:h,x2:m,y2:f}};return Ms(async()=>{await Fe(),l()}),La(()=>{t&&t.disconnect()}),Bn([r,o],()=>l(),{deep:!0}),{d:i,state:s}}});function VRt(n,e,t,i,s,r){const o=_t("connection-view");return O(),Ot(o,{x1:n.d.x1,y1:n.d.y1,x2:n.d.x2,y2:n.d.y2,state:n.state},null,8,["x1","y1","x2","y2","state"])}const zRt=cn(GRt,[["render",VRt]]);function cu(n){return n.node&&n.interface&&n.port?[n.node.offsetLeft+n.interface.offsetLeft+n.port.offsetLeft+n.port.clientWidth/2,n.node.offsetTop+n.interface.offsetTop+n.port.offsetTop+n.port.clientHeight/2]:[0,0]}const HRt=ln({components:{"connection-view":lI},props:{connection:{type:Object,required:!0}},setup(n){const e=et(()=>n.connection?n.connection.status:_i.NONE);return{d:et(()=>{if(!n.connection)return{input:[0,0],output:[0,0]};const i=cu(Na(n.connection.from)),s=n.connection.to?cu(Na(n.connection.to)):[n.connection.mx||i[0],n.connection.my||i[1]];return n.connection.from.isInput?{input:s,output:i}:{input:i,output:s}}),status:e}}});function qRt(n,e,t,i,s,r){const o=_t("connection-view");return O(),Ot(o,{x1:n.d.input[0],y1:n.d.input[1],x2:n.d.output[0],y2:n.d.output[1],state:n.status,"is-temporary":""},null,8,["x1","y1","x2","y2","state"])}const YRt=cn(HRt,[["render",qRt]]),$Rt=ln({setup(){const{viewModel:n}=yi(),{graph:e}=Ui(),t=dt(null),i=kd(n.value.settings.sidebar,"width"),s=et(()=>n.value.settings.sidebar.resizable),r=et(()=>{const u=e.value.sidebar.nodeId;return e.value.nodes.find(h=>h.id===u)}),o=et(()=>({width:`${i.value}px`})),a=et(()=>r.value?[...Object.values(r.value.inputs),...Object.values(r.value.outputs)].filter(h=>h.displayInSidebar&&h.component):[]),l=()=>{e.value.sidebar.visible=!1},c=()=>{window.addEventListener("mousemove",d),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",d)},{once:!0})},d=u=>{var h,m;const f=((m=(h=t.value)==null?void 0:h.parentElement)==null?void 0:m.getBoundingClientRect().width)??500;let b=i.value-u.movementX;b<300?b=300:b>.9*f&&(b=.9*f),i.value=b};return{el:t,graph:e,resizable:s,node:r,styles:o,displayedInterfaces:a,startResize:c,close:l}}}),WRt={class:"__header"},KRt={class:"__node-name"};function jRt(n,e,t,i,s,r){return O(),D("div",{ref:"el",class:He(["baklava-sidebar",{"--open":n.graph.sidebar.visible}]),style:Xt(n.styles)},[n.resizable?(O(),D("div",{key:0,class:"__resizer",onMousedown:e[0]||(e[0]=(...o)=>n.startResize&&n.startResize(...o))},null,32)):j("",!0),_("div",WRt,[_("button",{tabindex:"-1",class:"__close",onClick:e[1]||(e[1]=(...o)=>n.close&&n.close(...o))},"×"),_("div",KRt,[_("b",null,he(n.node?n.node.title:""),1)])]),(O(!0),D($e,null,lt(n.displayedInterfaces,o=>(O(),D("div",{key:o.id,class:"__interface"},[(O(),Ot(Tu(o.component),{modelValue:o.value,"onUpdate:modelValue":a=>o.value=a,node:n.node,intf:o},null,8,["modelValue","onUpdate:modelValue","node","intf"]))]))),128))],6)}const QRt=cn($Rt,[["render",jRt]]),XRt=ln({__name:"Minimap",setup(n){const{viewModel:e}=yi(),{graph:t}=Ui(),i=dt(null),s=dt(!1);let r,o=!1,a={x1:0,y1:0,x2:0,y2:0},l;const c=()=>{var x,w;if(!r)return;r.canvas.width=i.value.offsetWidth,r.canvas.height=i.value.offsetHeight;const R=new Map,v=new Map;for(const L of t.value.nodes){const H=BRt(L),B=(H==null?void 0:H.offsetWidth)??0,k=(H==null?void 0:H.offsetHeight)??0,$=((x=L.position)==null?void 0:x.x)??0,K=((w=L.position)==null?void 0:w.y)??0;R.set(L,{x1:$,y1:K,x2:$+B,y2:K+k}),v.set(L,H)}const A={x1:Number.MAX_SAFE_INTEGER,y1:Number.MAX_SAFE_INTEGER,x2:Number.MIN_SAFE_INTEGER,y2:Number.MIN_SAFE_INTEGER};for(const L of R.values())L.x1A.x2&&(A.x2=L.x2),L.y2>A.y2&&(A.y2=L.y2);const P=50;A.x1-=P,A.y1-=P,A.x2+=P,A.y2+=P,a=A;const U=r.canvas.width/r.canvas.height,Y=(a.x2-a.x1)/(a.y2-a.y1);if(U>Y){const L=(U-Y)*(a.y2-a.y1)*.5;a.x1-=L,a.x2+=L}else{const L=a.x2-a.x1,H=a.y2-a.y1,B=(L-U*H)/U*.5;a.y1-=B,a.y2+=B}r.clearRect(0,0,r.canvas.width,r.canvas.height),r.strokeStyle="white";for(const L of t.value.connections){const[H,B]=cu(Na(L.from)),[k,$]=cu(Na(L.to)),[K,W]=d(H,B),[le,J]=d(k,$);if(r.beginPath(),r.moveTo(K,W),e.value.settings.useStraightConnections)r.lineTo(le,J);else{const ee=.3*Math.abs(K-le);r.bezierCurveTo(K+ee,W,le-ee,J,le,J)}r.stroke()}r.strokeStyle="lightgray";for(const[L,H]of R.entries()){const[B,k]=d(H.x1,H.y1),[$,K]=d(H.x2,H.y2);r.fillStyle=h(v.get(L)),r.beginPath(),r.rect(B,k,$-B,K-k),r.fill(),r.stroke()}if(s.value){const L=f(),[H,B]=d(L.x1,L.y1),[k,$]=d(L.x2,L.y2);r.fillStyle="rgba(255, 255, 255, 0.2)",r.fillRect(H,B,k-H,$-B)}},d=(x,w)=>[(x-a.x1)/(a.x2-a.x1)*r.canvas.width,(w-a.y1)/(a.y2-a.y1)*r.canvas.height],u=(x,w)=>[x*(a.x2-a.x1)/r.canvas.width+a.x1,w*(a.y2-a.y1)/r.canvas.height+a.y1],h=x=>{if(x){const w=x.querySelector(".__content");if(w){const v=m(w);if(v)return v}const R=m(x);if(R)return R}return"gray"},m=x=>{const w=getComputedStyle(x).backgroundColor;if(w&&w!=="rgba(0, 0, 0, 0)")return w},f=()=>{const x=i.value.parentElement.offsetWidth,w=i.value.parentElement.offsetHeight,R=x/t.value.scaling-t.value.panning.x,v=w/t.value.scaling-t.value.panning.y;return{x1:-t.value.panning.x,y1:-t.value.panning.y,x2:R,y2:v}},b=x=>{x.button===0&&(o=!0,E(x))},E=x=>{if(o){const[w,R]=u(x.offsetX,x.offsetY),v=f(),A=(v.x2-v.x1)/2,P=(v.y2-v.y1)/2;t.value.panning.x=-(w-A),t.value.panning.y=-(R-P)}},g=()=>{o=!1},S=()=>{s.value=!0},y=()=>{s.value=!1,g()};Bn([s,t.value.panning,()=>t.value.scaling,()=>t.value.connections.length],()=>{c()});const T=et(()=>t.value.nodes.map(x=>x.position)),C=et(()=>t.value.nodes.map(x=>x.width));return Bn([T,C],()=>{c()},{deep:!0}),Ms(()=>{r=i.value.getContext("2d"),r.imageSmoothingQuality="high",c(),l=setInterval(c,500)}),La(()=>{clearInterval(l)}),(x,w)=>(O(),D("canvas",{ref_key:"canvas",ref:i,class:"baklava-minimap",onMouseenter:S,onMouseleave:y,onMousedown:Te(b,["self"]),onMousemove:Te(E,["self"]),onMouseup:g},null,544))}}),ZRt=ln({components:{ContextMenu:$b,VerticalDots:aI},props:{type:{type:String,required:!0},title:{type:String,required:!0}},setup(n){const{viewModel:e}=yi(),{switchGraph:t}=Ui(),i=dt(!1),s=et(()=>n.type.startsWith(Jl));return{showContextMenu:i,hasContextMenu:s,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{i.value=!0},onContextMenuClick:l=>{const c=n.type.substring(Jl.length),d=e.value.editor.graphTemplates.find(u=>u.id===c);if(d)switch(l){case"editSubgraph":t(d);break;case"deleteSubgraph":e.value.editor.removeGraphTemplate(d);break}}}}}),JRt=["data-node-type"],eAt={class:"__title"},tAt={class:"__title-label"},nAt={key:0,class:"__menu"};function iAt(n,e,t,i,s,r){const o=_t("vertical-dots"),a=_t("context-menu");return O(),D("div",{class:"baklava-node --palette","data-node-type":n.type},[_("div",eAt,[_("div",tAt,he(n.title),1),n.hasContextMenu?(O(),D("div",nAt,[Ie(o,{class:"--clickable",onPointerdown:e[0]||(e[0]=Te(()=>{},["stop","prevent"])),onClick:Te(n.openContextMenu,["stop","prevent"])},null,8,["onClick"]),Ie(a,{modelValue:n.showContextMenu,"onUpdate:modelValue":e[1]||(e[1]=l=>n.showContextMenu=l),x:-100,y:0,items:n.contextMenuItems,onClick:n.onContextMenuClick,onPointerdown:e[2]||(e[2]=Te(()=>{},["stop","prevent"]))},null,8,["modelValue","items","onClick"])])):j("",!0)])],8,JRt)}const pR=cn(ZRt,[["render",iAt]]),sAt={class:"baklava-node-palette"},rAt={key:0},oAt=ln({__name:"NodePalette",setup(n){const{viewModel:e}=yi(),{x:t,y:i}=_Rt(),{transform:s}=nI(),r=tI(e),o=Ii("editorEl"),a=dt(null),l=et(()=>{if(!a.value||!(o!=null&&o.value))return{};const{left:d,top:u}=o.value.getBoundingClientRect();return{top:`${i.value-u}px`,left:`${t.value-d}px`}}),c=(d,u)=>{a.value={type:d,nodeInformation:u};const h=()=>{const m=jn(new u.type);e.value.displayedGraph.addNode(m);const f=o.value.getBoundingClientRect(),[b,E]=s(t.value-f.left,i.value-f.top);m.position.x=b,m.position.y=E,a.value=null,document.removeEventListener("pointerup",h)};document.addEventListener("pointerup",h)};return(d,u)=>(O(),D($e,null,[_("div",sAt,[(O(!0),D($e,null,lt(vt(r),h=>(O(),D("section",{key:h.name},[h.name!=="default"?(O(),D("h1",rAt,he(h.name),1)):j("",!0),(O(!0),D($e,null,lt(h.nodeTypes,(m,f)=>(O(),Ot(pR,{key:f,type:f,title:m.title,onPointerdown:b=>c(f,m)},null,8,["type","title","onPointerdown"]))),128))]))),128))]),Ie(ws,{name:"fade"},{default:ot(()=>[a.value?(O(),D("div",{key:0,class:"baklava-dragged-node",style:Xt(l.value)},[Ie(pR,{type:a.value.type,title:a.value.nodeInformation.title},null,8,["type","title"])],4)):j("",!0)]),_:1})],64))}});let fd;const aAt=new Uint8Array(16);function lAt(){if(!fd&&(fd=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!fd))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return fd(aAt)}const vn=[];for(let n=0;n<256;++n)vn.push((n+256).toString(16).slice(1));function cAt(n,e=0){return vn[n[e+0]]+vn[n[e+1]]+vn[n[e+2]]+vn[n[e+3]]+"-"+vn[n[e+4]]+vn[n[e+5]]+"-"+vn[n[e+6]]+vn[n[e+7]]+"-"+vn[n[e+8]]+vn[n[e+9]]+"-"+vn[n[e+10]]+vn[n[e+11]]+vn[n[e+12]]+vn[n[e+13]]+vn[n[e+14]]+vn[n[e+15]]}const dAt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_R={randomUUID:dAt};function du(n,e,t){if(_R.randomUUID&&!e&&!n)return _R.randomUUID();n=n||{};const i=n.random||(n.rng||lAt)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let s=0;s<16;++s)e[t+s]=i[s];return e}return cAt(i)}const ec="SAVE_SUBGRAPH";function uAt(n,e){const t=()=>{const i=n.value;if(!i.template)throw new Error("Graph template property not set");i.template.update(i.save()),i.template.panning=i.panning,i.template.scaling=i.scaling};e.registerCommand(ec,{canExecute:()=>{var i;return n.value!==((i=n.value.editor)==null?void 0:i.graph)},execute:t})}const pAt={},_At={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},hAt=_("polyline",{points:"6 9 12 15 18 9"},null,-1),fAt=[hAt];function mAt(n,e){return O(),D("svg",_At,fAt)}const gAt=cn(pAt,[["render",mAt]]),EAt=ln({components:{"i-arrow":gAt},props:{intf:{type:Object,required:!0}},setup(n){const e=dt(null),t=dt(!1),i=et(()=>n.intf.items.find(o=>typeof o=="string"?o===n.intf.value:o.value===n.intf.value)),s=et(()=>i.value?typeof i.value=="string"?i.value:i.value.text:""),r=o=>{n.intf.value=typeof o=="string"?o:o.value};return rI(e,()=>{t.value=!1}),{el:e,open:t,selectedItem:i,selectedText:s,setSelected:r}}}),bAt=["title"],SAt={class:"__selected"},vAt={class:"__text"},yAt={class:"__icon"},TAt={class:"__dropdown"},xAt={class:"item --header"},CAt=["onClick"];function RAt(n,e,t,i,s,r){const o=_t("i-arrow");return O(),D("div",{ref:"el",class:He(["baklava-select",{"--open":n.open}]),title:n.intf.name,onClick:e[0]||(e[0]=a=>n.open=!n.open)},[_("div",SAt,[_("div",vAt,he(n.selectedText),1),_("div",yAt,[Ie(o)])]),Ie(ws,{name:"slide-fade"},{default:ot(()=>[xe(_("div",TAt,[_("div",xAt,he(n.intf.name),1),(O(!0),D($e,null,lt(n.intf.items,(a,l)=>(O(),D("div",{key:l,class:He(["item",{"--active":a===n.selectedItem}]),onClick:c=>n.setSelected(a)},he(typeof a=="string"?a:a.text),11,CAt))),128))],512),[[At,n.open]])]),_:1})],10,bAt)}const AAt=cn(EAt,[["render",RAt]]);class wAt extends pn{constructor(e,t,i){super(e,t),this.component=tc(AAt),this.items=i}}const NAt=ln({props:{intf:{type:Object,required:!0}}});function OAt(n,e,t,i,s,r){return O(),D("div",null,he(n.intf.value),1)}const IAt=cn(NAt,[["render",OAt]]);class MAt extends pn{constructor(e,t){super(e,t),this.component=tc(IAt),this.setPort(!1)}}const DAt=ln({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(n,{emit:e}){return{v:et({get:()=>n.modelValue,set:i=>{e("update:modelValue",i)}})}}}),LAt=["placeholder","title"];function kAt(n,e,t,i,s,r){return O(),D("div",null,[xe(_("input",{"onUpdate:modelValue":e[0]||(e[0]=o=>n.v=o),type:"text",class:"baklava-input",placeholder:n.intf.name,title:n.intf.name},null,8,LAt),[[Xe,n.v]])])}const PAt=cn(DAt,[["render",kAt]]);class tp extends pn{constructor(){super(...arguments),this.component=tc(PAt)}}class cI extends jO{constructor(){super(...arguments),this._title="Subgraph Input",this.inputs={name:new tp("Name","Input").setPort(!1)},this.outputs={placeholder:new pn("Connection",void 0)}}}class dI extends QO{constructor(){super(...arguments),this._title="Subgraph Output",this.inputs={name:new tp("Name","Output").setPort(!1),placeholder:new pn("Connection",void 0)},this.outputs={output:new pn("Output",void 0).setHidden(!0)}}}const uI="CREATE_SUBGRAPH",hR=[Ra,Aa];function UAt(n,e,t){const i=()=>n.value.selectedNodes.filter(r=>!hR.includes(r.type)).length>0,s=()=>{const{viewModel:r}=yi(),o=n.value,a=n.value.editor;if(o.selectedNodes.length===0)return;const l=o.selectedNodes.filter(v=>!hR.includes(v.type)),c=l.flatMap(v=>Object.values(v.inputs)),d=l.flatMap(v=>Object.values(v.outputs)),u=o.connections.filter(v=>!d.includes(v.from)&&c.includes(v.to)),h=o.connections.filter(v=>d.includes(v.from)&&!c.includes(v.to)),m=o.connections.filter(v=>d.includes(v.from)&&c.includes(v.to)),f=l.map(v=>v.save()),b=m.map(v=>({id:v.id,from:v.from.id,to:v.to.id})),E=new Map,{xLeft:g,xRight:S,yTop:y}=FAt(l);console.log(g,S,y);for(const[v,A]of u.entries()){const P=new cI;P.inputs.name.value=A.to.name,f.push({...P.save(),position:{x:S-r.value.settings.nodes.defaultWidth-100,y:y+v*200}}),b.push({id:du(),from:P.outputs.placeholder.id,to:A.to.id}),E.set(A.to.id,P.graphInterfaceId)}for(const[v,A]of h.entries()){const P=new dI;P.inputs.name.value=A.from.name,f.push({...P.save(),position:{x:g+100,y:y+v*200}}),b.push({id:du(),from:A.from.id,to:P.inputs.placeholder.id}),E.set(A.from.id,P.graphInterfaceId)}const T=jn(new ep({connections:b,nodes:f,inputs:[],outputs:[]},a));a.addGraphTemplate(T);const C=a.nodeTypes.get(wa(T));if(!C)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");const x=jn(new C.type);o.addNode(x);const w=Math.round(l.map(v=>v.position.x).reduce((v,A)=>v+A,0)/l.length),R=Math.round(l.map(v=>v.position.y).reduce((v,A)=>v+A,0)/l.length);x.position.x=w,x.position.y=R,u.forEach(v=>{o.removeConnection(v),o.addConnection(v.from,x.inputs[E.get(v.to.id)])}),h.forEach(v=>{o.removeConnection(v),o.addConnection(x.outputs[E.get(v.from.id)],v.to)}),l.forEach(v=>o.removeNode(v)),e.canExecuteCommand(ec)&&e.executeCommand(ec),t(T),n.value.panning={...o.panning},n.value.scaling=o.scaling};e.registerCommand(uI,{canExecute:i,execute:s})}function FAt(n){const e=n.reduce((s,r)=>{const o=r.position.x;return o{const o=r.position.y;return o{const o=r.position.x+r.width;return o>s?o:s},-1/0),xRight:e,yTop:t}}const fR="DELETE_NODES";function BAt(n,e){e.registerCommand(fR,{canExecute:()=>n.value.selectedNodes.length>0,execute(){n.value.selectedNodes.forEach(t=>n.value.removeNode(t))}}),e.registerHotkey(["Delete"],fR)}const pI="SWITCH_TO_MAIN_GRAPH";function GAt(n,e,t){e.registerCommand(pI,{canExecute:()=>n.value!==n.value.editor.graph,execute:()=>{e.executeCommand(ec),t(n.value.editor.graph)}})}function VAt(n,e,t){BAt(n,e),UAt(n,e,t),uAt(n,e),GAt(n,e,t)}class mR{constructor(e,t){this.type=e,e==="addNode"?this.nodeId=t:this.nodeState=t}undo(e){this.type==="addNode"?this.removeNode(e):this.addNode(e)}redo(e){this.type==="addNode"&&this.nodeState?this.addNode(e):this.type==="removeNode"&&this.nodeId&&this.removeNode(e)}addNode(e){const t=e.editor.nodeTypes.get(this.nodeState.type);if(!t)return;const i=new t.type;e.addNode(i),i.load(this.nodeState),this.nodeId=i.id}removeNode(e){const t=e.nodes.find(i=>i.id===this.nodeId);t&&(this.nodeState=t.save(),e.removeNode(t))}}class gR{constructor(e,t){if(this.type=e,e==="addConnection")this.connectionId=t;else{const i=t;this.connectionState={id:i.id,from:i.from.id,to:i.to.id}}}undo(e){this.type==="addConnection"?this.removeConnection(e):this.addConnection(e)}redo(e){this.type==="addConnection"&&this.connectionState?this.addConnection(e):this.type==="removeConnection"&&this.connectionId&&this.removeConnection(e)}addConnection(e){const t=e.findNodeInterface(this.connectionState.from),i=e.findNodeInterface(this.connectionState.to);!t||!i||e.addConnection(t,i)}removeConnection(e){const t=e.connections.find(i=>i.id===this.connectionId);t&&(this.connectionState={id:t.id,from:t.from.id,to:t.to.id},e.removeConnection(t))}}class zAt{constructor(e){if(this.type="transaction",e.length===0)throw new Error("Can't create a transaction with no steps");this.steps=e}undo(e){for(let t=this.steps.length-1;t>=0;t--)this.steps[t].undo(e)}redo(e){for(let t=0;t{if(!r.value)if(a.value)l.value.push(E);else for(o.value!==s.value.length-1&&(s.value=s.value.slice(0,o.value+1)),s.value.push(E),o.value++;s.value.length>i.value;)s.value.shift()},d=()=>{a.value=!0},u=()=>{a.value=!1,l.value.length>0&&(c(new zAt(l.value)),l.value=[])},h=()=>s.value.length!==0&&o.value!==-1,m=()=>{h()&&(r.value=!0,s.value[o.value--].undo(n.value),r.value=!1)},f=()=>s.value.length!==0&&o.value{f()&&(r.value=!0,s.value[++o.value].redo(n.value),r.value=!1)};return Bn(n,(E,g)=>{g&&(g.events.addNode.unsubscribe(t),g.events.removeNode.unsubscribe(t),g.events.addConnection.unsubscribe(t),g.events.removeConnection.unsubscribe(t)),E&&(E.events.addNode.subscribe(t,S=>{c(new mR("addNode",S.id))}),E.events.removeNode.subscribe(t,S=>{c(new mR("removeNode",S.save()))}),E.events.addConnection.subscribe(t,S=>{c(new gR("addConnection",S.id))}),E.events.removeConnection.subscribe(t,S=>{c(new gR("removeConnection",S))}))},{immediate:!0}),e.registerCommand(eE,{canExecute:h,execute:m}),e.registerCommand(tE,{canExecute:f,execute:b}),e.registerCommand(_I,{canExecute:()=>!a.value,execute:d}),e.registerCommand(hI,{canExecute:()=>a.value,execute:u}),e.registerHotkey(["Control","z"],eE),e.registerHotkey(["Control","y"],tE),jn({maxSteps:i})}const nE="COPY",iE="PASTE",qAt="CLEAR_CLIPBOARD";function YAt(n,e,t){const i=Symbol("ClipboardToken"),s=dt(""),r=dt(""),o=et(()=>!s.value),a=()=>{s.value="",r.value=""},l=()=>{const u=n.value.selectedNodes.flatMap(m=>[...Object.values(m.inputs),...Object.values(m.outputs)]),h=n.value.connections.filter(m=>u.includes(m.from)||u.includes(m.to)).map(m=>({from:m.from.id,to:m.to.id}));r.value=JSON.stringify(h),s.value=JSON.stringify(n.value.selectedNodes.map(m=>m.save()))},c=(u,h,m)=>{for(const f of u){let b;if((!m||m==="input")&&(b=Object.values(f.inputs).find(E=>E.id===h)),!b&&(!m||m==="output")&&(b=Object.values(f.outputs).find(E=>E.id===h)),b)return b}},d=()=>{if(o.value)return;const u=new Map,h=JSON.parse(s.value),m=JSON.parse(r.value),f=[],b=[],E=n.value;t.executeCommand(_I);for(const g of h){const S=e.value.nodeTypes.get(g.type);if(!S){console.warn(`Node type ${g.type} not registered`);return}const y=new S.type,T=y.id;f.push(y),y.hooks.beforeLoad.subscribe(i,C=>{const x=C;return x.position&&(x.position.x+=100,x.position.y+=100),y.hooks.beforeLoad.unsubscribe(i),x}),E.addNode(y),y.load({...g,id:T}),y.id=T,u.set(g.id,T);for(const C of Object.values(y.inputs)){const x=du();u.set(C.id,x),C.id=x}for(const C of Object.values(y.outputs)){const x=du();u.set(C.id,x),C.id=x}}for(const g of m){const S=c(f,u.get(g.from),"output"),y=c(f,u.get(g.to),"input");if(!S||!y)continue;const T=E.addConnection(S,y);T&&b.push(T)}return n.value.selectedNodes=f,t.executeCommand(hI),{newNodes:f,newConnections:b}};return t.registerCommand(nE,{canExecute:()=>n.value.selectedNodes.length>0,execute:l}),t.registerHotkey(["Control","c"],nE),t.registerCommand(iE,{canExecute:()=>!o.value,execute:d}),t.registerHotkey(["Control","v"],iE),t.registerCommand(qAt,{canExecute:()=>!0,execute:a}),jn({isEmpty:o})}const $At="OPEN_SIDEBAR";function WAt(n,e){e.registerCommand($At,{execute:t=>{n.value.sidebar.nodeId=t,n.value.sidebar.visible=!0},canExecute:()=>!0})}function KAt(n,e){WAt(n,e)}const jAt={},QAt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},XAt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),ZAt=_("path",{d:"M9 13l-4 -4l4 -4m-4 4h11a4 4 0 0 1 0 8h-1"},null,-1),JAt=[XAt,ZAt];function ewt(n,e){return O(),D("svg",QAt,JAt)}const twt=cn(jAt,[["render",ewt]]),nwt={},iwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},swt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),rwt=_("path",{d:"M15 13l4 -4l-4 -4m4 4h-11a4 4 0 0 0 0 8h1"},null,-1),owt=[swt,rwt];function awt(n,e){return O(),D("svg",iwt,owt)}const lwt=cn(nwt,[["render",awt]]),cwt={},dwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},uwt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),pwt=_("line",{x1:"5",y1:"12",x2:"19",y2:"12"},null,-1),_wt=_("line",{x1:"5",y1:"12",x2:"11",y2:"18"},null,-1),hwt=_("line",{x1:"5",y1:"12",x2:"11",y2:"6"},null,-1),fwt=[uwt,pwt,_wt,hwt];function mwt(n,e){return O(),D("svg",dwt,fwt)}const gwt=cn(cwt,[["render",mwt]]),Ewt={},bwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},Swt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),vwt=_("path",{d:"M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2"},null,-1),ywt=_("rect",{x:"9",y:"3",width:"6",height:"4",rx:"2"},null,-1),Twt=[Swt,vwt,ywt];function xwt(n,e){return O(),D("svg",bwt,Twt)}const Cwt=cn(Ewt,[["render",xwt]]),Rwt={},Awt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},wwt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),Nwt=_("rect",{x:"8",y:"8",width:"12",height:"12",rx:"2"},null,-1),Owt=_("path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"},null,-1),Iwt=[wwt,Nwt,Owt];function Mwt(n,e){return O(),D("svg",Awt,Iwt)}const Dwt=cn(Rwt,[["render",Mwt]]),Lwt={},kwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},Pwt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),Uwt=_("path",{d:"M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2"},null,-1),Fwt=_("circle",{cx:"12",cy:"14",r:"2"},null,-1),Bwt=_("polyline",{points:"14 4 14 8 8 8 8 4"},null,-1),Gwt=[Pwt,Uwt,Fwt,Bwt];function Vwt(n,e){return O(),D("svg",kwt,Gwt)}const zwt=cn(Lwt,[["render",Vwt]]),Hwt={},qwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},Ywt=Ru('',6),$wt=[Ywt];function Wwt(n,e){return O(),D("svg",qwt,$wt)}const Kwt=cn(Hwt,[["render",Wwt]]),jwt=ln({props:{command:{type:String,required:!0},title:{type:String,required:!0},icon:{type:Object,required:!1,default:void 0}},setup(){const{viewModel:n}=yi();return{viewModel:n}}}),Qwt=["disabled","title"];function Xwt(n,e,t,i,s,r){return O(),D("button",{class:"baklava-toolbar-entry baklava-toolbar-button",disabled:!n.viewModel.commandHandler.canExecuteCommand(n.command),title:n.title,onClick:e[0]||(e[0]=o=>n.viewModel.commandHandler.executeCommand(n.command))},[n.icon?(O(),Ot(Tu(n.icon),{key:0})):(O(),D($e,{key:1},[je(he(n.title),1)],64))],8,Qwt)}const Zwt=cn(jwt,[["render",Xwt]]),Jwt=ln({components:{ToolbarButton:Zwt},setup(){const{viewModel:n}=yi();return{isSubgraph:et(()=>n.value.displayedGraph!==n.value.editor.graph),commands:[{command:nE,title:"Copy",icon:Dwt},{command:iE,title:"Paste",icon:Cwt},{command:eE,title:"Undo",icon:twt},{command:tE,title:"Redo",icon:lwt},{command:uI,title:"Create Subgraph",icon:Kwt}],subgraphCommands:[{command:ec,title:"Save Subgraph",icon:zwt},{command:pI,title:"Back to Main Graph",icon:gwt}]}}}),eNt={class:"baklava-toolbar"};function tNt(n,e,t,i,s,r){const o=_t("toolbar-button");return O(),D("div",eNt,[(O(!0),D($e,null,lt(n.commands,a=>(O(),Ot(o,{key:a.command,command:a.command,title:a.title,icon:a.icon},null,8,["command","title","icon"]))),128)),n.isSubgraph?(O(!0),D($e,{key:0},lt(n.subgraphCommands,a=>(O(),Ot(o,{key:a.command,command:a.command,title:a.title,icon:a.icon},null,8,["command","title","icon"]))),128)):j("",!0)])}const nNt=cn(Jwt,[["render",tNt]]),iNt={class:"connections-container"},sNt=ln({__name:"Editor",props:{viewModel:{}},setup(n){const e=n,t=Symbol("EditorToken"),i=kd(e,"viewModel");Z1t(i);const s=dt(null);Qo("editorEl",s);const r=et(()=>e.viewModel.displayedGraph.nodes),o=et(()=>e.viewModel.displayedGraph.nodes.map(w=>JO(kd(w,"position")))),a=et(()=>e.viewModel.displayedGraph.connections),l=et(()=>e.viewModel.displayedGraph.selectedNodes),c=J1t(),d=eRt(),u=tRt(i),h=et(()=>({...c.styles.value})),m=dt(0);e.viewModel.editor.hooks.load.subscribe(t,w=>(m.value++,w));const f=w=>{c.onPointerMove(w),d.onMouseMove(w)},b=w=>{w.button===0&&(w.target===s.value&&(T(),c.onPointerDown(w)),d.onMouseDown())},E=w=>{c.onPointerUp(w),d.onMouseUp()},g=w=>{w.key==="Tab"&&w.preventDefault(),e.viewModel.commandHandler.handleKeyDown(w)},S=w=>{e.viewModel.commandHandler.handleKeyUp(w)},y=w=>{["Control","Shift"].some(R=>e.viewModel.commandHandler.pressedKeys.includes(R))||T(),e.viewModel.displayedGraph.selectedNodes.push(w)},T=()=>{e.viewModel.displayedGraph.selectedNodes=[]},C=w=>{for(const R of e.viewModel.displayedGraph.selectedNodes){const v=r.value.indexOf(R),A=o.value[v];A.onPointerDown(w),document.addEventListener("pointermove",A.onPointerMove)}document.addEventListener("pointerup",x)},x=()=>{for(const w of e.viewModel.displayedGraph.selectedNodes){const R=r.value.indexOf(w),v=o.value[R];v.onPointerUp(),document.removeEventListener("pointermove",v.onPointerMove)}document.removeEventListener("pointerup",x)};return(w,R)=>(O(),D("div",{ref_key:"el",ref:s,tabindex:"-1",class:He(["baklava-editor",{"baklava-ignore-mouse":!!vt(d).temporaryConnection.value||vt(c).dragging.value,"--temporary-connection":!!vt(d).temporaryConnection.value}]),onPointermove:Te(f,["self"]),onPointerdown:b,onPointerup:E,onWheel:R[1]||(R[1]=Te((...v)=>vt(c).onMouseWheel&&vt(c).onMouseWheel(...v),["self"])),onKeydown:g,onKeyup:S,onContextmenu:R[2]||(R[2]=Te((...v)=>vt(u).open&&vt(u).open(...v),["self","prevent"]))},[Nn(w.$slots,"background",{},()=>[Ie(sRt)]),Nn(w.$slots,"toolbar",{},()=>[Ie(nNt)]),Nn(w.$slots,"palette",{},()=>[Ie(oAt)]),(O(),D("svg",iNt,[(O(!0),D($e,null,lt(a.value,v=>(O(),D("g",{key:v.id+m.value.toString()},[Nn(w.$slots,"connection",{connection:v},()=>[Ie(zRt,{connection:v},null,8,["connection"])])]))),128)),Nn(w.$slots,"temporaryConnection",{temporaryConnection:vt(d).temporaryConnection.value},()=>[vt(d).temporaryConnection.value?(O(),Ot(YRt,{key:0,connection:vt(d).temporaryConnection.value},null,8,["connection"])):j("",!0)])])),_("div",{class:"node-container",style:Xt(h.value)},[Ie(ys,{name:"fade"},{default:ot(()=>[(O(!0),D($e,null,lt(r.value,(v,A)=>Nn(w.$slots,"node",{key:v.id+m.value.toString(),node:v,selected:l.value.includes(v),dragging:o.value[A].dragging.value,onSelect:P=>y(v),onStartDrag:C},()=>[Ie(kRt,{node:v,selected:l.value.includes(v),dragging:o.value[A].dragging.value,onSelect:P=>y(v),onStartDrag:C},null,8,["node","selected","dragging","onSelect"])])),128))]),_:3})],4),Nn(w.$slots,"sidebar",{},()=>[Ie(QRt)]),Nn(w.$slots,"minimap",{},()=>[w.viewModel.settings.enableMinimap?(O(),Ot(XRt,{key:0})):j("",!0)]),Nn(w.$slots,"contextMenu",{contextMenu:vt(u)},()=>[w.viewModel.settings.contextMenu.enabled?(O(),Ot($b,{key:0,modelValue:vt(u).show.value,"onUpdate:modelValue":R[0]||(R[0]=v=>vt(u).show.value=v),items:vt(u).items.value,x:vt(u).x.value,y:vt(u).y.value,onClick:vt(u).onClick},null,8,["modelValue","items","x","y","onClick"])):j("",!0)])],34))}}),rNt=["INPUT","TEXTAREA","SELECT"];function oNt(n){const e=dt([]),t=dt([]);return{pressedKeys:e,handleKeyDown:o=>{var a;e.value.includes(o.key)||e.value.push(o.key),!rNt.includes(((a=document.activeElement)==null?void 0:a.tagName)??"")&&t.value.forEach(l=>{l.keys.every(c=>e.value.includes(c))&&n(l.commandName)})},handleKeyUp:o=>{const a=e.value.indexOf(o.key);a>=0&&e.value.splice(a,1)},registerHotkey:(o,a)=>{t.value.push({keys:o,commandName:a})}}}const aNt=()=>{const n=dt(new Map),e=(r,o)=>{if(n.value.has(r))throw new Error(`Command "${r}" already exists`);n.value.set(r,o)},t=(r,o=!1,...a)=>{if(!n.value.has(r)){if(o)throw new Error(`[CommandHandler] Command ${r} not registered`);return}return n.value.get(r).execute(...a)},i=(r,o=!1,...a)=>{if(!n.value.has(r)){if(o)throw new Error(`[CommandHandler] Command ${r} not registered`);return!1}return n.value.get(r).canExecute(a)},s=oNt(t);return jn({registerCommand:e,executeCommand:t,canExecuteCommand:i,...s})},lNt=n=>!(n instanceof mc);function cNt(n,e){return{switchGraph:i=>{let s;if(lNt(i))s=new mc(n.value),i.createGraph(s);else{if(i!==n.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");s=i}e.value&&e.value!==n.value.graph&&e.value.destroy(),s.panning=s.panning??i.panning??{x:0,y:0},s.scaling=s.scaling??i.scaling??1,s.selectedNodes=s.selectedNodes??[],s.sidebar=s.sidebar??{visible:!1,nodeId:"",optionName:""},e.value=s}}}function dNt(n,e){n.position=n.position??{x:0,y:0},n.disablePointerEvents=!1,n.twoColumn=n.twoColumn??!1,n.width=n.width??e.defaultWidth}const uNt=()=>({useStraightConnections:!1,enableMinimap:!1,background:{gridSize:100,gridDivision:5,subGridVisibleThreshold:.6},sidebar:{width:300,resizable:!0},displayValueOnHover:!1,nodes:{defaultWidth:200,maxWidth:320,minWidth:150,resizable:!1},contextMenu:{enabled:!0,additionalItems:[]}});function pNt(n){const e=dt(n??new $1t),t=Symbol("ViewModelToken"),i=dt(null),s=gM(i),{switchGraph:r}=cNt(e,i),o=et(()=>s.value&&s.value!==e.value.graph),a=jn(uNt()),l=aNt(),c=HAt(s,l),d=YAt(s,e,l),u={renderNode:new ii(null),renderInterface:new ii(null)};return VAt(s,l,r),KAt(s,l),Bn(e,(h,m)=>{m&&(m.events.registerGraph.unsubscribe(t),m.graphEvents.beforeAddNode.unsubscribe(t),h.nodeHooks.beforeLoad.unsubscribe(t),h.nodeHooks.afterSave.unsubscribe(t),h.graphTemplateHooks.beforeLoad.unsubscribe(t),h.graphTemplateHooks.afterSave.unsubscribe(t),h.graph.hooks.load.unsubscribe(t),h.graph.hooks.save.unsubscribe(t)),h&&(h.nodeHooks.beforeLoad.subscribe(t,(f,b)=>(b.position=f.position??{x:0,y:0},b.width=f.width??a.nodes.defaultWidth,b.twoColumn=f.twoColumn??!1,f)),h.nodeHooks.afterSave.subscribe(t,(f,b)=>(f.position=b.position,f.width=b.width,f.twoColumn=b.twoColumn,f)),h.graphTemplateHooks.beforeLoad.subscribe(t,(f,b)=>(b.panning=f.panning,b.scaling=f.scaling,f)),h.graphTemplateHooks.afterSave.subscribe(t,(f,b)=>(f.panning=b.panning,f.scaling=b.scaling,f)),h.graph.hooks.load.subscribe(t,(f,b)=>(b.panning=f.panning,b.scaling=f.scaling,f)),h.graph.hooks.save.subscribe(t,(f,b)=>(f.panning=b.panning,f.scaling=b.scaling,f)),h.graphEvents.beforeAddNode.subscribe(t,f=>dNt(f,{defaultWidth:a.nodes.defaultWidth})),e.value.registerNodeType(cI,{category:"Subgraphs"}),e.value.registerNodeType(dI,{category:"Subgraphs"}),r(h.graph))},{immediate:!0}),jn({editor:e,displayedGraph:s,isSubgraph:o,settings:a,commandHandler:l,history:c,clipboard:d,hooks:u,switchGraph:r})}const ER=Hb({type:"AgentNode",title:"Agent",inputs:{request:()=>new pn("Request",""),agent_name:()=>new wAt("Agent name","",sE.state.config.personalities).setPort(!1)},outputs:{display:()=>new MAt("Output",""),response:()=>new pn("Response","")},async calculate({request:n}){console.log(sE.state.config.personalities);let e="";try{e=(await Ue.get("/generate",{params:{text:n}})).data}catch(t){console.error(t)}return{display:e,response:e}}}),_Nt=Hb({type:"RAGNode",title:"RAG",inputs:{request:()=>new pn("Prompt",""),document_path:()=>new tp("Document path","").setPort(!1)},outputs:{prompt:()=>new pn("Prompt with Data","")},async calculate({request:n,document_path:e}){let t="";try{t=(await Ue.get("/rag",{params:{text:n,doc_path:e}})).data}catch(i){console.error(i)}return{response:t}}}),bR=Hb({type:"Task",title:"Task",inputs:{description:()=>new tp("Task description","").setPort(!1)},outputs:{prompt:()=>new pn("Prompt")},calculate({description:n}){return{prompt:n}}}),hNt=ln({components:{"baklava-editor":sNt},setup(){const n=pNt(),e=new X1t(n.editor);n.editor.registerNodeType(ER),n.editor.registerNodeType(bR),n.editor.registerNodeType(_Nt);const t=Symbol();e.events.afterRun.subscribe(t,o=>{e.pause(),W1t(o,n.editor),e.resume()}),e.start();function i(o,a,l){const c=new o;return n.displayedGraph.addNode(c),c.position.x=a,c.position.y=l,c}const s=i(bR,300,140),r=i(ER,550,140);return n.displayedGraph.addConnection(s.outputs.result,r.inputs.value),{baklava:n,saveGraph:()=>{const o=e.export();localStorage.setItem("myGraph",JSON.stringify(o))},loadGraph:()=>{const o=JSON.parse(localStorage.getItem("myGraph"));e.import(o)}}}}),fNt={style:{width:"100vw",height:"100vh"}};function mNt(n,e,t,i,s,r){const o=_t("baklava-editor");return O(),D("div",fNt,[Ie(o,{"view-model":n.baklava},null,8,["view-model"]),_("button",{onClick:e[0]||(e[0]=(...a)=>n.saveGraph&&n.saveGraph(...a))},"Save Graph"),_("button",{onClick:e[1]||(e[1]=(...a)=>n.loadGraph&&n.loadGraph(...a))},"Load Graph")])}const gNt=gt(hNt,[["render",mNt]]),ENt=Zk({history:mk("/"),routes:[{path:"/playground/",name:"playground",component:KZe},{path:"/extensions/",name:"extensions",component:rJe},{path:"/help/",name:"help",component:CJe},{path:"/settings/",name:"settings",component:Kut},{path:"/training/",name:"training",component:fpt},{path:"/quantizing/",name:"quantizing",component:xpt},{path:"/",name:"discussions",component:Tbt},{path:"/",name:"interactive",component:B1t},{path:"/",name:"nodes",component:gNt}]});const np=l2(NB);console.log("Loaded main.js");function SR(n){const e={};for(const t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e}const sE=k2({state(){return{yesNoDialog:null,universalForm:null,toast:null,messageBox:null,api_get_req:null,startSpeechRecognition:null,ready:!1,loading_infos:"",loading_progress:0,version:"unknown",settingsChanged:!1,isConnected:!1,isModelOk:!1,isGenerating:!1,config:null,mountedPers:null,mountedPersArr:[],mountedExtensions:[],bindingsZoo:[],modelsArr:[],selectedModel:null,personalities:[],diskUsage:null,ramUsage:null,vramUsage:null,modelsZoo:[],installedModels:[],currentModel:null,extensionsZoo:[],databases:[]}},mutations:{setIsReady(n,e){n.ready=e},setIsConnected(n,e){n.isConnected=e},setIsModelOk(n,e){n.isModelOk=e},setIsGenerating(n,e){n.isGenerating=e},setConfig(n,e){n.config=e},setPersonalities(n,e){n.personalities=e},setMountedPers(n,e){n.mountedPers=e},setMountedPersArr(n,e){n.mountedPersArr=e},setMountedExtensions(n,e){n.mountedExtensions=e},setbindingsZoo(n,e){n.bindingsZoo=e},setModelsArr(n,e){n.modelsArr=e},setselectedModel(n,e){n.selectedModel=e},setDiskUsage(n,e){n.diskUsage=e},setRamUsage(n,e){n.ramUsage=e},setVramUsage(n,e){n.vramUsage=e},setModelsZoo(n,e){n.modelsZoo=e},setCurrentModel(n,e){n.currentModel=e},setExtensionsZoo(n,e){n.extensionsZoo=e},setDatabases(n,e){n.databases=e}},getters:{getIsConnected(n){return n.isConnected},getIsModelOk(n){return n.isModelOk},getIsGenerating(n){return n.isGenerating},getConfig(n){return n.config},getPersonalities(n){return n.personalities},getMountedPersArr(n){return n.mountedPersArr},getmmountedExtensions(n){return n.mountedExtensions},getMountedPers(n){return n.mountedPers},getbindingsZoo(n){return n.bindingsZoo},getModelsArr(n){return n.modelsArr},getDiskUsage(n){return n.diskUsage},getRamUsage(n){return n.ramUsage},getVramUsage(n){return n.vramUsage},getDatabasesList(n){return n.databases},getModelsZoo(n){return n.modelsZoo},getCurrentModel(n){return n.currentModel},getExtensionsZoo(n){return n.extensionsZoo}},actions:{async getVersion(){try{let n=await Ue.get("/get_lollms_webui_version",{});n&&(this.state.version=n.data.version)}catch{console.log("Coudln't get version")}},async refreshConfig({commit:n}){console.log("Fetching configuration");try{const e=await oi("get_config");e.active_personality_id<0&&(e.active_personality_id=0);let t=e.personalities[e.active_personality_id].split("/");e.personality_category=t[0],e.personality_folder=t[1],e.extensions.length>0?e.extension_category=e.extensions[-1]:e.extension_category="ai_sensors",console.log("Recovered config"),console.log(e),console.log("Committing config"),console.log(e),console.log(this.state.config),n("setConfig",e)}catch(e){console.log(e.message,"refreshConfig")}},async refreshDatabase({commit:n}){let e=await oi("list_databases");console.log("databases:",e),n("setDatabases",e)},async refreshPersonalitiesZoo({commit:n}){let e=[];const t=await oi("get_all_personalities"),i=Object.keys(t);console.log("Personalities recovered:"+this.state.config.personalities);for(let s=0;s{let c=!1;for(const u of this.state.config.personalities)if(u.includes(r+"/"+l.folder))if(c=!0,u.includes(":")){const h=u.split(":");l.language=h[1]}else l.language=null;let d={};return d=l,d.category=r,d.full_path=r+"/"+l.folder,d.isMounted=c,d});e.length==0?e=a:e=e.concat(a)}e.sort((s,r)=>s.name.localeCompare(r.name)),n("setPersonalities",e),console.log("Done loading personalities")},refreshMountedPersonalities({commit:n}){this.state.config.active_personality_id<0&&(this.state.config.active_personality_id=0);let e=[];const t=[];for(let i=0;ia.full_path==s||a.full_path==r[0]);if(o>=0){let a=SR(this.state.personalities[o]);r.length>1&&(a.language=r[1]),a?e.push(a):e.push(this.state.personalities[this.state.personalities.findIndex(l=>l.full_path=="generic/lollms")])}else t.push(i),console.log("Couldn't load personality : ",s)}for(let i=t.length-1;i>=0;i--)console.log("Removing personality : ",this.state.config.personalities[t[i]]),this.state.config.personalities.splice(t[i],1),this.state.config.active_personality_id>t[i]&&(this.state.config.active_personality_id-=1);n("setMountedPersArr",e),this.state.mountedPers=this.state.personalities[this.state.personalities.findIndex(i=>i.full_path==this.state.config.personalities[this.state.config.active_personality_id]||i.full_path+":"+i.language==this.state.config.personalities[this.state.config.active_personality_id])]},async refreshBindings({commit:n}){let e=await oi("list_bindings");n("setbindingsZoo",e)},async refreshModelsZoo({commit:n}){console.log("Fetching models");const e=await Ue.get("/get_available_models");n("setModelsZoo",e.data.filter(t=>t.variants&&t.variants.length>0))},async refreshModelStatus({commit:n}){let e=await oi("get_model_status");n("setIsModelOk",e.status)},async refreshModels({commit:n}){console.log("Fetching models");let e=await oi("list_models");console.log(`Found ${e}`);let t=await oi("get_active_model");console.log("Selected model ",t),t!=null&&n("setselectedModel",t.model),n("setModelsArr",e),console.log("setModelsArr",e),this.state.modelsZoo.map(s=>{s.isInstalled=e.includes(s.name)}),this.state.installedModels=this.state.modelsZoo.filter(s=>s.isInstalled);const i=this.state.modelsZoo.findIndex(s=>s.name==this.state.config.model_name);i!=-1&&n("setCurrentModel",this.state.modelsZoo[i])},async refreshExtensionsZoo({commit:n}){let e=[],t=await oi("list_extensions");const i=Object.keys(t);console.log("Extensions recovered:"+t);for(let s=0;s{let c=!1;for(const u of this.state.config.extensions)u.includes(r+"/"+l.folder)&&(c=!0);let d={};return d=l,d.category=r,d.full_path=r+"/"+l.folder,d.isMounted=c,d});e.length==0?e=a:e=e.concat(a)}e.sort((s,r)=>s.name.localeCompare(r.name)),console.log("Done loading extensions"),n("setExtensionsZoo",e)},refreshmountedExtensions({commit:n}){console.log("Mounting extensions");let e=[];const t=[];for(let i=0;io.full_path==s);if(r>=0){let o=SR(this.state.config.extensions[r]);o&&e.push(o)}else t.push(i),console.log("Couldn't load extension : ",s)}for(let i=t.length-1;i>=0;i--)console.log("Removing extensions : ",this.state.config.extensions[t[i]]),this.state.config.extensions.splice(t[i],1);n("setMountedExtensions",e)},async refreshDiskUsage({commit:n}){this.state.diskUsage=await oi("disk_usage")},async refreshRamUsage({commit:n}){this.state.ramUsage=await oi("ram_usage")},async refreshVramUsage({commit:n}){const e=await oi("vram_usage"),t=[];if(e.nb_gpus>0){for(let s=0;s!!t.value),onPointerDown:l=>{t.value={x:l.pageX,y:l.pageY},i.value={x:n.value.x,y:n.value.y}},onPointerMove:l=>{if(t.value){const c=l.pageX-t.value.x,d=l.pageY-t.value.y;n.value.x=i.value.x+c/e.value.scaling,n.value.y=i.value.y+d/e.value.scaling}},onPointerUp:()=>{t.value=null,i.value=null}}}function eI(n,e,t){if(!e.template)return!1;if(wa(e.template)===t)return!0;const i=n.graphTemplates.find(r=>wa(r)===t);return i?i.nodes.filter(r=>r.type.startsWith(Jl)).some(r=>eI(n,e,r.type)):!1}function tI(n){return et(()=>{const e=Array.from(n.value.editor.nodeTypes.entries()),t=new Set(e.map(([,s])=>s.category)),i=[];for(const s of t.values()){let r=e.filter(([,o])=>o.category===s);n.value.displayedGraph.template?r=r.filter(([o])=>!eI(n.value.editor,n.value.displayedGraph,o)):r=r.filter(([o])=>![Ra,Aa].includes(o)),r.length>0&&i.push({name:s,nodeTypes:Object.fromEntries(r)})}return i.sort((s,r)=>s.name==="default"?-1:r.name==="default"||s.name>r.name?1:-1),i})}function nI(){const{graph:n}=Ui();return{transform:(t,i)=>{const s=t/n.value.scaling-n.value.panning.x,r=i/n.value.scaling-n.value.panning.y;return[s,r]}}}function J1t(){const{graph:n}=Ui();let e=[],t=-1,i={x:0,y:0};const s=et(()=>n.value.panning),r=JO(s),o=et(()=>({"transform-origin":"0 0",transform:`scale(${n.value.scaling}) translate(${n.value.panning.x}px, ${n.value.panning.y}px)`})),a=(m,f,b)=>{const E=[m/n.value.scaling-n.value.panning.x,f/n.value.scaling-n.value.panning.y],g=[m/b-n.value.panning.x,f/b-n.value.panning.y],S=[g[0]-E[0],g[1]-E[1]];n.value.panning.x+=S[0],n.value.panning.y+=S[1],n.value.scaling=b},l=m=>{m.preventDefault();let f=m.deltaY;m.deltaMode===1&&(f*=32);const b=n.value.scaling*(1-f/3e3);a(m.offsetX,m.offsetY,b)},c=()=>({ax:e[0].clientX,ay:e[0].clientY,bx:e[1].clientX,by:e[1].clientY});return{styles:o,...r,onPointerDown:m=>{if(e.push(m),r.onPointerDown(m),e.length===2){const{ax:f,ay:b,bx:E,by:g}=c();i={x:f+(E-f)/2,y:b+(g-b)/2}}},onPointerMove:m=>{for(let f=0;f0){const C=n.value.scaling*(1+(T-t)/500);a(i.x,i.y,C)}t=T}else r.onPointerMove(m)},onPointerUp:m=>{e=e.filter(f=>f.pointerId!==m.pointerId),t=-1,r.onPointerUp()},onMouseWheel:l}}var _i=(n=>(n[n.NONE=0]="NONE",n[n.ALLOWED=1]="ALLOWED",n[n.FORBIDDEN=2]="FORBIDDEN",n))(_i||{});const iI=Symbol();function eRt(){const{graph:n}=Ui(),e=dt(null),t=dt(null),i=a=>{e.value&&(e.value.mx=a.offsetX/n.value.scaling-n.value.panning.x,e.value.my=a.offsetY/n.value.scaling-n.value.panning.y)},s=()=>{if(t.value){if(e.value)return;const a=n.value.connections.find(l=>l.to===t.value);t.value.isInput&&a?(e.value={status:_i.NONE,from:a.from},n.value.removeConnection(a)):e.value={status:_i.NONE,from:t.value},e.value.mx=void 0,e.value.my=void 0}},r=()=>{if(e.value&&t.value){if(e.value.from===t.value)return;n.value.addConnection(e.value.from,e.value.to)}e.value=null},o=a=>{if(t.value=a??null,a&&e.value){e.value.to=a;const l=n.value.checkConnection(e.value.from,e.value.to);if(e.value.status=l.connectionAllowed?_i.ALLOWED:_i.FORBIDDEN,l.connectionAllowed){const c=l.connectionsInDanger.map(d=>d.id);n.value.connections.forEach(d=>{c.includes(d.id)&&(d.isInDanger=!0)})}}else!a&&e.value&&(e.value.to=void 0,e.value.status=_i.NONE,n.value.connections.forEach(l=>{l.isInDanger=!1}))};return Qo(iI,{temporaryConnection:e,hoveredOver:o}),{temporaryConnection:e,onMouseMove:i,onMouseDown:s,onMouseUp:r,hoveredOver:o}}function tRt(n){const e=dt(!1),t=dt(0),i=dt(0),s=tI(n),{transform:r}=nI(),o=et(()=>{let d=[];const u={};for(const m of s.value){const f=Object.entries(m.nodeTypes).map(([b,E])=>({label:E.title,value:"addNode:"+b}));m.name==="default"?d=f:u[m.name]=f}const h=[...Object.entries(u).map(([m,f])=>({label:m,submenu:f}))];return h.length>0&&d.length>0&&h.push({isDivider:!0}),h.push(...d),h}),a=et(()=>n.value.settings.contextMenu.additionalItems.length===0?o.value:[{label:"Add node",submenu:o.value},...n.value.settings.contextMenu.additionalItems.map(d=>"isDivider"in d||"submenu"in d?d:{label:d.label,value:"command:"+d.command,disabled:!n.value.commandHandler.canExecuteCommand(d.command)})]);function l(d){e.value=!0,t.value=d.offsetX,i.value=d.offsetY}function c(d){if(d.startsWith("addNode:")){const u=d.substring(8),h=n.value.editor.nodeTypes.get(u);if(!h)return;const m=jn(new h.type);n.value.displayedGraph.addNode(m);const[f,b]=r(t.value,i.value);m.position.x=f,m.position.y=b}else if(d.startsWith("command:")){const u=d.substring(8);n.value.commandHandler.canExecuteCommand(u)&&n.value.commandHandler.executeCommand(u)}}return{show:e,x:t,y:i,items:a,open:l,onClick:c}}const nRt=ln({setup(){const{viewModel:n}=yi(),{graph:e}=Ui();return{styles:et(()=>{const i=n.value.settings.background,s=e.value.panning.x*e.value.scaling,r=e.value.panning.y*e.value.scaling,o=e.value.scaling*i.gridSize,a=o/i.gridDivision,l=`${o}px ${o}px, ${o}px ${o}px`,c=e.value.scaling>i.subGridVisibleThreshold?`, ${a}px ${a}px, ${a}px ${a}px`:"";return{backgroundPosition:`left ${s}px top ${r}px`,backgroundSize:`${l} ${c}`}})}}}),cn=(n,e)=>{const t=n.__vccOpts||n;for(const[i,s]of e)t[i]=s;return t};function iRt(n,e,t,i,s,r){return O(),D("div",{class:"background",style:Xt(n.styles)},null,4)}const sRt=cn(nRt,[["render",iRt]]);function rRt(n){return wR()?(zI(n),!0):!1}function qb(n){return typeof n=="function"?n():vt(n)}const sI=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const oRt=Object.prototype.toString,aRt=n=>oRt.call(n)==="[object Object]",Od=()=>{},lRt=cRt();function cRt(){var n,e;return sI&&((n=window==null?void 0:window.navigator)==null?void 0:n.userAgent)&&(/iP(ad|hone|od)/.test(window.navigator.userAgent)||((e=window==null?void 0:window.navigator)==null?void 0:e.maxTouchPoints)>2&&/iPad|Macintosh/.test(window==null?void 0:window.navigator.userAgent))}function dRt(n,e,t=!1){return e.reduce((i,s)=>(s in n&&(!t||n[s]!==void 0)&&(i[s]=n[s]),i),{})}function uRt(n,e={}){if(!un(n))return TM(n);const t=Array.isArray(n.value)?Array.from({length:n.value.length}):{};for(const i in n.value)t[i]=yM(()=>({get(){return n.value[i]},set(s){var r;if((r=qb(e.replaceRef))!=null?r:!0)if(Array.isArray(n.value)){const a=[...n.value];a[i]=s,n.value=a}else{const a={...n.value,[i]:s};Object.setPrototypeOf(a,Object.getPrototypeOf(n.value)),n.value=a}else n.value[i]=s}}));return t}function bl(n){var e;const t=qb(n);return(e=t==null?void 0:t.$el)!=null?e:t}const Yb=sI?window:void 0;function Ml(...n){let e,t,i,s;if(typeof n[0]=="string"||Array.isArray(n[0])?([t,i,s]=n,e=Yb):[e,t,i,s]=n,!e)return Od;Array.isArray(t)||(t=[t]),Array.isArray(i)||(i=[i]);const r=[],o=()=>{r.forEach(d=>d()),r.length=0},a=(d,u,h,m)=>(d.addEventListener(u,h,m),()=>d.removeEventListener(u,h,m)),l=Bn(()=>[bl(e),qb(s)],([d,u])=>{if(o(),!d)return;const h=aRt(u)?{...u}:u;r.push(...t.flatMap(m=>i.map(f=>a(d,m,f,h))))},{immediate:!0,flush:"post"}),c=()=>{l(),o()};return rRt(c),c}let dR=!1;function rI(n,e,t={}){const{window:i=Yb,ignore:s=[],capture:r=!0,detectIframe:o=!1}=t;if(!i)return Od;lRt&&!dR&&(dR=!0,Array.from(i.document.body.children).forEach(h=>h.addEventListener("click",Od)),i.document.documentElement.addEventListener("click",Od));let a=!0;const l=h=>s.some(m=>{if(typeof m=="string")return Array.from(i.document.querySelectorAll(m)).some(f=>f===h.target||h.composedPath().includes(f));{const f=bl(m);return f&&(h.target===f||h.composedPath().includes(f))}}),d=[Ml(i,"click",h=>{const m=bl(n);if(!(!m||m===h.target||h.composedPath().includes(m))){if(h.detail===0&&(a=!l(h)),!a){a=!0;return}e(h)}},{passive:!0,capture:r}),Ml(i,"pointerdown",h=>{const m=bl(n);a=!l(h)&&!!(m&&!h.composedPath().includes(m))},{passive:!0}),o&&Ml(i,"blur",h=>{setTimeout(()=>{var m;const f=bl(n);((m=i.document.activeElement)==null?void 0:m.tagName)==="IFRAME"&&!(f!=null&&f.contains(i.document.activeElement))&&e(h)},0)})].filter(Boolean);return()=>d.forEach(h=>h())}const oI={x:0,y:0,pointerId:0,pressure:0,tiltX:0,tiltY:0,width:0,height:0,twist:0,pointerType:null},pRt=Object.keys(oI);function _Rt(n={}){const{target:e=Yb}=n,t=dt(!1),i=dt(n.initialValue||{});Object.assign(i.value,oI,i.value);const s=r=>{t.value=!0,!(n.pointerTypes&&!n.pointerTypes.includes(r.pointerType))&&(i.value=dRt(r,pRt,!1))};if(e){const r={passive:!0};Ml(e,["pointerdown","pointermove","pointerup"],s,r),Ml(e,"pointerleave",()=>t.value=!1,r)}return{...uRt(i),isInside:t}}const hRt=["onMouseenter","onMouseleave","onClick"],fRt={class:"flex-fill"},mRt={key:0,class:"__submenu-icon",style:{"line-height":"1em"}},gRt=_("svg",{width:"13",height:"13",viewBox:"-60 120 250 250"},[_("path",{d:"M160.875 279.5625 L70.875 369.5625 L70.875 189.5625 L160.875 279.5625 Z",stroke:"none",fill:"white"})],-1),ERt=[gRt],$b=ln({__name:"ContextMenu",props:{modelValue:{type:Boolean},items:{},x:{default:0},y:{default:0},isNested:{type:Boolean,default:!1},isFlipped:{default:()=>({x:!1,y:!1})},flippable:{type:Boolean,default:!1}},emits:["update:modelValue","click"],setup(n,{emit:e}){const t=n,i=e;let s=null;const r=dt(null),o=dt(-1),a=dt(0),l=dt({x:!1,y:!1}),c=et(()=>t.flippable&&(l.value.x||t.isFlipped.x)),d=et(()=>t.flippable&&(l.value.y||t.isFlipped.y)),u=et(()=>{const S={};return t.isNested||(S.top=(d.value?t.y-a.value:t.y)+"px",S.left=t.x+"px"),S}),h=et(()=>({"--flipped-x":c.value,"--flipped-y":d.value,"--nested":t.isNested})),m=et(()=>t.items.map(S=>({...S,hover:!1})));Bn([()=>t.y,()=>t.items],()=>{var S,y,T,C;a.value=t.items.length*30;const x=((y=(S=r.value)==null?void 0:S.parentElement)==null?void 0:y.offsetWidth)??0,w=((C=(T=r.value)==null?void 0:T.parentElement)==null?void 0:C.offsetHeight)??0;l.value.x=!t.isNested&&t.x>x*.75,l.value.y=!t.isNested&&t.y+a.value>w-20}),rI(r,()=>{t.modelValue&&i("update:modelValue",!1)});const f=S=>{!S.submenu&&S.value&&(i("click",S.value),i("update:modelValue",!1))},b=S=>{i("click",S),o.value=-1,t.isNested||i("update:modelValue",!1)},E=(S,y)=>{t.items[y].submenu&&(o.value=y,s!==null&&(clearTimeout(s),s=null))},g=(S,y)=>{t.items[y].submenu&&(s=window.setTimeout(()=>{o.value=-1,s=null},200))};return(S,y)=>{const T=_t("ContextMenu",!0);return O(),Ot(ws,{name:"slide-fade"},{default:ot(()=>[xe(_("div",{ref_key:"el",ref:r,class:He(["baklava-context-menu",h.value]),style:Xt(u.value)},[(O(!0),D($e,null,lt(m.value,(C,x)=>(O(),D($e,null,[C.isDivider?(O(),D("div",{key:`d-${x}`,class:"divider"})):(O(),D("div",{key:`i-${x}`,class:He(["item",{submenu:!!C.submenu,"--disabled":!!C.disabled}]),onMouseenter:w=>E(w,x),onMouseleave:w=>g(w,x),onClick:Te(w=>f(C),["stop","prevent"])},[_("div",fRt,he(C.label),1),C.submenu?(O(),D("div",mRt,ERt)):j("",!0),C.submenu?(O(),Ot(T,{key:1,"model-value":o.value===x,items:C.submenu,"is-nested":!0,"is-flipped":{x:c.value,y:d.value},flippable:S.flippable,onClick:b},null,8,["model-value","items","is-flipped","flippable"])):j("",!0)],42,hRt))],64))),256))],6),[[At,S.modelValue]])]),_:1})}}}),bRt={},SRt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"16",height:"16",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},vRt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),yRt=_("circle",{cx:"12",cy:"12",r:"1"},null,-1),TRt=_("circle",{cx:"12",cy:"19",r:"1"},null,-1),xRt=_("circle",{cx:"12",cy:"5",r:"1"},null,-1),CRt=[vRt,yRt,TRt,xRt];function RRt(n,e){return O(),D("svg",SRt,CRt)}const aI=cn(bRt,[["render",RRt]]),ARt=["id"],wRt={key:0,class:"__tooltip"},NRt={key:2,class:"align-middle"},uR=ln({__name:"NodeInterface",props:{node:{},intf:{}},setup(n){const e=(E,g=100)=>{const S=E!=null&&E.toString?E.toString():"";return S.length>g?S.slice(0,g)+"...":S},t=n,{viewModel:i}=yi(),{hoveredOver:s,temporaryConnection:r}=Ii(iI),o=dt(null),a=et(()=>t.intf.connectionCount>0),l=dt(!1),c=et(()=>i.value.settings.displayValueOnHover&&l.value),d=et(()=>({"--input":t.intf.isInput,"--output":!t.intf.isInput,"--connected":a.value})),u=et(()=>t.intf.component&&(!t.intf.isInput||!t.intf.port||t.intf.connectionCount===0)),h=()=>{l.value=!0,s(t.intf)},m=()=>{l.value=!1,s(void 0)},f=()=>{o.value&&i.value.hooks.renderInterface.execute({intf:t.intf,el:o.value})},b=()=>{const E=i.value.displayedGraph.sidebar;E.nodeId=t.node.id,E.optionName=t.intf.name,E.visible=!0};return Ms(f),nc(f),(E,g)=>{var S;return O(),D("div",{id:E.intf.id,ref_key:"el",ref:o,class:He(["baklava-node-interface",d.value])},[E.intf.port?(O(),D("div",{key:0,class:He(["__port",{"--selected":((S=vt(r))==null?void 0:S.from)===E.intf}]),onPointerover:h,onPointerout:m},[Nn(E.$slots,"portTooltip",{showTooltip:c.value},()=>[c.value===!0?(O(),D("span",wRt,he(e(E.intf.value)),1)):j("",!0)])],34)):j("",!0),u.value?(O(),Ot(Tu(E.intf.component),{key:1,modelValue:E.intf.value,"onUpdate:modelValue":g[0]||(g[0]=y=>E.intf.value=y),node:E.node,intf:E.intf,onOpenSidebar:b},null,40,["modelValue","node","intf"])):(O(),D("span",NRt,he(E.intf.name),1))],10,ARt)}}}),ORt=["id","data-node-type"],IRt={class:"__title-label"},MRt={class:"__menu"},DRt={class:"__outputs"},LRt={class:"__inputs"},kRt=ln({__name:"Node",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag"],setup(n,{emit:e}){const t=n,i=e,{viewModel:s}=yi(),{graph:r,switchGraph:o}=Ui(),a=dt(null),l=dt(!1),c=dt(""),d=dt(null),u=dt(!1),h=dt(!1),m=et(()=>{const P=[{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return t.node.type.startsWith(Jl)&&P.push({value:"editSubgraph",label:"Edit Subgraph"}),P}),f=et(()=>({"--selected":t.selected,"--dragging":t.dragging,"--two-column":!!t.node.twoColumn})),b=et(()=>{var P,U;return{top:`${((P=t.node.position)==null?void 0:P.y)??0}px`,left:`${((U=t.node.position)==null?void 0:U.x)??0}px`,"--width":`${t.node.width??s.value.settings.nodes.defaultWidth}px`}}),E=et(()=>Object.values(t.node.inputs).filter(P=>!P.hidden)),g=et(()=>Object.values(t.node.outputs).filter(P=>!P.hidden)),S=()=>{i("select")},y=P=>{t.selected||S(),i("start-drag",P)},T=()=>{h.value=!0},C=async P=>{var U;switch(P){case"delete":r.value.removeNode(t.node);break;case"rename":c.value=t.node.title,l.value=!0,await Fe(),(U=d.value)==null||U.focus();break;case"editSubgraph":o(t.node.template);break}},x=()=>{t.node.title=c.value,l.value=!1},w=()=>{a.value&&s.value.hooks.renderNode.execute({node:t.node,el:a.value})},R=P=>{u.value=!0,P.preventDefault()},v=P=>{if(!u.value)return;const U=t.node.width+P.movementX/r.value.scaling,Y=s.value.settings.nodes.minWidth,L=s.value.settings.nodes.maxWidth;t.node.width=Math.max(Y,Math.min(L,U))},A=()=>{u.value=!1};return Ms(()=>{w(),window.addEventListener("mousemove",v),window.addEventListener("mouseup",A)}),nc(w),La(()=>{window.removeEventListener("mousemove",v),window.removeEventListener("mouseup",A)}),(P,U)=>(O(),D("div",{id:P.node.id,ref_key:"el",ref:a,class:He(["baklava-node",f.value]),style:Xt(b.value),"data-node-type":P.node.type,onPointerdown:S},[vt(s).settings.nodes.resizable?(O(),D("div",{key:0,class:"__resize-handle",onMousedown:R},null,32)):j("",!0),Nn(P.$slots,"title",{},()=>[_("div",{class:"__title",onPointerdown:Te(y,["self","stop"])},[l.value?xe((O(),D("input",{key:1,ref_key:"renameInputEl",ref:d,"onUpdate:modelValue":U[1]||(U[1]=Y=>c.value=Y),type:"text",class:"baklava-input",placeholder:"Node Name",onBlur:x,onKeydown:mr(x,["enter"])},null,544)),[[Xe,c.value]]):(O(),D($e,{key:0},[_("div",IRt,he(P.node.title),1),_("div",MRt,[Ie(aI,{class:"--clickable",onClick:T}),Ie($b,{modelValue:h.value,"onUpdate:modelValue":U[0]||(U[0]=Y=>h.value=Y),x:0,y:0,items:m.value,onClick:C},null,8,["modelValue","items"])])],64))],32)]),Nn(P.$slots,"content",{},()=>[_("div",{class:"__content",onKeydown:U[2]||(U[2]=mr(Te(()=>{},["stop"]),["delete"]))},[_("div",DRt,[(O(!0),D($e,null,lt(g.value,Y=>Nn(P.$slots,"nodeInterface",{key:Y.id,type:"output",node:P.node,intf:Y},()=>[Ie(uR,{node:P.node,intf:Y},null,8,["node","intf"])])),128))]),_("div",LRt,[(O(!0),D($e,null,lt(E.value,Y=>Nn(P.$slots,"nodeInterface",{key:Y.id,type:"input",node:P.node,intf:Y},()=>[Ie(uR,{node:P.node,intf:Y},null,8,["node","intf"])])),128))])],32)])],46,ORt))}}),PRt=ln({props:{x1:{type:Number,required:!0},y1:{type:Number,required:!0},x2:{type:Number,required:!0},y2:{type:Number,required:!0},state:{type:Number,default:_i.NONE},isTemporary:{type:Boolean,default:!1}},setup(n){const{viewModel:e}=yi(),{graph:t}=Ui(),i=(o,a)=>{const l=(o+t.value.panning.x)*t.value.scaling,c=(a+t.value.panning.y)*t.value.scaling;return[l,c]},s=et(()=>{const[o,a]=i(n.x1,n.y1),[l,c]=i(n.x2,n.y2);if(e.value.settings.useStraightConnections)return`M ${o} ${a} L ${l} ${c}`;{const d=.3*Math.abs(o-l);return`M ${o} ${a} C ${o+d} ${a}, ${l-d} ${c}, ${l} ${c}`}}),r=et(()=>({"--temporary":n.isTemporary,"--allowed":n.state===_i.ALLOWED,"--forbidden":n.state===_i.FORBIDDEN}));return{d:s,classes:r}}}),URt=["d"];function FRt(n,e,t,i,s,r){return O(),D("path",{class:He(["baklava-connection",n.classes]),d:n.d},null,10,URt)}const lI=cn(PRt,[["render",FRt]]);function BRt(n){return document.getElementById(n.id)}function Na(n){const e=document.getElementById(n.id),t=e==null?void 0:e.getElementsByClassName("__port");return{node:(e==null?void 0:e.closest(".baklava-node"))??null,interface:e,port:t&&t.length>0?t[0]:null}}const GRt=ln({components:{"connection-view":lI},props:{connection:{type:Object,required:!0}},setup(n){const{graph:e}=Ui();let t;const i=dt({x1:0,y1:0,x2:0,y2:0}),s=et(()=>n.connection.isInDanger?_i.FORBIDDEN:_i.NONE),r=et(()=>{var c;return(c=e.value.findNodeById(n.connection.from.nodeId))==null?void 0:c.position}),o=et(()=>{var c;return(c=e.value.findNodeById(n.connection.to.nodeId))==null?void 0:c.position}),a=c=>c.node&&c.interface&&c.port?[c.node.offsetLeft+c.interface.offsetLeft+c.port.offsetLeft+c.port.clientWidth/2,c.node.offsetTop+c.interface.offsetTop+c.port.offsetTop+c.port.clientHeight/2]:[0,0],l=()=>{const c=Na(n.connection.from),d=Na(n.connection.to);c.node&&d.node&&(t||(t=new ResizeObserver(()=>{l()}),t.observe(c.node),t.observe(d.node)));const[u,h]=a(c),[m,f]=a(d);i.value={x1:u,y1:h,x2:m,y2:f}};return Ms(async()=>{await Fe(),l()}),La(()=>{t&&t.disconnect()}),Bn([r,o],()=>l(),{deep:!0}),{d:i,state:s}}});function VRt(n,e,t,i,s,r){const o=_t("connection-view");return O(),Ot(o,{x1:n.d.x1,y1:n.d.y1,x2:n.d.x2,y2:n.d.y2,state:n.state},null,8,["x1","y1","x2","y2","state"])}const zRt=cn(GRt,[["render",VRt]]);function cu(n){return n.node&&n.interface&&n.port?[n.node.offsetLeft+n.interface.offsetLeft+n.port.offsetLeft+n.port.clientWidth/2,n.node.offsetTop+n.interface.offsetTop+n.port.offsetTop+n.port.clientHeight/2]:[0,0]}const HRt=ln({components:{"connection-view":lI},props:{connection:{type:Object,required:!0}},setup(n){const e=et(()=>n.connection?n.connection.status:_i.NONE);return{d:et(()=>{if(!n.connection)return{input:[0,0],output:[0,0]};const i=cu(Na(n.connection.from)),s=n.connection.to?cu(Na(n.connection.to)):[n.connection.mx||i[0],n.connection.my||i[1]];return n.connection.from.isInput?{input:s,output:i}:{input:i,output:s}}),status:e}}});function qRt(n,e,t,i,s,r){const o=_t("connection-view");return O(),Ot(o,{x1:n.d.input[0],y1:n.d.input[1],x2:n.d.output[0],y2:n.d.output[1],state:n.status,"is-temporary":""},null,8,["x1","y1","x2","y2","state"])}const YRt=cn(HRt,[["render",qRt]]),$Rt=ln({setup(){const{viewModel:n}=yi(),{graph:e}=Ui(),t=dt(null),i=kd(n.value.settings.sidebar,"width"),s=et(()=>n.value.settings.sidebar.resizable),r=et(()=>{const u=e.value.sidebar.nodeId;return e.value.nodes.find(h=>h.id===u)}),o=et(()=>({width:`${i.value}px`})),a=et(()=>r.value?[...Object.values(r.value.inputs),...Object.values(r.value.outputs)].filter(h=>h.displayInSidebar&&h.component):[]),l=()=>{e.value.sidebar.visible=!1},c=()=>{window.addEventListener("mousemove",d),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",d)},{once:!0})},d=u=>{var h,m;const f=((m=(h=t.value)==null?void 0:h.parentElement)==null?void 0:m.getBoundingClientRect().width)??500;let b=i.value-u.movementX;b<300?b=300:b>.9*f&&(b=.9*f),i.value=b};return{el:t,graph:e,resizable:s,node:r,styles:o,displayedInterfaces:a,startResize:c,close:l}}}),WRt={class:"__header"},KRt={class:"__node-name"};function jRt(n,e,t,i,s,r){return O(),D("div",{ref:"el",class:He(["baklava-sidebar",{"--open":n.graph.sidebar.visible}]),style:Xt(n.styles)},[n.resizable?(O(),D("div",{key:0,class:"__resizer",onMousedown:e[0]||(e[0]=(...o)=>n.startResize&&n.startResize(...o))},null,32)):j("",!0),_("div",WRt,[_("button",{tabindex:"-1",class:"__close",onClick:e[1]||(e[1]=(...o)=>n.close&&n.close(...o))},"×"),_("div",KRt,[_("b",null,he(n.node?n.node.title:""),1)])]),(O(!0),D($e,null,lt(n.displayedInterfaces,o=>(O(),D("div",{key:o.id,class:"__interface"},[(O(),Ot(Tu(o.component),{modelValue:o.value,"onUpdate:modelValue":a=>o.value=a,node:n.node,intf:o},null,8,["modelValue","onUpdate:modelValue","node","intf"]))]))),128))],6)}const QRt=cn($Rt,[["render",jRt]]),XRt=ln({__name:"Minimap",setup(n){const{viewModel:e}=yi(),{graph:t}=Ui(),i=dt(null),s=dt(!1);let r,o=!1,a={x1:0,y1:0,x2:0,y2:0},l;const c=()=>{var x,w;if(!r)return;r.canvas.width=i.value.offsetWidth,r.canvas.height=i.value.offsetHeight;const R=new Map,v=new Map;for(const L of t.value.nodes){const H=BRt(L),B=(H==null?void 0:H.offsetWidth)??0,k=(H==null?void 0:H.offsetHeight)??0,$=((x=L.position)==null?void 0:x.x)??0,K=((w=L.position)==null?void 0:w.y)??0;R.set(L,{x1:$,y1:K,x2:$+B,y2:K+k}),v.set(L,H)}const A={x1:Number.MAX_SAFE_INTEGER,y1:Number.MAX_SAFE_INTEGER,x2:Number.MIN_SAFE_INTEGER,y2:Number.MIN_SAFE_INTEGER};for(const L of R.values())L.x1A.x2&&(A.x2=L.x2),L.y2>A.y2&&(A.y2=L.y2);const P=50;A.x1-=P,A.y1-=P,A.x2+=P,A.y2+=P,a=A;const U=r.canvas.width/r.canvas.height,Y=(a.x2-a.x1)/(a.y2-a.y1);if(U>Y){const L=(U-Y)*(a.y2-a.y1)*.5;a.x1-=L,a.x2+=L}else{const L=a.x2-a.x1,H=a.y2-a.y1,B=(L-U*H)/U*.5;a.y1-=B,a.y2+=B}r.clearRect(0,0,r.canvas.width,r.canvas.height),r.strokeStyle="white";for(const L of t.value.connections){const[H,B]=cu(Na(L.from)),[k,$]=cu(Na(L.to)),[K,W]=d(H,B),[le,J]=d(k,$);if(r.beginPath(),r.moveTo(K,W),e.value.settings.useStraightConnections)r.lineTo(le,J);else{const ee=.3*Math.abs(K-le);r.bezierCurveTo(K+ee,W,le-ee,J,le,J)}r.stroke()}r.strokeStyle="lightgray";for(const[L,H]of R.entries()){const[B,k]=d(H.x1,H.y1),[$,K]=d(H.x2,H.y2);r.fillStyle=h(v.get(L)),r.beginPath(),r.rect(B,k,$-B,K-k),r.fill(),r.stroke()}if(s.value){const L=f(),[H,B]=d(L.x1,L.y1),[k,$]=d(L.x2,L.y2);r.fillStyle="rgba(255, 255, 255, 0.2)",r.fillRect(H,B,k-H,$-B)}},d=(x,w)=>[(x-a.x1)/(a.x2-a.x1)*r.canvas.width,(w-a.y1)/(a.y2-a.y1)*r.canvas.height],u=(x,w)=>[x*(a.x2-a.x1)/r.canvas.width+a.x1,w*(a.y2-a.y1)/r.canvas.height+a.y1],h=x=>{if(x){const w=x.querySelector(".__content");if(w){const v=m(w);if(v)return v}const R=m(x);if(R)return R}return"gray"},m=x=>{const w=getComputedStyle(x).backgroundColor;if(w&&w!=="rgba(0, 0, 0, 0)")return w},f=()=>{const x=i.value.parentElement.offsetWidth,w=i.value.parentElement.offsetHeight,R=x/t.value.scaling-t.value.panning.x,v=w/t.value.scaling-t.value.panning.y;return{x1:-t.value.panning.x,y1:-t.value.panning.y,x2:R,y2:v}},b=x=>{x.button===0&&(o=!0,E(x))},E=x=>{if(o){const[w,R]=u(x.offsetX,x.offsetY),v=f(),A=(v.x2-v.x1)/2,P=(v.y2-v.y1)/2;t.value.panning.x=-(w-A),t.value.panning.y=-(R-P)}},g=()=>{o=!1},S=()=>{s.value=!0},y=()=>{s.value=!1,g()};Bn([s,t.value.panning,()=>t.value.scaling,()=>t.value.connections.length],()=>{c()});const T=et(()=>t.value.nodes.map(x=>x.position)),C=et(()=>t.value.nodes.map(x=>x.width));return Bn([T,C],()=>{c()},{deep:!0}),Ms(()=>{r=i.value.getContext("2d"),r.imageSmoothingQuality="high",c(),l=setInterval(c,500)}),La(()=>{clearInterval(l)}),(x,w)=>(O(),D("canvas",{ref_key:"canvas",ref:i,class:"baklava-minimap",onMouseenter:S,onMouseleave:y,onMousedown:Te(b,["self"]),onMousemove:Te(E,["self"]),onMouseup:g},null,544))}}),ZRt=ln({components:{ContextMenu:$b,VerticalDots:aI},props:{type:{type:String,required:!0},title:{type:String,required:!0}},setup(n){const{viewModel:e}=yi(),{switchGraph:t}=Ui(),i=dt(!1),s=et(()=>n.type.startsWith(Jl));return{showContextMenu:i,hasContextMenu:s,contextMenuItems:[{label:"Edit Subgraph",value:"editSubgraph"},{label:"Delete Subgraph",value:"deleteSubgraph"}],openContextMenu:()=>{i.value=!0},onContextMenuClick:l=>{const c=n.type.substring(Jl.length),d=e.value.editor.graphTemplates.find(u=>u.id===c);if(d)switch(l){case"editSubgraph":t(d);break;case"deleteSubgraph":e.value.editor.removeGraphTemplate(d);break}}}}}),JRt=["data-node-type"],eAt={class:"__title"},tAt={class:"__title-label"},nAt={key:0,class:"__menu"};function iAt(n,e,t,i,s,r){const o=_t("vertical-dots"),a=_t("context-menu");return O(),D("div",{class:"baklava-node --palette","data-node-type":n.type},[_("div",eAt,[_("div",tAt,he(n.title),1),n.hasContextMenu?(O(),D("div",nAt,[Ie(o,{class:"--clickable",onPointerdown:e[0]||(e[0]=Te(()=>{},["stop","prevent"])),onClick:Te(n.openContextMenu,["stop","prevent"])},null,8,["onClick"]),Ie(a,{modelValue:n.showContextMenu,"onUpdate:modelValue":e[1]||(e[1]=l=>n.showContextMenu=l),x:-100,y:0,items:n.contextMenuItems,onClick:n.onContextMenuClick,onPointerdown:e[2]||(e[2]=Te(()=>{},["stop","prevent"]))},null,8,["modelValue","items","onClick"])])):j("",!0)])],8,JRt)}const pR=cn(ZRt,[["render",iAt]]),sAt={class:"baklava-node-palette"},rAt={key:0},oAt=ln({__name:"NodePalette",setup(n){const{viewModel:e}=yi(),{x:t,y:i}=_Rt(),{transform:s}=nI(),r=tI(e),o=Ii("editorEl"),a=dt(null),l=et(()=>{if(!a.value||!(o!=null&&o.value))return{};const{left:d,top:u}=o.value.getBoundingClientRect();return{top:`${i.value-u}px`,left:`${t.value-d}px`}}),c=(d,u)=>{a.value={type:d,nodeInformation:u};const h=()=>{const m=jn(new u.type);e.value.displayedGraph.addNode(m);const f=o.value.getBoundingClientRect(),[b,E]=s(t.value-f.left,i.value-f.top);m.position.x=b,m.position.y=E,a.value=null,document.removeEventListener("pointerup",h)};document.addEventListener("pointerup",h)};return(d,u)=>(O(),D($e,null,[_("div",sAt,[(O(!0),D($e,null,lt(vt(r),h=>(O(),D("section",{key:h.name},[h.name!=="default"?(O(),D("h1",rAt,he(h.name),1)):j("",!0),(O(!0),D($e,null,lt(h.nodeTypes,(m,f)=>(O(),Ot(pR,{key:f,type:f,title:m.title,onPointerdown:b=>c(f,m)},null,8,["type","title","onPointerdown"]))),128))]))),128))]),Ie(ws,{name:"fade"},{default:ot(()=>[a.value?(O(),D("div",{key:0,class:"baklava-dragged-node",style:Xt(l.value)},[Ie(pR,{type:a.value.type,title:a.value.nodeInformation.title},null,8,["type","title"])],4)):j("",!0)]),_:1})],64))}});let fd;const aAt=new Uint8Array(16);function lAt(){if(!fd&&(fd=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!fd))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return fd(aAt)}const vn=[];for(let n=0;n<256;++n)vn.push((n+256).toString(16).slice(1));function cAt(n,e=0){return vn[n[e+0]]+vn[n[e+1]]+vn[n[e+2]]+vn[n[e+3]]+"-"+vn[n[e+4]]+vn[n[e+5]]+"-"+vn[n[e+6]]+vn[n[e+7]]+"-"+vn[n[e+8]]+vn[n[e+9]]+"-"+vn[n[e+10]]+vn[n[e+11]]+vn[n[e+12]]+vn[n[e+13]]+vn[n[e+14]]+vn[n[e+15]]}const dAt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_R={randomUUID:dAt};function du(n,e,t){if(_R.randomUUID&&!e&&!n)return _R.randomUUID();n=n||{};const i=n.random||(n.rng||lAt)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let s=0;s<16;++s)e[t+s]=i[s];return e}return cAt(i)}const ec="SAVE_SUBGRAPH";function uAt(n,e){const t=()=>{const i=n.value;if(!i.template)throw new Error("Graph template property not set");i.template.update(i.save()),i.template.panning=i.panning,i.template.scaling=i.scaling};e.registerCommand(ec,{canExecute:()=>{var i;return n.value!==((i=n.value.editor)==null?void 0:i.graph)},execute:t})}const pAt={},_At={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},hAt=_("polyline",{points:"6 9 12 15 18 9"},null,-1),fAt=[hAt];function mAt(n,e){return O(),D("svg",_At,fAt)}const gAt=cn(pAt,[["render",mAt]]),EAt=ln({components:{"i-arrow":gAt},props:{intf:{type:Object,required:!0}},setup(n){const e=dt(null),t=dt(!1),i=et(()=>n.intf.items.find(o=>typeof o=="string"?o===n.intf.value:o.value===n.intf.value)),s=et(()=>i.value?typeof i.value=="string"?i.value:i.value.text:""),r=o=>{n.intf.value=typeof o=="string"?o:o.value};return rI(e,()=>{t.value=!1}),{el:e,open:t,selectedItem:i,selectedText:s,setSelected:r}}}),bAt=["title"],SAt={class:"__selected"},vAt={class:"__text"},yAt={class:"__icon"},TAt={class:"__dropdown"},xAt={class:"item --header"},CAt=["onClick"];function RAt(n,e,t,i,s,r){const o=_t("i-arrow");return O(),D("div",{ref:"el",class:He(["baklava-select",{"--open":n.open}]),title:n.intf.name,onClick:e[0]||(e[0]=a=>n.open=!n.open)},[_("div",SAt,[_("div",vAt,he(n.selectedText),1),_("div",yAt,[Ie(o)])]),Ie(ws,{name:"slide-fade"},{default:ot(()=>[xe(_("div",TAt,[_("div",xAt,he(n.intf.name),1),(O(!0),D($e,null,lt(n.intf.items,(a,l)=>(O(),D("div",{key:l,class:He(["item",{"--active":a===n.selectedItem}]),onClick:c=>n.setSelected(a)},he(typeof a=="string"?a:a.text),11,CAt))),128))],512),[[At,n.open]])]),_:1})],10,bAt)}const AAt=cn(EAt,[["render",RAt]]);class wAt extends pn{constructor(e,t,i){super(e,t),this.component=tc(AAt),this.items=i}}const NAt=ln({props:{intf:{type:Object,required:!0}}});function OAt(n,e,t,i,s,r){return O(),D("div",null,he(n.intf.value),1)}const IAt=cn(NAt,[["render",OAt]]);class MAt extends pn{constructor(e,t){super(e,t),this.component=tc(IAt),this.setPort(!1)}}const DAt=ln({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(n,{emit:e}){return{v:et({get:()=>n.modelValue,set:i=>{e("update:modelValue",i)}})}}}),LAt=["placeholder","title"];function kAt(n,e,t,i,s,r){return O(),D("div",null,[xe(_("input",{"onUpdate:modelValue":e[0]||(e[0]=o=>n.v=o),type:"text",class:"baklava-input",placeholder:n.intf.name,title:n.intf.name},null,8,LAt),[[Xe,n.v]])])}const PAt=cn(DAt,[["render",kAt]]);class tp extends pn{constructor(){super(...arguments),this.component=tc(PAt)}}class cI extends jO{constructor(){super(...arguments),this._title="Subgraph Input",this.inputs={name:new tp("Name","Input").setPort(!1)},this.outputs={placeholder:new pn("Connection",void 0)}}}class dI extends QO{constructor(){super(...arguments),this._title="Subgraph Output",this.inputs={name:new tp("Name","Output").setPort(!1),placeholder:new pn("Connection",void 0)},this.outputs={output:new pn("Output",void 0).setHidden(!0)}}}const uI="CREATE_SUBGRAPH",hR=[Ra,Aa];function UAt(n,e,t){const i=()=>n.value.selectedNodes.filter(r=>!hR.includes(r.type)).length>0,s=()=>{const{viewModel:r}=yi(),o=n.value,a=n.value.editor;if(o.selectedNodes.length===0)return;const l=o.selectedNodes.filter(v=>!hR.includes(v.type)),c=l.flatMap(v=>Object.values(v.inputs)),d=l.flatMap(v=>Object.values(v.outputs)),u=o.connections.filter(v=>!d.includes(v.from)&&c.includes(v.to)),h=o.connections.filter(v=>d.includes(v.from)&&!c.includes(v.to)),m=o.connections.filter(v=>d.includes(v.from)&&c.includes(v.to)),f=l.map(v=>v.save()),b=m.map(v=>({id:v.id,from:v.from.id,to:v.to.id})),E=new Map,{xLeft:g,xRight:S,yTop:y}=FAt(l);console.log(g,S,y);for(const[v,A]of u.entries()){const P=new cI;P.inputs.name.value=A.to.name,f.push({...P.save(),position:{x:S-r.value.settings.nodes.defaultWidth-100,y:y+v*200}}),b.push({id:du(),from:P.outputs.placeholder.id,to:A.to.id}),E.set(A.to.id,P.graphInterfaceId)}for(const[v,A]of h.entries()){const P=new dI;P.inputs.name.value=A.from.name,f.push({...P.save(),position:{x:g+100,y:y+v*200}}),b.push({id:du(),from:A.from.id,to:P.inputs.placeholder.id}),E.set(A.from.id,P.graphInterfaceId)}const T=jn(new ep({connections:b,nodes:f,inputs:[],outputs:[]},a));a.addGraphTemplate(T);const C=a.nodeTypes.get(wa(T));if(!C)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");const x=jn(new C.type);o.addNode(x);const w=Math.round(l.map(v=>v.position.x).reduce((v,A)=>v+A,0)/l.length),R=Math.round(l.map(v=>v.position.y).reduce((v,A)=>v+A,0)/l.length);x.position.x=w,x.position.y=R,u.forEach(v=>{o.removeConnection(v),o.addConnection(v.from,x.inputs[E.get(v.to.id)])}),h.forEach(v=>{o.removeConnection(v),o.addConnection(x.outputs[E.get(v.from.id)],v.to)}),l.forEach(v=>o.removeNode(v)),e.canExecuteCommand(ec)&&e.executeCommand(ec),t(T),n.value.panning={...o.panning},n.value.scaling=o.scaling};e.registerCommand(uI,{canExecute:i,execute:s})}function FAt(n){const e=n.reduce((s,r)=>{const o=r.position.x;return o{const o=r.position.y;return o{const o=r.position.x+r.width;return o>s?o:s},-1/0),xRight:e,yTop:t}}const fR="DELETE_NODES";function BAt(n,e){e.registerCommand(fR,{canExecute:()=>n.value.selectedNodes.length>0,execute(){n.value.selectedNodes.forEach(t=>n.value.removeNode(t))}}),e.registerHotkey(["Delete"],fR)}const pI="SWITCH_TO_MAIN_GRAPH";function GAt(n,e,t){e.registerCommand(pI,{canExecute:()=>n.value!==n.value.editor.graph,execute:()=>{e.executeCommand(ec),t(n.value.editor.graph)}})}function VAt(n,e,t){BAt(n,e),UAt(n,e,t),uAt(n,e),GAt(n,e,t)}class mR{constructor(e,t){this.type=e,e==="addNode"?this.nodeId=t:this.nodeState=t}undo(e){this.type==="addNode"?this.removeNode(e):this.addNode(e)}redo(e){this.type==="addNode"&&this.nodeState?this.addNode(e):this.type==="removeNode"&&this.nodeId&&this.removeNode(e)}addNode(e){const t=e.editor.nodeTypes.get(this.nodeState.type);if(!t)return;const i=new t.type;e.addNode(i),i.load(this.nodeState),this.nodeId=i.id}removeNode(e){const t=e.nodes.find(i=>i.id===this.nodeId);t&&(this.nodeState=t.save(),e.removeNode(t))}}class gR{constructor(e,t){if(this.type=e,e==="addConnection")this.connectionId=t;else{const i=t;this.connectionState={id:i.id,from:i.from.id,to:i.to.id}}}undo(e){this.type==="addConnection"?this.removeConnection(e):this.addConnection(e)}redo(e){this.type==="addConnection"&&this.connectionState?this.addConnection(e):this.type==="removeConnection"&&this.connectionId&&this.removeConnection(e)}addConnection(e){const t=e.findNodeInterface(this.connectionState.from),i=e.findNodeInterface(this.connectionState.to);!t||!i||e.addConnection(t,i)}removeConnection(e){const t=e.connections.find(i=>i.id===this.connectionId);t&&(this.connectionState={id:t.id,from:t.from.id,to:t.to.id},e.removeConnection(t))}}class zAt{constructor(e){if(this.type="transaction",e.length===0)throw new Error("Can't create a transaction with no steps");this.steps=e}undo(e){for(let t=this.steps.length-1;t>=0;t--)this.steps[t].undo(e)}redo(e){for(let t=0;t{if(!r.value)if(a.value)l.value.push(E);else for(o.value!==s.value.length-1&&(s.value=s.value.slice(0,o.value+1)),s.value.push(E),o.value++;s.value.length>i.value;)s.value.shift()},d=()=>{a.value=!0},u=()=>{a.value=!1,l.value.length>0&&(c(new zAt(l.value)),l.value=[])},h=()=>s.value.length!==0&&o.value!==-1,m=()=>{h()&&(r.value=!0,s.value[o.value--].undo(n.value),r.value=!1)},f=()=>s.value.length!==0&&o.value{f()&&(r.value=!0,s.value[++o.value].redo(n.value),r.value=!1)};return Bn(n,(E,g)=>{g&&(g.events.addNode.unsubscribe(t),g.events.removeNode.unsubscribe(t),g.events.addConnection.unsubscribe(t),g.events.removeConnection.unsubscribe(t)),E&&(E.events.addNode.subscribe(t,S=>{c(new mR("addNode",S.id))}),E.events.removeNode.subscribe(t,S=>{c(new mR("removeNode",S.save()))}),E.events.addConnection.subscribe(t,S=>{c(new gR("addConnection",S.id))}),E.events.removeConnection.subscribe(t,S=>{c(new gR("removeConnection",S))}))},{immediate:!0}),e.registerCommand(eE,{canExecute:h,execute:m}),e.registerCommand(tE,{canExecute:f,execute:b}),e.registerCommand(_I,{canExecute:()=>!a.value,execute:d}),e.registerCommand(hI,{canExecute:()=>a.value,execute:u}),e.registerHotkey(["Control","z"],eE),e.registerHotkey(["Control","y"],tE),jn({maxSteps:i})}const nE="COPY",iE="PASTE",qAt="CLEAR_CLIPBOARD";function YAt(n,e,t){const i=Symbol("ClipboardToken"),s=dt(""),r=dt(""),o=et(()=>!s.value),a=()=>{s.value="",r.value=""},l=()=>{const u=n.value.selectedNodes.flatMap(m=>[...Object.values(m.inputs),...Object.values(m.outputs)]),h=n.value.connections.filter(m=>u.includes(m.from)||u.includes(m.to)).map(m=>({from:m.from.id,to:m.to.id}));r.value=JSON.stringify(h),s.value=JSON.stringify(n.value.selectedNodes.map(m=>m.save()))},c=(u,h,m)=>{for(const f of u){let b;if((!m||m==="input")&&(b=Object.values(f.inputs).find(E=>E.id===h)),!b&&(!m||m==="output")&&(b=Object.values(f.outputs).find(E=>E.id===h)),b)return b}},d=()=>{if(o.value)return;const u=new Map,h=JSON.parse(s.value),m=JSON.parse(r.value),f=[],b=[],E=n.value;t.executeCommand(_I);for(const g of h){const S=e.value.nodeTypes.get(g.type);if(!S){console.warn(`Node type ${g.type} not registered`);return}const y=new S.type,T=y.id;f.push(y),y.hooks.beforeLoad.subscribe(i,C=>{const x=C;return x.position&&(x.position.x+=100,x.position.y+=100),y.hooks.beforeLoad.unsubscribe(i),x}),E.addNode(y),y.load({...g,id:T}),y.id=T,u.set(g.id,T);for(const C of Object.values(y.inputs)){const x=du();u.set(C.id,x),C.id=x}for(const C of Object.values(y.outputs)){const x=du();u.set(C.id,x),C.id=x}}for(const g of m){const S=c(f,u.get(g.from),"output"),y=c(f,u.get(g.to),"input");if(!S||!y)continue;const T=E.addConnection(S,y);T&&b.push(T)}return n.value.selectedNodes=f,t.executeCommand(hI),{newNodes:f,newConnections:b}};return t.registerCommand(nE,{canExecute:()=>n.value.selectedNodes.length>0,execute:l}),t.registerHotkey(["Control","c"],nE),t.registerCommand(iE,{canExecute:()=>!o.value,execute:d}),t.registerHotkey(["Control","v"],iE),t.registerCommand(qAt,{canExecute:()=>!0,execute:a}),jn({isEmpty:o})}const $At="OPEN_SIDEBAR";function WAt(n,e){e.registerCommand($At,{execute:t=>{n.value.sidebar.nodeId=t,n.value.sidebar.visible=!0},canExecute:()=>!0})}function KAt(n,e){WAt(n,e)}const jAt={},QAt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},XAt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),ZAt=_("path",{d:"M9 13l-4 -4l4 -4m-4 4h11a4 4 0 0 1 0 8h-1"},null,-1),JAt=[XAt,ZAt];function ewt(n,e){return O(),D("svg",QAt,JAt)}const twt=cn(jAt,[["render",ewt]]),nwt={},iwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},swt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),rwt=_("path",{d:"M15 13l4 -4l-4 -4m4 4h-11a4 4 0 0 0 0 8h1"},null,-1),owt=[swt,rwt];function awt(n,e){return O(),D("svg",iwt,owt)}const lwt=cn(nwt,[["render",awt]]),cwt={},dwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},uwt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),pwt=_("line",{x1:"5",y1:"12",x2:"19",y2:"12"},null,-1),_wt=_("line",{x1:"5",y1:"12",x2:"11",y2:"18"},null,-1),hwt=_("line",{x1:"5",y1:"12",x2:"11",y2:"6"},null,-1),fwt=[uwt,pwt,_wt,hwt];function mwt(n,e){return O(),D("svg",dwt,fwt)}const gwt=cn(cwt,[["render",mwt]]),Ewt={},bwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},Swt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),vwt=_("path",{d:"M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2"},null,-1),ywt=_("rect",{x:"9",y:"3",width:"6",height:"4",rx:"2"},null,-1),Twt=[Swt,vwt,ywt];function xwt(n,e){return O(),D("svg",bwt,Twt)}const Cwt=cn(Ewt,[["render",xwt]]),Rwt={},Awt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},wwt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),Nwt=_("rect",{x:"8",y:"8",width:"12",height:"12",rx:"2"},null,-1),Owt=_("path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"},null,-1),Iwt=[wwt,Nwt,Owt];function Mwt(n,e){return O(),D("svg",Awt,Iwt)}const Dwt=cn(Rwt,[["render",Mwt]]),Lwt={},kwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},Pwt=_("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),Uwt=_("path",{d:"M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2"},null,-1),Fwt=_("circle",{cx:"12",cy:"14",r:"2"},null,-1),Bwt=_("polyline",{points:"14 4 14 8 8 8 8 4"},null,-1),Gwt=[Pwt,Uwt,Fwt,Bwt];function Vwt(n,e){return O(),D("svg",kwt,Gwt)}const zwt=cn(Lwt,[["render",Vwt]]),Hwt={},qwt={xmlns:"http://www.w3.org/2000/svg",class:"baklava-icon",width:"24",height:"24",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},Ywt=Ru('',6),$wt=[Ywt];function Wwt(n,e){return O(),D("svg",qwt,$wt)}const Kwt=cn(Hwt,[["render",Wwt]]),jwt=ln({props:{command:{type:String,required:!0},title:{type:String,required:!0},icon:{type:Object,required:!1,default:void 0}},setup(){const{viewModel:n}=yi();return{viewModel:n}}}),Qwt=["disabled","title"];function Xwt(n,e,t,i,s,r){return O(),D("button",{class:"baklava-toolbar-entry baklava-toolbar-button",disabled:!n.viewModel.commandHandler.canExecuteCommand(n.command),title:n.title,onClick:e[0]||(e[0]=o=>n.viewModel.commandHandler.executeCommand(n.command))},[n.icon?(O(),Ot(Tu(n.icon),{key:0})):(O(),D($e,{key:1},[je(he(n.title),1)],64))],8,Qwt)}const Zwt=cn(jwt,[["render",Xwt]]),Jwt=ln({components:{ToolbarButton:Zwt},setup(){const{viewModel:n}=yi();return{isSubgraph:et(()=>n.value.displayedGraph!==n.value.editor.graph),commands:[{command:nE,title:"Copy",icon:Dwt},{command:iE,title:"Paste",icon:Cwt},{command:eE,title:"Undo",icon:twt},{command:tE,title:"Redo",icon:lwt},{command:uI,title:"Create Subgraph",icon:Kwt}],subgraphCommands:[{command:ec,title:"Save Subgraph",icon:zwt},{command:pI,title:"Back to Main Graph",icon:gwt}]}}}),eNt={class:"baklava-toolbar"};function tNt(n,e,t,i,s,r){const o=_t("toolbar-button");return O(),D("div",eNt,[(O(!0),D($e,null,lt(n.commands,a=>(O(),Ot(o,{key:a.command,command:a.command,title:a.title,icon:a.icon},null,8,["command","title","icon"]))),128)),n.isSubgraph?(O(!0),D($e,{key:0},lt(n.subgraphCommands,a=>(O(),Ot(o,{key:a.command,command:a.command,title:a.title,icon:a.icon},null,8,["command","title","icon"]))),128)):j("",!0)])}const nNt=cn(Jwt,[["render",tNt]]),iNt={class:"connections-container"},sNt=ln({__name:"Editor",props:{viewModel:{}},setup(n){const e=n,t=Symbol("EditorToken"),i=kd(e,"viewModel");Z1t(i);const s=dt(null);Qo("editorEl",s);const r=et(()=>e.viewModel.displayedGraph.nodes),o=et(()=>e.viewModel.displayedGraph.nodes.map(w=>JO(kd(w,"position")))),a=et(()=>e.viewModel.displayedGraph.connections),l=et(()=>e.viewModel.displayedGraph.selectedNodes),c=J1t(),d=eRt(),u=tRt(i),h=et(()=>({...c.styles.value})),m=dt(0);e.viewModel.editor.hooks.load.subscribe(t,w=>(m.value++,w));const f=w=>{c.onPointerMove(w),d.onMouseMove(w)},b=w=>{w.button===0&&(w.target===s.value&&(T(),c.onPointerDown(w)),d.onMouseDown())},E=w=>{c.onPointerUp(w),d.onMouseUp()},g=w=>{w.key==="Tab"&&w.preventDefault(),e.viewModel.commandHandler.handleKeyDown(w)},S=w=>{e.viewModel.commandHandler.handleKeyUp(w)},y=w=>{["Control","Shift"].some(R=>e.viewModel.commandHandler.pressedKeys.includes(R))||T(),e.viewModel.displayedGraph.selectedNodes.push(w)},T=()=>{e.viewModel.displayedGraph.selectedNodes=[]},C=w=>{for(const R of e.viewModel.displayedGraph.selectedNodes){const v=r.value.indexOf(R),A=o.value[v];A.onPointerDown(w),document.addEventListener("pointermove",A.onPointerMove)}document.addEventListener("pointerup",x)},x=()=>{for(const w of e.viewModel.displayedGraph.selectedNodes){const R=r.value.indexOf(w),v=o.value[R];v.onPointerUp(),document.removeEventListener("pointermove",v.onPointerMove)}document.removeEventListener("pointerup",x)};return(w,R)=>(O(),D("div",{ref_key:"el",ref:s,tabindex:"-1",class:He(["baklava-editor",{"baklava-ignore-mouse":!!vt(d).temporaryConnection.value||vt(c).dragging.value,"--temporary-connection":!!vt(d).temporaryConnection.value}]),onPointermove:Te(f,["self"]),onPointerdown:b,onPointerup:E,onWheel:R[1]||(R[1]=Te((...v)=>vt(c).onMouseWheel&&vt(c).onMouseWheel(...v),["self"])),onKeydown:g,onKeyup:S,onContextmenu:R[2]||(R[2]=Te((...v)=>vt(u).open&&vt(u).open(...v),["self","prevent"]))},[Nn(w.$slots,"background",{},()=>[Ie(sRt)]),Nn(w.$slots,"toolbar",{},()=>[Ie(nNt)]),Nn(w.$slots,"palette",{},()=>[Ie(oAt)]),(O(),D("svg",iNt,[(O(!0),D($e,null,lt(a.value,v=>(O(),D("g",{key:v.id+m.value.toString()},[Nn(w.$slots,"connection",{connection:v},()=>[Ie(zRt,{connection:v},null,8,["connection"])])]))),128)),Nn(w.$slots,"temporaryConnection",{temporaryConnection:vt(d).temporaryConnection.value},()=>[vt(d).temporaryConnection.value?(O(),Ot(YRt,{key:0,connection:vt(d).temporaryConnection.value},null,8,["connection"])):j("",!0)])])),_("div",{class:"node-container",style:Xt(h.value)},[Ie(ys,{name:"fade"},{default:ot(()=>[(O(!0),D($e,null,lt(r.value,(v,A)=>Nn(w.$slots,"node",{key:v.id+m.value.toString(),node:v,selected:l.value.includes(v),dragging:o.value[A].dragging.value,onSelect:P=>y(v),onStartDrag:C},()=>[Ie(kRt,{node:v,selected:l.value.includes(v),dragging:o.value[A].dragging.value,onSelect:P=>y(v),onStartDrag:C},null,8,["node","selected","dragging","onSelect"])])),128))]),_:3})],4),Nn(w.$slots,"sidebar",{},()=>[Ie(QRt)]),Nn(w.$slots,"minimap",{},()=>[w.viewModel.settings.enableMinimap?(O(),Ot(XRt,{key:0})):j("",!0)]),Nn(w.$slots,"contextMenu",{contextMenu:vt(u)},()=>[w.viewModel.settings.contextMenu.enabled?(O(),Ot($b,{key:0,modelValue:vt(u).show.value,"onUpdate:modelValue":R[0]||(R[0]=v=>vt(u).show.value=v),items:vt(u).items.value,x:vt(u).x.value,y:vt(u).y.value,onClick:vt(u).onClick},null,8,["modelValue","items","x","y","onClick"])):j("",!0)])],34))}}),rNt=["INPUT","TEXTAREA","SELECT"];function oNt(n){const e=dt([]),t=dt([]);return{pressedKeys:e,handleKeyDown:o=>{var a;e.value.includes(o.key)||e.value.push(o.key),!rNt.includes(((a=document.activeElement)==null?void 0:a.tagName)??"")&&t.value.forEach(l=>{l.keys.every(c=>e.value.includes(c))&&n(l.commandName)})},handleKeyUp:o=>{const a=e.value.indexOf(o.key);a>=0&&e.value.splice(a,1)},registerHotkey:(o,a)=>{t.value.push({keys:o,commandName:a})}}}const aNt=()=>{const n=dt(new Map),e=(r,o)=>{if(n.value.has(r))throw new Error(`Command "${r}" already exists`);n.value.set(r,o)},t=(r,o=!1,...a)=>{if(!n.value.has(r)){if(o)throw new Error(`[CommandHandler] Command ${r} not registered`);return}return n.value.get(r).execute(...a)},i=(r,o=!1,...a)=>{if(!n.value.has(r)){if(o)throw new Error(`[CommandHandler] Command ${r} not registered`);return!1}return n.value.get(r).canExecute(a)},s=oNt(t);return jn({registerCommand:e,executeCommand:t,canExecuteCommand:i,...s})},lNt=n=>!(n instanceof mc);function cNt(n,e){return{switchGraph:i=>{let s;if(lNt(i))s=new mc(n.value),i.createGraph(s);else{if(i!==n.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");s=i}e.value&&e.value!==n.value.graph&&e.value.destroy(),s.panning=s.panning??i.panning??{x:0,y:0},s.scaling=s.scaling??i.scaling??1,s.selectedNodes=s.selectedNodes??[],s.sidebar=s.sidebar??{visible:!1,nodeId:"",optionName:""},e.value=s}}}function dNt(n,e){n.position=n.position??{x:0,y:0},n.disablePointerEvents=!1,n.twoColumn=n.twoColumn??!1,n.width=n.width??e.defaultWidth}const uNt=()=>({useStraightConnections:!1,enableMinimap:!1,background:{gridSize:100,gridDivision:5,subGridVisibleThreshold:.6},sidebar:{width:300,resizable:!0},displayValueOnHover:!1,nodes:{defaultWidth:200,maxWidth:320,minWidth:150,resizable:!1},contextMenu:{enabled:!0,additionalItems:[]}});function pNt(n){const e=dt(n??new $1t),t=Symbol("ViewModelToken"),i=dt(null),s=gM(i),{switchGraph:r}=cNt(e,i),o=et(()=>s.value&&s.value!==e.value.graph),a=jn(uNt()),l=aNt(),c=HAt(s,l),d=YAt(s,e,l),u={renderNode:new ii(null),renderInterface:new ii(null)};return VAt(s,l,r),KAt(s,l),Bn(e,(h,m)=>{m&&(m.events.registerGraph.unsubscribe(t),m.graphEvents.beforeAddNode.unsubscribe(t),h.nodeHooks.beforeLoad.unsubscribe(t),h.nodeHooks.afterSave.unsubscribe(t),h.graphTemplateHooks.beforeLoad.unsubscribe(t),h.graphTemplateHooks.afterSave.unsubscribe(t),h.graph.hooks.load.unsubscribe(t),h.graph.hooks.save.unsubscribe(t)),h&&(h.nodeHooks.beforeLoad.subscribe(t,(f,b)=>(b.position=f.position??{x:0,y:0},b.width=f.width??a.nodes.defaultWidth,b.twoColumn=f.twoColumn??!1,f)),h.nodeHooks.afterSave.subscribe(t,(f,b)=>(f.position=b.position,f.width=b.width,f.twoColumn=b.twoColumn,f)),h.graphTemplateHooks.beforeLoad.subscribe(t,(f,b)=>(b.panning=f.panning,b.scaling=f.scaling,f)),h.graphTemplateHooks.afterSave.subscribe(t,(f,b)=>(f.panning=b.panning,f.scaling=b.scaling,f)),h.graph.hooks.load.subscribe(t,(f,b)=>(b.panning=f.panning,b.scaling=f.scaling,f)),h.graph.hooks.save.subscribe(t,(f,b)=>(f.panning=b.panning,f.scaling=b.scaling,f)),h.graphEvents.beforeAddNode.subscribe(t,f=>dNt(f,{defaultWidth:a.nodes.defaultWidth})),e.value.registerNodeType(cI,{category:"Subgraphs"}),e.value.registerNodeType(dI,{category:"Subgraphs"}),r(h.graph))},{immediate:!0}),jn({editor:e,displayedGraph:s,isSubgraph:o,settings:a,commandHandler:l,history:c,clipboard:d,hooks:u,switchGraph:r})}const ER=Hb({type:"PersonalityNode",title:"Personality",inputs:{request:()=>new pn("Request",""),agent_name:()=>new wAt("Personality","",sE.state.config.personalities).setPort(!1)},outputs:{display:()=>new MAt("Output",""),response:()=>new pn("Response","")},async calculate({request:n}){console.log(sE.state.config.personalities);let e="";try{e=(await Ue.get("/generate",{params:{text:n}})).data}catch(t){console.error(t)}return{display:e,response:e}}}),_Nt=Hb({type:"RAGNode",title:"RAG",inputs:{request:()=>new pn("Prompt",""),document_path:()=>new tp("Document path","").setPort(!1)},outputs:{prompt:()=>new pn("Prompt with Data","")},async calculate({request:n,document_path:e}){let t="";try{t=(await Ue.get("/rag",{params:{text:n,doc_path:e}})).data}catch(i){console.error(i)}return{response:t}}}),bR=Hb({type:"Task",title:"Task",inputs:{description:()=>new tp("Task description","").setPort(!1)},outputs:{prompt:()=>new pn("Prompt")},calculate({description:n}){return{prompt:n}}}),hNt=ln({components:{"baklava-editor":sNt},setup(){const n=pNt(),e=new X1t(n.editor);n.editor.registerNodeType(ER),n.editor.registerNodeType(bR),n.editor.registerNodeType(_Nt);const t=Symbol();e.events.afterRun.subscribe(t,o=>{e.pause(),W1t(o,n.editor),e.resume()}),e.start();function i(o,a,l){const c=new o;return n.displayedGraph.addNode(c),c.position.x=a,c.position.y=l,c}const s=i(bR,300,140),r=i(ER,550,140);return n.displayedGraph.addConnection(s.outputs.result,r.inputs.value),{baklava:n,saveGraph:()=>{const o=e.export();localStorage.setItem("myGraph",JSON.stringify(o))},loadGraph:()=>{const o=JSON.parse(localStorage.getItem("myGraph"));e.import(o)}}}}),fNt={style:{width:"100vw",height:"100vh"}};function mNt(n,e,t,i,s,r){const o=_t("baklava-editor");return O(),D("div",fNt,[Ie(o,{"view-model":n.baklava},null,8,["view-model"]),_("button",{onClick:e[0]||(e[0]=(...a)=>n.saveGraph&&n.saveGraph(...a))},"Save Graph"),_("button",{onClick:e[1]||(e[1]=(...a)=>n.loadGraph&&n.loadGraph(...a))},"Load Graph")])}const gNt=gt(hNt,[["render",mNt]]),ENt=Zk({history:mk("/"),routes:[{path:"/playground/",name:"playground",component:KZe},{path:"/extensions/",name:"extensions",component:rJe},{path:"/help/",name:"help",component:CJe},{path:"/settings/",name:"settings",component:Kut},{path:"/training/",name:"training",component:fpt},{path:"/quantizing/",name:"quantizing",component:xpt},{path:"/",name:"discussions",component:Tbt},{path:"/",name:"interactive",component:B1t},{path:"/",name:"nodes",component:gNt}]});const np=l2(NB);console.log("Loaded main.js");function SR(n){const e={};for(const t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e}const sE=k2({state(){return{yesNoDialog:null,universalForm:null,toast:null,messageBox:null,api_get_req:null,startSpeechRecognition:null,ready:!1,loading_infos:"",loading_progress:0,version:"unknown",settingsChanged:!1,isConnected:!1,isModelOk:!1,isGenerating:!1,config:null,mountedPers:null,mountedPersArr:[],mountedExtensions:[],bindingsZoo:[],modelsArr:[],selectedModel:null,personalities:[],diskUsage:null,ramUsage:null,vramUsage:null,modelsZoo:[],installedModels:[],currentModel:null,extensionsZoo:[],databases:[]}},mutations:{setIsReady(n,e){n.ready=e},setIsConnected(n,e){n.isConnected=e},setIsModelOk(n,e){n.isModelOk=e},setIsGenerating(n,e){n.isGenerating=e},setConfig(n,e){n.config=e},setPersonalities(n,e){n.personalities=e},setMountedPers(n,e){n.mountedPers=e},setMountedPersArr(n,e){n.mountedPersArr=e},setMountedExtensions(n,e){n.mountedExtensions=e},setbindingsZoo(n,e){n.bindingsZoo=e},setModelsArr(n,e){n.modelsArr=e},setselectedModel(n,e){n.selectedModel=e},setDiskUsage(n,e){n.diskUsage=e},setRamUsage(n,e){n.ramUsage=e},setVramUsage(n,e){n.vramUsage=e},setModelsZoo(n,e){n.modelsZoo=e},setCurrentModel(n,e){n.currentModel=e},setExtensionsZoo(n,e){n.extensionsZoo=e},setDatabases(n,e){n.databases=e}},getters:{getIsConnected(n){return n.isConnected},getIsModelOk(n){return n.isModelOk},getIsGenerating(n){return n.isGenerating},getConfig(n){return n.config},getPersonalities(n){return n.personalities},getMountedPersArr(n){return n.mountedPersArr},getmmountedExtensions(n){return n.mountedExtensions},getMountedPers(n){return n.mountedPers},getbindingsZoo(n){return n.bindingsZoo},getModelsArr(n){return n.modelsArr},getDiskUsage(n){return n.diskUsage},getRamUsage(n){return n.ramUsage},getVramUsage(n){return n.vramUsage},getDatabasesList(n){return n.databases},getModelsZoo(n){return n.modelsZoo},getCurrentModel(n){return n.currentModel},getExtensionsZoo(n){return n.extensionsZoo}},actions:{async getVersion(){try{let n=await Ue.get("/get_lollms_webui_version",{});n&&(this.state.version=n.data.version)}catch{console.log("Coudln't get version")}},async refreshConfig({commit:n}){console.log("Fetching configuration");try{const e=await oi("get_config");e.active_personality_id<0&&(e.active_personality_id=0);let t=e.personalities[e.active_personality_id].split("/");e.personality_category=t[0],e.personality_folder=t[1],e.extensions.length>0?e.extension_category=e.extensions[-1]:e.extension_category="ai_sensors",console.log("Recovered config"),console.log(e),console.log("Committing config"),console.log(e),console.log(this.state.config),n("setConfig",e)}catch(e){console.log(e.message,"refreshConfig")}},async refreshDatabase({commit:n}){let e=await oi("list_databases");console.log("databases:",e),n("setDatabases",e)},async refreshPersonalitiesZoo({commit:n}){let e=[];const t=await oi("get_all_personalities"),i=Object.keys(t);console.log("Personalities recovered:"+this.state.config.personalities);for(let s=0;s{let c=!1;for(const u of this.state.config.personalities)if(u.includes(r+"/"+l.folder))if(c=!0,u.includes(":")){const h=u.split(":");l.language=h[1]}else l.language=null;let d={};return d=l,d.category=r,d.full_path=r+"/"+l.folder,d.isMounted=c,d});e.length==0?e=a:e=e.concat(a)}e.sort((s,r)=>s.name.localeCompare(r.name)),n("setPersonalities",e),console.log("Done loading personalities")},refreshMountedPersonalities({commit:n}){this.state.config.active_personality_id<0&&(this.state.config.active_personality_id=0);let e=[];const t=[];for(let i=0;ia.full_path==s||a.full_path==r[0]);if(o>=0){let a=SR(this.state.personalities[o]);r.length>1&&(a.language=r[1]),a?e.push(a):e.push(this.state.personalities[this.state.personalities.findIndex(l=>l.full_path=="generic/lollms")])}else t.push(i),console.log("Couldn't load personality : ",s)}for(let i=t.length-1;i>=0;i--)console.log("Removing personality : ",this.state.config.personalities[t[i]]),this.state.config.personalities.splice(t[i],1),this.state.config.active_personality_id>t[i]&&(this.state.config.active_personality_id-=1);n("setMountedPersArr",e),this.state.mountedPers=this.state.personalities[this.state.personalities.findIndex(i=>i.full_path==this.state.config.personalities[this.state.config.active_personality_id]||i.full_path+":"+i.language==this.state.config.personalities[this.state.config.active_personality_id])]},async refreshBindings({commit:n}){let e=await oi("list_bindings");n("setbindingsZoo",e)},async refreshModelsZoo({commit:n}){console.log("Fetching models");const e=await Ue.get("/get_available_models");n("setModelsZoo",e.data.filter(t=>t.variants&&t.variants.length>0))},async refreshModelStatus({commit:n}){let e=await oi("get_model_status");n("setIsModelOk",e.status)},async refreshModels({commit:n}){console.log("Fetching models");let e=await oi("list_models");console.log(`Found ${e}`);let t=await oi("get_active_model");console.log("Selected model ",t),t!=null&&n("setselectedModel",t.model),n("setModelsArr",e),console.log("setModelsArr",e),this.state.modelsZoo.map(s=>{s.isInstalled=e.includes(s.name)}),this.state.installedModels=this.state.modelsZoo.filter(s=>s.isInstalled);const i=this.state.modelsZoo.findIndex(s=>s.name==this.state.config.model_name);i!=-1&&n("setCurrentModel",this.state.modelsZoo[i])},async refreshExtensionsZoo({commit:n}){let e=[],t=await oi("list_extensions");const i=Object.keys(t);console.log("Extensions recovered:"+t);for(let s=0;s{let c=!1;for(const u of this.state.config.extensions)u.includes(r+"/"+l.folder)&&(c=!0);let d={};return d=l,d.category=r,d.full_path=r+"/"+l.folder,d.isMounted=c,d});e.length==0?e=a:e=e.concat(a)}e.sort((s,r)=>s.name.localeCompare(r.name)),console.log("Done loading extensions"),n("setExtensionsZoo",e)},refreshmountedExtensions({commit:n}){console.log("Mounting extensions");let e=[];const t=[];for(let i=0;io.full_path==s);if(r>=0){let o=SR(this.state.config.extensions[r]);o&&e.push(o)}else t.push(i),console.log("Couldn't load extension : ",s)}for(let i=t.length-1;i>=0;i--)console.log("Removing extensions : ",this.state.config.extensions[t[i]]),this.state.config.extensions.splice(t[i],1);n("setMountedExtensions",e)},async refreshDiskUsage({commit:n}){this.state.diskUsage=await oi("disk_usage")},async refreshRamUsage({commit:n}){this.state.ramUsage=await oi("ram_usage")},async refreshVramUsage({commit:n}){const e=await oi("vram_usage"),t=[];if(e.nb_gpus>0){for(let s=0;s LoLLMS WebUI - Welcome - + diff --git a/web/src/components/ChatBox.vue b/web/src/components/ChatBox.vue index a8681ec3..1bfd6593 100644 --- a/web/src/components/ChatBox.vue +++ b/web/src/components/ChatBox.vue @@ -144,7 +144,7 @@ ref="installedModels">
@@ -153,7 +153,7 @@
diff --git a/web/src/css/classic.css b/web/src/css/classic.css new file mode 100644 index 00000000..58abc8f6 --- /dev/null +++ b/web/src/css/classic.css @@ -0,0 +1,763 @@ +:root { + --baklava-control-color-primary: #5379b5; + --baklava-control-color-error: red; + --baklava-control-color-background: #2c2c2c; + --baklava-control-color-foreground: white; + --baklava-control-color-hover: #4c4c4c; + --baklava-control-color-active: #6c6c6c; + --baklava-control-color-disabled-foreground: gray; + --baklava-control-border-radius: 3px; + --baklava-sidebar-color-background: #3f3f3f; + --baklava-sidebar-color-foreground: white; + --baklava-node-color-background: #3f3f3fcc; + --baklava-node-color-foreground: white; + --baklava-node-color-hover: #5379b577; + --baklava-node-color-selected: var(--baklava-control-color-primary); + --baklava-node-color-resize-handle: var(--baklava-control-color-background); + --baklava-node-title-color-background: black; + --baklava-node-title-color-foreground: white; + --baklava-group-node-title-color-background: rgb(5, 75, 5); + --baklava-group-node-title-color-foreground: white; + --baklava-node-interface-port-tooltip-color-foreground: var(--baklava-control-color-primary); + --baklava-node-interface-port-tooltip-color-background: var(--baklava-editor-background-pattern-black); + --baklava-node-border-radius: 4px; + --baklava-color-connection-default: white; + --baklava-color-connection-allowed: green; + --baklava-color-connection-forbidden: red; + --baklava-editor-background-pattern-default: #232323; + --baklava-editor-background-pattern-line: #131313; + --baklava-editor-background-pattern-black: #00000022; + --baklava-context-menu-background: #000000cc; + --baklava-context-menu-shadow: 0 0 8px rgba(0, 0, 0, 0.65); + --baklava-toolbar-background: #0003; + --baklava-toolbar-foreground: white; + --baklava-node-palette-background: #0003; + --baklava-node-palette-foreground: white; + --baklava-visual-transition: 0.1s linear; +} + +.baklava-button { + background-color: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + transition: background-color var(--baklava-visual-transition); + border: none; + padding: 0.45em 0.35em; + border-radius: var(--baklava-control-border-radius); + font-size: inherit; + cursor: pointer; + overflow-x: hidden; +} +.baklava-button:hover { + background-color: var(--baklava-control-color-hover); +} +.baklava-button:active { + background-color: var(--baklava-control-color-primary); +} +.baklava-button.--block { + width: 100%; +} + +.baklava-checkbox { + display: flex; + padding: 0.35em 0; + cursor: pointer; + overflow-x: hidden; + align-items: center; +} +.baklava-checkbox .__checkmark-container { + display: flex; + background-color: var(--baklava-control-color-background); + border-radius: var(--baklava-control-border-radius); + transition: background-color var(--baklava-visual-transition); + width: 18px; + height: 18px; +} +.baklava-checkbox:hover .__checkmark-container { + background-color: var(--baklava-control-color-hover); +} +.baklava-checkbox:active .__checkmark-container { + background-color: var(--baklava-control-color-active); +} +.baklava-checkbox .__checkmark { + stroke-dasharray: 15; + stroke-dashoffset: 15; + stroke: var(--baklava-control-color-foreground); + stroke-width: 2px; + fill: none; + transition: stroke-dashoffset var(--baklava-visual-transition); +} +.baklava-checkbox.--checked .__checkmark { + stroke-dashoffset: 0; +} +.baklava-checkbox.--checked .__checkmark-container { + background-color: var(--baklava-control-color-primary); +} +.baklava-checkbox .__label { + margin-left: 0.5rem; +} + +.baklava-context-menu { + color: var(--baklava-control-color-foreground); + position: absolute; + display: inline-block; + z-index: 100; + background-color: var(--baklava-context-menu-background); + box-shadow: var(--baklava-context-menu-shadow); + border-radius: 0 0 var(--baklava-control-border-radius) var(--baklava-control-border-radius); + min-width: 6rem; + width: max-content; +} +.baklava-context-menu > .item { + display: flex; + align-items: center; + padding: 0.35em 1em; + transition: background 0.05s linear; + position: relative; +} +.baklava-context-menu > .item > .__label { + flex: 1 1 auto; +} +.baklava-context-menu > .item > .__submenu-icon { + margin-left: 0.75rem; +} +.baklava-context-menu > .item.--disabled { + color: var(--baklava-control-color-hover); +} +.baklava-context-menu > .item:not(.--header):not(.--active):not(.--disabled):hover { + background: var(--baklava-control-color-primary); +} +.baklava-context-menu > .item.--active { + background: var(--baklava-control-color-primary); +} +.baklava-context-menu.--nested { + left: 100%; + top: 0; +} +.baklava-context-menu.--flipped-x.--nested { + left: unset; + right: 100%; +} +.baklava-context-menu.--flipped-y.--nested { + top: unset; + bottom: 0; +} +.baklava-context-menu > .divider { + margin: 0.35em 0; + height: 1px; + background-color: var(--baklava-control-color-hover); +} + +.baklava-icon { + display: block; + height: 100%; +} +.baklava-icon.--clickable { + cursor: pointer; + transition: color var(--baklava-visual-transition); +} +.baklava-icon.--clickable:hover { + color: var(--baklava-control-color-primary); +} + +.baklava-input { + background-color: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + caret-color: var(--baklava-control-color-primary); + border: none; + border-radius: var(--baklava-control-border-radius); + padding: 0.45em 0.75em; + width: 100%; + transition: background-color var(--baklava-visual-transition); + font-size: inherit; + font: inherit; +} +.baklava-input:hover { + background-color: var(--baklava-control-color-hover); +} +.baklava-input:active { + background-color: var(--baklava-control-color-active); +} +.baklava-input:focus-visible { + outline: 1px solid var(--baklava-control-color-primary); +} +.baklava-input[type=number]::-webkit-inner-spin-button, .baklava-input[type=number]::-webkit-outer-spin-button { + -webkit-appearance: none; + margin: 0; +} +.baklava-input.--invalid { + box-shadow: 0 0 2px 2px var(--baklava-control-color-error); +} + +.baklava-num-input { + background: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + border-radius: var(--baklava-control-border-radius); + width: 100%; + display: grid; + grid-template-columns: 20px 1fr 20px; +} +.baklava-num-input > .__button { + display: flex; + flex: 0 0 auto; + width: 20px; + justify-content: center; + align-items: center; + transition: background var(--baklava-visual-transition); + cursor: pointer; +} +.baklava-num-input > .__button:hover { + background-color: var(--baklava-control-color-hover); +} +.baklava-num-input > .__button:active { + background-color: var(--baklava-control-color-active); +} +.baklava-num-input > .__button.--dec { + grid-area: 1/1/span 1/span 1; +} +.baklava-num-input > .__button.--dec > svg { + transform: rotateZ(90deg); +} +.baklava-num-input > .__button.--inc { + grid-area: 1/3/span 1/span 1; +} +.baklava-num-input > .__button.--inc > svg { + transform: rotateZ(-90deg); +} +.baklava-num-input > .__button path { + stroke: var(--baklava-control-color-foreground); + fill: var(--baklava-control-color-foreground); +} +.baklava-num-input > .__content { + grid-area: 1/2/span 1/span 1; + display: inline-flex; + cursor: pointer; + max-width: 100%; + min-width: 0; + align-items: center; + transition: background-color var(--baklava-visual-transition); +} +.baklava-num-input > .__content:hover { + background-color: var(--baklava-control-color-hover); +} +.baklava-num-input > .__content:active { + background-color: var(--baklava-control-color-active); +} +.baklava-num-input > .__content > .__label, .baklava-num-input > .__content > .__value { + margin: 0.35em 0; + padding: 0 0.5em; +} +.baklava-num-input > .__content > .__label { + flex: 1; + min-width: 0; + overflow: hidden; +} +.baklava-num-input > .__content > .__value { + text-align: right; +} +.baklava-num-input > .__content > input { + background-color: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + caret-color: var(--baklava-control-color-primary); + padding: 0.35em; + width: 100%; +} + +.baklava-select { + width: 100%; + position: relative; + color: var(--baklava-control-color-foreground); +} +.baklava-select.--open > .__selected { + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; +} +.baklava-select.--open > .__selected > .__icon { + transform: rotate(180deg); +} +.baklava-select > .__selected { + background-color: var(--baklava-control-color-background); + padding: 0.35em 0.75em; + border-radius: var(--baklava-control-border-radius); + transition: background var(--baklava-visual-transition); + min-height: 1.7em; + display: flex; + align-items: center; + cursor: pointer; +} +.baklava-select > .__selected:hover { + background: var(--baklava-control-color-hover); +} +.baklava-select > .__selected:active { + background: var(--baklava-control-color-active); +} +.baklava-select > .__selected > .__text { + flex: 1 0 auto; + flex-basis: 0; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +} +.baklava-select > .__selected > .__icon { + flex: 0 0 auto; + display: flex; + justify-content: center; + align-items: center; + transition: transform 0.25s ease; + width: 18px; + height: 18px; +} +.baklava-select > .__selected > .__icon path { + stroke: var(--baklava-control-color-foreground); + fill: var(--baklava-control-color-foreground); +} +.baklava-select > .__dropdown { + position: absolute; + top: 100%; + left: 0; + right: 0; + z-index: 10; + background-color: var(--baklava-context-menu-background); + filter: drop-shadow(0 0 4px black); + border-radius: 0 0 var(--baklava-control-border-radius) var(--baklava-control-border-radius); + max-height: 15em; + overflow-y: scroll; +} +.baklava-select > .__dropdown::-webkit-scrollbar { + width: 0px; + background: transparent; +} +.baklava-select > .__dropdown > .item { + padding: 0.35em; + padding-left: 1em; + transition: background 0.05s linear; +} +.baklava-select > .__dropdown > .item:not(.--header):not(.--active) { + cursor: pointer; +} +.baklava-select > .__dropdown > .item:not(.--header):not(.--active):hover { + background: var(--baklava-control-color-hover); +} +.baklava-select > .__dropdown > .item.--active { + background: var(--baklava-control-color-primary); +} +.baklava-select > .__dropdown > .item.--header { + color: var(--baklava-control-color-disabled-foreground); + border-bottom: 1px solid var(--baklava-control-color-disabled-foreground); + padding: 0.5em 0.35em; + padding-left: 1em; +} + +.baklava-slider { + background: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + border-radius: var(--baklava-control-border-radius); + position: relative; + cursor: pointer; +} +.baklava-slider > .__content { + display: flex; + position: relative; +} +.baklava-slider > .__content > .__label, .baklava-slider > .__content > .__value { + flex: 1 1 auto; + margin: 0.35em 0; + padding: 0 0.5em; + text-overflow: ellipsis; +} +.baklava-slider > .__content > .__value { + text-align: right; +} +.baklava-slider > .__content > input { + background-color: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + caret-color: var(--baklava-control-color-primary); + padding: 0.35em; + width: 100%; +} +.baklava-slider > .__slider { + position: absolute; + top: 0; + bottom: 0; + left: 0; + background-color: var(--baklava-control-color-primary); + border-radius: var(--baklava-control-border-radius); +} + +.baklava-connection { + stroke: var(--baklava-color-connection-default); + stroke-width: 2px; + fill: none; +} +.baklava-connection.--temporary { + stroke-width: 4px; + stroke-dasharray: 5 5; + stroke-dashoffset: 0; + animation: dash 1s linear infinite; + transform: translateY(-1px); +} +@keyframes dash { + to { + stroke-dashoffset: 20; + } +} +.baklava-connection.--allowed { + stroke: var(--baklava-color-connection-allowed); +} +.baklava-connection.--forbidden { + stroke: var(--baklava-color-connection-forbidden); +} + +.baklava-minimap { + position: absolute; + height: 15%; + width: 15%; + min-width: 150px; + max-width: 90%; + top: 20px; + right: 20px; + z-index: 900; +} + +.baklava-editor { + width: 100%; + height: 100%; + position: relative; + overflow: hidden; + outline: none !important; + font-family: "Lato", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; + font-size: 15px; + touch-action: none; +} +.baklava-editor .background { + background-color: var(--baklava-editor-background-pattern-default); + background-image: linear-gradient(var(--baklava-editor-background-pattern-black) 2px, transparent 2px), linear-gradient(90deg, var(--baklava-editor-background-pattern-black) 2px, transparent 2px), linear-gradient(var(--baklava-editor-background-pattern-line) 1px, transparent 1px), linear-gradient(90deg, var(--baklava-editor-background-pattern-line) 1px, transparent 1px); + background-repeat: repeat; + width: 100%; + height: 100%; + pointer-events: none !important; +} +.baklava-editor *:not(input):not(textarea) { + user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + touch-action: none; +} +.baklava-editor .input-user-select { + user-select: auto; + -moz-user-select: auto; + -webkit-user-select: auto; +} +.baklava-editor *, .baklava-editor *::after, .baklava-editor *::before { + box-sizing: border-box; +} +.baklava-editor.--temporary-connection { + cursor: crosshair; +} +.baklava-editor .connections-container { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + pointer-events: none !important; +} +.baklava-editor .node-container { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + pointer-events: none; +} +.baklava-editor .node-container * { + pointer-events: all; +} + +.baklava-ignore-mouse * { + pointer-events: none !important; +} + +.baklava-ignore-mouse .__port { + pointer-events: all !important; +} + +.baklava-node-interface { + padding: 0.25em 0; + position: relative; +} +.baklava-node-interface .__port { + position: absolute; + width: 10px; + height: 10px; + background: white; + border-radius: 50%; + top: calc(50% - 5px); + cursor: crosshair; +} +.baklava-node-interface .__port.--selected { + outline: 2px var(--baklava-color-connection-default) solid; + outline-offset: 4px; +} +.baklava-node-interface.--input { + text-align: left; + padding-left: 0.5em; +} +.baklava-node-interface.--input .__port { + left: -1.1em; +} +.baklava-node-interface.--output { + text-align: right; + padding-right: 0.5em; +} +.baklava-node-interface.--output .__port { + right: -1.1em; +} +.baklava-node-interface .__tooltip { + position: absolute; + left: 5px; + top: 15px; + transform: translate(-50%, 0%); + background: var(--baklava-node-interface-port-tooltip-color-background); + color: var(--baklava-node-interface-port-tooltip-color-foreground); + padding: 0.25em 0.5em; + text-align: center; + z-index: 2; +} + +.baklava-node-palette { + position: absolute; + left: 0; + top: 60px; + width: 250px; + height: calc(100% - 60px); + z-index: 3; + padding: 2rem; + overflow-y: auto; + background: var(--baklava-node-palette-background); + color: var(--baklava-node-palette-foreground); +} +.baklava-node-palette h1 { + margin-top: 2rem; +} + +.baklava-node.--palette { + position: unset; + margin: 1rem 0; + cursor: grab; +} +.baklava-node.--palette:first-child { + margin-top: 0; +} +.baklava-node.--palette .__title { + padding: 0.5rem; + border-radius: var(--baklava-node-border-radius); +} + +.baklava-dragged-node { + position: absolute; + width: calc(250px - 4rem); + height: 40px; + z-index: 4; + pointer-events: none; +} + +.baklava-node { + background: var(--baklava-node-color-background); + color: var(--baklava-node-color-foreground); + border: 1px solid transparent; + border-radius: var(--baklava-node-border-radius); + position: absolute; + box-shadow: 0 0 4px rgba(0, 0, 0, 0.8); + transition: border-color var(--baklava-visual-transition), box-shadow var(--baklava-visual-transition); + width: var(--width); +} +.baklava-node:hover { + border-color: var(--baklava-node-color-hover); +} +.baklava-node:hover .__resize-handle::after { + opacity: 1; +} +.baklava-node.--selected { + z-index: 5; + border-color: var(--baklava-node-color-selected); +} +.baklava-node.--dragging { + box-shadow: 0 0 12px rgba(0, 0, 0, 0.8); +} +.baklava-node.--dragging > .__title { + cursor: grabbing; +} +.baklava-node > .__title { + display: flex; + background: var(--baklava-node-title-color-background); + color: var(--baklava-node-title-color-foreground); + padding: 0.4em 0.75em; + border-radius: var(--baklava-node-border-radius) var(--baklava-node-border-radius) 0 0; + cursor: grab; +} +.baklava-node > .__title > *:first-child { + flex-grow: 1; +} +.baklava-node > .__title > .__title-label { + pointer-events: none; +} +.baklava-node > .__title > .__menu { + position: relative; + cursor: initial; +} +.baklava-node[data-node-type^=__baklava_] > .__title { + background: var(--baklava-group-node-title-color-background); + color: var(--baklava-group-node-title-color-foreground); +} +.baklava-node > .__content { + padding: 0.75em; +} +.baklava-node > .__content > div > div { + margin: 0.5em 0; +} +.baklava-node.--two-column > .__content { + display: grid; + grid-template-columns: 1fr 1fr; + grid-template-rows: auto auto; + grid-template-areas: ". ." ". ."; +} +.baklava-node.--two-column > .__content > .__inputs { + grid-row: 1; + grid-column: 1; +} +.baklava-node.--two-column > .__content > .__outputs { + grid-row: 1; + grid-column: 2; +} +.baklava-node .__resize-handle { + position: absolute; + right: 0; + bottom: 0; + width: 1rem; + height: 1rem; + transform: translateX(50%); + cursor: ew-resize; +} +.baklava-node .__resize-handle::after { + content: ""; + position: absolute; + bottom: 0; + left: -0.5rem; + width: 1rem; + height: 1rem; + opacity: 0; + border-bottom-right-radius: var(--baklava-node-border-radius); + transition: opacity var(--baklava-visual-transition); + background: linear-gradient(-45deg, transparent 10%, var(--baklava-node-color-resize-handle) 10%, var(--baklava-node-color-resize-handle) 15%, transparent 15%, transparent 30%, var(--baklava-node-color-resize-handle) 30%, var(--baklava-node-color-resize-handle) 35%, transparent 35%, transparent 50%, var(--baklava-node-color-resize-handle) 50%, var(--baklava-node-color-resize-handle) 55%, transparent 55%); +} + +.baklava-sidebar { + position: absolute; + height: 100%; + width: 25%; + min-width: 300px; + max-width: 90%; + top: 0; + right: 0; + z-index: 1000; + background-color: var(--baklava-sidebar-color-background); + color: var(--baklava-sidebar-color-foreground); + box-shadow: none; + overflow-x: hidden; + padding: 1em; + transform: translateX(100%); + transition: transform 0.5s; + display: flex; + flex-direction: column; +} +.baklava-sidebar.--open { + transform: translateX(0); + box-shadow: 0px 0px 15px black; +} +.baklava-sidebar .__resizer { + position: absolute; + left: 0; + top: 0; + height: 100%; + width: 4px; + cursor: col-resize; +} +.baklava-sidebar .__header { + display: flex; + align-items: center; +} +.baklava-sidebar .__header .__node-name { + margin-left: 0.5rem; +} +.baklava-sidebar .__close { + font-size: 2em; + border: none; + background: none; + color: inherit; + cursor: pointer; +} +.baklava-sidebar .__interface { + margin: 0.5em 0; +} + +.baklava-toolbar { + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 60px; + z-index: 3; + padding: 0.5rem 2rem; + background: var(--baklava-toolbar-background); + color: var(--baklava-toolbar-foreground); + display: flex; + align-items: center; +} + +.baklava-toolbar-entry { + margin-left: 0.5rem; + margin-right: 0.5rem; +} + +.baklava-toolbar-button { + color: var(--baklava-toolbar-foreground); + background: none; + border: none; + transition: color var(--baklava-visual-transition); +} +.baklava-toolbar-button:not([disabled]) { + cursor: pointer; +} +.baklava-toolbar-button:hover:not([disabled]) { + color: var(--baklava-control-color-primary); +} +.baklava-toolbar-button[disabled] { + color: var(--baklava-control-color-disabled-foreground); +} + +.slide-fade-enter-active { + transition: all 0.1s ease-out; +} + +.slide-fade-leave-active { + transition: all 0.1s ease-out; +} + +.slide-fade-enter-from, +.slide-fade-leave-to { + transform: translateY(5px); + opacity: 0; +} + +.fade-enter-active { + transition: opacity 0.1s ease-out !important; +} + +.fade-leave-active { + transition: opacity 0.1s ease-out !important; +} + +.fade-enter-from, +.fade-leave-to { + opacity: 0; +} \ No newline at end of file diff --git a/web/src/css/syrup-dark.css b/web/src/css/syrup-dark.css new file mode 100644 index 00000000..e9f60531 --- /dev/null +++ b/web/src/css/syrup-dark.css @@ -0,0 +1,763 @@ +:root { + --baklava-control-color-primary: #e28b46; + --baklava-control-color-error: #d00000; + --baklava-control-color-background: #2c3748; + --baklava-control-color-foreground: white; + --baklava-control-color-hover: #455670; + --baklava-control-color-active: #556986; + --baklava-control-color-disabled-foreground: #666c75; + --baklava-control-border-radius: 3px; + --baklava-sidebar-color-background: #1b202c; + --baklava-sidebar-color-foreground: white; + --baklava-node-color-background: #1b202c; + --baklava-node-color-foreground: white; + --baklava-node-color-hover: #e28c4677; + --baklava-node-color-selected: var(--baklava-control-color-primary); + --baklava-node-color-resize-handle: var(--baklava-control-color-background); + --baklava-node-title-color-background: #151a24; + --baklava-node-title-color-foreground: white; + --baklava-group-node-title-color-background: #215636; + --baklava-group-node-title-color-foreground: white; + --baklava-node-interface-port-tooltip-color-foreground: var(--baklava-control-color-primary); + --baklava-node-interface-port-tooltip-color-background: var(--baklava-editor-background-pattern-black); + --baklava-node-border-radius: 6px; + --baklava-color-connection-default: #737f96; + --baklava-color-connection-allowed: #48bc79; + --baklava-color-connection-forbidden: #bc4848; + --baklava-editor-background-pattern-default: #202b3c; + --baklava-editor-background-pattern-line: #263140; + --baklava-editor-background-pattern-black: #263140; + --baklava-context-menu-background: #1b202c; + --baklava-context-menu-shadow: 0 0 8px rgba(0, 0, 0, 0.65); + --baklava-toolbar-background: #1b202caa; + --baklava-toolbar-foreground: white; + --baklava-node-palette-background: #1b202caa; + --baklava-node-palette-foreground: white; + --baklava-visual-transition: 0.1s linear; +} + +.baklava-button { + background-color: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + transition: background-color var(--baklava-visual-transition); + border: none; + padding: 0.45em 0.35em; + border-radius: var(--baklava-control-border-radius); + font-size: inherit; + cursor: pointer; + overflow-x: hidden; +} +.baklava-button:hover { + background-color: var(--baklava-control-color-hover); +} +.baklava-button:active { + background-color: var(--baklava-control-color-primary); +} +.baklava-button.--block { + width: 100%; +} + +.baklava-checkbox { + display: flex; + padding: 0.35em 0; + cursor: pointer; + overflow-x: hidden; + align-items: center; +} +.baklava-checkbox .__checkmark-container { + display: flex; + background-color: var(--baklava-control-color-background); + border-radius: var(--baklava-control-border-radius); + transition: background-color var(--baklava-visual-transition); + width: 18px; + height: 18px; +} +.baklava-checkbox:hover .__checkmark-container { + background-color: var(--baklava-control-color-hover); +} +.baklava-checkbox:active .__checkmark-container { + background-color: var(--baklava-control-color-active); +} +.baklava-checkbox .__checkmark { + stroke-dasharray: 15; + stroke-dashoffset: 15; + stroke: var(--baklava-control-color-foreground); + stroke-width: 2px; + fill: none; + transition: stroke-dashoffset var(--baklava-visual-transition); +} +.baklava-checkbox.--checked .__checkmark { + stroke-dashoffset: 0; +} +.baklava-checkbox.--checked .__checkmark-container { + background-color: var(--baklava-control-color-primary); +} +.baklava-checkbox .__label { + margin-left: 0.5rem; +} + +.baklava-context-menu { + color: var(--baklava-control-color-foreground); + position: absolute; + display: inline-block; + z-index: 100; + background-color: var(--baklava-context-menu-background); + box-shadow: var(--baklava-context-menu-shadow); + border-radius: 0 0 var(--baklava-control-border-radius) var(--baklava-control-border-radius); + min-width: 6rem; + width: max-content; +} +.baklava-context-menu > .item { + display: flex; + align-items: center; + padding: 0.35em 1em; + transition: background 0.05s linear; + position: relative; +} +.baklava-context-menu > .item > .__label { + flex: 1 1 auto; +} +.baklava-context-menu > .item > .__submenu-icon { + margin-left: 0.75rem; +} +.baklava-context-menu > .item.--disabled { + color: var(--baklava-control-color-hover); +} +.baklava-context-menu > .item:not(.--header):not(.--active):not(.--disabled):hover { + background: var(--baklava-control-color-primary); +} +.baklava-context-menu > .item.--active { + background: var(--baklava-control-color-primary); +} +.baklava-context-menu.--nested { + left: 100%; + top: 0; +} +.baklava-context-menu.--flipped-x.--nested { + left: unset; + right: 100%; +} +.baklava-context-menu.--flipped-y.--nested { + top: unset; + bottom: 0; +} +.baklava-context-menu > .divider { + margin: 0.35em 0; + height: 1px; + background-color: var(--baklava-control-color-hover); +} + +.baklava-icon { + display: block; + height: 100%; +} +.baklava-icon.--clickable { + cursor: pointer; + transition: color var(--baklava-visual-transition); +} +.baklava-icon.--clickable:hover { + color: var(--baklava-control-color-primary); +} + +.baklava-input { + background-color: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + caret-color: var(--baklava-control-color-primary); + border: none; + border-radius: var(--baklava-control-border-radius); + padding: 0.45em 0.75em; + width: 100%; + transition: background-color var(--baklava-visual-transition); + font-size: inherit; + font: inherit; +} +.baklava-input:hover { + background-color: var(--baklava-control-color-hover); +} +.baklava-input:active { + background-color: var(--baklava-control-color-active); +} +.baklava-input:focus-visible { + outline: 1px solid var(--baklava-control-color-primary); +} +.baklava-input[type=number]::-webkit-inner-spin-button, .baklava-input[type=number]::-webkit-outer-spin-button { + -webkit-appearance: none; + margin: 0; +} +.baklava-input.--invalid { + box-shadow: 0 0 2px 2px var(--baklava-control-color-error); +} + +.baklava-num-input { + background: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + border-radius: var(--baklava-control-border-radius); + width: 100%; + display: grid; + grid-template-columns: 20px 1fr 20px; +} +.baklava-num-input > .__button { + display: flex; + flex: 0 0 auto; + width: 20px; + justify-content: center; + align-items: center; + transition: background var(--baklava-visual-transition); + cursor: pointer; +} +.baklava-num-input > .__button:hover { + background-color: var(--baklava-control-color-hover); +} +.baklava-num-input > .__button:active { + background-color: var(--baklava-control-color-active); +} +.baklava-num-input > .__button.--dec { + grid-area: 1/1/span 1/span 1; +} +.baklava-num-input > .__button.--dec > svg { + transform: rotateZ(90deg); +} +.baklava-num-input > .__button.--inc { + grid-area: 1/3/span 1/span 1; +} +.baklava-num-input > .__button.--inc > svg { + transform: rotateZ(-90deg); +} +.baklava-num-input > .__button path { + stroke: var(--baklava-control-color-foreground); + fill: var(--baklava-control-color-foreground); +} +.baklava-num-input > .__content { + grid-area: 1/2/span 1/span 1; + display: inline-flex; + cursor: pointer; + max-width: 100%; + min-width: 0; + align-items: center; + transition: background-color var(--baklava-visual-transition); +} +.baklava-num-input > .__content:hover { + background-color: var(--baklava-control-color-hover); +} +.baklava-num-input > .__content:active { + background-color: var(--baklava-control-color-active); +} +.baklava-num-input > .__content > .__label, .baklava-num-input > .__content > .__value { + margin: 0.35em 0; + padding: 0 0.5em; +} +.baklava-num-input > .__content > .__label { + flex: 1; + min-width: 0; + overflow: hidden; +} +.baklava-num-input > .__content > .__value { + text-align: right; +} +.baklava-num-input > .__content > input { + background-color: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + caret-color: var(--baklava-control-color-primary); + padding: 0.35em; + width: 100%; +} + +.baklava-select { + width: 100%; + position: relative; + color: var(--baklava-control-color-foreground); +} +.baklava-select.--open > .__selected { + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; +} +.baklava-select.--open > .__selected > .__icon { + transform: rotate(180deg); +} +.baklava-select > .__selected { + background-color: var(--baklava-control-color-background); + padding: 0.35em 0.75em; + border-radius: var(--baklava-control-border-radius); + transition: background var(--baklava-visual-transition); + min-height: 1.7em; + display: flex; + align-items: center; + cursor: pointer; +} +.baklava-select > .__selected:hover { + background: var(--baklava-control-color-hover); +} +.baklava-select > .__selected:active { + background: var(--baklava-control-color-active); +} +.baklava-select > .__selected > .__text { + flex: 1 0 auto; + flex-basis: 0; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +} +.baklava-select > .__selected > .__icon { + flex: 0 0 auto; + display: flex; + justify-content: center; + align-items: center; + transition: transform 0.25s ease; + width: 18px; + height: 18px; +} +.baklava-select > .__selected > .__icon path { + stroke: var(--baklava-control-color-foreground); + fill: var(--baklava-control-color-foreground); +} +.baklava-select > .__dropdown { + position: absolute; + top: 100%; + left: 0; + right: 0; + z-index: 10; + background-color: var(--baklava-context-menu-background); + filter: drop-shadow(0 0 4px black); + border-radius: 0 0 var(--baklava-control-border-radius) var(--baklava-control-border-radius); + max-height: 15em; + overflow-y: scroll; +} +.baklava-select > .__dropdown::-webkit-scrollbar { + width: 0px; + background: transparent; +} +.baklava-select > .__dropdown > .item { + padding: 0.35em; + padding-left: 1em; + transition: background 0.05s linear; +} +.baklava-select > .__dropdown > .item:not(.--header):not(.--active) { + cursor: pointer; +} +.baklava-select > .__dropdown > .item:not(.--header):not(.--active):hover { + background: var(--baklava-control-color-hover); +} +.baklava-select > .__dropdown > .item.--active { + background: var(--baklava-control-color-primary); +} +.baklava-select > .__dropdown > .item.--header { + color: var(--baklava-control-color-disabled-foreground); + border-bottom: 1px solid var(--baklava-control-color-disabled-foreground); + padding: 0.5em 0.35em; + padding-left: 1em; +} + +.baklava-slider { + background: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + border-radius: var(--baklava-control-border-radius); + position: relative; + cursor: pointer; +} +.baklava-slider > .__content { + display: flex; + position: relative; +} +.baklava-slider > .__content > .__label, .baklava-slider > .__content > .__value { + flex: 1 1 auto; + margin: 0.35em 0; + padding: 0 0.5em; + text-overflow: ellipsis; +} +.baklava-slider > .__content > .__value { + text-align: right; +} +.baklava-slider > .__content > input { + background-color: var(--baklava-control-color-background); + color: var(--baklava-control-color-foreground); + caret-color: var(--baklava-control-color-primary); + padding: 0.35em; + width: 100%; +} +.baklava-slider > .__slider { + position: absolute; + top: 0; + bottom: 0; + left: 0; + background-color: var(--baklava-control-color-primary); + border-radius: var(--baklava-control-border-radius); +} + +.baklava-connection { + stroke: var(--baklava-color-connection-default); + stroke-width: 2px; + fill: none; +} +.baklava-connection.--temporary { + stroke-width: 4px; + stroke-dasharray: 5 5; + stroke-dashoffset: 0; + animation: dash 1s linear infinite; + transform: translateY(-1px); +} +@keyframes dash { + to { + stroke-dashoffset: 20; + } +} +.baklava-connection.--allowed { + stroke: var(--baklava-color-connection-allowed); +} +.baklava-connection.--forbidden { + stroke: var(--baklava-color-connection-forbidden); +} + +.baklava-minimap { + position: absolute; + height: 15%; + width: 15%; + min-width: 150px; + max-width: 90%; + top: 20px; + right: 20px; + z-index: 900; +} + +.baklava-editor { + width: 100%; + height: 100%; + position: relative; + overflow: hidden; + outline: none !important; + font-family: "Lato", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; + font-size: 15px; + touch-action: none; +} +.baklava-editor .background { + background-color: var(--baklava-editor-background-pattern-default); + background-image: linear-gradient(var(--baklava-editor-background-pattern-black) 2px, transparent 2px), linear-gradient(90deg, var(--baklava-editor-background-pattern-black) 2px, transparent 2px), linear-gradient(var(--baklava-editor-background-pattern-line) 1px, transparent 1px), linear-gradient(90deg, var(--baklava-editor-background-pattern-line) 1px, transparent 1px); + background-repeat: repeat; + width: 100%; + height: 100%; + pointer-events: none !important; +} +.baklava-editor *:not(input):not(textarea) { + user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + touch-action: none; +} +.baklava-editor .input-user-select { + user-select: auto; + -moz-user-select: auto; + -webkit-user-select: auto; +} +.baklava-editor *, .baklava-editor *::after, .baklava-editor *::before { + box-sizing: border-box; +} +.baklava-editor.--temporary-connection { + cursor: crosshair; +} +.baklava-editor .connections-container { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + pointer-events: none !important; +} +.baklava-editor .node-container { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + pointer-events: none; +} +.baklava-editor .node-container * { + pointer-events: all; +} + +.baklava-ignore-mouse * { + pointer-events: none !important; +} + +.baklava-ignore-mouse .__port { + pointer-events: all !important; +} + +.baklava-node-interface { + padding: 0.25em 0; + position: relative; +} +.baklava-node-interface .__port { + position: absolute; + width: 10px; + height: 10px; + background: white; + border-radius: 50%; + top: calc(50% - 5px); + cursor: crosshair; +} +.baklava-node-interface .__port.--selected { + outline: 2px var(--baklava-color-connection-default) solid; + outline-offset: 4px; +} +.baklava-node-interface.--input { + text-align: left; + padding-left: 0.5em; +} +.baklava-node-interface.--input .__port { + left: -1.1em; +} +.baklava-node-interface.--output { + text-align: right; + padding-right: 0.5em; +} +.baklava-node-interface.--output .__port { + right: -1.1em; +} +.baklava-node-interface .__tooltip { + position: absolute; + left: 5px; + top: 15px; + transform: translate(-50%, 0%); + background: var(--baklava-node-interface-port-tooltip-color-background); + color: var(--baklava-node-interface-port-tooltip-color-foreground); + padding: 0.25em 0.5em; + text-align: center; + z-index: 2; +} + +.baklava-node-palette { + position: absolute; + left: 0; + top: 60px; + width: 250px; + height: calc(100% - 60px); + z-index: 3; + padding: 2rem; + overflow-y: auto; + background: var(--baklava-node-palette-background); + color: var(--baklava-node-palette-foreground); +} +.baklava-node-palette h1 { + margin-top: 2rem; +} + +.baklava-node.--palette { + position: unset; + margin: 1rem 0; + cursor: grab; +} +.baklava-node.--palette:first-child { + margin-top: 0; +} +.baklava-node.--palette .__title { + padding: 0.5rem; + border-radius: var(--baklava-node-border-radius); +} + +.baklava-dragged-node { + position: absolute; + width: calc(250px - 4rem); + height: 40px; + z-index: 4; + pointer-events: none; +} + +.baklava-node { + background: var(--baklava-node-color-background); + color: var(--baklava-node-color-foreground); + border: 1px solid transparent; + border-radius: var(--baklava-node-border-radius); + position: absolute; + box-shadow: 0 0 4px rgba(0, 0, 0, 0.8); + transition: border-color var(--baklava-visual-transition), box-shadow var(--baklava-visual-transition); + width: var(--width); +} +.baklava-node:hover { + border-color: var(--baklava-node-color-hover); +} +.baklava-node:hover .__resize-handle::after { + opacity: 1; +} +.baklava-node.--selected { + z-index: 5; + border-color: var(--baklava-node-color-selected); +} +.baklava-node.--dragging { + box-shadow: 0 0 12px rgba(0, 0, 0, 0.8); +} +.baklava-node.--dragging > .__title { + cursor: grabbing; +} +.baklava-node > .__title { + display: flex; + background: var(--baklava-node-title-color-background); + color: var(--baklava-node-title-color-foreground); + padding: 0.4em 0.75em; + border-radius: var(--baklava-node-border-radius) var(--baklava-node-border-radius) 0 0; + cursor: grab; +} +.baklava-node > .__title > *:first-child { + flex-grow: 1; +} +.baklava-node > .__title > .__title-label { + pointer-events: none; +} +.baklava-node > .__title > .__menu { + position: relative; + cursor: initial; +} +.baklava-node[data-node-type^=__baklava_] > .__title { + background: var(--baklava-group-node-title-color-background); + color: var(--baklava-group-node-title-color-foreground); +} +.baklava-node > .__content { + padding: 0.75em; +} +.baklava-node > .__content > div > div { + margin: 0.5em 0; +} +.baklava-node.--two-column > .__content { + display: grid; + grid-template-columns: 1fr 1fr; + grid-template-rows: auto auto; + grid-template-areas: ". ." ". ."; +} +.baklava-node.--two-column > .__content > .__inputs { + grid-row: 1; + grid-column: 1; +} +.baklava-node.--two-column > .__content > .__outputs { + grid-row: 1; + grid-column: 2; +} +.baklava-node .__resize-handle { + position: absolute; + right: 0; + bottom: 0; + width: 1rem; + height: 1rem; + transform: translateX(50%); + cursor: ew-resize; +} +.baklava-node .__resize-handle::after { + content: ""; + position: absolute; + bottom: 0; + left: -0.5rem; + width: 1rem; + height: 1rem; + opacity: 0; + border-bottom-right-radius: var(--baklava-node-border-radius); + transition: opacity var(--baklava-visual-transition); + background: linear-gradient(-45deg, transparent 10%, var(--baklava-node-color-resize-handle) 10%, var(--baklava-node-color-resize-handle) 15%, transparent 15%, transparent 30%, var(--baklava-node-color-resize-handle) 30%, var(--baklava-node-color-resize-handle) 35%, transparent 35%, transparent 50%, var(--baklava-node-color-resize-handle) 50%, var(--baklava-node-color-resize-handle) 55%, transparent 55%); +} + +.baklava-sidebar { + position: absolute; + height: 100%; + width: 25%; + min-width: 300px; + max-width: 90%; + top: 0; + right: 0; + z-index: 1000; + background-color: var(--baklava-sidebar-color-background); + color: var(--baklava-sidebar-color-foreground); + box-shadow: none; + overflow-x: hidden; + padding: 1em; + transform: translateX(100%); + transition: transform 0.5s; + display: flex; + flex-direction: column; +} +.baklava-sidebar.--open { + transform: translateX(0); + box-shadow: 0px 0px 15px black; +} +.baklava-sidebar .__resizer { + position: absolute; + left: 0; + top: 0; + height: 100%; + width: 4px; + cursor: col-resize; +} +.baklava-sidebar .__header { + display: flex; + align-items: center; +} +.baklava-sidebar .__header .__node-name { + margin-left: 0.5rem; +} +.baklava-sidebar .__close { + font-size: 2em; + border: none; + background: none; + color: inherit; + cursor: pointer; +} +.baklava-sidebar .__interface { + margin: 0.5em 0; +} + +.baklava-toolbar { + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 60px; + z-index: 3; + padding: 0.5rem 2rem; + background: var(--baklava-toolbar-background); + color: var(--baklava-toolbar-foreground); + display: flex; + align-items: center; +} + +.baklava-toolbar-entry { + margin-left: 0.5rem; + margin-right: 0.5rem; +} + +.baklava-toolbar-button { + color: var(--baklava-toolbar-foreground); + background: none; + border: none; + transition: color var(--baklava-visual-transition); +} +.baklava-toolbar-button:not([disabled]) { + cursor: pointer; +} +.baklava-toolbar-button:hover:not([disabled]) { + color: var(--baklava-control-color-primary); +} +.baklava-toolbar-button[disabled] { + color: var(--baklava-control-color-disabled-foreground); +} + +.slide-fade-enter-active { + transition: all 0.1s ease-out; +} + +.slide-fade-leave-active { + transition: all 0.1s ease-out; +} + +.slide-fade-enter-from, +.slide-fade-leave-to { + transform: translateY(5px); + opacity: 0; +} + +.fade-enter-active { + transition: opacity 0.1s ease-out !important; +} + +.fade-leave-active { + transition: opacity 0.1s ease-out !important; +} + +.fade-enter-from, +.fade-leave-to { + opacity: 0; +} \ No newline at end of file diff --git a/web/src/nodes/Personality.js b/web/src/nodes/Personality.js new file mode 100644 index 00000000..6ea78613 --- /dev/null +++ b/web/src/nodes/Personality.js @@ -0,0 +1,33 @@ +import { defineNode, NodeInterface, TextInterface, SelectInterface } from "baklavajs"; +import axios from 'axios'; +import { store } from '../main' + +export const AgentNode = defineNode({ + type: "PersonalityNode", + title: "Personality", + inputs: { + request: () => new NodeInterface("Request", ""), + agent_name: () => + new SelectInterface("Personality", "", store.state.config.personalities).setPort( + false + ), + }, + outputs: { + display: () => new TextInterface("Output", ""), + response: () => new NodeInterface("Response", "") + }, + async calculate({ request }) { + console.log(store.state.config.personalities) + let response = ''; + try { + const result = await axios.get('/generate', { params: { text: request } }); + response = result.data; + } catch (error) { + console.error(error); + } + return { + display: response, + response: response + }; + } +}); diff --git a/web/src/nodes/Rag.js b/web/src/nodes/Rag.js new file mode 100644 index 00000000..8065e43c --- /dev/null +++ b/web/src/nodes/Rag.js @@ -0,0 +1,29 @@ +import { defineNode, NodeInterface, TextInputInterface } from "baklavajs"; +import axios from 'axios'; +import { store } from '../main' + +export const RAGNode = defineNode({ + type: "RAGNode", + title: "RAG", + inputs: { + request: () => new NodeInterface("Prompt", ""), + document_path: () => new TextInputInterface("Document path", "").setPort( + false + ), + }, + outputs: { + prompt: () => new NodeInterface("Prompt with Data", "") + }, + async calculate({ request, document_path }) { + let response = ''; + try { + const result = await axios.get('/rag', { params: { text: request, doc_path:document_path } }); + response = result.data; + } catch (error) { + console.error(error); + } + return { + response: response + }; + } +}); diff --git a/web/src/nodes/Task.js b/web/src/nodes/Task.js new file mode 100644 index 00000000..7c16f9bc --- /dev/null +++ b/web/src/nodes/Task.js @@ -0,0 +1,22 @@ +import { + defineNode, + TextInputInterface, + NodeInterface + } from "baklavajs"; + + export const TaskNode = defineNode({ + type: "Task", + title: "Task", + inputs: { + description: () => new TextInputInterface("Task description", "").setPort( + false + ), + }, + outputs: { + prompt: () => new NodeInterface("Prompt") + }, + calculate({ description }) { + return { prompt: description }; + } + }); + \ No newline at end of file diff --git a/web/src/nodes/TaskDispatcher.js b/web/src/nodes/TaskDispatcher.js new file mode 100644 index 00000000..4b961760 --- /dev/null +++ b/web/src/nodes/TaskDispatcher.js @@ -0,0 +1,23 @@ +import { + defineNode, + TextInputInterface, + NodeInterface + } from "baklavajs"; + + export const TaskDispatcherNode = defineNode({ + type: "Task", + title: "Task", + description: { + + }, + inputs: { + description: () => new TextInputInterface("Description", ""), + }, + outputs: { + result: () => new NodeInterface("Result") + }, + calculate({ description }) { + return { result: description }; + } + }); + \ No newline at end of file diff --git a/web/src/views/NodesView.vue b/web/src/views/NodesView.vue index 5458c4ed..cdc2219e 100644 --- a/web/src/views/NodesView.vue +++ b/web/src/views/NodesView.vue @@ -17,7 +17,7 @@ //import "../css/classic.css"; import "@baklavajs/themes/dist/syrup-dark.css"; - import { AgentNode } from "../nodes/Agent"; + import { AgentNode } from "../nodes/Personality"; import { RAGNode } from "../nodes/Rag"; import { TaskNode } from "../nodes/Task"; diff --git a/zoos/bindings_zoo b/zoos/bindings_zoo index 8c9d4eae..3b48b2cd 160000 --- a/zoos/bindings_zoo +++ b/zoos/bindings_zoo @@ -1 +1 @@ -Subproject commit 8c9d4eae604734f1bb04d8b529727546dba22c10 +Subproject commit 3b48b2cdf95665a1472e3274b538b39f97bd93eb diff --git a/zoos/personalities_zoo b/zoos/personalities_zoo index cd981705..211dc1c9 160000 --- a/zoos/personalities_zoo +++ b/zoos/personalities_zoo @@ -1 +1 @@ -Subproject commit cd9817054bee86a377a589b6598c0076095f7992 +Subproject commit 211dc1c9c449e528eabe04a4592a025f7737a78c