@marimo-team/frontend 0.23.10 → 0.23.11-dev1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/dist/assets/{add-cell-with-ai-Bd_3tPEt.js → add-cell-with-ai-C2OtCghK.js} +20 -20
  2. package/dist/assets/{agent-panel-Dm0KI1sF.js → agent-panel-D6ryE8xb.js} +6 -6
  3. package/dist/assets/{cell-editor-B3aYYyAI.js → cell-editor-XNa3wJ3P.js} +15 -12
  4. package/dist/assets/{chat-display-DI0jRLIv.js → chat-display-CezkHLLR.js} +1 -1
  5. package/dist/assets/{chat-panel-BU4HHdf5.js → chat-panel-DEBTPtwE.js} +2 -2
  6. package/dist/assets/{chat-ui-C7igY2w5.js → chat-ui-CIr1o1hq.js} +4 -4
  7. package/dist/assets/{command-palette-Bjv1Z7v8.js → command-palette-_VEEjmkI.js} +1 -1
  8. package/dist/assets/{edit-page-BeWwLeT8.js → edit-page-D-02q6iz.js} +4 -4
  9. package/dist/assets/{hooks-DyMacA-R.js → hooks-5gNQitDd.js} +1 -1
  10. package/dist/assets/{index-fNBoXCyz.js → index-CGCBsDqs.js} +3 -3
  11. package/dist/assets/{layout-dRNPwA-7.js → layout-D3pd3R21.js} +2 -2
  12. package/dist/assets/{panels-BTEEcvYR.js → panels-CTy3hq0L.js} +1 -1
  13. package/dist/assets/{reveal-component-DGQQBmed.js → reveal-component-lTtEZQh1.js} +1 -1
  14. package/dist/assets/{run-page-yFxABzXq.js → run-page-BB6ghGfO.js} +1 -1
  15. package/dist/assets/{scratchpad-panel-B_nxW99u.js → scratchpad-panel-Bvb8RxUv.js} +1 -1
  16. package/dist/assets/{useNotebookActions-Dw6tY2qa.js → useNotebookActions-BIQkawja.js} +1 -1
  17. package/dist/index.html +1 -1
  18. package/package.json +1 -1
  19. package/src/components/editor/ai/ai-completion-editor.tsx +6 -5
  20. package/src/core/ai/__tests__/strip-wrapping-backticks.test.ts +133 -0
  21. package/src/core/ai/stream-completion-text.ts +48 -0
  22. package/src/core/ai/strip-wrapping-backticks.ts +88 -0
  23. package/src/core/codemirror/ai/request.ts +2 -14
@@ -1 +1 @@
1
- import{s as ve}from"./chunk-LvLJmgfZ.js";import{d as L,l as at,p as ot,u as Q}from"./useEvent-D91BmmQi.js";import{t as nt}from"./react-Bj1aDYRI.js";import{An as it,Cr as st,D as Ce,E as lt,Li as me,Nn as rt,On as dt,Or as ct,Qt as ht,Xr as pt,_ as mt,br as ut,ct as ft,dt as ze,h as We,kn as bt,lt as yt,t as kt,vr as xt}from"./cells-DOA0Gew8.js";import{t as N}from"./compiler-runtime-B3qBwwSJ.js";import{n as wt,x as gt}from"./ai-model-dropdown-CG4B4rqH.js";import{_ as T,d as Me}from"./useEventListener-DvoEXWke.js";import{x as jt}from"./utils-CvI-39U6.js";import{n as C,t as De}from"./constants-DMpttj8Q.js";import{T as X,v as vt,w as Ct}from"./config-ClMcu_sV.js";import{t as zt}from"./jsx-runtime-BqBOg78p.js";import{o as Wt}from"./alert-dialog-5BGIfskO.js";import{a as Mt,c as Dt,i as _t,n as St,r as At,s as Nt,t as Pt}from"./select-6suE6YM2.js";import{Nt as It}from"./JsonOutput-DRNPZOvX.js";import{c as _e,d as ue,n as Et,o as Lt,r as fe,t as Tt}from"./download-DhxnAw14.js";import{t as Ht}from"./tooltip-B_PkSKN3.js";import{r as Rt,t as be}from"./button-BbCh-29a.js";import{i as Ot,t as Se}from"./strings-wdPMRf6Z.js";import{r as H}from"./requests-DIwGYs0l.js";import{t as h}from"./createLucideIcon-D5guW7EU.js";import{F as Ft,I as qt,L as Ae,P as Bt,R as Vt,a as Ne,i as Pe,u as Ie}from"./layout-dRNPwA-7.js";import{t as Ee}from"./check-BH35Ndha.js";import{r as Yt}from"./useCellActionButton-C4V7J6PS.js";import{t as $t}from"./copy-BwrPA9zQ.js";import{t as Kt}from"./eye-off-Cm6DdkeR.js";import{t as Ut}from"./external-link-BTNxSavU.js";import{t as Z}from"./file-BrdxGLRX.js";import{t as Gt}from"./github-BKS_2Qwn.js";import{u as Jt}from"./form-CxBAInfg.js";import{n as Qt,r as Xt,t as Zt}from"./youtube-CbdpN8oL.js";import{i as ea,n as Le}from"./add-connection-dialog-AhwxOztN.js";import{t as ta}from"./house-mGK3v0Mm.js";import{t as aa}from"./image-DQHXdEQn.js";import{t as oa}from"./link-CfEtM3Rl.js";import{r as na}from"./input-DA8xlX70.js";import{t as ia}from"./settings-DfFe0dWD.js";import{t as sa}from"./sparkles-lWUAsPhp.js";import{y as la}from"./textarea-bBuxbFm7.js";import{t as ra}from"./square-B5xWCt0a.js";import{t as z}from"./use-toast-CJ1Tj2eC.js";import{n as Te,t as da}from"./paths-D5zczhUD.js";import{o as ca}from"./session-0B5NBztP.js";import{n as ee}from"./copy-LK56fFow.js";import{r as ha}from"./useRunCells-cSZpNqnR.js";import{a as pa,c as ma,i as ua,n as fa,r as ba}from"./dialog-DRnNAWYl.js";import{n as ye}from"./ImperativeModal-BW1dmntO.js";import{r as ya,t as He}from"./share-mSf5FZIP.js";import{a as ka}from"./cell-link-Bj4-yOIx.js";import{a as xa}from"./renderShortcut--ku7VECI.js";import{t as wa}from"./icons-Ol38nIbL.js";import{t as ga}from"./pair-with-agent-modal-_SlYEcmZ.js";import{n as Re}from"./marimo-icons-CLbC-oB3.js";import{t as ja}from"./links-DoPgJNku.js";import{r as va,t as Oe}from"./hooks-DyMacA-R.js";import{t as Fe}from"./types-Cpe-qFT-.js";var Ca=h("circle-chevron-down",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 10-4 4-4-4",key:"894hmk"}]]),za=h("circle-chevron-right",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m10 8 4 4-4 4",key:"1wy4r4"}]]),qe=h("clipboard-copy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]),Be=h("command",[["path",{d:"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3",key:"11bfej"}]]),Ve=h("diamond-plus",[["path",{d:"M12 8v8",key:"napkw2"}],["path",{d:"M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41L13.7 2.71a2.41 2.41 0 0 0-3.41 0z",key:"1ey20j"}],["path",{d:"M8 12h8",key:"1wcyev"}]]),Wa=h("fast-forward",[["path",{d:"M12 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 12 18z",key:"b19h5q"}],["path",{d:"M2 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 2 18z",key:"h7h5ge"}]]),Ma=h("files",[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8",key:"14sh0y"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z",key:"1970lx"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1",key:"l4dndm"}]]),Da=h("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]),_a=h("notebook",[["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["path",{d:"M16 2v20",key:"rotuqe"}]]),Sa=h("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]),Ye=h("presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]),Aa=h("share-2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]),Na=h("square-power",[["path",{d:"M12 7v4",key:"xawao1"}],["path",{d:"M7.998 9.003a5 5 0 1 0 8-.005",key:"1pek45"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]),$e=h("undo-2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Ke=N(),ke=ve(nt(),1),a=ve(zt(),1),te="https://static.marimo.app";const Pa=e=>{let t=(0,Ke.c)(25),{onClose:n}=e,[o,s]=(0,ke.useState)(""),{exportAsHTML:r}=H(),l=`${o}-${Math.random().toString(36).slice(2,6)}`,i=`${te}/static/${l}`,d;t[0]!==r||t[1]!==n||t[2]!==l?(d=async v=>{v.preventDefault(),n();let I=await r({download:!1,includeCode:!0,files:Bt.INSTANCE.filenames()}),W=z({title:"Uploading static notebook...",description:"Please wait."});await fetch(`${te}/api/static`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:I,path:l})}).catch(()=>{W.dismiss(),z({title:"Error uploading static page",description:(0,a.jsxs)("div",{children:["Please try again later. If the problem persists, please file a bug report on"," ",(0,a.jsx)("a",{href:C.issuesPage,target:"_blank",className:"underline",children:"GitHub"}),"."]})})}),W.dismiss(),z({title:"Static page uploaded!",description:(0,a.jsxs)("div",{children:["The URL has been copied to your clipboard.",(0,a.jsx)("br",{}),"You can share it with anyone."]})})},t[0]=r,t[1]=n,t[2]=l,t[3]=d):d=t[3];let m;t[4]===Symbol.for("react.memo_cache_sentinel")?(m=(0,a.jsx)(ma,{children:"Share static notebook"}),t[4]=m):m=t[4];let w;t[5]===Symbol.for("react.memo_cache_sentinel")?(w=(0,a.jsxs)(pa,{children:[m,(0,a.jsxs)(ba,{children:["You can publish a static, non-interactive version of this notebook to the public web. We will create a link for you that lives on"," ",(0,a.jsx)("a",{href:te,target:"_blank",children:te}),"."]})]}),t[5]=w):w=t[5];let g;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=v=>{s(v.target.value.toLowerCase().replaceAll(/\s/g,"-").replaceAll(/[^\da-z-]/g,""))},t[6]=g):g=t[6];let u;t[7]===o?u=t[8]:(u=(0,a.jsx)(na,{"data-testid":"slug-input",id:"slug",autoFocus:!0,value:o,placeholder:"Notebook slug",onChange:g,required:!0,autoComplete:"off"}),t[7]=o,t[8]=u);let f;t[9]===i?f=t[10]:(f=(0,a.jsxs)("div",{className:"font-semibold text-sm text-muted-foreground gap-2 flex flex-col",children:["Anyone will be able to access your notebook at this URL:",(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(Ia,{text:i}),(0,a.jsx)("span",{className:"text-primary",children:i})]})]}),t[9]=i,t[10]=f);let b;t[11]!==u||t[12]!==f?(b=(0,a.jsxs)("div",{className:"flex flex-col gap-6 py-4",children:[u,f]}),t[11]=u,t[12]=f,t[13]=b):b=t[13];let y;t[14]===n?y=t[15]:(y=(0,a.jsx)(be,{"data-testid":"cancel-share-static-notebook-button",variant:"secondary",onClick:n,children:"Cancel"}),t[14]=n,t[15]=y);let k;t[16]===i?k=t[17]:(k=(0,a.jsx)(be,{"data-testid":"share-static-notebook-button","aria-label":"Save",variant:"default",type:"submit",onClick:async()=>{await ee(i)},children:"Create"}),t[16]=i,t[17]=k);let x;t[18]!==y||t[19]!==k?(x=(0,a.jsxs)(ua,{children:[y,k]}),t[18]=y,t[19]=k,t[20]=x):x=t[20];let j;return t[21]!==d||t[22]!==x||t[23]!==b?(j=(0,a.jsx)(fa,{className:"w-fit",children:(0,a.jsxs)("form",{onSubmit:d,children:[w,b,x]})}),t[21]=d,t[22]=x,t[23]=b,t[24]=j):j=t[24],j};var Ia=e=>{let t=(0,Ke.c)(8),[n,o]=ke.useState(!1),s;t[0]===e.text?s=t[1]:(s=Rt.stopPropagation(async m=>{m.preventDefault(),await ee(e.text),o(!0),setTimeout(()=>o(!1),2e3)}),t[0]=e.text,t[1]=s);let r=s,l;t[2]===Symbol.for("react.memo_cache_sentinel")?(l=(0,a.jsx)($t,{size:14,strokeWidth:1.5}),t[2]=l):l=t[2];let i;t[3]===r?i=t[4]:(i=(0,a.jsx)(be,{"data-testid":"copy-static-notebook-url-button",onClick:r,size:"xs",variant:"secondary",children:l}),t[3]=r,t[4]=i);let d;return t[5]!==n||t[6]!==i?(d=(0,a.jsx)(Ht,{content:"Copied!",open:n,children:i}),t[5]=n,t[6]=i,t[7]=d):d=t[7],d},Ea=N();function La(){let e=document.getElementsByClassName(De.outputArea);for(let t of e){let n=t.getBoundingClientRect();if(n.bottom>0&&n.top<window.innerHeight){let o=me.findElement(t);if(!o){T.warn("Could not find HTMLCellId for visible output area",t);continue}return{cellId:me.parse(o.id)}}}return T.warn("No visible output area found for scroll anchor"),null}function Ta(e){if(!e){T.warn("No scroll anchor provided to restore scroll position");return}let t=document.getElementById(me.create(e.cellId));if(!t){T.warn("Could not find cell element to restore scroll position",e.cellId);return}if(!t.querySelector(`.${De.outputArea}`)){T.warn("Could not find output area to restore scroll position",e.cellId);return}t.scrollIntoView({block:"start",behavior:"auto"})}function Ue(){let e=(0,Ea.c)(2),t=L(ze),n;return e[0]===t?n=e[1]:(n=()=>{let o=La();t(s=>({mode:yt(s.mode),cellAnchor:(o==null?void 0:o.cellId)??null})),requestAnimationFrame(()=>{requestAnimationFrame(()=>{Ta(o)})})},e[0]=t,e[1]=n),n}const Ge=ot(!1);var Ha=N();const Ra=()=>{let e=(0,Ha.c)(7),{selectedLayout:t}=Ne(),{setLayoutView:n}=Pe();if(X()&&!rt("wasm_layouts"))return null;let o;e[0]===n?o=e[1]:(o=i=>n(i),e[0]=n,e[1]=o);let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=(0,a.jsx)(Nt,{className:"min-w-[110px] border-border bg-background","data-testid":"layout-select",children:(0,a.jsx)(Dt,{placeholder:"Select a view"})}),e[2]=s):s=e[2];let r;e[3]===Symbol.for("react.memo_cache_sentinel")?(r=(0,a.jsx)(St,{children:(0,a.jsxs)(At,{children:[(0,a.jsx)(Mt,{children:"View as"}),Fe.map(Fa)]})}),e[3]=r):r=e[3];let l;return e[4]!==t||e[5]!==o?(l=(0,a.jsxs)(Pt,{"data-testid":"layout-select",value:t,onValueChange:o,children:[s,r]}),e[4]=t,e[5]=o,e[6]=l):l=e[6],l};function Oa(e){return(0,a.jsx)(Je(e),{className:"h-4 w-4"})}function Je(e){switch(e){case"vertical":return Da;case"grid":return Xt;case"slides":return Ye;default:return Ot(e),ra}}function Qe(e){return Se.startCase(e)}function Fa(e){return(0,a.jsx)(_t,{value:e,children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5 leading-5",children:[Oa(e),(0,a.jsx)("span",{children:Qe(e)})]})},e)}async function qa(e){let{filename:t,preset:n,downloadPDF:o}=e;await o({filename:t,webpdf:!1,preset:n,includeInputs:!0,rasterServer:"static"})}var Ba=N();function Va(e){let t=(0,Ba.c)(5),{openPrompt:n,closeModal:o}=ye(),{sendCopy:s}=H(),r;return t[0]!==o||t[1]!==n||t[2]!==s||t[3]!==e?(r=()=>{if(!e)return null;let l=da.guessDeliminator(e);n({title:"Copy notebook",description:"Enter a new filename for the notebook copy.",defaultValue:`_${Te.basename(e)}`,confirmText:"Copy notebook",spellCheck:!1,onConfirm:i=>{let d=l.join(Te.dirname(e),i);s({source:e,destination:d}).then(()=>{o(),z({title:"Notebook copied",description:"A copy of the notebook has been created."}),ja(d)})}})},t[0]=o,t[1]=n,t[2]=s,t[3]=e,t[4]=r):r=t[4],r}const Ya=()=>{let{updateCellConfig:e}=Ce(),{saveCellConfig:t}=H();return(0,ke.useCallback)(async()=>{let n=new ht,o=We(),s=o.cellIds.inOrderIds,r={};for(let i of s){if(o.cellData[i]===void 0)continue;let{code:d,config:m}=o.cellData[i];m.hide_code||n.isSupported(d)&&(r[i]={hide_code:!0})}let l=Me.entries(r);if(l.length!==0){await t({configs:r});for(let[i,d]of l)e({cellId:i,config:d})}},[e])};var $a=N();function Xe(){let e=(0,$a.c)(4),{openConfirm:t}=ye(),n=L(vt),{sendRestart:o}=H(),s;return e[0]!==t||e[1]!==o||e[2]!==n?(s=()=>{t({title:"Restart Kernel",description:"This will restart the Python kernel. You'll lose all data that's in memory. You will also lose any unsaved changes, so make sure to save your work before restarting.",variant:"destructive",confirmAction:(0,a.jsx)(Wt,{onClick:async()=>{n({state:Ct.CLOSING}),await o(),ya()},"aria-label":"Confirm Restart",children:"Restart"})})},e[0]=t,e[1]=o,e[2]=n,e[3]=s):s=e[3],s}var Ka=N(),P=e=>{e==null||e.preventDefault(),e==null||e.stopPropagation()};function Ua(){var we,ge,je;let e=(0,Ka.c)(53),t=ka(),{openModal:n,closeModal:o}=ye(),{toggleApplication:s}=dt(),{selectedPanel:r}=bt(),[l]=at(ze),i=Q(ft),d=Ya(),[m]=jt(),{updateCellConfig:w,undoDeleteCell:g,clearAllCellOutputs:u,addSetupCellIfDoesntExist:f,collapseAllCells:b,expandAllCells:y}=Ce(),k=Xe(),x=ha(),j=Va(t),v=L(Ge),I=L(wt),W=L(gt),{exportAsIPYNB:oe,exportAsMarkdown:ne,readCode:M,saveCellConfig:ie,updateCellOutputs:D}=H(),_=va(),se=Q(mt),le=Q(kt),re=Q(lt),{selectedLayout:R}=Ne(),{setLayoutView:de}=Pe(),O=Ue(),F=((we=m.sharing)==null?void 0:we.html)??!0,q=((ge=m.sharing)==null?void 0:ge.wasm)??!0,B=((je=m.sharing)==null?void 0:je.molab)??!0,xe=!X(),ce=R==="slides",Ze=mo,et=po,V;e[0]!==t||e[1]!==_||e[2]!==D?(V=async c=>{let{preset:p,title:E}=c;if(!t){ae();return}await _e(E,async pe=>{await Oe({takeScreenshots:()=>_({progress:pe}),updateCellOutputs:D}),await qa({filename:t,preset:p,downloadPDF:Et})})},e[0]=t,e[1]=_,e[2]=D,e[3]=V):V=e[3];let S=V,Y;e[4]===S?Y=e[5]:(Y=async()=>{if(xe){await S({preset:"document",title:"Downloading Document PDF..."});return}let c=new Event("export-beforeprint"),p=new Event("export-afterprint");window.dispatchEvent(c),setTimeout(ho,0),setTimeout(()=>window.dispatchEvent(p),0)},e[4]=S,e[5]=Y);let $=Y,K;e[6]!==oe||e[7]!==t||e[8]!==_||e[9]!==D?(K=async()=>{if(!t){ae();return}await _e("Downloading IPYNB...",async c=>{await Oe({takeScreenshots:()=>_({progress:c}),updateCellOutputs:D});let p=await oe({download:!1});fe(new Blob([p],{type:"application/x-ipynb+json"}),ue.toIPYNB(document.title))})},e[6]=oe,e[7]=t,e[8]=_,e[9]=D,e[10]=K):K=e[10];let he=K,U;e[11]===Symbol.for("react.memo_cache_sentinel")?(U=(0,a.jsx)(It,{size:14,strokeWidth:1.5}),e[11]=U):U=e[11];let G;e[12]===Symbol.for("react.memo_cache_sentinel")?(G=(0,a.jsx)(Ae,{size:14,strokeWidth:1.5}),e[12]=G):G=e[12];let A;e[13]===t?A=e[14]:(A=async()=>{if(!t){ae();return}await Ie({filename:t,includeCode:!0})},e[13]=t,e[14]=A);let J;return e[15]!==f||e[16]!==le||e[17]!==u||e[18]!==o||e[19]!==b||e[20]!==j||e[21]!==S||e[22]!==y||e[23]!==ne||e[24]!==t||e[25]!==$||e[26]!==he||e[27]!==se||e[28]!==d||e[29]!==ce||e[30]!==i||e[31]!==n||e[32]!==M||e[33]!==k||e[34]!==x||e[35]!==ie||e[36]!==R||e[37]!==r||e[38]!==v||e[39]!==W||e[40]!==de||e[41]!==I||e[42]!==F||e[43]!==B||e[44]!==q||e[45]!==A||e[46]!==s||e[47]!==O||e[48]!==g||e[49]!==re||e[50]!==w||e[51]!==l.mode?(J=[{icon:U,label:"Download",handle:P,dropdown:[{icon:G,label:"Download as HTML",handle:A},{icon:(0,a.jsx)(Ae,{size:14,strokeWidth:1.5}),label:"Download as HTML (exclude code)",handle:async()=>{if(!t){ae();return}await Ie({filename:t,includeCode:!1})}},{icon:(0,a.jsx)(wa,{strokeWidth:1.5,style:{width:14,height:14}}),label:"Download as Markdown",handle:async()=>{let c=await ne({download:!1});fe(new Blob([c],{type:"text/plain"}),ue.toMarkdown(document.title))}},{icon:(0,a.jsx)(_a,{size:14,strokeWidth:1.5}),label:"Download as ipynb",handle:he},{icon:(0,a.jsx)(Vt,{size:14,strokeWidth:1.5}),label:"Download Python code",handle:async()=>{let c=await M();fe(new Blob([c.contents],{type:"text/plain"}),ue.toPY(document.title))}},{divider:!0,icon:(0,a.jsx)(aa,{size:14,strokeWidth:1.5}),label:"Download as PNG",disabled:l.mode!=="present",tooltip:l.mode==="present"?void 0:(0,a.jsxs)("span",{children:["Only available in app view. ",(0,a.jsx)("br",{}),"Toggle with: ",xa("global.hideCode",!1)]}),handle:co},ce?{divider:!0,icon:(0,a.jsx)(Z,{size:14,strokeWidth:1.5}),label:"Download as PDF",handle:P,dropdown:[{icon:(0,a.jsx)(Z,{size:14,strokeWidth:1.5}),label:"Document Layout",handle:$},{icon:(0,a.jsx)(Z,{size:14,strokeWidth:1.5}),label:"Slides Layout",rightElement:et(!0),hidden:!xe,handle:async()=>{await S({preset:"slides",title:"Downloading Slides PDF..."})}}]}:{divider:!0,icon:(0,a.jsx)(Z,{size:14,strokeWidth:1.5}),label:"Download as PDF",handle:$}]},{icon:(0,a.jsx)(sa,{size:14,strokeWidth:1.5}),label:"Pair with an agent",hidden:X(),handle:async()=>{n((0,a.jsx)(ga,{onClose:o}))}},{icon:(0,a.jsx)(Aa,{size:14,strokeWidth:1.5}),label:"Share",handle:P,hidden:!F&&!q&&!B,dropdown:[{icon:(0,a.jsx)(Jt,{size:14,strokeWidth:1.5}),label:"Publish HTML to web",hidden:!F,handle:async()=>{n((0,a.jsx)(Pa,{onClose:o}))}},{icon:(0,a.jsx)(oa,{size:14,strokeWidth:1.5}),label:"Create WebAssembly link",hidden:!q,handle:async()=>{await ee(He({code:(await M()).contents})),z({title:"Copied",description:"Link copied to clipboard."})}},{icon:(0,a.jsx)(Re,{size:14,strokeWidth:1.5}),label:"Create molab notebook",hidden:!B,handle:async()=>{let c=He({code:(await M()).contents,baseUrl:`${C.molab}/new`});window.open(c,"_blank")}}]},{icon:(0,a.jsx)(Sa,{size:14,strokeWidth:1.5}),label:"Helper panel",redundant:!0,handle:P,dropdown:it.flatMap(c=>{let{type:p,Icon:E,hidden:pe,additionalKeywords:tt}=c;return pe?[]:{label:Se.startCase(p),rightElement:Ze(r===p),icon:(0,a.jsx)(E,{size:14,strokeWidth:1.5}),handle:()=>s(p),additionalKeywords:tt}})},{icon:(0,a.jsx)(Ye,{size:14,strokeWidth:1.5}),label:"Present as",handle:P,dropdown:[{icon:l.mode==="present"?(0,a.jsx)(la,{size:14,strokeWidth:1.5}):(0,a.jsx)(Ft,{size:14,strokeWidth:1.5}),label:"Toggle app view",hotkey:"global.hideCode",handle:()=>{O()}},...Fe.map((c,p)=>{let E=Je(c);return{divider:p===0,label:Qe(c),icon:(0,a.jsx)(E,{size:14,strokeWidth:1.5}),rightElement:(0,a.jsx)("div",{className:"w-8 flex justify-end",children:R===c&&(0,a.jsx)(Ee,{size:14})}),handle:()=>{de(c),l.mode==="edit"&&O()}}})]},{icon:(0,a.jsx)(Ma,{size:14,strokeWidth:1.5}),label:"Duplicate notebook",hidden:!t||X(),handle:j},{icon:(0,a.jsx)(qe,{size:14,strokeWidth:1.5}),label:"Copy code to clipboard",hidden:!t,handle:async()=>{await ee((await M()).contents),z({title:"Copied",description:"Code copied to clipboard."})}},{icon:(0,a.jsx)(Yt,{size:14,strokeWidth:1.5}),label:"Enable all cells",hidden:!se||i,handle:async()=>{let c=pt(We());await ie({configs:Me.fromEntries(c.map(ro))});for(let p of c)w({cellId:p,config:{disabled:!1}})}},{divider:!0,icon:(0,a.jsx)(Ve,{size:14,strokeWidth:1.5}),label:"Add setup cell",handle:()=>{f({})}},{icon:(0,a.jsx)(ut,{size:14,strokeWidth:1.5}),label:"Add database connection",handle:()=>{n((0,a.jsx)(Le,{onClose:o}))}},{icon:(0,a.jsx)(ea,{size:14,strokeWidth:1.5}),label:"Add remote storage",handle:()=>{n((0,a.jsx)(Le,{defaultTab:"storage",onClose:o}))}},{icon:(0,a.jsx)($e,{size:14,strokeWidth:1.5}),label:re,hidden:!le||i,handle:()=>{g()}},{icon:(0,a.jsx)(Na,{size:14,strokeWidth:1.5}),label:"Restart kernel",variant:"danger",handle:k,additionalKeywords:["reset","reload","restart"]},{icon:(0,a.jsx)(Wa,{size:14,strokeWidth:1.5}),label:"Re-run all cells",redundant:!0,hotkey:"global.runAll",handle:async()=>{x()}},{icon:(0,a.jsx)(st,{size:14,strokeWidth:1.5}),label:"Clear all outputs",redundant:!0,handle:()=>{u()}},{icon:(0,a.jsx)(Kt,{size:14,strokeWidth:1.5}),label:"Hide all markdown code",handle:d,redundant:!0},{icon:(0,a.jsx)(za,{size:14,strokeWidth:1.5}),label:"Collapse all sections",hotkey:"global.collapseAllSections",handle:b,redundant:!0},{icon:(0,a.jsx)(Ca,{size:14,strokeWidth:1.5}),label:"Expand all sections",hotkey:"global.expandAllSections",handle:y,redundant:!0},{divider:!0,icon:(0,a.jsx)(Be,{size:14,strokeWidth:1.5}),label:"Command palette",hotkey:"global.commandPalette",handle:()=>v(lo)},{icon:(0,a.jsx)(qt,{size:14,strokeWidth:1.5}),label:"Keyboard shortcuts",hotkey:"global.showHelp",handle:()=>W(so)},{icon:(0,a.jsx)(ia,{size:14,strokeWidth:1.5}),label:"User settings",handle:()=>I(io),redundant:!0,additionalKeywords:["preferences","options","configuration"]},{icon:(0,a.jsx)(Ut,{size:14,strokeWidth:1.5}),label:"Resources",handle:P,dropdown:[{icon:(0,a.jsx)(ct,{size:14,strokeWidth:1.5}),label:"Documentation",handle:no},{icon:(0,a.jsx)(Gt,{size:14,strokeWidth:1.5}),label:"GitHub",handle:oo},{icon:(0,a.jsx)(Qt,{size:14,strokeWidth:1.5}),label:"Discord Community",handle:ao},{icon:(0,a.jsx)(Zt,{size:14,strokeWidth:1.5}),label:"YouTube",handle:to},{icon:(0,a.jsx)(xt,{size:14,strokeWidth:1.5}),label:"Changelog",handle:eo}]},{divider:!0,icon:(0,a.jsx)(ta,{size:14,strokeWidth:1.5}),label:"Return home",hidden:!location.search.includes("file"),handle:Za},{icon:(0,a.jsx)(Re,{size:14,strokeWidth:1.5}),label:"New notebook",hidden:!location.search.includes("file"),handle:Xa}].filter(Qa).map(Ga),e[15]=f,e[16]=le,e[17]=u,e[18]=o,e[19]=b,e[20]=j,e[21]=S,e[22]=y,e[23]=ne,e[24]=t,e[25]=$,e[26]=he,e[27]=se,e[28]=d,e[29]=ce,e[30]=i,e[31]=n,e[32]=M,e[33]=k,e[34]=x,e[35]=ie,e[36]=R,e[37]=r,e[38]=v,e[39]=W,e[40]=de,e[41]=I,e[42]=F,e[43]=B,e[44]=q,e[45]=A,e[46]=s,e[47]=O,e[48]=g,e[49]=re,e[50]=w,e[51]=l.mode,e[52]=J):J=e[52],J}function Ga(e){return e.dropdown?{...e,dropdown:e.dropdown.filter(Ja)}:e}function Ja(e){return!e.hidden}function Qa(e){return!e.hidden}function Xa(){let e=ca();window.open(e,"_blank")}function Za(){let e=document.baseURI.split("?")[0];window.open(e,"_self")}function eo(){window.open(C.releasesPage,"_blank")}function to(){window.open(C.youtube,"_blank")}function ao(){window.open(C.discordLink,"_blank")}function oo(){window.open(C.githubPage,"_blank")}function no(){window.open(C.docsPage,"_blank")}function io(e){return!e}function so(e){return!e}function lo(e){return!e}function ro(e){return[e,{disabled:!1}]}async function co(){let e=document.getElementById("App");e&&await Lt({element:e,filename:document.title,prepare:Tt})}function ho(){return window.print()}function po(e){return e?(0,a.jsx)("span",{className:"ml-3 shrink-0 rounded-full border border-emerald-200 bg-emerald-50 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-emerald-700",children:"Recommended"}):null}function mo(e){return(0,a.jsx)("div",{className:"w-8 flex justify-end",children:e&&(0,a.jsx)(Ee,{size:14})})}function ae(){z({title:"Error",description:"Notebooks must be named to be exported.",variant:"danger"})}export{Ue as a,Be as c,Ge as i,qe as l,Xe as n,$e as o,Ra as r,Ve as s,Ua as t};
1
+ import{s as ve}from"./chunk-LvLJmgfZ.js";import{d as L,l as at,p as ot,u as Q}from"./useEvent-D91BmmQi.js";import{t as nt}from"./react-Bj1aDYRI.js";import{An as it,Cr as st,D as Ce,E as lt,Li as me,Nn as rt,On as dt,Or as ct,Qt as ht,Xr as pt,_ as mt,br as ut,ct as ft,dt as ze,h as We,kn as bt,lt as yt,t as kt,vr as xt}from"./cells-DOA0Gew8.js";import{t as N}from"./compiler-runtime-B3qBwwSJ.js";import{n as wt,x as gt}from"./ai-model-dropdown-CG4B4rqH.js";import{_ as T,d as Me}from"./useEventListener-DvoEXWke.js";import{x as jt}from"./utils-CvI-39U6.js";import{n as C,t as De}from"./constants-DMpttj8Q.js";import{T as X,v as vt,w as Ct}from"./config-ClMcu_sV.js";import{t as zt}from"./jsx-runtime-BqBOg78p.js";import{o as Wt}from"./alert-dialog-5BGIfskO.js";import{a as Mt,c as Dt,i as _t,n as St,r as At,s as Nt,t as Pt}from"./select-6suE6YM2.js";import{Nt as It}from"./JsonOutput-DRNPZOvX.js";import{c as _e,d as ue,n as Et,o as Lt,r as fe,t as Tt}from"./download-DhxnAw14.js";import{t as Ht}from"./tooltip-B_PkSKN3.js";import{r as Rt,t as be}from"./button-BbCh-29a.js";import{i as Ot,t as Se}from"./strings-wdPMRf6Z.js";import{r as H}from"./requests-DIwGYs0l.js";import{t as h}from"./createLucideIcon-D5guW7EU.js";import{F as Ft,I as qt,L as Ae,P as Bt,R as Vt,a as Ne,i as Pe,u as Ie}from"./layout-D3pd3R21.js";import{t as Ee}from"./check-BH35Ndha.js";import{r as Yt}from"./useCellActionButton-C4V7J6PS.js";import{t as $t}from"./copy-BwrPA9zQ.js";import{t as Kt}from"./eye-off-Cm6DdkeR.js";import{t as Ut}from"./external-link-BTNxSavU.js";import{t as Z}from"./file-BrdxGLRX.js";import{t as Gt}from"./github-BKS_2Qwn.js";import{u as Jt}from"./form-CxBAInfg.js";import{n as Qt,r as Xt,t as Zt}from"./youtube-CbdpN8oL.js";import{i as ea,n as Le}from"./add-connection-dialog-AhwxOztN.js";import{t as ta}from"./house-mGK3v0Mm.js";import{t as aa}from"./image-DQHXdEQn.js";import{t as oa}from"./link-CfEtM3Rl.js";import{r as na}from"./input-DA8xlX70.js";import{t as ia}from"./settings-DfFe0dWD.js";import{t as sa}from"./sparkles-lWUAsPhp.js";import{y as la}from"./textarea-bBuxbFm7.js";import{t as ra}from"./square-B5xWCt0a.js";import{t as z}from"./use-toast-CJ1Tj2eC.js";import{n as Te,t as da}from"./paths-D5zczhUD.js";import{o as ca}from"./session-0B5NBztP.js";import{n as ee}from"./copy-LK56fFow.js";import{r as ha}from"./useRunCells-cSZpNqnR.js";import{a as pa,c as ma,i as ua,n as fa,r as ba}from"./dialog-DRnNAWYl.js";import{n as ye}from"./ImperativeModal-BW1dmntO.js";import{r as ya,t as He}from"./share-mSf5FZIP.js";import{a as ka}from"./cell-link-Bj4-yOIx.js";import{a as xa}from"./renderShortcut--ku7VECI.js";import{t as wa}from"./icons-Ol38nIbL.js";import{t as ga}from"./pair-with-agent-modal-_SlYEcmZ.js";import{n as Re}from"./marimo-icons-CLbC-oB3.js";import{t as ja}from"./links-DoPgJNku.js";import{r as va,t as Oe}from"./hooks-5gNQitDd.js";import{t as Fe}from"./types-Cpe-qFT-.js";var Ca=h("circle-chevron-down",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 10-4 4-4-4",key:"894hmk"}]]),za=h("circle-chevron-right",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m10 8 4 4-4 4",key:"1wy4r4"}]]),qe=h("clipboard-copy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]),Be=h("command",[["path",{d:"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3",key:"11bfej"}]]),Ve=h("diamond-plus",[["path",{d:"M12 8v8",key:"napkw2"}],["path",{d:"M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41L13.7 2.71a2.41 2.41 0 0 0-3.41 0z",key:"1ey20j"}],["path",{d:"M8 12h8",key:"1wcyev"}]]),Wa=h("fast-forward",[["path",{d:"M12 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 12 18z",key:"b19h5q"}],["path",{d:"M2 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 2 18z",key:"h7h5ge"}]]),Ma=h("files",[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8",key:"14sh0y"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z",key:"1970lx"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1",key:"l4dndm"}]]),Da=h("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]),_a=h("notebook",[["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["path",{d:"M16 2v20",key:"rotuqe"}]]),Sa=h("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]),Ye=h("presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]),Aa=h("share-2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]),Na=h("square-power",[["path",{d:"M12 7v4",key:"xawao1"}],["path",{d:"M7.998 9.003a5 5 0 1 0 8-.005",key:"1pek45"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]),$e=h("undo-2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Ke=N(),ke=ve(nt(),1),a=ve(zt(),1),te="https://static.marimo.app";const Pa=e=>{let t=(0,Ke.c)(25),{onClose:n}=e,[o,s]=(0,ke.useState)(""),{exportAsHTML:r}=H(),l=`${o}-${Math.random().toString(36).slice(2,6)}`,i=`${te}/static/${l}`,d;t[0]!==r||t[1]!==n||t[2]!==l?(d=async v=>{v.preventDefault(),n();let I=await r({download:!1,includeCode:!0,files:Bt.INSTANCE.filenames()}),W=z({title:"Uploading static notebook...",description:"Please wait."});await fetch(`${te}/api/static`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:I,path:l})}).catch(()=>{W.dismiss(),z({title:"Error uploading static page",description:(0,a.jsxs)("div",{children:["Please try again later. If the problem persists, please file a bug report on"," ",(0,a.jsx)("a",{href:C.issuesPage,target:"_blank",className:"underline",children:"GitHub"}),"."]})})}),W.dismiss(),z({title:"Static page uploaded!",description:(0,a.jsxs)("div",{children:["The URL has been copied to your clipboard.",(0,a.jsx)("br",{}),"You can share it with anyone."]})})},t[0]=r,t[1]=n,t[2]=l,t[3]=d):d=t[3];let m;t[4]===Symbol.for("react.memo_cache_sentinel")?(m=(0,a.jsx)(ma,{children:"Share static notebook"}),t[4]=m):m=t[4];let w;t[5]===Symbol.for("react.memo_cache_sentinel")?(w=(0,a.jsxs)(pa,{children:[m,(0,a.jsxs)(ba,{children:["You can publish a static, non-interactive version of this notebook to the public web. We will create a link for you that lives on"," ",(0,a.jsx)("a",{href:te,target:"_blank",children:te}),"."]})]}),t[5]=w):w=t[5];let g;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=v=>{s(v.target.value.toLowerCase().replaceAll(/\s/g,"-").replaceAll(/[^\da-z-]/g,""))},t[6]=g):g=t[6];let u;t[7]===o?u=t[8]:(u=(0,a.jsx)(na,{"data-testid":"slug-input",id:"slug",autoFocus:!0,value:o,placeholder:"Notebook slug",onChange:g,required:!0,autoComplete:"off"}),t[7]=o,t[8]=u);let f;t[9]===i?f=t[10]:(f=(0,a.jsxs)("div",{className:"font-semibold text-sm text-muted-foreground gap-2 flex flex-col",children:["Anyone will be able to access your notebook at this URL:",(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(Ia,{text:i}),(0,a.jsx)("span",{className:"text-primary",children:i})]})]}),t[9]=i,t[10]=f);let b;t[11]!==u||t[12]!==f?(b=(0,a.jsxs)("div",{className:"flex flex-col gap-6 py-4",children:[u,f]}),t[11]=u,t[12]=f,t[13]=b):b=t[13];let y;t[14]===n?y=t[15]:(y=(0,a.jsx)(be,{"data-testid":"cancel-share-static-notebook-button",variant:"secondary",onClick:n,children:"Cancel"}),t[14]=n,t[15]=y);let k;t[16]===i?k=t[17]:(k=(0,a.jsx)(be,{"data-testid":"share-static-notebook-button","aria-label":"Save",variant:"default",type:"submit",onClick:async()=>{await ee(i)},children:"Create"}),t[16]=i,t[17]=k);let x;t[18]!==y||t[19]!==k?(x=(0,a.jsxs)(ua,{children:[y,k]}),t[18]=y,t[19]=k,t[20]=x):x=t[20];let j;return t[21]!==d||t[22]!==x||t[23]!==b?(j=(0,a.jsx)(fa,{className:"w-fit",children:(0,a.jsxs)("form",{onSubmit:d,children:[w,b,x]})}),t[21]=d,t[22]=x,t[23]=b,t[24]=j):j=t[24],j};var Ia=e=>{let t=(0,Ke.c)(8),[n,o]=ke.useState(!1),s;t[0]===e.text?s=t[1]:(s=Rt.stopPropagation(async m=>{m.preventDefault(),await ee(e.text),o(!0),setTimeout(()=>o(!1),2e3)}),t[0]=e.text,t[1]=s);let r=s,l;t[2]===Symbol.for("react.memo_cache_sentinel")?(l=(0,a.jsx)($t,{size:14,strokeWidth:1.5}),t[2]=l):l=t[2];let i;t[3]===r?i=t[4]:(i=(0,a.jsx)(be,{"data-testid":"copy-static-notebook-url-button",onClick:r,size:"xs",variant:"secondary",children:l}),t[3]=r,t[4]=i);let d;return t[5]!==n||t[6]!==i?(d=(0,a.jsx)(Ht,{content:"Copied!",open:n,children:i}),t[5]=n,t[6]=i,t[7]=d):d=t[7],d},Ea=N();function La(){let e=document.getElementsByClassName(De.outputArea);for(let t of e){let n=t.getBoundingClientRect();if(n.bottom>0&&n.top<window.innerHeight){let o=me.findElement(t);if(!o){T.warn("Could not find HTMLCellId for visible output area",t);continue}return{cellId:me.parse(o.id)}}}return T.warn("No visible output area found for scroll anchor"),null}function Ta(e){if(!e){T.warn("No scroll anchor provided to restore scroll position");return}let t=document.getElementById(me.create(e.cellId));if(!t){T.warn("Could not find cell element to restore scroll position",e.cellId);return}if(!t.querySelector(`.${De.outputArea}`)){T.warn("Could not find output area to restore scroll position",e.cellId);return}t.scrollIntoView({block:"start",behavior:"auto"})}function Ue(){let e=(0,Ea.c)(2),t=L(ze),n;return e[0]===t?n=e[1]:(n=()=>{let o=La();t(s=>({mode:yt(s.mode),cellAnchor:(o==null?void 0:o.cellId)??null})),requestAnimationFrame(()=>{requestAnimationFrame(()=>{Ta(o)})})},e[0]=t,e[1]=n),n}const Ge=ot(!1);var Ha=N();const Ra=()=>{let e=(0,Ha.c)(7),{selectedLayout:t}=Ne(),{setLayoutView:n}=Pe();if(X()&&!rt("wasm_layouts"))return null;let o;e[0]===n?o=e[1]:(o=i=>n(i),e[0]=n,e[1]=o);let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=(0,a.jsx)(Nt,{className:"min-w-[110px] border-border bg-background","data-testid":"layout-select",children:(0,a.jsx)(Dt,{placeholder:"Select a view"})}),e[2]=s):s=e[2];let r;e[3]===Symbol.for("react.memo_cache_sentinel")?(r=(0,a.jsx)(St,{children:(0,a.jsxs)(At,{children:[(0,a.jsx)(Mt,{children:"View as"}),Fe.map(Fa)]})}),e[3]=r):r=e[3];let l;return e[4]!==t||e[5]!==o?(l=(0,a.jsxs)(Pt,{"data-testid":"layout-select",value:t,onValueChange:o,children:[s,r]}),e[4]=t,e[5]=o,e[6]=l):l=e[6],l};function Oa(e){return(0,a.jsx)(Je(e),{className:"h-4 w-4"})}function Je(e){switch(e){case"vertical":return Da;case"grid":return Xt;case"slides":return Ye;default:return Ot(e),ra}}function Qe(e){return Se.startCase(e)}function Fa(e){return(0,a.jsx)(_t,{value:e,children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5 leading-5",children:[Oa(e),(0,a.jsx)("span",{children:Qe(e)})]})},e)}async function qa(e){let{filename:t,preset:n,downloadPDF:o}=e;await o({filename:t,webpdf:!1,preset:n,includeInputs:!0,rasterServer:"static"})}var Ba=N();function Va(e){let t=(0,Ba.c)(5),{openPrompt:n,closeModal:o}=ye(),{sendCopy:s}=H(),r;return t[0]!==o||t[1]!==n||t[2]!==s||t[3]!==e?(r=()=>{if(!e)return null;let l=da.guessDeliminator(e);n({title:"Copy notebook",description:"Enter a new filename for the notebook copy.",defaultValue:`_${Te.basename(e)}`,confirmText:"Copy notebook",spellCheck:!1,onConfirm:i=>{let d=l.join(Te.dirname(e),i);s({source:e,destination:d}).then(()=>{o(),z({title:"Notebook copied",description:"A copy of the notebook has been created."}),ja(d)})}})},t[0]=o,t[1]=n,t[2]=s,t[3]=e,t[4]=r):r=t[4],r}const Ya=()=>{let{updateCellConfig:e}=Ce(),{saveCellConfig:t}=H();return(0,ke.useCallback)(async()=>{let n=new ht,o=We(),s=o.cellIds.inOrderIds,r={};for(let i of s){if(o.cellData[i]===void 0)continue;let{code:d,config:m}=o.cellData[i];m.hide_code||n.isSupported(d)&&(r[i]={hide_code:!0})}let l=Me.entries(r);if(l.length!==0){await t({configs:r});for(let[i,d]of l)e({cellId:i,config:d})}},[e])};var $a=N();function Xe(){let e=(0,$a.c)(4),{openConfirm:t}=ye(),n=L(vt),{sendRestart:o}=H(),s;return e[0]!==t||e[1]!==o||e[2]!==n?(s=()=>{t({title:"Restart Kernel",description:"This will restart the Python kernel. You'll lose all data that's in memory. You will also lose any unsaved changes, so make sure to save your work before restarting.",variant:"destructive",confirmAction:(0,a.jsx)(Wt,{onClick:async()=>{n({state:Ct.CLOSING}),await o(),ya()},"aria-label":"Confirm Restart",children:"Restart"})})},e[0]=t,e[1]=o,e[2]=n,e[3]=s):s=e[3],s}var Ka=N(),P=e=>{e==null||e.preventDefault(),e==null||e.stopPropagation()};function Ua(){var we,ge,je;let e=(0,Ka.c)(53),t=ka(),{openModal:n,closeModal:o}=ye(),{toggleApplication:s}=dt(),{selectedPanel:r}=bt(),[l]=at(ze),i=Q(ft),d=Ya(),[m]=jt(),{updateCellConfig:w,undoDeleteCell:g,clearAllCellOutputs:u,addSetupCellIfDoesntExist:f,collapseAllCells:b,expandAllCells:y}=Ce(),k=Xe(),x=ha(),j=Va(t),v=L(Ge),I=L(wt),W=L(gt),{exportAsIPYNB:oe,exportAsMarkdown:ne,readCode:M,saveCellConfig:ie,updateCellOutputs:D}=H(),_=va(),se=Q(mt),le=Q(kt),re=Q(lt),{selectedLayout:R}=Ne(),{setLayoutView:de}=Pe(),O=Ue(),F=((we=m.sharing)==null?void 0:we.html)??!0,q=((ge=m.sharing)==null?void 0:ge.wasm)??!0,B=((je=m.sharing)==null?void 0:je.molab)??!0,xe=!X(),ce=R==="slides",Ze=mo,et=po,V;e[0]!==t||e[1]!==_||e[2]!==D?(V=async c=>{let{preset:p,title:E}=c;if(!t){ae();return}await _e(E,async pe=>{await Oe({takeScreenshots:()=>_({progress:pe}),updateCellOutputs:D}),await qa({filename:t,preset:p,downloadPDF:Et})})},e[0]=t,e[1]=_,e[2]=D,e[3]=V):V=e[3];let S=V,Y;e[4]===S?Y=e[5]:(Y=async()=>{if(xe){await S({preset:"document",title:"Downloading Document PDF..."});return}let c=new Event("export-beforeprint"),p=new Event("export-afterprint");window.dispatchEvent(c),setTimeout(ho,0),setTimeout(()=>window.dispatchEvent(p),0)},e[4]=S,e[5]=Y);let $=Y,K;e[6]!==oe||e[7]!==t||e[8]!==_||e[9]!==D?(K=async()=>{if(!t){ae();return}await _e("Downloading IPYNB...",async c=>{await Oe({takeScreenshots:()=>_({progress:c}),updateCellOutputs:D});let p=await oe({download:!1});fe(new Blob([p],{type:"application/x-ipynb+json"}),ue.toIPYNB(document.title))})},e[6]=oe,e[7]=t,e[8]=_,e[9]=D,e[10]=K):K=e[10];let he=K,U;e[11]===Symbol.for("react.memo_cache_sentinel")?(U=(0,a.jsx)(It,{size:14,strokeWidth:1.5}),e[11]=U):U=e[11];let G;e[12]===Symbol.for("react.memo_cache_sentinel")?(G=(0,a.jsx)(Ae,{size:14,strokeWidth:1.5}),e[12]=G):G=e[12];let A;e[13]===t?A=e[14]:(A=async()=>{if(!t){ae();return}await Ie({filename:t,includeCode:!0})},e[13]=t,e[14]=A);let J;return e[15]!==f||e[16]!==le||e[17]!==u||e[18]!==o||e[19]!==b||e[20]!==j||e[21]!==S||e[22]!==y||e[23]!==ne||e[24]!==t||e[25]!==$||e[26]!==he||e[27]!==se||e[28]!==d||e[29]!==ce||e[30]!==i||e[31]!==n||e[32]!==M||e[33]!==k||e[34]!==x||e[35]!==ie||e[36]!==R||e[37]!==r||e[38]!==v||e[39]!==W||e[40]!==de||e[41]!==I||e[42]!==F||e[43]!==B||e[44]!==q||e[45]!==A||e[46]!==s||e[47]!==O||e[48]!==g||e[49]!==re||e[50]!==w||e[51]!==l.mode?(J=[{icon:U,label:"Download",handle:P,dropdown:[{icon:G,label:"Download as HTML",handle:A},{icon:(0,a.jsx)(Ae,{size:14,strokeWidth:1.5}),label:"Download as HTML (exclude code)",handle:async()=>{if(!t){ae();return}await Ie({filename:t,includeCode:!1})}},{icon:(0,a.jsx)(wa,{strokeWidth:1.5,style:{width:14,height:14}}),label:"Download as Markdown",handle:async()=>{let c=await ne({download:!1});fe(new Blob([c],{type:"text/plain"}),ue.toMarkdown(document.title))}},{icon:(0,a.jsx)(_a,{size:14,strokeWidth:1.5}),label:"Download as ipynb",handle:he},{icon:(0,a.jsx)(Vt,{size:14,strokeWidth:1.5}),label:"Download Python code",handle:async()=>{let c=await M();fe(new Blob([c.contents],{type:"text/plain"}),ue.toPY(document.title))}},{divider:!0,icon:(0,a.jsx)(aa,{size:14,strokeWidth:1.5}),label:"Download as PNG",disabled:l.mode!=="present",tooltip:l.mode==="present"?void 0:(0,a.jsxs)("span",{children:["Only available in app view. ",(0,a.jsx)("br",{}),"Toggle with: ",xa("global.hideCode",!1)]}),handle:co},ce?{divider:!0,icon:(0,a.jsx)(Z,{size:14,strokeWidth:1.5}),label:"Download as PDF",handle:P,dropdown:[{icon:(0,a.jsx)(Z,{size:14,strokeWidth:1.5}),label:"Document Layout",handle:$},{icon:(0,a.jsx)(Z,{size:14,strokeWidth:1.5}),label:"Slides Layout",rightElement:et(!0),hidden:!xe,handle:async()=>{await S({preset:"slides",title:"Downloading Slides PDF..."})}}]}:{divider:!0,icon:(0,a.jsx)(Z,{size:14,strokeWidth:1.5}),label:"Download as PDF",handle:$}]},{icon:(0,a.jsx)(sa,{size:14,strokeWidth:1.5}),label:"Pair with an agent",hidden:X(),handle:async()=>{n((0,a.jsx)(ga,{onClose:o}))}},{icon:(0,a.jsx)(Aa,{size:14,strokeWidth:1.5}),label:"Share",handle:P,hidden:!F&&!q&&!B,dropdown:[{icon:(0,a.jsx)(Jt,{size:14,strokeWidth:1.5}),label:"Publish HTML to web",hidden:!F,handle:async()=>{n((0,a.jsx)(Pa,{onClose:o}))}},{icon:(0,a.jsx)(oa,{size:14,strokeWidth:1.5}),label:"Create WebAssembly link",hidden:!q,handle:async()=>{await ee(He({code:(await M()).contents})),z({title:"Copied",description:"Link copied to clipboard."})}},{icon:(0,a.jsx)(Re,{size:14,strokeWidth:1.5}),label:"Create molab notebook",hidden:!B,handle:async()=>{let c=He({code:(await M()).contents,baseUrl:`${C.molab}/new`});window.open(c,"_blank")}}]},{icon:(0,a.jsx)(Sa,{size:14,strokeWidth:1.5}),label:"Helper panel",redundant:!0,handle:P,dropdown:it.flatMap(c=>{let{type:p,Icon:E,hidden:pe,additionalKeywords:tt}=c;return pe?[]:{label:Se.startCase(p),rightElement:Ze(r===p),icon:(0,a.jsx)(E,{size:14,strokeWidth:1.5}),handle:()=>s(p),additionalKeywords:tt}})},{icon:(0,a.jsx)(Ye,{size:14,strokeWidth:1.5}),label:"Present as",handle:P,dropdown:[{icon:l.mode==="present"?(0,a.jsx)(la,{size:14,strokeWidth:1.5}):(0,a.jsx)(Ft,{size:14,strokeWidth:1.5}),label:"Toggle app view",hotkey:"global.hideCode",handle:()=>{O()}},...Fe.map((c,p)=>{let E=Je(c);return{divider:p===0,label:Qe(c),icon:(0,a.jsx)(E,{size:14,strokeWidth:1.5}),rightElement:(0,a.jsx)("div",{className:"w-8 flex justify-end",children:R===c&&(0,a.jsx)(Ee,{size:14})}),handle:()=>{de(c),l.mode==="edit"&&O()}}})]},{icon:(0,a.jsx)(Ma,{size:14,strokeWidth:1.5}),label:"Duplicate notebook",hidden:!t||X(),handle:j},{icon:(0,a.jsx)(qe,{size:14,strokeWidth:1.5}),label:"Copy code to clipboard",hidden:!t,handle:async()=>{await ee((await M()).contents),z({title:"Copied",description:"Code copied to clipboard."})}},{icon:(0,a.jsx)(Yt,{size:14,strokeWidth:1.5}),label:"Enable all cells",hidden:!se||i,handle:async()=>{let c=pt(We());await ie({configs:Me.fromEntries(c.map(ro))});for(let p of c)w({cellId:p,config:{disabled:!1}})}},{divider:!0,icon:(0,a.jsx)(Ve,{size:14,strokeWidth:1.5}),label:"Add setup cell",handle:()=>{f({})}},{icon:(0,a.jsx)(ut,{size:14,strokeWidth:1.5}),label:"Add database connection",handle:()=>{n((0,a.jsx)(Le,{onClose:o}))}},{icon:(0,a.jsx)(ea,{size:14,strokeWidth:1.5}),label:"Add remote storage",handle:()=>{n((0,a.jsx)(Le,{defaultTab:"storage",onClose:o}))}},{icon:(0,a.jsx)($e,{size:14,strokeWidth:1.5}),label:re,hidden:!le||i,handle:()=>{g()}},{icon:(0,a.jsx)(Na,{size:14,strokeWidth:1.5}),label:"Restart kernel",variant:"danger",handle:k,additionalKeywords:["reset","reload","restart"]},{icon:(0,a.jsx)(Wa,{size:14,strokeWidth:1.5}),label:"Re-run all cells",redundant:!0,hotkey:"global.runAll",handle:async()=>{x()}},{icon:(0,a.jsx)(st,{size:14,strokeWidth:1.5}),label:"Clear all outputs",redundant:!0,handle:()=>{u()}},{icon:(0,a.jsx)(Kt,{size:14,strokeWidth:1.5}),label:"Hide all markdown code",handle:d,redundant:!0},{icon:(0,a.jsx)(za,{size:14,strokeWidth:1.5}),label:"Collapse all sections",hotkey:"global.collapseAllSections",handle:b,redundant:!0},{icon:(0,a.jsx)(Ca,{size:14,strokeWidth:1.5}),label:"Expand all sections",hotkey:"global.expandAllSections",handle:y,redundant:!0},{divider:!0,icon:(0,a.jsx)(Be,{size:14,strokeWidth:1.5}),label:"Command palette",hotkey:"global.commandPalette",handle:()=>v(lo)},{icon:(0,a.jsx)(qt,{size:14,strokeWidth:1.5}),label:"Keyboard shortcuts",hotkey:"global.showHelp",handle:()=>W(so)},{icon:(0,a.jsx)(ia,{size:14,strokeWidth:1.5}),label:"User settings",handle:()=>I(io),redundant:!0,additionalKeywords:["preferences","options","configuration"]},{icon:(0,a.jsx)(Ut,{size:14,strokeWidth:1.5}),label:"Resources",handle:P,dropdown:[{icon:(0,a.jsx)(ct,{size:14,strokeWidth:1.5}),label:"Documentation",handle:no},{icon:(0,a.jsx)(Gt,{size:14,strokeWidth:1.5}),label:"GitHub",handle:oo},{icon:(0,a.jsx)(Qt,{size:14,strokeWidth:1.5}),label:"Discord Community",handle:ao},{icon:(0,a.jsx)(Zt,{size:14,strokeWidth:1.5}),label:"YouTube",handle:to},{icon:(0,a.jsx)(xt,{size:14,strokeWidth:1.5}),label:"Changelog",handle:eo}]},{divider:!0,icon:(0,a.jsx)(ta,{size:14,strokeWidth:1.5}),label:"Return home",hidden:!location.search.includes("file"),handle:Za},{icon:(0,a.jsx)(Re,{size:14,strokeWidth:1.5}),label:"New notebook",hidden:!location.search.includes("file"),handle:Xa}].filter(Qa).map(Ga),e[15]=f,e[16]=le,e[17]=u,e[18]=o,e[19]=b,e[20]=j,e[21]=S,e[22]=y,e[23]=ne,e[24]=t,e[25]=$,e[26]=he,e[27]=se,e[28]=d,e[29]=ce,e[30]=i,e[31]=n,e[32]=M,e[33]=k,e[34]=x,e[35]=ie,e[36]=R,e[37]=r,e[38]=v,e[39]=W,e[40]=de,e[41]=I,e[42]=F,e[43]=B,e[44]=q,e[45]=A,e[46]=s,e[47]=O,e[48]=g,e[49]=re,e[50]=w,e[51]=l.mode,e[52]=J):J=e[52],J}function Ga(e){return e.dropdown?{...e,dropdown:e.dropdown.filter(Ja)}:e}function Ja(e){return!e.hidden}function Qa(e){return!e.hidden}function Xa(){let e=ca();window.open(e,"_blank")}function Za(){let e=document.baseURI.split("?")[0];window.open(e,"_self")}function eo(){window.open(C.releasesPage,"_blank")}function to(){window.open(C.youtube,"_blank")}function ao(){window.open(C.discordLink,"_blank")}function oo(){window.open(C.githubPage,"_blank")}function no(){window.open(C.docsPage,"_blank")}function io(e){return!e}function so(e){return!e}function lo(e){return!e}function ro(e){return[e,{disabled:!1}]}async function co(){let e=document.getElementById("App");e&&await Lt({element:e,filename:document.title,prepare:Tt})}function ho(){return window.print()}function po(e){return e?(0,a.jsx)("span",{className:"ml-3 shrink-0 rounded-full border border-emerald-200 bg-emerald-50 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-emerald-700",children:"Recommended"}):null}function mo(e){return(0,a.jsx)("div",{className:"w-8 flex justify-end",children:e&&(0,a.jsx)(Ee,{size:14})})}function ae(){z({title:"Error",description:"Notebooks must be named to be exported.",variant:"danger"})}export{Ue as a,Be as c,Ge as i,qe as l,Xe as n,$e as o,Ra as r,Ve as s,Ua as t};
package/dist/index.html CHANGED
@@ -66,7 +66,7 @@
66
66
  <marimo-server-token data-token="{{ server_token }}" hidden></marimo-server-token>
67
67
  <!-- /TODO -->
68
68
  <title>{{ title }}</title>
69
- <script type="module" crossorigin src="./assets/index-fNBoXCyz.js"></script>
69
+ <script type="module" crossorigin src="./assets/index-CGCBsDqs.js"></script>
70
70
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-BPPi7vOr.js">
71
71
  <link rel="modulepreload" crossorigin href="./assets/chunk-LvLJmgfZ.js">
72
72
  <link rel="modulepreload" crossorigin href="./assets/react-Bj1aDYRI.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/frontend",
3
- "version": "0.23.10",
3
+ "version": "0.23.11-dev1",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -27,7 +27,7 @@ import { Label } from "@/components/ui/label";
27
27
  import { Switch } from "@/components/ui/switch";
28
28
  import { Tooltip } from "@/components/ui/tooltip";
29
29
  import { toast } from "@/components/ui/use-toast";
30
- import { stagedAICellsAtom } from "@/core/ai/staged-cells";
30
+ import { stripWrappingBackticks } from "@/core/ai/strip-wrapping-backticks";
31
31
  import { type AiCompletionCell, includeOtherCellsAtom } from "@/core/ai/state";
32
32
  import type { CellId } from "@/core/cells/ids";
33
33
  import { getCodes } from "@/core/codemirror/copilot/getCodes";
@@ -45,6 +45,7 @@ import {
45
45
  RejectCompletionButton,
46
46
  } from "./completion-handlers";
47
47
  import { addContextCompletion, getAICompletionBody } from "./completion-utils";
48
+ import { stagedAICellsAtom } from "@/core/ai/staged-cells";
48
49
 
49
50
  const Original = CodeMirrorMerge.Original;
50
51
  const Modified = CodeMirrorMerge.Modified;
@@ -123,7 +124,6 @@ export const AiCompletionEditor: React.FC<Props> = ({
123
124
  api: runtimeManager.getAiURL("completion").toString(),
124
125
  headers: runtimeManager.headers(),
125
126
  initialInput: initialPrompt,
126
- streamProtocol: "text",
127
127
  // Throttle the messages and data updates to 100ms
128
128
  experimental_throttle: 100,
129
129
  body: {
@@ -143,13 +143,14 @@ export const AiCompletionEditor: React.FC<Props> = ({
143
143
  });
144
144
  },
145
145
  onFinish: (_prompt, completion) => {
146
- // Remove trailing new lines
147
- setCompletion(completion.trimEnd());
146
+ setCompletion(stripWrappingBackticks(completion).trimEnd());
148
147
  },
149
148
  });
150
149
 
151
150
  const inputRef = React.useRef<ReactCodeMirrorRef>(null);
152
- const completion = untrimmedCompletion.trimEnd();
151
+ const completion = stripWrappingBackticks(untrimmedCompletion, {
152
+ streaming: isLoading,
153
+ }).trimEnd();
153
154
 
154
155
  const initialSubmit = useCallback(() => {
155
156
  if (triggerImmediately && !isLoading && initialPrompt) {
@@ -0,0 +1,133 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { describe, expect, it } from "vitest";
4
+ import { stripWrappingBackticks } from "../strip-wrapping-backticks";
5
+
6
+ // Cases aligned with `without_wrapping_backticks` on a complete string (single chunk).
7
+ const CASES: [string[], string][] = [
8
+ [["Hello", " world", "!"], "Hello world!"],
9
+ [["```", "print('hello')", "print('world')"], "print('hello')print('world')"],
10
+ [
11
+ ["print('hello')", "print('world')", "```"],
12
+ "print('hello')print('world')```",
13
+ ],
14
+ [["```", "print('hello')", "```"], "print('hello')"],
15
+ [["Hello", " ``` ", "world"], "Hello ``` world"],
16
+ [["``", "`print('hello')", "``", "`"], "print('hello')"],
17
+ [["``", "`", "\n", "print('hello')", "\n", "``", "`"], "print('hello')"],
18
+ [
19
+ ["```\n", "print('hello')", "print('world')", "\n```"],
20
+ "print('hello')print('world')",
21
+ ],
22
+ [
23
+ ["```\nprint('hello')\n", "print('world')\n```"],
24
+ "print('hello')\nprint('world')",
25
+ ],
26
+ [
27
+ ["```\n", "def test():\n ", "return True\n```"],
28
+ "def test():\n return True",
29
+ ],
30
+ [[], ""],
31
+ [["```idk```"], "idk"],
32
+ [["Hello world"], "Hello world"],
33
+ [
34
+ ["```python\n", "def hello():\n ", "print('world')\n```"],
35
+ "def hello():\n print('world')",
36
+ ],
37
+ [
38
+ ["```python", "\ndef hello():\n ", "print('world')\n```"],
39
+ "def hello():\n print('world')",
40
+ ],
41
+ [
42
+ ["```sql", "SELECT * FROM table", " WHERE id = 1", "```"],
43
+ "SELECT * FROM table WHERE id = 1",
44
+ ],
45
+ [
46
+ ["```sql\n", "SELECT * FROM table\n", "WHERE id = 1\n```"],
47
+ "SELECT * FROM table\nWHERE id = 1",
48
+ ],
49
+ [["```", "print('hello')", "``` "], "print('hello') "],
50
+ [["```python\n", "print('hello')", "\n``` "], "print('hello') "],
51
+ [["```", "code", "```\t\n"], "code\t\n"],
52
+ [[" ```", "code", "```"], "code"],
53
+ [[" ```python\n", "code", "```"], "code"],
54
+ [["\t```", "code", "```"], "code"],
55
+ [["\n", "\n", "```\n", "code", "\n```\n"], "code\n"],
56
+ [["\n", "\n", "```python\n", "code", "\n```\n"], "code\n"],
57
+ [["\n``", "`python\n", "code", "\n```\n"], "code\n"],
58
+ [["\n`", "`", "`python\n", "code", "\n```\n"], "code\n"],
59
+ [["```python ", "code", "```"], " code"],
60
+ [["```python\t", "code", "```"], "\tcode"],
61
+ [["```\n", "```"], ""],
62
+ [["```python\n", "```"], ""],
63
+ [["```\n", "code"], "code"],
64
+ [["```python\n", "code"], "code"],
65
+ [["code", "\n```"], "code\n```"],
66
+ [
67
+ ["```\n", "x = 1\n", "```\n", "```\n", "y = 2\n", "```"],
68
+ "x = 1\n```\n```\ny = 2",
69
+ ],
70
+ [["```python\n", "s = 'use `backticks`'\n", "```"], "s = 'use `backticks`'"],
71
+ [["``", "`\n", "code\n", "``", "`"], "code"],
72
+ [["```", "python\n", "code\n", "```"], "code"],
73
+ [["```", "code", "```"], "code"],
74
+ [["prefix ", "```\n", "code\n", "```"], "prefix ```\ncode\n```"],
75
+ [["```\n", "code\n", "```", " suffix"], "code\n``` suffix"],
76
+ [["```\n\n", "code\n\n", "```"], "\ncode\n"],
77
+ [["```\n", " code \n", "```"], " code "],
78
+ [["```\n", "\tcode\t\n", "```"], "\tcode\t"],
79
+ [
80
+ ["```\n", "x\n", "```\n", "```python\n", "y\n", "```"],
81
+ "x\n```\n```python\ny",
82
+ ],
83
+ [["```javascript\n", "console.log()\n", "```"], "javascript\nconsole.log()"],
84
+ [["```markdown\n", "# Title\n", "```"], "# Title"],
85
+ ];
86
+
87
+ describe("stripWrappingBackticks", () => {
88
+ it.each(CASES)("strips fences for %j", (chunks, expected) => {
89
+ expect(stripWrappingBackticks(chunks.join(""))).toBe(expected);
90
+ });
91
+ });
92
+
93
+ // In streaming mode, the opening fence is stripped as soon as it is
94
+ // unambiguous, but the closing fence is left untouched (it may not have
95
+ // arrived yet, or a trailing "```" may be content).
96
+ const STREAMING_CASES: [string, string][] = [
97
+ // No fence: passthrough.
98
+ ["import pandas as pd", "import pandas as pd"],
99
+ // Plain opening fence stripped once the first line is terminated.
100
+ ["```\n", ""],
101
+ ["```\ncode", "code"],
102
+ ["```\ncode\nmore", "code\nmore"],
103
+ // Opening fence stripped, closing fence intentionally kept while streaming.
104
+ ["```\ncode\n```", "code\n```"],
105
+ ["```python\ncode\n```", "code\n```"],
106
+ // Language fences stripped as soon as the full identifier is present.
107
+ ["```python", ""],
108
+ ["```python\n", ""],
109
+ ["```python\ncode", "code"],
110
+ ["```sql\nSELECT 1", "SELECT 1"],
111
+ ["```markdown\n# Title", "# Title"],
112
+ // Leading whitespace before the fence.
113
+ [" ```python\ncode", "code"],
114
+ // Partial language identifiers are left intact until they resolve.
115
+ ["```", "```"],
116
+ ["```p", "```p"],
117
+ ["```py", "```py"],
118
+ ["```pyth", "```pyth"],
119
+ ["```s", "```s"],
120
+ ["```mark", "```mark"],
121
+ // First-line content that is not a known language prefix is stripped as a
122
+ // plain fence even before a newline arrives.
123
+ ["```x", "x"],
124
+ ["```x = 1", "x = 1"],
125
+ // Unsupported language identifiers are kept as content (matches final mode).
126
+ ["```json\ncode", "json\ncode"],
127
+ ];
128
+
129
+ describe("stripWrappingBackticks (streaming)", () => {
130
+ it.each(STREAMING_CASES)("strips opening fence for %j", (text, expected) => {
131
+ expect(stripWrappingBackticks(text, { streaming: true })).toBe(expected);
132
+ });
133
+ });
@@ -0,0 +1,48 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { consumeStream, parseJsonEventStream, uiMessageChunkSchema } from "ai";
4
+ import { stripWrappingBackticks } from "./strip-wrapping-backticks";
5
+
6
+ /**
7
+ * Read an AI SDK UI message stream response and return the assistant text.
8
+ */
9
+ export async function streamCompletionText(
10
+ response: Response,
11
+ ): Promise<string> {
12
+ if (!response.ok) {
13
+ throw new Error(await response.text());
14
+ }
15
+
16
+ if (!response.body) {
17
+ throw new Error("Failed to get response body");
18
+ }
19
+
20
+ let result = "";
21
+
22
+ await consumeStream({
23
+ stream: parseJsonEventStream({
24
+ stream: response.body,
25
+ schema: uiMessageChunkSchema,
26
+ }).pipeThrough(
27
+ new TransformStream({
28
+ transform(part) {
29
+ if (!part.success) {
30
+ throw part.error;
31
+ }
32
+
33
+ const streamPart = part.value;
34
+ if (streamPart.type === "text-delta") {
35
+ result += streamPart.delta;
36
+ } else if (streamPart.type === "error") {
37
+ throw new Error(streamPart.errorText);
38
+ }
39
+ },
40
+ }),
41
+ ),
42
+ onError: (error) => {
43
+ throw error;
44
+ },
45
+ });
46
+
47
+ return stripWrappingBackticks(result);
48
+ }
@@ -0,0 +1,88 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ const LANGS = ["python", "sql", "markdown"] as const;
4
+
5
+ interface StripOptions {
6
+ /**
7
+ * When true, the text is treated as a partial stream:
8
+ * - the opening fence is only stripped once we can be sure of its language
9
+ * identifier (e.g. "```py" is left untouched since it may still become
10
+ * "```python"), and
11
+ * - the closing fence is left in place, since it may not have arrived yet (or
12
+ * a trailing "```" may be part of the content).
13
+ */
14
+ streaming?: boolean;
15
+ }
16
+
17
+ /**
18
+ * Removes wrapping markdown code fences from a completion string.
19
+ */
20
+ export function stripWrappingBackticks(
21
+ text: string,
22
+ opts: StripOptions = {},
23
+ ): string {
24
+ const { streaming = false } = opts;
25
+ const leadingWhitespace = text.match(/^\s*/)?.[0] ?? "";
26
+ const rest = text.slice(leadingWhitespace.length);
27
+
28
+ let body: string | null = null;
29
+ let strippedOpening = false;
30
+
31
+ for (const lang of LANGS) {
32
+ if (rest.startsWith(`\`\`\`${lang}`)) {
33
+ strippedOpening = true;
34
+ body = rest.slice(3 + lang.length);
35
+ if (body.startsWith("\n")) {
36
+ body = body.slice(1);
37
+ }
38
+ break;
39
+ }
40
+ }
41
+
42
+ if (!strippedOpening && rest.startsWith("```")) {
43
+ const afterFence = rest.slice(3);
44
+ if (streaming && isPartialLanguageFence(afterFence)) {
45
+ return text;
46
+ }
47
+ strippedOpening = true;
48
+ body = afterFence;
49
+ if (body.startsWith("\n")) {
50
+ body = body.slice(1);
51
+ }
52
+ }
53
+
54
+ if (!strippedOpening || body === null) {
55
+ return text;
56
+ }
57
+
58
+ // While streaming, the closing fence may not have arrived yet, so leave the
59
+ // body as-is once the opening fence is removed.
60
+ if (streaming) {
61
+ return body;
62
+ }
63
+
64
+ const strippedEnd = body.trimEnd();
65
+ const trailingSpace = body.slice(strippedEnd.length);
66
+
67
+ if (strippedEnd.endsWith("\n```")) {
68
+ return strippedEnd.slice(0, -4) + trailingSpace;
69
+ }
70
+ if (strippedEnd.endsWith("```")) {
71
+ return strippedEnd.slice(0, -3) + trailingSpace;
72
+ }
73
+
74
+ return body;
75
+ }
76
+
77
+ /**
78
+ * Returns true if the text after an opening "```" has no terminating newline
79
+ * yet and could still become a known language identifier.
80
+ */
81
+ function isPartialLanguageFence(afterFence: string): boolean {
82
+ // Once the first line is terminated, we already know it is not a known
83
+ // language fence (those are handled above), so treat it as a plain fence.
84
+ if (afterFence.includes("\n")) {
85
+ return false;
86
+ }
87
+ return LANGS.some((lang) => lang.startsWith(afterFence));
88
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { waitForConnectionOpen } from "@/core/network/connection";
4
4
  import type { AiCompletionRequest } from "@/core/network/types";
5
+ import { streamCompletionText } from "@/core/ai/stream-completion-text";
5
6
  import { getRuntimeManager } from "@/core/runtime/config";
6
7
  import type { LanguageAdapterType } from "../language/types";
7
8
 
@@ -47,20 +48,7 @@ ${opts.codeAfter}
47
48
 
48
49
  const firstLineIndent = opts.selection.match(/^\s*/)?.[0] || "";
49
50
 
50
- const reader = response.body?.getReader();
51
- if (!reader) {
52
- throw new Error("Failed to get response reader");
53
- }
54
-
55
- let result = "";
56
- // oxlint-disable-next-line no-constant-condition
57
- while (true) {
58
- const { done, value } = await reader.read();
59
- if (done) {
60
- break;
61
- }
62
- result += new TextDecoder().decode(value);
63
- }
51
+ let result = await streamCompletionText(response);
64
52
 
65
53
  // Add back the indent if it was stripped, which can happen with
66
54
  // LLM responses