@marimo-team/frontend 0.25.1-dev17 → 0.25.1-dev18

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 (100) hide show
  1. package/dist/assets/{ConnectedDataExplorerComponent-6WFKCUzO.js → ConnectedDataExplorerComponent-C2uC5lJf.js} +1 -1
  2. package/dist/assets/{ErrorBoundary-AmSQgV_f.js → ErrorBoundary-BVJqkhwk.js} +2 -2
  3. package/dist/assets/{LazyAnyLanguageCodeMirror-D38yVMV5.js → LazyAnyLanguageCodeMirror-BqNgl9tZ.js} +2 -2
  4. package/dist/assets/{RunButton-CmaVvEXE.js → RunButton-adYpTAaW.js} +7 -7
  5. package/dist/assets/{abnfDiagram-VCTEODGH-DbN3lc-G.js → abnfDiagram-VCTEODGH-Daqziwy1.js} +1 -1
  6. package/dist/assets/{add-cell-with-ai-DYEESV1_.js → add-cell-with-ai-CjPxSVh0.js} +10 -10
  7. package/dist/assets/{agent-panel-BBXyOr4f.js → agent-panel-mRH4isVn.js} +4 -4
  8. package/dist/assets/{ai-model-dropdown-DWp8ZCIu.js → ai-model-dropdown-BZNUB6Iv.js} +1 -1
  9. package/dist/assets/{any-language-editor-DxOWP_Dz.js → any-language-editor-DRf07PJG.js} +1 -1
  10. package/dist/assets/{app-config-button-DXferVy2.js → app-config-button-Cc7EMA4I.js} +1 -1
  11. package/dist/assets/{architectureDiagram-5GKGNRK7-CxYo7ny1.js → architectureDiagram-5GKGNRK7-YBlh_63B.js} +1 -1
  12. package/dist/assets/{blockDiagram-I7D4REHJ-XXtnxNOM.js → blockDiagram-I7D4REHJ-Ci6Gslkc.js} +1 -1
  13. package/dist/assets/{cache-panel-CDGgj_k1.js → cache-panel-BBQ7HY25.js} +1 -1
  14. package/dist/assets/{chat-display-B735hdwS.js → chat-display-ChsJwSGb.js} +1 -1
  15. package/dist/assets/{chat-panel-CRLY-8Q_.js → chat-panel-tXybKozg.js} +1 -1
  16. package/dist/assets/{chat-ui-COwKnPlV.js → chat-ui-Dj4a0ZyX.js} +1 -1
  17. package/dist/assets/{chunk-IMKFNOWR-DBsaOYkA.js → chunk-IMKFNOWR-CVUGMMR5.js} +1 -1
  18. package/dist/assets/{chunk-SHT3W25Y-NC5eClb6.js → chunk-SHT3W25Y-V-OZGYmC.js} +1 -1
  19. package/dist/assets/{chunk-SVP7TREG-zq4GRMSe.js → chunk-SVP7TREG-NYpzvObK.js} +1 -1
  20. package/dist/assets/{chunk-TICWLB2K-CtF--EWj.js → chunk-TICWLB2K-DAmEhpdA.js} +1 -1
  21. package/dist/assets/{classDiagram-ZZMXUADV-Ufnn74aN.js → classDiagram-ZZMXUADV-DmHJAfc5.js} +1 -1
  22. package/dist/assets/{classDiagram-v2-VYDZK3BY-Ufnn74aN.js → classDiagram-v2-VYDZK3BY-DmHJAfc5.js} +1 -1
  23. package/dist/assets/{code-visibility-DrRJBvIr.js → code-visibility-DEaFLO3A.js} +1 -1
  24. package/dist/assets/{command-palette-qcsu_Bp2.js → command-palette-CERIrl2Z.js} +1 -1
  25. package/dist/assets/{common-B-ub9i8J.js → common-DBH2dPfd.js} +1 -1
  26. package/dist/assets/{components-DaOSHEng.js → components-Chs3VCBR.js} +1 -1
  27. package/dist/assets/{components-BRVhsaex.js → components-CuWdJDJ8.js} +1 -1
  28. package/dist/assets/{cynefinDiagram-5FMLGOSQ-DEtkQ5VA.js → cynefinDiagram-5FMLGOSQ-DTjbXw-r.js} +1 -1
  29. package/dist/assets/{dagre-Br6SwCX-.js → dagre-4szy_3ND.js} +1 -1
  30. package/dist/assets/{dagre-GXQ25YYZ-CWfhwi40.js → dagre-GXQ25YYZ-BLLPL51D.js} +1 -1
  31. package/dist/assets/{data-grid-overlay-editor-BQ4XUYyf.js → data-grid-overlay-editor-CD6nx7Jc.js} +1 -1
  32. package/dist/assets/{dependency-graph-panel-DC7VQLMv.js → dependency-graph-panel-Dsa9_1CE.js} +1 -1
  33. package/dist/assets/{diagram-S7CK7UJ4-DgJkPXj-.js → diagram-S7CK7UJ4-BEOWs3DZ.js} +1 -1
  34. package/dist/assets/{diagram-UQ7AKVKN-BgMVSftv.js → diagram-UQ7AKVKN-DhcB9YNh.js} +1 -1
  35. package/dist/assets/{diagram-VX7I27RA-DPObfkHw.js → diagram-VX7I27RA-BZS6D99M.js} +1 -1
  36. package/dist/assets/{diagram-Z3DM3KII-BYHzWlR5.js → diagram-Z3DM3KII-Df9yG0Dr.js} +1 -1
  37. package/dist/assets/{documentation-panel-BauooX2S.js → documentation-panel-cgPFYBCG.js} +1 -1
  38. package/dist/assets/{ebnfDiagram-PWID7BFC-CoxVieSX.js → ebnfDiagram-PWID7BFC-D44ZGUpd.js} +1 -1
  39. package/dist/assets/{edit-page-DPhd7_gi.js → edit-page-5BoxMdRg.js} +8 -8
  40. package/dist/assets/{erDiagram-RLTQ6QDP-CryK8kTO.js → erDiagram-RLTQ6QDP-wMbCu1k0.js} +1 -1
  41. package/dist/assets/{error-panel-Chbt4Stb.js → error-panel-BQkG8Owp.js} +1 -1
  42. package/dist/assets/{feedback-button-DSa5c3Pq.js → feedback-button-L9wRkYQK.js} +1 -1
  43. package/dist/assets/{file-explorer-panel-BRzhiu8T.js → file-explorer-panel-BqbyZB-C.js} +1 -1
  44. package/dist/assets/{file-name-input-im0iaWXy.js → file-name-input-BIU5kyHZ.js} +1 -1
  45. package/dist/assets/{flowDiagram-HODETNUW-W7clPIx_.js → flowDiagram-HODETNUW-DXu8WHYs.js} +1 -1
  46. package/dist/assets/{gallery-page-B_5zGznh.js → gallery-page-CfV7ZAmL.js} +1 -1
  47. package/dist/assets/{glide-data-editor-CTXzjUkg.js → glide-data-editor-0wu6GiLW.js} +4 -4
  48. package/dist/assets/{graphlib-5TBKpf9f.js → graphlib-CTJqVmKw.js} +1 -1
  49. package/dist/assets/has-CGywqNo7.js +1 -0
  50. package/dist/assets/{home-page-gnNxFA7J.js → home-page-BpvVdseG.js} +1 -1
  51. package/dist/assets/{index-BGA2MQ61.js → index-D0aUt523.js} +31 -31
  52. package/dist/assets/{infoDiagram-27XIBGKW-COO_rLcz.js → infoDiagram-27XIBGKW-Cdc1u3v9.js} +1 -1
  53. package/dist/assets/{ishikawaDiagram-5VMMS53U-KrNEKYYj.js → ishikawaDiagram-5VMMS53U-CBLHwkrk.js} +1 -1
  54. package/dist/assets/{kanban-definition-UXKFOSKX-mL1vOpaC.js → kanban-definition-UXKFOSKX-B9VLtQSr.js} +1 -1
  55. package/dist/assets/{logs-panel-BKMIsY8h.js → logs-panel-bEm9k3zD.js} +1 -1
  56. package/dist/assets/{mermaid-D9cuWIJ3.js → mermaid-3TiKkcPE.js} +4 -4
  57. package/dist/assets/{mindmap-definition-YA3MSWOX-0UfzA6jE.js → mindmap-definition-YA3MSWOX-wGOfhH41.js} +1 -1
  58. package/dist/assets/{number-overlay-editor-D7NjYfe7.js → number-overlay-editor-K9e5ZWrL.js} +1 -1
  59. package/dist/assets/{outline-panel-QSMLTTpe.js → outline-panel-CffssgnN.js} +1 -1
  60. package/dist/assets/{packages-panel-DpmTy1Zj.js → packages-panel-CKmdUILr.js} +1 -1
  61. package/dist/assets/{panels-Bso8csB-.js → panels-14vO4F3h.js} +6 -6
  62. package/dist/assets/{pegDiagram-XKGWAZYB-C_Mn8HQY.js → pegDiagram-XKGWAZYB-BCEdVP7M.js} +1 -1
  63. package/dist/assets/{pieDiagram-E7YTZNPT-BCjUjlVJ.js → pieDiagram-E7YTZNPT-C8l_dDam.js} +1 -1
  64. package/dist/assets/{process-output-CEKLHiTm.js → process-output-ZDYA_DfN.js} +1 -1
  65. package/dist/assets/{railroadDiagram-O6MQD6OU-B1XuNasU.js → railroadDiagram-O6MQD6OU-t5SV0Qh9.js} +1 -1
  66. package/dist/assets/{requirementDiagram-BXWQKSXE-XekNJuFR.js → requirementDiagram-BXWQKSXE-CQaLae__.js} +1 -1
  67. package/dist/assets/{reveal-component-BYO2ErQd.js → reveal-component-Ce4laJYz.js} +1 -1
  68. package/dist/assets/{run-page-B8V4EsPe.js → run-page-BFPh-t5N.js} +1 -1
  69. package/dist/assets/{scratchpad-panel-BVRfI5pY.js → scratchpad-panel--eaSPPbI.js} +1 -1
  70. package/dist/assets/{secrets-panel-C8RCq9AF.js → secrets-panel-D5VC4iGd.js} +1 -1
  71. package/dist/assets/{sequenceDiagram-WJ2MYXX4-kkt3zDHa.js → sequenceDiagram-WJ2MYXX4-BdUEvoNa.js} +1 -1
  72. package/dist/assets/session-panel-C4xjKL7P.js +1 -0
  73. package/dist/assets/{snippets-panel-C-ljIDQt.js → snippets-panel-D5IV2SYF.js} +1 -1
  74. package/dist/assets/{stateDiagram-D77RDMKH-Bph_mhCF.js → stateDiagram-D77RDMKH-BxQBCmyb.js} +1 -1
  75. package/dist/assets/{stateDiagram-v2-MP3YSRHH-DSDmMkGt.js → stateDiagram-v2-MP3YSRHH-ldBZz7Qk.js} +1 -1
  76. package/dist/assets/{swimlanes-42K2YHIH-DOgT6SSZ.js → swimlanes-42K2YHIH-DyeulHZ_.js} +1 -1
  77. package/dist/assets/{swimlanesDiagram-VR7AAH4N-B0jZFEqF.js → swimlanesDiagram-VR7AAH4N-DtS183IV.js} +1 -1
  78. package/dist/assets/{swiper-component-D2sgxyxf.js → swiper-component-IXbGG3F9.js} +1 -1
  79. package/dist/assets/{terminal-B6gr5FPU.js → terminal-B0l9hsf7.js} +1 -1
  80. package/dist/assets/{timeline-definition-24CTP7MA-D6roMSAh.js → timeline-definition-24CTP7MA-Do_68DsI.js} +1 -1
  81. package/dist/assets/tooltip-PLkI_UfK.js +61 -0
  82. package/dist/assets/{tracing-BI61lCpo.js → tracing-CKx0JpOw.js} +1 -1
  83. package/dist/assets/{tracing-panel-BMqSLs2l.js → tracing-panel-CSkFln9f.js} +2 -2
  84. package/dist/assets/{useCellActionButton-DOqFLFDe.js → useCellActionButton-YroFjW8i.js} +1 -1
  85. package/dist/assets/{vega-component-CWmtMc1h.js → vega-component-B_nXcaF8.js} +1 -1
  86. package/dist/assets/{vega-embed-container-BDH_VhfS.js → vega-embed-container-Bwqt153O.js} +1 -1
  87. package/dist/assets/{vennDiagram-4TSXK5OY-AYIHuyE9.js → vennDiagram-4TSXK5OY-DkrPIenW.js} +1 -1
  88. package/dist/assets/{wardleyDiagram-VM6X3IG4-CogDfA2Q.js → wardleyDiagram-VM6X3IG4-Bx7dpVo2.js} +1 -1
  89. package/dist/assets/{xychartDiagram-S5SC5T6Z-D6Lub9hS.js → xychartDiagram-S5SC5T6Z-BDpyRtk7.js} +1 -1
  90. package/dist/index.html +4 -4
  91. package/package.json +1 -1
  92. package/src/components/data-table/charts/__tests__/chart-panel.test.tsx +286 -0
  93. package/src/components/data-table/charts/charts.tsx +26 -13
  94. package/src/plugins/impl/vega/__tests__/utils.test.ts +16 -1
  95. package/src/plugins/impl/vega/__tests__/vega.test.ts +37 -0
  96. package/src/plugins/impl/vega/loader.ts +23 -1
  97. package/src/plugins/impl/vega/utils.ts +5 -4
  98. package/dist/assets/has-QplVKfjH.js +0 -1
  99. package/dist/assets/session-panel-Ctbe5R3e.js +0 -1
  100. package/dist/assets/tooltip-B1vGi-z4.js +0 -61
@@ -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-D9cuWIJ3.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-zq4GRMSe.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-3TiKkcPE.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-NYpzvObK.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{Bt as u,D as d,Fa as f,Fi as p,In as m,Pi as h,Qr as g,Ti as _,Va as v,Z as y,Zn as b,_a as x,b as S,bo as C,da as ee,f as te,ft as ne,ir as w,ja as T,ji as E,qa as re,ti as D,yo as ie}from"./cells-B3WiM6w3.js";import{A as ae,B as oe,C as se,D as ce,E as le,I as ue,L as de,N as fe,P as O,R as pe,S as me,T as he,W as ge,_ as _e,j as k,k as ve,v as ye,w as be,x as xe,y as Se}from"./schemas-BL-NsLlF.js";import{t as Ce}from"./compiler-runtime-BQ9S8nyo.js";import{t as we}from"./config-BxZgoFvi.js";import{j as Te,t as Ee}from"./ai-model-dropdown-DWp8ZCIu.js";import{f as De,g as A}from"./useEventListener-BdZUApHd.js";import{a as Oe}from"./session-DXKMv4Bs.js";import{A as ke,O as Ae,o as je}from"./config-DpGPGznL.js";import{t as Me}from"./cn-ldLVeaqm.js";import{t as Ne}from"./jsx-runtime-B74pBk57.js";import{a as Pe,c as Fe,p as Ie,r as Le,t as Re}from"./dropdown-menu-VuyoeQOD.js";import{t as ze}from"./tooltip-DR2Z2N4w.js";import{t as Be}from"./button-BoklZTGL.js";import{t as Ve}from"./createLucideIcon-rHn2EdoM.js";import{i as He,r as Ue}from"./paths-CzfpItSz.js";import{r as We}from"./useNumberFormatter-C4-_TnkF.js";import{a as Ge,n as Ke,t as qe}from"./process-output-CEKLHiTm.js";import{r as Je}from"./input-BDakodZ2.js";import{t as Ye}from"./use-toast-CC89xOwH.js";import{Gt as Xe,Qt as Ze,Tt as Qe,Wt as $e,Zt as et,at as tt,dt as nt,en as rt,qt as it,st as at,ut as ot,wt as st}from"./dist-BczecT6V.js";import{t as ct}from"./createReducer-BPvK7C_R.js";import{h as lt,n as ut,o as dt,r as ft}from"./dist-Ccyblc8N.js";import{t as pt}from"./requests-yTHMxhVa.js";import{n as mt}from"./dist-DBqBVprh.js";import{t as ht}from"./uuid-k9DpjH68.js";import{r as gt}from"./useTheme-DcnXlv0_.js";import{a as _t}from"./errors-D9vyuMar.js";import{C as vt,Ca as yt,Cr as bt,Ct as xt,Er as St,Gn as Ct,Na as wt,Ra as Tt,Sr as Et,T as Dt,Tr as Ot,br as kt,ei as At,gi as jt,ir as Mt,k as Nt,ki as Pt,o as Ft,qt as It,wr as Lt,xr as Rt,ya as zt}from"./index-BGA2MQ61.js";import{i as Bt,r as Vt,t as Ht}from"./error-entries-BpXezjVq.js";var Ut=Ve(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),Wt=Ve(`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=Ve(`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=Ve(`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`}]]),j=Ce(),qt=`vercel.ai.error`,Jt=Symbol.for(qt),Yt,Xt,M=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=M,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 M.hasMarker(e,$t)}},an=`AI_JSONParseError`,on=`vercel.ai.error.${an}`,sn=Symbol.for(on),cn,ln,un=class extends (ln=M,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{Bt as u,D as d,Fa as f,Fi as p,In as m,Pi as h,Qr as g,Ti as _,Va as v,Z as y,Zn as b,_a as x,b as S,bo as C,da as ee,f as te,ft as ne,ir as w,ja as T,ji as E,qa as re,ti as D,yo as ie}from"./cells-B3WiM6w3.js";import{A as ae,B as oe,C as se,D as ce,E as le,I as ue,L as de,N as fe,P as O,R as pe,S as me,T as he,W as ge,_ as _e,j as k,k as ve,v as ye,w as be,x as xe,y as Se}from"./schemas-BL-NsLlF.js";import{t as Ce}from"./compiler-runtime-BQ9S8nyo.js";import{t as we}from"./config-BxZgoFvi.js";import{j as Te,t as Ee}from"./ai-model-dropdown-BZNUB6Iv.js";import{f as De,g as A}from"./useEventListener-BdZUApHd.js";import{a as Oe}from"./session-DXKMv4Bs.js";import{A as ke,O as Ae,o as je}from"./config-DpGPGznL.js";import{t as Me}from"./cn-ldLVeaqm.js";import{t as Ne}from"./jsx-runtime-B74pBk57.js";import{a as Pe,c as Fe,p as Ie,r as Le,t as Re}from"./dropdown-menu-VuyoeQOD.js";import{t as ze}from"./tooltip-DR2Z2N4w.js";import{t as Be}from"./button-BoklZTGL.js";import{t as Ve}from"./createLucideIcon-rHn2EdoM.js";import{i as He,r as Ue}from"./paths-CzfpItSz.js";import{r as We}from"./useNumberFormatter-C4-_TnkF.js";import{a as Ge,n as Ke,t as qe}from"./process-output-ZDYA_DfN.js";import{r as Je}from"./input-BDakodZ2.js";import{t as Ye}from"./use-toast-CC89xOwH.js";import{Gt as Xe,Qt as Ze,Tt as Qe,Wt as $e,Zt as et,at as tt,dt as nt,en as rt,qt as it,st as at,ut as ot,wt as st}from"./dist-BczecT6V.js";import{t as ct}from"./createReducer-BPvK7C_R.js";import{h as lt,n as ut,o as dt,r as ft}from"./dist-Ccyblc8N.js";import{t as pt}from"./requests-yTHMxhVa.js";import{n as mt}from"./dist-DBqBVprh.js";import{t as ht}from"./uuid-k9DpjH68.js";import{r as gt}from"./useTheme-DcnXlv0_.js";import{a as _t}from"./errors-D9vyuMar.js";import{Ca as vt,Cr as yt,Ct as bt,Er as xt,Gn as St,Na as Ct,Ra as wt,S as Tt,Sr as Et,Tr as Dt,br as Ot,ei as kt,gi as At,ir as jt,k as Mt,ki as Nt,o as Pt,qt as Ft,w as It,wr as Lt,xr as Rt,ya as zt}from"./index-D0aUt523.js";import{i as Bt,r as Vt,t as Ht}from"./error-entries-BpXezjVq.js";var Ut=Ve(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),Wt=Ve(`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=Ve(`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=Ve(`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`}]]),j=Ce(),qt=`vercel.ai.error`,Jt=Symbol.for(qt),Yt,Xt,M=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=M,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 M.hasMarker(e,$t)}},an=`AI_JSONParseError`,on=`vercel.ai.error.${an}`,sn=Symbol.for(on),cn,ln,un=class extends (ln=M,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 M.hasMarker(e,on)}},dn=`AI_TypeValidationError`,fn=`vercel.ai.error.${dn}`,pn=Symbol.for(fn),mn,hn,N=class e extends (hn=M,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 M.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})}},gn=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}},_n=10,vn=13,yn=32;function bn(e){}function xn(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=bn,onError:n=bn,onRetry:r=bn,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 gn(`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.`},uo=k({edit:k({type:_e([`update_cell`,`add_cell`,`delete_cell`]),code:O().optional(),position:k({type:_e([`relative`,`column_end`,`notebook_end`]).optional(),cellId:O().optional(),columnIndex:ae().optional(),before:me().optional()})})}),fo=class{name=`edit_notebook_tool`;description=lo;schema=uo;outputSchema=Ka;mode=[`agent`];handler=async({edit:e},t)=>{let{addStagedCell:n,createNewCell:r,store:i}=t;switch(e.type){case`update_cell`:{let{position:t,code:r}=e,a=t.cellId;if(!a)throw new Y(`Cell ID is required for update_cell`,`CELL_ID_REQUIRED_FOR_UPDATE_CELL`,!0,`Provide a cell ID to update`);if(!r)throw new Y(`Code is required for update_cell`,`CODE_REQUIRED_FOR_UPDATE_CELL`,!0,`Provide the new code to update the cell`);let o=i.get(S);this.validateCellIdExists(a,o);let s=this.getCellEditorView(a,o);Mt(a);let c=i.get(Z).get(a);if(c?.type===`add_cell`){ne(s,r);break}let l=s.state.doc.toString(),u=c?.previousCode??l;if(r===u)break;n({cellId:a,edit:{type:`update_cell`,previousCode:u}}),ne(s,r);break}case`add_cell`:{let{position:t,code:a}=e,o=`__end__`,s=!1,c=ie.create(),l=i.get(S);switch(t.type){case`relative`:{let e=t.cellId;if(!e)throw new Y(`Cell ID is required for add_cell with relative position`,`TOOL_ERROR`,!0,`Provide a cell ID to add the cell before`);if(t.before===void 0)throw new Y(`Before is required for add_cell with relative position`,`TOOL_ERROR`,!0,`Provide a boolean value for before, true to add before cell ${e}, false to add after the cell`);this.validateCellIdExists(e,l),o=e,s=t.before;break}case`column_end`:if(!t.columnIndex)throw new Y(`Column index is required for add_cell with column_end position`,`TOOL_ERROR`,!0,`Provide a column index to add the cell at the end of`);o={type:`__end__`,columnId:this.getColumnId(t.columnIndex,l)}}r({cellId:o,before:s,code:a,newCellId:c}),n({cellId:c,edit:{type:`add_cell`}}),Mt(c);break}case`delete_cell`:{let{position:t}=e,r=t.cellId;if(!r)throw new Y(`Cell ID is required for delete_cell`,`CELL_ID_REQUIRED_FOR_DELETE_CELL`,!0,`Provide a cell ID to delete`);let a=i.get(S);this.validateCellIdExists(r,a),n({cellId:r,edit:{type:`delete_cell`,previousCode:this.getCellEditorView(r,a).state.doc.toString()}}),Mt(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 po(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 mo=class extends Ot{title=`Cell Outputs`;mentionPrefix=`@`;contextType=`cell-output`;store;constructor(e){super(),this.store=e}getItems(){let e=this.store.get(S),t=[];for(let n of e.cellIds.inOrderIds){let r=_o(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`?Et.HIGH:Et.MEDIUM,type:this.contextType,section:bt.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}`)),Lt({type:this.contextType,data:a,details:o})}async getAttachments(e){let t=e[0].data.cellId,n=e[0].data.cellName;return ho(e.map(e=>e.data.cellOutput),t,n)}};async function ho(e,t,n){let r=e.filter(e=>e.shouldDownloadImage&&e.outputType===`media`);if(r.length===0)return[];let i=r.flatMap(e=>{let r=document.getElementById(C.create(t));return r?{cellId:t,cellName:n,mimetype:e.output.mimetype,element:r}:(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 It(e.element)})))}catch(e){return A.error(`Error downloading cell output images:`,e),[]}}function go(e){if(Ct(e))return null;let t=e.mimetype,n=po(t,String(e.data))?`media`:`text`,r=qe(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 _o(e,t,n){let{includeConsoleOutput:r=!1}=n||{},i=t.cellRuntime[e],a=t.cellData[e],o=t.cellIds.inOrderIds.indexOf(e),s=m(a.name,o),c;r&&(c=i.consoleOutputs.map(e=>go(e)).filter(e=>e!==null));let l,u=i.output;return u&&!Ct(u)&&(l=go(u)??void 0),{cellId:e,cellName:s,cellCode:a.code,cellOutput:l,consoleOutputs:c}}var vo=200,yo=3e4,bo=2e3,xo=3e3,So=4e4,Co={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.`},wo=k({type:le(`file`),url:O(),mediaType:O()}),To=class{name=`run_stale_cells_tool`;description=Co;schema=k({});outputSchema=Ka.extend({cellsToOutput:fe(O(),k({consoleOutput:O().optional(),cellOutput:O().optional(),consoleAttachments:xe(wo).optional(),cellAttachments:xe(wo).optional()}).nullable()).optional()});mode=[`agent`];postExecutionDelay;constructor(e){this.postExecutionDelay=e?.postExecutionDelay??vo}handler=async(e,t)=>{let{prepareForRun:n,sendRun:r,store:i}=t,a=i.get(S),o=ee(a);if(o.length===0)return{status:`success`,message:`No stale cells found.`};if(await Pt({cellIds:o,sendRun:r,prepareForRun:n,notebook:a}),!await this.waitForCellsToFinish(i,o,yo,this.postExecutionDelay))return{status:`success`,message:`No output was returned because some cells have not finished executing`};let s=i.get(S),c=new Map,l=!1,u=!1,d=0;for(let e of o){let t=_o(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>=So){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.`},uo=k({edit:k({type:_e([`update_cell`,`add_cell`,`delete_cell`]),code:O().optional(),position:k({type:_e([`relative`,`column_end`,`notebook_end`]).optional(),cellId:O().optional(),columnIndex:ae().optional(),before:me().optional()})})}),fo=class{name=`edit_notebook_tool`;description=lo;schema=uo;outputSchema=Ka;mode=[`agent`];handler=async({edit:e},t)=>{let{addStagedCell:n,createNewCell:r,store:i}=t;switch(e.type){case`update_cell`:{let{position:t,code:r}=e,a=t.cellId;if(!a)throw new Y(`Cell ID is required for update_cell`,`CELL_ID_REQUIRED_FOR_UPDATE_CELL`,!0,`Provide a cell ID to update`);if(!r)throw new Y(`Code is required for update_cell`,`CODE_REQUIRED_FOR_UPDATE_CELL`,!0,`Provide the new code to update the cell`);let o=i.get(S);this.validateCellIdExists(a,o);let s=this.getCellEditorView(a,o);jt(a);let c=i.get(Z).get(a);if(c?.type===`add_cell`){ne(s,r);break}let l=s.state.doc.toString(),u=c?.previousCode??l;if(r===u)break;n({cellId:a,edit:{type:`update_cell`,previousCode:u}}),ne(s,r);break}case`add_cell`:{let{position:t,code:a}=e,o=`__end__`,s=!1,c=ie.create(),l=i.get(S);switch(t.type){case`relative`:{let e=t.cellId;if(!e)throw new Y(`Cell ID is required for add_cell with relative position`,`TOOL_ERROR`,!0,`Provide a cell ID to add the cell before`);if(t.before===void 0)throw new Y(`Before is required for add_cell with relative position`,`TOOL_ERROR`,!0,`Provide a boolean value for before, true to add before cell ${e}, false to add after the cell`);this.validateCellIdExists(e,l),o=e,s=t.before;break}case`column_end`:if(!t.columnIndex)throw new Y(`Column index is required for add_cell with column_end position`,`TOOL_ERROR`,!0,`Provide a column index to add the cell at the end of`);o={type:`__end__`,columnId:this.getColumnId(t.columnIndex,l)}}r({cellId:o,before:s,code:a,newCellId:c}),n({cellId:c,edit:{type:`add_cell`}}),jt(c);break}case`delete_cell`:{let{position:t}=e,r=t.cellId;if(!r)throw new Y(`Cell ID is required for delete_cell`,`CELL_ID_REQUIRED_FOR_DELETE_CELL`,!0,`Provide a cell ID to delete`);let a=i.get(S);this.validateCellIdExists(r,a),n({cellId:r,edit:{type:`delete_cell`,previousCode:this.getCellEditorView(r,a).state.doc.toString()}}),jt(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 po(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 mo=class extends Dt{title=`Cell Outputs`;mentionPrefix=`@`;contextType=`cell-output`;store;constructor(e){super(),this.store=e}getItems(){let e=this.store.get(S),t=[];for(let n of e.cellIds.inOrderIds){let r=_o(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`?Et.HIGH:Et.MEDIUM,type:this.contextType,section:yt.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}`)),Lt({type:this.contextType,data:a,details:o})}async getAttachments(e){let t=e[0].data.cellId,n=e[0].data.cellName;return ho(e.map(e=>e.data.cellOutput),t,n)}};async function ho(e,t,n){let r=e.filter(e=>e.shouldDownloadImage&&e.outputType===`media`);if(r.length===0)return[];let i=r.flatMap(e=>{let r=document.getElementById(C.create(t));return r?{cellId:t,cellName:n,mimetype:e.output.mimetype,element:r}:(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 go(e){if(St(e))return null;let t=e.mimetype,n=po(t,String(e.data))?`media`:`text`,r=qe(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 _o(e,t,n){let{includeConsoleOutput:r=!1}=n||{},i=t.cellRuntime[e],a=t.cellData[e],o=t.cellIds.inOrderIds.indexOf(e),s=m(a.name,o),c;r&&(c=i.consoleOutputs.map(e=>go(e)).filter(e=>e!==null));let l,u=i.output;return u&&!St(u)&&(l=go(u)??void 0),{cellId:e,cellName:s,cellCode:a.code,cellOutput:l,consoleOutputs:c}}var vo=200,yo=3e4,bo=2e3,xo=3e3,So=4e4,Co={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.`},wo=k({type:le(`file`),url:O(),mediaType:O()}),To=class{name=`run_stale_cells_tool`;description=Co;schema=k({});outputSchema=Ka.extend({cellsToOutput:fe(O(),k({consoleOutput:O().optional(),cellOutput:O().optional(),consoleAttachments:xe(wo).optional(),cellAttachments:xe(wo).optional()}).nullable()).optional()});mode=[`agent`];postExecutionDelay;constructor(e){this.postExecutionDelay=e?.postExecutionDelay??vo}handler=async(e,t)=>{let{prepareForRun:n,sendRun:r,store:i}=t,a=i.get(S),o=ee(a);if(o.length===0)return{status:`success`,message:`No stale cells found.`};if(await Nt({cellIds:o,sendRun:r,prepareForRun:n,notebook:a}),!await this.waitForCellsToFinish(i,o,yo,this.postExecutionDelay))return{status:`success`,message:`No output was returned because some cells have not finished executing`};let s=i.get(S),c=new Map,l=!1,u=!1,d=0;for(let e of o){let t=_o(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>=So){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,bo),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)?xo:bo,o=n;return o||=typeof i.data==`string`?i.data:JSON.stringify(i.data),`Output:\n${this.truncateString(o,a)}`}truncateString(e,t){return e.length<=t?e:`${e.slice(0,t)}\n\n[TRUNCATED: ${e.length.toLocaleString()} → ${t.toLocaleString()} chars. Full output visible in the notebook UI.]`}async waitForCellsToFinish(e,t,r,i){let a=e=>t.every(t=>{let n=e.cellRuntime[t];return n?.status!==`running`&&n?.status!==`queued`}),o=async()=>(i>0&&await new Promise(e=>setTimeout(e,i)),!0);if(a(e.get(S)))return await o();try{return await Promise.race([n(S,a),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),r))]),await o()}catch{return!1}}};function Eo(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(`
@@ -51,11 +51,11 @@ ${t}`,d++;break;case`id`:l=t.includes(`\0`)?void 0:t;break;case`retry`:/^\d+$/.t
51
51
  `)),e.errorData.some(e=>e.type===`sql-error`)){let r=Rt(e.cellId,t);r&&n.push(`Database schema:\n${r}`)}return n.join(`
52
52
 
53
53
  `)}function Ao(e,t){return Lt({type:`error`,data:{name:e.cellName||`Cell ${e.cellId}`,cellId:e.cellId},details:ko(e,t)})}function jo(e){return e.errorData.length===1?Ht(e.errorData[0]):e.errorData.length>1?`${e.errorData.length} errors`:e.tracebackHtml?y(e.tracebackHtml).trim().split(`
54
- `).find(e=>e.trim())?.trim()||`traceback`:`error`}function Mo(e){return`Error: ${e.cellName||`Cell ${e.cellId}`}`}var No=new _(`error`,`errors`),Po=class extends Ot{title=`Errors`;mentionPrefix=`@`;contextType=`error`;store;constructor(e){super(),this.store=e}getItems(){let e=Bt(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:Mo(n),type:this.contextType,data:{type:`cell-error`,error:n},description:jo(n)});return t}formatCompletion(e){if(e.data.type===`all-errors`){let t=e.data.errors.length;return{label:`@Errors`,displayLabel:`Errors`,detail:`${t} ${No.pluralize(t)}`,type:`error`,apply:`@error://all`,section:bt.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} ${No.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:jo(t),type:`error`}),section:bt.ERROR}}return{label:`Error`,displayLabel:`Error`,section:bt.ERROR}}formatContext(e){return(e.data.type===`all-errors`?e.data.errors:[e.data.error]).map(e=>Ao(e,this.store)).join(`
54
+ `).find(e=>e.trim())?.trim()||`traceback`:`error`}function Mo(e){return`Error: ${e.cellName||`Cell ${e.cellId}`}`}var No=new _(`error`,`errors`),Po=class extends Dt{title=`Errors`;mentionPrefix=`@`;contextType=`error`;store;constructor(e){super(),this.store=e}getItems(){let e=Bt(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:Mo(n),type:this.contextType,data:{type:`cell-error`,error:n},description:jo(n)});return t}formatCompletion(e){if(e.data.type===`all-errors`){let t=e.data.errors.length;return{label:`@Errors`,displayLabel:`Errors`,detail:`${t} ${No.pluralize(t)}`,type:`error`,apply:`@error://all`,section:yt.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} ${No.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:jo(t),type:`error`}),section:yt.ERROR}}return{label:`Error`,displayLabel:`Error`,section:yt.ERROR}}formatContext(e){return(e.data.type===`all-errors`?e.data.errors:[e.data.error]).map(e=>Ao(e,this.store)).join(`
55
55
 
56
- `)}},Fo=x(),Io={maxDepth:3,maxResults:20,defaultResultsLimit:5,includeDirectories:!1},Lo=class extends Ot{title=`Files`;mentionPrefix=`#`;contextType=`file`;apiRequests;config;constructor(e,t=Io){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:bt.FILE,boost:t.isDirectory?Et.MEDIUM:Et.LOW,detail:t.path,displayLabel:`${r} ${n}`,apply:async(e,r,i,a)=>{let o=e.state.facet(Fo)?.addAttachment;if(!o){A.warn(`No addAttachment callback provided`);return}let s=await this.apiRequests.sendFileDetails({path:t.path}).catch(e=>(Ye({title:`Failed to get file details`,description:e.message}),null));if(!s)return;let c=s.mimeType||`text/plain`,l=jt({contents:s.contents??``,mimeType:c,isBase64:s.isBase64??!1});o(new File([l],n,{type:c})),e.dispatch({changes:{from:i,to:a,insert:``}}),dt(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 Lt({type:this.contextType,data:{name:n,path:t.path,isDirectory:t.isDirectory},details:t.isDirectory?`Directory containing files and subdirectories`:`File`})}},Ro=class extends Ot{title=`Tables`;mentionPrefix=`@`;contextType=`data`;tablesMap;constructor(e){super(),this.tablesMap=e}getItems(){return[...this.tablesMap.entries()].map(([e,t])=>({uri:this.asURI(e),name:e,type:this.contextType,description:t.source===`memory`?`in-memory`:t.source,data:t}))}formatContext(e){let{data:t}=e,{columns:n,source:r,num_rows:i,num_columns:a,name:o,variable_name:s}=t,c=[i==null?void 0:`${i} rows`,a==null?void 0:`${a} columns`].filter(Boolean).join(`, `),l=``;if(c&&(l+=`Shape: ${c}\n`),s&&(l+=`Variable: ${s}\n`),n&&n.length>0){l+=`Columns:
57
- `;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 Lt({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`?Et.LOCAL_TABLE:Et.REMOTE_TABLE,type:p(n),apply:`@${t}`,section:{name:p(n)===`dataframe`?`Dataframe`:`Table`,rank:bt.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}}},zo=class extends Ot{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:bt.VARIABLE,info:()=>w(n)}}formatContext(e){let{data:t}=e,{variable:n}=t;return Lt({type:this.contextType,data:{name:n.name,dataType:n.dataType},details:n.value==null?void 0:JSON.stringify(n.value)})}};function Bo(e){let t=e.get(h),n=e.get(E),r=e.get(D);return new St().register(new Ro(n)).register(new zo(r,n)).register(new Po(e)).register(new mo(e)).register(new kt(t.connectionsMap,n))}function Vo(){return new Lo(pt())}function Ho({input:e}){let t=``;return e.includes(`@`)&&(t=Xo(e),A.debug(`Included context`,t)),{includeOtherCode:b(``),context:{plainText:t,schema:[],variables:[]}}}var Uo=`data-marimo-context`,Wo={marimo:{source:`context`}};function Go(e){return e.type===`file`&&e.providerMetadata?.marimo?.source===Wo.marimo.source}function Ko(e){return{...e,providerMetadata:{...e.providerMetadata,marimo:{...e.providerMetadata?.marimo,...Wo.marimo}}}}async function qo(e){if(!e.includes(`@`))return{plainText:``,contextIds:[],attachments:[]};let t=Bo(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(Ko)}catch(e){A.error(`Error getting attachments:`,e)}return{plainText:r,contextIds:n,attachments:i}}async function Jo(e){let{plainText:t,contextIds:n,attachments:r}=await qo(e),i=null;return t.trim()&&(i={type:Uo,data:{plainText:t,contextIds:n.map(String)}}),{contextPart:i,attachments:r}}async function Yo({input:e}){let{plainText:t,attachments:n}=await qo(e);return{body:{includeOtherCode:b(``),context:{plainText:t,schema:[],variables:[]}},attachments:n}}function Xo(e){let t=Bo(s),n=t.parseAllContextIds(e);return t.formatContextForAI(n)}function Zo(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 Qo(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(),lt(e.current.view)}}var $o=new Set([`openai`,`google`,`anthropic`]),es=[`image/*`,`text/*`],ts=52428800;function ns(e){return e.length>50?`${e.slice(0,50)}...`:e}async function rs(e){return await Promise.all(e.map(async e=>({type:`file`,mediaType:e.type,filename:e.name,url:await Ft(e,`dataUrl`)})))}function is(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 as(e){return e.map(e=>e.type===`text`?e.text:``).join(`
58
- `)}async function os(e){let t=await Yo({input:as(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 ss({invokeAiTool:e,addToolOutput:t,toolCall:n,toolContext:r}){try{if(Oo.has(n.toolName)){let e=await Oo.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 cs(e){let t=e.at(-1);if(!t||t.role!==`assistant`)return!1;let n=t.parts.at(-1);return!n||!H(n)?!1:_a({messages:e})||ga({messages:e})||n.state===`output-denied`&&!n.providerExecuted}function ls(e){let t=e.at(-1);return!t||t.role!==`assistant`?!1:t.parts.some(e=>H(e)&&us(e.state))}function us(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 ds(){let e=(0,j.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(fs,0)>ts){Ye({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 fs(e,t){return e+t.size}function ps(e){return e.isError?!1:e.isAbort?!0:!e.hasPendingToolCalls&&!e.hasUnresolvedToolCalls}function ms(){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:ht(),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 hs=e=>{let t=(0,j.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)(yt,{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},gs=e=>{let t=(0,j.c)(12),{file:n,className:r,onRemove:i}=e,[a,o]=(0,W.useState)(!1),s;t[0]===r?s=t[1]:(s=Me(`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)(We,{className:`h-3 w-3 mt-0.5`,onClick:i}):bs(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},_s=e=>{let t=(0,j.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)(At,{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)(Be,{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)(ze,{content:u,children:m}),t[9]=u,t[10]=m,t[11]=h):h=t[11],h},vs=e=>{let t=(0,j.c)(4),{handleAddContext:n,isLoading:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,G.jsx)(Tt,{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)(ze,{content:`Add context`,children:(0,G.jsx)(Be,{variant:`text`,size:`icon`,onClick:n,disabled:r,children:i})}),t[1]=n,t[2]=r,t[3]=a):a=t[3],a},ys=e=>{let t=(0,j.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)(ze,{content:`Attach a file`,children:(0,G.jsx)(Be,{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=es.join(`,`),t[8]=l):l=t[8];let u;t[9]!==n||t[10]!==c?(u=(0,G.jsx)(Je,{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 bs(e){let t=`h-3 w-3 mt-0.5`;return e.type.startsWith(`image/`)?(0,G.jsx)(zt,{className:t}):e.type.startsWith(`text/`)?(0,G.jsx)(Ue,{className:t}):(0,G.jsx)(yt,{className:t})}var xs=e=>{let t=(0,j.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&&Oe(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},Ss=et.define(),Q=Ze.define({create(){return new Map},update(e,t){let n=!1,r=e;for(let i of t.effects)if(i.is(Ss)){n||=(r=new Map(e),!0);for(let[e,t]of i.value)r.set(e,t)}return r}}),Cs=Ze.define({create(){return{onResourceClick:void 0,onResourceMouseOver:void 0,onResourceMouseOut:void 0,onPromptSubmit:void 0}},update(e){return e}}),ws=et.define();Ze.define({create(){return new Map},update(e,t){let n=!1,r=e;for(let i of t.effects)if(i.is(ws)){n||=(r=new Map(e),!0);for(let[e,t]of i.value)r.set(e,t)}return r}});var Ts=(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=Ss.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}},Es=/@[\w-]+:\/\/(?!\/)[^\s]+/;function $(e){return e.matchAll(new RegExp(Es.source,`g`))}var Ds=class extends nt{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(Cs,!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}},Os=class extends nt{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 ks(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(tt.replace({widget:new Ds(s,e)}).range(a,a+i[0].length)):n.push(tt.replace({widget:new Os(o,e)}).range(a,a+i[0].length))}}return tt.set(n)}var As=ot.fromClass(class{decorations;constructor(e){this.decorations=ks(e)}update(e){(e.docChanged||e.viewportChanged||e.transactions.some(e=>e.effects.some(e=>e.is(Ss))))&&(this.decorations=ks(e.view))}},{decorations:e=>e.decorations});function js(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 Ms(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 Ns(e){return st((t,n)=>{let{from:r,text:i}=t.state.doc.lineAt(n),a=Ms(i,n,t.state.field(Q),r);return a?{pos:a.start,end:a.end,above:!0,create(){return(e.createTooltip??js)(a.resource)}}:null})}function Ps(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 Fs(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 Is(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 Ls(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 Rs(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 zs=$e.transactionFilter.of(e=>{let t=e.annotation(rt.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!==`
56
+ `)}},Fo=x(),Io={maxDepth:3,maxResults:20,defaultResultsLimit:5,includeDirectories:!1},Lo=class extends Dt{title=`Files`;mentionPrefix=`#`;contextType=`file`;apiRequests;config;constructor(e,t=Io){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:yt.FILE,boost:t.isDirectory?Et.MEDIUM:Et.LOW,detail:t.path,displayLabel:`${r} ${n}`,apply:async(e,r,i,a)=>{let o=e.state.facet(Fo)?.addAttachment;if(!o){A.warn(`No addAttachment callback provided`);return}let s=await this.apiRequests.sendFileDetails({path:t.path}).catch(e=>(Ye({title:`Failed to get file details`,description:e.message}),null));if(!s)return;let c=s.mimeType||`text/plain`,l=At({contents:s.contents??``,mimeType:c,isBase64:s.isBase64??!1});o(new File([l],n,{type:c})),e.dispatch({changes:{from:i,to:a,insert:``}}),dt(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 Lt({type:this.contextType,data:{name:n,path:t.path,isDirectory:t.isDirectory},details:t.isDirectory?`Directory containing files and subdirectories`:`File`})}},Ro=class extends Dt{title=`Tables`;mentionPrefix=`@`;contextType=`data`;tablesMap;constructor(e){super(),this.tablesMap=e}getItems(){return[...this.tablesMap.entries()].map(([e,t])=>({uri:this.asURI(e),name:e,type:this.contextType,description:t.source===`memory`?`in-memory`:t.source,data:t}))}formatContext(e){let{data:t}=e,{columns:n,source:r,num_rows:i,num_columns:a,name:o,variable_name:s}=t,c=[i==null?void 0:`${i} rows`,a==null?void 0:`${a} columns`].filter(Boolean).join(`, `),l=``;if(c&&(l+=`Shape: ${c}\n`),s&&(l+=`Variable: ${s}\n`),n&&n.length>0){l+=`Columns:
57
+ `;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 Lt({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`?Et.LOCAL_TABLE:Et.REMOTE_TABLE,type:p(n),apply:`@${t}`,section:{name:p(n)===`dataframe`?`Dataframe`:`Table`,rank:yt.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}}},zo=class extends Dt{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:yt.VARIABLE,info:()=>w(n)}}formatContext(e){let{data:t}=e,{variable:n}=t;return Lt({type:this.contextType,data:{name:n.name,dataType:n.dataType},details:n.value==null?void 0:JSON.stringify(n.value)})}};function Bo(e){let t=e.get(h),n=e.get(E),r=e.get(D);return new xt().register(new Ro(n)).register(new zo(r,n)).register(new Po(e)).register(new mo(e)).register(new Ot(t.connectionsMap,n))}function Vo(){return new Lo(pt())}function Ho({input:e}){let t=``;return e.includes(`@`)&&(t=Xo(e),A.debug(`Included context`,t)),{includeOtherCode:b(``),context:{plainText:t,schema:[],variables:[]}}}var Uo=`data-marimo-context`,Wo={marimo:{source:`context`}};function Go(e){return e.type===`file`&&e.providerMetadata?.marimo?.source===Wo.marimo.source}function Ko(e){return{...e,providerMetadata:{...e.providerMetadata,marimo:{...e.providerMetadata?.marimo,...Wo.marimo}}}}async function qo(e){if(!e.includes(`@`))return{plainText:``,contextIds:[],attachments:[]};let t=Bo(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(Ko)}catch(e){A.error(`Error getting attachments:`,e)}return{plainText:r,contextIds:n,attachments:i}}async function Jo(e){let{plainText:t,contextIds:n,attachments:r}=await qo(e),i=null;return t.trim()&&(i={type:Uo,data:{plainText:t,contextIds:n.map(String)}}),{contextPart:i,attachments:r}}async function Yo({input:e}){let{plainText:t,attachments:n}=await qo(e);return{body:{includeOtherCode:b(``),context:{plainText:t,schema:[],variables:[]}},attachments:n}}function Xo(e){let t=Bo(s),n=t.parseAllContextIds(e);return t.formatContextForAI(n)}function Zo(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 Qo(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(),lt(e.current.view)}}var $o=new Set([`openai`,`google`,`anthropic`]),es=[`image/*`,`text/*`],ts=52428800;function ns(e){return e.length>50?`${e.slice(0,50)}...`:e}async function rs(e){return await Promise.all(e.map(async e=>({type:`file`,mediaType:e.type,filename:e.name,url:await Pt(e,`dataUrl`)})))}function is(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 as(e){return e.map(e=>e.type===`text`?e.text:``).join(`
58
+ `)}async function os(e){let t=await Yo({input:as(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 ss({invokeAiTool:e,addToolOutput:t,toolCall:n,toolContext:r}){try{if(Oo.has(n.toolName)){let e=await Oo.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 cs(e){let t=e.at(-1);if(!t||t.role!==`assistant`)return!1;let n=t.parts.at(-1);return!n||!H(n)?!1:_a({messages:e})||ga({messages:e})||n.state===`output-denied`&&!n.providerExecuted}function ls(e){let t=e.at(-1);return!t||t.role!==`assistant`?!1:t.parts.some(e=>H(e)&&us(e.state))}function us(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 ds(){let e=(0,j.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(fs,0)>ts){Ye({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 fs(e,t){return e+t.size}function ps(e){return e.isError?!1:e.isAbort?!0:!e.hasPendingToolCalls&&!e.hasUnresolvedToolCalls}function ms(){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:ht(),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 hs=e=>{let t=(0,j.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)(vt,{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},gs=e=>{let t=(0,j.c)(12),{file:n,className:r,onRemove:i}=e,[a,o]=(0,W.useState)(!1),s;t[0]===r?s=t[1]:(s=Me(`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)(We,{className:`h-3 w-3 mt-0.5`,onClick:i}):bs(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},_s=e=>{let t=(0,j.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)(kt,{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)(Be,{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)(ze,{content:u,children:m}),t[9]=u,t[10]=m,t[11]=h):h=t[11],h},vs=e=>{let t=(0,j.c)(4),{handleAddContext:n,isLoading:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,G.jsx)(wt,{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)(ze,{content:`Add context`,children:(0,G.jsx)(Be,{variant:`text`,size:`icon`,onClick:n,disabled:r,children:i})}),t[1]=n,t[2]=r,t[3]=a):a=t[3],a},ys=e=>{let t=(0,j.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)(ze,{content:`Attach a file`,children:(0,G.jsx)(Be,{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=es.join(`,`),t[8]=l):l=t[8];let u;t[9]!==n||t[10]!==c?(u=(0,G.jsx)(Je,{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 bs(e){let t=`h-3 w-3 mt-0.5`;return e.type.startsWith(`image/`)?(0,G.jsx)(zt,{className:t}):e.type.startsWith(`text/`)?(0,G.jsx)(Ue,{className:t}):(0,G.jsx)(vt,{className:t})}var xs=e=>{let t=(0,j.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&&Oe(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},Ss=et.define(),Q=Ze.define({create(){return new Map},update(e,t){let n=!1,r=e;for(let i of t.effects)if(i.is(Ss)){n||=(r=new Map(e),!0);for(let[e,t]of i.value)r.set(e,t)}return r}}),Cs=Ze.define({create(){return{onResourceClick:void 0,onResourceMouseOver:void 0,onResourceMouseOut:void 0,onPromptSubmit:void 0}},update(e){return e}}),ws=et.define();Ze.define({create(){return new Map},update(e,t){let n=!1,r=e;for(let i of t.effects)if(i.is(ws)){n||=(r=new Map(e),!0);for(let[e,t]of i.value)r.set(e,t)}return r}});var Ts=(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=Ss.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}},Es=/@[\w-]+:\/\/(?!\/)[^\s]+/;function $(e){return e.matchAll(new RegExp(Es.source,`g`))}var Ds=class extends nt{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(Cs,!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}},Os=class extends nt{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 ks(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(tt.replace({widget:new Ds(s,e)}).range(a,a+i[0].length)):n.push(tt.replace({widget:new Os(o,e)}).range(a,a+i[0].length))}}return tt.set(n)}var As=ot.fromClass(class{decorations;constructor(e){this.decorations=ks(e)}update(e){(e.docChanged||e.viewportChanged||e.transactions.some(e=>e.effects.some(e=>e.is(Ss))))&&(this.decorations=ks(e.view))}},{decorations:e=>e.decorations});function js(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 Ms(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 Ns(e){return st((t,n)=>{let{from:r,text:i}=t.state.doc.lineAt(n),a=Ms(i,n,t.state.field(Q),r);return a?{pos:a.start,end:a.end,above:!0,create(){return(e.createTooltip??js)(a.resource)}}:null})}function Ps(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 Fs(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 Is(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 Ls(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 Rs(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 zs=$e.transactionFilter.of(e=>{let t=e.annotation(rt.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!==`
59
59
  `&&e!==` `&&(h=!0)}if(d===i){let e=d<n.length?n.sliceString(d,d+1):``;(e===``||e!==` `&&e!==`
60
60
  `&&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=Ps(e.startState,n.head):t===`delete.forward`&&(r=Fs(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=Is(e.startState,t);i=n&&t>n.from?n.from:Ls(e.startState,t)}else if(r>t){let n=Is(e.startState,t);i=n&&t<n.to?n.to:Rs(e.startState,t)}if(i!==null&&i!==r)return[{selection:{anchor:i},scrollIntoView:!0}]}return e}),Bs=150;function Vs(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 Hs(e){return[...e].sort().join(`
61
61
  `)}function Us(e){return!$(e).next().done}function Ws(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(`
@@ -63,14 +63,14 @@ ${t}`,d++;break;case`id`:l=t.includes(`\0`)?void 0:t;break;case`retry`:/^\d+$/.t
63
63
  `)}}function Gs(e,t){let n=t.debounceMs??Bs,{logger:r,resolve:i}=t;return class{view;timer;running=!1;rerun=!1;lastKey=``;destroyed=!1;constructor(e){this.view=e,this.maybeSchedule(e)}update(e){if(e.docChanged){let t=Ws(e);if(Us(t.before)){this.maybeSchedule(e.view);return}this.maybeSchedule(e.view,t.after)}}destroy(){this.destroyed=!0,this.clearTimer()}maybeSchedule(e,t){let r=t??e.state.doc.toString();if(!Us(r)){t===void 0&&(this.lastKey=``,this.clearTimer());return}let i=Hs(Vs(r,e.state.field(Q)));if(i===``){t===void 0&&(this.lastKey=``,this.clearTimer());return}if(i===this.lastKey){this.clearTimer();return}this.clearTimer(),this.timer=setTimeout(()=>{this.timer=void 0,this.run(e)},n)}clearTimer(){this.timer!==void 0&&(clearTimeout(this.timer),this.timer=void 0)}async run(t){if(!this.destroyed){if(this.running){this.rerun=!0;return}this.running=!0;try{do{this.rerun=!1;let n=Vs(t.state.doc.toString(),t.state.field(Q));if(n.length===0){this.lastKey=``;break}this.lastKey=Hs(n);let r=i?await i(n):await e();if(this.destroyed)return;let a=new Set(n),o=r.filter(e=>a.has(e.uri));if(o.length===0){if(this.rerun)continue;break}t.dispatch({effects:Ss.of(new Map(o.map(e=>[e.uri,e])))}),this.rerun=!0}while(this.rerun)}catch(e){this.lastKey=``,r?.error(`Failed to sync resources:`,e)}finally{this.running=!1}}}}}function Ks(e,t={}){return ot.fromClass(Gs(e,t))}var qs=at.baseTheme({".cm-resource-widget":{background:`light-dark(rgba(86,156,214,0.08),rgba(86,156,214,0.18))`,borderRadius:`4px`,padding:`2px 4px`,color:`light-dark(#2367a2,#7ecbff)`,fontWeight:`500`},".cm-resource-widget:hover":{background:`light-dark(rgba(86,156,214,0.18),rgba(86,156,214,0.28))`},".cm-not-found-resource-widget":{background:`light-dark(rgba(151,151,151,0.08),rgba(151,151,151,0.18))`,borderRadius:`4px`,padding:`2px 4px`,color:`light-dark(#b00020,#ff8080)`,fontWeight:`500`}}),Js=`_none_`,Ys=[{uri:``,name:`No resources`,type:Js,data:{}}],Xs={info:`Variables, dataframes, and tables will appear here.`,apply:()=>{}};function Zs(e){let t=Bo(e).getAllItems();return t.length===0?Ys:t}function Qs(e){let{language:t,store:n,onAddFiles:r}=e,i=()=>Zs(n);return[t.data.of({autocomplete:Ts(async()=>i(),e=>e.type===Js?Xs:Bo(n).getProvider(e.type)?.formatCompletion(e)||{})}),it.high(Qe.of([{key:`Tab`,preventDefault:!0,run:e=>ut(e)}])),Fo.of({addAttachment:e=>r?.([e])}),...r?[t.data.of({autocomplete:Vo().createCompletionSource()})]:[],As,zs,Ks(i,{logger:A}),Q.init(()=>{let e=Zs(n);return new Map(e.map(e=>[e.uri,e]))}),qs,Ns({createTooltip:e=>{let t=Bo(n).getProvider(e.type);if(!t)return A.warn(`No provider found for resource`,e),$s(e.description||e.name);let r=t.formatCompletion(e),i=e.description||e.name;if(!r?.info)return $s(i);if(typeof r.info==`string`)return $s(r.info);let a=r.info(r);return a?`dom`in a?{dom:a.dom}:`then`in a?(A.warn(`info is a promise. This is not supported`,a),$s(i)):{dom:a}:$s(i)}})]}function $s(e){let t=document.createElement(`div`);return t.innerHTML=e,{dom:t}}var ec={accept:`Keep change`,decline:`Revert change`},tc=e=>{let{handleAcceptCompletion:t,handleDeclineCompletion:n,isLoading:r,hasCompletion:i}=e;return e=>{let a=De()?e.metaKey:e.ctrlKey;a&&e.key===`Enter`&&!r&&i&&t(),(e.key===`Delete`||e.key===`Backspace`)&&a&&e.shiftKey&&(n(),e.preventDefault(),e.stopPropagation())}},nc=e=>{let t=(0,j.c)(14),{isLoading:n,onAccept:r,onDecline:i,runCell:a,acceptLabel:o,declineLabel:s,size:c}=e,l;t[0]!==o||t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==c?(l=(0,G.jsx)(rc,{isLoading:n,onAccept:r,size:c,runCell:a,label:o}),t[0]=o,t[1]=n,t[2]=r,t[3]=a,t[4]=c,t[5]=l):l=t[5];let u;t[6]!==s||t[7]!==n||t[8]!==i||t[9]!==c?(u=(0,G.jsx)(ic,{onDecline:i,size:c,label:s,disabled:n}),t[6]=s,t[7]=n,t[8]=i,t[9]=c,t[10]=u):u=t[10];let d;return t[11]!==l||t[12]!==u?(d=(0,G.jsxs)(G.Fragment,{children:[l,u]}),t[11]=l,t[12]=u,t[13]=d):d=t[13],d},rc=e=>{let t=(0,j.c)(33),{isLoading:n,onAccept:r,multipleCompletions:i,size:a,buttonStyles:o,acceptShortcut:s,runCell:c,playButtonStyles:l,borderless:u,label:d}=e,f=i!==void 0&&i,p=a===void 0?`sm`:a,m=u!==void 0&&u,h;t[0]!==r||t[1]!==c?(h=()=>{r(),c&&c()},t[0]=r,t[1]=c,t[2]=h):h=t[2];let g=h,_=d??(f?`Accept all`:`Accept`);if(c){let e=`h-6 text-(--grass-11) bg-(--grass-3)/60
64
64
  hover:bg-(--grass-3) dark:bg-(--grass-4)/80 dark:hover:bg-(--grass-3) font-semibold
65
65
  active:bg-(--grass-5) dark:active:bg-(--grass-4)
66
- border-(--green-6) border hover:shadow-xs rounded-r-none ${m&&`border-none rounded-md rounded-r-none`} ${o}`,i;t[3]===s?i=t[4]:(i=s&&(0,G.jsx)(xt,{className:`ml-1 inline`,shortcut:s}),t[3]=s,t[4]=i);let a;t[5]!==n||t[6]!==r||t[7]!==p||t[8]!==e||t[9]!==i||t[10]!==_?(a=(0,G.jsxs)(Be,{variant:`text`,size:p,disabled:n,onClick:r,className:e,children:[_,i]}),t[5]=n,t[6]=r,t[7]=p,t[8]=e,t[9]=i,t[10]=_,t[11]=a):a=t[11];let c=`${_} and run ${f?`all cells`:`cell`}`,u=`h-6 text-(--grass-11) bg-(--grass-3)/60
66
+ border-(--green-6) border hover:shadow-xs rounded-r-none ${m&&`border-none rounded-md rounded-r-none`} ${o}`,i;t[3]===s?i=t[4]:(i=s&&(0,G.jsx)(bt,{className:`ml-1 inline`,shortcut:s}),t[3]=s,t[4]=i);let a;t[5]!==n||t[6]!==r||t[7]!==p||t[8]!==e||t[9]!==i||t[10]!==_?(a=(0,G.jsxs)(Be,{variant:`text`,size:p,disabled:n,onClick:r,className:e,children:[_,i]}),t[5]=n,t[6]=r,t[7]=p,t[8]=e,t[9]=i,t[10]=_,t[11]=a):a=t[11];let c=`${_} and run ${f?`all cells`:`cell`}`,u=`h-6 text-(--grass-11) bg-(--grass-3)/60
67
67
  hover:bg-(--grass-3) dark:bg-(--grass-4)/80 dark:hover:bg-(--grass-3) font-semibold
68
68
  active:bg-(--grass-5) dark:active:bg-(--grass-4)
69
69
  border-(--green-6) border hover:shadow-xs rounded-l-none px-1.5 ${m&&`border-0 border-l`} ${l}`,d;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,G.jsx)(Ge,{className:`h-2.5 w-2.5`}),t[12]=d):d=t[12];let h;t[13]!==g||t[14]!==n||t[15]!==p||t[16]!==u?(h=(0,G.jsx)(Be,{variant:`text`,size:p,disabled:n,onClick:g,className:u,children:d}),t[13]=g,t[14]=n,t[15]=p,t[16]=u,t[17]=h):h=t[17];let v;t[18]!==h||t[19]!==c?(v=(0,G.jsx)(ze,{content:c,children:h}),t[18]=h,t[19]=c,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==a?(y=(0,G.jsxs)(`div`,{className:`flex`,children:[a,v]}),t[21]=v,t[22]=a,t[23]=y):y=t[23],y}let v=`h-6 text-(--grass-11) bg-(--grass-3)/60
70
70
  hover:bg-(--grass-3) dark:bg-(--grass-4)/80 dark:hover:bg-(--grass-3) font-semibold
71
71
  active:bg-(--grass-5) dark:active:bg-(--grass-4)
72
- border-(--green-6) border hover:shadow-xs rounded px-3 ${o}`,y;t[24]===s?y=t[25]:(y=s&&(0,G.jsx)(xt,{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)(Be,{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},ic=e=>{let t=(0,j.c)(9),{onDecline:n,disabled:r,multipleCompletions:i,size:a,className:o,declineShortcut:s,borderless:c,label:l}=e,u=r!==void 0&&r,d=i!==void 0&&i,f=a===void 0?`sm`:a,p=`h-6 text-(--red-10) bg-(--red-3)/60 hover:bg-(--red-3)
72
+ border-(--green-6) border hover:shadow-xs rounded px-3 ${o}`,y;t[24]===s?y=t[25]:(y=s&&(0,G.jsx)(bt,{className:`ml-1 inline`,shortcut:s}),t[24]=s,t[25]=y);let b;return t[26]!==n||t[27]!==r||t[28]!==p||t[29]!==v||t[30]!==y||t[31]!==_?(b=(0,G.jsxs)(Be,{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},ic=e=>{let t=(0,j.c)(9),{onDecline:n,disabled:r,multipleCompletions:i,size:a,className:o,declineShortcut:s,borderless:c,label:l}=e,u=r!==void 0&&r,d=i!==void 0&&i,f=a===void 0?`sm`:a,p=`h-6 text-(--red-10) bg-(--red-3)/60 hover:bg-(--red-3)
73
73
  dark:bg-(--red-4)/80 dark:hover:bg-(--red-3) rounded px-3 font-semibold
74
74
  active:bg-(--red-5) dark:active:bg-(--red-4)
75
- border-(--red-6) border hover:shadow-xs ${c!==void 0&&c&&`border-none rounded-md`} ${o}`,m=l??`Reject${d?` all`:``}`,h;t[0]===s?h=t[1]:(h=s&&(0,G.jsx)(xt,{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)(Be,{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},ac=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}}},oc=Ae(`marimo:ai-language`,`python`,g),sc=`marimo:ai-prompt-history`,cc=new f(xe(O()),()=>[]),lc=({onClose:e})=>{let t=i(),[n,a]=(0,W.useState)(``),{acceptOwnedStagedCells:s,beginStagedCellGeneration:l,discardOwnedStagedCells:u,finishStagedCellGeneration:d,hasOwnedStagedCells:f,onData:p}=so(t),[m,h]=r(oc),g=je(),_=(0,W.useRef)(null),v=(0,W.useRef)(new ac).current,y=(0,W.useRef)(null),{files:b,addFiles:x,removeFile:S}=ds(),C=o(we),ee=(0,W.useMemo)(()=>new ma({api:g.getAiURL(`completion`).toString(),headers:()=>g.headers(),prepareSendMessagesRequest:async e=>{let t={...await os(e.messages),id:e.id,code:``,prompt:``,language:m};return{api:g.getAiURL(`completion`).toString(),body:t}}}),[m,g]),te=c(e=>{d(!1),Ye({title:`Generate with AI failed`,description:_t(e)})}),{sendMessage:ne,stop:w,status:T}=Fa({throttle:100,transport:ee,onData:p,onError:te,onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{d(!e&&!t&&!n&&r===`stop`)}}),E=T===`streaming`||T===`submitted`,D=f(),ie=c(()=>{v.cancel(),d(!1),w()}),ae=c(()=>{v.cancel(),u(),w()});(0,W.useEffect)(()=>()=>{ie()},[ie]);let oe=C?.models?.edit_model||`openai/gpt-4o`,se=Te.parse(oe).providerId,ce=$o.has(se),le=async()=>{E||await v.run({prepare:async()=>(_.current?.view&&Wa(_.current.view),b?await rs(b):void 0),submit:async e=>{l(),await ne({text:n,files:e})},onError:te})},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)(He,{className:`size-4 mr-2`}),`SQL`]}),fe=(0,G.jsxs)(Re,{modal:!1,children:[(0,G.jsxs)(Ie,{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)(wt,{className:`ml-1 h-3.5 w-3.5 text-muted-foreground/70`})]}),(0,G.jsxs)(Le,{align:`center`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1 text-sm text-muted-foreground`,children:`Select language`}),(0,G.jsx)(Fe,{}),(0,G.jsx)(Pe,{onClick:()=>h(`python`),children:ue}),(0,G.jsx)(Pe,{onClick:()=>h(`sql`),children:de})]})]}),O=()=>{s()&&e()},pe=()=>{ae(),_.current?.view?.focus()},me=()=>{ae(),e()},he=(0,G.jsxs)(`div`,{className:`flex items-center px-3`,children:[(0,G.jsx)(re,{className:`size-4 text-(--blue-11) mr-2`}),(0,G.jsx)(uc,{inputRef:_,onClose:me,value:n,onChange:e=>{a(e)},onSubmit:le,onKeyDown:tc({handleAcceptCompletion:O,handleDeclineCompletion:pe,isLoading:E,hasCompletion:D})}),(0,G.jsx)(Be,{variant:`text`,size:`sm`,className:`mb-0 px-1`,onClick:me,children:(0,G.jsx)(We,{className:`size-4`})})]}),ge=(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)(Ee,{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:[b.length>0&&(0,G.jsx)(`div`,{className:`flex flex-row gap-1 flex-wrap pr-1`,children:b?.map((e,t)=>(0,G.jsx)(gs,{file:e,onRemove:()=>S(e)},`${e.name}-${t}`))}),(0,G.jsx)(vs,{handleAddContext:()=>Qo(_),isLoading:E}),ce&&(0,G.jsx)(ys,{fileInputRef:y,isLoading:E,onAddFiles:x}),(0,G.jsx)(_s,{isLoading:E,onStop:ie,onSendClick:le,isEmpty:!n.trim(),showStopLabel:!0})]})]});return(0,G.jsxs)(`div`,{className:Me(`flex flex-col w-full py-2`),children:[he,ge]})},uc=e=>{let t=(0,j.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}=gt(),y;t[0]===p?y=t[1]:(y=e=>p?Zo([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=mt();t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=ft({}),t[9]=x):x=t[9],S=e,C=Qs({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=Ga({storage:{load:dc,save:fc}}),t[10]=te):te=t[10];let ne;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(ne=Dt(),t[11]=ne):ne=t[11];let w;t[12]===h?w=t[13]:(w=it.highest(Qe.of([{preventDefault:!0,stopPropagation:!0,any:(e,t)=>{let n=t.metaKey||t.ctrlKey||t.shiftKey;if(t.key===`Enter`&&!n)return h(t,e.state.doc.toString()),t.preventDefault(),t.stopPropagation(),!0;if(t.key===`Enter`&&t.shiftKey){let n=e.state.selection.main.from;return e.dispatch({changes:{from:n,to:n,insert:`
76
- `},selection:{anchor:n+1,head:n+1}}),t.preventDefault(),t.stopPropagation(),!0}return!1}}])),t[12]=h,t[13]=w);let T;t[14]===g?T=t[15]:(T=Qe.of([{key:`Escape`,preventDefault:!0,stopPropagation:!0,run:()=>(g(),!0)}]),t[14]=g,t[15]=T);let E;t[16]!==x||t[17]!==S||t[18]!==C||t[19]!==ee||t[20]!==w||t[21]!==T?(E=[x,S,C,ee,te,at.lineWrapping,ne,w,T],t[16]=x,t[17]=S,t[18]=C,t[19]=ee,t[20]=w,t[21]=T,t[22]=E):E=t[22];let re=E,D;t[23]===o?D=t[24]:(D=Me(`flex-1 font-sans overflow-auto my-1`,o),t[23]=o,t[24]=D);let ie=v===`dark`?`dark`:`light`,ae=r||`Generate with AI, @ to include context`,oe;return t[25]!==re||t[26]!==a||t[27]!==m||t[28]!==s||t[29]!==u||t[30]!==D||t[31]!==ie||t[32]!==ae||t[33]!==n?(oe=(0,G.jsx)(vt,{ref:a,className:D,width:`100%`,maxHeight:m,value:n,basicSetup:!1,extensions:re,onChange:s,onKeyDown:u,theme:ie,placeholder:ae}),t[25]=re,t[26]=a,t[27]=m,t[28]=s,t[29]=u,t[30]=D,t[31]=ie,t[32]=ae,t[33]=n,t[34]=oe):oe=t[34],oe};function dc(){return cc.get(sc)}function fc(e){return cc.set(sc,e)}export{Z as A,ma as B,ms as C,Jo as D,Go as E,Ya as F,Jr as G,Ji as H,Za as I,Wt as J,Kt as K,eo as L,ao as M,no as N,Bo as O,oo as P,Wa as R,ds as S,Ho as T,ua as U,ia as V,Xi as W,Ut as Y,ss as _,nc as a,is as b,vs as c,gs as d,_s as f,ns as g,rs as h,rc as i,to as j,Oo as k,ys as l,$o as m,uc as n,ic as o,xs as p,Gt as q,ec as r,tc as s,lc as t,hs as u,cs as v,Qo as w,ps as x,ls as y,Fa as z};
75
+ border-(--red-6) border hover:shadow-xs ${c!==void 0&&c&&`border-none rounded-md`} ${o}`,m=l??`Reject${d?` all`:``}`,h;t[0]===s?h=t[1]:(h=s&&(0,G.jsx)(bt,{className:`ml-1 inline`,shortcut:s}),t[0]=s,t[1]=h);let g;return t[2]!==u||t[3]!==n||t[4]!==f||t[5]!==p||t[6]!==m||t[7]!==h?(g=(0,G.jsxs)(Be,{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},ac=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}}},oc=Ae(`marimo:ai-language`,`python`,g),sc=`marimo:ai-prompt-history`,cc=new f(xe(O()),()=>[]),lc=({onClose:e})=>{let t=i(),[n,a]=(0,W.useState)(``),{acceptOwnedStagedCells:s,beginStagedCellGeneration:l,discardOwnedStagedCells:u,finishStagedCellGeneration:d,hasOwnedStagedCells:f,onData:p}=so(t),[m,h]=r(oc),g=je(),_=(0,W.useRef)(null),v=(0,W.useRef)(new ac).current,y=(0,W.useRef)(null),{files:b,addFiles:x,removeFile:S}=ds(),C=o(we),ee=(0,W.useMemo)(()=>new ma({api:g.getAiURL(`completion`).toString(),headers:()=>g.headers(),prepareSendMessagesRequest:async e=>{let t={...await os(e.messages),id:e.id,code:``,prompt:``,language:m};return{api:g.getAiURL(`completion`).toString(),body:t}}}),[m,g]),te=c(e=>{d(!1),Ye({title:`Generate with AI failed`,description:_t(e)})}),{sendMessage:ne,stop:w,status:T}=Fa({throttle:100,transport:ee,onData:p,onError:te,onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{d(!e&&!t&&!n&&r===`stop`)}}),E=T===`streaming`||T===`submitted`,D=f(),ie=c(()=>{v.cancel(),d(!1),w()}),ae=c(()=>{v.cancel(),u(),w()});(0,W.useEffect)(()=>()=>{ie()},[ie]);let oe=C?.models?.edit_model||`openai/gpt-4o`,se=Te.parse(oe).providerId,ce=$o.has(se),le=async()=>{E||await v.run({prepare:async()=>(_.current?.view&&Wa(_.current.view),b?await rs(b):void 0),submit:async e=>{l(),await ne({text:n,files:e})},onError:te})},ue=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Mt,{className:`size-4 mr-2`}),`Python`]}),de=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(He,{className:`size-4 mr-2`}),`SQL`]}),fe=(0,G.jsxs)(Re,{modal:!1,children:[(0,G.jsxs)(Ie,{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)(Ct,{className:`ml-1 h-3.5 w-3.5 text-muted-foreground/70`})]}),(0,G.jsxs)(Le,{align:`center`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1 text-sm text-muted-foreground`,children:`Select language`}),(0,G.jsx)(Fe,{}),(0,G.jsx)(Pe,{onClick:()=>h(`python`),children:ue}),(0,G.jsx)(Pe,{onClick:()=>h(`sql`),children:de})]})]}),O=()=>{s()&&e()},pe=()=>{ae(),_.current?.view?.focus()},me=()=>{ae(),e()},he=(0,G.jsxs)(`div`,{className:`flex items-center px-3`,children:[(0,G.jsx)(re,{className:`size-4 text-(--blue-11) mr-2`}),(0,G.jsx)(uc,{inputRef:_,onClose:me,value:n,onChange:e=>{a(e)},onSubmit:le,onKeyDown:tc({handleAcceptCompletion:O,handleDeclineCompletion:pe,isLoading:E,hasCompletion:D})}),(0,G.jsx)(Be,{variant:`text`,size:`sm`,className:`mb-0 px-1`,onClick:me,children:(0,G.jsx)(We,{className:`size-4`})})]}),ge=(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)(Ee,{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:[b.length>0&&(0,G.jsx)(`div`,{className:`flex flex-row gap-1 flex-wrap pr-1`,children:b?.map((e,t)=>(0,G.jsx)(gs,{file:e,onRemove:()=>S(e)},`${e.name}-${t}`))}),(0,G.jsx)(vs,{handleAddContext:()=>Qo(_),isLoading:E}),ce&&(0,G.jsx)(ys,{fileInputRef:y,isLoading:E,onAddFiles:x}),(0,G.jsx)(_s,{isLoading:E,onStop:ie,onSendClick:le,isEmpty:!n.trim(),showStopLabel:!0})]})]});return(0,G.jsxs)(`div`,{className:Me(`flex flex-col w-full py-2`),children:[he,ge]})},uc=e=>{let t=(0,j.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}=gt(),y;t[0]===p?y=t[1]:(y=e=>p?Zo([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=mt();t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=ft({}),t[9]=x):x=t[9],S=e,C=Qs({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=Ga({storage:{load:dc,save:fc}}),t[10]=te):te=t[10];let ne;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(ne=It(),t[11]=ne):ne=t[11];let w;t[12]===h?w=t[13]:(w=it.highest(Qe.of([{preventDefault:!0,stopPropagation:!0,any:(e,t)=>{let n=t.metaKey||t.ctrlKey||t.shiftKey;if(t.key===`Enter`&&!n)return h(t,e.state.doc.toString()),t.preventDefault(),t.stopPropagation(),!0;if(t.key===`Enter`&&t.shiftKey){let n=e.state.selection.main.from;return e.dispatch({changes:{from:n,to:n,insert:`
76
+ `},selection:{anchor:n+1,head:n+1}}),t.preventDefault(),t.stopPropagation(),!0}return!1}}])),t[12]=h,t[13]=w);let T;t[14]===g?T=t[15]:(T=Qe.of([{key:`Escape`,preventDefault:!0,stopPropagation:!0,run:()=>(g(),!0)}]),t[14]=g,t[15]=T);let E;t[16]!==x||t[17]!==S||t[18]!==C||t[19]!==ee||t[20]!==w||t[21]!==T?(E=[x,S,C,ee,te,at.lineWrapping,ne,w,T],t[16]=x,t[17]=S,t[18]=C,t[19]=ee,t[20]=w,t[21]=T,t[22]=E):E=t[22];let re=E,D;t[23]===o?D=t[24]:(D=Me(`flex-1 font-sans overflow-auto my-1`,o),t[23]=o,t[24]=D);let ie=v===`dark`?`dark`:`light`,ae=r||`Generate with AI, @ to include context`,oe;return t[25]!==re||t[26]!==a||t[27]!==m||t[28]!==s||t[29]!==u||t[30]!==D||t[31]!==ie||t[32]!==ae||t[33]!==n?(oe=(0,G.jsx)(Tt,{ref:a,className:D,width:`100%`,maxHeight:m,value:n,basicSetup:!1,extensions:re,onChange:s,onKeyDown:u,theme:ie,placeholder:ae}),t[25]=re,t[26]=a,t[27]=m,t[28]=s,t[29]=u,t[30]=D,t[31]=ie,t[32]=ae,t[33]=n,t[34]=oe):oe=t[34],oe};function dc(){return cc.get(sc)}function fc(e){return cc.set(sc,e)}export{Z as A,ma as B,ms as C,Jo as D,Go as E,Ya as F,Jr as G,Ji as H,Za as I,Wt as J,Kt as K,eo as L,ao as M,no as N,Bo as O,oo as P,Wa as R,ds as S,Ho as T,ua as U,ia as V,Xi as W,Ut as Y,ss as _,nc as a,is as b,vs as c,gs as d,_s as f,ns as g,rs as h,rc as i,to as j,Oo as k,ys as l,$o as m,uc as n,ic as o,xs as p,Gt as q,ec as r,tc as s,lc as t,hs as u,cs as v,Qo as w,ps as x,ls as y,Fa as z};