import{N as y,r as l,a1 as s,a2 as I}from"./DGA3dmy8.js";import{u as p}from"./Bp4HP0eH.js";const S="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let k=(e=21)=>{let c="",t=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)c+=S[t[e]&63];return c};const i=e=>{var t;if("dynamic"in e)return typeof e.dynamic=="object"&&"command"in e.dynamic?i({script:e.dynamic}):i({command:e.dynamic});if("script"in e&&e.script.label)return e.script.label;const c="command"in e?e.command:(t=e.script)==null?void 0:t.command;return typeof c=="object"?"npm"in c?c.npm:"shell"in c?c.shell:"Custom Function":c??"Custom Function"},u=(e,c)=>{var r;if("dynamic"in e)return typeof e.dynamic=="object"&&"command"in e.dynamic?u({script:e.dynamic},c):u({command:e.dynamic},c);const t="command"in e?e.command:(r=e.script)==null?void 0:r.command;let a="";return typeof t=="object"?("package"in t&&t.package===!0&&(a+=`cd ${c} && `),"npm"in t?a+=`npm run ${t.npm}`:"shell"in t?a+=t.shell:a+="::custom_function::"):typeof t=="string"?a+=t:a+="::custom_function::",a};var g=(e=>(e.Closed="closed",e.Opened="opened",e))(g||{});const h=e=>new EventSource("/event-stream?clientId=0"),n=l([]),o=l(!0),v=e=>n.value.findIndex(c=>c.id===e),w=e=>n.value.find(c=>c.id===e),b=async()=>{const e=await $fetch("/api/active-script");o.value=!1;const c=await p();n.value=e.scripts.map(t=>({package:c.value.packages[t.packageId]||null,packageId:t.packageId??null,commandId:t.commandId??null,command:t.command,createdAt:t.createdAt,id:t.id,logs:t.logs.map(a=>({date:new Date(a.date),text:a.text,type:a.type})),status:t.status}))};b();I([n],([e])=>{o.value||$fetch("/api/active-script",{method:"POST",body:{scripts:e}})},{deep:!0});const f=l();f.value=h(),f.value.addEventListener("message",e=>{const c=JSON.parse(e.data),t=v(c.id);if(n.value[t]){if(c.message){const a={text:c.message,date:new Date,type:c.type};n.value[t].logs=n.value[t].logs.concat(a).slice(-100)}c.status&&(n.value[t].status=c.status)}});const O=()=>{const e=y("interactiveTerminal",!1);return{scripts:n,runScript:async a=>{var m;const r=await p();a.id??(a.id=k()),a.interactiveTerminal=e.value;const d="command"in a?a.command:(m=r.value.packages[a.packageId??""])==null?void 0:m.scripts[a.commandId];d&&(n.value=n.value.concat({package:"packageId"in a&&r.value.packages[a.packageId]||null,packageId:"packageId"in a?a.packageId??null:null,commandId:"commandId"in a?a.commandId:null,command:d,createdAt:new Date,id:a.id,logs:[],status:g.Opened}).slice(-10),s.success(`Running script ${i({dynamic:d})}.`),await $fetch("/api/run-script",{method:"POST",body:a,timeout:1e3}))},killScript:async a=>{a!==void 0&&await $fetch("/api/kill-script",{method:"POST",body:{id:a}}).catch(r=>{s("Error Occurred",{description:r.data.message})})},getScriptIndex:v,getScript:w}};export{g as S,u as a,i as g,k as n,O as u};
//# sourceMappingURL=CjwkogD-.js.map
