@marimo-team/frontend 0.25.3-dev29 → 0.25.3-dev30

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 (79) hide show
  1. package/dist/assets/{CellStatus-C_6iw05f.js → CellStatus-wFCGHpDX.js} +1 -1
  2. package/dist/assets/{ErrorBoundary-B6yKaNNU.js → ErrorBoundary-D1ozl9e0.js} +2 -2
  3. package/dist/assets/{JsonOutput-D7ovfzRT.js → JsonOutput-Dqg7qwkl.js} +1 -1
  4. package/dist/assets/{MarimoErrorOutput-x1b8BEel.js → MarimoErrorOutput-BYSTEwo1.js} +1 -1
  5. package/dist/assets/{RenderHTML-CHgN4Sj3.js → RenderHTML-B18UiW8r.js} +1 -1
  6. package/dist/assets/{RunButton-CjebHh_3.js → RunButton-CWvRnb98.js} +1 -1
  7. package/dist/assets/{add-cell-with-ai-Hyi0ODfx.js → add-cell-with-ai-C4pN_ho7.js} +1 -1
  8. package/dist/assets/{add-connection-dialog-DtE-EeJT.js → add-connection-dialog-BErVOfUV.js} +1 -1
  9. package/dist/assets/{agent-panel-C56B-F79.js → agent-panel-QQDTP8Vb.js} +1 -1
  10. package/dist/assets/{ai-model-dropdown-BSXpoT5O.js → ai-model-dropdown-D5Fe5GS-.js} +1 -1
  11. package/dist/assets/{app-config-button-ClnrveEl.js → app-config-button-DBHN-U2l.js} +1 -1
  12. package/dist/assets/{blob-DlOuX2uQ.js → blob-DY_W1wFZ.js} +1 -1
  13. package/dist/assets/{cell-editor-Ca6rrpD_.js → cell-editor-CCFDuQIT.js} +1 -1
  14. package/dist/assets/{cell-link-amlgOuMH.js → cell-link-BOqoitvE.js} +1 -1
  15. package/dist/assets/{cells-CJf50CB9.js → cells-CN1I_0eH.js} +1 -1
  16. package/dist/assets/{chat-display-CrPNkPHG.js → chat-display-D1_UV6v7.js} +1 -1
  17. package/dist/assets/{chat-panel-9sMQH6CP.js → chat-panel-C4OJDIt6.js} +1 -1
  18. package/dist/assets/{chat-ui-DJx7LIGF.js → chat-ui-wuDYPZ-w.js} +1 -1
  19. package/dist/assets/{column-preview-Br2kWTnb.js → column-preview-z4bqk4HW.js} +1 -1
  20. package/dist/assets/command-palette-TblDi15Q.js +1 -0
  21. package/dist/assets/{common-CaLv3bfC.js → common-Cbk0KIh7.js} +1 -1
  22. package/dist/assets/{components-CfzE8WQz.js → components-C88UxBXz.js} +1 -1
  23. package/dist/assets/{datasource-D7lJC0XO.js → datasource-DZJ6qqVI.js} +1 -1
  24. package/dist/assets/{dependency-graph-panel-CSi0twlb.js → dependency-graph-panel-DeZ66gIo.js} +1 -1
  25. package/dist/assets/{documentation-panel-DjTdVTMN.js → documentation-panel-Tl5G1cPt.js} +1 -1
  26. package/dist/assets/{download-CDIt5qnG.js → download-s8iwxGDb.js} +1 -1
  27. package/dist/assets/{edit-page-s5f2C8qH.js → edit-page-CjoAJvyN.js} +4 -4
  28. package/dist/assets/{error-entries-Yxnz11PL.js → error-entries-D11Bn1Hk.js} +1 -1
  29. package/dist/assets/{error-panel-CKKofC1g.js → error-panel-kfxFDscu.js} +1 -1
  30. package/dist/assets/feedback-button-3bZHpuSh.js +1 -0
  31. package/dist/assets/{feedback-button-CngqEjnR.js → feedback-button-DVABjD9Y.js} +1 -1
  32. package/dist/assets/{file-explorer-panel-DmRPr6jB.js → file-explorer-panel-CvmK-rEU.js} +1 -1
  33. package/dist/assets/{file-name-input-BG72jLLC.js → file-name-input-DAj9a3RQ.js} +1 -1
  34. package/dist/assets/{floating-outline-Bgn_3A2O.js → floating-outline-DDavqWJx.js} +1 -1
  35. package/dist/assets/{gallery-page-Dkdclwy-.js → gallery-page-xP6VqDyd.js} +1 -1
  36. package/dist/assets/{glide-data-editor-D3wKJL3e.js → glide-data-editor-32vBJJf8.js} +1 -1
  37. package/dist/assets/{home-page-qTKg4Ads.js → home-page-CvGzjVr4.js} +1 -1
  38. package/dist/assets/{hooks-BqWhLYfF.js → hooks-C1_gQ8kr.js} +1 -1
  39. package/dist/assets/{index-DTBCxL4Q.js → index-Dtv0HH-7.js} +4 -4
  40. package/dist/assets/{layout-C9xXio49.js → layout-BccvBeZy.js} +3 -3
  41. package/dist/assets/{logs-panel-D7219WDO.js → logs-panel-BhXo1sVJ.js} +1 -1
  42. package/dist/assets/{markdown-renderer-BPIzalVh.js → markdown-renderer-D2dafr8r.js} +1 -1
  43. package/dist/assets/{name-cell-input-4uJovCYk.js → name-cell-input-SHvgfcBR.js} +1 -1
  44. package/dist/assets/{outline-panel-BHVikyc1.js → outline-panel-CpY3FH-u.js} +1 -1
  45. package/dist/assets/{packages-panel-BtC7izyo.js → packages-panel-oZ0qZBec.js} +1 -1
  46. package/dist/assets/{panel-accordion-state-DPO3I0D8.js → panel-accordion-state-ChFIY2WQ.js} +1 -1
  47. package/dist/assets/panels-91ywfwgc.js +4 -0
  48. package/dist/assets/{process-output-CWvtHmic.js → process-output-Dvq4b2kJ.js} +1 -1
  49. package/dist/assets/{readonly-code-display-C1vCt8xX.js → readonly-code-display-C1eH5BDP.js} +1 -1
  50. package/dist/assets/{readonly-python-code-DcHbbnwj.js → readonly-python-code-BaElyj-4.js} +1 -1
  51. package/dist/assets/{reveal-component-CFfNa2YY.js → reveal-component-FCuqfC5H.js} +1 -1
  52. package/dist/assets/{run-page-Ci01VgVL.js → run-page-CbyMlRt1.js} +1 -1
  53. package/dist/assets/{runtime-details-state-GfolX-MI.js → runtime-details-state-Bpn67vTN.js} +1 -1
  54. package/dist/assets/{scratchpad-panel-Deuf7tpT.js → scratchpad-panel-OF9_e0l_.js} +1 -1
  55. package/dist/assets/{session-panel-dS5R90fQ.js → session-panel-CExxjkjV.js} +1 -1
  56. package/dist/assets/{snippets-panel-CDidd2MC.js → snippets-panel-DfRtTFJ-.js} +1 -1
  57. package/dist/assets/{state-DI_45AC3.js → state-BUqF6L9e.js} +1 -1
  58. package/dist/assets/{state-ZLQj4kZ7.js → state-CHojzKpZ.js} +1 -1
  59. package/dist/assets/{tracing-Be3zVYH3.js → tracing-BnfAB-BH.js} +1 -1
  60. package/dist/assets/{tracing-panel-UnSwXNoE.js → tracing-panel-DNabsbtA.js} +2 -2
  61. package/dist/assets/{tree-actions-d-fO9KIX.js → tree-actions-BXvnBv45.js} +1 -1
  62. package/dist/assets/{useAddCell-BUAQpDsD.js → useAddCell-6ECZ0xPG.js} +1 -1
  63. package/dist/assets/{useCellActionButton-DbgnioC5.js → useCellActionButton-Djyiwayj.js} +1 -1
  64. package/dist/assets/{useDeleteCell-CkcC1fWW.js → useDeleteCell-KX6SEwki.js} +1 -1
  65. package/dist/assets/{useDependencyPanelTab-C6YUVupC.js → useDependencyPanelTab-B8ke9iTY.js} +1 -1
  66. package/dist/assets/{useNotebookActions-BxtuPdK2.js → useNotebookActions-CluLEhAd.js} +1 -1
  67. package/dist/assets/{useRunCells-B5s8dBxS.js → useRunCells-B847kPLO.js} +1 -1
  68. package/dist/assets/{useSplitCell-5ootkjG6.js → useSplitCell-CnvTmIw7.js} +1 -1
  69. package/dist/index.html +20 -20
  70. package/package.json +1 -1
  71. package/src/components/editor/__tests__/dynamic-favicon.test.tsx +111 -18
  72. package/src/components/editor/controls/__tests__/command-palette.test.tsx +53 -0
  73. package/src/components/editor/controls/command-palette.tsx +22 -10
  74. package/src/components/editor/dynamic-favicon.tsx +21 -40
  75. package/src/core/cells/__tests__/notebook-outline.test.ts +113 -0
  76. package/src/core/cells/cells.ts +2 -1
  77. package/dist/assets/command-palette-RAkvowQQ.js +0 -1
  78. package/dist/assets/feedback-button-LtN1kjRE.js +0 -1
  79. package/dist/assets/panels-9EUsphaD.js +0 -4
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t}from"./useEvent-Dfcbgjhg.js";import{t as n}from"./react-DVplv7_D.js";import{$t as r,Bn as i,En as a,On as o,Xt as s,Yt as c,Zt as l,cn as u,dn as d,en as f,nn as p,tn as m,un as h}from"./cells-CJf50CB9.js";import{P as g}from"./config-MaHeMC9o.js";import{t as _}from"./compiler-runtime-BrajqUja.js";import{D as v,O as y,S as b}from"./config-CA1V-wjh.js";import{t as x}from"./jsx-runtime-B74pBk57.js";import{o as S}from"./alert-dialog-BaPGzeOK.js";import{l as C}from"./select-DTBn5eTb.js";import{c as w}from"./switch-CTaiAjrz.js";import{t as T}from"./tooltip-C9TuY18o.js";import{t as E}from"./button-COI-NGrx.js";import{t as D}from"./createLucideIcon-DfJ2oMlA.js";import{d as O,f as k,i as A,k as j,n as M,u as N}from"./ai-model-dropdown-BSXpoT5O.js";import{r as P}from"./useNumberFormatter-D7O_26UI.js";import{b as F,p as I}from"./write-secret-modal-DzKAInL2.js";import{Jt as L,Yt as R,nn as ee,r as z,tn as B}from"./input-BoBxR50a.js";import{t as V}from"./settings-BpdQZRgT.js";import{t as te}from"./use-toast-Wu434mLr.js";import{s as H}from"./arrays-BqUx5USx.js";import{r as U}from"./requests-lt0JK8Jt.js";import{r as ne}from"./useDebounce-B_ccBZTp.js";import{t as W}from"./kbd-pdKBv96t.js";import{t as G}from"./Inputs-BsQm29hD.js";var K=D(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),q=_(),J=x(),Y=e=>{let t=(0,q.c)(15),{description:n,disabled:r,tooltip:i}=e,a=r!==void 0&&r,o=i===void 0?`Shutdown`:i,{openConfirm:s,closeModal:c}=F(),{sendShutdown:l}=U(),u;t[0]===l?u=t[1]:(u=()=>{l(),setTimeout(X,200)},t[0]=l,t[1]=u);let d=u;if(g())return null;let f=a?`disabled`:`red`,p;t[2]!==c||t[3]!==n||t[4]!==d||t[5]!==s?(p=e=>{e.stopPropagation(),s({title:`Shutdown`,description:n,variant:`destructive`,confirmAction:(0,J.jsx)(S,{onClick:()=>{d(),c()},"aria-label":`Confirm Shutdown`,children:`Shutdown`})})},t[2]=c,t[3]=n,t[4]=d,t[5]=s,t[6]=p):p=t[6];let m;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(P,{strokeWidth:1}),t[7]=m):m=t[7];let h;t[8]!==a||t[9]!==f||t[10]!==p?(h=(0,J.jsx)(G,{"aria-label":`Shutdown`,"data-testid":`shutdown-button`,shape:`circle`,size:`small`,color:f,className:`h-[27px] w-[27px]`,disabled:a,onClick:p,children:m}),t[8]=a,t[9]=f,t[10]=p,t[11]=h):h=t[11];let _;return t[12]!==h||t[13]!==o?(_=(0,J.jsx)(T,{content:o,children:h}),t[12]=h,t[13]=o,t[14]=_):_=t[14],_};function X(){window.close()}var Z=e(n(),1),re=100,ie=()=>{let e=(0,q.c)(37),[t,n]=b(),{saveAppConfig:u}=U(),d=(0,Z.useId)(),h=(0,Z.useId)(),g;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=a(v),e[0]=g):g=e[0];let _;e[1]===t?_=e[2]:(_={resolver:g,defaultValues:t},e[1]=t,e[2]=_);let y=o(_),x;e[3]!==u||e[4]!==n?(x=async e=>{await u({config:e}).then(()=>{n(e)}).catch(()=>{n(e)})},e[3]=u,e[4]=n,e[5]=x):x=e[5];let S=x,C;e[6]===S?C=e[7]:(C=e=>{S(e)},e[6]=S,e[7]=C);let w=ne(C,re),T;e[8]===t.width?T=e[9]:(T=[t.width],e[8]=t.width,e[9]=T),(0,Z.useEffect)(ae,T);let E;e[10]!==w||e[11]!==y?(E=y.handleSubmit(w),e[10]=w,e[11]=y,e[12]=E):E=e[12];let D;e[13]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,J.jsxs)(`div`,{children:[(0,J.jsx)(k,{children:`Notebook Settings`}),(0,J.jsx)(O,{children:`Configure how your notebook or application looks and behaves.`})]}),e[13]=D):D=e[13];let A;e[14]===y.control?A=e[15]:(A=(0,J.jsxs)(Q,{title:`Display`,children:[(0,J.jsx)(r,{control:y.control,name:`width`,render:se}),(0,J.jsx)(r,{control:y.control,name:`app_title`,render:$})]}),e[14]=y.control,e[15]=A);let j;e[16]===y.control?j=e[17]:(j=(0,J.jsxs)(Q,{title:`Custom Files`,children:[(0,J.jsx)(r,{control:y.control,name:`css_file`,render:ce}),(0,J.jsx)(r,{control:y.control,name:`html_head_file`,render:le})]}),e[16]=y.control,e[17]=j);let M;e[18]===y.control?M=e[19]:(M=(0,J.jsx)(Q,{title:`Data`,children:(0,J.jsx)(r,{control:y.control,name:`sql_output`,render:de})}),e[18]=y.control,e[19]=M);let N;e[20]!==d||e[21]!==h?(N=e=>{let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(s,{children:(0,J.jsxs)(`div`,{className:`flex gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,J.jsx)(i,{id:d,"data-testid":`html-checkbox`,checked:t.value.includes(`html`),onCheckedChange:()=>{t.onChange(H(t.value,`html`))}}),(0,J.jsx)(m,{htmlFor:d,children:`HTML`})]}),(0,J.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,J.jsx)(i,{id:h,"data-testid":`ipynb-checkbox`,checked:t.value.includes(`ipynb`),onCheckedChange:()=>{t.onChange(H(t.value,`ipynb`))}}),(0,J.jsx)(m,{htmlFor:h,children:`IPYNB`})]})]})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`When enabled, marimo will periodically save this notebook in your selected formats (HTML, IPYNB) to a folder named`,` `,(0,J.jsx)(W,{className:`inline`,children:`__marimo__`}),` next to your notebook file.`]})]})},e[20]=d,e[21]=h,e[22]=N):N=e[22];let P;e[23]!==y.control||e[24]!==N?(P=(0,J.jsx)(Q,{title:`Exporting outputs`,children:(0,J.jsx)(r,{control:y.control,name:`auto_download`,render:N})}),e[23]=y.control,e[24]=N,e[25]=P):P=e[25];let F;e[26]!==P||e[27]!==A||e[28]!==j||e[29]!==M?(F=(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-8 gap-y-4`,children:[A,j,M,P]}),e[26]=P,e[27]=A,e[28]=j,e[29]=M,e[30]=F):F=e[30];let I;e[31]!==F||e[32]!==E?(I=(0,J.jsxs)(`form`,{onChange:E,className:`flex flex-col gap-6`,children:[D,F]}),e[31]=F,e[32]=E,e[33]=I):I=e[33];let L;return e[34]!==y||e[35]!==I?(L=(0,J.jsx)(c,{...y,children:I}),e[34]=y,e[35]=I,e[36]=L):L=e[36],L},Q=e=>{let t=(0,q.c)(5),{title:n,children:r}=e,i;t[0]===n?i=t[1]:(i=(0,J.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:n}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-2`,children:[i,r]}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a};function ae(){window.dispatchEvent(new Event(`resize`))}function oe(e){return(0,J.jsx)(`option`,{value:e,children:e},e)}function se(e){let{field:t}=e;return(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`Width`}),(0,J.jsx)(s,{children:(0,J.jsx)(C,{"data-testid":`app-width-select`,onChange:e=>t.onChange(e.target.value),value:t.value,disabled:t.disabled,className:`inline-flex mr-2`,children:j().map(oe)})}),(0,J.jsx)(p,{})]})}function $(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`App title`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,onChange:e=>{t.onChange(e.target.value),y.safeParse(e.target.value).success&&(document.title=e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsx)(l,{children:`The application title is put in the title tag in the HTML code and typically displayed in the title bar of the browser window.`})]})}function ce(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{className:`shrink-0`,children:`Custom CSS`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,placeholder:`custom.css`,onChange:e=>{t.onChange(e.target.value),y.safeParse(e.target.value).success&&(document.title=e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsx)(l,{children:`A filepath to a custom css file to be injected into the notebook.`})]})}function le(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{className:`shrink-0`,children:`HTML Head`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,placeholder:`head.html`,onChange:e=>{t.onChange(e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`A filepath to an HTML file to be injected into the`,` `,(0,J.jsx)(W,{className:`inline`,children:`<head/>`}),` section of the notebook. Use this to add analytics, custom fonts, meta tags, or external scripts.`]})]})}function ue(e){return(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value)}function de(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`SQL Output Type`}),(0,J.jsx)(s,{children:(0,J.jsx)(C,{"data-testid":`sql-output-select`,onChange:e=>{t.onChange(e.target.value),te({title:`Kernel Restart Required`,description:`This change requires a kernel restart to take effect.`})},value:t.value,disabled:t.disabled,className:`inline-flex mr-2`,children:N.map(ue)})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`The Python type returned by a SQL cell. For best performance with large datasets, we recommend using`,` `,(0,J.jsx)(W,{className:`inline`,children:`native`}),`. See the`,` `,(0,J.jsx)(I,{href:`https://docs.marimo.io/guides/working_with_data/sql`,children:`SQL guide`}),` `,`for more information.`]})]})}var fe=e=>{let n=(0,q.c)(32),{showAppConfig:r,disabled:i,tooltip:a}=e,o=r===void 0||r,s=i!==void 0&&i,c=a===void 0?`Settings`:a,[l,f]=t(M),p=s?`disabled`:`hint-green`,m;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(V,{strokeWidth:1.8}),n[0]=m):m=n[0];let g;n[1]===c?g=n[2]:(g=(0,J.jsx)(T,{content:c,children:m}),n[1]=c,n[2]=g);let _;n[3]!==s||n[4]!==p||n[5]!==g?(_=(0,J.jsx)(G,{"aria-label":`Config`,"data-testid":`app-config-button`,shape:`circle`,size:`small`,className:`h-[27px] w-[27px]`,disabled:s,color:p,children:g}),n[3]=s,n[4]=p,n[5]=g,n[6]=_):_=n[6];let v=_,y;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,J.jsxs)(R,{className:`w-[90vw] h-[90vh] overflow-hidden sm:max-w-5xl top-[5vh] p-0`,children:[(0,J.jsx)(w,{children:(0,J.jsx)(B,{children:`User settings`})}),(0,J.jsx)(A,{})]}),n[7]=y):y=n[7];let b=y;if(!o){let e;n[8]===v?e=n[9]:(e=(0,J.jsx)(ee,{children:v}),n[8]=v,n[9]=e);let t;return n[10]!==f||n[11]!==l||n[12]!==e?(t=(0,J.jsxs)(L,{open:l,onOpenChange:f,children:[e,b]}),n[10]=f,n[11]=l,n[12]=e,n[13]=t):t=n[13],t}let x;n[14]===v?x=n[15]:(x=(0,J.jsx)(d,{asChild:!0,children:v}),n[14]=v,n[15]=x);let S,C;n[16]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,J.jsx)(ie,{}),C=(0,J.jsx)(`div`,{className:`h-px bg-border my-2`}),n[16]=S,n[17]=C):(S=n[16],C=n[17]);let D;n[18]===f?D=n[19]:(D=()=>f(!0),n[18]=f,n[19]=D);let O;n[20]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,J.jsx)(V,{strokeWidth:1.8,className:`w-4 h-4 mr-2`}),n[20]=O):O=n[20];let k;n[21]===D?k=n[22]:(k=(0,J.jsxs)(h,{className:`w-[650px] overflow-auto max-h-[80vh] max-w-[80vw]`,align:`end`,side:`bottom`,onFocusOutside:pe,children:[S,C,(0,J.jsxs)(E,{onClick:D,variant:`link`,className:`px-0`,children:[O,`User settings`]})]}),n[21]=D,n[22]=k);let j;n[23]!==k||n[24]!==x?(j=(0,J.jsxs)(u,{children:[x,k]}),n[23]=k,n[24]=x,n[25]=j):j=n[25];let N;n[26]!==f||n[27]!==l?(N=(0,J.jsx)(L,{open:l,onOpenChange:f,children:b}),n[26]=f,n[27]=l,n[28]=N):N=n[28];let P;return n[29]!==j||n[30]!==N?(P=(0,J.jsxs)(J.Fragment,{children:[j,N]}),n[29]=j,n[30]=N,n[31]=P):P=n[31],P};function pe(e){return e.preventDefault()}export{Y as n,K as r,fe as t};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t}from"./useEvent-Dfcbgjhg.js";import{t as n}from"./react-DVplv7_D.js";import{$t as r,Bn as i,En as a,On as o,Xt as s,Yt as c,Zt as l,cn as u,dn as d,en as f,nn as p,tn as m,un as h}from"./cells-CN1I_0eH.js";import{P as g}from"./config-MaHeMC9o.js";import{t as _}from"./compiler-runtime-BrajqUja.js";import{D as v,O as y,S as b}from"./config-CA1V-wjh.js";import{t as x}from"./jsx-runtime-B74pBk57.js";import{o as S}from"./alert-dialog-BaPGzeOK.js";import{l as C}from"./select-DTBn5eTb.js";import{c as w}from"./switch-CTaiAjrz.js";import{t as T}from"./tooltip-C9TuY18o.js";import{t as E}from"./button-COI-NGrx.js";import{t as D}from"./createLucideIcon-DfJ2oMlA.js";import{d as O,f as k,i as A,k as j,n as M,u as N}from"./ai-model-dropdown-D5Fe5GS-.js";import{r as P}from"./useNumberFormatter-D7O_26UI.js";import{b as F,p as I}from"./write-secret-modal-DzKAInL2.js";import{Jt as L,Yt as R,nn as ee,r as z,tn as B}from"./input-BoBxR50a.js";import{t as V}from"./settings-BpdQZRgT.js";import{t as te}from"./use-toast-Wu434mLr.js";import{s as H}from"./arrays-BqUx5USx.js";import{r as U}from"./requests-lt0JK8Jt.js";import{r as ne}from"./useDebounce-B_ccBZTp.js";import{t as W}from"./kbd-pdKBv96t.js";import{t as G}from"./Inputs-BsQm29hD.js";var K=D(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),q=_(),J=x(),Y=e=>{let t=(0,q.c)(15),{description:n,disabled:r,tooltip:i}=e,a=r!==void 0&&r,o=i===void 0?`Shutdown`:i,{openConfirm:s,closeModal:c}=F(),{sendShutdown:l}=U(),u;t[0]===l?u=t[1]:(u=()=>{l(),setTimeout(X,200)},t[0]=l,t[1]=u);let d=u;if(g())return null;let f=a?`disabled`:`red`,p;t[2]!==c||t[3]!==n||t[4]!==d||t[5]!==s?(p=e=>{e.stopPropagation(),s({title:`Shutdown`,description:n,variant:`destructive`,confirmAction:(0,J.jsx)(S,{onClick:()=>{d(),c()},"aria-label":`Confirm Shutdown`,children:`Shutdown`})})},t[2]=c,t[3]=n,t[4]=d,t[5]=s,t[6]=p):p=t[6];let m;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(P,{strokeWidth:1}),t[7]=m):m=t[7];let h;t[8]!==a||t[9]!==f||t[10]!==p?(h=(0,J.jsx)(G,{"aria-label":`Shutdown`,"data-testid":`shutdown-button`,shape:`circle`,size:`small`,color:f,className:`h-[27px] w-[27px]`,disabled:a,onClick:p,children:m}),t[8]=a,t[9]=f,t[10]=p,t[11]=h):h=t[11];let _;return t[12]!==h||t[13]!==o?(_=(0,J.jsx)(T,{content:o,children:h}),t[12]=h,t[13]=o,t[14]=_):_=t[14],_};function X(){window.close()}var Z=e(n(),1),re=100,ie=()=>{let e=(0,q.c)(37),[t,n]=b(),{saveAppConfig:u}=U(),d=(0,Z.useId)(),h=(0,Z.useId)(),g;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=a(v),e[0]=g):g=e[0];let _;e[1]===t?_=e[2]:(_={resolver:g,defaultValues:t},e[1]=t,e[2]=_);let y=o(_),x;e[3]!==u||e[4]!==n?(x=async e=>{await u({config:e}).then(()=>{n(e)}).catch(()=>{n(e)})},e[3]=u,e[4]=n,e[5]=x):x=e[5];let S=x,C;e[6]===S?C=e[7]:(C=e=>{S(e)},e[6]=S,e[7]=C);let w=ne(C,re),T;e[8]===t.width?T=e[9]:(T=[t.width],e[8]=t.width,e[9]=T),(0,Z.useEffect)(ae,T);let E;e[10]!==w||e[11]!==y?(E=y.handleSubmit(w),e[10]=w,e[11]=y,e[12]=E):E=e[12];let D;e[13]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,J.jsxs)(`div`,{children:[(0,J.jsx)(k,{children:`Notebook Settings`}),(0,J.jsx)(O,{children:`Configure how your notebook or application looks and behaves.`})]}),e[13]=D):D=e[13];let A;e[14]===y.control?A=e[15]:(A=(0,J.jsxs)(Q,{title:`Display`,children:[(0,J.jsx)(r,{control:y.control,name:`width`,render:se}),(0,J.jsx)(r,{control:y.control,name:`app_title`,render:$})]}),e[14]=y.control,e[15]=A);let j;e[16]===y.control?j=e[17]:(j=(0,J.jsxs)(Q,{title:`Custom Files`,children:[(0,J.jsx)(r,{control:y.control,name:`css_file`,render:ce}),(0,J.jsx)(r,{control:y.control,name:`html_head_file`,render:le})]}),e[16]=y.control,e[17]=j);let M;e[18]===y.control?M=e[19]:(M=(0,J.jsx)(Q,{title:`Data`,children:(0,J.jsx)(r,{control:y.control,name:`sql_output`,render:de})}),e[18]=y.control,e[19]=M);let N;e[20]!==d||e[21]!==h?(N=e=>{let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(s,{children:(0,J.jsxs)(`div`,{className:`flex gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,J.jsx)(i,{id:d,"data-testid":`html-checkbox`,checked:t.value.includes(`html`),onCheckedChange:()=>{t.onChange(H(t.value,`html`))}}),(0,J.jsx)(m,{htmlFor:d,children:`HTML`})]}),(0,J.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,J.jsx)(i,{id:h,"data-testid":`ipynb-checkbox`,checked:t.value.includes(`ipynb`),onCheckedChange:()=>{t.onChange(H(t.value,`ipynb`))}}),(0,J.jsx)(m,{htmlFor:h,children:`IPYNB`})]})]})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`When enabled, marimo will periodically save this notebook in your selected formats (HTML, IPYNB) to a folder named`,` `,(0,J.jsx)(W,{className:`inline`,children:`__marimo__`}),` next to your notebook file.`]})]})},e[20]=d,e[21]=h,e[22]=N):N=e[22];let P;e[23]!==y.control||e[24]!==N?(P=(0,J.jsx)(Q,{title:`Exporting outputs`,children:(0,J.jsx)(r,{control:y.control,name:`auto_download`,render:N})}),e[23]=y.control,e[24]=N,e[25]=P):P=e[25];let F;e[26]!==P||e[27]!==A||e[28]!==j||e[29]!==M?(F=(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-8 gap-y-4`,children:[A,j,M,P]}),e[26]=P,e[27]=A,e[28]=j,e[29]=M,e[30]=F):F=e[30];let I;e[31]!==F||e[32]!==E?(I=(0,J.jsxs)(`form`,{onChange:E,className:`flex flex-col gap-6`,children:[D,F]}),e[31]=F,e[32]=E,e[33]=I):I=e[33];let L;return e[34]!==y||e[35]!==I?(L=(0,J.jsx)(c,{...y,children:I}),e[34]=y,e[35]=I,e[36]=L):L=e[36],L},Q=e=>{let t=(0,q.c)(5),{title:n,children:r}=e,i;t[0]===n?i=t[1]:(i=(0,J.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:n}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-2`,children:[i,r]}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a};function ae(){window.dispatchEvent(new Event(`resize`))}function oe(e){return(0,J.jsx)(`option`,{value:e,children:e},e)}function se(e){let{field:t}=e;return(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`Width`}),(0,J.jsx)(s,{children:(0,J.jsx)(C,{"data-testid":`app-width-select`,onChange:e=>t.onChange(e.target.value),value:t.value,disabled:t.disabled,className:`inline-flex mr-2`,children:j().map(oe)})}),(0,J.jsx)(p,{})]})}function $(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`App title`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,onChange:e=>{t.onChange(e.target.value),y.safeParse(e.target.value).success&&(document.title=e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsx)(l,{children:`The application title is put in the title tag in the HTML code and typically displayed in the title bar of the browser window.`})]})}function ce(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{className:`shrink-0`,children:`Custom CSS`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,placeholder:`custom.css`,onChange:e=>{t.onChange(e.target.value),y.safeParse(e.target.value).success&&(document.title=e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsx)(l,{children:`A filepath to a custom css file to be injected into the notebook.`})]})}function le(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{className:`shrink-0`,children:`HTML Head`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,placeholder:`head.html`,onChange:e=>{t.onChange(e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`A filepath to an HTML file to be injected into the`,` `,(0,J.jsx)(W,{className:`inline`,children:`<head/>`}),` section of the notebook. Use this to add analytics, custom fonts, meta tags, or external scripts.`]})]})}function ue(e){return(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value)}function de(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`SQL Output Type`}),(0,J.jsx)(s,{children:(0,J.jsx)(C,{"data-testid":`sql-output-select`,onChange:e=>{t.onChange(e.target.value),te({title:`Kernel Restart Required`,description:`This change requires a kernel restart to take effect.`})},value:t.value,disabled:t.disabled,className:`inline-flex mr-2`,children:N.map(ue)})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`The Python type returned by a SQL cell. For best performance with large datasets, we recommend using`,` `,(0,J.jsx)(W,{className:`inline`,children:`native`}),`. See the`,` `,(0,J.jsx)(I,{href:`https://docs.marimo.io/guides/working_with_data/sql`,children:`SQL guide`}),` `,`for more information.`]})]})}var fe=e=>{let n=(0,q.c)(32),{showAppConfig:r,disabled:i,tooltip:a}=e,o=r===void 0||r,s=i!==void 0&&i,c=a===void 0?`Settings`:a,[l,f]=t(M),p=s?`disabled`:`hint-green`,m;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(V,{strokeWidth:1.8}),n[0]=m):m=n[0];let g;n[1]===c?g=n[2]:(g=(0,J.jsx)(T,{content:c,children:m}),n[1]=c,n[2]=g);let _;n[3]!==s||n[4]!==p||n[5]!==g?(_=(0,J.jsx)(G,{"aria-label":`Config`,"data-testid":`app-config-button`,shape:`circle`,size:`small`,className:`h-[27px] w-[27px]`,disabled:s,color:p,children:g}),n[3]=s,n[4]=p,n[5]=g,n[6]=_):_=n[6];let v=_,y;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,J.jsxs)(R,{className:`w-[90vw] h-[90vh] overflow-hidden sm:max-w-5xl top-[5vh] p-0`,children:[(0,J.jsx)(w,{children:(0,J.jsx)(B,{children:`User settings`})}),(0,J.jsx)(A,{})]}),n[7]=y):y=n[7];let b=y;if(!o){let e;n[8]===v?e=n[9]:(e=(0,J.jsx)(ee,{children:v}),n[8]=v,n[9]=e);let t;return n[10]!==f||n[11]!==l||n[12]!==e?(t=(0,J.jsxs)(L,{open:l,onOpenChange:f,children:[e,b]}),n[10]=f,n[11]=l,n[12]=e,n[13]=t):t=n[13],t}let x;n[14]===v?x=n[15]:(x=(0,J.jsx)(d,{asChild:!0,children:v}),n[14]=v,n[15]=x);let S,C;n[16]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,J.jsx)(ie,{}),C=(0,J.jsx)(`div`,{className:`h-px bg-border my-2`}),n[16]=S,n[17]=C):(S=n[16],C=n[17]);let D;n[18]===f?D=n[19]:(D=()=>f(!0),n[18]=f,n[19]=D);let O;n[20]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,J.jsx)(V,{strokeWidth:1.8,className:`w-4 h-4 mr-2`}),n[20]=O):O=n[20];let k;n[21]===D?k=n[22]:(k=(0,J.jsxs)(h,{className:`w-[650px] overflow-auto max-h-[80vh] max-w-[80vw]`,align:`end`,side:`bottom`,onFocusOutside:pe,children:[S,C,(0,J.jsxs)(E,{onClick:D,variant:`link`,className:`px-0`,children:[O,`User settings`]})]}),n[21]=D,n[22]=k);let j;n[23]!==k||n[24]!==x?(j=(0,J.jsxs)(u,{children:[x,k]}),n[23]=k,n[24]=x,n[25]=j):j=n[25];let N;n[26]!==f||n[27]!==l?(N=(0,J.jsx)(L,{open:l,onOpenChange:f,children:b}),n[26]=f,n[27]=l,n[28]=N):N=n[28];let P;return n[29]!==j||n[30]!==N?(P=(0,J.jsxs)(J.Fragment,{children:[j,N]}),n[29]=j,n[30]=N,n[31]=P):P=n[31],P};function pe(e){return e.preventDefault()}export{Y as n,K as r,fe as t};
@@ -1 +1 @@
1
- import{a as e}from"./markdown-renderer-BPIzalVh.js";function t(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{t(e.target?.result)},r.onerror=e=>{n(Error(`Failed to read blob: ${e.type}`))},r.readAsDataURL(e)})}function n(e){let[t,n]=e.split(`,`,2),r=/^data:(.+);base64$/.exec(t)?.[1],i=atob(n),a=i.length,o=new Uint8Array(a);for(let e=0;e<a;e++)o[e]=i.charCodeAt(e);return new Blob([o],{type:r})}function r({contents:t,mimeType:r,isBase64:i}){return i?n(e(t,r)):new Blob([t],{type:r})}export{r as n,t as r,n as t};
1
+ import{a as e}from"./markdown-renderer-D2dafr8r.js";function t(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{t(e.target?.result)},r.onerror=e=>{n(Error(`Failed to read blob: ${e.type}`))},r.readAsDataURL(e)})}function n(e){let[t,n]=e.split(`,`,2),r=/^data:(.+);base64$/.exec(t)?.[1],i=atob(n),a=i.length,o=new Uint8Array(a);for(let e=0;e<a;e++)o[e]=i.charCodeAt(e);return new Blob([o],{type:r})}function r({contents:t,mimeType:r,isBase64:i}){return i?n(e(t,r)):new Blob([t],{type:r})}export{r as n,t as r,n as t};
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./loro_wasm_bg-C2Fqi8D-.js","./loro_wasm_bg-Ctp2cNI9.js","./rolldown-runtime-B0Z9INg1.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,f as r,l as i,o as a,r as o,s,t as c,u as l}from"./useEvent-Dfcbgjhg.js";import{t as u}from"./react-DVplv7_D.js";import{$i as d,Bn as f,Br as p,Bt as m,Ca as h,Ci as g,Co as _,Cr as v,D as y,Dr as b,Fr as x,H as S,I as C,Ir as w,K as T,Lr as E,Lt as D,Ni as O,Nn as ee,Nr as k,Pr as te,Qi as ne,Ri as re,Rr as A,Si as j,U as ie,Ur as M,V as N,Vn as P,W as ae,Wr as oe,Yn as se,Zn as ce,_i as le,_n as ue,_t as de,ai as fe,ar as pe,at as me,b as he,ba as ge,bi as _e,bt as ve,ca as ye,ci as be,cn as xe,cr as Se,d as Ce,dt as we,fi as Te,fn as Ee,fo as De,ft as Oe,ga as ke,gn as Ae,gt as je,h as Me,ha as Ne,ht as Pe,i as Fe,it as Ie,jo as Le,jr as Re,li as ze,lr as Be,mn as Ve,mt as He,ni as Ue,nr as We,or as Ge,ot as Ke,pi as qe,pt as Je,qa as Ye,ri as Xe,rr as Ze,sa as Qe,si as $e,sr as et,ti as tt,tr as nt,tt as rt,u as it,ui as at,un as ot,vn as st,vr as ct,vt as lt,wa as ut,wi as dt,xa as ft,xi as pt,xo as mt,yi as ht,za as gt,zr as F}from"./cells-CJf50CB9.js";import{t as _t}from"./react-dom-_LrxgvjW.js";import{C as vt,I as yt,M as bt,N as xt,O as St,R as Ct,S as wt,b as Tt}from"./schemas-ChRqMOTL.js";import{C as Et,E as Dt,P as Ot,k as kt,m as At,o as jt,r as Mt,v as Nt}from"./config-MaHeMC9o.js";import{t as Pt}from"./compiler-runtime-BrajqUja.js";import{t as Ft}from"./debounce-aFmHgJZY.js";import{E as It,_ as Lt,c as Rt,g as zt,h as Bt,s as Vt}from"./config-CA1V-wjh.js";import{_ as Ht,c as Ut,g as Wt,m as Gt,t as Kt}from"./useEventListener-D9cftcHj.js";import{t as qt}from"./invariant-Ci2dTZ72.js";import{s as Jt}from"./config-DEzFV5-l.js";import{d as Yt,m as Xt,t as Zt}from"./session-DqoWmb7X.js";import{c as Qt}from"./state-C3oDoyFe.js";import{t as $t}from"./ErrorBoundary-B6yKaNNU.js";import{t as en}from"./cn-ldLVeaqm.js";import{t as tn}from"./jsx-runtime-B74pBk57.js";import{Q as nn,Z as rn}from"./JsonOutput-D7ovfzRT.js";import{d as an}from"./select-DTBn5eTb.js";import{n as on}from"./download-CDIt5qnG.js";import{t as sn}from"./switch-CTaiAjrz.js";import{t as cn}from"./tooltip-C9TuY18o.js";import{r as ln,t as un}from"./button-COI-NGrx.js";import{t as dn}from"./createLucideIcon-DfJ2oMlA.js";import{i as fn,n as pn}from"./paths-bkIFVj8h.js";import{r as mn}from"./layout-C9xXio49.js";import{A as hn,C as gn,D as _n,_ as vn,j as yn,t as bn,v as xn,y as Sn}from"./ai-model-dropdown-BSXpoT5O.js";import{r as Cn}from"./useNumberFormatter-D7O_26UI.js";import{t as wn}from"./circle-check-BCurAHEb.js";import{B as Tn,F as En,G as Dn,I as On,L as kn,M as An,R as jn,T as Mn,V as Nn,W as Pn,c as Fn,f as In,i as Ln,n as Rn,o as zn,r as Bn,s as Vn,w as Hn,z as Un}from"./add-cell-with-ai-Hyi0ODfx.js";import{t as Wn}from"./database-zap-B_PMVg8T.js";import{r as Gn,t as Kn}from"./file-icons-CdJgUy-I.js";import{t as qn}from"./components-CskjK6xZ.js";import{b as Jn}from"./write-secret-modal-DzKAInL2.js";import{n as Yn}from"./spinner-DyNE-o8o.js";import{n as Xn,o as Zn,r as Qn}from"./readonly-python-code-DcHbbnwj.js";import{n as $n,t as er}from"./useDeleteCell-CkcC1fWW.js";import{t as tr}from"./save-Dgoim6QF.js";import{G as nr,I as rr,Ut as ir,Xt as ar,Yt as or,Zt as sr,tn as cr}from"./input-BoBxR50a.js";import{n as lr}from"./copy-D8O_CYCG.js";import{t as ur}from"./use-toast-Wu434mLr.js";import{t as dr}from"./preload-helper-uBIymjUX.js";import{$t as fr,Ct as pr,Dt as mr,E as hr,Et as gr,Ft as _r,Gt as vr,H as yr,I as br,It as xr,Jt as Sr,Kt as Cr,Ot as wr,P as Tr,Qt as I,St as Er,Ut as Dr,V as Or,Vt as kr,Wt as Ar,Xt as jr,_ as Mr,at as L,dt as Nr,gt as Pr,ht as Fr,in as Ir,jt as Lr,lt as Rr,m as zr,ot as Br,st as R,tn as Vr,ut as Hr,w as Ur,wt as Wr,zt as Gr}from"./dist-Cny7_yZb.js";import{C as Kr,E as qr,I as Jr,O as Yr,S as Xr,a as Zr,c as Qr,n as $r,r as ei,w as ti}from"./dist-DBMV4gqt.js";import{o as ni}from"./arrays-BqUx5USx.js";import{n as ri}from"./once-Haz_uxEL.js";import{t as ii}from"./createReducer-DgRODTW6.js";import{a as ai,c as oi,f as si,h as ci,i as li,l as ui,n as di,o as fi,t as pi}from"./dist-qhAY4L2r.js";import{r as mi}from"./strings-B2vv-ENv.js";import{r as hi,t as gi}from"./requests-lt0JK8Jt.js";import{t as _i}from"./badge-crT3E0Rm.js";import{a as vi}from"./dist-DusFODSa.js";import{r as yi}from"./useTheme-n8Dj1zH7.js";import{t as bi}from"./I18nProvider-Cg2I_s1_.js";import{i as xi}from"./numbers-Mk3-CcoU.js";import{n as Si}from"./useAsyncData-C7aJJz0Y.js";import{a as Ci}from"./useRunCells-B5s8dBxS.js";import{l as wi}from"./useInstallPackage-C9-icL78.js";import{a as Ti}from"./errors-CNsgAw6m.js";import{t as z}from"./extends-CvVTau-c.js";import{t as Ei}from"./objectWithoutPropertiesLoose-Do6ywDBO.js";import{t as Di}from"./kbd-pdKBv96t.js";import{a as Oi,n as ki}from"./state-ZLQj4kZ7.js";import{a as Ai,o as ji}from"./cell-link-amlgOuMH.js";import{a as Mi}from"./renderShortcut-C1JwYcqW.js";import{n as Ni,t as Pi}from"./icons-CiZ_8zS-.js";import{n as Fi}from"./esm-CI_o7NhW.js";import{t as Ii}from"./dist-AelfNxj6.js";import{t as Li}from"./skeleton-Cqh4O9g1.js";import{t as Ri}from"./requests-CgSY1X4a.js";import{n as zi}from"./formatting-BqrP-n49.js";import{t as Bi}from"./useSplitCell-5ootkjG6.js";import{n as Vi,r as Hi,t as Ui}from"./panel-accordion-state-DPO3I0D8.js";import{Bo as Wi,Fo as Gi,Ho as Ki,Io as qi,Lo as Ji,No as Yi,Po as Xi,Ro as Zi,Uo as Qi,Vo as $i,ut as ea,zo as ta}from"./loro_wasm_bg-Ctp2cNI9.js";import{t as na}from"./ws-BXWY541V.js";import{t as ra}from"./Inputs-BsQm29hD.js";import{n as ia}from"./hooks-BqWhLYfF.js";var aa=dn(`file-pen`,[[`path`,{d:`M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34`,key:`o6klzx`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z`,key:`zhnas1`}]]),oa={showInput:`Mod-l`,acceptEdit:`Mod-y`,rejectEdit:`Mod-u`},sa=300,ca=Cr.define({combine:e=>Ir(e,{onError:console.error,inputDebounceTime:sa,keymaps:oa},{onError:(e,t)=>e&&t,inputDebounceTime:(e,t)=>e&&t,keymaps:(e,t)=>e&&t})}),la=I.define(),ua=fr.define({create(){return{show:!1,lineFrom:0,lineTo:0}},update(e,t){for(let e of t.effects)if(e.is(la))return e.value;return e}}),da=I.define(),fa=I.define(),pa=fr.define({create(){return{shouldFocus:!1,inputValue:``}},update(e,t){let n=e;for(let e of t.effects)e.is(da)&&(n={...n,inputValue:e.value}),e.is(fa)&&(n={...n,shouldFocus:e.value});return n}}),ma=I.define(),ha=fr.define({create(){return null},update(e,t){for(let e of t.effects)if(e.is(ma))return e.value;return e}}),ga=I.define(),_a=fr.define({create(){return!1},update(e,t){for(let e of t.effects)if(e.is(ga))return e.value;return e}}),va=1,ya=e=>{let{state:t}=e,n=t.selection.main;if(n.empty)return!1;let r=t.doc,i=r.lineAt(n.from),a=r.lineAt(n.to);if(t.sliceDoc(i.from,a.to).trim().length<va)return!1;let o=Math.max(1,Math.min(i.number,r.lines)),s=Math.max(1,Math.min(a.number,r.lines));return e.dispatch({effects:[la.of({show:!0,lineFrom:o,lineTo:s}),fa.of(!0),da.of(``)],selection:Ar.cursor(i.from)}),!0},ba=e=>e.state.field(ha)?(e.dispatch({effects:[ma.of(null),la.of({show:!1,lineFrom:0,lineTo:0}),fa.of(!1),da.of(``),ga.of(!1)]}),!0):!1,xa=e=>{let t=e.state.field(ha);return t?(e.dispatch({changes:{from:t.from,to:t.to,insert:t.oldCode},effects:[ma.of(null),la.of({show:!1,lineFrom:0,lineTo:0}),fa.of(!1),da.of(``),ga.of(!1)]}),!0):!1},Sa=fr.define({create(){return{suggestion:null}},update(e,t){let n=t.effects.find(e=>e.is(Ca));if(!t.docChanged&&!n&&!t.selection)return e;if(n&&t.state.doc===n.value.doc&&t.state.selection.main.head===n.value.pos)return{suggestion:n.value.text};if(e.suggestion&&t.docChanged&&t.startState.selection.ranges.length===1&&t.startState.selection.main.empty&&t.state.selection.ranges.length===1&&t.state.selection.main.empty){let n=t.startState.selection.main.head,r=``,i=0,a=!0;if(t.changes.iterChanges((e,t,o,s,c)=>{i++,a&&=e===n&&t===n,r=c.toString()}),a&&i===1&&r&&e.suggestion.startsWith(r)&&t.state.selection.main.head===n+r.length)return{suggestion:e.suggestion.slice(r.length)||null}}return{suggestion:null}}}),Ca=I.define();function wa(e,t){let n=e.state.selection.main.head,r=[],i=L.widget({widget:new Ta(t),side:1});return r.push(i.range(n)),L.set(r)}var Ta=class extends Nr{suggestion;constructor(e){super(),this.suggestion=e}toDOM(){let e=document.createElement(`span`);return e.style.opacity=`0.4`,e.className=`cm-inline-suggestion`,e.textContent=this.suggestion,e.setAttribute(`role`,`suggestion`),e.setAttribute(`aria-label`,`Suggestion: ${this.suggestion}`),e}get lineBreaks(){return this.suggestion.split(`
2
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,f as r,l as i,o as a,r as o,s,t as c,u as l}from"./useEvent-Dfcbgjhg.js";import{t as u}from"./react-DVplv7_D.js";import{$i as d,Bn as f,Br as p,Bt as m,Ca as h,Ci as g,Co as _,Cr as v,D as y,Dr as b,Fr as x,H as S,I as C,Ir as w,K as T,Lr as E,Lt as D,Ni as O,Nn as ee,Nr as k,Pr as te,Qi as ne,Ri as re,Rr as A,Si as j,U as ie,Ur as M,V as N,Vn as P,W as ae,Wr as oe,Yn as se,Zn as ce,_i as le,_n as ue,_t as de,ai as fe,ar as pe,at as me,b as he,ba as ge,bi as _e,bt as ve,ca as ye,ci as be,cn as xe,cr as Se,d as Ce,dt as we,fi as Te,fn as Ee,fo as De,ft as Oe,ga as ke,gn as Ae,gt as je,h as Me,ha as Ne,ht as Pe,i as Fe,it as Ie,jo as Le,jr as Re,li as ze,lr as Be,mn as Ve,mt as He,ni as Ue,nr as We,or as Ge,ot as Ke,pi as qe,pt as Je,qa as Ye,ri as Xe,rr as Ze,sa as Qe,si as $e,sr as et,ti as tt,tr as nt,tt as rt,u as it,ui as at,un as ot,vn as st,vr as ct,vt as lt,wa as ut,wi as dt,xa as ft,xi as pt,xo as mt,yi as ht,za as gt,zr as F}from"./cells-CN1I_0eH.js";import{t as _t}from"./react-dom-_LrxgvjW.js";import{C as vt,I as yt,M as bt,N as xt,O as St,R as Ct,S as wt,b as Tt}from"./schemas-ChRqMOTL.js";import{C as Et,E as Dt,P as Ot,k as kt,m as At,o as jt,r as Mt,v as Nt}from"./config-MaHeMC9o.js";import{t as Pt}from"./compiler-runtime-BrajqUja.js";import{t as Ft}from"./debounce-aFmHgJZY.js";import{E as It,_ as Lt,c as Rt,g as zt,h as Bt,s as Vt}from"./config-CA1V-wjh.js";import{_ as Ht,c as Ut,g as Wt,m as Gt,t as Kt}from"./useEventListener-D9cftcHj.js";import{t as qt}from"./invariant-Ci2dTZ72.js";import{s as Jt}from"./config-DEzFV5-l.js";import{d as Yt,m as Xt,t as Zt}from"./session-DqoWmb7X.js";import{c as Qt}from"./state-C3oDoyFe.js";import{t as $t}from"./ErrorBoundary-D1ozl9e0.js";import{t as en}from"./cn-ldLVeaqm.js";import{t as tn}from"./jsx-runtime-B74pBk57.js";import{Q as nn,Z as rn}from"./JsonOutput-Dqg7qwkl.js";import{d as an}from"./select-DTBn5eTb.js";import{n as on}from"./download-s8iwxGDb.js";import{t as sn}from"./switch-CTaiAjrz.js";import{t as cn}from"./tooltip-C9TuY18o.js";import{r as ln,t as un}from"./button-COI-NGrx.js";import{t as dn}from"./createLucideIcon-DfJ2oMlA.js";import{i as fn,n as pn}from"./paths-bkIFVj8h.js";import{r as mn}from"./layout-BccvBeZy.js";import{A as hn,C as gn,D as _n,_ as vn,j as yn,t as bn,v as xn,y as Sn}from"./ai-model-dropdown-D5Fe5GS-.js";import{r as Cn}from"./useNumberFormatter-D7O_26UI.js";import{t as wn}from"./circle-check-BCurAHEb.js";import{B as Tn,F as En,G as Dn,I as On,L as kn,M as An,R as jn,T as Mn,V as Nn,W as Pn,c as Fn,f as In,i as Ln,n as Rn,o as zn,r as Bn,s as Vn,w as Hn,z as Un}from"./add-cell-with-ai-C4pN_ho7.js";import{t as Wn}from"./database-zap-B_PMVg8T.js";import{r as Gn,t as Kn}from"./file-icons-CdJgUy-I.js";import{t as qn}from"./components-CskjK6xZ.js";import{b as Jn}from"./write-secret-modal-DzKAInL2.js";import{n as Yn}from"./spinner-DyNE-o8o.js";import{n as Xn,o as Zn,r as Qn}from"./readonly-python-code-BaElyj-4.js";import{n as $n,t as er}from"./useDeleteCell-KX6SEwki.js";import{t as tr}from"./save-Dgoim6QF.js";import{G as nr,I as rr,Ut as ir,Xt as ar,Yt as or,Zt as sr,tn as cr}from"./input-BoBxR50a.js";import{n as lr}from"./copy-D8O_CYCG.js";import{t as ur}from"./use-toast-Wu434mLr.js";import{t as dr}from"./preload-helper-uBIymjUX.js";import{$t as fr,Ct as pr,Dt as mr,E as hr,Et as gr,Ft as _r,Gt as vr,H as yr,I as br,It as xr,Jt as Sr,Kt as Cr,Ot as wr,P as Tr,Qt as I,St as Er,Ut as Dr,V as Or,Vt as kr,Wt as Ar,Xt as jr,_ as Mr,at as L,dt as Nr,gt as Pr,ht as Fr,in as Ir,jt as Lr,lt as Rr,m as zr,ot as Br,st as R,tn as Vr,ut as Hr,w as Ur,wt as Wr,zt as Gr}from"./dist-Cny7_yZb.js";import{C as Kr,E as qr,I as Jr,O as Yr,S as Xr,a as Zr,c as Qr,n as $r,r as ei,w as ti}from"./dist-DBMV4gqt.js";import{o as ni}from"./arrays-BqUx5USx.js";import{n as ri}from"./once-Haz_uxEL.js";import{t as ii}from"./createReducer-DgRODTW6.js";import{a as ai,c as oi,f as si,h as ci,i as li,l as ui,n as di,o as fi,t as pi}from"./dist-qhAY4L2r.js";import{r as mi}from"./strings-B2vv-ENv.js";import{r as hi,t as gi}from"./requests-lt0JK8Jt.js";import{t as _i}from"./badge-crT3E0Rm.js";import{a as vi}from"./dist-DusFODSa.js";import{r as yi}from"./useTheme-n8Dj1zH7.js";import{t as bi}from"./I18nProvider-Cg2I_s1_.js";import{i as xi}from"./numbers-Mk3-CcoU.js";import{n as Si}from"./useAsyncData-C7aJJz0Y.js";import{a as Ci}from"./useRunCells-B847kPLO.js";import{l as wi}from"./useInstallPackage-C9-icL78.js";import{a as Ti}from"./errors-CNsgAw6m.js";import{t as z}from"./extends-CvVTau-c.js";import{t as Ei}from"./objectWithoutPropertiesLoose-Do6ywDBO.js";import{t as Di}from"./kbd-pdKBv96t.js";import{a as Oi,n as ki}from"./state-CHojzKpZ.js";import{a as Ai,o as ji}from"./cell-link-BOqoitvE.js";import{a as Mi}from"./renderShortcut-C1JwYcqW.js";import{n as Ni,t as Pi}from"./icons-CiZ_8zS-.js";import{n as Fi}from"./esm-CI_o7NhW.js";import{t as Ii}from"./dist-AelfNxj6.js";import{t as Li}from"./skeleton-Cqh4O9g1.js";import{t as Ri}from"./requests-CgSY1X4a.js";import{n as zi}from"./formatting-BqrP-n49.js";import{t as Bi}from"./useSplitCell-CnvTmIw7.js";import{n as Vi,r as Hi,t as Ui}from"./panel-accordion-state-ChFIY2WQ.js";import{Bo as Wi,Fo as Gi,Ho as Ki,Io as qi,Lo as Ji,No as Yi,Po as Xi,Ro as Zi,Uo as Qi,Vo as $i,ut as ea,zo as ta}from"./loro_wasm_bg-Ctp2cNI9.js";import{t as na}from"./ws-BXWY541V.js";import{t as ra}from"./Inputs-BsQm29hD.js";import{n as ia}from"./hooks-C1_gQ8kr.js";var aa=dn(`file-pen`,[[`path`,{d:`M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34`,key:`o6klzx`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z`,key:`zhnas1`}]]),oa={showInput:`Mod-l`,acceptEdit:`Mod-y`,rejectEdit:`Mod-u`},sa=300,ca=Cr.define({combine:e=>Ir(e,{onError:console.error,inputDebounceTime:sa,keymaps:oa},{onError:(e,t)=>e&&t,inputDebounceTime:(e,t)=>e&&t,keymaps:(e,t)=>e&&t})}),la=I.define(),ua=fr.define({create(){return{show:!1,lineFrom:0,lineTo:0}},update(e,t){for(let e of t.effects)if(e.is(la))return e.value;return e}}),da=I.define(),fa=I.define(),pa=fr.define({create(){return{shouldFocus:!1,inputValue:``}},update(e,t){let n=e;for(let e of t.effects)e.is(da)&&(n={...n,inputValue:e.value}),e.is(fa)&&(n={...n,shouldFocus:e.value});return n}}),ma=I.define(),ha=fr.define({create(){return null},update(e,t){for(let e of t.effects)if(e.is(ma))return e.value;return e}}),ga=I.define(),_a=fr.define({create(){return!1},update(e,t){for(let e of t.effects)if(e.is(ga))return e.value;return e}}),va=1,ya=e=>{let{state:t}=e,n=t.selection.main;if(n.empty)return!1;let r=t.doc,i=r.lineAt(n.from),a=r.lineAt(n.to);if(t.sliceDoc(i.from,a.to).trim().length<va)return!1;let o=Math.max(1,Math.min(i.number,r.lines)),s=Math.max(1,Math.min(a.number,r.lines));return e.dispatch({effects:[la.of({show:!0,lineFrom:o,lineTo:s}),fa.of(!0),da.of(``)],selection:Ar.cursor(i.from)}),!0},ba=e=>e.state.field(ha)?(e.dispatch({effects:[ma.of(null),la.of({show:!1,lineFrom:0,lineTo:0}),fa.of(!1),da.of(``),ga.of(!1)]}),!0):!1,xa=e=>{let t=e.state.field(ha);return t?(e.dispatch({changes:{from:t.from,to:t.to,insert:t.oldCode},effects:[ma.of(null),la.of({show:!1,lineFrom:0,lineTo:0}),fa.of(!1),da.of(``),ga.of(!1)]}),!0):!1},Sa=fr.define({create(){return{suggestion:null}},update(e,t){let n=t.effects.find(e=>e.is(Ca));if(!t.docChanged&&!n&&!t.selection)return e;if(n&&t.state.doc===n.value.doc&&t.state.selection.main.head===n.value.pos)return{suggestion:n.value.text};if(e.suggestion&&t.docChanged&&t.startState.selection.ranges.length===1&&t.startState.selection.main.empty&&t.state.selection.ranges.length===1&&t.state.selection.main.empty){let n=t.startState.selection.main.head,r=``,i=0,a=!0;if(t.changes.iterChanges((e,t,o,s,c)=>{i++,a&&=e===n&&t===n,r=c.toString()}),a&&i===1&&r&&e.suggestion.startsWith(r)&&t.state.selection.main.head===n+r.length)return{suggestion:e.suggestion.slice(r.length)||null}}return{suggestion:null}}}),Ca=I.define();function wa(e,t){let n=e.state.selection.main.head,r=[],i=L.widget({widget:new Ta(t),side:1});return r.push(i.range(n)),L.set(r)}var Ta=class extends Nr{suggestion;constructor(e){super(),this.suggestion=e}toDOM(){let e=document.createElement(`span`);return e.style.opacity=`0.4`,e.className=`cm-inline-suggestion`,e.textContent=this.suggestion,e.setAttribute(`role`,`suggestion`),e.setAttribute(`aria-label`,`Suggestion: ${this.suggestion}`),e}get lineBreaks(){return this.suggestion.split(`
3
3
  `).length-1}},Ea=class{cache=new Map;timeout;constructor(e){this.timeout=e}get(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>this.timeout?(this.cache.delete(e),null):t.result:null}set(e,t){if(t){for(let[e,t]of this.cache)Date.now()-t.timestamp>this.timeout&&this.cache.delete(e);if(this.cache.delete(e),this.cache.set(e,{result:t,timestamp:Date.now()}),this.cache.size>20){let e=this.cache.keys().next().value;e!==void 0&&this.cache.delete(e)}}}},Da=(e,t)=>Hr.fromClass(class{abortController=null;timer=null;cache;constructor(){this.cache=new Ea(t.cacheTimeout??1e3)}cancel(){this.timer!==null&&clearTimeout(this.timer),this.timer=null,this.abortController?.abort(),this.abortController=null}update(n){let r=n.transactions.some(e=>e.effects.some(e=>e.is(Ca)&&e.value.text===null));if(!n.docChanged&&!n.selectionSet&&!r&&!(n.focusChanged&&!n.view.hasFocus)||(this.cancel(),!n.docChanged||n.state.field(Sa).suggestion||!n.state.selection.main.empty||n.state.selection.ranges.length!==1||t.events?.beforeSuggestionFetch?.(n.view)===!1))return;let i=new AbortController;this.abortController=i;let a=n.state.doc,o=n.state.selection.main.head,s=JSON.stringify([a.toString(),o]),c=this.cache.get(s),l=async()=>{if(!i.signal.aborted)try{let r=c??await e(n.state,i.signal,n.view);if(i.signal.aborted||n.view.state.doc!==a||n.view.state.selection.main.head!==o||t.events?.shouldShowSuggestion?.(n.view,r)===!1)return;this.cache.set(s,r),n.view.dispatch({effects:Ca.of({text:r,doc:a,pos:o})})}catch(e){!i.signal.aborted&&e instanceof Error&&e.name!==`AbortError`&&console.error(`Suggestion fetch error:`,e)}};this.timer=setTimeout(l,c?0:t.delay??500)}destroy(){this.cancel()}}),Oa=Hr.fromClass(class{decorations;constructor(){this.decorations=L.none}update(e){let t=e.state.field(Sa)?.suggestion;if(!t){this.decorations=L.none;return}this.decorations=wa(e.view,t)}},{decorations:e=>e.decorations});function ka(e,t,n,r){return{...e.changeByRange(i=>{if(i===e.selection.main)return{changes:{from:n,to:r,insert:t},range:Ar.cursor(n+t.length)};let a=r-n;return!i.empty||a&&e.sliceDoc(i.from-a,i.from)!==e.sliceDoc(n,r)?{range:i}:{changes:{from:i.from-a,to:i.from,insert:t},range:Ar.cursor(i.from-a+t.length)}}),userEvent:`input.complete`}}var Aa=e=>{let t=e.state.field(Sa)?.suggestion;if(!t)return!1;let n=e.state.facet(Na);return e.dispatch({...ka(e.state,t,e.state.selection.main.head,e.state.selection.main.head)}),n.events?.onSuggestionAccepted?.(e,t),!0},ja=e=>{let t=e.state.field(Sa)?.suggestion;if(!t)return!1;let n=e.state.facet(Na);return e.dispatch({effects:Ca.of({text:null,doc:e.state.doc,pos:e.state.selection.main.head})}),n.events?.onSuggestionRejected?.(e,t),!0},Ma=gr.of([{key:`Tab`,run:Aa},{key:`Escape`,run:ja}]),Na=Cr.define({combine:e=>e.at(-1)});function Pa(e){let{includeKeymap:t=!0}=e;return[Sa,Na.of(e),Da(e.fetchFn,e),Oa,t?Ma:[]]}var Fa=R.baseTheme({".cm-ai-input-container":{display:`flex`,flexDirection:`column`,gap:`4px`,width:`min(calc(100% + 7px), 500px)`,padding:`5px 5px`,margin:`0 -6px`,backgroundColor:`light-dark(rgb(241, 243, 245), rgb(40, 40, 40))`},".cm-ai-input":{display:`block`,width:`100%`,padding:`3px 8px`,border:`2px solid rgb(51, 154, 240)`,borderRadius:`5px`,fontSize:`12px`},".cm-ai-help-info-button":{fontSize:`10px`,paddingLeft:`10px`,height:`18px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,display:`block`,marginRight:`auto`},".cm-ai-help-info-button:hover":{color:`light-dark(rgb(89, 97, 105), rgb(190, 190, 190))`},".cm-ai-generate-button":{background:`#0E639C`,border:`none`,padding:`2px 6px`,color:`#ffffff`,cursor:`pointer`,font:`inherit`,borderRadius:`4px`,"&:hover":{backgroundColor:`#1177bb`}},".cm-line.cm-ai-selection, .cm-line.cm-ai-selection.cm-active-line":{backgroundColor:`light-dark(color-mix(in srgb, rgb(223, 227, 232) 50%, transparent), color-mix(in srgb, rgb(50, 50, 50) 50%, transparent)) !important`},".cm-line:has(.cm-new-code-line)":{backgroundColor:`light-dark(color-mix(in srgb, rgb(183, 235, 143) 50%, transparent), color-mix(in srgb, rgb(40, 100, 40) 50%, transparent)) !important`},".cm-old-code-container":{backgroundColor:`light-dark(rgb(255, 205, 205), rgb(100, 40, 40))`,position:`relative`,display:`flex`,paddingTop:`0`,width:`100%`,alignItems:`center`},".cm-code-button":{position:`absolute`,right:`5px`,top:`50%`,transform:`translateY(-50%)`,background:`none`,border:`none`,cursor:`pointer`,fontSize:`16px`},".cm-floating-buttons":{fontFamily:`sans-serif`,position:`absolute`,top:`-20px`,left:`5px`,display:`flex`},".cm-floating-button":{fontFamily:`sans-serif`,padding:`2px 5px`,fontSize:`10px`,cursor:`pointer`,fontWeight:`700`},".cm-floating-accept":{backgroundColor:`light-dark(rgb(55, 125, 34), rgb(40, 80, 25))`,borderTopLeftRadius:`5px`,borderBottomLeftRadius:`5px`,color:`white`,filter:`brightness(90%)`,"&:hover":{filter:`brightness(100%)`}},".cm-floating-reject":{backgroundColor:`light-dark(rgb(220, 53, 69), rgb(180, 40, 50))`,color:`white`,borderTopRightRadius:`5px`,borderBottomRightRadius:`5px`,filter:`brightness(90%)`,"&:hover":{filter:`brightness(100%)`}},".hotkey":{display:`inline-block`,padding:`0 4px`,borderRadius:`3px`,backgroundColor:`rgba(255, 255, 255, 0.1)`,fontSize:`90%`},".cm-ai-loading-indicator":{fontStyle:`italic`,fontSize:`10px`,paddingLeft:`12px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,opacity:`0`,transition:`opacity 0.3s ease-in-out`,"&::after":{content:`""`,display:`inline-block`,animation:`ellipsis-pulse 1.5s steps(4, end) infinite`},"&:not(:empty)":{opacity:`1`}},".cm-ai-input:disabled":{opacity:`0.5`},"@keyframes ellipsis-pulse":{"0%":{content:`'.'`},"25%":{content:`'..'`},"50%":{content:`'...'`},"75%":{content:`''`}},".cm-ai-loading-container":{display:`flex`,alignItems:`center`,padding:`0 8px`},".cm-ai-cancel-button":{padding:`2px 8px`,fontSize:`10px`,borderRadius:`4px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,cursor:`pointer`,"&:hover":{background:`light-dark(rgb(223, 227, 232), rgb(50, 50, 50))`}},".hidden":{display:`none`}}),Ia={mac:`⌘`,windows:`Ctrl`,default:`Ctrl`};function La(){return navigator.platform.startsWith(`Mac`)?Ia.mac:navigator.platform.startsWith(`Win`)?Ia.windows:Ia.default}function Ra(e){return e.replace(`Mod`,La()).replace(`-`,` `).toUpperCase()}function B(e,t){let n=document.createElement(e);return n.className=t,n}function za(e){let t=e.state.facet(ca),n={...oa,...t.keymaps},r=e.state.facet(Ba),i=B(`div`,`cm-ai-tooltip`).appendChild(B(`div`,`cm-ai-tooltip-button`)),a=i.appendChild(document.createElement(`span`));a.textContent=`${r.label} `;let o=a.appendChild(document.createElement(`span`));return o.className=`hotkey`,o.textContent=Ra(n.showInput),i.querySelector(`span`)?.addEventListener(`mousedown`,e=>{e.stopPropagation(),e.button===0&&e.preventDefault()}),i.querySelector(`span`)?.addEventListener(`click`,t=>{t.preventDefault(),ya(e)}),i}var Ba=Cr.define({combine(e){return Ir(e,{render:za,hideOnBlur:!1,label:`Edit with AI`})}}),Va=Hr.fromClass(class{view;suppress;dom;mousedown=()=>{this.suppress=!0};mouseup=()=>{this.suppress=!1,this.display(this.view)};scroll=()=>{this.display(this.view)};windowScroll=()=>{this.display(this.view)};constructor(e){this.view=e;let t=e.state.facet(Ba);this.suppress=!1,document.addEventListener(`mousedown`,this.mousedown),document.addEventListener(`mouseup`,this.mouseup),e.scrollDOM.addEventListener(`scroll`,this.scroll),window.addEventListener(`scroll`,this.windowScroll,!0);let n=t.render(e);e.dom.appendChild(n),this.dom=n}update(e){this.display(e.view)}docViewUpdate(e){this.display(e)}display(e){if(e.state.field(ua).show){this.dom.style.display=`none`;return}if(e.state.facet(Ba).hideOnBlur&&!e.hasFocus){this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`);return}e.requestMeasure({read:this.#e})}#e=e=>{let t=e.state.selection.ranges.find(e=>!e.empty);if(t&&!this.suppress){let n=e.coordsAtPos(t.from),r=e.coordsAtPos(t.to);if(!n||!r)return;let i=e.dom.getBoundingClientRect(),a=e.dom.parentElement?.getBoundingClientRect(),o=e=>e.top>=i.top&&e.top<=i.bottom&&e.left>=i.left&&e.left<=i.right,s=e=>!a||e.top>=a.top&&e.top<=a.bottom&&e.left>=a.left&&e.left<=a.right,c=o(n)||o(r),l=s(n)||s(r);if(!c||!l){this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`);return}this.dom.style.display=`flex`,this.dom.setAttribute(`aria-hidden`,`false`);let u=this.dom.getBoundingClientRect(),d=o(n)?n:r,f=i.right-u.width,p=Math.min(d.left,f),m=d.top-u.height,h=a?a.y:-1/0;m<h&&(m=r.bottom),this.dom.style.left=`${p}px`,this.dom.style.top=`${m}px`,requestAnimationFrame(()=>{this.dom&&this.dom.setAttribute(`aria-hidden`,`false`)})}else this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`)};destroy(){document.removeEventListener(`mousedown`,this.mousedown),document.removeEventListener(`mouseup`,this.mouseup),this.view.scrollDOM.removeEventListener(`scroll`,this.scroll),window.removeEventListener(`scroll`,this.windowScroll,!0),this.dom.remove()}}),Ha=R.baseTheme({".cm-ai-tooltip-button":{userSelect:`none`,fontFamily:`system-ui, -apple-system, sans-serif`,position:`fixed`,display:`flex`,boxSizing:`border-box`,padding:`2px 6px`,borderRadius:`4px`,fontSize:`12px`,backgroundColor:`#0E639C`,color:`#ffffff`,border:`1px solid transparent`,boxShadow:`0 2px 4px rgba(0,0,0,0.1)`,zIndex:`999`,transition:`opacity 0.5s`,"&[aria-hidden='true']":{opacity:`0`},"&[aria-hidden='false']":{opacity:`1`},"& > span":{pointerEvents:`auto`,cursor:`pointer`,display:`inline-block`,padding:`2px`},"&:hover":{backgroundColor:`#1177bb`}}});function Ua(){return[Va,Ha]}var Wa=class extends Nr{oldCode;constructor(e){super(),this.oldCode=e}toDOM(e){let t=B(`div`,`cm-old-code-container`);t.setAttribute(`role`,`region`),t.setAttribute(`aria-label`,`Previous code version`);let n=B(`div`,`cm-old-code cm-line`);n.textContent=this.oldCode;let r=B(`div`,`cm-floating-buttons`),i=e.state.facet(ca),a={...oa,...i.keymaps},o=B(`button`,`cm-floating-button cm-floating-accept`);o.innerHTML=`<span class="hotkey">${Ra(a.acceptEdit)}</span> Accept`,o.setAttribute(`aria-label`,`Accept changes`),o.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e.focus(),ba(e)});let s=B(`button`,`cm-floating-button cm-floating-reject`);return s.innerHTML=`<span class="hotkey">${Ra(a.rejectEdit)}</span> Reject`,s.setAttribute(`aria-label`,`Reject changes`),s.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e.focus(),xa(e)}),r.append(o,s),t.append(n,r),t}updateDOM(e,t){return!0}},Ga=class extends Nr{complete;abortController=null;dom=null;input=null;loadingContainer=null;helpInfo=null;inputContainer=null;form=null;view=null;constructor(e){super(),this.complete=e}toDOM(e){if(this.dom)return this.dom;this.view=e;let t=e.state.field(pa),n=e.state.field(_a),r=B(`div`,`cm-ai-input-container`);this.inputContainer=r,this.dom=r;let i=B(`form`,`cm-ai-input-form`);this.form=i,i.setAttribute(`role`,`search`),i.setAttribute(`aria-label`,`AI editing instructions`),i.addEventListener(`submit`,e=>e.preventDefault());let a=B(`input`,`cm-ai-input`);this.input=a,i.append(a),a.placeholder=`Editing instructions...`,a.setAttribute(`aria-label`,`AI editing instructions`),a.setAttribute(`autocomplete`,`off`),a.setAttribute(`spellcheck`,`true`),a.value=t.inputValue;let o=B(`div`,`cm-ai-loading-container`);this.loadingContainer=o;let s=B(`div`,`cm-ai-loading-indicator`);s.setAttribute(`role`,`status`),s.setAttribute(`aria-live`,`polite`),s.textContent=`Generating`;let c=B(`button`,`cm-ai-cancel-button`);c.textContent=`Cancel`,c.setAttribute(`aria-label`,`Cancel code generation`),c.addEventListener(`click`,this.onCancel),o.append(c,s);let l=B(`div`,`cm-ai-help-info`);this.helpInfo=l;let u=l.appendChild(document.createElement(`button`));u.className=`cm-ai-help-info-button`,u.textContent=`Esc to close`,u.addEventListener(`click`,this.onCancel);let d=B(`button`,`cm-ai-generate-button`);d.textContent=`⏎ Generate`,d.setAttribute(`aria-label`,`Generate code`),d.addEventListener(`click`,this.handleSubmit),this.toggleLoading(n),t.shouldFocus&&requestAnimationFrame(()=>{a.value=t.inputValue,a.focus(),e.dispatch({effects:fa.of(!1)})}),f(a.value),a.addEventListener(`input`,m),a.addEventListener(`keydown`,this.onKeyDown);function f(e){l.replaceChildren(e?d:u)}let p=``;function m(){e.dispatch({effects:da.of(a.value)});let t=a.value.trim();t!==p&&(p=t,f(t))}return r}toggleLoading(e){this.inputContainer&&this.form&&this.loadingContainer&&this.helpInfo&&this.inputContainer?.replaceChildren(this.form,e?this.loadingContainer:this.helpInfo)}onKeyDown=async e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),await this.handleSubmit()):e.key===`Escape`&&this.onCancel()};onCancel=()=>{this.cleanup();let e=this.view;e&&(e.dispatch({effects:[la.of({show:!1,lineFrom:0,lineTo:0}),ga.of(!1)]}),e.focus())};handleSubmit=async e=>{let t=this.view;if(!t)return;let n=t.state.facet(ca);e?.stopPropagation();let r=t.state.field(ua),{input:i}=this;if(!i)return;let a=i.value.trim();if(!r.show||!a)return;let o=t.state.doc.line(r.lineFrom),s=t.state.doc.line(r.lineTo),c=o.from,l=s.to,u=t.state.sliceDoc(c,l),d=t.state.sliceDoc(0,c),f=t.state.sliceDoc(l);this.abortController=new AbortController,t.dispatch({effects:ga.of(!0)}),this.toggleLoading(!0);try{let e=await this.complete({prompt:a,selection:u,codeBefore:d,codeAfter:f,editorView:t,signal:this.abortController.signal});if(!t.state.field(ua).show)return;if(!e||typeof e!=`string`)throw Error(`Invalid completion result`);t.dispatch({changes:{from:c,to:l,insert:e},effects:[la.of({show:!1,lineFrom:0,lineTo:0}),ma.of({from:c,to:c+e.length,oldCode:u,newCode:e}),ga.of(!1)]})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;n.onError?.(e)}finally{this.cleanup(),this.toggleLoading(!1),t.focus()}};updateDOM(e,t){return this.dom=e,this.input=e.querySelector(`.cm-ai-input`),!0}cleanup(){this.abortController?.abort(),this.abortController=null,this.dom?.remove(),this.input?.remove(),this.dom=null,this.input=null}destroy(){this.cleanup()}};function Ka(e){if(!e.prompt)throw Error(`prompt function is required`);let t={...oa,...e.keymaps};return[ca.of(e),ua,pa,ha,_a,Ua(),Fa,gr.of([{key:t.showInput,run:ya}]),Sr.highest([gr.of([{key:t.acceptEdit,run:ba},{key:t.rejectEdit,run:xa}])]),qa,Ja,Ya,Xa]}var qa=R.updateListener.of(e=>{let t=e.state.field(ua);if(!t.show||!e.docChanged)return;let{lineFrom:n,lineTo:r}=t,i=!1;e.changes.iterChanges((t,a,o,s)=>{let c=e.state.doc.lineAt(t).number;if(c<n){let t=e.state.doc.lineAt(s).number-e.state.doc.lineAt(o).number;n+=t,r+=t,i=!0}else if(c<=r){let t=e.state.doc.lineAt(s).number-e.state.doc.lineAt(o).number;r+=t,i=!0}}),i&&e.view.dispatch({effects:[la.of({show:!0,lineFrom:n,lineTo:r})]})}),Ja=R.decorations.of(e=>{let t=e.state.field(ha);return t?L.set([L.mark({class:`cm-new-code-line`}).range(t.from,t.to)]):L.none}),Ya=R.decorations.compute([ua],e=>{let t=e.field(ua),n=e.facet(ca),r=[];if(t.show){let i=t.lineFrom,a=t.lineTo;for(let t=i;t<=a;t++){let a=e.doc.line(t).from;r.push(L.line({class:`cm-ai-selection`}).range(a)),t===i&&r.push(L.widget({widget:new Ga(n.prompt),side:-1}).range(a))}}return L.set(r)}),Xa=fr.define({create(e){return L.none},update(e,t){let n=t.state.field(ha);return n?L.set([L.widget({widget:new Wa(n.oldCode),block:!0}).range(n.from)]):L.none},provide:e=>R.decorations.from(e)}),V=e(u(),1),H=Pt(),Za=()=>({entries:new Map}),{valueAtom:Qa,useActions:$a}=ii(Za,{submit:(e,t)=>{let{cellIds:n,deleteCell:r,deleteManyCells:i,store:a}=t,o=a.get(he),s=a.get(tt),c=new Set(o.cellIds.inOrderIds.filter(e=>o.cellData[e].code.trim()===``)),l=new Map;for(let e of n){if(c.has(e)){l.set(e,{cellId:e,type:`simple`});continue}let t=o.cellRuntime[e],n=new Map;for(let t of Object.values(s)){let r=t.declaredBy.includes(e),i=t.usedBy.some(e=>!c.has(e));r&&i&&n.set(t.name,t.usedBy)}let r;t?.runElapsedTimeMs&&t.runElapsedTimeMs>2e3&&(r=t.runElapsedTimeMs),n.size===0&&r===void 0?l.set(e,{cellId:e,type:`simple`}):l.set(e,{cellId:e,type:`expensive`,executionDurationMs:r,defs:n})}let u=[...l.values()].every(e=>e.type===`simple`);return l.size>0&&u?(l.size===1?r({cellId:[...l.values()][0].cellId}):i({cellIds:[...l.values()].map(e=>e.cellId)}),Za()):{...e,entries:l}},clear:()=>Za()});function eo(){let e=n(),{submit:t,clear:r}=$a(),{entries:a}=i(Qa),o=er(),s=$n();return{submit:n=>{t({cellIds:n,deleteCell:o,deleteManyCells:s,store:e})},clear:r,get idle(){return a.size===0},get shouldConfirmDelete(){return a.size>1}}}function to(e){let t=(0,H.c)(16),n=i(Qa),r=$a(),a=$n(),o;t[0]!==e||t[1]!==n.entries?(o=n.entries.get(e),t[0]=e,t[1]=n.entries,t[2]=o):o=t[2];let s=o;if(!s){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e={isPending:!1},t[3]=e):e=t[3],e}if(n.entries.size!==1){let e;return t[4]===s?e=t[5]:(e={isPending:!0,shouldConfirmDelete:!1,...s},t[4]=s,t[5]=e),e}let c;t[6]!==r||t[7]!==a||t[8]!==n.entries?(c=()=>{a({cellIds:[...n.entries.values()].map(no)}),r.clear()},t[6]=r,t[7]=a,t[8]=n.entries,t[9]=c):c=t[9];let l;t[10]===r?l=t[11]:(l=()=>r.clear(),t[10]=r,t[11]=l);let u;return t[12]!==s||t[13]!==c||t[14]!==l?(u={isPending:!0,...s,shouldConfirmDelete:!0,confirm:c,cancel:l},t[12]=s,t[13]=c,t[14]=l,t[15]=u):u=t[15],u}function no(e){return e.cellId}async function ro(e){if(!e.ok)throw Error(await e.text());if(!e.body)throw Error(`Failed to get response body`);let t=null,n=!1;if(await Nn({stream:Dn({stream:e.body,schema:Pn}).pipeThrough(new TransformStream({transform(e){if(!e.success)throw e.error;let r=e.value;if(kn(r)&&r.type===En)t=On.parse(r.data).code;else if(r.type===`error`)throw Error(r.errorText);else r.type===`finish`&&(n=r.finishReason===`stop`)}})),onError:e=>{throw e}}),!n)throw Error(`AI completion ended before final validation`);if(t===null)throw Error(`AI completion returned no cell code`);return t}async function io(e){let t=`
4
4
  ${e.codeBefore}
5
5
  <rewrite_this>
@@ -1 +1 @@
1
- import{c as e,l as t,t as n,u as r}from"./useEvent-Dfcbgjhg.js";import{D as i,In as a,M as o,P as s,gr as c,xo as l,za as u}from"./cells-CJf50CB9.js";import{E as d,v as f}from"./config-MaHeMC9o.js";import{t as p}from"./compiler-runtime-BrajqUja.js";import{p as m}from"./config-CA1V-wjh.js";import{g as h}from"./useEventListener-D9cftcHj.js";import{i as g}from"./utils-B4K466FK.js";import{c as _}from"./session-DqoWmb7X.js";import{t as v}from"./cn-ldLVeaqm.js";import{t as y}from"./jsx-runtime-B74pBk57.js";import{n as b}from"./paths-bkIFVj8h.js";import{b as x}from"./write-secret-modal-DzKAInL2.js";import{r as S}from"./requests-lt0JK8Jt.js";var C=p();function w(){return t(u)}function T(){let t=(0,C.c)(5),[i]=e(f),a=r(u),{openAlert:o}=x(),{sendRename:s}=S(),c;return t[0]!==i.state||t[1]!==o||t[2]!==s||t[3]!==a?(c=async e=>{let t=m();return i.state===d.OPEN?(_(t=>{e===null?t.delete(g.filePath):t.set(g.filePath,e)}),s({filename:e}).then(()=>(a(e),document.title=t.app_title||b.basename(e)||`Untitled Notebook`,e)).catch(e=>(o(e.message),null))):(o(`Failed to save notebook: not connected to a kernel.`),null)},t[0]=i.state,t[1]=o,t[2]=s,t[3]=a,t[4]=c):c=t[4],n(c)}var E=y(),D=e=>{let t=(0,C.c)(12),{className:n,cellId:r,variant:c,onClick:l,formatCellName:u,skipScroll:d}=e,f=s()[r]??``,p=o().inOrderIds.indexOf(r),{showCellIfHidden:m}=i(),h=u??j,g;t[0]===n?g=t[1]:(g=v(`inline-block cursor-pointer text-link hover:underline`,n),t[0]=n,t[1]=g);let _;t[2]!==r||t[3]!==l||t[4]!==m||t[5]!==d||t[6]!==c?(_=e=>{if(r===`__scratch__`)return!1;m({cellId:r}),e.stopPropagation(),e.preventDefault(),requestAnimationFrame(()=>{A(r,c,d)&&l?.()})},t[2]=r,t[3]=l,t[4]=m,t[5]=d,t[6]=c,t[7]=_):_=t[7];let y=h(a(f,p)),b;return t[8]!==g||t[9]!==_||t[10]!==y?(b=(0,E.jsx)(`div`,{className:g,role:`link`,tabIndex:-1,onClick:_,children:y}),t[8]=g,t[9]=_,t[10]=y,t[11]=b):b=t[11],b},O=e=>{let t=(0,C.c)(2),n;return t[0]===e?n=t[1]:(n=(0,E.jsx)(D,{...e,variant:`destructive`}),t[0]=e,t[1]=n),n},k=e=>{let t=(0,C.c)(10),{cellId:n,lineNumber:r}=e,i=w(),a;t[0]!==n||t[1]!==r?(a=()=>c(n,r),t[0]=n,t[1]=r,t[2]=a):a=t[2];let o;t[3]!==n||t[4]!==i?(o=e=>n===`__scratch__`?`scratch`:`marimo://${i||`untitled`}#cell=${e}`,t[3]=n,t[4]=i,t[5]=o):o=t[5];let s;return t[6]!==n||t[7]!==a||t[8]!==o?(s=(0,E.jsx)(D,{cellId:n,onClick:a,skipScroll:!0,variant:`destructive`,className:`traceback-cell-link`,formatCellName:o}),t[6]=n,t[7]=a,t[8]=o,t[9]=s):s=t[9],s};function A(e,t,n){let r=l.create(e),i=document.getElementById(r),a=i?.classList.contains(`has-error`);return i===null?(h.error(`Cell ${r} not found on page.`),!1):(n||i.scrollIntoView({behavior:`smooth`,block:`center`}),(t===`destructive`||a&&t===void 0)&&(i.classList.add(`error-outline`),setTimeout(()=>{i.classList.remove(`error-outline`)},2e3)),(t===`focus`||!a&&t===void 0)&&(i.classList.add(`focus-outline`),setTimeout(()=>{i.classList.remove(`focus-outline`)},2e3)),!0)}function j(e){return e}export{w as a,A as i,O as n,T as o,k as r,D as t};
1
+ import{c as e,l as t,t as n,u as r}from"./useEvent-Dfcbgjhg.js";import{D as i,In as a,M as o,P as s,gr as c,xo as l,za as u}from"./cells-CN1I_0eH.js";import{E as d,v as f}from"./config-MaHeMC9o.js";import{t as p}from"./compiler-runtime-BrajqUja.js";import{p as m}from"./config-CA1V-wjh.js";import{g as h}from"./useEventListener-D9cftcHj.js";import{i as g}from"./utils-B4K466FK.js";import{c as _}from"./session-DqoWmb7X.js";import{t as v}from"./cn-ldLVeaqm.js";import{t as y}from"./jsx-runtime-B74pBk57.js";import{n as b}from"./paths-bkIFVj8h.js";import{b as x}from"./write-secret-modal-DzKAInL2.js";import{r as S}from"./requests-lt0JK8Jt.js";var C=p();function w(){return t(u)}function T(){let t=(0,C.c)(5),[i]=e(f),a=r(u),{openAlert:o}=x(),{sendRename:s}=S(),c;return t[0]!==i.state||t[1]!==o||t[2]!==s||t[3]!==a?(c=async e=>{let t=m();return i.state===d.OPEN?(_(t=>{e===null?t.delete(g.filePath):t.set(g.filePath,e)}),s({filename:e}).then(()=>(a(e),document.title=t.app_title||b.basename(e)||`Untitled Notebook`,e)).catch(e=>(o(e.message),null))):(o(`Failed to save notebook: not connected to a kernel.`),null)},t[0]=i.state,t[1]=o,t[2]=s,t[3]=a,t[4]=c):c=t[4],n(c)}var E=y(),D=e=>{let t=(0,C.c)(12),{className:n,cellId:r,variant:c,onClick:l,formatCellName:u,skipScroll:d}=e,f=s()[r]??``,p=o().inOrderIds.indexOf(r),{showCellIfHidden:m}=i(),h=u??j,g;t[0]===n?g=t[1]:(g=v(`inline-block cursor-pointer text-link hover:underline`,n),t[0]=n,t[1]=g);let _;t[2]!==r||t[3]!==l||t[4]!==m||t[5]!==d||t[6]!==c?(_=e=>{if(r===`__scratch__`)return!1;m({cellId:r}),e.stopPropagation(),e.preventDefault(),requestAnimationFrame(()=>{A(r,c,d)&&l?.()})},t[2]=r,t[3]=l,t[4]=m,t[5]=d,t[6]=c,t[7]=_):_=t[7];let y=h(a(f,p)),b;return t[8]!==g||t[9]!==_||t[10]!==y?(b=(0,E.jsx)(`div`,{className:g,role:`link`,tabIndex:-1,onClick:_,children:y}),t[8]=g,t[9]=_,t[10]=y,t[11]=b):b=t[11],b},O=e=>{let t=(0,C.c)(2),n;return t[0]===e?n=t[1]:(n=(0,E.jsx)(D,{...e,variant:`destructive`}),t[0]=e,t[1]=n),n},k=e=>{let t=(0,C.c)(10),{cellId:n,lineNumber:r}=e,i=w(),a;t[0]!==n||t[1]!==r?(a=()=>c(n,r),t[0]=n,t[1]=r,t[2]=a):a=t[2];let o;t[3]!==n||t[4]!==i?(o=e=>n===`__scratch__`?`scratch`:`marimo://${i||`untitled`}#cell=${e}`,t[3]=n,t[4]=i,t[5]=o):o=t[5];let s;return t[6]!==n||t[7]!==a||t[8]!==o?(s=(0,E.jsx)(D,{cellId:n,onClick:a,skipScroll:!0,variant:`destructive`,className:`traceback-cell-link`,formatCellName:o}),t[6]=n,t[7]=a,t[8]=o,t[9]=s):s=t[9],s};function A(e,t,n){let r=l.create(e),i=document.getElementById(r),a=i?.classList.contains(`has-error`);return i===null?(h.error(`Cell ${r} not found on page.`),!1):(n||i.scrollIntoView({behavior:`smooth`,block:`center`}),(t===`destructive`||a&&t===void 0)&&(i.classList.add(`error-outline`),setTimeout(()=>{i.classList.remove(`error-outline`)},2e3)),(t===`focus`||!a&&t===void 0)&&(i.classList.add(`focus-outline`),setTimeout(()=>{i.classList.remove(`focus-outline`)},2e3)),!0)}function j(e){return e}export{w as a,A as i,O as n,T as o,k as r,D as t};
@@ -217,4 +217,4 @@ mark line col
217
217
  )
218
218
  `]));let n=this._buffer.match(this._osc_regex);if(n===null)return e.kind=Bj.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;e.kind=Bj.OSCURL,e.url=n[1],e.text=n[2];var i=n[0].length;return this._buffer=this._buffer.slice(i),e}if(r==`(`)return e.kind=Bj.Unknown,this._buffer=this._buffer.slice(3),e}}ansi_to_html(e){this.append_buffer(e);for(var t=[];;){var n=this.get_next_packet();if(n.kind==Bj.EOS||n.kind==Bj.Incomplete)break;n.kind!=Bj.ESC&&n.kind!=Bj.Unknown&&(n.kind==Bj.Text?t.push(this.transform_to_html(this.with_state(n))):n.kind==Bj.SGR?this.process_ansi(n):n.kind==Bj.OSCURL&&t.push(this.process_hyperlink(n)))}return t.join(``)}with_state(e){return{bold:this.bold,faint:this.faint,italic:this.italic,underline:this.underline,fg:this.fg,bg:this.bg,text:e.text}}process_ansi(e){let t=e.text.split(`;`);for(;t.length>0;){let e=t.shift(),n=parseInt(e,10);if(isNaN(n)||n===0)this.fg=null,this.bg=null,this.bold=!1,this.faint=!1,this.italic=!1,this.underline=!1;else if(n===1)this.bold=!0;else if(n===2)this.faint=!0;else if(n===3)this.italic=!0;else if(n===4)this.underline=!0;else if(n===21)this.bold=!1;else if(n===22)this.faint=!1,this.bold=!1;else if(n===23)this.italic=!1;else if(n===24)this.underline=!1;else if(n===39)this.fg=null;else if(n===49)this.bg=null;else if(n>=30&&n<38)this.fg=this.ansi_colors[0][n-30];else if(n>=40&&n<48)this.bg=this.ansi_colors[0][n-40];else if(n>=90&&n<98)this.fg=this.ansi_colors[1][n-90];else if(n>=100&&n<108)this.bg=this.ansi_colors[1][n-100];else if((n===38||n===48)&&t.length>0){let e=n===38,r=t.shift();if(r===`5`&&t.length>0){let n=parseInt(t.shift(),10);n>=0&&n<=255&&(e?this.fg=this.palette_256[n]:this.bg=this.palette_256[n])}if(r===`2`&&t.length>2){let n=parseInt(t.shift(),10),r=parseInt(t.shift(),10),i=parseInt(t.shift(),10);if(n>=0&&n<=255&&r>=0&&r<=255&&i>=0&&i<=255){let t={rgb:[n,r,i],class_name:`truecolor`};e?this.fg=t:this.bg=t}}}}}transform_to_html(e){let t=e.text;if(t.length===0||(t=this.escape_txt_for_html(t),!e.bold&&!e.italic&&!e.faint&&!e.underline&&e.fg===null&&e.bg===null))return t;let n=[],r=[],i=e.fg,a=e.bg;e.bold&&n.push(this._boldStyle),e.faint&&n.push(this._faintStyle),e.italic&&n.push(this._italicStyle),e.underline&&n.push(this._underlineStyle),this._use_classes?(i&&(i.class_name===`truecolor`?n.push(`color:rgb(${i.rgb.join(`,`)})`):r.push(`${i.class_name}-fg`)),a&&(a.class_name===`truecolor`?n.push(`background-color:rgb(${a.rgb.join(`,`)})`):r.push(`${a.class_name}-bg`))):(i&&n.push(`color:rgb(${i.rgb.join(`,`)})`),a&&n.push(`background-color:rgb(${a.rgb})`));let o=``,s=``;return r.length&&(o=` class="${r.join(` `)}"`),n.length&&(s=` style="${n.join(`;`)}"`),`<span${s}${o}>${t}</span>`}process_hyperlink(e){let t=e.url.split(`:`);return t.length<1||!this._url_allowlist[t[0]]?``:`<a href="${this.escape_txt_for_html(e.url)}">${this.escape_txt_for_html(e.text)}</a>`}};function Hj(e,...t){let n=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,``);return new RegExp(n)}function Uj(e,...t){let n=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,``);return new RegExp(n,`g`)}var Wj,Gj,Kj,qj=new Vj;function Jj(e){try{let t=document.createElement(`div`);return t.innerHTML=e,(t.textContent||t.innerText||``).split(`
219
219
  `).map(e=>e.trimEnd()).join(`
220
- `)}catch(t){return B.error(`Error parsing HTML content:`,t),e}}function Yj(e){if(!e)return``;try{return Jj(qj.ansi_to_html(e))}catch(t){return B.error(`Error converting ANSI to plain text:`,t),e}}var Xj=o(null);function Zj(e){return e.type===`cell`?e.cellId:`lsp:${e.name}`}var Qj=!1;function $j(e){let t=[],n=[e.console].filter(Boolean).flat();for(let r of n){let n=r.mimetype===`text/plain`,i=r.mimetype===`text/html`||r.mimetype===`application/vnd.marimo+traceback`;if(n||i){let n=r.channel===`stderr`||r.channel===`marimo-error`;switch(r.channel){case`stdout`:case`stderr`:case`marimo-error`:{let a=Rr.asString(r.data),o=i?Jj(a):a;t.push({timestamp:r.timestamp||Date.now(),level:n?`stderr`:`stdout`,message:o,source:{type:`cell`,cellId:e.cell_id}});break}}}}if(t.forEach(eM.log),n.length===0&&ff(e.output?.mimetype)&&Array.isArray(e.output.data)){e.output.data.forEach(t=>{eM.log({level:`stderr`,source:{type:`cell`,cellId:e.cell_id},timestamp:e.timestamp??0,message:JSON.stringify(t)})});let t=e.output.data.filter(e=>`type`in e&&e.type===`exception`||e.type===`internal`),n=u.get(be)===`read`;if(t.length>0&&!Qj&&n){Qj=!0;let e=t.find(e=>e.traceback);rn(e?{title:`An internal error occurred`,description:e.msg||`Click 'View' to see traceback`,variant:`danger`,action:K.createElement(ht,{altText:`View traceback`,onClick:()=>{u.set(Xj,{traceback:e.traceback,errorMessage:e.msg||`An internal error occurred`})}},`View`)}:{title:`An internal error occurred`,description:`See console for details.`,variant:`danger`})}}return t}var eM={log:e=>{let t=e.level===`stdout`?`gray`:e.level===`stderr`?`red`:`orange`,n=e.level.toUpperCase();console.log(`%c[${n}]`,`color:${t}; padding:2px 0; border-radius:2px; font-weight:bold`,`[${tM(e.timestamp)}]`,`(${Zj(e.source)}) ${e.message}`)}};function tM(e){try{return Rj(e).toLocaleTimeString(void 0,{hour12:!0,hour:`numeric`,minute:`numeric`,second:`numeric`})}catch{return``}}function nM(e,t){let n=dN(t);n?n.focus():B.warn(`[CellFocusManager] focusCellEditor: element not found: ${t}`)}function rM(e){let t=document.getElementById(Pi.create(e));t?oM(t):B.warn(`[CellFocusManager] focusCell: element not found: ${e}`)}function iM(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}function aM(){return document.activeElement instanceof HTMLElement&&document.activeElement.classList.contains(`marimo-cell`)}function oM(e){try{e.focus()}catch{B.warn(`[CellFocusManager] element may not be focusable`,e)}}function sM(e,t){let{retries:n,delay:r,initialDelay:i=0}=t,a=0,o=()=>{if(a<n){try{if(e())return}catch(e){B.error(`Error executing function on attempt ${a+1}, retrying`,{error:e})}a++,setTimeout(o,r)}};i>0?setTimeout(o,i):o()}function cM({cellId:e,cell:t,isCodeHidden:n,codeFocus:r,variableName:i}){if(!t)return;let a=document.getElementById(Pi.create(e));if(!a){B.warn(`scrollCellIntoView: element not found`);return}if(aM()){oM(a);return}if(n)oM(a);else{Ws.promote(e);let n=t.current?.editorView;if(!n){B.warn(`scrollCellIntoView: editor not found`,e);return}if(n.hasFocus||!document.hasFocus())return;if(sM(()=>(n.focus(),n.hasFocus),{retries:5,delay:20}),r===`top`)n.dispatch({selection:{anchor:0,head:0}});else if(r===`bottom`){let e=n.state.doc.line(n.state.doc.lines);n.dispatch({selection:{anchor:e.from,head:e.from}})}else i&&V_(n,i)}a.scrollIntoView({behavior:`smooth`,block:`nearest`})}function lM(e){let t=document.getElementById(Pi.create(e));if(!t){B.warn(`scrollCellIntoView: element not found`);return}t.classList.add(`focus-outline`),setTimeout(()=>{t.classList.remove(`focus-outline`)},2e3),t.scrollIntoView({behavior:`smooth`,block:`center`})}function uM(){let e=document.getElementById(`App`);e?.scrollTo({top:e.scrollHeight,behavior:`smooth`})}function dM(){document.getElementById(`App`)?.scrollTo({top:0,behavior:`smooth`})}function fM(e){let t=dN(e);if(t?.hasFocus){Eh(t,{behavior:`instant`});return}let n=document.getElementById(Pi.create(e));n?n.scrollIntoView({behavior:`instant`,block:`nearest`}):B.warn(`[CellFocusManager] scrollCellIntoView: element not found: ${e}`)}function pM({id:e,name:t=`_`,code:n=``,lastCodeRun:r=null,lastExecutionTime:i=null,edited:a=!1,config:o,serializedEditorState:s=null}){return{id:e,config:o||{hide_code:!1,disabled:!1,column:null,expand_output:!1},name:t,code:n,edited:a,lastCodeRun:r,lastExecutionTime:i,serializedEditorState:s}}function mM(e){return{hide_code:!1,disabled:!1,column:null,expand_output:!1,...e}}function hM(e){return{outline:null,output:null,consoleOutputs:[],status:`idle`,staleInputs:!1,interrupted:!1,errored:!1,stopped:!1,runElapsedTimeMs:null,runStartTimestamp:null,lastRunStartTimestamp:null,debuggerActive:!1,...e}}function gM(e){let t={column:0,hide_code:!1,disabled:!1,expand_output:!1};return{...e,cellData:{[ji]:pM({id:ji,config:t}),...e.cellData},cellRuntime:{[ji]:hM(),...e.cellRuntime},cellHandles:{[ji]:(0,K.createRef)(),...e.cellHandles}}}function _M(){return gM({cellIds:ys.from([]),cellData:{},cellRuntime:{},cellHandles:{},history:[],scrollKey:null,cellLogs:[],untouchedNewCells:new Set})}var{reducer:vM,addMiddleware:yM,createActions:bM,useActions:xM,valueAtom:SM}=Or(_M,{createNewCell:(e,t)=>{let{cellId:n,before:r,code:i,name:a,config:o,lastCodeRun:s=null,lastExecutionTime:c=null,autoFocus:l=!0,skipIfCodeExists:u=!1,hideCode:d=void 0}=t,f,p;if(u){for(let t of e.cellIds.inOrderIds)if(e.cellData[t]?.code===i)return e}if(n===`__end__`){let t=e.cellIds.atOrThrow(0);f=t.id,p=t.length}else if(typeof n==`string`){let t=e.cellIds.findWithId(n);f=t.id,p=t.topLevelIds.indexOf(n)}else if(n.type===`__end__`){let t=e.cellIds.get(n.columnId)||e.cellIds.atOrThrow(0);f=t.id,p=t.length}else throw Error(`Invalid cellId`);let m=t.newCellId||Ni.create(),h=r?p:p+1;return{...e,cellIds:e.cellIds.insertId(m,f,h),cellData:{...e.cellData,[m]:pM({id:m,code:i,name:a,lastCodeRun:s,config:mM({...o,...d!=null&&{hide_code:d}}),lastExecutionTime:c,edited:!!i&&i!==s})},cellRuntime:{...e.cellRuntime,[m]:hM()},cellHandles:{...e.cellHandles,[m]:(0,K.createRef)()},scrollKey:l?m:null,untouchedNewCells:d&&l?new Set([...e.untouchedNewCells,m]):e.untouchedNewCells}},moveCell:(e,t)=>{let{cellId:n,before:r,direction:i}=t;if(r!==void 0&&i!==void 0&&B.warn(`Both before and direction specified for moveCell. Ignoring one.`),i){let t=e.cellIds.findWithId(n),r=e.cellIds.indexOf(t),a=i===`left`?r-1:r+1,o=e.cellIds.at(a);return o?{...e,cellIds:e.cellIds.moveAcrossColumns(t.id,n,o.id,void 0),scrollKey:n}:e}let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n);return r&&o===0?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,0),scrollKey:n}:!r&&o===a.length-1?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,a.length-1),scrollKey:n}:r?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o-1),scrollKey:n}:{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o+1),scrollKey:n}},moveCellToIndex:(e,t)=>{let{cellId:n,columnId:r,index:i}=t,a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=e.cellIds.get(r);if(!s)return e;let c=Math.max(0,Math.min(i,s.length)),l=a.id===r&&o<c?c-1:c;if(a.id===r&&o===l)return e;let u=e.cellIds.deleteById(n),d=u.get(r);return d?{...e,cellIds:u.insertId(n,r,Math.max(0,Math.min(l,d.length))),scrollKey:null}:e},dropCellOverCell:(e,t)=>{let{cellId:n,overCellId:r}=t,i=e.cellIds.findWithId(n),a=e.cellIds.findWithId(r),o=i.indexOfOrThrow(n),s=a.indexOfOrThrow(r);return i.id===a.id?o===s?e:{...e,cellIds:e.cellIds.moveWithinColumn(i.id,o,s),scrollKey:null}:{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,a.id,r),scrollKey:null}},moveCellsRelativeTo:(e,t)=>{let{cellIds:n,targetCellId:r,position:i,previousPlacements:a}=t;if(n.length===0)return e;let o=e.cellIds.moveCellsRelativeTo(n,r,i),s=a&&a.length===n.length?[...e.history,{type:`move`,cellIds:n,placements:a}]:e.history;return{...e,cellIds:o,history:s,scrollKey:null}},dropCellOverColumn:(e,t)=>{let{cellId:n,columnId:r}=t,i=e.cellIds.findWithId(n);return{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,r,void 0)}},dropOverNewColumn:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.moveToNewColumn(n)}},moveColumn:(e,t)=>t.column===t.overColumn?e:{...e,cellIds:e.cellIds.moveColumn(t.column,t.overColumn)},focusCell:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,where:i}=t,a=n.indexOfOrThrow(r),o;o=i===`before`?Cr(a-1,0,n.length-1):i===`after`?Cr(a+1,0,n.length-1):a;let s=n.atOrThrow(o);return cM({cellId:s,cell:e.cellHandles[s],isCodeHidden:CM(e,s),codeFocus:i===`after`?`top`:`bottom`,variableName:void 0}),e},focusTopCell:e=>{let t=e.cellIds.getColumns().at(0);if(t===void 0||t.length===0)return e;let n=t.first();return cM({cellId:n,cell:e.cellHandles[n],isCodeHidden:CM(e,n),codeFocus:void 0,variableName:void 0}),dM(),e},focusBottomCell:e=>{let t=e.cellIds.getColumns().at(-1);if(t===void 0||t.length===0)return e;let n=t.last();return cM({cellId:n,cell:e.cellHandles[n],isCodeHidden:CM(e,n),codeFocus:void 0,variableName:void 0}),uM(),e},sendToTop:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,scroll:i=!0}=t,a=n.indexOfOrThrow(r);return a===0?e:{...e,cellIds:e.cellIds.moveWithinColumn(n.id,a,0),scrollKey:i?r:null}},sendToBottom:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,scroll:i=!0}=t,a=n.indexOfOrThrow(r),o=n.length-1;return a===o?e:{...e,cellIds:e.cellIds.moveWithinColumn(n.id,a,o),scrollKey:i?r:null}},addColumn:(e,t)=>{let n=Ni.create();return{...e,cellIds:e.cellIds.addColumn(t.columnId,[n]),cellData:{...e.cellData,[n]:pM({id:n})},cellRuntime:{...e.cellRuntime,[n]:hM()},cellHandles:{...e.cellHandles,[n]:(0,K.createRef)()},scrollKey:n}},addColumnBreakpoint:(e,t)=>{let{cellId:n}=t;return e.cellIds.getColumns()[0].inOrderIds[0]===n?e:{...e,cellIds:e.cellIds.insertBreakpoint(n)}},deleteColumn:(e,t)=>{let{columnId:n}=t;return{...e,cellIds:e.cellIds.delete(n)}},mergeAllColumns:e=>({...e,cellIds:e.cellIds.mergeAllColumns()}),compactColumns:e=>({...e,cellIds:e.cellIds.compact()}),deleteCell:(e,t)=>{let n=t.cellId;if(e.cellIds.hasOnlyOneId())return e;let r;try{r=e.cellIds.findWithId(n)}catch(t){return B.warn(`Skipping delete for missing cellId`,{cellId:n,error:t}),e}let i=r.indexOfOrThrow(n),a=i===0?1:i-1,o=null;r.length>1&&(o=r.atOrThrow(a));let s=(e.cellHandles[n].current?.editorView)?.state.toJSON({history:tr});s&&(s.doc=e.cellData[n].code),oN(n);let c=e.cellData[n];return{...e,cellIds:e.cellIds.deleteById(n),history:[...e.history,{type:`delete`,name:c.name,serializedEditorState:s,column:r.id,index:i,isSetupCell:n===Mi,config:c.config}],scrollKey:o}},undoDeleteCell:e=>{if(e.history.length===0)return e;let t=e.history[e.history.length-1];if(t.type===`move`){let{cellIds:n,placements:r}=t;if(n.length===0||r.length!==n.length||n.some(t=>!e.cellData[t]))return{...e,history:e.history.slice(0,-1)};let i=n.map((e,t)=>({id:e,columnId:r[t].columnId,index:r[t].index}));return{...e,cellIds:e.cellIds.placeCells(i),history:e.history.slice(0,-1),scrollKey:n[0]??null}}let{name:n,serializedEditorState:r={doc:``},column:i,index:a,isSetupCell:o,config:s}=t,c=o?Mi:Ni.create(),l=pM({id:c,name:n,code:r.doc,edited:r.doc.trim().length>0,serializedEditorState:r,config:s});return{...e,cellIds:e.cellIds.insertId(c,i,a),cellData:{...e.cellData,[c]:l},cellRuntime:{...e.cellRuntime,[c]:hM()},cellHandles:{...e.cellHandles,[c]:(0,K.createRef)()},history:e.history.slice(0,-1),scrollKey:c}},clearSerializedEditorState:(e,t)=>{let{cellId:n}=t;return TM({state:e,cellId:n,cellReducer:e=>({...e,serializedEditorState:null})})},updateCellCode:(e,t)=>{let{cellId:n,code:r,formattingChange:i}=t;return e.cellData[n]?TM({state:e,cellId:n,cellReducer:e=>i?{...e,code:r,lastCodeRun:e.edited?e.lastCodeRun:r}:{...e,code:r,edited:r.trim()!==e.lastCodeRun}}):e},updateCellName:(e,t)=>{let{cellId:n,name:r}=t;return TM({state:e,cellId:n,cellReducer:e=>({...e,name:r})})},updateCellConfig:(e,t)=>{let{cellId:n,config:r}=t;return TM({state:e,cellId:n,cellReducer:e=>({...e,config:mM({...e.config,...r})})})},prepareForRun:(e,t)=>TM({state:wM({state:e,cellId:t.cellId,cellReducer:e=>rj(e)}),cellId:t.cellId,cellReducer:e=>({...e,edited:!1,lastCodeRun:e.code.trim()})}),handleCellMessage:(e,t)=>{let n=t.cell_id,r=wM({state:e,cellId:n,cellReducer:e=>nj(e,t)});return t.status===`queued`&&(r=TM({state:r,cellId:n,cellReducer:e=>({...e,lastCodeRun:e.code.trim(),edited:!1})})),{...r,cellLogs:[...r.cellLogs,...$j(t)]}},addLogs:(e,t)=>({...e,cellLogs:[...e.cellLogs,...t.logs]}),setCellIds:(e,t)=>{if(l(e.cellIds.inOrderIds,t.cellIds))return e;let n={...e.cellData},r={...e.cellRuntime},i={...e.cellHandles};for(let a of t.cellIds)a in e.cellData||(n[a]=pM({id:a})),a in e.cellRuntime||(r[a]=hM()),a in e.cellHandles||(i[a]=(0,K.createRef)());return{...e,cellIds:ys.fromWithPreviousShape(t.cellIds,e.cellIds),cellData:n,cellRuntime:r,cellHandles:i}},rebuildCellColumns:(e,t)=>{let n=ys.fromIdsAndColumns(t.cellIds.map(t=>[t,e.cellData[t]?.config.column??null]));return{...e,cellIds:n}},setCellCodes:(e,t)=>{ve(t.codes.length===t.ids.length,`Expected codes and ids to have the same length`);let n={...e},r=({cell:e,code:r,cellId:i,name:a,config:o})=>{if(!e)return pM({id:i,code:r,name:a,config:o,lastCodeRun:t.codeIsStale?null:r,edited:t.codeIsStale&&r.trim().length>0});let s=t.codeIsStale?e.lastCodeRun:r,c=s?s.trim()!==r.trim():!!r;if(e.code.trim()===r.trim())return{...e,code:r,edited:c,lastCodeRun:s,...a!==void 0&&{name:a},...o!==void 0&&{config:o}};if(!WA()||!GA(i)){let e=n.cellHandles[i].current;e?.editorViewOrNull&&jA(e.editorViewOrNull,r)}return{...e,code:r,edited:c,lastCodeRun:s,...a!==void 0&&{name:a},...o!==void 0&&{config:o}}};for(let e=0;e<t.ids.length;e++){let i=t.ids[e],a=t.codes[e];if(i===void 0||a===void 0)continue;let o=t.names?.[e],s=t.configs?.[e];n={...n,cellData:{...n.cellData,[i]:r({cell:n.cellData[i],code:a,cellId:i,name:o,config:s})}}}return n},setStdinResponse:(e,t)=>{let{cellId:n,response:r,outputIndex:i}=t;return wM({state:e,cellId:n,cellReducer:e=>{let t=[...e.consoleOutputs],n=t[i];return n==null||n.channel!==`stdin`?(B.warn(`Expected stdin output`),e):(t[i]={channel:`stdin`,mimetype:n.mimetype,data:n.data,timestamp:n.timestamp,response:n.mimetype===`text/password`?``:r},{...e,interrupted:!1,consoleOutputs:t})}})},setCells:(e,t)=>{let n=Object.fromEntries(t.map(e=>[e.id,e])),r=I(),i=t=>{if(!r)return hM();let n=e.cellRuntime[t];return n&&(n.output!=null||n.consoleOutputs.length>0)?n:hM()},a=Object.fromEntries(t.map(e=>[e.id,i(e.id)]));return gM({...e,cellIds:ys.fromIdsAndColumns(t.map(e=>[e.id,e.config.column])),cellData:n,cellRuntime:a,cellHandles:Object.fromEntries(t.map(e=>[e.id,(0,K.createRef)()]))})},moveToNextCell:(e,t)=>{let{cellId:n,before:r,noCreate:i=!1}=t;if(n===`__scratch__`)return e;let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=r?o-1:o+1,c=s===a.length,l=s===-1;if(c&&!i){let t=Ni.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,s),cellData:{...e.cellData,[t]:pM({id:t})},cellRuntime:{...e.cellRuntime,[t]:hM()},cellHandles:{...e.cellHandles,[t]:(0,K.createRef)()},scrollKey:t}}if(l&&!i){let t=Ni.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,0),cellData:{...e.cellData,[t]:pM({id:t})},cellRuntime:{...e.cellRuntime,[t]:hM()},cellHandles:{...e.cellHandles,[t]:(0,K.createRef)()},scrollKey:t}}if((c||l)&&i)return e;if(s>=0&&s<a.length){let t=a.atOrThrow(s);cM({cellId:t,cell:e.cellHandles[t],isCodeHidden:CM(e,t),codeFocus:r?`bottom`:`top`,variableName:void 0})}return e},markTouched:(e,t)=>{let{cellId:n}=t;if(e.untouchedNewCells.has(n)){let t=new Set(e.untouchedNewCells);return t.delete(n),{...e,untouchedNewCells:t}}return e},markUntouched:(e,t)=>{let{cellId:n}=t;if(!e.untouchedNewCells.has(n)){let t=new Set(e.untouchedNewCells);return t.add(n),{...e,untouchedNewCells:t}}return e},scrollToTarget:e=>{let t=e.scrollKey;if(t===null)return e;let n=e.cellIds.findWithId(t),r=n.indexOfOrThrow(t),i=r===n.length-1?n.last():n.atOrThrow(r);return cM({cellId:i,cell:e.cellHandles[i],isCodeHidden:CM(e,i),codeFocus:void 0,variableName:void 0}),{...e,scrollKey:null}},foldAll:e=>(zs(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),unfoldAll:e=>(Bs(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),clearLogs:e=>({...e,cellLogs:[]}),collapseCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.topLevelIds.map(t=>e.cellRuntime[t].outline),a=HA(r.indexOfOrThrow(n),i);if(!a)return e;let o=r.atOrThrow(a[1]);return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.collapse(n,o)),scrollKey:n}},expandCell:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.expand(n)),scrollKey:n}},collapseAllCells:e=>({...e,cellIds:e.cellIds.transformAll(t=>{let n=t.topLevelIds.map(t=>e.cellRuntime[t].outline),r=[...t.nodes],i=new Map,a=[],o=r.length-1;for(;o>=0;){let e=HA(o,n);if(e){let n=o,r=e[1],s=i.get(r)??r;i.set(r,n);let c=t.atOrThrow(n),l=t.atOrThrow(s);a.push({id:c,until:l})}else a.push(null);o--}let s=a.toReversed();return t.collapseAll(s)})}),expandAllCells:e=>({...e,cellIds:e.cellIds.transformAll(e=>e.expandAll())}),showCellIfHidden:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r,a=r.findAndExpandDeep(n);return a.equals(i)?e:{...e,cellIds:e.cellIds.transformWithCellId(n,()=>a)}},splitCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.indexOfOrThrow(n),a=e.cellData[n],o=e.cellHandles[n].current;if(o?.editorView==null)return e;let{beforeCursorCode:s,afterCursorCode:c}=MA(o.editorView);jA(o.editorView,s);let l=Ni.create();return{...e,cellIds:e.cellIds.insertId(l,r.id,i+1),cellData:{...e.cellData,[n]:{...a,code:s,edited:!!s&&s.trim()!==a.lastCodeRun?.trim()},[l]:pM({id:l,code:c,edited:!!c})},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]},[l]:hM()},cellHandles:{...e.cellHandles,[l]:(0,K.createRef)()},scrollKey:l}},undoSplitCell:(e,t)=>{let{cellId:n,snapshot:r}=t,i=e.cellData[n],a=e.cellHandles[n].current;return a?.editorView==null?e:(jA(a.editorView,r),{...e,cellIds:e.cellIds.transformWithCellId(n,e=>{let t=e.indexOfOrThrow(n)+1;return e.deleteAtIndex(t)}),cellData:{...e.cellData,[n]:{...i,code:r,edited:!!r&&r?.trim()!==i.lastCodeRun?.trim()}},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]}},cellHandles:{...e.cellHandles}})},clearCellOutput:(e,t)=>{let{cellId:n}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,output:null,consoleOutputs:[]})})},clearCellConsoleOutput:(e,t)=>{let{cellId:n}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,consoleOutputs:e.consoleOutputs.filter(e=>e.channel===`stdin`&&e.response==null)})})},clearAllCellOutputs:e=>{let t={...e.cellRuntime};for(let n of e.cellIds.inOrderIds)t[n]={...t[n],output:null,consoleOutputs:[]};return{...e,cellRuntime:t}},addSetupCellIfDoesntExist:(e,t)=>{let{code:n}=t;return e.cellIds.setupCellExists()?{...e,scrollKey:Mi}:{...e,cellIds:e.cellIds.insertId(Mi,e.cellIds.atOrThrow(0).id,0),cellData:{...e.cellData,[Mi]:pM({id:Mi,name:Mi,code:n,edited:!!n})},cellRuntime:{...e.cellRuntime,[Mi]:hM()},cellHandles:{...e.cellHandles,[Mi]:(0,K.createRef)()},scrollKey:Mi}}});yM(Ij);function CM(e,t){return!!e.cellData[t].config.hide_code&&!e.untouchedNewCells.has(t)}function wM({state:e,cellId:t,cellReducer:n}){return t in e.cellRuntime?{...e,cellRuntime:{...e.cellRuntime,[t]:n(e.cellRuntime[t])}}:(B.warn(`Cell ${t} not found in state`),e)}function TM({state:e,cellId:t,cellReducer:n}){return t in e.cellData?{...e,cellData:{...e.cellData,[t]:n(e.cellData[t])}}:(B.warn(`Cell ${t} not found in state`),e)}function EM(e){let t=e.cellData,n={column:null};return e.cellIds.getColumns().length>1?e.cellIds.getColumns().flatMap((e,r)=>e.inOrderIds.map((e,i)=>{let a={...n};return i===0&&(a.column=r),{...t[e].config,...a}})):e.cellIds.getColumns().flatMap(e=>e.inOrderIds.map(e=>({...t[e].config,...n})))}var DM=bM(e=>{u.set(SM,t=>vM(t,e))}).addLogs,OM=o(e=>e(SM).cellIds),kM=o(e=>e(OM).hasOnlyOneId()),AM=o(e=>vf(e(SM)).length>0);o(e=>yf(e(SM)).length>0);var jM=o(e=>bf(e(SM))),MM=o(e=>xf(e(SM))),NM=o(e=>hf(e(SM))),PM=o(e=>{let{cellIds:t,cellRuntime:n,cellData:r}=e(SM);return t.inOrderIds.map(e=>{let t=n[e],{name:i}=r[e];if(ff(t.output?.mimetype)){ve(Array.isArray(t.output.data),`Expected array data`);let n=t.output.data.filter(e=>!e.type.includes(`ancestor`));if(n.length>0)return{output:{...t.output,data:n},cellId:e,cellName:i}}return null}).filter(Boolean)}),FM=o(e=>{let{cellIds:t,cellRuntime:n}=e(SM);return zA(t.inOrderIds.map(e=>n[e].outline))}),IM=o(e=>e(PM).length),LM=c(o(e=>{let{cellIds:t,cellData:n}=e(SM);return _e.fromEntries(t.inOrderIds.map(e=>[e,n[e]?.name]))})),RM=o(e=>e(SM).scrollKey),zM=()=>s(SM),BM=()=>s(OM),VM=()=>s(LM),HM=()=>s(PM),UM=()=>s(SM).cellLogs,WM=()=>s(RM),GM=()=>u.get(SM),KM=()=>u.get(SM).cellIds,qM=()=>{let{cellIds:e,cellData:t}=u.get(SM);return e.inOrderIds.map(e=>t[e]?.name).filter(Boolean)},JM=F(re(SM,e=>e.cellIds.inOrderIds.map(t=>e.cellData[t]))),YM=()=>a(JM),XM=o(e=>e(SM).cellRuntime),ZM=o(e=>pf(e(SM))),QM=o(e=>{let{cellRuntime:t}=e(SM);return Object.entries(t).every(([e,t])=>t.status!==`running`||e===`__scratch__`)}),$M=o(e=>mf(e(SM))),eN=o(e=>e(SM).cellIds.colLength),tN=o(e=>e(SM).cellIds.idLength>0),nN=o(e=>e(SM).cellIds.getColumnIds()),rN=ie(e=>o(t=>t(SM).cellData[e])),iN=ie(e=>o(t=>t(SM).cellRuntime[e])),aN=ie(e=>o(t=>t(SM).cellHandles[e]));function oN(e){rN.remove(e),iN.remove(e),aN.remove(e)}var sN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=rN(e),t[0]=e,t[1]=n),s(n)},cN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=iN(e),t[0]=e,t[1]=n),s(n)},lN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=aN(e),t[0]=e,t[1]=n),s(n)},uN=()=>{let{cellIds:e,cellHandles:t}=u.get(SM);return e.inOrderIds.map(e=>t[e]?.current?.editorViewOrNull).filter(Boolean)},dN=e=>{let{cellHandles:t}=u.get(SM);return t[e].current?.editorView},fN=e=>(Ws.promote(e),dN(e));function pN(e){let{cellIds:t,cellData:n,cellRuntime:r}=e;return t.getColumns().flatMap(e=>e.topLevelIds.map(e=>({...n[e],...r[e]})))}function mN(e){return o(t=>t(SM).untouchedNewCells.has(e))}function hN(e){let t=iN(e);return o(n=>{let r=n(t);if(!r||r.status===`queued`||r.status===`running`)return;let i=[],a=r.consoleOutputs;if(a&&a.length>0){let e=a.find(e=>e.mimetype===`application/vnd.marimo+traceback`);if(e){let t=e.data;i.push(...Ls(t))}}let o=r.output;if(o?.mimetype===`application/vnd.marimo+error`){let t=o.data;if(Array.isArray(t))for(let n of t)n.type===`syntax`&&n.lineno!=null&&i.push({kind:`cell`,cellId:e,lineNumber:n.lineno}),n.type===`import-star`&&n.lineno!=null&&i.push({kind:`cell`,cellId:e,lineNumber:n.lineno})}return i.length>0?i:void 0})}function gN(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n),xM(n)}export{Lj as $,Lo as $a,kf as $i,Ky as $n,Mh as $r,_O as $t,HM as A,ys as Aa,Cp as Ai,kT as An,yi as Ao,b_ as Ar,wk as At,lM as B,ns as Ba,ip as Bi,Dw as Bn,ig as Br,QO as Bt,$M as C,pu as Ca,Qp as Ci,ED as Cn,Mi as Co,D_ as Cr,Yk as Ct,gN as D,Is as Da,Tp as Di,dE as Dn,Di as Do,k_ as Dr,Ik as Dt,MM as E,Ls as Ea,kp as Ei,WE as En,Ei as Eo,E_ as Er,Lk as Et,cN as F,cs as Fa,xp as Fi,zw as Fn,gg as Fr,sk as Ft,aM as G,qo as Ga,Qf as Gi,LC as Gn,Hh as Gr,IO as Gt,sM as H,Xo as Ha,Kf as Hi,iw as Hn,eg as Hr,VO as Ht,zM as I,os as Ia,gp as Ii,jw as In,ug as Ir,ak as It,Zj as J,Ho as Ja,Jf as Ji,zC as Jn,Ih as Jr,kO as Jt,iM as K,Ko as Ka,Uf as Ki,IC as Kn,Qh as Kr,MO as Kt,WM as L,rs as La,sp as Li,Aw as Ln,ag as Lr,ik as Lt,BM as M,ps as Ma,vp as Mi,Iw as Mn,bg as Mr,Dk as Mt,UM as N,ls as Na,_p as Ni,Rw as Nn,pg as Nr,rk as Nt,sN as O,Ns as Oa,Dp as Oi,PE as On,xi as Oo,d_ as Or,Fk as Ot,VM as P,ss as Pa,hp as Pi,Lw as Pn,vg as Pr,ck as Pt,Vj as Q,Ro as Qa,Vf as Qi,qy as Qn,Fh as Qr,hO as Qt,pM as R,ts as Ra,ap as Ri,Mw as Rn,rg as Rr,ok as Rt,FM as S,kd as Sa,Zp as Si,WD as Sn,ji as So,S_ as Sr,qk as St,QM as T,Fs as Ta,Op as Ti,KE as Tn,Fi as To,w_ as Tr,Rk as Tt,rM as U,Yo as Ua,Wf as Ui,VC as Un,Yh as Ur,PO as Ut,fM as V,Zo as Va,cp as Vi,Tw as Vn,ng as Vr,BO as Vt,nM as W,Jo as Wa,Gf as Wi,FC as Wn,$h as Wr,FO as Wt,Yj as X,Bo as Xa,Hf as Xi,Lb as Xn,Rh as Xr,SO as Xt,Xj as Y,Vo as Ya,Zf as Yi,Qb as Yn,Lh as Yr,mO as Yt,Jj as Z,zo as Za,Bf as Zi,Yy as Zn,Ph as Zr,CO as Zt,AM as _,tf as _a,dm as _i,QD as _n,Vi as _o,q_ as _r,xA as _t,XM as a,Sf as aa,_h as ai,uO as an,ko as ao,ly as ar,WA as at,SM as b,Vd as ba,Bp as bi,$D as bn,Li as bo,T_ as br,Kk as bt,fN as c,gf as ca,fh as ci,eO as cn,Eo as co,Uv as cr,RA as ct,EM as d,Cf as da,uh as di,tO as dn,So as do,xv as dr,AA as dt,Af as ea,Nh as ei,bO as en,Io as eo,My as er,Oj as et,dN as f,ff as fa,lh as fi,GD as fn,Pa as fo,cv as fr,jA as ft,tN as g,cf as ga,Om as gi,qD as gn,Bi as go,Z_ as gr,kA as gt,GM as h,lf as ha,Zm as hi,XD as hn,zi as ho,uv as hr,SA as ht,OM as i,yf as ia,Ch as ii,lO as in,jo as io,hy as ir,GA as it,lN as j,hs as ja,bp as ji,Xw as jn,mi as jo,wg as jr,Ck as jt,YM as k,Ms as ka,Ep as ki,vT as kn,Si as ko,x_ as kr,Ok as kt,pN as l,Df as la,ch as li,rO as ln,wo as lo,Rv as lr,BA as lt,KM as m,df as ma,eh as mi,YD as mn,Hi as mo,tv as mr,EA as mt,rN as n,Ef as na,Th as ni,wO as nn,Po as no,ky as nr,ij as nt,nN as o,wf as oa,hh as oi,sO as on,Oo as oo,uy as or,UA as ot,qM as p,uf as pa,dh as pi,KD as pn,Ra as po,lv as pr,TA as pt,tM as q,Wo as qa,qf as qi,RC as qn,Zh as qr,OO as qt,IM as r,vf as ra,xh as ri,TO as rn,Mo as ro,Ay as rr,aj as rt,mN as s,_f as sa,ph as si,cO as sn,Do as so,Wv as sr,VA as st,jM as t,Tf as ta,Ah as ti,xO as tn,J as to,jy as tr,Nj as tt,uN as u,Of as ua,sh as ui,aO as un,Co as uo,bv as ur,NA as ut,kM as v,ef as va,um as vi,JD as vn,Ri as vo,Y_ as vr,OA as vt,eN as w,Ws as wa,Wp as wi,GE as wn,Ii as wo,O_ as wr,Xk as wt,ZM as x,Hd as xa,zp as xi,UD as xn,Pi as xo,C_ as xr,Gk as xt,NM as y,Yd as ya,Np as yi,ZD as yn,Ni as yo,V_ as yr,Qk as yt,hM as z,es as za,op as zi,kw as zn,Q as zr,$O as zt};
220
+ `)}catch(t){return B.error(`Error parsing HTML content:`,t),e}}function Yj(e){if(!e)return``;try{return Jj(qj.ansi_to_html(e))}catch(t){return B.error(`Error converting ANSI to plain text:`,t),e}}var Xj=o(null);function Zj(e){return e.type===`cell`?e.cellId:`lsp:${e.name}`}var Qj=!1;function $j(e){let t=[],n=[e.console].filter(Boolean).flat();for(let r of n){let n=r.mimetype===`text/plain`,i=r.mimetype===`text/html`||r.mimetype===`application/vnd.marimo+traceback`;if(n||i){let n=r.channel===`stderr`||r.channel===`marimo-error`;switch(r.channel){case`stdout`:case`stderr`:case`marimo-error`:{let a=Rr.asString(r.data),o=i?Jj(a):a;t.push({timestamp:r.timestamp||Date.now(),level:n?`stderr`:`stdout`,message:o,source:{type:`cell`,cellId:e.cell_id}});break}}}}if(t.forEach(eM.log),n.length===0&&ff(e.output?.mimetype)&&Array.isArray(e.output.data)){e.output.data.forEach(t=>{eM.log({level:`stderr`,source:{type:`cell`,cellId:e.cell_id},timestamp:e.timestamp??0,message:JSON.stringify(t)})});let t=e.output.data.filter(e=>`type`in e&&e.type===`exception`||e.type===`internal`),n=u.get(be)===`read`;if(t.length>0&&!Qj&&n){Qj=!0;let e=t.find(e=>e.traceback);rn(e?{title:`An internal error occurred`,description:e.msg||`Click 'View' to see traceback`,variant:`danger`,action:K.createElement(ht,{altText:`View traceback`,onClick:()=>{u.set(Xj,{traceback:e.traceback,errorMessage:e.msg||`An internal error occurred`})}},`View`)}:{title:`An internal error occurred`,description:`See console for details.`,variant:`danger`})}}return t}var eM={log:e=>{let t=e.level===`stdout`?`gray`:e.level===`stderr`?`red`:`orange`,n=e.level.toUpperCase();console.log(`%c[${n}]`,`color:${t}; padding:2px 0; border-radius:2px; font-weight:bold`,`[${tM(e.timestamp)}]`,`(${Zj(e.source)}) ${e.message}`)}};function tM(e){try{return Rj(e).toLocaleTimeString(void 0,{hour12:!0,hour:`numeric`,minute:`numeric`,second:`numeric`})}catch{return``}}function nM(e,t){let n=dN(t);n?n.focus():B.warn(`[CellFocusManager] focusCellEditor: element not found: ${t}`)}function rM(e){let t=document.getElementById(Pi.create(e));t?oM(t):B.warn(`[CellFocusManager] focusCell: element not found: ${e}`)}function iM(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}function aM(){return document.activeElement instanceof HTMLElement&&document.activeElement.classList.contains(`marimo-cell`)}function oM(e){try{e.focus()}catch{B.warn(`[CellFocusManager] element may not be focusable`,e)}}function sM(e,t){let{retries:n,delay:r,initialDelay:i=0}=t,a=0,o=()=>{if(a<n){try{if(e())return}catch(e){B.error(`Error executing function on attempt ${a+1}, retrying`,{error:e})}a++,setTimeout(o,r)}};i>0?setTimeout(o,i):o()}function cM({cellId:e,cell:t,isCodeHidden:n,codeFocus:r,variableName:i}){if(!t)return;let a=document.getElementById(Pi.create(e));if(!a){B.warn(`scrollCellIntoView: element not found`);return}if(aM()){oM(a);return}if(n)oM(a);else{Ws.promote(e);let n=t.current?.editorView;if(!n){B.warn(`scrollCellIntoView: editor not found`,e);return}if(n.hasFocus||!document.hasFocus())return;if(sM(()=>(n.focus(),n.hasFocus),{retries:5,delay:20}),r===`top`)n.dispatch({selection:{anchor:0,head:0}});else if(r===`bottom`){let e=n.state.doc.line(n.state.doc.lines);n.dispatch({selection:{anchor:e.from,head:e.from}})}else i&&V_(n,i)}a.scrollIntoView({behavior:`smooth`,block:`nearest`})}function lM(e){let t=document.getElementById(Pi.create(e));if(!t){B.warn(`scrollCellIntoView: element not found`);return}t.classList.add(`focus-outline`),setTimeout(()=>{t.classList.remove(`focus-outline`)},2e3),t.scrollIntoView({behavior:`smooth`,block:`center`})}function uM(){let e=document.getElementById(`App`);e?.scrollTo({top:e.scrollHeight,behavior:`smooth`})}function dM(){document.getElementById(`App`)?.scrollTo({top:0,behavior:`smooth`})}function fM(e){let t=dN(e);if(t?.hasFocus){Eh(t,{behavior:`instant`});return}let n=document.getElementById(Pi.create(e));n?n.scrollIntoView({behavior:`instant`,block:`nearest`}):B.warn(`[CellFocusManager] scrollCellIntoView: element not found: ${e}`)}function pM({id:e,name:t=`_`,code:n=``,lastCodeRun:r=null,lastExecutionTime:i=null,edited:a=!1,config:o,serializedEditorState:s=null}){return{id:e,config:o||{hide_code:!1,disabled:!1,column:null,expand_output:!1},name:t,code:n,edited:a,lastCodeRun:r,lastExecutionTime:i,serializedEditorState:s}}function mM(e){return{hide_code:!1,disabled:!1,column:null,expand_output:!1,...e}}function hM(e){return{outline:null,output:null,consoleOutputs:[],status:`idle`,staleInputs:!1,interrupted:!1,errored:!1,stopped:!1,runElapsedTimeMs:null,runStartTimestamp:null,lastRunStartTimestamp:null,debuggerActive:!1,...e}}function gM(e){let t={column:0,hide_code:!1,disabled:!1,expand_output:!1};return{...e,cellData:{[ji]:pM({id:ji,config:t}),...e.cellData},cellRuntime:{[ji]:hM(),...e.cellRuntime},cellHandles:{[ji]:(0,K.createRef)(),...e.cellHandles}}}function _M(){return gM({cellIds:ys.from([]),cellData:{},cellRuntime:{},cellHandles:{},history:[],scrollKey:null,cellLogs:[],untouchedNewCells:new Set})}var{reducer:vM,addMiddleware:yM,createActions:bM,useActions:xM,valueAtom:SM}=Or(_M,{createNewCell:(e,t)=>{let{cellId:n,before:r,code:i,name:a,config:o,lastCodeRun:s=null,lastExecutionTime:c=null,autoFocus:l=!0,skipIfCodeExists:u=!1,hideCode:d=void 0}=t,f,p;if(u){for(let t of e.cellIds.inOrderIds)if(e.cellData[t]?.code===i)return e}if(n===`__end__`){let t=e.cellIds.atOrThrow(0);f=t.id,p=t.length}else if(typeof n==`string`){let t=e.cellIds.findWithId(n);f=t.id,p=t.topLevelIds.indexOf(n)}else if(n.type===`__end__`){let t=e.cellIds.get(n.columnId)||e.cellIds.atOrThrow(0);f=t.id,p=t.length}else throw Error(`Invalid cellId`);let m=t.newCellId||Ni.create(),h=r?p:p+1;return{...e,cellIds:e.cellIds.insertId(m,f,h),cellData:{...e.cellData,[m]:pM({id:m,code:i,name:a,lastCodeRun:s,config:mM({...o,...d!=null&&{hide_code:d}}),lastExecutionTime:c,edited:!!i&&i!==s})},cellRuntime:{...e.cellRuntime,[m]:hM()},cellHandles:{...e.cellHandles,[m]:(0,K.createRef)()},scrollKey:l?m:null,untouchedNewCells:d&&l?new Set([...e.untouchedNewCells,m]):e.untouchedNewCells}},moveCell:(e,t)=>{let{cellId:n,before:r,direction:i}=t;if(r!==void 0&&i!==void 0&&B.warn(`Both before and direction specified for moveCell. Ignoring one.`),i){let t=e.cellIds.findWithId(n),r=e.cellIds.indexOf(t),a=i===`left`?r-1:r+1,o=e.cellIds.at(a);return o?{...e,cellIds:e.cellIds.moveAcrossColumns(t.id,n,o.id,void 0),scrollKey:n}:e}let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n);return r&&o===0?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,0),scrollKey:n}:!r&&o===a.length-1?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,a.length-1),scrollKey:n}:r?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o-1),scrollKey:n}:{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o+1),scrollKey:n}},moveCellToIndex:(e,t)=>{let{cellId:n,columnId:r,index:i}=t,a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=e.cellIds.get(r);if(!s)return e;let c=Math.max(0,Math.min(i,s.length)),l=a.id===r&&o<c?c-1:c;if(a.id===r&&o===l)return e;let u=e.cellIds.deleteById(n),d=u.get(r);return d?{...e,cellIds:u.insertId(n,r,Math.max(0,Math.min(l,d.length))),scrollKey:null}:e},dropCellOverCell:(e,t)=>{let{cellId:n,overCellId:r}=t,i=e.cellIds.findWithId(n),a=e.cellIds.findWithId(r),o=i.indexOfOrThrow(n),s=a.indexOfOrThrow(r);return i.id===a.id?o===s?e:{...e,cellIds:e.cellIds.moveWithinColumn(i.id,o,s),scrollKey:null}:{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,a.id,r),scrollKey:null}},moveCellsRelativeTo:(e,t)=>{let{cellIds:n,targetCellId:r,position:i,previousPlacements:a}=t;if(n.length===0)return e;let o=e.cellIds.moveCellsRelativeTo(n,r,i),s=a&&a.length===n.length?[...e.history,{type:`move`,cellIds:n,placements:a}]:e.history;return{...e,cellIds:o,history:s,scrollKey:null}},dropCellOverColumn:(e,t)=>{let{cellId:n,columnId:r}=t,i=e.cellIds.findWithId(n);return{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,r,void 0)}},dropOverNewColumn:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.moveToNewColumn(n)}},moveColumn:(e,t)=>t.column===t.overColumn?e:{...e,cellIds:e.cellIds.moveColumn(t.column,t.overColumn)},focusCell:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,where:i}=t,a=n.indexOfOrThrow(r),o;o=i===`before`?Cr(a-1,0,n.length-1):i===`after`?Cr(a+1,0,n.length-1):a;let s=n.atOrThrow(o);return cM({cellId:s,cell:e.cellHandles[s],isCodeHidden:CM(e,s),codeFocus:i===`after`?`top`:`bottom`,variableName:void 0}),e},focusTopCell:e=>{let t=e.cellIds.getColumns().at(0);if(t===void 0||t.length===0)return e;let n=t.first();return cM({cellId:n,cell:e.cellHandles[n],isCodeHidden:CM(e,n),codeFocus:void 0,variableName:void 0}),dM(),e},focusBottomCell:e=>{let t=e.cellIds.getColumns().at(-1);if(t===void 0||t.length===0)return e;let n=t.last();return cM({cellId:n,cell:e.cellHandles[n],isCodeHidden:CM(e,n),codeFocus:void 0,variableName:void 0}),uM(),e},sendToTop:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,scroll:i=!0}=t,a=n.indexOfOrThrow(r);return a===0?e:{...e,cellIds:e.cellIds.moveWithinColumn(n.id,a,0),scrollKey:i?r:null}},sendToBottom:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,scroll:i=!0}=t,a=n.indexOfOrThrow(r),o=n.length-1;return a===o?e:{...e,cellIds:e.cellIds.moveWithinColumn(n.id,a,o),scrollKey:i?r:null}},addColumn:(e,t)=>{let n=Ni.create();return{...e,cellIds:e.cellIds.addColumn(t.columnId,[n]),cellData:{...e.cellData,[n]:pM({id:n})},cellRuntime:{...e.cellRuntime,[n]:hM()},cellHandles:{...e.cellHandles,[n]:(0,K.createRef)()},scrollKey:n}},addColumnBreakpoint:(e,t)=>{let{cellId:n}=t;return e.cellIds.getColumns()[0].inOrderIds[0]===n?e:{...e,cellIds:e.cellIds.insertBreakpoint(n)}},deleteColumn:(e,t)=>{let{columnId:n}=t;return{...e,cellIds:e.cellIds.delete(n)}},mergeAllColumns:e=>({...e,cellIds:e.cellIds.mergeAllColumns()}),compactColumns:e=>({...e,cellIds:e.cellIds.compact()}),deleteCell:(e,t)=>{let n=t.cellId;if(e.cellIds.hasOnlyOneId())return e;let r;try{r=e.cellIds.findWithId(n)}catch(t){return B.warn(`Skipping delete for missing cellId`,{cellId:n,error:t}),e}let i=r.indexOfOrThrow(n),a=i===0?1:i-1,o=null;r.length>1&&(o=r.atOrThrow(a));let s=(e.cellHandles[n].current?.editorView)?.state.toJSON({history:tr});s&&(s.doc=e.cellData[n].code),oN(n);let c=e.cellData[n];return{...e,cellIds:e.cellIds.deleteById(n),history:[...e.history,{type:`delete`,name:c.name,serializedEditorState:s,column:r.id,index:i,isSetupCell:n===Mi,config:c.config}],scrollKey:o}},undoDeleteCell:e=>{if(e.history.length===0)return e;let t=e.history[e.history.length-1];if(t.type===`move`){let{cellIds:n,placements:r}=t;if(n.length===0||r.length!==n.length||n.some(t=>!e.cellData[t]))return{...e,history:e.history.slice(0,-1)};let i=n.map((e,t)=>({id:e,columnId:r[t].columnId,index:r[t].index}));return{...e,cellIds:e.cellIds.placeCells(i),history:e.history.slice(0,-1),scrollKey:n[0]??null}}let{name:n,serializedEditorState:r={doc:``},column:i,index:a,isSetupCell:o,config:s}=t,c=o?Mi:Ni.create(),l=pM({id:c,name:n,code:r.doc,edited:r.doc.trim().length>0,serializedEditorState:r,config:s});return{...e,cellIds:e.cellIds.insertId(c,i,a),cellData:{...e.cellData,[c]:l},cellRuntime:{...e.cellRuntime,[c]:hM()},cellHandles:{...e.cellHandles,[c]:(0,K.createRef)()},history:e.history.slice(0,-1),scrollKey:c}},clearSerializedEditorState:(e,t)=>{let{cellId:n}=t;return TM({state:e,cellId:n,cellReducer:e=>({...e,serializedEditorState:null})})},updateCellCode:(e,t)=>{let{cellId:n,code:r,formattingChange:i}=t;return e.cellData[n]?TM({state:e,cellId:n,cellReducer:e=>i?{...e,code:r,lastCodeRun:e.edited?e.lastCodeRun:r}:{...e,code:r,edited:r.trim()!==e.lastCodeRun}}):e},updateCellName:(e,t)=>{let{cellId:n,name:r}=t;return TM({state:e,cellId:n,cellReducer:e=>({...e,name:r})})},updateCellConfig:(e,t)=>{let{cellId:n,config:r}=t;return TM({state:e,cellId:n,cellReducer:e=>({...e,config:mM({...e.config,...r})})})},prepareForRun:(e,t)=>TM({state:wM({state:e,cellId:t.cellId,cellReducer:e=>rj(e)}),cellId:t.cellId,cellReducer:e=>({...e,edited:!1,lastCodeRun:e.code.trim()})}),handleCellMessage:(e,t)=>{let n=t.cell_id,r=wM({state:e,cellId:n,cellReducer:e=>nj(e,t)});return t.status===`queued`&&(r=TM({state:r,cellId:n,cellReducer:e=>({...e,lastCodeRun:e.code.trim(),edited:!1})})),{...r,cellLogs:[...r.cellLogs,...$j(t)]}},addLogs:(e,t)=>({...e,cellLogs:[...e.cellLogs,...t.logs]}),setCellIds:(e,t)=>{if(l(e.cellIds.inOrderIds,t.cellIds))return e;let n={...e.cellData},r={...e.cellRuntime},i={...e.cellHandles};for(let a of t.cellIds)a in e.cellData||(n[a]=pM({id:a})),a in e.cellRuntime||(r[a]=hM()),a in e.cellHandles||(i[a]=(0,K.createRef)());return{...e,cellIds:ys.fromWithPreviousShape(t.cellIds,e.cellIds),cellData:n,cellRuntime:r,cellHandles:i}},rebuildCellColumns:(e,t)=>{let n=ys.fromIdsAndColumns(t.cellIds.map(t=>[t,e.cellData[t]?.config.column??null]));return{...e,cellIds:n}},setCellCodes:(e,t)=>{ve(t.codes.length===t.ids.length,`Expected codes and ids to have the same length`);let n={...e},r=({cell:e,code:r,cellId:i,name:a,config:o})=>{if(!e)return pM({id:i,code:r,name:a,config:o,lastCodeRun:t.codeIsStale?null:r,edited:t.codeIsStale&&r.trim().length>0});let s=t.codeIsStale?e.lastCodeRun:r,c=s?s.trim()!==r.trim():!!r;if(e.code.trim()===r.trim())return{...e,code:r,edited:c,lastCodeRun:s,...a!==void 0&&{name:a},...o!==void 0&&{config:o}};if(!WA()||!GA(i)){let e=n.cellHandles[i].current;e?.editorViewOrNull&&jA(e.editorViewOrNull,r)}return{...e,code:r,edited:c,lastCodeRun:s,...a!==void 0&&{name:a},...o!==void 0&&{config:o}}};for(let e=0;e<t.ids.length;e++){let i=t.ids[e],a=t.codes[e];if(i===void 0||a===void 0)continue;let o=t.names?.[e],s=t.configs?.[e];n={...n,cellData:{...n.cellData,[i]:r({cell:n.cellData[i],code:a,cellId:i,name:o,config:s})}}}return n},setStdinResponse:(e,t)=>{let{cellId:n,response:r,outputIndex:i}=t;return wM({state:e,cellId:n,cellReducer:e=>{let t=[...e.consoleOutputs],n=t[i];return n==null||n.channel!==`stdin`?(B.warn(`Expected stdin output`),e):(t[i]={channel:`stdin`,mimetype:n.mimetype,data:n.data,timestamp:n.timestamp,response:n.mimetype===`text/password`?``:r},{...e,interrupted:!1,consoleOutputs:t})}})},setCells:(e,t)=>{let n=Object.fromEntries(t.map(e=>[e.id,e])),r=I(),i=t=>{if(!r)return hM();let n=e.cellRuntime[t];return n&&(n.output!=null||n.consoleOutputs.length>0)?n:hM()},a=Object.fromEntries(t.map(e=>[e.id,i(e.id)]));return gM({...e,cellIds:ys.fromIdsAndColumns(t.map(e=>[e.id,e.config.column])),cellData:n,cellRuntime:a,cellHandles:Object.fromEntries(t.map(e=>[e.id,(0,K.createRef)()]))})},moveToNextCell:(e,t)=>{let{cellId:n,before:r,noCreate:i=!1}=t;if(n===`__scratch__`)return e;let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=r?o-1:o+1,c=s===a.length,l=s===-1;if(c&&!i){let t=Ni.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,s),cellData:{...e.cellData,[t]:pM({id:t})},cellRuntime:{...e.cellRuntime,[t]:hM()},cellHandles:{...e.cellHandles,[t]:(0,K.createRef)()},scrollKey:t}}if(l&&!i){let t=Ni.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,0),cellData:{...e.cellData,[t]:pM({id:t})},cellRuntime:{...e.cellRuntime,[t]:hM()},cellHandles:{...e.cellHandles,[t]:(0,K.createRef)()},scrollKey:t}}if((c||l)&&i)return e;if(s>=0&&s<a.length){let t=a.atOrThrow(s);cM({cellId:t,cell:e.cellHandles[t],isCodeHidden:CM(e,t),codeFocus:r?`bottom`:`top`,variableName:void 0})}return e},markTouched:(e,t)=>{let{cellId:n}=t;if(e.untouchedNewCells.has(n)){let t=new Set(e.untouchedNewCells);return t.delete(n),{...e,untouchedNewCells:t}}return e},markUntouched:(e,t)=>{let{cellId:n}=t;if(!e.untouchedNewCells.has(n)){let t=new Set(e.untouchedNewCells);return t.add(n),{...e,untouchedNewCells:t}}return e},scrollToTarget:e=>{let t=e.scrollKey;if(t===null)return e;let n=e.cellIds.findWithId(t),r=n.indexOfOrThrow(t),i=r===n.length-1?n.last():n.atOrThrow(r);return cM({cellId:i,cell:e.cellHandles[i],isCodeHidden:CM(e,i),codeFocus:void 0,variableName:void 0}),{...e,scrollKey:null}},foldAll:e=>(zs(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),unfoldAll:e=>(Bs(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),clearLogs:e=>({...e,cellLogs:[]}),collapseCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.topLevelIds.map(t=>e.cellRuntime[t].outline),a=HA(r.indexOfOrThrow(n),i);if(!a)return e;let o=r.atOrThrow(a[1]);return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.collapse(n,o)),scrollKey:n}},expandCell:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.expand(n)),scrollKey:n}},collapseAllCells:e=>({...e,cellIds:e.cellIds.transformAll(t=>{let n=t.topLevelIds.map(t=>e.cellRuntime[t].outline),r=[...t.nodes],i=new Map,a=[],o=r.length-1;for(;o>=0;){let e=HA(o,n);if(e){let n=o,r=e[1],s=i.get(r)??r;i.set(r,n);let c=t.atOrThrow(n),l=t.atOrThrow(s);a.push({id:c,until:l})}else a.push(null);o--}let s=a.toReversed();return t.collapseAll(s)})}),expandAllCells:e=>({...e,cellIds:e.cellIds.transformAll(e=>e.expandAll())}),showCellIfHidden:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r,a=r.findAndExpandDeep(n);return a.equals(i)?e:{...e,cellIds:e.cellIds.transformWithCellId(n,()=>a)}},splitCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.indexOfOrThrow(n),a=e.cellData[n],o=e.cellHandles[n].current;if(o?.editorView==null)return e;let{beforeCursorCode:s,afterCursorCode:c}=MA(o.editorView);jA(o.editorView,s);let l=Ni.create();return{...e,cellIds:e.cellIds.insertId(l,r.id,i+1),cellData:{...e.cellData,[n]:{...a,code:s,edited:!!s&&s.trim()!==a.lastCodeRun?.trim()},[l]:pM({id:l,code:c,edited:!!c})},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]},[l]:hM()},cellHandles:{...e.cellHandles,[l]:(0,K.createRef)()},scrollKey:l}},undoSplitCell:(e,t)=>{let{cellId:n,snapshot:r}=t,i=e.cellData[n],a=e.cellHandles[n].current;return a?.editorView==null?e:(jA(a.editorView,r),{...e,cellIds:e.cellIds.transformWithCellId(n,e=>{let t=e.indexOfOrThrow(n)+1;return e.deleteAtIndex(t)}),cellData:{...e.cellData,[n]:{...i,code:r,edited:!!r&&r?.trim()!==i.lastCodeRun?.trim()}},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]}},cellHandles:{...e.cellHandles}})},clearCellOutput:(e,t)=>{let{cellId:n}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,output:null,consoleOutputs:[]})})},clearCellConsoleOutput:(e,t)=>{let{cellId:n}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,consoleOutputs:e.consoleOutputs.filter(e=>e.channel===`stdin`&&e.response==null)})})},clearAllCellOutputs:e=>{let t={...e.cellRuntime};for(let n of e.cellIds.inOrderIds)t[n]={...t[n],output:null,consoleOutputs:[]};return{...e,cellRuntime:t}},addSetupCellIfDoesntExist:(e,t)=>{let{code:n}=t;return e.cellIds.setupCellExists()?{...e,scrollKey:Mi}:{...e,cellIds:e.cellIds.insertId(Mi,e.cellIds.atOrThrow(0).id,0),cellData:{...e.cellData,[Mi]:pM({id:Mi,name:Mi,code:n,edited:!!n})},cellRuntime:{...e.cellRuntime,[Mi]:hM()},cellHandles:{...e.cellHandles,[Mi]:(0,K.createRef)()},scrollKey:Mi}}});yM(Ij);function CM(e,t){return!!e.cellData[t].config.hide_code&&!e.untouchedNewCells.has(t)}function wM({state:e,cellId:t,cellReducer:n}){return t in e.cellRuntime?{...e,cellRuntime:{...e.cellRuntime,[t]:n(e.cellRuntime[t])}}:(B.warn(`Cell ${t} not found in state`),e)}function TM({state:e,cellId:t,cellReducer:n}){return t in e.cellData?{...e,cellData:{...e.cellData,[t]:n(e.cellData[t])}}:(B.warn(`Cell ${t} not found in state`),e)}function EM(e){let t=e.cellData,n={column:null};return e.cellIds.getColumns().length>1?e.cellIds.getColumns().flatMap((e,r)=>e.inOrderIds.map((e,i)=>{let a={...n};return i===0&&(a.column=r),{...t[e].config,...a}})):e.cellIds.getColumns().flatMap(e=>e.inOrderIds.map(e=>({...t[e].config,...n})))}var DM=bM(e=>{u.set(SM,t=>vM(t,e))}).addLogs,OM=o(e=>e(SM).cellIds),kM=o(e=>e(OM).hasOnlyOneId()),AM=o(e=>vf(e(SM)).length>0);o(e=>yf(e(SM)).length>0);var jM=o(e=>bf(e(SM))),MM=o(e=>xf(e(SM))),NM=o(e=>hf(e(SM))),PM=o(e=>{let{cellIds:t,cellRuntime:n,cellData:r}=e(SM);return t.inOrderIds.map(e=>{let t=n[e],{name:i}=r[e];if(ff(t.output?.mimetype)){ve(Array.isArray(t.output.data),`Expected array data`);let n=t.output.data.filter(e=>!e.type.includes(`ancestor`));if(n.length>0)return{output:{...t.output,data:n},cellId:e,cellName:i}}return null}).filter(Boolean)}),FM=o(e=>{let t=e(OM),n=e(XM);return zA(t.inOrderIds.map(e=>n[e].outline))}),IM=o(e=>e(PM).length),LM=c(o(e=>{let{cellIds:t,cellData:n}=e(SM);return _e.fromEntries(t.inOrderIds.map(e=>[e,n[e]?.name]))})),RM=o(e=>e(SM).scrollKey),zM=()=>s(SM),BM=()=>s(OM),VM=()=>s(LM),HM=()=>s(PM),UM=()=>s(SM).cellLogs,WM=()=>s(RM),GM=()=>u.get(SM),KM=()=>u.get(SM).cellIds,qM=()=>{let{cellIds:e,cellData:t}=u.get(SM);return e.inOrderIds.map(e=>t[e]?.name).filter(Boolean)},JM=F(re(SM,e=>e.cellIds.inOrderIds.map(t=>e.cellData[t]))),YM=()=>a(JM),XM=o(e=>e(SM).cellRuntime),ZM=o(e=>pf(e(SM))),QM=o(e=>{let{cellRuntime:t}=e(SM);return Object.entries(t).every(([e,t])=>t.status!==`running`||e===`__scratch__`)}),$M=o(e=>mf(e(SM))),eN=o(e=>e(SM).cellIds.colLength),tN=o(e=>e(SM).cellIds.idLength>0),nN=o(e=>e(SM).cellIds.getColumnIds()),rN=ie(e=>o(t=>t(SM).cellData[e])),iN=ie(e=>o(t=>t(SM).cellRuntime[e])),aN=ie(e=>o(t=>t(SM).cellHandles[e]));function oN(e){rN.remove(e),iN.remove(e),aN.remove(e)}var sN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=rN(e),t[0]=e,t[1]=n),s(n)},cN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=iN(e),t[0]=e,t[1]=n),s(n)},lN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=aN(e),t[0]=e,t[1]=n),s(n)},uN=()=>{let{cellIds:e,cellHandles:t}=u.get(SM);return e.inOrderIds.map(e=>t[e]?.current?.editorViewOrNull).filter(Boolean)},dN=e=>{let{cellHandles:t}=u.get(SM);return t[e].current?.editorView},fN=e=>(Ws.promote(e),dN(e));function pN(e){let{cellIds:t,cellData:n,cellRuntime:r}=e;return t.getColumns().flatMap(e=>e.topLevelIds.map(e=>({...n[e],...r[e]})))}function mN(e){return o(t=>t(SM).untouchedNewCells.has(e))}function hN(e){let t=iN(e);return o(n=>{let r=n(t);if(!r||r.status===`queued`||r.status===`running`)return;let i=[],a=r.consoleOutputs;if(a&&a.length>0){let e=a.find(e=>e.mimetype===`application/vnd.marimo+traceback`);if(e){let t=e.data;i.push(...Ls(t))}}let o=r.output;if(o?.mimetype===`application/vnd.marimo+error`){let t=o.data;if(Array.isArray(t))for(let n of t)n.type===`syntax`&&n.lineno!=null&&i.push({kind:`cell`,cellId:e,lineNumber:n.lineno}),n.type===`import-star`&&n.lineno!=null&&i.push({kind:`cell`,cellId:e,lineNumber:n.lineno})}return i.length>0?i:void 0})}function gN(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n),xM(n)}export{Lj as $,Lo as $a,kf as $i,Ky as $n,Mh as $r,_O as $t,HM as A,ys as Aa,Cp as Ai,kT as An,yi as Ao,b_ as Ar,wk as At,lM as B,ns as Ba,ip as Bi,Dw as Bn,ig as Br,QO as Bt,$M as C,pu as Ca,Qp as Ci,ED as Cn,Mi as Co,D_ as Cr,Yk as Ct,gN as D,Is as Da,Tp as Di,dE as Dn,Di as Do,k_ as Dr,Ik as Dt,MM as E,Ls as Ea,kp as Ei,WE as En,Ei as Eo,E_ as Er,Lk as Et,cN as F,cs as Fa,xp as Fi,zw as Fn,gg as Fr,sk as Ft,aM as G,qo as Ga,Qf as Gi,LC as Gn,Hh as Gr,IO as Gt,sM as H,Xo as Ha,Kf as Hi,iw as Hn,eg as Hr,VO as Ht,zM as I,os as Ia,gp as Ii,jw as In,ug as Ir,ak as It,Zj as J,Ho as Ja,Jf as Ji,zC as Jn,Ih as Jr,kO as Jt,iM as K,Ko as Ka,Uf as Ki,IC as Kn,Qh as Kr,MO as Kt,WM as L,rs as La,sp as Li,Aw as Ln,ag as Lr,ik as Lt,BM as M,ps as Ma,vp as Mi,Iw as Mn,bg as Mr,Dk as Mt,UM as N,ls as Na,_p as Ni,Rw as Nn,pg as Nr,rk as Nt,sN as O,Ns as Oa,Dp as Oi,PE as On,xi as Oo,d_ as Or,Fk as Ot,VM as P,ss as Pa,hp as Pi,Lw as Pn,vg as Pr,ck as Pt,Vj as Q,Ro as Qa,Vf as Qi,qy as Qn,Fh as Qr,hO as Qt,pM as R,ts as Ra,ap as Ri,Mw as Rn,rg as Rr,ok as Rt,FM as S,kd as Sa,Zp as Si,WD as Sn,ji as So,S_ as Sr,qk as St,QM as T,Fs as Ta,Op as Ti,KE as Tn,Fi as To,w_ as Tr,Rk as Tt,rM as U,Yo as Ua,Wf as Ui,VC as Un,Yh as Ur,PO as Ut,fM as V,Zo as Va,cp as Vi,Tw as Vn,ng as Vr,BO as Vt,nM as W,Jo as Wa,Gf as Wi,FC as Wn,$h as Wr,FO as Wt,Yj as X,Bo as Xa,Hf as Xi,Lb as Xn,Rh as Xr,SO as Xt,Xj as Y,Vo as Ya,Zf as Yi,Qb as Yn,Lh as Yr,mO as Yt,Jj as Z,zo as Za,Bf as Zi,Yy as Zn,Ph as Zr,CO as Zt,AM as _,tf as _a,dm as _i,QD as _n,Vi as _o,q_ as _r,xA as _t,XM as a,Sf as aa,_h as ai,uO as an,ko as ao,ly as ar,WA as at,SM as b,Vd as ba,Bp as bi,$D as bn,Li as bo,T_ as br,Kk as bt,fN as c,gf as ca,fh as ci,eO as cn,Eo as co,Uv as cr,RA as ct,EM as d,Cf as da,uh as di,tO as dn,So as do,xv as dr,AA as dt,Af as ea,Nh as ei,bO as en,Io as eo,My as er,Oj as et,dN as f,ff as fa,lh as fi,GD as fn,Pa as fo,cv as fr,jA as ft,tN as g,cf as ga,Om as gi,qD as gn,Bi as go,Z_ as gr,kA as gt,GM as h,lf as ha,Zm as hi,XD as hn,zi as ho,uv as hr,SA as ht,OM as i,yf as ia,Ch as ii,lO as in,jo as io,hy as ir,GA as it,lN as j,hs as ja,bp as ji,Xw as jn,mi as jo,wg as jr,Ck as jt,YM as k,Ms as ka,Ep as ki,vT as kn,Si as ko,x_ as kr,Ok as kt,pN as l,Df as la,ch as li,rO as ln,wo as lo,Rv as lr,BA as lt,KM as m,df as ma,eh as mi,YD as mn,Hi as mo,tv as mr,EA as mt,rN as n,Ef as na,Th as ni,wO as nn,Po as no,ky as nr,ij as nt,nN as o,wf as oa,hh as oi,sO as on,Oo as oo,uy as or,UA as ot,qM as p,uf as pa,dh as pi,KD as pn,Ra as po,lv as pr,TA as pt,tM as q,Wo as qa,qf as qi,RC as qn,Zh as qr,OO as qt,IM as r,vf as ra,xh as ri,TO as rn,Mo as ro,Ay as rr,aj as rt,mN as s,_f as sa,ph as si,cO as sn,Do as so,Wv as sr,VA as st,jM as t,Tf as ta,Ah as ti,xO as tn,J as to,jy as tr,Nj as tt,uN as u,Of as ua,sh as ui,aO as un,Co as uo,bv as ur,NA as ut,kM as v,ef as va,um as vi,JD as vn,Ri as vo,Y_ as vr,OA as vt,eN as w,Ws as wa,Wp as wi,GE as wn,Ii as wo,O_ as wr,Xk as wt,ZM as x,Hd as xa,zp as xi,UD as xn,Pi as xo,C_ as xr,Gk as xt,NM as y,Yd as ya,Np as yi,ZD as yn,Ni as yo,V_ as yr,Qk as yt,hM as z,es as za,op as zi,kw as zn,Q as zr,$O as zt};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-DVplv7_D.js";import{no as n,oo as r}from"./cells-CJf50CB9.js";import{C as i,I as a,k as o,x as s}from"./schemas-ChRqMOTL.js";import{t as c}from"./compiler-runtime-BrajqUja.js";import{t as l}from"./isEmpty-BJso7_X0.js";import{g as u}from"./useEventListener-D9cftcHj.js";import{a as d,i as f,o as p,r as m}from"./config-DEzFV5-l.js";import{t as h}from"./cn-ldLVeaqm.js";import{t as g}from"./jsx-runtime-B74pBk57.js";import{t as _}from"./button-COI-NGrx.js";import{t as v}from"./createLucideIcon-DfJ2oMlA.js";import{r as y}from"./paths-bkIFVj8h.js";import{t as b}from"./ban-YzvUro5I.js";import{t as x}from"./bot-message-square-8xmbrehG.js";import{rt as S}from"./ai-model-dropdown-BSXpoT5O.js";import{a as C}from"./useNumberFormatter-D7O_26UI.js";import{t as w}from"./markdown-renderer-BPIzalVh.js";import{p as T,u as E}from"./add-cell-with-ai-Hyi0ODfx.js";import{t as D}from"./external-link-UrX9KO36.js";import{n as O}from"./spinner-DyNE-o8o.js";import{l as k}from"./datasource-D7lJC0XO.js";import{i as A}from"./strings-B2vv-ENv.js";import{t as j}from"./RenderHTML-CHgN4Sj3.js";var M=v(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),N=v(`shield-question-mark`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),P=`user_cancelled`;function F(e){if(e.type===`abort`)return e.reason}function I(e){return e.isAbort?e.streamReason||`user_cancelled`:null}function L(e){switch(e){case P:return`Generation stopped`;case`timeout`:return`Generation stopped: timed out`;default:return`Generation stopped: ${e}`}}var R=c(),z=e(t(),1),B=g(),V=e=>{let t=(0,R.c)(13),{reasoning:n,index:r,isStreaming:i}=e,a=r===void 0?0:r,o=i!==void 0&&i,[s,c]=z.useState(``);if(!n&&!o)return null;let l=o?`reasoning`:s,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,B.jsx)(x,{className:`h-3 w-3`}),t[0]=u):u=t[0];let h=o?`Thinking`:`View reasoning`,g=n.length>0&&` (${n.length} chars)`,_;t[1]!==h||t[2]!==g?(_=(0,B.jsx)(p,{className:`text-xs text-muted-foreground hover:bg-muted/50 px-2 py-1 h-auto rounded-sm [&[data-state=open]>svg]:rotate-180`,children:(0,B.jsxs)(`span`,{className:`flex items-center gap-2`,children:[u,h,g]})}),t[1]=h,t[2]=g,t[3]=_):_=t[3];let v;t[4]===n?v=t[5]:(v=(0,B.jsx)(f,{className:`pb-2 px-2`,children:(0,B.jsx)(`div`,{className:`bg-muted/30 border border-muted/50 rounded-md p-3 italic text-muted-foreground/90 relative`,children:(0,B.jsx)(`div`,{className:`pr-6`,children:(0,B.jsx)(w,{content:n})})})}),t[4]=n,t[5]=v);let y;t[6]!==_||t[7]!==v?(y=(0,B.jsxs)(d,{value:`reasoning`,className:`border-0`,children:[_,v]}),t[6]=_,t[7]=v,t[8]=y):y=t[8];let b;return t[9]!==a||t[10]!==l||t[11]!==y?(b=(0,B.jsx)(m,{type:`single`,collapsible:!0,className:`w-full mb-2`,value:l,onValueChange:c,children:y},a),t[9]=a,t[10]=l,t[11]=y,t[12]=b):b=t[12],b};function H(e){return e.replace(`tool-`,``)}var U=e=>{let t=(0,R.c)(9),{input:n,label:r}=e,i=r===void 0?`Tool Request`:r;if(n==null)return null;let a;t[0]===i?a=t[1]:(a=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:i}),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=JSON.stringify(n,null,2),t[2]=n,t[3]=o);let s;t[4]===o?s=t[5]:(s=(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:o}),t[4]=o,t[5]=s);let c;return t[6]!==a||t[7]!==s?(c=(0,B.jsxs)(`div`,{className:`space-y-2`,children:[a,s]}),t[6]=a,t[7]=s,t[8]=c):c=t[8],c},W=e=>{let t=(0,R.c)(27),{toolName:n,input:r,approval:i,onApprove:a,className:o}=e,s;t[0]===o?s=t[1]:(s=h(`rounded-md border border-(--amber-6) bg-(--amber-2) p-3 space-y-3`,o),t[0]=o,t[1]=s);let c;t[2]===n?c=t[3]:(c=H(n),t[2]=n,t[3]=c);let l=`Approval required for ${c}`,u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,B.jsx)(N,{className:`h-4 w-4 text-(--amber-11) mt-0.5 shrink-0`}),t[4]=u):u=t[4];let d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Approval required:`}),t[5]=d):d=t[5];let f;t[6]===n?f=t[7]:(f=H(n),t[6]=n,t[7]=f);let p;t[8]===f?p=t[9]:(p=(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[u,(0,B.jsxs)(`div`,{className:`text-xs text-(--amber-11) leading-relaxed`,children:[d,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:f})]})]}),t[8]=f,t[9]=p);let m;t[10]===r?m=t[11]:(m=(0,B.jsx)(U,{input:r}),t[10]=r,t[11]=m);let g;t[12]!==i.id||t[13]!==a?(g=(0,B.jsx)(_,{size:`xs`,variant:`outline`,onClick:()=>a({id:i.id,approved:!1}),children:`Deny`}),t[12]=i.id,t[13]=a,t[14]=g):g=t[14];let v;t[15]!==i.id||t[16]!==a?(v=(0,B.jsx)(_,{size:`xs`,onClick:()=>a({id:i.id,approved:!0}),children:`Approve`}),t[15]=i.id,t[16]=a,t[17]=v):v=t[17];let y;t[18]!==v||t[19]!==g?(y=(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[g,v]}),t[18]=v,t[19]=g,t[20]=y):y=t[20];let b;return t[21]!==s||t[22]!==y||t[23]!==l||t[24]!==p||t[25]!==m?(b=(0,B.jsxs)(`div`,{className:s,role:`alertdialog`,"aria-label":l,children:[p,m,y]}),t[21]=s,t[22]=y,t[23]=l,t[24]=p,t[25]=m,t[26]=b):b=t[26],b},G=e=>{let t=(0,R.c)(28),{toolName:n,input:i,errorText:a,isLive:o,className:s}=e,[c,l]=z.useState(o),u=z.useRef(o),d,f;t[0]===o?(d=t[1],f=t[2]):(d=()=>{u.current&&!o&&l(!1),u.current=o},f=[o],t[0]=o,t[1]=d,t[2]=f),z.useEffect(d,f);let p;t[3]===s?p=t[4]:(p=h(`rounded-md border border-(--red-6) bg-(--red-2)`,s),t[3]=s,t[4]=p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>l(K),t[5]=m):m=t[5];let g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,B.jsx)(r,{className:`h-3.5 w-3.5 shrink-0`}),t[6]=g):g=t[6];let _;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Failed:`}),t[7]=_):_=t[7];let v;t[8]===n?v=t[9]:(v=H(n),t[8]=n,t[9]=v);let y;t[10]===v?y=t[11]:(y=(0,B.jsxs)(`span`,{className:`flex-1 text-left`,children:[_,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:v})]}),t[10]=v,t[11]=y);let b=c&&`rotate-180`,x;t[12]===b?x=t[13]:(x=h(`h-3.5 w-3.5 shrink-0 transition-transform`,b),t[12]=b,t[13]=x);let S;t[14]===x?S=t[15]:(S=(0,B.jsx)(C,{className:x}),t[14]=x,t[15]=S);let w;t[16]!==c||t[17]!==S||t[18]!==y?(w=(0,B.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full flex items-center gap-2 px-3 py-2 text-xs text-(--red-11) hover:bg-(--red-3) rounded-md transition-colors`,"aria-expanded":c,children:[g,y,S]}),t[16]=c,t[17]=S,t[18]=y,t[19]=w):w=t[19];let T;t[20]!==a||t[21]!==i||t[22]!==c?(T=c&&(0,B.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t border-(--red-6)/40 pt-3`,children:[(0,B.jsx)(U,{input:i}),a&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-(--red-11) mb-1`,children:`Error`}),(0,B.jsx)(`pre`,{className:`bg-(--red-2) border border-(--red-6) rounded p-2 text-xs text-(--red-11) leading-relaxed overflow-auto scrollbar-thin max-h-64 whitespace-pre-wrap`,children:a})]})]}),t[20]=a,t[21]=i,t[22]=c,t[23]=T):T=t[23];let E;return t[24]!==w||t[25]!==T||t[26]!==p?(E=(0,B.jsxs)(`div`,{className:p,children:[w,T]}),t[24]=w,t[25]=T,t[26]=p,t[27]=E):E=t[27],E};function K(e){return!e}function q(e){return e==null||typeof e==`object`&&l(e)}var J=o({status:a().default(`success`),auth_required:i().default(!1),action_url:s().optional(),next_steps:s().optional(),meta:s().optional(),message:a().nullish()}),Y=e=>{let t=(0,R.c)(12),{data:r}=e,i;if(t[0]!==r){let{status:e,auth_required:a,action_url:o,meta:s,next_steps:c,message:l,...u}=r,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:`Tool Result`}),t[2]=d):d=t[2];let f;t[3]===e?f=t[4]:(f=(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--grass-2) text-(--grass-11) rounded-full font-medium capitalize`,children:e}),t[3]=e,t[4]=f);let p;t[5]===a?p=t[6]:(p=a&&(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--amber-2) text-(--amber-11) rounded-full`,children:`Auth Required`}),t[5]=a,t[6]=p);let m;t[7]!==f||t[8]!==p?(m=(0,B.jsxs)(`div`,{className:`flex items-center justify-between`,children:[d,(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f,p]})]}),t[7]=f,t[8]=p,t[9]=m):m=t[9];let h;t[10]===l?h=t[11]:(h=l&&(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(n,{className:`h-3 w-3 text-(--blue-11) mt-0.5 shrink-0`}),(0,B.jsx)(`div`,{className:`text-xs text-foreground`,children:l})]}),t[10]=l,t[11]=h),i=(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[m,h,u&&(0,B.jsx)(`div`,{className:`space-y-3`,children:Object.entries(u).map(Z)})]}),t[0]=r,t[1]=i}else i=t[1];return i},X=e=>{let t=(0,R.c)(8),{result:n}=e,r;t[0]===n?r=t[1]:(r=J.safeParse(n),t[0]=n,t[1]=r);let i=r;if(i.success){let e;return t[2]===i.data?e=t[3]:(e=(0,B.jsx)(Y,{data:i.data}),t[2]=i.data,t[3]=e),e}let a;t[4]===n?a=t[5]:(a=typeof n==`string`?n:JSON.stringify(n,null,2),t[4]=n,t[5]=a);let o;return t[6]===a?o=t[7]:(o=(0,B.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1 max-h-64 overflow-y-auto scrollbar-thin`,children:a}),t[6]=a,t[7]=o),o};function Z(e){let[t,n]=e;return q(n)?null:(0,B.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:JSON.stringify(n,null,2)})]},t)}var ee={"input-streaming":`Generating`,"input-available":`Running`,"approval-responded":`Awaiting result`,"output-available":`Done`,"output-denied":`Denied`},te=new Set([`input-streaming`,`input-available`,`approval-responded`]),ne=e=>{let t=(0,R.c)(5),{state:n,interrupted:r}=e;if(r){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(M,{className:`h-3 w-3 text-muted-foreground`}),t[0]=e):e=t[0],e}switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(O,{className:`h-3 w-3 animate-spin`}),t[1]=e):e=t[1],e}case`output-available`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(S,{className:`h-3 w-3 text-(--grass-11)`}),t[2]=e):e=t[2],e}case`output-denied`:{let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(b,{className:`h-3 w-3 text-muted-foreground`}),t[3]=e):e=t[3],e}default:{A(n);let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(k,{className:`h-3 w-3`}),t[4]=e):e=t[4],e}}};function re(e){switch(e){case`output-available`:return`text-(--grass-11)/80`;case`output-denied`:return`text-muted-foreground`;case`input-streaming`:case`input-available`:case`approval-responded`:return``;default:return A(e),``}}var Q=e=>{let t=(0,R.c)(34),{toolName:n,state:r,input:i,result:a,approval:o,index:s,className:c,isActive:l}=e,u=s===void 0?0:s,g=l===void 0||l,_;t[0]!==g||t[1]!==r?(_=!g&&te.has(r),t[0]=g,t[1]=r,t[2]=_):_=t[2];let v=_,y=`tool-${u}`,b;t[3]===c?b=t[4]:(b=h(`w-full`,c),t[3]=c,t[4]=b);let x;t[5]!==v||t[6]!==r?(x=h(`h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline`,v?`text-muted-foreground`:re(r)),t[5]=v,t[6]=r,t[7]=x):x=t[7];let S;t[8]!==v||t[9]!==r?(S=(0,B.jsx)(ne,{state:r,interrupted:v}),t[8]=v,t[9]=r,t[10]=S):S=t[10];let C=v?`Interrupted`:ee[r],w;t[11]===n?w=t[12]:(w=H(n),t[11]=n,t[12]=w);let T;t[13]===w?T=t[14]:(T=(0,B.jsx)(`code`,{className:`font-mono text-xs`,children:w}),t[13]=w,t[14]=T);let E;t[15]!==T||t[16]!==S||t[17]!==C?(E=(0,B.jsxs)(`span`,{className:`flex items-center gap-1`,children:[S,C,`:`,T]}),t[15]=T,t[16]=S,t[17]=C,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==x?(D=(0,B.jsx)(p,{className:x,children:E}),t[19]=E,t[20]=x,t[21]=D):D=t[21];let O;t[22]!==o||t[23]!==i||t[24]!==a||t[25]!==r?(O=(0,B.jsx)(f,{className:`py-2 px-2`,children:(0,B.jsx)(ie,{state:r,input:i,result:a,approval:o})}),t[22]=o,t[23]=i,t[24]=a,t[25]=r,t[26]=O):O=t[26];let k;t[27]!==D||t[28]!==O?(k=(0,B.jsxs)(d,{value:`tool-call`,className:`border-0`,children:[D,O]}),t[27]=D,t[28]=O,t[29]=k):k=t[29];let A;return t[30]!==k||t[31]!==y||t[32]!==b?(A=(0,B.jsx)(m,{type:`single`,collapsible:!0,className:b,children:k},y),t[30]=k,t[31]=y,t[32]=b,t[33]=A):A=t[33],A},ie=e=>{let t=(0,R.c)(16),{state:n,input:r,result:i,approval:a}=e;switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[0]===r?e=t[1]:(e=(0,B.jsx)(U,{input:r}),t[0]=r,t[1]=e),e}case`output-available`:{let e;t[2]===r?e=t[3]:(e=(0,B.jsx)(U,{input:r}),t[2]=r,t[3]=e);let n;t[4]===i?n=t[5]:(n=i!=null&&(0,B.jsx)(X,{result:i}),t[4]=i,t[5]=n);let a;return t[6]!==e||t[7]!==n?(a=(0,B.jsxs)(`div`,{className:`space-y-3`,children:[e,n]}),t[6]=e,t[7]=n,t[8]=a):a=t[8],a}case`output-denied`:{let e;t[9]===r?e=t[10]:(e=(0,B.jsx)(U,{input:r}),t[9]=r,t[10]=e);let n=a?.reason?`: ${a.reason}`:`.`,i;t[11]===n?i=t[12]:(i=(0,B.jsxs)(`div`,{className:`bg-muted/40 border border-border rounded-md p-3 text-xs text-muted-foreground leading-relaxed`,children:[`Tool execution was denied`,n]}),t[11]=n,t[12]=i);let o;return t[13]!==e||t[14]!==i?(o=(0,B.jsxs)(`div`,{className:`space-y-3`,children:[e,i]}),t[13]=e,t[14]=i,t[15]=o):o=t[15],o}default:return A(n),null}},$=e=>{let t=(0,R.c)(27),{toolName:n,state:r,result:i,errorText:a,input:o,approval:s,onApprove:c,index:l,className:u,isLive:d,isActive:f}=e,p=d===void 0||d,m=f===void 0||f;switch(r){case`approval-requested`:{if(s!=null&&c!=null){let e;return t[0]!==s||t[1]!==u||t[2]!==o||t[3]!==c||t[4]!==n?(e=(0,B.jsx)(W,{toolName:n,input:o,approval:s,onApprove:c,className:u}),t[0]=s,t[1]=u,t[2]=o,t[3]=c,t[4]=n,t[5]=e):e=t[5],e}let e;return t[6]!==u||t[7]!==l||t[8]!==o||t[9]!==m||t[10]!==n?(e=(0,B.jsx)(Q,{toolName:n,state:`input-available`,input:o,index:l,className:u,isActive:m}),t[6]=u,t[7]=l,t[8]=o,t[9]=m,t[10]=n,t[11]=e):e=t[11],e}case`output-error`:{let e;return t[12]!==u||t[13]!==a||t[14]!==o||t[15]!==p||t[16]!==n?(e=(0,B.jsx)(G,{toolName:n,input:o,errorText:a,isLive:p,className:u}),t[12]=u,t[13]=a,t[14]=o,t[15]=p,t[16]=n,t[17]=e):e=t[17],e}case`input-streaming`:case`input-available`:case`approval-responded`:case`output-available`:case`output-denied`:{let e;return t[18]!==s||t[19]!==u||t[20]!==l||t[21]!==o||t[22]!==m||t[23]!==i||t[24]!==r||t[25]!==n?(e=(0,B.jsx)(Q,{toolName:n,state:r,input:o,result:i,approval:s,index:l,className:u,isActive:m}),t[18]=s,t[19]=u,t[20]=l,t[21]=o,t[22]=m,t[23]=i,t[24]=r,t[25]=n,t[26]=e):e=t[26],e}default:return A(r),null}},ae=({message:e,isStreamingReasoning:t,isLast:n,isActive:r,addToolApprovalResponse:i})=>{return(0,B.jsx)(B.Fragment,{children:e.parts.map((e,t)=>a(e,t))});function a(a,o){if(oe(a))return(0,B.jsx)($,{index:o,toolName:a.type,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,className:`my-2`,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);if(se(a))return u.debug(`Found data part`,a),null;switch(a.type){case`text`:return a.text.includes(`<marimo-`)?(0,B.jsx)(z.Fragment,{children:j({html:a.text})},o):(0,B.jsx)(w,{content:a.text},o);case`reasoning`:return(0,B.jsx)(V,{reasoning:a.text,index:o,isStreaming:t&&n&&o===(e.parts.length||0)-1},o);case`file`:return(0,B.jsx)(E,{attachment:a},o);case`reasoning-file`:return(0,B.jsx)(E,{attachment:{type:`file`,mediaType:a.mediaType,url:a.url}},o);case`dynamic-tool`:return(0,B.jsx)($,{toolName:a.toolName,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);case`source-document`:return(0,B.jsx)(T,{icon:(0,B.jsx)(y,{className:`h-3 w-3 shrink-0`}),title:a.title,subtitle:a.filename},o);case`source-url`:return(0,B.jsx)(T,{icon:(0,B.jsx)(D,{className:`h-3 w-3 shrink-0`}),title:a.title??a.url,subtitle:a.title?a.url:void 0,href:a.url},o);case`custom`:return(0,B.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.kind},o);case`step-start`:return null;default:return A(a),null}}};function oe(e){return e.type.startsWith(`tool-`)}function se(e){return e.type.startsWith(`data-`)}export{I as i,L as n,F as r,ae as t};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-DVplv7_D.js";import{no as n,oo as r}from"./cells-CN1I_0eH.js";import{C as i,I as a,k as o,x as s}from"./schemas-ChRqMOTL.js";import{t as c}from"./compiler-runtime-BrajqUja.js";import{t as l}from"./isEmpty-BJso7_X0.js";import{g as u}from"./useEventListener-D9cftcHj.js";import{a as d,i as f,o as p,r as m}from"./config-DEzFV5-l.js";import{t as h}from"./cn-ldLVeaqm.js";import{t as g}from"./jsx-runtime-B74pBk57.js";import{t as _}from"./button-COI-NGrx.js";import{t as v}from"./createLucideIcon-DfJ2oMlA.js";import{r as y}from"./paths-bkIFVj8h.js";import{t as b}from"./ban-YzvUro5I.js";import{t as x}from"./bot-message-square-8xmbrehG.js";import{rt as S}from"./ai-model-dropdown-D5Fe5GS-.js";import{a as C}from"./useNumberFormatter-D7O_26UI.js";import{t as w}from"./markdown-renderer-D2dafr8r.js";import{p as T,u as E}from"./add-cell-with-ai-C4pN_ho7.js";import{t as D}from"./external-link-UrX9KO36.js";import{n as O}from"./spinner-DyNE-o8o.js";import{l as k}from"./datasource-DZJ6qqVI.js";import{i as A}from"./strings-B2vv-ENv.js";import{t as j}from"./RenderHTML-B18UiW8r.js";var M=v(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),N=v(`shield-question-mark`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),P=`user_cancelled`;function F(e){if(e.type===`abort`)return e.reason}function I(e){return e.isAbort?e.streamReason||`user_cancelled`:null}function L(e){switch(e){case P:return`Generation stopped`;case`timeout`:return`Generation stopped: timed out`;default:return`Generation stopped: ${e}`}}var R=c(),z=e(t(),1),B=g(),V=e=>{let t=(0,R.c)(13),{reasoning:n,index:r,isStreaming:i}=e,a=r===void 0?0:r,o=i!==void 0&&i,[s,c]=z.useState(``);if(!n&&!o)return null;let l=o?`reasoning`:s,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,B.jsx)(x,{className:`h-3 w-3`}),t[0]=u):u=t[0];let h=o?`Thinking`:`View reasoning`,g=n.length>0&&` (${n.length} chars)`,_;t[1]!==h||t[2]!==g?(_=(0,B.jsx)(p,{className:`text-xs text-muted-foreground hover:bg-muted/50 px-2 py-1 h-auto rounded-sm [&[data-state=open]>svg]:rotate-180`,children:(0,B.jsxs)(`span`,{className:`flex items-center gap-2`,children:[u,h,g]})}),t[1]=h,t[2]=g,t[3]=_):_=t[3];let v;t[4]===n?v=t[5]:(v=(0,B.jsx)(f,{className:`pb-2 px-2`,children:(0,B.jsx)(`div`,{className:`bg-muted/30 border border-muted/50 rounded-md p-3 italic text-muted-foreground/90 relative`,children:(0,B.jsx)(`div`,{className:`pr-6`,children:(0,B.jsx)(w,{content:n})})})}),t[4]=n,t[5]=v);let y;t[6]!==_||t[7]!==v?(y=(0,B.jsxs)(d,{value:`reasoning`,className:`border-0`,children:[_,v]}),t[6]=_,t[7]=v,t[8]=y):y=t[8];let b;return t[9]!==a||t[10]!==l||t[11]!==y?(b=(0,B.jsx)(m,{type:`single`,collapsible:!0,className:`w-full mb-2`,value:l,onValueChange:c,children:y},a),t[9]=a,t[10]=l,t[11]=y,t[12]=b):b=t[12],b};function H(e){return e.replace(`tool-`,``)}var U=e=>{let t=(0,R.c)(9),{input:n,label:r}=e,i=r===void 0?`Tool Request`:r;if(n==null)return null;let a;t[0]===i?a=t[1]:(a=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:i}),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=JSON.stringify(n,null,2),t[2]=n,t[3]=o);let s;t[4]===o?s=t[5]:(s=(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:o}),t[4]=o,t[5]=s);let c;return t[6]!==a||t[7]!==s?(c=(0,B.jsxs)(`div`,{className:`space-y-2`,children:[a,s]}),t[6]=a,t[7]=s,t[8]=c):c=t[8],c},W=e=>{let t=(0,R.c)(27),{toolName:n,input:r,approval:i,onApprove:a,className:o}=e,s;t[0]===o?s=t[1]:(s=h(`rounded-md border border-(--amber-6) bg-(--amber-2) p-3 space-y-3`,o),t[0]=o,t[1]=s);let c;t[2]===n?c=t[3]:(c=H(n),t[2]=n,t[3]=c);let l=`Approval required for ${c}`,u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,B.jsx)(N,{className:`h-4 w-4 text-(--amber-11) mt-0.5 shrink-0`}),t[4]=u):u=t[4];let d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Approval required:`}),t[5]=d):d=t[5];let f;t[6]===n?f=t[7]:(f=H(n),t[6]=n,t[7]=f);let p;t[8]===f?p=t[9]:(p=(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[u,(0,B.jsxs)(`div`,{className:`text-xs text-(--amber-11) leading-relaxed`,children:[d,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:f})]})]}),t[8]=f,t[9]=p);let m;t[10]===r?m=t[11]:(m=(0,B.jsx)(U,{input:r}),t[10]=r,t[11]=m);let g;t[12]!==i.id||t[13]!==a?(g=(0,B.jsx)(_,{size:`xs`,variant:`outline`,onClick:()=>a({id:i.id,approved:!1}),children:`Deny`}),t[12]=i.id,t[13]=a,t[14]=g):g=t[14];let v;t[15]!==i.id||t[16]!==a?(v=(0,B.jsx)(_,{size:`xs`,onClick:()=>a({id:i.id,approved:!0}),children:`Approve`}),t[15]=i.id,t[16]=a,t[17]=v):v=t[17];let y;t[18]!==v||t[19]!==g?(y=(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[g,v]}),t[18]=v,t[19]=g,t[20]=y):y=t[20];let b;return t[21]!==s||t[22]!==y||t[23]!==l||t[24]!==p||t[25]!==m?(b=(0,B.jsxs)(`div`,{className:s,role:`alertdialog`,"aria-label":l,children:[p,m,y]}),t[21]=s,t[22]=y,t[23]=l,t[24]=p,t[25]=m,t[26]=b):b=t[26],b},G=e=>{let t=(0,R.c)(28),{toolName:n,input:i,errorText:a,isLive:o,className:s}=e,[c,l]=z.useState(o),u=z.useRef(o),d,f;t[0]===o?(d=t[1],f=t[2]):(d=()=>{u.current&&!o&&l(!1),u.current=o},f=[o],t[0]=o,t[1]=d,t[2]=f),z.useEffect(d,f);let p;t[3]===s?p=t[4]:(p=h(`rounded-md border border-(--red-6) bg-(--red-2)`,s),t[3]=s,t[4]=p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>l(K),t[5]=m):m=t[5];let g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,B.jsx)(r,{className:`h-3.5 w-3.5 shrink-0`}),t[6]=g):g=t[6];let _;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Failed:`}),t[7]=_):_=t[7];let v;t[8]===n?v=t[9]:(v=H(n),t[8]=n,t[9]=v);let y;t[10]===v?y=t[11]:(y=(0,B.jsxs)(`span`,{className:`flex-1 text-left`,children:[_,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:v})]}),t[10]=v,t[11]=y);let b=c&&`rotate-180`,x;t[12]===b?x=t[13]:(x=h(`h-3.5 w-3.5 shrink-0 transition-transform`,b),t[12]=b,t[13]=x);let S;t[14]===x?S=t[15]:(S=(0,B.jsx)(C,{className:x}),t[14]=x,t[15]=S);let w;t[16]!==c||t[17]!==S||t[18]!==y?(w=(0,B.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full flex items-center gap-2 px-3 py-2 text-xs text-(--red-11) hover:bg-(--red-3) rounded-md transition-colors`,"aria-expanded":c,children:[g,y,S]}),t[16]=c,t[17]=S,t[18]=y,t[19]=w):w=t[19];let T;t[20]!==a||t[21]!==i||t[22]!==c?(T=c&&(0,B.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t border-(--red-6)/40 pt-3`,children:[(0,B.jsx)(U,{input:i}),a&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-(--red-11) mb-1`,children:`Error`}),(0,B.jsx)(`pre`,{className:`bg-(--red-2) border border-(--red-6) rounded p-2 text-xs text-(--red-11) leading-relaxed overflow-auto scrollbar-thin max-h-64 whitespace-pre-wrap`,children:a})]})]}),t[20]=a,t[21]=i,t[22]=c,t[23]=T):T=t[23];let E;return t[24]!==w||t[25]!==T||t[26]!==p?(E=(0,B.jsxs)(`div`,{className:p,children:[w,T]}),t[24]=w,t[25]=T,t[26]=p,t[27]=E):E=t[27],E};function K(e){return!e}function q(e){return e==null||typeof e==`object`&&l(e)}var J=o({status:a().default(`success`),auth_required:i().default(!1),action_url:s().optional(),next_steps:s().optional(),meta:s().optional(),message:a().nullish()}),Y=e=>{let t=(0,R.c)(12),{data:r}=e,i;if(t[0]!==r){let{status:e,auth_required:a,action_url:o,meta:s,next_steps:c,message:l,...u}=r,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:`Tool Result`}),t[2]=d):d=t[2];let f;t[3]===e?f=t[4]:(f=(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--grass-2) text-(--grass-11) rounded-full font-medium capitalize`,children:e}),t[3]=e,t[4]=f);let p;t[5]===a?p=t[6]:(p=a&&(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--amber-2) text-(--amber-11) rounded-full`,children:`Auth Required`}),t[5]=a,t[6]=p);let m;t[7]!==f||t[8]!==p?(m=(0,B.jsxs)(`div`,{className:`flex items-center justify-between`,children:[d,(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f,p]})]}),t[7]=f,t[8]=p,t[9]=m):m=t[9];let h;t[10]===l?h=t[11]:(h=l&&(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(n,{className:`h-3 w-3 text-(--blue-11) mt-0.5 shrink-0`}),(0,B.jsx)(`div`,{className:`text-xs text-foreground`,children:l})]}),t[10]=l,t[11]=h),i=(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[m,h,u&&(0,B.jsx)(`div`,{className:`space-y-3`,children:Object.entries(u).map(Z)})]}),t[0]=r,t[1]=i}else i=t[1];return i},X=e=>{let t=(0,R.c)(8),{result:n}=e,r;t[0]===n?r=t[1]:(r=J.safeParse(n),t[0]=n,t[1]=r);let i=r;if(i.success){let e;return t[2]===i.data?e=t[3]:(e=(0,B.jsx)(Y,{data:i.data}),t[2]=i.data,t[3]=e),e}let a;t[4]===n?a=t[5]:(a=typeof n==`string`?n:JSON.stringify(n,null,2),t[4]=n,t[5]=a);let o;return t[6]===a?o=t[7]:(o=(0,B.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1 max-h-64 overflow-y-auto scrollbar-thin`,children:a}),t[6]=a,t[7]=o),o};function Z(e){let[t,n]=e;return q(n)?null:(0,B.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:JSON.stringify(n,null,2)})]},t)}var ee={"input-streaming":`Generating`,"input-available":`Running`,"approval-responded":`Awaiting result`,"output-available":`Done`,"output-denied":`Denied`},te=new Set([`input-streaming`,`input-available`,`approval-responded`]),ne=e=>{let t=(0,R.c)(5),{state:n,interrupted:r}=e;if(r){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(M,{className:`h-3 w-3 text-muted-foreground`}),t[0]=e):e=t[0],e}switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(O,{className:`h-3 w-3 animate-spin`}),t[1]=e):e=t[1],e}case`output-available`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(S,{className:`h-3 w-3 text-(--grass-11)`}),t[2]=e):e=t[2],e}case`output-denied`:{let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(b,{className:`h-3 w-3 text-muted-foreground`}),t[3]=e):e=t[3],e}default:{A(n);let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(k,{className:`h-3 w-3`}),t[4]=e):e=t[4],e}}};function re(e){switch(e){case`output-available`:return`text-(--grass-11)/80`;case`output-denied`:return`text-muted-foreground`;case`input-streaming`:case`input-available`:case`approval-responded`:return``;default:return A(e),``}}var Q=e=>{let t=(0,R.c)(34),{toolName:n,state:r,input:i,result:a,approval:o,index:s,className:c,isActive:l}=e,u=s===void 0?0:s,g=l===void 0||l,_;t[0]!==g||t[1]!==r?(_=!g&&te.has(r),t[0]=g,t[1]=r,t[2]=_):_=t[2];let v=_,y=`tool-${u}`,b;t[3]===c?b=t[4]:(b=h(`w-full`,c),t[3]=c,t[4]=b);let x;t[5]!==v||t[6]!==r?(x=h(`h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline`,v?`text-muted-foreground`:re(r)),t[5]=v,t[6]=r,t[7]=x):x=t[7];let S;t[8]!==v||t[9]!==r?(S=(0,B.jsx)(ne,{state:r,interrupted:v}),t[8]=v,t[9]=r,t[10]=S):S=t[10];let C=v?`Interrupted`:ee[r],w;t[11]===n?w=t[12]:(w=H(n),t[11]=n,t[12]=w);let T;t[13]===w?T=t[14]:(T=(0,B.jsx)(`code`,{className:`font-mono text-xs`,children:w}),t[13]=w,t[14]=T);let E;t[15]!==T||t[16]!==S||t[17]!==C?(E=(0,B.jsxs)(`span`,{className:`flex items-center gap-1`,children:[S,C,`:`,T]}),t[15]=T,t[16]=S,t[17]=C,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==x?(D=(0,B.jsx)(p,{className:x,children:E}),t[19]=E,t[20]=x,t[21]=D):D=t[21];let O;t[22]!==o||t[23]!==i||t[24]!==a||t[25]!==r?(O=(0,B.jsx)(f,{className:`py-2 px-2`,children:(0,B.jsx)(ie,{state:r,input:i,result:a,approval:o})}),t[22]=o,t[23]=i,t[24]=a,t[25]=r,t[26]=O):O=t[26];let k;t[27]!==D||t[28]!==O?(k=(0,B.jsxs)(d,{value:`tool-call`,className:`border-0`,children:[D,O]}),t[27]=D,t[28]=O,t[29]=k):k=t[29];let A;return t[30]!==k||t[31]!==y||t[32]!==b?(A=(0,B.jsx)(m,{type:`single`,collapsible:!0,className:b,children:k},y),t[30]=k,t[31]=y,t[32]=b,t[33]=A):A=t[33],A},ie=e=>{let t=(0,R.c)(16),{state:n,input:r,result:i,approval:a}=e;switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[0]===r?e=t[1]:(e=(0,B.jsx)(U,{input:r}),t[0]=r,t[1]=e),e}case`output-available`:{let e;t[2]===r?e=t[3]:(e=(0,B.jsx)(U,{input:r}),t[2]=r,t[3]=e);let n;t[4]===i?n=t[5]:(n=i!=null&&(0,B.jsx)(X,{result:i}),t[4]=i,t[5]=n);let a;return t[6]!==e||t[7]!==n?(a=(0,B.jsxs)(`div`,{className:`space-y-3`,children:[e,n]}),t[6]=e,t[7]=n,t[8]=a):a=t[8],a}case`output-denied`:{let e;t[9]===r?e=t[10]:(e=(0,B.jsx)(U,{input:r}),t[9]=r,t[10]=e);let n=a?.reason?`: ${a.reason}`:`.`,i;t[11]===n?i=t[12]:(i=(0,B.jsxs)(`div`,{className:`bg-muted/40 border border-border rounded-md p-3 text-xs text-muted-foreground leading-relaxed`,children:[`Tool execution was denied`,n]}),t[11]=n,t[12]=i);let o;return t[13]!==e||t[14]!==i?(o=(0,B.jsxs)(`div`,{className:`space-y-3`,children:[e,i]}),t[13]=e,t[14]=i,t[15]=o):o=t[15],o}default:return A(n),null}},$=e=>{let t=(0,R.c)(27),{toolName:n,state:r,result:i,errorText:a,input:o,approval:s,onApprove:c,index:l,className:u,isLive:d,isActive:f}=e,p=d===void 0||d,m=f===void 0||f;switch(r){case`approval-requested`:{if(s!=null&&c!=null){let e;return t[0]!==s||t[1]!==u||t[2]!==o||t[3]!==c||t[4]!==n?(e=(0,B.jsx)(W,{toolName:n,input:o,approval:s,onApprove:c,className:u}),t[0]=s,t[1]=u,t[2]=o,t[3]=c,t[4]=n,t[5]=e):e=t[5],e}let e;return t[6]!==u||t[7]!==l||t[8]!==o||t[9]!==m||t[10]!==n?(e=(0,B.jsx)(Q,{toolName:n,state:`input-available`,input:o,index:l,className:u,isActive:m}),t[6]=u,t[7]=l,t[8]=o,t[9]=m,t[10]=n,t[11]=e):e=t[11],e}case`output-error`:{let e;return t[12]!==u||t[13]!==a||t[14]!==o||t[15]!==p||t[16]!==n?(e=(0,B.jsx)(G,{toolName:n,input:o,errorText:a,isLive:p,className:u}),t[12]=u,t[13]=a,t[14]=o,t[15]=p,t[16]=n,t[17]=e):e=t[17],e}case`input-streaming`:case`input-available`:case`approval-responded`:case`output-available`:case`output-denied`:{let e;return t[18]!==s||t[19]!==u||t[20]!==l||t[21]!==o||t[22]!==m||t[23]!==i||t[24]!==r||t[25]!==n?(e=(0,B.jsx)(Q,{toolName:n,state:r,input:o,result:i,approval:s,index:l,className:u,isActive:m}),t[18]=s,t[19]=u,t[20]=l,t[21]=o,t[22]=m,t[23]=i,t[24]=r,t[25]=n,t[26]=e):e=t[26],e}default:return A(r),null}},ae=({message:e,isStreamingReasoning:t,isLast:n,isActive:r,addToolApprovalResponse:i})=>{return(0,B.jsx)(B.Fragment,{children:e.parts.map((e,t)=>a(e,t))});function a(a,o){if(oe(a))return(0,B.jsx)($,{index:o,toolName:a.type,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,className:`my-2`,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);if(se(a))return u.debug(`Found data part`,a),null;switch(a.type){case`text`:return a.text.includes(`<marimo-`)?(0,B.jsx)(z.Fragment,{children:j({html:a.text})},o):(0,B.jsx)(w,{content:a.text},o);case`reasoning`:return(0,B.jsx)(V,{reasoning:a.text,index:o,isStreaming:t&&n&&o===(e.parts.length||0)-1},o);case`file`:return(0,B.jsx)(E,{attachment:a},o);case`reasoning-file`:return(0,B.jsx)(E,{attachment:{type:`file`,mediaType:a.mediaType,url:a.url}},o);case`dynamic-tool`:return(0,B.jsx)($,{toolName:a.toolName,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);case`source-document`:return(0,B.jsx)(T,{icon:(0,B.jsx)(y,{className:`h-3 w-3 shrink-0`}),title:a.title,subtitle:a.filename},o);case`source-url`:return(0,B.jsx)(T,{icon:(0,B.jsx)(D,{className:`h-3 w-3 shrink-0`}),title:a.title??a.url,subtitle:a.title?a.url:void 0,href:a.url},o);case`custom`:return(0,B.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.kind},o);case`step-start`:return null;default:return A(a),null}}};function oe(e){return e.type.startsWith(`tool-`)}function se(e){return e.type.startsWith(`data-`)}export{I as i,L as n,F as r,ae as t};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,l as r,t as i,u as a}from"./useEvent-Dfcbgjhg.js";import{t as o}from"./react-DVplv7_D.js";import{D as s,Zn as c,ao as l,br as u,cn as d,dn as f,qa as p,un as m}from"./cells-CJf50CB9.js";import{P as h,o as g}from"./config-MaHeMC9o.js";import{t as _}from"./compiler-runtime-BrajqUja.js";import{i as v,t as y}from"./config-CA1V-wjh.js";import{g as b,o as x}from"./useEventListener-D9cftcHj.js";import{t as S}from"./config-DEzFV5-l.js";import{t as C}from"./cn-ldLVeaqm.js";import{t as w}from"./jsx-runtime-B74pBk57.js";import{C as T,S as E,T as D,b as O,v as k,w as A}from"./fullscreen-B9tHcfpV.js";import{u as j}from"./menu-items-BrwnTgyK.js";import{o as M}from"./alert-dialog-BaPGzeOK.js";import{a as N,i as P,m as F,n as I,r as L,s as R,t as z}from"./select-DTBn5eTb.js";import{t as B}from"./switch-CTaiAjrz.js";import{i as ee,t as V}from"./tooltip-C9TuY18o.js";import{t as H}from"./button-COI-NGrx.js";import{t as te}from"./createLucideIcon-DfJ2oMlA.js";import{t as ne}from"./arrow-right-Cgit4Nk2.js";import{t as U}from"./bot-message-square-8xmbrehG.js";import{M as re,c as ie,h as ae,m as oe,p as se,r as ce,t as le}from"./ai-model-dropdown-BSXpoT5O.js";import{i as ue,n as de,r as fe,t as pe}from"./chat-display-CrPNkPHG.js";import{B as W,C as me,D as he,E as ge,N as _e,R as ve,S as ye,U as be,_ as xe,b as Se,c as Ce,d as we,f as Te,g as Ee,h as De,k as Oe,l as ke,m as Ae,n as je,u as Me,v as Ne,w as Pe,x as Fe,y as Ie,z as Le}from"./add-cell-with-ai-Hyi0ODfx.js";import{t as Re}from"./code-BEiQP4pS.js";import{t as ze}from"./hat-glasses-C8RhSVii.js";import{b as Be,p as Ve}from"./write-secret-modal-DzKAInL2.js";import{n as He}from"./spinner-DyNE-o8o.js";import{t as G}from"./message-circle-C3rKm8_a.js";import{t as Ue}from"./plus-C5silF6g.js";import{r as We,rn as Ge}from"./input-BoBxR50a.js";import{t as Ke}from"./settings-BpdQZRgT.js";import{t as qe}from"./trash-2-DcgaW8fn.js";import{t as Je}from"./copy-icon-BIiRXh_3.js";import{r as Ye}from"./requests-lt0JK8Jt.js";import{t as Xe}from"./uuid-k9DpjH68.js";import{t as Ze}from"./I18nProvider-Cg2I_s1_.js";import{l as Qe}from"./dates-CfmdTL6B.js";import{i as $e,o as et,r as tt,t as nt}from"./state-ZLQj4kZ7.js";import{n as rt}from"./error-banner-COZ7SfYV.js";import{t as it}from"./empty-state-BaCKb7o3.js";import{t as at}from"./scroll-to-bottom-button-1FyowpWV.js";var K=e(o(),1),q=w(),ot=Object.defineProperty,J=(e,t)=>ot(e,`name`,{value:t,configurable:!0});function st(e,t){return K.useReducer((e,n)=>t[e][n]??e,e)}J(st,`useStateMachine`);var ct=`ScrollArea`,[lt,ut]=A(ct),[Y,X]=lt(ct),dt=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,type:r=`hover`,dir:i,scrollHideDelay:a=600,...o}=e,[s,c]=K.useState(null),[l,u]=K.useState(null),[d,f]=K.useState(null),[p,m]=K.useState(null),[h,g]=K.useState(null),[_,v]=K.useState(0),[y,b]=K.useState(0),[S,C]=K.useState(!1),[w,T]=K.useState(!1),E=x(t,c),O=j(i);return(0,q.jsx)(Y,{scope:n,type:r,dir:O,scrollHideDelay:a,scrollArea:s,viewport:l,onViewportChange:u,content:d,onContentChange:f,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:S,onScrollbarXEnabledChange:C,scrollbarY:h,onScrollbarYChange:g,scrollbarYEnabled:w,onScrollbarYEnabledChange:T,onCornerWidthChange:v,onCornerHeightChange:b,children:(0,q.jsx)(D.div,{dir:O,...o,ref:E,style:{position:`relative`,"--radix-scroll-area-corner-width":_+`px`,"--radix-scroll-area-corner-height":y+`px`,...e.style}})})},`ScrollArea`)),ft=`ScrollAreaViewport`,pt=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,children:r,nonce:i,...a}=e,o=X(ft,n),s=K.useRef(null),c=x(t,s,o.onViewportChange);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(mt,{nonce:i}),(0,q.jsx)(D.div,{"data-radix-scroll-area-viewport":``,...a,ref:c,style:{overflowX:o.scrollbarXEnabled?`scroll`:`hidden`,overflowY:o.scrollbarYEnabled?`scroll`:`hidden`,...e.style},children:(0,q.jsx)(`div`,{ref:o.onContentChange,style:{minWidth:`100%`,display:`table`},children:r})})]})},`ScrollAreaViewport`)),mt=K.memo(J(function({nonce:e}){return(0,q.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}`},nonce:e})},`ScrollAreaViewportStyle`),(e,t)=>e.nonce===t.nonce),Z=`ScrollAreaScrollbar`,ht=K.forwardRef(J(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),{onScrollbarXEnabledChange:a,onScrollbarYEnabledChange:o}=i,s=e.orientation===`horizontal`;return K.useEffect(()=>(s?a(!0):o(!0),()=>{s?a(!1):o(!1)}),[s,a,o]),i.type===`hover`?(0,q.jsx)(gt,{...r,ref:t,forceMount:n}):i.type===`scroll`?(0,q.jsx)(_t,{...r,ref:t,forceMount:n}):i.type===`auto`?(0,q.jsx)(vt,{...r,ref:t,forceMount:n}):i.type===`always`?(0,q.jsx)(yt,{...r,ref:t,"data-state":`visible`}):null},`ScrollAreaScrollbar`)),gt=K.forwardRef(J(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),[a,o]=K.useState(!1);return K.useEffect(()=>{let e=i.scrollArea,t=0;if(e){let n=J(()=>{window.clearTimeout(t),o(!0)},`handlePointerEnter`),r=J(()=>{t=window.setTimeout(()=>o(!1),i.scrollHideDelay)},`handlePointerLeave`);return e.addEventListener(`pointerenter`,n),e.addEventListener(`pointerleave`,r),()=>{window.clearTimeout(t),e.removeEventListener(`pointerenter`,n),e.removeEventListener(`pointerleave`,r)}}},[i.scrollArea,i.scrollHideDelay]),(0,q.jsx)(O,{present:n||a,children:(0,q.jsx)(vt,{"data-state":a?`visible`:`hidden`,...r,ref:t})})},`ScrollAreaScrollbarHover`)),_t=K.forwardRef(J(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),a=e.orientation===`horizontal`,o=zt(()=>c(`SCROLL_END`),100),[s,c]=st(`hidden`,{hidden:{SCROLL:`scrolling`},scrolling:{SCROLL_END:`idle`,POINTER_ENTER:`interacting`},interacting:{SCROLL:`interacting`,POINTER_LEAVE:`idle`},idle:{HIDE:`hidden`,SCROLL:`scrolling`,POINTER_ENTER:`interacting`}});return K.useEffect(()=>{if(s===`idle`){let e=window.setTimeout(()=>c(`HIDE`),i.scrollHideDelay);return()=>window.clearTimeout(e)}},[s,i.scrollHideDelay,c]),K.useEffect(()=>{let e=i.viewport,t=a?`scrollLeft`:`scrollTop`;if(e){let n=e[t],r=J(()=>{let r=e[t];n!==r&&(c(`SCROLL`),o()),n=r},`handleScroll`);return e.addEventListener(`scroll`,r),()=>e.removeEventListener(`scroll`,r)}},[i.viewport,a,c,o]),(0,q.jsx)(O,{present:n||s!==`hidden`,children:(0,q.jsx)(yt,{"data-state":s===`hidden`?`hidden`:`visible`,...r,ref:t,onPointerEnter:T(e.onPointerEnter,()=>c(`POINTER_ENTER`)),onPointerLeave:T(e.onPointerLeave,()=>c(`POINTER_LEAVE`))})})},`ScrollAreaScrollbarScroll`)),vt=K.forwardRef(J(function(e,t){let n=X(Z,e.__scopeScrollArea),{forceMount:r,...i}=e,[a,o]=K.useState(!1),s=e.orientation===`horizontal`,c=zt(()=>{if(n.viewport){let e=n.viewport.offsetWidth<n.viewport.scrollWidth,t=n.viewport.offsetHeight<n.viewport.scrollHeight;o(s?e:t)}},10);return Q(n.viewport,c),Q(n.content,c),(0,q.jsx)(O,{present:r||a,children:(0,q.jsx)(yt,{"data-state":a?`visible`:`hidden`,...i,ref:t})})},`ScrollAreaScrollbarAuto`)),yt=K.forwardRef(J(function(e,t){let{orientation:n=`vertical`,...r}=e,i=X(Z,e.__scopeScrollArea),a=K.useRef(null),o=K.useRef(0),[s,c]=K.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),l=Mt(s.viewport,s.content),u={...r,sizes:s,onSizesChange:c,hasThumb:l>0&&l<1,onThumbChange:J(e=>a.current=e,`onThumbChange`),onThumbPointerUp:J(()=>o.current=0,`onThumbPointerUp`),onThumbPointerDown:J(e=>o.current=e,`onThumbPointerDown`)};function d(e,t){return Pt(e,o.current,s,t)}return J(d,`getScrollPosition`),n===`horizontal`?(0,q.jsx)(bt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollLeft,t=Ft(e,s,i.dir);a.current.style.transform=`translate3d(${t}px, 0, 0)`}},onWheelScroll:e=>{i.viewport&&(i.viewport.scrollLeft=e)},onDragScroll:e=>{i.viewport&&(i.viewport.scrollLeft=d(e,i.dir))}}):n===`vertical`?(0,q.jsx)(xt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollTop,t=Ft(e,s);a.current.style.transform=`translate3d(0, ${t}px, 0)`}},onWheelScroll:e=>{i.viewport&&(i.viewport.scrollTop=e)},onDragScroll:e=>{i.viewport&&(i.viewport.scrollTop=d(e))}}):null},`ScrollAreaScrollbarVisible`)),bt=K.forwardRef(J(function(e,t){let{sizes:n,onSizesChange:r,...i}=e,a=X(Z,e.__scopeScrollArea),[o,s]=K.useState(),c=K.useRef(null),l=x(t,c,a.onScrollbarXChange);return K.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,q.jsx)(wt,{"data-orientation":`horizontal`,...i,ref:l,sizes:n,style:{bottom:0,left:a.dir===`rtl`?`var(--radix-scroll-area-corner-width)`:0,right:a.dir===`ltr`?`var(--radix-scroll-area-corner-width)`:0,"--radix-scroll-area-thumb-width":Nt(n)+`px`,...e.style},onThumbPointerDown:t=>e.onThumbPointerDown(t.x),onDragScroll:t=>e.onDragScroll(t.x),onWheelScroll:(t,n)=>{if(a.viewport){let r=a.viewport.scrollLeft+t.deltaX;e.onWheelScroll(r),Lt(r,n)&&t.preventDefault()}},onResize:()=>{c.current&&a.viewport&&o&&r({content:a.viewport.scrollWidth,viewport:a.viewport.offsetWidth,scrollbar:{size:c.current.clientWidth,paddingStart:jt(o.paddingLeft),paddingEnd:jt(o.paddingRight)}})}})},`ScrollAreaScrollbarX`)),xt=K.forwardRef(J(function(e,t){let{sizes:n,onSizesChange:r,...i}=e,a=X(Z,e.__scopeScrollArea),[o,s]=K.useState(),c=K.useRef(null),l=x(t,c,a.onScrollbarYChange);return K.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,q.jsx)(wt,{"data-orientation":`vertical`,...i,ref:l,sizes:n,style:{top:0,right:a.dir===`ltr`?0:void 0,left:a.dir===`rtl`?0:void 0,bottom:`var(--radix-scroll-area-corner-height)`,"--radix-scroll-area-thumb-height":Nt(n)+`px`,...e.style},onThumbPointerDown:t=>e.onThumbPointerDown(t.y),onDragScroll:t=>e.onDragScroll(t.y),onWheelScroll:(t,n)=>{if(a.viewport){let r=a.viewport.scrollTop+t.deltaY;e.onWheelScroll(r),Lt(r,n)&&t.preventDefault()}},onResize:()=>{c.current&&a.viewport&&o&&r({content:a.viewport.scrollHeight,viewport:a.viewport.offsetHeight,scrollbar:{size:c.current.clientHeight,paddingStart:jt(o.paddingTop),paddingEnd:jt(o.paddingBottom)}})}})},`ScrollAreaScrollbarY`)),[St,Ct]=lt(Z),wt=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,sizes:r,hasThumb:i,onThumbChange:a,onThumbPointerUp:o,onThumbPointerDown:s,onThumbPositionChange:c,onDragScroll:l,onWheelScroll:u,onResize:d,...f}=e,p=X(Z,n),[m,h]=K.useState(null),g=x(t,h),_=K.useRef(null),v=K.useRef(``),y=p.viewport,b=r.content-r.viewport,S=k(u),C=k(c),w=zt(d,10);function E(e){if(_.current){let t=e.clientX-_.current.left,n=e.clientY-_.current.top;l({x:t,y:n})}}return J(E,`handleDragScroll`),K.useEffect(()=>{let e=J(e=>{let t=e.target;m?.contains(t)&&S(e,b)},`handleWheel`);return document.addEventListener(`wheel`,e,{passive:!1}),()=>document.removeEventListener(`wheel`,e,{passive:!1})},[y,m,b,S]),K.useEffect(C,[r,C]),Q(m,w),Q(p.content,w),(0,q.jsx)(St,{scope:n,scrollbar:m,hasThumb:i,onThumbChange:k(a),onThumbPointerUp:k(o),onThumbPositionChange:C,onThumbPointerDown:k(s),children:(0,q.jsx)(D.div,{...f,ref:g,style:{position:`absolute`,...f.style},onPointerDown:T(e.onPointerDown,e=>{e.button===0&&(e.target.setPointerCapture(e.pointerId),_.current=m.getBoundingClientRect(),v.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect=`none`,p.viewport&&(p.viewport.style.scrollBehavior=`auto`),E(e))}),onPointerMove:T(e.onPointerMove,E),onPointerUp:T(e.onPointerUp,e=>{let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),document.body.style.webkitUserSelect=v.current,p.viewport&&(p.viewport.style.scrollBehavior=``),_.current=null})})})},`ScrollAreaScrollbarImpl`)),Tt=`ScrollAreaThumb`,Et=K.forwardRef(J(function(e,t){let{forceMount:n,...r}=e,i=Ct(Tt,e.__scopeScrollArea);return(0,q.jsx)(O,{present:n||i.hasThumb,children:(0,q.jsx)(Dt,{ref:t,...r})})},`ScrollAreaThumb`)),Dt=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,style:r,...i}=e,a=X(Tt,n),o=Ct(Tt,n),{onThumbPositionChange:s}=o,c=x(t,o.onThumbChange),l=K.useRef(void 0),u=zt(()=>{l.current&&=(l.current(),void 0)},100);return K.useEffect(()=>{let e=a.viewport;if(e){let t=J(()=>{if(u(),!l.current){let t=Rt(e,s);l.current=t,s()}},`handleScroll`);return s(),e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)}},[a.viewport,u,s]),(0,q.jsx)(D.div,{"data-state":o.hasThumb?`visible`:`hidden`,...i,ref:c,style:{width:`var(--radix-scroll-area-thumb-width)`,height:`var(--radix-scroll-area-thumb-height)`,...r},onPointerDownCapture:T(e.onPointerDownCapture,e=>{let t=e.target.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top;o.onThumbPointerDown({x:n,y:r})}),onPointerUp:T(e.onPointerUp,o.onThumbPointerUp)})},`ScrollAreaThumbImpl`)),Ot=`ScrollAreaCorner`,kt=K.forwardRef(J(function(e,t){let n=X(Ot,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!==`scroll`&&r?(0,q.jsx)(At,{...e,ref:t}):null},`ScrollAreaCorner`)),At=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,...r}=e,i=X(Ot,n),[a,o]=K.useState(0),[s,c]=K.useState(0),l=!!(a&&s),{onCornerWidthChange:u,onCornerHeightChange:d}=i;return Q(i.scrollbarX,()=>{let e=i.scrollbarX?.offsetHeight||0;i.onCornerHeightChange(e),c(e)}),Q(i.scrollbarY,()=>{let e=i.scrollbarY?.offsetWidth||0;i.onCornerWidthChange(e),o(e)}),K.useEffect(()=>()=>{u(0),d(0)},[u,d]),l?(0,q.jsx)(D.div,{...r,ref:t,style:{width:a,height:s,position:`absolute`,right:i.dir===`ltr`?0:void 0,left:i.dir===`rtl`?0:void 0,bottom:0,...e.style}}):null},`ScrollAreaCornerImpl`));function jt(e){return e?parseInt(e,10):0}J(jt,`toInt`);function Mt(e,t){let n=e/t;return isNaN(n)?0:n}J(Mt,`getThumbRatio`);function Nt(e){let t=Mt(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}J(Nt,`getThumbSize`);function Pt(e,t,n,r=`ltr`){let i=Nt(n),a=i/2,o=t||a,s=i-o,c=n.scrollbar.paddingStart+o,l=n.scrollbar.size-n.scrollbar.paddingEnd-s,u=n.content-n.viewport,d=r===`ltr`?[0,u]:[u*-1,0];return It([c,l],d)(e)}J(Pt,`getScrollPositionFromPointer`);function Ft(e,t,n=`ltr`){let r=Nt(t),i=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,a=t.scrollbar.size-i,o=t.content-t.viewport,s=a-r,c=n===`ltr`?[0,o]:[o*-1,0],l=F(e,c);return It([0,o],[0,s])(l)}J(Ft,`getThumbOffsetFromScroll`);function It(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];let r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}J(It,`linearScale`);function Lt(e,t){return e>0&&e<t}J(Lt,`isScrollingWithinScrollbarBounds`);var Rt=J((e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return J((function i(){let a={left:e.scrollLeft,top:e.scrollTop},o=n.left!==a.left,s=n.top!==a.top;(o||s)&&t(),n=a,r=window.requestAnimationFrame(i)}),`loop`)(),()=>window.cancelAnimationFrame(r)},`addUnlinkedScrollListener`);function zt(e,t){let n=k(e),r=K.useRef(0);return K.useEffect(()=>()=>window.clearTimeout(r.current),[]),K.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}J(zt,`useDebounceCallback`);function Q(e,t){let n=k(t);E(()=>{let t=0;if(e){let r=new ResizeObserver(()=>{cancelAnimationFrame(t),t=window.requestAnimationFrame(n)});return r.observe(e),()=>{window.cancelAnimationFrame(t),r.unobserve(e)}}},[e,n])}J(Q,`useResizeObserver`);var Bt=dt,Vt=pt,Ht=kt,Ut=te(`notebook-text`,[[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`path`,{d:`M9.5 8h5`,key:`11mslq`}],[`path`,{d:`M9.5 12H16`,key:`ktog6x`}],[`path`,{d:`M9.5 16H14`,key:`p1seyn`}]]),Wt=te(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),$=_(),Gt=({chatState:e,chatId:t,messages:n})=>{if(!t)return b.warn(`No active chat`),e;let r=e.chats.get(t);if(!r)return b.warn(`No active chat`),e;let i=new Map(e.chats),a=Date.now();return i.set(r.id,{...r,messages:n,updatedAt:a}),{...e,chats:i}},Kt=class extends W{onChunkReceived;constructor(e,t){super(e),this.onChunkReceived=t}processResponseStream(e){let t=this.onChunkReceived;return super.processResponseStream(e).pipeThrough(new TransformStream({async transform(e,n){t(e),n.enqueue(e)}}))}},qt=K.forwardRef((e,t)=>{let n=(0,$.c)(15),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:i,children:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===i?o=n[5]:(o=C(`relative overflow-hidden`,i),n[4]=i,n[5]=o);let s;n[6]===r?s=n[7]:(s=(0,q.jsx)(Vt,{className:`h-full w-full rounded-[inherit]`,children:r}),n[6]=r,n[7]=s);let c,l;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,q.jsx)(Jt,{}),l=(0,q.jsx)(Ht,{}),n[8]=c,n[9]=l):(c=n[8],l=n[9]);let u;return n[10]!==a||n[11]!==t||n[12]!==o||n[13]!==s?(u=(0,q.jsxs)(Bt,{ref:t,className:o,...a,children:[s,c,l]}),n[10]=a,n[11]=t,n[12]=o,n[13]=s,n[14]=u):u=n[14],u});qt.displayName=Bt.displayName;var Jt=K.forwardRef((e,t)=>{let n=(0,$.c)(14),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,orientation:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=a===void 0?`vertical`:a,s=o===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-px`,c=o===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-px`,l;n[4]!==r||n[5]!==s||n[6]!==c?(l=C(`flex touch-none select-none transition-colors`,s,c,r),n[4]=r,n[5]=s,n[6]=c,n[7]=l):l=n[7];let u;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,q.jsx)(Et,{className:`relative flex-1 rounded-full bg-border`}),n[8]=u):u=n[8];let d;return n[9]!==o||n[10]!==i||n[11]!==t||n[12]!==l?(d=(0,q.jsx)(ht,{ref:t,orientation:o,className:l,...i,children:u}),n[9]=o,n[10]=i,n[11]=t,n[12]=l,n[13]=d):d=n[13],d});Jt.displayName=ht.displayName;var Yt=[{label:`Today`,days:0},{label:`Yesterday`,days:1},{label:`2d ago`,days:2},{label:`3d ago`,days:3},{label:`This week`,days:7},{label:`This month`,days:30}],Xt=e=>{let t=Date.now(),n=Yt.map(e=>({...e,chats:[]})),r={label:`Older`,days:1/0,chats:[]},i=e=>{switch(e){case 0:return n[0];case 1:return n[1];case 2:return n[2];case 3:return n[3];default:return e>=4&&e<=7?n[4]:e>=8&&e<=30?n[5]:r}};for(let n of e)i(Math.floor((t-n.updatedAt)/864e5)).chats.push(n);return[...n,r].filter(e=>e.chats.length>0)},Zt=50,Qt=e=>{let t=(0,$.c)(45),{activeChatId:n,setActiveChat:i,onDeleteChats:a,isLoading:o}=e,s=r($e),{locale:c}=Ze(),[u,p]=(0,K.useState)(``),h=(0,K.useRef)(null),[g,_]=(0,K.useState)(!1),{openConfirm:v,closeModal:y}=Be(),b;t[0]!==y||t[1]!==a||t[2]!==v?(b=()=>{_(!1),v({title:`Delete all chats?`,description:`This will permanently delete all chat history for all notebooks on this site in this browser. This cannot be undone.`,variant:`destructive`,confirmAction:(0,q.jsx)(M,{onClick:()=>{a(null),y()},children:`Delete all chats`})})},t[0]=y,t[1]=a,t[2]=v,t[3]=b):b=t[3];let x=b,S;t[4]===s.chats?S=t[5]:(S=[...s.chats.values()].toSorted($t),t[4]=s.chats,t[5]=S);let w=S,T;bb0:{if(!u.trim()){T=w;break bb0}let e;if(t[6]!==w||t[7]!==u){let n;t[9]===u?n=t[10]:(n=e=>e.title.toLowerCase().includes(u.toLowerCase()),t[9]=u,t[10]=n),e=w.filter(n),t[6]=w,t[7]=u,t[8]=e}else e=t[8];T=e}let E=T,D;t[11]===E?D=t[12]:(D=Xt(E),t[11]=E,t[12]=D);let O=D,k;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,q.jsx)(V,{content:`Previous chats`,children:(0,q.jsx)(f,{asChild:!0,children:(0,q.jsx)(H,{variant:`text`,size:`icon`,"aria-label":`Previous chats`,children:(0,q.jsx)(l,{className:`h-4 w-4`})})})}),t[13]=k):k=t[13];let A;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(A=e=>p(e.target.value),t[14]=A):A=t[14];let j;t[15]===u?j=t[16]:(j=(0,q.jsx)(`div`,{className:`pt-3 px-3 w-full`,children:(0,q.jsx)(We,{ref:h,placeholder:`Search chat history...`,value:u,onChange:A,className:`text-xs`})}),t[15]=u,t[16]=j);let N;t[17]===w.length?N=t[18]:(N=w.length===0&&(0,q.jsx)(it,{title:`No chats yet`,description:`Start a new chat to get started`,icon:(0,q.jsx)(U,{})}),t[17]=w.length,t[18]=N);let P;t[19]!==w.length||t[20]!==E.length||t[21]!==u?(P=E.length===0&&u&&w.length>0&&(0,q.jsx)(it,{title:`No chats found`,description:`No chats match "${u}"`,icon:(0,q.jsx)(Ge,{})}),t[19]=w.length,t[20]=E.length,t[21]=u,t[22]=P):P=t[22];let F;t[23]!==n||t[24]!==O||t[25]!==o||t[26]!==c||t[27]!==a||t[28]!==i?(F=O.map((e,t)=>(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`div`,{className:`text-xs px-1 text-muted-foreground/60`,children:e.label}),(0,q.jsx)(`div`,{children:e.chats.map(e=>(0,q.jsxs)(`div`,{className:C(`w-full rounded-md flex items-center justify-between`,e.id===n&&`bg-accent`,e.id!==n&&`hover:bg-muted/20`),children:[(0,q.jsxs)(`button`,{className:`flex flex-1 min-w-0 items-center justify-between p-1 text-left cursor-pointer`,onClick:()=>i(e.id),type:`button`,children:[(0,q.jsx)(`span`,{className:`text-sm truncate`,children:e.title}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground/60 ml-2 shrink-0`,children:Qe(e.updatedAt,c)})]}),(0,q.jsx)(V,{content:o&&e.id===n?`Stop the response before deleting this chat`:`Delete chat`,children:(0,q.jsx)(H,{variant:`text`,size:`icon`,className:`text-muted-foreground/90 hover:text-destructive transition-colors ml-px`,"aria-label":`Delete chat: ${e.title}`,disabled:o&&e.id===n,onClick:()=>{h.current?.focus(),a(e.id)},children:(0,q.jsx)(qe,{className:`h-3.5 w-3.5`})})})]},e.id))}),t!==O.length-1&&(0,q.jsx)(`hr`,{})]},e.label)),t[23]=n,t[24]=O,t[25]=o,t[26]=c,t[27]=a,t[28]=i,t[29]=F):F=t[29];let I;t[30]!==F||t[31]!==N||t[32]!==P?(I=(0,q.jsx)(qt,{className:`h-[450px] p-2`,children:(0,q.jsxs)(`div`,{className:`space-y-3`,children:[N,P,F]})}),t[30]=F,t[31]=N,t[32]=P,t[33]=I):I=t[33];let L;t[34]!==w.length||t[35]!==x||t[36]!==o?(L=w.length>0&&(0,q.jsxs)(`div`,{className:`border-t p-2 flex items-center justify-between gap-2`,children:[w.length>Zt?(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`You have over `,(0,q.jsx)(`b`,{children:Zt}),` chats. Delete old chats to free up browser storage.`]}):(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Chats are shared across notebooks.`}),(0,q.jsx)(H,{variant:`linkDestructive`,size:`xs`,disabled:o,onClick:x,children:`Delete all chats`})]}),t[34]=w.length,t[35]=x,t[36]=o,t[37]=L):L=t[37];let R;t[38]!==I||t[39]!==L||t[40]!==j?(R=(0,q.jsxs)(m,{className:`w-[480px] p-0`,align:`start`,side:`right`,children:[j,I,L]}),t[38]=I,t[39]=L,t[40]=j,t[41]=R):R=t[41];let z;return t[42]!==g||t[43]!==R?(z=(0,q.jsxs)(d,{open:g,onOpenChange:_,children:[k,R]}),t[42]=g,t[43]=R,t[44]=z):z=t[44],z};function $t(e,t){return t.updatedAt-e.updatedAt}var en=()=>{let e=(0,$.c)(17),[n,r]=t(tt),i=n.webSearch,a=i?`Capabilities (web search enabled)`:`Capabilities`,o=i||void 0,s=i&&`bg-primary/15 text-primary ring-1 ring-primary/30 opacity-100 hover:bg-primary/20`,c;e[0]===s?c=e[1]:(c=C(`h-6 w-6 shrink-0 bg-muted hover:bg-muted/30`,s),e[0]=s,e[1]=c);let l;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,q.jsx)(Wt,{className:`h-3.5 w-3.5`}),e[2]=l):l=e[2];let u;e[3]!==a||e[4]!==o||e[5]!==c?(u=(0,q.jsx)(f,{asChild:!0,children:(0,q.jsx)(H,{"aria-label":`Capabilities`,title:a,"data-active":o,variant:`text`,size:`icon`,className:c,children:l})}),e[3]=a,e[4]=o,e[5]=c,e[6]=u):u=e[6];let p;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,q.jsx)(`span`,{className:`text-sm font-semibold`,children:`Web search`}),e[7]=p):p=e[7];let h;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,q.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[p,(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Search the web when the model supports it.`,` `,(0,q.jsx)(Ve,{href:`https://docs.marimo.io/guides/editor_features/tools#web-search-and-fetch`,children:`Learn more`})]})]}),e[8]=h):h=e[8];let g;e[9]===r?g=e[10]:(g=e=>r(t=>({...t,webSearch:e})),e[9]=r,e[10]=g);let _;e[11]!==g||e[12]!==i?(_=(0,q.jsx)(m,{className:`w-76 p-3`,align:`start`,side:`top`,children:(0,q.jsxs)(`label`,{htmlFor:`web-search-toggle`,className:`flex items-start justify-between gap-3 cursor-pointer`,children:[h,(0,q.jsx)(B,{id:`web-search-toggle`,"aria-label":`Web search`,size:`sm`,checked:i,onCheckedChange:g})]})}),e[11]=g,e[12]=i,e[13]=_):_=e[13];let v;return e[14]!==u||e[15]!==_?(v=(0,q.jsxs)(d,{children:[u,_]}),e[14]=u,e[15]=_,e[16]=v):v=e[16],v};function tn(){return Xe()}function nn(e){let t=(0,$.c)(4),[n,r]=(0,K.useState)(tn),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>r(tn()),t[0]=a):a=t[0];let o=i(a),s=e??n,c;return t[1]!==o||t[2]!==s?(c={chatControllerId:s,renewDraftChatId:o},t[1]=o,t[2]=s,t[3]=c):c=t[3],c}var rn=`manual`,an=(0,K.memo)(e=>{let t=(0,$.c)(18),{message:n}=e,r;t[0]===n.parts?r=t[1]:(r=n.parts.filter(pn).map(mn).join(`
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,l as r,t as i,u as a}from"./useEvent-Dfcbgjhg.js";import{t as o}from"./react-DVplv7_D.js";import{D as s,Zn as c,ao as l,br as u,cn as d,dn as f,qa as p,un as m}from"./cells-CN1I_0eH.js";import{P as h,o as g}from"./config-MaHeMC9o.js";import{t as _}from"./compiler-runtime-BrajqUja.js";import{i as v,t as y}from"./config-CA1V-wjh.js";import{g as b,o as x}from"./useEventListener-D9cftcHj.js";import{t as S}from"./config-DEzFV5-l.js";import{t as C}from"./cn-ldLVeaqm.js";import{t as w}from"./jsx-runtime-B74pBk57.js";import{C as T,S as E,T as D,b as O,v as k,w as A}from"./fullscreen-B9tHcfpV.js";import{u as j}from"./menu-items-BrwnTgyK.js";import{o as M}from"./alert-dialog-BaPGzeOK.js";import{a as N,i as P,m as F,n as I,r as L,s as R,t as z}from"./select-DTBn5eTb.js";import{t as B}from"./switch-CTaiAjrz.js";import{i as ee,t as V}from"./tooltip-C9TuY18o.js";import{t as H}from"./button-COI-NGrx.js";import{t as te}from"./createLucideIcon-DfJ2oMlA.js";import{t as ne}from"./arrow-right-Cgit4Nk2.js";import{t as U}from"./bot-message-square-8xmbrehG.js";import{M as re,c as ie,h as ae,m as oe,p as se,r as ce,t as le}from"./ai-model-dropdown-D5Fe5GS-.js";import{i as ue,n as de,r as fe,t as pe}from"./chat-display-D1_UV6v7.js";import{B as W,C as me,D as he,E as ge,N as _e,R as ve,S as ye,U as be,_ as xe,b as Se,c as Ce,d as we,f as Te,g as Ee,h as De,k as Oe,l as ke,m as Ae,n as je,u as Me,v as Ne,w as Pe,x as Fe,y as Ie,z as Le}from"./add-cell-with-ai-C4pN_ho7.js";import{t as Re}from"./code-BEiQP4pS.js";import{t as ze}from"./hat-glasses-C8RhSVii.js";import{b as Be,p as Ve}from"./write-secret-modal-DzKAInL2.js";import{n as He}from"./spinner-DyNE-o8o.js";import{t as G}from"./message-circle-C3rKm8_a.js";import{t as Ue}from"./plus-C5silF6g.js";import{r as We,rn as Ge}from"./input-BoBxR50a.js";import{t as Ke}from"./settings-BpdQZRgT.js";import{t as qe}from"./trash-2-DcgaW8fn.js";import{t as Je}from"./copy-icon-BIiRXh_3.js";import{r as Ye}from"./requests-lt0JK8Jt.js";import{t as Xe}from"./uuid-k9DpjH68.js";import{t as Ze}from"./I18nProvider-Cg2I_s1_.js";import{l as Qe}from"./dates-CfmdTL6B.js";import{i as $e,o as et,r as tt,t as nt}from"./state-CHojzKpZ.js";import{n as rt}from"./error-banner-COZ7SfYV.js";import{t as it}from"./empty-state-BaCKb7o3.js";import{t as at}from"./scroll-to-bottom-button-1FyowpWV.js";var K=e(o(),1),q=w(),ot=Object.defineProperty,J=(e,t)=>ot(e,`name`,{value:t,configurable:!0});function st(e,t){return K.useReducer((e,n)=>t[e][n]??e,e)}J(st,`useStateMachine`);var ct=`ScrollArea`,[lt,ut]=A(ct),[Y,X]=lt(ct),dt=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,type:r=`hover`,dir:i,scrollHideDelay:a=600,...o}=e,[s,c]=K.useState(null),[l,u]=K.useState(null),[d,f]=K.useState(null),[p,m]=K.useState(null),[h,g]=K.useState(null),[_,v]=K.useState(0),[y,b]=K.useState(0),[S,C]=K.useState(!1),[w,T]=K.useState(!1),E=x(t,c),O=j(i);return(0,q.jsx)(Y,{scope:n,type:r,dir:O,scrollHideDelay:a,scrollArea:s,viewport:l,onViewportChange:u,content:d,onContentChange:f,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:S,onScrollbarXEnabledChange:C,scrollbarY:h,onScrollbarYChange:g,scrollbarYEnabled:w,onScrollbarYEnabledChange:T,onCornerWidthChange:v,onCornerHeightChange:b,children:(0,q.jsx)(D.div,{dir:O,...o,ref:E,style:{position:`relative`,"--radix-scroll-area-corner-width":_+`px`,"--radix-scroll-area-corner-height":y+`px`,...e.style}})})},`ScrollArea`)),ft=`ScrollAreaViewport`,pt=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,children:r,nonce:i,...a}=e,o=X(ft,n),s=K.useRef(null),c=x(t,s,o.onViewportChange);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(mt,{nonce:i}),(0,q.jsx)(D.div,{"data-radix-scroll-area-viewport":``,...a,ref:c,style:{overflowX:o.scrollbarXEnabled?`scroll`:`hidden`,overflowY:o.scrollbarYEnabled?`scroll`:`hidden`,...e.style},children:(0,q.jsx)(`div`,{ref:o.onContentChange,style:{minWidth:`100%`,display:`table`},children:r})})]})},`ScrollAreaViewport`)),mt=K.memo(J(function({nonce:e}){return(0,q.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}`},nonce:e})},`ScrollAreaViewportStyle`),(e,t)=>e.nonce===t.nonce),Z=`ScrollAreaScrollbar`,ht=K.forwardRef(J(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),{onScrollbarXEnabledChange:a,onScrollbarYEnabledChange:o}=i,s=e.orientation===`horizontal`;return K.useEffect(()=>(s?a(!0):o(!0),()=>{s?a(!1):o(!1)}),[s,a,o]),i.type===`hover`?(0,q.jsx)(gt,{...r,ref:t,forceMount:n}):i.type===`scroll`?(0,q.jsx)(_t,{...r,ref:t,forceMount:n}):i.type===`auto`?(0,q.jsx)(vt,{...r,ref:t,forceMount:n}):i.type===`always`?(0,q.jsx)(yt,{...r,ref:t,"data-state":`visible`}):null},`ScrollAreaScrollbar`)),gt=K.forwardRef(J(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),[a,o]=K.useState(!1);return K.useEffect(()=>{let e=i.scrollArea,t=0;if(e){let n=J(()=>{window.clearTimeout(t),o(!0)},`handlePointerEnter`),r=J(()=>{t=window.setTimeout(()=>o(!1),i.scrollHideDelay)},`handlePointerLeave`);return e.addEventListener(`pointerenter`,n),e.addEventListener(`pointerleave`,r),()=>{window.clearTimeout(t),e.removeEventListener(`pointerenter`,n),e.removeEventListener(`pointerleave`,r)}}},[i.scrollArea,i.scrollHideDelay]),(0,q.jsx)(O,{present:n||a,children:(0,q.jsx)(vt,{"data-state":a?`visible`:`hidden`,...r,ref:t})})},`ScrollAreaScrollbarHover`)),_t=K.forwardRef(J(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),a=e.orientation===`horizontal`,o=zt(()=>c(`SCROLL_END`),100),[s,c]=st(`hidden`,{hidden:{SCROLL:`scrolling`},scrolling:{SCROLL_END:`idle`,POINTER_ENTER:`interacting`},interacting:{SCROLL:`interacting`,POINTER_LEAVE:`idle`},idle:{HIDE:`hidden`,SCROLL:`scrolling`,POINTER_ENTER:`interacting`}});return K.useEffect(()=>{if(s===`idle`){let e=window.setTimeout(()=>c(`HIDE`),i.scrollHideDelay);return()=>window.clearTimeout(e)}},[s,i.scrollHideDelay,c]),K.useEffect(()=>{let e=i.viewport,t=a?`scrollLeft`:`scrollTop`;if(e){let n=e[t],r=J(()=>{let r=e[t];n!==r&&(c(`SCROLL`),o()),n=r},`handleScroll`);return e.addEventListener(`scroll`,r),()=>e.removeEventListener(`scroll`,r)}},[i.viewport,a,c,o]),(0,q.jsx)(O,{present:n||s!==`hidden`,children:(0,q.jsx)(yt,{"data-state":s===`hidden`?`hidden`:`visible`,...r,ref:t,onPointerEnter:T(e.onPointerEnter,()=>c(`POINTER_ENTER`)),onPointerLeave:T(e.onPointerLeave,()=>c(`POINTER_LEAVE`))})})},`ScrollAreaScrollbarScroll`)),vt=K.forwardRef(J(function(e,t){let n=X(Z,e.__scopeScrollArea),{forceMount:r,...i}=e,[a,o]=K.useState(!1),s=e.orientation===`horizontal`,c=zt(()=>{if(n.viewport){let e=n.viewport.offsetWidth<n.viewport.scrollWidth,t=n.viewport.offsetHeight<n.viewport.scrollHeight;o(s?e:t)}},10);return Q(n.viewport,c),Q(n.content,c),(0,q.jsx)(O,{present:r||a,children:(0,q.jsx)(yt,{"data-state":a?`visible`:`hidden`,...i,ref:t})})},`ScrollAreaScrollbarAuto`)),yt=K.forwardRef(J(function(e,t){let{orientation:n=`vertical`,...r}=e,i=X(Z,e.__scopeScrollArea),a=K.useRef(null),o=K.useRef(0),[s,c]=K.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),l=Mt(s.viewport,s.content),u={...r,sizes:s,onSizesChange:c,hasThumb:l>0&&l<1,onThumbChange:J(e=>a.current=e,`onThumbChange`),onThumbPointerUp:J(()=>o.current=0,`onThumbPointerUp`),onThumbPointerDown:J(e=>o.current=e,`onThumbPointerDown`)};function d(e,t){return Pt(e,o.current,s,t)}return J(d,`getScrollPosition`),n===`horizontal`?(0,q.jsx)(bt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollLeft,t=Ft(e,s,i.dir);a.current.style.transform=`translate3d(${t}px, 0, 0)`}},onWheelScroll:e=>{i.viewport&&(i.viewport.scrollLeft=e)},onDragScroll:e=>{i.viewport&&(i.viewport.scrollLeft=d(e,i.dir))}}):n===`vertical`?(0,q.jsx)(xt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollTop,t=Ft(e,s);a.current.style.transform=`translate3d(0, ${t}px, 0)`}},onWheelScroll:e=>{i.viewport&&(i.viewport.scrollTop=e)},onDragScroll:e=>{i.viewport&&(i.viewport.scrollTop=d(e))}}):null},`ScrollAreaScrollbarVisible`)),bt=K.forwardRef(J(function(e,t){let{sizes:n,onSizesChange:r,...i}=e,a=X(Z,e.__scopeScrollArea),[o,s]=K.useState(),c=K.useRef(null),l=x(t,c,a.onScrollbarXChange);return K.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,q.jsx)(wt,{"data-orientation":`horizontal`,...i,ref:l,sizes:n,style:{bottom:0,left:a.dir===`rtl`?`var(--radix-scroll-area-corner-width)`:0,right:a.dir===`ltr`?`var(--radix-scroll-area-corner-width)`:0,"--radix-scroll-area-thumb-width":Nt(n)+`px`,...e.style},onThumbPointerDown:t=>e.onThumbPointerDown(t.x),onDragScroll:t=>e.onDragScroll(t.x),onWheelScroll:(t,n)=>{if(a.viewport){let r=a.viewport.scrollLeft+t.deltaX;e.onWheelScroll(r),Lt(r,n)&&t.preventDefault()}},onResize:()=>{c.current&&a.viewport&&o&&r({content:a.viewport.scrollWidth,viewport:a.viewport.offsetWidth,scrollbar:{size:c.current.clientWidth,paddingStart:jt(o.paddingLeft),paddingEnd:jt(o.paddingRight)}})}})},`ScrollAreaScrollbarX`)),xt=K.forwardRef(J(function(e,t){let{sizes:n,onSizesChange:r,...i}=e,a=X(Z,e.__scopeScrollArea),[o,s]=K.useState(),c=K.useRef(null),l=x(t,c,a.onScrollbarYChange);return K.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,q.jsx)(wt,{"data-orientation":`vertical`,...i,ref:l,sizes:n,style:{top:0,right:a.dir===`ltr`?0:void 0,left:a.dir===`rtl`?0:void 0,bottom:`var(--radix-scroll-area-corner-height)`,"--radix-scroll-area-thumb-height":Nt(n)+`px`,...e.style},onThumbPointerDown:t=>e.onThumbPointerDown(t.y),onDragScroll:t=>e.onDragScroll(t.y),onWheelScroll:(t,n)=>{if(a.viewport){let r=a.viewport.scrollTop+t.deltaY;e.onWheelScroll(r),Lt(r,n)&&t.preventDefault()}},onResize:()=>{c.current&&a.viewport&&o&&r({content:a.viewport.scrollHeight,viewport:a.viewport.offsetHeight,scrollbar:{size:c.current.clientHeight,paddingStart:jt(o.paddingTop),paddingEnd:jt(o.paddingBottom)}})}})},`ScrollAreaScrollbarY`)),[St,Ct]=lt(Z),wt=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,sizes:r,hasThumb:i,onThumbChange:a,onThumbPointerUp:o,onThumbPointerDown:s,onThumbPositionChange:c,onDragScroll:l,onWheelScroll:u,onResize:d,...f}=e,p=X(Z,n),[m,h]=K.useState(null),g=x(t,h),_=K.useRef(null),v=K.useRef(``),y=p.viewport,b=r.content-r.viewport,S=k(u),C=k(c),w=zt(d,10);function E(e){if(_.current){let t=e.clientX-_.current.left,n=e.clientY-_.current.top;l({x:t,y:n})}}return J(E,`handleDragScroll`),K.useEffect(()=>{let e=J(e=>{let t=e.target;m?.contains(t)&&S(e,b)},`handleWheel`);return document.addEventListener(`wheel`,e,{passive:!1}),()=>document.removeEventListener(`wheel`,e,{passive:!1})},[y,m,b,S]),K.useEffect(C,[r,C]),Q(m,w),Q(p.content,w),(0,q.jsx)(St,{scope:n,scrollbar:m,hasThumb:i,onThumbChange:k(a),onThumbPointerUp:k(o),onThumbPositionChange:C,onThumbPointerDown:k(s),children:(0,q.jsx)(D.div,{...f,ref:g,style:{position:`absolute`,...f.style},onPointerDown:T(e.onPointerDown,e=>{e.button===0&&(e.target.setPointerCapture(e.pointerId),_.current=m.getBoundingClientRect(),v.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect=`none`,p.viewport&&(p.viewport.style.scrollBehavior=`auto`),E(e))}),onPointerMove:T(e.onPointerMove,E),onPointerUp:T(e.onPointerUp,e=>{let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),document.body.style.webkitUserSelect=v.current,p.viewport&&(p.viewport.style.scrollBehavior=``),_.current=null})})})},`ScrollAreaScrollbarImpl`)),Tt=`ScrollAreaThumb`,Et=K.forwardRef(J(function(e,t){let{forceMount:n,...r}=e,i=Ct(Tt,e.__scopeScrollArea);return(0,q.jsx)(O,{present:n||i.hasThumb,children:(0,q.jsx)(Dt,{ref:t,...r})})},`ScrollAreaThumb`)),Dt=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,style:r,...i}=e,a=X(Tt,n),o=Ct(Tt,n),{onThumbPositionChange:s}=o,c=x(t,o.onThumbChange),l=K.useRef(void 0),u=zt(()=>{l.current&&=(l.current(),void 0)},100);return K.useEffect(()=>{let e=a.viewport;if(e){let t=J(()=>{if(u(),!l.current){let t=Rt(e,s);l.current=t,s()}},`handleScroll`);return s(),e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)}},[a.viewport,u,s]),(0,q.jsx)(D.div,{"data-state":o.hasThumb?`visible`:`hidden`,...i,ref:c,style:{width:`var(--radix-scroll-area-thumb-width)`,height:`var(--radix-scroll-area-thumb-height)`,...r},onPointerDownCapture:T(e.onPointerDownCapture,e=>{let t=e.target.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top;o.onThumbPointerDown({x:n,y:r})}),onPointerUp:T(e.onPointerUp,o.onThumbPointerUp)})},`ScrollAreaThumbImpl`)),Ot=`ScrollAreaCorner`,kt=K.forwardRef(J(function(e,t){let n=X(Ot,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!==`scroll`&&r?(0,q.jsx)(At,{...e,ref:t}):null},`ScrollAreaCorner`)),At=K.forwardRef(J(function(e,t){let{__scopeScrollArea:n,...r}=e,i=X(Ot,n),[a,o]=K.useState(0),[s,c]=K.useState(0),l=!!(a&&s),{onCornerWidthChange:u,onCornerHeightChange:d}=i;return Q(i.scrollbarX,()=>{let e=i.scrollbarX?.offsetHeight||0;i.onCornerHeightChange(e),c(e)}),Q(i.scrollbarY,()=>{let e=i.scrollbarY?.offsetWidth||0;i.onCornerWidthChange(e),o(e)}),K.useEffect(()=>()=>{u(0),d(0)},[u,d]),l?(0,q.jsx)(D.div,{...r,ref:t,style:{width:a,height:s,position:`absolute`,right:i.dir===`ltr`?0:void 0,left:i.dir===`rtl`?0:void 0,bottom:0,...e.style}}):null},`ScrollAreaCornerImpl`));function jt(e){return e?parseInt(e,10):0}J(jt,`toInt`);function Mt(e,t){let n=e/t;return isNaN(n)?0:n}J(Mt,`getThumbRatio`);function Nt(e){let t=Mt(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}J(Nt,`getThumbSize`);function Pt(e,t,n,r=`ltr`){let i=Nt(n),a=i/2,o=t||a,s=i-o,c=n.scrollbar.paddingStart+o,l=n.scrollbar.size-n.scrollbar.paddingEnd-s,u=n.content-n.viewport,d=r===`ltr`?[0,u]:[u*-1,0];return It([c,l],d)(e)}J(Pt,`getScrollPositionFromPointer`);function Ft(e,t,n=`ltr`){let r=Nt(t),i=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,a=t.scrollbar.size-i,o=t.content-t.viewport,s=a-r,c=n===`ltr`?[0,o]:[o*-1,0],l=F(e,c);return It([0,o],[0,s])(l)}J(Ft,`getThumbOffsetFromScroll`);function It(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];let r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}J(It,`linearScale`);function Lt(e,t){return e>0&&e<t}J(Lt,`isScrollingWithinScrollbarBounds`);var Rt=J((e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return J((function i(){let a={left:e.scrollLeft,top:e.scrollTop},o=n.left!==a.left,s=n.top!==a.top;(o||s)&&t(),n=a,r=window.requestAnimationFrame(i)}),`loop`)(),()=>window.cancelAnimationFrame(r)},`addUnlinkedScrollListener`);function zt(e,t){let n=k(e),r=K.useRef(0);return K.useEffect(()=>()=>window.clearTimeout(r.current),[]),K.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}J(zt,`useDebounceCallback`);function Q(e,t){let n=k(t);E(()=>{let t=0;if(e){let r=new ResizeObserver(()=>{cancelAnimationFrame(t),t=window.requestAnimationFrame(n)});return r.observe(e),()=>{window.cancelAnimationFrame(t),r.unobserve(e)}}},[e,n])}J(Q,`useResizeObserver`);var Bt=dt,Vt=pt,Ht=kt,Ut=te(`notebook-text`,[[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`path`,{d:`M9.5 8h5`,key:`11mslq`}],[`path`,{d:`M9.5 12H16`,key:`ktog6x`}],[`path`,{d:`M9.5 16H14`,key:`p1seyn`}]]),Wt=te(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),$=_(),Gt=({chatState:e,chatId:t,messages:n})=>{if(!t)return b.warn(`No active chat`),e;let r=e.chats.get(t);if(!r)return b.warn(`No active chat`),e;let i=new Map(e.chats),a=Date.now();return i.set(r.id,{...r,messages:n,updatedAt:a}),{...e,chats:i}},Kt=class extends W{onChunkReceived;constructor(e,t){super(e),this.onChunkReceived=t}processResponseStream(e){let t=this.onChunkReceived;return super.processResponseStream(e).pipeThrough(new TransformStream({async transform(e,n){t(e),n.enqueue(e)}}))}},qt=K.forwardRef((e,t)=>{let n=(0,$.c)(15),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:i,children:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===i?o=n[5]:(o=C(`relative overflow-hidden`,i),n[4]=i,n[5]=o);let s;n[6]===r?s=n[7]:(s=(0,q.jsx)(Vt,{className:`h-full w-full rounded-[inherit]`,children:r}),n[6]=r,n[7]=s);let c,l;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,q.jsx)(Jt,{}),l=(0,q.jsx)(Ht,{}),n[8]=c,n[9]=l):(c=n[8],l=n[9]);let u;return n[10]!==a||n[11]!==t||n[12]!==o||n[13]!==s?(u=(0,q.jsxs)(Bt,{ref:t,className:o,...a,children:[s,c,l]}),n[10]=a,n[11]=t,n[12]=o,n[13]=s,n[14]=u):u=n[14],u});qt.displayName=Bt.displayName;var Jt=K.forwardRef((e,t)=>{let n=(0,$.c)(14),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,orientation:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=a===void 0?`vertical`:a,s=o===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-px`,c=o===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-px`,l;n[4]!==r||n[5]!==s||n[6]!==c?(l=C(`flex touch-none select-none transition-colors`,s,c,r),n[4]=r,n[5]=s,n[6]=c,n[7]=l):l=n[7];let u;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,q.jsx)(Et,{className:`relative flex-1 rounded-full bg-border`}),n[8]=u):u=n[8];let d;return n[9]!==o||n[10]!==i||n[11]!==t||n[12]!==l?(d=(0,q.jsx)(ht,{ref:t,orientation:o,className:l,...i,children:u}),n[9]=o,n[10]=i,n[11]=t,n[12]=l,n[13]=d):d=n[13],d});Jt.displayName=ht.displayName;var Yt=[{label:`Today`,days:0},{label:`Yesterday`,days:1},{label:`2d ago`,days:2},{label:`3d ago`,days:3},{label:`This week`,days:7},{label:`This month`,days:30}],Xt=e=>{let t=Date.now(),n=Yt.map(e=>({...e,chats:[]})),r={label:`Older`,days:1/0,chats:[]},i=e=>{switch(e){case 0:return n[0];case 1:return n[1];case 2:return n[2];case 3:return n[3];default:return e>=4&&e<=7?n[4]:e>=8&&e<=30?n[5]:r}};for(let n of e)i(Math.floor((t-n.updatedAt)/864e5)).chats.push(n);return[...n,r].filter(e=>e.chats.length>0)},Zt=50,Qt=e=>{let t=(0,$.c)(45),{activeChatId:n,setActiveChat:i,onDeleteChats:a,isLoading:o}=e,s=r($e),{locale:c}=Ze(),[u,p]=(0,K.useState)(``),h=(0,K.useRef)(null),[g,_]=(0,K.useState)(!1),{openConfirm:v,closeModal:y}=Be(),b;t[0]!==y||t[1]!==a||t[2]!==v?(b=()=>{_(!1),v({title:`Delete all chats?`,description:`This will permanently delete all chat history for all notebooks on this site in this browser. This cannot be undone.`,variant:`destructive`,confirmAction:(0,q.jsx)(M,{onClick:()=>{a(null),y()},children:`Delete all chats`})})},t[0]=y,t[1]=a,t[2]=v,t[3]=b):b=t[3];let x=b,S;t[4]===s.chats?S=t[5]:(S=[...s.chats.values()].toSorted($t),t[4]=s.chats,t[5]=S);let w=S,T;bb0:{if(!u.trim()){T=w;break bb0}let e;if(t[6]!==w||t[7]!==u){let n;t[9]===u?n=t[10]:(n=e=>e.title.toLowerCase().includes(u.toLowerCase()),t[9]=u,t[10]=n),e=w.filter(n),t[6]=w,t[7]=u,t[8]=e}else e=t[8];T=e}let E=T,D;t[11]===E?D=t[12]:(D=Xt(E),t[11]=E,t[12]=D);let O=D,k;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,q.jsx)(V,{content:`Previous chats`,children:(0,q.jsx)(f,{asChild:!0,children:(0,q.jsx)(H,{variant:`text`,size:`icon`,"aria-label":`Previous chats`,children:(0,q.jsx)(l,{className:`h-4 w-4`})})})}),t[13]=k):k=t[13];let A;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(A=e=>p(e.target.value),t[14]=A):A=t[14];let j;t[15]===u?j=t[16]:(j=(0,q.jsx)(`div`,{className:`pt-3 px-3 w-full`,children:(0,q.jsx)(We,{ref:h,placeholder:`Search chat history...`,value:u,onChange:A,className:`text-xs`})}),t[15]=u,t[16]=j);let N;t[17]===w.length?N=t[18]:(N=w.length===0&&(0,q.jsx)(it,{title:`No chats yet`,description:`Start a new chat to get started`,icon:(0,q.jsx)(U,{})}),t[17]=w.length,t[18]=N);let P;t[19]!==w.length||t[20]!==E.length||t[21]!==u?(P=E.length===0&&u&&w.length>0&&(0,q.jsx)(it,{title:`No chats found`,description:`No chats match "${u}"`,icon:(0,q.jsx)(Ge,{})}),t[19]=w.length,t[20]=E.length,t[21]=u,t[22]=P):P=t[22];let F;t[23]!==n||t[24]!==O||t[25]!==o||t[26]!==c||t[27]!==a||t[28]!==i?(F=O.map((e,t)=>(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`div`,{className:`text-xs px-1 text-muted-foreground/60`,children:e.label}),(0,q.jsx)(`div`,{children:e.chats.map(e=>(0,q.jsxs)(`div`,{className:C(`w-full rounded-md flex items-center justify-between`,e.id===n&&`bg-accent`,e.id!==n&&`hover:bg-muted/20`),children:[(0,q.jsxs)(`button`,{className:`flex flex-1 min-w-0 items-center justify-between p-1 text-left cursor-pointer`,onClick:()=>i(e.id),type:`button`,children:[(0,q.jsx)(`span`,{className:`text-sm truncate`,children:e.title}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground/60 ml-2 shrink-0`,children:Qe(e.updatedAt,c)})]}),(0,q.jsx)(V,{content:o&&e.id===n?`Stop the response before deleting this chat`:`Delete chat`,children:(0,q.jsx)(H,{variant:`text`,size:`icon`,className:`text-muted-foreground/90 hover:text-destructive transition-colors ml-px`,"aria-label":`Delete chat: ${e.title}`,disabled:o&&e.id===n,onClick:()=>{h.current?.focus(),a(e.id)},children:(0,q.jsx)(qe,{className:`h-3.5 w-3.5`})})})]},e.id))}),t!==O.length-1&&(0,q.jsx)(`hr`,{})]},e.label)),t[23]=n,t[24]=O,t[25]=o,t[26]=c,t[27]=a,t[28]=i,t[29]=F):F=t[29];let I;t[30]!==F||t[31]!==N||t[32]!==P?(I=(0,q.jsx)(qt,{className:`h-[450px] p-2`,children:(0,q.jsxs)(`div`,{className:`space-y-3`,children:[N,P,F]})}),t[30]=F,t[31]=N,t[32]=P,t[33]=I):I=t[33];let L;t[34]!==w.length||t[35]!==x||t[36]!==o?(L=w.length>0&&(0,q.jsxs)(`div`,{className:`border-t p-2 flex items-center justify-between gap-2`,children:[w.length>Zt?(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`You have over `,(0,q.jsx)(`b`,{children:Zt}),` chats. Delete old chats to free up browser storage.`]}):(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Chats are shared across notebooks.`}),(0,q.jsx)(H,{variant:`linkDestructive`,size:`xs`,disabled:o,onClick:x,children:`Delete all chats`})]}),t[34]=w.length,t[35]=x,t[36]=o,t[37]=L):L=t[37];let R;t[38]!==I||t[39]!==L||t[40]!==j?(R=(0,q.jsxs)(m,{className:`w-[480px] p-0`,align:`start`,side:`right`,children:[j,I,L]}),t[38]=I,t[39]=L,t[40]=j,t[41]=R):R=t[41];let z;return t[42]!==g||t[43]!==R?(z=(0,q.jsxs)(d,{open:g,onOpenChange:_,children:[k,R]}),t[42]=g,t[43]=R,t[44]=z):z=t[44],z};function $t(e,t){return t.updatedAt-e.updatedAt}var en=()=>{let e=(0,$.c)(17),[n,r]=t(tt),i=n.webSearch,a=i?`Capabilities (web search enabled)`:`Capabilities`,o=i||void 0,s=i&&`bg-primary/15 text-primary ring-1 ring-primary/30 opacity-100 hover:bg-primary/20`,c;e[0]===s?c=e[1]:(c=C(`h-6 w-6 shrink-0 bg-muted hover:bg-muted/30`,s),e[0]=s,e[1]=c);let l;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,q.jsx)(Wt,{className:`h-3.5 w-3.5`}),e[2]=l):l=e[2];let u;e[3]!==a||e[4]!==o||e[5]!==c?(u=(0,q.jsx)(f,{asChild:!0,children:(0,q.jsx)(H,{"aria-label":`Capabilities`,title:a,"data-active":o,variant:`text`,size:`icon`,className:c,children:l})}),e[3]=a,e[4]=o,e[5]=c,e[6]=u):u=e[6];let p;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,q.jsx)(`span`,{className:`text-sm font-semibold`,children:`Web search`}),e[7]=p):p=e[7];let h;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,q.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[p,(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Search the web when the model supports it.`,` `,(0,q.jsx)(Ve,{href:`https://docs.marimo.io/guides/editor_features/tools#web-search-and-fetch`,children:`Learn more`})]})]}),e[8]=h):h=e[8];let g;e[9]===r?g=e[10]:(g=e=>r(t=>({...t,webSearch:e})),e[9]=r,e[10]=g);let _;e[11]!==g||e[12]!==i?(_=(0,q.jsx)(m,{className:`w-76 p-3`,align:`start`,side:`top`,children:(0,q.jsxs)(`label`,{htmlFor:`web-search-toggle`,className:`flex items-start justify-between gap-3 cursor-pointer`,children:[h,(0,q.jsx)(B,{id:`web-search-toggle`,"aria-label":`Web search`,size:`sm`,checked:i,onCheckedChange:g})]})}),e[11]=g,e[12]=i,e[13]=_):_=e[13];let v;return e[14]!==u||e[15]!==_?(v=(0,q.jsxs)(d,{children:[u,_]}),e[14]=u,e[15]=_,e[16]=v):v=e[16],v};function tn(){return Xe()}function nn(e){let t=(0,$.c)(4),[n,r]=(0,K.useState)(tn),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>r(tn()),t[0]=a):a=t[0];let o=i(a),s=e??n,c;return t[1]!==o||t[2]!==s?(c={chatControllerId:s,renewDraftChatId:o},t[1]=o,t[2]=s,t[3]=c):c=t[3],c}var rn=`manual`,an=(0,K.memo)(e=>{let t=(0,$.c)(18),{message:n}=e,r;t[0]===n.parts?r=t[1]:(r=n.parts.filter(pn).map(mn).join(`
2
2
  `),t[0]=n.parts,t[1]=r);let i=r,a,o,s;if(t[2]!==n.parts){let e=n.parts.filter(hn);s=`flex justify-end`,a=`w-[95%] bg-background border border-dashed p-2 rounded-sm opacity-70`,o=e.map(gn),t[2]=n.parts,t[3]=a,t[4]=o,t[5]=s}else a=t[3],o=t[4],s=t[5];let c;t[6]===i?c=t[7]:(c=(0,q.jsx)(`span`,{className:`wrap-break-word`,children:i}),t[6]=i,t[7]=c);let l;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,q.jsx)(He,{className:`h-3.5 w-3.5 shrink-0 animate-spin`}),t[8]=l):l=t[8];let u;t[9]===c?u=t[10]:(u=(0,q.jsxs)(`div`,{className:`flex items-center justify-end gap-2 text-sm text-muted-foreground`,children:[c,l]}),t[9]=c,t[10]=u);let d;t[11]!==a||t[12]!==o||t[13]!==u?(d=(0,q.jsxs)(`div`,{className:a,children:[o,u]}),t[11]=a,t[12]=o,t[13]=u,t[14]=d):d=t[14];let f;return t[15]!==s||t[16]!==d?(f=(0,q.jsx)(`div`,{className:s,children:d}),t[15]=s,t[16]=d,t[17]=f):f=t[17],f});an.displayName=`QueuedMessageDisplay`;var on=e=>{let t=(0,$.c)(21),{onNewChat:n,activeChatId:r,setActiveChat:i,onDeleteChats:a,isLoading:o}=e,{handleClick:s}=ce(),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,q.jsx)(Ue,{className:`h-4 w-4`}),t[0]=c):c=t[0];let l;t[1]===n?l=t[2]:(l=(0,q.jsx)(V,{content:`New chat`,children:(0,q.jsx)(H,{variant:`text`,size:`icon`,onClick:n,children:c})}),t[1]=n,t[2]=l);let u,d;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,q.jsx)(V,{content:`Connect your agent`,children:(0,q.jsx)(oe,{className:`mr-1`,label:`Connect`})}),d=(0,q.jsx)(ie,{}),t[3]=u,t[4]=d):(u=t[3],d=t[4]);let f;t[5]===s?f=t[6]:(f=()=>s(`ai`),t[5]=s,t[6]=f);let p;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,q.jsx)(Ke,{className:`h-4 w-4`}),t[7]=p):p=t[7];let m;t[8]===f?m=t[9]:(m=(0,q.jsx)(V,{content:`AI Settings`,children:(0,q.jsx)(H,{variant:`text`,size:`xs`,className:`hover:bg-foreground/10 py-2`,onClick:f,children:p})}),t[8]=f,t[9]=m);let h;t[10]!==r||t[11]!==o||t[12]!==a||t[13]!==i?(h=(0,q.jsx)(Qt,{activeChatId:r,setActiveChat:i,onDeleteChats:a,isLoading:o}),t[10]=r,t[11]=o,t[12]=a,t[13]=i,t[14]=h):h=t[14];let g;t[15]!==m||t[16]!==h?(g=(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u,d,m,h]}),t[15]=m,t[16]=h,t[17]=g):g=t[17];let _;return t[18]!==l||t[19]!==g?(_=(0,q.jsxs)(`div`,{className:`flex border-b px-2 py-1 justify-between shrink-0 items-center`,children:[l,g]}),t[18]=l,t[19]=g,t[20]=_):_=t[20],_},sn=(0,K.memo)(e=>{let t=(0,$.c)(17),{message:n,index:r,onEdit:i,isStreamingReasoning:a,isLast:o,isActive:s,addToolApprovalResponse:c}=e,l;t[0]!==r||t[1]!==i?(l=e=>{let t=(e.parts?.filter(_n))?.map(vn).join(`
3
3
  `),n=e.parts?.filter(yn);return(0,q.jsxs)(`div`,{className:`w-[95%] bg-background border p-1 rounded-sm`,children:[n?.map(bn),(0,q.jsx)(je,{value:t,placeholder:`Type your message...`,onChange:xn,onSubmit:(e,t)=>{t.trim()&&i(r,t)},onClose:Sn},e.id)]})},t[0]=r,t[1]=i,t[2]=l):l=t[2];let u=l,d;t[3]!==c||t[4]!==s||t[5]!==o||t[6]!==a?(d=e=>{let t=e.parts.filter(Cn).map(wn).join(`
4
4
  `);return(0,q.jsxs)(`div`,{className:`w-[95%] wrap-break-word`,children:[(0,q.jsx)(`div`,{className:`absolute right-1 top-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,q.jsx)(Je,{className:`h-3 w-3`,value:t||``})}),pe({message:e,isStreamingReasoning:a,isLast:o,isActive:s,addToolApprovalResponse:c})]})},t[3]=c,t[4]=s,t[5]=o,t[6]=a,t[7]=d):d=t[7];let f=d,p=n.role===`user`?`justify-end`:`justify-start`,m;t[8]===p?m=t[9]:(m=C(`flex group relative`,p),t[8]=p,t[9]=m);let h;t[10]!==n||t[11]!==f||t[12]!==u?(h=n.role===`user`?u(n):f(n),t[10]=n,t[11]=f,t[12]=u,t[13]=h):h=t[13];let g;return t[14]!==m||t[15]!==h?(g=(0,q.jsx)(`div`,{className:m,children:h}),t[14]=m,t[15]=h,t[16]=g):g=t[16],g});sn.displayName=`ChatMessage`;var cn=(0,K.memo)(e=>{let t=(0,$.c)(43),{isEmpty:n,onSendClick:i,isLoading:a,onStop:o,fileInputRef:s,onAddFiles:c,onAddContext:l}=e,u=r(y),d=u?.mode||rn,f=u?.models?.chat_model||`openai/gpt-4o`,p=re.parse(f).providerId,{saveModeChange:m}=S(),h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=[{value:`manual`,label:`Manual`,subtitle:`Pure chat, no tool usage`,Icon:G},{value:`ask`,label:`Ask`,subtitle:`AI with access to read-only tools like documentation search`,Icon:Ut},{value:`agent`,label:`Agent`,subtitle:`AI with access to read and write tools`,Icon:ze},{value:`code_mode`,label:`Code Mode (beta)`,subtitle:`AI with access to the notebook's kernel. Potentially destructive.`,Icon:Re}],t[0]=h):h=t[0];let g=h,_=Ae.has(p),v;t[1]!==d||t[2]!==g?(v=g.find(e=>e.value===d),t[1]=d,t[2]=g,t[3]=v):v=t[3];let b=v,x=b?.Icon,C=b?.label,w;t[4]===x?w=t[5]:(w=x&&(0,q.jsx)(x,{className:`h-3 w-3`}),t[4]=x,t[5]=w);let T;t[6]===C?T=t[7]:(T=(0,q.jsx)(`span`,{className:`text-nowrap`,children:C}),t[6]=C,t[7]=T);let E;t[8]!==w||t[9]!==T?(E=(0,q.jsxs)(R,{className:`h-6 text-xs border-border shadow-none! ring-0! bg-muted hover:bg-muted/30 py-0 px-2 gap-1.5 shrink-0`,children:[w,T]}),t[8]=w,t[9]=T,t[10]=E):E=t[10];let D;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,q.jsx)(N,{className:`text-xs uppercase tracking-wider text-muted-foreground/70 font-medium`,children:`AI Mode`}),t[11]=D):D=t[11];let O;t[12]===g?O=t[13]:(O=(0,q.jsx)(I,{children:(0,q.jsxs)(L,{children:[D,g.map(Tn)]})}),t[12]=g,t[13]=O);let k;t[14]!==d||t[15]!==m||t[16]!==E||t[17]!==O?(k=(0,q.jsxs)(z,{value:d,onValueChange:m,children:[E,O]}),t[14]=d,t[15]=m,t[16]=E,t[17]=O,t[18]=k):k=t[18];let A,j;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,q.jsx)(le,{placeholder:`Model`,triggerClassName:`h-6 text-xs shadow-none! ring-0! bg-muted hover:bg-muted/30 rounded-sm max-w-[200px]`,iconSize:`small`,showAddCustomModelDocs:!0,forRole:`chat`}),A=(0,q.jsx)(en,{}),t[19]=A,t[20]=j):(A=t[19],j=t[20]);let M;t[21]===k?M=t[22]:(M=(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[k,j,A]}),t[21]=k,t[22]=M);let P;t[23]!==a||t[24]!==l?(P=(0,q.jsx)(Ce,{handleAddContext:l,isLoading:a}),t[23]=a,t[24]=l,t[25]=P):P=t[25];let F;t[26]!==s||t[27]!==_||t[28]!==a||t[29]!==c?(F=_&&(0,q.jsx)(ke,{fileInputRef:s,isLoading:a,onAddFiles:c}),t[26]=s,t[27]=_,t[28]=a,t[29]=c,t[30]=F):F=t[30];let B;t[31]!==n||t[32]!==a||t[33]!==i||t[34]!==o?(B=(0,q.jsx)(Te,{isLoading:a,onStop:o,onSendClick:i,isEmpty:n}),t[31]=n,t[32]=a,t[33]=i,t[34]=o,t[35]=B):B=t[35];let V;t[36]!==P||t[37]!==F||t[38]!==B?(V=(0,q.jsxs)(`div`,{className:`flex flex-row ml-auto`,children:[P,F,B]}),t[36]=P,t[37]=F,t[38]=B,t[39]=V):V=t[39];let H;return t[40]!==M||t[41]!==V?(H=(0,q.jsx)(ee,{children:(0,q.jsxs)(`div`,{className:`px-3 py-2 border-t border-border/20 flex flex-wrap items-center gap-1`,children:[M,V]})}),t[40]=M,t[41]=V,t[42]=H):H=t[42],H});cn.displayName=`ChatInputFooter`;var ln=(0,K.memo)(e=>{let t=(0,$.c)(31),{placeholder:n,input:r,inputClassName:a,setInput:o,onSubmit:s,inputRef:c,isLoading:l,onStop:u,fileInputRef:d,onAddFiles:f,onClose:p}=e,m;t[0]!==r||t[1]!==s?(m=()=>{r.trim()&&s(void 0,r)},t[0]=r,t[1]=s,t[2]=m):m=t[2];let h=i(m),g;t[3]===a?g=t[4]:(g=C(`px-2 py-1.5`,a),t[3]=a,t[4]=g);let _=n||`Type your message...`,v;t[5]!==r||t[6]!==c||t[7]!==f||t[8]!==p||t[9]!==s||t[10]!==o||t[11]!==_?(v=(0,q.jsx)(je,{className:`max-h-[400px]`,inputRef:c,value:r,onChange:o,onSubmit:s,onClose:p,onAddFiles:f,placeholder:_}),t[5]=r,t[6]=c,t[7]=f,t[8]=p,t[9]=s,t[10]=o,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==g||t[14]!==v?(y=(0,q.jsx)(`div`,{className:g,children:v}),t[13]=g,t[14]=v,t[15]=y):y=t[15];let b;t[16]===r?b=t[17]:(b=r.trim(),t[16]=r,t[17]=b);let x=!b,S;t[18]===c?S=t[19]:(S=()=>Pe(c),t[18]=c,t[19]=S);let w;t[20]!==d||t[21]!==h||t[22]!==l||t[23]!==f||t[24]!==u||t[25]!==x||t[26]!==S?(w=(0,q.jsx)(cn,{isEmpty:x,onAddContext:S,onSendClick:h,isLoading:l,onStop:u,fileInputRef:d,onAddFiles:f}),t[20]=d,t[21]=h,t[22]=l,t[23]=f,t[24]=u,t[25]=x,t[26]=S,t[27]=w):w=t[27];let T;return t[28]!==y||t[29]!==w?(T=(0,q.jsxs)(`div`,{className:`relative shrink-0 flex flex-col border-t`,children:[y,w]}),t[28]=y,t[29]=w,t[30]=T):T=t[30],T});ln.displayName=`ChatInput`;var un=e=>{let t=(0,$.c)(5),{onPairWithAgent:n}=e;if(h())return null;let r,i,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,q.jsx)(p,{className:`h-3.5 w-3.5 shrink-0`}),i=(0,q.jsx)(`span`,{children:`Connect your own agent to this notebook`}),a=(0,q.jsx)(ne,{className:`h-3 w-3 shrink-0`}),t[0]=r,t[1]=i,t[2]=a):(r=t[0],i=t[1],a=t[2]);let o;return t[3]===n?o=t[4]:(o=(0,q.jsxs)(H,{variant:`text`,className:`gap-1.5 text-sm text-link hover:underline`,onClick:n,children:[r,i,a]}),t[3]=n,t[4]=o),o},dn=()=>{let e=(0,$.c)(9),t=r(v),{handleClick:n}=ce();if(!t){let t;e[0]===n?t=e[1]:(t=(0,q.jsx)(H,{variant:`outline`,size:`sm`,className:`self-start`,onClick:()=>n(`ai`,`ai-providers`),children:`Edit AI settings`}),e[0]=n,e[1]=t);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,q.jsx)(se,{}),e[2]=r):r=e[2];let i;e[3]===t?i=e[4]:(i=(0,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[t,r]}),e[3]=t,e[4]=i);let a;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,q.jsx)(U,{}),e[5]=a):a=e[5];let o;return e[6]===i?o=e[7]:(o=(0,q.jsx)(it,{title:`Chat with AI`,description:`No AI provider configured or Chat model not selected`,action:i,icon:a}),e[6]=i,e[7]=o),o}let i;return e[8]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,q.jsx)(fn,{}),e[8]=i):i=e[8],i},fn=()=>{let e=a($e),[r,o]=t(nt),[l,d]=t(et),[f,p]=(0,K.useState)(``),[m,h]=(0,K.useState)(``),[_,v]=(0,K.useState)(!0),{files:x,addFiles:S,clearFiles:w,removeFile:T}=ye(),{messages:E,enqueue:D,flushNext:O,clear:k,hasQueuedRef:A}=me(),j=(0,K.useRef)(null),M=(0,K.useRef)(null),N=(0,K.useRef)(null),P=(0,K.useRef)(null),F=(0,K.useRef)(null),[I,L]=(0,K.useState)(null),R=i(()=>{F.current=null,L(null)}),z=g(),{invokeAiTool:B,sendRun:V}=Ye(),{openModal:te,closeModal:ne}=Be(),U=r?.id,{chatControllerId:re,renewDraftChatId:ie}=nn(U),oe=n(),{addStagedCell:se}=_e(),{createNewCell:ce,prepareForRun:le}=s(),pe={addStagedCell:se,createNewCell:ce,prepareForRun:le,sendRun:V,store:oe},{messages:W,sendMessage:Ce,error:Te,status:ke,regenerate:Ae,stop:je,addToolOutput:Me,addToolApprovalResponse:Pe,id:Re}=Le({id:re,throttle:100,sendAutomaticallyWhen:({messages:e})=>Ne(e),messages:r?.messages||[],transport:new Kt({api:z.getAiURL(`chat`).toString(),headers:()=>z.headers(),prepareSendMessagesRequest:async e=>{let t=await be({messages:e.messages});t.success||b.debug(`Outgoing chat messages failed AI SDK schema validation`,t.error);let n={uiMessages:e.messages,includeOtherCode:c(``),options:oe.get(tt)},r=oe.get(y)?.mode||rn,i=Oe.getToolSchemas(r);return{api:z.getAiURL(`chat`).toString(),body:{tools:i,...e,...n}}}},e=>{let t=fe(e);t!==void 0&&(F.current=t)}),onFinish:({messages:t,isError:n,isAbort:r,finishReason:i})=>{if(e(e=>Gt({chatState:e,chatId:e.activeChatId,messages:t})),r){let e=ue({isAbort:!0,streamReason:F.current});if(R(),e!=null){let t=de(e);b.debug(`Chat stream aborted`,{reason:e,finishReason:i}),L(t)}}else R();Ve(t,{isError:n,isAbort:r})},onToolCall:async({toolCall:e})=>{await xe({invokeAiTool:B,addToolOutput:Me,toolCall:{toolName:e.toolName,toolCallId:e.toolCallId,input:e.input},toolContext:pe})},onError:e=>{b.error(`An error occurred:`,e)}}),ze=i(e=>{R(),Ce({role:`user`,parts:e})}),Ve=i((e,t)=>{A.current&&Fe({isError:t.isError,isAbort:t.isAbort,hasPendingToolCalls:Ne(e),hasUnresolvedToolCalls:Ie(e)})&&O(ze)}),G=ke===`submitted`||ke===`streaming`,Ue=(0,K.useRef)(G);Ue.current=G;let We=i(e=>{Ue.current||A.current?D(e):ze(e)}),Ge=i(()=>{let e=N.current;if(!e)return;let{scrollTop:t,scrollHeight:n,clientHeight:r}=e,i=n>r?Math.abs(n-r-t)<5:!0;v(i)}),Ke=i((e=!1)=>{let t=N.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?`smooth`:`auto`})}),qe=G&&W.length>0&&Se(W);(0,K.useEffect)(()=>{v(!0),k(),R()},[U,k,R]),(0,K.useEffect)(()=>{if(!_)return;let e=requestAnimationFrame(()=>{Ke()});return()=>cancelAnimationFrame(e)},[W,E,G,_,Ke]),(0,K.useEffect)(()=>{G||Ve(W,{isError:Te!=null,isAbort:!1})},[W,G,Te,Ve]);let Je=i(t=>{let n=Date.now(),r={id:Re,title:Ee(t),messages:[],createdAt:n,updatedAt:n};e(e=>{let t=new Map(e.chats);return t.set(r.id,r),{...e,chats:t,activeChatId:r.id}})}),Xe=i(async(e,t)=>{Je(e);let n=t&&t.length>0?await De(t):void 0,{contextPart:r,attachments:i}=await he(e);Ce({role:`user`,parts:[{type:`text`,text:e},...r?[r]:[],...n??[],...i]}),w(),p(``)}),Ze=i(()=>{ie(),o(null),p(``),h(``),k(),w()}),Qe=i(t=>{(t===null||t===U)&&Ze(),e(e=>{let n=new Map(e.chats);return t===null?n.clear():n.delete(t),{chats:n,activeChatId:e.activeChatId&&n.has(e.activeChatId)?e.activeChatId:null}})}),it=i(()=>{te((0,q.jsx)(ae,{onClose:ne}))}),ot=i(async(e,t)=>{let n=W[e],r=n.parts?.filter(e=>e.type===`file`&&!ge(e))??[],{contextPart:i,attachments:a}=await he(t),o=n.id;Ce({messageId:o,role:`user`,parts:[{type:`text`,text:t},...i?[i]:[],...r,...a]})}),J=i(async(e,t)=>{if(!t.trim())return;M.current?.view&&ve(M.current.view);let n=x?await De(x):void 0,{contextPart:r,attachments:i}=await he(t);e?.preventDefault(),We([{type:`text`,text:t},...r?[r]:[],...n??[],...i]),p(``),w()}),st=()=>{R(),Ae()},ct=i(()=>{m.trim()&&(j.current?.view&&ve(j.current.view),Xe(m.trim(),x))}),lt=()=>j.current?.editor?.blur(),ut=i(async e=>{U??(Je(e),p(m));let{contextPart:t,attachments:n}=await he(e);We([{type:`text`,text:e},...t?[t]:[],...n])}),Y=W.length===0;(0,K.useEffect)(()=>{if(!l)return;d(null);let{prompt:e,submit:t}=l;t?ut(e):Y?(h(e),u(j)):(p(e),u(M))},[l,d,Y,ut]);let X=Y?(0,q.jsx)(ln,{placeholder:`Ask anything, @ to include context about tables or dataframes`,input:m,inputRef:j,inputClassName:`px-1 py-0`,setInput:h,onSubmit:ct,isLoading:G,onStop:je,fileInputRef:P,onAddFiles:S,onClose:lt},`new-thread-input`):(0,q.jsx)(ln,{input:f,setInput:p,onSubmit:J,inputRef:M,isLoading:G,onStop:je,onClose:()=>M.current?.editor?.blur(),fileInputRef:P,onAddFiles:S}),dt=x&&x.length>0&&(0,q.jsx)(`div`,{className:C(`flex flex-row gap-1 flex-wrap p-1`,Y&&`py-2 px-1`),children:x?.map(e=>(0,q.jsx)(we,{file:e,onRemove:()=>T(e)},e.name))});return(0,q.jsxs)(`div`,{className:`flex flex-col h-[calc(100%-53px)]`,children:[(0,q.jsx)(ee,{children:(0,q.jsx)(on,{onNewChat:Ze,activeChatId:r?.id,setActiveChat:o,onDeleteChats:Qe,isLoading:G})}),(0,q.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden relative min-h-0`,children:[(0,q.jsxs)(`div`,{className:`flex-1 px-3 bg-(--slate-1) gap-4 py-3 flex flex-col overflow-y-auto`,ref:N,onScroll:Ge,children:[Y&&(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`div`,{className:`rounded-md border bg-background`,children:[dt,X]}),(0,q.jsx)(un,{onPairWithAgent:it})]}),W.map((e,t)=>(0,q.jsx)(sn,{message:e,index:t,onEdit:ot,isStreamingReasoning:qe,isLast:t===W.length-1,isActive:G,addToolApprovalResponse:Pe},e.id)),E.map(e=>(0,q.jsx)(an,{message:e},e.id)),G&&(0,q.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,q.jsx)(He,{className:`h-4 w-4 animate-spin`})}),Te&&(0,q.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 mb-4`,children:[(0,q.jsx)(rt,{error:Te||Error(`Unknown error`)}),(0,q.jsx)(H,{variant:`outline`,size:`sm`,onClick:st,children:`Retry`})]}),I&&!G&&!Te&&(0,q.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:I})})]}),(0,q.jsx)(at,{isVisible:!_&&(W.length>0||E.length>0),onScrollToBottom:()=>Ke(!0)})]}),G&&(0,q.jsx)(`div`,{className:`w-full flex justify-center items-center z-20 border-t`,children:(0,q.jsx)(H,{variant:`linkDestructive`,size:`sm`,onClick:je,children:`Stop`})}),!Y&&(0,q.jsxs)(q.Fragment,{children:[dt,X]})]})};function pn(e){return e.type===`text`}function mn(e){return e.text}function hn(e){return e.type===`file`}function gn(e,t){return(0,q.jsx)(Me,{attachment:e},t)}function _n(e){return e.type===`text`}function vn(e){return e.text}function yn(e){return e.type===`file`}function bn(e,t){return(0,q.jsx)(Me,{attachment:e},t)}function xn(){}function Sn(){}function Cn(e){return e.type===`text`}function wn(e){return e.text}function Tn(e){return(0,q.jsx)(P,{value:e.value,className:`text-xs py-1`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,q.jsx)(`span`,{className:`mt-1 text-muted-foreground`,children:(0,q.jsx)(e.Icon,{className:`h-3 w-3`})}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,q.jsx)(`span`,{className:`font-semibold`,children:e.label}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e.subtitle})]})]})},e.value)}export{dn as default};