"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("solid-js"),i=require("@opencode/plugin/gui"),y=require("@opencode/plugin/rpc"),m={type:"object",properties:{},additionalProperties:!1},v=y.Rpc.define({id:"vllm-autostart",methods:{status:{input:m,output:{type:"object",properties:{running:{type:"boolean"},owned:{type:"boolean"},starting:{type:"boolean"},model:{type:"string"}},required:["running","owned","starting","model"],additionalProperties:!1}},eject:{input:m,output:{type:"object",properties:{stopped:{type:"boolean"},reason:{type:"string"}},required:["stopped","reason"],additionalProperties:!1}}},events:{}}),w=i.Plugin.define({i18n:{en:{"titlebar.stop":"Stop vLLM","titlebar.stopping":"Stopping vLLM","titlebar.title":"Eject the loaded model and stop the vLLM server","command.eject":"vLLM: Eject loaded model","command.ejectDescription":"Stop the local vLLM server this plugin started","command.group":"vLLM","toast.stopped":"vLLM stopped","toast.stoppedDescription":"The model was unloaded and the server stopped.","toast.notOwned":"vLLM was not started by this plugin","toast.notOwnedDescription":"The server was left running.","toast.error":"Could not stop vLLM"}},setup(e){const[a,d]=o.createSignal(!1),[l,p]=o.createSignal(!1),[f,u]=o.createSignal(!1),[s,c]=o.createSignal(!1);let n=!1;const r=async()=>{try{const t=await e.client.rpc(v).status({});if(n)return;d(!!t.running),p(!!t.owned),u(!!t.starting)}catch{if(n)return;d(!1),p(!1),u(!1)}};r();const b=setInterval(()=>{r()},5e3);e.signal.addEventListener("abort",()=>{n=!0,clearInterval(b)});const g=async()=>{if(!s()){c(!0);try{const t=await e.client.rpc(v).eject({});t.stopped?e.toast.show({title:e.t("toast.stopped"),description:e.t("toast.stoppedDescription"),variant:"success"}):t.reason==="not-owned"&&e.toast.show({title:e.t("toast.notOwned"),description:e.t("toast.notOwnedDescription")})}catch(t){e.toast.show({title:e.t("toast.error"),description:t instanceof Error?t.message:String(t),variant:"error"})}finally{c(!1),r()}}};e.add(i.TitlebarItem,()=>{if(!(!a()||!l()))return{id:"eject",label:s()||f()?e.t("titlebar.stopping"):e.t("titlebar.stop"),title:e.t("titlebar.title"),icon:"stop",busy:s(),run:()=>{g()}}}),e.add(i.Command,()=>({id:"eject",title:e.t("command.eject"),description:e.t("command.ejectDescription"),keywords:"vllm stop unload eject gpu model",group:e.t("command.group"),section:"model",enabled:a()&&l(),run:()=>{g()}}))}});exports.default=w;