import{s as le}from"./chunk-LvLJmgfZ.js";import{d as ae,f as ie,i as Qe,l as oe,n as He,p as Re,u as ce}from"./useEvent-D91BmmQi.js";import{t as Ve}from"./react-Bj1aDYRI.js";import{$n as de,Ar as Ke,Bn as me,E as Ge,Hi as Je,Kn as Y,Pr as Xe,Ui as pe,it as Ye,na as Z,y as Ze}from"./cells-CJLUCcQg.js";import{t as A}from"./compiler-runtime-B3qBwwSJ.js";import{g as et,p as tt}from"./useEventListener-C0195JsF.js";import{t as st}from"./invariant-CkiqGLcK.js";import{a as rt,i as nt,x as lt}from"./utils-BWBBpCkT.js";import{t as ue}from"./cn-DYvqRARy.js";import{t as at}from"./jsx-runtime-Blw4afVn.js";import{a as it,i as ot,o as ct,r as dt,t as mt}from"./config-BJVx3eBW.js";import{a as pt,p as ut,r as xt,t as ht}from"./dropdown-menu-dHmZR8bI.js";import{t as Q}from"./tooltip-4bZlU7jl.js";import{r as xe,t as P}from"./button-DDGiD1NW.js";import{n as ft}from"./strings--BknHX9C.js";import{t as he}from"./createLucideIcon-w-Qo9n0R.js";import{t as gt}from"./check-rzLRd0j9.js";import{r as fe}from"./x-C-Eq0ag8.js";import{t as jt}from"./chevron-right-BS_NcSch.js";import{t as yt}from"./hat-glasses-BttHlyvs.js";import{t as bt}from"./package-Bxz_8e44.js";import{t as vt}from"./sparkles-DUCpRFlS.js";import{l as ge,r as Nt}from"./datasource-DbljozeY.js";import{a as It}from"./dist-CPjTeT8p.js";import{t as wt}from"./uuid-ImXS-885.js";import{t as kt}from"./use-toast-BwJoaaDM.js";import{t as $t}from"./RenderHTML-C1rWkDWe.js";import{t as je}from"./kbd-C5HnBH5U.js";import{t as q}from"./links-wcQA1Np1.js";import{r as _t,t as At}from"./alert-jlwhGxSb.js";import{o as Tt,t as Ft}from"./useInstallPackage-WiYBwhUO.js";import{a as St,n as Ct}from"./state-Rxc-B11B.js";import{n as $}from"./cell-link-CWQ4BYr-.js";var L=he("square-arrow-out-up-right",[["path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6",key:"y09zxi"}],["path",{d:"m21 3-9 9",key:"mpx6sq"}],["path",{d:"M15 3h6v6",key:"1q9fwt"}]]),ye=he("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]),be=String.raw`_cell_([^\W_][\w-]*?)(_\w*)`,ve=String.raw`(?<!_)${be}`;`${be}`;var Mt=new RegExp(ve),ee=new RegExp(ve,"g");function Ne(t){let e=[];ee.lastIndex=0;let n=0,r=ee.exec(t);for(;r!==null;)r.index>n&&e.push(t.slice(n,r.index)),e.push({cellId:r[1],name:r[2]}),n=r.index+r[0].length,r=ee.exec(t);return n<t.length&&e.push(t.slice(n)),e}function Pt(t){return Mt.test(t)}function Et(t){let e=null,n=t.cursor();do n.name==="ExpressionStatement"&&(e=n.node);while(n.next());return e}function zt(t){let e=t.split(`
`),n="    ",r=Et(It.parse(t));if(!r)return["def _():",...te(e,n),`${n}return`,"","","_()"].join(`
`);let a=t.slice(0,r.from).trim(),l=t.slice(r.from).trim(),o=a.split(`
`),i=l.split(`
`);return["def _():",...te(o,n),`${n}return ${i[0]}`,...te(i.slice(1),n),"","","_()"].join(`
`)}function te(t,e){if(t.length===1&&t[0]==="")return[];let n=[];for(let r of t)r===""?n.push(""):n.push(e+r);return n}function qt(t,e){var n;if(t.type==="multiple-defs")return[{title:"Fix: Wrap in a function",description:"Make this cell's variables local by wrapping the cell in a function.",fixType:"manual",onFix:async r=>{st(r.editor,"Editor is null");let a=zt(r.editor.state.doc.toString());r.editor.dispatch({changes:{from:0,to:r.editor.state.doc.length,insert:a}})}}];if(t.type==="exception"&&t.exception_type==="NameError"){let r=(n=t.msg.match(/name '(.+)' is not defined/))==null?void 0:n[1];if(!r||!(r in Ie))return[];let a=Lt(r);return[{title:`Fix: Add '${a}'`,description:"Add a new cell for the missing import",fixType:"manual",onFix:async l=>{l.addCodeBelow(a)}}]}return t.type==="sql-error"&&e.aiEnabled?[{title:"Fix with AI",description:"Fix the SQL statement",fixType:"ai",onFix:async r=>{var o;let a=Nt(r.cellId,Qe),l=`Fix the SQL statement: ${t.msg}.`;a&&(l+=`
Database schema: ${a}`),(o=r.aiFix)==null||o.setAiCompletionCell({cellId:r.cellId,initialPrompt:l,triggerImmediately:r.aiFix.triggerFix})}}]:[]}function Lt(t){let e=Ie[t];return e===t?`import ${e}`:`import ${e} as ${t}`}var Ie={mo:"marimo",alt:"altair",bokeh:"bokeh",dask:"dask",np:"numpy",pd:"pandas",pl:"polars",plotly:"plotly",plt:"matplotlib.pyplot",px:"plotly.express",scipy:"scipy",sk:"sklearn",sns:"seaborn",stats:"scipy.stats",tf:"tensorflow",torch:"torch",xr:"xarray",dt:"datetime",json:"json",math:"math",os:"os",re:"re",sys:"sys"},we=1;const H=Z("marimo:acp:sessions:v1",{sessions:[],activeTabId:null},Y),Wt=Re(t=>{let e=t(H);return e.activeTabId&&e.sessions.find(n=>n.tabId===e.activeTabId)||null},(t,e,n)=>{e(H,r=>({...r,activeTabId:n}))});function Dt(){return`tab_${wt()}`}function ke(t,e=20){return t.length<=e?t:`${t.slice(0,e-3)}...`}function Ut(t,e){let n=$e(e.agentId),r=Date.now(),a=e.firstMessage?ke(e.firstMessage.trim()):`New ${e.agentId} session`,l=Dt();if(n==="single"){let o=t.sessions.filter(c=>c.agentId===e.agentId),i=t.sessions.filter(c=>c.agentId!==e.agentId);if(o.length>0){let c=o[0],d={agentId:e.agentId,title:a,createdAt:r,lastUsedAt:r,tabId:c.tabId,externalAgentSessionId:null,selectedModel:e.model??c.selectedModel??null};return{...t,sessions:[...i.slice(0,we-1),d],activeTabId:d.tabId}}}return{...t,sessions:[...t.sessions.slice(0,we-1),{agentId:e.agentId,tabId:l,title:a,createdAt:r,lastUsedAt:r,externalAgentSessionId:null,selectedModel:e.model??null}],activeTabId:l}}function Bt(t,e){let n=t.sessions.filter(r=>r.tabId!==e);return{sessions:n,activeTabId:t.activeTabId===e?n.length>0?n[n.length-1].tabId:null:t.activeTabId}}function Ot(t,e){let n=t.activeTabId;return n?{...t,sessions:t.sessions.map(r=>r.tabId===n?{...r,title:ke(e)}:r)}:t}function Qt(t,e){return{...t,sessions:t.sessions.map(n=>n.tabId===e?{...n,lastUsedAt:Date.now()}:n)}}function Ht(t,e){let n=t.activeTabId;return n?{...t,sessions:t.sessions.map(r=>r.tabId===n?{...r,externalAgentSessionId:e,lastUsedAt:Date.now()}:r)}:t}function Rt(){return["claude","gemini","codex","opencode","cursor"]}function Vt(t){return ft(t)}function Kt(t){let e=R[t].port,n=window.location.hostname;return`${window.location.protocol==="https:"?"wss:":"ws:"}//${n}:${e}/message`}var R={claude:{port:3017,command:"npx @zed-industries/claude-code-acp",sessionSupport:"single"},gemini:{port:3019,command:"npx @google/gemini-cli --experimental-acp",sessionSupport:"single"},codex:{port:3021,command:"npx @zed-industries/codex-acp",sessionSupport:"single"},opencode:{port:3023,command:"npx opencode-ai acp",sessionSupport:"single"},cursor:{port:3025,command:"agent acp",sessionSupport:"single"}};function $e(t){return R[t].sessionSupport}function Gt(t){let e=R[t].port,n=R[t].command;return`npx stdio-to-ws "${tt()?`cmd /c ${n}`:n}" --port ${e}`}var Jt=A();const _e=Z("marimo:chrome:ai-panel-tab","chat",Y);function Ae(){let t=(0,Jt.c)(3),[e,n]=oe(_e),r;return t[0]!==e||t[1]!==n?(r={aiPanelTab:e,setAiPanelTab:n},t[0]=e,t[1]=n,t[2]=r):r=t[2],r}var Xt=A(),Yt="code_mode";function Zt(t,e){return t||(de("external_agents")?e:"chat")}function Te(){let t=(0,Xt.c)(6),{openApplication:e}=me(),{setAiPanelTab:n}=Ae(),{saveModeChange:r}=mt(),a=ae(St),l=ie(),o;return t[0]!==e||t[1]!==r||t[2]!==n||t[3]!==a||t[4]!==l?(o=async i=>{let c=Zt(i.panel,l.get(_e)),d=l.get(rt),p=de("external_agents")&&l.get(H).sessions.length>0;if(!(c==="agents"?p:d)){kt({title:c==="agents"?"No agent session":"AI not configured",description:c==="agents"?"Start an agent session or switch to the chat panel.":"Configure an AI provider and chat model to fix with AI.",variant:"danger"});return}i.panel&&n(i.panel),c==="chat"&&await r(Yt).catch(es),a({prompt:i.prompt,submit:i.submit??!1}),e("ai")},t[0]=e,t[1]=r,t[2]=n,t[3]=a,t[4]=l,t[5]=o):o=t[5],He(o)}function es(){return et.error("Failed to save mode change")}var ts=A(),ss=Z("marimo:ai-autofix-mode","autofix",Y);function rs(){let t=(0,ts.c)(3),[e,n]=oe(ss),r;return t[0]!==e||t[1]!==n?(r={fixMode:e,setFixMode:n},t[0]=e,t[1]=n,t[2]=r):r=t[2],r}var se=A(),s=le(at(),1);function Fe(t,e){if(t!=null)return`@error://${t}

Please fix this error.`;let n=e==null?void 0:e.trim();return n?`My code gives the following error. Please fix it:

${n}`:"Please fix this error."}const w=t=>{let e=(0,se.c)(25),{errors:n,cellId:r,className:a}=t,l=ie(),{createNewCell:o}=Ge(),i=ce(nt),c;if(e[0]!==i||e[1]!==n){let v;e[3]===i?v=e[4]:(v=k=>qt(k,{aiEnabled:i}),e[3]=i,e[4]=v),c=n.flatMap(v),e[0]=i,e[1]=n,e[2]=c}else c=e[2];let d=c,p=ae(Ct),u=Te();if(d.length===0)return null;let m=d[0],x;e[5]!==r||e[6]!==o||e[7]!==m||e[8]!==p||e[9]!==l?(x=v=>{var S;let k=(S=l.get(Ze).cellHandles[r].current)==null?void 0:S.editorView;m.onFix({addCodeBelow:E=>{o({cellId:r,autoFocus:!1,before:!1,code:E})},editor:k,cellId:r,aiFix:{setAiCompletionCell:p,triggerFix:v}}),k==null||k.focus()},e[5]=r,e[6]=o,e[7]=m,e[8]=p,e[9]=l,e[10]=x):x=e[10];let g=x,h;e[11]!==r||e[12]!==u?(h=()=>{u({prompt:Fe(r)})},e[11]=r,e[12]=u,e[13]=h):h=e[13];let y=h,j;e[14]===a?j=e[15]:(j=ue("my-2",a),e[14]=a,e[15]=j);let b;e[16]!==m.description||e[17]!==m.fixType||e[18]!==m.title||e[19]!==g||e[20]!==y?(b=m.fixType==="ai"?(0,s.jsx)(Ce,{tooltip:m.description,openPrompt:()=>g(!1),applyAutofix:()=>g(!0),openChat:y}):(0,s.jsx)(Q,{content:m.description,align:"start",children:(0,s.jsxs)(P,{size:"xs",variant:"outline",className:"font-normal",onClick:()=>g(!1),children:[(0,s.jsx)(ge,{className:"h-3 w-3 mr-2"}),m.title]})}),e[16]=m.description,e[17]=m.fixType,e[18]=m.title,e[19]=g,e[20]=y,e[21]=b):b=e[21];let N;return e[22]!==j||e[23]!==b?(N=(0,s.jsx)("div",{className:j,children:b}),e[22]=j,e[23]=b,e[24]=N):N=e[24],N};var Se={autofix:{Icon:ge,title:"Inline AI Fix",description:"Apply AI fixes inline in the cell"},chat:{Icon:yt,title:"Fix with AI assistant",description:"Open the AI sidebar to fix"},prompt:{Icon:vt,title:"Suggest a prompt",description:"Edit the prompt before applying"}},ns=["autofix","prompt","chat"];const Ce=t=>{let e=(0,se.c)(18),{tooltip:n,openPrompt:r,applyAutofix:a,openChat:l}=t,{fixMode:o,setFixMode:i}=rs(),c=r;o==="chat"?c=l:o==="autofix"&&(c=a);let{Icon:d,title:p}=Se[o],u;e[0]===d?u=e[1]:(u=(0,s.jsx)(d,{className:"h-3 w-3 mr-2 mb-0.5"}),e[0]=d,e[1]=u);let m;e[2]!==c||e[3]!==u||e[4]!==p?(m=(0,s.jsxs)(P,{size:"xs",variant:"outline",className:"font-normal rounded-r-none border-r-0",onClick:c,children:[u,p]}),e[2]=c,e[3]=u,e[4]=p,e[5]=m):m=e[5];let x;e[6]!==m||e[7]!==n?(x=(0,s.jsx)(Q,{content:n,align:"start",children:m}),e[6]=m,e[7]=n,e[8]=x):x=e[8];let g;e[9]===Symbol.for("react.memo_cache_sentinel")?(g=(0,s.jsx)(ut,{asChild:!0,children:(0,s.jsx)(P,{size:"xs",variant:"outline",className:"rounded-l-none px-2","aria-label":"Fix options",children:(0,s.jsx)(fe,{className:"h-3 w-3"})})}),e[9]=g):g=e[9];let h;e[10]!==o||e[11]!==i?(h=ns.map(b=>(0,s.jsx)(pt,{className:"flex items-center gap-2",onClick:()=>i(b),children:(0,s.jsx)(ls,{mode:b,selected:b===o})},b)),e[10]=o,e[11]=i,e[12]=h):h=e[12];let y;e[13]===h?y=e[14]:(y=(0,s.jsxs)(ht,{children:[g,(0,s.jsx)(xt,{align:"end",className:"w-56",children:h})]}),e[13]=h,e[14]=y);let j;return e[15]!==x||e[16]!==y?(j=(0,s.jsxs)("div",{className:"flex",children:[x,y]}),e[15]=x,e[16]=y,e[17]=j):j=e[17],j};var ls=t=>{let e=(0,se.c)(15),{mode:n,selected:r}=t,{Icon:a,title:l,description:o}=Se[n],i;e[0]===a?i=e[1]:(i=(0,s.jsx)(a,{className:"h-4 w-4 shrink-0"}),e[0]=a,e[1]=i);let c;e[2]===l?c=e[3]:(c=(0,s.jsx)("span",{className:"font-medium",children:l}),e[2]=l,e[3]=c);let d;e[4]===o?d=e[5]:(d=(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:o}),e[4]=o,e[5]=d);let p;e[6]!==c||e[7]!==d?(p=(0,s.jsxs)("div",{className:"flex flex-col",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8];let u;e[9]===r?u=e[10]:(u=r&&(0,s.jsx)(gt,{className:"h-4 w-4 ml-auto shrink-0"}),e[9]=r,e[10]=u);let m;return e[11]!==i||e[12]!==p||e[13]!==u?(m=(0,s.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[i,p,u]}),e[11]=i,e[12]=p,e[13]=u,e[14]=m):m=e[14],m},Me=A();const as=t=>{let e=(0,Me.c)(12),{local:n}=t,r;e[0]===n.name?r=e[1]:(r=(0,s.jsx)("span",{className:"font-code",children:n.name}),e[0]=n.name,e[1]=r);let a;e[2]===n.cellId?a=e[3]:(a=(0,s.jsx)($,{cellId:n.cellId}),e[2]=n.cellId,e[3]=a);let l;e[4]!==r||e[5]!==a?(l=(0,s.jsxs)("div",{className:"max-w-xs",children:["Local variable ",r," in cell"," ",a,"."]}),e[4]=r,e[5]=a,e[6]=l):l=e[6];let o=l,i;e[7]===n.name?i=e[8]:(i=(0,s.jsx)("span",{className:"font-code cursor-help",children:n.name}),e[7]=n.name,e[8]=i);let c;return e[9]!==i||e[10]!==o?(c=(0,s.jsx)(Q,{content:o,children:i}),e[9]=i,e[10]=o,e[11]=c):c=e[11],c},Pe=t=>{let e=(0,Me.c)(4),{segments:n}=t,r;e[0]===n?r=e[1]:(r=n.map(is),e[0]=n,e[1]=r);let a;return e[2]===r?a=e[3]:(a=(0,s.jsx)(s.Fragment,{children:r}),e[2]=r,e[3]=a),a};function is(t,e){return typeof t=="string"?(0,s.jsx)("span",{children:t},e):(0,s.jsx)(as,{local:t},e)}var Ee=/(https?:\/\/\S+)/,os=/\.(png|jpe?g|gif|webp|svg|ico)(\?.*)?$/i,ze=/^data:image\//i,cs=["avatars.githubusercontent.com"];function qe(t){return ze.test(t)?[{type:"image",url:t}]:t.split(Ee).filter(e=>e!=="").map(e=>Ee.test(e)?os.test(e)||ze.test(e)||cs.some(n=>e.includes(n))?{type:"image",url:e}:{type:"url",url:e}:{type:"text",value:e})}var Le=A(),W=le(Ve(),1),ds=new Ye;const re=t=>{let e=RegExp("\x1B\\[[0-9;]*m","g");return t.replaceAll(e,"")};var We=/(pip\s+install|uv\s+add|uv\s+pip\s+install)\s+/gi;function ms(t){We.lastIndex=0;let e=We.exec(t);if(!e)return null;let n=e.index+e[0].length,r=t.slice(n).split(/\s+/),a="",l=0;for(let i of r){let c=i.trim();if(!c)continue;if(c.startsWith("-")){l+=c.length+1;continue}let d=c.match(/^[\w,.[\]-]+/);if(d){a=d[0];break}break}if(!a)return null;let o=n+l+a.length;return{package:a,endIndex:o}}function T(t,e=""){if(!t)return null;if(!/https?:\/\//.test(t))return t;let n=qe(t);return n.length===1&&n[0].type==="text"?t:(0,s.jsx)(s.Fragment,{children:n.map((r,a)=>{let l=e?`${e}-${a}`:a;if(r.type==="url"){let o=re(r.url);return(0,s.jsx)("a",{href:o,target:"_blank",rel:"noopener noreferrer",onClick:xe.stopPropagation(),className:"text-link hover:underline",children:o},l)}if(r.type==="image"){let o=re(r.url);return(0,s.jsx)("a",{href:o,target:"_blank",rel:"noopener noreferrer",onClick:xe.stopPropagation(),className:"text-link hover:underline",children:o},l)}return(0,s.jsx)(W.Fragment,{children:r.value},l)})})}var ps=t=>{let e=(0,Le.c)(6),{packages:n,children:r}=t,{handleInstallPackages:a}=Ft(),l;e[0]!==a||e[1]!==n?(l=i=>{a(n),i.preventDefault()},e[0]=a,e[1]=n,e[2]=l):l=e[2];let o;return e[3]!==r||e[4]!==l?(o=(0,s.jsx)("button",{onClick:l,className:"text-link hover:underline",type:"button",children:r}),e[3]=r,e[4]=l,e[5]=o):o=e[5],o};const us=t=>{if(!(t instanceof pe.Text))return;let e=re(t.data);if(!/(pip\s+install|uv\s+add|uv\s+pip\s+install)/i.test(e))return;let n=[],r=/(pip\s+install|uv\s+add|uv\s+pip\s+install)\s+/gi,a;for(;(a=r.exec(e))!==null;){let i=a.index,c=ms(e.slice(i));c&&n.push({match:a,result:c})}if(n.length===0)return;let l=[],o=0;if(n.forEach((i,c)=>{let{match:d,result:p}=i,u=d.index,m=u+p.endIndex;if(o<u){let g=e.slice(o,u);l.push((0,s.jsx)(W.Fragment,{children:T(g,`before-${c}`)},`before-${c}`))}let x=e.slice(u,m);l.push((0,s.jsx)(ps,{packages:[p.package],children:x},`install-${c}`)),o=m}),o<e.length){let i=e.slice(o);l.push((0,s.jsx)(W.Fragment,{children:T(i,"after")},"after"))}return(0,s.jsx)(s.Fragment,{children:l})},xs=t=>{if(!(t instanceof pe.Text))return;let e=t.data;if(!/https?:\/\//.test(e))return;let n=T(e);if(typeof n!="string")return(0,s.jsx)(s.Fragment,{children:n})},hs=(...t)=>e=>{for(let n of t){let r=n(e);if(r!==void 0)return r}},fs=(t,e)=>(0,s.jsx)("span",{children:Je(ds.ansi_to_html(t),{replace:n=>e(n)})}),gs=t=>{let e=(0,Le.c)(4),{text:n}=t,r;e[0]===n?r=e[1]:(r=fs(n,hs(us,xs)),e[0]=n,e[1]=r);let a=r,l;return e[2]===a?l=e[3]:(l=(0,s.jsx)(s.Fragment,{children:a}),e[2]=a,e[3]=l),l};var ne=A(),De=t=>{let e=(0,ne.c)(16),{traceback:n}=t,[r,a]=(0,W.useState)(!0),l;e[0]===r?l=e[1]:(l=()=>a(!r),e[0]=r,e[1]=l);let o=r?"Collapse traceback":"Expand traceback",i;e[2]===r?i=e[3]:(i=r?(0,s.jsx)(fe,{className:"h-3 w-3"}):(0,s.jsx)(jt,{className:"h-3 w-3"}),e[2]=r,e[3]=i);let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=(0,s.jsx)("span",{className:"text-[0.6875rem] uppercase tracking-wider",children:"Traceback"}),e[4]=c):c=e[4];let d;e[5]!==r||e[6]!==l||e[7]!==o||e[8]!==i?(d=(0,s.jsxs)("button",{type:"button",onClick:l,"aria-expanded":r,"aria-label":o,className:"flex items-center gap-1 text-muted-foreground/70 hover:text-muted-foreground transition-colors",children:[i,c]}),e[5]=r,e[6]=l,e[7]=o,e[8]=i,e[9]=d):d=e[9];let p;e[10]!==r||e[11]!==n?(p=r&&(0,s.jsx)("div",{className:"font-code text-sm mt-1 p-3 bg-muted rounded border overflow-auto max-h-[50vh] cursor-text select-text",children:$t({html:n})}),e[10]=r,e[11]=n,e[12]=p):p=e[12];let u;return e[13]!==d||e[14]!==p?(u=(0,s.jsxs)("div",{className:"mt-2",children:[d,p]}),e[13]=d,e[14]=p,e[15]=u):u=e[15],u},F=t=>{let e=(0,ne.c)(10),n=t.title??"Tip",r;e[0]===n?r=e[1]:(r=(0,s.jsx)(ct,{className:"pt-2 pb-0 font-normal",children:n}),e[0]=n,e[1]=r);let a;e[2]===t.children?a=e[3]:(a=(0,s.jsx)(ot,{className:"mr-24 text-[0.84375rem]",wrapperClassName:"pt-0 pb-2",children:t.children}),e[2]=t.children,e[3]=a);let l;e[4]!==r||e[5]!==a?(l=(0,s.jsxs)(it,{value:"item-1",className:"text-muted-foreground",children:[r,a]}),e[4]=r,e[5]=a,e[6]=l):l=e[6];let o;return e[7]!==t.className||e[8]!==l?(o=(0,s.jsx)(dt,{type:"single",collapsible:!0,className:t.className,children:l}),e[7]=t.className,e[8]=l,e[9]=o):o=e[9],o};const js=t=>{let e=(0,ne.c)(38),{errors:n,cellId:r,className:a}=t,l=me(),o=ce(lt).display.cell_output==="above",i="This cell wasn't run because it has errors",c="destructive",d="text-error",p=null;if(n.some(ys))i="Interrupted";else if(n.some(bs))i="An internal error occurred";else if(n.some(vs))i="Ancestor prevented from running",c="default",d="text-secondary-foreground";else if(n.some(Ns))i="Ancestor stopped",c="default",d="text-secondary-foreground";else if(n.some(Is))i="SQL error";else if(n.some(ws))i=null,p="Cell not run";else{let N;e[0]===n?N=e[1]:(N=n.find(ks),e[0]=n,e[1]=N);let v=N;v&&"exception_type"in v&&(i=v.exception_type)}let u,m,x,g,h,y;if(e[2]!==c||e[3]!==r||e[4]!==l||e[5]!==a||e[6]!==n||e[7]!==o||e[8]!==p||e[9]!==d||e[10]!==i){let N=n.filter($s),v=n.filter(_s),k=n.filter(As),S=n.filter(Ts),E=n.filter(Fs),D=n.filter(Ss),U=n.filter(Cs),V=n.filter(Ms),K=n.filter(Ps),G=n.filter(Es),z=n.filter(zs),J=n.filter(qs),X=n.filter(Ls),B;e[17]===l?B=e[18]:(B=()=>{l.openApplication("scratchpad")},e[17]=l,e[18]=B);let Ue=B,Be=()=>{let I=[];if(z.length>0||J.length>0){let f=z.some(Ws),_=!f&&z.some(Ds);I.push((0,s.jsxs)("div",{children:[z.map(Us),J.map(Bs),f&&(0,s.jsxs)(P,{size:"xs",variant:"outline",className:"mt-2 font-normal",onClick:()=>Tt(l),children:[(0,s.jsx)(bt,{className:"h-3.5 w-3.5 mr-1.5 mb-0.5"}),(0,s.jsx)("span",{children:"Open package manager"})]}),_&&(0,s.jsxs)(P,{size:"xs",variant:"outline",className:"mt-2 font-normal",onClick:()=>l.openApplication("terminal"),children:[(0,s.jsx)(ye,{className:"h-3.5 w-3.5 mr-1.5"}),(0,s.jsx)("span",{children:"Open terminal"})]}),r&&(0,s.jsx)(w,{errors:[...z,...J],cellId:r})]},"syntax-unknown"))}if(N.length>0&&I.push((0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-muted-foreground font-medium",children:"The setup cell cannot be run because it has references."}),(0,s.jsx)("ul",{className:"list-disc",children:N.flatMap(Os)}),r&&(0,s.jsx)(w,{errors:N,cellId:r}),(0,s.jsxs)(F,{title:"Why can't the setup cell have references?",className:"mb-2",children:[(0,s.jsx)("p",{className:"pb-2",children:"The setup cell contains logic that must be run before any other cell runs, including top-level imports used by top-level functions. For this reason, it can't refer to other cells' variables."}),(0,s.jsx)("p",{className:"py-2",children:"Try simplifying the setup cell to only contain only necessary variables."}),(0,s.jsxs)("p",{className:"py-2",children:[(0,s.jsxs)(q,{href:"https://links.marimo.app/errors-setup",children:["Learn more at our docs"," ",(0,s.jsx)(L,{size:"0.75rem",className:"inline"})]}),"."]})]})]},"setup-refs")),v.length>0&&I.push((0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-muted-foreground font-medium",children:"This cell is in a cycle."}),(0,s.jsx)("ul",{className:"list-disc",children:v.flatMap(Qs)}),r&&(0,s.jsx)(w,{errors:v,cellId:r}),(0,s.jsxs)(F,{title:"What are cycles and how do I resolve them?",className:"mb-2",children:[(0,s.jsx)("p",{className:"pb-2",children:"An example of a cycle is if one cell declares a variable 'a' and reads 'b', and another cell declares 'b' and and reads 'a'. Cycles like this make it impossible for marimo to know how to run your cells, and generally suggest that your code has a bug."}),(0,s.jsx)("p",{className:"py-2",children:"Try merging these cells into a single cell to eliminate the cycle."}),(0,s.jsxs)("p",{className:"py-2",children:[(0,s.jsxs)(q,{href:"https://links.marimo.app/errors-cycles",children:["Learn more at our docs"," ",(0,s.jsx)(L,{size:"0.75rem",className:"inline"})]}),"."]})]})]},"cycle")),k.length>0){let f=k[0].name;I.push((0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-muted-foreground font-medium",children:"This cell redefines variables from other cells."}),k.map(Rs),r&&(0,s.jsx)(w,{errors:k,cellId:r}),(0,s.jsxs)(F,{title:"Why can't I redefine variables?",children:[(0,s.jsx)("p",{className:"pb-2",children:"marimo requires that each variable is defined in just one cell. This constraint enables reactive and reproducible execution, arbitrary cell reordering, seamless UI elements, execution as a script, and more."}),(0,s.jsxs)("p",{className:"py-2",children:["Try merging this cell with the mentioned cells or wrapping it in a function. Alternatively, prefix variables with an underscore (e.g., ",(0,s.jsxs)(je,{className:"inline",children:["_",f]}),"). to make them private to this cell."]}),(0,s.jsxs)("p",{className:"py-2",children:[(0,s.jsxs)(q,{href:"https://links.marimo.app/errors-multiple-definitions",children:["Learn more at our docs"," ",(0,s.jsx)(L,{size:"0.75rem",className:"inline"})]}),"."]})]}),(0,s.jsx)(F,{title:"Need a scratchpad?",children:(0,s.jsxs)("div",{className:"flex flex-row gap-2 items-center",children:[(0,s.jsxs)(P,{size:"xs",variant:"link",className:"my-2 font-normal mx-0 px-0",onClick:Ue,children:[(0,s.jsx)(Ke,{className:"h-3"}),(0,s.jsx)("span",{children:"Try the scratchpad"})]}),(0,s.jsx)("span",{children:"to experiment without restrictions on variable names."})]})})]},"multiple-defs"))}return S.length>0&&I.push((0,s.jsxs)("div",{children:[S.map(Vs),r&&(0,s.jsx)(w,{errors:S,cellId:r}),(0,s.jsxs)(F,{title:"Why can't I use `import *`?",children:[(0,s.jsx)("p",{className:"pb-2",children:"Star imports are incompatible with marimo's git-friendly file format and reproducible reactive execution."}),(0,s.jsx)("p",{className:"py-2",children:"marimo's Python file format stores code in functions, so notebooks can be imported as regular Python modules without executing all their code. But Python disallows `import *` everywhere except at the top-level of a module."}),(0,s.jsx)("p",{className:"py-2",children:"Star imports would also silently add names to globals, which would be incompatible with reactive execution."}),(0,s.jsxs)("p",{className:"py-2",children:[(0,s.jsxs)(q,{href:"https://links.marimo.app/errors-import-star",children:["Learn more at our docs"," ",(0,s.jsx)(L,{size:"0.75rem",className:"inline"})]}),"."]})]})]},"import-star")),E.length>0&&I.push((0,s.jsxs)("div",{children:[E.map(Ks),r&&(0,s.jsx)(w,{errors:E,cellId:r})]},"interruption")),D.length>0&&I.push((0,s.jsxs)("ul",{children:[D.map((f,_)=>f.exception_type==="NameError"&&f.msg.startsWith("name 'mo'")?(0,s.jsx)("li",{className:"my-2",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-muted-foreground",children:"name 'mo' is not defined."}),(0,s.jsxs)("p",{className:"text-muted-foreground mt-2",children:["The marimo module (imported as"," ",(0,s.jsx)(je,{className:"inline",children:"mo"}),") is required for Markdown, SQL, and UI elements."]})]})},`exception-${_}`):f.exception_type==="NameError"&&f.msg.startsWith("name '_")?(0,s.jsx)("li",{className:"my-2",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-muted-foreground",children:(0,s.jsx)(Pe,{segments:Ne(f.msg)})}),(0,s.jsxs)("p",{className:"text-muted-foreground mt-2",children:["Variables prefixed with an underscore are local to a cell"," ","(",(0,s.jsxs)(q,{href:"https://links.marimo.app/local-variables",children:["docs"," ",(0,s.jsx)(L,{size:"0.75rem",className:"inline"})]}),")."]}),o&&(0,s.jsx)("div",{className:"text-muted-foreground mt-2",children:"See the console area for a traceback."})]})},`exception-${_}`):(0,s.jsx)("li",{className:"my-2",children:f.raising_cell==null?(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-muted-foreground",children:T(f.msg,`exception-${_}`)}),"traceback"in f&&f.traceback?(0,s.jsx)(De,{traceback:f.traceback}):o&&(0,s.jsx)("div",{className:"text-muted-foreground mt-2",children:"See the console area for a traceback."})]}):(0,s.jsxs)("div",{children:[T(f.msg,`exception-${_}`),(0,s.jsx)($,{cellId:f.raising_cell}),"traceback"in f&&f.traceback&&(0,s.jsx)(De,{traceback:f.traceback})]})},`exception-${_}`)),D.some(Gs)&&(0,s.jsx)(F,{children:"Fix the error in the mentioned cells, or handle the exceptions with try/except blocks."}),r&&(0,s.jsx)(w,{errors:D,cellId:r})]},"exception")),U.length>0&&I.push((0,s.jsxs)("ul",{children:[U.map(Js),r&&(0,s.jsx)(w,{errors:U,cellId:r}),(0,s.jsx)(F,{children:U.some(Xs)?"Ensure that the referenced cells define the required variables, or turn off strict execution.":"Something is wrong with your declarations. Fix any discrepancies, or turn off strict execution."})]},"strict-exception")),V.length>0&&I.push((0,s.jsxs)("div",{children:[V.map(Ys),r&&(0,s.jsx)(w,{errors:V,cellId:r})]},"internal")),K.length>0&&I.push((0,s.jsxs)("div",{children:[K.map(Zs),r&&(0,s.jsx)(w,{errors:K,cellId:r})]},"ancestor-prevented")),G.length>0&&I.push((0,s.jsxs)("div",{children:[G.map(er),r&&(0,s.jsx)(w,{errors:G,cellId:r})]},"ancestor-stopped")),X.length>0&&I.push((0,s.jsxs)("div",{children:[X.map(tr),r&&(0,s.jsx)(w,{errors:X,cellId:r,className:"mt-2.5"})]},"sql-errors")),I},C;e[19]===p?C=e[20]:(C=p&&(0,s.jsxs)("div",{className:"flex items-center gap-1 font-code text-[0.6875rem] uppercase tracking-wider text-muted-foreground/70",children:[p,(0,s.jsx)(Q,{content:"marimo didn't run this cell because it detected an error.",delayDuration:200,children:(0,s.jsx)(Xe,{className:"size-3 cursor-help"})})]}),e[19]=p,e[20]=C);let M;e[21]!==d||e[22]!==i?(M=i&&(0,s.jsx)(_t,{className:`font-code font-medium ${d}`,children:i}),e[21]=d,e[22]=i,e[23]=M):M=e[23];let O;e[24]!==C||e[25]!==M?(O=(0,s.jsxs)("div",{className:"space-y-0.5",children:[C,M]}),e[24]=C,e[25]=M,e[26]=O):O=e[26];let Oe=O;u=At,g=c,e[27]===a?h=e[28]:(h=ue("border-none font-code text-sm text-[0.84375rem] p-0 text-muted-foreground normal has-[svg]:pl-0 space-y-2",a),e[27]=a,e[28]=h),y=Oe,m="flex flex-col gap-4",x=Be(),e[2]=c,e[3]=r,e[4]=l,e[5]=a,e[6]=n,e[7]=o,e[8]=p,e[9]=d,e[10]=i,e[11]=u,e[12]=m,e[13]=x,e[14]=g,e[15]=h,e[16]=y}else u=e[11],m=e[12],x=e[13],g=e[14],h=e[15],y=e[16];let j;e[29]!==m||e[30]!==x?(j=(0,s.jsx)("div",{className:m,children:x}),e[29]=m,e[30]=x,e[31]=j):j=e[31];let b;return e[32]!==u||e[33]!==g||e[34]!==h||e[35]!==y||e[36]!==j?(b=(0,s.jsxs)(u,{variant:g,className:h,children:[y,j]}),e[32]=u,e[33]=g,e[34]=h,e[35]=y,e[36]=j,e[37]=b):b=e[37],b};function ys(t){return t.type==="interruption"}function bs(t){return t.type==="internal"}function vs(t){return t.type==="ancestor-prevented"}function Ns(t){return t.type==="ancestor-stopped"}function Is(t){return t.type==="sql-error"}function ws(t){return t.type==="multiple-defs"||t.type==="cycle"||t.type==="setup-refs"||t.type==="import-star"}function ks(t){return t.type==="exception"}function $s(t){return t.type==="setup-refs"}function _s(t){return t.type==="cycle"}function As(t){return t.type==="multiple-defs"}function Ts(t){return t.type==="import-star"}function Fs(t){return t.type==="interruption"}function Ss(t){return t.type==="exception"}function Cs(t){return t.type==="strict-exception"}function Ms(t){return t.type==="internal"}function Ps(t){return t.type==="ancestor-prevented"}function Es(t){return t.type==="ancestor-stopped"}function zs(t){return t.type==="syntax"}function qs(t){return t.type==="unknown"}function Ls(t){return t.type==="sql-error"}function Ws(t){return t.msg.includes("!pip")}function Ds(t){return t.msg.includes("use os.subprocess")}function Us(t,e){return(0,s.jsx)("pre",{children:T(t.msg,`syntax-${e}`)},`syntax-${e}`)}function Bs(t,e){return(0,s.jsx)("pre",{children:T(t.msg,`unknown-${e}`)},`unknown-${e}`)}function Os(t,e){return t.edges_with_vars.map((n,r)=>(0,s.jsxs)("li",{className:"my-0.5 ml-8 text-muted-foreground/40",children:[(0,s.jsx)($,{cellId:n[0]}),(0,s.jsxs)("span",{className:"text-muted-foreground",children:[": "," ",n[1].length===1?n[1][0]:n[1].join(", ")]})]},`setup-refs-${e}-${r}`))}function Qs(t,e){return t.edges_with_vars.map((n,r)=>(0,s.jsxs)("li",{className:"my-0.5 ml-8 text-muted-foreground/40",children:[(0,s.jsx)($,{cellId:n[0]}),(0,s.jsxs)("span",{className:"text-muted-foreground",children:[" -> ",n[1].length===1?n[1][0]:n[1].join(", ")," -> "]}),(0,s.jsx)($,{cellId:n[2]})]},`cycle-${e}-${r}`))}function Hs(t,e){return(0,s.jsx)("li",{className:"my-0.5 ml-8 text-muted-foreground/40",children:(0,s.jsx)($,{cellId:t})},`cell-${e}`)}function Rs(t,e){return(0,s.jsxs)(W.Fragment,{children:[(0,s.jsx)("p",{className:"text-muted-foreground mt-2",children:`'${t.name}' was also defined by:`}),(0,s.jsx)("ul",{className:"list-disc",children:t.cells.map(Hs)})]},`multiple-defs-${e}`)}function Vs(t,e){return(0,s.jsx)("p",{className:"text-muted-foreground",children:t.msg},`import-star-${e}`)}function Ks(t,e){return(0,s.jsx)("p",{children:"This cell was interrupted and needs to be re-run."},`interruption-${e}`)}function Gs(t){return t.raising_cell!=null}function Js(t,e){return(0,s.jsx)("li",{className:"my-2",children:t.blamed_cell==null?(0,s.jsx)("p",{children:t.msg}):(0,s.jsxs)("div",{children:[t.msg,(0,s.jsx)($,{cellId:t.blamed_cell})]})},`strict-exception-${e}`)}function Xs(t){return t.blamed_cell!=null}function Ys(t,e){return(0,s.jsx)("p",{children:t.msg},`internal-${e}`)}function Zs(t,e){return(0,s.jsxs)("div",{children:[t.msg,t.blamed_cell==null?(0,s.jsxs)("span",{children:["(",(0,s.jsx)($,{cellId:t.raising_cell}),")"]}):(0,s.jsxs)("span",{children:["(",(0,s.jsx)($,{cellId:t.raising_cell}),"\xA0blames\xA0",(0,s.jsx)($,{cellId:t.blamed_cell}),")"]})]},`ancestor-prevented-${e}`)}function er(t,e){return(0,s.jsxs)("div",{children:[t.msg,(0,s.jsx)($,{cellId:t.raising_cell})]},`ancestor-stopped-${e}`)}function tr(t,e){return(0,s.jsx)("div",{className:"space-y-2 mt-2",children:(0,s.jsx)("p",{className:"text-muted-foreground whitespace-pre-wrap",children:t.msg})},`sql-error-${e}`)}export{ye as C,Ne as S,Wt as _,Ce as a,Ot as b,Ae as c,Gt as d,Vt as f,Bt as g,Rt as h,Pe as i,Ut as l,Kt as m,gs as n,Fe as o,$e as p,qe as r,Te as s,js as t,H as u,Ht as v,Pt as x,Qt as y};
