@marimo-team/frontend 0.24.3-dev2 → 0.24.3-dev4

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 (94) hide show
  1. package/dist/assets/{CellStatus-LoTwk7fR.js → CellStatus-0QNZS4By.js} +1 -1
  2. package/dist/assets/{JsonOutput-CzIGPEZQ.js → JsonOutput-D2ZWLZs4.js} +7 -7
  3. package/dist/assets/{MarimoErrorOutput-DqpoYOvw.js → MarimoErrorOutput-BlmIJ9WY.js} +2 -2
  4. package/dist/assets/{RenderHTML-DwhMAd9l.js → RenderHTML-DnPB4qpJ.js} +1 -1
  5. package/dist/assets/{RunButton-BlpbweyH.js → RunButton-C7TxE07w.js} +1 -1
  6. package/dist/assets/{add-cell-with-ai-R-3DS79K.js → add-cell-with-ai-OQ4sSXg4.js} +12 -12
  7. package/dist/assets/{add-connection-dialog-BGfpw5lC.js → add-connection-dialog-MTOC2ycO.js} +73 -73
  8. package/dist/assets/{agent-panel-Cgt_K0tD.js → agent-panel-BdEDIHdc.js} +4 -4
  9. package/dist/assets/ai-model-dropdown-CmJEEhSC.js +3 -0
  10. package/dist/assets/app-config-button-W8Pytgb5.js +1 -0
  11. package/dist/assets/{blob-B2d_dHwI.js → blob-BrVH7IJp.js} +1 -1
  12. package/dist/assets/{cell-editor-Dw09J9yD.js → cell-editor-C7IiingQ.js} +8 -8
  13. package/dist/assets/{cell-link-6burT2XF.js → cell-link-CbHXmrt8.js} +1 -1
  14. package/dist/assets/{cells-Cp-G34Rz.js → cells-BBhW3FXj.js} +1 -1
  15. package/dist/assets/{chat-display-Bu405iyc.js → chat-display-CIpYPLlF.js} +1 -1
  16. package/dist/assets/{chat-panel-BlUwNY5j.js → chat-panel-CK3X_KPy.js} +2 -2
  17. package/dist/assets/{chat-ui-DGiVDzNh.js → chat-ui-BJwtx1SR.js} +4 -4
  18. package/dist/assets/{column-preview-riSXbYe_.js → column-preview-Coa5PyHk.js} +1 -1
  19. package/dist/assets/{command-palette-CCVzJcyf.js → command-palette-_xpwMniA.js} +1 -1
  20. package/dist/assets/{common-CHR7w7aQ.js → common-KqtqJsml.js} +1 -1
  21. package/dist/assets/{components-C7mWrmXr.js → components-Cpv2z-yV.js} +1 -1
  22. package/dist/assets/{datasource-DrODSIs0.js → datasource-B3qF2oaW.js} +2 -2
  23. package/dist/assets/{dependency-graph-panel-AY5BEVH2.js → dependency-graph-panel-Av1CMZ61.js} +3 -3
  24. package/dist/assets/{documentation-panel-CaJF7e-j.js → documentation-panel-BEz3Hjfu.js} +1 -1
  25. package/dist/assets/{download-DMxOzI7b.js → download-BgO9EN-W.js} +1 -1
  26. package/dist/assets/edit-page-DslcxB67.js +9 -0
  27. package/dist/assets/error-entries-BFzSRy80.js +5 -0
  28. package/dist/assets/{error-panel-Bhlvt6_H.js → error-panel-BtLTJDUq.js} +1 -1
  29. package/dist/assets/{file-explorer-panel-s0ohSG_L.js → file-explorer-panel-DEyChgqS.js} +1 -1
  30. package/dist/assets/{file-icons-DdGYuADJ.js → file-icons-BhotQqrU.js} +1 -1
  31. package/dist/assets/{file-name-input-K4MKESI_.js → file-name-input-CH-hNP6F.js} +1 -1
  32. package/dist/assets/{floating-outline-DaUHnl_e.js → floating-outline-Cmk3XDJi.js} +1 -1
  33. package/dist/assets/{home-page-BLd6rnbk.js → home-page-CUBuu5Go.js} +1 -1
  34. package/dist/assets/index-C5h1aWhw.js +29 -0
  35. package/dist/assets/{layout-DWnrxIo2.js → layout-CsLuqwD3.js} +5 -5
  36. package/dist/assets/{logs-panel-BGS2v3ba.js → logs-panel-BV4VZ_uH.js} +1 -1
  37. package/dist/assets/{markdown-renderer-BZKlbm2Q.js → markdown-renderer-751VNlrQ.js} +1 -1
  38. package/dist/assets/{name-cell-input-BMCdK-el.js → name-cell-input-DexJ7ZIH.js} +1 -1
  39. package/dist/assets/{outline-panel-Dr5u73V6.js → outline-panel-QU3nj1VW.js} +1 -1
  40. package/dist/assets/packages-panel-D7oDuI6v.js +1 -0
  41. package/dist/assets/panel-accordion-state-Dl0VcB79.js +1 -0
  42. package/dist/assets/panels-nM4QKfEI.js +4 -0
  43. package/dist/assets/process-output-CPUOlFhp.js +1 -0
  44. package/dist/assets/readonly-code-display-DP7DxRA1.js +1 -0
  45. package/dist/assets/{readonly-python-code-DpIyjHqY.js → readonly-python-code-CAYyabaV.js} +1 -1
  46. package/dist/assets/{reveal-component-nZIAapoD.js → reveal-component-D9DygPds.js} +2 -2
  47. package/dist/assets/rotate-cw-CESctpLh.js +1 -0
  48. package/dist/assets/{run-page-9pl8qhQR.js → run-page-CzO-uMUn.js} +1 -1
  49. package/dist/assets/{scratchpad-panel-BleGt2KM.js → scratchpad-panel-7YBL6E95.js} +1 -1
  50. package/dist/assets/session-panel-hnFaUP0Y.js +1 -0
  51. package/dist/assets/share-BZW3tzEX.js +1 -0
  52. package/dist/assets/{skeleton-BKeh8hf3.js → skeleton-CM7HxSva.js} +1 -1
  53. package/dist/assets/{snippets-panel-D5yy7kj0.js → snippets-panel-AdjuR23O.js} +1 -1
  54. package/dist/assets/state-DOrY1Jyf.js +1 -0
  55. package/dist/assets/state-DQHafeTV.js +3 -0
  56. package/dist/assets/{tracing-DNk3gmWv.js → tracing-CUlvXr_H.js} +1 -1
  57. package/dist/assets/{tracing-panel-Yqazr6w_.js → tracing-panel-CjyayE-l.js} +2 -2
  58. package/dist/assets/{tree-actions-CG5g7aUQ.js → tree-actions-mfuAcK1x.js} +1 -1
  59. package/dist/assets/{useAddCell-DdB_uBif.js → useAddCell-BR8kYnb6.js} +1 -1
  60. package/dist/assets/{useCellActionButton-B31neI3m.js → useCellActionButton-BhREXvvn.js} +1 -1
  61. package/dist/assets/{useDeleteCell-Bz49_cFj.js → useDeleteCell-DwaN6KAw.js} +1 -1
  62. package/dist/assets/useDependencyPanelTab-I-7B78cW.js +1 -0
  63. package/dist/assets/useInstallPackage-IUt497GC.js +1 -0
  64. package/dist/assets/useNotebookActions-D5_YLR42.js +10 -0
  65. package/dist/assets/useRunCells-BMQuitYY.js +1 -0
  66. package/dist/assets/{useSplitCell-Dy2_DmJR.js → useSplitCell-B7AvHoya.js} +1 -1
  67. package/dist/index.html +22 -22
  68. package/package.json +1 -1
  69. package/src/__mocks__/requests.ts +7 -2
  70. package/src/components/editor/chrome/panels/__tests__/packages-panel.test.tsx +143 -0
  71. package/src/components/editor/chrome/panels/packages-panel.tsx +145 -51
  72. package/src/components/editor/package-alert.tsx +25 -1
  73. package/src/core/packages/__tests__/useInstallPackage.test.tsx +47 -1
  74. package/src/core/packages/toast-components.tsx +26 -0
  75. package/src/core/packages/useInstallPackage.ts +7 -2
  76. package/src/core/wasm/bridge.ts +1 -0
  77. package/dist/assets/ai-model-dropdown-DCmiuk7x.js +0 -3
  78. package/dist/assets/app-config-button-DUJC6b6x.js +0 -1
  79. package/dist/assets/edit-page-xlMlcLnI.js +0 -9
  80. package/dist/assets/error-entries-Cv2m1yhc.js +0 -5
  81. package/dist/assets/index-4n22QjCD.js +0 -29
  82. package/dist/assets/packages-panel-BdpRg9tX.js +0 -1
  83. package/dist/assets/panel-accordion-state-DjUTN7i5.js +0 -1
  84. package/dist/assets/panels-CWn0Yh1D.js +0 -4
  85. package/dist/assets/process-output-Ck7-P_xp.js +0 -1
  86. package/dist/assets/readonly-code-display--S2daDa6.js +0 -1
  87. package/dist/assets/session-panel-DRGPlL5J.js +0 -1
  88. package/dist/assets/share-CPtBiNgr.js +0 -1
  89. package/dist/assets/state-B6AklCzD.js +0 -1
  90. package/dist/assets/state-Di9TbuV9.js +0 -3
  91. package/dist/assets/useDependencyPanelTab-C_ps0r--.js +0 -1
  92. package/dist/assets/useInstallPackage-DsD08SLK.js +0 -1
  93. package/dist/assets/useNotebookActions-CQtbk9CB.js +0 -10
  94. package/dist/assets/useRunCells-CX7oW5zy.js +0 -1
@@ -1 +1 @@
1
- import{c as e,l as t,t as n,u as r}from"./useEvent-xfs0Sn4r.js";import{D as i,Hn as a,M as o,P as s,Po as c,Sr as l,yo as u}from"./cells-Cp-G34Rz.js";import{t as d}from"./compiler-runtime-CYIjoINj.js";import{m as f}from"./utils-D5Ywm7-q.js";import{g as p}from"./useEventListener-92uWqz-P.js";import{r as m}from"./constants-BDbGiS7O.js";import{T as h,v as g}from"./config-BlNM0caL.js";import{t as _}from"./cn-ldLVeaqm.js";import{t as v}from"./jsx-runtime-B74pBk57.js";import{r as y}from"./requests-C6_IaFh7.js";import{b}from"./write-secret-modal-D6zoZgLY.js";import{n as x}from"./paths-zcL04qUW.js";import{s as S}from"./session-Sz5nSFku.js";var C=d();function w(){return t(u)}function T(){let t=(0,C.c)(5),[i]=e(g),a=r(u),{openAlert:o}=b(),{sendRename:s}=y(),c;return t[0]!==i.state||t[1]!==o||t[2]!==s||t[3]!==a?(c=async e=>{let t=f();return i.state===h.OPEN?(S(t=>{e===null?t.delete(m.filePath):t.set(m.filePath,e)}),s({filename:e}).then(()=>(a(e),document.title=t.app_title||x.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=v(),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=_(`inline-block cursor-pointer text-link hover:underline`,n),t[0]=n,t[1]=g);let v;t[2]!==r||t[3]!==l||t[4]!==m||t[5]!==d||t[6]!==c?(v=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]=v):v=t[7];let y=h(a(f,p)),b;return t[8]!==g||t[9]!==v||t[10]!==y?(b=(0,E.jsx)(`div`,{className:g,role:`link`,tabIndex:-1,onClick:v,children:y}),t[8]=g,t[9]=v,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=()=>l(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=c.create(e),i=document.getElementById(r),a=i?.classList.contains(`has-error`);return i===null?(p.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-xfs0Sn4r.js";import{Cr as i,D as a,Fo as o,M as s,P as c,Un as l,bo as u}from"./cells-BBhW3FXj.js";import{t as d}from"./compiler-runtime-CYIjoINj.js";import{m as f}from"./utils-D5Ywm7-q.js";import{g as p}from"./useEventListener-92uWqz-P.js";import{r as m}from"./constants-BDbGiS7O.js";import{T as h,v as g}from"./config-BlNM0caL.js";import{t as _}from"./cn-ldLVeaqm.js";import{t as v}from"./jsx-runtime-B74pBk57.js";import{r as y}from"./requests-C6_IaFh7.js";import{b}from"./write-secret-modal-D6zoZgLY.js";import{n as x}from"./paths-zcL04qUW.js";import{s as S}from"./session-Sz5nSFku.js";var C=d();function w(){return t(u)}function T(){let t=(0,C.c)(5),[i]=e(g),a=r(u),{openAlert:o}=b(),{sendRename:s}=y(),c;return t[0]!==i.state||t[1]!==o||t[2]!==s||t[3]!==a?(c=async e=>{let t=f();return i.state===h.OPEN?(S(t=>{e===null?t.delete(m.filePath):t.set(m.filePath,e)}),s({filename:e}).then(()=>(a(e),document.title=t.app_title||x.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=v(),D=e=>{let t=(0,C.c)(12),{className:n,cellId:r,variant:i,onClick:o,formatCellName:u,skipScroll:d}=e,f=c()[r]??``,p=s().inOrderIds.indexOf(r),{showCellIfHidden:m}=a(),h=u??j,g;t[0]===n?g=t[1]:(g=_(`inline-block cursor-pointer text-link hover:underline`,n),t[0]=n,t[1]=g);let v;t[2]!==r||t[3]!==o||t[4]!==m||t[5]!==d||t[6]!==i?(v=e=>{if(r===`__scratch__`)return!1;m({cellId:r}),e.stopPropagation(),e.preventDefault(),requestAnimationFrame(()=>{A(r,i,d)&&o?.()})},t[2]=r,t[3]=o,t[4]=m,t[5]=d,t[6]=i,t[7]=v):v=t[7];let y=h(l(f,p)),b;return t[8]!==g||t[9]!==v||t[10]!==y?(b=(0,E.jsx)(`div`,{className:g,role:`link`,tabIndex:-1,onClick:v,children:y}),t[8]=g,t[9]=v,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,a=w(),o;t[0]!==n||t[1]!==r?(o=()=>i(n,r),t[0]=n,t[1]=r,t[2]=o):o=t[2];let s;t[3]!==n||t[4]!==a?(s=e=>n===`__scratch__`?`scratch`:`marimo://${a||`untitled`}#cell=${e}`,t[3]=n,t[4]=a,t[5]=s):s=t[5];let c;return t[6]!==n||t[7]!==o||t[8]!==s?(c=(0,E.jsx)(D,{cellId:n,onClick:o,skipScroll:!0,variant:`destructive`,className:`traceback-cell-link`,formatCellName:s}),t[6]=n,t[7]=o,t[8]=s,t[9]=c):c=t[9],c};function A(e,t,n){let r=o.create(e),i=document.getElementById(r),a=i?.classList.contains(`has-error`);return i===null?(p.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};
@@ -224,4 +224,4 @@ mark line col
224
224
  )
225
225
  `]));let n=this._buffer.match(this._osc_regex);if(n===null)return e.kind=xU.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;e.kind=xU.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=xU.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==xU.EOS||n.kind==xU.Incomplete)break;n.kind!=xU.ESC&&n.kind!=xU.Unknown&&(n.kind==xU.Text?t.push(this.transform_to_html(this.with_state(n))):n.kind==xU.SGR?this.process_ansi(n):n.kind==xU.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 CU(e,...t){let n=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,``);return new RegExp(n)}function wU(e,...t){let n=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,``);return new RegExp(n,`g`)}var TU,EU,DU,OU=new SU;function kU(e){try{let t=document.createElement(`div`);return t.innerHTML=e,(t.textContent||t.innerText||``).split(`
226
226
  `).map(e=>e.trimEnd()).join(`
227
- `)}catch(t){return V.error(`Error parsing HTML content:`,t),e}}function AU(e){if(!e)return``;try{return kU(OU.ansi_to_html(e))}catch(t){return V.error(`Error converting ANSI to plain text:`,t),e}}var jU=o(null),MU=h_,NU=q.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=Sc(`fixed top-0 z-100 flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:w-fit md:max-w-[420px]`,`print:hidden`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,J.jsx)(g_,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});NU.displayName=g_.displayName;var PU={default:`bg-background border forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]`,danger:`group destructive text-error border-destructive bg-(--red-1) shadow-md-solid shadow-error forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]`},FU=xc(`data-[swipe=move]:transition-none group relative pointer-events-auto flex w-full items-start justify-between gap-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=move]:translate-x-(--radix-toast-swipe-move-x) data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-(--radix-toast-swipe-end-x) data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=open]:slide-in-from-top-full sm:data-[state=open]:slide-in-from-bottom-full data-[state=closed]:slide-out-to-right-full forced-color-adjust-none`,{variants:{variant:PU},defaultVariants:{variant:`default`}});function IU(e){return typeof e==`string`&&e in PU}var LU=q.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=IU(a)?a:`default`,s;n[4]!==r||n[5]!==o?(s=Sc(FU({variant:o}),`print:hidden`,r),n[4]=r,n[5]=o,n[6]=s):s=n[6];let c;return n[7]!==i||n[8]!==t||n[9]!==s?(c=(0,J.jsx)(__,{ref:t,className:s,...i}),n[7]=i,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});LU.displayName=__.displayName;var RU=q.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=Sc(`inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-destructive/30 hover:group-[.destructive]:border-destructive/30 hover:group-[.destructive]:bg-destructive hover:group-[.destructive]:text-destructive-foreground focus-visible:group-[.destructive]:ring-destructive`,`forced-color-adjust-none forced-colors:border-[ButtonText] forced-colors:bg-[ButtonFace] forced-colors:text-[ButtonText] forced-colors:hover:bg-[Highlight] forced-colors:hover:text-[HighlightText] forced-colors:disabled:border-[GrayText] forced-colors:disabled:text-[GrayText]`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,J.jsx)(b_,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});RU.displayName=b_.displayName;var zU=q.forwardRef((e,t)=>{let n=(0,X.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=Sc(`absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 hover:group-[.destructive]:text-red-500 focus-visible:group-[.destructive]:ring-red-400 focus-visible:group-[.destructive]:ring-offset-red-600`,`forced-colors:text-[CanvasText] forced-colors:hover:text-[CanvasText] forced-colors:group-[.destructive]:text-[CanvasText] forced-colors:hover:group-[.destructive]:text-[CanvasText]`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,J.jsx)(wd,{className:`h-4 w-4`}),n[5]=o):o=n[5];let s;return n[6]!==i||n[7]!==t||n[8]!==a?(s=(0,J.jsx)(x_,{ref:t,className:a,"toast-close":``,...i,children:o}),n[6]=i,n[7]=t,n[8]=a,n[9]=s):s=n[9],s});zU.displayName=x_.displayName;var BU=q.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=Sc(`text-sm font-semibold`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,J.jsx)(v_,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});BU.displayName=v_.displayName;var VU=q.forwardRef((e,t)=>{let n=(0,X.c)(13),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,onPointerDown:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===r?o=n[5]:(o=Sc(`max-h-48 overflow-auto text-sm opacity-90 whitespace-pre-wrap wrap-break-word select-text cursor-text`,r),n[4]=r,n[5]=o);let s;n[6]===i?s=n[7]:(s=e=>{e.stopPropagation(),i?.(e)},n[6]=i,n[7]=s);let c;return n[8]!==a||n[9]!==t||n[10]!==o||n[11]!==s?(c=(0,J.jsx)(y_,{ref:t,className:o,onPointerDown:s,...a}),n[8]=a,n[9]=t,n[10]=o,n[11]=s,n[12]=c):c=n[12],c});VU.displayName=y_.displayName;function HU(e){return e.type===`cell`?e.cellId:`lsp:${e.name}`}var UU=!1;function WU(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=nd.asString(r.data),o=i?kU(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(GU.log),n.length===0&&nC(e.output?.mimetype)&&Array.isArray(e.output.data)){e.output.data.forEach(t=>{GU.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(hc)===`read`;if(t.length>0&&!UU&&n){UU=!0;let e=t.find(e=>e.traceback);of(e?{title:`An internal error occurred`,description:e.msg||`Click 'View' to see traceback`,variant:`danger`,action:q.createElement(RU,{altText:`View traceback`,onClick:()=>{u.set(jU,{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 GU={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`,`[${KU(e.timestamp)}]`,`(${HU(e.source)}) ${e.message}`)}};function KU(e){try{return yU(e).toLocaleTimeString(void 0,{hour12:!0,hour:`numeric`,minute:`numeric`,second:`numeric`})}catch{return``}}function qU(e,t){let n=nG(t);n?n.focus():V.warn(`[CellFocusManager] focusCellEditor: element not found: ${t}`)}function JU(e){let t=document.getElementById(Xm.create(e));t?ZU(t):V.warn(`[CellFocusManager] focusCell: element not found: ${e}`)}function YU(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}function XU(){return document.activeElement instanceof HTMLElement&&document.activeElement.classList.contains(`marimo-cell`)}function ZU(e){try{e.focus()}catch{V.warn(`[CellFocusManager] element may not be focusable`,e)}}function QU(e,t){let{retries:n,delay:r,initialDelay:i=0}=t,a=0,o=()=>{if(a<n){try{if(e())return}catch(e){V.error(`Error executing function on attempt ${a+1}, retrying`,{error:e})}a++,setTimeout(o,r)}};i>0?setTimeout(o,i):o()}function $U({cellId:e,cell:t,isCodeHidden:n,codeFocus:r,variableName:i}){if(!t)return;let a=document.getElementById(Xm.create(e));if(!a){V.warn(`scrollCellIntoView: element not found`);return}if(XU()){ZU(a);return}if(n)ZU(a);else{Iv.promote(e);let n=t.current?.editorView;if(!n){V.warn(`scrollCellIntoView: editor not found`,e);return}if(n.hasFocus||!document.hasFocus())return;if(QU(()=>(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&&uk(n,i)}a.scrollIntoView({behavior:`smooth`,block:`nearest`})}function eW(e){let t=document.getElementById(Xm.create(e));if(!t){V.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 tW(){let e=document.getElementById(`App`);e?.scrollTo({top:e.scrollHeight,behavior:`smooth`})}function nW(){document.getElementById(`App`)?.scrollTo({top:0,behavior:`smooth`})}function rW(e){let t=nG(e);if(t?.hasFocus){XE(t,{behavior:`instant`});return}let n=document.getElementById(Xm.create(e));n?n.scrollIntoView({behavior:`instant`,block:`nearest`}):V.warn(`[CellFocusManager] scrollCellIntoView: element not found: ${e}`)}function iW({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},name:t,code:n,edited:a,lastCodeRun:r,lastExecutionTime:i,serializedEditorState:s}}function aW(e){return{hide_code:!1,disabled:!1,column:null,...e}}function oW(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 sW(e){let t={column:0,hide_code:!1,disabled:!1};return{...e,cellData:{[qm]:iW({id:qm,config:t}),...e.cellData},cellRuntime:{[qm]:oW(),...e.cellRuntime},cellHandles:{[qm]:(0,q.createRef)(),...e.cellHandles}}}function cW(){return sW({cellIds:dv.from([]),cellData:{},cellRuntime:{},cellHandles:{},history:[],scrollKey:null,cellLogs:[],untouchedNewCells:new Set})}var{reducer:lW,addMiddleware:uW,createActions:dW,useActions:fW,valueAtom:pW}=Ku(cW,{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||Ym.create(),h=r?p:p+1;return{...e,cellIds:e.cellIds.insertId(m,f,h),cellData:{...e.cellData,[m]:iW({id:m,code:i,name:a,lastCodeRun:s,config:aW({...o,...d!=null&&{hide_code:d}}),lastExecutionTime:c,edited:!!i&&i!==s})},cellRuntime:{...e.cellRuntime,[m]:oW()},cellHandles:{...e.cellHandles,[m]:(0,q.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&&V.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`?Vu(a-1,0,n.length-1):i===`after`?Vu(a+1,0,n.length-1):a;let s=n.atOrThrow(o);return $U({cellId:s,cell:e.cellHandles[s],isCodeHidden:mW(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 $U({cellId:n,cell:e.cellHandles[n],isCodeHidden:mW(e,n),codeFocus:void 0,variableName:void 0}),nW(),e},focusBottomCell:e=>{let t=e.cellIds.getColumns().at(-1);if(t===void 0||t.length===0)return e;let n=t.last();return $U({cellId:n,cell:e.cellHandles[n],isCodeHidden:mW(e,n),codeFocus:void 0,variableName:void 0}),tW(),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=Ym.create();return{...e,cellIds:e.cellIds.addColumn(t.columnId,[n]),cellData:{...e.cellData,[n]:iW({id:n})},cellRuntime:{...e.cellRuntime,[n]:oW()},cellHandles:{...e.cellHandles,[n]:(0,q.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 V.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:yu});s&&(s.doc=e.cellData[n].code),ZW(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===Jm,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?Jm:Ym.create(),l=iW({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]:oW()},cellHandles:{...e.cellHandles,[c]:(0,q.createRef)()},history:e.history.slice(0,-1),scrollKey:c}},clearSerializedEditorState:(e,t)=>{let{cellId:n}=t;return gW({state:e,cellId:n,cellReducer:e=>({...e,serializedEditorState:null})})},updateCellCode:(e,t)=>{let{cellId:n,code:r,formattingChange:i}=t;return e.cellData[n]?gW({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 gW({state:e,cellId:n,cellReducer:e=>({...e,name:r})})},updateCellConfig:(e,t)=>{let{cellId:n,config:r}=t;return gW({state:e,cellId:n,cellReducer:e=>({...e,config:aW({...e.config,...r})})})},prepareForRun:(e,t)=>gW({state:hW({state:e,cellId:t.cellId,cellReducer:e=>RH(e)}),cellId:t.cellId,cellReducer:e=>({...e,edited:!1,lastCodeRun:e.code.trim()})}),handleCellMessage:(e,t)=>{let n=t.cell_id,r=hW({state:e,cellId:n,cellReducer:e=>LH(e,t)});return t.status===`queued`&&(r=gW({state:r,cellId:n,cellReducer:e=>({...e,lastCodeRun:e.code.trim(),edited:!1})})),{...r,cellLogs:[...r.cellLogs,...WU(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]=iW({id:a})),a in e.cellRuntime||(r[a]=oW()),a in e.cellHandles||(i[a]=(0,q.createRef)());return{...e,cellIds:dv.fromWithPreviousShape(t.cellIds,e.cellIds),cellData:n,cellRuntime:r,cellHandles:i}},rebuildCellColumns:(e,t)=>{let n=dv.fromIdsAndColumns(t.cellIds.map(t=>[t,e.cellData[t]?.config.column??null]));return{...e,cellIds:n}},setCellCodes:(e,t)=>{pc(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 iW({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(!TH()||!EH(i)){let e=n.cellHandles[i].current;e?.editorViewOrNull&&fH(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 hW({state:e,cellId:n,cellReducer:e=>{let t=[...e.consoleOutputs],n=t[i];return n==null||n.channel!==`stdin`?(V.warn(`Expected stdin output`),e):(t[i]={channel:`stdin`,mimetype:n.mimetype,data:n.data,timestamp:n.timestamp,response:r},{...e,interrupted:!1,consoleOutputs:t})}})},setCells:(e,t)=>{let n=Object.fromEntries(t.map(e=>[e.id,e])),r=gc(),i=t=>{if(!r)return oW();let n=e.cellRuntime[t];return n&&(n.output!=null||n.consoleOutputs.length>0)?n:oW()},a=Object.fromEntries(t.map(e=>[e.id,i(e.id)]));return sW({...e,cellIds:dv.fromIdsAndColumns(t.map(e=>[e.id,e.config.column])),cellData:n,cellRuntime:a,cellHandles:Object.fromEntries(t.map(e=>[e.id,(0,q.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=Ym.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,s),cellData:{...e.cellData,[t]:iW({id:t})},cellRuntime:{...e.cellRuntime,[t]:oW()},cellHandles:{...e.cellHandles,[t]:(0,q.createRef)()},scrollKey:t}}if(l&&!i){let t=Ym.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,0),cellData:{...e.cellData,[t]:iW({id:t})},cellRuntime:{...e.cellRuntime,[t]:oW()},cellHandles:{...e.cellHandles,[t]:(0,q.createRef)()},scrollKey:t}}if((c||l)&&i)return e;if(s>=0&&s<a.length){let t=a.atOrThrow(s);$U({cellId:t,cell:e.cellHandles[t],isCodeHidden:mW(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 $U({cellId:i,cell:e.cellHandles[i],isCodeHidden:mW(e,i),codeFocus:void 0,variableName:void 0}),{...e,scrollKey:null}},foldAll:e=>(jv(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),unfoldAll:e=>(Mv(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=CH(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=[],a=[],o=r.length-1;for(;o>=0;){let e=CH(o,n);if(e){let n=o,r=e[1],s=i.find(e=>e.start<=r&&e.end===r);s&&(r=s.start),i.push({start:n,end:r});let c=t.atOrThrow(n),l=t.atOrThrow(r);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}=pH(o.editorView);fH(o.editorView,s);let l=Ym.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]:iW({id:l,code:c,edited:!!c})},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]},[l]:oW()},cellHandles:{...e.cellHandles,[l]:(0,q.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:(fH(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 hW({state:e,cellId:n,cellReducer:e=>({...e,output:null,consoleOutputs:[]})})},clearCellConsoleOutput:(e,t)=>{let{cellId:n}=t;return hW({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:Jm}:{...e,cellIds:e.cellIds.insertId(Jm,e.cellIds.atOrThrow(0).id,0),cellData:{...e.cellData,[Jm]:iW({id:Jm,name:Jm,code:n,edited:!!n})},cellRuntime:{...e.cellRuntime,[Jm]:oW()},cellHandles:{...e.cellHandles,[Jm]:(0,q.createRef)()},scrollKey:Jm}}});uW(_U);function mW(e,t){return!!e.cellData[t].config.hide_code&&!e.untouchedNewCells.has(t)}function hW({state:e,cellId:t,cellReducer:n}){return t in e.cellRuntime?{...e,cellRuntime:{...e.cellRuntime,[t]:n(e.cellRuntime[t])}}:(V.warn(`Cell ${t} not found in state`),e)}function gW({state:e,cellId:t,cellReducer:n}){return t in e.cellData?{...e,cellData:{...e.cellData,[t]:n(e.cellData[t])}}:(V.warn(`Cell ${t} not found in state`),e)}function _W(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 vW=dW(e=>{u.set(pW,t=>lW(t,e))}).addLogs,yW=o(e=>e(pW).cellIds),bW=o(e=>e(yW).hasOnlyOneId()),xW=o(e=>cC(e(pW)).length>0);o(e=>lC(e(pW)).length>0);var SW=o(e=>uC(e(pW))),CW=o(e=>dC(e(pW))),wW=o(e=>aC(e(pW))),TW=o(e=>{let{cellIds:t,cellRuntime:n,cellData:r}=e(pW);return t.inOrderIds.map(e=>{let t=n[e],{name:i}=r[e];if(nC(t.output?.mimetype)){pc(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)}),EW=o(e=>{let{cellIds:t,cellRuntime:n}=e(pW);return bH(t.inOrderIds.map(e=>n[e].outline))}),DW=o(e=>e(TW).length),OW=c(o(e=>{let{cellIds:t,cellData:n}=e(pW);return fc.fromEntries(t.inOrderIds.map(e=>[e,n[e]?.name]))})),kW=o(e=>e(pW).scrollKey),AW=()=>s(pW),jW=()=>s(yW),MW=()=>s(OW),NW=()=>s(TW),PW=()=>s(pW).cellLogs,FW=()=>s(kW),IW=()=>u.get(pW),LW=()=>u.get(pW).cellIds,RW=()=>{let{cellIds:e,cellData:t}=u.get(pW);return e.inOrderIds.map(e=>t[e]?.name).filter(Boolean)},zW=R_(j_(pW,e=>e.cellIds.inOrderIds.map(t=>e.cellData[t]))),BW=()=>a(zW),VW=o(e=>e(pW).cellRuntime),HW=o(e=>rC(e(pW))),UW=o(e=>{let{cellRuntime:t}=e(pW);return Object.entries(t).every(([e,t])=>t.status!==`running`||e===`__scratch__`)}),WW=o(e=>iC(e(pW))),GW=o(e=>e(pW).cellIds.colLength),KW=o(e=>e(pW).cellIds.idLength>0),qW=o(e=>e(pW).cellIds.getColumnIds()),JW=D_(e=>o(t=>t(pW).cellData[e])),YW=D_(e=>o(t=>t(pW).cellRuntime[e])),XW=D_(e=>o(t=>t(pW).cellHandles[e]));function ZW(e){JW.remove(e),YW.remove(e),XW.remove(e)}var QW=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=JW(e),t[0]=e,t[1]=n),s(n)},$W=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=YW(e),t[0]=e,t[1]=n),s(n)},eG=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=XW(e),t[0]=e,t[1]=n),s(n)},tG=()=>{let{cellIds:e,cellHandles:t}=u.get(pW);return e.inOrderIds.map(e=>t[e]?.current?.editorViewOrNull).filter(Boolean)},nG=e=>{let{cellHandles:t}=u.get(pW);return t[e].current?.editorView},rG=e=>(Iv.promote(e),nG(e));function iG(e){let{cellIds:t,cellData:n,cellRuntime:r}=e;return t.getColumns().flatMap(e=>e.topLevelIds.map(e=>({...n[e],...r[e]})))}function aG(e){return o(t=>t(pW).untouchedNewCells.has(e))}function oG(e){let t=YW(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(...kv(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 sG(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),fW(n)}export{BU as $,BS as $a,Ew as $i,lF as $n,bD as $r,lB as $t,NW as A,MC as Aa,mT as Ai,hR as An,rh as Ao,ZO as Ar,jV as At,eW as B,mC as Ba,Uw as Bi,cI as Bn,Wm as Bo,VD as Br,UB as Bt,WW as C,PC as Ca,FT as Ci,Nz as Cn,H_ as Co,gk as Cr,nH as Ct,sG as D,LC as Da,lT as Di,wz as Dn,ih as Do,KO as Dr,EV as Dt,CW as E,NC as Ea,uT as Ei,Pz as En,Qh as Eo,JO as Er,DV as Et,$W as F,hC as Fa,Xw as Fi,UI as Fn,qm as Fo,WO as Fr,lV as Ft,XU as G,pC as Ga,Iw as Gi,eI as Gn,km as Go,Q as Gr,PB as Gt,QU as H,oC as Ha,Bw as Hi,nI as Hn,zm as Ho,ND as Hr,BB as Ht,AW as I,gC as Ia,qw as Ii,eL as In,Jm as Io,UO as Ir,aV as It,HU as J,tC as Ja,Nw as Ji,kF as Jn,mm as Jo,CD as Jr,SB as Jt,YU as K,nC as Ka,Fw as Ki,QF as Kn,Em as Ko,DD as Kr,NB as Kt,FW as L,cC as La,Kw as Li,xI as Ln,Qm as Lo,qD as Lr,iV as Lt,jW as M,jC as Ma,$w as Mi,mR as Mn,Ym as Mo,YO as Mr,vV as Mt,PW as N,yC as Na,Yw as Ni,IL as Nn,$m as No,QO as Nr,_V as Nt,QW as O,RC as Oa,xT as Oi,Tz as On,th as Oo,GO as Or,OV as Ot,MW as P,bC as Pa,Zw as Pi,aR as Pn,Xm as Po,PO as Pr,gV as Pt,MU as Q,GS as Qa,Dw as Qi,sF as Qn,xD as Qr,pB as Qt,iW as R,lC as Ra,Gw as Ri,sI as Rn,Zm as Ro,UD as Rr,cV as Rt,EW as S,IC as Sa,QT as Si,Oz as Sn,E_ as So,bk as Sr,uH as St,UW as T,HC as Ta,rT as Ti,Mz as Tn,Jh as To,uk as Tr,NV as Tt,JU as U,_C as Ua,Rw as Ui,tI as Un,Im as Uo,OD as Ur,zB as Ut,rW as V,sC as Va,Hw as Vi,uI as Vn,Rm as Vo,zD as Vr,HB as Vt,qU as W,vC as Wa,Lw as Wi,rI as Wn,jm as Wo,ED as Wr,VB as Wt,zU as X,QS as Xa,jw as Xi,oF as Xn,SD as Xr,gB as Xt,LU as Y,$S as Ya,Mw as Yi,fF as Yn,mf as Yo,vD as Yr,hB as Yt,VU as Z,KS as Za,kw as Zi,cF as Zn,dD as Zr,_B as Zt,xW as _,ZC as _a,PE as _i,Iz as _n,Y_ as _o,Wk as _r,dH as _t,VW as a,yw as aa,nD as ai,Qz as an,Dv as ao,_j as ar,vU as at,pW as b,JC as ba,wE as bi,Az as bn,J_ as bo,wk as br,sH as bt,rG as c,hw as ca,YE as ci,aB as cn,Tv as co,ej as cr,zH as ct,_W as d,uw as da,VE as di,Gz as dn,sv as do,MA as dr,TH as dt,Tw as ea,oD as ei,uB as en,MS as eo,uF as er,NU as et,nG as f,cw as fa,zE as fi,Hz as fn,av as fo,NA as fr,wH as ft,KW as g,ow as ga,jE as gi,Bz as gn,Q_ as go,Uk as gr,mH as gt,IW as h,dw as ha,ME as hi,Rz as hn,ev as ho,sA as hr,xH as ht,yW as i,bw as ia,aD as ii,Xz as in,Iv as io,vj as ir,SU as it,eG as j,AC as ja,Qw as ji,gR as jn,eh as jo,qO as jr,yV as jt,BW as k,VC as ka,ST as ki,sz as kn,nh as ko,XO as kr,AV as kt,iG as l,mw as la,GE as li,oB as ln,wv as lo,tj as lr,BH as lt,LW as m,aw as ma,IE as mi,Fz as mn,$_ as mo,fA as mr,yH as mt,JW as n,Sw as na,cD as ni,rB as nn,bS as no,cM as nr,AU as nt,qW as o,_w as oa,rD as oi,tB as on,kv as oo,rj as or,lU as ot,RW as p,sw as pa,LE as pi,Uz as pn,tv as po,pA as pr,SH as pt,KU as q,eC as qa,Pw as qi,XF as qn,Tm as qo,TD as qr,xB as qt,DW as r,xw as ra,iD as ri,iB as rn,ix as ro,bj as rr,kU as rt,aG as s,gw as sa,eD as si,nB as sn,Ov as so,nj as sr,mU as st,SW as t,ww as ta,sD as ti,Yz as tn,NS as to,CM as tr,jU as tt,tG as u,pw as ua,qE as ui,Wz as un,dv as uo,RA as ur,EH as ut,bW as v,YC as va,NE as vi,Ez as vn,q_ as vo,jk as vr,fH as vt,GW as w,FC as wa,PT as wi,kz as wn,j_ as wo,vk as wr,lH as wt,HW as x,QC as xa,xE as xi,jz as xn,U_ as xo,Nk as xr,rH as xt,wW as y,XC as ya,FE as yi,Dz as yn,K_ as yo,Mk as yr,oH as yt,oW as z,fC as za,Ww as zi,lI as zn,Um as zo,ID as zr,RB as zt};
227
+ `)}catch(t){return V.error(`Error parsing HTML content:`,t),e}}function AU(e){if(!e)return``;try{return kU(OU.ansi_to_html(e))}catch(t){return V.error(`Error converting ANSI to plain text:`,t),e}}var jU=o(null),MU=h_,NU=q.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=Sc(`fixed top-0 z-100 flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:w-fit md:max-w-[420px]`,`print:hidden`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,J.jsx)(g_,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});NU.displayName=g_.displayName;var PU={default:`bg-background border forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]`,danger:`group destructive text-error border-destructive bg-(--red-1) shadow-md-solid shadow-error forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]`},FU=xc(`data-[swipe=move]:transition-none group relative pointer-events-auto flex w-full items-start justify-between gap-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=move]:translate-x-(--radix-toast-swipe-move-x) data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-(--radix-toast-swipe-end-x) data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=open]:slide-in-from-top-full sm:data-[state=open]:slide-in-from-bottom-full data-[state=closed]:slide-out-to-right-full forced-color-adjust-none`,{variants:{variant:PU},defaultVariants:{variant:`default`}});function IU(e){return typeof e==`string`&&e in PU}var LU=q.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=IU(a)?a:`default`,s;n[4]!==r||n[5]!==o?(s=Sc(FU({variant:o}),`print:hidden`,r),n[4]=r,n[5]=o,n[6]=s):s=n[6];let c;return n[7]!==i||n[8]!==t||n[9]!==s?(c=(0,J.jsx)(__,{ref:t,className:s,...i}),n[7]=i,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});LU.displayName=__.displayName;var RU=q.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=Sc(`inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-destructive/30 hover:group-[.destructive]:border-destructive/30 hover:group-[.destructive]:bg-destructive hover:group-[.destructive]:text-destructive-foreground focus-visible:group-[.destructive]:ring-destructive`,`forced-color-adjust-none forced-colors:border-[ButtonText] forced-colors:bg-[ButtonFace] forced-colors:text-[ButtonText] forced-colors:hover:bg-[Highlight] forced-colors:hover:text-[HighlightText] forced-colors:disabled:border-[GrayText] forced-colors:disabled:text-[GrayText]`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,J.jsx)(b_,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});RU.displayName=b_.displayName;var zU=q.forwardRef((e,t)=>{let n=(0,X.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=Sc(`absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 hover:group-[.destructive]:text-red-500 focus-visible:group-[.destructive]:ring-red-400 focus-visible:group-[.destructive]:ring-offset-red-600`,`forced-colors:text-[CanvasText] forced-colors:hover:text-[CanvasText] forced-colors:group-[.destructive]:text-[CanvasText] forced-colors:hover:group-[.destructive]:text-[CanvasText]`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,J.jsx)(wd,{className:`h-4 w-4`}),n[5]=o):o=n[5];let s;return n[6]!==i||n[7]!==t||n[8]!==a?(s=(0,J.jsx)(x_,{ref:t,className:a,"toast-close":``,...i,children:o}),n[6]=i,n[7]=t,n[8]=a,n[9]=s):s=n[9],s});zU.displayName=x_.displayName;var BU=q.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=Sc(`text-sm font-semibold`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,J.jsx)(v_,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});BU.displayName=v_.displayName;var VU=q.forwardRef((e,t)=>{let n=(0,X.c)(13),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,onPointerDown:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===r?o=n[5]:(o=Sc(`max-h-48 overflow-auto text-sm opacity-90 whitespace-pre-wrap wrap-break-word select-text cursor-text`,r),n[4]=r,n[5]=o);let s;n[6]===i?s=n[7]:(s=e=>{e.stopPropagation(),i?.(e)},n[6]=i,n[7]=s);let c;return n[8]!==a||n[9]!==t||n[10]!==o||n[11]!==s?(c=(0,J.jsx)(y_,{ref:t,className:o,onPointerDown:s,...a}),n[8]=a,n[9]=t,n[10]=o,n[11]=s,n[12]=c):c=n[12],c});VU.displayName=y_.displayName;function HU(e){return e.type===`cell`?e.cellId:`lsp:${e.name}`}var UU=!1;function WU(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=nd.asString(r.data),o=i?kU(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(GU.log),n.length===0&&nC(e.output?.mimetype)&&Array.isArray(e.output.data)){e.output.data.forEach(t=>{GU.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(hc)===`read`;if(t.length>0&&!UU&&n){UU=!0;let e=t.find(e=>e.traceback);of(e?{title:`An internal error occurred`,description:e.msg||`Click 'View' to see traceback`,variant:`danger`,action:q.createElement(RU,{altText:`View traceback`,onClick:()=>{u.set(jU,{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 GU={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`,`[${KU(e.timestamp)}]`,`(${HU(e.source)}) ${e.message}`)}};function KU(e){try{return yU(e).toLocaleTimeString(void 0,{hour12:!0,hour:`numeric`,minute:`numeric`,second:`numeric`})}catch{return``}}function qU(e,t){let n=nG(t);n?n.focus():V.warn(`[CellFocusManager] focusCellEditor: element not found: ${t}`)}function JU(e){let t=document.getElementById(Xm.create(e));t?ZU(t):V.warn(`[CellFocusManager] focusCell: element not found: ${e}`)}function YU(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}function XU(){return document.activeElement instanceof HTMLElement&&document.activeElement.classList.contains(`marimo-cell`)}function ZU(e){try{e.focus()}catch{V.warn(`[CellFocusManager] element may not be focusable`,e)}}function QU(e,t){let{retries:n,delay:r,initialDelay:i=0}=t,a=0,o=()=>{if(a<n){try{if(e())return}catch(e){V.error(`Error executing function on attempt ${a+1}, retrying`,{error:e})}a++,setTimeout(o,r)}};i>0?setTimeout(o,i):o()}function $U({cellId:e,cell:t,isCodeHidden:n,codeFocus:r,variableName:i}){if(!t)return;let a=document.getElementById(Xm.create(e));if(!a){V.warn(`scrollCellIntoView: element not found`);return}if(XU()){ZU(a);return}if(n)ZU(a);else{Iv.promote(e);let n=t.current?.editorView;if(!n){V.warn(`scrollCellIntoView: editor not found`,e);return}if(n.hasFocus||!document.hasFocus())return;if(QU(()=>(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&&uk(n,i)}a.scrollIntoView({behavior:`smooth`,block:`nearest`})}function eW(e){let t=document.getElementById(Xm.create(e));if(!t){V.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 tW(){let e=document.getElementById(`App`);e?.scrollTo({top:e.scrollHeight,behavior:`smooth`})}function nW(){document.getElementById(`App`)?.scrollTo({top:0,behavior:`smooth`})}function rW(e){let t=nG(e);if(t?.hasFocus){XE(t,{behavior:`instant`});return}let n=document.getElementById(Xm.create(e));n?n.scrollIntoView({behavior:`instant`,block:`nearest`}):V.warn(`[CellFocusManager] scrollCellIntoView: element not found: ${e}`)}function iW({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},name:t,code:n,edited:a,lastCodeRun:r,lastExecutionTime:i,serializedEditorState:s}}function aW(e){return{hide_code:!1,disabled:!1,column:null,...e}}function oW(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 sW(e){let t={column:0,hide_code:!1,disabled:!1};return{...e,cellData:{[qm]:iW({id:qm,config:t}),...e.cellData},cellRuntime:{[qm]:oW(),...e.cellRuntime},cellHandles:{[qm]:(0,q.createRef)(),...e.cellHandles}}}function cW(){return sW({cellIds:dv.from([]),cellData:{},cellRuntime:{},cellHandles:{},history:[],scrollKey:null,cellLogs:[],untouchedNewCells:new Set})}var{reducer:lW,addMiddleware:uW,createActions:dW,useActions:fW,valueAtom:pW}=Ku(cW,{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||Ym.create(),h=r?p:p+1;return{...e,cellIds:e.cellIds.insertId(m,f,h),cellData:{...e.cellData,[m]:iW({id:m,code:i,name:a,lastCodeRun:s,config:aW({...o,...d!=null&&{hide_code:d}}),lastExecutionTime:c,edited:!!i&&i!==s})},cellRuntime:{...e.cellRuntime,[m]:oW()},cellHandles:{...e.cellHandles,[m]:(0,q.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&&V.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`?Vu(a-1,0,n.length-1):i===`after`?Vu(a+1,0,n.length-1):a;let s=n.atOrThrow(o);return $U({cellId:s,cell:e.cellHandles[s],isCodeHidden:mW(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 $U({cellId:n,cell:e.cellHandles[n],isCodeHidden:mW(e,n),codeFocus:void 0,variableName:void 0}),nW(),e},focusBottomCell:e=>{let t=e.cellIds.getColumns().at(-1);if(t===void 0||t.length===0)return e;let n=t.last();return $U({cellId:n,cell:e.cellHandles[n],isCodeHidden:mW(e,n),codeFocus:void 0,variableName:void 0}),tW(),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=Ym.create();return{...e,cellIds:e.cellIds.addColumn(t.columnId,[n]),cellData:{...e.cellData,[n]:iW({id:n})},cellRuntime:{...e.cellRuntime,[n]:oW()},cellHandles:{...e.cellHandles,[n]:(0,q.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 V.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:yu});s&&(s.doc=e.cellData[n].code),ZW(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===Jm,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?Jm:Ym.create(),l=iW({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]:oW()},cellHandles:{...e.cellHandles,[c]:(0,q.createRef)()},history:e.history.slice(0,-1),scrollKey:c}},clearSerializedEditorState:(e,t)=>{let{cellId:n}=t;return gW({state:e,cellId:n,cellReducer:e=>({...e,serializedEditorState:null})})},updateCellCode:(e,t)=>{let{cellId:n,code:r,formattingChange:i}=t;return e.cellData[n]?gW({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 gW({state:e,cellId:n,cellReducer:e=>({...e,name:r})})},updateCellConfig:(e,t)=>{let{cellId:n,config:r}=t;return gW({state:e,cellId:n,cellReducer:e=>({...e,config:aW({...e.config,...r})})})},prepareForRun:(e,t)=>gW({state:hW({state:e,cellId:t.cellId,cellReducer:e=>RH(e)}),cellId:t.cellId,cellReducer:e=>({...e,edited:!1,lastCodeRun:e.code.trim()})}),handleCellMessage:(e,t)=>{let n=t.cell_id,r=hW({state:e,cellId:n,cellReducer:e=>LH(e,t)});return t.status===`queued`&&(r=gW({state:r,cellId:n,cellReducer:e=>({...e,lastCodeRun:e.code.trim(),edited:!1})})),{...r,cellLogs:[...r.cellLogs,...WU(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]=iW({id:a})),a in e.cellRuntime||(r[a]=oW()),a in e.cellHandles||(i[a]=(0,q.createRef)());return{...e,cellIds:dv.fromWithPreviousShape(t.cellIds,e.cellIds),cellData:n,cellRuntime:r,cellHandles:i}},rebuildCellColumns:(e,t)=>{let n=dv.fromIdsAndColumns(t.cellIds.map(t=>[t,e.cellData[t]?.config.column??null]));return{...e,cellIds:n}},setCellCodes:(e,t)=>{pc(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 iW({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(!TH()||!EH(i)){let e=n.cellHandles[i].current;e?.editorViewOrNull&&fH(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 hW({state:e,cellId:n,cellReducer:e=>{let t=[...e.consoleOutputs],n=t[i];return n==null||n.channel!==`stdin`?(V.warn(`Expected stdin output`),e):(t[i]={channel:`stdin`,mimetype:n.mimetype,data:n.data,timestamp:n.timestamp,response:r},{...e,interrupted:!1,consoleOutputs:t})}})},setCells:(e,t)=>{let n=Object.fromEntries(t.map(e=>[e.id,e])),r=gc(),i=t=>{if(!r)return oW();let n=e.cellRuntime[t];return n&&(n.output!=null||n.consoleOutputs.length>0)?n:oW()},a=Object.fromEntries(t.map(e=>[e.id,i(e.id)]));return sW({...e,cellIds:dv.fromIdsAndColumns(t.map(e=>[e.id,e.config.column])),cellData:n,cellRuntime:a,cellHandles:Object.fromEntries(t.map(e=>[e.id,(0,q.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=Ym.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,s),cellData:{...e.cellData,[t]:iW({id:t})},cellRuntime:{...e.cellRuntime,[t]:oW()},cellHandles:{...e.cellHandles,[t]:(0,q.createRef)()},scrollKey:t}}if(l&&!i){let t=Ym.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,0),cellData:{...e.cellData,[t]:iW({id:t})},cellRuntime:{...e.cellRuntime,[t]:oW()},cellHandles:{...e.cellHandles,[t]:(0,q.createRef)()},scrollKey:t}}if((c||l)&&i)return e;if(s>=0&&s<a.length){let t=a.atOrThrow(s);$U({cellId:t,cell:e.cellHandles[t],isCodeHidden:mW(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 $U({cellId:i,cell:e.cellHandles[i],isCodeHidden:mW(e,i),codeFocus:void 0,variableName:void 0}),{...e,scrollKey:null}},foldAll:e=>(jv(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),unfoldAll:e=>(Mv(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=CH(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=[],a=[],o=r.length-1;for(;o>=0;){let e=CH(o,n);if(e){let n=o,r=e[1],s=i.find(e=>e.start<=r&&e.end===r);s&&(r=s.start),i.push({start:n,end:r});let c=t.atOrThrow(n),l=t.atOrThrow(r);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}=pH(o.editorView);fH(o.editorView,s);let l=Ym.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]:iW({id:l,code:c,edited:!!c})},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]},[l]:oW()},cellHandles:{...e.cellHandles,[l]:(0,q.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:(fH(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 hW({state:e,cellId:n,cellReducer:e=>({...e,output:null,consoleOutputs:[]})})},clearCellConsoleOutput:(e,t)=>{let{cellId:n}=t;return hW({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:Jm}:{...e,cellIds:e.cellIds.insertId(Jm,e.cellIds.atOrThrow(0).id,0),cellData:{...e.cellData,[Jm]:iW({id:Jm,name:Jm,code:n,edited:!!n})},cellRuntime:{...e.cellRuntime,[Jm]:oW()},cellHandles:{...e.cellHandles,[Jm]:(0,q.createRef)()},scrollKey:Jm}}});uW(_U);function mW(e,t){return!!e.cellData[t].config.hide_code&&!e.untouchedNewCells.has(t)}function hW({state:e,cellId:t,cellReducer:n}){return t in e.cellRuntime?{...e,cellRuntime:{...e.cellRuntime,[t]:n(e.cellRuntime[t])}}:(V.warn(`Cell ${t} not found in state`),e)}function gW({state:e,cellId:t,cellReducer:n}){return t in e.cellData?{...e,cellData:{...e.cellData,[t]:n(e.cellData[t])}}:(V.warn(`Cell ${t} not found in state`),e)}function _W(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 vW=dW(e=>{u.set(pW,t=>lW(t,e))}).addLogs,yW=o(e=>e(pW).cellIds),bW=o(e=>e(yW).hasOnlyOneId()),xW=o(e=>cC(e(pW)).length>0);o(e=>lC(e(pW)).length>0);var SW=o(e=>uC(e(pW))),CW=o(e=>dC(e(pW))),wW=o(e=>aC(e(pW))),TW=o(e=>{let{cellIds:t,cellRuntime:n,cellData:r}=e(pW);return t.inOrderIds.map(e=>{let t=n[e],{name:i}=r[e];if(nC(t.output?.mimetype)){pc(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)}),EW=o(e=>{let{cellIds:t,cellRuntime:n}=e(pW);return bH(t.inOrderIds.map(e=>n[e].outline))}),DW=o(e=>e(TW).length),OW=c(o(e=>{let{cellIds:t,cellData:n}=e(pW);return fc.fromEntries(t.inOrderIds.map(e=>[e,n[e]?.name]))})),kW=o(e=>e(pW).scrollKey),AW=()=>s(pW),jW=()=>s(yW),MW=()=>s(OW),NW=()=>s(TW),PW=()=>s(pW).cellLogs,FW=()=>s(kW),IW=()=>u.get(pW),LW=()=>u.get(pW).cellIds,RW=()=>{let{cellIds:e,cellData:t}=u.get(pW);return e.inOrderIds.map(e=>t[e]?.name).filter(Boolean)},zW=R_(j_(pW,e=>e.cellIds.inOrderIds.map(t=>e.cellData[t]))),BW=()=>a(zW),VW=o(e=>e(pW).cellRuntime),HW=o(e=>rC(e(pW))),UW=o(e=>{let{cellRuntime:t}=e(pW);return Object.entries(t).every(([e,t])=>t.status!==`running`||e===`__scratch__`)}),WW=o(e=>iC(e(pW))),GW=o(e=>e(pW).cellIds.colLength),KW=o(e=>e(pW).cellIds.idLength>0),qW=o(e=>e(pW).cellIds.getColumnIds()),JW=D_(e=>o(t=>t(pW).cellData[e])),YW=D_(e=>o(t=>t(pW).cellRuntime[e])),XW=D_(e=>o(t=>t(pW).cellHandles[e]));function ZW(e){JW.remove(e),YW.remove(e),XW.remove(e)}var QW=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=JW(e),t[0]=e,t[1]=n),s(n)},$W=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=YW(e),t[0]=e,t[1]=n),s(n)},eG=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=XW(e),t[0]=e,t[1]=n),s(n)},tG=()=>{let{cellIds:e,cellHandles:t}=u.get(pW);return e.inOrderIds.map(e=>t[e]?.current?.editorViewOrNull).filter(Boolean)},nG=e=>{let{cellHandles:t}=u.get(pW);return t[e].current?.editorView},rG=e=>(Iv.promote(e),nG(e));function iG(e){let{cellIds:t,cellData:n,cellRuntime:r}=e;return t.getColumns().flatMap(e=>e.topLevelIds.map(e=>({...n[e],...r[e]})))}function aG(e){return o(t=>t(pW).untouchedNewCells.has(e))}function oG(e){let t=YW(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(...kv(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 sG(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),fW(n)}export{MU as $,GS as $a,Dw as $i,sF as $n,xD as $r,pB as $t,NW as A,VC as Aa,ST as Ai,sz as An,nh as Ao,XO as Ar,AV as At,eW as B,fC as Ba,Ww as Bi,lI as Bn,Um as Bo,ID as Br,RB as Bt,WW as C,IC as Ca,QT as Ci,Oz as Cn,E_ as Co,bk as Cr,uH as Ct,sG as D,NC as Da,uT as Di,Pz as Dn,Qh as Do,JO as Dr,DV as Dt,CW as E,HC as Ea,rT as Ei,Mz as En,Jh as Eo,uk as Er,NV as Et,$W as F,bC as Fa,Zw as Fi,aR as Fn,Xm as Fo,PO as Fr,gV as Ft,XU as G,vC as Ga,Lw as Gi,rI as Gn,jm as Go,ED as Gr,VB as Gt,QU as H,sC as Ha,Hw as Hi,uI as Hn,Rm as Ho,zD as Hr,HB as Ht,AW as I,hC as Ia,Xw as Ii,UI as In,qm as Io,WO as Ir,lV as It,HU as J,eC as Ja,Pw as Ji,XF as Jn,Tm as Jo,TD as Jr,xB as Jt,YU as K,pC as Ka,Iw as Ki,eI as Kn,km as Ko,Q as Kr,PB as Kt,FW as L,gC as La,qw as Li,eL as Ln,Jm as Lo,UO as Lr,aV as Lt,jW as M,AC as Ma,Qw as Mi,gR as Mn,eh as Mo,qO as Mr,yV as Mt,PW as N,jC as Na,$w as Ni,mR as Nn,Ym as No,YO as Nr,vV as Nt,QW as O,LC as Oa,lT as Oi,wz as On,ih as Oo,KO as Or,EV as Ot,MW as P,yC as Pa,Yw as Pi,IL as Pn,$m as Po,QO as Pr,_V as Pt,VU as Q,KS as Qa,kw as Qi,cF as Qn,dD as Qr,_B as Qt,iW as R,cC as Ra,Kw as Ri,xI as Rn,Qm as Ro,qD as Rr,iV as Rt,EW as S,QC as Sa,xE as Si,jz as Sn,U_ as So,Nk as Sr,rH as St,UW as T,FC as Ta,PT as Ti,kz as Tn,j_ as To,vk as Tr,lH as Tt,JU as U,oC as Ua,Bw as Ui,nI as Un,zm as Uo,ND as Ur,BB as Ut,rW as V,mC as Va,Uw as Vi,cI as Vn,Wm as Vo,VD as Vr,UB as Vt,qU as W,_C as Wa,Rw as Wi,tI as Wn,Im as Wo,OD as Wr,zB as Wt,RU as X,$S as Xa,Mw as Xi,fF as Xn,mf as Xo,vD as Xr,hB as Xt,LU as Y,tC as Ya,Nw as Yi,kF as Yn,mm as Yo,CD as Yr,SB as Yt,zU as Z,QS as Za,jw as Zi,oF as Zn,SD as Zr,gB as Zt,xW as _,ow as _a,jE as _i,Bz as _n,Q_ as _o,Uk as _r,mH as _t,VW as a,bw as aa,aD as ai,Xz as an,Iv as ao,vj as ar,SU as at,pW as b,XC as ba,FE as bi,Dz as bn,K_ as bo,Mk as br,oH as bt,rG as c,gw as ca,eD as ci,nB as cn,Ov as co,nj as cr,mU as ct,_W as d,pw as da,qE as di,Wz as dn,dv as do,RA as dr,EH as dt,Ew as ea,bD as ei,lB as en,BS as eo,lF as er,BU as et,nG as f,uw as fa,VE as fi,Gz as fn,sv as fo,MA as fr,TH as ft,KW as g,dw as ga,ME as gi,Rz as gn,ev as go,sA as gr,xH as gt,IW as h,aw as ha,IE as hi,Fz as hn,$_ as ho,fA as hr,yH as ht,yW as i,xw as ia,iD as ii,iB as in,ix as io,bj as ir,kU as it,eG as j,MC as ja,mT as ji,hR as jn,rh as jo,ZO as jr,jV as jt,BW as k,RC as ka,xT as ki,Tz as kn,th as ko,GO as kr,OV as kt,iG as l,hw as la,YE as li,aB as ln,Tv as lo,ej as lr,zH as lt,LW as m,sw as ma,LE as mi,Uz as mn,tv as mo,pA as mr,SH as mt,JW as n,ww as na,sD as ni,Yz as nn,NS as no,CM as nr,jU as nt,qW as o,yw as oa,nD as oi,Qz as on,Dv as oo,_j as or,vU as ot,RW as p,cw as pa,zE as pi,Hz as pn,av as po,NA as pr,wH as pt,KU as q,nC as qa,Fw as qi,QF as qn,Em as qo,DD as qr,NB as qt,DW as r,Sw as ra,cD as ri,rB as rn,bS as ro,cM as rr,AU as rt,aG as s,_w as sa,rD as si,tB as sn,kv as so,rj as sr,lU as st,SW as t,Tw as ta,oD as ti,uB as tn,MS as to,uF as tr,NU as tt,tG as u,mw as ua,GE as ui,oB as un,wv as uo,tj as ur,BH as ut,bW as v,ZC as va,PE as vi,Iz as vn,Y_ as vo,Wk as vr,dH as vt,GW as w,PC as wa,FT as wi,Nz as wn,H_ as wo,gk as wr,nH as wt,HW as x,JC as xa,wE as xi,Az as xn,J_ as xo,wk as xr,sH as xt,wW as y,YC as ya,NE as yi,Ez as yn,q_ as yo,jk as yr,fH as yt,oW as z,lC as za,Gw as zi,sI as zn,Zm as zo,UD as zr,cV as zt};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-CBDbhulC.js";import{Qi as n,Zi as r,ra as i}from"./cells-Cp-G34Rz.js";import{In as a,kt as o,un as s,wt as c}from"./schemas-aTUejmFi.js";import{t as l}from"./compiler-runtime-CYIjoINj.js";import{t as u}from"./isEmpty-BJso7_X0.js";import{et as d}from"./ai-model-dropdown-DCmiuk7x.js";import{g as f}from"./useEventListener-92uWqz-P.js";import{t as p}from"./cn-ldLVeaqm.js";import{t as m}from"./jsx-runtime-B74pBk57.js";import{a as h,i as g,o as _,r as v}from"./config-B-r81uZ6.js";import{t as y}from"./button-Dh8EwhsF.js";import{i as b}from"./strings-CReV1AYG.js";import{t as x}from"./createLucideIcon-B7HeEoG2.js";import{t as S}from"./ban-CwXfMsC1.js";import{t as C}from"./bot-message-square-CGhPjWFf.js";import{a as w}from"./useNumberFormatter-DHJ9s6Vk.js";import{t as T}from"./markdown-renderer-BZKlbm2Q.js";import{p as E,u as D}from"./add-cell-with-ai-R-3DS79K.js";import{t as O}from"./external-link-Bp3BxyRA.js";import{n as k}from"./spinner-Ck-Hgfvj.js";import{l as A}from"./datasource-DrODSIs0.js";import{t as j}from"./RenderHTML-DwhMAd9l.js";var M=x(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),N=x(`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=l(),z=e(t(),1),B=m(),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)(C,{className:`h-3 w-3`}),t[0]=u):u=t[0];let d=o?`Thinking`:`View reasoning`,f=n.length>0&&` (${n.length} chars)`,p;t[1]!==d||t[2]!==f?(p=(0,B.jsx)(_,{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,d,f]})}),t[1]=d,t[2]=f,t[3]=p):p=t[3];let m;t[4]===n?m=t[5]:(m=(0,B.jsx)(g,{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)(T,{content:n})})})}),t[4]=n,t[5]=m);let y;t[6]!==p||t[7]!==m?(y=(0,B.jsxs)(h,{value:`reasoning`,className:`border-0`,children:[p,m]}),t[6]=p,t[7]=m,t[8]=y):y=t[8];let b;return t[9]!==a||t[10]!==l||t[11]!==y?(b=(0,B.jsx)(v,{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=p(`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 m;t[8]===f?m=t[9]:(m=(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]=m);let h;t[10]===r?h=t[11]:(h=(0,B.jsx)(U,{input:r}),t[10]=r,t[11]=h);let g;t[12]!==i.id||t[13]!==a?(g=(0,B.jsx)(y,{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 _;t[15]!==i.id||t[16]!==a?(_=(0,B.jsx)(y,{size:`xs`,onClick:()=>a({id:i.id,approved:!0}),children:`Approve`}),t[15]=i.id,t[16]=a,t[17]=_):_=t[17];let v;t[18]!==_||t[19]!==g?(v=(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[g,_]}),t[18]=_,t[19]=g,t[20]=v):v=t[20];let b;return t[21]!==s||t[22]!==v||t[23]!==l||t[24]!==m||t[25]!==h?(b=(0,B.jsxs)(`div`,{className:s,role:`alertdialog`,"aria-label":l,children:[m,h,v]}),t[21]=s,t[22]=v,t[23]=l,t[24]=m,t[25]=h,t[26]=b):b=t[26],b},G=e=>{let t=(0,R.c)(28),{toolName:n,input:r,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 m;t[3]===s?m=t[4]:(m=p(`rounded-md border border-(--red-6) bg-(--red-2)`,s),t[3]=s,t[4]=m);let h;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>l(K),t[5]=h):h=t[5];let g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,B.jsx)(i,{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=p(`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)(w,{className:x}),t[14]=x,t[15]=S);let C;t[16]!==c||t[17]!==S||t[18]!==y?(C=(0,B.jsxs)(`button`,{type:`button`,onClick:h,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]=C):C=t[19];let T;t[20]!==a||t[21]!==r||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:r}),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]=r,t[22]=c,t[23]=T):T=t[23];let E;return t[24]!==C||t[25]!==T||t[26]!==m?(E=(0,B.jsxs)(`div`,{className:m,children:[C,T]}),t[24]=C,t[25]=T,t[26]=m,t[27]=E):E=t[27],E};function K(e){return!e}function q(e){return e==null||typeof e==`object`&&u(e)}var J=s({status:a().default(`success`),auth_required:o().default(!1),action_url:c(),next_steps:c(),meta:c(),message:a().nullish()}),Y=e=>{let t=(0,R.c)(12),{data:n}=e,i;if(t[0]!==n){let{status:e,auth_required:a,action_url:o,meta:s,next_steps:c,message:l,...u}=n,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)(r,{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]=n,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)(k,{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)(d,{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)(S,{className:`h-3 w-3 text-muted-foreground`}),t[3]=e):e=t[3],e}default:{b(n);let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(A,{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 b(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,d=l===void 0||l,f;t[0]!==d||t[1]!==r?(f=!d&&te.has(r),t[0]=d,t[1]=r,t[2]=f):f=t[2];let m=f,y=`tool-${u}`,b;t[3]===c?b=t[4]:(b=p(`w-full`,c),t[3]=c,t[4]=b);let x;t[5]!==m||t[6]!==r?(x=p(`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`,m?`text-muted-foreground`:re(r)),t[5]=m,t[6]=r,t[7]=x):x=t[7];let S;t[8]!==m||t[9]!==r?(S=(0,B.jsx)(ne,{state:r,interrupted:m}),t[8]=m,t[9]=r,t[10]=S):S=t[10];let C=m?`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)(_,{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)(g,{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)(h,{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)(v,{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 b(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 b(r),null}},ae=({message:e,isStreamingReasoning:t,isLast:r,isActive:i,addToolApprovalResponse:a})=>{return(0,B.jsx)(B.Fragment,{children:e.parts.map((e,t)=>o(e,t))});function o(o,s){if(oe(o))return(0,B.jsx)($,{index:s,toolName:o.type,result:o.output,errorText:o.state===`output-error`?o.errorText:void 0,className:`my-2`,state:o.state,input:o.input,approval:o.approval,onApprove:a,isLive:r,isActive:i},s);if(se(o))return f.debug(`Found data part`,o),null;switch(o.type){case`text`:return o.text.includes(`<marimo-`)?(0,B.jsx)(z.Fragment,{children:j({html:o.text})},s):(0,B.jsx)(T,{content:o.text},s);case`reasoning`:return(0,B.jsx)(V,{reasoning:o.text,index:s,isStreaming:t&&r&&s===(e.parts.length||0)-1},s);case`file`:return(0,B.jsx)(D,{attachment:o},s);case`reasoning-file`:return(0,B.jsx)(D,{attachment:{type:`file`,mediaType:o.mediaType,url:o.url}},s);case`dynamic-tool`:return(0,B.jsx)($,{toolName:o.toolName,result:o.output,errorText:o.state===`output-error`?o.errorText:void 0,state:o.state,input:o.input,approval:o.approval,onApprove:a,isLive:r,isActive:i},s);case`source-document`:return(0,B.jsx)(E,{icon:(0,B.jsx)(n,{className:`h-3 w-3 shrink-0`}),title:o.title,subtitle:o.filename},s);case`source-url`:return(0,B.jsx)(E,{icon:(0,B.jsx)(O,{className:`h-3 w-3 shrink-0`}),title:o.title??o.url,subtitle:o.title?o.url:void 0,href:o.url},s);case`custom`:return(0,B.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:o.kind},s);case`step-start`:return null;default:return b(o),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-CBDbhulC.js";import{$i as n,Qi as r,ia as i}from"./cells-BBhW3FXj.js";import{In as a,kt as o,un as s,wt as c}from"./schemas-aTUejmFi.js";import{t as l}from"./compiler-runtime-CYIjoINj.js";import{t as u}from"./isEmpty-BJso7_X0.js";import{et as d}from"./ai-model-dropdown-CmJEEhSC.js";import{g as f}from"./useEventListener-92uWqz-P.js";import{t as p}from"./cn-ldLVeaqm.js";import{t as m}from"./jsx-runtime-B74pBk57.js";import{a as h,i as g,o as _,r as v}from"./config-B-r81uZ6.js";import{t as y}from"./button-Dh8EwhsF.js";import{i as b}from"./strings-CReV1AYG.js";import{t as x}from"./createLucideIcon-B7HeEoG2.js";import{t as S}from"./ban-CwXfMsC1.js";import{t as C}from"./bot-message-square-CGhPjWFf.js";import{a as w}from"./useNumberFormatter-DHJ9s6Vk.js";import{t as T}from"./markdown-renderer-751VNlrQ.js";import{p as E,u as D}from"./add-cell-with-ai-OQ4sSXg4.js";import{t as O}from"./external-link-Bp3BxyRA.js";import{n as k}from"./spinner-Ck-Hgfvj.js";import{l as A}from"./datasource-B3qF2oaW.js";import{t as j}from"./RenderHTML-DnPB4qpJ.js";var M=x(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),N=x(`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=l(),z=e(t(),1),B=m(),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)(C,{className:`h-3 w-3`}),t[0]=u):u=t[0];let d=o?`Thinking`:`View reasoning`,f=n.length>0&&` (${n.length} chars)`,p;t[1]!==d||t[2]!==f?(p=(0,B.jsx)(_,{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,d,f]})}),t[1]=d,t[2]=f,t[3]=p):p=t[3];let m;t[4]===n?m=t[5]:(m=(0,B.jsx)(g,{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)(T,{content:n})})})}),t[4]=n,t[5]=m);let y;t[6]!==p||t[7]!==m?(y=(0,B.jsxs)(h,{value:`reasoning`,className:`border-0`,children:[p,m]}),t[6]=p,t[7]=m,t[8]=y):y=t[8];let b;return t[9]!==a||t[10]!==l||t[11]!==y?(b=(0,B.jsx)(v,{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=p(`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 m;t[8]===f?m=t[9]:(m=(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]=m);let h;t[10]===r?h=t[11]:(h=(0,B.jsx)(U,{input:r}),t[10]=r,t[11]=h);let g;t[12]!==i.id||t[13]!==a?(g=(0,B.jsx)(y,{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 _;t[15]!==i.id||t[16]!==a?(_=(0,B.jsx)(y,{size:`xs`,onClick:()=>a({id:i.id,approved:!0}),children:`Approve`}),t[15]=i.id,t[16]=a,t[17]=_):_=t[17];let v;t[18]!==_||t[19]!==g?(v=(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[g,_]}),t[18]=_,t[19]=g,t[20]=v):v=t[20];let b;return t[21]!==s||t[22]!==v||t[23]!==l||t[24]!==m||t[25]!==h?(b=(0,B.jsxs)(`div`,{className:s,role:`alertdialog`,"aria-label":l,children:[m,h,v]}),t[21]=s,t[22]=v,t[23]=l,t[24]=m,t[25]=h,t[26]=b):b=t[26],b},G=e=>{let t=(0,R.c)(28),{toolName:n,input:r,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 m;t[3]===s?m=t[4]:(m=p(`rounded-md border border-(--red-6) bg-(--red-2)`,s),t[3]=s,t[4]=m);let h;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>l(K),t[5]=h):h=t[5];let g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,B.jsx)(i,{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=p(`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)(w,{className:x}),t[14]=x,t[15]=S);let C;t[16]!==c||t[17]!==S||t[18]!==y?(C=(0,B.jsxs)(`button`,{type:`button`,onClick:h,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]=C):C=t[19];let T;t[20]!==a||t[21]!==r||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:r}),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]=r,t[22]=c,t[23]=T):T=t[23];let E;return t[24]!==C||t[25]!==T||t[26]!==m?(E=(0,B.jsxs)(`div`,{className:m,children:[C,T]}),t[24]=C,t[25]=T,t[26]=m,t[27]=E):E=t[27],E};function K(e){return!e}function q(e){return e==null||typeof e==`object`&&u(e)}var J=s({status:a().default(`success`),auth_required:o().default(!1),action_url:c(),next_steps:c(),meta:c(),message:a().nullish()}),Y=e=>{let t=(0,R.c)(12),{data:n}=e,i;if(t[0]!==n){let{status:e,auth_required:a,action_url:o,meta:s,next_steps:c,message:l,...u}=n,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)(r,{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]=n,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)(k,{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)(d,{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)(S,{className:`h-3 w-3 text-muted-foreground`}),t[3]=e):e=t[3],e}default:{b(n);let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(A,{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 b(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,d=l===void 0||l,f;t[0]!==d||t[1]!==r?(f=!d&&te.has(r),t[0]=d,t[1]=r,t[2]=f):f=t[2];let m=f,y=`tool-${u}`,b;t[3]===c?b=t[4]:(b=p(`w-full`,c),t[3]=c,t[4]=b);let x;t[5]!==m||t[6]!==r?(x=p(`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`,m?`text-muted-foreground`:re(r)),t[5]=m,t[6]=r,t[7]=x):x=t[7];let S;t[8]!==m||t[9]!==r?(S=(0,B.jsx)(ne,{state:r,interrupted:m}),t[8]=m,t[9]=r,t[10]=S):S=t[10];let C=m?`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)(_,{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)(g,{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)(h,{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)(v,{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 b(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 b(r),null}},ae=({message:e,isStreamingReasoning:t,isLast:r,isActive:i,addToolApprovalResponse:a})=>{return(0,B.jsx)(B.Fragment,{children:e.parts.map((e,t)=>o(e,t))});function o(o,s){if(oe(o))return(0,B.jsx)($,{index:s,toolName:o.type,result:o.output,errorText:o.state===`output-error`?o.errorText:void 0,className:`my-2`,state:o.state,input:o.input,approval:o.approval,onApprove:a,isLive:r,isActive:i},s);if(se(o))return f.debug(`Found data part`,o),null;switch(o.type){case`text`:return o.text.includes(`<marimo-`)?(0,B.jsx)(z.Fragment,{children:j({html:o.text})},s):(0,B.jsx)(T,{content:o.text},s);case`reasoning`:return(0,B.jsx)(V,{reasoning:o.text,index:s,isStreaming:t&&r&&s===(e.parts.length||0)-1},s);case`file`:return(0,B.jsx)(D,{attachment:o},s);case`reasoning-file`:return(0,B.jsx)(D,{attachment:{type:`file`,mediaType:o.mediaType,url:o.url}},s);case`dynamic-tool`:return(0,B.jsx)($,{toolName:o.toolName,result:o.output,errorText:o.state===`output-error`?o.errorText:void 0,state:o.state,input:o.input,approval:o.approval,onApprove:a,isLive:r,isActive:i},s);case`source-document`:return(0,B.jsx)(E,{icon:(0,B.jsx)(n,{className:`h-3 w-3 shrink-0`}),title:o.title,subtitle:o.filename},s);case`source-url`:return(0,B.jsx)(E,{icon:(0,B.jsx)(O,{className:`h-3 w-3 shrink-0`}),title:o.title??o.url,subtitle:o.title?o.url:void 0,href:o.url},s);case`custom`:return(0,B.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:o.kind},s);case`step-start`:return null;default:return b(o),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-xfs0Sn4r.js";import{t as o}from"./react-CBDbhulC.js";import{D as s,Er as c,Hi as l,_n as u,gn as d,mn as f,na as p,rr as m}from"./cells-Cp-G34Rz.js";import{t as h}from"./compiler-runtime-CYIjoINj.js";import{a as g,n as _}from"./utils-D5Ywm7-q.js";import{c as v,k as y,r as b,t as x}from"./ai-model-dropdown-DCmiuk7x.js";import{g as S,o as C}from"./useEventListener-92uWqz-P.js";import{N as w,o as T}from"./config-BlNM0caL.js";import{t as E}from"./switch-DjXr9Y9D.js";import{t as D}from"./cn-ldLVeaqm.js";import{t as O}from"./jsx-runtime-B74pBk57.js";import{S as k,T as A,_ as j,w as M,x as N,y as P}from"./fullscreen-BH2jz-F4.js";import{u as F}from"./menu-items-BSRA2YI9.js";import{t as ee}from"./config-B-r81uZ6.js";import{a as te,i as I,m as L,n as ne,r as re,s as ie,t as ae}from"./select-nLt2y0Sw.js";import{i as oe,t as R}from"./tooltip-BUtPzKB4.js";import{t as z}from"./button-Dh8EwhsF.js";import{r as se}from"./requests-C6_IaFh7.js";import{t as ce}from"./createLucideIcon-B7HeEoG2.js";import{t as le}from"./scroll-to-bottom-button-DufiYUD7.js";import{t as ue}from"./arrow-right-CMihiUEa.js";import{t as B}from"./bot-message-square-CGhPjWFf.js";import{i as de,n as fe,r as pe,t as me}from"./chat-display-Bu405iyc.js";import{B as he,C as ge,D as V,E as _e,N as ve,R as ye,S as be,U as xe,_ as Se,b as Ce,c as we,d as Te,f as Ee,g as De,h as Oe,k as ke,l as H,m as Ae,n as U,u as je,v as Me,w as Ne,x as Pe,y as Fe,z as Ie}from"./add-cell-with-ai-R-3DS79K.js";import{t as Le}from"./code-CF0HKE9K.js";import{t as Re}from"./hat-glasses-C8LSY3HT.js";import{b as ze,p as Be}from"./write-secret-modal-D6zoZgLY.js";import{n as Ve}from"./spinner-Ck-Hgfvj.js";import{t as He}from"./message-circle-BQB1AIAg.js";import{t as Ue}from"./plus-C4J9gIE1.js";import{Wt as W,r as G}from"./input-DEbY281O.js";import{t as We}from"./settings-C-cYas75.js";import{t as Ge}from"./uuid-k9DpjH68.js";import{t as Ke}from"./context-Do8M9TDF.js";import{s as qe}from"./dates-B58T85Jq.js";import{t as Je}from"./copy-icon-z8fuTE3w.js";import{i as Ye,o as Xe,r as Ze,t as Qe}from"./state-B6AklCzD.js";import{n as $e}from"./error-banner-Dw5YY9wq.js";import{t as K}from"./empty-state-kWyb5dCS.js";import{t as et}from"./pair-with-agent-modal-CbUFKJHP.js";var q=e(o(),1),J=O();function tt(e,t){return q.useReducer((e,n)=>t[e][n]??e,e)}var nt=`ScrollArea`,[rt,it]=M(nt),[at,Y]=rt(nt),ot=q.forwardRef((e,t)=>{let{__scopeScrollArea:n,type:r=`hover`,dir:i,scrollHideDelay:a=600,...o}=e,[s,c]=q.useState(null),[l,u]=q.useState(null),[d,f]=q.useState(null),[p,m]=q.useState(null),[h,g]=q.useState(null),[_,v]=q.useState(0),[y,b]=q.useState(0),[x,S]=q.useState(!1),[w,T]=q.useState(!1),E=C(t,e=>c(e)),D=F(i);return(0,J.jsx)(at,{scope:n,type:r,dir:D,scrollHideDelay:a,scrollArea:s,viewport:l,onViewportChange:u,content:d,onContentChange:f,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:x,onScrollbarXEnabledChange:S,scrollbarY:h,onScrollbarYChange:g,scrollbarYEnabled:w,onScrollbarYEnabledChange:T,onCornerWidthChange:v,onCornerHeightChange:b,children:(0,J.jsx)(A.div,{dir:D,...o,ref:E,style:{position:`relative`,"--radix-scroll-area-corner-width":_+`px`,"--radix-scroll-area-corner-height":y+`px`,...e.style}})})});ot.displayName=nt;var st=`ScrollAreaViewport`,ct=q.forwardRef((e,t)=>{let{__scopeScrollArea:n,children:r,nonce:i,...a}=e,o=Y(st,n),s=q.useRef(null),c=C(t,s,o.onViewportChange);return(0,J.jsxs)(J.Fragment,{children:[(0,J.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:i}),(0,J.jsx)(A.div,{"data-radix-scroll-area-viewport":``,...a,ref:c,style:{overflowX:o.scrollbarXEnabled?`scroll`:`hidden`,overflowY:o.scrollbarYEnabled?`scroll`:`hidden`,...e.style},children:(0,J.jsx)(`div`,{ref:o.onContentChange,style:{minWidth:`100%`,display:`table`},children:r})})]})});ct.displayName=st;var X=`ScrollAreaScrollbar`,Z=q.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=Y(X,e.__scopeScrollArea),{onScrollbarXEnabledChange:a,onScrollbarYEnabledChange:o}=i,s=e.orientation===`horizontal`;return q.useEffect(()=>(s?a(!0):o(!0),()=>{s?a(!1):o(!1)}),[s,a,o]),i.type===`hover`?(0,J.jsx)(lt,{...r,ref:t,forceMount:n}):i.type===`scroll`?(0,J.jsx)(ut,{...r,ref:t,forceMount:n}):i.type===`auto`?(0,J.jsx)(dt,{...r,ref:t,forceMount:n}):i.type===`always`?(0,J.jsx)(ft,{...r,ref:t}):null});Z.displayName=X;var lt=q.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=Y(X,e.__scopeScrollArea),[a,o]=q.useState(!1);return q.useEffect(()=>{let e=i.scrollArea,t=0;if(e){let n=()=>{window.clearTimeout(t),o(!0)},r=()=>{t=window.setTimeout(()=>o(!1),i.scrollHideDelay)};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,J.jsx)(P,{present:n||a,children:(0,J.jsx)(dt,{"data-state":a?`visible`:`hidden`,...r,ref:t})})}),ut=q.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=Y(X,e.__scopeScrollArea),a=e.orientation===`horizontal`,o=Mt(()=>c(`SCROLL_END`),100),[s,c]=tt(`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 q.useEffect(()=>{if(s===`idle`){let e=window.setTimeout(()=>c(`HIDE`),i.scrollHideDelay);return()=>window.clearTimeout(e)}},[s,i.scrollHideDelay,c]),q.useEffect(()=>{let e=i.viewport,t=a?`scrollLeft`:`scrollTop`;if(e){let n=e[t],r=()=>{let r=e[t];n!==r&&(c(`SCROLL`),o()),n=r};return e.addEventListener(`scroll`,r),()=>e.removeEventListener(`scroll`,r)}},[i.viewport,a,c,o]),(0,J.jsx)(P,{present:n||s!==`hidden`,children:(0,J.jsx)(ft,{"data-state":s===`hidden`?`hidden`:`visible`,...r,ref:t,onPointerEnter:k(e.onPointerEnter,()=>c(`POINTER_ENTER`)),onPointerLeave:k(e.onPointerLeave,()=>c(`POINTER_LEAVE`))})})}),dt=q.forwardRef((e,t)=>{let n=Y(X,e.__scopeScrollArea),{forceMount:r,...i}=e,[a,o]=q.useState(!1),s=e.orientation===`horizontal`,c=Mt(()=>{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,J.jsx)(P,{present:r||a,children:(0,J.jsx)(ft,{"data-state":a?`visible`:`hidden`,...i,ref:t})})}),ft=q.forwardRef((e,t)=>{let{orientation:n=`vertical`,...r}=e,i=Y(X,e.__scopeScrollArea),a=q.useRef(null),o=q.useRef(0),[s,c]=q.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),l=Tt(s.viewport,s.content),u={...r,sizes:s,onSizesChange:c,hasThumb:l>0&&l<1,onThumbChange:e=>a.current=e,onThumbPointerUp:()=>o.current=0,onThumbPointerDown:e=>o.current=e};function d(e,t){return Dt(e,o.current,s,t)}return n===`horizontal`?(0,J.jsx)(pt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollLeft,t=Ot(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,J.jsx)(mt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollTop,t=Ot(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}),pt=q.forwardRef((e,t)=>{let{sizes:n,onSizesChange:r,...i}=e,a=Y(X,e.__scopeScrollArea),[o,s]=q.useState(),c=q.useRef(null),l=C(t,c,a.onScrollbarXChange);return q.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,J.jsx)(_t,{"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":Et(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),At(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:wt(o.paddingLeft),paddingEnd:wt(o.paddingRight)}})}})}),mt=q.forwardRef((e,t)=>{let{sizes:n,onSizesChange:r,...i}=e,a=Y(X,e.__scopeScrollArea),[o,s]=q.useState(),c=q.useRef(null),l=C(t,c,a.onScrollbarYChange);return q.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,J.jsx)(_t,{"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":Et(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),At(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:wt(o.paddingTop),paddingEnd:wt(o.paddingBottom)}})}})}),[ht,gt]=rt(X),_t=q.forwardRef((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=Y(X,n),[m,h]=q.useState(null),g=C(t,e=>h(e)),_=q.useRef(null),v=q.useRef(``),y=p.viewport,b=r.content-r.viewport,x=j(u),S=j(c),w=Mt(d,10);function T(e){if(_.current){let t=e.clientX-_.current.left,n=e.clientY-_.current.top;l({x:t,y:n})}}return q.useEffect(()=>{let e=e=>{let t=e.target;m?.contains(t)&&x(e,b)};return document.addEventListener(`wheel`,e,{passive:!1}),()=>document.removeEventListener(`wheel`,e,{passive:!1})},[y,m,b,x]),q.useEffect(S,[r,S]),Q(m,w),Q(p.content,w),(0,J.jsx)(ht,{scope:n,scrollbar:m,hasThumb:i,onThumbChange:j(a),onThumbPointerUp:j(o),onThumbPositionChange:S,onThumbPointerDown:j(s),children:(0,J.jsx)(A.div,{...f,ref:g,style:{position:`absolute`,...f.style},onPointerDown:k(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`),T(e))}),onPointerMove:k(e.onPointerMove,T),onPointerUp:k(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})})})}),vt=`ScrollAreaThumb`,yt=q.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=gt(vt,e.__scopeScrollArea);return(0,J.jsx)(P,{present:n||i.hasThumb,children:(0,J.jsx)(bt,{ref:t,...r})})}),bt=q.forwardRef((e,t)=>{let{__scopeScrollArea:n,style:r,...i}=e,a=Y(vt,n),o=gt(vt,n),{onThumbPositionChange:s}=o,c=C(t,e=>o.onThumbChange(e)),l=q.useRef(void 0),u=Mt(()=>{l.current&&=(l.current(),void 0)},100);return q.useEffect(()=>{let e=a.viewport;if(e){let t=()=>{if(u(),!l.current){let t=jt(e,s);l.current=t,s()}};return s(),e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)}},[a.viewport,u,s]),(0,J.jsx)(A.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:k(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:k(e.onPointerUp,o.onThumbPointerUp)})});yt.displayName=vt;var xt=`ScrollAreaCorner`,St=q.forwardRef((e,t)=>{let n=Y(xt,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!==`scroll`&&r?(0,J.jsx)(Ct,{...e,ref:t}):null});St.displayName=xt;var Ct=q.forwardRef((e,t)=>{let{__scopeScrollArea:n,...r}=e,i=Y(xt,n),[a,o]=q.useState(0),[s,c]=q.useState(0),l=!!(a&&s);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)}),l?(0,J.jsx)(A.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});function wt(e){return e?parseInt(e,10):0}function Tt(e,t){let n=e/t;return isNaN(n)?0:n}function Et(e){let t=Tt(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function Dt(e,t,n,r=`ltr`){let i=Et(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 kt([c,l],d)(e)}function Ot(e,t,n=`ltr`){let r=Et(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=L(e,c);return kt([0,o],[0,s])(l)}function kt(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])}}function At(e,t){return e>0&&e<t}var jt=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return(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)})(),()=>window.cancelAnimationFrame(r)};function Mt(e,t){let n=j(e),r=q.useRef(0);return q.useEffect(()=>()=>window.clearTimeout(r.current),[]),q.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Q(e,t){let n=j(t);N(()=>{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])}var Nt=ot,Pt=ct,Ft=St,It=ce(`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`}]]),Lt=ce(`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`}]]),$=h(),Rt=({chatState:e,chatId:t,messages:n})=>{if(!t)return S.warn(`No active chat`),e;let r=e.chats.get(t);if(!r)return S.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}},zt=class extends he{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)}}))}},Bt=q.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=D(`relative overflow-hidden`,i),n[4]=i,n[5]=o);let s;n[6]===r?s=n[7]:(s=(0,J.jsx)(Pt,{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,J.jsx)(Vt,{}),l=(0,J.jsx)(Ft,{}),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,J.jsxs)(Nt,{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});Bt.displayName=Nt.displayName;var Vt=q.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=D(`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,J.jsx)(yt,{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,J.jsx)(Z,{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});Vt.displayName=Z.displayName;var Ht=[{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}],Ut=e=>{let t=Date.now(),n=Ht.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)},Wt=e=>{let t=(0,$.c)(36),{activeChatId:n,setActiveChat:i}=e,a=r(Ye),{locale:o}=Ke(),[s,c]=(0,q.useState)(``),l;t[0]===a.chats?l=t[1]:(l=[...a.chats.values()].toSorted(Gt),t[0]=a.chats,t[1]=l);let m=l,h;bb0:{if(!s.trim()){h=m;break bb0}let e;if(t[2]!==m||t[3]!==s){let n;t[5]===s?n=t[6]:(n=e=>e.title.toLowerCase().includes(s.toLowerCase()),t[5]=s,t[6]=n),e=m.filter(n),t[2]=m,t[3]=s,t[4]=e}else e=t[4];h=e}let g=h,_;t[7]===g?_=t[8]:(_=Ut(g),t[7]=g,t[8]=_);let v=_,y;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,J.jsx)(R,{content:`Previous chats`,children:(0,J.jsx)(u,{asChild:!0,children:(0,J.jsx)(z,{variant:`text`,size:`icon`,children:(0,J.jsx)(p,{className:`h-4 w-4`})})})}),t[9]=y):y=t[9];let b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b=e=>c(e.target.value),t[10]=b):b=t[10];let x;t[11]===s?x=t[12]:(x=(0,J.jsx)(`div`,{className:`pt-3 px-3 w-full`,children:(0,J.jsx)(G,{placeholder:`Search chat history...`,value:s,onChange:b,className:`text-xs`})}),t[11]=s,t[12]=x);let S;t[13]===m.length?S=t[14]:(S=m.length===0&&(0,J.jsx)(K,{title:`No chats yet`,description:`Start a new chat to get started`,icon:(0,J.jsx)(B,{})}),t[13]=m.length,t[14]=S);let C;t[15]!==m.length||t[16]!==g.length||t[17]!==s?(C=g.length===0&&s&&m.length>0&&(0,J.jsx)(K,{title:`No chats found`,description:`No chats match "${s}"`,icon:(0,J.jsx)(W,{})}),t[15]=m.length,t[16]=g.length,t[17]=s,t[18]=C):C=t[18];let w;if(t[19]!==n||t[20]!==v||t[21]!==o||t[22]!==i){let e;t[24]!==n||t[25]!==v.length||t[26]!==o||t[27]!==i?(e=(e,t)=>(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`div`,{className:`text-xs px-1 text-muted-foreground/60`,children:e.label}),(0,J.jsx)(`div`,{children:e.chats.map(e=>(0,J.jsxs)(`button`,{className:D(`w-full p-1 rounded-md cursor-pointer text-left flex items-center justify-between`,e.id===n&&`bg-accent`,e.id!==n&&`hover:bg-muted/20`),onClick:()=>{i(e.id)},type:`button`,children:[(0,J.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,J.jsx)(`div`,{className:`text-sm truncate`,children:e.title})}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground/60 ml-2 shrink-0`,children:qe(e.updatedAt,o)})]},e.id))}),t!==v.length-1&&(0,J.jsx)(`hr`,{})]},e.label),t[24]=n,t[25]=v.length,t[26]=o,t[27]=i,t[28]=e):e=t[28],w=v.map(e),t[19]=n,t[20]=v,t[21]=o,t[22]=i,t[23]=w}else w=t[23];let T;t[29]!==S||t[30]!==C||t[31]!==w?(T=(0,J.jsx)(Bt,{className:`h-[450px] p-2`,children:(0,J.jsxs)(`div`,{className:`space-y-3`,children:[S,C,w]})}),t[29]=S,t[30]=C,t[31]=w,t[32]=T):T=t[32];let E;return t[33]!==T||t[34]!==x?(E=(0,J.jsxs)(f,{children:[y,(0,J.jsxs)(d,{className:`w-[480px] p-0`,align:`start`,side:`right`,children:[x,T]})]}),t[33]=T,t[34]=x,t[35]=E):E=t[35],E};function Gt(e,t){return t.updatedAt-e.updatedAt}var Kt=()=>{let e=(0,$.c)(17),[n,r]=t(Ze),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=D(`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,J.jsx)(Lt,{className:`h-3.5 w-3.5`}),e[2]=l):l=e[2];let p;e[3]!==a||e[4]!==o||e[5]!==c?(p=(0,J.jsx)(u,{asChild:!0,children:(0,J.jsx)(z,{"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]=p):p=e[6];let m;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(`span`,{className:`text-sm font-semibold`,children:`Web search`}),e[7]=m):m=e[7];let h;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[m,(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Search the web when the model supports it.`,` `,(0,J.jsx)(Be,{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,J.jsx)(d,{className:`w-76 p-3`,align:`start`,side:`top`,children:(0,J.jsxs)(`label`,{htmlFor:`web-search-toggle`,className:`flex items-start justify-between gap-3 cursor-pointer`,children:[h,(0,J.jsx)(E,{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]!==p||e[15]!==_?(v=(0,J.jsxs)(f,{children:[p,_]}),e[14]=p,e[15]=_,e[16]=v):v=e[16],v};function qt(){return Ge()}function Jt(e){let t=(0,$.c)(4),[n,r]=(0,q.useState)(qt),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>r(qt()),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 Yt=`manual`,Xt=(0,q.memo)(e=>{let t=(0,$.c)(18),{message:n}=e,r;t[0]===n.parts?r=t[1]:(r=n.parts.filter(an).map(on).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-xfs0Sn4r.js";import{t as o}from"./react-CBDbhulC.js";import{D as s,Dr as c,Ui as l,_n as u,hn as d,ir as f,ra as p,vn as m}from"./cells-BBhW3FXj.js";import{t as h}from"./compiler-runtime-CYIjoINj.js";import{a as g,n as _}from"./utils-D5Ywm7-q.js";import{c as v,k as y,r as b,t as x}from"./ai-model-dropdown-CmJEEhSC.js";import{g as S,o as C}from"./useEventListener-92uWqz-P.js";import{N as w,o as T}from"./config-BlNM0caL.js";import{t as E}from"./switch-DjXr9Y9D.js";import{t as D}from"./cn-ldLVeaqm.js";import{t as O}from"./jsx-runtime-B74pBk57.js";import{S as k,T as A,_ as j,w as M,x as N,y as P}from"./fullscreen-BH2jz-F4.js";import{u as F}from"./menu-items-BSRA2YI9.js";import{t as ee}from"./config-B-r81uZ6.js";import{a as te,i as I,m as L,n as ne,r as re,s as ie,t as ae}from"./select-nLt2y0Sw.js";import{i as oe,t as R}from"./tooltip-BUtPzKB4.js";import{t as z}from"./button-Dh8EwhsF.js";import{r as se}from"./requests-C6_IaFh7.js";import{t as ce}from"./createLucideIcon-B7HeEoG2.js";import{t as le}from"./scroll-to-bottom-button-DufiYUD7.js";import{t as ue}from"./arrow-right-CMihiUEa.js";import{t as B}from"./bot-message-square-CGhPjWFf.js";import{i as de,n as fe,r as pe,t as me}from"./chat-display-CIpYPLlF.js";import{B as he,C as ge,D as V,E as _e,N as ve,R as ye,S as be,U as xe,_ as Se,b as Ce,c as we,d as Te,f as Ee,g as De,h as Oe,k as ke,l as H,m as Ae,n as U,u as je,v as Me,w as Ne,x as Pe,y as Fe,z as Ie}from"./add-cell-with-ai-OQ4sSXg4.js";import{t as Le}from"./code-CF0HKE9K.js";import{t as Re}from"./hat-glasses-C8LSY3HT.js";import{b as ze,p as Be}from"./write-secret-modal-D6zoZgLY.js";import{n as Ve}from"./spinner-Ck-Hgfvj.js";import{t as He}from"./message-circle-BQB1AIAg.js";import{t as Ue}from"./plus-C4J9gIE1.js";import{Wt as W,r as G}from"./input-DEbY281O.js";import{t as We}from"./settings-C-cYas75.js";import{t as Ge}from"./uuid-k9DpjH68.js";import{t as Ke}from"./context-Do8M9TDF.js";import{s as qe}from"./dates-B58T85Jq.js";import{t as Je}from"./copy-icon-z8fuTE3w.js";import{i as Ye,o as Xe,r as Ze,t as Qe}from"./state-DOrY1Jyf.js";import{n as $e}from"./error-banner-Dw5YY9wq.js";import{t as K}from"./empty-state-kWyb5dCS.js";import{t as et}from"./pair-with-agent-modal-CbUFKJHP.js";var q=e(o(),1),J=O();function tt(e,t){return q.useReducer((e,n)=>t[e][n]??e,e)}var nt=`ScrollArea`,[rt,it]=M(nt),[at,Y]=rt(nt),ot=q.forwardRef((e,t)=>{let{__scopeScrollArea:n,type:r=`hover`,dir:i,scrollHideDelay:a=600,...o}=e,[s,c]=q.useState(null),[l,u]=q.useState(null),[d,f]=q.useState(null),[p,m]=q.useState(null),[h,g]=q.useState(null),[_,v]=q.useState(0),[y,b]=q.useState(0),[x,S]=q.useState(!1),[w,T]=q.useState(!1),E=C(t,e=>c(e)),D=F(i);return(0,J.jsx)(at,{scope:n,type:r,dir:D,scrollHideDelay:a,scrollArea:s,viewport:l,onViewportChange:u,content:d,onContentChange:f,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:x,onScrollbarXEnabledChange:S,scrollbarY:h,onScrollbarYChange:g,scrollbarYEnabled:w,onScrollbarYEnabledChange:T,onCornerWidthChange:v,onCornerHeightChange:b,children:(0,J.jsx)(A.div,{dir:D,...o,ref:E,style:{position:`relative`,"--radix-scroll-area-corner-width":_+`px`,"--radix-scroll-area-corner-height":y+`px`,...e.style}})})});ot.displayName=nt;var st=`ScrollAreaViewport`,ct=q.forwardRef((e,t)=>{let{__scopeScrollArea:n,children:r,nonce:i,...a}=e,o=Y(st,n),s=q.useRef(null),c=C(t,s,o.onViewportChange);return(0,J.jsxs)(J.Fragment,{children:[(0,J.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:i}),(0,J.jsx)(A.div,{"data-radix-scroll-area-viewport":``,...a,ref:c,style:{overflowX:o.scrollbarXEnabled?`scroll`:`hidden`,overflowY:o.scrollbarYEnabled?`scroll`:`hidden`,...e.style},children:(0,J.jsx)(`div`,{ref:o.onContentChange,style:{minWidth:`100%`,display:`table`},children:r})})]})});ct.displayName=st;var X=`ScrollAreaScrollbar`,Z=q.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=Y(X,e.__scopeScrollArea),{onScrollbarXEnabledChange:a,onScrollbarYEnabledChange:o}=i,s=e.orientation===`horizontal`;return q.useEffect(()=>(s?a(!0):o(!0),()=>{s?a(!1):o(!1)}),[s,a,o]),i.type===`hover`?(0,J.jsx)(lt,{...r,ref:t,forceMount:n}):i.type===`scroll`?(0,J.jsx)(ut,{...r,ref:t,forceMount:n}):i.type===`auto`?(0,J.jsx)(dt,{...r,ref:t,forceMount:n}):i.type===`always`?(0,J.jsx)(ft,{...r,ref:t}):null});Z.displayName=X;var lt=q.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=Y(X,e.__scopeScrollArea),[a,o]=q.useState(!1);return q.useEffect(()=>{let e=i.scrollArea,t=0;if(e){let n=()=>{window.clearTimeout(t),o(!0)},r=()=>{t=window.setTimeout(()=>o(!1),i.scrollHideDelay)};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,J.jsx)(P,{present:n||a,children:(0,J.jsx)(dt,{"data-state":a?`visible`:`hidden`,...r,ref:t})})}),ut=q.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=Y(X,e.__scopeScrollArea),a=e.orientation===`horizontal`,o=Mt(()=>c(`SCROLL_END`),100),[s,c]=tt(`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 q.useEffect(()=>{if(s===`idle`){let e=window.setTimeout(()=>c(`HIDE`),i.scrollHideDelay);return()=>window.clearTimeout(e)}},[s,i.scrollHideDelay,c]),q.useEffect(()=>{let e=i.viewport,t=a?`scrollLeft`:`scrollTop`;if(e){let n=e[t],r=()=>{let r=e[t];n!==r&&(c(`SCROLL`),o()),n=r};return e.addEventListener(`scroll`,r),()=>e.removeEventListener(`scroll`,r)}},[i.viewport,a,c,o]),(0,J.jsx)(P,{present:n||s!==`hidden`,children:(0,J.jsx)(ft,{"data-state":s===`hidden`?`hidden`:`visible`,...r,ref:t,onPointerEnter:k(e.onPointerEnter,()=>c(`POINTER_ENTER`)),onPointerLeave:k(e.onPointerLeave,()=>c(`POINTER_LEAVE`))})})}),dt=q.forwardRef((e,t)=>{let n=Y(X,e.__scopeScrollArea),{forceMount:r,...i}=e,[a,o]=q.useState(!1),s=e.orientation===`horizontal`,c=Mt(()=>{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,J.jsx)(P,{present:r||a,children:(0,J.jsx)(ft,{"data-state":a?`visible`:`hidden`,...i,ref:t})})}),ft=q.forwardRef((e,t)=>{let{orientation:n=`vertical`,...r}=e,i=Y(X,e.__scopeScrollArea),a=q.useRef(null),o=q.useRef(0),[s,c]=q.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),l=Tt(s.viewport,s.content),u={...r,sizes:s,onSizesChange:c,hasThumb:l>0&&l<1,onThumbChange:e=>a.current=e,onThumbPointerUp:()=>o.current=0,onThumbPointerDown:e=>o.current=e};function d(e,t){return Dt(e,o.current,s,t)}return n===`horizontal`?(0,J.jsx)(pt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollLeft,t=Ot(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,J.jsx)(mt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollTop,t=Ot(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}),pt=q.forwardRef((e,t)=>{let{sizes:n,onSizesChange:r,...i}=e,a=Y(X,e.__scopeScrollArea),[o,s]=q.useState(),c=q.useRef(null),l=C(t,c,a.onScrollbarXChange);return q.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,J.jsx)(_t,{"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":Et(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),At(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:wt(o.paddingLeft),paddingEnd:wt(o.paddingRight)}})}})}),mt=q.forwardRef((e,t)=>{let{sizes:n,onSizesChange:r,...i}=e,a=Y(X,e.__scopeScrollArea),[o,s]=q.useState(),c=q.useRef(null),l=C(t,c,a.onScrollbarYChange);return q.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,J.jsx)(_t,{"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":Et(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),At(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:wt(o.paddingTop),paddingEnd:wt(o.paddingBottom)}})}})}),[ht,gt]=rt(X),_t=q.forwardRef((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=Y(X,n),[m,h]=q.useState(null),g=C(t,e=>h(e)),_=q.useRef(null),v=q.useRef(``),y=p.viewport,b=r.content-r.viewport,x=j(u),S=j(c),w=Mt(d,10);function T(e){if(_.current){let t=e.clientX-_.current.left,n=e.clientY-_.current.top;l({x:t,y:n})}}return q.useEffect(()=>{let e=e=>{let t=e.target;m?.contains(t)&&x(e,b)};return document.addEventListener(`wheel`,e,{passive:!1}),()=>document.removeEventListener(`wheel`,e,{passive:!1})},[y,m,b,x]),q.useEffect(S,[r,S]),Q(m,w),Q(p.content,w),(0,J.jsx)(ht,{scope:n,scrollbar:m,hasThumb:i,onThumbChange:j(a),onThumbPointerUp:j(o),onThumbPositionChange:S,onThumbPointerDown:j(s),children:(0,J.jsx)(A.div,{...f,ref:g,style:{position:`absolute`,...f.style},onPointerDown:k(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`),T(e))}),onPointerMove:k(e.onPointerMove,T),onPointerUp:k(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})})})}),vt=`ScrollAreaThumb`,yt=q.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=gt(vt,e.__scopeScrollArea);return(0,J.jsx)(P,{present:n||i.hasThumb,children:(0,J.jsx)(bt,{ref:t,...r})})}),bt=q.forwardRef((e,t)=>{let{__scopeScrollArea:n,style:r,...i}=e,a=Y(vt,n),o=gt(vt,n),{onThumbPositionChange:s}=o,c=C(t,e=>o.onThumbChange(e)),l=q.useRef(void 0),u=Mt(()=>{l.current&&=(l.current(),void 0)},100);return q.useEffect(()=>{let e=a.viewport;if(e){let t=()=>{if(u(),!l.current){let t=jt(e,s);l.current=t,s()}};return s(),e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)}},[a.viewport,u,s]),(0,J.jsx)(A.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:k(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:k(e.onPointerUp,o.onThumbPointerUp)})});yt.displayName=vt;var xt=`ScrollAreaCorner`,St=q.forwardRef((e,t)=>{let n=Y(xt,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!==`scroll`&&r?(0,J.jsx)(Ct,{...e,ref:t}):null});St.displayName=xt;var Ct=q.forwardRef((e,t)=>{let{__scopeScrollArea:n,...r}=e,i=Y(xt,n),[a,o]=q.useState(0),[s,c]=q.useState(0),l=!!(a&&s);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)}),l?(0,J.jsx)(A.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});function wt(e){return e?parseInt(e,10):0}function Tt(e,t){let n=e/t;return isNaN(n)?0:n}function Et(e){let t=Tt(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function Dt(e,t,n,r=`ltr`){let i=Et(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 kt([c,l],d)(e)}function Ot(e,t,n=`ltr`){let r=Et(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=L(e,c);return kt([0,o],[0,s])(l)}function kt(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])}}function At(e,t){return e>0&&e<t}var jt=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return(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)})(),()=>window.cancelAnimationFrame(r)};function Mt(e,t){let n=j(e),r=q.useRef(0);return q.useEffect(()=>()=>window.clearTimeout(r.current),[]),q.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Q(e,t){let n=j(t);N(()=>{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])}var Nt=ot,Pt=ct,Ft=St,It=ce(`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`}]]),Lt=ce(`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`}]]),$=h(),Rt=({chatState:e,chatId:t,messages:n})=>{if(!t)return S.warn(`No active chat`),e;let r=e.chats.get(t);if(!r)return S.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}},zt=class extends he{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)}}))}},Bt=q.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=D(`relative overflow-hidden`,i),n[4]=i,n[5]=o);let s;n[6]===r?s=n[7]:(s=(0,J.jsx)(Pt,{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,J.jsx)(Vt,{}),l=(0,J.jsx)(Ft,{}),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,J.jsxs)(Nt,{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});Bt.displayName=Nt.displayName;var Vt=q.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=D(`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,J.jsx)(yt,{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,J.jsx)(Z,{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});Vt.displayName=Z.displayName;var Ht=[{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}],Ut=e=>{let t=Date.now(),n=Ht.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)},Wt=e=>{let t=(0,$.c)(36),{activeChatId:n,setActiveChat:i}=e,a=r(Ye),{locale:o}=Ke(),[s,c]=(0,q.useState)(``),l;t[0]===a.chats?l=t[1]:(l=[...a.chats.values()].toSorted(Gt),t[0]=a.chats,t[1]=l);let f=l,h;bb0:{if(!s.trim()){h=f;break bb0}let e;if(t[2]!==f||t[3]!==s){let n;t[5]===s?n=t[6]:(n=e=>e.title.toLowerCase().includes(s.toLowerCase()),t[5]=s,t[6]=n),e=f.filter(n),t[2]=f,t[3]=s,t[4]=e}else e=t[4];h=e}let g=h,_;t[7]===g?_=t[8]:(_=Ut(g),t[7]=g,t[8]=_);let v=_,y;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,J.jsx)(R,{content:`Previous chats`,children:(0,J.jsx)(m,{asChild:!0,children:(0,J.jsx)(z,{variant:`text`,size:`icon`,children:(0,J.jsx)(p,{className:`h-4 w-4`})})})}),t[9]=y):y=t[9];let b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b=e=>c(e.target.value),t[10]=b):b=t[10];let x;t[11]===s?x=t[12]:(x=(0,J.jsx)(`div`,{className:`pt-3 px-3 w-full`,children:(0,J.jsx)(G,{placeholder:`Search chat history...`,value:s,onChange:b,className:`text-xs`})}),t[11]=s,t[12]=x);let S;t[13]===f.length?S=t[14]:(S=f.length===0&&(0,J.jsx)(K,{title:`No chats yet`,description:`Start a new chat to get started`,icon:(0,J.jsx)(B,{})}),t[13]=f.length,t[14]=S);let C;t[15]!==f.length||t[16]!==g.length||t[17]!==s?(C=g.length===0&&s&&f.length>0&&(0,J.jsx)(K,{title:`No chats found`,description:`No chats match "${s}"`,icon:(0,J.jsx)(W,{})}),t[15]=f.length,t[16]=g.length,t[17]=s,t[18]=C):C=t[18];let w;if(t[19]!==n||t[20]!==v||t[21]!==o||t[22]!==i){let e;t[24]!==n||t[25]!==v.length||t[26]!==o||t[27]!==i?(e=(e,t)=>(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`div`,{className:`text-xs px-1 text-muted-foreground/60`,children:e.label}),(0,J.jsx)(`div`,{children:e.chats.map(e=>(0,J.jsxs)(`button`,{className:D(`w-full p-1 rounded-md cursor-pointer text-left flex items-center justify-between`,e.id===n&&`bg-accent`,e.id!==n&&`hover:bg-muted/20`),onClick:()=>{i(e.id)},type:`button`,children:[(0,J.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,J.jsx)(`div`,{className:`text-sm truncate`,children:e.title})}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground/60 ml-2 shrink-0`,children:qe(e.updatedAt,o)})]},e.id))}),t!==v.length-1&&(0,J.jsx)(`hr`,{})]},e.label),t[24]=n,t[25]=v.length,t[26]=o,t[27]=i,t[28]=e):e=t[28],w=v.map(e),t[19]=n,t[20]=v,t[21]=o,t[22]=i,t[23]=w}else w=t[23];let T;t[29]!==S||t[30]!==C||t[31]!==w?(T=(0,J.jsx)(Bt,{className:`h-[450px] p-2`,children:(0,J.jsxs)(`div`,{className:`space-y-3`,children:[S,C,w]})}),t[29]=S,t[30]=C,t[31]=w,t[32]=T):T=t[32];let E;return t[33]!==T||t[34]!==x?(E=(0,J.jsxs)(d,{children:[y,(0,J.jsxs)(u,{className:`w-[480px] p-0`,align:`start`,side:`right`,children:[x,T]})]}),t[33]=T,t[34]=x,t[35]=E):E=t[35],E};function Gt(e,t){return t.updatedAt-e.updatedAt}var Kt=()=>{let e=(0,$.c)(17),[n,r]=t(Ze),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=D(`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,J.jsx)(Lt,{className:`h-3.5 w-3.5`}),e[2]=l):l=e[2];let f;e[3]!==a||e[4]!==o||e[5]!==c?(f=(0,J.jsx)(m,{asChild:!0,children:(0,J.jsx)(z,{"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]=f):f=e[6];let p;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,J.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,J.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[p,(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Search the web when the model supports it.`,` `,(0,J.jsx)(Be,{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,J.jsx)(u,{className:`w-76 p-3`,align:`start`,side:`top`,children:(0,J.jsxs)(`label`,{htmlFor:`web-search-toggle`,className:`flex items-start justify-between gap-3 cursor-pointer`,children:[h,(0,J.jsx)(E,{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]!==f||e[15]!==_?(v=(0,J.jsxs)(d,{children:[f,_]}),e[14]=f,e[15]=_,e[16]=v):v=e[16],v};function qt(){return Ge()}function Jt(e){let t=(0,$.c)(4),[n,r]=(0,q.useState)(qt),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>r(qt()),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 Yt=`manual`,Xt=(0,q.memo)(e=>{let t=(0,$.c)(18),{message:n}=e,r;t[0]===n.parts?r=t[1]:(r=n.parts.filter(an).map(on).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(sn);s=`flex justify-end`,a=`w-[95%] bg-background border border-dashed p-2 rounded-sm opacity-70`,o=e.map(cn),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,J.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,J.jsx)(Ve,{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,J.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,J.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,J.jsx)(`div`,{className:s,children:d}),t[15]=s,t[16]=d,t[17]=f):f=t[17],f});Xt.displayName=`QueuedMessageDisplay`;var Zt=e=>{let t=(0,$.c)(18),{onNewChat:n,activeChatId:r,setActiveChat:i}=e,{handleClick:a}=b(),o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,J.jsx)(Ue,{className:`h-4 w-4`}),t[0]=o):o=t[0];let s;t[1]===n?s=t[2]:(s=(0,J.jsx)(R,{content:`New chat`,children:(0,J.jsx)(z,{variant:`text`,size:`icon`,onClick:n,children:o})}),t[1]=n,t[2]=s);let c;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,J.jsx)(v,{}),t[3]=c):c=t[3];let l;t[4]===a?l=t[5]:(l=()=>a(`ai`),t[4]=a,t[5]=l);let u;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,J.jsx)(We,{className:`h-4 w-4`}),t[6]=u):u=t[6];let d;t[7]===l?d=t[8]:(d=(0,J.jsx)(R,{content:`AI Settings`,children:(0,J.jsx)(z,{variant:`text`,size:`xs`,className:`hover:bg-foreground/10 py-2`,onClick:l,children:u})}),t[7]=l,t[8]=d);let f;t[9]!==r||t[10]!==i?(f=(0,J.jsx)(Wt,{activeChatId:r,setActiveChat:i}),t[9]=r,t[10]=i,t[11]=f):f=t[11];let p;t[12]!==d||t[13]!==f?(p=(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,d,f]}),t[12]=d,t[13]=f,t[14]=p):p=t[14];let m;return t[15]!==s||t[16]!==p?(m=(0,J.jsxs)(`div`,{className:`flex border-b px-2 py-1 justify-between shrink-0 items-center`,children:[s,p]}),t[15]=s,t[16]=p,t[17]=m):m=t[17],m},Qt=(0,q.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(ln))?.map(un).join(`
3
3
  `),n=e.parts?.filter(dn);return(0,J.jsxs)(`div`,{className:`w-[95%] bg-background border p-1 rounded-sm`,children:[n?.map(fn),(0,J.jsx)(U,{value:t,placeholder:`Type your message...`,onChange:pn,onSubmit:(e,t)=>{t.trim()&&i(r,t)},onClose:mn},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(hn).map(gn).join(`
4
- `);return(0,J.jsxs)(`div`,{className:`w-[95%] wrap-break-word`,children:[(0,J.jsx)(`div`,{className:`absolute right-1 top-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,J.jsx)(Je,{className:`h-3 w-3`,value:t||``})}),me({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=D(`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,J.jsx)(`div`,{className:m,children:h}),t[14]=m,t[15]=h,t[16]=g):g=t[16],g});Qt.displayName=`ChatMessage`;var $t=(0,q.memo)(e=>{let t=(0,$.c)(43),{isEmpty:n,onSendClick:i,isLoading:a,onStop:o,fileInputRef:s,onAddFiles:c,onAddContext:l}=e,u=r(_),d=u?.mode||Yt,f=u?.models?.chat_model||`openai/gpt-4o`,p=y.parse(f).providerId,{saveModeChange:m}=ee(),h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=[{value:`manual`,label:`Manual`,subtitle:`Pure chat, no tool usage`,Icon:He},{value:`ask`,label:`Ask`,subtitle:`AI with access to read-only tools like documentation search`,Icon:It},{value:`agent`,label:`Agent`,subtitle:`AI with access to read and write tools`,Icon:Re},{value:`code_mode`,label:`Code Mode (beta)`,subtitle:`AI with access to the notebook's kernel. Potentially destructive.`,Icon:Le}],t[0]=h):h=t[0];let g=h,v=Ae.has(p),b;t[1]!==d||t[2]!==g?(b=g.find(e=>e.value===d),t[1]=d,t[2]=g,t[3]=b):b=t[3];let S=b,C=S?.Icon,w=S?.label,T;t[4]===C?T=t[5]:(T=C&&(0,J.jsx)(C,{className:`h-3 w-3`}),t[4]=C,t[5]=T);let E;t[6]===w?E=t[7]:(E=(0,J.jsx)(`span`,{className:`text-nowrap`,children:w}),t[6]=w,t[7]=E);let D;t[8]!==T||t[9]!==E?(D=(0,J.jsxs)(ie,{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:[T,E]}),t[8]=T,t[9]=E,t[10]=D):D=t[10];let O;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,J.jsx)(te,{className:`text-xs uppercase tracking-wider text-muted-foreground/70 font-medium`,children:`AI Mode`}),t[11]=O):O=t[11];let k;t[12]===g?k=t[13]:(k=(0,J.jsx)(ne,{children:(0,J.jsxs)(re,{children:[O,g.map(_n)]})}),t[12]=g,t[13]=k);let A;t[14]!==d||t[15]!==m||t[16]!==D||t[17]!==k?(A=(0,J.jsxs)(ae,{value:d,onValueChange:m,children:[D,k]}),t[14]=d,t[15]=m,t[16]=D,t[17]=k,t[18]=A):A=t[18];let j,M;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,J.jsx)(x,{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`}),j=(0,J.jsx)(Kt,{}),t[19]=j,t[20]=M):(j=t[19],M=t[20]);let N;t[21]===A?N=t[22]:(N=(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[A,M,j]}),t[21]=A,t[22]=N);let P;t[23]!==a||t[24]!==l?(P=(0,J.jsx)(we,{handleAddContext:l,isLoading:a}),t[23]=a,t[24]=l,t[25]=P):P=t[25];let F;t[26]!==s||t[27]!==v||t[28]!==a||t[29]!==c?(F=v&&(0,J.jsx)(H,{fileInputRef:s,isLoading:a,onAddFiles:c}),t[26]=s,t[27]=v,t[28]=a,t[29]=c,t[30]=F):F=t[30];let I;t[31]!==n||t[32]!==a||t[33]!==i||t[34]!==o?(I=(0,J.jsx)(Ee,{isLoading:a,onStop:o,onSendClick:i,isEmpty:n}),t[31]=n,t[32]=a,t[33]=i,t[34]=o,t[35]=I):I=t[35];let L;t[36]!==P||t[37]!==F||t[38]!==I?(L=(0,J.jsxs)(`div`,{className:`flex flex-row ml-auto`,children:[P,F,I]}),t[36]=P,t[37]=F,t[38]=I,t[39]=L):L=t[39];let R;return t[40]!==N||t[41]!==L?(R=(0,J.jsx)(oe,{children:(0,J.jsxs)(`div`,{className:`px-3 py-2 border-t border-border/20 flex flex-wrap items-center gap-1`,children:[N,L]})}),t[40]=N,t[41]=L,t[42]=R):R=t[42],R});$t.displayName=`ChatInputFooter`;var en=(0,q.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=D(`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,J.jsx)(U,{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,J.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=()=>Ne(c),t[18]=c,t[19]=S);let C;t[20]!==d||t[21]!==h||t[22]!==l||t[23]!==f||t[24]!==u||t[25]!==x||t[26]!==S?(C=(0,J.jsx)($t,{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]=C):C=t[27];let w;return t[28]!==y||t[29]!==C?(w=(0,J.jsxs)(`div`,{className:`relative shrink-0 flex flex-col border-t`,children:[y,C]}),t[28]=y,t[29]=C,t[30]=w):w=t[30],w});en.displayName=`ChatInput`;var tn=e=>{let t=(0,$.c)(5),{onPairWithAgent:n}=e;if(w())return null;let r,i,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,J.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}),i=(0,J.jsx)(`span`,{children:`Work on this notebook with your own agent`}),a=(0,J.jsx)(ue,{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,J.jsxs)(z,{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},nn=()=>{let e=(0,$.c)(6),t=r(g),{handleClick:n}=b();if(!t){let t;e[0]===n?t=e[1]:(t=(0,J.jsx)(z,{variant:`outline`,size:`sm`,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,J.jsx)(B,{}),e[2]=r):r=e[2];let i;return e[3]===t?i=e[4]:(i=(0,J.jsx)(K,{title:`Chat with AI`,description:`No AI provider configured or Chat model not selected`,action:t,icon:r}),e[3]=t,e[4]=i),i}let i;return e[5]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,J.jsx)(rn,{}),e[5]=i):i=e[5],i},rn=()=>{let e=a(Ye),[r,o]=t(Qe),[l,u]=t(Xe),[d,f]=(0,q.useState)(``),[p,h]=(0,q.useState)(``),[g,v]=(0,q.useState)(!0),{files:y,addFiles:b,clearFiles:x,removeFile:C}=be(),{messages:w,enqueue:E,flushNext:O,clear:k,hasQueuedRef:A}=ge(),j=(0,q.useRef)(null),M=(0,q.useRef)(null),N=(0,q.useRef)(null),P=(0,q.useRef)(null),F=(0,q.useRef)(null),[ee,te]=(0,q.useState)(null),I=i(()=>{F.current=null,te(null)}),L=T(),{invokeAiTool:ne,sendRun:re}=se(),{openModal:ie,closeModal:ae}=ze(),R=r?.id,{chatControllerId:ce,renewDraftChatId:ue}=Jt(R),B=n(),{addStagedCell:me}=ve(),{createNewCell:he,prepareForRun:we}=s(),Ee={addStagedCell:me,createNewCell:he,prepareForRun:we,sendRun:re,store:B},{messages:H,sendMessage:Ae,error:U,status:je,regenerate:Ne,stop:Le,addToolOutput:Re,addToolApprovalResponse:Be,id:He}=Ie({id:ce,throttle:100,sendAutomaticallyWhen:({messages:e})=>Me(e),messages:r?.messages||[],transport:new zt({api:L.getAiURL(`chat`).toString(),headers:()=>L.headers(),prepareSendMessagesRequest:async e=>{let t=await xe({messages:e.messages});t.success||S.debug(`Outgoing chat messages failed AI SDK schema validation`,t.error);let n={uiMessages:e.messages,includeOtherCode:m(``),options:B.get(Ze)},r=B.get(_)?.mode||Yt,i=ke.getToolSchemas(r);return{api:L.getAiURL(`chat`).toString(),body:{tools:i,...e,...n}}}},e=>{let t=pe(e);t!==void 0&&(F.current=t)}),onFinish:({messages:t,isError:n,isAbort:r,finishReason:i})=>{if(e(e=>Rt({chatState:e,chatId:e.activeChatId,messages:t})),r){let e=de({isAbort:!0,streamReason:F.current});if(I(),e!=null){let t=fe(e);S.debug(`Chat stream aborted`,{reason:e,finishReason:i}),te(t)}}else I();W(t,{isError:n,isAbort:r})},onToolCall:async({toolCall:e})=>{await Se({invokeAiTool:ne,addToolOutput:Re,toolCall:{toolName:e.toolName,toolCallId:e.toolCallId,input:e.input},toolContext:Ee})},onError:e=>{S.error(`An error occurred:`,e)}}),Ue=i(e=>{I(),Ae({role:`user`,parts:e})}),W=i((e,t)=>{A.current&&Pe({isError:t.isError,isAbort:t.isAbort,hasPendingToolCalls:Me(e),hasUnresolvedToolCalls:Fe(e)})&&O(Ue)}),G=je===`submitted`||je===`streaming`,We=(0,q.useRef)(G);We.current=G;let Ge=i(e=>{We.current||A.current?E(e):Ue(e)}),Ke=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)}),qe=i((e=!1)=>{let t=N.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?`smooth`:`auto`})}),Je=G&&H.length>0&&Ce(H);(0,q.useEffect)(()=>{v(!0),k(),I()},[R,k,I]),(0,q.useEffect)(()=>{if(!g)return;let e=requestAnimationFrame(()=>{qe()});return()=>cancelAnimationFrame(e)},[H,w,G,g,qe]),(0,q.useEffect)(()=>{G||W(H,{isError:U!=null,isAbort:!1})},[H,G,U,W]);let K=i(t=>{let n=Date.now(),r={id:He,title:De(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}})}),tt=i(async(e,t)=>{K(e);let n=t&&t.length>0?await Oe(t):void 0,{contextPart:r,attachments:i}=await V(e);Ae({role:`user`,parts:[{type:`text`,text:e},...r?[r]:[],...n??[],...i]}),x(),f(``)}),nt=i(()=>{ue(),o(null),f(``),h(``),k(),x()}),rt=i(()=>{ie((0,J.jsx)(et,{onClose:ae}))}),it=i(async(e,t)=>{let n=H[e],r=n.parts?.filter(e=>e.type===`file`&&!_e(e))??[],{contextPart:i,attachments:a}=await V(t),o=n.id;Ae({messageId:o,role:`user`,parts:[{type:`text`,text:t},...i?[i]:[],...r,...a]})}),at=i(async(e,t)=>{if(!t.trim())return;M.current?.view&&ye(M.current.view);let n=y?await Oe(y):void 0,{contextPart:r,attachments:i}=await V(t);e?.preventDefault(),Ge([{type:`text`,text:t},...r?[r]:[],...n??[],...i]),f(``),x()}),Y=()=>{I(),Ne()},ot=i(()=>{p.trim()&&(j.current?.view&&ye(j.current.view),tt(p.trim(),y))}),st=()=>j.current?.editor?.blur(),ct=i(async e=>{R??(K(e),f(p));let{contextPart:t,attachments:n}=await V(e);Ge([{type:`text`,text:e},...t?[t]:[],...n])}),X=H.length===0;(0,q.useEffect)(()=>{if(!l)return;u(null);let{prompt:e,submit:t}=l;t?ct(e):X?(h(e),c(j)):(f(e),c(M))},[l,u,X,ct]);let Z=X?(0,J.jsx)(en,{placeholder:`Ask anything, @ to include context about tables or dataframes`,input:p,inputRef:j,inputClassName:`px-1 py-0`,setInput:h,onSubmit:ot,isLoading:G,onStop:Le,fileInputRef:P,onAddFiles:b,onClose:st},`new-thread-input`):(0,J.jsx)(en,{input:d,setInput:f,onSubmit:at,inputRef:M,isLoading:G,onStop:Le,onClose:()=>M.current?.editor?.blur(),fileInputRef:P,onAddFiles:b}),lt=y&&y.length>0&&(0,J.jsx)(`div`,{className:D(`flex flex-row gap-1 flex-wrap p-1`,X&&`py-2 px-1`),children:y?.map(e=>(0,J.jsx)(Te,{file:e,onRemove:()=>C(e)},e.name))});return(0,J.jsxs)(`div`,{className:`flex flex-col h-[calc(100%-53px)]`,children:[(0,J.jsx)(oe,{children:(0,J.jsx)(Zt,{onNewChat:nt,activeChatId:r?.id,setActiveChat:o})}),(0,J.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden relative min-h-0`,children:[(0,J.jsxs)(`div`,{className:`flex-1 px-3 bg-(--slate-1) gap-4 py-3 flex flex-col overflow-y-auto`,ref:N,onScroll:Ke,children:[X&&(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsxs)(`div`,{className:`rounded-md border bg-background`,children:[lt,Z]}),(0,J.jsx)(tn,{onPairWithAgent:rt})]}),H.map((e,t)=>(0,J.jsx)(Qt,{message:e,index:t,onEdit:it,isStreamingReasoning:Je,isLast:t===H.length-1,isActive:G,addToolApprovalResponse:Be},e.id)),w.map(e=>(0,J.jsx)(Xt,{message:e},e.id)),G&&(0,J.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,J.jsx)(Ve,{className:`h-4 w-4 animate-spin`})}),U&&(0,J.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 mb-4`,children:[(0,J.jsx)($e,{error:U||Error(`Unknown error`)}),(0,J.jsx)(z,{variant:`outline`,size:`sm`,onClick:Y,children:`Retry`})]}),ee&&!G&&!U&&(0,J.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ee})})]}),(0,J.jsx)(le,{isVisible:!g&&(H.length>0||w.length>0),onScrollToBottom:()=>qe(!0)})]}),G&&(0,J.jsx)(`div`,{className:`w-full flex justify-center items-center z-20 border-t`,children:(0,J.jsx)(z,{variant:`linkDestructive`,size:`sm`,onClick:Le,children:`Stop`})}),!X&&(0,J.jsxs)(J.Fragment,{children:[lt,Z]})]})};function an(e){return e.type===`text`}function on(e){return e.text}function sn(e){return e.type===`file`}function cn(e,t){return(0,J.jsx)(je,{attachment:e},t)}function ln(e){return e.type===`text`}function un(e){return e.text}function dn(e){return e.type===`file`}function fn(e,t){return(0,J.jsx)(je,{attachment:e},t)}function pn(){}function mn(){}function hn(e){return e.type===`text`}function gn(e){return e.text}function _n(e){return(0,J.jsx)(I,{value:e.value,className:`text-xs py-1`,children:(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(`span`,{className:`mt-1 text-muted-foreground`,children:(0,J.jsx)(e.Icon,{className:`h-3 w-3`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,J.jsx)(`span`,{className:`font-semibold`,children:e.label}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e.subtitle})]})]})},e.value)}export{nn as default};
4
+ `);return(0,J.jsxs)(`div`,{className:`w-[95%] wrap-break-word`,children:[(0,J.jsx)(`div`,{className:`absolute right-1 top-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,J.jsx)(Je,{className:`h-3 w-3`,value:t||``})}),me({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=D(`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,J.jsx)(`div`,{className:m,children:h}),t[14]=m,t[15]=h,t[16]=g):g=t[16],g});Qt.displayName=`ChatMessage`;var $t=(0,q.memo)(e=>{let t=(0,$.c)(43),{isEmpty:n,onSendClick:i,isLoading:a,onStop:o,fileInputRef:s,onAddFiles:c,onAddContext:l}=e,u=r(_),d=u?.mode||Yt,f=u?.models?.chat_model||`openai/gpt-4o`,p=y.parse(f).providerId,{saveModeChange:m}=ee(),h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=[{value:`manual`,label:`Manual`,subtitle:`Pure chat, no tool usage`,Icon:He},{value:`ask`,label:`Ask`,subtitle:`AI with access to read-only tools like documentation search`,Icon:It},{value:`agent`,label:`Agent`,subtitle:`AI with access to read and write tools`,Icon:Re},{value:`code_mode`,label:`Code Mode (beta)`,subtitle:`AI with access to the notebook's kernel. Potentially destructive.`,Icon:Le}],t[0]=h):h=t[0];let g=h,v=Ae.has(p),b;t[1]!==d||t[2]!==g?(b=g.find(e=>e.value===d),t[1]=d,t[2]=g,t[3]=b):b=t[3];let S=b,C=S?.Icon,w=S?.label,T;t[4]===C?T=t[5]:(T=C&&(0,J.jsx)(C,{className:`h-3 w-3`}),t[4]=C,t[5]=T);let E;t[6]===w?E=t[7]:(E=(0,J.jsx)(`span`,{className:`text-nowrap`,children:w}),t[6]=w,t[7]=E);let D;t[8]!==T||t[9]!==E?(D=(0,J.jsxs)(ie,{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:[T,E]}),t[8]=T,t[9]=E,t[10]=D):D=t[10];let O;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,J.jsx)(te,{className:`text-xs uppercase tracking-wider text-muted-foreground/70 font-medium`,children:`AI Mode`}),t[11]=O):O=t[11];let k;t[12]===g?k=t[13]:(k=(0,J.jsx)(ne,{children:(0,J.jsxs)(re,{children:[O,g.map(_n)]})}),t[12]=g,t[13]=k);let A;t[14]!==d||t[15]!==m||t[16]!==D||t[17]!==k?(A=(0,J.jsxs)(ae,{value:d,onValueChange:m,children:[D,k]}),t[14]=d,t[15]=m,t[16]=D,t[17]=k,t[18]=A):A=t[18];let j,M;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,J.jsx)(x,{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`}),j=(0,J.jsx)(Kt,{}),t[19]=j,t[20]=M):(j=t[19],M=t[20]);let N;t[21]===A?N=t[22]:(N=(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[A,M,j]}),t[21]=A,t[22]=N);let P;t[23]!==a||t[24]!==l?(P=(0,J.jsx)(we,{handleAddContext:l,isLoading:a}),t[23]=a,t[24]=l,t[25]=P):P=t[25];let F;t[26]!==s||t[27]!==v||t[28]!==a||t[29]!==c?(F=v&&(0,J.jsx)(H,{fileInputRef:s,isLoading:a,onAddFiles:c}),t[26]=s,t[27]=v,t[28]=a,t[29]=c,t[30]=F):F=t[30];let I;t[31]!==n||t[32]!==a||t[33]!==i||t[34]!==o?(I=(0,J.jsx)(Ee,{isLoading:a,onStop:o,onSendClick:i,isEmpty:n}),t[31]=n,t[32]=a,t[33]=i,t[34]=o,t[35]=I):I=t[35];let L;t[36]!==P||t[37]!==F||t[38]!==I?(L=(0,J.jsxs)(`div`,{className:`flex flex-row ml-auto`,children:[P,F,I]}),t[36]=P,t[37]=F,t[38]=I,t[39]=L):L=t[39];let R;return t[40]!==N||t[41]!==L?(R=(0,J.jsx)(oe,{children:(0,J.jsxs)(`div`,{className:`px-3 py-2 border-t border-border/20 flex flex-wrap items-center gap-1`,children:[N,L]})}),t[40]=N,t[41]=L,t[42]=R):R=t[42],R});$t.displayName=`ChatInputFooter`;var en=(0,q.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=D(`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,J.jsx)(U,{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,J.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=()=>Ne(c),t[18]=c,t[19]=S);let C;t[20]!==d||t[21]!==h||t[22]!==l||t[23]!==f||t[24]!==u||t[25]!==x||t[26]!==S?(C=(0,J.jsx)($t,{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]=C):C=t[27];let w;return t[28]!==y||t[29]!==C?(w=(0,J.jsxs)(`div`,{className:`relative shrink-0 flex flex-col border-t`,children:[y,C]}),t[28]=y,t[29]=C,t[30]=w):w=t[30],w});en.displayName=`ChatInput`;var tn=e=>{let t=(0,$.c)(5),{onPairWithAgent:n}=e;if(w())return null;let r,i,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,J.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}),i=(0,J.jsx)(`span`,{children:`Work on this notebook with your own agent`}),a=(0,J.jsx)(ue,{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,J.jsxs)(z,{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},nn=()=>{let e=(0,$.c)(6),t=r(g),{handleClick:n}=b();if(!t){let t;e[0]===n?t=e[1]:(t=(0,J.jsx)(z,{variant:`outline`,size:`sm`,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,J.jsx)(B,{}),e[2]=r):r=e[2];let i;return e[3]===t?i=e[4]:(i=(0,J.jsx)(K,{title:`Chat with AI`,description:`No AI provider configured or Chat model not selected`,action:t,icon:r}),e[3]=t,e[4]=i),i}let i;return e[5]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,J.jsx)(rn,{}),e[5]=i):i=e[5],i},rn=()=>{let e=a(Ye),[r,o]=t(Qe),[l,u]=t(Xe),[d,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(``),[g,v]=(0,q.useState)(!0),{files:y,addFiles:b,clearFiles:x,removeFile:C}=be(),{messages:w,enqueue:E,flushNext:O,clear:k,hasQueuedRef:A}=ge(),j=(0,q.useRef)(null),M=(0,q.useRef)(null),N=(0,q.useRef)(null),P=(0,q.useRef)(null),F=(0,q.useRef)(null),[ee,te]=(0,q.useState)(null),I=i(()=>{F.current=null,te(null)}),L=T(),{invokeAiTool:ne,sendRun:re}=se(),{openModal:ie,closeModal:ae}=ze(),R=r?.id,{chatControllerId:ce,renewDraftChatId:ue}=Jt(R),B=n(),{addStagedCell:me}=ve(),{createNewCell:he,prepareForRun:we}=s(),Ee={addStagedCell:me,createNewCell:he,prepareForRun:we,sendRun:re,store:B},{messages:H,sendMessage:Ae,error:U,status:je,regenerate:Ne,stop:Le,addToolOutput:Re,addToolApprovalResponse:Be,id:He}=Ie({id:ce,throttle:100,sendAutomaticallyWhen:({messages:e})=>Me(e),messages:r?.messages||[],transport:new zt({api:L.getAiURL(`chat`).toString(),headers:()=>L.headers(),prepareSendMessagesRequest:async e=>{let t=await xe({messages:e.messages});t.success||S.debug(`Outgoing chat messages failed AI SDK schema validation`,t.error);let n={uiMessages:e.messages,includeOtherCode:f(``),options:B.get(Ze)},r=B.get(_)?.mode||Yt,i=ke.getToolSchemas(r);return{api:L.getAiURL(`chat`).toString(),body:{tools:i,...e,...n}}}},e=>{let t=pe(e);t!==void 0&&(F.current=t)}),onFinish:({messages:t,isError:n,isAbort:r,finishReason:i})=>{if(e(e=>Rt({chatState:e,chatId:e.activeChatId,messages:t})),r){let e=de({isAbort:!0,streamReason:F.current});if(I(),e!=null){let t=fe(e);S.debug(`Chat stream aborted`,{reason:e,finishReason:i}),te(t)}}else I();W(t,{isError:n,isAbort:r})},onToolCall:async({toolCall:e})=>{await Se({invokeAiTool:ne,addToolOutput:Re,toolCall:{toolName:e.toolName,toolCallId:e.toolCallId,input:e.input},toolContext:Ee})},onError:e=>{S.error(`An error occurred:`,e)}}),Ue=i(e=>{I(),Ae({role:`user`,parts:e})}),W=i((e,t)=>{A.current&&Pe({isError:t.isError,isAbort:t.isAbort,hasPendingToolCalls:Me(e),hasUnresolvedToolCalls:Fe(e)})&&O(Ue)}),G=je===`submitted`||je===`streaming`,We=(0,q.useRef)(G);We.current=G;let Ge=i(e=>{We.current||A.current?E(e):Ue(e)}),Ke=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)}),qe=i((e=!1)=>{let t=N.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?`smooth`:`auto`})}),Je=G&&H.length>0&&Ce(H);(0,q.useEffect)(()=>{v(!0),k(),I()},[R,k,I]),(0,q.useEffect)(()=>{if(!g)return;let e=requestAnimationFrame(()=>{qe()});return()=>cancelAnimationFrame(e)},[H,w,G,g,qe]),(0,q.useEffect)(()=>{G||W(H,{isError:U!=null,isAbort:!1})},[H,G,U,W]);let K=i(t=>{let n=Date.now(),r={id:He,title:De(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}})}),tt=i(async(e,t)=>{K(e);let n=t&&t.length>0?await Oe(t):void 0,{contextPart:r,attachments:i}=await V(e);Ae({role:`user`,parts:[{type:`text`,text:e},...r?[r]:[],...n??[],...i]}),x(),p(``)}),nt=i(()=>{ue(),o(null),p(``),h(``),k(),x()}),rt=i(()=>{ie((0,J.jsx)(et,{onClose:ae}))}),it=i(async(e,t)=>{let n=H[e],r=n.parts?.filter(e=>e.type===`file`&&!_e(e))??[],{contextPart:i,attachments:a}=await V(t),o=n.id;Ae({messageId:o,role:`user`,parts:[{type:`text`,text:t},...i?[i]:[],...r,...a]})}),at=i(async(e,t)=>{if(!t.trim())return;M.current?.view&&ye(M.current.view);let n=y?await Oe(y):void 0,{contextPart:r,attachments:i}=await V(t);e?.preventDefault(),Ge([{type:`text`,text:t},...r?[r]:[],...n??[],...i]),p(``),x()}),Y=()=>{I(),Ne()},ot=i(()=>{m.trim()&&(j.current?.view&&ye(j.current.view),tt(m.trim(),y))}),st=()=>j.current?.editor?.blur(),ct=i(async e=>{R??(K(e),p(m));let{contextPart:t,attachments:n}=await V(e);Ge([{type:`text`,text:e},...t?[t]:[],...n])}),X=H.length===0;(0,q.useEffect)(()=>{if(!l)return;u(null);let{prompt:e,submit:t}=l;t?ct(e):X?(h(e),c(j)):(p(e),c(M))},[l,u,X,ct]);let Z=X?(0,J.jsx)(en,{placeholder:`Ask anything, @ to include context about tables or dataframes`,input:m,inputRef:j,inputClassName:`px-1 py-0`,setInput:h,onSubmit:ot,isLoading:G,onStop:Le,fileInputRef:P,onAddFiles:b,onClose:st},`new-thread-input`):(0,J.jsx)(en,{input:d,setInput:p,onSubmit:at,inputRef:M,isLoading:G,onStop:Le,onClose:()=>M.current?.editor?.blur(),fileInputRef:P,onAddFiles:b}),lt=y&&y.length>0&&(0,J.jsx)(`div`,{className:D(`flex flex-row gap-1 flex-wrap p-1`,X&&`py-2 px-1`),children:y?.map(e=>(0,J.jsx)(Te,{file:e,onRemove:()=>C(e)},e.name))});return(0,J.jsxs)(`div`,{className:`flex flex-col h-[calc(100%-53px)]`,children:[(0,J.jsx)(oe,{children:(0,J.jsx)(Zt,{onNewChat:nt,activeChatId:r?.id,setActiveChat:o})}),(0,J.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden relative min-h-0`,children:[(0,J.jsxs)(`div`,{className:`flex-1 px-3 bg-(--slate-1) gap-4 py-3 flex flex-col overflow-y-auto`,ref:N,onScroll:Ke,children:[X&&(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsxs)(`div`,{className:`rounded-md border bg-background`,children:[lt,Z]}),(0,J.jsx)(tn,{onPairWithAgent:rt})]}),H.map((e,t)=>(0,J.jsx)(Qt,{message:e,index:t,onEdit:it,isStreamingReasoning:Je,isLast:t===H.length-1,isActive:G,addToolApprovalResponse:Be},e.id)),w.map(e=>(0,J.jsx)(Xt,{message:e},e.id)),G&&(0,J.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,J.jsx)(Ve,{className:`h-4 w-4 animate-spin`})}),U&&(0,J.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 mb-4`,children:[(0,J.jsx)($e,{error:U||Error(`Unknown error`)}),(0,J.jsx)(z,{variant:`outline`,size:`sm`,onClick:Y,children:`Retry`})]}),ee&&!G&&!U&&(0,J.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ee})})]}),(0,J.jsx)(le,{isVisible:!g&&(H.length>0||w.length>0),onScrollToBottom:()=>qe(!0)})]}),G&&(0,J.jsx)(`div`,{className:`w-full flex justify-center items-center z-20 border-t`,children:(0,J.jsx)(z,{variant:`linkDestructive`,size:`sm`,onClick:Le,children:`Stop`})}),!X&&(0,J.jsxs)(J.Fragment,{children:[lt,Z]})]})};function an(e){return e.type===`text`}function on(e){return e.text}function sn(e){return e.type===`file`}function cn(e,t){return(0,J.jsx)(je,{attachment:e},t)}function ln(e){return e.type===`text`}function un(e){return e.text}function dn(e){return e.type===`file`}function fn(e,t){return(0,J.jsx)(je,{attachment:e},t)}function pn(){}function mn(){}function hn(e){return e.type===`text`}function gn(e){return e.text}function _n(e){return(0,J.jsx)(I,{value:e.value,className:`text-xs py-1`,children:(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(`span`,{className:`mt-1 text-muted-foreground`,children:(0,J.jsx)(e.Icon,{className:`h-3 w-3`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,J.jsx)(`span`,{className:`font-semibold`,children:e.label}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e.subtitle})]})]})},e.value)}export{nn as default};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-CBDbhulC.js";import{To as n,_n as r,gn as i,jr as a,mn as o}from"./cells-Cp-G34Rz.js";import{Cn as s,In as c,kt as l,ln as u,wt as d}from"./schemas-aTUejmFi.js";import{t as f}from"./compiler-runtime-CYIjoINj.js";import{g as p,t as m}from"./useEventListener-92uWqz-P.js";import{t as h}from"./objects-snlMn4yk.js";import{t as g}from"./cn-ldLVeaqm.js";import{t as _}from"./jsx-runtime-B74pBk57.js";import{d as v}from"./select-nLt2y0Sw.js";import{a as y,p as b,r as x,t as S}from"./dropdown-menu-C40jM9o4.js";import{t as C}from"./tooltip-BUtPzKB4.js";import{t as w}from"./button-Dh8EwhsF.js";import{t as T}from"./strings-CReV1AYG.js";import{t as E}from"./createLucideIcon-B7HeEoG2.js";import{t as D}from"./bot-message-square-CGhPjWFf.js";import{r as ee}from"./useNumberFormatter-DHJ9s6Vk.js";import{u as O}from"./toDate-hGYJX0Ha.js";import{i as k,n as A,r as te,t as ne}from"./chat-display-Bu405iyc.js";import{B as re,H as ie,K as ae,h as oe,n as se,q as ce,v as le,z as ue}from"./add-cell-with-ai-R-3DS79K.js";import{t as de}from"./spinner-Ck-Hgfvj.js";import{o as j,r as M}from"./input-DEbY281O.js";import{t as N}from"./settings-C-cYas75.js";import{t as P}from"./square-B58Ib8Ir.js";import{t as F}from"./trash-2-D_HX-0qx.js";import{t as I}from"./uuid-k9DpjH68.js";import{n as L}from"./useAsyncData-Buhk-UgR.js";import{t as R}from"./copy-icon-z8fuTE3w.js";import{r as z}from"./react-icons.esm-hr79-MCS.js";import{t as B}from"./events-CbeVJ6OD.js";import{n as V}from"./error-banner-Dw5YY9wq.js";var fe=E(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),H=f(),U=_(),W=e(t(),1),G=n,pe=s({type:u(`stream_chunk`),message_id:c(),content:d().nullable().transform(e=>e),is_final:l().optional()});function me(e,t){let{controllerRef:n,activeRequestIdRef:r}=t,i=n.current;if(i===null)return`dropped-no-controller`;let a=r.current;return a!==null&&e.message_id!==a?(p.debug(`Dropping stale chat chunk`,{chunkRequestId:e.message_id,activeRequestId:a}),`dropped-stale`):(e.content&&i.enqueue(e.content),e.is_final?(i.close(),n.current=null,r.current=null,`closed`):`enqueued`)}var K=e=>{let[t,n]=(0,W.useState)(``),[r,i]=(0,W.useState)(e.config),[o,s]=(0,W.useState)(e.config),[c,l]=(0,W.useState)(void 0),u=(0,W.useRef)(null),d=(0,W.useRef)(null),f=(0,W.useRef)(null),h=(0,W.useRef)(null);Object.keys(e.config).some(t=>e.config[t]!==o[t])&&(i(e.config),s(e.config));let _=(0,W.useRef)(r);_.current=r;let v=(0,W.useRef)(null),y=(0,W.useRef)(null),b=(0,W.useRef)(null),[x,S]=(0,W.useState)(null),T=()=>{b.current=null,S(null)},{data:E}=L(async()=>(await e.get_chat_history({})).messages,[]),O=e.value.length>0?e.value:E,{messages:j,sendMessage:M,setMessages:N,status:z,stop:H,error:G,regenerate:K,clearError:q,addToolApprovalResponse:J}=ue({sendAutomaticallyWhen:({messages:e})=>le(e),transport:new re({fetch:async(t,n)=>{if(n===void 0)return fetch(t);let r=JSON.parse(n.body),i=n.signal,a={max_tokens:_.current.max_tokens,temperature:_.current.temperature,top_p:_.current.top_p,top_k:_.current.top_k,frequency_penalty:_.current.frequency_penalty,presence_penalty:_.current.presence_penalty};try{let t=r.messages.map(e=>({...e,content:e.parts?.map(e=>`text`in e?e.text:``).join(`
2
- `)})),n=I();T();let o=new ReadableStream({start(t){v.current=t,y.current=n;let r=()=>{try{t.close()}catch(e){p.debug(`Controller may already be closed`,{error:e})}v.current=null,y.current=null,e.cancel_prompt({request_id:n}).catch(e=>{p.debug(`cancel_prompt failed`,{error:e})})};return i?.addEventListener(`abort`,r),()=>{i?.removeEventListener(`abort`,r)}},cancel(){v.current=null,y.current=null}});return e.send_prompt({request_id:n,messages:t,config:a}).catch(e=>{v.current?.error(e),v.current=null,y.current=null}),ie({stream:o})}catch(e){if(e instanceof Error&&e.name===`AbortError`)return new Response(`Aborted`,{status:499});let t=e.message?.split(`failed with exception `).pop();return new Response(t,{status:400})}}}),messages:O,onFinish:({messages:t,isAbort:n,finishReason:r})=>{if(l(void 0),u.current&&(u.current.value=``),p.debug(`Finished streaming message:`,{finishReason:r,isAbort:n}),n){let e=k({isAbort:!0,streamReason:b.current});if(T(),e!=null){let t=A(e);p.debug(`Chat stream aborted`,{reason:e,finishReason:r}),S(t)}}else T();e.setValue(t)},onError:e=>{p.error(`An error occurred:`,e)}});m(e.host,B.TYPE,e=>{let t=pe.safeParse(e.detail.message);if(t.success){if(t.data.content&&t.data.message_id===y.current){let e=te(t.data.content);e!==void 0&&(b.current=e)}me(t.data,{controllerRef:v,activeRequestIdRef:y})}});let Y=z===`submitted`||z===`streaming`,X=t=>{let n=j.findIndex(e=>e.id===t);if(n!==-1){let r=j.filter(e=>e.id!==t);e.delete_chat_message({index:n}),N(r),e.setValue(r),r.length===0&&T()}},Z=Array.isArray(e.allowAttachments)&&e.allowAttachments.length>0||e.allowAttachments===!0,_e={triggerCompletionRegex:/^\/(\w+)?/,completions:e.prompts.map(e=>({label:`/${e}`,displayLabel:e,apply:e}))},Q=e.prompts.length>0?`Type your message here, / for prompts`:`Type your message here...`;(0,W.useEffect)(()=>{h.current?.scrollTo({top:h.current.scrollHeight,behavior:`smooth`})},[j.length,h]);let $=f.current?.view,ve=()=>{if($){let e=$.state.doc.length;$.dispatch({changes:{from:0,to:e,insert:``}})}n(``)};return(0,U.jsxs)(`div`,{className:`flex flex-col h-full bg-(--slate-1) rounded-lg shadow border border-(--slate-6) overflow-hidden relative`,style:{maxHeight:e.maxHeight},children:[(0,U.jsx)(`div`,{className:`absolute top-0 right-0 flex justify-end z-10 border border-(--slate-6) bg-inherit rounded-bl-lg`,children:(0,U.jsx)(w,{variant:`text`,size:`icon`,disabled:j.length===0,onClick:()=>{N([]),e.setValue([]),e.delete_chat_history({}),q(),T()},children:(0,U.jsx)(fe,{className:`h-3 w-3`})})}),(0,U.jsxs)(`div`,{className:`grow overflow-y-auto gap-4 pt-8 pb-4 px-2 flex flex-col`,ref:h,children:[j.length===0&&(0,U.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground text-center p-4`,children:[(0,U.jsx)(D,{className:`h-12 w-12 mb-4`}),(0,U.jsx)(`h3`,{className:`text-lg font-semibold mb-2`,children:`No messages yet`}),(0,U.jsx)(`p`,{className:`text-sm`,children:`Start a conversation by typing a message below.`})]}),j.map((e,t)=>{let n=e.parts?.filter(e=>e.type===`text`).map(e=>e.text).join(`
3
- `),r=t===j.length-1;return(0,U.jsxs)(`div`,{className:g(`flex flex-col group gap-2`,e.role===`user`?`items-end`:`items-start`),children:[(0,U.jsx)(`div`,{className:`max-w-[80%] p-3 rounded-lg ${e.role===`user`?`bg-(--sky-11) text-(--slate-1) whitespace-pre-wrap`:`bg-(--slate-4) text-(--slate-12)`}`,children:ne({message:e,isStreamingReasoning:z===`streaming`,isLast:r,isActive:Y,addToolApprovalResponse:r?J:void 0})}),(0,U.jsxs)(`div`,{className:`flex justify-end text-xs gap-2 invisible group-hover:visible`,children:[(0,U.jsx)(R,{value:n,className:`h-3 w-3`,buttonClassName:`text-xs text-(--slate-9) hover:text-(--slate-11)`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>X(e.id),className:`text-xs text-(--slate-9) hover:text-(--slate-11)`,children:(0,U.jsx)(F,{className:`h-3 w-3 text-(--red-9)`})})]})]},`${e.id}-${t}`)}),Y&&(0,U.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,U.jsx)(de,{size:`small`})}),G&&(0,U.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 mb-4`,children:[(0,U.jsx)(V,{error:G}),(0,U.jsx)(w,{variant:`outline`,size:`sm`,onClick:()=>K(),children:`Retry`})]}),x&&!Y&&!G&&(0,U.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,U.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:x})})]}),(0,U.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),e.disabled)return;let r=c?await oe(c):void 0;M({role:`user`,parts:[{type:`text`,text:t},...r??[]]}),ve()},ref:d,inert:e.disabled||void 0,className:g(`flex w-full border-t border-(--slate-6) px-2 py-1 items-center`,e.disabled&&`opacity-50 cursor-not-allowed`),children:[e.showConfigurationControls&&(0,U.jsx)(he,{config:r,onChange:i}),e.prompts.length>0&&(0,U.jsx)(ge,{prompts:e.prompts,onSelect:e=>{n(e),requestAnimationFrame(()=>{$?.focus(),a($)})}}),(0,U.jsx)(se,{className:`rounded-sm mr-2`,placeholder:Q,value:t,inputRef:f,maxHeight:e.maxHeight?`${e.maxHeight/2}px`:void 0,onChange:n,onSubmit:(e,t)=>{t.trim()&&d.current?.requestSubmit()},onClose:()=>{},additionalCompletions:_e}),c&&c.length===1&&(0,U.jsx)(`span`,{title:c[0].name,className:`text-sm text-(--slate-11) truncate shrink-0 w-fit max-w-24`,children:c[0].name}),c&&c.length>1&&(0,U.jsxs)(`span`,{title:[...c].map(e=>e.name).join(`
4
- `),className:`text-sm text-(--slate-11) truncate shrink-0`,children:[c.length,` files`]}),c&&c.length>0&&(0,U.jsx)(w,{type:`button`,variant:`text`,size:`sm`,onClick:()=>{l(void 0),u.current&&(u.current.value=``)},children:(0,U.jsx)(ee,{className:`size-3`})}),Z&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(w,{type:`button`,variant:`text`,size:`sm`,onClick:()=>u.current?.click(),children:(0,U.jsx)(ce,{className:`h-4`})}),(0,U.jsx)(`input`,{type:`file`,ref:u,className:`hidden`,multiple:!0,accept:Array.isArray(e.allowAttachments)?e.allowAttachments.join(`,`):void 0,onChange:e=>{e.target.files&&l([...e.target.files])}})]}),Y?(0,U.jsx)(C,{content:`Stop generating`,children:(0,U.jsx)(w,{type:`button`,variant:`link`,size:`xs`,onClick:()=>H(),className:`text-(--red-9) hover:text-(--red-11)`,children:(0,U.jsx)(P,{className:`h-4 w-4 fill-current`})})}):(0,U.jsx)(w,{type:`submit`,disabled:!t,variant:`outline`,size:`xs`,className:`text-(--slate-11)`,"aria-label":`Send message`,children:(0,U.jsx)(ae,{className:`h-4 w-4`})})]})]})},q={max_tokens:{min:1,max:4096,description:`Maximum number of tokens to generate`},temperature:{min:0,max:2,step:.1,description:`Controls randomness (0: deterministic, 2: very random)`},top_p:{min:0,max:1,step:.1,description:`Nucleus sampling: probability mass to consider`},top_k:{min:1,max:100,description:`Top-k sampling: number of highest probability tokens to consider`},frequency_penalty:{min:-2,max:2,description:`Penalizes frequent tokens (-2: favor, 2: avoid)`},presence_penalty:{min:-2,max:2,description:`Penalizes new tokens (-2: favor, 2: avoid)`}},he=e=>{let t=(0,H.c)(16),{config:n,onChange:a}=e,[s,c]=(0,W.useState)(!1),l;t[0]!==n||t[1]!==a?(l=(e,t)=>{let r=t===null||Number.isNaN(t)?null:t;if(r!==null){let{min:t,max:n}=q[e];r=Math.max(t,Math.min(n,r))}let i={...n,[e]:r};a(i)},t[0]=n,t[1]=a,t[2]=l):l=t[2];let u=l,d;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>{e.key===`Enter`&&(e.preventDefault(),c(!1))},t[3]=d):d=t[3];let f=d,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,U.jsx)(C,{content:`Configuration`,children:(0,U.jsx)(r,{asChild:!0,children:(0,U.jsx)(w,{variant:`outline`,size:`sm`,className:`border-none shadow-none hover:bg-transparent`,children:(0,U.jsx)(N,{className:`h-3 w-3`})})})}),t[4]=p):p=t[4];let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,U.jsx)(`h4`,{className:`font-bold leading-none`,children:`Configuration`}),t[5]=m):m=t[5];let g;if(t[6]!==n||t[7]!==u){let e;t[9]===u?e=t[10]:(e=e=>{let[t,n]=e;return(0,U.jsxs)(`div`,{className:`grid grid-cols-3 items-center gap-1`,children:[(0,U.jsxs)(v,{htmlFor:t,className:`flex w-full justify-between col-span-3 align-end`,children:[T.startCase(t),(0,U.jsx)(C,{delayDuration:200,side:`top`,content:(0,U.jsx)(`div`,{className:`text-xs flex flex-col`,children:q[t].description}),children:(0,U.jsx)(O,{className:`h-3 w-3 cursor-help text-muted-foreground hover:text-foreground`})})]}),(0,U.jsx)(j,{id:t,"aria-label":t,value:n??NaN,placeholder:`null`,minValue:q[t].min,maxValue:q[t].max,step:q[t].step??1,onChange:e=>u(t,e),onKeyDown:f,className:`col-span-3`})]},t)},t[9]=u,t[10]=e),g=h.entries(n).map(e),t[6]=n,t[7]=u,t[8]=g}else g=t[8];let _;t[11]===g?_=t[12]:(_=(0,U.jsx)(i,{className:`w-70 border`,children:(0,U.jsxs)(`div`,{className:`grid gap-3`,children:[m,g]})}),t[11]=g,t[12]=_);let y;return t[13]!==s||t[14]!==_?(y=(0,U.jsxs)(o,{open:s,onOpenChange:c,children:[p,_]}),t[13]=s,t[14]=_,t[15]=y):y=t[15],y},ge=e=>{let t=(0,H.c)(18),{prompts:n,onSelect:r}=e,[a,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(``),u;t[0]===r?u=t[1]:(u=e=>{[...e.matchAll(/{{(\w+)}}/g)].length>0?(l(e),s(!0)):r(e)},t[0]=r,t[1]=u);let d=u,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,U.jsx)(C,{content:`Select a prompt`,children:(0,U.jsx)(b,{asChild:!0,children:(0,U.jsx)(w,{variant:`outline`,size:`sm`,className:`border-none shadow-none hover:bg-transparent`,children:(0,U.jsx)(z,{className:`h-3 w-3`})})})}),t[2]=f):f=t[2];let p;if(t[3]!==d||t[4]!==n){let e;t[6]===d?e=t[7]:(e=(e,t)=>(0,U.jsx)(y,{onSelect:()=>d(e),className:`whitespace-normal text-left`,children:e},t),t[6]=d,t[7]=e),p=n.map(e),t[3]=d,t[4]=n,t[5]=p}else p=t[5];let m;t[8]===p?m=t[9]:(m=(0,U.jsx)(G,{children:(0,U.jsxs)(S,{children:[f,(0,U.jsx)(x,{side:`right`,align:`end`,onCloseAutoFocus:Y,className:`w-64 max-h-96 overflow-y-auto`,children:p})]})}),t[8]=p,t[9]=m);let h;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>s(!1),t[10]=h):h=t[10];let g;t[11]!==r||t[12]!==c?(g=(0,U.jsx)(i,{side:`right`,align:`end`,className:`min-w-80 px-2`,children:(0,U.jsx)(J,{prompt:c,onClose:h,onSelect:r})}),t[11]=r,t[12]=c,t[13]=g):g=t[13];let _;return t[14]!==a||t[15]!==m||t[16]!==g?(_=(0,U.jsxs)(o,{open:a,onOpenChange:s,children:[m,g]}),t[14]=a,t[15]=m,t[16]=g,t[17]=_):_=t[17],_},J=e=>{let t=(0,H.c)(32),{prompt:n,onClose:r,onSelect:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a={},t[0]=a):a=t[0];let[o,s]=(0,W.useState)(a),c,l;t[1]===n?(c=t[2],l=t[3]):(c=()=>{let e=[...n.matchAll(/{{(\w+)}}/g)].reduce(X,{});s(e)},l=[n],t[1]=n,t[2]=c,t[3]=l),(0,W.useEffect)(c,l);let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(e,t)=>{s(n=>({...n,[e]:t}))},t[4]=u):u=t[4];let d=u,f;if(t[5]!==n||t[6]!==o){let e;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(e=/{{(\w+)}}/g,t[8]=e):e=t[8];let r;t[9]===o?r=t[10]:(r=(e,t)=>o[t]||`{{${t}}}`,t[9]=o,t[10]=r),f=n.replaceAll(e,r),t[5]=n,t[6]=o,t[7]=f}else f=t[7];let p=f,m;t[11]===o?m=t[12]:(m=Object.values(o).some(Z),t[11]=o,t[12]=m);let h=m,g;t[13]!==r||t[14]!==i||t[15]!==p?(g=()=>{i(p),r()},t[13]=r,t[14]=i,t[15]=p,t[16]=g):g=t[16];let _=g,y;t[17]===o?y=t[18]:(y=Object.entries(o),t[17]=o,t[18]=y);let b;t[19]!==_||t[20]!==h||t[21]!==y?(b=y.map((e,t)=>{let[n,r]=e;return(0,U.jsxs)(`div`,{className:`grid grid-cols-4 items-center gap-2`,children:[(0,U.jsx)(v,{htmlFor:n,className:`font-semibold text-base`,children:n}),(0,U.jsx)(M,{id:n,value:r,onChange:e=>d(n,e.target.value),rootClassName:`col-span-3 w-full`,className:`m-0`,placeholder:`Enter value for ${n}`,autoFocus:t===0,onKeyDown:e=>{e.key===`Enter`&&!h&&_()}})]},n)}),t[19]=_,t[20]=h,t[21]=y,t[22]=b):b=t[22];let x;t[23]===p?x=t[24]:(x=(0,U.jsx)(`div`,{className:`grid gap-2 prose dark:prose-invert`,children:(0,U.jsx)(`blockquote`,{className:`text-sm`,children:p})}),t[23]=p,t[24]=x);let S;t[25]!==_||t[26]!==h?(S=(0,U.jsx)(w,{onClick:_,size:`xs`,disabled:h,children:`Submit`}),t[25]=_,t[26]=h,t[27]=S):S=t[27];let C;return t[28]!==x||t[29]!==S||t[30]!==b?(C=(0,U.jsxs)(`div`,{className:`grid gap-4`,children:[b,x,S]}),t[28]=x,t[29]=S,t[30]=b,t[31]=C):C=t[31],C};function Y(e){return e.preventDefault()}function X(e,t){return e[t[1]]=``,e}function Z(e){return e==null||e.trim()===``}export{K as Chatbot};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-CBDbhulC.js";import{Eo as n,Mr as r,_n as i,hn as a,vn as o}from"./cells-BBhW3FXj.js";import{Cn as s,In as c,kt as l,ln as u,wt as d}from"./schemas-aTUejmFi.js";import{t as f}from"./compiler-runtime-CYIjoINj.js";import{g as p,t as m}from"./useEventListener-92uWqz-P.js";import{t as h}from"./objects-snlMn4yk.js";import{t as g}from"./cn-ldLVeaqm.js";import{t as _}from"./jsx-runtime-B74pBk57.js";import{d as v}from"./select-nLt2y0Sw.js";import{a as y,p as b,r as x,t as S}from"./dropdown-menu-C40jM9o4.js";import{t as C}from"./tooltip-BUtPzKB4.js";import{t as w}from"./button-Dh8EwhsF.js";import{t as T}from"./strings-CReV1AYG.js";import{t as E}from"./bot-message-square-CGhPjWFf.js";import{r as D}from"./useNumberFormatter-DHJ9s6Vk.js";import{u as O}from"./toDate-hGYJX0Ha.js";import{i as k,n as A,r as ee,t as te}from"./chat-display-CIpYPLlF.js";import{B as ne,H as re,K as ie,h as ae,n as oe,q as se,v as ce,z as le}from"./add-cell-with-ai-OQ4sSXg4.js";import{t as ue}from"./spinner-Ck-Hgfvj.js";import{t as de}from"./rotate-cw-CESctpLh.js";import{o as j,r as M}from"./input-DEbY281O.js";import{t as N}from"./settings-C-cYas75.js";import{t as P}from"./square-B58Ib8Ir.js";import{t as F}from"./trash-2-D_HX-0qx.js";import{t as I}from"./uuid-k9DpjH68.js";import{n as L}from"./useAsyncData-Buhk-UgR.js";import{t as R}from"./copy-icon-z8fuTE3w.js";import{r as z}from"./react-icons.esm-hr79-MCS.js";import{t as B}from"./events-CbeVJ6OD.js";import{n as V}from"./error-banner-Dw5YY9wq.js";var H=f(),U=_(),W=e(t(),1),G=n,fe=s({type:u(`stream_chunk`),message_id:c(),content:d().nullable().transform(e=>e),is_final:l().optional()});function pe(e,t){let{controllerRef:n,activeRequestIdRef:r}=t,i=n.current;if(i===null)return`dropped-no-controller`;let a=r.current;return a!==null&&e.message_id!==a?(p.debug(`Dropping stale chat chunk`,{chunkRequestId:e.message_id,activeRequestId:a}),`dropped-stale`):(e.content&&i.enqueue(e.content),e.is_final?(i.close(),n.current=null,r.current=null,`closed`):`enqueued`)}var K=e=>{let[t,n]=(0,W.useState)(``),[i,a]=(0,W.useState)(e.config),[o,s]=(0,W.useState)(e.config),[c,l]=(0,W.useState)(void 0),u=(0,W.useRef)(null),d=(0,W.useRef)(null),f=(0,W.useRef)(null),h=(0,W.useRef)(null);Object.keys(e.config).some(t=>e.config[t]!==o[t])&&(a(e.config),s(e.config));let _=(0,W.useRef)(i);_.current=i;let v=(0,W.useRef)(null),y=(0,W.useRef)(null),b=(0,W.useRef)(null),[x,S]=(0,W.useState)(null),T=()=>{b.current=null,S(null)},{data:O}=L(async()=>(await e.get_chat_history({})).messages,[]),j=e.value.length>0?e.value:O,{messages:M,sendMessage:N,setMessages:z,status:H,stop:G,error:K,regenerate:q,clearError:J,addToolApprovalResponse:Y}=le({sendAutomaticallyWhen:({messages:e})=>ce(e),transport:new ne({fetch:async(t,n)=>{if(n===void 0)return fetch(t);let r=JSON.parse(n.body),i=n.signal,a={max_tokens:_.current.max_tokens,temperature:_.current.temperature,top_p:_.current.top_p,top_k:_.current.top_k,frequency_penalty:_.current.frequency_penalty,presence_penalty:_.current.presence_penalty};try{let t=r.messages.map(e=>({...e,content:e.parts?.map(e=>`text`in e?e.text:``).join(`
2
+ `)})),n=I();T();let o=new ReadableStream({start(t){v.current=t,y.current=n;let r=()=>{try{t.close()}catch(e){p.debug(`Controller may already be closed`,{error:e})}v.current=null,y.current=null,e.cancel_prompt({request_id:n}).catch(e=>{p.debug(`cancel_prompt failed`,{error:e})})};return i?.addEventListener(`abort`,r),()=>{i?.removeEventListener(`abort`,r)}},cancel(){v.current=null,y.current=null}});return e.send_prompt({request_id:n,messages:t,config:a}).catch(e=>{v.current?.error(e),v.current=null,y.current=null}),re({stream:o})}catch(e){if(e instanceof Error&&e.name===`AbortError`)return new Response(`Aborted`,{status:499});let t=e.message?.split(`failed with exception `).pop();return new Response(t,{status:400})}}}),messages:j,onFinish:({messages:t,isAbort:n,finishReason:r})=>{if(l(void 0),u.current&&(u.current.value=``),p.debug(`Finished streaming message:`,{finishReason:r,isAbort:n}),n){let e=k({isAbort:!0,streamReason:b.current});if(T(),e!=null){let t=A(e);p.debug(`Chat stream aborted`,{reason:e,finishReason:r}),S(t)}}else T();e.setValue(t)},onError:e=>{p.error(`An error occurred:`,e)}});m(e.host,B.TYPE,e=>{let t=fe.safeParse(e.detail.message);if(t.success){if(t.data.content&&t.data.message_id===y.current){let e=ee(t.data.content);e!==void 0&&(b.current=e)}pe(t.data,{controllerRef:v,activeRequestIdRef:y})}});let X=H===`submitted`||H===`streaming`,Z=t=>{let n=M.findIndex(e=>e.id===t);if(n!==-1){let r=M.filter(e=>e.id!==t);e.delete_chat_message({index:n}),z(r),e.setValue(r),r.length===0&&T()}},ge=Array.isArray(e.allowAttachments)&&e.allowAttachments.length>0||e.allowAttachments===!0,_e={triggerCompletionRegex:/^\/(\w+)?/,completions:e.prompts.map(e=>({label:`/${e}`,displayLabel:e,apply:e}))},Q=e.prompts.length>0?`Type your message here, / for prompts`:`Type your message here...`;(0,W.useEffect)(()=>{h.current?.scrollTo({top:h.current.scrollHeight,behavior:`smooth`})},[M.length,h]);let $=f.current?.view,ve=()=>{if($){let e=$.state.doc.length;$.dispatch({changes:{from:0,to:e,insert:``}})}n(``)};return(0,U.jsxs)(`div`,{className:`flex flex-col h-full bg-(--slate-1) rounded-lg shadow border border-(--slate-6) overflow-hidden relative`,style:{maxHeight:e.maxHeight},children:[(0,U.jsx)(`div`,{className:`absolute top-0 right-0 flex justify-end z-10 border border-(--slate-6) bg-inherit rounded-bl-lg`,children:(0,U.jsx)(w,{variant:`text`,size:`icon`,disabled:M.length===0,onClick:()=>{z([]),e.setValue([]),e.delete_chat_history({}),J(),T()},children:(0,U.jsx)(de,{className:`h-3 w-3`})})}),(0,U.jsxs)(`div`,{className:`grow overflow-y-auto gap-4 pt-8 pb-4 px-2 flex flex-col`,ref:h,children:[M.length===0&&(0,U.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground text-center p-4`,children:[(0,U.jsx)(E,{className:`h-12 w-12 mb-4`}),(0,U.jsx)(`h3`,{className:`text-lg font-semibold mb-2`,children:`No messages yet`}),(0,U.jsx)(`p`,{className:`text-sm`,children:`Start a conversation by typing a message below.`})]}),M.map((e,t)=>{let n=e.parts?.filter(e=>e.type===`text`).map(e=>e.text).join(`
3
+ `),r=t===M.length-1;return(0,U.jsxs)(`div`,{className:g(`flex flex-col group gap-2`,e.role===`user`?`items-end`:`items-start`),children:[(0,U.jsx)(`div`,{className:`max-w-[80%] p-3 rounded-lg ${e.role===`user`?`bg-(--sky-11) text-(--slate-1) whitespace-pre-wrap`:`bg-(--slate-4) text-(--slate-12)`}`,children:te({message:e,isStreamingReasoning:H===`streaming`,isLast:r,isActive:X,addToolApprovalResponse:r?Y:void 0})}),(0,U.jsxs)(`div`,{className:`flex justify-end text-xs gap-2 invisible group-hover:visible`,children:[(0,U.jsx)(R,{value:n,className:`h-3 w-3`,buttonClassName:`text-xs text-(--slate-9) hover:text-(--slate-11)`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>Z(e.id),className:`text-xs text-(--slate-9) hover:text-(--slate-11)`,children:(0,U.jsx)(F,{className:`h-3 w-3 text-(--red-9)`})})]})]},`${e.id}-${t}`)}),X&&(0,U.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,U.jsx)(ue,{size:`small`})}),K&&(0,U.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 mb-4`,children:[(0,U.jsx)(V,{error:K}),(0,U.jsx)(w,{variant:`outline`,size:`sm`,onClick:()=>q(),children:`Retry`})]}),x&&!X&&!K&&(0,U.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,U.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:x})})]}),(0,U.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),e.disabled)return;let r=c?await ae(c):void 0;N({role:`user`,parts:[{type:`text`,text:t},...r??[]]}),ve()},ref:d,inert:e.disabled||void 0,className:g(`flex w-full border-t border-(--slate-6) px-2 py-1 items-center`,e.disabled&&`opacity-50 cursor-not-allowed`),children:[e.showConfigurationControls&&(0,U.jsx)(me,{config:i,onChange:a}),e.prompts.length>0&&(0,U.jsx)(he,{prompts:e.prompts,onSelect:e=>{n(e),requestAnimationFrame(()=>{$?.focus(),r($)})}}),(0,U.jsx)(oe,{className:`rounded-sm mr-2`,placeholder:Q,value:t,inputRef:f,maxHeight:e.maxHeight?`${e.maxHeight/2}px`:void 0,onChange:n,onSubmit:(e,t)=>{t.trim()&&d.current?.requestSubmit()},onClose:()=>{},additionalCompletions:_e}),c&&c.length===1&&(0,U.jsx)(`span`,{title:c[0].name,className:`text-sm text-(--slate-11) truncate shrink-0 w-fit max-w-24`,children:c[0].name}),c&&c.length>1&&(0,U.jsxs)(`span`,{title:[...c].map(e=>e.name).join(`
4
+ `),className:`text-sm text-(--slate-11) truncate shrink-0`,children:[c.length,` files`]}),c&&c.length>0&&(0,U.jsx)(w,{type:`button`,variant:`text`,size:`sm`,onClick:()=>{l(void 0),u.current&&(u.current.value=``)},children:(0,U.jsx)(D,{className:`size-3`})}),ge&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(w,{type:`button`,variant:`text`,size:`sm`,onClick:()=>u.current?.click(),children:(0,U.jsx)(se,{className:`h-4`})}),(0,U.jsx)(`input`,{type:`file`,ref:u,className:`hidden`,multiple:!0,accept:Array.isArray(e.allowAttachments)?e.allowAttachments.join(`,`):void 0,onChange:e=>{e.target.files&&l([...e.target.files])}})]}),X?(0,U.jsx)(C,{content:`Stop generating`,children:(0,U.jsx)(w,{type:`button`,variant:`link`,size:`xs`,onClick:()=>G(),className:`text-(--red-9) hover:text-(--red-11)`,children:(0,U.jsx)(P,{className:`h-4 w-4 fill-current`})})}):(0,U.jsx)(w,{type:`submit`,disabled:!t,variant:`outline`,size:`xs`,className:`text-(--slate-11)`,"aria-label":`Send message`,children:(0,U.jsx)(ie,{className:`h-4 w-4`})})]})]})},q={max_tokens:{min:1,max:4096,description:`Maximum number of tokens to generate`},temperature:{min:0,max:2,step:.1,description:`Controls randomness (0: deterministic, 2: very random)`},top_p:{min:0,max:1,step:.1,description:`Nucleus sampling: probability mass to consider`},top_k:{min:1,max:100,description:`Top-k sampling: number of highest probability tokens to consider`},frequency_penalty:{min:-2,max:2,description:`Penalizes frequent tokens (-2: favor, 2: avoid)`},presence_penalty:{min:-2,max:2,description:`Penalizes new tokens (-2: favor, 2: avoid)`}},me=e=>{let t=(0,H.c)(16),{config:n,onChange:r}=e,[s,c]=(0,W.useState)(!1),l;t[0]!==n||t[1]!==r?(l=(e,t)=>{let i=t===null||Number.isNaN(t)?null:t;if(i!==null){let{min:t,max:n}=q[e];i=Math.max(t,Math.min(n,i))}let a={...n,[e]:i};r(a)},t[0]=n,t[1]=r,t[2]=l):l=t[2];let u=l,d;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>{e.key===`Enter`&&(e.preventDefault(),c(!1))},t[3]=d):d=t[3];let f=d,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,U.jsx)(C,{content:`Configuration`,children:(0,U.jsx)(o,{asChild:!0,children:(0,U.jsx)(w,{variant:`outline`,size:`sm`,className:`border-none shadow-none hover:bg-transparent`,children:(0,U.jsx)(N,{className:`h-3 w-3`})})})}),t[4]=p):p=t[4];let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,U.jsx)(`h4`,{className:`font-bold leading-none`,children:`Configuration`}),t[5]=m):m=t[5];let g;if(t[6]!==n||t[7]!==u){let e;t[9]===u?e=t[10]:(e=e=>{let[t,n]=e;return(0,U.jsxs)(`div`,{className:`grid grid-cols-3 items-center gap-1`,children:[(0,U.jsxs)(v,{htmlFor:t,className:`flex w-full justify-between col-span-3 align-end`,children:[T.startCase(t),(0,U.jsx)(C,{delayDuration:200,side:`top`,content:(0,U.jsx)(`div`,{className:`text-xs flex flex-col`,children:q[t].description}),children:(0,U.jsx)(O,{className:`h-3 w-3 cursor-help text-muted-foreground hover:text-foreground`})})]}),(0,U.jsx)(j,{id:t,"aria-label":t,value:n??NaN,placeholder:`null`,minValue:q[t].min,maxValue:q[t].max,step:q[t].step??1,onChange:e=>u(t,e),onKeyDown:f,className:`col-span-3`})]},t)},t[9]=u,t[10]=e),g=h.entries(n).map(e),t[6]=n,t[7]=u,t[8]=g}else g=t[8];let _;t[11]===g?_=t[12]:(_=(0,U.jsx)(i,{className:`w-70 border`,children:(0,U.jsxs)(`div`,{className:`grid gap-3`,children:[m,g]})}),t[11]=g,t[12]=_);let y;return t[13]!==s||t[14]!==_?(y=(0,U.jsxs)(a,{open:s,onOpenChange:c,children:[p,_]}),t[13]=s,t[14]=_,t[15]=y):y=t[15],y},he=e=>{let t=(0,H.c)(18),{prompts:n,onSelect:r}=e,[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(``),u;t[0]===r?u=t[1]:(u=e=>{[...e.matchAll(/{{(\w+)}}/g)].length>0?(l(e),s(!0)):r(e)},t[0]=r,t[1]=u);let d=u,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,U.jsx)(C,{content:`Select a prompt`,children:(0,U.jsx)(b,{asChild:!0,children:(0,U.jsx)(w,{variant:`outline`,size:`sm`,className:`border-none shadow-none hover:bg-transparent`,children:(0,U.jsx)(z,{className:`h-3 w-3`})})})}),t[2]=f):f=t[2];let p;if(t[3]!==d||t[4]!==n){let e;t[6]===d?e=t[7]:(e=(e,t)=>(0,U.jsx)(y,{onSelect:()=>d(e),className:`whitespace-normal text-left`,children:e},t),t[6]=d,t[7]=e),p=n.map(e),t[3]=d,t[4]=n,t[5]=p}else p=t[5];let m;t[8]===p?m=t[9]:(m=(0,U.jsx)(G,{children:(0,U.jsxs)(S,{children:[f,(0,U.jsx)(x,{side:`right`,align:`end`,onCloseAutoFocus:Y,className:`w-64 max-h-96 overflow-y-auto`,children:p})]})}),t[8]=p,t[9]=m);let h;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>s(!1),t[10]=h):h=t[10];let g;t[11]!==r||t[12]!==c?(g=(0,U.jsx)(i,{side:`right`,align:`end`,className:`min-w-80 px-2`,children:(0,U.jsx)(J,{prompt:c,onClose:h,onSelect:r})}),t[11]=r,t[12]=c,t[13]=g):g=t[13];let _;return t[14]!==o||t[15]!==m||t[16]!==g?(_=(0,U.jsxs)(a,{open:o,onOpenChange:s,children:[m,g]}),t[14]=o,t[15]=m,t[16]=g,t[17]=_):_=t[17],_},J=e=>{let t=(0,H.c)(32),{prompt:n,onClose:r,onSelect:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a={},t[0]=a):a=t[0];let[o,s]=(0,W.useState)(a),c,l;t[1]===n?(c=t[2],l=t[3]):(c=()=>{let e=[...n.matchAll(/{{(\w+)}}/g)].reduce(X,{});s(e)},l=[n],t[1]=n,t[2]=c,t[3]=l),(0,W.useEffect)(c,l);let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(e,t)=>{s(n=>({...n,[e]:t}))},t[4]=u):u=t[4];let d=u,f;if(t[5]!==n||t[6]!==o){let e;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(e=/{{(\w+)}}/g,t[8]=e):e=t[8];let r;t[9]===o?r=t[10]:(r=(e,t)=>o[t]||`{{${t}}}`,t[9]=o,t[10]=r),f=n.replaceAll(e,r),t[5]=n,t[6]=o,t[7]=f}else f=t[7];let p=f,m;t[11]===o?m=t[12]:(m=Object.values(o).some(Z),t[11]=o,t[12]=m);let h=m,g;t[13]!==r||t[14]!==i||t[15]!==p?(g=()=>{i(p),r()},t[13]=r,t[14]=i,t[15]=p,t[16]=g):g=t[16];let _=g,y;t[17]===o?y=t[18]:(y=Object.entries(o),t[17]=o,t[18]=y);let b;t[19]!==_||t[20]!==h||t[21]!==y?(b=y.map((e,t)=>{let[n,r]=e;return(0,U.jsxs)(`div`,{className:`grid grid-cols-4 items-center gap-2`,children:[(0,U.jsx)(v,{htmlFor:n,className:`font-semibold text-base`,children:n}),(0,U.jsx)(M,{id:n,value:r,onChange:e=>d(n,e.target.value),rootClassName:`col-span-3 w-full`,className:`m-0`,placeholder:`Enter value for ${n}`,autoFocus:t===0,onKeyDown:e=>{e.key===`Enter`&&!h&&_()}})]},n)}),t[19]=_,t[20]=h,t[21]=y,t[22]=b):b=t[22];let x;t[23]===p?x=t[24]:(x=(0,U.jsx)(`div`,{className:`grid gap-2 prose dark:prose-invert`,children:(0,U.jsx)(`blockquote`,{className:`text-sm`,children:p})}),t[23]=p,t[24]=x);let S;t[25]!==_||t[26]!==h?(S=(0,U.jsx)(w,{onClick:_,size:`xs`,disabled:h,children:`Submit`}),t[25]=_,t[26]=h,t[27]=S):S=t[27];let C;return t[28]!==x||t[29]!==S||t[30]!==b?(C=(0,U.jsxs)(`div`,{className:`grid gap-4`,children:[b,x,S]}),t[28]=x,t[29]=S,t[30]=b,t[31]=C):C=t[31],C};function Y(e){return e.preventDefault()}function X(e,t){return e[t[1]]=``,e}function Z(e){return e==null||e.trim()===``}export{K as Chatbot};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{l as t}from"./useEvent-xfs0Sn4r.js";import{t as n}from"./react-CBDbhulC.js";import{Aa as r,D as i,Gt as a,Ta as o,Wt as s,ka as c}from"./cells-Cp-G34Rz.js";import{t as l}from"./compiler-runtime-CYIjoINj.js";import{c as u}from"./utils-D5Ywm7-q.js";import{t as d}from"./jsx-runtime-B74pBk57.js";import{l as f,p,yt as m}from"./JsonOutput-CzIGPEZQ.js";import{t as h}from"./tooltip-BUtPzKB4.js";import{r as g,t as _}from"./button-Dh8EwhsF.js";import{r as v}from"./requests-C6_IaFh7.js";import{t as y}from"./createLucideIcon-B7HeEoG2.js";import{t as b}from"./useLifecycle-BUaJcygz.js";import{t as x}from"./spinner-Ck-Hgfvj.js";import{r as S}from"./useTheme-C-ri8BtY.js";import{t as C}from"./context-Do8M9TDF.js";import{i as w}from"./numbers-Bc-r3jsC.js";import{t as T}from"./copy-icon-z8fuTE3w.js";var E=y(`square-plus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),D=l(),O=e(n(),1),k=d(),A=e=>{let t=(0,D.c)(53),{table:n,column:i,preview:a,onAddColumnChart:o,sqlTableContext:s}=e,{theme:l}=S(),{previewDatasetColumn:u}=v(),{locale:d}=C(),f;t[0]!==i.name||t[1]!==u||t[2]!==s||t[3]!==n.name||t[4]!==n.source||t[5]!==n.source_type?(f=()=>{u({source:n.source,tableName:n.name,columnName:i.name,sourceType:n.source_type,fullyQualifiedTableName:r(s,n.name)})},t[0]=i.name,t[1]=u,t[2]=s,t[3]=n.name,t[4]=n.source,t[5]=n.source_type,t[6]=f):f=t[6];let m=f,y;if(t[7]!==a||t[8]!==m||t[9]!==n.source_type?(y=()=>{a||n.source_type!==`connection`&&n.source_type!==`catalog`&&m()},t[7]=a,t[8]=m,t[9]=n.source_type,t[10]=y):y=t[10],b(y),n.source_type===`connection`){let e=i.name,r=i.external_type,a;t[11]!==i.name||t[12]!==o||t[13]!==s||t[14]!==n?(a=g.stopPropagation(()=>{o(c({table:n,columnName:i.name,sqlTableContext:s}))}),t[11]=i.name,t[12]=o,t[13]=s,t[14]=n,t[15]=a):a=t[15];let l;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,k.jsx)(E,{className:`h-3 w-3 mr-1`}),t[16]=l):l=t[16];let u;t[17]===a?u=t[18]:(u=(0,k.jsxs)(_,{variant:`outline`,size:`xs`,onClick:a,children:[l,` Add SQL cell`]}),t[17]=a,t[18]=u);let d;return t[19]!==i.external_type||t[20]!==i.name||t[21]!==u?(d=(0,k.jsxs)(`span`,{className:`text-xs text-muted-foreground gap-2 flex items-center justify-between pl-7`,children:[e,` (`,r,`)`,u]}),t[19]=i.external_type,t[20]=i.name,t[21]=u,t[22]=d):d=t[22],d}if(n.source_type===`catalog`){let e;return t[23]!==i.external_type||t[24]!==i.name?(e=(0,k.jsxs)(`span`,{className:`text-xs text-muted-foreground gap-2 flex items-center justify-between pl-7`,children:[i.name,` (`,i.external_type,`)`]}),t[23]=i.external_type,t[24]=i.name,t[25]=e):e=t[25],e}if(!a){let e;return t[26]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Loading...`}),t[26]=e):e=t[26],e}let x;t[27]!==a.error||t[28]!==a.missing_packages||t[29]!==m?(x=a.error&&j({error:a.error,missingPackages:a.missing_packages,refetchPreview:m}),t[27]=a.error,t[28]=a.missing_packages,t[29]=m,t[30]=x):x=t[30];let w=x,T;t[31]!==i.type||t[32]!==d||t[33]!==a.stats?(T=a.stats&&M({stats:a.stats,dataType:i.type,locale:d}),t[31]=i.type,t[32]=d,t[33]=a.stats,t[34]=T):T=t[34];let O=T,A;t[35]!==a.chart_spec||t[36]!==l?(A=a.chart_spec&&P(a.chart_spec,l),t[35]=a.chart_spec,t[36]=l,t[37]=A):A=t[37];let N=A,I;t[38]!==a.chart_code||t[39]!==n.source_type?(I=a.chart_code&&n.source_type===`local`&&(0,k.jsx)(F,{chartCode:a.chart_code}),t[38]=a.chart_code,t[39]=n.source_type,t[40]=I):I=t[40];let L=I,R;t[41]!==i.name||t[42]!==o||t[43]!==s||t[44]!==n?(R=n.source_type===`duckdb`&&(0,k.jsx)(h,{content:`Add SQL cell`,delayDuration:400,children:(0,k.jsx)(_,{variant:`outline`,size:`icon`,className:`z-10 bg-background absolute right-1 -top-1`,onClick:g.stopPropagation(()=>{o(c({table:n,columnName:i.name,sqlTableContext:s}))}),children:(0,k.jsx)(E,{className:`h-3 w-3`})})}),t[41]=i.name,t[42]=o,t[43]=s,t[44]=n,t[45]=R):R=t[45];let z=R;if(!w&&!O&&!N){let e;return t[46]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No data`}),t[46]=e):e=t[46],e}let B;return t[47]!==L||t[48]!==z||t[49]!==N||t[50]!==w||t[51]!==O?(B=(0,k.jsxs)(p,{children:[w,L,z,N,O]}),t[47]=L,t[48]=z,t[49]=N,t[50]=w,t[51]=O,t[52]=B):B=t[52],B};function j({error:e,missingPackages:t,refetchPreview:n}){return(0,k.jsxs)(`div`,{className:`text-xs text-muted-foreground p-2 border border-border rounded flex items-center justify-between`,children:[(0,k.jsx)(`span`,{children:e}),t&&(0,k.jsx)(f,{packages:t,showMaxPackages:1,className:`w-32`,onInstall:n})]})}function M({stats:e,dataType:t,locale:n}){return(0,k.jsx)(`div`,{className:`gap-x-16 gap-y-1 grid grid-cols-2-fit border rounded p-2 empty:hidden`,children:Object.entries(e).map(([e,r])=>r==null?null:(0,k.jsxs)(`div`,{className:`flex items-center gap-1 group`,children:[(0,k.jsx)(`span`,{className:`text-xs min-w-[60px] capitalize`,children:o(e,t)}),(0,k.jsx)(`span`,{className:`text-xs font-bold text-muted-foreground tracking-wide`,children:w(r,n)}),(0,k.jsx)(T,{className:`h-3 w-3 invisible group-hover:visible`,value:String(r)})]},e))})}var N=(0,k.jsx)(`div`,{className:`flex justify-center`,children:(0,k.jsx)(x,{className:`size-4`})});function P(e,t){return(0,k.jsx)(O.Suspense,{fallback:N,children:(0,k.jsx)(m,{"data-container-width":`container`,spec:(e=>({...e,background:`transparent`,config:{...e.config,background:`transparent`}}))(JSON.parse(e)),options:{theme:t===`dark`?`dark`:`vox`,height:100,width:`container`,actions:!1,renderer:`canvas`}})})}var F=e=>{let n=(0,D.c)(10),{chartCode:r}=e,o=t(u),c=s(),{createNewCell:l}=i(),d;n[0]!==o||n[1]!==l||n[2]!==c?(d=e=>{e.includes(`alt`)&&a({autoInstantiate:o,createNewCell:l,fromCellId:c}),l({code:e,before:!1,cellId:c??`__end__`})},n[0]=o,n[1]=l,n[2]=c,n[3]=d):d=n[3];let f=d,p;n[4]!==r||n[5]!==f?(p=g.stopPropagation(()=>f(r)),n[4]=r,n[5]=f,n[6]=p):p=n[6];let m;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,k.jsx)(E,{className:`h-3 w-3`}),n[7]=m):m=n[7];let v;return n[8]===p?v=n[9]:(v=(0,k.jsx)(h,{content:`Add chart to notebook`,delayDuration:400,children:(0,k.jsx)(_,{variant:`outline`,size:`icon`,className:`z-10 bg-background absolute right-1 -top-0.5`,onClick:p,children:m})}),n[8]=p,n[9]=v),v};export{M as a,j as i,A as n,E as o,P as r,F as t};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{l as t}from"./useEvent-xfs0Sn4r.js";import{t as n}from"./react-CBDbhulC.js";import{Aa as r,D as i,Ea as a,Gt as o,Kt as s,ja as c}from"./cells-BBhW3FXj.js";import{t as l}from"./compiler-runtime-CYIjoINj.js";import{c as u}from"./utils-D5Ywm7-q.js";import{t as d}from"./jsx-runtime-B74pBk57.js";import{l as f,p,yt as m}from"./JsonOutput-D2ZWLZs4.js";import{t as h}from"./tooltip-BUtPzKB4.js";import{r as g,t as _}from"./button-Dh8EwhsF.js";import{r as v}from"./requests-C6_IaFh7.js";import{t as y}from"./createLucideIcon-B7HeEoG2.js";import{t as b}from"./useLifecycle-BUaJcygz.js";import{t as x}from"./spinner-Ck-Hgfvj.js";import{r as S}from"./useTheme-C-ri8BtY.js";import{t as C}from"./context-Do8M9TDF.js";import{i as w}from"./numbers-Bc-r3jsC.js";import{t as T}from"./copy-icon-z8fuTE3w.js";var E=y(`square-plus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),D=l(),O=e(n(),1),k=d(),A=e=>{let t=(0,D.c)(53),{table:n,column:i,preview:a,onAddColumnChart:o,sqlTableContext:s}=e,{theme:l}=S(),{previewDatasetColumn:u}=v(),{locale:d}=C(),f;t[0]!==i.name||t[1]!==u||t[2]!==s||t[3]!==n.name||t[4]!==n.source||t[5]!==n.source_type?(f=()=>{u({source:n.source,tableName:n.name,columnName:i.name,sourceType:n.source_type,fullyQualifiedTableName:c(s,n.name)})},t[0]=i.name,t[1]=u,t[2]=s,t[3]=n.name,t[4]=n.source,t[5]=n.source_type,t[6]=f):f=t[6];let m=f,y;if(t[7]!==a||t[8]!==m||t[9]!==n.source_type?(y=()=>{a||n.source_type!==`connection`&&n.source_type!==`catalog`&&m()},t[7]=a,t[8]=m,t[9]=n.source_type,t[10]=y):y=t[10],b(y),n.source_type===`connection`){let e=i.name,a=i.external_type,c;t[11]!==i.name||t[12]!==o||t[13]!==s||t[14]!==n?(c=g.stopPropagation(()=>{o(r({table:n,columnName:i.name,sqlTableContext:s}))}),t[11]=i.name,t[12]=o,t[13]=s,t[14]=n,t[15]=c):c=t[15];let l;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,k.jsx)(E,{className:`h-3 w-3 mr-1`}),t[16]=l):l=t[16];let u;t[17]===c?u=t[18]:(u=(0,k.jsxs)(_,{variant:`outline`,size:`xs`,onClick:c,children:[l,` Add SQL cell`]}),t[17]=c,t[18]=u);let d;return t[19]!==i.external_type||t[20]!==i.name||t[21]!==u?(d=(0,k.jsxs)(`span`,{className:`text-xs text-muted-foreground gap-2 flex items-center justify-between pl-7`,children:[e,` (`,a,`)`,u]}),t[19]=i.external_type,t[20]=i.name,t[21]=u,t[22]=d):d=t[22],d}if(n.source_type===`catalog`){let e;return t[23]!==i.external_type||t[24]!==i.name?(e=(0,k.jsxs)(`span`,{className:`text-xs text-muted-foreground gap-2 flex items-center justify-between pl-7`,children:[i.name,` (`,i.external_type,`)`]}),t[23]=i.external_type,t[24]=i.name,t[25]=e):e=t[25],e}if(!a){let e;return t[26]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Loading...`}),t[26]=e):e=t[26],e}let x;t[27]!==a.error||t[28]!==a.missing_packages||t[29]!==m?(x=a.error&&j({error:a.error,missingPackages:a.missing_packages,refetchPreview:m}),t[27]=a.error,t[28]=a.missing_packages,t[29]=m,t[30]=x):x=t[30];let w=x,T;t[31]!==i.type||t[32]!==d||t[33]!==a.stats?(T=a.stats&&M({stats:a.stats,dataType:i.type,locale:d}),t[31]=i.type,t[32]=d,t[33]=a.stats,t[34]=T):T=t[34];let O=T,A;t[35]!==a.chart_spec||t[36]!==l?(A=a.chart_spec&&P(a.chart_spec,l),t[35]=a.chart_spec,t[36]=l,t[37]=A):A=t[37];let N=A,I;t[38]!==a.chart_code||t[39]!==n.source_type?(I=a.chart_code&&n.source_type===`local`&&(0,k.jsx)(F,{chartCode:a.chart_code}),t[38]=a.chart_code,t[39]=n.source_type,t[40]=I):I=t[40];let L=I,R;t[41]!==i.name||t[42]!==o||t[43]!==s||t[44]!==n?(R=n.source_type===`duckdb`&&(0,k.jsx)(h,{content:`Add SQL cell`,delayDuration:400,children:(0,k.jsx)(_,{variant:`outline`,size:`icon`,className:`z-10 bg-background absolute right-1 -top-1`,onClick:g.stopPropagation(()=>{o(r({table:n,columnName:i.name,sqlTableContext:s}))}),children:(0,k.jsx)(E,{className:`h-3 w-3`})})}),t[41]=i.name,t[42]=o,t[43]=s,t[44]=n,t[45]=R):R=t[45];let z=R;if(!w&&!O&&!N){let e;return t[46]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No data`}),t[46]=e):e=t[46],e}let B;return t[47]!==L||t[48]!==z||t[49]!==N||t[50]!==w||t[51]!==O?(B=(0,k.jsxs)(p,{children:[w,L,z,N,O]}),t[47]=L,t[48]=z,t[49]=N,t[50]=w,t[51]=O,t[52]=B):B=t[52],B};function j({error:e,missingPackages:t,refetchPreview:n}){return(0,k.jsxs)(`div`,{className:`text-xs text-muted-foreground p-2 border border-border rounded flex items-center justify-between`,children:[(0,k.jsx)(`span`,{children:e}),t&&(0,k.jsx)(f,{packages:t,showMaxPackages:1,className:`w-32`,onInstall:n})]})}function M({stats:e,dataType:t,locale:n}){return(0,k.jsx)(`div`,{className:`gap-x-16 gap-y-1 grid grid-cols-2-fit border rounded p-2 empty:hidden`,children:Object.entries(e).map(([e,r])=>r==null?null:(0,k.jsxs)(`div`,{className:`flex items-center gap-1 group`,children:[(0,k.jsx)(`span`,{className:`text-xs min-w-[60px] capitalize`,children:a(e,t)}),(0,k.jsx)(`span`,{className:`text-xs font-bold text-muted-foreground tracking-wide`,children:w(r,n)}),(0,k.jsx)(T,{className:`h-3 w-3 invisible group-hover:visible`,value:String(r)})]},e))})}var N=(0,k.jsx)(`div`,{className:`flex justify-center`,children:(0,k.jsx)(x,{className:`size-4`})});function P(e,t){return(0,k.jsx)(O.Suspense,{fallback:N,children:(0,k.jsx)(m,{"data-container-width":`container`,spec:(e=>({...e,background:`transparent`,config:{...e.config,background:`transparent`}}))(JSON.parse(e)),options:{theme:t===`dark`?`dark`:`vox`,height:100,width:`container`,actions:!1,renderer:`canvas`}})})}var F=e=>{let n=(0,D.c)(10),{chartCode:r}=e,a=t(u),c=o(),{createNewCell:l}=i(),d;n[0]!==a||n[1]!==l||n[2]!==c?(d=e=>{e.includes(`alt`)&&s({autoInstantiate:a,createNewCell:l,fromCellId:c}),l({code:e,before:!1,cellId:c??`__end__`})},n[0]=a,n[1]=l,n[2]=c,n[3]=d):d=n[3];let f=d,p;n[4]!==r||n[5]!==f?(p=g.stopPropagation(()=>f(r)),n[4]=r,n[5]=f,n[6]=p):p=n[6];let m;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,k.jsx)(E,{className:`h-3 w-3`}),n[7]=m):m=n[7];let v;return n[8]===p?v=n[9]:(v=(0,k.jsx)(h,{content:`Add chart to notebook`,delayDuration:400,children:(0,k.jsx)(_,{variant:`outline`,size:`icon`,className:`z-10 bg-background absolute right-1 -top-0.5`,onClick:p,children:m})}),n[8]=p,n[9]=v),v};export{M as a,j as i,A as n,E as o,P as r,F as t};