@marimo-team/frontend 0.25.3-dev3 → 0.25.3-dev5

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 (113) hide show
  1. package/dist/assets/{CellStatus-BP2mavAq.js → CellStatus-nZpuDkm7.js} +1 -1
  2. package/dist/assets/{ErrorBoundary-Gl5nCA8C.js → ErrorBoundary-B4n9EnHB.js} +2 -2
  3. package/dist/assets/JsonOutput-d-k8v_17.js +11 -0
  4. package/dist/assets/MarimoErrorOutput-CLYUxiKW.js +10 -0
  5. package/dist/assets/{RenderHTML-BbOqmHy3.js → RenderHTML-9bMgbYmo.js} +1 -1
  6. package/dist/assets/{RunButton-CK3LhnP5.js → RunButton-CFQUNN5c.js} +1 -1
  7. package/dist/assets/{add-cell-with-ai-8UBC0xwR.js → add-cell-with-ai-C_SruRWS.js} +9 -9
  8. package/dist/assets/{add-connection-dialog-DXQnd6eB.js → add-connection-dialog-CoE_PhuD.js} +1 -1
  9. package/dist/assets/{agent-panel-D7kMZLG-.js → agent-panel-0b3k4QzJ.js} +5 -5
  10. package/dist/assets/ai-model-dropdown-C6GHHEdR.js +5 -0
  11. package/dist/assets/{app-config-button-BKEG4x9u.js → app-config-button-iXdCWvfC.js} +1 -1
  12. package/dist/assets/{blob-D5nfNHOo.js → blob-iOBwGaP9.js} +1 -1
  13. package/dist/assets/{cell-editor-ADVfycpN.js → cell-editor-CR-tZNnc.js} +9 -9
  14. package/dist/assets/{cell-link-LSth_8hT.js → cell-link-1CynTVGQ.js} +1 -1
  15. package/dist/assets/{cells-BRkCaSsh.js → cells-rA_jsZCj.js} +1 -1
  16. package/dist/assets/{chat-display-Dnagy4Nv.js → chat-display-luF7psRA.js} +1 -1
  17. package/dist/assets/{chat-panel-DQ6HkWEF.js → chat-panel-DDDTnLvB.js} +2 -2
  18. package/dist/assets/{chat-ui-Df8Vcj6n.js → chat-ui-nV_m4Btr.js} +1 -1
  19. package/dist/assets/{column-preview-Cm2D6vyX.js → column-preview-uosAAL4X.js} +1 -1
  20. package/dist/assets/{command-palette-DTSQ7gOC.js → command-palette-BZ13RKDJ.js} +1 -1
  21. package/dist/assets/{common-Cu6CDbuw.js → common-lisZ0l6a.js} +1 -1
  22. package/dist/assets/{components-CGw16R_N.js → components-S7ZwOrvO.js} +1 -1
  23. package/dist/assets/config-FzDtjF1-.js +1 -0
  24. package/dist/assets/{datasource-Cq6x_5ML.js → datasource-V0-52XOh.js} +1 -1
  25. package/dist/assets/{dates-BbFQ2oE4.js → dates-CfmdTL6B.js} +1 -1
  26. package/dist/assets/{dependency-graph-panel--Kgtktcw.js → dependency-graph-panel-B0uP-_id.js} +1 -1
  27. package/dist/assets/{documentation-panel-BHmbeznw.js → documentation-panel-DVl_ebWy.js} +1 -1
  28. package/dist/assets/{download-DCJXy66H.js → download-Bx55LMki.js} +1 -1
  29. package/dist/assets/{edit-page-ChcSgpke.js → edit-page-CGyjT-CQ.js} +6 -6
  30. package/dist/assets/{error-entries-Dk3VZ-OK.js → error-entries-DOWpdGvI.js} +1 -1
  31. package/dist/assets/{error-panel-BPRYmC5J.js → error-panel-C-uxLOHF.js} +1 -1
  32. package/dist/assets/{feedback-button-Bik2-e33.js → feedback-button-B99ThNJW.js} +1 -1
  33. package/dist/assets/feedback-button-DlqZkJwz.js +1 -0
  34. package/dist/assets/{file-explorer-panel-BEEK5lcl.js → file-explorer-panel-D3CphidS.js} +1 -1
  35. package/dist/assets/{file-name-input-Cdc-TVqO.js → file-name-input-ChnBsDE_.js} +1 -1
  36. package/dist/assets/{floating-outline-XD9FAV-f.js → floating-outline-MYqQW4Vp.js} +1 -1
  37. package/dist/assets/{gallery-page-Dm6mGwBi.js → gallery-page-DSL0J4md.js} +1 -1
  38. package/dist/assets/{glide-data-editor-J9CAb70d.js → glide-data-editor-B1MWlKeM.js} +1 -1
  39. package/dist/assets/{home-page-DMHnsRxm.js → home-page-B1M3X9Yf.js} +1 -1
  40. package/dist/assets/{hooks-93IwHd2u.js → hooks-Bj0C0zrZ.js} +1 -1
  41. package/dist/assets/index-CXIE-QEG.css +2 -0
  42. package/dist/assets/{index-s-M1OXjs.js → index-DnIgeCyQ.js} +7 -7
  43. package/dist/assets/{layout-DmcNEu3P.js → layout-DBuMeWh0.js} +3 -3
  44. package/dist/assets/{logs-panel-ABM16htT.js → logs-panel-y0XnfulJ.js} +1 -1
  45. package/dist/assets/{markdown-renderer-BG3sp2rs.js → markdown-renderer-Q5AhbRU3.js} +1 -1
  46. package/dist/assets/{name-cell-input-BgEBmqyL.js → name-cell-input-BNOnF6-0.js} +1 -1
  47. package/dist/assets/{outline-panel-DCXQ3_F6.js → outline-panel-Be7stWwv.js} +1 -1
  48. package/dist/assets/{packages-panel-BMGOmZkR.js → packages-panel-9Qs1npCZ.js} +1 -1
  49. package/dist/assets/{panel-accordion-state-C1sdPp0m.js → panel-accordion-state-GeMEdCPw.js} +1 -1
  50. package/dist/assets/panels-B9x935By.js +4 -0
  51. package/dist/assets/{process-output-D0KGq04R.js → process-output-DNFKMODr.js} +1 -1
  52. package/dist/assets/{readonly-code-display-Do50PHI8.js → readonly-code-display-YULOXf4h.js} +1 -1
  53. package/dist/assets/{readonly-python-code-DCSMIsTX.js → readonly-python-code-CadgXgRu.js} +1 -1
  54. package/dist/assets/{reveal-component-ltaepAqw.js → reveal-component-B9FLjTg_.js} +1 -1
  55. package/dist/assets/{run-page-DF3c5cDk.js → run-page-CjdGaic3.js} +1 -1
  56. package/dist/assets/{runtime-details-state-CSPobEdR.js → runtime-details-state-DuChzsA6.js} +1 -1
  57. package/dist/assets/{scratchpad-panel-Dwd6W5PE.js → scratchpad-panel-DtB0A8xj.js} +1 -1
  58. package/dist/assets/session-panel-B6tA28BD.js +1 -0
  59. package/dist/assets/{snippets-panel-Bh1oTw4m.js → snippets-panel-CQ1dn3lA.js} +1 -1
  60. package/dist/assets/state-BUsmcyaT.js +3 -0
  61. package/dist/assets/{state-XsPO8hNi.js → state-Bfh_2SLl.js} +1 -1
  62. package/dist/assets/{tracing-Di6pUmX8.js → tracing-BARlJ_Dk.js} +1 -1
  63. package/dist/assets/{tracing-panel-PeRXHD8_.js → tracing-panel-dgnr2fIN.js} +2 -2
  64. package/dist/assets/{tree-actions-GM5E_bUs.js → tree-actions-DAd80MbP.js} +1 -1
  65. package/dist/assets/{useAddCell-GR7eEQrT.js → useAddCell-DGstJK0S.js} +1 -1
  66. package/dist/assets/{useCellActionButton-B-9eG5z_.js → useCellActionButton-DY9RlJTb.js} +1 -1
  67. package/dist/assets/{useDeleteCell-2_bMClHd.js → useDeleteCell-DFBGlSQk.js} +1 -1
  68. package/dist/assets/{useDependencyPanelTab-k3C3M18S.js → useDependencyPanelTab-DydxsE5d.js} +1 -1
  69. package/dist/assets/{useNotebookActions-NHN6A-cN.js → useNotebookActions-CupIPSlg.js} +1 -1
  70. package/dist/assets/{useRunCells-B2vUhREg.js → useRunCells-BFjFX3hz.js} +1 -1
  71. package/dist/assets/{useSplitCell-DEb03htp.js → useSplitCell-Tqv5pPtL.js} +1 -1
  72. package/dist/index.html +24 -25
  73. package/package.json +1 -1
  74. package/src/components/data-table/__tests__/context-menu.test.ts +176 -0
  75. package/src/components/data-table/__tests__/date-filter-inputs.test.tsx +24 -1
  76. package/src/components/data-table/context-menu.tsx +125 -26
  77. package/src/components/data-table/date-filter-inputs.tsx +15 -42
  78. package/src/components/data-table/utils.ts +18 -0
  79. package/src/components/editor/Output.tsx +5 -2
  80. package/src/components/editor/chrome/panels/error-panel.tsx +1 -0
  81. package/src/components/editor/chrome/wrapper/__tests__/attachment-status.test.tsx +167 -0
  82. package/src/components/editor/chrome/wrapper/footer-item.tsx +32 -24
  83. package/src/components/editor/chrome/wrapper/footer-items/attachment-status.tsx +82 -0
  84. package/src/components/editor/chrome/wrapper/footer.tsx +2 -0
  85. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +434 -0
  86. package/src/components/editor/errors/send-error-report-button.tsx +66 -0
  87. package/src/components/editor/output/MarimoErrorOutput.tsx +21 -5
  88. package/src/components/editor/output/MarimoTracebackOutput.tsx +9 -0
  89. package/src/components/editor/output/__tests__/ansi-reduce.test.ts +18 -0
  90. package/src/components/editor/output/ansi-reduce.ts +6 -0
  91. package/src/core/attachments/state.ts +21 -0
  92. package/src/core/cells/__tests__/cells.test.ts +52 -0
  93. package/src/core/cells/__tests__/error-report.test.ts +89 -0
  94. package/src/core/cells/__tests__/session.test.ts +34 -0
  95. package/src/core/cells/error-report.ts +55 -0
  96. package/src/core/cells/session.ts +9 -0
  97. package/src/core/islands/__tests__/bootstrap.test.ts +26 -0
  98. package/src/core/islands/bootstrap.ts +1 -0
  99. package/src/core/websocket/__tests__/useMarimoKernelConnection.hook.test.tsx +193 -0
  100. package/src/core/websocket/useMarimoKernelConnection.tsx +9 -0
  101. package/src/utils/__tests__/dates.test.ts +116 -0
  102. package/src/utils/dates.ts +94 -0
  103. package/dist/assets/JsonOutput-D6HIIsCb.js +0 -11
  104. package/dist/assets/MarimoErrorOutput-D60XkCny.js +0 -6
  105. package/dist/assets/ai-model-dropdown-B0z6-zhp.js +0 -5
  106. package/dist/assets/api-BeC_VSGv.js +0 -1
  107. package/dist/assets/config-BOKzA3tF.js +0 -1
  108. package/dist/assets/feedback-button-B2gKC5cn.js +0 -1
  109. package/dist/assets/index-Bcdzex-3.css +0 -2
  110. package/dist/assets/pair-CaQyK6En.js +0 -1
  111. package/dist/assets/panels-CxVG8-v2.js +0 -4
  112. package/dist/assets/session-panel-VdDhEBa-.js +0 -1
  113. package/dist/assets/state-_Qai_QyX.js +0 -3
@@ -0,0 +1,10 @@
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,f as r,l as i,r as a,t as o,u as s}from"./useEvent-Dfcbgjhg.js";import{t as c}from"./react-DVplv7_D.js";import{Ao as l,D as u,Kr as d,Oa as f,Q as p,Qr as m,Z as h,Za as g,ai as _,b as v,ka as y,no as b,qa as x,ut as S}from"./cells-rA_jsZCj.js";import{t as C}from"./compiler-runtime-BrajqUja.js";import{i as w,r as T,x as E}from"./config-VPSq73n8.js";import{g as D,p as O}from"./useEventListener-D9cftcHj.js";import{t as k}from"./invariant-Ci2dTZ72.js";import{a as A,i as j,o as M,p as ee,r as te,s as N,t as P}from"./config-FzDtjF1-.js";import{r as F,v as ne}from"./session-DqoWmb7X.js";import{O as I,v as re}from"./config-DX8Y2WbJ.js";import{t as ie}from"./cn-ldLVeaqm.js";import{t as ae}from"./jsx-runtime-B74pBk57.js";import{a as oe,p as se,r as ce,t as le}from"./dropdown-menu-C1rnl-0o.js";import{t as L}from"./tooltip-C9TuY18o.js";import{r as ue,t as R}from"./button-COI-NGrx.js";import{t as z}from"./createLucideIcon-DfJ2oMlA.js";import{t as de}from"./check-BQNapYaf.js";import{a as fe}from"./useNumberFormatter-D7O_26UI.js";import{t as pe}from"./chevron-right-eAtVhbNZ.js";import{t as me}from"./hat-glasses-C8RhSVii.js";import{p as B}from"./write-secret-modal-DzKAInL2.js";import{t as he}from"./package-GSoSTiIK.js";import{l as ge,r as _e}from"./datasource-V0-52XOh.js";import{t as V}from"./use-toast-Wu434mLr.js";import{n as ve}from"./strings-B2vv-ENv.js";import{a as ye}from"./dist-DusFODSa.js";import{t as be}from"./uuid-k9DpjH68.js";import{t as xe}from"./RenderHTML-9bMgbYmo.js";import{t as Se,u as Ce}from"./useInstallPackage-iX1eufdl.js";import{r as we}from"./errors-DCrsa1nH.js";import{t as Te}from"./kbd-pdKBv96t.js";import{t as Ee}from"./error-entries-DOWpdGvI.js";import{r as De,t as Oe}from"./alert-DTaqCu_d.js";import{n as ke,o as Ae}from"./state-Bfh_2SLl.js";import{n as H}from"./cell-link-1CynTVGQ.js";var je=z(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),U=z(`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`}]]),Me=z(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),W=e(c(),1),G=C();function Ne(e,t){let n,r;return`errors`in t?(n=t.errors.map(Ee).join(`
2
+ `),r=t.errors.flatMap(e=>`traceback`in e&&e.traceback?[h(S(e.traceback))]:[]).join(`
3
+
4
+ `)):(r=h(S(t.traceback)),n=r.split(`
5
+ `).findLast(e=>e.length>0)??``),{type:`cell-output`,cell_id:e,...t.code===void 0?{}:{code:t.code},output:{type:`error`,message:n,...r?{traceback:r}:{}}}}var Pe=String.raw`_cell_([^\W_][\w-]*?)(_\w*)`,Fe=String.raw`(?<!_)${Pe}`;RegExp(`^${Pe}$`);var Ie=new RegExp(Fe),K=new RegExp(Fe,`g`);function Le(e){let t=[];K.lastIndex=0;let n=0,r=K.exec(e);for(;r!==null;)r.index>n&&t.push(e.slice(n,r.index)),t.push({cellId:r[1],name:r[2]}),n=r.index+r[0].length,r=K.exec(e);return n<e.length&&t.push(e.slice(n)),t}function Re(e){return Ie.test(e)}function ze(e){let t=null,n=e.cursor();do n.name===`ExpressionStatement`&&(t=n.node);while(n.next());return t}function Be(e){let t=e.split(`
6
+ `),n=` `,r=ze(ye.parse(e));if(!r)return[`def _():`,...q(t,n),`${n}return`,``,``,`_()`].join(`
7
+ `);let i=e.slice(0,r.from).trim(),a=e.slice(r.from).trim(),o=i.split(`
8
+ `),s=a.split(`
9
+ `);return[`def _():`,...q(o,n),`${n}return ${s[0]}`,...q(s.slice(1),n),``,``,`_()`].join(`
10
+ `)}function q(e,t){if(e.length===1&&e[0]===``)return[];let n=[];for(let r of e)r===``?n.push(``):n.push(t+r);return n}function Ve(e,t){if(e.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 e=>{k(e.editor,`Editor is null`);let t=Be(e.editor.state.doc.toString());e.editor.dispatch({changes:{from:0,to:e.editor.state.doc.length,insert:t}})}}];if(e.type===`exception`&&e.exception_type===`NameError`){let t=e.msg.match(/name '(.+)' is not defined/)?.[1];if(!t||!(t in Ue))return[];let n=He(t);return[{title:`Fix: Add '${n}'`,description:`Add a new cell for the missing import`,fixType:`manual`,onFix:async e=>{e.addCodeBelow(n)}}]}return e.type===`sql-error`&&t.aiEnabled?[{title:`Fix with AI`,description:`Fix the SQL statement`,fixType:`ai`,onFix:async t=>{let n=_e(t.cellId,a),r=`Fix the SQL statement: ${e.msg}.`;n&&(r+=`\nDatabase schema: ${n}`),t.aiFix?.setAiCompletionCell({cellId:t.cellId,initialPrompt:r,triggerImmediately:t.aiFix.triggerFix})}}]:[]}function He(e){let t=Ue[e];return t===e?`import ${t}`:`import ${t} as ${e}`}var Ue={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`},J=I(`marimo:acp:sessions:v1`,{sessions:[],activeTabId:null},m),We=r(e=>{let t=e(J);return t.activeTabId&&t.sessions.find(e=>e.tabId===t.activeTabId)||null},(e,t,n)=>{t(J,e=>({...e,activeTabId:n}))});function Ge(){return`tab_${be()}`}function Ke(e,t=20){return e.length<=t?e:`${e.slice(0,t-3)}...`}function qe(e,t){let n=tt(t.agentId),r=Date.now(),i=t.firstMessage?Ke(t.firstMessage.trim()):`New ${t.agentId} session`,a=Ge();if(n===`single`){let n=e.sessions.filter(e=>e.agentId===t.agentId),a=e.sessions.filter(e=>e.agentId!==t.agentId);if(n.length>0){let o=n[0],s={agentId:t.agentId,title:i,createdAt:r,lastUsedAt:r,tabId:o.tabId,externalAgentSessionId:null,selectedModel:t.model??o.selectedModel??null};return{...e,sessions:[...a.slice(0,0),s],activeTabId:s.tabId}}}return{...e,sessions:[...e.sessions.slice(0,0),{agentId:t.agentId,tabId:a,title:i,createdAt:r,lastUsedAt:r,externalAgentSessionId:null,selectedModel:t.model??null}],activeTabId:a}}function Je(e,t){let n=e.sessions.filter(e=>e.tabId!==t);return{sessions:n,activeTabId:e.activeTabId===t?n.length>0?n[n.length-1].tabId:null:e.activeTabId}}function Ye(e,t){let n=e.activeTabId;return n?{...e,sessions:e.sessions.map(e=>e.tabId===n?{...e,title:Ke(t)}:e)}:e}function Xe(e,t){return{...e,sessions:e.sessions.map(e=>e.tabId===t?{...e,lastUsedAt:Date.now()}:e)}}function Ze(e,t){let n=e.activeTabId;return n?{...e,sessions:e.sessions.map(e=>e.tabId===n?{...e,externalAgentSessionId:t,lastUsedAt:Date.now()}:e)}:e}function Qe(){return[`claude`,`gemini`,`codex`,`opencode`,`cursor`]}function $e(e){return ve(e)}function et(e){let t=Y[e].port,n=window.location.hostname;return`${window.location.protocol===`https:`?`wss:`:`ws:`}//${n}:${t}/message`}var Y={claude:{port:3017,command:`npx @agentclientprotocol/claude-agent-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 tt(e){return Y[e].sessionSupport}function nt(e){let t=Y[e].port,n=Y[e].command;return`npx stdio-to-ws "${O()?`cmd /c ${n}`:n}" --port ${t}`}var rt=I(`marimo:chrome:ai-panel-tab`,`chat`,m);function it(){let e=(0,G.c)(3),[n,r]=t(rt),i;return e[0]!==n||e[1]!==r?(i={aiPanelTab:n,setAiPanelTab:r},e[0]=n,e[1]=r,e[2]=i):i=e[2],i}var at=`code_mode`;function ot(e,t){return e||(_(`external_agents`)?t:`chat`)}function st(){let e=(0,G.c)(6),{openApplication:t}=d(),{setAiPanelTab:r}=it(),{saveModeChange:i}=P(),a=s(Ae),c=n(),l;return e[0]!==t||e[1]!==i||e[2]!==r||e[3]!==a||e[4]!==c?(l=async e=>{let n=ot(e.panel,c.get(rt)),o=c.get(w),s=_(`external_agents`)&&c.get(J).sessions.length>0;if(!(n===`agents`?s:o)){V({title:n===`agents`?`No agent session`:`AI not configured`,description:n===`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}e.panel&&r(e.panel),n===`chat`&&await i(at).catch(ct),a({prompt:e.prompt,submit:e.submit??!1}),t(`ai`)},e[0]=t,e[1]=i,e[2]=r,e[3]=a,e[4]=c,e[5]=l):l=e[5],o(l)}function ct(){return D.error(`Failed to save mode change`)}var lt=I(`marimo:ai-autofix-mode`,`autofix`,m);function ut(){let e=(0,G.c)(3),[n,r]=t(lt),i;return e[0]!==n||e[1]!==r?(i={fixMode:n,setFixMode:r},e[0]=n,e[1]=r,e[2]=i):i=e[2],i}var X=ae();function dt(e,t){if(e!=null)return`@error://${e}\n\nPlease fix this error.`;let n=t?.trim();return n?`My code gives the following error. Please fix it:\n\n${n}`:`Please fix this error.`}var Z=e=>{let t=(0,G.c)(25),{errors:r,cellId:a,className:o}=e,c=n(),{createNewCell:l}=u(),d=i(T),f;if(t[0]!==d||t[1]!==r){let e;t[3]===d?e=t[4]:(e=e=>Ve(e,{aiEnabled:d}),t[3]=d,t[4]=e),f=r.flatMap(e),t[0]=d,t[1]=r,t[2]=f}else f=t[2];let p=f,m=s(ke),h=st();if(p.length===0)return null;let g=p[0],_;t[5]!==a||t[6]!==l||t[7]!==g||t[8]!==m||t[9]!==c?(_=e=>{let t=c.get(v).cellHandles[a].current?.editorView;g.onFix({addCodeBelow:e=>{l({cellId:a,autoFocus:!1,before:!1,code:e})},editor:t,cellId:a,aiFix:{setAiCompletionCell:m,triggerFix:e}}),t?.focus()},t[5]=a,t[6]=l,t[7]=g,t[8]=m,t[9]=c,t[10]=_):_=t[10];let y=_,b;t[11]!==a||t[12]!==h?(b=()=>{h({prompt:dt(a)})},t[11]=a,t[12]=h,t[13]=b):b=t[13];let x=b,S;t[14]===o?S=t[15]:(S=ie(`my-2`,o),t[14]=o,t[15]=S);let C;t[16]!==g.description||t[17]!==g.fixType||t[18]!==g.title||t[19]!==y||t[20]!==x?(C=g.fixType===`ai`?(0,X.jsx)(mt,{tooltip:g.description,openPrompt:()=>y(!1),applyAutofix:()=>y(!0),openChat:x}):(0,X.jsx)(L,{content:g.description,align:`start`,children:(0,X.jsxs)(R,{size:`xs`,variant:`outline`,className:`font-normal`,onClick:()=>y(!1),children:[(0,X.jsx)(ge,{className:`h-3 w-3 mr-2`}),g.title]})}),t[16]=g.description,t[17]=g.fixType,t[18]=g.title,t[19]=y,t[20]=x,t[21]=C):C=t[21];let w;return t[22]!==S||t[23]!==C?(w=(0,X.jsx)(`div`,{className:S,children:C}),t[22]=S,t[23]=C,t[24]=w):w=t[24],w},ft={autofix:{Icon:ge,title:`Inline AI Fix`,description:`Apply AI fixes inline in the cell`},chat:{Icon:me,title:`Fix with AI assistant`,description:`Open the AI sidebar to fix`},prompt:{Icon:x,title:`Suggest a prompt`,description:`Edit the prompt before applying`}},pt=[`autofix`,`prompt`,`chat`],mt=e=>{let t=(0,G.c)(18),{tooltip:n,openPrompt:r,applyAutofix:i,openChat:a}=e,{fixMode:o,setFixMode:s}=ut(),c=r;o===`chat`?c=a:o===`autofix`&&(c=i);let{Icon:l,title:u}=ft[o],d;t[0]===l?d=t[1]:(d=(0,X.jsx)(l,{className:`h-3 w-3 mr-2 mb-0.5`}),t[0]=l,t[1]=d);let f;t[2]!==c||t[3]!==d||t[4]!==u?(f=(0,X.jsxs)(R,{size:`xs`,variant:`outline`,className:`font-normal rounded-r-none border-r-0`,onClick:c,children:[d,u]}),t[2]=c,t[3]=d,t[4]=u,t[5]=f):f=t[5];let p;t[6]!==f||t[7]!==n?(p=(0,X.jsx)(L,{content:n,align:`start`,children:f}),t[6]=f,t[7]=n,t[8]=p):p=t[8];let m;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,X.jsx)(se,{asChild:!0,children:(0,X.jsx)(R,{size:`xs`,variant:`outline`,className:`rounded-l-none px-2`,"aria-label":`Fix options`,children:(0,X.jsx)(fe,{className:`h-3 w-3`})})}),t[9]=m):m=t[9];let h;t[10]!==o||t[11]!==s?(h=pt.map(e=>(0,X.jsx)(oe,{className:`flex items-center gap-2`,onClick:()=>s(e),children:(0,X.jsx)(ht,{mode:e,selected:e===o})},e)),t[10]=o,t[11]=s,t[12]=h):h=t[12];let g;t[13]===h?g=t[14]:(g=(0,X.jsxs)(le,{children:[m,(0,X.jsx)(ce,{align:`end`,className:`w-56`,children:h})]}),t[13]=h,t[14]=g);let _;return t[15]!==p||t[16]!==g?(_=(0,X.jsxs)(`div`,{className:`flex`,children:[p,g]}),t[15]=p,t[16]=g,t[17]=_):_=t[17],_},ht=e=>{let t=(0,G.c)(15),{mode:n,selected:r}=e,{Icon:i,title:a,description:o}=ft[n],s;t[0]===i?s=t[1]:(s=(0,X.jsx)(i,{className:`h-4 w-4 shrink-0`}),t[0]=i,t[1]=s);let c;t[2]===a?c=t[3]:(c=(0,X.jsx)(`span`,{className:`font-medium`,children:a}),t[2]=a,t[3]=c);let l;t[4]===o?l=t[5]:(l=(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o}),t[4]=o,t[5]=l);let u;t[6]!==c||t[7]!==l?(u=(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[c,l]}),t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]===r?d=t[10]:(d=r&&(0,X.jsx)(de,{className:`h-4 w-4 ml-auto shrink-0`}),t[9]=r,t[10]=d);let f;return t[11]!==s||t[12]!==u||t[13]!==d?(f=(0,X.jsxs)(`div`,{className:`flex items-center gap-2 w-full`,children:[s,u,d]}),t[11]=s,t[12]=u,t[13]=d,t[14]=f):f=t[14],f},gt=e=>{let t=(0,G.c)(12),{local:n}=e,r;t[0]===n.name?r=t[1]:(r=(0,X.jsx)(`span`,{className:`font-code`,children:n.name}),t[0]=n.name,t[1]=r);let i;t[2]===n.cellId?i=t[3]:(i=(0,X.jsx)(H,{cellId:n.cellId}),t[2]=n.cellId,t[3]=i);let a;t[4]!==r||t[5]!==i?(a=(0,X.jsxs)(`div`,{className:`max-w-xs`,children:[`Local variable `,r,` in cell`,` `,i,`.`]}),t[4]=r,t[5]=i,t[6]=a):a=t[6];let o=a,s;t[7]===n.name?s=t[8]:(s=(0,X.jsx)(`span`,{className:`font-code cursor-help`,children:n.name}),t[7]=n.name,t[8]=s);let c;return t[9]!==s||t[10]!==o?(c=(0,X.jsx)(L,{content:o,children:s}),t[9]=s,t[10]=o,t[11]=c):c=t[11],c},_t=e=>{let t=(0,G.c)(4),{segments:n}=e,r;t[0]===n?r=t[1]:(r=n.map(vt),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,X.jsx)(X.Fragment,{children:r}),t[2]=r,t[3]=i),i};function vt(e,t){return typeof e==`string`?(0,X.jsx)(`span`,{children:e},t):(0,X.jsx)(gt,{local:e},t)}var yt=r([]),bt=r(e=>e(re)?e(yt).filter(e=>e.kind===`agent`):[]);function xt(e){return e.name||`Agent`}function St({getContent:e}){let t=i(ee),n=i(bt),r=i(F),[a,o]=(0,W.useState)(!1);return t?(0,X.jsxs)(R,{size:`xs`,variant:`outline`,disabled:a||n.length===0||!r,onClick:async()=>{if(!(a||n.length===0||!r)){o(!0);try{await N.post(`/pair/notebooks/${encodeURIComponent(r)}/messages`,e()),V({title:`Sent to ${n.map(xt).join(`, `)}`})}catch(e){V({variant:`danger`,title:e instanceof we&&e.status===409?`No agent attached`:`Could not send error`})}finally{o(!1)}}},children:[(0,X.jsx)(je,{className:`h-3 w-3 mr-2`}),`Send error to agent`]}):null}var Ct=new p,wt=e=>{let t=RegExp(`\x1B\\[[0-9;]*m`,`g`);return e.replaceAll(t,``)},Tt=/(pip\s+install|uv\s+add|uv\s+pip\s+install)\s+/gi;function Et(e){Tt.lastIndex=0;let t=Tt.exec(e);if(!t)return null;let n=t.index+t[0].length,r=e.slice(n).split(/\s+/),i=``,a=0;for(let e of r){let t=e.trim();if(!t)continue;if(t.startsWith(`-`)){a+=t.length+1;continue}let n=t.match(/^[\w,.[\]-]+/);if(n){i=n[0];break}break}if(!i)return null;let o=n+a+i.length;return{package:i,endIndex:o}}function Q(e,t=``){if(!e)return null;if(!/https?:\/\//.test(e))return e;let n=l(e);return n.length===1&&n[0].type===`text`?e:(0,X.jsx)(X.Fragment,{children:n.map((e,n)=>{let r=t?`${t}-${n}`:n;if(e.type===`url`){let t=wt(e.url);return(0,X.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,onClick:ue.stopPropagation(),className:`text-link hover:underline`,children:t},r)}if(e.type===`image`){let t=wt(e.url);return(0,X.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,onClick:ue.stopPropagation(),className:`text-link hover:underline`,children:t},r)}return(0,X.jsx)(W.Fragment,{children:e.value},r)})})}var Dt=e=>{let t=(0,G.c)(6),{packages:n,children:r}=e,{handleInstallPackages:i}=Se(),a;t[0]!==i||t[1]!==n?(a=e=>{i(n),e.preventDefault()},t[0]=i,t[1]=n,t[2]=a):a=t[2];let o;return t[3]!==r||t[4]!==a?(o=(0,X.jsx)(`button`,{onClick:a,className:`text-link hover:underline`,type:`button`,children:r}),t[3]=r,t[4]=a,t[5]=o):o=t[5],o},Ot=e=>{if(!(e instanceof y.Text))return;let t=wt(e.data);if(!/(pip\s+install|uv\s+add|uv\s+pip\s+install)/i.test(t))return;let n=[],r=/(pip\s+install|uv\s+add|uv\s+pip\s+install)\s+/gi,i;for(;(i=r.exec(t))!==null;){let e=i.index,r=Et(t.slice(e));r&&n.push({match:i,result:r})}if(n.length===0)return;let a=[],o=0;if(n.forEach((e,n)=>{let{match:r,result:i}=e,s=r.index,c=s+i.endIndex;if(o<s){let e=t.slice(o,s);a.push((0,X.jsx)(W.Fragment,{children:Q(e,`before-${n}`)},`before-${n}`))}let l=t.slice(s,c);a.push((0,X.jsx)(Dt,{packages:[i.package],children:l},`install-${n}`)),o=c}),o<t.length){let e=t.slice(o);a.push((0,X.jsx)(W.Fragment,{children:Q(e,`after`)},`after`))}return(0,X.jsx)(X.Fragment,{children:a})},kt=e=>{if(!(e instanceof y.Text))return;let t=e.data;if(!/https?:\/\//.test(t))return;let n=Q(t);if(typeof n!=`string`)return(0,X.jsx)(X.Fragment,{children:n})},At=(...e)=>t=>{for(let n of e){let e=n(t);if(e!==void 0)return e}},jt=(e,t)=>{let n=Ct.ansi_to_html(e),r=f(n,{replace:e=>t(e)});return(0,X.jsx)(`span`,{children:r})},Mt=e=>{let t=(0,G.c)(2),{text:n}=e,r;return t[0]===n?r=t[1]:(r=jt(n,At(Ot,kt)),t[0]=n,t[1]=r),r},Nt=e=>{let t=(0,G.c)(16),{traceback:n}=e,[r,i]=(0,W.useState)(!0),a;t[0]===r?a=t[1]:(a=()=>i(!r),t[0]=r,t[1]=a);let o=r?`Collapse traceback`:`Expand traceback`,s;t[2]===r?s=t[3]:(s=r?(0,X.jsx)(fe,{className:`h-3 w-3`}):(0,X.jsx)(pe,{className:`h-3 w-3`}),t[2]=r,t[3]=s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,X.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wider`,children:`Traceback`}),t[4]=c):c=t[4];let l;t[5]!==r||t[6]!==a||t[7]!==o||t[8]!==s?(l=(0,X.jsxs)(`button`,{type:`button`,onClick:a,"aria-expanded":r,"aria-label":o,className:`flex items-center gap-1 text-muted-foreground/70 hover:text-muted-foreground transition-colors`,children:[s,c]}),t[5]=r,t[6]=a,t[7]=o,t[8]=s,t[9]=l):l=t[9];let u;t[10]!==r||t[11]!==n?(u=r&&(0,X.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:xe({html:n})}),t[10]=r,t[11]=n,t[12]=u):u=t[12];let d;return t[13]!==l||t[14]!==u?(d=(0,X.jsxs)(`div`,{className:`mt-2`,children:[l,u]}),t[13]=l,t[14]=u,t[15]=d):d=t[15],d},$=e=>{let t=(0,G.c)(10),n=e.title??`Tip`,r;t[0]===n?r=t[1]:(r=(0,X.jsx)(M,{className:`pt-2 pb-0 font-normal`,children:n}),t[0]=n,t[1]=r);let i;t[2]===e.children?i=t[3]:(i=(0,X.jsx)(j,{className:`mr-24 text-[0.84375rem]`,wrapperClassName:`pt-0 pb-2`,children:e.children}),t[2]=e.children,t[3]=i);let a;t[4]!==r||t[5]!==i?(a=(0,X.jsxs)(A,{value:`item-1`,className:`text-muted-foreground`,children:[r,i]}),t[4]=r,t[5]=i,t[6]=a):a=t[6];let o;return t[7]!==e.className||t[8]!==a?(o=(0,X.jsx)(te,{type:`single`,collapsible:!0,className:e.className,children:a}),t[7]=e.className,t[8]=a,t[9]=o):o=t[9],o},Pt=e=>{let t=(0,G.c)(44),{errors:n,cellId:r,code:a,className:o}=e,s=d(),c=i(E).display.cell_output===`above`,l=i(ne).mode!==`edit`,u=`This cell wasn't run because it has errors`,f=`destructive`,p=`text-error`,m=null;if(n.some(Ft))u=`Interrupted`;else if(n.some(It))u=`An internal error occurred`;else if(n.some(Lt))u=`Ancestor prevented from running`,f=`default`,p=`text-secondary-foreground`;else if(n.some(Rt))u=`Ancestor stopped`,f=`default`,p=`text-secondary-foreground`;else if(n.some(zt))u=`SQL error`;else if(n.some(Bt))u=null,m=`Cell not run`;else{let e;t[0]===n?e=t[1]:(e=n.find(Vt),t[0]=n,t[1]=e);let r=e;r&&`exception_type`in r&&(u=r.exception_type)}let h,_,v,y,x,S;if(t[2]!==f||t[3]!==r||t[4]!==s||t[5]!==o||t[6]!==n||t[7]!==c||t[8]!==l||t[9]!==m||t[10]!==p||t[11]!==u){let e=n.filter(Ht),i=n.filter(Ut),a=n.filter(Wt),d=n.filter(Gt),C=n.filter(Kt),w=n.filter(qt),T=n.filter(Jt),E=n.filter(Yt),D=n.filter(Xt),O=n.filter(Zt),k=n.filter(Qt),A=n.filter($t),j=n.filter(en),M;t[18]===s?M=t[19]:(M=()=>{s.openApplication(`scratchpad`)},t[18]=s,t[19]=M);let ee=M,te=()=>{let t=[];if(k.length>0||A.length>0){let e=k.some(tn),n=!e&&k.some(nn);t.push((0,X.jsxs)(`div`,{children:[k.map(rn),A.map(an),e&&(0,X.jsxs)(R,{size:`xs`,variant:`outline`,className:`mt-2 font-normal`,onClick:()=>Ce(s),children:[(0,X.jsx)(he,{className:`h-3.5 w-3.5 mr-1.5 mb-0.5`}),(0,X.jsx)(`span`,{children:`Open package manager`})]}),n&&(0,X.jsxs)(R,{size:`xs`,variant:`outline`,className:`mt-2 font-normal`,onClick:()=>s.openApplication(`terminal`),children:[(0,X.jsx)(Me,{className:`h-3.5 w-3.5 mr-1.5`}),(0,X.jsx)(`span`,{children:`Open terminal`})]}),r&&(0,X.jsx)(Z,{errors:[...k,...A],cellId:r})]},`syntax-unknown`))}if(e.length>0&&t.push((0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-muted-foreground font-medium`,children:`The setup cell cannot be run because it has references.`}),(0,X.jsx)(`ul`,{className:`list-disc`,children:e.flatMap(on)}),r&&(0,X.jsx)(Z,{errors:e,cellId:r}),(0,X.jsxs)($,{title:`Why can't the setup cell have references?`,className:`mb-2`,children:[(0,X.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,X.jsx)(`p`,{className:`py-2`,children:`Try simplifying the setup cell to only contain only necessary variables.`}),(0,X.jsxs)(`p`,{className:`py-2`,children:[(0,X.jsxs)(B,{href:`https://links.marimo.app/errors-setup`,children:[`Learn more at our docs`,` `,(0,X.jsx)(U,{size:`0.75rem`,className:`inline`})]}),`.`]})]})]},`setup-refs`)),i.length>0&&t.push((0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-muted-foreground font-medium`,children:`This cell is in a cycle.`}),(0,X.jsx)(`ul`,{className:`list-disc`,children:i.flatMap(sn)}),r&&(0,X.jsx)(Z,{errors:i,cellId:r}),(0,X.jsxs)($,{title:`What are cycles and how do I resolve them?`,className:`mb-2`,children:[(0,X.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,X.jsx)(`p`,{className:`py-2`,children:`Try merging these cells into a single cell to eliminate the cycle.`}),(0,X.jsxs)(`p`,{className:`py-2`,children:[(0,X.jsxs)(B,{href:`https://links.marimo.app/errors-cycles`,children:[`Learn more at our docs`,` `,(0,X.jsx)(U,{size:`0.75rem`,className:`inline`})]}),`.`]})]})]},`cycle`)),a.length>0){let e=a[0].name;t.push((0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-muted-foreground font-medium`,children:`This cell redefines variables from other cells.`}),a.map(ln),r&&(0,X.jsx)(Z,{errors:a,cellId:r}),(0,X.jsxs)($,{title:`Why can't I redefine variables?`,children:[(0,X.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,X.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,X.jsxs)(Te,{className:`inline`,children:[`_`,e]}),`). to make them private to this cell.`]}),(0,X.jsxs)(`p`,{className:`py-2`,children:[(0,X.jsxs)(B,{href:`https://links.marimo.app/errors-multiple-definitions`,children:[`Learn more at our docs`,` `,(0,X.jsx)(U,{size:`0.75rem`,className:`inline`})]}),`.`]})]}),(0,X.jsx)($,{title:`Need a scratchpad?`,children:(0,X.jsxs)(`div`,{className:`flex flex-row gap-2 items-center`,children:[(0,X.jsxs)(R,{size:`xs`,variant:`link`,className:`my-2 font-normal mx-0 px-0`,onClick:ee,children:[(0,X.jsx)(g,{className:`h-3`}),(0,X.jsx)(`span`,{children:`Try the scratchpad`})]}),(0,X.jsx)(`span`,{children:`to experiment without restrictions on variable names.`})]})})]},`multiple-defs`))}return d.length>0&&t.push((0,X.jsxs)(`div`,{children:[d.map(un),r&&(0,X.jsx)(Z,{errors:d,cellId:r}),(0,X.jsxs)($,{title:"Why can't I use `import *`?",children:[(0,X.jsx)(`p`,{className:`pb-2`,children:`Star imports are incompatible with marimo's git-friendly file format and reproducible reactive execution.`}),(0,X.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,X.jsx)(`p`,{className:`py-2`,children:`Star imports would also silently add names to globals, which would be incompatible with reactive execution.`}),(0,X.jsxs)(`p`,{className:`py-2`,children:[(0,X.jsxs)(B,{href:`https://links.marimo.app/errors-import-star`,children:[`Learn more at our docs`,` `,(0,X.jsx)(U,{size:`0.75rem`,className:`inline`})]}),`.`]})]})]},`import-star`)),C.length>0&&t.push((0,X.jsxs)(`div`,{children:[C.map(dn),r&&(0,X.jsx)(Z,{errors:C,cellId:r})]},`interruption`)),w.length>0&&t.push((0,X.jsxs)(`ul`,{children:[w.map((e,t)=>{if(e.exception_type===`NameError`&&e.msg.startsWith(`name 'mo'`))return(0,X.jsx)(`li`,{className:`my-2`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:`name 'mo' is not defined.`}),(0,X.jsxs)(`p`,{className:`text-muted-foreground mt-2`,children:[`The marimo module (imported as`,` `,(0,X.jsx)(Te,{className:`inline`,children:`mo`}),`) is required for Markdown, SQL, and UI elements.`]})]})},`exception-${t}`);if(e.exception_type===`NameError`&&e.msg.startsWith(`name '_`)){let n=Le(e.msg);return(0,X.jsx)(`li`,{className:`my-2`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:(0,X.jsx)(_t,{segments:n})}),(0,X.jsxs)(`p`,{className:`text-muted-foreground mt-2`,children:[`Variables prefixed with an underscore are local to a cell`,` `,`(`,(0,X.jsxs)(B,{href:`https://links.marimo.app/local-variables`,children:[`docs`,` `,(0,X.jsx)(U,{size:`0.75rem`,className:`inline`})]}),`).`]}),c&&(0,X.jsx)(`div`,{className:`text-muted-foreground mt-2`,children:`See the console area for a traceback.`})]})},`exception-${t}`)}return(0,X.jsx)(`li`,{className:`my-2`,children:e.raising_cell==null?(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:Q(e.msg,`exception-${t}`)}),l&&`traceback`in e&&e.traceback?(0,X.jsx)(Nt,{traceback:e.traceback}):c&&(0,X.jsx)(`div`,{className:`text-muted-foreground mt-2`,children:`See the console area for a traceback.`})]}):(0,X.jsxs)(`div`,{children:[Q(e.msg,`exception-${t}`),(0,X.jsx)(H,{cellId:e.raising_cell}),l&&`traceback`in e&&e.traceback&&(0,X.jsx)(Nt,{traceback:e.traceback})]})},`exception-${t}`)}),w.some(fn)&&(0,X.jsx)($,{children:`Fix the error in the mentioned cells, or handle the exceptions with try/except blocks.`}),r&&(0,X.jsx)(Z,{errors:w,cellId:r})]},`exception`)),T.length>0&&t.push((0,X.jsxs)(`ul`,{children:[T.map(pn),r&&(0,X.jsx)(Z,{errors:T,cellId:r}),(0,X.jsx)($,{children:T.some(mn)?`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`)),E.length>0&&t.push((0,X.jsxs)(`div`,{children:[E.map(hn),r&&(0,X.jsx)(Z,{errors:E,cellId:r})]},`internal`)),D.length>0&&t.push((0,X.jsxs)(`div`,{children:[D.map(gn),r&&(0,X.jsx)(Z,{errors:D,cellId:r})]},`ancestor-prevented`)),O.length>0&&t.push((0,X.jsxs)(`div`,{children:[O.map(_n),r&&(0,X.jsx)(Z,{errors:O,cellId:r})]},`ancestor-stopped`)),j.length>0&&t.push((0,X.jsxs)(`div`,{children:[j.map(vn),r&&(0,X.jsx)(Z,{errors:j,cellId:r,className:`mt-2.5`})]},`sql-errors`)),t},N;t[20]===m?N=t[21]:(N=m&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 font-code text-[0.6875rem] uppercase tracking-wider text-muted-foreground/70`,children:[m,(0,X.jsx)(L,{content:`marimo didn't run this cell because it detected an error.`,delayDuration:200,children:(0,X.jsx)(b,{className:`size-3 cursor-help`})})]}),t[20]=m,t[21]=N);let P;t[22]!==p||t[23]!==u?(P=u&&(0,X.jsx)(De,{className:`font-code font-medium ${p}`,children:u}),t[22]=p,t[23]=u,t[24]=P):P=t[24];let F;t[25]!==N||t[26]!==P?(F=(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[N,P]}),t[25]=N,t[26]=P,t[27]=F):F=t[27];let ne=F;h=Oe,y=f,t[28]===o?x=t[29]:(x=ie(`border-none font-code text-sm text-[0.84375rem] p-0 text-muted-foreground normal has-[svg]:pl-0 space-y-2`,o),t[28]=o,t[29]=x),S=ne,_=`flex flex-col gap-4`,v=te(),t[2]=f,t[3]=r,t[4]=s,t[5]=o,t[6]=n,t[7]=c,t[8]=l,t[9]=m,t[10]=p,t[11]=u,t[12]=h,t[13]=_,t[14]=v,t[15]=y,t[16]=x,t[17]=S}else h=t[12],_=t[13],v=t[14],y=t[15],x=t[16],S=t[17];let C;t[30]!==_||t[31]!==v?(C=(0,X.jsx)(`div`,{className:_,children:v}),t[30]=_,t[31]=v,t[32]=C):C=t[32];let w;t[33]!==r||t[34]!==a||t[35]!==n?(w=r&&n.length>0&&(0,X.jsx)(St,{getContent:()=>Ne(r,{code:a,errors:n})}),t[33]=r,t[34]=a,t[35]=n,t[36]=w):w=t[36];let T;return t[37]!==h||t[38]!==y||t[39]!==x||t[40]!==S||t[41]!==C||t[42]!==w?(T=(0,X.jsxs)(h,{variant:y,className:x,children:[S,C,w]}),t[37]=h,t[38]=y,t[39]=x,t[40]=S,t[41]=C,t[42]=w,t[43]=T):T=t[43],T};function Ft(e){return e.type===`interruption`}function It(e){return e.type===`internal`}function Lt(e){return e.type===`ancestor-prevented`}function Rt(e){return e.type===`ancestor-stopped`}function zt(e){return e.type===`sql-error`}function Bt(e){return e.type===`multiple-defs`||e.type===`cycle`||e.type===`setup-refs`||e.type===`import-star`}function Vt(e){return e.type===`exception`}function Ht(e){return e.type===`setup-refs`}function Ut(e){return e.type===`cycle`}function Wt(e){return e.type===`multiple-defs`}function Gt(e){return e.type===`import-star`}function Kt(e){return e.type===`interruption`}function qt(e){return e.type===`exception`}function Jt(e){return e.type===`strict-exception`}function Yt(e){return e.type===`internal`}function Xt(e){return e.type===`ancestor-prevented`}function Zt(e){return e.type===`ancestor-stopped`}function Qt(e){return e.type===`syntax`}function $t(e){return e.type===`unknown`}function en(e){return e.type===`sql-error`}function tn(e){return e.msg.includes(`!pip`)}function nn(e){return e.msg.includes(`use os.subprocess`)}function rn(e,t){return(0,X.jsx)(`pre`,{children:Q(e.msg,`syntax-${t}`)},`syntax-${t}`)}function an(e,t){return(0,X.jsx)(`pre`,{children:Q(e.msg,`unknown-${t}`)},`unknown-${t}`)}function on(e,t){return e.edges_with_vars.map((e,n)=>(0,X.jsxs)(`li`,{className:`my-0.5 ml-8 text-muted-foreground/40`,children:[(0,X.jsx)(H,{cellId:e[0]}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`: `,` `,e[1].length===1?e[1][0]:e[1].join(`, `)]})]},`setup-refs-${t}-${n}`))}function sn(e,t){return e.edges_with_vars.map((e,n)=>(0,X.jsxs)(`li`,{className:`my-0.5 ml-8 text-muted-foreground/40`,children:[(0,X.jsx)(H,{cellId:e[0]}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[` -> `,e[1].length===1?e[1][0]:e[1].join(`, `),` -> `]}),(0,X.jsx)(H,{cellId:e[2]})]},`cycle-${t}-${n}`))}function cn(e,t){return(0,X.jsx)(`li`,{className:`my-0.5 ml-8 text-muted-foreground/40`,children:(0,X.jsx)(H,{cellId:e})},`cell-${t}`)}function ln(e,t){return(0,X.jsxs)(W.Fragment,{children:[(0,X.jsx)(`p`,{className:`text-muted-foreground mt-2`,children:`'${e.name}' was also defined by:`}),(0,X.jsx)(`ul`,{className:`list-disc`,children:e.cells.map(cn)})]},`multiple-defs-${t}`)}function un(e,t){return(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:e.msg},`import-star-${t}`)}function dn(e,t){return(0,X.jsx)(`p`,{children:`This cell was interrupted and needs to be re-run.`},`interruption-${t}`)}function fn(e){return e.raising_cell!=null}function pn(e,t){return(0,X.jsx)(`li`,{className:`my-2`,children:e.blamed_cell==null?(0,X.jsx)(`p`,{children:e.msg}):(0,X.jsxs)(`div`,{children:[e.msg,(0,X.jsx)(H,{cellId:e.blamed_cell})]})},`strict-exception-${t}`)}function mn(e){return e.blamed_cell!=null}function hn(e,t){return(0,X.jsx)(`p`,{children:e.msg},`internal-${t}`)}function gn(e,t){return(0,X.jsxs)(`div`,{children:[e.msg,e.blamed_cell==null?(0,X.jsxs)(`span`,{children:[`(`,(0,X.jsx)(H,{cellId:e.raising_cell}),`)`]}):(0,X.jsxs)(`span`,{children:[`(`,(0,X.jsx)(H,{cellId:e.raising_cell}),`\xA0blames\xA0`,(0,X.jsx)(H,{cellId:e.blamed_cell}),`)`]})]},`ancestor-prevented-${t}`)}function _n(e,t){return(0,X.jsxs)(`div`,{children:[e.msg,(0,X.jsx)(H,{cellId:e.raising_cell})]},`ancestor-stopped-${t}`)}function vn(e,t){return(0,X.jsx)(`div`,{className:`space-y-2 mt-2`,children:(0,X.jsx)(`p`,{className:`text-muted-foreground whitespace-pre-wrap`,children:e.msg})},`sql-error-${t}`)}export{Ye as C,Me as D,Ne as E,Xe as S,Le as T,et as _,xt as a,We as b,mt as c,it as d,qe as f,tt as g,$e as h,bt as i,dt as l,nt as m,Mt as n,yt as o,J as p,St as r,_t as s,Pt as t,st as u,Qe as v,Re as w,Ze as x,Je as y};
@@ -1,2 +1,2 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{f as t,l as n,r}from"./useEvent-Dfcbgjhg.js";import{t as i}from"./react-DVplv7_D.js";import{Mr as a,Oa as o,Vr as s,ka as c,m as l,ut as u}from"./cells-BRkCaSsh.js";import{t as d}from"./compiler-runtime-BrajqUja.js";import{s as f}from"./config-VPSq73n8.js";import{g as p}from"./useEventListener-D9cftcHj.js";import{d as m}from"./session-DqoWmb7X.js";import{t as h}from"./jsx-runtime-B74pBk57.js";import{t as g}from"./tooltip-C9TuY18o.js";import{L as _}from"./input-BoBxR50a.js";import{t as v}from"./copy-icon-BIiRXh_3.js";import{r as y}from"./useDebounce-B_ccBZTp.js";import{t as b}from"./useRunCells-B2vUhREg.js";var x=d(),S=e(i(),1),C=h(),w=e=>{let t=(0,x.c)(16),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({href:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=(0,S.useRef)(null),o;t[4]===r?o=t[5]:(o=()=>{let e=new URL(globalThis.location.href);e.hash=r,globalThis.history.pushState({},``,e.toString()),globalThis.dispatchEvent(new HashChangeEvent(`hashchange`));let t=r.slice(1),n=document.getElementById(t);n&&n.scrollIntoView({behavior:`smooth`,block:`start`})},t[4]=r,t[5]=o);let s=o,c;t[6]===s?c=t[7]:(c={onPress:()=>{s()}},t[6]=s,t[7]=c);let{pressProps:l}=_(c),u;t[8]===s?u=t[9]:(u=e=>{e.preventDefault(),s()},t[8]=s,t[9]=u);let d=u,f;return t[10]!==n||t[11]!==d||t[12]!==r||t[13]!==l||t[14]!==i?(f=(0,C.jsx)(`a`,{ref:a,href:r,...l,onClick:d,...i,children:n}),t[10]=n,t[11]=d,t[12]=r,t[13]=l,t[14]=i,t[15]=f):f=t[15],f};async function T(e){let t=l().inOrderIds.at(0);if(t)try{let n=await a.request({document:e,cellId:t});if(!n||n.options.length===0)return;let i=e.split(`.`).pop()??e,o=n.options[0],c=n.options.find(e=>e.name===i)??o;c?.completion_info&&r.set(s,{documentation:c.completion_info})}catch(t){p.debug(`Doc lookup failed for "${e}"`,t)}}var E=e=>{let t=(0,x.c)(8),{qualifiedName:n,children:r}=e,i;t[0]===n?i=t[1]:(i=()=>{T(n)},t[0]=n,t[1]=i);let a=y(i,100),o;t[2]===a?o=t[3]:(o=()=>a.cancel(),t[2]=a,t[3]=o);let s;return t[4]!==r||t[5]!==a||t[6]!==o?(s=(0,C.jsx)(`span`,{onMouseEnter:a,onMouseLeave:o,children:r}),t[4]=r,t[5]=a,t[6]=o,t[7]=s):s=t[7],s};function D(e){if(typeof e!=`object`||!e)return!1;let t=e;return!(t.trusted!==!0||t.notebookCode!==void 0&&typeof t.notebookCode!=`string`)}function O(){let e=window?.__MARIMO_EXPORT_CONTEXT__;return D(e)?e:void 0}function k(){return O()?.trusted===!0}function A(){if(r.get(b)||k()||r.get(f))return!0;try{if(m()===`read`)return!0}catch{}return!1}var j=t(e=>{let t=e(b),n=e(f);if(t||n||k())return!1;let r=!0;try{r=m()===`read`}catch{return!0}return!r});function M(){return n(j)}var N=[],P=e=>{if(e instanceof c.Element&&!/^[A-Za-z][\w-]*$/.test(e.name))return S.createElement(S.Fragment)},F=(e,t)=>{if(t instanceof c.Element&&t.name===`body`){if((0,S.isValidElement)(e)&&`props`in e){let t=e.props.children;return(0,C.jsx)(C.Fragment,{children:t})}return}},I=(e,t)=>{if(t instanceof c.Element&&t.name===`html`){if((0,S.isValidElement)(e)&&`props`in e){let t=e.props.children;return(0,C.jsx)(C.Fragment,{children:t})}return}},L=e=>{if(e instanceof c.Element&&e.attribs&&e.name===`iframe`){let t=document.createElement(`iframe`);return Object.entries(e.attribs).forEach(([e,n])=>{e.startsWith(`"`)&&e.endsWith(`"`)&&(e=e.slice(1,-1)),t.setAttribute(e,n)}),(0,C.jsx)(`div`,{dangerouslySetInnerHTML:{__html:t.outerHTML}})}},R=e=>{if(e instanceof c.Element&&e.name===`script`){let t=e.attribs.src;if(!t)return;if(!A())return p.warn(`[RenderHTML] refusing <script src> in untrusted context: ${t}`),(0,C.jsx)(C.Fragment,{});if(![...document.querySelectorAll(`script[src]`)].some(e=>e.getAttribute(`src`)===t)){let e=document.createElement(`script`);e.src=t,document.head.append(e)}return(0,C.jsx)(C.Fragment,{})}},z=(e,t)=>{if(t instanceof c.Element&&t.name===`a`){let n=t.attribs.href;if(n?.startsWith(`#`)&&!n.startsWith(`#code/`)){let r=null;return(0,S.isValidElement)(e)&&`props`in e&&(r=e.props.children),(0,C.jsx)(w,{href:n,...t.attribs,children:r})}}},B=(e,t,n)=>{if(t instanceof c.Element&&t.name===`div`&&t.attribs?.class?.includes(`codehilite`))return(0,C.jsx)(G,{children:e},n)},V=(e,t,n)=>{if(!(t instanceof c.Element)||t.name!==`img`)return;let r=t.attribs?.src;if(!(!r||!(0,S.isValidElement)(e))&&!/^data:/i.test(r))return(0,S.cloneElement)(e,{key:`${r}-${n}`})},H=(e,t,n)=>{if(!(t instanceof c.Element)||t.name!==`input`||t.attribs?.type!==`checkbox`||!(0,S.isValidElement)(e))return;let r=`checked`in t.attribs;return(0,S.cloneElement)(e,{key:`checkbox-${n}-${r}`})},U=(e,t)=>{if(t instanceof c.Element&&t.attribs?.[`data-marimo-doc`]){let n=t.attribs[`data-marimo-doc`];return(0,C.jsx)(E,{qualifiedName:n,children:e})}},W=(e,t)=>{if(t instanceof c.Element&&t.attribs?.[`data-tooltip`]){if((t.name?.toLowerCase()??``).startsWith(`marimo-`))return;let n=t.attribs[`data-tooltip`].replace(/^[\r\n]+|[\r\n]+$/g,``);return(0,C.jsx)(g,{content:n.includes(`
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{f as t,l as n,r}from"./useEvent-Dfcbgjhg.js";import{t as i}from"./react-DVplv7_D.js";import{Mr as a,Oa as o,Vr as s,ka as c,m as l,ut as u}from"./cells-rA_jsZCj.js";import{t as d}from"./compiler-runtime-BrajqUja.js";import{s as f}from"./config-VPSq73n8.js";import{g as p}from"./useEventListener-D9cftcHj.js";import{d as m}from"./session-DqoWmb7X.js";import{t as h}from"./jsx-runtime-B74pBk57.js";import{t as g}from"./tooltip-C9TuY18o.js";import{L as _}from"./input-BoBxR50a.js";import{t as v}from"./copy-icon-BIiRXh_3.js";import{r as y}from"./useDebounce-B_ccBZTp.js";import{t as b}from"./useRunCells-BFjFX3hz.js";var x=d(),S=e(i(),1),C=h(),w=e=>{let t=(0,x.c)(16),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({href:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=(0,S.useRef)(null),o;t[4]===r?o=t[5]:(o=()=>{let e=new URL(globalThis.location.href);e.hash=r,globalThis.history.pushState({},``,e.toString()),globalThis.dispatchEvent(new HashChangeEvent(`hashchange`));let t=r.slice(1),n=document.getElementById(t);n&&n.scrollIntoView({behavior:`smooth`,block:`start`})},t[4]=r,t[5]=o);let s=o,c;t[6]===s?c=t[7]:(c={onPress:()=>{s()}},t[6]=s,t[7]=c);let{pressProps:l}=_(c),u;t[8]===s?u=t[9]:(u=e=>{e.preventDefault(),s()},t[8]=s,t[9]=u);let d=u,f;return t[10]!==n||t[11]!==d||t[12]!==r||t[13]!==l||t[14]!==i?(f=(0,C.jsx)(`a`,{ref:a,href:r,...l,onClick:d,...i,children:n}),t[10]=n,t[11]=d,t[12]=r,t[13]=l,t[14]=i,t[15]=f):f=t[15],f};async function T(e){let t=l().inOrderIds.at(0);if(t)try{let n=await a.request({document:e,cellId:t});if(!n||n.options.length===0)return;let i=e.split(`.`).pop()??e,o=n.options[0],c=n.options.find(e=>e.name===i)??o;c?.completion_info&&r.set(s,{documentation:c.completion_info})}catch(t){p.debug(`Doc lookup failed for "${e}"`,t)}}var E=e=>{let t=(0,x.c)(8),{qualifiedName:n,children:r}=e,i;t[0]===n?i=t[1]:(i=()=>{T(n)},t[0]=n,t[1]=i);let a=y(i,100),o;t[2]===a?o=t[3]:(o=()=>a.cancel(),t[2]=a,t[3]=o);let s;return t[4]!==r||t[5]!==a||t[6]!==o?(s=(0,C.jsx)(`span`,{onMouseEnter:a,onMouseLeave:o,children:r}),t[4]=r,t[5]=a,t[6]=o,t[7]=s):s=t[7],s};function D(e){if(typeof e!=`object`||!e)return!1;let t=e;return!(t.trusted!==!0||t.notebookCode!==void 0&&typeof t.notebookCode!=`string`)}function O(){let e=window?.__MARIMO_EXPORT_CONTEXT__;return D(e)?e:void 0}function k(){return O()?.trusted===!0}function A(){if(r.get(b)||k()||r.get(f))return!0;try{if(m()===`read`)return!0}catch{}return!1}var j=t(e=>{let t=e(b),n=e(f);if(t||n||k())return!1;let r=!0;try{r=m()===`read`}catch{return!0}return!r});function M(){return n(j)}var N=[],P=e=>{if(e instanceof c.Element&&!/^[A-Za-z][\w-]*$/.test(e.name))return S.createElement(S.Fragment)},F=(e,t)=>{if(t instanceof c.Element&&t.name===`body`){if((0,S.isValidElement)(e)&&`props`in e){let t=e.props.children;return(0,C.jsx)(C.Fragment,{children:t})}return}},I=(e,t)=>{if(t instanceof c.Element&&t.name===`html`){if((0,S.isValidElement)(e)&&`props`in e){let t=e.props.children;return(0,C.jsx)(C.Fragment,{children:t})}return}},L=e=>{if(e instanceof c.Element&&e.attribs&&e.name===`iframe`){let t=document.createElement(`iframe`);return Object.entries(e.attribs).forEach(([e,n])=>{e.startsWith(`"`)&&e.endsWith(`"`)&&(e=e.slice(1,-1)),t.setAttribute(e,n)}),(0,C.jsx)(`div`,{dangerouslySetInnerHTML:{__html:t.outerHTML}})}},R=e=>{if(e instanceof c.Element&&e.name===`script`){let t=e.attribs.src;if(!t)return;if(!A())return p.warn(`[RenderHTML] refusing <script src> in untrusted context: ${t}`),(0,C.jsx)(C.Fragment,{});if(![...document.querySelectorAll(`script[src]`)].some(e=>e.getAttribute(`src`)===t)){let e=document.createElement(`script`);e.src=t,document.head.append(e)}return(0,C.jsx)(C.Fragment,{})}},z=(e,t)=>{if(t instanceof c.Element&&t.name===`a`){let n=t.attribs.href;if(n?.startsWith(`#`)&&!n.startsWith(`#code/`)){let r=null;return(0,S.isValidElement)(e)&&`props`in e&&(r=e.props.children),(0,C.jsx)(w,{href:n,...t.attribs,children:r})}}},B=(e,t,n)=>{if(t instanceof c.Element&&t.name===`div`&&t.attribs?.class?.includes(`codehilite`))return(0,C.jsx)(G,{children:e},n)},V=(e,t,n)=>{if(!(t instanceof c.Element)||t.name!==`img`)return;let r=t.attribs?.src;if(!(!r||!(0,S.isValidElement)(e))&&!/^data:/i.test(r))return(0,S.cloneElement)(e,{key:`${r}-${n}`})},H=(e,t,n)=>{if(!(t instanceof c.Element)||t.name!==`input`||t.attribs?.type!==`checkbox`||!(0,S.isValidElement)(e))return;let r=`checked`in t.attribs;return(0,S.cloneElement)(e,{key:`checkbox-${n}-${r}`})},U=(e,t)=>{if(t instanceof c.Element&&t.attribs?.[`data-marimo-doc`]){let n=t.attribs[`data-marimo-doc`];return(0,C.jsx)(E,{qualifiedName:n,children:e})}},W=(e,t)=>{if(t instanceof c.Element&&t.attribs?.[`data-tooltip`]){if((t.name?.toLowerCase()??``).startsWith(`marimo-`))return;let n=t.attribs[`data-tooltip`].replace(/^[\r\n]+|[\r\n]+$/g,``);return(0,C.jsx)(g,{content:n.includes(`
2
2
  `)?(0,C.jsx)(`span`,{className:`whitespace-pre-wrap`,children:n.split(/\r?\n/).map((e,t)=>(0,C.jsxs)(S.Fragment,{children:[t>0&&(0,C.jsx)(`br`,{}),e]},t))}):n,children:e})}},G=e=>{let t=(0,x.c)(3),{children:n}=e,r=(0,S.useRef)(null),i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,C.jsx)(`div`,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,C.jsx)(v,{tooltip:!1,className:`p-1`,value:()=>{let e=r.current?.firstChild;return e&&e.textContent||``}})}),t[0]=i):i=t[0];let a;return t[1]===n?a=t[2]:(a=(0,C.jsxs)(`div`,{className:`relative group codehilite-wrapper`,ref:r,children:[n,i]}),t[1]=n,t[2]=a),a},K=({html:e,additionalReplacements:t=N,alwaysSanitizeHtml:n=!0})=>(0,C.jsx)(q,{html:e,alwaysSanitizeHtml:n,additionalReplacements:t}),q=e=>{let t=(0,x.c)(5),{html:n,additionalReplacements:r,alwaysSanitizeHtml:i}=e,a=r===void 0?N:r,o=M(),s;bb0:{if(i||o){let e;t[0]===n?e=t[1]:(e=u(n),t[0]=n,t[1]=e),s=e;break bb0}s=n}let c=s,l;return t[2]!==a||t[3]!==c?(l=J({html:c,additionalReplacements:a}),t[2]=a,t[3]=c,t[4]=l):l=t[4],l};function J({html:e,additionalReplacements:t=N}){let n=[P,L,R,...t],r=[B,z,U,W,F,I],i=[V,H];return o(e,{replace:(e,t)=>{for(let r of n){let n=r(e,t);if(n)return n}return e},transform:(e,t,n)=>{let a=e;for(let e of r){let r=e(a,t,n);if(r){a=r;break}}for(let e of i){let r=e(a,t,n);r&&(a=r)}return a}})}export{k as n,K as t};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-DVplv7_D.js";import{t as n}from"./compiler-runtime-BrajqUja.js";import{_ as r}from"./useEventListener-D9cftcHj.js";import{m as i,u as a}from"./config-DX8Y2WbJ.js";import{n as o,t as s}from"./cn-ldLVeaqm.js";import{t as c}from"./jsx-runtime-B74pBk57.js";import{o as l}from"./switch-CTaiAjrz.js";import{t as u}from"./tooltip-C9TuY18o.js";import{r as d}from"./button-COI-NGrx.js";import{t as f}from"./createLucideIcon-DfJ2oMlA.js";import{i as p}from"./useDeleteCell-2_bMClHd.js";import{Et as m,Ft as h,Kt as g,Pt as _,St as v,Ut as y,V as b,wt as x,zt as S}from"./input-BoBxR50a.js";import{t as C}from"./square-BPmgQFnh.js";import{r as w}from"./requests-lt0JK8Jt.js";import{t as T}from"./I18nProvider-Cg2I_s1_.js";import{a as E}from"./renderShortcut-BkVJQ_Zh.js";var D=f(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),O=e(t(),1);function k(e,t){let{"aria-label":n,"aria-labelledby":r,orientation:i=`horizontal`}=e,[a,o]=(0,O.useState)(!1);g(()=>{o(!!(t.current&&t.current.parentElement?.closest(`[role="toolbar"]`)))});let{direction:s}=T(),c=s===`rtl`&&i===`horizontal`,u=l(t),d=e=>{if(v(e.currentTarget,m(e))){if(i===`horizontal`&&e.key===`ArrowRight`||i===`vertical`&&e.key===`ArrowDown`)c?u.focusPrevious():u.focusNext();else if(i===`horizontal`&&e.key===`ArrowLeft`||i===`vertical`&&e.key===`ArrowUp`)c?u.focusNext():u.focusPrevious();else if(e.key===`Tab`){f.current=x(),e.shiftKey?u.focusFirst():u.focusLast();return}else return;e.stopPropagation(),e.preventDefault()}},f=(0,O.useRef)(null),p=e=>{!v(e.currentTarget,e.relatedTarget)&&!f.current&&(f.current=m(e))},h=e=>{f.current&&!v(e.currentTarget,e.relatedTarget)&&v(t.current,m(e))&&(f.current?.focus(),f.current=null)};return{toolbarProps:{...b(e,{labelable:!0}),role:a?`group`:`toolbar`,"aria-orientation":i,"aria-label":n,"aria-labelledby":n==null?r:void 0,onKeyDownCapture:a?void 0:d,onFocusCapture:a?void 0:h,onBlurCapture:a?void 0:p}}}var A=(0,O.createContext)({}),j=(0,O.forwardRef)(function(e,t){[e,t]=_(e,t,A);let{toolbarProps:n}=k(e,t),r=h({...e,values:{orientation:e.orientation||`horizontal`},defaultClassName:`react-aria-Toolbar`}),i=b(e,{global:!0});return delete i.id,O.createElement(S.div,{...y(i,r,n),ref:t,slot:e.slot||void 0,"data-orientation":e.orientation||`horizontal`},r.children)}),M=c(),N=n(),P=200;function F(e){let t=(0,N.c)(3),[n,r]=(0,O.useState)(!1),i,a;return t[0]===e?(i=t[1],a=t[2]):(i=()=>{if(!e)return;r(!1);let t=setTimeout(()=>{r(!0)},P);return()=>clearTimeout(t)},a=[e],t[0]=e,t[1]=i,t[2]=a),(0,O.useEffect)(i,a),e&&n}var I=o(`rounded-full shadow-xs-solid border p-[5px] transition-colors focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 [&>svg]:size-3 active:shadow-none bg-background`,{variants:{variant:{default:`hover:bg-accent hover:text-accent-foreground`,stale:`bg-(--yellow-3) hover:bg-(--yellow-4) text-(--yellow-11)`,green:`hover:bg-(--grass-2) hover:text-(--grass-11) hover:border-[var(--grass-7)],`,disabled:`opacity-50 cursor-not-allowed`,danger:`hover:bg-(--red-3) hover:text-(--red-11)`}},defaultVariants:{variant:`default`}}),L=e=>{let t=(0,N.c)(22),n,r,i,a,o,c,l,f,p;if(t[0]!==e){let{children:u,tooltip:m,disabled:h,variant:g,..._}=e;n=u,p=m;let v=h!==void 0&&h;r=`button`,i=v,a=_,o=e=>{!d.hasModifier(e)&&(e.key===`Enter`||e.key===` `)&&e.stopPropagation(),_.onKeyDown?.(e)},c=e=>{v||_.onClick?.(e)},l=d.preventFocus,f=s(I({variant:g}),_.className),t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=c,t[7]=l,t[8]=f,t[9]=p}else n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],c=t[6],l=t[7],f=t[8],p=t[9];let m;t[10]!==n||t[11]!==r||t[12]!==i||t[13]!==a||t[14]!==o||t[15]!==c||t[16]!==l||t[17]!==f?(m=(0,M.jsx)(`button`,{type:r,disabled:i,...a,onKeyDown:o,onClick:c,onMouseDown:l,className:f,children:n}),t[10]=n,t[11]=r,t[12]=i,t[13]=a,t[14]=o,t[15]=c,t[16]=l,t[17]=f,t[18]=m):m=t[18];let h=m;if(p){let e;return t[19]!==h||t[20]!==p?(e=(0,M.jsx)(u,{content:p,side:`top`,delayDuration:200,usePortal:!1,children:h}),t[19]=h,t[20]=p,t[21]=e):e=t[21],e}return h},R=e=>{let t=(0,N.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=s(`flex items-center gap-1 bg-background m-[2px] rounded-full`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,M.jsx)(j,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},z=e=>{let t=(0,N.c)(9),{connectionState:n,status:a}=e,{sendInterrupt:o}=w(),s=F(a===`running`),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=E(`global.interrupt`),t[0]=c):c=t[0];let l;t[1]!==n||t[2]!==s?(l=i(n)||!s,t[1]=n,t[2]=s,t[3]=l):l=t[3];let u=s?o:r.NOOP,d=s?`stale`:`disabled`,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,M.jsx)(C,{strokeWidth:1.5}),t[4]=f):f=t[4];let p;return t[5]!==l||t[6]!==u||t[7]!==d?(p=(0,M.jsx)(L,{tooltip:c,disabled:l,onClick:u,variant:d,"data-testid":`run-button`,children:f}),t[5]=l,t[6]=u,t[7]=d,t[8]=p):p=t[8],p};function B({connectionState:e,needsRun:t,loading:n,inactive:r}){return i(e)?`disabled`:t&&!n?`stale`:n||r?`disabled`:`green`}var V=e=>{let t=(0,N.c)(27),{onClick:n,connectionState:r,needsRun:o,status:s,config:c,edited:l}=e,u=s===`disabled-transitively`,d=s===`running`||s===`queued`,f,m;t[0]!==u||t[1]!==c.disabled||t[2]!==r||t[3]!==l||t[4]!==d||t[5]!==o?(f=i(r)||d||!c.disabled&&u&&!l,m=B({connectionState:r,needsRun:o,loading:d,inactive:f}),t[0]=u,t[1]=c.disabled,t[2]=r,t[3]=l,t[4]=d,t[5]=o,t[6]=f,t[7]=m):(f=t[6],m=t[7]);let h=m;if(c.disabled){let e;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,M.jsx)(D,{}),t[8]=e):e=t[8];let r;return t[9]!==f||t[10]!==n||t[11]!==h?(r=(0,M.jsx)(L,{tooltip:`Add code to notebook`,disabled:f,onClick:n,variant:h,"data-testid":`run-button`,children:e}),t[9]=f,t[10]=n,t[11]=h,t[12]=r):r=t[12],r}if(!c.disabled&&u&&!l){let e;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,M.jsx)(p,{strokeWidth:1.2}),t[13]=e):e=t[13];let r;return t[14]!==f||t[15]!==n||t[16]!==h?(r=(0,M.jsx)(L,{disabled:f,tooltip:`This cell can't be run because it has a disabled ancestor`,onClick:n,variant:h,"data-testid":`run-button`,children:e}),t[14]=f,t[15]=n,t[16]=h,t[17]=r):r=t[17],r}let g;if(i(r)){let e;t[18]===r?e=t[19]:(e=a(r),t[18]=r,t[19]=e),g=e}else if(s===`queued`)g=`This cell is already queued to run`;else if(s===`running`)g=`This cell is already running.`;else{let e;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(e=E(`cell.run`),t[20]=e):e=t[20],g=e}let _;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,M.jsx)(p,{strokeWidth:1.2}),t[21]=_):_=t[21];let v;return t[22]!==f||t[23]!==n||t[24]!==g||t[25]!==h?(v=(0,M.jsx)(L,{tooltip:g,disabled:f,onClick:n,variant:h,"data-testid":`run-button`,children:_}),t[22]=f,t[23]=n,t[24]=g,t[25]=h,t[26]=v):v=t[26],v};export{F as a,L as i,z as n,R as r,V as t};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-DVplv7_D.js";import{t as n}from"./compiler-runtime-BrajqUja.js";import{_ as r}from"./useEventListener-D9cftcHj.js";import{m as i,u as a}from"./config-DX8Y2WbJ.js";import{n as o,t as s}from"./cn-ldLVeaqm.js";import{t as c}from"./jsx-runtime-B74pBk57.js";import{o as l}from"./switch-CTaiAjrz.js";import{t as u}from"./tooltip-C9TuY18o.js";import{r as d}from"./button-COI-NGrx.js";import{t as f}from"./createLucideIcon-DfJ2oMlA.js";import{i as p}from"./useDeleteCell-DFBGlSQk.js";import{Et as m,Ft as h,Kt as g,Pt as _,St as v,Ut as y,V as b,wt as x,zt as S}from"./input-BoBxR50a.js";import{t as C}from"./square-BPmgQFnh.js";import{r as w}from"./requests-lt0JK8Jt.js";import{t as T}from"./I18nProvider-Cg2I_s1_.js";import{a as E}from"./renderShortcut-BkVJQ_Zh.js";var D=f(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),O=e(t(),1);function k(e,t){let{"aria-label":n,"aria-labelledby":r,orientation:i=`horizontal`}=e,[a,o]=(0,O.useState)(!1);g(()=>{o(!!(t.current&&t.current.parentElement?.closest(`[role="toolbar"]`)))});let{direction:s}=T(),c=s===`rtl`&&i===`horizontal`,u=l(t),d=e=>{if(v(e.currentTarget,m(e))){if(i===`horizontal`&&e.key===`ArrowRight`||i===`vertical`&&e.key===`ArrowDown`)c?u.focusPrevious():u.focusNext();else if(i===`horizontal`&&e.key===`ArrowLeft`||i===`vertical`&&e.key===`ArrowUp`)c?u.focusNext():u.focusPrevious();else if(e.key===`Tab`){f.current=x(),e.shiftKey?u.focusFirst():u.focusLast();return}else return;e.stopPropagation(),e.preventDefault()}},f=(0,O.useRef)(null),p=e=>{!v(e.currentTarget,e.relatedTarget)&&!f.current&&(f.current=m(e))},h=e=>{f.current&&!v(e.currentTarget,e.relatedTarget)&&v(t.current,m(e))&&(f.current?.focus(),f.current=null)};return{toolbarProps:{...b(e,{labelable:!0}),role:a?`group`:`toolbar`,"aria-orientation":i,"aria-label":n,"aria-labelledby":n==null?r:void 0,onKeyDownCapture:a?void 0:d,onFocusCapture:a?void 0:h,onBlurCapture:a?void 0:p}}}var A=(0,O.createContext)({}),j=(0,O.forwardRef)(function(e,t){[e,t]=_(e,t,A);let{toolbarProps:n}=k(e,t),r=h({...e,values:{orientation:e.orientation||`horizontal`},defaultClassName:`react-aria-Toolbar`}),i=b(e,{global:!0});return delete i.id,O.createElement(S.div,{...y(i,r,n),ref:t,slot:e.slot||void 0,"data-orientation":e.orientation||`horizontal`},r.children)}),M=c(),N=n(),P=200;function F(e){let t=(0,N.c)(3),[n,r]=(0,O.useState)(!1),i,a;return t[0]===e?(i=t[1],a=t[2]):(i=()=>{if(!e)return;r(!1);let t=setTimeout(()=>{r(!0)},P);return()=>clearTimeout(t)},a=[e],t[0]=e,t[1]=i,t[2]=a),(0,O.useEffect)(i,a),e&&n}var I=o(`rounded-full shadow-xs-solid border p-[5px] transition-colors focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 [&>svg]:size-3 active:shadow-none bg-background`,{variants:{variant:{default:`hover:bg-accent hover:text-accent-foreground`,stale:`bg-(--yellow-3) hover:bg-(--yellow-4) text-(--yellow-11)`,green:`hover:bg-(--grass-2) hover:text-(--grass-11) hover:border-[var(--grass-7)],`,disabled:`opacity-50 cursor-not-allowed`,danger:`hover:bg-(--red-3) hover:text-(--red-11)`}},defaultVariants:{variant:`default`}}),L=e=>{let t=(0,N.c)(22),n,r,i,a,o,c,l,f,p;if(t[0]!==e){let{children:u,tooltip:m,disabled:h,variant:g,..._}=e;n=u,p=m;let v=h!==void 0&&h;r=`button`,i=v,a=_,o=e=>{!d.hasModifier(e)&&(e.key===`Enter`||e.key===` `)&&e.stopPropagation(),_.onKeyDown?.(e)},c=e=>{v||_.onClick?.(e)},l=d.preventFocus,f=s(I({variant:g}),_.className),t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=c,t[7]=l,t[8]=f,t[9]=p}else n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],c=t[6],l=t[7],f=t[8],p=t[9];let m;t[10]!==n||t[11]!==r||t[12]!==i||t[13]!==a||t[14]!==o||t[15]!==c||t[16]!==l||t[17]!==f?(m=(0,M.jsx)(`button`,{type:r,disabled:i,...a,onKeyDown:o,onClick:c,onMouseDown:l,className:f,children:n}),t[10]=n,t[11]=r,t[12]=i,t[13]=a,t[14]=o,t[15]=c,t[16]=l,t[17]=f,t[18]=m):m=t[18];let h=m;if(p){let e;return t[19]!==h||t[20]!==p?(e=(0,M.jsx)(u,{content:p,side:`top`,delayDuration:200,usePortal:!1,children:h}),t[19]=h,t[20]=p,t[21]=e):e=t[21],e}return h},R=e=>{let t=(0,N.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=s(`flex items-center gap-1 bg-background m-[2px] rounded-full`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,M.jsx)(j,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},z=e=>{let t=(0,N.c)(9),{connectionState:n,status:a}=e,{sendInterrupt:o}=w(),s=F(a===`running`),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=E(`global.interrupt`),t[0]=c):c=t[0];let l;t[1]!==n||t[2]!==s?(l=i(n)||!s,t[1]=n,t[2]=s,t[3]=l):l=t[3];let u=s?o:r.NOOP,d=s?`stale`:`disabled`,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,M.jsx)(C,{strokeWidth:1.5}),t[4]=f):f=t[4];let p;return t[5]!==l||t[6]!==u||t[7]!==d?(p=(0,M.jsx)(L,{tooltip:c,disabled:l,onClick:u,variant:d,"data-testid":`run-button`,children:f}),t[5]=l,t[6]=u,t[7]=d,t[8]=p):p=t[8],p};function B({connectionState:e,needsRun:t,loading:n,inactive:r}){return i(e)?`disabled`:t&&!n?`stale`:n||r?`disabled`:`green`}var V=e=>{let t=(0,N.c)(27),{onClick:n,connectionState:r,needsRun:o,status:s,config:c,edited:l}=e,u=s===`disabled-transitively`,d=s===`running`||s===`queued`,f,m;t[0]!==u||t[1]!==c.disabled||t[2]!==r||t[3]!==l||t[4]!==d||t[5]!==o?(f=i(r)||d||!c.disabled&&u&&!l,m=B({connectionState:r,needsRun:o,loading:d,inactive:f}),t[0]=u,t[1]=c.disabled,t[2]=r,t[3]=l,t[4]=d,t[5]=o,t[6]=f,t[7]=m):(f=t[6],m=t[7]);let h=m;if(c.disabled){let e;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,M.jsx)(D,{}),t[8]=e):e=t[8];let r;return t[9]!==f||t[10]!==n||t[11]!==h?(r=(0,M.jsx)(L,{tooltip:`Add code to notebook`,disabled:f,onClick:n,variant:h,"data-testid":`run-button`,children:e}),t[9]=f,t[10]=n,t[11]=h,t[12]=r):r=t[12],r}if(!c.disabled&&u&&!l){let e;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,M.jsx)(p,{strokeWidth:1.2}),t[13]=e):e=t[13];let r;return t[14]!==f||t[15]!==n||t[16]!==h?(r=(0,M.jsx)(L,{disabled:f,tooltip:`This cell can't be run because it has a disabled ancestor`,onClick:n,variant:h,"data-testid":`run-button`,children:e}),t[14]=f,t[15]=n,t[16]=h,t[17]=r):r=t[17],r}let g;if(i(r)){let e;t[18]===r?e=t[19]:(e=a(r),t[18]=r,t[19]=e),g=e}else if(s===`queued`)g=`This cell is already queued to run`;else if(s===`running`)g=`This cell is already running.`;else{let e;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(e=E(`cell.run`),t[20]=e):e=t[20],g=e}let _;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,M.jsx)(p,{strokeWidth:1.2}),t[21]=_):_=t[21];let v;return t[22]!==f||t[23]!==n||t[24]!==g||t[25]!==h?(v=(0,M.jsx)(L,{tooltip:g,disabled:f,onClick:n,variant:h,"data-testid":`run-button`,children:_}),t[22]=f,t[23]=n,t[24]=g,t[25]=h,t[26]=v):v=t[26],v};export{F as a,L as i,z as n,R as r,V as t};
@@ -1,4 +1,4 @@
1
- import{a as e,t}from"./rolldown-runtime-B0Z9INg1.js";import{a as n,c as r,d as i,f as a,l as o,r as s,t as c}from"./useEvent-Dfcbgjhg.js";import{t as l}from"./react-DVplv7_D.js";import{Bt as u,D as d,Fa as f,Fi as p,In as m,Pi as h,Qr as g,Ti as _,Va as v,Z as y,Zn as b,_a as x,b as S,bo as C,da as ee,f as te,ft as ne,ir as w,ja as T,ji as E,qa as re,ti as ie,yo as ae}from"./cells-BRkCaSsh.js";import{A as oe,B as se,C as ce,D as le,E as ue,I as de,L as fe,N as pe,P as D,R as me,S as he,T as ge,W as _e,_ as ve,j as O,k as ye,v as be,w as xe,x as Se,y as Ce}from"./schemas-Dv42wLFq.js";import{t as we}from"./compiler-runtime-BrajqUja.js";import{t as Te}from"./config-VPSq73n8.js";import{f as Ee,g as k}from"./useEventListener-D9cftcHj.js";import{o as De}from"./session-DqoWmb7X.js";import{A as Oe,O as ke,o as Ae}from"./config-DX8Y2WbJ.js";import{t as je}from"./cn-ldLVeaqm.js";import{t as Me}from"./jsx-runtime-B74pBk57.js";import{a as Ne,c as Pe,p as Fe,r as Ie,t as Le}from"./dropdown-menu-C1rnl-0o.js";import{t as Re}from"./tooltip-C9TuY18o.js";import{t as ze}from"./button-COI-NGrx.js";import{t as Be}from"./createLucideIcon-DfJ2oMlA.js";import{i as Ve,r as He}from"./paths-bkIFVj8h.js";import{r as Ue,t as We}from"./fileToBase64-BgBraYAr.js";import{M as Ge,m as Ke,t as qe}from"./ai-model-dropdown-B0z6-zhp.js";import{r as Je}from"./useNumberFormatter-D7O_26UI.js";import{f as Ye,n as Xe}from"./markdown-renderer-BG3sp2rs.js";import{t as Ze}from"./file-BPBVl9pl.js";import{t as Qe}from"./image-wZvTj8WY.js";import{t as $e}from"./spinner-DyNE-o8o.js";import{i as et,t as tt}from"./useDeleteCell-2_bMClHd.js";import{r as nt}from"./input-BoBxR50a.js";import{a as rt,c as it,i as at,n as ot,o as st,s as ct,t as lt}from"./datasource-Cq6x_5ML.js";import{t as ut}from"./use-toast-Wu434mLr.js";import{$t as dt,Et as ft,Gt as pt,Jt as mt,Kt as ht,Qt as gt,Tt as _t,at as vt,dt as yt,st as bt,tn as xt,ut as St}from"./dist-Cny7_yZb.js";import{t as Ct}from"./createReducer-DgRODTW6.js";import{h as wt,n as Tt,o as Et,r as Dt}from"./dist-qhAY4L2r.js";import{t as Ot}from"./requests-lt0JK8Jt.js";import{a as kt}from"./dist-LSsCJjA3.js";import{t as At}from"./uuid-k9DpjH68.js";import{r as jt}from"./useTheme-COhSHkCj.js";import{n as Mt}from"./useRunCells-B2vUhREg.js";import{n as Nt}from"./blob-D5nfNHOo.js";import{a as Pt}from"./errors-DCrsa1nH.js";import{i as Ft}from"./cell-link-LSth_8hT.js";import{t as It}from"./html-to-image-DK9Zl1lU.js";import{n as Lt}from"./renderShortcut-BkVJQ_Zh.js";import{n as Rt}from"./icons-CiZ_8zS-.js";import{r as zt,t as Bt}from"./esm-CI_o7NhW.js";import{t as Vt}from"./process-output-D0KGq04R.js";import{i as Ht,r as Ut,t as Wt}from"./error-entries-Dk3VZ-OK.js";var Gt=Be(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Kt=Be(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),qt=Be(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),A=we(),Jt=`vercel.ai.error`,Yt=Symbol.for(Jt),Xt,Zt,j=class e extends (Zt=Error,Xt=Yt,Zt){constructor({name:e,message:t,cause:n}){super(t),this[Xt]=!0,this.name=e,this.cause=n}static isInstance(t){return e.hasMarker(t,Jt)}static hasMarker(e,t){let n=Symbol.for(t);return typeof e==`object`&&!!e&&n in e&&typeof e[n]==`boolean`&&e[n]===!0}},Qt=`AI_APICallError`,$t=`vercel.ai.error.${Qt}`,en=Symbol.for($t),tn,nn,rn=class extends (nn=j,tn=en,nn){constructor({message:e,url:t,requestBodyValues:n,statusCode:r,responseHeaders:i,responseBody:a,cause:o,isRetryable:s=r!=null&&(r===408||r===409||r===429||r>=500),data:c}){super({name:Qt,message:e,cause:o}),this[tn]=!0,this.url=t,this.requestBodyValues=n,this.statusCode=r,this.responseHeaders=i,this.responseBody=a,this.isRetryable=s,this.data=c}static isInstance(e){return j.hasMarker(e,$t)}},an=`AI_EmptyResponseBodyError`,on=`vercel.ai.error.${an}`,sn=Symbol.for(on),cn,ln,un=class extends (ln=j,cn=sn,ln){constructor({message:e=`Empty response body`}={}){super({name:an,message:e}),this[cn]=!0}static isInstance(e){return j.hasMarker(e,on)}};function dn(e){return e==null?`unknown error`:typeof e==`string`?e:e instanceof Error?e.toString():JSON.stringify(e)}var fn=`AI_InvalidArgumentError`,pn=`vercel.ai.error.${fn}`,mn=Symbol.for(pn),hn,gn,_n=class extends (gn=j,hn=mn,gn){constructor({message:e,cause:t,argument:n}){super({name:fn,message:e,cause:t}),this[hn]=!0,this.argument=n}static isInstance(e){return j.hasMarker(e,pn)}},vn=`AI_JSONParseError`,yn=`vercel.ai.error.${vn}`,bn=Symbol.for(yn),xn,Sn,Cn=class extends (Sn=j,xn=bn,Sn){constructor({text:e,cause:t}){super({name:vn,message:`JSON parsing failed: Text: ${e}.
1
+ import{a as e,t}from"./rolldown-runtime-B0Z9INg1.js";import{a as n,c as r,d as i,f as a,l as o,r as s,t as c}from"./useEvent-Dfcbgjhg.js";import{t as l}from"./react-DVplv7_D.js";import{Bt as u,D as d,Fa as f,Fi as p,In as m,Pi as h,Qr as g,Ti as _,Va as v,Z as y,Zn as b,_a as x,b as S,bo as C,da as ee,f as te,ft as ne,ir as w,ja as T,ji as E,qa as re,ti as ie,yo as ae}from"./cells-rA_jsZCj.js";import{A as oe,B as se,C as ce,D as le,E as ue,I as de,L as fe,N as pe,P as D,R as me,S as he,T as ge,W as _e,_ as ve,j as O,k as ye,v as be,w as xe,x as Se,y as Ce}from"./schemas-Dv42wLFq.js";import{t as we}from"./compiler-runtime-BrajqUja.js";import{t as Te}from"./config-VPSq73n8.js";import{f as Ee,g as k}from"./useEventListener-D9cftcHj.js";import{o as De}from"./session-DqoWmb7X.js";import{A as Oe,O as ke,o as Ae}from"./config-DX8Y2WbJ.js";import{t as je}from"./cn-ldLVeaqm.js";import{t as Me}from"./jsx-runtime-B74pBk57.js";import{a as Ne,c as Pe,p as Fe,r as Ie,t as Le}from"./dropdown-menu-C1rnl-0o.js";import{t as Re}from"./tooltip-C9TuY18o.js";import{t as ze}from"./button-COI-NGrx.js";import{t as Be}from"./createLucideIcon-DfJ2oMlA.js";import{i as Ve,r as He}from"./paths-bkIFVj8h.js";import{r as Ue,t as We}from"./fileToBase64-BgBraYAr.js";import{M as Ge,m as Ke,t as qe}from"./ai-model-dropdown-C6GHHEdR.js";import{r as Je}from"./useNumberFormatter-D7O_26UI.js";import{f as Ye,n as Xe}from"./markdown-renderer-Q5AhbRU3.js";import{t as Ze}from"./file-BPBVl9pl.js";import{t as Qe}from"./image-wZvTj8WY.js";import{t as $e}from"./spinner-DyNE-o8o.js";import{i as et,t as tt}from"./useDeleteCell-DFBGlSQk.js";import{r as nt}from"./input-BoBxR50a.js";import{a as rt,c as it,i as at,n as ot,o as st,s as ct,t as lt}from"./datasource-V0-52XOh.js";import{t as ut}from"./use-toast-Wu434mLr.js";import{$t as dt,Et as ft,Gt as pt,Jt as mt,Kt as ht,Qt as gt,Tt as _t,at as vt,dt as yt,st as bt,tn as xt,ut as St}from"./dist-Cny7_yZb.js";import{t as Ct}from"./createReducer-DgRODTW6.js";import{h as wt,n as Tt,o as Et,r as Dt}from"./dist-qhAY4L2r.js";import{t as Ot}from"./requests-lt0JK8Jt.js";import{a as kt}from"./dist-LSsCJjA3.js";import{t as At}from"./uuid-k9DpjH68.js";import{r as jt}from"./useTheme-COhSHkCj.js";import{n as Mt}from"./useRunCells-BFjFX3hz.js";import{n as Nt}from"./blob-iOBwGaP9.js";import{a as Pt}from"./errors-DCrsa1nH.js";import{i as Ft,r as It,t as Lt}from"./error-entries-DOWpdGvI.js";import{i as Rt}from"./cell-link-1CynTVGQ.js";import{t as zt}from"./html-to-image-DK9Zl1lU.js";import{n as Bt}from"./renderShortcut-BkVJQ_Zh.js";import{n as Vt}from"./icons-CiZ_8zS-.js";import{r as Ht,t as Ut}from"./esm-CI_o7NhW.js";import{t as Wt}from"./process-output-DNFKMODr.js";var Gt=Be(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Kt=Be(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),qt=Be(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),A=we(),Jt=`vercel.ai.error`,Yt=Symbol.for(Jt),Xt,Zt,j=class e extends (Zt=Error,Xt=Yt,Zt){constructor({name:e,message:t,cause:n}){super(t),this[Xt]=!0,this.name=e,this.cause=n}static isInstance(t){return e.hasMarker(t,Jt)}static hasMarker(e,t){let n=Symbol.for(t);return typeof e==`object`&&!!e&&n in e&&typeof e[n]==`boolean`&&e[n]===!0}},Qt=`AI_APICallError`,$t=`vercel.ai.error.${Qt}`,en=Symbol.for($t),tn,nn,rn=class extends (nn=j,tn=en,nn){constructor({message:e,url:t,requestBodyValues:n,statusCode:r,responseHeaders:i,responseBody:a,cause:o,isRetryable:s=r!=null&&(r===408||r===409||r===429||r>=500),data:c}){super({name:Qt,message:e,cause:o}),this[tn]=!0,this.url=t,this.requestBodyValues=n,this.statusCode=r,this.responseHeaders=i,this.responseBody=a,this.isRetryable=s,this.data=c}static isInstance(e){return j.hasMarker(e,$t)}},an=`AI_EmptyResponseBodyError`,on=`vercel.ai.error.${an}`,sn=Symbol.for(on),cn,ln,un=class extends (ln=j,cn=sn,ln){constructor({message:e=`Empty response body`}={}){super({name:an,message:e}),this[cn]=!0}static isInstance(e){return j.hasMarker(e,on)}};function dn(e){return e==null?`unknown error`:typeof e==`string`?e:e instanceof Error?e.toString():JSON.stringify(e)}var fn=`AI_InvalidArgumentError`,pn=`vercel.ai.error.${fn}`,mn=Symbol.for(pn),hn,gn,_n=class extends (gn=j,hn=mn,gn){constructor({message:e,cause:t,argument:n}){super({name:fn,message:e,cause:t}),this[hn]=!0,this.argument=n}static isInstance(e){return j.hasMarker(e,pn)}},vn=`AI_JSONParseError`,yn=`vercel.ai.error.${vn}`,bn=Symbol.for(yn),xn,Sn,Cn=class extends (Sn=j,xn=bn,Sn){constructor({text:e,cause:t}){super({name:vn,message:`JSON parsing failed: Text: ${e}.
2
2
  Error message: ${dn(t)}`,cause:t}),this[xn]=!0,this.text=e}static isInstance(e){return j.hasMarker(e,yn)}},wn=`AI_TypeValidationError`,Tn=`vercel.ai.error.${wn}`,En=Symbol.for(Tn),Dn,On,M=class e extends (On=j,Dn=En,On){constructor({value:e,cause:t,context:n}){let r=`Type validation failed`;if(n?.field&&(r+=` for ${n.field}`),n?.entityName||n?.entityId){r+=` (`;let e=[];n.entityName&&e.push(n.entityName),n.entityId&&e.push(`id: "${n.entityId}"`),r+=e.join(`, `),r+=`)`}super({name:wn,message:`${r}: Value: ${JSON.stringify(e)}.
3
3
  Error message: ${dn(t)}`,cause:t}),this[Dn]=!0,this.value=e,this.context=n}static isInstance(e){return j.hasMarker(e,Tn)}static wrap({value:t,cause:n,context:r}){return e.isInstance(n)&&n.value===t&&n.context?.field===r?.field&&n.context?.entityName===r?.entityName&&n.context?.entityId===r?.entityId?n:new e({value:t,cause:n,context:r})}},kn=`AI_UnsupportedFunctionalityError`,An=`vercel.ai.error.${kn}`,jn=Symbol.for(An),Mn,Nn,Pn=class extends (Nn=j,Mn=jn,Nn){constructor({functionality:e,message:t=`'${e}' functionality not supported.`}){super({name:kn,message:t}),this[Mn]=!0,this.functionality=e}static isInstance(e){return j.hasMarker(e,An)}},Fn=class extends Error{constructor(e,t){super(e),this.name=`ParseError`,this.type=t.type,this.field=t.field,this.value=t.value,this.line=t.line}},In=10,Ln=13,Rn=32;function zn(e){}function Bn(e){if(typeof e==`function`)throw TypeError("`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?");let{onEvent:t=zn,onError:n=zn,onRetry:r=zn,onComment:i,maxBufferSize:a}=e,o=[],s=0,c=!0,l,u=``,d=0,f,p=!1;function m(e){if(p)throw Error("Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing.");if(c&&(c=!1,e.charCodeAt(0)===239&&e.charCodeAt(1)===187&&e.charCodeAt(2)===191&&(e=e.slice(3))),o.length===0){let t=g(e);t!==``&&(o.push(t),s=t.length),h();return}if(e.indexOf(`
4
4
  `)===-1&&e.indexOf(`\r`)===-1){o.push(e),s+=e.length,h();return}o.push(e);let t=o.join(``);o.length=0,s=0;let n=g(t);n!==``&&(o.push(n),s=n.length),h()}function h(){a!==void 0&&(s+u.length<=a||(p=!0,o.length=0,s=0,l=void 0,u=``,d=0,f=void 0,n(new Fn(`Buffered data exceeded max buffer size of ${a} characters`,{type:`max-buffer-size-exceeded`}))))}function g(e){let n=0;if(e.indexOf(`\r`)===-1){let r=e.indexOf(`
@@ -41,17 +41,17 @@ ${t}`,d++;break;case`id`:l=t.includes(`\0`)?void 0:t;break;case`retry`:/^\d+$/.t
41
41
  - SQL cells: use mo.sql(f"""{content}""") function to insert content. If a database engine is specified, use mo.sql(f"""{content}""", engine=engine) instead.
42
42
 
43
43
  Returns:
44
- - A result object containing standard tool metadata.`},zo=O({edit:O({type:ve([`update_cell`,`add_cell`,`delete_cell`]),code:D().optional(),position:O({type:ve([`relative`,`column_end`,`notebook_end`]).optional(),cellId:D().optional(),columnIndex:oe().optional(),before:he().optional()})})}),Bo=class{name=`edit_notebook_tool`;description=Ro;schema=zo;outputSchema=xo;mode=[`agent`];handler=async({edit:e},t)=>{let{addStagedCell:n,createNewCell:r,store:i}=t;switch(e.type){case`update_cell`:{let{position:t,code:r}=e,a=t.cellId;if(!a)throw new Y(`Cell ID is required for update_cell`,`CELL_ID_REQUIRED_FOR_UPDATE_CELL`,!0,`Provide a cell ID to update`);if(!r)throw new Y(`Code is required for update_cell`,`CODE_REQUIRED_FOR_UPDATE_CELL`,!0,`Provide the new code to update the cell`);let o=i.get(S);this.validateCellIdExists(a,o);let s=this.getCellEditorView(a,o);Ft(a);let c=i.get(Z).get(a);if(c?.type===`add_cell`){ne(s,r);break}let l=s.state.doc.toString(),u=c?.previousCode??l;if(r===u)break;n({cellId:a,edit:{type:`update_cell`,previousCode:u}}),ne(s,r);break}case`add_cell`:{let{position:t,code:a}=e,o=`__end__`,s=!1,c=ae.create(),l=i.get(S);switch(t.type){case`relative`:{let e=t.cellId;if(!e)throw new Y(`Cell ID is required for add_cell with relative position`,`TOOL_ERROR`,!0,`Provide a cell ID to add the cell before`);if(t.before===void 0)throw new Y(`Before is required for add_cell with relative position`,`TOOL_ERROR`,!0,`Provide a boolean value for before, true to add before cell ${e}, false to add after the cell`);this.validateCellIdExists(e,l),o=e,s=t.before;break}case`column_end`:if(!t.columnIndex)throw new Y(`Column index is required for add_cell with column_end position`,`TOOL_ERROR`,!0,`Provide a column index to add the cell at the end of`);o={type:`__end__`,columnId:this.getColumnId(t.columnIndex,l)}}r({cellId:o,before:s,code:a,newCellId:c}),n({cellId:c,edit:{type:`add_cell`}}),Ft(c);break}case`delete_cell`:{let{position:t}=e,r=t.cellId;if(!r)throw new Y(`Cell ID is required for delete_cell`,`CELL_ID_REQUIRED_FOR_DELETE_CELL`,!0,`Provide a cell ID to delete`);let a=i.get(S);this.validateCellIdExists(r,a),n({cellId:r,edit:{type:`delete_cell`,previousCode:this.getCellEditorView(r,a).state.doc.toString()}}),Ft(r);break}}return{status:`success`,next_steps:[`If you need to perform more edits, call this tool again.`,`You should use the lint notebook tool to check for errors and lint issues. Fix them by editing the notebook.`,`You should use the run stale cells tool to run the cells that have been edited or newly added. This allows you to see the output of the cells and fix any errors.`]}};validateCellIdExists(e,t){if(!t.cellIds.getColumns().some(t=>t.idSet.has(e)))throw new Y(`Cell not found`,`CELL_NOT_FOUND`,!1,`Check which cells exist in the notebook`)}getColumnId(e,t){let n=t.cellIds.getColumns();if(e<0||e>=n.length)throw new Y(`Column index is out of range`,`COLUMN_INDEX_OUT_OF_RANGE`,!0,`Choose a column index between 0 and the number of columns in the notebook (0-based)`);return n[e].id}getCellEditorView(e,t){let n=t.cellHandles[e].current;if(!n?.editorView)throw new Y(`Cell editor not found`,`CELL_EDITOR_NOT_FOUND`,!1,`Internal error, ask the user to report this error`);return n.editorView}};function Vo(e,t){return e?!!([`image/`,`video/`,`audio/`,`application/pdf`].some(t=>e.startsWith(t))||[`svg`,`vega`].some(t=>e.includes(t))||e===`text/html`&&[`<img`,`<video`,`<audio`,`<iframe`,`<canvas`,`<svg`,`<marimo-ui-element`].some(e=>t.includes(e))):!1}var Ho=class extends ct{title=`Cell Outputs`;mentionPrefix=`@`;contextType=`cell-output`;store;constructor(e){super(),this.store=e}getItems(){let e=this.store.get(S),t=[];for(let n of e.cellIds.inOrderIds){let r=Go(n,e),i=r.cellOutput;if(!i)continue;let a=i.output.mimetype||`unknown`;t.push({uri:this.asURI(n),name:r.cellName,type:this.contextType,description:`Cell output (${a})`,data:{...r,cellOutput:i}})}return t}formatCompletion(e){let{cellOutput:t,cellName:n,cellCode:r}=e.data;return{label:`@${n}`,displayLabel:n,detail:`${t.outputType} output`,boost:t.outputType===`media`?at.HIGH:at.MEDIUM,type:this.contextType,section:rt.CELL_OUTPUT,apply:`@${n}`,info:()=>{let e=document.createElement(`div`);e.classList.add(`mo-cm-tooltip`,`docs-documentation`,`min-w-[300px]`,`max-w-[500px]`,`flex`,`flex-col`,`gap-2`);let i=document.createElement(`div`);i.classList.add(`flex`,`flex-col`,`gap-1`);let a=document.createElement(`div`);a.classList.add(`font-bold`,`text-base`),a.textContent=n,i.append(a);let o=document.createElement(`div`);if(o.classList.add(`text-sm`,`text-muted-foreground`),i.append(o),e.append(i),r){let t=document.createElement(`div`);t.classList.add(`text-xs`,`font-medium`,`text-muted-foreground`),t.textContent=`Code:`,e.append(t);let n=document.createElement(`div`);n.classList.add(`text-xs`,`font-mono`,`bg-muted`,`p-2`,`rounded`,`max-h-20`,`overflow-y-auto`),n.textContent=r.slice(0,200)+(r.length>200?`...`:``),e.append(n)}if(t.processedContent){let n=document.createElement(`div`);n.classList.add(`text-xs`,`font-medium`,`text-muted-foreground`,`mt-2`),n.textContent=`Output Preview:`,e.append(n);let r=document.createElement(`div`);r.classList.add(`text-xs`,`bg-muted`,`p-2`,`rounded`,`max-h-24`,`overflow-y-auto`,`mb-2`),r.textContent=t.processedContent.slice(0,300)+(t.processedContent.length>300?`...`:``),e.append(r)}if(t.outputType===`media`){let t=document.createElement(`div`);t.classList.add(`text-xs`,`text-muted-foreground`,`italic`,`mb-2`),t.textContent=`A screenshot of the output will be attached`,e.append(t)}return e}}}formatContext(e){let{cellOutput:t,cellName:n,cellId:r,cellCode:i}=e.data,a={name:n,cellId:r,outputType:t.outputType,mimetype:t.output.mimetype},o=`Cell Code:\n${i}\n\n`;return t.outputType===`text`&&t.processedContent?o+=`Output:\n${t.processedContent}`:t.outputType===`media`&&(o+=`Media Output: Contains ${t.output.mimetype} content`,t.imageUrl&&(o+=`\nImage URL: ${t.imageUrl}`)),st({type:this.contextType,data:a,details:o})}async getAttachments(e){let t=e[0].data.cellId,n=e[0].data.cellName;return Uo(e.map(e=>e.data.cellOutput),t,n)}};async function Uo(e,t,n){let r=e.filter(e=>e.shouldDownloadImage&&e.outputType===`media`);if(r.length===0)return[];let i=r.flatMap(e=>{let r=document.getElementById(C.create(t));return r?{cellId:t,cellName:n,mimetype:e.output.mimetype,element:r}:(k.warn(`Output element not found for cell ${t}`),[])});try{return await Promise.all(i.map(async e=>({type:`file`,filename:`${n}-output-screenshot`,mediaType:`image/png`,url:await It(e.element)})))}catch(e){return k.error(`Error downloading cell output images:`,e),[]}}function Wo(e){if(Xe(e))return null;let t=e.mimetype,n=Vo(t,String(e.data))?`media`:`text`,r=Vt(e),i,a=!1;return n===`media`&&(typeof e.data==`string`&&e.data.startsWith(`data:`)||typeof e.data==`string`&&e.data.startsWith(`http`)?i=e.data:a=!0),{processedContent:r,imageUrl:i,shouldDownloadImage:a,outputType:n,output:e}}function Go(e,t,n){let{includeConsoleOutput:r=!1}=n||{},i=t.cellRuntime[e],a=t.cellData[e],o=t.cellIds.inOrderIds.indexOf(e),s=m(a.name,o),c;r&&(c=i.consoleOutputs.map(e=>Wo(e)).filter(e=>e!==null));let l,u=i.output;return u&&!Xe(u)&&(l=Wo(u)??void 0),{cellId:e,cellName:s,cellCode:a.code,cellOutput:l,consoleOutputs:c}}var Ko=200,qo=3e4,Jo=2e3,Yo=3e3,Xo=4e4,Zo={baseDescription:`Run cells in the current notebook that are stale. Stale cells are cells that have been edited or newly added. You can run this tool after editing the notebook or when requested. The output of the ran cells will be returned alongside metadata.`},Qo=O({type:ue(`file`),url:D(),mediaType:D()}),$o=class{name=`run_stale_cells_tool`;description=Zo;schema=O({});outputSchema=xo.extend({cellsToOutput:pe(D(),O({consoleOutput:D().optional(),cellOutput:D().optional(),consoleAttachments:Se(Qo).optional(),cellAttachments:Se(Qo).optional()}).nullable()).optional()});mode=[`agent`];postExecutionDelay;constructor(e){this.postExecutionDelay=e?.postExecutionDelay??Ko}handler=async(e,t)=>{let{prepareForRun:n,sendRun:r,store:i}=t,a=i.get(S),o=ee(a);if(o.length===0)return{status:`success`,message:`No stale cells found.`};if(await Mt({cellIds:o,sendRun:r,prepareForRun:n,notebook:a}),!await this.waitForCellsToFinish(i,o,qo,this.postExecutionDelay))return{status:`success`,message:`No output was returned because some cells have not finished executing`};let s=i.get(S),c=new Map,l=!1,u=!1,d=0;for(let e of o){let t=Go(e,s,{includeConsoleOutput:!0}),n=t.cellOutput,r=t.consoleOutputs,i=r&&r.length>0;if((n&&this.outputHasErrors(n)||i&&r.some(e=>this.outputHasErrors(e)))&&(l=!0),!n&&!i){c.set(e,null);continue}if(d>=Xo){c.set(e,{cellOutput:`Cell executed (output omitted due to context limits).`});continue}let a,o;n&&(a=this.formatOutputString(n),d+=a.length),i&&(u=!0,o=r.map(e=>this.formatOutputString(e)).join(`
44
+ - A result object containing standard tool metadata.`},zo=O({edit:O({type:ve([`update_cell`,`add_cell`,`delete_cell`]),code:D().optional(),position:O({type:ve([`relative`,`column_end`,`notebook_end`]).optional(),cellId:D().optional(),columnIndex:oe().optional(),before:he().optional()})})}),Bo=class{name=`edit_notebook_tool`;description=Ro;schema=zo;outputSchema=xo;mode=[`agent`];handler=async({edit:e},t)=>{let{addStagedCell:n,createNewCell:r,store:i}=t;switch(e.type){case`update_cell`:{let{position:t,code:r}=e,a=t.cellId;if(!a)throw new Y(`Cell ID is required for update_cell`,`CELL_ID_REQUIRED_FOR_UPDATE_CELL`,!0,`Provide a cell ID to update`);if(!r)throw new Y(`Code is required for update_cell`,`CODE_REQUIRED_FOR_UPDATE_CELL`,!0,`Provide the new code to update the cell`);let o=i.get(S);this.validateCellIdExists(a,o);let s=this.getCellEditorView(a,o);Rt(a);let c=i.get(Z).get(a);if(c?.type===`add_cell`){ne(s,r);break}let l=s.state.doc.toString(),u=c?.previousCode??l;if(r===u)break;n({cellId:a,edit:{type:`update_cell`,previousCode:u}}),ne(s,r);break}case`add_cell`:{let{position:t,code:a}=e,o=`__end__`,s=!1,c=ae.create(),l=i.get(S);switch(t.type){case`relative`:{let e=t.cellId;if(!e)throw new Y(`Cell ID is required for add_cell with relative position`,`TOOL_ERROR`,!0,`Provide a cell ID to add the cell before`);if(t.before===void 0)throw new Y(`Before is required for add_cell with relative position`,`TOOL_ERROR`,!0,`Provide a boolean value for before, true to add before cell ${e}, false to add after the cell`);this.validateCellIdExists(e,l),o=e,s=t.before;break}case`column_end`:if(!t.columnIndex)throw new Y(`Column index is required for add_cell with column_end position`,`TOOL_ERROR`,!0,`Provide a column index to add the cell at the end of`);o={type:`__end__`,columnId:this.getColumnId(t.columnIndex,l)}}r({cellId:o,before:s,code:a,newCellId:c}),n({cellId:c,edit:{type:`add_cell`}}),Rt(c);break}case`delete_cell`:{let{position:t}=e,r=t.cellId;if(!r)throw new Y(`Cell ID is required for delete_cell`,`CELL_ID_REQUIRED_FOR_DELETE_CELL`,!0,`Provide a cell ID to delete`);let a=i.get(S);this.validateCellIdExists(r,a),n({cellId:r,edit:{type:`delete_cell`,previousCode:this.getCellEditorView(r,a).state.doc.toString()}}),Rt(r);break}}return{status:`success`,next_steps:[`If you need to perform more edits, call this tool again.`,`You should use the lint notebook tool to check for errors and lint issues. Fix them by editing the notebook.`,`You should use the run stale cells tool to run the cells that have been edited or newly added. This allows you to see the output of the cells and fix any errors.`]}};validateCellIdExists(e,t){if(!t.cellIds.getColumns().some(t=>t.idSet.has(e)))throw new Y(`Cell not found`,`CELL_NOT_FOUND`,!1,`Check which cells exist in the notebook`)}getColumnId(e,t){let n=t.cellIds.getColumns();if(e<0||e>=n.length)throw new Y(`Column index is out of range`,`COLUMN_INDEX_OUT_OF_RANGE`,!0,`Choose a column index between 0 and the number of columns in the notebook (0-based)`);return n[e].id}getCellEditorView(e,t){let n=t.cellHandles[e].current;if(!n?.editorView)throw new Y(`Cell editor not found`,`CELL_EDITOR_NOT_FOUND`,!1,`Internal error, ask the user to report this error`);return n.editorView}};function Vo(e,t){return e?!!([`image/`,`video/`,`audio/`,`application/pdf`].some(t=>e.startsWith(t))||[`svg`,`vega`].some(t=>e.includes(t))||e===`text/html`&&[`<img`,`<video`,`<audio`,`<iframe`,`<canvas`,`<svg`,`<marimo-ui-element`].some(e=>t.includes(e))):!1}var Ho=class extends ct{title=`Cell Outputs`;mentionPrefix=`@`;contextType=`cell-output`;store;constructor(e){super(),this.store=e}getItems(){let e=this.store.get(S),t=[];for(let n of e.cellIds.inOrderIds){let r=Go(n,e),i=r.cellOutput;if(!i)continue;let a=i.output.mimetype||`unknown`;t.push({uri:this.asURI(n),name:r.cellName,type:this.contextType,description:`Cell output (${a})`,data:{...r,cellOutput:i}})}return t}formatCompletion(e){let{cellOutput:t,cellName:n,cellCode:r}=e.data;return{label:`@${n}`,displayLabel:n,detail:`${t.outputType} output`,boost:t.outputType===`media`?at.HIGH:at.MEDIUM,type:this.contextType,section:rt.CELL_OUTPUT,apply:`@${n}`,info:()=>{let e=document.createElement(`div`);e.classList.add(`mo-cm-tooltip`,`docs-documentation`,`min-w-[300px]`,`max-w-[500px]`,`flex`,`flex-col`,`gap-2`);let i=document.createElement(`div`);i.classList.add(`flex`,`flex-col`,`gap-1`);let a=document.createElement(`div`);a.classList.add(`font-bold`,`text-base`),a.textContent=n,i.append(a);let o=document.createElement(`div`);if(o.classList.add(`text-sm`,`text-muted-foreground`),i.append(o),e.append(i),r){let t=document.createElement(`div`);t.classList.add(`text-xs`,`font-medium`,`text-muted-foreground`),t.textContent=`Code:`,e.append(t);let n=document.createElement(`div`);n.classList.add(`text-xs`,`font-mono`,`bg-muted`,`p-2`,`rounded`,`max-h-20`,`overflow-y-auto`),n.textContent=r.slice(0,200)+(r.length>200?`...`:``),e.append(n)}if(t.processedContent){let n=document.createElement(`div`);n.classList.add(`text-xs`,`font-medium`,`text-muted-foreground`,`mt-2`),n.textContent=`Output Preview:`,e.append(n);let r=document.createElement(`div`);r.classList.add(`text-xs`,`bg-muted`,`p-2`,`rounded`,`max-h-24`,`overflow-y-auto`,`mb-2`),r.textContent=t.processedContent.slice(0,300)+(t.processedContent.length>300?`...`:``),e.append(r)}if(t.outputType===`media`){let t=document.createElement(`div`);t.classList.add(`text-xs`,`text-muted-foreground`,`italic`,`mb-2`),t.textContent=`A screenshot of the output will be attached`,e.append(t)}return e}}}formatContext(e){let{cellOutput:t,cellName:n,cellId:r,cellCode:i}=e.data,a={name:n,cellId:r,outputType:t.outputType,mimetype:t.output.mimetype},o=`Cell Code:\n${i}\n\n`;return t.outputType===`text`&&t.processedContent?o+=`Output:\n${t.processedContent}`:t.outputType===`media`&&(o+=`Media Output: Contains ${t.output.mimetype} content`,t.imageUrl&&(o+=`\nImage URL: ${t.imageUrl}`)),st({type:this.contextType,data:a,details:o})}async getAttachments(e){let t=e[0].data.cellId,n=e[0].data.cellName;return Uo(e.map(e=>e.data.cellOutput),t,n)}};async function Uo(e,t,n){let r=e.filter(e=>e.shouldDownloadImage&&e.outputType===`media`);if(r.length===0)return[];let i=r.flatMap(e=>{let r=document.getElementById(C.create(t));return r?{cellId:t,cellName:n,mimetype:e.output.mimetype,element:r}:(k.warn(`Output element not found for cell ${t}`),[])});try{return await Promise.all(i.map(async e=>({type:`file`,filename:`${n}-output-screenshot`,mediaType:`image/png`,url:await zt(e.element)})))}catch(e){return k.error(`Error downloading cell output images:`,e),[]}}function Wo(e){if(Xe(e))return null;let t=e.mimetype,n=Vo(t,String(e.data))?`media`:`text`,r=Wt(e),i,a=!1;return n===`media`&&(typeof e.data==`string`&&e.data.startsWith(`data:`)||typeof e.data==`string`&&e.data.startsWith(`http`)?i=e.data:a=!0),{processedContent:r,imageUrl:i,shouldDownloadImage:a,outputType:n,output:e}}function Go(e,t,n){let{includeConsoleOutput:r=!1}=n||{},i=t.cellRuntime[e],a=t.cellData[e],o=t.cellIds.inOrderIds.indexOf(e),s=m(a.name,o),c;r&&(c=i.consoleOutputs.map(e=>Wo(e)).filter(e=>e!==null));let l,u=i.output;return u&&!Xe(u)&&(l=Wo(u)??void 0),{cellId:e,cellName:s,cellCode:a.code,cellOutput:l,consoleOutputs:c}}var Ko=200,qo=3e4,Jo=2e3,Yo=3e3,Xo=4e4,Zo={baseDescription:`Run cells in the current notebook that are stale. Stale cells are cells that have been edited or newly added. You can run this tool after editing the notebook or when requested. The output of the ran cells will be returned alongside metadata.`},Qo=O({type:ue(`file`),url:D(),mediaType:D()}),$o=class{name=`run_stale_cells_tool`;description=Zo;schema=O({});outputSchema=xo.extend({cellsToOutput:pe(D(),O({consoleOutput:D().optional(),cellOutput:D().optional(),consoleAttachments:Se(Qo).optional(),cellAttachments:Se(Qo).optional()}).nullable()).optional()});mode=[`agent`];postExecutionDelay;constructor(e){this.postExecutionDelay=e?.postExecutionDelay??Ko}handler=async(e,t)=>{let{prepareForRun:n,sendRun:r,store:i}=t,a=i.get(S),o=ee(a);if(o.length===0)return{status:`success`,message:`No stale cells found.`};if(await Mt({cellIds:o,sendRun:r,prepareForRun:n,notebook:a}),!await this.waitForCellsToFinish(i,o,qo,this.postExecutionDelay))return{status:`success`,message:`No output was returned because some cells have not finished executing`};let s=i.get(S),c=new Map,l=!1,u=!1,d=0;for(let e of o){let t=Go(e,s,{includeConsoleOutput:!0}),n=t.cellOutput,r=t.consoleOutputs,i=r&&r.length>0;if((n&&this.outputHasErrors(n)||i&&r.some(e=>this.outputHasErrors(e)))&&(l=!0),!n&&!i){c.set(e,null);continue}if(d>=Xo){c.set(e,{cellOutput:`Cell executed (output omitted due to context limits).`});continue}let a,o;n&&(a=this.formatOutputString(n),d+=a.length),i&&(u=!0,o=r.map(e=>this.formatOutputString(e)).join(`
45
45
  `),o=this.truncateString(o,Jo),d+=o.length),c.set(e,{cellOutput:a,consoleOutput:o})}if(c.size===0)return{status:`success`,message:`Stale cells have been run. No output was returned.`};let f=[`Review the output of the cells. The CellId is the key of the result object.`,l?`There are errors in the cells. Please fix them by using the edit notebook tool and the given CellIds.`:`You may edit the notebook further with the given CellIds.`];return{status:`success`,cellsToOutput:Object.fromEntries(c),message:u?`Console output represents the stdout or stderr of the cell (eg. print statements).`:void 0,next_steps:f}};outputHasErrors(e){return e.output.mimetype===`application/vnd.marimo+error`||e.output.mimetype===`application/vnd.marimo+traceback`}formatOutputString(e){let{outputType:t,processedContent:n,imageUrl:r,output:i}=e;if(t===`media`){let e=`Media Output: Contains ${i.mimetype} content`;return r?`${e}\nImage URL: ${r}`:e}if(i.mimetype===`text/html`)return`HTML Output: text/html content (${(typeof i.data==`string`?i.data.length:JSON.stringify(i.data).length).toLocaleString()} chars). Full output visible in notebook UI.`;let a=this.outputHasErrors(e)?Yo:Jo,o=n;return o||=typeof i.data==`string`?i.data:JSON.stringify(i.data),`Output:\n${this.truncateString(o,a)}`}truncateString(e,t){return e.length<=t?e:`${e.slice(0,t)}\n\n[TRUNCATED: ${e.length.toLocaleString()} → ${t.toLocaleString()} chars. Full output visible in the notebook UI.]`}async waitForCellsToFinish(e,t,r,i){let a=e=>t.every(t=>{let n=e.cellRuntime[t];return n?.status!==`running`&&n?.status!==`queued`}),o=async()=>(i>0&&await new Promise(e=>setTimeout(e,i)),!0);if(a(e.get(S)))return await o();try{return await Promise.race([n(S,a),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),r))]),await o()}catch{return!1}}};function es(e){let t=e.baseDescription;return e.whenToUse&&(t+=`\n\n## When to use:\n- ${e.whenToUse.join(`
46
46
  - `)}`),e.avoidIf&&(t+=`\n\n## Avoid if:\n- ${e.avoidIf.join(`
47
47
  - `)}`),e.prerequisites&&(t+=`\n\n## Prerequisites:\n- ${e.prerequisites.join(`
48
48
  - `)}`),e.sideEffects&&(t+=`\n\n## Side effects:\n- ${e.sideEffects.join(`
49
- - `)}`),e.additionalInfo&&(t+=`\n\n## Additional info:\n- ${e.additionalInfo}`),t}var ts=class{tools=new Map;constructor(e=[]){this.tools=new Map(e.map(e=>[e.name,e]))}has(e){return this.tools.has(e)}getToolOrThrow(e){let t=this.tools.get(e);if(!t)throw Error(`Tool ${e} not found`);return t}async invoke({toolName:e,rawArgs:t,toolContext:n}){let r=this.getToolOrThrow(e),i=r.handler,a=r.schema,o=r.outputSchema;try{let r=await a.safeParseAsync(t);if(r.error)throw new Y(`Tool ${e} returned invalid input: ${_e(r.error)}`,`INVALID_ARGUMENTS`,!0,`Please check the arguments and try again.`);let s=r.data,c=await i(s,n),l=await o.safeParseAsync(c);if(l.error){let t=_e(l.error);throw Error(`Tool ${e} returned invalid output: ${t}`)}return{tool_name:e,result:l.data,error:null}}catch(n){return n instanceof Y?{tool_name:e,result:null,error:n.toStructuredString()}:{tool_name:e,result:null,error:new Y(n instanceof Error?n.message:String(n),`TOOL_ERROR`,!1,`Check the error message and try again with valid arguments.`,{args:t,errorType:n?.constructor?.name??typeof n}).toStructuredString()}}}getToolSchemas(e){return[...this.tools.values()].filter(t=>t.mode.includes(e)).map(e=>({name:e.name,description:es(e.description),parameters:se(e.schema),source:`frontend`,mode:e.mode}))}};T([v()],ts.prototype,`getToolSchemas`,null);var ns=new ts([new Bo,new $o]);function rs(e,t){let n=[`Code:\n${e.cellCode}`];if(e.tracebackHtml&&n.push(`Traceback:\n${y(e.tracebackHtml)}`),e.errorData.length>0&&n.push(e.errorData.map(e=>Ut(e)).join(`
49
+ - `)}`),e.additionalInfo&&(t+=`\n\n## Additional info:\n- ${e.additionalInfo}`),t}var ts=class{tools=new Map;constructor(e=[]){this.tools=new Map(e.map(e=>[e.name,e]))}has(e){return this.tools.has(e)}getToolOrThrow(e){let t=this.tools.get(e);if(!t)throw Error(`Tool ${e} not found`);return t}async invoke({toolName:e,rawArgs:t,toolContext:n}){let r=this.getToolOrThrow(e),i=r.handler,a=r.schema,o=r.outputSchema;try{let r=await a.safeParseAsync(t);if(r.error)throw new Y(`Tool ${e} returned invalid input: ${_e(r.error)}`,`INVALID_ARGUMENTS`,!0,`Please check the arguments and try again.`);let s=r.data,c=await i(s,n),l=await o.safeParseAsync(c);if(l.error){let t=_e(l.error);throw Error(`Tool ${e} returned invalid output: ${t}`)}return{tool_name:e,result:l.data,error:null}}catch(n){return n instanceof Y?{tool_name:e,result:null,error:n.toStructuredString()}:{tool_name:e,result:null,error:new Y(n instanceof Error?n.message:String(n),`TOOL_ERROR`,!1,`Check the error message and try again with valid arguments.`,{args:t,errorType:n?.constructor?.name??typeof n}).toStructuredString()}}}getToolSchemas(e){return[...this.tools.values()].filter(t=>t.mode.includes(e)).map(e=>({name:e.name,description:es(e.description),parameters:se(e.schema),source:`frontend`,mode:e.mode}))}};T([v()],ts.prototype,`getToolSchemas`,null);var ns=new ts([new Bo,new $o]);function rs(e,t){let n=[`Code:\n${e.cellCode}`];if(e.tracebackHtml&&n.push(`Traceback:\n${y(e.tracebackHtml)}`),e.errorData.length>0&&n.push(e.errorData.map(e=>It(e)).join(`
50
50
 
51
51
  `)),e.errorData.some(e=>e.type===`sql-error`)){let r=ot(e.cellId,t);r&&n.push(`Database schema:\n${r}`)}return n.join(`
52
52
 
53
- `)}function is(e,t){return st({type:`error`,data:{name:e.cellName||`Cell ${e.cellId}`,cellId:e.cellId},details:rs(e,t)})}function as(e){return e.errorData.length===1?Wt(e.errorData[0]):e.errorData.length>1?`${e.errorData.length} errors`:e.tracebackHtml?y(e.tracebackHtml).trim().split(`
54
- `).find(e=>e.trim())?.trim()||`traceback`:`error`}function os(e){return`Error: ${e.cellName||`Cell ${e.cellId}`}`}var ss=new _(`error`,`errors`),cs=class extends ct{title=`Errors`;mentionPrefix=`@`;contextType=`error`;store;constructor(e){super(),this.store=e}getItems(){let e=Ht(this.store);if(e.length===0)return[];let t=[{uri:this.asURI(`all`),name:`Errors`,type:this.contextType,data:{type:`all-errors`,errors:e},description:`All errors in the notebook`}];for(let n of e)t.push({uri:this.asURI(n.cellId),name:os(n),type:this.contextType,data:{type:`cell-error`,error:n},description:as(n)});return t}formatCompletion(e){if(e.data.type===`all-errors`){let t=e.data.errors.length;return{label:`@Errors`,displayLabel:`Errors`,detail:`${t} ${ss.pluralize(t)}`,type:`error`,apply:`@error://all`,section:rt.ERROR,info:()=>{let e=document.createElement(`div`);e.classList.add(`mo-cm-tooltip`,`docs-documentation`,`min-w-[200px]`,`flex`,`flex-col`,`gap-1`,`p-2`);let n=document.createElement(`div`);n.classList.add(`flex`,`flex-col`,`gap-1`);let r=document.createElement(`div`);r.classList.add(`font-bold`,`text-base`),r.textContent=`Errors`,n.append(r);let i=document.createElement(`div`);return i.classList.add(`text-sm`,`text-muted-foreground`),i.textContent=`${t} ${ss.pluralize(t)}`,n.append(i),e.append(n),e}}}if(e.data.type===`cell-error`){let{error:t}=e.data;return{...this.createBasicCompletion(e,{detail:as(t),type:`error`}),section:rt.ERROR}}return{label:`Error`,displayLabel:`Error`,section:rt.ERROR}}formatContext(e){return(e.data.type===`all-errors`?e.data.errors:[e.data.error]).map(e=>is(e,this.store)).join(`
53
+ `)}function is(e,t){return st({type:`error`,data:{name:e.cellName||`Cell ${e.cellId}`,cellId:e.cellId},details:rs(e,t)})}function as(e){return e.errorData.length===1?Lt(e.errorData[0]):e.errorData.length>1?`${e.errorData.length} errors`:e.tracebackHtml?y(e.tracebackHtml).trim().split(`
54
+ `).find(e=>e.trim())?.trim()||`traceback`:`error`}function os(e){return`Error: ${e.cellName||`Cell ${e.cellId}`}`}var ss=new _(`error`,`errors`),cs=class extends ct{title=`Errors`;mentionPrefix=`@`;contextType=`error`;store;constructor(e){super(),this.store=e}getItems(){let e=Ft(this.store);if(e.length===0)return[];let t=[{uri:this.asURI(`all`),name:`Errors`,type:this.contextType,data:{type:`all-errors`,errors:e},description:`All errors in the notebook`}];for(let n of e)t.push({uri:this.asURI(n.cellId),name:os(n),type:this.contextType,data:{type:`cell-error`,error:n},description:as(n)});return t}formatCompletion(e){if(e.data.type===`all-errors`){let t=e.data.errors.length;return{label:`@Errors`,displayLabel:`Errors`,detail:`${t} ${ss.pluralize(t)}`,type:`error`,apply:`@error://all`,section:rt.ERROR,info:()=>{let e=document.createElement(`div`);e.classList.add(`mo-cm-tooltip`,`docs-documentation`,`min-w-[200px]`,`flex`,`flex-col`,`gap-1`,`p-2`);let n=document.createElement(`div`);n.classList.add(`flex`,`flex-col`,`gap-1`);let r=document.createElement(`div`);r.classList.add(`font-bold`,`text-base`),r.textContent=`Errors`,n.append(r);let i=document.createElement(`div`);return i.classList.add(`text-sm`,`text-muted-foreground`),i.textContent=`${t} ${ss.pluralize(t)}`,n.append(i),e.append(n),e}}}if(e.data.type===`cell-error`){let{error:t}=e.data;return{...this.createBasicCompletion(e,{detail:as(t),type:`error`}),section:rt.ERROR}}return{label:`Error`,displayLabel:`Error`,section:rt.ERROR}}formatContext(e){return(e.data.type===`all-errors`?e.data.errors:[e.data.error]).map(e=>is(e,this.store)).join(`
55
55
 
56
56
  `)}},ls=x(),us={maxDepth:3,maxResults:20,defaultResultsLimit:5,includeDirectories:!1},ds=class extends ct{title=`Files`;mentionPrefix=`#`;contextType=`file`;apiRequests;config;constructor(e,t=us){super(),this.apiRequests=e,this.config=t}createCompletionSource(){return async e=>{let t=e.matchBefore(/#[^\s#]*/);if(!t)return null;let n=t.text;if(!n.startsWith(`#`))return null;let r=n.slice(1);if(r.length===0)return this.getDefaultCompletions(t);try{let e=(await this.searchFiles(r)||[]).map(e=>{let t={uri:this.asURI(e.path),name:e.name,type:this.contextType,description:e.isDirectory?`Directory`:`File`,data:{path:e.path,isDirectory:e.isDirectory}};return this.formatCompletion(t)});return{from:t.from,options:e}}catch(e){return k.error(`Failed to search files:`,e),null}}}searchFiles=async(e,t={})=>{let{maxDepth:n,maxResults:r,includeDirectories:i}={...this.config,...t};return(await this.apiRequests.sendSearchFiles({query:e,includeFiles:!0,includeDirectories:i,depth:n,limit:r})).files};async getDefaultCompletions(e){try{for(let t of[`py`,`md`,`csv`])try{let n=await this.searchFiles(t,{maxDepth:1,maxResults:5});if(n&&n.length>0){let t=n.map(e=>{let t={uri:this.asURI(e.path),name:e.name,type:this.contextType,description:e.isDirectory?`Directory`:`File`,data:{path:e.path,isDirectory:e.isDirectory}};return this.formatCompletion(t)});return{from:e.from,options:t}}}catch(e){k.error(`Failed to get default file completions:`,e)}return{from:e.from,options:[]}}catch(e){return k.error(`Failed to get default file completions:`,e),null}}getItems(){return[]}formatCompletion(e){let{data:t,name:n}=e,r=t.isDirectory?`📁`:`📄`;return{...this.createBasicCompletion(e),type:`file`,section:rt.FILE,boost:t.isDirectory?at.MEDIUM:at.LOW,detail:t.path,displayLabel:`${r} ${n}`,apply:async(e,r,i,a)=>{let o=e.state.facet(ls)?.addAttachment;if(!o){k.warn(`No addAttachment callback provided`);return}let s=await this.apiRequests.sendFileDetails({path:t.path}).catch(e=>(ut({title:`Failed to get file details`,description:e.message}),null));if(!s)return;let c=s.mimeType||`text/plain`,l=Nt({contents:s.contents??``,mimeType:c,isBase64:s.isBase64??!1});o(new File([l],n,{type:c})),e.dispatch({changes:{from:i,to:a,insert:``}}),Et(e)},info:()=>{let e=document.createElement(`div`);e.classList.add(`flex`,`flex-col`,`gap-1`,`p-2`);let r=document.createElement(`div`);r.classList.add(`font-bold`),r.textContent=n,e.append(r);let i=document.createElement(`div`);return i.classList.add(`text-xs`,`text-muted-foreground`),i.textContent=t.path,e.append(i),e}}}formatContext(e){let{data:t,name:n}=e;return st({type:this.contextType,data:{name:n,path:t.path,isDirectory:t.isDirectory},details:t.isDirectory?`Directory containing files and subdirectories`:`File`})}},fs=class extends ct{title=`Tables`;mentionPrefix=`@`;contextType=`data`;tablesMap;constructor(e){super(),this.tablesMap=e}getItems(){return[...this.tablesMap.entries()].map(([e,t])=>({uri:this.asURI(e),name:e,type:this.contextType,description:t.source===`memory`?`in-memory`:t.source,data:t}))}formatContext(e){let{data:t}=e,{columns:n,source:r,num_rows:i,num_columns:a,name:o,variable_name:s}=t,c=[i==null?void 0:`${i} rows`,a==null?void 0:`${a} columns`].filter(Boolean).join(`, `),l=``;if(c&&(l+=`Shape: ${c}\n`),s&&(l+=`Variable: ${s}\n`),n&&n.length>0){l+=`Columns:
57
57
  `;for(let e of n){let t=` ${e.name} (${e.type})`;if(e.sample_values&&e.sample_values.length>0){let n=e.sample_values.slice(0,3).map(e=>e===null?`null`:String(e)).join(`, `);t+=` - samples: [${n}]`}l+=`${t}\n`}}return st({type:this.contextType,data:{name:o,source:r??`unknown`},details:l.trim()})}formatCompletion(e){let t=e.data.name,n=e.data;return{label:`@${t}`,displayLabel:t,detail:n.source===`memory`?`in-memory`:n.source,boost:n.source_type===`local`?at.LOCAL_TABLE:at.REMOTE_TABLE,type:p(n),apply:`@${t}`,section:{name:p(n)===`dataframe`?`Dataframe`:`Table`,rank:rt.TABLE.rank},info:()=>this.createTableInfoElement(t,n)}}createTableInfoElement(e,t){let n=document.createElement(`div`);n.classList.add(`mo-cm-tooltip`,`docs-documentation`,`min-w-[200px]`,`flex`,`flex-col`,`gap-1`,`p-2`);let r=document.createElement(`div`);r.classList.add(`flex`,`flex-col`,`gap-1`);let i=document.createElement(`div`);if(i.classList.add(`font-bold`,`text-base`),i.textContent=e,r.append(i),t.source){let e=document.createElement(`div`);e.classList.add(`text-xs`,`text-muted-foreground`),e.textContent=`Source: ${t.source}`,r.append(e)}n.append(r);let a=[t.num_rows==null?void 0:`${t.num_rows} rows`,t.num_columns==null?void 0:`${t.num_columns} columns`].filter(Boolean).join(`, `);if(a){let e=document.createElement(`div`);e.classList.add(`text-xs`,`bg-muted`,`px-2`,`py-1`,`rounded`),e.textContent=a,n.append(e)}if(t.columns&&t.columns.length>0){let e=document.createElement(`div`);e.classList.add(`overflow-auto`,`max-h-60`);let r=document.createElement(`table`);r.classList.add(`w-full`,`text-xs`,`border-collapse`);let i=r.insertRow();i.classList.add(`bg-muted`);let a=i.insertCell();a.classList.add(`p-2`,`font-medium`,`text-left`),a.textContent=`Column`;let o=i.insertCell();o.classList.add(`p-2`,`font-medium`,`text-left`),o.textContent=`Type`;let s=t.columns.some(e=>this.getItemMetadata(t,e)!==void 0),c;s&&(c=i.insertCell(),c.classList.add(`p-2`,`font-medium`,`text-left`),c.textContent=`Metadata`),t.columns.forEach((e,n)=>{let i=r.insertRow();i.classList.add(n%2==0?`bg-background`:`bg-muted/30`);let a=i.insertCell();a.classList.add(`p-2`,`font-mono`),a.textContent=e.name;let o=i.insertCell();if(o.classList.add(`p-2`,`text-muted-foreground`),o.textContent=e.type,s){let n=i.insertCell();n.classList.add(`p-2`);let r=this.getItemMetadata(t,e);r&&n.append(r)}}),e.append(r),n.append(e)}return n}getItemMetadata(e,t){let n=e.primary_keys?.includes(t.name),r=e.indexes?.includes(t.name);if(n||r){let e=document.createElement(`span`);e.textContent=n?`PK`:`IDX`;let t=n?`bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200`:`bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200`;return e.classList.add(`text-xs`,`px-1.5`,`py-0.5`,`rounded-full`,`font-medium`,...t.split(` `)),e}}},ps=class extends ct{title=`Variables`;mentionPrefix=`@`;contextType=`variable`;variables;tablesMap;constructor(e,t){super(),this.variables=e,this.tablesMap=t}getItems(){let e=new Set(this.tablesMap.keys());return Object.entries(this.variables).flatMap(([t,n])=>e.has(t)?[]:[{uri:this.asURI(t),name:t,type:this.contextType,description:n.dataType??``,dataType:n.dataType,data:{variable:n}}])}formatCompletion(e){let{data:t}=e,{variable:n}=t;return{label:`@${n.name}`,displayLabel:n.name,detail:n.dataType??``,type:this.contextType,section:rt.VARIABLE,info:()=>w(n)}}formatContext(e){let{data:t}=e,{variable:n}=t;return st({type:this.contextType,data:{name:n.name,dataType:n.dataType},details:n.value==null?void 0:JSON.stringify(n.value)})}};function ms(e){let t=e.get(h),n=e.get(E),r=e.get(ie);return new it().register(new fs(n)).register(new ps(r,n)).register(new cs(e)).register(new Ho(e)).register(new lt(t.connectionsMap,n))}function hs(){return new ds(Ot())}function gs({input:e}){let t=``;return e.includes(`@`)&&(t=ws(e),k.debug(`Included context`,t)),{includeOtherCode:b(``),context:{plainText:t,schema:[],variables:[]}}}var _s=`data-marimo-context`,vs={marimo:{source:`context`}};function ys(e){return e.type===`file`&&e.providerMetadata?.marimo?.source===vs.marimo.source}function bs(e){return{...e,providerMetadata:{...e.providerMetadata,marimo:{...e.providerMetadata?.marimo,...vs.marimo}}}}async function xs(e){if(!e.includes(`@`))return{plainText:``,contextIds:[],attachments:[]};let t=ms(s),n=t.parseAllContextIds(e);if(n.length===0)return{plainText:``,contextIds:[],attachments:[]};let r=t.formatContextForAI(n),i=[];try{i=(await t.getAttachmentsForContext(n)).map(bs)}catch(e){k.error(`Error getting attachments:`,e)}return{plainText:r,contextIds:n,attachments:i}}async function Ss(e){let{plainText:t,contextIds:n,attachments:r}=await xs(e),i=null;return t.trim()&&(i={type:_s,data:{plainText:t,contextIds:n.map(String)}}),{contextPart:i,attachments:r}}async function Cs({input:e}){let{plainText:t,attachments:n}=await xs(e);return{body:{includeOtherCode:b(``),context:{plainText:t,schema:[],variables:[]}},attachments:n}}function ws(e){let t=ms(s),n=t.parseAllContextIds(e);return t.formatContextForAI(n)}function Ts(e,t=[]){return n=>{let r=e.map(e=>n.matchBefore(e)).find(Boolean);return!r||r&&r.from===r.to&&!n.explicit?null:{from:r?.from,options:[...t]}}}function Es(e){if(e.current?.view){let t=e.current.view.state.selection.main.from;e.current.view.dispatch({changes:{from:t,to:t,insert:`@`},selection:{anchor:t+1,head:t+1}}),e.current.view.focus(),wt(e.current.view)}}var Ds=new Set([`openai`,`google`,`anthropic`]),Os=[`image/*`,`text/*`],ks=52428800;function As(e){return e.length>50?`${e.slice(0,50)}...`:e}async function js(e){return await Promise.all(e.map(async e=>({type:`file`,mediaType:e.type,filename:e.name,url:await We(e,`dataUrl`)})))}function Ms(e){if(e.length===0)return!1;let t=e.at(-1);if(!t||t.role!==`assistant`||!t.parts)return!1;let n=t.parts;return n.length!==0&&n[n.length-1].type===`reasoning`}function Ns(e){return e.map(e=>e.type===`text`?e.text:``).join(`
@@ -63,14 +63,14 @@ ${t}`,d++;break;case`id`:l=t.includes(`\0`)?void 0:t;break;case`retry`:/^\d+$/.t
63
63
  `)}}function yc(e,t){let n=t.debounceMs??mc,{logger:r,resolve:i}=t;return class{view;timer;running=!1;rerun=!1;lastKey=``;destroyed=!1;constructor(e){this.view=e,this.maybeSchedule(e)}update(e){if(e.docChanged){let t=vc(e);if(_c(t.before)){this.maybeSchedule(e.view);return}this.maybeSchedule(e.view,t.after)}}destroy(){this.destroyed=!0,this.clearTimer()}maybeSchedule(e,t){let r=t??e.state.doc.toString();if(!_c(r)){t===void 0&&(this.lastKey=``,this.clearTimer());return}let i=gc(hc(r,e.state.field(Q)));if(i===``){t===void 0&&(this.lastKey=``,this.clearTimer());return}if(i===this.lastKey){this.clearTimer();return}this.clearTimer(),this.timer=setTimeout(()=>{this.timer=void 0,this.run(e)},n)}clearTimer(){this.timer!==void 0&&(clearTimeout(this.timer),this.timer=void 0)}async run(t){if(!this.destroyed){if(this.running){this.rerun=!0;return}this.running=!0;try{do{this.rerun=!1;let n=hc(t.state.doc.toString(),t.state.field(Q));if(n.length===0){this.lastKey=``;break}this.lastKey=gc(n);let r=i?await i(n):await e();if(this.destroyed)return;let a=new Set(n),o=r.filter(e=>a.has(e.uri));if(o.length===0){if(this.rerun)continue;break}t.dispatch({effects:Xs.of(new Map(o.map(e=>[e.uri,e])))}),this.rerun=!0}while(this.rerun)}catch(e){this.lastKey=``,r?.error(`Failed to sync resources:`,e)}finally{this.running=!1}}}}}function bc(e,t={}){return St.fromClass(yc(e,t))}var xc=bt.baseTheme({".cm-resource-widget":{background:`light-dark(rgba(86,156,214,0.08),rgba(86,156,214,0.18))`,borderRadius:`4px`,padding:`2px 4px`,color:`light-dark(#2367a2,#7ecbff)`,fontWeight:`500`},".cm-resource-widget:hover":{background:`light-dark(rgba(86,156,214,0.18),rgba(86,156,214,0.28))`},".cm-not-found-resource-widget":{background:`light-dark(rgba(151,151,151,0.08),rgba(151,151,151,0.18))`,borderRadius:`4px`,padding:`2px 4px`,color:`light-dark(#b00020,#ff8080)`,fontWeight:`500`}}),Sc=`_none_`,Cc=[{uri:``,name:`No resources`,type:Sc,data:{}}],wc={info:`Variables, dataframes, and tables will appear here.`,apply:()=>{}};function Tc(e){let t=ms(e).getAllItems();return t.length===0?Cc:t}function Ec(e){let{language:t,store:n,onAddFiles:r}=e,i=()=>Tc(n);return[t.data.of({autocomplete:$s(async()=>i(),e=>e.type===Sc?wc:ms(n).getProvider(e.type)?.formatCompletion(e)||{})}),mt.high(ft.of([{key:`Tab`,preventDefault:!0,run:e=>Tt(e)}])),ls.of({addAttachment:e=>r?.([e])}),...r?[t.data.of({autocomplete:hs().createCompletionSource()})]:[],ic,pc,bc(i,{logger:k}),Q.init(()=>{let e=Tc(n);return new Map(e.map(e=>[e.uri,e]))}),xc,sc({createTooltip:e=>{let t=ms(n).getProvider(e.type);if(!t)return k.warn(`No provider found for resource`,e),Dc(e.description||e.name);let r=t.formatCompletion(e),i=e.description||e.name;if(!r?.info)return Dc(i);if(typeof r.info==`string`)return Dc(r.info);let a=r.info(r);return a?`dom`in a?{dom:a.dom}:`then`in a?(k.warn(`info is a promise. This is not supported`,a),Dc(i)):{dom:a}:Dc(i)}})]}function Dc(e){let t=document.createElement(`div`);return t.innerHTML=e,{dom:t}}var Oc={accept:`Keep change`,decline:`Revert change`},kc=e=>{let{handleAcceptCompletion:t,handleDeclineCompletion:n,isLoading:r,hasCompletion:i}=e;return e=>{let a=Ee()?e.metaKey:e.ctrlKey;a&&e.key===`Enter`&&!r&&i&&t(),(e.key===`Delete`||e.key===`Backspace`)&&a&&e.shiftKey&&(n(),e.preventDefault(),e.stopPropagation())}},Ac=e=>{let t=(0,A.c)(14),{isLoading:n,onAccept:r,onDecline:i,runCell:a,acceptLabel:o,declineLabel:s,size:c}=e,l;t[0]!==o||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==c?(l=(0,G.jsx)(jc,{isLoading:n,onAccept:r,size:c,runCell:a,label:o}),t[0]=o,t[1]=n,t[2]=r,t[3]=a,t[4]=c,t[5]=l):l=t[5];let u;t[6]!==s||t[7]!==n||t[8]!==i||t[9]!==c?(u=(0,G.jsx)(Mc,{onDecline:i,size:c,label:s,disabled:n}),t[6]=s,t[7]=n,t[8]=i,t[9]=c,t[10]=u):u=t[10];let d;return t[11]!==l||t[12]!==u?(d=(0,G.jsxs)(G.Fragment,{children:[l,u]}),t[11]=l,t[12]=u,t[13]=d):d=t[13],d},jc=e=>{let t=(0,A.c)(33),{isLoading:n,onAccept:r,multipleCompletions:i,size:a,buttonStyles:o,acceptShortcut:s,runCell:c,playButtonStyles:l,borderless:u,label:d}=e,f=i!==void 0&&i,p=a===void 0?`sm`:a,m=u!==void 0&&u,h;t[0]!==r||t[1]!==c?(h=()=>{r(),c&&c()},t[0]=r,t[1]=c,t[2]=h):h=t[2];let g=h,_=d??(f?`Accept all`:`Accept`);if(c){let e=`h-6 text-(--grass-11) bg-(--grass-3)/60
64
64
  hover:bg-(--grass-3) dark:bg-(--grass-4)/80 dark:hover:bg-(--grass-3) font-semibold
65
65
  active:bg-(--grass-5) dark:active:bg-(--grass-4)
66
- border-(--green-6) border hover:shadow-xs rounded-r-none ${m&&`border-none rounded-md rounded-r-none`} ${o}`,i;t[3]===s?i=t[4]:(i=s&&(0,G.jsx)(Lt,{className:`ml-1 inline`,shortcut:s}),t[3]=s,t[4]=i);let a;t[5]!==n||t[6]!==r||t[7]!==p||t[8]!==e||t[9]!==i||t[10]!==_?(a=(0,G.jsxs)(ze,{variant:`text`,size:p,disabled:n,onClick:r,className:e,children:[_,i]}),t[5]=n,t[6]=r,t[7]=p,t[8]=e,t[9]=i,t[10]=_,t[11]=a):a=t[11];let c=`${_} and run ${f?`all cells`:`cell`}`,u=`h-6 text-(--grass-11) bg-(--grass-3)/60
66
+ border-(--green-6) border hover:shadow-xs rounded-r-none ${m&&`border-none rounded-md rounded-r-none`} ${o}`,i;t[3]===s?i=t[4]:(i=s&&(0,G.jsx)(Bt,{className:`ml-1 inline`,shortcut:s}),t[3]=s,t[4]=i);let a;t[5]!==n||t[6]!==r||t[7]!==p||t[8]!==e||t[9]!==i||t[10]!==_?(a=(0,G.jsxs)(ze,{variant:`text`,size:p,disabled:n,onClick:r,className:e,children:[_,i]}),t[5]=n,t[6]=r,t[7]=p,t[8]=e,t[9]=i,t[10]=_,t[11]=a):a=t[11];let c=`${_} and run ${f?`all cells`:`cell`}`,u=`h-6 text-(--grass-11) bg-(--grass-3)/60
67
67
  hover:bg-(--grass-3) dark:bg-(--grass-4)/80 dark:hover:bg-(--grass-3) font-semibold
68
68
  active:bg-(--grass-5) dark:active:bg-(--grass-4)
69
69
  border-(--green-6) border hover:shadow-xs rounded-l-none px-1.5 ${m&&`border-0 border-l`} ${l}`,d;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,G.jsx)(et,{className:`h-2.5 w-2.5`}),t[12]=d):d=t[12];let h;t[13]!==g||t[14]!==n||t[15]!==p||t[16]!==u?(h=(0,G.jsx)(ze,{variant:`text`,size:p,disabled:n,onClick:g,className:u,children:d}),t[13]=g,t[14]=n,t[15]=p,t[16]=u,t[17]=h):h=t[17];let v;t[18]!==h||t[19]!==c?(v=(0,G.jsx)(Re,{content:c,children:h}),t[18]=h,t[19]=c,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==a?(y=(0,G.jsxs)(`div`,{className:`flex`,children:[a,v]}),t[21]=v,t[22]=a,t[23]=y):y=t[23],y}let v=`h-6 text-(--grass-11) bg-(--grass-3)/60
70
70
  hover:bg-(--grass-3) dark:bg-(--grass-4)/80 dark:hover:bg-(--grass-3) font-semibold
71
71
  active:bg-(--grass-5) dark:active:bg-(--grass-4)
72
- border-(--green-6) border hover:shadow-xs rounded px-3 ${o}`,y;t[24]===s?y=t[25]:(y=s&&(0,G.jsx)(Lt,{className:`ml-1 inline`,shortcut:s}),t[24]=s,t[25]=y);let b;return t[26]!==n||t[27]!==r||t[28]!==p||t[29]!==v||t[30]!==y||t[31]!==_?(b=(0,G.jsxs)(ze,{variant:`text`,size:p,disabled:n,onClick:r,className:v,children:[_,y]}),t[26]=n,t[27]=r,t[28]=p,t[29]=v,t[30]=y,t[31]=_,t[32]=b):b=t[32],b},Mc=e=>{let t=(0,A.c)(9),{onDecline:n,disabled:r,multipleCompletions:i,size:a,className:o,declineShortcut:s,borderless:c,label:l}=e,u=r!==void 0&&r,d=i!==void 0&&i,f=a===void 0?`sm`:a,p=`h-6 text-(--red-10) bg-(--red-3)/60 hover:bg-(--red-3)
72
+ border-(--green-6) border hover:shadow-xs rounded px-3 ${o}`,y;t[24]===s?y=t[25]:(y=s&&(0,G.jsx)(Bt,{className:`ml-1 inline`,shortcut:s}),t[24]=s,t[25]=y);let b;return t[26]!==n||t[27]!==r||t[28]!==p||t[29]!==v||t[30]!==y||t[31]!==_?(b=(0,G.jsxs)(ze,{variant:`text`,size:p,disabled:n,onClick:r,className:v,children:[_,y]}),t[26]=n,t[27]=r,t[28]=p,t[29]=v,t[30]=y,t[31]=_,t[32]=b):b=t[32],b},Mc=e=>{let t=(0,A.c)(9),{onDecline:n,disabled:r,multipleCompletions:i,size:a,className:o,declineShortcut:s,borderless:c,label:l}=e,u=r!==void 0&&r,d=i!==void 0&&i,f=a===void 0?`sm`:a,p=`h-6 text-(--red-10) bg-(--red-3)/60 hover:bg-(--red-3)
73
73
  dark:bg-(--red-4)/80 dark:hover:bg-(--red-3) rounded px-3 font-semibold
74
74
  active:bg-(--red-5) dark:active:bg-(--red-4)
75
- border-(--red-6) border hover:shadow-xs ${c!==void 0&&c&&`border-none rounded-md`} ${o}`,m=l??`Reject${d?` all`:``}`,h;t[0]===s?h=t[1]:(h=s&&(0,G.jsx)(Lt,{className:`ml-1 inline`,shortcut:s}),t[0]=s,t[1]=h);let g;return t[2]!==u||t[3]!==n||t[4]!==f||t[5]!==p||t[6]!==m||t[7]!==h?(g=(0,G.jsxs)(ze,{variant:`text`,size:f,disabled:u,onClick:n,className:p,children:[m,h]}),t[2]=u,t[3]=n,t[4]=f,t[5]=p,t[6]=m,t[7]=h,t[8]=g):g=t[8],g},Nc=class{activeAttempt=null;cancel(){this.activeAttempt&&(this.activeAttempt.cancelled=!0)}async run({prepare:e,submit:t,onError:n}){if(this.activeAttempt!==null)return;let r={cancelled:!1};this.activeAttempt=r;try{let n=await e();if(r.cancelled)return;await t(n)}catch(e){r.cancelled||n(e)}finally{this.activeAttempt=null}}},Pc=ke(`marimo:ai-language`,`python`,g),Fc=`marimo:ai-prompt-history`,Ic=new f(Se(D()),()=>[]),Lc=({onClose:e})=>{let t=i(),[n,a]=(0,W.useState)(``),{acceptOwnedStagedCells:s,beginStagedCellGeneration:l,discardOwnedStagedCells:u,finishStagedCellGeneration:d,hasOwnedStagedCells:f,onData:p}=Io(t),[m,h]=r(Pc),g=Ae(),_=(0,W.useRef)(null),v=(0,W.useRef)(new Nc).current,y=(0,W.useRef)(null),{files:b,addFiles:x,removeFile:S}=zs(),C=o(Te),ee=(0,W.useMemo)(()=>new Ha({api:g.getAiURL(`completion`).toString(),headers:()=>g.headers(),prepareSendMessagesRequest:async e=>{let t={...await Ps(e.messages),id:e.id,code:``,prompt:``,language:m};return{api:g.getAiURL(`completion`).toString(),body:t}}}),[m,g]),te=c(e=>{d(!1),ut({title:`Generate with AI failed`,description:Pt(e)})}),{sendMessage:ne,stop:w,status:T}=lo({throttle:100,transport:ee,onData:p,onError:te,onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{d(!e&&!t&&!n&&r===`stop`)}}),E=T===`streaming`||T===`submitted`,ie=f(),ae=c(()=>{v.cancel(),d(!1),w()}),oe=c(()=>{v.cancel(),u(),w()});(0,W.useEffect)(()=>()=>{ae()},[ae]);let se=C?.models?.edit_model||`openai/gpt-4o`,ce=Ge.parse(se).providerId,le=Ds.has(ce),ue=async()=>{E||await v.run({prepare:async()=>(_.current?.view&&yo(_.current.view),b?await js(b):void 0),submit:async e=>{l(),await ne({text:n,files:e})},onError:te})},de=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Rt,{className:`size-4 mr-2`}),`Python`]}),fe=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ve,{className:`size-4 mr-2`}),`SQL`]}),pe=(0,G.jsxs)(Le,{modal:!1,children:[(0,G.jsxs)(Fe,{className:`flex items-center justify-between h-7 text-xs px-2 py-0.5 border rounded-md hover:text-accent-foreground`,"data-testid":`language-button`,children:[m===`python`?de:fe,(0,G.jsx)(Ye,{className:`ml-1 h-3.5 w-3.5 text-muted-foreground/70`})]}),(0,G.jsxs)(Ie,{align:`center`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1 text-sm text-muted-foreground`,children:`Select language`}),(0,G.jsx)(Pe,{}),(0,G.jsx)(Ne,{onClick:()=>h(`python`),children:de}),(0,G.jsx)(Ne,{onClick:()=>h(`sql`),children:fe})]})]}),D=()=>{s()&&e()},me=()=>{oe(),_.current?.view?.focus()},he=()=>{oe(),e()},ge=(0,G.jsxs)(`div`,{className:`flex items-center px-3`,children:[(0,G.jsx)(re,{className:`size-4 text-(--blue-11) mr-2`}),(0,G.jsx)(Rc,{inputRef:_,onClose:he,value:n,onChange:e=>{a(e)},onSubmit:ue,onKeyDown:kc({handleAcceptCompletion:D,handleDeclineCompletion:me,isLoading:E,hasCompletion:ie})}),(0,G.jsx)(ze,{variant:`text`,size:`sm`,className:`mb-0 px-1`,onClick:he,children:(0,G.jsx)(Je,{className:`size-4`})})]}),_e=(0,G.jsxs)(`div`,{className:`px-3 pt-1 flex flex-row items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(qe,{triggerClassName:`h-7 text-xs max-w-64`,iconSize:`small`,forRole:`edit`,showAddCustomModelDocs:!0}),pe,(0,G.jsx)(Ke,{})]}),(0,G.jsxs)(`div`,{className:`flex flex-row items-center`,children:[b.length>0&&(0,G.jsx)(`div`,{className:`flex flex-row gap-1 flex-wrap pr-1`,children:b?.map((e,t)=>(0,G.jsx)(Ws,{file:e,onRemove:()=>S(e)},`${e.name}-${t}`))}),(0,G.jsx)(Ks,{handleAddContext:()=>Es(_),isLoading:E}),le&&(0,G.jsx)(qs,{fileInputRef:y,isLoading:E,onAddFiles:x}),(0,G.jsx)(Gs,{isLoading:E,onStop:ae,onSendClick:ue,isEmpty:!n.trim(),showStopLabel:!0})]})]});return(0,G.jsxs)(`div`,{className:je(`flex flex-col w-full py-2`),children:[ge,_e]})},Rc=e=>{let t=(0,A.c)(35),{value:n,placeholder:r,inputRef:a,className:o,onChange:s,onSubmit:l,onKeyDown:u,onClose:d,onAddFiles:f,additionalCompletions:p,maxHeight:m}=e,h=l,g=d,_=i(),{theme:v}=jt(),y;t[0]===p?y=t[1]:(y=e=>p?Ts([p.triggerCompletionRegex],p.completions)(e):null,t[0]=p,t[1]=y);let b=c(y),x,S,C,ee;if(t[2]!==b||t[3]!==f||t[4]!==_){let e=kt();t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=Dt({}),t[9]=x):x=t[9],S=e,C=Ec({language:e.language,store:_,onAddFiles:f}),ee=e.language.data.of({autocomplete:b}),t[2]=b,t[3]=f,t[4]=_,t[5]=x,t[6]=S,t[7]=C,t[8]=ee}else x=t[5],S=t[6],C=t[7],ee=t[8];let te;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(te=bo({storage:{load:zc,save:Bc}}),t[10]=te):te=t[10];let ne;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(ne=zt(),t[11]=ne):ne=t[11];let w;t[12]===h?w=t[13]:(w=mt.highest(ft.of([{preventDefault:!0,stopPropagation:!0,any:(e,t)=>{let n=t.metaKey||t.ctrlKey||t.shiftKey;if(t.key===`Enter`&&!n)return h(t,e.state.doc.toString()),t.preventDefault(),t.stopPropagation(),!0;if(t.key===`Enter`&&t.shiftKey){let n=e.state.selection.main.from;return e.dispatch({changes:{from:n,to:n,insert:`
76
- `},selection:{anchor:n+1,head:n+1}}),t.preventDefault(),t.stopPropagation(),!0}return!1}}])),t[12]=h,t[13]=w);let T;t[14]===g?T=t[15]:(T=ft.of([{key:`Escape`,preventDefault:!0,stopPropagation:!0,run:()=>(g(),!0)}]),t[14]=g,t[15]=T);let E;t[16]!==x||t[17]!==S||t[18]!==C||t[19]!==ee||t[20]!==w||t[21]!==T?(E=[x,S,C,ee,te,bt.lineWrapping,ne,w,T],t[16]=x,t[17]=S,t[18]=C,t[19]=ee,t[20]=w,t[21]=T,t[22]=E):E=t[22];let re=E,ie;t[23]===o?ie=t[24]:(ie=je(`flex-1 font-sans overflow-auto my-1`,o),t[23]=o,t[24]=ie);let ae=v===`dark`?`dark`:`light`,oe=r||`Generate with AI, @ to include context`,se;return t[25]!==re||t[26]!==a||t[27]!==m||t[28]!==s||t[29]!==u||t[30]!==ie||t[31]!==ae||t[32]!==oe||t[33]!==n?(se=(0,G.jsx)(Bt,{ref:a,className:ie,width:`100%`,maxHeight:m,value:n,basicSetup:!1,extensions:re,onChange:s,onKeyDown:u,theme:ae,placeholder:oe}),t[25]=re,t[26]=a,t[27]=m,t[28]=s,t[29]=u,t[30]=ie,t[31]=ae,t[32]=oe,t[33]=n,t[34]=se):se=t[34],se};function zc(){return Ic.get(Fc)}function Bc(e){return Ic.set(Fc,e)}export{Z as A,Ha as B,Hs as C,Ss as D,ys as E,wo as F,di as G,_a as H,Eo as I,Gt as J,qt as K,ko as L,Po as M,jo as N,ms as O,Fo as P,yo as R,zs as S,gs as T,Fa as U,ka as V,ya as W,Fs as _,Ac as a,Ms as b,Ks as c,Ws as d,Gs as f,As as g,js as h,jc as i,Ao as j,ns as k,qs as l,Ds as m,Rc as n,Mc as o,Ys as p,Kt as q,Oc as r,kc as s,Lc as t,Us as u,Is as v,Es as w,Vs as x,Ls as y,lo as z};
75
+ border-(--red-6) border hover:shadow-xs ${c!==void 0&&c&&`border-none rounded-md`} ${o}`,m=l??`Reject${d?` all`:``}`,h;t[0]===s?h=t[1]:(h=s&&(0,G.jsx)(Bt,{className:`ml-1 inline`,shortcut:s}),t[0]=s,t[1]=h);let g;return t[2]!==u||t[3]!==n||t[4]!==f||t[5]!==p||t[6]!==m||t[7]!==h?(g=(0,G.jsxs)(ze,{variant:`text`,size:f,disabled:u,onClick:n,className:p,children:[m,h]}),t[2]=u,t[3]=n,t[4]=f,t[5]=p,t[6]=m,t[7]=h,t[8]=g):g=t[8],g},Nc=class{activeAttempt=null;cancel(){this.activeAttempt&&(this.activeAttempt.cancelled=!0)}async run({prepare:e,submit:t,onError:n}){if(this.activeAttempt!==null)return;let r={cancelled:!1};this.activeAttempt=r;try{let n=await e();if(r.cancelled)return;await t(n)}catch(e){r.cancelled||n(e)}finally{this.activeAttempt=null}}},Pc=ke(`marimo:ai-language`,`python`,g),Fc=`marimo:ai-prompt-history`,Ic=new f(Se(D()),()=>[]),Lc=({onClose:e})=>{let t=i(),[n,a]=(0,W.useState)(``),{acceptOwnedStagedCells:s,beginStagedCellGeneration:l,discardOwnedStagedCells:u,finishStagedCellGeneration:d,hasOwnedStagedCells:f,onData:p}=Io(t),[m,h]=r(Pc),g=Ae(),_=(0,W.useRef)(null),v=(0,W.useRef)(new Nc).current,y=(0,W.useRef)(null),{files:b,addFiles:x,removeFile:S}=zs(),C=o(Te),ee=(0,W.useMemo)(()=>new Ha({api:g.getAiURL(`completion`).toString(),headers:()=>g.headers(),prepareSendMessagesRequest:async e=>{let t={...await Ps(e.messages),id:e.id,code:``,prompt:``,language:m};return{api:g.getAiURL(`completion`).toString(),body:t}}}),[m,g]),te=c(e=>{d(!1),ut({title:`Generate with AI failed`,description:Pt(e)})}),{sendMessage:ne,stop:w,status:T}=lo({throttle:100,transport:ee,onData:p,onError:te,onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{d(!e&&!t&&!n&&r===`stop`)}}),E=T===`streaming`||T===`submitted`,ie=f(),ae=c(()=>{v.cancel(),d(!1),w()}),oe=c(()=>{v.cancel(),u(),w()});(0,W.useEffect)(()=>()=>{ae()},[ae]);let se=C?.models?.edit_model||`openai/gpt-4o`,ce=Ge.parse(se).providerId,le=Ds.has(ce),ue=async()=>{E||await v.run({prepare:async()=>(_.current?.view&&yo(_.current.view),b?await js(b):void 0),submit:async e=>{l(),await ne({text:n,files:e})},onError:te})},de=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Vt,{className:`size-4 mr-2`}),`Python`]}),fe=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ve,{className:`size-4 mr-2`}),`SQL`]}),pe=(0,G.jsxs)(Le,{modal:!1,children:[(0,G.jsxs)(Fe,{className:`flex items-center justify-between h-7 text-xs px-2 py-0.5 border rounded-md hover:text-accent-foreground`,"data-testid":`language-button`,children:[m===`python`?de:fe,(0,G.jsx)(Ye,{className:`ml-1 h-3.5 w-3.5 text-muted-foreground/70`})]}),(0,G.jsxs)(Ie,{align:`center`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1 text-sm text-muted-foreground`,children:`Select language`}),(0,G.jsx)(Pe,{}),(0,G.jsx)(Ne,{onClick:()=>h(`python`),children:de}),(0,G.jsx)(Ne,{onClick:()=>h(`sql`),children:fe})]})]}),D=()=>{s()&&e()},me=()=>{oe(),_.current?.view?.focus()},he=()=>{oe(),e()},ge=(0,G.jsxs)(`div`,{className:`flex items-center px-3`,children:[(0,G.jsx)(re,{className:`size-4 text-(--blue-11) mr-2`}),(0,G.jsx)(Rc,{inputRef:_,onClose:he,value:n,onChange:e=>{a(e)},onSubmit:ue,onKeyDown:kc({handleAcceptCompletion:D,handleDeclineCompletion:me,isLoading:E,hasCompletion:ie})}),(0,G.jsx)(ze,{variant:`text`,size:`sm`,className:`mb-0 px-1`,onClick:he,children:(0,G.jsx)(Je,{className:`size-4`})})]}),_e=(0,G.jsxs)(`div`,{className:`px-3 pt-1 flex flex-row items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(qe,{triggerClassName:`h-7 text-xs max-w-64`,iconSize:`small`,forRole:`edit`,showAddCustomModelDocs:!0}),pe,(0,G.jsx)(Ke,{})]}),(0,G.jsxs)(`div`,{className:`flex flex-row items-center`,children:[b.length>0&&(0,G.jsx)(`div`,{className:`flex flex-row gap-1 flex-wrap pr-1`,children:b?.map((e,t)=>(0,G.jsx)(Ws,{file:e,onRemove:()=>S(e)},`${e.name}-${t}`))}),(0,G.jsx)(Ks,{handleAddContext:()=>Es(_),isLoading:E}),le&&(0,G.jsx)(qs,{fileInputRef:y,isLoading:E,onAddFiles:x}),(0,G.jsx)(Gs,{isLoading:E,onStop:ae,onSendClick:ue,isEmpty:!n.trim(),showStopLabel:!0})]})]});return(0,G.jsxs)(`div`,{className:je(`flex flex-col w-full py-2`),children:[ge,_e]})},Rc=e=>{let t=(0,A.c)(35),{value:n,placeholder:r,inputRef:a,className:o,onChange:s,onSubmit:l,onKeyDown:u,onClose:d,onAddFiles:f,additionalCompletions:p,maxHeight:m}=e,h=l,g=d,_=i(),{theme:v}=jt(),y;t[0]===p?y=t[1]:(y=e=>p?Ts([p.triggerCompletionRegex],p.completions)(e):null,t[0]=p,t[1]=y);let b=c(y),x,S,C,ee;if(t[2]!==b||t[3]!==f||t[4]!==_){let e=kt();t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=Dt({}),t[9]=x):x=t[9],S=e,C=Ec({language:e.language,store:_,onAddFiles:f}),ee=e.language.data.of({autocomplete:b}),t[2]=b,t[3]=f,t[4]=_,t[5]=x,t[6]=S,t[7]=C,t[8]=ee}else x=t[5],S=t[6],C=t[7],ee=t[8];let te;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(te=bo({storage:{load:zc,save:Bc}}),t[10]=te):te=t[10];let ne;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(ne=Ht(),t[11]=ne):ne=t[11];let w;t[12]===h?w=t[13]:(w=mt.highest(ft.of([{preventDefault:!0,stopPropagation:!0,any:(e,t)=>{let n=t.metaKey||t.ctrlKey||t.shiftKey;if(t.key===`Enter`&&!n)return h(t,e.state.doc.toString()),t.preventDefault(),t.stopPropagation(),!0;if(t.key===`Enter`&&t.shiftKey){let n=e.state.selection.main.from;return e.dispatch({changes:{from:n,to:n,insert:`
76
+ `},selection:{anchor:n+1,head:n+1}}),t.preventDefault(),t.stopPropagation(),!0}return!1}}])),t[12]=h,t[13]=w);let T;t[14]===g?T=t[15]:(T=ft.of([{key:`Escape`,preventDefault:!0,stopPropagation:!0,run:()=>(g(),!0)}]),t[14]=g,t[15]=T);let E;t[16]!==x||t[17]!==S||t[18]!==C||t[19]!==ee||t[20]!==w||t[21]!==T?(E=[x,S,C,ee,te,bt.lineWrapping,ne,w,T],t[16]=x,t[17]=S,t[18]=C,t[19]=ee,t[20]=w,t[21]=T,t[22]=E):E=t[22];let re=E,ie;t[23]===o?ie=t[24]:(ie=je(`flex-1 font-sans overflow-auto my-1`,o),t[23]=o,t[24]=ie);let ae=v===`dark`?`dark`:`light`,oe=r||`Generate with AI, @ to include context`,se;return t[25]!==re||t[26]!==a||t[27]!==m||t[28]!==s||t[29]!==u||t[30]!==ie||t[31]!==ae||t[32]!==oe||t[33]!==n?(se=(0,G.jsx)(Ut,{ref:a,className:ie,width:`100%`,maxHeight:m,value:n,basicSetup:!1,extensions:re,onChange:s,onKeyDown:u,theme:ae,placeholder:oe}),t[25]=re,t[26]=a,t[27]=m,t[28]=s,t[29]=u,t[30]=ie,t[31]=ae,t[32]=oe,t[33]=n,t[34]=se):se=t[34],se};function zc(){return Ic.get(Fc)}function Bc(e){return Ic.set(Fc,e)}export{Z as A,Ha as B,Hs as C,Ss as D,ys as E,wo as F,di as G,_a as H,Eo as I,Gt as J,qt as K,ko as L,Po as M,jo as N,ms as O,Fo as P,yo as R,zs as S,gs as T,Fa as U,ka as V,ya as W,Fs as _,Ac as a,Ms as b,Ks as c,Ws as d,Gs as f,As as g,js as h,jc as i,Ao as j,ns as k,qs as l,Ds as m,Rc as n,Mc as o,Ys as p,Kt as q,Oc as r,kc as s,Lc as t,Us as u,Is as v,Es as w,Vs as x,Ls as y,lo as z};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-DVplv7_D.js";import{At as n,Mt as r,gi as i,jn as a,jt as o,kt as s,qa as c,wn as l,yt as u}from"./cells-BRkCaSsh.js";import{E as d,P as f,S as p,j as m,w as h}from"./schemas-Dv42wLFq.js";import{r as g}from"./coerce-CpE6kUdX.js";import{t as _}from"./compiler-runtime-BrajqUja.js";import{t as v}from"./cn-ldLVeaqm.js";import{t as y}from"./jsx-runtime-B74pBk57.js";import{i as ee,n as te,r as ne,t as re}from"./tabs-BuQlZFbt.js";import{i as b,t as ie}from"./tooltip-C9TuY18o.js";import{t as ae}from"./components-CP_UoFtT.js";import{a as x,l as oe,p as S,r as C,s as w}from"./write-secret-modal-DzKAInL2.js";import{t as se}from"./plus-C5silF6g.js";import{Jt as ce,Qt as le,Xt as ue,Yt as de,nn as fe,tn as pe}from"./input-BoBxR50a.js";import{r as T}from"./strings-B2vv-ENv.js";import{t as me}from"./useIframeCapabilities-CwTkczVN.js";var E=e(t(),1),D=_();function O(){return f().optional().describe(l.of({label:`Password`,inputType:`password`,optionRegex:`(password|passwd|pgpassword|db.?pass(word)?)`}))}function k(e,t){let n=f();return n=t?n.nonempty():n.optional(),n=n.describe(l.of({label:e||`Token`,inputType:`password`,optionRegex:`(token|api.?key|access.?token|auth.?token|(^|_)pat(_|$))`})),n}function A(){return f().optional().describe(l.of({label:`Warehouse Name`,optionRegex:`(warehouse|snowflake.?warehouse)`}))}function j(e,t){let n=f();return n=t?n.nonempty():n.optional(),n.describe(l.of({label:e||`URI`,optionRegex:`(uri|url|connection.?string|database.?url|jdbc)`}))}function M(e){return f().nonempty().describe(l.of({label:e||`Host`,optionRegex:`^(?!.*(kubernetes|gpg)).*(host(name)?|pghost|db.?host|database.?host|mysql.?host|postgres.?host|server.?host)`}))}function N(){return f().describe(l.of({label:`Database`,optionRegex:`(database|db.?name|pgdatabase|^DB$|^DATABASE$)`}))}function he(){return f().describe(l.of({label:`Schema`,optionRegex:`(^SCHEMA$|db.?schema|postgres.?schema|pg.?schema|_SCHEMA$)`}))}function P(){return f().nonempty().describe(l.of({label:`Username`,optionRegex:`(username|pguser|db.?user|^USER$|_USER$)`}))}function F(e){let t=g().describe(l.of({label:`Port`,inputType:`number`,placeholder:e?.toString()})).transform(Number).refine(e=>e>=0&&e<=65535,{message:`Port must be between 0 and 65535`});return e===void 0?t:t.default(e)}function ge(){return p().default(!1).describe(l.of({label:`Read Only`}))}var _e=m({type:d(`postgres`),host:M(),port:F(5432).optional(),database:N(),username:P(),password:O(),ssl:p().default(!1).describe(l.of({label:`Use SSL`}))}).describe(l.of({direction:`two-columns`})),ve=m({type:d(`mysql`),host:M(),port:F(3306),database:N(),username:P(),password:O(),ssl:p().default(!1).describe(l.of({label:`Use SSL`}))}).describe(l.of({direction:`two-columns`})),ye=m({type:d(`sqlite`),database:N().describe(l.of({label:`Database Path`}))}).describe(l.of({direction:`two-columns`})),be=m({type:d(`duckdb`),database:N().describe(l.of({label:`Database Path`})),read_only:ge()}).describe(l.of({direction:`two-columns`})),I=m({type:d(`motherduck`),database:N().default(`my_db`).describe(l.of({label:`Database Name`})),token:k()}).describe(l.of({direction:`two-columns`})),L=m({type:d(`snowflake`),account:f().nonempty().describe(l.of({label:`Account`,optionRegex:`(snowflake.?account|^SNOWFLAKE_ACCOUNT$|account.?id)`})),warehouse:f().optional().describe(l.of({label:`Warehouse`,optionRegex:`(snowflake.?warehouse|warehouse)`})),database:N(),schema:f().optional().describe(l.of({label:`Schema`,optionRegex:`(snowflake.?schema|^SCHEMA$|_SCHEMA$)`})),role:f().optional().describe(l.of({label:`Role`})),authType:h(`type`,[m({type:d(`Password`),username:P(),password:O(),enable_mfa:p().default(!1).describe(l.of({label:`Enable MFA (Duo Push)`}))}),m({type:d(`SSO (Browser)`),username:P()}),m({type:d(`Key Pair`),username:P(),private_key_path:f().nonempty().describe(l.of({label:`Private Key Path`,placeholder:`/path/to/rsa_key.p8`})),private_key_passphrase:f().optional().describe(l.of({label:`Private Key Passphrase`,inputType:`password`,optionRegex:`(passphrase|private.?key.?passphrase|key.?passphrase)`}))}),m({type:d(`OAuth / PAT`),token:k(`Token`,!0)})]).default({type:`Password`,username:`username`,enable_mfa:!1}).describe(l.of({special:`tabs`}))}).describe(l.of({direction:`two-columns`})),R=m({type:d(`bigquery`),project:f().nonempty().describe(l.of({label:`Project ID`,optionRegex:`(bigquery.?project|gcp.?project|google.?cloud.?project|project.?id)`})),dataset:f().nonempty().describe(l.of({label:`Dataset`,optionRegex:`(bigquery.?dataset|dataset)`})),credentials_json:f().describe(l.of({label:`Credentials JSON`,special:`secret_textarea`}))}).describe(l.of({direction:`two-columns`})),z=m({type:d(`clickhouse_connect`),host:M(),port:F(8123).optional(),username:P(),password:O(),secure:p().default(!1).describe(l.of({label:`Use HTTPs`})),proxy_path:f().optional().describe(l.of({label:`Proxy Path`,placeholder:`/clickhouse`}))}).describe(l.of({direction:`two-columns`})),B=m({type:d(`timeplus`),host:M().default(`localhost`),port:F(8123).optional(),username:P().default(`default`),password:O().default(``)}).describe(l.of({direction:`two-columns`})),V=m({type:d(`chdb`),database:N().describe(l.of({label:`Database Path`})),read_only:ge()}).describe(l.of({direction:`two-columns`})),H=m({type:d(`trino`),host:M(),port:F(8080),database:N(),schema:he().optional(),username:P(),password:O(),async_support:p().default(!1).describe(l.of({label:`Async Support`}))}).describe(l.of({direction:`two-columns`})),U=m({type:d(`iceberg`),name:f().describe(l.of({label:`Catalog Name`})),catalog:h(`type`,[m({type:d(`REST`),warehouse:A(),uri:f().optional().describe(l.of({label:`URI`,placeholder:`https://`,optionRegex:`(uri|url|connection.?string|database.?url|jdbc)`})),token:k()}),m({type:d(`SQL`),warehouse:A(),uri:f().optional().describe(l.of({label:`URI`,placeholder:`jdbc:iceberg://host:port/database`,optionRegex:`(uri|url|connection.?string|database.?url|jdbc)`}))}),m({type:d(`Hive`),warehouse:A(),uri:j()}),m({type:d(`Glue`),warehouse:A(),uri:j()}),m({type:d(`DynamoDB`),"dynamodb.profile-name":f().optional().describe(l.of({label:`Profile Name`})),"dynamodb.region":f().optional().describe(l.of({label:`Region`})),"dynamodb.access-key-id":f().optional().describe(l.of({label:`Access Key ID`,inputType:`password`,optionRegex:`(access.?key.?id|aws.?access.?key)`})),"dynamodb.secret-access-key":f().optional().describe(l.of({label:`Secret Access Key`,inputType:`password`,optionRegex:`(secret.?access.?key|aws.?secret)`})),"dynamodb.session-token":f().optional().describe(l.of({label:`Session Token`,inputType:`password`,optionRegex:`(session.?token|aws.?session)`}))})]).default({type:`REST`,token:void 0}).describe(l.of({special:`tabs`}))}),W=m({type:d(`datafusion`),sessionContext:p().optional().describe(l.of({label:`Use Session Context`}))}),G=m({type:d(`pyspark`),host:M().optional(),port:F().optional()}),K=m({type:d(`redshift`),host:M(),port:F(5439),connectionType:h(`type`,[m({type:d(`IAM credentials`),region:f().describe(l.of({label:`Region`})),aws_access_key_id:f().nonempty().describe(l.of({label:`AWS Access Key ID`,inputType:`password`,optionRegex:`(access.?key.?id|aws.?access.?key)`})),aws_secret_access_key:f().nonempty().describe(l.of({label:`AWS Secret Access Key`,inputType:`password`,optionRegex:`(secret.?access.?key|aws.?secret)`})),aws_session_token:f().optional().describe(l.of({label:`AWS Session Token`,inputType:`password`,optionRegex:`(session.?token|aws.?session)`}))}),m({type:d(`DB credentials`),user:P(),password:O()})]).default({type:`IAM credentials`,aws_access_key_id:``,aws_secret_access_key:``,region:``}),database:N()}).describe(l.of({direction:`two-columns`})),q=m({type:d(`databricks`),access_token:k(`Access Token`,!0),server_hostname:M(`Server Hostname`),http_path:j(`HTTP Path`,!0),catalog:f().optional().describe(l.of({label:`Catalog`})),schema:f().optional().describe(l.of({label:`Schema`}))}).describe(l.of({direction:`two-columns`})),xe=m({type:d(`supabase`),host:M(),port:F(5432).optional(),database:N(),username:P(),password:O(),disable_client_pooling:p().default(!1).describe(l.of({label:`Disable Client-Side Pooling`}))}).describe(l.of({direction:`two-columns`})),Se=h(`type`,[_e,ve,ye,be,I,L,R,z,B,V,H,U,W,G,K,q,xe]),Ce={sqlmodel:`SQLModel`,sqlalchemy:`SQLAlchemy`,duckdb:`DuckDB`,clickhouse_connect:`ClickHouse Connect`,chdb:`chDB`,pyiceberg:`PyIceberg`,ibis:`Ibis`,motherduck:`MotherDuck`,redshift:`Redshift`,databricks:`Databricks`},J=class{connection;orm;secrets;constructor(e,t,n){this.connection=e,this.orm=t,this.secrets=n}get imports(){let e=new Set(this.generateImports());switch(this.orm){case`sqlalchemy`:e.add(`import sqlalchemy`);break;case`sqlmodel`:e.add(`import sqlmodel`);break;case`duckdb`:e.add(`import duckdb`);break;case`ibis`:e.add(`import ibis`)}return e}},we=e=>`_${e}`,Te=class{secrets={};get imports(){return Object.keys(this.secrets).length===0?new Set:new Set([`import os`])}print(e,t,n){if(e=we(e),w(t)){let r=oe(t),i=n?`os.environ.get("${r}", "${n}")`:`os.environ.get("${r}")`;return this.secrets[e]=i,e}if(n!=null){let r=`os.environ.get("${t}", "${n}")`;return this.secrets[e]=r,e}return typeof t==`number`||typeof t==`number`?`${t}`:typeof t==`boolean`?Y(t):t?`"${t}"`:``}printInFString(e,t,n){if(t===void 0)return``;if(typeof t==`number`)return`${t}`;if(typeof t==`boolean`)return Y(t);let r=this.print(e,t,n);return r.startsWith(`"`)&&r.endsWith(`"`)?r.slice(1,-1):`{${r}}`}printPassword(e,t,n,r){let i=n?this.printInFString.bind(this):this.print.bind(this);return w(e)?i(r||`password`,e):i(r||`password`,t,e)}getSecrets(){return this.secrets}formatSecrets(){return Object.keys(this.secrets).length===0?``:Object.entries(this.secrets).map(([e,t])=>`${e} = ${t}`).join(`
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-DVplv7_D.js";import{At as n,Mt as r,gi as i,jn as a,jt as o,kt as s,qa as c,wn as l,yt as u}from"./cells-rA_jsZCj.js";import{E as d,P as f,S as p,j as m,w as h}from"./schemas-Dv42wLFq.js";import{r as g}from"./coerce-CpE6kUdX.js";import{t as _}from"./compiler-runtime-BrajqUja.js";import{t as v}from"./cn-ldLVeaqm.js";import{t as y}from"./jsx-runtime-B74pBk57.js";import{i as ee,n as te,r as ne,t as re}from"./tabs-BuQlZFbt.js";import{i as b,t as ie}from"./tooltip-C9TuY18o.js";import{t as ae}from"./components-CP_UoFtT.js";import{a as x,l as oe,p as S,r as C,s as w}from"./write-secret-modal-DzKAInL2.js";import{t as se}from"./plus-C5silF6g.js";import{Jt as ce,Qt as le,Xt as ue,Yt as de,nn as fe,tn as pe}from"./input-BoBxR50a.js";import{r as T}from"./strings-B2vv-ENv.js";import{t as me}from"./useIframeCapabilities-CwTkczVN.js";var E=e(t(),1),D=_();function O(){return f().optional().describe(l.of({label:`Password`,inputType:`password`,optionRegex:`(password|passwd|pgpassword|db.?pass(word)?)`}))}function k(e,t){let n=f();return n=t?n.nonempty():n.optional(),n=n.describe(l.of({label:e||`Token`,inputType:`password`,optionRegex:`(token|api.?key|access.?token|auth.?token|(^|_)pat(_|$))`})),n}function A(){return f().optional().describe(l.of({label:`Warehouse Name`,optionRegex:`(warehouse|snowflake.?warehouse)`}))}function j(e,t){let n=f();return n=t?n.nonempty():n.optional(),n.describe(l.of({label:e||`URI`,optionRegex:`(uri|url|connection.?string|database.?url|jdbc)`}))}function M(e){return f().nonempty().describe(l.of({label:e||`Host`,optionRegex:`^(?!.*(kubernetes|gpg)).*(host(name)?|pghost|db.?host|database.?host|mysql.?host|postgres.?host|server.?host)`}))}function N(){return f().describe(l.of({label:`Database`,optionRegex:`(database|db.?name|pgdatabase|^DB$|^DATABASE$)`}))}function he(){return f().describe(l.of({label:`Schema`,optionRegex:`(^SCHEMA$|db.?schema|postgres.?schema|pg.?schema|_SCHEMA$)`}))}function P(){return f().nonempty().describe(l.of({label:`Username`,optionRegex:`(username|pguser|db.?user|^USER$|_USER$)`}))}function F(e){let t=g().describe(l.of({label:`Port`,inputType:`number`,placeholder:e?.toString()})).transform(Number).refine(e=>e>=0&&e<=65535,{message:`Port must be between 0 and 65535`});return e===void 0?t:t.default(e)}function ge(){return p().default(!1).describe(l.of({label:`Read Only`}))}var _e=m({type:d(`postgres`),host:M(),port:F(5432).optional(),database:N(),username:P(),password:O(),ssl:p().default(!1).describe(l.of({label:`Use SSL`}))}).describe(l.of({direction:`two-columns`})),ve=m({type:d(`mysql`),host:M(),port:F(3306),database:N(),username:P(),password:O(),ssl:p().default(!1).describe(l.of({label:`Use SSL`}))}).describe(l.of({direction:`two-columns`})),ye=m({type:d(`sqlite`),database:N().describe(l.of({label:`Database Path`}))}).describe(l.of({direction:`two-columns`})),be=m({type:d(`duckdb`),database:N().describe(l.of({label:`Database Path`})),read_only:ge()}).describe(l.of({direction:`two-columns`})),I=m({type:d(`motherduck`),database:N().default(`my_db`).describe(l.of({label:`Database Name`})),token:k()}).describe(l.of({direction:`two-columns`})),L=m({type:d(`snowflake`),account:f().nonempty().describe(l.of({label:`Account`,optionRegex:`(snowflake.?account|^SNOWFLAKE_ACCOUNT$|account.?id)`})),warehouse:f().optional().describe(l.of({label:`Warehouse`,optionRegex:`(snowflake.?warehouse|warehouse)`})),database:N(),schema:f().optional().describe(l.of({label:`Schema`,optionRegex:`(snowflake.?schema|^SCHEMA$|_SCHEMA$)`})),role:f().optional().describe(l.of({label:`Role`})),authType:h(`type`,[m({type:d(`Password`),username:P(),password:O(),enable_mfa:p().default(!1).describe(l.of({label:`Enable MFA (Duo Push)`}))}),m({type:d(`SSO (Browser)`),username:P()}),m({type:d(`Key Pair`),username:P(),private_key_path:f().nonempty().describe(l.of({label:`Private Key Path`,placeholder:`/path/to/rsa_key.p8`})),private_key_passphrase:f().optional().describe(l.of({label:`Private Key Passphrase`,inputType:`password`,optionRegex:`(passphrase|private.?key.?passphrase|key.?passphrase)`}))}),m({type:d(`OAuth / PAT`),token:k(`Token`,!0)})]).default({type:`Password`,username:`username`,enable_mfa:!1}).describe(l.of({special:`tabs`}))}).describe(l.of({direction:`two-columns`})),R=m({type:d(`bigquery`),project:f().nonempty().describe(l.of({label:`Project ID`,optionRegex:`(bigquery.?project|gcp.?project|google.?cloud.?project|project.?id)`})),dataset:f().nonempty().describe(l.of({label:`Dataset`,optionRegex:`(bigquery.?dataset|dataset)`})),credentials_json:f().describe(l.of({label:`Credentials JSON`,special:`secret_textarea`}))}).describe(l.of({direction:`two-columns`})),z=m({type:d(`clickhouse_connect`),host:M(),port:F(8123).optional(),username:P(),password:O(),secure:p().default(!1).describe(l.of({label:`Use HTTPs`})),proxy_path:f().optional().describe(l.of({label:`Proxy Path`,placeholder:`/clickhouse`}))}).describe(l.of({direction:`two-columns`})),B=m({type:d(`timeplus`),host:M().default(`localhost`),port:F(8123).optional(),username:P().default(`default`),password:O().default(``)}).describe(l.of({direction:`two-columns`})),V=m({type:d(`chdb`),database:N().describe(l.of({label:`Database Path`})),read_only:ge()}).describe(l.of({direction:`two-columns`})),H=m({type:d(`trino`),host:M(),port:F(8080),database:N(),schema:he().optional(),username:P(),password:O(),async_support:p().default(!1).describe(l.of({label:`Async Support`}))}).describe(l.of({direction:`two-columns`})),U=m({type:d(`iceberg`),name:f().describe(l.of({label:`Catalog Name`})),catalog:h(`type`,[m({type:d(`REST`),warehouse:A(),uri:f().optional().describe(l.of({label:`URI`,placeholder:`https://`,optionRegex:`(uri|url|connection.?string|database.?url|jdbc)`})),token:k()}),m({type:d(`SQL`),warehouse:A(),uri:f().optional().describe(l.of({label:`URI`,placeholder:`jdbc:iceberg://host:port/database`,optionRegex:`(uri|url|connection.?string|database.?url|jdbc)`}))}),m({type:d(`Hive`),warehouse:A(),uri:j()}),m({type:d(`Glue`),warehouse:A(),uri:j()}),m({type:d(`DynamoDB`),"dynamodb.profile-name":f().optional().describe(l.of({label:`Profile Name`})),"dynamodb.region":f().optional().describe(l.of({label:`Region`})),"dynamodb.access-key-id":f().optional().describe(l.of({label:`Access Key ID`,inputType:`password`,optionRegex:`(access.?key.?id|aws.?access.?key)`})),"dynamodb.secret-access-key":f().optional().describe(l.of({label:`Secret Access Key`,inputType:`password`,optionRegex:`(secret.?access.?key|aws.?secret)`})),"dynamodb.session-token":f().optional().describe(l.of({label:`Session Token`,inputType:`password`,optionRegex:`(session.?token|aws.?session)`}))})]).default({type:`REST`,token:void 0}).describe(l.of({special:`tabs`}))}),W=m({type:d(`datafusion`),sessionContext:p().optional().describe(l.of({label:`Use Session Context`}))}),G=m({type:d(`pyspark`),host:M().optional(),port:F().optional()}),K=m({type:d(`redshift`),host:M(),port:F(5439),connectionType:h(`type`,[m({type:d(`IAM credentials`),region:f().describe(l.of({label:`Region`})),aws_access_key_id:f().nonempty().describe(l.of({label:`AWS Access Key ID`,inputType:`password`,optionRegex:`(access.?key.?id|aws.?access.?key)`})),aws_secret_access_key:f().nonempty().describe(l.of({label:`AWS Secret Access Key`,inputType:`password`,optionRegex:`(secret.?access.?key|aws.?secret)`})),aws_session_token:f().optional().describe(l.of({label:`AWS Session Token`,inputType:`password`,optionRegex:`(session.?token|aws.?session)`}))}),m({type:d(`DB credentials`),user:P(),password:O()})]).default({type:`IAM credentials`,aws_access_key_id:``,aws_secret_access_key:``,region:``}),database:N()}).describe(l.of({direction:`two-columns`})),q=m({type:d(`databricks`),access_token:k(`Access Token`,!0),server_hostname:M(`Server Hostname`),http_path:j(`HTTP Path`,!0),catalog:f().optional().describe(l.of({label:`Catalog`})),schema:f().optional().describe(l.of({label:`Schema`}))}).describe(l.of({direction:`two-columns`})),xe=m({type:d(`supabase`),host:M(),port:F(5432).optional(),database:N(),username:P(),password:O(),disable_client_pooling:p().default(!1).describe(l.of({label:`Disable Client-Side Pooling`}))}).describe(l.of({direction:`two-columns`})),Se=h(`type`,[_e,ve,ye,be,I,L,R,z,B,V,H,U,W,G,K,q,xe]),Ce={sqlmodel:`SQLModel`,sqlalchemy:`SQLAlchemy`,duckdb:`DuckDB`,clickhouse_connect:`ClickHouse Connect`,chdb:`chDB`,pyiceberg:`PyIceberg`,ibis:`Ibis`,motherduck:`MotherDuck`,redshift:`Redshift`,databricks:`Databricks`},J=class{connection;orm;secrets;constructor(e,t,n){this.connection=e,this.orm=t,this.secrets=n}get imports(){let e=new Set(this.generateImports());switch(this.orm){case`sqlalchemy`:e.add(`import sqlalchemy`);break;case`sqlmodel`:e.add(`import sqlmodel`);break;case`duckdb`:e.add(`import duckdb`);break;case`ibis`:e.add(`import ibis`)}return e}},we=e=>`_${e}`,Te=class{secrets={};get imports(){return Object.keys(this.secrets).length===0?new Set:new Set([`import os`])}print(e,t,n){if(e=we(e),w(t)){let r=oe(t),i=n?`os.environ.get("${r}", "${n}")`:`os.environ.get("${r}")`;return this.secrets[e]=i,e}if(n!=null){let r=`os.environ.get("${t}", "${n}")`;return this.secrets[e]=r,e}return typeof t==`number`||typeof t==`number`?`${t}`:typeof t==`boolean`?Y(t):t?`"${t}"`:``}printInFString(e,t,n){if(t===void 0)return``;if(typeof t==`number`)return`${t}`;if(typeof t==`boolean`)return Y(t);let r=this.print(e,t,n);return r.startsWith(`"`)&&r.endsWith(`"`)?r.slice(1,-1):`{${r}}`}printPassword(e,t,n,r){let i=n?this.printInFString.bind(this):this.print.bind(this);return w(e)?i(r||`password`,e):i(r||`password`,t,e)}getSecrets(){return this.secrets}formatSecrets(){return Object.keys(this.secrets).length===0?``:Object.entries(this.secrets).map(([e,t])=>`${e} = ${t}`).join(`
2
2
  `)}},Ee=class extends J{generateImports(){return[]}generateConnectionCode(){let e=this.connection.ssl?`, connect_args={'sslmode': 'require'}`:``,t=this.secrets.printPassword(this.connection.password,`POSTGRES_PASSWORD`,!0),n=this.secrets.printInFString(`username`,this.connection.username),r=this.secrets.printInFString(`host`,this.connection.host),a=this.secrets.printInFString(`port`,this.connection.port),o=this.secrets.printInFString(`database`,this.connection.database);return i(`
3
3
  DATABASE_URL = f"postgresql://${n}:${t}@${r}:${a}/${o}"
4
4
  engine = ${this.orm}.create_engine(DATABASE_URL${e})