@marimo-team/frontend 0.23.11-dev1 → 0.23.11-dev10

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 (84) hide show
  1. package/dist/assets/{CellStatus-e0ex7Iei.js → CellStatus-CLGvVxcw.js} +1 -1
  2. package/dist/assets/{JsonOutput-DRNPZOvX.js → JsonOutput-uEJijGXp.js} +5 -5
  3. package/dist/assets/{MarimoErrorOutput-BH6hs0Ir.js → MarimoErrorOutput-DzoKyXWR.js} +2 -2
  4. package/dist/assets/{RenderHTML-BQ1PO4Wd.js → RenderHTML-DAt48X-F.js} +1 -1
  5. package/dist/assets/{RunButton-F8pLIvFp.js → RunButton-B7msyyYi.js} +1 -1
  6. package/dist/assets/{add-cell-with-ai-C2OtCghK.js → add-cell-with-ai-CAkcousR.js} +8 -8
  7. package/dist/assets/{add-connection-dialog-AhwxOztN.js → add-connection-dialog-ZyXXfAVG.js} +32 -32
  8. package/dist/assets/{agent-panel-D6ryE8xb.js → agent-panel-BfIguQXh.js} +3 -3
  9. package/dist/assets/{ai-model-dropdown-CG4B4rqH.js → ai-model-dropdown-rE64ytSX.js} +3 -3
  10. package/dist/assets/{app-config-button-D_sFrSql.js → app-config-button-DLRZ5d9c.js} +1 -1
  11. package/dist/assets/{cell-editor-XNa3wJ3P.js → cell-editor-2JIpvFn4.js} +5 -5
  12. package/dist/assets/{cell-link-Bj4-yOIx.js → cell-link-DY95GSb7.js} +1 -1
  13. package/dist/assets/{cells-DOA0Gew8.js → cells-D-v2lBet.js} +67 -67
  14. package/dist/assets/{chat-display-CezkHLLR.js → chat-display-DO-tqsbY.js} +1 -1
  15. package/dist/assets/{chat-panel-DEBTPtwE.js → chat-panel-BT5gLfs6.js} +1 -1
  16. package/dist/assets/{chat-ui-CIr1o1hq.js → chat-ui-Be4yDBZS.js} +1 -1
  17. package/dist/assets/column-preview-BzvFdLI5.js +1 -0
  18. package/dist/assets/{command-palette-_VEEjmkI.js → command-palette-CKKzfpGt.js} +1 -1
  19. package/dist/assets/{common-fDFYY_sv.js → common-Do4N1uVK.js} +1 -1
  20. package/dist/assets/{components--C6N-DXq.js → components-DUC0f1XD.js} +1 -1
  21. package/dist/assets/{datasource-CR6RRpTi.js → datasource-BQGI7c_u.js} +2 -2
  22. package/dist/assets/{dependency-graph-panel-BEgkvdX0.js → dependency-graph-panel-Czoya7c2.js} +1 -1
  23. package/dist/assets/{documentation-panel-HvbKykbI.js → documentation-panel-LokVYDIZ.js} +1 -1
  24. package/dist/assets/{download-DhxnAw14.js → download-WGU5w_3m.js} +3 -3
  25. package/dist/assets/{edit-page-D-02q6iz.js → edit-page-BPQO1Uuz.js} +6 -6
  26. package/dist/assets/{error-panel-WLBQ3q9p.js → error-panel-BCm_e4eM.js} +1 -1
  27. package/dist/assets/{file-explorer-panel-DtzGlnzT.js → file-explorer-panel-D1NN-z8x.js} +3 -3
  28. package/dist/assets/{file-icons-D2f3nfbq.js → file-icons-CF-YT4hq.js} +1 -1
  29. package/dist/assets/{file-name-input-BNYf9WWM.js → file-name-input-BRVXQ3OU.js} +1 -1
  30. package/dist/assets/{floating-outline-BvHFWRoz.js → floating-outline-D33Zu-Ad.js} +1 -1
  31. package/dist/assets/{focus-Ldqh99xE.js → focus-BfFAxl9X.js} +1 -1
  32. package/dist/assets/{form-CxBAInfg.js → form-CVBFx2z3.js} +1 -1
  33. package/dist/assets/{home-page-DwFpLpXK.js → home-page-CL9Hv1Hg.js} +2 -2
  34. package/dist/assets/{hooks-5gNQitDd.js → hooks-83y0XCiC.js} +1 -1
  35. package/dist/assets/{html-to-image-CyAtzePO.js → html-to-image-IPNqWX7V.js} +2 -2
  36. package/dist/assets/index-BNWrEIlp.css +2 -0
  37. package/dist/assets/{index-CGCBsDqs.js → index-CuhY66ZR.js} +14 -14
  38. package/dist/assets/{kiosk-mode-CTWHjzXs.js → kiosk-mode-BSufcIZH.js} +1 -1
  39. package/dist/assets/{layout-D3pd3R21.js → layout-ks0WJ2vR.js} +5 -5
  40. package/dist/assets/{logs-panel-BVLYycQb.js → logs-panel-DXN6sUaA.js} +1 -1
  41. package/dist/assets/{markdown-renderer-C9Ujvj0b.js → markdown-renderer-DWRPo52L.js} +1 -1
  42. package/dist/assets/{name-cell-input-DabvuruX.js → name-cell-input-BiDIx6YQ.js} +1 -1
  43. package/dist/assets/{outline-panel-B-ncbNWI.js → outline-panel-DVSGNRgP.js} +1 -1
  44. package/dist/assets/{packages-panel-CESeW_3T.js → packages-panel-DTX6CBnm.js} +1 -1
  45. package/dist/assets/{panels-CTy3hq0L.js → panels-NhGV0SBq.js} +1 -1
  46. package/dist/assets/{process-output-pPgH0ANl.js → process-output-BiWV34b7.js} +1 -1
  47. package/dist/assets/{radio-group-D7rh6Zek.js → radio-group-DV-lQvil.js} +1 -1
  48. package/dist/assets/{readonly-python-code-CvPx4CU_.js → readonly-python-code-B0glFTKW.js} +1 -1
  49. package/dist/assets/{reveal-component-lTtEZQh1.js → reveal-component-C2M2FixA.js} +12 -12
  50. package/dist/assets/{run-page-BB6ghGfO.js → run-page-B6I-Lshx.js} +1 -1
  51. package/dist/assets/{scratchpad-panel-Bvb8RxUv.js → scratchpad-panel-DU7perVk.js} +1 -1
  52. package/dist/assets/session-panel-B4UTmf-j.js +1 -0
  53. package/dist/assets/{snippets-panel-BSgcoo-M.js → snippets-panel-KRdl4bVk.js} +1 -1
  54. package/dist/assets/{state-BWM3qRkR.js → state-BSm0OM93.js} +1 -1
  55. package/dist/assets/{state-C8yHPSLN.js → state-CbkvENzk.js} +2 -2
  56. package/dist/assets/{textarea-bBuxbFm7.js → textarea-CBbixTxi.js} +1 -1
  57. package/dist/assets/{tracing-pt7eDHWc.js → tracing-D8LGpuXa.js} +1 -1
  58. package/dist/assets/{tracing-panel-BveZ5DZw.js → tracing-panel-TUP6kAd5.js} +2 -2
  59. package/dist/assets/{tree-actions-1KQDSu1H.js → tree-actions-BvrKFU0g.js} +1 -1
  60. package/dist/assets/{useCellActionButton-C4V7J6PS.js → useCellActionButton-CtOZIXD0.js} +1 -1
  61. package/dist/assets/{useDeleteCell-BvnurAZ9.js → useDeleteCell-BLvzLWAT.js} +1 -1
  62. package/dist/assets/{useDependencyPanelTab-DNlXaxbt.js → useDependencyPanelTab-BP0sNfUz.js} +1 -1
  63. package/dist/assets/{useNotebookActions-BIQkawja.js → useNotebookActions-BI5dWutQ.js} +1 -1
  64. package/dist/assets/{useRunCells-cSZpNqnR.js → useRunCells-BClkx9Pq.js} +1 -1
  65. package/dist/assets/{useSplitCell-s7dSiBUa.js → useSplitCell-CpddCX_u.js} +1 -1
  66. package/dist/index.html +23 -23
  67. package/package.json +1 -1
  68. package/src/components/datasources/__tests__/column-preview.test.tsx +97 -0
  69. package/src/components/datasources/__tests__/filter-empty.test.ts +81 -0
  70. package/src/components/datasources/__tests__/utils.test.ts +62 -1
  71. package/src/components/datasources/column-preview.tsx +2 -4
  72. package/src/components/datasources/components.tsx +15 -7
  73. package/src/components/datasources/datasources.tsx +311 -178
  74. package/src/components/datasources/utils.ts +40 -1
  75. package/src/components/editor/connections/components.tsx +13 -0
  76. package/src/components/editor/connections/storage/__tests__/__snapshots__/as-code.test.ts.snap +4 -4
  77. package/src/components/editor/connections/storage/as-code.ts +11 -4
  78. package/src/core/cells/__tests__/cells.test.ts +33 -0
  79. package/src/core/cells/cells.ts +1 -1
  80. package/src/core/datasets/__tests__/data-source.test.ts +226 -0
  81. package/src/core/datasets/data-source-connections.ts +88 -24
  82. package/dist/assets/column-preview-nu3Qo2OW.js +0 -1
  83. package/dist/assets/index-BAYF7dcV.css +0 -2
  84. package/dist/assets/session-panel-CTJPYbAa.js +0 -1
@@ -1,4 +1,4 @@
1
- var Oi=Object.defineProperty;var Ri=(t,e,a)=>e in t?Oi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a;var D=(t,e,a)=>Ri(t,typeof e!="symbol"?e+"":e,a);import{s as Ba,t as Ni}from"./chunk-LvLJmgfZ.js";import{f as rs,i as ss,l as Mi,n as ns,o as ji,u as is}from"./useEvent-D91BmmQi.js";import{t as Pi}from"./react-Bj1aDYRI.js";import{Ar as $i,Ct as Ja,D as os,Di as Li,Fi as ls,Ii as Di,In as Zi,Lt as Fi,Mr as zi,Nr as ds,Xt as us,b as Xe,br as Ui,f as qi,i as Vi,ii as Wi,ki as Bi,nn as Ji,nr as Ki,ti as Yi,vr as Hi,xi as Gi,zn as Qi}from"./cells-DOA0Gew8.js";import{B as fe,D as Xi,E as cs,H as eo,I as pt,J as ps,L as X,M as V,N as ms,O as to,P as A,R as h,S as ao,T as U,V as H,W as hs,b as mt,k as w,w as Se,x as fa}from"./zod-H_cgTO0M.js";import{t as Wt}from"./compiler-runtime-B3qBwwSJ.js";import{T as ro,t as so}from"./ai-model-dropdown-CG4B4rqH.js";import{_ as le,p as no}from"./useEventListener-DvoEXWke.js";import{n as io}from"./utils-CvI-39U6.js";import{o as oo}from"./config-ClMcu_sV.js";import{t as Ka}from"./cn-DCUzRj2J.js";import{t as lo}from"./jsx-runtime-BqBOg78p.js";import{d as uo}from"./popover-CNCYAwbC.js";import{a as fs,c as co,p as po,r as mo,t as ho}from"./dropdown-menu-CZ4XbE-c.js";import{t as ga}from"./tooltip-B_PkSKN3.js";import{t as et}from"./button-BbCh-29a.js";import{$t as fo,Ct as go,Kt as gs,Ut as yo,Wt as vo,Xt as ya,Zt as va,at as Ya,dt as ys,st as vs,ut as xo,wt as xa}from"./dist-D0HyMpgV.js";import{t as bo}from"./createReducer-CI9qeK_X.js";import{h as _o,n as wo,o as ko,r as Co}from"./dist-Bo13cFwO.js";import{i as xs}from"./strings-wdPMRf6Z.js";import{r as Io,t as Eo}from"./requests-DIwGYs0l.js";import{t as Ha}from"./createLucideIcon-D5guW7EU.js";import{r as To,t as So}from"./fileToBase64-D15LPv1Y.js";import{t as bs}from"./x-C-6liIBr.js";import{f as Ao,l as _s,n as Oo}from"./markdown-renderer-C9Ujvj0b.js";import{t as ws}from"./file-BrdxGLRX.js";import{t as Ro}from"./image-DQHXdEQn.js";import{t as No}from"./spinner-Bhir8k53.js";import{i as Mo,t as jo}from"./useDeleteCell-BvnurAZ9.js";import{r as Po}from"./input-DA8xlX70.js";import{t as $o}from"./sparkles-lWUAsPhp.js";import{a as Bt,i as jt,o as Jt,r as Pt,s as Lo,t as Do}from"./datasource-CR6RRpTi.js";import{a as Zo}from"./dist-HyCgERnW.js";import{t as Ga}from"./use-toast-CJ1Tj2eC.js";import{a as Fo}from"./session-0B5NBztP.js";import{r as zo}from"./useTheme-CI2eq4XN.js";import{n as Uo}from"./useRunCells-cSZpNqnR.js";import{t as qo}from"./blob-Bgnx1kuY.js";import{i as Vo}from"./errors-D3F5g1xA.js";import{i as Qa}from"./cell-link-Bj4-yOIx.js";import{r as Wo,t as Bo}from"./html-to-image-CyAtzePO.js";import{n as Xa}from"./renderShortcut--ku7VECI.js";import{n as Jo}from"./icons-Ol38nIbL.js";import{r as Ko,t as Yo}from"./esm-xaw4Vy8N.js";import{t as Ho}from"./process-output-pPgH0ANl.js";var ks=Ha("circle-stop",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]]),Cs=Ha("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"}]]),Is=Ha("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"}]]),Es="vercel.ai.error",Go=Symbol.for(Es),Ts,Ss,ke=class _i extends(Ss=Error,Ts=Go,Ss){constructor({name:e,message:a,cause:r}){super(a),this[Ts]=!0,this.name=e,this.cause=r}static isInstance(e){return _i.hasMarker(e,Es)}static hasMarker(e,a){let r=Symbol.for(a);return typeof e=="object"&&!!e&&r in e&&typeof e[r]=="boolean"&&e[r]===!0}};function As(t){return t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t)}var Os="AI_InvalidArgumentError",Rs=`vercel.ai.error.${Os}`,Qo=Symbol.for(Rs),Ns,Ms,Xo=class extends(Ms=ke,Ns=Qo,Ms){constructor({message:t,cause:e,argument:a}){super({name:Os,message:t,cause:e}),this[Ns]=!0,this.argument=a}static isInstance(t){return ke.hasMarker(t,Rs)}},js="AI_JSONParseError",Ps=`vercel.ai.error.${js}`,el=Symbol.for(Ps),$s,Ls,Ds=class extends(Ls=ke,$s=el,Ls){constructor({text:t,cause:e}){super({name:js,message:`JSON parsing failed: Text: ${t}.
1
+ var Oi=Object.defineProperty;var Ri=(t,e,a)=>e in t?Oi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a;var D=(t,e,a)=>Ri(t,typeof e!="symbol"?e+"":e,a);import{s as Ba,t as Ni}from"./chunk-LvLJmgfZ.js";import{f as rs,i as ss,l as Mi,n as ns,o as ji,u as is}from"./useEvent-D91BmmQi.js";import{t as Pi}from"./react-Bj1aDYRI.js";import{Ar as $i,Bi as Li,Ct as Ja,D as os,In as Di,Lt as Zi,Mr as Fi,Ni as zi,Nr as ls,Ti as Ui,Xt as ds,ai as qi,b as Xe,br as Vi,ci as Wi,f as Bi,i as Ji,ji as Ki,nn as Yi,nr as Hi,vr as Gi,zi as us,zn as Qi}from"./cells-D-v2lBet.js";import{B as fe,D as Xi,E as cs,H as eo,I as pt,J as ps,L as X,M as V,N as ms,O as to,P as A,R as h,S as ao,T as U,V as H,W as hs,b as mt,k as w,w as Se,x as fa}from"./zod-H_cgTO0M.js";import{t as Wt}from"./compiler-runtime-B3qBwwSJ.js";import{T as ro,t as so}from"./ai-model-dropdown-rE64ytSX.js";import{_ as le,p as no}from"./useEventListener-DvoEXWke.js";import{n as io}from"./utils-CvI-39U6.js";import{o as oo}from"./config-ClMcu_sV.js";import{t as Ka}from"./cn-DCUzRj2J.js";import{t as lo}from"./jsx-runtime-BqBOg78p.js";import{d as uo}from"./popover-CNCYAwbC.js";import{a as fs,c as co,p as po,r as mo,t as ho}from"./dropdown-menu-CZ4XbE-c.js";import{t as ga}from"./tooltip-B_PkSKN3.js";import{t as et}from"./button-BbCh-29a.js";import{$t as fo,Ct as go,Kt as gs,Ut as yo,Wt as vo,Xt as ya,Zt as va,at as Ya,dt as ys,st as vs,ut as xo,wt as xa}from"./dist-D0HyMpgV.js";import{t as bo}from"./createReducer-CI9qeK_X.js";import{h as _o,n as wo,o as ko,r as Co}from"./dist-Bo13cFwO.js";import{i as xs}from"./strings-wdPMRf6Z.js";import{r as Io,t as Eo}from"./requests-DIwGYs0l.js";import{t as Ha}from"./createLucideIcon-D5guW7EU.js";import{r as To,t as So}from"./fileToBase64-D15LPv1Y.js";import{t as bs}from"./x-C-6liIBr.js";import{f as Ao,l as _s,n as Oo}from"./markdown-renderer-DWRPo52L.js";import{t as ws}from"./file-BrdxGLRX.js";import{t as Ro}from"./image-DQHXdEQn.js";import{t as No}from"./spinner-Bhir8k53.js";import{i as Mo,t as jo}from"./useDeleteCell-BLvzLWAT.js";import{r as Po}from"./input-DA8xlX70.js";import{t as $o}from"./sparkles-lWUAsPhp.js";import{a as Bt,i as jt,o as Jt,r as Pt,s as Lo,t as Do}from"./datasource-BQGI7c_u.js";import{a as Zo}from"./dist-HyCgERnW.js";import{t as Ga}from"./use-toast-CJ1Tj2eC.js";import{a as Fo}from"./session-0B5NBztP.js";import{r as zo}from"./useTheme-CI2eq4XN.js";import{n as Uo}from"./useRunCells-BClkx9Pq.js";import{t as qo}from"./blob-Bgnx1kuY.js";import{i as Vo}from"./errors-D3F5g1xA.js";import{i as Qa}from"./cell-link-DY95GSb7.js";import{r as Wo,t as Bo}from"./html-to-image-IPNqWX7V.js";import{n as Xa}from"./renderShortcut--ku7VECI.js";import{n as Jo}from"./icons-Ol38nIbL.js";import{r as Ko,t as Yo}from"./esm-xaw4Vy8N.js";import{t as Ho}from"./process-output-BiWV34b7.js";var ks=Ha("circle-stop",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]]),Cs=Ha("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"}]]),Is=Ha("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"}]]),Es="vercel.ai.error",Go=Symbol.for(Es),Ts,Ss,ke=class _i extends(Ss=Error,Ts=Go,Ss){constructor({name:e,message:a,cause:r}){super(a),this[Ts]=!0,this.name=e,this.cause=r}static isInstance(e){return _i.hasMarker(e,Es)}static hasMarker(e,a){let r=Symbol.for(a);return typeof e=="object"&&!!e&&r in e&&typeof e[r]=="boolean"&&e[r]===!0}};function As(t){return t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t)}var Os="AI_InvalidArgumentError",Rs=`vercel.ai.error.${Os}`,Qo=Symbol.for(Rs),Ns,Ms,Xo=class extends(Ms=ke,Ns=Qo,Ms){constructor({message:t,cause:e,argument:a}){super({name:Os,message:t,cause:e}),this[Ns]=!0,this.argument=a}static isInstance(t){return ke.hasMarker(t,Rs)}},js="AI_JSONParseError",Ps=`vercel.ai.error.${js}`,el=Symbol.for(Ps),$s,Ls,Ds=class extends(Ls=ke,$s=el,Ls){constructor({text:t,cause:e}){super({name:js,message:`JSON parsing failed: Text: ${t}.
2
2
  Error message: ${As(e)}`,cause:e}),this[$s]=!0,this.text=t}static isInstance(t){return ke.hasMarker(t,Ps)}},Zs="AI_TypeValidationError",Fs=`vercel.ai.error.${Zs}`,tl=Symbol.for(Fs),zs,Us,tt=class Hr extends(Us=ke,zs=tl,Us){constructor({value:e,cause:a,context:r}){let s="Type validation failed";if(r!=null&&r.field&&(s+=` for ${r.field}`),(r==null?void 0:r.entityName)||(r==null?void 0:r.entityId)){s+=" (";let n=[];r.entityName&&n.push(r.entityName),r.entityId&&n.push(`id: "${r.entityId}"`),s+=n.join(", "),s+=")"}super({name:Zs,message:`${s}: Value: ${JSON.stringify(e)}.
3
3
  Error message: ${As(a)}`,cause:a}),this[zs]=!0,this.value=e,this.context=r}static isInstance(e){return ke.hasMarker(e,Fs)}static wrap({value:e,cause:a,context:r}){var s,n,o;return Hr.isInstance(a)&&a.value===e&&((s=a.context)==null?void 0:s.field)===(r==null?void 0:r.field)&&((n=a.context)==null?void 0:n.entityName)===(r==null?void 0:r.entityName)&&((o=a.context)==null?void 0:o.entityId)===(r==null?void 0:r.entityId)?a:new Hr({value:e,cause:a,context:r})}},W;(function(t){t.assertEqual=s=>{};function e(s){}t.assertIs=e;function a(s){throw Error()}t.assertNever=a,t.arrayToEnum=s=>{let n={};for(let o of s)n[o]=o;return n},t.getValidEnumValues=s=>{let n=t.objectKeys(s).filter(i=>typeof s[s[i]]!="number"),o={};for(let i of n)o[i]=s[i];return t.objectValues(o)},t.objectValues=s=>t.objectKeys(s).map(function(n){return s[n]}),t.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{let n=[];for(let o in s)Object.prototype.hasOwnProperty.call(s,o)&&n.push(o);return n},t.find=(s,n)=>{for(let o of s)if(n(o))return o},t.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,n=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(n)}t.joinValues=r,t.jsonStringifyReplacer=(s,n)=>typeof n=="bigint"?n.toString():n})(W||(W={}));var al;(function(t){t.mergeShapes=(e,a)=>({...e,...a})})(al||(al={}));const S=W.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),at=t=>{switch(typeof t){case"undefined":return S.undefined;case"string":return S.string;case"number":return Number.isNaN(t)?S.nan:S.number;case"boolean":return S.boolean;case"function":return S.function;case"bigint":return S.bigint;case"symbol":return S.symbol;case"object":return Array.isArray(t)?S.array:t===null?S.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?S.promise:typeof Map<"u"&&t instanceof Map?S.map:typeof Set<"u"&&t instanceof Set?S.set:typeof Date<"u"&&t instanceof Date?S.date:S.object;default:return S.unknown}},x=W.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);var Le=class wi extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};let a=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,a):this.__proto__=a,this.name="ZodError",this.issues=e}format(e){let a=e||function(n){return n.message},r={_errors:[]},s=n=>{for(let o of n.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)r._errors.push(a(o));else{let i=r,l=0;for(;l<o.path.length;){let d=o.path[l];l===o.path.length-1?(i[d]=i[d]||{_errors:[]},i[d]._errors.push(a(o))):i[d]=i[d]||{_errors:[]},i=i[d],l++}}};return s(this),r}static assert(e){if(!(e instanceof wi))throw Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,W.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=a=>a.message){let a=Object.create(null),r=[];for(let s of this.issues)if(s.path.length>0){let n=s.path[0];a[n]=a[n]||[],a[n].push(e(s))}else r.push(e(s));return{formErrors:r,fieldErrors:a}}get formErrors(){return this.flatten()}};Le.create=t=>new Le(t);var Kt=(t,e)=>{let a;switch(t.code){case x.invalid_type:a=t.received===S.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case x.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(t.expected,W.jsonStringifyReplacer)}`;break;case x.unrecognized_keys:a=`Unrecognized key(s) in object: ${W.joinValues(t.keys,", ")}`;break;case x.invalid_union:a="Invalid input";break;case x.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${W.joinValues(t.options)}`;break;case x.invalid_enum_value:a=`Invalid enum value. Expected ${W.joinValues(t.options)}, received '${t.received}'`;break;case x.invalid_arguments:a="Invalid function arguments";break;case x.invalid_return_type:a="Invalid function return type";break;case x.invalid_date:a="Invalid date";break;case x.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(a=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(a=`${a} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?a=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?a=`Invalid input: must end with "${t.validation.endsWith}"`:W.assertNever(t.validation):a=t.validation==="regex"?"Invalid":`Invalid ${t.validation}`;break;case x.too_small:a=t.type==="array"?`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"||t.type==="bigint"?`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:"Invalid input";break;case x.too_big:a=t.type==="array"?`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:"Invalid input";break;case x.custom:a="Invalid input";break;case x.invalid_intersection_types:a="Intersection results could not be merged";break;case x.not_multiple_of:a=`Number must be a multiple of ${t.multipleOf}`;break;case x.not_finite:a="Number must be finite";break;default:a=e.defaultError,W.assertNever(t)}return{message:a}},rl=Kt;function er(){return rl}const tr=t=>{let{data:e,path:a,errorMaps:r,issueData:s}=t,n=[...a,...s.path||[]],o={...s,path:n};if(s.message!==void 0)return{...s,path:n,message:s.message};let i="",l=r.filter(d=>!!d).slice().reverse();for(let d of l)i=d(o,{data:e,defaultError:i}).message;return{...s,path:n,message:i}};function I(t,e){let a=er(),r=tr({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,a,a===Kt?void 0:Kt].filter(s=>!!s)});t.common.issues.push(r)}var xe=class ki{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,a){let r=[];for(let s of a){if(s.status==="aborted")return j;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,a){let r=[];for(let s of a){let n=await s.key,o=await s.value;r.push({key:n,value:o})}return ki.mergeObjectSync(e,r)}static mergeObjectSync(e,a){let r={};for(let s of a){let{key:n,value:o}=s;if(n.status==="aborted"||o.status==="aborted")return j;n.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),n.value!=="__proto__"&&(o.value!==void 0||s.alwaysSet)&&(r[n.value]=o.value)}return{status:e.value,value:r}}};const j=Object.freeze({status:"aborted"}),ar=t=>({status:"dirty",value:t}),ve=t=>({status:"valid",value:t}),qs=t=>t.status==="aborted",Vs=t=>t.status==="dirty",$t=t=>t.status==="valid",ba=t=>typeof Promise<"u"&&t instanceof Promise;var R;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(R||(R={}));var De=class{constructor(t,e,a,r){this._cachedPath=[],this.parent=t,this.data=e,this._path=a,this._key=r}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},Ws=(t,e)=>{if($t(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){return this._error||(this._error=new Le(t.common.issues)),this._error}}};function L(t){if(!t)return{};let{errorMap:e,invalid_type_error:a,required_error:r,description:s}=t;if(e&&(a||r))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(n,o)=>{let{message:i}=t;return n.code==="invalid_enum_value"?{message:i??o.defaultError}:o.data===void 0?{message:i??r??o.defaultError}:n.code==="invalid_type"?{message:i??a??o.defaultError}:{message:o.defaultError}},description:s}}var F=class{get description(){return this._def.description}_getType(t){return at(t.data)}_getOrReturnCtx(t,e){return e||{common:t.parent.common,data:t.data,parsedType:at(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new xe,ctx:{common:t.parent.common,data:t.data,parsedType:at(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){let e=this._parse(t);if(ba(e))throw Error("Synchronous parse encountered promise.");return e}_parseAsync(t){let e=this._parse(t);return Promise.resolve(e)}parse(t,e){let a=this.safeParse(t,e);if(a.success)return a.data;throw a.error}safeParse(t,e){let a={common:{issues:[],async:(e==null?void 0:e.async)??!1,contextualErrorMap:e==null?void 0:e.errorMap},path:(e==null?void 0:e.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:at(t)};return Ws(a,this._parseSync({data:t,path:a.path,parent:a}))}"~validate"(t){var a,r;let e={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:at(t)};if(!this["~standard"].async)try{let s=this._parseSync({data:t,path:[],parent:e});return $t(s)?{value:s.value}:{issues:e.common.issues}}catch(s){(r=(a=s==null?void 0:s.message)==null?void 0:a.toLowerCase())!=null&&r.includes("encountered")&&(this["~standard"].async=!0),e.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:e}).then(s=>$t(s)?{value:s.value}:{issues:e.common.issues})}async parseAsync(t,e){let a=await this.safeParseAsync(t,e);if(a.success)return a.data;throw a.error}async safeParseAsync(t,e){let a={common:{issues:[],contextualErrorMap:e==null?void 0:e.errorMap,async:!0},path:(e==null?void 0:e.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:at(t)},r=this._parse({data:t,path:a.path,parent:a});return Ws(a,await(ba(r)?r:Promise.resolve(r)))}refine(t,e){let a=r=>typeof e=="string"||e===void 0?{message:e}:typeof e=="function"?e(r):e;return this._refinement((r,s)=>{let n=t(r),o=()=>s.addIssue({code:x.custom,...a(r)});return typeof Promise<"u"&&n instanceof Promise?n.then(i=>i?!0:(o(),!1)):n?!0:(o(),!1)})}refinement(t,e){return this._refinement((a,r)=>t(a)?!0:(r.addIssue(typeof e=="function"?e(a,r):e),!1))}_refinement(t){return new Ve({schema:this,typeName:_.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return We.create(this,this._def)}nullable(){return ft.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Dt.create(this)}promise(){return Yt.create(this,this._def)}or(t){return Ca.create([this,t],this._def)}and(t){return Ia.create(this,t,this._def)}transform(t){return new Ve({...L(this._def),schema:this,typeName:_.ZodEffects,effect:{type:"transform",transform:t}})}default(t){let e=typeof t=="function"?t:()=>t;return new Oa({...L(this._def),innerType:this,defaultValue:e,typeName:_.ZodDefault})}brand(){return new Hs({typeName:_.ZodBranded,type:this,...L(this._def)})}catch(t){let e=typeof t=="function"?t:()=>t;return new Ra({...L(this._def),innerType:this,catchValue:e,typeName:_.ZodCatch})}describe(t){let e=this.constructor;return new e({...this._def,description:t})}pipe(t){return Gs.create(this,t)}readonly(){return Na.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},sl=/^c[^\s-]{8,}$/i,nl=/^[0-9a-z]+$/,il=/^[0-9A-HJKMNP-TV-Z]{26}$/i,ol=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,ll=/^[a-z0-9_-]{21}$/i,dl=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ul=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,cl=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,pl="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Bs,ml=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,hl=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,fl=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,gl=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,yl=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,vl=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Js="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",xl=RegExp(`^${Js}$`);function Ks(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision??(e=`${e}(\\.\\d+)?`);let a=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${a}`}function bl(t){return RegExp(`^${Ks(t)}$`)}function _l(t){let e=`${Js}T${Ks(t)}`,a=[];return a.push(t.local?"Z?":"Z"),t.offset&&a.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${a.join("|")})`,RegExp(`^${e}$`)}function wl(t,e){return!!((e==="v4"||!e)&&ml.test(t)||(e==="v6"||!e)&&fl.test(t))}function kl(t,e){if(!dl.test(t))return!1;try{let[a]=t.split(".");if(!a)return!1;let r=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||!s||"typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function Cl(t,e){return!!((e==="v4"||!e)&&hl.test(t)||(e==="v6"||!e)&&gl.test(t))}var _a=class oa extends F{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==S.string){let s=this._getOrReturnCtx(e);return I(s,{code:x.invalid_type,expected:S.string,received:s.parsedType}),j}let a=new xe,r;for(let s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(r=this._getOrReturnCtx(e,r),I(r,{code:x.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),a.dirty());else if(s.kind==="max")e.data.length>s.value&&(r=this._getOrReturnCtx(e,r),I(r,{code:x.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),a.dirty());else if(s.kind==="length"){let n=e.data.length>s.value,o=e.data.length<s.value;(n||o)&&(r=this._getOrReturnCtx(e,r),n?I(r,{code:x.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):o&&I(r,{code:x.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),a.dirty())}else if(s.kind==="email")cl.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"email",code:x.invalid_string,message:s.message}),a.dirty());else if(s.kind==="emoji")Bs||(Bs=new RegExp(pl,"u")),Bs.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"emoji",code:x.invalid_string,message:s.message}),a.dirty());else if(s.kind==="uuid")ol.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"uuid",code:x.invalid_string,message:s.message}),a.dirty());else if(s.kind==="nanoid")ll.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"nanoid",code:x.invalid_string,message:s.message}),a.dirty());else if(s.kind==="cuid")sl.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"cuid",code:x.invalid_string,message:s.message}),a.dirty());else if(s.kind==="cuid2")nl.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"cuid2",code:x.invalid_string,message:s.message}),a.dirty());else if(s.kind==="ulid")il.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"ulid",code:x.invalid_string,message:s.message}),a.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{r=this._getOrReturnCtx(e,r),I(r,{validation:"url",code:x.invalid_string,message:s.message}),a.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"regex",code:x.invalid_string,message:s.message}),a.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(r=this._getOrReturnCtx(e,r),I(r,{code:x.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),a.dirty()):s.kind==="toLowerCase"?e.data=e.data.toLowerCase():s.kind==="toUpperCase"?e.data=e.data.toUpperCase():s.kind==="startsWith"?e.data.startsWith(s.value)||(r=this._getOrReturnCtx(e,r),I(r,{code:x.invalid_string,validation:{startsWith:s.value},message:s.message}),a.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(r=this._getOrReturnCtx(e,r),I(r,{code:x.invalid_string,validation:{endsWith:s.value},message:s.message}),a.dirty()):s.kind==="datetime"?_l(s).test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{code:x.invalid_string,validation:"datetime",message:s.message}),a.dirty()):s.kind==="date"?xl.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{code:x.invalid_string,validation:"date",message:s.message}),a.dirty()):s.kind==="time"?bl(s).test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{code:x.invalid_string,validation:"time",message:s.message}),a.dirty()):s.kind==="duration"?ul.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"duration",code:x.invalid_string,message:s.message}),a.dirty()):s.kind==="ip"?wl(e.data,s.version)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"ip",code:x.invalid_string,message:s.message}),a.dirty()):s.kind==="jwt"?kl(e.data,s.alg)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"jwt",code:x.invalid_string,message:s.message}),a.dirty()):s.kind==="cidr"?Cl(e.data,s.version)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"cidr",code:x.invalid_string,message:s.message}),a.dirty()):s.kind==="base64"?yl.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"base64",code:x.invalid_string,message:s.message}),a.dirty()):s.kind==="base64url"?vl.test(e.data)||(r=this._getOrReturnCtx(e,r),I(r,{validation:"base64url",code:x.invalid_string,message:s.message}),a.dirty()):W.assertNever(s);return{status:a.value,value:e.data}}_regex(e,a,r){return this.refinement(s=>e.test(s),{validation:a,code:x.invalid_string,...R.errToObj(r)})}_addCheck(e){return new oa({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...R.errToObj(e)})}url(e){return this._addCheck({kind:"url",...R.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...R.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...R.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...R.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...R.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...R.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...R.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...R.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...R.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...R.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...R.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...R.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:(e==null?void 0:e.precision)===void 0?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...R.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:(e==null?void 0:e.precision)===void 0?null:e==null?void 0:e.precision,...R.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...R.errToObj(e)})}regex(e,a){return this._addCheck({kind:"regex",regex:e,...R.errToObj(a)})}includes(e,a){return this._addCheck({kind:"includes",value:e,position:a==null?void 0:a.position,...R.errToObj(a==null?void 0:a.message)})}startsWith(e,a){return this._addCheck({kind:"startsWith",value:e,...R.errToObj(a)})}endsWith(e,a){return this._addCheck({kind:"endsWith",value:e,...R.errToObj(a)})}min(e,a){return this._addCheck({kind:"min",value:e,...R.errToObj(a)})}max(e,a){return this._addCheck({kind:"max",value:e,...R.errToObj(a)})}length(e,a){return this._addCheck({kind:"length",value:e,...R.errToObj(a)})}nonempty(e){return this.min(1,R.errToObj(e))}trim(){return new oa({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new oa({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new oa({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let a of this._def.checks)a.kind==="min"&&(e===null||a.value>e)&&(e=a.value);return e}get maxLength(){let e=null;for(let a of this._def.checks)a.kind==="max"&&(e===null||a.value<e)&&(e=a.value);return e}};_a.create=t=>new _a({checks:[],typeName:_.ZodString,coerce:(t==null?void 0:t.coerce)??!1,...L(t)});function Il(t,e){let a=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=a>r?a:r;return Number.parseInt(t.toFixed(s).replace(".",""))%Number.parseInt(e.toFixed(s).replace(".",""))/10**s}var rr=class Gr extends F{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==S.number){let s=this._getOrReturnCtx(e);return I(s,{code:x.invalid_type,expected:S.number,received:s.parsedType}),j}let a,r=new xe;for(let s of this._def.checks)s.kind==="int"?W.isInteger(e.data)||(a=this._getOrReturnCtx(e,a),I(a,{code:x.invalid_type,expected:"integer",received:"float",message:s.message}),r.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(a=this._getOrReturnCtx(e,a),I(a,{code:x.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),r.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(a=this._getOrReturnCtx(e,a),I(a,{code:x.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),r.dirty()):s.kind==="multipleOf"?Il(e.data,s.value)!==0&&(a=this._getOrReturnCtx(e,a),I(a,{code:x.not_multiple_of,multipleOf:s.value,message:s.message}),r.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(a=this._getOrReturnCtx(e,a),I(a,{code:x.not_finite,message:s.message}),r.dirty()):W.assertNever(s);return{status:r.value,value:e.data}}gte(e,a){return this.setLimit("min",e,!0,R.toString(a))}gt(e,a){return this.setLimit("min",e,!1,R.toString(a))}lte(e,a){return this.setLimit("max",e,!0,R.toString(a))}lt(e,a){return this.setLimit("max",e,!1,R.toString(a))}setLimit(e,a,r,s){return new Gr({...this._def,checks:[...this._def.checks,{kind:e,value:a,inclusive:r,message:R.toString(s)}]})}_addCheck(e){return new Gr({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:R.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:R.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:R.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:R.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:R.toString(e)})}multipleOf(e,a){return this._addCheck({kind:"multipleOf",value:e,message:R.toString(a)})}finite(e){return this._addCheck({kind:"finite",message:R.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:-(2**53-1),message:R.toString(e)})._addCheck({kind:"max",inclusive:!0,value:2**53-1,message:R.toString(e)})}get minValue(){let e=null;for(let a of this._def.checks)a.kind==="min"&&(e===null||a.value>e)&&(e=a.value);return e}get maxValue(){let e=null;for(let a of this._def.checks)a.kind==="max"&&(e===null||a.value<e)&&(e=a.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&W.isInteger(e.value))}get isFinite(){let e=null,a=null;for(let r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(a===null||r.value>a)&&(a=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(a)&&Number.isFinite(e)}};rr.create=t=>new rr({checks:[],typeName:_.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...L(t)});var sr=class Qr extends F{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==S.bigint)return this._getInvalidInput(e);let a,r=new xe;for(let s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(a=this._getOrReturnCtx(e,a),I(a,{code:x.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),r.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(a=this._getOrReturnCtx(e,a),I(a,{code:x.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),r.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(a=this._getOrReturnCtx(e,a),I(a,{code:x.not_multiple_of,multipleOf:s.value,message:s.message}),r.dirty()):W.assertNever(s);return{status:r.value,value:e.data}}_getInvalidInput(e){let a=this._getOrReturnCtx(e);return I(a,{code:x.invalid_type,expected:S.bigint,received:a.parsedType}),j}gte(e,a){return this.setLimit("min",e,!0,R.toString(a))}gt(e,a){return this.setLimit("min",e,!1,R.toString(a))}lte(e,a){return this.setLimit("max",e,!0,R.toString(a))}lt(e,a){return this.setLimit("max",e,!1,R.toString(a))}setLimit(e,a,r,s){return new Qr({...this._def,checks:[...this._def.checks,{kind:e,value:a,inclusive:r,message:R.toString(s)}]})}_addCheck(e){return new Qr({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:R.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:R.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:R.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:R.toString(e)})}multipleOf(e,a){return this._addCheck({kind:"multipleOf",value:e,message:R.toString(a)})}get minValue(){let e=null;for(let a of this._def.checks)a.kind==="min"&&(e===null||a.value>e)&&(e=a.value);return e}get maxValue(){let e=null;for(let a of this._def.checks)a.kind==="max"&&(e===null||a.value<e)&&(e=a.value);return e}};sr.create=t=>new sr({checks:[],typeName:_.ZodBigInt,coerce:(t==null?void 0:t.coerce)??!1,...L(t)});var nr=class extends F{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==S.boolean){let e=this._getOrReturnCtx(t);return I(e,{code:x.invalid_type,expected:S.boolean,received:e.parsedType}),j}return ve(t.data)}};nr.create=t=>new nr({typeName:_.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...L(t)});var ir=class Ci extends F{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==S.date){let s=this._getOrReturnCtx(e);return I(s,{code:x.invalid_type,expected:S.date,received:s.parsedType}),j}if(Number.isNaN(e.data.getTime()))return I(this._getOrReturnCtx(e),{code:x.invalid_date}),j;let a=new xe,r;for(let s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(r=this._getOrReturnCtx(e,r),I(r,{code:x.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),a.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(r=this._getOrReturnCtx(e,r),I(r,{code:x.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),a.dirty()):W.assertNever(s);return{status:a.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Ci({...this._def,checks:[...this._def.checks,e]})}min(e,a){return this._addCheck({kind:"min",value:e.getTime(),message:R.toString(a)})}max(e,a){return this._addCheck({kind:"max",value:e.getTime(),message:R.toString(a)})}get minDate(){let e=null;for(let a of this._def.checks)a.kind==="min"&&(e===null||a.value>e)&&(e=a.value);return e==null?null:new Date(e)}get maxDate(){let e=null;for(let a of this._def.checks)a.kind==="max"&&(e===null||a.value<e)&&(e=a.value);return e==null?null:new Date(e)}};ir.create=t=>new ir({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:_.ZodDate,...L(t)});var or=class extends F{_parse(t){if(this._getType(t)!==S.symbol){let e=this._getOrReturnCtx(t);return I(e,{code:x.invalid_type,expected:S.symbol,received:e.parsedType}),j}return ve(t.data)}};or.create=t=>new or({typeName:_.ZodSymbol,...L(t)});var wa=class extends F{_parse(t){if(this._getType(t)!==S.undefined){let e=this._getOrReturnCtx(t);return I(e,{code:x.invalid_type,expected:S.undefined,received:e.parsedType}),j}return ve(t.data)}};wa.create=t=>new wa({typeName:_.ZodUndefined,...L(t)});var ka=class extends F{_parse(t){if(this._getType(t)!==S.null){let e=this._getOrReturnCtx(t);return I(e,{code:x.invalid_type,expected:S.null,received:e.parsedType}),j}return ve(t.data)}};ka.create=t=>new ka({typeName:_.ZodNull,...L(t)});var lr=class extends F{constructor(){super(...arguments),this._any=!0}_parse(t){return ve(t.data)}};lr.create=t=>new lr({typeName:_.ZodAny,...L(t)});var Lt=class extends F{constructor(){super(...arguments),this._unknown=!0}_parse(t){return ve(t.data)}};Lt.create=t=>new Lt({typeName:_.ZodUnknown,...L(t)});var rt=class extends F{_parse(t){let e=this._getOrReturnCtx(t);return I(e,{code:x.invalid_type,expected:S.never,received:e.parsedType}),j}};rt.create=t=>new rt({typeName:_.ZodNever,...L(t)});var dr=class extends F{_parse(t){if(this._getType(t)!==S.undefined){let e=this._getOrReturnCtx(t);return I(e,{code:x.invalid_type,expected:S.void,received:e.parsedType}),j}return ve(t.data)}};dr.create=t=>new dr({typeName:_.ZodVoid,...L(t)});var Dt=class za extends F{_parse(e){let{ctx:a,status:r}=this._processInputParams(e),s=this._def;if(a.parsedType!==S.array)return I(a,{code:x.invalid_type,expected:S.array,received:a.parsedType}),j;if(s.exactLength!==null){let o=a.data.length>s.exactLength.value,i=a.data.length<s.exactLength.value;(o||i)&&(I(a,{code:o?x.too_big:x.too_small,minimum:i?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&a.data.length<s.minLength.value&&(I(a,{code:x.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&a.data.length>s.maxLength.value&&(I(a,{code:x.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),a.common.async)return Promise.all([...a.data].map((o,i)=>s.type._parseAsync(new De(a,o,a.path,i)))).then(o=>xe.mergeArray(r,o));let n=[...a.data].map((o,i)=>s.type._parseSync(new De(a,o,a.path,i)));return xe.mergeArray(r,n)}get element(){return this._def.type}min(e,a){return new za({...this._def,minLength:{value:e,message:R.toString(a)}})}max(e,a){return new za({...this._def,maxLength:{value:e,message:R.toString(a)}})}length(e,a){return new za({...this._def,exactLength:{value:e,message:R.toString(a)}})}nonempty(e){return this.min(1,e)}};Dt.create=(t,e)=>new Dt({type:t,minLength:null,maxLength:null,exactLength:null,typeName:_.ZodArray,...L(e)});function Zt(t){if(t instanceof Ae){let e={};for(let a in t.shape){let r=t.shape[a];e[a]=We.create(Zt(r))}return new Ae({...t._def,shape:()=>e})}else return t instanceof Dt?new Dt({...t._def,type:Zt(t.element)}):t instanceof We?We.create(Zt(t.unwrap())):t instanceof ft?ft.create(Zt(t.unwrap())):t instanceof ht?ht.create(t.items.map(e=>Zt(e))):t}var Ae=class Me extends F{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape();return this._cached={shape:e,keys:W.objectKeys(e)},this._cached}_parse(e){if(this._getType(e)!==S.object){let l=this._getOrReturnCtx(e);return I(l,{code:x.invalid_type,expected:S.object,received:l.parsedType}),j}let{status:a,ctx:r}=this._processInputParams(e),{shape:s,keys:n}=this._getCached(),o=[];if(!(this._def.catchall instanceof rt&&this._def.unknownKeys==="strip"))for(let l in r.data)n.includes(l)||o.push(l);let i=[];for(let l of n){let d=s[l],u=r.data[l];i.push({key:{status:"valid",value:l},value:d._parse(new De(r,u,r.path,l)),alwaysSet:l in r.data})}if(this._def.catchall instanceof rt){let l=this._def.unknownKeys;if(l==="passthrough")for(let d of o)i.push({key:{status:"valid",value:d},value:{status:"valid",value:r.data[d]}});else if(l==="strict")o.length>0&&(I(r,{code:x.unrecognized_keys,keys:o}),a.dirty());else if(l!=="strip")throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let l=this._def.catchall;for(let d of o){let u=r.data[d];i.push({key:{status:"valid",value:d},value:l._parse(new De(r,u,r.path,d)),alwaysSet:d in r.data})}}return r.common.async?Promise.resolve().then(async()=>{let l=[];for(let d of i){let u=await d.key,p=await d.value;l.push({key:u,value:p,alwaysSet:d.alwaysSet})}return l}).then(l=>xe.mergeObjectSync(a,l)):xe.mergeObjectSync(a,i)}get shape(){return this._def.shape()}strict(e){return R.errToObj,new Me({...this._def,unknownKeys:"strict",...e===void 0?{}:{errorMap:(a,r)=>{var n,o;let s=((o=(n=this._def).errorMap)==null?void 0:o.call(n,a,r).message)??r.defaultError;return a.code==="unrecognized_keys"?{message:R.errToObj(e).message??s}:{message:s}}}})}strip(){return new Me({...this._def,unknownKeys:"strip"})}passthrough(){return new Me({...this._def,unknownKeys:"passthrough"})}extend(e){return new Me({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new Me({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:_.ZodObject})}setKey(e,a){return this.augment({[e]:a})}catchall(e){return new Me({...this._def,catchall:e})}pick(e){let a={};for(let r of W.objectKeys(e))e[r]&&this.shape[r]&&(a[r]=this.shape[r]);return new Me({...this._def,shape:()=>a})}omit(e){let a={};for(let r of W.objectKeys(this.shape))e[r]||(a[r]=this.shape[r]);return new Me({...this._def,shape:()=>a})}deepPartial(){return Zt(this)}partial(e){let a={};for(let r of W.objectKeys(this.shape)){let s=this.shape[r];e&&!e[r]?a[r]=s:a[r]=s.optional()}return new Me({...this._def,shape:()=>a})}required(e){let a={};for(let r of W.objectKeys(this.shape))if(e&&!e[r])a[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof We;)s=s._def.innerType;a[r]=s}return new Me({...this._def,shape:()=>a})}keyof(){return Ys(W.objectKeys(this.shape))}};Ae.create=(t,e)=>new Ae({shape:()=>t,unknownKeys:"strip",catchall:rt.create(),typeName:_.ZodObject,...L(e)}),Ae.strictCreate=(t,e)=>new Ae({shape:()=>t,unknownKeys:"strict",catchall:rt.create(),typeName:_.ZodObject,...L(e)}),Ae.lazycreate=(t,e)=>new Ae({shape:t,unknownKeys:"strip",catchall:rt.create(),typeName:_.ZodObject,...L(e)});var Ca=class extends F{_parse(t){let{ctx:e}=this._processInputParams(t),a=this._def.options;function r(s){for(let o of s)if(o.result.status==="valid")return o.result;for(let o of s)if(o.result.status==="dirty")return e.common.issues.push(...o.ctx.common.issues),o.result;let n=s.map(o=>new Le(o.ctx.common.issues));return I(e,{code:x.invalid_union,unionErrors:n}),j}if(e.common.async)return Promise.all(a.map(async s=>{let n={...e,common:{...e.common,issues:[]},parent:null};return{result:await s._parseAsync({data:e.data,path:e.path,parent:n}),ctx:n}})).then(r);{let s,n=[];for(let i of a){let l={...e,common:{...e.common,issues:[]},parent:null},d=i._parseSync({data:e.data,path:e.path,parent:l});if(d.status==="valid")return d;d.status==="dirty"&&!s&&(s={result:d,ctx:l}),l.common.issues.length&&n.push(l.common.issues)}if(s)return e.common.issues.push(...s.ctx.common.issues),s.result;let o=n.map(i=>new Le(i));return I(e,{code:x.invalid_union,unionErrors:o}),j}}get options(){return this._def.options}};Ca.create=(t,e)=>new Ca({options:t,typeName:_.ZodUnion,...L(e)});var st=t=>t instanceof Ea?st(t.schema):t instanceof Ve?st(t.innerType()):t instanceof Ta?[t.value]:t instanceof Sa?t.options:t instanceof Aa?W.objectValues(t.enum):t instanceof Oa?st(t._def.innerType):t instanceof wa?[void 0]:t instanceof ka?[null]:t instanceof We?[void 0,...st(t.unwrap())]:t instanceof ft?[null,...st(t.unwrap())]:t instanceof Hs||t instanceof Na?st(t.unwrap()):t instanceof Ra?st(t._def.innerType):[],El=class Ii extends F{_parse(e){let{ctx:a}=this._processInputParams(e);if(a.parsedType!==S.object)return I(a,{code:x.invalid_type,expected:S.object,received:a.parsedType}),j;let r=this.discriminator,s=a.data[r],n=this.optionsMap.get(s);return n?a.common.async?n._parseAsync({data:a.data,path:a.path,parent:a}):n._parseSync({data:a.data,path:a.path,parent:a}):(I(a,{code:x.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),j)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,a,r){let s=new Map;for(let n of a){let o=st(n.shape[e]);if(!o.length)throw Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let i of o){if(s.has(i))throw Error(`Discriminator property ${String(e)} has duplicate value ${String(i)}`);s.set(i,n)}}return new Ii({typeName:_.ZodDiscriminatedUnion,discriminator:e,options:a,optionsMap:s,...L(r)})}};function ur(t,e){let a=at(t),r=at(e);if(t===e)return{valid:!0,data:t};if(a===S.object&&r===S.object){let s=W.objectKeys(e),n=W.objectKeys(t).filter(i=>s.indexOf(i)!==-1),o={...t,...e};for(let i of n){let l=ur(t[i],e[i]);if(!l.valid)return{valid:!1};o[i]=l.data}return{valid:!0,data:o}}else if(a===S.array&&r===S.array){if(t.length!==e.length)return{valid:!1};let s=[];for(let n=0;n<t.length;n++){let o=t[n],i=e[n],l=ur(o,i);if(!l.valid)return{valid:!1};s.push(l.data)}return{valid:!0,data:s}}else return a===S.date&&r===S.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var Ia=class extends F{_parse(t){let{status:e,ctx:a}=this._processInputParams(t),r=(s,n)=>{if(qs(s)||qs(n))return j;let o=ur(s.value,n.value);return o.valid?((Vs(s)||Vs(n))&&e.dirty(),{status:e.value,value:o.data}):(I(a,{code:x.invalid_intersection_types}),j)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then(([s,n])=>r(s,n)):r(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}};Ia.create=(t,e,a)=>new Ia({left:t,right:e,typeName:_.ZodIntersection,...L(a)});var ht=class Ei extends F{_parse(e){let{status:a,ctx:r}=this._processInputParams(e);if(r.parsedType!==S.array)return I(r,{code:x.invalid_type,expected:S.array,received:r.parsedType}),j;if(r.data.length<this._def.items.length)return I(r,{code:x.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),j;!this._def.rest&&r.data.length>this._def.items.length&&(I(r,{code:x.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),a.dirty());let s=[...r.data].map((n,o)=>{let i=this._def.items[o]||this._def.rest;return i?i._parse(new De(r,n,r.path,o)):null}).filter(n=>!!n);return r.common.async?Promise.all(s).then(n=>xe.mergeArray(a,n)):xe.mergeArray(a,s)}get items(){return this._def.items}rest(e){return new Ei({...this._def,rest:e})}};ht.create=(t,e)=>{if(!Array.isArray(t))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new ht({items:t,typeName:_.ZodTuple,rest:null,...L(e)})};var Tl=class Xr extends F{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:a,ctx:r}=this._processInputParams(e);if(r.parsedType!==S.object)return I(r,{code:x.invalid_type,expected:S.object,received:r.parsedType}),j;let s=[],n=this._def.keyType,o=this._def.valueType;for(let i in r.data)s.push({key:n._parse(new De(r,i,r.path,i)),value:o._parse(new De(r,r.data[i],r.path,i)),alwaysSet:i in r.data});return r.common.async?xe.mergeObjectAsync(a,s):xe.mergeObjectSync(a,s)}get element(){return this._def.valueType}static create(e,a,r){return a instanceof F?new Xr({keyType:e,valueType:a,typeName:_.ZodRecord,...L(r)}):new Xr({keyType:_a.create(),valueType:e,typeName:_.ZodRecord,...L(a)})}},cr=class extends F{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){let{status:e,ctx:a}=this._processInputParams(t);if(a.parsedType!==S.map)return I(a,{code:x.invalid_type,expected:S.map,received:a.parsedType}),j;let r=this._def.keyType,s=this._def.valueType,n=[...a.data.entries()].map(([o,i],l)=>({key:r._parse(new De(a,o,a.path,[l,"key"])),value:s._parse(new De(a,i,a.path,[l,"value"]))}));if(a.common.async){let o=new Map;return Promise.resolve().then(async()=>{for(let i of n){let l=await i.key,d=await i.value;if(l.status==="aborted"||d.status==="aborted")return j;(l.status==="dirty"||d.status==="dirty")&&e.dirty(),o.set(l.value,d.value)}return{status:e.value,value:o}})}else{let o=new Map;for(let i of n){let l=i.key,d=i.value;if(l.status==="aborted"||d.status==="aborted")return j;(l.status==="dirty"||d.status==="dirty")&&e.dirty(),o.set(l.value,d.value)}return{status:e.value,value:o}}}};cr.create=(t,e,a)=>new cr({valueType:e,keyType:t,typeName:_.ZodMap,...L(a)});var pr=class es extends F{_parse(e){let{status:a,ctx:r}=this._processInputParams(e);if(r.parsedType!==S.set)return I(r,{code:x.invalid_type,expected:S.set,received:r.parsedType}),j;let s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(I(r,{code:x.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),a.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(I(r,{code:x.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),a.dirty());let n=this._def.valueType;function o(l){let d=new Set;for(let u of l){if(u.status==="aborted")return j;u.status==="dirty"&&a.dirty(),d.add(u.value)}return{status:a.value,value:d}}let i=[...r.data.values()].map((l,d)=>n._parse(new De(r,l,r.path,d)));return r.common.async?Promise.all(i).then(l=>o(l)):o(i)}min(e,a){return new es({...this._def,minSize:{value:e,message:R.toString(a)}})}max(e,a){return new es({...this._def,maxSize:{value:e,message:R.toString(a)}})}size(e,a){return this.min(e,a).max(e,a)}nonempty(e){return this.min(1,e)}};pr.create=(t,e)=>new pr({valueType:t,minSize:null,maxSize:null,typeName:_.ZodSet,...L(e)});var Sl=class Ua extends F{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:a}=this._processInputParams(e);if(a.parsedType!==S.function)return I(a,{code:x.invalid_type,expected:S.function,received:a.parsedType}),j;function r(i,l){return tr({data:i,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,er(),Kt].filter(d=>!!d),issueData:{code:x.invalid_arguments,argumentsError:l}})}function s(i,l){return tr({data:i,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,er(),Kt].filter(d=>!!d),issueData:{code:x.invalid_return_type,returnTypeError:l}})}let n={errorMap:a.common.contextualErrorMap},o=a.data;if(this._def.returns instanceof Yt){let i=this;return ve(async function(...l){let d=new Le([]),u=await i._def.args.parseAsync(l,n).catch(f=>{throw d.addIssue(r(l,f)),d}),p=await Reflect.apply(o,this,u);return await i._def.returns._def.type.parseAsync(p,n).catch(f=>{throw d.addIssue(s(p,f)),d})})}else{let i=this;return ve(function(...l){let d=i._def.args.safeParse(l,n);if(!d.success)throw new Le([r(l,d.error)]);let u=Reflect.apply(o,this,d.data),p=i._def.returns.safeParse(u,n);if(!p.success)throw new Le([s(u,p.error)]);return p.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new Ua({...this._def,args:ht.create(e).rest(Lt.create())})}returns(e){return new Ua({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,a,r){return new Ua({args:e||ht.create([]).rest(Lt.create()),returns:a||Lt.create(),typeName:_.ZodFunction,...L(r)})}},Ea=class extends F{get schema(){return this._def.getter()}_parse(t){let{ctx:e}=this._processInputParams(t);return this._def.getter()._parse({data:e.data,path:e.path,parent:e})}};Ea.create=(t,e)=>new Ea({getter:t,typeName:_.ZodLazy,...L(e)});var Ta=class extends F{_parse(t){if(t.data!==this._def.value){let e=this._getOrReturnCtx(t);return I(e,{received:e.data,code:x.invalid_literal,expected:this._def.value}),j}return{status:"valid",value:t.data}}get value(){return this._def.value}};Ta.create=(t,e)=>new Ta({value:t,typeName:_.ZodLiteral,...L(e)});function Ys(t,e){return new Sa({values:t,typeName:_.ZodEnum,...L(e)})}var Sa=class ts extends F{_parse(e){if(typeof e.data!="string"){let a=this._getOrReturnCtx(e),r=this._def.values;return I(a,{expected:W.joinValues(r),received:a.parsedType,code:x.invalid_type}),j}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let a=this._getOrReturnCtx(e),r=this._def.values;return I(a,{received:a.data,code:x.invalid_enum_value,options:r}),j}return ve(e.data)}get options(){return this._def.values}get enum(){let e={};for(let a of this._def.values)e[a]=a;return e}get Values(){let e={};for(let a of this._def.values)e[a]=a;return e}get Enum(){let e={};for(let a of this._def.values)e[a]=a;return e}extract(e,a=this._def){return ts.create(e,{...this._def,...a})}exclude(e,a=this._def){return ts.create(this.options.filter(r=>!e.includes(r)),{...this._def,...a})}};Sa.create=Ys;var Aa=class extends F{_parse(t){let e=W.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(t);if(a.parsedType!==S.string&&a.parsedType!==S.number){let r=W.objectValues(e);return I(a,{expected:W.joinValues(r),received:a.parsedType,code:x.invalid_type}),j}if(this._cache||(this._cache=new Set(W.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){let r=W.objectValues(e);return I(a,{received:a.data,code:x.invalid_enum_value,options:r}),j}return ve(t.data)}get enum(){return this._def.values}};Aa.create=(t,e)=>new Aa({values:t,typeName:_.ZodNativeEnum,...L(e)});var Yt=class extends F{unwrap(){return this._def.type}_parse(t){let{ctx:e}=this._processInputParams(t);return e.parsedType!==S.promise&&e.common.async===!1?(I(e,{code:x.invalid_type,expected:S.promise,received:e.parsedType}),j):ve((e.parsedType===S.promise?e.data:Promise.resolve(e.data)).then(a=>this._def.type.parseAsync(a,{path:e.path,errorMap:e.common.contextualErrorMap})))}};Yt.create=(t,e)=>new Yt({type:t,typeName:_.ZodPromise,...L(e)});var Ve=class extends F{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===_.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){let{status:e,ctx:a}=this._processInputParams(t),r=this._def.effect||null,s={addIssue:n=>{I(a,n),n.fatal?e.abort():e.dirty()},get path(){return a.path}};if(s.addIssue=s.addIssue.bind(s),r.type==="preprocess"){let n=r.transform(a.data,s);if(a.common.async)return Promise.resolve(n).then(async o=>{if(e.value==="aborted")return j;let i=await this._def.schema._parseAsync({data:o,path:a.path,parent:a});return i.status==="aborted"?j:i.status==="dirty"||e.value==="dirty"?ar(i.value):i});{if(e.value==="aborted")return j;let o=this._def.schema._parseSync({data:n,path:a.path,parent:a});return o.status==="aborted"?j:o.status==="dirty"||e.value==="dirty"?ar(o.value):o}}if(r.type==="refinement"){let n=o=>{let i=r.refinement(o,s);if(a.common.async)return Promise.resolve(i);if(i instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(a.common.async===!1){let o=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return o.status==="aborted"?j:(o.status==="dirty"&&e.dirty(),n(o.value),{status:e.value,value:o.value})}else return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(o=>o.status==="aborted"?j:(o.status==="dirty"&&e.dirty(),n(o.value).then(()=>({status:e.value,value:o.value}))))}if(r.type==="transform")if(a.common.async===!1){let n=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});if(!$t(n))return j;let o=r.transform(n.value,s);if(o instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:e.value,value:o}}else return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(n=>$t(n)?Promise.resolve(r.transform(n.value,s)).then(o=>({status:e.value,value:o})):j);W.assertNever(r)}};Ve.create=(t,e,a)=>new Ve({schema:t,typeName:_.ZodEffects,effect:e,...L(a)}),Ve.createWithPreprocess=(t,e,a)=>new Ve({schema:e,effect:{type:"preprocess",transform:t},typeName:_.ZodEffects,...L(a)});var We=class extends F{_parse(t){return this._getType(t)===S.undefined?ve(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}};We.create=(t,e)=>new We({innerType:t,typeName:_.ZodOptional,...L(e)});var ft=class extends F{_parse(t){return this._getType(t)===S.null?ve(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}};ft.create=(t,e)=>new ft({innerType:t,typeName:_.ZodNullable,...L(e)});var Oa=class extends F{_parse(t){let{ctx:e}=this._processInputParams(t),a=e.data;return e.parsedType===S.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:e.path,parent:e})}removeDefault(){return this._def.innerType}};Oa.create=(t,e)=>new Oa({innerType:t,typeName:_.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...L(e)});var Ra=class extends F{_parse(t){let{ctx:e}=this._processInputParams(t),a={...e,common:{...e.common,issues:[]}},r=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return ba(r)?r.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Le(a.common.issues)},input:a.data})})):{status:"valid",value:r.status==="valid"?r.value:this._def.catchValue({get error(){return new Le(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}};Ra.create=(t,e)=>new Ra({innerType:t,typeName:_.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...L(e)});var mr=class extends F{_parse(t){if(this._getType(t)!==S.nan){let e=this._getOrReturnCtx(t);return I(e,{code:x.invalid_type,expected:S.nan,received:e.parsedType}),j}return{status:"valid",value:t.data}}};mr.create=t=>new mr({typeName:_.ZodNaN,...L(t)});var Hs=class extends F{_parse(t){let{ctx:e}=this._processInputParams(t),a=e.data;return this._def.type._parse({data:a,path:e.path,parent:e})}unwrap(){return this._def.type}},Gs=class Ti extends F{_parse(e){let{status:a,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?j:s.status==="dirty"?(a.dirty(),ar(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{let s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?j:s.status==="dirty"?(a.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,a){return new Ti({in:e,out:a,typeName:_.ZodPipeline})}},Na=class extends F{_parse(t){let e=this._def.innerType._parse(t),a=r=>($t(r)&&(r.value=Object.freeze(r.value)),r);return ba(e)?e.then(r=>a(r)):a(e)}unwrap(){return this._def.innerType}};Na.create=(t,e)=>new Na({innerType:t,typeName:_.ZodReadonly,...L(e)}),Ae.lazycreate;var _;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(_||(_={})),_a.create,rr.create,mr.create,sr.create,nr.create,ir.create,or.create,wa.create,ka.create,lr.create,Lt.create,rt.create,dr.create,Dt.create,Ae.create,Ae.strictCreate,Ca.create,El.create,Ia.create,ht.create,Tl.create,cr.create,pr.create,Sl.create,Ea.create,Ta.create,Sa.create,Aa.create,Yt.create,Ve.create,We.create,ft.create,Ve.createWithPreprocess,Gs.create;var Qs=class extends Error{constructor(t,e){super(t),this.name="ParseError",this.type=e.type,this.field=e.field,this.value=e.value,this.line=e.line}},Xs=10,Al=13,gt=32;function hr(t){}function Ol(t){if(typeof t=="function")throw TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");let{onEvent:e=hr,onError:a=hr,onRetry:r=hr,onComment:s}=t,n=[],o=!0,i,l="",d=0,u;function p(m){if(o&&(o=!1,m.charCodeAt(0)===239&&m.charCodeAt(1)===187&&m.charCodeAt(2)===191&&(m=m.slice(3))),n.length===0){let C=f(m);C!==""&&n.push(C);return}if(m.indexOf(`
4
4
  `)===-1&&m.indexOf("\r")===-1){n.push(m);return}n.push(m);let g=n.join("");n.length=0;let v=f(g);v!==""&&n.push(v)}function f(m){let g=0;if(m.indexOf("\r")===-1){let v=m.indexOf(`
@@ -22,15 +22,15 @@ ${n}
22
22
 
23
23
  `;return a.outputType==="text"&&a.processedContent?i+=`Output:
24
24
  ${a.processedContent}`:a.outputType==="media"&&(i+=`Media Output: Contains ${a.output.mimetype} content`,a.imageUrl&&(i+=`
25
- Image URL: ${a.imageUrl}`)),Bt({type:this.contextType,data:o,details:i})}async getAttachments(e){let a=e[0].data.cellId,r=e[0].data.cellName;return Hu(e.map(s=>s.data.cellOutput),a,r)}};async function Hu(t,e,a){let r=t.filter(n=>n.shouldDownloadImage&&n.outputType==="media");if(r.length===0)return[];let s=r.flatMap(n=>{let o=document.getElementById(Di.create(e));return o?{cellId:e,cellName:a,mimetype:n.output.mimetype,element:o}:(le.warn(`Output element not found for cell ${e}`),[])});try{return await Promise.all(s.map(async n=>({type:"file",filename:`${a}-output-screenshot`,mediaType:"image/png",url:await Bo(n.element)})))}catch(n){return le.error("Error downloading cell output images:",n),[]}}function Wn(t){if(_s(t))return null;let e=t.mimetype,a=Ku(e,String(t.data))?"media":"text",r=Ho(t),s,n=!1;return a==="media"&&(typeof t.data=="string"&&t.data.startsWith("data:")||typeof t.data=="string"&&t.data.startsWith("http")?s=t.data:n=!0),{processedContent:r,imageUrl:s,shouldDownloadImage:n,outputType:a,output:t}}function Bn(t,e,a){let{includeConsoleOutput:r=!1}=a||{},s=e.cellRuntime[t],n=e.cellData[t],o=e.cellIds.inOrderIds.indexOf(t),i=Fi(n.name,o),l;r&&(l=s.consoleOutputs.map(p=>Wn(p)).filter(p=>p!==null));let d,u=s.output;return u&&!_s(u)&&(d=Wn(u)??void 0),{cellId:t,cellName:i,cellCode:n.code,cellOutput:d,consoleOutputs:l}}function Gu(t){return t.type==="setup-refs"?"The setup cell cannot have references":t.type==="cycle"?"This cell is in a cycle":t.type==="multiple-defs"?`The variable '${t.name}' was defined by another cell`:t.type==="import-star"||t.type==="ancestor-stopped"||t.type==="ancestor-prevented"||t.type==="exception"||t.type==="strict-exception"?t.msg:t.type==="interruption"?"This cell was interrupted and needs to be re-run":t.type==="syntax"||t.type==="unknown"||t.type==="sql-error"?t.msg:t.type==="internal"?t.msg||"An internal error occurred":(xs(t),"Unknown error")}var Jn=new Ki("error","errors"),Qu=class extends Jt{constructor(e){super();D(this,"title","Errors");D(this,"mentionPrefix","@");D(this,"contextType","error");this.store=e}getItems(){let e=this.store.get(Vi);return e.length===0?[]:[{uri:this.asURI("all"),name:"Errors",type:this.contextType,data:{type:"all-errors",errors:e.map(a=>({cellId:a.cellId,cellName:a.cellName,errorData:a.output.data}))},description:"All errors in the notebook"}]}formatCompletion(e){return e.data.type==="all-errors"?{label:"@Errors",displayLabel:"Errors",detail:`${e.data.errors.length} ${Jn.pluralize(e.data.errors.length)}`,type:"error",apply:"@Errors",section:jt.ERROR,info:()=>{let a=document.createElement("div");a.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 s=document.createElement("div");s.classList.add("font-bold","text-base"),s.textContent="Errors",r.append(s);let n=document.createElement("div");return n.classList.add("text-sm","text-muted-foreground"),n.textContent=`${e.data.errors.length} ${Jn.pluralize(e.data.errors.length)}`,r.append(n),a.append(r),a}}:{label:"Error",displayLabel:"Error",section:jt.ERROR}}formatContext(e){let{data:a}=e;return a.errors.map(r=>Bt({type:this.contextType,data:{name:r.cellName||`Cell ${r.cellId}`,description:r.errorData.map(s=>Gu(s)).join(`
25
+ Image URL: ${a.imageUrl}`)),Bt({type:this.contextType,data:o,details:i})}async getAttachments(e){let a=e[0].data.cellId,r=e[0].data.cellName;return Hu(e.map(s=>s.data.cellOutput),a,r)}};async function Hu(t,e,a){let r=t.filter(n=>n.shouldDownloadImage&&n.outputType==="media");if(r.length===0)return[];let s=r.flatMap(n=>{let o=document.getElementById(Li.create(e));return o?{cellId:e,cellName:a,mimetype:n.output.mimetype,element:o}:(le.warn(`Output element not found for cell ${e}`),[])});try{return await Promise.all(s.map(async n=>({type:"file",filename:`${a}-output-screenshot`,mediaType:"image/png",url:await Bo(n.element)})))}catch(n){return le.error("Error downloading cell output images:",n),[]}}function Wn(t){if(_s(t))return null;let e=t.mimetype,a=Ku(e,String(t.data))?"media":"text",r=Ho(t),s,n=!1;return a==="media"&&(typeof t.data=="string"&&t.data.startsWith("data:")||typeof t.data=="string"&&t.data.startsWith("http")?s=t.data:n=!0),{processedContent:r,imageUrl:s,shouldDownloadImage:n,outputType:a,output:t}}function Bn(t,e,a){let{includeConsoleOutput:r=!1}=a||{},s=e.cellRuntime[t],n=e.cellData[t],o=e.cellIds.inOrderIds.indexOf(t),i=Zi(n.name,o),l;r&&(l=s.consoleOutputs.map(p=>Wn(p)).filter(p=>p!==null));let d,u=s.output;return u&&!_s(u)&&(d=Wn(u)??void 0),{cellId:t,cellName:i,cellCode:n.code,cellOutput:d,consoleOutputs:l}}function Gu(t){return t.type==="setup-refs"?"The setup cell cannot have references":t.type==="cycle"?"This cell is in a cycle":t.type==="multiple-defs"?`The variable '${t.name}' was defined by another cell`:t.type==="import-star"||t.type==="ancestor-stopped"||t.type==="ancestor-prevented"||t.type==="exception"||t.type==="strict-exception"?t.msg:t.type==="interruption"?"This cell was interrupted and needs to be re-run":t.type==="syntax"||t.type==="unknown"||t.type==="sql-error"?t.msg:t.type==="internal"?t.msg||"An internal error occurred":(xs(t),"Unknown error")}var Jn=new Hi("error","errors"),Qu=class extends Jt{constructor(e){super();D(this,"title","Errors");D(this,"mentionPrefix","@");D(this,"contextType","error");this.store=e}getItems(){let e=this.store.get(Ji);return e.length===0?[]:[{uri:this.asURI("all"),name:"Errors",type:this.contextType,data:{type:"all-errors",errors:e.map(a=>({cellId:a.cellId,cellName:a.cellName,errorData:a.output.data}))},description:"All errors in the notebook"}]}formatCompletion(e){return e.data.type==="all-errors"?{label:"@Errors",displayLabel:"Errors",detail:`${e.data.errors.length} ${Jn.pluralize(e.data.errors.length)}`,type:"error",apply:"@Errors",section:jt.ERROR,info:()=>{let a=document.createElement("div");a.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 s=document.createElement("div");s.classList.add("font-bold","text-base"),s.textContent="Errors",r.append(s);let n=document.createElement("div");return n.classList.add("text-sm","text-muted-foreground"),n.textContent=`${e.data.errors.length} ${Jn.pluralize(e.data.errors.length)}`,r.append(n),a.append(r),a}}:{label:"Error",displayLabel:"Error",section:jt.ERROR}}formatContext(e){let{data:a}=e;return a.errors.map(r=>Bt({type:this.contextType,data:{name:r.cellName||`Cell ${r.cellId}`,description:r.errorData.map(s=>Gu(s)).join(`
26
26
  `)}})).join(`
27
27
 
28
28
  `)}};const Kn=Wi();var Xu={maxDepth:3,maxResults:20,defaultResultsLimit:5,includeDirectories:!1},ec=class extends Jt{constructor(e,a=Xu){super();D(this,"title","Files");D(this,"mentionPrefix","#");D(this,"contextType","file");D(this,"searchFiles",async(e,a={})=>{let{maxDepth:r,maxResults:s,includeDirectories:n}={...this.config,...a};return(await this.apiRequests.sendSearchFiles({query:e,includeFiles:!0,includeDirectories:n,depth:r,limit:s})).files});this.apiRequests=e,this.config=a}createCompletionSource(){return async e=>{let a=e.matchBefore(/#[^\s#]*/);if(!a)return null;let r=a.text;if(!r.startsWith("#"))return null;let s=r.slice(1);if(s.length===0)return this.getDefaultCompletions(a);try{let n=(await this.searchFiles(s)||[]).map(o=>{let i={uri:this.asURI(o.path),name:o.name,type:this.contextType,description:o.isDirectory?"Directory":"File",data:{path:o.path,isDirectory:o.isDirectory}};return this.formatCompletion(i)});return{from:a.from,options:n}}catch(n){return le.error("Failed to search files:",n),null}}}async getDefaultCompletions(e){try{for(let a of["py","md","csv"])try{let r=await this.searchFiles(a,{maxDepth:1,maxResults:5});if(r&&r.length>0){let s=r.map(n=>{let o={uri:this.asURI(n.path),name:n.name,type:this.contextType,description:n.isDirectory?"Directory":"File",data:{path:n.path,isDirectory:n.isDirectory}};return this.formatCompletion(o)});return{from:e.from,options:s}}}catch(r){le.error("Failed to get default file completions:",r)}return{from:e.from,options:[]}}catch(a){return le.error("Failed to get default file completions:",a),null}}getItems(){return[]}formatCompletion(e){let{data:a,name:r}=e,s=a.isDirectory?"\u{1F4C1}":"\u{1F4C4}";return{...this.createBasicCompletion(e),type:"file",section:jt.FILE,boost:a.isDirectory?Pt.MEDIUM:Pt.LOW,detail:a.path,displayLabel:`${s} ${r}`,apply:async(n,o,i,l)=>{var y;let d=(y=n.state.facet(Kn))==null?void 0:y.addAttachment;if(!d){le.warn("No addAttachment callback provided");return}let u=await this.apiRequests.sendFileDetails({path:a.path}).catch(k=>(Ga({title:"Failed to get file details",description:k.message}),null));if(!u)return;let p=u.mimeType||"text/plain",f;if(p.startsWith("text/")||p.includes("json")||p.includes("xml"))f=new Blob([u.contents||""],{type:p});else if(u.contents)try{f=qo(Oo(u.contents,p))}catch{f=new Blob([u.contents],{type:p})}else f=new Blob([""],{type:p});d(new File([f],r,{type:p})),n.dispatch({changes:{from:i,to:l,insert:""}}),ko(n)},info:()=>{let n=document.createElement("div");n.classList.add("flex","flex-col","gap-1","p-2");let o=document.createElement("div");o.classList.add("font-bold"),o.textContent=r,n.append(o);let i=document.createElement("div");return i.classList.add("text-xs","text-muted-foreground"),i.textContent=a.path,n.append(i),n}}}formatContext(e){let{data:a,name:r}=e;return Bt({type:this.contextType,data:{name:r,path:a.path,isDirectory:a.isDirectory},details:a.isDirectory?"Directory containing files and subdirectories":"File"})}},tc=class extends Jt{constructor(e){super();D(this,"title","Tables");D(this,"mentionPrefix","@");D(this,"contextType","data");this.tablesMap=e}getItems(){return[...this.tablesMap.entries()].map(([e,a])=>({uri:this.asURI(e),name:e,type:this.contextType,description:a.source==="memory"?"in-memory":a.source,data:a}))}formatContext(e){let{data:a}=e,{columns:r,source:s,num_rows:n,num_columns:o,name:i,variable_name:l}=a,d=[n==null?void 0:`${n} rows`,o==null?void 0:`${o} columns`].filter(Boolean).join(", "),u="";if(d&&(u+=`Shape: ${d}
29
29
  `),l&&(u+=`Variable: ${l}
30
30
  `),r&&r.length>0){u+=`Columns:
31
31
  `;for(let p of r){let f=` ${p.name} (${p.type})`;if(p.sample_values&&p.sample_values.length>0){let y=p.sample_values.slice(0,3).map(k=>k===null?"null":String(k)).join(", ");f+=` - samples: [${y}]`}u+=`${f}
32
- `}}return Bt({type:this.contextType,data:{name:i,source:s??"unknown"},details:u.trim()})}formatCompletion(e){let a=e.data.name,r=e.data;return{label:`@${a}`,displayLabel:a,detail:r.source==="memory"?"in-memory":r.source,boost:r.source_type==="local"?Pt.LOCAL_TABLE:Pt.REMOTE_TABLE,type:ds(r),apply:`@${a}`,section:{name:ds(r)==="dataframe"?"Dataframe":"Table",rank:jt.TABLE.rank},info:()=>this.createTableInfoElement(a,r)}}createTableInfoElement(e,a){let r=document.createElement("div");r.classList.add("mo-cm-tooltip","docs-documentation","min-w-[200px]","flex","flex-col","gap-1","p-2");let s=document.createElement("div");s.classList.add("flex","flex-col","gap-1");let n=document.createElement("div");if(n.classList.add("font-bold","text-base"),n.textContent=e,s.append(n),a.source){let i=document.createElement("div");i.classList.add("text-xs","text-muted-foreground"),i.textContent=`Source: ${a.source}`,s.append(i)}r.append(s);let o=[a.num_rows==null?void 0:`${a.num_rows} rows`,a.num_columns==null?void 0:`${a.num_columns} columns`].filter(Boolean).join(", ");if(o){let i=document.createElement("div");i.classList.add("text-xs","bg-muted","px-2","py-1","rounded"),i.textContent=o,r.append(i)}if(a.columns&&a.columns.length>0){let i=document.createElement("div");i.classList.add("overflow-auto","max-h-60");let l=document.createElement("table");l.classList.add("w-full","text-xs","border-collapse");let d=l.insertRow();d.classList.add("bg-muted");let u=d.insertCell();u.classList.add("p-2","font-medium","text-left"),u.textContent="Column";let p=d.insertCell();p.classList.add("p-2","font-medium","text-left"),p.textContent="Type";let f=a.columns.some(k=>this.getItemMetadata(a,k)!==void 0),y;f&&(y=d.insertCell(),y.classList.add("p-2","font-medium","text-left"),y.textContent="Metadata"),a.columns.forEach((k,c)=>{let b=l.insertRow();b.classList.add(c%2==0?"bg-background":"bg-muted/30");let m=b.insertCell();m.classList.add("p-2","font-mono"),m.textContent=k.name;let g=b.insertCell();if(g.classList.add("p-2","text-muted-foreground"),g.textContent=k.type,f){let v=b.insertCell();v.classList.add("p-2");let C=this.getItemMetadata(a,k);C&&v.append(C)}}),i.append(l),r.append(i)}return r}getItemMetadata(e,a){var n,o;let r=(n=e.primary_keys)==null?void 0:n.includes(a.name),s=(o=e.indexes)==null?void 0:o.includes(a.name);if(r||s){let i=document.createElement("span");i.textContent=r?"PK":"IDX";let l=r?"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 i.classList.add("text-xs","px-1.5","py-0.5","rounded-full","font-medium",...l.split(" ")),i}}},ac=class extends Jt{constructor(e,a){super();D(this,"title","Variables");D(this,"mentionPrefix","@");D(this,"contextType","variable");this.variables=e,this.tablesMap=a}getItems(){let e=new Set(this.tablesMap.keys());return Object.entries(this.variables).flatMap(([a,r])=>e.has(a)?[]:[{uri:this.asURI(a),name:a,type:this.contextType,description:r.dataType??"",dataType:r.dataType,data:{variable:r}}])}formatCompletion(e){let{data:a}=e,{variable:r}=a;return{label:`@${r.name}`,displayLabel:r.name,detail:r.dataType??"",type:this.contextType,section:jt.VARIABLE,info:()=>Ji(r)}}formatContext(e){let{data:a}=e,{variable:r}=a;return Bt({type:this.contextType,data:{name:r.name,dataType:r.dataType},details:r.value==null?void 0:JSON.stringify(r.value)})}};function Ct(t){let e=t.get(zi),a=t.get($i),r=t.get(Qi);return new Lo().register(new tc(a)).register(new ac(r,a)).register(new Qu(t)).register(new Yu(t)).register(new Do(e.connectionsMap,a))}function rc(){return new ec(Eo())}const sc="@";function nc({input:t}){let e="";return t.includes("@")&&(e=oc(t),le.debug("Included context",e)),{includeOtherCode:us(""),context:{plainText:e,schema:[],variables:[]}}}async function ic({input:t}){let e="",a=[];if(t.includes("@")){let r=Ct(ss),s=r.parseAllContextIds(t);e=r.formatContextForAI(s);try{a=await r.getAttachmentsForContext(s),le.debug("Included attachments",a.length)}catch(n){le.error("Error getting attachments:",n)}}return{body:{includeOtherCode:us(""),context:{plainText:e,schema:[],variables:[]}},attachments:a}}function oc(t){let e=Ct(ss),a=e.parseAllContextIds(t);return e.formatContextForAI(a)}function lc(t,e=[]){return a=>{let r=t.map(s=>a.matchBefore(s)).find(Boolean);return!r||r&&r.from===r.to&&!a.explicit?null:{from:r==null?void 0:r.from,options:[...e]}}}function Yn(t){var e;if((e=t.current)!=null&&e.view){let a=t.current.view.state.selection.main.from;t.current.view.dispatch({changes:{from:a,to:a,insert:"@"},selection:{anchor:a+1,head:a+1}}),t.current.view.focus(),_o(t.current.view)}}function dc(t){if(t.trim().length===0)return[];if(!t.includes("```"))return[{language:"python",code:t}];let e=[],a=0,r=t.indexOf("```",a);for(;r!==-1;){let s=t.indexOf(`
33
- `,r);if(s===-1){let d=t.slice(r+3),u=d.indexOf(" "),p=u===-1?d:d.slice(0,u),f=p==="markdown"?"markdown":p==="sql"?"sql":"python",y=u===-1?"":d.slice(u+1);y.trim()&&e.push({language:f,code:y.trim()});break}let n=t.slice(r+3,s).trim()||"";n=n==="markdown"?"markdown":n==="sql"?"sql":"python";let o=s+1,i=t.indexOf("```",o);if(i===-1){let d=t.slice(o).replace(/\n+$/,"");d.trim()&&e.push({language:n,code:d});break}let l=t.slice(o,i).replace(/\n+$/,"");l.trim()&&e.push({language:n,code:l}),a=i+3,r=t.indexOf("```",a)}return e.length===0&&e.push({language:"python",code:t}),e}var uc=Wt(),Hn=()=>new Map,{valueAtom:sa,useActions:Gn,createActions:am,reducer:rm}=bo(Hn,{addStagedCell:(t,e)=>{let{cellId:a,edit:r}=e;return new Map([...t,[a,r]])},removeStagedCell:(t,e)=>{let a=new Map(t);return a.delete(e),a},clearStagedCells:()=>Hn()});function Qn(t){let e=(0,uc.c)(27),{addStagedCell:a,removeStagedCell:r,clearStagedCells:s}=Gn(),{createNewCell:n,updateCellCode:o}=os(),i=jo(),l=(0,N.useRef)(null),d;e[0]!==a||e[1]!==n?(d=C=>{let T=ls.create();return a({cellId:T,edit:{type:"add_cell"}}),n({cellId:"__end__",code:C,before:!1,newCellId:T}),T},e[0]=a,e[1]=n,e[2]=d):d=e[2];let u=d,p;e[3]!==t||e[4]!==o?(p=C=>{let{cellId:T,code:M}=C;if(!t.get(sa).has(T)){le.error("Staged cell not found",{cellId:T});return}let Z=qi(T);Z?Ja(Z,M):o({cellId:T,code:M,formattingChange:!1})},e[3]=t,e[4]=o,e[5]=p):p=e[5];let f=p,y;e[6]!==i||e[7]!==r?(y=C=>{r(C),i({cellId:C})},e[6]=i,e[7]=r,e[8]=y):y=e[8];let k=y,c;e[9]!==s||e[10]!==i||e[11]!==t?(c=()=>{let C=t.get(sa);for(let T of C.keys())i({cellId:T});s()},e[9]=s,e[10]=i,e[11]=t,e[12]=c):c=e[12];let b=c,m;e[13]!==a||e[14]!==n||e[15]!==u||e[16]!==f?(m=C=>{e:switch(C.type){case"text-start":l.current=new cc(u,f,a,n);break e;case"text-delta":if(!l.current){le.error("Cell creation stream not found");return}l.current.stream(C);break e;case"text-end":case"finish":if(!l.current){le.error("Cell creation stream not found");return}l.current.stop();break e;case"abort":case"error":case"tool-input-error":case"tool-output-error":le.error("Error",C.type,{chunk:C});break e;case"tool-approval-request":le.log("Tool approval request",{chunk:C});break e;case"tool-output-denied":le.error("Tool output denied",{chunk:C});break e;case"start":case"start-step":case"finish-step":case"data-reasoning-signature":break e;case"message-metadata":case"tool-input-available":case"tool-output-available":case"reasoning-start":case"reasoning-delta":case"reasoning-end":case"file":case"source-document":case"source-url":case"tool-input-start":case"tool-input-delta":le.debug(C.type,{chunk:C});break e;default:if(pc(C)){le.debug("Data chunk",{chunk:C});break e}xs(C)}},e[13]=a,e[14]=n,e[15]=u,e[16]=f,e[17]=m):m=e[17];let g=m,v;return e[18]!==a||e[19]!==s||e[20]!==u||e[21]!==b||e[22]!==k||e[23]!==g||e[24]!==r||e[25]!==f?(v={createStagedCell:u,updateStagedCell:f,addStagedCell:a,removeStagedCell:r,clearStagedCells:s,deleteStagedCell:k,deleteAllStagedCells:b,onStream:g},e[18]=a,e[19]=s,e[20]=u,e[21]=b,e[22]=k,e[23]=g,e[24]=r,e[25]=f,e[26]=v):v=e[26],v}var cc=class{constructor(t,e,a,r){D(this,"createdCells",[]);D(this,"buffer","");D(this,"hasMarimoImport",!1);this.onCreateCell=t,this.onUpdateCell=e,this.addStagedCell=a,this.createNewCell=r}stream(t){let e=t.delta;this.buffer+=e;let a=dc(this.buffer);for(let[r,s]of a.entries())if(r<this.createdCells.length){this.addMarimoImport(s.language);let n=this.createdCells[r];this.createdCells[r]={...n,cell:s},this.onUpdateCell({cellId:n.cellId,code:s.code,language:s.language})}else{let n=this.onCreateCell(s.code);this.createdCells.push({cellId:n,cell:s})}}addMarimoImport(t){var a;if(this.hasMarimoImport||t==="python")return;let e=Wo({autoInstantiate:!1,createNewCell:this.createNewCell,fromCellId:(a=this.createdCells[0])==null?void 0:a.cellId,before:!0});e&&this.addStagedCell({cellId:e,edit:{type:"add_cell"}}),this.hasMarimoImport=!0}stop(){this.buffer=""}};function pc(t){return t.type.startsWith("data-")}var mc={baseDescription:"Perform editing operations on the current notebook. You should prefer to create new cells unless you need to edit existing cells. Call this tool multiple times to perform multiple edits. Separate code into logical individual cells to take advantage of the notebook's reactive execution model.",prerequisites:["If you are updating existing cells, you need the cellIds. If they are not known, call the lightweight_cell_map_tool to find out."],additionalInfo:`
32
+ `}}return Bt({type:this.contextType,data:{name:i,source:s??"unknown"},details:u.trim()})}formatCompletion(e){let a=e.data.name,r=e.data;return{label:`@${a}`,displayLabel:a,detail:r.source==="memory"?"in-memory":r.source,boost:r.source_type==="local"?Pt.LOCAL_TABLE:Pt.REMOTE_TABLE,type:ls(r),apply:`@${a}`,section:{name:ls(r)==="dataframe"?"Dataframe":"Table",rank:jt.TABLE.rank},info:()=>this.createTableInfoElement(a,r)}}createTableInfoElement(e,a){let r=document.createElement("div");r.classList.add("mo-cm-tooltip","docs-documentation","min-w-[200px]","flex","flex-col","gap-1","p-2");let s=document.createElement("div");s.classList.add("flex","flex-col","gap-1");let n=document.createElement("div");if(n.classList.add("font-bold","text-base"),n.textContent=e,s.append(n),a.source){let i=document.createElement("div");i.classList.add("text-xs","text-muted-foreground"),i.textContent=`Source: ${a.source}`,s.append(i)}r.append(s);let o=[a.num_rows==null?void 0:`${a.num_rows} rows`,a.num_columns==null?void 0:`${a.num_columns} columns`].filter(Boolean).join(", ");if(o){let i=document.createElement("div");i.classList.add("text-xs","bg-muted","px-2","py-1","rounded"),i.textContent=o,r.append(i)}if(a.columns&&a.columns.length>0){let i=document.createElement("div");i.classList.add("overflow-auto","max-h-60");let l=document.createElement("table");l.classList.add("w-full","text-xs","border-collapse");let d=l.insertRow();d.classList.add("bg-muted");let u=d.insertCell();u.classList.add("p-2","font-medium","text-left"),u.textContent="Column";let p=d.insertCell();p.classList.add("p-2","font-medium","text-left"),p.textContent="Type";let f=a.columns.some(k=>this.getItemMetadata(a,k)!==void 0),y;f&&(y=d.insertCell(),y.classList.add("p-2","font-medium","text-left"),y.textContent="Metadata"),a.columns.forEach((k,c)=>{let b=l.insertRow();b.classList.add(c%2==0?"bg-background":"bg-muted/30");let m=b.insertCell();m.classList.add("p-2","font-mono"),m.textContent=k.name;let g=b.insertCell();if(g.classList.add("p-2","text-muted-foreground"),g.textContent=k.type,f){let v=b.insertCell();v.classList.add("p-2");let C=this.getItemMetadata(a,k);C&&v.append(C)}}),i.append(l),r.append(i)}return r}getItemMetadata(e,a){var n,o;let r=(n=e.primary_keys)==null?void 0:n.includes(a.name),s=(o=e.indexes)==null?void 0:o.includes(a.name);if(r||s){let i=document.createElement("span");i.textContent=r?"PK":"IDX";let l=r?"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 i.classList.add("text-xs","px-1.5","py-0.5","rounded-full","font-medium",...l.split(" ")),i}}},ac=class extends Jt{constructor(e,a){super();D(this,"title","Variables");D(this,"mentionPrefix","@");D(this,"contextType","variable");this.variables=e,this.tablesMap=a}getItems(){let e=new Set(this.tablesMap.keys());return Object.entries(this.variables).flatMap(([a,r])=>e.has(a)?[]:[{uri:this.asURI(a),name:a,type:this.contextType,description:r.dataType??"",dataType:r.dataType,data:{variable:r}}])}formatCompletion(e){let{data:a}=e,{variable:r}=a;return{label:`@${r.name}`,displayLabel:r.name,detail:r.dataType??"",type:this.contextType,section:jt.VARIABLE,info:()=>Yi(r)}}formatContext(e){let{data:a}=e,{variable:r}=a;return Bt({type:this.contextType,data:{name:r.name,dataType:r.dataType},details:r.value==null?void 0:JSON.stringify(r.value)})}};function Ct(t){let e=t.get(Fi),a=t.get($i),r=t.get(Qi);return new Lo().register(new tc(a)).register(new ac(r,a)).register(new Qu(t)).register(new Yu(t)).register(new Do(e.connectionsMap,a))}function rc(){return new ec(Eo())}const sc="@";function nc({input:t}){let e="";return t.includes("@")&&(e=oc(t),le.debug("Included context",e)),{includeOtherCode:ds(""),context:{plainText:e,schema:[],variables:[]}}}async function ic({input:t}){let e="",a=[];if(t.includes("@")){let r=Ct(ss),s=r.parseAllContextIds(t);e=r.formatContextForAI(s);try{a=await r.getAttachmentsForContext(s),le.debug("Included attachments",a.length)}catch(n){le.error("Error getting attachments:",n)}}return{body:{includeOtherCode:ds(""),context:{plainText:e,schema:[],variables:[]}},attachments:a}}function oc(t){let e=Ct(ss),a=e.parseAllContextIds(t);return e.formatContextForAI(a)}function lc(t,e=[]){return a=>{let r=t.map(s=>a.matchBefore(s)).find(Boolean);return!r||r&&r.from===r.to&&!a.explicit?null:{from:r==null?void 0:r.from,options:[...e]}}}function Yn(t){var e;if((e=t.current)!=null&&e.view){let a=t.current.view.state.selection.main.from;t.current.view.dispatch({changes:{from:a,to:a,insert:"@"},selection:{anchor:a+1,head:a+1}}),t.current.view.focus(),_o(t.current.view)}}function dc(t){if(t.trim().length===0)return[];if(!t.includes("```"))return[{language:"python",code:t}];let e=[],a=0,r=t.indexOf("```",a);for(;r!==-1;){let s=t.indexOf(`
33
+ `,r);if(s===-1){let d=t.slice(r+3),u=d.indexOf(" "),p=u===-1?d:d.slice(0,u),f=p==="markdown"?"markdown":p==="sql"?"sql":"python",y=u===-1?"":d.slice(u+1);y.trim()&&e.push({language:f,code:y.trim()});break}let n=t.slice(r+3,s).trim()||"";n=n==="markdown"?"markdown":n==="sql"?"sql":"python";let o=s+1,i=t.indexOf("```",o);if(i===-1){let d=t.slice(o).replace(/\n+$/,"");d.trim()&&e.push({language:n,code:d});break}let l=t.slice(o,i).replace(/\n+$/,"");l.trim()&&e.push({language:n,code:l}),a=i+3,r=t.indexOf("```",a)}return e.length===0&&e.push({language:"python",code:t}),e}var uc=Wt(),Hn=()=>new Map,{valueAtom:sa,useActions:Gn,createActions:am,reducer:rm}=bo(Hn,{addStagedCell:(t,e)=>{let{cellId:a,edit:r}=e;return new Map([...t,[a,r]])},removeStagedCell:(t,e)=>{let a=new Map(t);return a.delete(e),a},clearStagedCells:()=>Hn()});function Qn(t){let e=(0,uc.c)(27),{addStagedCell:a,removeStagedCell:r,clearStagedCells:s}=Gn(),{createNewCell:n,updateCellCode:o}=os(),i=jo(),l=(0,N.useRef)(null),d;e[0]!==a||e[1]!==n?(d=C=>{let T=us.create();return a({cellId:T,edit:{type:"add_cell"}}),n({cellId:"__end__",code:C,before:!1,newCellId:T}),T},e[0]=a,e[1]=n,e[2]=d):d=e[2];let u=d,p;e[3]!==t||e[4]!==o?(p=C=>{let{cellId:T,code:M}=C;if(!t.get(sa).has(T)){le.error("Staged cell not found",{cellId:T});return}let Z=Bi(T);Z?Ja(Z,M):o({cellId:T,code:M,formattingChange:!1})},e[3]=t,e[4]=o,e[5]=p):p=e[5];let f=p,y;e[6]!==i||e[7]!==r?(y=C=>{r(C),i({cellId:C})},e[6]=i,e[7]=r,e[8]=y):y=e[8];let k=y,c;e[9]!==s||e[10]!==i||e[11]!==t?(c=()=>{let C=t.get(sa);for(let T of C.keys())i({cellId:T});s()},e[9]=s,e[10]=i,e[11]=t,e[12]=c):c=e[12];let b=c,m;e[13]!==a||e[14]!==n||e[15]!==u||e[16]!==f?(m=C=>{e:switch(C.type){case"text-start":l.current=new cc(u,f,a,n);break e;case"text-delta":if(!l.current){le.error("Cell creation stream not found");return}l.current.stream(C);break e;case"text-end":case"finish":if(!l.current){le.error("Cell creation stream not found");return}l.current.stop();break e;case"abort":case"error":case"tool-input-error":case"tool-output-error":le.error("Error",C.type,{chunk:C});break e;case"tool-approval-request":le.log("Tool approval request",{chunk:C});break e;case"tool-output-denied":le.error("Tool output denied",{chunk:C});break e;case"start":case"start-step":case"finish-step":case"data-reasoning-signature":break e;case"message-metadata":case"tool-input-available":case"tool-output-available":case"reasoning-start":case"reasoning-delta":case"reasoning-end":case"file":case"source-document":case"source-url":case"tool-input-start":case"tool-input-delta":le.debug(C.type,{chunk:C});break e;default:if(pc(C)){le.debug("Data chunk",{chunk:C});break e}xs(C)}},e[13]=a,e[14]=n,e[15]=u,e[16]=f,e[17]=m):m=e[17];let g=m,v;return e[18]!==a||e[19]!==s||e[20]!==u||e[21]!==b||e[22]!==k||e[23]!==g||e[24]!==r||e[25]!==f?(v={createStagedCell:u,updateStagedCell:f,addStagedCell:a,removeStagedCell:r,clearStagedCells:s,deleteStagedCell:k,deleteAllStagedCells:b,onStream:g},e[18]=a,e[19]=s,e[20]=u,e[21]=b,e[22]=k,e[23]=g,e[24]=r,e[25]=f,e[26]=v):v=e[26],v}var cc=class{constructor(t,e,a,r){D(this,"createdCells",[]);D(this,"buffer","");D(this,"hasMarimoImport",!1);this.onCreateCell=t,this.onUpdateCell=e,this.addStagedCell=a,this.createNewCell=r}stream(t){let e=t.delta;this.buffer+=e;let a=dc(this.buffer);for(let[r,s]of a.entries())if(r<this.createdCells.length){this.addMarimoImport(s.language);let n=this.createdCells[r];this.createdCells[r]={...n,cell:s},this.onUpdateCell({cellId:n.cellId,code:s.code,language:s.language})}else{let n=this.onCreateCell(s.code);this.createdCells.push({cellId:n,cell:s})}}addMarimoImport(t){var a;if(this.hasMarimoImport||t==="python")return;let e=Wo({autoInstantiate:!1,createNewCell:this.createNewCell,fromCellId:(a=this.createdCells[0])==null?void 0:a.cellId,before:!0});e&&this.addStagedCell({cellId:e,edit:{type:"add_cell"}}),this.hasMarimoImport=!0}stop(){this.buffer=""}};function pc(t){return t.type.startsWith("data-")}var mc={baseDescription:"Perform editing operations on the current notebook. You should prefer to create new cells unless you need to edit existing cells. Call this tool multiple times to perform multiple edits. Separate code into logical individual cells to take advantage of the notebook's reactive execution model.",prerequisites:["If you are updating existing cells, you need the cellIds. If they are not known, call the lightweight_cell_map_tool to find out."],additionalInfo:`
34
34
  Args:
35
35
  edit (object): The editing operation to perform with the following structure:
36
36
  - type: One of "update_cell", "add_cell", or "delete_cell"
@@ -54,7 +54,7 @@ Image URL: ${a.imageUrl}`)),Bt({type:this.contextType,data:o,details:i})}async g
54
54
  - 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.
55
55
 
56
56
  Returns:
57
- - A result object containing standard tool metadata.`},hc=A({edit:A({type:mt(["update_cell","add_cell","delete_cell"]),code:h().optional(),position:A({type:mt(["relative","column_end","notebook_end"]).optional(),cellId:h().optional(),columnIndex:ms().optional(),before:U().optional()})})}),fc=class{constructor(){D(this,"name","edit_notebook_tool");D(this,"description",mc);D(this,"schema",hc);D(this,"outputSchema",Vn);D(this,"mode",["agent"]);D(this,"handler",async({edit:t},e)=>{let{addStagedCell:a,createNewCell:r,store:s}=e;switch(t.type){case"update_cell":{let{position:n,code:o}=t,i=n.cellId;if(i){if(!o)throw new Ie("Code is required for update_cell","CODE_REQUIRED_FOR_UPDATE_CELL",!0,"Provide the new code to update the cell")}else throw new Ie("Cell ID is required for update_cell","CELL_ID_REQUIRED_FOR_UPDATE_CELL",!0,"Provide a cell ID to update");let l=s.get(Xe);this.validateCellIdExists(i,l);let d=this.getCellEditorView(i,l);Qa(i);let u=s.get(sa).get(i);if((u==null?void 0:u.type)==="add_cell"){Ja(d,o);break}let p=d.state.doc.toString(),f=(u==null?void 0:u.previousCode)??p;if(o===f)break;a({cellId:i,edit:{type:"update_cell",previousCode:f}}),Ja(d,o);break}case"add_cell":{let{position:n,code:o}=t,i="__end__",l=!1,d=ls.create(),u=s.get(Xe);switch(n.type){case"relative":{let p=n.cellId;if(!p)throw new Ie("Cell ID is required for add_cell with relative position","TOOL_ERROR",!0,"Provide a cell ID to add the cell before");if(n.before===void 0)throw new Ie("Before is required for add_cell with relative position","TOOL_ERROR",!0,`Provide a boolean value for before, true to add before cell ${p}, false to add after the cell`);this.validateCellIdExists(p,u),i=p,l=n.before;break}case"column_end":if(!n.columnIndex)throw new Ie("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");i={type:"__end__",columnId:this.getColumnId(n.columnIndex,u)};break;case"notebook_end":break}r({cellId:i,before:l,code:o,newCellId:d}),a({cellId:d,edit:{type:"add_cell"}}),Qa(d);break}case"delete_cell":{let{position:n}=t,o=n.cellId;if(!o)throw new Ie("Cell ID is required for delete_cell","CELL_ID_REQUIRED_FOR_DELETE_CELL",!0,"Provide a cell ID to delete");let i=s.get(Xe);this.validateCellIdExists(o,i),a({cellId:o,edit:{type:"delete_cell",previousCode:this.getCellEditorView(o,i).state.doc.toString()}}),Qa(o);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(t,e){if(!e.cellIds.getColumns().some(a=>a.idSet.has(t)))throw new Ie("Cell not found","CELL_NOT_FOUND",!1,"Check which cells exist in the notebook")}getColumnId(t,e){let a=e.cellIds.getColumns();if(t<0||t>=a.length)throw new Ie("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 a[t].id}getCellEditorView(t,e){let a=e.cellHandles[t].current;if(!(a!=null&&a.editorView))throw new Ie("Cell editor not found","CELL_EDITOR_NOT_FOUND",!1,"Internal error, ask the user to report this error");return a.editorView}},gc=200,yc=3e4,Xn=2e3,vc=3e3,xc=4e4,bc={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."},ei=A({type:w("file"),url:h(),mediaType:h()}),_c=class{constructor(t){D(this,"name","run_stale_cells_tool");D(this,"description",bc);D(this,"schema",A({}));D(this,"outputSchema",Vn.extend({cellsToOutput:pt(h(),A({consoleOutput:h().optional(),cellOutput:h().optional(),consoleAttachments:Se(ei).optional(),cellAttachments:Se(ei).optional()}).nullable()).optional()}));D(this,"mode",["agent"]);D(this,"handler",async(t,e)=>{let{prepareForRun:a,sendRun:r,store:s}=e,n=s.get(Xe),o=Yi(n);if(o.length===0)return{status:"success",message:"No stale cells found."};if(await Uo({cellIds:o,sendRun:r,prepareForRun:a,notebook:n}),!await this.waitForCellsToFinish(s,o,yc,this.postExecutionDelay))return{status:"success",message:"No output was returned because some cells have not finished executing"};let i=s.get(Xe),l=new Map,d=!1,u=!1,p=0;for(let y of o){let k=Bn(y,i,{includeConsoleOutput:!0}),c=k.cellOutput,b=k.consoleOutputs,m=b&&b.length>0;if((c&&this.outputHasErrors(c)||m&&b.some(C=>this.outputHasErrors(C)))&&(d=!0),!c&&!m){l.set(y,null);continue}if(p>=xc){l.set(y,{cellOutput:"Cell executed (output omitted due to context limits)."});continue}let g,v;c&&(g=this.formatOutputString(c),p+=g.length),m&&(u=!0,v=b.map(C=>this.formatOutputString(C)).join(`
57
+ - A result object containing standard tool metadata.`},hc=A({edit:A({type:mt(["update_cell","add_cell","delete_cell"]),code:h().optional(),position:A({type:mt(["relative","column_end","notebook_end"]).optional(),cellId:h().optional(),columnIndex:ms().optional(),before:U().optional()})})}),fc=class{constructor(){D(this,"name","edit_notebook_tool");D(this,"description",mc);D(this,"schema",hc);D(this,"outputSchema",Vn);D(this,"mode",["agent"]);D(this,"handler",async({edit:t},e)=>{let{addStagedCell:a,createNewCell:r,store:s}=e;switch(t.type){case"update_cell":{let{position:n,code:o}=t,i=n.cellId;if(i){if(!o)throw new Ie("Code is required for update_cell","CODE_REQUIRED_FOR_UPDATE_CELL",!0,"Provide the new code to update the cell")}else throw new Ie("Cell ID is required for update_cell","CELL_ID_REQUIRED_FOR_UPDATE_CELL",!0,"Provide a cell ID to update");let l=s.get(Xe);this.validateCellIdExists(i,l);let d=this.getCellEditorView(i,l);Qa(i);let u=s.get(sa).get(i);if((u==null?void 0:u.type)==="add_cell"){Ja(d,o);break}let p=d.state.doc.toString(),f=(u==null?void 0:u.previousCode)??p;if(o===f)break;a({cellId:i,edit:{type:"update_cell",previousCode:f}}),Ja(d,o);break}case"add_cell":{let{position:n,code:o}=t,i="__end__",l=!1,d=us.create(),u=s.get(Xe);switch(n.type){case"relative":{let p=n.cellId;if(!p)throw new Ie("Cell ID is required for add_cell with relative position","TOOL_ERROR",!0,"Provide a cell ID to add the cell before");if(n.before===void 0)throw new Ie("Before is required for add_cell with relative position","TOOL_ERROR",!0,`Provide a boolean value for before, true to add before cell ${p}, false to add after the cell`);this.validateCellIdExists(p,u),i=p,l=n.before;break}case"column_end":if(!n.columnIndex)throw new Ie("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");i={type:"__end__",columnId:this.getColumnId(n.columnIndex,u)};break;case"notebook_end":break}r({cellId:i,before:l,code:o,newCellId:d}),a({cellId:d,edit:{type:"add_cell"}}),Qa(d);break}case"delete_cell":{let{position:n}=t,o=n.cellId;if(!o)throw new Ie("Cell ID is required for delete_cell","CELL_ID_REQUIRED_FOR_DELETE_CELL",!0,"Provide a cell ID to delete");let i=s.get(Xe);this.validateCellIdExists(o,i),a({cellId:o,edit:{type:"delete_cell",previousCode:this.getCellEditorView(o,i).state.doc.toString()}}),Qa(o);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(t,e){if(!e.cellIds.getColumns().some(a=>a.idSet.has(t)))throw new Ie("Cell not found","CELL_NOT_FOUND",!1,"Check which cells exist in the notebook")}getColumnId(t,e){let a=e.cellIds.getColumns();if(t<0||t>=a.length)throw new Ie("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 a[t].id}getCellEditorView(t,e){let a=e.cellHandles[t].current;if(!(a!=null&&a.editorView))throw new Ie("Cell editor not found","CELL_EDITOR_NOT_FOUND",!1,"Internal error, ask the user to report this error");return a.editorView}},gc=200,yc=3e4,Xn=2e3,vc=3e3,xc=4e4,bc={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."},ei=A({type:w("file"),url:h(),mediaType:h()}),_c=class{constructor(t){D(this,"name","run_stale_cells_tool");D(this,"description",bc);D(this,"schema",A({}));D(this,"outputSchema",Vn.extend({cellsToOutput:pt(h(),A({consoleOutput:h().optional(),cellOutput:h().optional(),consoleAttachments:Se(ei).optional(),cellAttachments:Se(ei).optional()}).nullable()).optional()}));D(this,"mode",["agent"]);D(this,"handler",async(t,e)=>{let{prepareForRun:a,sendRun:r,store:s}=e,n=s.get(Xe),o=qi(n);if(o.length===0)return{status:"success",message:"No stale cells found."};if(await Uo({cellIds:o,sendRun:r,prepareForRun:a,notebook:n}),!await this.waitForCellsToFinish(s,o,yc,this.postExecutionDelay))return{status:"success",message:"No output was returned because some cells have not finished executing"};let i=s.get(Xe),l=new Map,d=!1,u=!1,p=0;for(let y of o){let k=Bn(y,i,{includeConsoleOutput:!0}),c=k.cellOutput,b=k.consoleOutputs,m=b&&b.length>0;if((c&&this.outputHasErrors(c)||m&&b.some(C=>this.outputHasErrors(C)))&&(d=!0),!c&&!m){l.set(y,null);continue}if(p>=xc){l.set(y,{cellOutput:"Cell executed (output omitted due to context limits)."});continue}let g,v;c&&(g=this.formatOutputString(c),p+=g.length),m&&(u=!0,v=b.map(C=>this.formatOutputString(C)).join(`
58
58
  `),v=this.truncateString(v,Xn),p+=v.length),l.set(y,{cellOutput:g,consoleOutput:v})}if(l.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.",d?"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(l),message:u?"Console output represents the stdout or stderr of the cell (eg. print statements).":void 0,next_steps:f}});this.postExecutionDelay=(t==null?void 0:t.postExecutionDelay)??gc}outputHasErrors(t){return t.output.mimetype==="application/vnd.marimo+error"||t.output.mimetype==="application/vnd.marimo+traceback"}formatOutputString(t){let{outputType:e,processedContent:a,imageUrl:r,output:s}=t;if(e==="media"){let i=`Media Output: Contains ${s.mimetype} content`;return r?`${i}
59
59
  Image URL: ${r}`:i}if(s.mimetype==="text/html")return`HTML Output: text/html content (${(typeof s.data=="string"?s.data.length:JSON.stringify(s.data).length).toLocaleString()} chars). Full output visible in notebook UI.`;let n=this.outputHasErrors(t)?vc:Xn,o=a;return o||(o=typeof s.data=="string"?s.data:JSON.stringify(s.data)),`Output:
60
60
  ${this.truncateString(o,n)}`}truncateString(t,e){return t.length<=e?t:`${t.slice(0,e)}
@@ -78,8 +78,8 @@ ${this.truncateString(o,n)}`}truncateString(t,e){return t.length<=e?t:`${t.slice
78
78
  - `)}`),t.additionalInfo&&(e+=`
79
79
 
80
80
  ## Additional info:
81
- - ${t.additionalInfo}`),e}var ti,na;function kc(t,e,a,r,s){var n={};return Object.keys(r).forEach(function(o){n[o]=r[o]}),n.enumerable=!!n.enumerable,n.configurable=!!n.configurable,("value"in n||n.initializer)&&(n.writable=!0),n=a.slice().reverse().reduce(function(o,i){return i(t,e,o)||o},n),s&&n.initializer!==void 0&&(n.value=n.initializer?n.initializer.call(s):void 0,n.initializer=void 0),n.initializer===void 0?(Object.defineProperty(t,e,n),null):n}const Jr=new(ti=Li(),na=class{constructor(t=[]){D(this,"tools",new Map);this.tools=new Map(t.map(e=>[e.name,e]))}has(t){return this.tools.has(t)}getToolOrThrow(t){let e=this.tools.get(t);if(!e)throw Error(`Tool ${t} not found`);return e}async invoke({toolName:t,rawArgs:e,toolContext:a}){var i;let r=this.getToolOrThrow(t),s=r.handler,n=r.schema,o=r.outputSchema;try{let l=await n.safeParseAsync(e);if(l.error)throw new Ie(`Tool ${t} returned invalid input: ${ps(l.error)}`,"INVALID_ARGUMENTS",!0,"Please check the arguments and try again.");let d=l.data,u=await s(d,a),p=await o.safeParseAsync(u);if(p.error){let f=ps(p.error);throw Error(`Tool ${t} returned invalid output: ${f}`)}return{tool_name:t,result:p.data,error:null}}catch(l){return l instanceof Ie?{tool_name:t,result:null,error:l.toStructuredString()}:{tool_name:t,result:null,error:new Ie(l instanceof Error?l.message:String(l),"TOOL_ERROR",!1,"Check the error message and try again with valid arguments.",{args:e,errorType:((i=l==null?void 0:l.constructor)==null?void 0:i.name)??typeof l}).toStructuredString()}}}getToolSchemas(t){return[...this.tools.values()].filter(e=>e.mode.includes(t)).map(e=>({name:e.name,description:wc(e.description),parameters:hs(e.schema),source:"frontend",mode:e.mode}))}},kc(na.prototype,"getToolSchemas",[ti],Object.getOwnPropertyDescriptor(na.prototype,"getToolSchemas"),na.prototype),na)([new fc,new _c]);var Cc=Wt();const ai=new Set(["openai","google","anthropic"]),Ic=["image/*","text/*"];var Ec=1024*1024*50;function Tc(t){return t.length>50?`${t.slice(0,50)}...`:t}async function ri(t){return await Promise.all(t.map(async e=>({type:"file",mediaType:e.type,filename:e.name,url:await So(e,"dataUrl")})))}function Sc(t){if(t.length===0)return!1;let e=t.at(-1);if(!e||e.role!=="assistant"||!e.parts)return!1;let a=e.parts;return a.length===0?!1:a[a.length-1].type==="reasoning"}function Ac(t){return t.map(e=>e.type==="text"?e.text:"").join(`
82
- `)}async function si(t){let e=await ic({input:Ac(t.flatMap(r=>r.parts))});function a(r,s){return s?{...r,parts:[...r.parts,...e.attachments]}:r}return{...e.body,uiMessages:t.map((r,s)=>a(r,s===t.length-1))}}async function ni({invokeAiTool:t,addToolOutput:e,toolCall:a,toolContext:r}){try{if(Jr.has(a.toolName)){let s=await Jr.invoke({toolName:a.toolName,rawArgs:a.input,toolContext:r});e({tool:a.toolName,toolCallId:a.toolCallId,output:s.result||s.error})}else{let s=await t({toolName:a.toolName,arguments:a.input??{}});e({tool:a.toolName,toolCallId:a.toolCallId,output:s.result||s.error})}}catch(s){le.error("Tool call failed:",s),e({tool:a.toolName,toolCallId:a.toolCallId,output:`Error: ${s instanceof Error?s.message:String(s)}`})}}function Oc(t){let e=t.at(-1);if(!e||e.role!=="assistant")return!1;let a=e.parts.at(-1);return!a||!wt(a)?!1:mu({messages:t})||pu({messages:t})}function ii(){let t=(0,Cc.c)(7),e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=[],t[0]=e):e=t[0];let[a,r]=(0,N.useState)(e),s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=p=>{if(p.length!==0){if(p.reduce(Rc,0)>Ec){Ga({title:"File size exceeded",description:"Attachments must be under 50 MB",variant:"danger"});return}r(f=>[...f,...p])}},t[1]=s):s=t[1];let n=ns(s),o;t[2]===Symbol.for("react.memo_cache_sentinel")?(o=()=>r([]),t[2]=o):o=t[2];let i=o,l;t[3]===Symbol.for("react.memo_cache_sentinel")?(l=p=>r(f=>f.filter(y=>y!==p)),t[3]=l):l=t[3];let d=l,u;return t[4]!==n||t[5]!==a?(u={files:a,addFiles:n,clearFiles:i,removeFile:d},t[4]=n,t[5]=a,t[6]=u):u=t[6],u}function Rc(t,e){return t+e.size}var qt=Wt(),E=Ba(lo(),1);const Nc=t=>{var o;let e=(0,qt.c)(6),{attachment:a}=t;if((o=a.mediaType)!=null&&o.startsWith("image/")){let i=a.filename||"Attachment",l;return e[0]!==a.url||e[1]!==i?(l=(0,E.jsx)("img",{src:a.url,alt:i,className:"max-h-[100px] max-w-[100px] object-contain mb-1.5"}),e[0]=a.url,e[1]=i,e[2]=l):l=e[2],l}let r;e[3]===Symbol.for("react.memo_cache_sentinel")?(r=(0,E.jsx)(ws,{className:"h-3 w-3 mt-0.5"}),e[3]=r):r=e[3];let s=a.filename||"Attachment",n;return e[4]===s?n=e[5]:(n=(0,E.jsxs)("div",{className:"flex flex-row gap-1 items-center text-xs",children:[r,s]}),e[4]=s,e[5]=n),n},oi=t=>{let e=(0,qt.c)(12),{file:a,className:r,onRemove:s}=t,[n,o]=(0,N.useState)(!1),i;e[0]===r?i=e[1]:(i=Ka("py-1 px-1.5 bg-muted rounded-md cursor-pointer flex flex-row gap-1 items-center text-xs",r),e[0]=r,e[1]=i);let l,d;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=()=>o(!0),d=()=>o(!1),e[2]=l,e[3]=d):(l=e[2],d=e[3]);let u;e[4]!==a||e[5]!==n||e[6]!==s?(u=n?(0,E.jsx)(bs,{className:"h-3 w-3 mt-0.5",onClick:s}):Mc(a),e[4]=a,e[5]=n,e[6]=s,e[7]=u):u=e[7];let p;return e[8]!==a.name||e[9]!==i||e[10]!==u?(p=(0,E.jsxs)("div",{className:i,onMouseEnter:l,onMouseLeave:d,children:[u,a.name]}),e[8]=a.name,e[9]=i,e[10]=u,e[11]=p):p=e[11],p},li=t=>{let e=(0,qt.c)(12),{isLoading:a,onStop:r,onSendClick:s,isEmpty:n,showStopLabel:o}=t,i=o===void 0?!1:o,l;e[0]===i?l=e[1]:(l=i?(0,E.jsxs)("div",{className:"flex flex-row items-center gap-1 px-1.5",children:[(0,E.jsx)("span",{className:"text-xs text-error",children:"Stop"}),(0,E.jsx)(No,{size:"small"})]}):(0,E.jsx)(ks,{className:"size-4 text-error"}),e[0]=i,e[1]=l);let d=l,u=a?"Stop":"Submit",p=a?r:s,f=a?!1:n,y;e[2]!==a||e[3]!==d?(y=a?d:(0,E.jsx)(Is,{className:"h-3.5 w-3.5"}),e[2]=a,e[3]=d,e[4]=y):y=e[4];let k;e[5]!==p||e[6]!==f||e[7]!==y?(k=(0,E.jsx)(et,{variant:"text",size:"sm",className:"h-6 min-w-6 p-0 hover:bg-muted/30 cursor-pointer",onClick:p,disabled:f,children:y}),e[5]=p,e[6]=f,e[7]=y,e[8]=k):k=e[8];let c;return e[9]!==u||e[10]!==k?(c=(0,E.jsx)(ga,{content:u,children:k}),e[9]=u,e[10]=k,e[11]=c):c=e[11],c},di=t=>{let e=(0,qt.c)(4),{handleAddContext:a,isLoading:r}=t,s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=(0,E.jsx)(To,{className:"h-3.5 w-3.5"}),e[0]=s):s=e[0];let n;return e[1]!==a||e[2]!==r?(n=(0,E.jsx)(ga,{content:"Add context",children:(0,E.jsx)(et,{variant:"text",size:"icon",onClick:a,disabled:r,children:s})}),e[1]=a,e[2]=r,e[3]=n):n=e[3],n},ui=t=>{let e=(0,qt.c)(15),{fileInputRef:a,isLoading:r,onAddFiles:s}=t,n;e[0]===a?n=e[1]:(n=()=>{var f;return(f=a.current)==null?void 0:f.click()},e[0]=a,e[1]=n);let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=(0,E.jsx)(Cs,{className:"h-3.5 w-3.5"}),e[2]=o):o=e[2];let i;e[3]!==r||e[4]!==n?(i=(0,E.jsx)(ga,{content:"Attach a file",children:(0,E.jsx)(et,{variant:"text",size:"icon",onClick:n,disabled:r,children:o})}),e[3]=r,e[4]=n,e[5]=i):i=e[5];let l;e[6]===s?l=e[7]:(l=f=>{f.target.files&&s([...f.target.files])},e[6]=s,e[7]=l);let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=Ic.join(","),e[8]=d):d=e[8];let u;e[9]!==a||e[10]!==l?(u=(0,E.jsx)(Po,{ref:a,type:"file",multiple:!0,hidden:!0,onChange:l,accept:d}),e[9]=a,e[10]=l,e[11]=u):u=e[11];let p;return e[12]!==i||e[13]!==u?(p=(0,E.jsxs)(E.Fragment,{children:[i,u]}),e[12]=i,e[13]=u,e[14]=p):p=e[14],p};function Mc(t){let e="h-3 w-3 mt-0.5";return t.type.startsWith("image/")?(0,E.jsx)(Ro,{className:e}):t.type.startsWith("text/")?(0,E.jsx)(Hi,{className:e}):(0,E.jsx)(ws,{className:e})}const jc=t=>{let e=(0,qt.c)(15),{icon:a,title:r,subtitle:s,href:n}=t,o;e[0]===r?o=e[1]:(o=(0,E.jsx)("span",{className:"truncate font-medium",children:r}),e[0]=r,e[1]=o);let i;e[2]===s?i=e[3]:(i=s&&(0,E.jsxs)("span",{className:"truncate opacity-70",children:["(",s,")"]}),e[2]=s,e[3]=i);let l;e[4]!==a||e[5]!==o||e[6]!==i?(l=(0,E.jsxs)(E.Fragment,{children:[a,o,i]}),e[4]=a,e[5]=o,e[6]=i,e[7]=l):l=e[7];let d=l;if(n&&Fo(n)){let f=s??r,y;return e[8]!==d||e[9]!==n||e[10]!==f?(y=(0,E.jsx)("a",{href:n,target:"_blank",rel:"noopener noreferrer",title:f,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:d}),e[8]=d,e[9]=n,e[10]=f,e[11]=y):y=e[11],y}let u=s??r,p;return e[12]!==d||e[13]!==u?(p=(0,E.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:d}),e[12]=d,e[13]=u,e[14]=p):p=e[14],p},Kr=ya.define(),Ke=va.define({create(){return new Map},update(t,e){let a=!1,r=t;for(let s of e.effects)if(s.is(Kr)){a||(a=(r=new Map(t),!0));for(let[n,o]of s.value)r.set(n,o)}return r}}),Pc=va.define({create(){return{onResourceClick:void 0,onResourceMouseOver:void 0,onResourceMouseOut:void 0,onPromptSubmit:void 0}},update(t){return t}}),$c=ya.define();va.define({create(){return new Map},update(t,e){let a=!1,r=t;for(let s of e.effects)if(s.is($c)){a||(a=(r=new Map(t),!0));for(let[n,o]of s.value)r.set(n,o)}return r}});const Lc=(t,e)=>async a=>{let r=a.matchBefore(/@(\w+)?/);if(!r||r.from===r.to&&!a.explicit)return null;let s=await t();if(s.length===0)return null;let n=Kr.of(new Map(s.map(i=>[i.uri,i])));a.view&&a.view.dispatch({effects:n});let o=s.map(i=>({label:`@${i.name}`,displayLabel:i.name,detail:i.uri,info:i.description||void 0,type:i.mimeType?"constant":"variable",boost:i.description?100:0,...e==null?void 0:e(i),apply:(l,d,u,p)=>{l.dispatch({changes:{from:u,to:p,insert:`@${i.uri} `}})}}));return{from:r.from,options:o}},Dc=/@[\w-]+:\/\/(?!\/)[^\s]+/;function lt(t){return t.matchAll(new RegExp(Dc.source,"g"))}var Zc=class extends ys{constructor(e,a){super();D(this,"resource");D(this,"view");this.resource=e,this.view=a}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 a=this.view.state.field(Pc,!1),r=a==null?void 0:a.onResourceClick,s=a==null?void 0:a.onResourceMouseOver,n=a==null?void 0:a.onResourceMouseOut;return r&&(e.style.cursor="pointer",e.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),r(this.resource)})),s&&e.addEventListener("mouseover",o=>{o.preventDefault(),o.stopPropagation(),s(this.resource)}),n&&e.addEventListener("mouseout",o=>{o.preventDefault(),o.stopPropagation(),n(this.resource)}),e}},Fc=class extends ys{constructor(e,a){super();D(this,"uri");D(this,"view");this.uri=e,this.view=a}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 ci(t){let e=t.state.field(Ke),a=[];for(let{from:r,to:s}of t.visibleRanges){let n=t.state.doc.sliceString(r,s);for(let o of lt(n)){let i=r+o.index,l=o[0].slice(1),d=e.get(l);d?a.push(Ya.replace({widget:new Zc(d,t)}).range(i,i+o[0].length)):a.push(Ya.replace({widget:new Fc(l,t)}).range(i,i+o[0].length))}}return Ya.set(a)}const zc=xo.fromClass(class{constructor(t){D(this,"decorations");this.decorations=ci(t)}update(t){(t.docChanged||t.viewportChanged||t.transactions.some(e=>e.effects.some(a=>a.is(Kr))))&&(this.decorations=ci(t.view))}},{decorations:t=>t.decorations});function Uc(t){let e=document.createElement("div");e.className="cm-tooltip-cursor";let a=document.createElement("div");if(a.className="cm-tooltip-cursor-title",a.textContent=`${t.name} (${t.uri})`,e.appendChild(a),t.description){let r=document.createElement("div");r.className="cm-tooltip-cursor-description",r.textContent=t.description,e.appendChild(r)}if(t.mimeType){let r=document.createElement("div");r.className="cm-tooltip-cursor-mimetype",r.textContent=t.mimeType,e.appendChild(r)}return{dom:e}}function qc(t,e,a,r=0){for(let s of lt(t)){let n=r+s.index,o=n+s[0].length;if(e>=n&&e<=o){let i=s[0].slice(1),l=a.get(i);if(l)return{resource:l,start:n,end:o}}}return null}function Vc(t){return go((e,a)=>{let{from:r,text:s}=e.state.doc.lineAt(a),n=qc(s,a,e.state.field(Ke),r);return n?{pos:n.start,end:n.end,above:!0,create(){return(t.createTooltip??Uc)(n.resource)}}:null})}function Wc(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e),n=r.sliceString(s.from,s.to),o=Array.from(lt(n));if(o.length===0)return null;for(let i of o){let l=s.from+i.index,d=l+i[0].length,u=i[0].slice(1);if(e===d&&a.has(u))return{from:l,to:d,uri:u}}return null}function Bc(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e).to,n=r.sliceString(e,s),o=Array.from(lt(n));if(o.length===0)return null;let i=o[0];if(!i||i.index!==0)return null;let l=e,d=e+i[0].length,u=i[0].slice(1);return a.has(u)?{from:l,to:d,uri:u}:null}function pi(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e),n=r.sliceString(s.from,s.to),o=Array.from(lt(n));for(let i of o){let l=s.from+i.index,d=l+i[0].length,u=i[0].slice(1);if(e>l&&e<d&&a.has(u))return{from:l,to:d,uri:u}}return null}function Jc(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e),n=r.sliceString(s.from,e),o=Array.from(lt(n)),i=null;for(let l of o){let d=s.from+l.index,u=d+l[0].length,p=l[0].slice(1);a.has(p)&&u<=e&&(e>u?i=u:e===u&&(i=d))}return i}function Kc(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e),n=r.sliceString(s.from,s.to),o=Array.from(lt(n));for(let i of o){let l=s.from+i.index,d=l+i[0].length,u=i[0].slice(1);if(a.has(u)&&l>=e){if(e<l)return l;if(e===l)return d}}return null}const Yc=yo.transactionFilter.of(t=>{var r;let e=t.annotation(fo.userEvent);if(!e)return t;let a=t.startState.selection.main;if(!a.empty)return t;if(e==="input.type"||e.startsWith("input")){if(t.changes.empty)return t;let s=t.startState.field(Ke),n=t.startState.doc,o=!1,i=0,l=[];if(t.changes.iterChanges((d,u,p,f,y)=>{let k=y.toString(),c=d;if(/^\s+$/.test(k)){l.push({from:d,to:u,insert:k});return}let b=n.lineAt(c),m=n.sliceString(b.from,b.to),g=Array.from(lt(m)),v=!1,C=!1;for(let M of g){let Z=b.from+M.index,$=Z+M[0].length,K=M[0].slice(1);if(s.has(K)){if(c===Z){let P=c>0?n.sliceString(c-1,c):"";P!==""&&P!==" "&&P!==`
81
+ - ${t.additionalInfo}`),e}var ti,na;function kc(t,e,a,r,s){var n={};return Object.keys(r).forEach(function(o){n[o]=r[o]}),n.enumerable=!!n.enumerable,n.configurable=!!n.configurable,("value"in n||n.initializer)&&(n.writable=!0),n=a.slice().reverse().reduce(function(o,i){return i(t,e,o)||o},n),s&&n.initializer!==void 0&&(n.value=n.initializer?n.initializer.call(s):void 0,n.initializer=void 0),n.initializer===void 0?(Object.defineProperty(t,e,n),null):n}const Jr=new(ti=Ki(),na=class{constructor(t=[]){D(this,"tools",new Map);this.tools=new Map(t.map(e=>[e.name,e]))}has(t){return this.tools.has(t)}getToolOrThrow(t){let e=this.tools.get(t);if(!e)throw Error(`Tool ${t} not found`);return e}async invoke({toolName:t,rawArgs:e,toolContext:a}){var i;let r=this.getToolOrThrow(t),s=r.handler,n=r.schema,o=r.outputSchema;try{let l=await n.safeParseAsync(e);if(l.error)throw new Ie(`Tool ${t} returned invalid input: ${ps(l.error)}`,"INVALID_ARGUMENTS",!0,"Please check the arguments and try again.");let d=l.data,u=await s(d,a),p=await o.safeParseAsync(u);if(p.error){let f=ps(p.error);throw Error(`Tool ${t} returned invalid output: ${f}`)}return{tool_name:t,result:p.data,error:null}}catch(l){return l instanceof Ie?{tool_name:t,result:null,error:l.toStructuredString()}:{tool_name:t,result:null,error:new Ie(l instanceof Error?l.message:String(l),"TOOL_ERROR",!1,"Check the error message and try again with valid arguments.",{args:e,errorType:((i=l==null?void 0:l.constructor)==null?void 0:i.name)??typeof l}).toStructuredString()}}}getToolSchemas(t){return[...this.tools.values()].filter(e=>e.mode.includes(t)).map(e=>({name:e.name,description:wc(e.description),parameters:hs(e.schema),source:"frontend",mode:e.mode}))}},kc(na.prototype,"getToolSchemas",[ti],Object.getOwnPropertyDescriptor(na.prototype,"getToolSchemas"),na.prototype),na)([new fc,new _c]);var Cc=Wt();const ai=new Set(["openai","google","anthropic"]),Ic=["image/*","text/*"];var Ec=1024*1024*50;function Tc(t){return t.length>50?`${t.slice(0,50)}...`:t}async function ri(t){return await Promise.all(t.map(async e=>({type:"file",mediaType:e.type,filename:e.name,url:await So(e,"dataUrl")})))}function Sc(t){if(t.length===0)return!1;let e=t.at(-1);if(!e||e.role!=="assistant"||!e.parts)return!1;let a=e.parts;return a.length===0?!1:a[a.length-1].type==="reasoning"}function Ac(t){return t.map(e=>e.type==="text"?e.text:"").join(`
82
+ `)}async function si(t){let e=await ic({input:Ac(t.flatMap(r=>r.parts))});function a(r,s){return s?{...r,parts:[...r.parts,...e.attachments]}:r}return{...e.body,uiMessages:t.map((r,s)=>a(r,s===t.length-1))}}async function ni({invokeAiTool:t,addToolOutput:e,toolCall:a,toolContext:r}){try{if(Jr.has(a.toolName)){let s=await Jr.invoke({toolName:a.toolName,rawArgs:a.input,toolContext:r});e({tool:a.toolName,toolCallId:a.toolCallId,output:s.result||s.error})}else{let s=await t({toolName:a.toolName,arguments:a.input??{}});e({tool:a.toolName,toolCallId:a.toolCallId,output:s.result||s.error})}}catch(s){le.error("Tool call failed:",s),e({tool:a.toolName,toolCallId:a.toolCallId,output:`Error: ${s instanceof Error?s.message:String(s)}`})}}function Oc(t){let e=t.at(-1);if(!e||e.role!=="assistant")return!1;let a=e.parts.at(-1);return!a||!wt(a)?!1:mu({messages:t})||pu({messages:t})}function ii(){let t=(0,Cc.c)(7),e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=[],t[0]=e):e=t[0];let[a,r]=(0,N.useState)(e),s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=p=>{if(p.length!==0){if(p.reduce(Rc,0)>Ec){Ga({title:"File size exceeded",description:"Attachments must be under 50 MB",variant:"danger"});return}r(f=>[...f,...p])}},t[1]=s):s=t[1];let n=ns(s),o;t[2]===Symbol.for("react.memo_cache_sentinel")?(o=()=>r([]),t[2]=o):o=t[2];let i=o,l;t[3]===Symbol.for("react.memo_cache_sentinel")?(l=p=>r(f=>f.filter(y=>y!==p)),t[3]=l):l=t[3];let d=l,u;return t[4]!==n||t[5]!==a?(u={files:a,addFiles:n,clearFiles:i,removeFile:d},t[4]=n,t[5]=a,t[6]=u):u=t[6],u}function Rc(t,e){return t+e.size}var qt=Wt(),E=Ba(lo(),1);const Nc=t=>{var o;let e=(0,qt.c)(6),{attachment:a}=t;if((o=a.mediaType)!=null&&o.startsWith("image/")){let i=a.filename||"Attachment",l;return e[0]!==a.url||e[1]!==i?(l=(0,E.jsx)("img",{src:a.url,alt:i,className:"max-h-[100px] max-w-[100px] object-contain mb-1.5"}),e[0]=a.url,e[1]=i,e[2]=l):l=e[2],l}let r;e[3]===Symbol.for("react.memo_cache_sentinel")?(r=(0,E.jsx)(ws,{className:"h-3 w-3 mt-0.5"}),e[3]=r):r=e[3];let s=a.filename||"Attachment",n;return e[4]===s?n=e[5]:(n=(0,E.jsxs)("div",{className:"flex flex-row gap-1 items-center text-xs",children:[r,s]}),e[4]=s,e[5]=n),n},oi=t=>{let e=(0,qt.c)(12),{file:a,className:r,onRemove:s}=t,[n,o]=(0,N.useState)(!1),i;e[0]===r?i=e[1]:(i=Ka("py-1 px-1.5 bg-muted rounded-md cursor-pointer flex flex-row gap-1 items-center text-xs",r),e[0]=r,e[1]=i);let l,d;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=()=>o(!0),d=()=>o(!1),e[2]=l,e[3]=d):(l=e[2],d=e[3]);let u;e[4]!==a||e[5]!==n||e[6]!==s?(u=n?(0,E.jsx)(bs,{className:"h-3 w-3 mt-0.5",onClick:s}):Mc(a),e[4]=a,e[5]=n,e[6]=s,e[7]=u):u=e[7];let p;return e[8]!==a.name||e[9]!==i||e[10]!==u?(p=(0,E.jsxs)("div",{className:i,onMouseEnter:l,onMouseLeave:d,children:[u,a.name]}),e[8]=a.name,e[9]=i,e[10]=u,e[11]=p):p=e[11],p},li=t=>{let e=(0,qt.c)(12),{isLoading:a,onStop:r,onSendClick:s,isEmpty:n,showStopLabel:o}=t,i=o===void 0?!1:o,l;e[0]===i?l=e[1]:(l=i?(0,E.jsxs)("div",{className:"flex flex-row items-center gap-1 px-1.5",children:[(0,E.jsx)("span",{className:"text-xs text-error",children:"Stop"}),(0,E.jsx)(No,{size:"small"})]}):(0,E.jsx)(ks,{className:"size-4 text-error"}),e[0]=i,e[1]=l);let d=l,u=a?"Stop":"Submit",p=a?r:s,f=a?!1:n,y;e[2]!==a||e[3]!==d?(y=a?d:(0,E.jsx)(Is,{className:"h-3.5 w-3.5"}),e[2]=a,e[3]=d,e[4]=y):y=e[4];let k;e[5]!==p||e[6]!==f||e[7]!==y?(k=(0,E.jsx)(et,{variant:"text",size:"sm",className:"h-6 min-w-6 p-0 hover:bg-muted/30 cursor-pointer",onClick:p,disabled:f,children:y}),e[5]=p,e[6]=f,e[7]=y,e[8]=k):k=e[8];let c;return e[9]!==u||e[10]!==k?(c=(0,E.jsx)(ga,{content:u,children:k}),e[9]=u,e[10]=k,e[11]=c):c=e[11],c},di=t=>{let e=(0,qt.c)(4),{handleAddContext:a,isLoading:r}=t,s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=(0,E.jsx)(To,{className:"h-3.5 w-3.5"}),e[0]=s):s=e[0];let n;return e[1]!==a||e[2]!==r?(n=(0,E.jsx)(ga,{content:"Add context",children:(0,E.jsx)(et,{variant:"text",size:"icon",onClick:a,disabled:r,children:s})}),e[1]=a,e[2]=r,e[3]=n):n=e[3],n},ui=t=>{let e=(0,qt.c)(15),{fileInputRef:a,isLoading:r,onAddFiles:s}=t,n;e[0]===a?n=e[1]:(n=()=>{var f;return(f=a.current)==null?void 0:f.click()},e[0]=a,e[1]=n);let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=(0,E.jsx)(Cs,{className:"h-3.5 w-3.5"}),e[2]=o):o=e[2];let i;e[3]!==r||e[4]!==n?(i=(0,E.jsx)(ga,{content:"Attach a file",children:(0,E.jsx)(et,{variant:"text",size:"icon",onClick:n,disabled:r,children:o})}),e[3]=r,e[4]=n,e[5]=i):i=e[5];let l;e[6]===s?l=e[7]:(l=f=>{f.target.files&&s([...f.target.files])},e[6]=s,e[7]=l);let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=Ic.join(","),e[8]=d):d=e[8];let u;e[9]!==a||e[10]!==l?(u=(0,E.jsx)(Po,{ref:a,type:"file",multiple:!0,hidden:!0,onChange:l,accept:d}),e[9]=a,e[10]=l,e[11]=u):u=e[11];let p;return e[12]!==i||e[13]!==u?(p=(0,E.jsxs)(E.Fragment,{children:[i,u]}),e[12]=i,e[13]=u,e[14]=p):p=e[14],p};function Mc(t){let e="h-3 w-3 mt-0.5";return t.type.startsWith("image/")?(0,E.jsx)(Ro,{className:e}):t.type.startsWith("text/")?(0,E.jsx)(Gi,{className:e}):(0,E.jsx)(ws,{className:e})}const jc=t=>{let e=(0,qt.c)(15),{icon:a,title:r,subtitle:s,href:n}=t,o;e[0]===r?o=e[1]:(o=(0,E.jsx)("span",{className:"truncate font-medium",children:r}),e[0]=r,e[1]=o);let i;e[2]===s?i=e[3]:(i=s&&(0,E.jsxs)("span",{className:"truncate opacity-70",children:["(",s,")"]}),e[2]=s,e[3]=i);let l;e[4]!==a||e[5]!==o||e[6]!==i?(l=(0,E.jsxs)(E.Fragment,{children:[a,o,i]}),e[4]=a,e[5]=o,e[6]=i,e[7]=l):l=e[7];let d=l;if(n&&Fo(n)){let f=s??r,y;return e[8]!==d||e[9]!==n||e[10]!==f?(y=(0,E.jsx)("a",{href:n,target:"_blank",rel:"noopener noreferrer",title:f,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:d}),e[8]=d,e[9]=n,e[10]=f,e[11]=y):y=e[11],y}let u=s??r,p;return e[12]!==d||e[13]!==u?(p=(0,E.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:d}),e[12]=d,e[13]=u,e[14]=p):p=e[14],p},Kr=ya.define(),Ke=va.define({create(){return new Map},update(t,e){let a=!1,r=t;for(let s of e.effects)if(s.is(Kr)){a||(a=(r=new Map(t),!0));for(let[n,o]of s.value)r.set(n,o)}return r}}),Pc=va.define({create(){return{onResourceClick:void 0,onResourceMouseOver:void 0,onResourceMouseOut:void 0,onPromptSubmit:void 0}},update(t){return t}}),$c=ya.define();va.define({create(){return new Map},update(t,e){let a=!1,r=t;for(let s of e.effects)if(s.is($c)){a||(a=(r=new Map(t),!0));for(let[n,o]of s.value)r.set(n,o)}return r}});const Lc=(t,e)=>async a=>{let r=a.matchBefore(/@(\w+)?/);if(!r||r.from===r.to&&!a.explicit)return null;let s=await t();if(s.length===0)return null;let n=Kr.of(new Map(s.map(i=>[i.uri,i])));a.view&&a.view.dispatch({effects:n});let o=s.map(i=>({label:`@${i.name}`,displayLabel:i.name,detail:i.uri,info:i.description||void 0,type:i.mimeType?"constant":"variable",boost:i.description?100:0,...e==null?void 0:e(i),apply:(l,d,u,p)=>{l.dispatch({changes:{from:u,to:p,insert:`@${i.uri} `}})}}));return{from:r.from,options:o}},Dc=/@[\w-]+:\/\/(?!\/)[^\s]+/;function lt(t){return t.matchAll(new RegExp(Dc.source,"g"))}var Zc=class extends ys{constructor(e,a){super();D(this,"resource");D(this,"view");this.resource=e,this.view=a}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 a=this.view.state.field(Pc,!1),r=a==null?void 0:a.onResourceClick,s=a==null?void 0:a.onResourceMouseOver,n=a==null?void 0:a.onResourceMouseOut;return r&&(e.style.cursor="pointer",e.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),r(this.resource)})),s&&e.addEventListener("mouseover",o=>{o.preventDefault(),o.stopPropagation(),s(this.resource)}),n&&e.addEventListener("mouseout",o=>{o.preventDefault(),o.stopPropagation(),n(this.resource)}),e}},Fc=class extends ys{constructor(e,a){super();D(this,"uri");D(this,"view");this.uri=e,this.view=a}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 ci(t){let e=t.state.field(Ke),a=[];for(let{from:r,to:s}of t.visibleRanges){let n=t.state.doc.sliceString(r,s);for(let o of lt(n)){let i=r+o.index,l=o[0].slice(1),d=e.get(l);d?a.push(Ya.replace({widget:new Zc(d,t)}).range(i,i+o[0].length)):a.push(Ya.replace({widget:new Fc(l,t)}).range(i,i+o[0].length))}}return Ya.set(a)}const zc=xo.fromClass(class{constructor(t){D(this,"decorations");this.decorations=ci(t)}update(t){(t.docChanged||t.viewportChanged||t.transactions.some(e=>e.effects.some(a=>a.is(Kr))))&&(this.decorations=ci(t.view))}},{decorations:t=>t.decorations});function Uc(t){let e=document.createElement("div");e.className="cm-tooltip-cursor";let a=document.createElement("div");if(a.className="cm-tooltip-cursor-title",a.textContent=`${t.name} (${t.uri})`,e.appendChild(a),t.description){let r=document.createElement("div");r.className="cm-tooltip-cursor-description",r.textContent=t.description,e.appendChild(r)}if(t.mimeType){let r=document.createElement("div");r.className="cm-tooltip-cursor-mimetype",r.textContent=t.mimeType,e.appendChild(r)}return{dom:e}}function qc(t,e,a,r=0){for(let s of lt(t)){let n=r+s.index,o=n+s[0].length;if(e>=n&&e<=o){let i=s[0].slice(1),l=a.get(i);if(l)return{resource:l,start:n,end:o}}}return null}function Vc(t){return go((e,a)=>{let{from:r,text:s}=e.state.doc.lineAt(a),n=qc(s,a,e.state.field(Ke),r);return n?{pos:n.start,end:n.end,above:!0,create(){return(t.createTooltip??Uc)(n.resource)}}:null})}function Wc(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e),n=r.sliceString(s.from,s.to),o=Array.from(lt(n));if(o.length===0)return null;for(let i of o){let l=s.from+i.index,d=l+i[0].length,u=i[0].slice(1);if(e===d&&a.has(u))return{from:l,to:d,uri:u}}return null}function Bc(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e).to,n=r.sliceString(e,s),o=Array.from(lt(n));if(o.length===0)return null;let i=o[0];if(!i||i.index!==0)return null;let l=e,d=e+i[0].length,u=i[0].slice(1);return a.has(u)?{from:l,to:d,uri:u}:null}function pi(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e),n=r.sliceString(s.from,s.to),o=Array.from(lt(n));for(let i of o){let l=s.from+i.index,d=l+i[0].length,u=i[0].slice(1);if(e>l&&e<d&&a.has(u))return{from:l,to:d,uri:u}}return null}function Jc(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e),n=r.sliceString(s.from,e),o=Array.from(lt(n)),i=null;for(let l of o){let d=s.from+l.index,u=d+l[0].length,p=l[0].slice(1);a.has(p)&&u<=e&&(e>u?i=u:e===u&&(i=d))}return i}function Kc(t,e){let a=t.field(Ke),r=t.doc,s=r.lineAt(e),n=r.sliceString(s.from,s.to),o=Array.from(lt(n));for(let i of o){let l=s.from+i.index,d=l+i[0].length,u=i[0].slice(1);if(a.has(u)&&l>=e){if(e<l)return l;if(e===l)return d}}return null}const Yc=yo.transactionFilter.of(t=>{var r;let e=t.annotation(fo.userEvent);if(!e)return t;let a=t.startState.selection.main;if(!a.empty)return t;if(e==="input.type"||e.startsWith("input")){if(t.changes.empty)return t;let s=t.startState.field(Ke),n=t.startState.doc,o=!1,i=0,l=[];if(t.changes.iterChanges((d,u,p,f,y)=>{let k=y.toString(),c=d;if(/^\s+$/.test(k)){l.push({from:d,to:u,insert:k});return}let b=n.lineAt(c),m=n.sliceString(b.from,b.to),g=Array.from(lt(m)),v=!1,C=!1;for(let M of g){let Z=b.from+M.index,$=Z+M[0].length,K=M[0].slice(1);if(s.has(K)){if(c===Z){let P=c>0?n.sliceString(c-1,c):"";P!==""&&P!==" "&&P!==`
83
83
  `&&P!==" "&&(v=!0)}if(c===$){let P=c<n.length?n.sliceString(c,c+1):"";(P===""||P!==" "&&P!==`
84
84
  `&&P!==" ")&&(C=!0)}}}let T=k;v&&(T=` ${T}`,i+=1),C&&(T=` ${T}`,i+=1),T!==k&&(o=!0),l.push({from:d,to:u,insert:T})}),o)return[{changes:l,selection:t.selection?{anchor:t.selection.main.anchor+i,head:t.selection.main.head+i}:void 0,scrollIntoView:t.scrollIntoView}]}if(e==="delete.backward"||e==="delete.forward"){let s=null;return e==="delete.backward"?s=Wc(t.startState,a.head):e==="delete.forward"&&(s=Bc(t.startState,a.head)),s?[{changes:{from:s.from,to:s.to,insert:""},selection:{anchor:s.from},scrollIntoView:!0}]:t}if((r=t.selection)!=null&&r.main.empty&&a.empty&&!e.startsWith("input")&&e!=="input.type"){let s=a.head,n=t.selection.main.head,o=null;if(n<s){let i=pi(t.startState,s);o=i&&s>i.from?i.from:Jc(t.startState,s)}else if(n>s){let i=pi(t.startState,s);o=i&&s<i.to?i.to:Kc(t.startState,s)}if(o!==null&&o!==n)return[{selection:{anchor:o},scrollIntoView:!0}]}return t}),Hc=vs.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"}});var mi="_none_",Gc=[{uri:"",name:"No resources",type:mi,data:{}}],Qc={info:"Variables, dataframes, and tables will appear here.",apply:()=>{}};function Xc(t){let{language:e,store:a,onAddFiles:r}=t;return[e.data.of({autocomplete:Lc(async()=>{let s=Ct(a).getAllItems();return s.length===0?Gc:s},s=>{var n;return s.type===mi?Qc:((n=Ct(a).getProvider(s.type))==null?void 0:n.formatCompletion(s))||{}})}),gs.high(xa.of([{key:"Tab",preventDefault:!0,run:s=>wo(s)}])),Kn.of({addAttachment:s=>r==null?void 0:r([s])}),...r?[e.data.of({autocomplete:rc().createCompletionSource()})]:[],zc,Yc,Ke.init(()=>{let s=Ct(a).getAllItems();return new Map(s.map(n=>[n.uri,n]))}),Hc,Vc({createTooltip:s=>{let n=Ct(a).getProvider(s.type);if(!n)return le.warn("No provider found for resource",s),ia(s.description||s.name);let o=n.formatCompletion(s),i=s.description||s.name;if(!(o!=null&&o.info))return ia(i);if(typeof o.info=="string")return ia(o.info);let l=o.info(o);return l?"dom"in l?{dom:l.dom}:"then"in l?(le.warn("info is a promise. This is not supported",l),ia(i)):{dom:l}:ia(i)}})]}function ia(t){let e=document.createElement("div");return e.innerHTML=t,{dom:e}}var Yr=Wt();const hi=t=>{let{handleAcceptCompletion:e,handleDeclineCompletion:a,isLoading:r,hasCompletion:s}=t;return n=>{let o=no()?n.metaKey:n.ctrlKey;o&&n.key==="Enter"&&!r&&s&&e(),(n.key==="Delete"||n.key==="Backspace")&&o&&n.shiftKey&&(a(),n.preventDefault(),n.stopPropagation())}},ep=t=>{let e=(0,Yr.c)(9),{isLoading:a,onAccept:r,onDecline:s,runCell:n}=t,o;e[0]!==a||e[1]!==r||e[2]!==n?(o=(0,E.jsx)(fi,{isLoading:a,onAccept:r,size:"xs",runCell:n}),e[0]=a,e[1]=r,e[2]=n,e[3]=o):o=e[3];let i;e[4]===s?i=e[5]:(i=(0,E.jsx)(gi,{onDecline:s,size:"xs"}),e[4]=s,e[5]=i);let l;return e[6]!==o||e[7]!==i?(l=(0,E.jsxs)(E.Fragment,{children:[o,i]}),e[6]=o,e[7]=i,e[8]=l):l=e[8],l},fi=t=>{let e=(0,Yr.c)(33),{isLoading:a,onAccept:r,multipleCompletions:s,size:n,buttonStyles:o,acceptShortcut:i,runCell:l,playButtonStyles:d,borderless:u}=t,p=s===void 0?!1:s,f=n===void 0?"sm":n,y=u===void 0?!1:u,k;e[0]!==r||e[1]!==l?(k=()=>{r(),l&&l()},e[0]=r,e[1]=l,e[2]=k):k=e[2];let c=k,b=p?"Accept all":"Accept";if(l){let C=`h-6 text-(--grass-11) bg-(--grass-3)/60
85
85
  hover:bg-(--grass-3) dark:bg-(--grass-4)/80 dark:hover:bg-(--grass-3) font-semibold
@@ -93,5 +93,5 @@ ${this.truncateString(o,n)}`}truncateString(t,e){return t.length<=e?t:`${t.slice
93
93
  border-(--green-6) border hover:shadow-xs rounded px-3 ${o}`,g;e[24]===i?g=e[25]:(g=i&&(0,E.jsx)(Xa,{className:"ml-1 inline",shortcut:i}),e[24]=i,e[25]=g);let v;return e[26]!==a||e[27]!==r||e[28]!==f||e[29]!==m||e[30]!==g||e[31]!==b?(v=(0,E.jsxs)(et,{variant:"text",size:f,disabled:a,onClick:r,className:m,children:[b,g]}),e[26]=a,e[27]=r,e[28]=f,e[29]=m,e[30]=g,e[31]=b,e[32]=v):v=e[32],v},gi=t=>{let e=(0,Yr.c)(8),{onDecline:a,multipleCompletions:r,size:s,className:n,declineShortcut:o,borderless:i}=t,l=r===void 0?!1:r,d=s===void 0?"sm":s,u=`h-6 text-(--red-10) bg-(--red-3)/60 hover:bg-(--red-3)
94
94
  dark:bg-(--red-4)/80 dark:hover:bg-(--red-3) rounded px-3 font-semibold
95
95
  active:bg-(--red-5) dark:active:bg-(--red-4)
96
- border-(--red-6) border hover:shadow-xs ${(i===void 0?!1:i)&&"border-none rounded-md"} ${n}`,p=l&&" all",f;e[0]===o?f=e[1]:(f=o&&(0,E.jsx)(Xa,{className:"ml-1 inline",shortcut:o}),e[0]=o,e[1]=f);let y;return e[2]!==a||e[3]!==d||e[4]!==u||e[5]!==p||e[6]!==f?(y=(0,E.jsxs)(et,{variant:"text",size:d,onClick:a,className:u,children:["Reject",p,f]}),e[2]=a,e[3]=d,e[4]=u,e[5]=p,e[6]=f,e[7]=y):y=e[7],y};var tp=class extends Er{constructor(t,e){super(t),this.onChunkReceived=e}processResponseStream(t){let e=this.onChunkReceived;return super.processResponseStream(t).pipeThrough(new TransformStream({async transform(a,r){e(a),r.enqueue(a)}}))}},yi=Wt(),ap=Bi("marimo:ai-language","python",Zi),vi="marimo:ai-prompt-history",xi=new Gi(Se(h()),()=>[]);const rp=t=>{var as;let e=(0,yi.c)(98),{onClose:a}=t,r=rs(),[s,n]=(0,N.useState)(""),{deleteAllStagedCells:o,clearStagedCells:i,onStream:l,addStagedCell:d}=Qn(r),[u,p]=Mi(ap),f=oo(),{invokeAiTool:y,sendRun:k}=Io(),c=is(sa),b=(0,N.useRef)(null),m=(0,N.useRef)(null),{files:g,addFiles:v,removeFile:C}=ii(),T=is(io),{createNewCell:M,prepareForRun:Z}=os(),$;e[0]!==d||e[1]!==M||e[2]!==Z||e[3]!==k||e[4]!==r?($={store:r,addStagedCell:d,createNewCell:M,prepareForRun:Z,sendRun:k},e[0]=d,e[1]=M,e[2]=Z,e[3]=k,e[4]=r,e[5]=$):$=e[5];let K=$,P;if(e[6]!==u||e[7]!==l||e[8]!==f){let pe;e[10]===f?pe=e[11]:(pe=()=>f.headers(),e[10]=f,e[11]=pe);let $e;e[12]!==u||e[13]!==f?($e=async ha=>{let Si=await si(ha.messages),Ai={...ha,...Si,code:"",prompt:"",language:u};return{api:f.getAiURL("completion").toString(),body:Ai}},e[12]=u,e[13]=f,e[14]=$e):$e=e[14];let ma;e[15]===l?ma=e[16]:(ma=ha=>{l(ha)},e[15]=l,e[16]=ma),P=new tp({api:f.getAiURL("completion").toString(),headers:pe,prepareSendMessagesRequest:$e},ma),e[6]=u,e[7]=l,e[8]=f,e[9]=P}else P=e[9];let{sendMessage:Q,stop:re,status:ne,addToolOutput:ie}=zn({experimental_throttle:100,transport:P,onToolCall:async pe=>{let{toolCall:$e}=pe;await ni({invokeAiTool:y,addToolOutput:ae,toolCall:{toolName:$e.toolName,toolCallId:$e.toolCallId,input:$e.input},toolContext:K})},onError:sp}),ae=ie,z=ne==="streaming"||ne==="submitted",ue=c.size>0,se=((as=T==null?void 0:T.models)==null?void 0:as.edit_model)||"openai/gpt-4o",Fe;if(e[17]!==se){let pe=ro.parse(se).providerId;Fe=ai.has(pe),e[17]=se,e[18]=Fe}else Fe=e[18];let je=Fe,Ee;e[19]!==o||e[20]!==g||e[21]!==s||e[22]!==z||e[23]!==Q?(Ee=async()=>{var pe;z||((pe=b.current)!=null&&pe.view&&qn(b.current.view),o(),Q({text:s,files:g?await ri(g):void 0}))},e[19]=o,e[20]=g,e[21]=s,e[22]=z,e[23]=Q,e[24]=Ee):Ee=e[24];let ye=Ee,ze;e[25]===Symbol.for("react.memo_cache_sentinel")?(ze=(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(Jo,{className:"size-4 mr-2"}),"Python"]}),e[25]=ze):ze=e[25];let It=ze,Ue;e[26]===Symbol.for("react.memo_cache_sentinel")?(Ue=(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(Ui,{className:"size-4 mr-2"}),"SQL"]}),e[26]=Ue):Ue=e[26];let Vt=Ue,Et=u==="python"?It:Vt,Tt;e[27]===Symbol.for("react.memo_cache_sentinel")?(Tt=(0,E.jsx)(Ao,{className:"ml-1 h-3.5 w-3.5 text-muted-foreground/70"}),e[27]=Tt):Tt=e[27];let Ye;e[28]===Et?Ye=e[29]:(Ye=(0,E.jsxs)(po,{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:[Et,Tt]}),e[28]=Et,e[29]=Ye);let Pe,dt;e[30]===Symbol.for("react.memo_cache_sentinel")?(Pe=(0,E.jsx)("div",{className:"px-2 py-1 text-sm text-muted-foreground",children:"Select language"}),dt=(0,E.jsx)(co,{}),e[30]=Pe,e[31]=dt):(Pe=e[30],dt=e[31]);let B;e[32]===p?B=e[33]:(B=(0,E.jsx)(fs,{onClick:()=>p("python"),children:It}),e[32]=p,e[33]=B);let J;e[34]===p?J=e[35]:(J=(0,E.jsx)(fs,{onClick:()=>p("sql"),children:Vt}),e[34]=p,e[35]=J);let te;e[36]!==B||e[37]!==J?(te=(0,E.jsxs)(mo,{align:"center",children:[Pe,dt,B,J]}),e[36]=B,e[37]=J,e[38]=te):te=e[38];let Y;e[39]!==Ye||e[40]!==te?(Y=(0,E.jsxs)(ho,{modal:!1,children:[Ye,te]}),e[39]=Ye,e[40]=te,e[41]=Y):Y=e[41];let Te=Y,_e;e[42]!==i||e[43]!==a?(_e=()=>{i(),a()},e[42]=i,e[43]=a,e[44]=_e):_e=e[44];let ce=_e,oe;e[45]===o?oe=e[46]:(oe=()=>{o()},e[45]=o,e[46]=oe);let we=oe,ut;e[47]===Symbol.for("react.memo_cache_sentinel")?(ut=(0,E.jsx)($o,{className:"size-4 text-(--blue-11) mr-2"}),e[47]=ut):ut=e[47];let qe;e[48]!==o||e[49]!==a?(qe=()=>{o(),a()},e[48]=o,e[49]=a,e[50]=qe):qe=e[50];let ct;e[51]===Symbol.for("react.memo_cache_sentinel")?(ct=pe=>{n(pe)},e[51]=ct):ct=e[51];let de;e[52]!==ce||e[53]!==we||e[54]!==ue||e[55]!==z?(de=hi({handleAcceptCompletion:ce,handleDeclineCompletion:we,isLoading:z,hasCompletion:ue}),e[52]=ce,e[53]=we,e[54]=ue,e[55]=z,e[56]=de):de=e[56];let me;e[57]!==s||e[58]!==ye||e[59]!==qe||e[60]!==de?(me=(0,E.jsx)(bi,{inputRef:b,onClose:qe,value:s,onChange:ct,onSubmit:ye,onKeyDown:de}),e[57]=s,e[58]=ye,e[59]=qe,e[60]=de,e[61]=me):me=e[61];let He;e[62]===Symbol.for("react.memo_cache_sentinel")?(He=(0,E.jsx)(bs,{className:"size-4"}),e[62]=He):He=e[62];let Ge;e[63]===a?Ge=e[64]:(Ge=(0,E.jsx)(et,{variant:"text",size:"sm",className:"mb-0 px-1",onClick:a,children:He}),e[63]=a,e[64]=Ge);let Qe;e[65]!==me||e[66]!==Ge?(Qe=(0,E.jsxs)("div",{className:"flex items-center px-3",children:[ut,me,Ge]}),e[65]=me,e[66]=Ge,e[67]=Qe):Qe=e[67];let qa=Qe,la;e[68]===Symbol.for("react.memo_cache_sentinel")?(la=(0,E.jsx)(so,{triggerClassName:"h-7 text-xs max-w-64",iconSize:"small",forRole:"edit",showAddCustomModelDocs:!0}),e[68]=la):la=e[68];let St;e[69]===Te?St=e[70]:(St=(0,E.jsxs)("div",{className:"flex items-center gap-2",children:[la,Te]}),e[69]=Te,e[70]=St);let At;e[71]!==g||e[72]!==C?(At=g.length>0&&(0,E.jsx)("div",{className:"flex flex-row gap-1 flex-wrap pr-1",children:g==null?void 0:g.map((pe,$e)=>(0,E.jsx)(oi,{file:pe,onRemove:()=>C(pe)},`${pe.name}-${$e}`))}),e[71]=g,e[72]=C,e[73]=At):At=e[73];let da;e[74]===Symbol.for("react.memo_cache_sentinel")?(da=()=>Yn(b),e[74]=da):da=e[74];let Ot;e[75]===z?Ot=e[76]:(Ot=(0,E.jsx)(di,{handleAddContext:da,isLoading:z}),e[75]=z,e[76]=Ot);let Rt;e[77]!==v||e[78]!==je||e[79]!==z?(Rt=je&&(0,E.jsx)(ui,{fileInputRef:m,isLoading:z,onAddFiles:v}),e[77]=v,e[78]=je,e[79]=z,e[80]=Rt):Rt=e[80];let Va=!s.trim(),Nt;e[81]!==z||e[82]!==re||e[83]!==ye||e[84]!==Va?(Nt=(0,E.jsx)(li,{isLoading:z,onStop:re,onSendClick:ye,isEmpty:Va,showStopLabel:!0}),e[81]=z,e[82]=re,e[83]=ye,e[84]=Va,e[85]=Nt):Nt=e[85];let Mt;e[86]!==At||e[87]!==Ot||e[88]!==Rt||e[89]!==Nt?(Mt=(0,E.jsxs)("div",{className:"flex flex-row items-center",children:[At,Ot,Rt,Nt]}),e[86]=At,e[87]=Ot,e[88]=Rt,e[89]=Nt,e[90]=Mt):Mt=e[90];let ua;e[91]!==St||e[92]!==Mt?(ua=(0,E.jsxs)("div",{className:"px-3 pt-1 flex flex-row items-center justify-between",children:[St,Mt]}),e[91]=St,e[92]=Mt,e[93]=ua):ua=e[93];let Wa=ua,ca;e[94]===Symbol.for("react.memo_cache_sentinel")?(ca=Ka("flex flex-col w-full py-2"),e[94]=ca):ca=e[94];let pa;return e[95]!==Wa||e[96]!==qa?(pa=(0,E.jsxs)("div",{className:ca,children:[qa,Wa]}),e[95]=Wa,e[96]=qa,e[97]=pa):pa=e[97],pa},bi=t=>{let e=(0,yi.c)(35),{value:a,placeholder:r,inputRef:s,className:n,onChange:o,onSubmit:i,onKeyDown:l,onClose:d,onAddFiles:u,additionalCompletions:p,maxHeight:f}=t,y=i,k=d,c=rs(),{theme:b}=zo(),m;e[0]===p?m=e[1]:(m=ue=>p?lc([p.triggerCompletionRegex],p.completions)(ue):null,e[0]=p,e[1]=m);let g=ns(m),v,C,T,M;if(e[2]!==g||e[3]!==u||e[4]!==c){let ue=Zo();e[9]===Symbol.for("react.memo_cache_sentinel")?(v=Co({}),e[9]=v):v=e[9],C=ue,T=Xc({language:ue.language,store:c,onAddFiles:u}),M=ue.language.data.of({autocomplete:g}),e[2]=g,e[3]=u,e[4]=c,e[5]=v,e[6]=C,e[7]=T,e[8]=M}else v=e[5],C=e[6],T=e[7],M=e[8];let Z;e[10]===Symbol.for("react.memo_cache_sentinel")?(Z=Ju({storage:{load:np,save:ip}}),e[10]=Z):Z=e[10];let $;e[11]===Symbol.for("react.memo_cache_sentinel")?($=Ko(),e[11]=$):$=e[11];let K;e[12]===y?K=e[13]:(K=gs.highest(xa.of([{preventDefault:!0,stopPropagation:!0,any:(ue,se)=>{let Fe=se.metaKey||se.ctrlKey||se.shiftKey;if(se.key==="Enter"&&!Fe)return y(se,ue.state.doc.toString()),se.preventDefault(),se.stopPropagation(),!0;if(se.key==="Enter"&&se.shiftKey){let je=ue.state.selection.main.from;return ue.dispatch({changes:{from:je,to:je,insert:`
96
+ border-(--red-6) border hover:shadow-xs ${(i===void 0?!1:i)&&"border-none rounded-md"} ${n}`,p=l&&" all",f;e[0]===o?f=e[1]:(f=o&&(0,E.jsx)(Xa,{className:"ml-1 inline",shortcut:o}),e[0]=o,e[1]=f);let y;return e[2]!==a||e[3]!==d||e[4]!==u||e[5]!==p||e[6]!==f?(y=(0,E.jsxs)(et,{variant:"text",size:d,onClick:a,className:u,children:["Reject",p,f]}),e[2]=a,e[3]=d,e[4]=u,e[5]=p,e[6]=f,e[7]=y):y=e[7],y};var tp=class extends Er{constructor(t,e){super(t),this.onChunkReceived=e}processResponseStream(t){let e=this.onChunkReceived;return super.processResponseStream(t).pipeThrough(new TransformStream({async transform(a,r){e(a),r.enqueue(a)}}))}},yi=Wt(),ap=zi("marimo:ai-language","python",Di),vi="marimo:ai-prompt-history",xi=new Ui(Se(h()),()=>[]);const rp=t=>{var as;let e=(0,yi.c)(98),{onClose:a}=t,r=rs(),[s,n]=(0,N.useState)(""),{deleteAllStagedCells:o,clearStagedCells:i,onStream:l,addStagedCell:d}=Qn(r),[u,p]=Mi(ap),f=oo(),{invokeAiTool:y,sendRun:k}=Io(),c=is(sa),b=(0,N.useRef)(null),m=(0,N.useRef)(null),{files:g,addFiles:v,removeFile:C}=ii(),T=is(io),{createNewCell:M,prepareForRun:Z}=os(),$;e[0]!==d||e[1]!==M||e[2]!==Z||e[3]!==k||e[4]!==r?($={store:r,addStagedCell:d,createNewCell:M,prepareForRun:Z,sendRun:k},e[0]=d,e[1]=M,e[2]=Z,e[3]=k,e[4]=r,e[5]=$):$=e[5];let K=$,P;if(e[6]!==u||e[7]!==l||e[8]!==f){let pe;e[10]===f?pe=e[11]:(pe=()=>f.headers(),e[10]=f,e[11]=pe);let $e;e[12]!==u||e[13]!==f?($e=async ha=>{let Si=await si(ha.messages),Ai={...ha,...Si,code:"",prompt:"",language:u};return{api:f.getAiURL("completion").toString(),body:Ai}},e[12]=u,e[13]=f,e[14]=$e):$e=e[14];let ma;e[15]===l?ma=e[16]:(ma=ha=>{l(ha)},e[15]=l,e[16]=ma),P=new tp({api:f.getAiURL("completion").toString(),headers:pe,prepareSendMessagesRequest:$e},ma),e[6]=u,e[7]=l,e[8]=f,e[9]=P}else P=e[9];let{sendMessage:Q,stop:re,status:ne,addToolOutput:ie}=zn({experimental_throttle:100,transport:P,onToolCall:async pe=>{let{toolCall:$e}=pe;await ni({invokeAiTool:y,addToolOutput:ae,toolCall:{toolName:$e.toolName,toolCallId:$e.toolCallId,input:$e.input},toolContext:K})},onError:sp}),ae=ie,z=ne==="streaming"||ne==="submitted",ue=c.size>0,se=((as=T==null?void 0:T.models)==null?void 0:as.edit_model)||"openai/gpt-4o",Fe;if(e[17]!==se){let pe=ro.parse(se).providerId;Fe=ai.has(pe),e[17]=se,e[18]=Fe}else Fe=e[18];let je=Fe,Ee;e[19]!==o||e[20]!==g||e[21]!==s||e[22]!==z||e[23]!==Q?(Ee=async()=>{var pe;z||((pe=b.current)!=null&&pe.view&&qn(b.current.view),o(),Q({text:s,files:g?await ri(g):void 0}))},e[19]=o,e[20]=g,e[21]=s,e[22]=z,e[23]=Q,e[24]=Ee):Ee=e[24];let ye=Ee,ze;e[25]===Symbol.for("react.memo_cache_sentinel")?(ze=(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(Jo,{className:"size-4 mr-2"}),"Python"]}),e[25]=ze):ze=e[25];let It=ze,Ue;e[26]===Symbol.for("react.memo_cache_sentinel")?(Ue=(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(Vi,{className:"size-4 mr-2"}),"SQL"]}),e[26]=Ue):Ue=e[26];let Vt=Ue,Et=u==="python"?It:Vt,Tt;e[27]===Symbol.for("react.memo_cache_sentinel")?(Tt=(0,E.jsx)(Ao,{className:"ml-1 h-3.5 w-3.5 text-muted-foreground/70"}),e[27]=Tt):Tt=e[27];let Ye;e[28]===Et?Ye=e[29]:(Ye=(0,E.jsxs)(po,{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:[Et,Tt]}),e[28]=Et,e[29]=Ye);let Pe,dt;e[30]===Symbol.for("react.memo_cache_sentinel")?(Pe=(0,E.jsx)("div",{className:"px-2 py-1 text-sm text-muted-foreground",children:"Select language"}),dt=(0,E.jsx)(co,{}),e[30]=Pe,e[31]=dt):(Pe=e[30],dt=e[31]);let B;e[32]===p?B=e[33]:(B=(0,E.jsx)(fs,{onClick:()=>p("python"),children:It}),e[32]=p,e[33]=B);let J;e[34]===p?J=e[35]:(J=(0,E.jsx)(fs,{onClick:()=>p("sql"),children:Vt}),e[34]=p,e[35]=J);let te;e[36]!==B||e[37]!==J?(te=(0,E.jsxs)(mo,{align:"center",children:[Pe,dt,B,J]}),e[36]=B,e[37]=J,e[38]=te):te=e[38];let Y;e[39]!==Ye||e[40]!==te?(Y=(0,E.jsxs)(ho,{modal:!1,children:[Ye,te]}),e[39]=Ye,e[40]=te,e[41]=Y):Y=e[41];let Te=Y,_e;e[42]!==i||e[43]!==a?(_e=()=>{i(),a()},e[42]=i,e[43]=a,e[44]=_e):_e=e[44];let ce=_e,oe;e[45]===o?oe=e[46]:(oe=()=>{o()},e[45]=o,e[46]=oe);let we=oe,ut;e[47]===Symbol.for("react.memo_cache_sentinel")?(ut=(0,E.jsx)($o,{className:"size-4 text-(--blue-11) mr-2"}),e[47]=ut):ut=e[47];let qe;e[48]!==o||e[49]!==a?(qe=()=>{o(),a()},e[48]=o,e[49]=a,e[50]=qe):qe=e[50];let ct;e[51]===Symbol.for("react.memo_cache_sentinel")?(ct=pe=>{n(pe)},e[51]=ct):ct=e[51];let de;e[52]!==ce||e[53]!==we||e[54]!==ue||e[55]!==z?(de=hi({handleAcceptCompletion:ce,handleDeclineCompletion:we,isLoading:z,hasCompletion:ue}),e[52]=ce,e[53]=we,e[54]=ue,e[55]=z,e[56]=de):de=e[56];let me;e[57]!==s||e[58]!==ye||e[59]!==qe||e[60]!==de?(me=(0,E.jsx)(bi,{inputRef:b,onClose:qe,value:s,onChange:ct,onSubmit:ye,onKeyDown:de}),e[57]=s,e[58]=ye,e[59]=qe,e[60]=de,e[61]=me):me=e[61];let He;e[62]===Symbol.for("react.memo_cache_sentinel")?(He=(0,E.jsx)(bs,{className:"size-4"}),e[62]=He):He=e[62];let Ge;e[63]===a?Ge=e[64]:(Ge=(0,E.jsx)(et,{variant:"text",size:"sm",className:"mb-0 px-1",onClick:a,children:He}),e[63]=a,e[64]=Ge);let Qe;e[65]!==me||e[66]!==Ge?(Qe=(0,E.jsxs)("div",{className:"flex items-center px-3",children:[ut,me,Ge]}),e[65]=me,e[66]=Ge,e[67]=Qe):Qe=e[67];let qa=Qe,la;e[68]===Symbol.for("react.memo_cache_sentinel")?(la=(0,E.jsx)(so,{triggerClassName:"h-7 text-xs max-w-64",iconSize:"small",forRole:"edit",showAddCustomModelDocs:!0}),e[68]=la):la=e[68];let St;e[69]===Te?St=e[70]:(St=(0,E.jsxs)("div",{className:"flex items-center gap-2",children:[la,Te]}),e[69]=Te,e[70]=St);let At;e[71]!==g||e[72]!==C?(At=g.length>0&&(0,E.jsx)("div",{className:"flex flex-row gap-1 flex-wrap pr-1",children:g==null?void 0:g.map((pe,$e)=>(0,E.jsx)(oi,{file:pe,onRemove:()=>C(pe)},`${pe.name}-${$e}`))}),e[71]=g,e[72]=C,e[73]=At):At=e[73];let da;e[74]===Symbol.for("react.memo_cache_sentinel")?(da=()=>Yn(b),e[74]=da):da=e[74];let Ot;e[75]===z?Ot=e[76]:(Ot=(0,E.jsx)(di,{handleAddContext:da,isLoading:z}),e[75]=z,e[76]=Ot);let Rt;e[77]!==v||e[78]!==je||e[79]!==z?(Rt=je&&(0,E.jsx)(ui,{fileInputRef:m,isLoading:z,onAddFiles:v}),e[77]=v,e[78]=je,e[79]=z,e[80]=Rt):Rt=e[80];let Va=!s.trim(),Nt;e[81]!==z||e[82]!==re||e[83]!==ye||e[84]!==Va?(Nt=(0,E.jsx)(li,{isLoading:z,onStop:re,onSendClick:ye,isEmpty:Va,showStopLabel:!0}),e[81]=z,e[82]=re,e[83]=ye,e[84]=Va,e[85]=Nt):Nt=e[85];let Mt;e[86]!==At||e[87]!==Ot||e[88]!==Rt||e[89]!==Nt?(Mt=(0,E.jsxs)("div",{className:"flex flex-row items-center",children:[At,Ot,Rt,Nt]}),e[86]=At,e[87]=Ot,e[88]=Rt,e[89]=Nt,e[90]=Mt):Mt=e[90];let ua;e[91]!==St||e[92]!==Mt?(ua=(0,E.jsxs)("div",{className:"px-3 pt-1 flex flex-row items-center justify-between",children:[St,Mt]}),e[91]=St,e[92]=Mt,e[93]=ua):ua=e[93];let Wa=ua,ca;e[94]===Symbol.for("react.memo_cache_sentinel")?(ca=Ka("flex flex-col w-full py-2"),e[94]=ca):ca=e[94];let pa;return e[95]!==Wa||e[96]!==qa?(pa=(0,E.jsxs)("div",{className:ca,children:[qa,Wa]}),e[95]=Wa,e[96]=qa,e[97]=pa):pa=e[97],pa},bi=t=>{let e=(0,yi.c)(35),{value:a,placeholder:r,inputRef:s,className:n,onChange:o,onSubmit:i,onKeyDown:l,onClose:d,onAddFiles:u,additionalCompletions:p,maxHeight:f}=t,y=i,k=d,c=rs(),{theme:b}=zo(),m;e[0]===p?m=e[1]:(m=ue=>p?lc([p.triggerCompletionRegex],p.completions)(ue):null,e[0]=p,e[1]=m);let g=ns(m),v,C,T,M;if(e[2]!==g||e[3]!==u||e[4]!==c){let ue=Zo();e[9]===Symbol.for("react.memo_cache_sentinel")?(v=Co({}),e[9]=v):v=e[9],C=ue,T=Xc({language:ue.language,store:c,onAddFiles:u}),M=ue.language.data.of({autocomplete:g}),e[2]=g,e[3]=u,e[4]=c,e[5]=v,e[6]=C,e[7]=T,e[8]=M}else v=e[5],C=e[6],T=e[7],M=e[8];let Z;e[10]===Symbol.for("react.memo_cache_sentinel")?(Z=Ju({storage:{load:np,save:ip}}),e[10]=Z):Z=e[10];let $;e[11]===Symbol.for("react.memo_cache_sentinel")?($=Ko(),e[11]=$):$=e[11];let K;e[12]===y?K=e[13]:(K=gs.highest(xa.of([{preventDefault:!0,stopPropagation:!0,any:(ue,se)=>{let Fe=se.metaKey||se.ctrlKey||se.shiftKey;if(se.key==="Enter"&&!Fe)return y(se,ue.state.doc.toString()),se.preventDefault(),se.stopPropagation(),!0;if(se.key==="Enter"&&se.shiftKey){let je=ue.state.selection.main.from;return ue.dispatch({changes:{from:je,to:je,insert:`
97
97
  `},selection:{anchor:je+1,head:je+1}}),se.preventDefault(),se.stopPropagation(),!0}return!1}}])),e[12]=y,e[13]=K);let P;e[14]===k?P=e[15]:(P=xa.of([{key:"Escape",preventDefault:!0,stopPropagation:!0,run:()=>(k(),!0)}]),e[14]=k,e[15]=P);let Q;e[16]!==v||e[17]!==C||e[18]!==T||e[19]!==M||e[20]!==K||e[21]!==P?(Q=[v,C,T,M,Z,vs.lineWrapping,$,K,P],e[16]=v,e[17]=C,e[18]=T,e[19]=M,e[20]=K,e[21]=P,e[22]=Q):Q=e[22];let re=Q,ne;e[23]===n?ne=e[24]:(ne=Ka("flex-1 font-sans overflow-auto my-1",n),e[23]=n,e[24]=ne);let ie=b==="dark"?"dark":"light",ae=r||"Generate with AI, @ to include context",z;return e[25]!==re||e[26]!==s||e[27]!==f||e[28]!==o||e[29]!==l||e[30]!==ne||e[31]!==ie||e[32]!==ae||e[33]!==a?(z=(0,E.jsx)(Yo,{ref:s,className:ne,width:"100%",maxHeight:f,value:a,basicSetup:!1,extensions:re,onChange:o,onKeyDown:l,theme:ie,placeholder:ae}),e[25]=re,e[26]=s,e[27]=f,e[28]=o,e[29]=l,e[30]=ne,e[31]=ie,e[32]=ae,e[33]=a,e[34]=z):z=e[34],z};function sp(t){Ga({title:"Generate with AI failed",description:Vo(t)})}function np(){return xi.get(vi)}function ip(t){return xi.set(vi,t)}export{zn as A,ks as B,Gn as C,nc as D,Yn as E,su as F,kr as I,wr as L,Er as M,Ir as N,Ct as O,Qd as P,Is as R,sa as S,sc as T,ni as _,gi as a,ii as b,ui as c,li as d,jc as f,Tc as g,ri as h,ep as i,Uu as j,qn as k,Nc as l,si as m,bi as n,hi as o,ai as p,fi as r,di as s,rp as t,oi as u,Oc as v,Qn as w,Jr as x,Sc as y,Cs as z};