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