import{t as I}from"./createReducer-80xvKyHq.js";function T(){return{runIds:[],runMap:new Map}}var{reducer:v,createActions:q,valueAtom:w,useActions:_}=I(T,{addCellOperation:(e,i)=>{let{cellOperation:t,code:u}=i,r=t.timestamp??0,s=t.run_id;if(!s)return e;let d=e.runMap.get(s);if(!d&&R(u))return e;let o=t.output&&(t.output.channel==="marimo-error"||t.output.channel==="stderr"),n=o?"error":t.status==="queued"?"queued":t.status==="running"?"running":"success";if(!d){let p={runId:s,cellRuns:new Map([[t.cell_id,{cellId:t.cell_id,code:u.slice(0,200),elapsedTime:0,status:n,startTime:r}]]),runStartTime:r},l=[s,...e.runIds],m=new Map(e.runMap);if(l.length>50){let f=l.pop();f&&m.delete(f)}return m.set(s,p),{runIds:l,runMap:m}}let c=new Map(d.cellRuns),a=c.get(t.cell_id);if(a&&!o&&t.status==="queued")return e;if(a){n=a.status==="error"||o?"error":n;let p=t.status==="running"?r:a.startTime,l=n==="success"||n==="error"?r-a.startTime:void 0;c.set(t.cell_id,{...a,startTime:p,elapsedTime:l,status:n})}else c.set(t.cell_id,{cellId:t.cell_id,code:u.slice(0,200),elapsedTime:0,status:n,startTime:r});let M=new Map(e.runMap);return M.set(s,{...d,cellRuns:c}),{...e,runMap:M}},clearRuns:e=>({...e,runIds:[],runMap:new Map}),removeRun:(e,i)=>{let t=e.runIds.filter(r=>r!==i),u=new Map(e.runMap);return u.delete(i),{...e,runIds:t,runMap:u}}}),g=/mo\.md\(\s*r?('''|""")/;function R(e){return e.startsWith("mo.md(")&&g.test(e)}export{_ as n,w as t};
