@marimo-team/frontend 0.24.3-dev37 → 0.24.3-dev39

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 (140) hide show
  1. package/dist/assets/{ConnectedDataExplorerComponent-CsA_EqMs.js → ConnectedDataExplorerComponent-B52ZeTyE.js} +1 -1
  2. package/dist/assets/{LazyAnyLanguageCodeMirror-jAV-LD6v.js → LazyAnyLanguageCodeMirror-DLXghRUF.js} +2 -2
  3. package/dist/assets/{RunButton-Bo4tYCqW.js → RunButton-BQonXEus.js} +7 -7
  4. package/dist/assets/{abnfDiagram-VCTEODGH-Dpe20TKk.js → abnfDiagram-VCTEODGH-DAeh_Fhj.js} +1 -1
  5. package/dist/assets/{add-cell-with-ai-CkjbbM3K.js → add-cell-with-ai-BqPNrEkg.js} +10 -10
  6. package/dist/assets/{agent-panel-CJ__bZ2U.js → agent-panel-0QpsWJ6N.js} +4 -4
  7. package/dist/assets/{ai-model-dropdown-CFjRFxPs.js → ai-model-dropdown-JyOkbRgs.js} +2 -2
  8. package/dist/assets/{any-language-editor-CVvssaI-.js → any-language-editor-DktznOiF.js} +1 -1
  9. package/dist/assets/app-config-button-hlzBggjV.js +1 -0
  10. package/dist/assets/{architectureDiagram-5GKGNRK7-LjPvmKXz.js → architectureDiagram-5GKGNRK7-CLV_t53p.js} +1 -1
  11. package/dist/assets/{blockDiagram-I7D4REHJ-Dcw3YZc7.js → blockDiagram-I7D4REHJ-4NgsF8dG.js} +1 -1
  12. package/dist/assets/cache-panel-JD-3Sv8N.js +1 -0
  13. package/dist/assets/{cells-DcI93as7.js → cells-CP3hwqVX.js} +5 -5
  14. package/dist/assets/{chat-display-BxoFsvsk.js → chat-display-f6K2vP1M.js} +1 -1
  15. package/dist/assets/{chat-panel-OPXY9xqa.js → chat-panel-CPSz0Ygy.js} +3 -3
  16. package/dist/assets/{chat-ui-B7Op0m5y.js → chat-ui-DJskwz2p.js} +3 -3
  17. package/dist/assets/{chunk-IMKFNOWR-BhKJw_u0.js → chunk-IMKFNOWR-gOOmxUZk.js} +1 -1
  18. package/dist/assets/{chunk-SHT3W25Y-BLq6CG7S.js → chunk-SHT3W25Y-Vz0rwhW1.js} +1 -1
  19. package/dist/assets/{chunk-SVP7TREG-DYlo9xS8.js → chunk-SVP7TREG-DXVPjbAe.js} +1 -1
  20. package/dist/assets/{chunk-TICWLB2K-D5DDJ9ap.js → chunk-TICWLB2K-DwIBziwV.js} +1 -1
  21. package/dist/assets/{classDiagram-ZZMXUADV-Cpgr9tEc.js → classDiagram-ZZMXUADV-CyUk9nSP.js} +1 -1
  22. package/dist/assets/{classDiagram-v2-VYDZK3BY-Cpgr9tEc.js → classDiagram-v2-VYDZK3BY-CyUk9nSP.js} +1 -1
  23. package/dist/assets/{command-palette-BBhAYPL7.js → command-palette-B8zE6Ssx.js} +1 -1
  24. package/dist/assets/{common-DGrIhswR.js → common-CHWS0pGT.js} +1 -1
  25. package/dist/assets/{components-BzThHPL8.js → components-B8fYemsk.js} +1 -1
  26. package/dist/assets/{components-XxbsL-NL.js → components-v8nHOj_y.js} +1 -1
  27. package/dist/assets/config-CBLBAU5c.js +1 -0
  28. package/dist/assets/{cynefinDiagram-5FMLGOSQ-cA8HNBWT.js → cynefinDiagram-5FMLGOSQ-DgdyjbQj.js} +1 -1
  29. package/dist/assets/{dagre-Cgh-CozI.js → dagre-CPZ1FUhr.js} +1 -1
  30. package/dist/assets/{dagre-GXQ25YYZ-DMu-4gaX.js → dagre-GXQ25YYZ-D-zMjnRl.js} +1 -1
  31. package/dist/assets/{data-grid-overlay-editor-o8dOZGaO.js → data-grid-overlay-editor-CFK1KT2V.js} +1 -1
  32. package/dist/assets/{dependency-graph-panel-DSfkNvTe.js → dependency-graph-panel-D_AqnRMs.js} +3 -3
  33. package/dist/assets/{diagram-S7CK7UJ4-0g042cjW.js → diagram-S7CK7UJ4-DgflUEq5.js} +1 -1
  34. package/dist/assets/{diagram-UQ7AKVKN-CoeYBFyV.js → diagram-UQ7AKVKN-m3R2UDJM.js} +1 -1
  35. package/dist/assets/{diagram-VX7I27RA-CIbkeHtW.js → diagram-VX7I27RA-Blh2o8ik.js} +1 -1
  36. package/dist/assets/{diagram-Z3DM3KII-VNvdSBDs.js → diagram-Z3DM3KII-C4PcKTD6.js} +1 -1
  37. package/dist/assets/{documentation-panel-BYssFEdu.js → documentation-panel-CoSoUakB.js} +1 -1
  38. package/dist/assets/{ebnfDiagram-PWID7BFC-gn-sVFpd.js → ebnfDiagram-PWID7BFC-BGtaPv5f.js} +1 -1
  39. package/dist/assets/edit-page-Qqpz6lsF.js +184 -0
  40. package/dist/assets/{erDiagram-RLTQ6QDP-CHEeDG3E.js → erDiagram-RLTQ6QDP-D8JVfIur.js} +1 -1
  41. package/dist/assets/{error-panel-BEyUxPKv.js → error-panel-CdqCDhu4.js} +1 -1
  42. package/dist/assets/{file-explorer-panel-BkidiqtU.js → file-explorer-panel-DcWEU9mt.js} +1 -1
  43. package/dist/assets/{file-name-input-DRW2aJnO.js → file-name-input-BQw4Jo-i.js} +1 -1
  44. package/dist/assets/{flowDiagram-HODETNUW-juSojTPv.js → flowDiagram-HODETNUW-DMus6jv_.js} +1 -1
  45. package/dist/assets/{gallery-page-C8KW0aF4.js → gallery-page-_mH_5ChL.js} +1 -1
  46. package/dist/assets/{glide-data-editor-C-EXft2Q.js → glide-data-editor-CFcsGnit.js} +4 -4
  47. package/dist/assets/{graphlib-rnp4xs81.js → graphlib-Sg3tw7ov.js} +1 -1
  48. package/dist/assets/has-DXmEv5FL.js +1 -0
  49. package/dist/assets/{home-page-CG6vbN4B.js → home-page-hKIN8akr.js} +2 -2
  50. package/dist/assets/index-B8OSEJVD.css +2 -0
  51. package/dist/assets/index-qY3lu9r4.js +62 -0
  52. package/dist/assets/{infoDiagram-27XIBGKW-C4VdBugr.js → infoDiagram-27XIBGKW-DYsYx_PP.js} +1 -1
  53. package/dist/assets/{ishikawaDiagram-5VMMS53U-BS-QMwse.js → ishikawaDiagram-5VMMS53U-D1Rpw_lT.js} +1 -1
  54. package/dist/assets/{kanban-definition-UXKFOSKX-HVONQMlk.js → kanban-definition-UXKFOSKX-CGxkIydR.js} +1 -1
  55. package/dist/assets/{logs-panel-BNeI_Aah.js → logs-panel-C4k8cMGx.js} +1 -1
  56. package/dist/assets/{mermaid-LovyOmSB.js → mermaid-BLxkTwc2.js} +4 -4
  57. package/dist/assets/{mindmap-definition-YA3MSWOX-DyBY39cg.js → mindmap-definition-YA3MSWOX-BiuGfVWP.js} +1 -1
  58. package/dist/assets/{number-overlay-editor-CwRpjoZm.js → number-overlay-editor-Ck2sCaO7.js} +1 -1
  59. package/dist/assets/{outline-panel-bDklL4uf.js → outline-panel-Z6FAHcVy.js} +1 -1
  60. package/dist/assets/packages-panel-CgL87fcO.js +1 -0
  61. package/dist/assets/panels-BSvT-tNo.js +33 -0
  62. package/dist/assets/{pegDiagram-XKGWAZYB-kQLDO-kO.js → pegDiagram-XKGWAZYB-Ci7mDvEz.js} +1 -1
  63. package/dist/assets/{pieDiagram-E7YTZNPT-DJsFtYCp.js → pieDiagram-E7YTZNPT-DZbp0Icu.js} +1 -1
  64. package/dist/assets/{process-output-CVZMao0e.js → process-output-COWXLjOr.js} +1 -1
  65. package/dist/assets/{railroadDiagram-O6MQD6OU-Bcf0CSqH.js → railroadDiagram-O6MQD6OU-CzXIAsPx.js} +1 -1
  66. package/dist/assets/{requirementDiagram-BXWQKSXE-AGcJcQbq.js → requirementDiagram-BXWQKSXE-DsIrXWi5.js} +1 -1
  67. package/dist/assets/{reveal-component-Dx_L-cIu.js → reveal-component-CnW6op6f.js} +3 -3
  68. package/dist/assets/run-page-B_JOrxWI.js +1 -0
  69. package/dist/assets/{scratchpad-panel-DfvfNJDq.js → scratchpad-panel-DktgeGw9.js} +1 -1
  70. package/dist/assets/{secrets-panel-CZbY8wgN.js → secrets-panel-Di8040gJ.js} +1 -1
  71. package/dist/assets/{sequenceDiagram-WJ2MYXX4-Cokf6L0R.js → sequenceDiagram-WJ2MYXX4-YEyNvwCq.js} +1 -1
  72. package/dist/assets/{session-panel-Cmsewdss.js → session-panel-FmN2Ix-x.js} +1 -1
  73. package/dist/assets/{snippets-panel-B_XreO-C.js → snippets-panel-BmXCx6yt.js} +1 -1
  74. package/dist/assets/{stateDiagram-D77RDMKH-CdkNCpaH.js → stateDiagram-D77RDMKH-B3Ja9Vk7.js} +1 -1
  75. package/dist/assets/{stateDiagram-v2-MP3YSRHH-CpudHHc4.js → stateDiagram-v2-MP3YSRHH-Bn7tPa_c.js} +1 -1
  76. package/dist/assets/{swimlanes-42K2YHIH-_8ELJqVB.js → swimlanes-42K2YHIH-DTgRQfmF.js} +1 -1
  77. package/dist/assets/{swimlanesDiagram-VR7AAH4N-qd1AHOJZ.js → swimlanesDiagram-VR7AAH4N-DKJ2qI6J.js} +1 -1
  78. package/dist/assets/{swiper-component-DY4M2PJo.js → swiper-component-CYrf6kVu.js} +1 -1
  79. package/dist/assets/{terminal-CTP4KOwN.js → terminal-CBss1CM1.js} +2 -2
  80. package/dist/assets/{timeline-definition-24CTP7MA-donBeXb2.js → timeline-definition-24CTP7MA-CKo5fHyB.js} +1 -1
  81. package/dist/assets/{tracing-DgHfkjPY.js → tracing-BBufraD6.js} +1 -1
  82. package/dist/assets/{tracing-panel-Qiu_S5kw.js → tracing-panel-lUoyxh7t.js} +2 -2
  83. package/dist/assets/{useCellActionButton-BCWgCI24.js → useCellActionButton-VJCYmjUy.js} +1 -1
  84. package/dist/assets/{vega-component-CC6LYLy6.js → vega-component-BUKpKmrE.js} +1 -1
  85. package/dist/assets/{vega-embed-container-CMoER1M0.js → vega-embed-container-BgSrb2ci.js} +1 -1
  86. package/dist/assets/{vennDiagram-4TSXK5OY-BgCWyFeF.js → vennDiagram-4TSXK5OY-CA_b78pk.js} +1 -1
  87. package/dist/assets/{wardleyDiagram-VM6X3IG4-rkxibRUc.js → wardleyDiagram-VM6X3IG4-CT2UYDxA.js} +1 -1
  88. package/dist/assets/{xychartDiagram-S5SC5T6Z-Bfs-6MBb.js → xychartDiagram-S5SC5T6Z-BOvLySSM.js} +1 -1
  89. package/dist/index.html +5 -5
  90. package/package.json +1 -1
  91. package/src/__mocks__/requests.ts +7 -0
  92. package/src/components/editor/alerts/connecting-alert.tsx +1 -66
  93. package/src/components/editor/alerts/connection-notice.tsx +140 -0
  94. package/src/components/editor/app-container.tsx +9 -3
  95. package/src/components/editor/chrome/panels/__tests__/packages-panel.test.tsx +114 -7
  96. package/src/components/editor/chrome/panels/__tests__/sandbox-recovery.test.tsx +165 -0
  97. package/src/components/editor/chrome/panels/packages-panel.tsx +93 -166
  98. package/src/components/editor/chrome/panels/sandbox-controller.tsx +106 -0
  99. package/src/components/editor/chrome/panels/sandbox-panel.tsx +173 -0
  100. package/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx +3 -1
  101. package/src/components/editor/header/__tests__/status.test.tsx +8 -20
  102. package/src/components/editor/header/status.tsx +5 -3
  103. package/src/components/editor/renderers/cell-array.tsx +1 -5
  104. package/src/core/MarimoApp.tsx +0 -2
  105. package/src/core/edit-app.tsx +8 -5
  106. package/src/core/errors/state.ts +1 -2
  107. package/src/core/islands/bootstrap.ts +1 -0
  108. package/src/core/islands/bridge.ts +3 -0
  109. package/src/core/network/connection-notice.ts +84 -0
  110. package/src/core/network/requests-lazy.ts +3 -0
  111. package/src/core/network/requests-network.ts +12 -0
  112. package/src/core/network/requests-static.ts +3 -0
  113. package/src/core/network/requests-toasting.tsx +3 -0
  114. package/src/core/network/resolve.ts +2 -1
  115. package/src/core/network/types.ts +7 -0
  116. package/src/core/packages/__tests__/usePackageAction.test.tsx +129 -0
  117. package/src/core/packages/__tests__/useSandboxController.test.tsx +165 -0
  118. package/src/core/packages/package-data.ts +35 -0
  119. package/src/core/packages/sandbox-state.ts +15 -0
  120. package/src/core/packages/toast-components.tsx +11 -0
  121. package/src/core/packages/useInstallPackage.ts +1 -1
  122. package/src/core/packages/usePackageAction.ts +51 -0
  123. package/src/core/packages/usePackageDependencies.ts +22 -0
  124. package/src/core/packages/useSandboxController.ts +188 -0
  125. package/src/core/run-app.tsx +2 -0
  126. package/src/core/wasm/bridge.ts +11 -0
  127. package/src/core/websocket/__tests__/useMarimoKernelConnection.hook.test.tsx +212 -2
  128. package/src/core/websocket/types.ts +11 -1
  129. package/src/core/websocket/useMarimoKernelConnection.tsx +43 -8
  130. package/src/stories/sandbox.stories.tsx +308 -0
  131. package/dist/assets/app-config-button-BgRYYpoH.js +0 -1
  132. package/dist/assets/cache-panel-DP6AuApU.js +0 -1
  133. package/dist/assets/config-D4PQ0ExB.js +0 -1
  134. package/dist/assets/edit-page-B5T44oKE.js +0 -184
  135. package/dist/assets/has-BPYf0PV2.js +0 -1
  136. package/dist/assets/index-Bit3pmfj.css +0 -2
  137. package/dist/assets/index-D3ydSabW.js +0 -62
  138. package/dist/assets/packages-panel-BvnEJCqo.js +0 -1
  139. package/dist/assets/panels-DvYa8VJO.js +0 -33
  140. package/dist/assets/run-page-BIX2SnOg.js +0 -1
@@ -1 +1 @@
1
- import{n as e}from"./chunk-Y2CYZVJY-DsF7k-Jl.js";import{t}from"./src-Cyu5G-Tr.js";import"./chunk-DU6HZSFF-J-califE.js";import"./mermaid-LovyOmSB.js";import{m as n,t as r}from"./mermaid-parser.core-3RKOfUXB.js";import{n as i,r as a,t as o}from"./chunk-SVP7TREG-DYlo9xS8.js";import{t as s}from"./chunk-JWPE2WC7-DVXcaiue.js";var c=n().RailroadAbnf.parser.LangiumParser,l=e(e=>{let t=e.alternatives.map(u);return t.length===1?t[0]:{type:`choice`,alternatives:t}},`transformAlternation`),u=e(e=>{let t=e.elements.map(f);return t.length===1?t[0]:{type:`sequence`,elements:t}},`transformConcatenation`),d=e(e=>{if(e.includes(`*`)){let[t,n]=e.split(`*`);return{min:t?parseInt(t,10):0,max:n?parseInt(n,10):1/0}}let t=parseInt(e,10);return{min:t,max:t}},`parseRepeat`),f=e(e=>{let t=p(e.primary);if(!e.repeat)return t;let{min:n,max:r}=d(e.repeat);return n===0&&r===1?{type:`optional`,element:t}:{type:`repetition`,element:t,min:n,max:r}},`transformElement`),p=e(e=>{switch(e.$type){case`AbnfStringLiteral`:return{type:`terminal`,value:e.value};case`AbnfNumVal`:return{type:`terminal`,value:e.value};case`AbnfRuleName`:return{type:`nonterminal`,name:e.name};case`AbnfGroup`:return l(e.element);case`AbnfOptionalGroup`:return{type:`optional`,element:l(e.element)};default:throw Error(`Unsupported ABNF primary node: ${e.$type}`)}},`transformPrimary`),m=e(e=>({name:e.name,definition:l(e.definition)}),`transformRule`),h=e(e=>{s(e,o),e.title&&o.setTitle(e.title),e.rules.map(e=>o.addRule(m(e)))},`populateDb`),g={parser:{parse:e(e=>{o.clear(),t.debug(`[ABNF Parser] Starting Langium parse`);let n=c.parse(e);if(n.lexerErrors.length>0||n.parserErrors.length>0)throw new r(n);let i=n.value;t.debug(`[ABNF Parser] Parsed rules:`,i.rules.length),h(i),t.debug(`[ABNF Parser] Parse complete`)},`parse`),parser:{yy:o}},db:o,renderer:a,styles:i};export{g as diagram};
1
+ import{n as e}from"./chunk-Y2CYZVJY-DsF7k-Jl.js";import{t}from"./src-Cyu5G-Tr.js";import"./chunk-DU6HZSFF-J-califE.js";import"./mermaid-BLxkTwc2.js";import{m as n,t as r}from"./mermaid-parser.core-3RKOfUXB.js";import{n as i,r as a,t as o}from"./chunk-SVP7TREG-DXVPjbAe.js";import{t as s}from"./chunk-JWPE2WC7-DVXcaiue.js";var c=n().RailroadAbnf.parser.LangiumParser,l=e(e=>{let t=e.alternatives.map(u);return t.length===1?t[0]:{type:`choice`,alternatives:t}},`transformAlternation`),u=e(e=>{let t=e.elements.map(f);return t.length===1?t[0]:{type:`sequence`,elements:t}},`transformConcatenation`),d=e(e=>{if(e.includes(`*`)){let[t,n]=e.split(`*`);return{min:t?parseInt(t,10):0,max:n?parseInt(n,10):1/0}}let t=parseInt(e,10);return{min:t,max:t}},`parseRepeat`),f=e(e=>{let t=p(e.primary);if(!e.repeat)return t;let{min:n,max:r}=d(e.repeat);return n===0&&r===1?{type:`optional`,element:t}:{type:`repetition`,element:t,min:n,max:r}},`transformElement`),p=e(e=>{switch(e.$type){case`AbnfStringLiteral`:return{type:`terminal`,value:e.value};case`AbnfNumVal`:return{type:`terminal`,value:e.value};case`AbnfRuleName`:return{type:`nonterminal`,name:e.name};case`AbnfGroup`:return l(e.element);case`AbnfOptionalGroup`:return{type:`optional`,element:l(e.element)};default:throw Error(`Unsupported ABNF primary node: ${e.$type}`)}},`transformPrimary`),m=e(e=>({name:e.name,definition:l(e.definition)}),`transformRule`),h=e(e=>{s(e,o),e.title&&o.setTitle(e.title),e.rules.map(e=>o.addRule(m(e)))},`populateDb`),g={parser:{parse:e(e=>{o.clear(),t.debug(`[ABNF Parser] Starting Langium parse`);let n=c.parse(e);if(n.lexerErrors.length>0||n.parserErrors.length>0)throw new r(n);let i=n.value;t.debug(`[ABNF Parser] Parsed rules:`,i.rules.length),h(i),t.debug(`[ABNF Parser] Parse complete`)},`parse`),parser:{yy:o}},db:o,renderer:a,styles:i};export{g as diagram};
@@ -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-Dc9HkKI2.js";import{t as l}from"./react-CUdNIagt.js";import{Ao as u,D as d,Ga as f,Ha as p,Ja as m,Mi as h,Ua as g,Ui as _,Un as v,Wa as y,ai as b,b as x,bo as S,ca as C,ci as ee,co as te,da as ne,dr as re,f as w,fa as ie,fo as T,ir as E,it as D,ko as ae,qt as oe,vo as se,xo as ce,yt as le}from"./cells-DcI93as7.js";import{A as ue,B as de,C as fe,D as pe,E as me,I as he,L as ge,N as _e,P as O,R as ve,S as ye,T as be,W as xe,_ as Se,j as k,k as Ce,v as we,w as Te,x as Ee,y as De}from"./schemas-BL-NsLlF.js";import{t as Oe}from"./compiler-runtime-BQ9S8nyo.js";import{n as ke}from"./utils-B3E7otfg.js";import{j as Ae,t as je}from"./ai-model-dropdown-CFjRFxPs.js";import{f as Me,g as A}from"./useEventListener-BdZUApHd.js";import{o as Ne}from"./config-D4PQ0ExB.js";import{t as Pe}from"./cn-ldLVeaqm.js";import{t as Fe}from"./jsx-runtime-B74pBk57.js";import{a as Ie,c as Le,p as Re,r as ze,t as Be}from"./dropdown-menu-qMsCfCym.js";import{t as Ve}from"./tooltip-Dnxk1tcQ.js";import{t as j}from"./button-BoklZTGL.js";import{Gt as He,Qt as Ue,Tt as We,Wt as Ge,Zt as Ke,at as qe,dt as Je,en as Ye,qt as Xe,st as Ze,ut as Qe,wt as $e}from"./dist-BczecT6V.js";import{t as et}from"./createReducer-BPvK7C_R.js";import{h as tt,n as nt,o as rt,r as it}from"./dist-Ccyblc8N.js";import{i as at}from"./strings-BHZPE0Mc.js";import{t as ot}from"./requests-yTHMxhVa.js";import{t as st}from"./createLucideIcon-rHn2EdoM.js";import{i as ct,r as lt}from"./paths-CzfpItSz.js";import{r as ut}from"./useNumberFormatter-C4-_TnkF.js";import{a as dt,n as ft,t as pt}from"./process-output-CVZMao0e.js";import{r as mt}from"./input-DPJmbuuZ.js";import{n as ht}from"./dist-DBqBVprh.js";import{t as gt}from"./uuid-k9DpjH68.js";import{t as _t}from"./use-toast-CC89xOwH.js";import{a as vt}from"./session-C8nQMsOE.js";import{r as yt}from"./useTheme-Ho3YdAx3.js";import{a as bt}from"./errors-D9vyuMar.js";import{$r as xt,C as St,Cr as Ct,Ct as wt,Ei as Tt,Gn as Et,Pa as Dt,Sr as Ot,T as kt,Tr as At,br as jt,hi as Mt,k as Nt,o as Pt,qt as Ft,rr as It,wa as Lt,wr as Rt,xr as zt,ya as Bt,yr as Vt,za as Ht}from"./index-D3ydSabW.js";var Ut=st(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),Wt=st(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Gt=st(`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`}]]),Kt=st(`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`}]]),M=Oe(),qt=`vercel.ai.error`,Jt=Symbol.for(qt),Yt,Xt,N=class e extends (Xt=Error,Yt=Jt,Xt){constructor({name:e,message:t,cause:n}){super(t),this[Yt]=!0,this.name=e,this.cause=n}static isInstance(t){return e.hasMarker(t,qt)}static hasMarker(e,t){let n=Symbol.for(t);return typeof e==`object`&&!!e&&n in e&&typeof e[n]==`boolean`&&e[n]===!0}};function Zt(e){return e==null?`unknown error`:typeof e==`string`?e:e instanceof Error?e.toString():JSON.stringify(e)}var Qt=`AI_InvalidArgumentError`,$t=`vercel.ai.error.${Qt}`,en=Symbol.for($t),tn,nn,rn=class extends (nn=N,tn=en,nn){constructor({message:e,cause:t,argument:n}){super({name:Qt,message:e,cause:t}),this[tn]=!0,this.argument=n}static isInstance(e){return N.hasMarker(e,$t)}},an=`AI_JSONParseError`,on=`vercel.ai.error.${an}`,sn=Symbol.for(on),cn,ln,un=class extends (ln=N,cn=sn,ln){constructor({text:e,cause:t}){super({name:an,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-Dc9HkKI2.js";import{t as l}from"./react-CUdNIagt.js";import{Ao as u,D as d,Ga as f,Ha as p,Ja as m,Mi as h,Ua as g,Ui as _,Un as v,Wa as y,ai as b,b as x,bo as S,ca as C,ci as ee,co as te,da as ne,dr as re,f as w,fa as ie,fo as T,ir as E,it as D,ko as ae,qt as oe,vo as se,xo as ce,yt as le}from"./cells-CP3hwqVX.js";import{A as ue,B as de,C as fe,D as pe,E as me,I as he,L as ge,N as _e,P as O,R as ve,S as ye,T as be,W as xe,_ as Se,j as k,k as Ce,v as we,w as Te,x as Ee,y as De}from"./schemas-BL-NsLlF.js";import{t as Oe}from"./compiler-runtime-BQ9S8nyo.js";import{n as ke}from"./utils-B3E7otfg.js";import{j as Ae,t as je}from"./ai-model-dropdown-JyOkbRgs.js";import{f as Me,g as A}from"./useEventListener-BdZUApHd.js";import{o as Ne}from"./config-CBLBAU5c.js";import{t as Pe}from"./cn-ldLVeaqm.js";import{t as Fe}from"./jsx-runtime-B74pBk57.js";import{a as Ie,c as Le,p as Re,r as ze,t as Be}from"./dropdown-menu-qMsCfCym.js";import{t as Ve}from"./tooltip-Dnxk1tcQ.js";import{t as j}from"./button-BoklZTGL.js";import{Gt as He,Qt as Ue,Tt as We,Wt as Ge,Zt as Ke,at as qe,dt as Je,en as Ye,qt as Xe,st as Ze,ut as Qe,wt as $e}from"./dist-BczecT6V.js";import{t as et}from"./createReducer-BPvK7C_R.js";import{h as tt,n as nt,o as rt,r as it}from"./dist-Ccyblc8N.js";import{i as at}from"./strings-BHZPE0Mc.js";import{t as ot}from"./requests-yTHMxhVa.js";import{t as st}from"./createLucideIcon-rHn2EdoM.js";import{i as ct,r as lt}from"./paths-CzfpItSz.js";import{r as ut}from"./useNumberFormatter-C4-_TnkF.js";import{a as dt,n as ft,t as pt}from"./process-output-COWXLjOr.js";import{r as mt}from"./input-DPJmbuuZ.js";import{n as ht}from"./dist-DBqBVprh.js";import{t as gt}from"./uuid-k9DpjH68.js";import{t as _t}from"./use-toast-CC89xOwH.js";import{a as vt}from"./session-C8nQMsOE.js";import{r as yt}from"./useTheme-Ho3YdAx3.js";import{a as bt}from"./errors-D9vyuMar.js";import{C as xt,Ca as St,Cr as Ct,Ct as wt,Er as Tt,Gn as Et,Pa as Dt,Sr as Ot,T as kt,Tr as At,br as jt,ei as Mt,gi as Nt,ir as Pt,k as Ft,ki as It,o as Lt,qt as Rt,wr as zt,xr as Bt,ya as Vt,za as Ht}from"./index-qY3lu9r4.js";var Ut=st(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),Wt=st(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Gt=st(`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`}]]),Kt=st(`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`}]]),M=Oe(),qt=`vercel.ai.error`,Jt=Symbol.for(qt),Yt,Xt,N=class e extends (Xt=Error,Yt=Jt,Xt){constructor({name:e,message:t,cause:n}){super(t),this[Yt]=!0,this.name=e,this.cause=n}static isInstance(t){return e.hasMarker(t,qt)}static hasMarker(e,t){let n=Symbol.for(t);return typeof e==`object`&&!!e&&n in e&&typeof e[n]==`boolean`&&e[n]===!0}};function Zt(e){return e==null?`unknown error`:typeof e==`string`?e:e instanceof Error?e.toString():JSON.stringify(e)}var Qt=`AI_InvalidArgumentError`,$t=`vercel.ai.error.${Qt}`,en=Symbol.for($t),tn,nn,rn=class extends (nn=N,tn=en,nn){constructor({message:e,cause:t,argument:n}){super({name:Qt,message:e,cause:t}),this[tn]=!0,this.argument=n}static isInstance(e){return N.hasMarker(e,$t)}},an=`AI_JSONParseError`,on=`vercel.ai.error.${an}`,sn=Symbol.for(on),cn,ln,un=class extends (ln=N,cn=sn,ln){constructor({text:e,cause:t}){super({name:an,message:`JSON parsing failed: Text: ${e}.
2
2
  Error message: ${Zt(t)}`,cause:t}),this[cn]=!0,this.text=e}static isInstance(e){return N.hasMarker(e,on)}},dn=`AI_TypeValidationError`,fn=`vercel.ai.error.${dn}`,pn=Symbol.for(fn),mn,hn,gn=class e extends (hn=N,mn=pn,hn){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:dn,message:`${r}: Value: ${JSON.stringify(e)}.
3
3
  Error message: ${Zt(t)}`,cause:t}),this[mn]=!0,this.value=e,this.context=n}static isInstance(e){return N.hasMarker(e,fn)}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})}},_n=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}},vn=10,yn=13,bn=32;function xn(e){}function Sn(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=xn,onError:n=xn,onRetry:r=xn,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 _n(`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,7 +41,7 @@ ${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.`},fo=k({edit:k({type:Se([`update_cell`,`add_cell`,`delete_cell`]),code:O().optional(),position:k({type:Se([`relative`,`column_end`,`notebook_end`]).optional(),cellId:O().optional(),columnIndex:ue().optional(),before:ye().optional()})})}),po=class{name=`edit_notebook_tool`;description=uo;schema=fo;outputSchema=qa;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(x);this.validateCellIdExists(a,o);let s=this.getCellEditorView(a,o);It(a);let c=i.get(Z).get(a);if(c?.type===`add_cell`){le(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}}),le(s,r);break}case`add_cell`:{let{position:t,code:a}=e,o=`__end__`,s=!1,c=ae.create(),l=i.get(x);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`}}),It(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(x);this.validateCellIdExists(r,a),n({cellId:r,edit:{type:`delete_cell`,previousCode:this.getCellEditorView(r,a).state.doc.toString()}}),It(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 mo(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 Rt{title=`Cell Outputs`;mentionPrefix=`@`;contextType=`cell-output`;store;constructor(e){super(),this.store=e}getItems(){let e=this.store.get(x),t=[];for(let n of e.cellIds.inOrderIds){let r=vo(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`?zt.HIGH:zt.MEDIUM,type:this.contextType,section:Ot.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}`)),Ct({type:this.contextType,data:a,details:o})}async getAttachments(e){let t=e[0].data.cellId,n=e[0].data.cellName;return go(e.map(e=>e.data.cellOutput),t,n)}};async function go(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(u.create(t));return r?{cellId:t,cellName:n,mimetype:e.output.mimetype,element:r}:(A.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 Ft(e.element)})))}catch(e){return A.error(`Error downloading cell output images:`,e),[]}}function _o(e){if(Et(e))return null;let t=e.mimetype,n=mo(t,String(e.data))?`media`:`text`,r=pt(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 vo(e,t,n){let{includeConsoleOutput:r=!1}=n||{},i=t.cellRuntime[e],a=t.cellData[e],o=t.cellIds.inOrderIds.indexOf(e),s=v(a.name,o),c;r&&(c=i.consoleOutputs.map(e=>_o(e)).filter(e=>e!==null));let l,u=i.output;return u&&!Et(u)&&(l=_o(u)??void 0),{cellId:e,cellName:s,cellCode:a.code,cellOutput:l,consoleOutputs:c}}var yo=200,bo=3e4,xo=2e3,So=3e3,Co=4e4,wo={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.`},To=k({type:me(`file`),url:O(),mediaType:O()}),Eo=class{name=`run_stale_cells_tool`;description=wo;schema=k({});outputSchema=qa.extend({cellsToOutput:_e(O(),k({consoleOutput:O().optional(),cellOutput:O().optional(),consoleAttachments:Ee(To).optional(),cellAttachments:Ee(To).optional()}).nullable()).optional()});mode=[`agent`];postExecutionDelay;constructor(e){this.postExecutionDelay=e?.postExecutionDelay??yo}handler=async(e,t)=>{let{prepareForRun:n,sendRun:r,store:i}=t,a=i.get(x),o=p(a);if(o.length===0)return{status:`success`,message:`No stale cells found.`};if(await Tt({cellIds:o,sendRun:r,prepareForRun:n,notebook:a}),!await this.waitForCellsToFinish(i,o,bo,this.postExecutionDelay))return{status:`success`,message:`No output was returned because some cells have not finished executing`};let s=i.get(x),c=new Map,l=!1,u=!1,d=0;for(let e of o){let t=vo(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>=Co){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.`},fo=k({edit:k({type:Se([`update_cell`,`add_cell`,`delete_cell`]),code:O().optional(),position:k({type:Se([`relative`,`column_end`,`notebook_end`]).optional(),cellId:O().optional(),columnIndex:ue().optional(),before:ye().optional()})})}),po=class{name=`edit_notebook_tool`;description=uo;schema=fo;outputSchema=qa;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(x);this.validateCellIdExists(a,o);let s=this.getCellEditorView(a,o);Pt(a);let c=i.get(Z).get(a);if(c?.type===`add_cell`){le(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}}),le(s,r);break}case`add_cell`:{let{position:t,code:a}=e,o=`__end__`,s=!1,c=ae.create(),l=i.get(x);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`}}),Pt(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(x);this.validateCellIdExists(r,a),n({cellId:r,edit:{type:`delete_cell`,previousCode:this.getCellEditorView(r,a).state.doc.toString()}}),Pt(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 mo(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 At{title=`Cell Outputs`;mentionPrefix=`@`;contextType=`cell-output`;store;constructor(e){super(),this.store=e}getItems(){let e=this.store.get(x),t=[];for(let n of e.cellIds.inOrderIds){let r=vo(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`?Ot.HIGH:Ot.MEDIUM,type:this.contextType,section:Ct.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}`)),zt({type:this.contextType,data:a,details:o})}async getAttachments(e){let t=e[0].data.cellId,n=e[0].data.cellName;return go(e.map(e=>e.data.cellOutput),t,n)}};async function go(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(u.create(t));return r?{cellId:t,cellName:n,mimetype:e.output.mimetype,element:r}:(A.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 Rt(e.element)})))}catch(e){return A.error(`Error downloading cell output images:`,e),[]}}function _o(e){if(Et(e))return null;let t=e.mimetype,n=mo(t,String(e.data))?`media`:`text`,r=pt(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 vo(e,t,n){let{includeConsoleOutput:r=!1}=n||{},i=t.cellRuntime[e],a=t.cellData[e],o=t.cellIds.inOrderIds.indexOf(e),s=v(a.name,o),c;r&&(c=i.consoleOutputs.map(e=>_o(e)).filter(e=>e!==null));let l,u=i.output;return u&&!Et(u)&&(l=_o(u)??void 0),{cellId:e,cellName:s,cellCode:a.code,cellOutput:l,consoleOutputs:c}}var yo=200,bo=3e4,xo=2e3,So=3e3,Co=4e4,wo={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.`},To=k({type:me(`file`),url:O(),mediaType:O()}),Eo=class{name=`run_stale_cells_tool`;description=wo;schema=k({});outputSchema=qa.extend({cellsToOutput:_e(O(),k({consoleOutput:O().optional(),cellOutput:O().optional(),consoleAttachments:Ee(To).optional(),cellAttachments:Ee(To).optional()}).nullable()).optional()});mode=[`agent`];postExecutionDelay;constructor(e){this.postExecutionDelay=e?.postExecutionDelay??yo}handler=async(e,t)=>{let{prepareForRun:n,sendRun:r,store:i}=t,a=i.get(x),o=p(a);if(o.length===0)return{status:`success`,message:`No stale cells found.`};if(await It({cellIds:o,sendRun:r,prepareForRun:n,notebook:a}),!await this.waitForCellsToFinish(i,o,bo,this.postExecutionDelay))return{status:`success`,message:`No output was returned because some cells have not finished executing`};let s=i.get(x),c=new Map,l=!1,u=!1,d=0;for(let e of o){let t=vo(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>=Co){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,xo),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)?So:xo,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(x)))return await o();try{return await Promise.race([n(x,a),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),r))]),await o()}catch{return!1}}};function Do(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(`
@@ -52,14 +52,14 @@ ${t}`,d++;break;case`id`:l=t.includes(`\0`)?void 0:t;break;case`retry`:/^\d+$/.t
52
52
 
53
53
  `)}function Ro(e,t){let n=[`Code:\n${e.cellCode}`];if(e.tracebackHtml&&n.push(`Traceback:\n${D(e.tracebackHtml)}`),e.errorData.length>0&&n.push(e.errorData.map(e=>Io(e)).join(`
54
54
 
55
- `)),e.errorData.some(e=>e.type===`sql-error`)){let r=jt(e.cellId,t);r&&n.push(`Database schema:\n${r}`)}return n.join(`
55
+ `)),e.errorData.some(e=>e.type===`sql-error`)){let r=Bt(e.cellId,t);r&&n.push(`Database schema:\n${r}`)}return n.join(`
56
56
 
57
- `)}function zo(e,t){return Ct({type:`error`,data:{name:e.cellName||`Cell ${e.cellId}`,cellId:e.cellId},details:Ro(e,t)})}function Bo(e){return e.errorData.length===1?Fo(e.errorData[0]):e.errorData.length>1?`${e.errorData.length} errors`:e.tracebackHtml?D(e.tracebackHtml).trim().split(`
58
- `).find(e=>e.trim())?.trim()||`traceback`:`error`}function Vo(e){return`Error: ${e.cellName||`Cell ${e.cellId}`}`}var Ho=new h(`error`,`errors`),Uo=class extends Rt{title=`Errors`;mentionPrefix=`@`;contextType=`error`;store;constructor(e){super(),this.store=e}getItems(){let e=Po(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:Vo(n),type:this.contextType,data:{type:`cell-error`,error:n},description:Bo(n)});return t}formatCompletion(e){if(e.data.type===`all-errors`){let t=e.data.errors.length;return{label:`@Errors`,displayLabel:`Errors`,detail:`${t} ${Ho.pluralize(t)}`,type:`error`,apply:`@error://all`,section:Ot.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} ${Ho.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:Bo(t),type:`error`}),section:Ot.ERROR}}return{label:`Error`,displayLabel:`Error`,section:Ot.ERROR}}formatContext(e){return(e.data.type===`all-errors`?e.data.errors:[e.data.error]).map(e=>zo(e,this.store)).join(`
57
+ `)}function zo(e,t){return zt({type:`error`,data:{name:e.cellName||`Cell ${e.cellId}`,cellId:e.cellId},details:Ro(e,t)})}function Bo(e){return e.errorData.length===1?Fo(e.errorData[0]):e.errorData.length>1?`${e.errorData.length} errors`:e.tracebackHtml?D(e.tracebackHtml).trim().split(`
58
+ `).find(e=>e.trim())?.trim()||`traceback`:`error`}function Vo(e){return`Error: ${e.cellName||`Cell ${e.cellId}`}`}var Ho=new h(`error`,`errors`),Uo=class extends At{title=`Errors`;mentionPrefix=`@`;contextType=`error`;store;constructor(e){super(),this.store=e}getItems(){let e=Po(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:Vo(n),type:this.contextType,data:{type:`cell-error`,error:n},description:Bo(n)});return t}formatCompletion(e){if(e.data.type===`all-errors`){let t=e.data.errors.length;return{label:`@Errors`,displayLabel:`Errors`,detail:`${t} ${Ho.pluralize(t)}`,type:`error`,apply:`@error://all`,section:Ct.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} ${Ho.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:Bo(t),type:`error`}),section:Ct.ERROR}}return{label:`Error`,displayLabel:`Error`,section:Ct.ERROR}}formatContext(e){return(e.data.type===`all-errors`?e.data.errors:[e.data.error]).map(e=>zo(e,this.store)).join(`
59
59
 
60
- `)}},Wo=m(),Go={maxDepth:3,maxResults:20,defaultResultsLimit:5,includeDirectories:!1},Ko=class extends Rt{title=`Files`;mentionPrefix=`#`;contextType=`file`;apiRequests;config;constructor(e,t=Go){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 A.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){A.error(`Failed to get default file completions:`,e)}return{from:e.from,options:[]}}catch(e){return A.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:Ot.FILE,boost:t.isDirectory?zt.MEDIUM:zt.LOW,detail:t.path,displayLabel:`${r} ${n}`,apply:async(e,r,i,a)=>{let o=e.state.facet(Wo)?.addAttachment;if(!o){A.warn(`No addAttachment callback provided`);return}let s=await this.apiRequests.sendFileDetails({path:t.path}).catch(e=>(_t({title:`Failed to get file details`,description:e.message}),null));if(!s)return;let c=s.mimeType||`text/plain`,l=Mt({contents:s.contents??``,mimeType:c,isBase64:s.isBase64??!1});o(new File([l],n,{type:c})),e.dispatch({changes:{from:i,to:a,insert:``}}),rt(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 Ct({type:this.contextType,data:{name:n,path:t.path,isDirectory:t.isDirectory},details:t.isDirectory?`Directory containing files and subdirectories`:`File`})}},qo=class extends Rt{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:
61
- `;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 Ct({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`?zt.LOCAL_TABLE:zt.REMOTE_TABLE,type:ie(n),apply:`@${t}`,section:{name:ie(n)===`dataframe`?`Dataframe`:`Table`,rank:Ot.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}}},Jo=class extends Rt{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:Ot.VARIABLE,info:()=>re(n)}}formatContext(e){let{data:t}=e,{variable:n}=t;return Ct({type:this.contextType,data:{name:n.name,dataType:n.dataType},details:n.value==null?void 0:JSON.stringify(n.value)})}};function Yo(e){let t=e.get(ne),n=e.get(C),r=e.get(ee);return new At().register(new qo(n)).register(new Jo(r,n)).register(new Uo(e)).register(new ho(e)).register(new Vt(t.connectionsMap,n))}function Xo(){return new Ko(ot())}function Zo({input:e}){let t=``;return e.includes(`@`)&&(t=as(e),A.debug(`Included context`,t)),{includeOtherCode:E(``),context:{plainText:t,schema:[],variables:[]}}}var Qo=`data-marimo-context`,$o={marimo:{source:`context`}};function es(e){return e.type===`file`&&e.providerMetadata?.marimo?.source===$o.marimo.source}function ts(e){return{...e,providerMetadata:{...e.providerMetadata,marimo:{...e.providerMetadata?.marimo,...$o.marimo}}}}async function ns(e){if(!e.includes(`@`))return{plainText:``,contextIds:[],attachments:[]};let t=Yo(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(ts)}catch(e){A.error(`Error getting attachments:`,e)}return{plainText:r,contextIds:n,attachments:i}}async function rs(e){let{plainText:t,contextIds:n,attachments:r}=await ns(e),i=null;return t.trim()&&(i={type:Qo,data:{plainText:t,contextIds:n.map(String)}}),{contextPart:i,attachments:r}}async function is({input:e}){let{plainText:t,attachments:n}=await ns(e);return{body:{includeOtherCode:E(``),context:{plainText:t,schema:[],variables:[]}},attachments:n}}function as(e){let t=Yo(s),n=t.parseAllContextIds(e);return t.formatContextForAI(n)}function os(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 ss(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(),tt(e.current.view)}}var cs=new Set([`openai`,`google`,`anthropic`]),ls=[`image/*`,`text/*`],us=52428800;function ds(e){return e.length>50?`${e.slice(0,50)}...`:e}async function fs(e){return await Promise.all(e.map(async e=>({type:`file`,mediaType:e.type,filename:e.name,url:await Pt(e,`dataUrl`)})))}function ps(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 ms(e){return e.map(e=>e.type===`text`?e.text:``).join(`
62
- `)}async function hs(e){let t=await is({input:ms(e.flatMap(e=>e.parts))});function n(e,n){return n?{...e,parts:[...e.parts,...t.attachments]}:e}return{...t.body,uiMessages:e.map((t,r)=>n(t,r===e.length-1))}}async function gs({invokeAiTool:e,addToolOutput:t,toolCall:n,toolContext:r}){try{if(ko.has(n.toolName)){let e=await ko.invoke({toolName:n.toolName,rawArgs:n.input,toolContext:r});t({tool:n.toolName,toolCallId:n.toolCallId,output:e.result||e.error})}else{let r=await e({toolName:n.toolName,arguments:n.input??{}});t({tool:n.toolName,toolCallId:n.toolCallId,output:r.result||r.error})}}catch(e){A.error(`Tool call failed:`,e),t({tool:n.toolName,toolCallId:n.toolCallId,output:`Error: ${e instanceof Error?e.message:String(e)}`})}}function _s(e){let t=e.at(-1);if(!t||t.role!==`assistant`)return!1;let n=t.parts.at(-1);return!n||!H(n)?!1:va({messages:e})||_a({messages:e})||n.state===`output-denied`&&!n.providerExecuted}function vs(e){let t=e.at(-1);return!t||t.role!==`assistant`?!1:t.parts.some(e=>H(e)&&ys(e.state))}function ys(e){switch(e){case`approval-requested`:case`input-streaming`:case`input-available`:return!0;case`approval-responded`:case`output-available`:case`output-error`:case`output-denied`:return!1;default:return e}}function bs(){let e=(0,M.c)(7),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0];let[n,r]=(0,W.useState)(t),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=e=>{if(e.length!==0){if(e.reduce(xs,0)>us){_t({title:`File size exceeded`,description:`Attachments must be under 50 MB`,variant:`danger`});return}r(t=>[...t,...e])}},e[1]=i):i=e[1];let a=c(i),o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>r([]),e[2]=o):o=e[2];let s=o,l;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=e=>r(t=>t.filter(t=>t!==e)),e[3]=l):l=e[3];let u=l,d;return e[4]!==a||e[5]!==n?(d={files:n,addFiles:a,clearFiles:s,removeFile:u},e[4]=a,e[5]=n,e[6]=d):d=e[6],d}function xs(e,t){return e+t.size}function Ss(e){return e.isError?!1:e.isAbort?!0:!e.hasPendingToolCalls&&!e.hasUnresolvedToolCalls}function Cs(){let[e,t]=(0,W.useState)([]),n=(0,W.useRef)([]),r=(0,W.useRef)(!1);return n.current=e,r.current=e.length>0,{messages:e,enqueue:c(e=>{t(t=>{let i=[...t,{id:gt(),parts:e}];return n.current=i,r.current=!0,i})}),flushNext:c(e=>{let i=n.current;if(i.length===0)return;let[a,...o]=i;n.current=o,r.current=o.length>0,t(o),e(a.parts)}),clear:c(()=>{n.current=[],r.current=!1,t([])}),hasQueuedRef:r}}var ws=e=>{let t=(0,M.c)(6),{attachment:n}=e;if(n.mediaType?.startsWith(`image/`)){let e=n.filename||`Attachment`,r;return t[0]!==n.url||t[1]!==e?(r=(0,G.jsx)(`img`,{src:n.url,alt:e,className:`max-h-[100px] max-w-[100px] object-contain mb-1.5`}),t[0]=n.url,t[1]=e,t[2]=r):r=t[2],r}let r;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,G.jsx)(Lt,{className:`h-3 w-3 mt-0.5`}),t[3]=r):r=t[3];let i=n.filename||`Attachment`,a;return t[4]===i?a=t[5]:(a=(0,G.jsxs)(`div`,{className:`flex flex-row gap-1 items-center text-xs`,children:[r,i]}),t[4]=i,t[5]=a),a},Ts=e=>{let t=(0,M.c)(12),{file:n,className:r,onRemove:i}=e,[a,o]=(0,W.useState)(!1),s;t[0]===r?s=t[1]:(s=Pe(`py-1 px-1.5 bg-muted rounded-md cursor-pointer flex flex-row gap-1 items-center text-xs`,r),t[0]=r,t[1]=s);let c,l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>o(!0),l=()=>o(!1),t[2]=c,t[3]=l):(c=t[2],l=t[3]);let u;t[4]!==n||t[5]!==a||t[6]!==i?(u=a?(0,G.jsx)(ut,{className:`h-3 w-3 mt-0.5`,onClick:i}):ks(n),t[4]=n,t[5]=a,t[6]=i,t[7]=u):u=t[7];let d;return t[8]!==n.name||t[9]!==s||t[10]!==u?(d=(0,G.jsxs)(`div`,{className:s,onMouseEnter:c,onMouseLeave:l,children:[u,n.name]}),t[8]=n.name,t[9]=s,t[10]=u,t[11]=d):d=t[11],d},Es=e=>{let t=(0,M.c)(12),{isLoading:n,onStop:r,onSendClick:i,isEmpty:a,showStopLabel:o}=e,s=o!==void 0&&o,c;t[0]===s?c=t[1]:(c=s?(0,G.jsxs)(`div`,{className:`flex flex-row items-center gap-1 px-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-error`,children:`Stop`}),(0,G.jsx)(xt,{size:`small`})]}):(0,G.jsx)(Wt,{className:`size-4 text-error`}),t[0]=s,t[1]=c);let l=c,u=n?`Stop`:`Submit`,d=n?r:i,f=!n&&a,p;t[2]!==n||t[3]!==l?(p=n?l:(0,G.jsx)(Kt,{className:`h-3.5 w-3.5`}),t[2]=n,t[3]=l,t[4]=p):p=t[4];let m;t[5]!==d||t[6]!==f||t[7]!==p?(m=(0,G.jsx)(j,{variant:`text`,size:`sm`,className:`h-6 min-w-6 p-0 hover:bg-muted/30 cursor-pointer`,onClick:d,disabled:f,children:p}),t[5]=d,t[6]=f,t[7]=p,t[8]=m):m=t[8];let h;return t[9]!==u||t[10]!==m?(h=(0,G.jsx)(Ve,{content:u,children:m}),t[9]=u,t[10]=m,t[11]=h):h=t[11],h},Ds=e=>{let t=(0,M.c)(4),{handleAddContext:n,isLoading:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,G.jsx)(Ht,{className:`h-3.5 w-3.5`}),t[0]=i):i=t[0];let a;return t[1]!==n||t[2]!==r?(a=(0,G.jsx)(Ve,{content:`Add context`,children:(0,G.jsx)(j,{variant:`text`,size:`icon`,onClick:n,disabled:r,children:i})}),t[1]=n,t[2]=r,t[3]=a):a=t[3],a},Os=e=>{let t=(0,M.c)(15),{fileInputRef:n,isLoading:r,onAddFiles:i}=e,a;t[0]===n?a=t[1]:(a=()=>n.current?.click(),t[0]=n,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,G.jsx)(Gt,{className:`h-3.5 w-3.5`}),t[2]=o):o=t[2];let s;t[3]!==r||t[4]!==a?(s=(0,G.jsx)(Ve,{content:`Attach a file`,children:(0,G.jsx)(j,{variant:`text`,size:`icon`,onClick:a,disabled:r,children:o})}),t[3]=r,t[4]=a,t[5]=s):s=t[5];let c;t[6]===i?c=t[7]:(c=e=>{e.target.files&&i([...e.target.files])},t[6]=i,t[7]=c);let l;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(l=ls.join(`,`),t[8]=l):l=t[8];let u;t[9]!==n||t[10]!==c?(u=(0,G.jsx)(mt,{ref:n,type:`file`,multiple:!0,hidden:!0,onChange:c,accept:l}),t[9]=n,t[10]=c,t[11]=u):u=t[11];let d;return t[12]!==s||t[13]!==u?(d=(0,G.jsxs)(G.Fragment,{children:[s,u]}),t[12]=s,t[13]=u,t[14]=d):d=t[14],d};function ks(e){let t=`h-3 w-3 mt-0.5`;return e.type.startsWith(`image/`)?(0,G.jsx)(Bt,{className:t}):e.type.startsWith(`text/`)?(0,G.jsx)(lt,{className:t}):(0,G.jsx)(Lt,{className:t})}var As=e=>{let t=(0,M.c)(15),{icon:n,title:r,subtitle:i,href:a}=e,o;t[0]===r?o=t[1]:(o=(0,G.jsx)(`span`,{className:`truncate font-medium`,children:r}),t[0]=r,t[1]=o);let s;t[2]===i?s=t[3]:(s=i&&(0,G.jsxs)(`span`,{className:`truncate opacity-70`,children:[`(`,i,`)`]}),t[2]=i,t[3]=s);let c;t[4]!==n||t[5]!==o||t[6]!==s?(c=(0,G.jsxs)(G.Fragment,{children:[n,o,s]}),t[4]=n,t[5]=o,t[6]=s,t[7]=c):c=t[7];let l=c;if(a&&vt(a)){let e=i??r,n;return t[8]!==l||t[9]!==a||t[10]!==e?(n=(0,G.jsx)(`a`,{href:a,target:`_blank`,rel:`noopener noreferrer`,title:e,className:`inline-flex max-w-full items-center gap-1.5 rounded-md border bg-muted/50 px-2 py-1 my-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground transition-colors`,children:l}),t[8]=l,t[9]=a,t[10]=e,t[11]=n):n=t[11],n}let u=i??r,d;return t[12]!==l||t[13]!==u?(d=(0,G.jsx)(`div`,{className:`inline-flex max-w-full items-center gap-1.5 rounded-md border bg-muted/50 px-2 py-1 my-1 text-xs text-muted-foreground`,title:u,children:l}),t[12]=l,t[13]=u,t[14]=d):d=t[14],d},js=Ke.define(),Q=Ue.define({create(){return new Map},update(e,t){let n=!1,r=e;for(let i of t.effects)if(i.is(js)){n||=(r=new Map(e),!0);for(let[e,t]of i.value)r.set(e,t)}return r}}),Ms=Ue.define({create(){return{onResourceClick:void 0,onResourceMouseOver:void 0,onResourceMouseOut:void 0,onPromptSubmit:void 0}},update(e){return e}}),Ns=Ke.define();Ue.define({create(){return new Map},update(e,t){let n=!1,r=e;for(let i of t.effects)if(i.is(Ns)){n||=(r=new Map(e),!0);for(let[e,t]of i.value)r.set(e,t)}return r}});var Ps=(e,t)=>async n=>{let r=n.matchBefore(/@(\w+)?/);if(!r||r.from===r.to&&!n.explicit)return null;let i=await e();if(i.length===0)return null;let a=js.of(new Map(i.map(e=>[e.uri,e])));n.view&&n.view.dispatch({effects:a});let o=i.map(e=>({label:`@${e.name}`,displayLabel:e.name,detail:e.uri,info:e.description||void 0,type:e.mimeType?`constant`:`variable`,boost:e.description?100:0,...t?.(e),apply:(t,n,r,i)=>{t.dispatch({changes:{from:r,to:i,insert:`@${e.uri} `}})}}));return{from:r.from,options:o}},Fs=/@[\w-]+:\/\/(?!\/)[^\s]+/;function $(e){return e.matchAll(new RegExp(Fs.source,`g`))}var Is=class extends Je{resource;view;constructor(e,t){super(),this.resource=e,this.view=t}eq(e){return e.resource.uri===this.resource.uri}toDOM(){let e=document.createElement(`span`);e.className=`cm-resource-widget`,e.textContent=`@${this.resource.name}`;let t=this.view.state.field(Ms,!1),n=t?.onResourceClick,r=t?.onResourceMouseOver,i=t?.onResourceMouseOut;return n&&(e.style.cursor=`pointer`,e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),n(this.resource)})),r&&e.addEventListener(`mouseover`,e=>{e.preventDefault(),e.stopPropagation(),r(this.resource)}),i&&e.addEventListener(`mouseout`,e=>{e.preventDefault(),e.stopPropagation(),i(this.resource)}),e}},Ls=class extends Je{uri;view;constructor(e,t){super(),this.uri=e,this.view=t}eq(e){return e.uri===this.uri}toDOM(){let e=document.createElement(`span`);return e.className=`cm-not-found-resource-widget`,e.textContent=`@${this.uri.split(`://`)[1]??this.uri}`,e}};function Rs(e){let t=e.state.field(Q),n=[];for(let{from:r,to:i}of e.visibleRanges){let a=e.state.doc.sliceString(r,i);for(let i of $(a)){let a=r+i.index,o=i[0].slice(1),s=t.get(o);s?n.push(qe.replace({widget:new Is(s,e)}).range(a,a+i[0].length)):n.push(qe.replace({widget:new Ls(o,e)}).range(a,a+i[0].length))}}return qe.set(n)}var zs=Qe.fromClass(class{decorations;constructor(e){this.decorations=Rs(e)}update(e){(e.docChanged||e.viewportChanged||e.transactions.some(e=>e.effects.some(e=>e.is(js))))&&(this.decorations=Rs(e.view))}},{decorations:e=>e.decorations});function Bs(e){let t=document.createElement(`div`);t.className=`cm-tooltip-cursor`;let n=document.createElement(`div`);if(n.className=`cm-tooltip-cursor-title`,n.textContent=`${e.name} (${e.uri})`,t.appendChild(n),e.description){let n=document.createElement(`div`);n.className=`cm-tooltip-cursor-description`,n.textContent=e.description,t.appendChild(n)}if(e.mimeType){let n=document.createElement(`div`);n.className=`cm-tooltip-cursor-mimetype`,n.textContent=e.mimeType,t.appendChild(n)}return{dom:t}}function Vs(e,t,n,r=0){for(let i of $(e)){let e=r+i.index,a=e+i[0].length;if(t>=e&&t<=a){let t=i[0].slice(1),r=n.get(t);if(r)return{resource:r,start:e,end:a}}}return null}function Hs(e){return $e((t,n)=>{let{from:r,text:i}=t.state.doc.lineAt(n),a=Vs(i,n,t.state.field(Q),r);return a?{pos:a.start,end:a.end,above:!0,create(){return(e.createTooltip??Bs)(a.resource)}}:null})}function Us(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t),a=r.sliceString(i.from,i.to),o=Array.from($(a));if(o.length===0)return null;for(let e of o){let r=i.from+e.index,a=r+e[0].length,o=e[0].slice(1);if(t===a&&n.has(o))return{from:r,to:a,uri:o}}return null}function Ws(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t).to,a=r.sliceString(t,i),o=Array.from($(a));if(o.length===0)return null;let s=o[0];if(!s||s.index!==0)return null;let c=t,l=t+s[0].length,u=s[0].slice(1);return n.has(u)?{from:c,to:l,uri:u}:null}function Gs(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t),a=r.sliceString(i.from,i.to),o=Array.from($(a));for(let e of o){let r=i.from+e.index,a=r+e[0].length,o=e[0].slice(1);if(t>r&&t<a&&n.has(o))return{from:r,to:a,uri:o}}return null}function Ks(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t),a=r.sliceString(i.from,t),o=Array.from($(a)),s=null;for(let e of o){let r=i.from+e.index,a=r+e[0].length,o=e[0].slice(1);n.has(o)&&a<=t&&(t>a?s=a:t===a&&(s=r))}return s}function qs(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t),a=r.sliceString(i.from,i.to),o=Array.from($(a));for(let e of o){let r=i.from+e.index,a=r+e[0].length,o=e[0].slice(1);if(n.has(o)&&r>=t){if(t<r)return r;if(t===r)return a}}return null}var Js=Ge.transactionFilter.of(e=>{let t=e.annotation(Ye.userEvent);if(!t)return e;let n=e.startState.selection.main;if(!n.empty)return e;if(t===`input.type`||t.startsWith(`input`)){if(e.changes.empty)return e;let t=e.startState.field(Q),n=e.startState.doc,r=!1,i=0,a=[];if(e.changes.iterChanges((e,o,s,c,l)=>{let u=l.toString(),d=e;if(/^\s+$/.test(u)){a.push({from:e,to:o,insert:u});return}let f=n.lineAt(d),p=n.sliceString(f.from,f.to),m=Array.from($(p)),h=!1,g=!1;for(let e of m){let r=f.from+e.index,i=r+e[0].length,a=e[0].slice(1);if(t.has(a)){if(d===r){let e=d>0?n.sliceString(d-1,d):``;e!==``&&e!==` `&&e!==`
60
+ `)}},Wo=m(),Go={maxDepth:3,maxResults:20,defaultResultsLimit:5,includeDirectories:!1},Ko=class extends At{title=`Files`;mentionPrefix=`#`;contextType=`file`;apiRequests;config;constructor(e,t=Go){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 A.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){A.error(`Failed to get default file completions:`,e)}return{from:e.from,options:[]}}catch(e){return A.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:Ct.FILE,boost:t.isDirectory?Ot.MEDIUM:Ot.LOW,detail:t.path,displayLabel:`${r} ${n}`,apply:async(e,r,i,a)=>{let o=e.state.facet(Wo)?.addAttachment;if(!o){A.warn(`No addAttachment callback provided`);return}let s=await this.apiRequests.sendFileDetails({path:t.path}).catch(e=>(_t({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:``}}),rt(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 zt({type:this.contextType,data:{name:n,path:t.path,isDirectory:t.isDirectory},details:t.isDirectory?`Directory containing files and subdirectories`:`File`})}},qo=class extends At{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:
61
+ `;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 zt({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`?Ot.LOCAL_TABLE:Ot.REMOTE_TABLE,type:ie(n),apply:`@${t}`,section:{name:ie(n)===`dataframe`?`Dataframe`:`Table`,rank:Ct.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}}},Jo=class extends At{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:Ct.VARIABLE,info:()=>re(n)}}formatContext(e){let{data:t}=e,{variable:n}=t;return zt({type:this.contextType,data:{name:n.name,dataType:n.dataType},details:n.value==null?void 0:JSON.stringify(n.value)})}};function Yo(e){let t=e.get(ne),n=e.get(C),r=e.get(ee);return new Tt().register(new qo(n)).register(new Jo(r,n)).register(new Uo(e)).register(new ho(e)).register(new jt(t.connectionsMap,n))}function Xo(){return new Ko(ot())}function Zo({input:e}){let t=``;return e.includes(`@`)&&(t=as(e),A.debug(`Included context`,t)),{includeOtherCode:E(``),context:{plainText:t,schema:[],variables:[]}}}var Qo=`data-marimo-context`,$o={marimo:{source:`context`}};function es(e){return e.type===`file`&&e.providerMetadata?.marimo?.source===$o.marimo.source}function ts(e){return{...e,providerMetadata:{...e.providerMetadata,marimo:{...e.providerMetadata?.marimo,...$o.marimo}}}}async function ns(e){if(!e.includes(`@`))return{plainText:``,contextIds:[],attachments:[]};let t=Yo(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(ts)}catch(e){A.error(`Error getting attachments:`,e)}return{plainText:r,contextIds:n,attachments:i}}async function rs(e){let{plainText:t,contextIds:n,attachments:r}=await ns(e),i=null;return t.trim()&&(i={type:Qo,data:{plainText:t,contextIds:n.map(String)}}),{contextPart:i,attachments:r}}async function is({input:e}){let{plainText:t,attachments:n}=await ns(e);return{body:{includeOtherCode:E(``),context:{plainText:t,schema:[],variables:[]}},attachments:n}}function as(e){let t=Yo(s),n=t.parseAllContextIds(e);return t.formatContextForAI(n)}function os(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 ss(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(),tt(e.current.view)}}var cs=new Set([`openai`,`google`,`anthropic`]),ls=[`image/*`,`text/*`],us=52428800;function ds(e){return e.length>50?`${e.slice(0,50)}...`:e}async function fs(e){return await Promise.all(e.map(async e=>({type:`file`,mediaType:e.type,filename:e.name,url:await Lt(e,`dataUrl`)})))}function ps(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 ms(e){return e.map(e=>e.type===`text`?e.text:``).join(`
62
+ `)}async function hs(e){let t=await is({input:ms(e.flatMap(e=>e.parts))});function n(e,n){return n?{...e,parts:[...e.parts,...t.attachments]}:e}return{...t.body,uiMessages:e.map((t,r)=>n(t,r===e.length-1))}}async function gs({invokeAiTool:e,addToolOutput:t,toolCall:n,toolContext:r}){try{if(ko.has(n.toolName)){let e=await ko.invoke({toolName:n.toolName,rawArgs:n.input,toolContext:r});t({tool:n.toolName,toolCallId:n.toolCallId,output:e.result||e.error})}else{let r=await e({toolName:n.toolName,arguments:n.input??{}});t({tool:n.toolName,toolCallId:n.toolCallId,output:r.result||r.error})}}catch(e){A.error(`Tool call failed:`,e),t({tool:n.toolName,toolCallId:n.toolCallId,output:`Error: ${e instanceof Error?e.message:String(e)}`})}}function _s(e){let t=e.at(-1);if(!t||t.role!==`assistant`)return!1;let n=t.parts.at(-1);return!n||!H(n)?!1:va({messages:e})||_a({messages:e})||n.state===`output-denied`&&!n.providerExecuted}function vs(e){let t=e.at(-1);return!t||t.role!==`assistant`?!1:t.parts.some(e=>H(e)&&ys(e.state))}function ys(e){switch(e){case`approval-requested`:case`input-streaming`:case`input-available`:return!0;case`approval-responded`:case`output-available`:case`output-error`:case`output-denied`:return!1;default:return e}}function bs(){let e=(0,M.c)(7),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0];let[n,r]=(0,W.useState)(t),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=e=>{if(e.length!==0){if(e.reduce(xs,0)>us){_t({title:`File size exceeded`,description:`Attachments must be under 50 MB`,variant:`danger`});return}r(t=>[...t,...e])}},e[1]=i):i=e[1];let a=c(i),o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>r([]),e[2]=o):o=e[2];let s=o,l;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=e=>r(t=>t.filter(t=>t!==e)),e[3]=l):l=e[3];let u=l,d;return e[4]!==a||e[5]!==n?(d={files:n,addFiles:a,clearFiles:s,removeFile:u},e[4]=a,e[5]=n,e[6]=d):d=e[6],d}function xs(e,t){return e+t.size}function Ss(e){return e.isError?!1:e.isAbort?!0:!e.hasPendingToolCalls&&!e.hasUnresolvedToolCalls}function Cs(){let[e,t]=(0,W.useState)([]),n=(0,W.useRef)([]),r=(0,W.useRef)(!1);return n.current=e,r.current=e.length>0,{messages:e,enqueue:c(e=>{t(t=>{let i=[...t,{id:gt(),parts:e}];return n.current=i,r.current=!0,i})}),flushNext:c(e=>{let i=n.current;if(i.length===0)return;let[a,...o]=i;n.current=o,r.current=o.length>0,t(o),e(a.parts)}),clear:c(()=>{n.current=[],r.current=!1,t([])}),hasQueuedRef:r}}var ws=e=>{let t=(0,M.c)(6),{attachment:n}=e;if(n.mediaType?.startsWith(`image/`)){let e=n.filename||`Attachment`,r;return t[0]!==n.url||t[1]!==e?(r=(0,G.jsx)(`img`,{src:n.url,alt:e,className:`max-h-[100px] max-w-[100px] object-contain mb-1.5`}),t[0]=n.url,t[1]=e,t[2]=r):r=t[2],r}let r;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,G.jsx)(St,{className:`h-3 w-3 mt-0.5`}),t[3]=r):r=t[3];let i=n.filename||`Attachment`,a;return t[4]===i?a=t[5]:(a=(0,G.jsxs)(`div`,{className:`flex flex-row gap-1 items-center text-xs`,children:[r,i]}),t[4]=i,t[5]=a),a},Ts=e=>{let t=(0,M.c)(12),{file:n,className:r,onRemove:i}=e,[a,o]=(0,W.useState)(!1),s;t[0]===r?s=t[1]:(s=Pe(`py-1 px-1.5 bg-muted rounded-md cursor-pointer flex flex-row gap-1 items-center text-xs`,r),t[0]=r,t[1]=s);let c,l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>o(!0),l=()=>o(!1),t[2]=c,t[3]=l):(c=t[2],l=t[3]);let u;t[4]!==n||t[5]!==a||t[6]!==i?(u=a?(0,G.jsx)(ut,{className:`h-3 w-3 mt-0.5`,onClick:i}):ks(n),t[4]=n,t[5]=a,t[6]=i,t[7]=u):u=t[7];let d;return t[8]!==n.name||t[9]!==s||t[10]!==u?(d=(0,G.jsxs)(`div`,{className:s,onMouseEnter:c,onMouseLeave:l,children:[u,n.name]}),t[8]=n.name,t[9]=s,t[10]=u,t[11]=d):d=t[11],d},Es=e=>{let t=(0,M.c)(12),{isLoading:n,onStop:r,onSendClick:i,isEmpty:a,showStopLabel:o}=e,s=o!==void 0&&o,c;t[0]===s?c=t[1]:(c=s?(0,G.jsxs)(`div`,{className:`flex flex-row items-center gap-1 px-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-error`,children:`Stop`}),(0,G.jsx)(Mt,{size:`small`})]}):(0,G.jsx)(Wt,{className:`size-4 text-error`}),t[0]=s,t[1]=c);let l=c,u=n?`Stop`:`Submit`,d=n?r:i,f=!n&&a,p;t[2]!==n||t[3]!==l?(p=n?l:(0,G.jsx)(Kt,{className:`h-3.5 w-3.5`}),t[2]=n,t[3]=l,t[4]=p):p=t[4];let m;t[5]!==d||t[6]!==f||t[7]!==p?(m=(0,G.jsx)(j,{variant:`text`,size:`sm`,className:`h-6 min-w-6 p-0 hover:bg-muted/30 cursor-pointer`,onClick:d,disabled:f,children:p}),t[5]=d,t[6]=f,t[7]=p,t[8]=m):m=t[8];let h;return t[9]!==u||t[10]!==m?(h=(0,G.jsx)(Ve,{content:u,children:m}),t[9]=u,t[10]=m,t[11]=h):h=t[11],h},Ds=e=>{let t=(0,M.c)(4),{handleAddContext:n,isLoading:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,G.jsx)(Ht,{className:`h-3.5 w-3.5`}),t[0]=i):i=t[0];let a;return t[1]!==n||t[2]!==r?(a=(0,G.jsx)(Ve,{content:`Add context`,children:(0,G.jsx)(j,{variant:`text`,size:`icon`,onClick:n,disabled:r,children:i})}),t[1]=n,t[2]=r,t[3]=a):a=t[3],a},Os=e=>{let t=(0,M.c)(15),{fileInputRef:n,isLoading:r,onAddFiles:i}=e,a;t[0]===n?a=t[1]:(a=()=>n.current?.click(),t[0]=n,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,G.jsx)(Gt,{className:`h-3.5 w-3.5`}),t[2]=o):o=t[2];let s;t[3]!==r||t[4]!==a?(s=(0,G.jsx)(Ve,{content:`Attach a file`,children:(0,G.jsx)(j,{variant:`text`,size:`icon`,onClick:a,disabled:r,children:o})}),t[3]=r,t[4]=a,t[5]=s):s=t[5];let c;t[6]===i?c=t[7]:(c=e=>{e.target.files&&i([...e.target.files])},t[6]=i,t[7]=c);let l;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(l=ls.join(`,`),t[8]=l):l=t[8];let u;t[9]!==n||t[10]!==c?(u=(0,G.jsx)(mt,{ref:n,type:`file`,multiple:!0,hidden:!0,onChange:c,accept:l}),t[9]=n,t[10]=c,t[11]=u):u=t[11];let d;return t[12]!==s||t[13]!==u?(d=(0,G.jsxs)(G.Fragment,{children:[s,u]}),t[12]=s,t[13]=u,t[14]=d):d=t[14],d};function ks(e){let t=`h-3 w-3 mt-0.5`;return e.type.startsWith(`image/`)?(0,G.jsx)(Vt,{className:t}):e.type.startsWith(`text/`)?(0,G.jsx)(lt,{className:t}):(0,G.jsx)(St,{className:t})}var As=e=>{let t=(0,M.c)(15),{icon:n,title:r,subtitle:i,href:a}=e,o;t[0]===r?o=t[1]:(o=(0,G.jsx)(`span`,{className:`truncate font-medium`,children:r}),t[0]=r,t[1]=o);let s;t[2]===i?s=t[3]:(s=i&&(0,G.jsxs)(`span`,{className:`truncate opacity-70`,children:[`(`,i,`)`]}),t[2]=i,t[3]=s);let c;t[4]!==n||t[5]!==o||t[6]!==s?(c=(0,G.jsxs)(G.Fragment,{children:[n,o,s]}),t[4]=n,t[5]=o,t[6]=s,t[7]=c):c=t[7];let l=c;if(a&&vt(a)){let e=i??r,n;return t[8]!==l||t[9]!==a||t[10]!==e?(n=(0,G.jsx)(`a`,{href:a,target:`_blank`,rel:`noopener noreferrer`,title:e,className:`inline-flex max-w-full items-center gap-1.5 rounded-md border bg-muted/50 px-2 py-1 my-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground transition-colors`,children:l}),t[8]=l,t[9]=a,t[10]=e,t[11]=n):n=t[11],n}let u=i??r,d;return t[12]!==l||t[13]!==u?(d=(0,G.jsx)(`div`,{className:`inline-flex max-w-full items-center gap-1.5 rounded-md border bg-muted/50 px-2 py-1 my-1 text-xs text-muted-foreground`,title:u,children:l}),t[12]=l,t[13]=u,t[14]=d):d=t[14],d},js=Ke.define(),Q=Ue.define({create(){return new Map},update(e,t){let n=!1,r=e;for(let i of t.effects)if(i.is(js)){n||=(r=new Map(e),!0);for(let[e,t]of i.value)r.set(e,t)}return r}}),Ms=Ue.define({create(){return{onResourceClick:void 0,onResourceMouseOver:void 0,onResourceMouseOut:void 0,onPromptSubmit:void 0}},update(e){return e}}),Ns=Ke.define();Ue.define({create(){return new Map},update(e,t){let n=!1,r=e;for(let i of t.effects)if(i.is(Ns)){n||=(r=new Map(e),!0);for(let[e,t]of i.value)r.set(e,t)}return r}});var Ps=(e,t)=>async n=>{let r=n.matchBefore(/@(\w+)?/);if(!r||r.from===r.to&&!n.explicit)return null;let i=await e();if(i.length===0)return null;let a=js.of(new Map(i.map(e=>[e.uri,e])));n.view&&n.view.dispatch({effects:a});let o=i.map(e=>({label:`@${e.name}`,displayLabel:e.name,detail:e.uri,info:e.description||void 0,type:e.mimeType?`constant`:`variable`,boost:e.description?100:0,...t?.(e),apply:(t,n,r,i)=>{t.dispatch({changes:{from:r,to:i,insert:`@${e.uri} `}})}}));return{from:r.from,options:o}},Fs=/@[\w-]+:\/\/(?!\/)[^\s]+/;function $(e){return e.matchAll(new RegExp(Fs.source,`g`))}var Is=class extends Je{resource;view;constructor(e,t){super(),this.resource=e,this.view=t}eq(e){return e.resource.uri===this.resource.uri}toDOM(){let e=document.createElement(`span`);e.className=`cm-resource-widget`,e.textContent=`@${this.resource.name}`;let t=this.view.state.field(Ms,!1),n=t?.onResourceClick,r=t?.onResourceMouseOver,i=t?.onResourceMouseOut;return n&&(e.style.cursor=`pointer`,e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),n(this.resource)})),r&&e.addEventListener(`mouseover`,e=>{e.preventDefault(),e.stopPropagation(),r(this.resource)}),i&&e.addEventListener(`mouseout`,e=>{e.preventDefault(),e.stopPropagation(),i(this.resource)}),e}},Ls=class extends Je{uri;view;constructor(e,t){super(),this.uri=e,this.view=t}eq(e){return e.uri===this.uri}toDOM(){let e=document.createElement(`span`);return e.className=`cm-not-found-resource-widget`,e.textContent=`@${this.uri.split(`://`)[1]??this.uri}`,e}};function Rs(e){let t=e.state.field(Q),n=[];for(let{from:r,to:i}of e.visibleRanges){let a=e.state.doc.sliceString(r,i);for(let i of $(a)){let a=r+i.index,o=i[0].slice(1),s=t.get(o);s?n.push(qe.replace({widget:new Is(s,e)}).range(a,a+i[0].length)):n.push(qe.replace({widget:new Ls(o,e)}).range(a,a+i[0].length))}}return qe.set(n)}var zs=Qe.fromClass(class{decorations;constructor(e){this.decorations=Rs(e)}update(e){(e.docChanged||e.viewportChanged||e.transactions.some(e=>e.effects.some(e=>e.is(js))))&&(this.decorations=Rs(e.view))}},{decorations:e=>e.decorations});function Bs(e){let t=document.createElement(`div`);t.className=`cm-tooltip-cursor`;let n=document.createElement(`div`);if(n.className=`cm-tooltip-cursor-title`,n.textContent=`${e.name} (${e.uri})`,t.appendChild(n),e.description){let n=document.createElement(`div`);n.className=`cm-tooltip-cursor-description`,n.textContent=e.description,t.appendChild(n)}if(e.mimeType){let n=document.createElement(`div`);n.className=`cm-tooltip-cursor-mimetype`,n.textContent=e.mimeType,t.appendChild(n)}return{dom:t}}function Vs(e,t,n,r=0){for(let i of $(e)){let e=r+i.index,a=e+i[0].length;if(t>=e&&t<=a){let t=i[0].slice(1),r=n.get(t);if(r)return{resource:r,start:e,end:a}}}return null}function Hs(e){return $e((t,n)=>{let{from:r,text:i}=t.state.doc.lineAt(n),a=Vs(i,n,t.state.field(Q),r);return a?{pos:a.start,end:a.end,above:!0,create(){return(e.createTooltip??Bs)(a.resource)}}:null})}function Us(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t),a=r.sliceString(i.from,i.to),o=Array.from($(a));if(o.length===0)return null;for(let e of o){let r=i.from+e.index,a=r+e[0].length,o=e[0].slice(1);if(t===a&&n.has(o))return{from:r,to:a,uri:o}}return null}function Ws(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t).to,a=r.sliceString(t,i),o=Array.from($(a));if(o.length===0)return null;let s=o[0];if(!s||s.index!==0)return null;let c=t,l=t+s[0].length,u=s[0].slice(1);return n.has(u)?{from:c,to:l,uri:u}:null}function Gs(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t),a=r.sliceString(i.from,i.to),o=Array.from($(a));for(let e of o){let r=i.from+e.index,a=r+e[0].length,o=e[0].slice(1);if(t>r&&t<a&&n.has(o))return{from:r,to:a,uri:o}}return null}function Ks(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t),a=r.sliceString(i.from,t),o=Array.from($(a)),s=null;for(let e of o){let r=i.from+e.index,a=r+e[0].length,o=e[0].slice(1);n.has(o)&&a<=t&&(t>a?s=a:t===a&&(s=r))}return s}function qs(e,t){let n=e.field(Q),r=e.doc,i=r.lineAt(t),a=r.sliceString(i.from,i.to),o=Array.from($(a));for(let e of o){let r=i.from+e.index,a=r+e[0].length,o=e[0].slice(1);if(n.has(o)&&r>=t){if(t<r)return r;if(t===r)return a}}return null}var Js=Ge.transactionFilter.of(e=>{let t=e.annotation(Ye.userEvent);if(!t)return e;let n=e.startState.selection.main;if(!n.empty)return e;if(t===`input.type`||t.startsWith(`input`)){if(e.changes.empty)return e;let t=e.startState.field(Q),n=e.startState.doc,r=!1,i=0,a=[];if(e.changes.iterChanges((e,o,s,c,l)=>{let u=l.toString(),d=e;if(/^\s+$/.test(u)){a.push({from:e,to:o,insert:u});return}let f=n.lineAt(d),p=n.sliceString(f.from,f.to),m=Array.from($(p)),h=!1,g=!1;for(let e of m){let r=f.from+e.index,i=r+e[0].length,a=e[0].slice(1);if(t.has(a)){if(d===r){let e=d>0?n.sliceString(d-1,d):``;e!==``&&e!==` `&&e!==`
63
63
  `&&e!==` `&&(h=!0)}if(d===i){let e=d<n.length?n.sliceString(d,d+1):``;(e===``||e!==` `&&e!==`
64
64
  `&&e!==` `)&&(g=!0)}}}let _=u;h&&(_=` ${_}`,i+=1),g&&(_=` ${_}`,i+=1),_!==u&&(r=!0),a.push({from:e,to:o,insert:_})}),r)return[{changes:a,selection:e.selection?{anchor:e.selection.main.anchor+i,head:e.selection.main.head+i}:void 0,scrollIntoView:e.scrollIntoView}]}if(t===`delete.backward`||t===`delete.forward`){let r=null;return t===`delete.backward`?r=Us(e.startState,n.head):t===`delete.forward`&&(r=Ws(e.startState,n.head)),r?[{changes:{from:r.from,to:r.to,insert:``},selection:{anchor:r.from},scrollIntoView:!0}]:e}if(e.selection?.main.empty&&n.empty&&!t.startsWith(`input`)&&t!==`input.type`){let t=n.head,r=e.selection.main.head,i=null;if(r<t){let n=Gs(e.startState,t);i=n&&t>n.from?n.from:Ks(e.startState,t)}else if(r>t){let n=Gs(e.startState,t);i=n&&t<n.to?n.to:qs(e.startState,t)}if(i!==null&&i!==r)return[{selection:{anchor:i},scrollIntoView:!0}]}return e}),Ys=150;function Xs(e,t){let n=new Set;for(let r of $(e)){let e=r[0].slice(1);t.has(e)||n.add(e)}return[...n]}function Zs(e){return[...e].sort().join(`
65
65
  `)}function Qs(e){return!$(e).next().done}function $s(e){let t=[],n=[];return e.changes.iterChanges((r,i,a,o)=>{let s=e.startState.doc.lineAt(r),c=e.startState.doc.lineAt(i===r?r:i-1);t.push(e.startState.doc.sliceString(s.from,c.to));let l=e.state.doc.lineAt(a),u=e.state.doc.lineAt(o===a?a:o-1);n.push(e.state.doc.sliceString(l.from,u.to))}),{before:t.join(`
@@ -76,5 +76,5 @@ ${t}`,d++;break;case`id`:l=t.includes(`\0`)?void 0:t;break;case`retry`:/^\d+$/.t
76
76
  border-(--green-6) border hover:shadow-xs rounded px-3 ${o}`,y;t[24]===s?y=t[25]:(y=s&&(0,G.jsx)(wt,{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)(j,{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},pc=e=>{let t=(0,M.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)
77
77
  dark:bg-(--red-4)/80 dark:hover:bg-(--red-3) rounded px-3 font-semibold
78
78
  active:bg-(--red-5) dark:active:bg-(--red-4)
79
- 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)(wt,{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)(j,{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},mc=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}}},hc=S(`marimo:ai-language`,`python`,b),gc=`marimo:ai-prompt-history`,_c=new T(Ee(O()),()=>[]),vc=({onClose:e})=>{let t=i(),[n,a]=(0,W.useState)(``),{acceptOwnedStagedCells:s,beginStagedCellGeneration:l,discardOwnedStagedCells:u,finishStagedCellGeneration:d,hasOwnedStagedCells:f,onData:p}=co(t),[m,h]=r(hc),g=Ne(),v=(0,W.useRef)(null),y=(0,W.useRef)(new mc).current,b=(0,W.useRef)(null),{files:x,addFiles:S,removeFile:C}=bs(),ee=o(ke),te=(0,W.useMemo)(()=>new ha({api:g.getAiURL(`completion`).toString(),headers:()=>g.headers(),prepareSendMessagesRequest:async e=>{let t={...await hs(e.messages),code:``,prompt:``,language:m};return{api:g.getAiURL(`completion`).toString(),body:t}}}),[m,g]),ne=c(e=>{d(!1),_t({title:`Generate with AI failed`,description:bt(e)})}),{sendMessage:re,stop:w,status:ie}=Ia({throttle:100,transport:te,onData:p,onError:ne,onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{d(!e&&!t&&!n&&r===`stop`)}}),T=ie===`streaming`||ie===`submitted`,E=f(),D=c(()=>{y.cancel(),d(!1),w()}),ae=c(()=>{y.cancel(),u(),w()});(0,W.useEffect)(()=>()=>{D()},[D]);let oe=ee?.models?.edit_model||`openai/gpt-4o`,se=Ae.parse(oe).providerId,ce=cs.has(se),le=async()=>{T||await y.run({prepare:async()=>(v.current?.view&&Ga(v.current.view),x?await fs(x):void 0),submit:async e=>{l(),await re({text:n,files:e})},onError:ne})},ue=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Nt,{className:`size-4 mr-2`}),`Python`]}),de=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ct,{className:`size-4 mr-2`}),`SQL`]}),fe=(0,G.jsxs)(Be,{modal:!1,children:[(0,G.jsxs)(Re,{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`?ue:de,(0,G.jsx)(Dt,{className:`ml-1 h-3.5 w-3.5 text-muted-foreground/70`})]}),(0,G.jsxs)(ze,{align:`center`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1 text-sm text-muted-foreground`,children:`Select language`}),(0,G.jsx)(Le,{}),(0,G.jsx)(Ie,{onClick:()=>h(`python`),children:ue}),(0,G.jsx)(Ie,{onClick:()=>h(`sql`),children:de})]})]}),pe=()=>{s()&&e()},me=()=>{ae(),v.current?.view?.focus()},he=()=>{ae(),e()},ge=(0,G.jsxs)(`div`,{className:`flex items-center px-3`,children:[(0,G.jsx)(_,{className:`size-4 text-(--blue-11) mr-2`}),(0,G.jsx)(yc,{inputRef:v,onClose:he,value:n,onChange:e=>{a(e)},onSubmit:le,onKeyDown:uc({handleAcceptCompletion:pe,handleDeclineCompletion:me,isLoading:T,hasCompletion:E})}),(0,G.jsx)(j,{variant:`text`,size:`sm`,className:`mb-0 px-1`,onClick:he,children:(0,G.jsx)(ut,{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)(je,{triggerClassName:`h-7 text-xs max-w-64`,iconSize:`small`,forRole:`edit`,showAddCustomModelDocs:!0}),fe]}),(0,G.jsxs)(`div`,{className:`flex flex-row items-center`,children:[x.length>0&&(0,G.jsx)(`div`,{className:`flex flex-row gap-1 flex-wrap pr-1`,children:x?.map((e,t)=>(0,G.jsx)(Ts,{file:e,onRemove:()=>C(e)},`${e.name}-${t}`))}),(0,G.jsx)(Ds,{handleAddContext:()=>ss(v),isLoading:T}),ce&&(0,G.jsx)(Os,{fileInputRef:b,isLoading:T,onAddFiles:S}),(0,G.jsx)(Es,{isLoading:T,onStop:D,onSendClick:le,isEmpty:!n.trim(),showStopLabel:!0})]})]});return(0,G.jsxs)(`div`,{className:Pe(`flex flex-col w-full py-2`),children:[ge,_e]})},yc=e=>{let t=(0,M.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}=yt(),y;t[0]===p?y=t[1]:(y=e=>p?os([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=ht();t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=it({}),t[9]=x):x=t[9],S=e,C=sc({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=Ka({storage:{load:bc,save:xc}}),t[10]=te):te=t[10];let ne;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(ne=kt(),t[11]=ne):ne=t[11];let re;t[12]===h?re=t[13]:(re=Xe.highest(We.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:`
80
- `},selection:{anchor:n+1,head:n+1}}),t.preventDefault(),t.stopPropagation(),!0}return!1}}])),t[12]=h,t[13]=re);let w;t[14]===g?w=t[15]:(w=We.of([{key:`Escape`,preventDefault:!0,stopPropagation:!0,run:()=>(g(),!0)}]),t[14]=g,t[15]=w);let ie;t[16]!==x||t[17]!==S||t[18]!==C||t[19]!==ee||t[20]!==re||t[21]!==w?(ie=[x,S,C,ee,te,Ze.lineWrapping,ne,re,w],t[16]=x,t[17]=S,t[18]=C,t[19]=ee,t[20]=re,t[21]=w,t[22]=ie):ie=t[22];let T=ie,E;t[23]===o?E=t[24]:(E=Pe(`flex-1 font-sans overflow-auto my-1`,o),t[23]=o,t[24]=E);let D=v===`dark`?`dark`:`light`,ae=r||`Generate with AI, @ to include context`,oe;return t[25]!==T||t[26]!==a||t[27]!==m||t[28]!==s||t[29]!==u||t[30]!==E||t[31]!==D||t[32]!==ae||t[33]!==n?(oe=(0,G.jsx)(St,{ref:a,className:E,width:`100%`,maxHeight:m,value:n,basicSetup:!1,extensions:T,onChange:s,onKeyDown:u,theme:D,placeholder:ae}),t[25]=T,t[26]=a,t[27]=m,t[28]=s,t[29]=u,t[30]=E,t[31]=D,t[32]=ae,t[33]=n,t[34]=oe):oe=t[34],oe};function bc(){return _c.get(gc)}function xc(e){return _c.set(gc,e)}export{Po as A,Ga as B,Cs as C,rs as D,es as E,ro as F,da as G,ha as H,so as I,Kt as J,Zi as K,Xa as L,Z as M,no as N,Yo as O,oo as P,Qa as R,bs as S,Zo as T,aa as U,Ia as V,Yi as W,Wt as X,Gt as Y,Ut as Z,gs as _,dc as a,ps as b,Ds as c,Ts as d,Es as f,ds as g,fs as h,fc as i,ko as j,Lo as k,Os as l,cs as m,yc as n,pc as o,As as p,Yr as q,lc as r,uc as s,vc as t,ws as u,_s as v,ss as w,Ss as x,vs as y,to as z};
79
+ 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)(wt,{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)(j,{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},mc=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}}},hc=S(`marimo:ai-language`,`python`,b),gc=`marimo:ai-prompt-history`,_c=new T(Ee(O()),()=>[]),vc=({onClose:e})=>{let t=i(),[n,a]=(0,W.useState)(``),{acceptOwnedStagedCells:s,beginStagedCellGeneration:l,discardOwnedStagedCells:u,finishStagedCellGeneration:d,hasOwnedStagedCells:f,onData:p}=co(t),[m,h]=r(hc),g=Ne(),v=(0,W.useRef)(null),y=(0,W.useRef)(new mc).current,b=(0,W.useRef)(null),{files:x,addFiles:S,removeFile:C}=bs(),ee=o(ke),te=(0,W.useMemo)(()=>new ha({api:g.getAiURL(`completion`).toString(),headers:()=>g.headers(),prepareSendMessagesRequest:async e=>{let t={...await hs(e.messages),code:``,prompt:``,language:m};return{api:g.getAiURL(`completion`).toString(),body:t}}}),[m,g]),ne=c(e=>{d(!1),_t({title:`Generate with AI failed`,description:bt(e)})}),{sendMessage:re,stop:w,status:ie}=Ia({throttle:100,transport:te,onData:p,onError:ne,onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{d(!e&&!t&&!n&&r===`stop`)}}),T=ie===`streaming`||ie===`submitted`,E=f(),D=c(()=>{y.cancel(),d(!1),w()}),ae=c(()=>{y.cancel(),u(),w()});(0,W.useEffect)(()=>()=>{D()},[D]);let oe=ee?.models?.edit_model||`openai/gpt-4o`,se=Ae.parse(oe).providerId,ce=cs.has(se),le=async()=>{T||await y.run({prepare:async()=>(v.current?.view&&Ga(v.current.view),x?await fs(x):void 0),submit:async e=>{l(),await re({text:n,files:e})},onError:ne})},ue=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ft,{className:`size-4 mr-2`}),`Python`]}),de=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ct,{className:`size-4 mr-2`}),`SQL`]}),fe=(0,G.jsxs)(Be,{modal:!1,children:[(0,G.jsxs)(Re,{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`?ue:de,(0,G.jsx)(Dt,{className:`ml-1 h-3.5 w-3.5 text-muted-foreground/70`})]}),(0,G.jsxs)(ze,{align:`center`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1 text-sm text-muted-foreground`,children:`Select language`}),(0,G.jsx)(Le,{}),(0,G.jsx)(Ie,{onClick:()=>h(`python`),children:ue}),(0,G.jsx)(Ie,{onClick:()=>h(`sql`),children:de})]})]}),pe=()=>{s()&&e()},me=()=>{ae(),v.current?.view?.focus()},he=()=>{ae(),e()},ge=(0,G.jsxs)(`div`,{className:`flex items-center px-3`,children:[(0,G.jsx)(_,{className:`size-4 text-(--blue-11) mr-2`}),(0,G.jsx)(yc,{inputRef:v,onClose:he,value:n,onChange:e=>{a(e)},onSubmit:le,onKeyDown:uc({handleAcceptCompletion:pe,handleDeclineCompletion:me,isLoading:T,hasCompletion:E})}),(0,G.jsx)(j,{variant:`text`,size:`sm`,className:`mb-0 px-1`,onClick:he,children:(0,G.jsx)(ut,{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)(je,{triggerClassName:`h-7 text-xs max-w-64`,iconSize:`small`,forRole:`edit`,showAddCustomModelDocs:!0}),fe]}),(0,G.jsxs)(`div`,{className:`flex flex-row items-center`,children:[x.length>0&&(0,G.jsx)(`div`,{className:`flex flex-row gap-1 flex-wrap pr-1`,children:x?.map((e,t)=>(0,G.jsx)(Ts,{file:e,onRemove:()=>C(e)},`${e.name}-${t}`))}),(0,G.jsx)(Ds,{handleAddContext:()=>ss(v),isLoading:T}),ce&&(0,G.jsx)(Os,{fileInputRef:b,isLoading:T,onAddFiles:S}),(0,G.jsx)(Es,{isLoading:T,onStop:D,onSendClick:le,isEmpty:!n.trim(),showStopLabel:!0})]})]});return(0,G.jsxs)(`div`,{className:Pe(`flex flex-col w-full py-2`),children:[ge,_e]})},yc=e=>{let t=(0,M.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}=yt(),y;t[0]===p?y=t[1]:(y=e=>p?os([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=ht();t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=it({}),t[9]=x):x=t[9],S=e,C=sc({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=Ka({storage:{load:bc,save:xc}}),t[10]=te):te=t[10];let ne;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(ne=kt(),t[11]=ne):ne=t[11];let re;t[12]===h?re=t[13]:(re=Xe.highest(We.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:`
80
+ `},selection:{anchor:n+1,head:n+1}}),t.preventDefault(),t.stopPropagation(),!0}return!1}}])),t[12]=h,t[13]=re);let w;t[14]===g?w=t[15]:(w=We.of([{key:`Escape`,preventDefault:!0,stopPropagation:!0,run:()=>(g(),!0)}]),t[14]=g,t[15]=w);let ie;t[16]!==x||t[17]!==S||t[18]!==C||t[19]!==ee||t[20]!==re||t[21]!==w?(ie=[x,S,C,ee,te,Ze.lineWrapping,ne,re,w],t[16]=x,t[17]=S,t[18]=C,t[19]=ee,t[20]=re,t[21]=w,t[22]=ie):ie=t[22];let T=ie,E;t[23]===o?E=t[24]:(E=Pe(`flex-1 font-sans overflow-auto my-1`,o),t[23]=o,t[24]=E);let D=v===`dark`?`dark`:`light`,ae=r||`Generate with AI, @ to include context`,oe;return t[25]!==T||t[26]!==a||t[27]!==m||t[28]!==s||t[29]!==u||t[30]!==E||t[31]!==D||t[32]!==ae||t[33]!==n?(oe=(0,G.jsx)(xt,{ref:a,className:E,width:`100%`,maxHeight:m,value:n,basicSetup:!1,extensions:T,onChange:s,onKeyDown:u,theme:D,placeholder:ae}),t[25]=T,t[26]=a,t[27]=m,t[28]=s,t[29]=u,t[30]=E,t[31]=D,t[32]=ae,t[33]=n,t[34]=oe):oe=t[34],oe};function bc(){return _c.get(gc)}function xc(e){return _c.set(gc,e)}export{Po as A,Ga as B,Cs as C,rs as D,es as E,ro as F,da as G,ha as H,so as I,Kt as J,Zi as K,Xa as L,Z as M,no as N,Yo as O,oo as P,Qa as R,bs as S,Zo as T,aa as U,Ia as V,Yi as W,Wt as X,Gt as Y,Ut as Z,gs as _,dc as a,ps as b,Ds as c,Ts as d,Es as f,ds as g,fs as h,fc as i,ko as j,Lo as k,Os as l,cs as m,yc as n,pc as o,As as p,Yr as q,lc as r,uc as s,vc as t,ws as u,_s as v,ss as w,Ss as x,vs as y,to as z};