import{Yr as e,tr as t}from"./KXnyWfWg.js";import{x as n}from"./BPCoDq-Y.js";var r=1e3;const i=t(`kernel`,()=>{let t=e(null),i=e([]),a=e(!1),o=null,s=async()=>{t.value=await n().getKernelStatus()},c=async()=>{t.value=await n().startKernel()},l=async()=>{t.value=await n().stopKernel()},u=async()=>{t.value=await n().restartKernel()},d=async()=>{t.value=await n().rollbackKernel()},f=async()=>{t.value=await n().recoverKernel()},p=e=>{i.value.push(e),i.value.length>r&&i.value.splice(0,i.value.length-r)};return{state:t,logs:i,connected:a,fetchStatus:s,start:c,stop:l,restart:u,rollback:d,recover:f,connectLogs:()=>{o||(o=new EventSource(n().logsUrl()),a.value=!0,o.onmessage=e=>{let n;try{n=JSON.parse(e.data)}catch{return}let r=n;if(r.type===`log`)p({stream:r.stream,line:r.line,ts:r.ts});else if(r.type===`state`){let{type:e,...n}=r;t.value=n}},o.onerror=()=>{a.value=!1})},disconnectLogs:()=>{o?.close(),o=null,a.value=!1},clearLogs:()=>{i.value=[]}}});export{i as t};