@marimo-team/frontend 0.24.3-dev80 → 0.24.3-dev81

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 (107) hide show
  1. package/dist/assets/{ConnectedDataExplorerComponent-S61Cojer.js → ConnectedDataExplorerComponent-DkTZ7AvX.js} +1 -1
  2. package/dist/assets/{ErrorBoundary-rFJTQttC.js → ErrorBoundary-DTpbqvzY.js} +2 -2
  3. package/dist/assets/{LazyAnyLanguageCodeMirror-DJWWnUeJ.js → LazyAnyLanguageCodeMirror-DYsZfkSk.js} +2 -2
  4. package/dist/assets/{RunButton-DfEJQMZn.js → RunButton-IMtEkRXV.js} +2 -2
  5. package/dist/assets/{abnfDiagram-VCTEODGH-Cp9dE6jg.js → abnfDiagram-VCTEODGH-pTFf_XLR.js} +1 -1
  6. package/dist/assets/{add-cell-with-ai-CY4gzrAg.js → add-cell-with-ai-CSNC0MIy.js} +1 -1
  7. package/dist/assets/{agent-panel-C3RY3rVh.js → agent-panel-DxU4qgxk.js} +1 -1
  8. package/dist/assets/{ai-model-dropdown-Bq7LNfwO.js → ai-model-dropdown-Ct4CTWKe.js} +1 -1
  9. package/dist/assets/{any-language-editor-DyDLZyTa.js → any-language-editor-DBp5CC3w.js} +1 -1
  10. package/dist/assets/{app-config-button-BEUe2niv.js → app-config-button-BjxXAmKd.js} +1 -1
  11. package/dist/assets/{architectureDiagram-5GKGNRK7-Bp0xYQON.js → architectureDiagram-5GKGNRK7-C7t0AR-N.js} +1 -1
  12. package/dist/assets/{blockDiagram-I7D4REHJ-CTdYGlif.js → blockDiagram-I7D4REHJ-DZgXohrV.js} +1 -1
  13. package/dist/assets/{cache-panel-BsWmIJNw.js → cache-panel-DDlfv8BP.js} +1 -1
  14. package/dist/assets/{cells-BY2lhea7.js → cells-C0itXtA7.js} +2 -2
  15. package/dist/assets/{chat-display-CHx8XIBv.js → chat-display-CHxh_MGC.js} +1 -1
  16. package/dist/assets/{chat-panel-akoUJ8qX.js → chat-panel-Ca6yjxkg.js} +1 -1
  17. package/dist/assets/{chat-ui-DZoDkcnO.js → chat-ui-D5zW1hYM.js} +1 -1
  18. package/dist/assets/{chunk-IMKFNOWR-BDUxpkzp.js → chunk-IMKFNOWR-CAmhQu-F.js} +1 -1
  19. package/dist/assets/{chunk-SHT3W25Y-BY2fwZu6.js → chunk-SHT3W25Y-BqEFXoRq.js} +1 -1
  20. package/dist/assets/{chunk-SVP7TREG-BMAK1dM1.js → chunk-SVP7TREG-Dxu0eRzD.js} +1 -1
  21. package/dist/assets/{chunk-TICWLB2K-DYvCP0dC.js → chunk-TICWLB2K-gHNMAWa9.js} +1 -1
  22. package/dist/assets/{classDiagram-ZZMXUADV-DInDmLPP.js → classDiagram-ZZMXUADV-DE3i3SzX.js} +1 -1
  23. package/dist/assets/{classDiagram-v2-VYDZK3BY-DInDmLPP.js → classDiagram-v2-VYDZK3BY-DE3i3SzX.js} +1 -1
  24. package/dist/assets/{code-visibility-C7jb6w0_.js → code-visibility-kUtIY_sH.js} +1 -1
  25. package/dist/assets/{command-palette-3rMZly6z.js → command-palette-BZJRR34P.js} +1 -1
  26. package/dist/assets/{common-Bg00voiB.js → common-DtiDLSXB.js} +1 -1
  27. package/dist/assets/{components-DF5RfdrX.js → components-CHh1MGbL.js} +1 -1
  28. package/dist/assets/{components-Djpop-6Y.js → components-DScgyZ8j.js} +1 -1
  29. package/dist/assets/{cynefinDiagram-5FMLGOSQ-DjGWNvBA.js → cynefinDiagram-5FMLGOSQ-C8RK-PLH.js} +1 -1
  30. package/dist/assets/{dagre-BdadXra2.js → dagre-Be6hV3Qt.js} +1 -1
  31. package/dist/assets/{dagre-GXQ25YYZ-4WrRwKjj.js → dagre-GXQ25YYZ-DZ6JGcBM.js} +1 -1
  32. package/dist/assets/{data-grid-overlay-editor-CdyFyGHp.js → data-grid-overlay-editor-BkZfO-uG.js} +1 -1
  33. package/dist/assets/{dependency-graph-panel-HTfghWvl.js → dependency-graph-panel-DhGTFsO9.js} +1 -1
  34. package/dist/assets/{diagram-S7CK7UJ4-BhNxBPOh.js → diagram-S7CK7UJ4-BN77DDKM.js} +1 -1
  35. package/dist/assets/{diagram-UQ7AKVKN-CpXP5J8O.js → diagram-UQ7AKVKN-BZthP0T4.js} +1 -1
  36. package/dist/assets/{diagram-VX7I27RA-8joParfV.js → diagram-VX7I27RA-D3GF3lRq.js} +1 -1
  37. package/dist/assets/{diagram-Z3DM3KII-Dj4QE7kS.js → diagram-Z3DM3KII-DnsKITpy.js} +1 -1
  38. package/dist/assets/{documentation-panel-BATWKMxI.js → documentation-panel-D8fz9UDV.js} +1 -1
  39. package/dist/assets/{ebnfDiagram-PWID7BFC-bg9GAIDY.js → ebnfDiagram-PWID7BFC-CHqqdhbQ.js} +1 -1
  40. package/dist/assets/{edit-page-Bw_9cD6X.js → edit-page-Cw1A5Rhq.js} +4 -4
  41. package/dist/assets/{erDiagram-RLTQ6QDP-B7AAtDAB.js → erDiagram-RLTQ6QDP-ChDyfc3w.js} +1 -1
  42. package/dist/assets/{error-entries-BGsjaQkq.js → error-entries-Dy7E9tUS.js} +1 -1
  43. package/dist/assets/{error-panel-gEXILkC3.js → error-panel-FYd4Tvsc.js} +1 -1
  44. package/dist/assets/{feedback-button-C_vk_D6i.js → feedback-button-Zjt-Mi38.js} +1 -1
  45. package/dist/assets/{file-explorer-panel-IuDHKOoY.js → file-explorer-panel-BpklXFSu.js} +1 -1
  46. package/dist/assets/{file-name-input-BOEaxkNs.js → file-name-input-DifonhZ7.js} +1 -1
  47. package/dist/assets/{flowDiagram-HODETNUW-CMeIUHlj.js → flowDiagram-HODETNUW-CelwDl0Y.js} +1 -1
  48. package/dist/assets/{gallery-page-CK1bqVLD.js → gallery-page-C0T1oyzr.js} +1 -1
  49. package/dist/assets/{glide-data-editor-DdFVvDaa.js → glide-data-editor-Dqd-if6R.js} +4 -4
  50. package/dist/assets/{graphlib-Czf9KyA4.js → graphlib-6_f7N0YM.js} +1 -1
  51. package/dist/assets/has-D5vyh6J_.js +1 -0
  52. package/dist/assets/{home-page-Da9V4OZH.js → home-page-CN05bwXu.js} +1 -1
  53. package/dist/assets/index-CcaMC2ZX.js +62 -0
  54. package/dist/assets/{infoDiagram-27XIBGKW-CIQ-BWOI.js → infoDiagram-27XIBGKW-Dh0ztpYZ.js} +1 -1
  55. package/dist/assets/{ishikawaDiagram-5VMMS53U-Dv_nv5Nd.js → ishikawaDiagram-5VMMS53U-Yy11Lj-8.js} +1 -1
  56. package/dist/assets/{kanban-definition-UXKFOSKX-XKnaVIBU.js → kanban-definition-UXKFOSKX-_hCm9ITM.js} +1 -1
  57. package/dist/assets/{logs-panel-De3Aixdf.js → logs-panel-D_Ki0PRi.js} +1 -1
  58. package/dist/assets/{mermaid-DxmgGQBY.js → mermaid-DUZOkwYg.js} +4 -4
  59. package/dist/assets/{mindmap-definition-YA3MSWOX-CaE8R-61.js → mindmap-definition-YA3MSWOX-CqKVab9Z.js} +1 -1
  60. package/dist/assets/{number-overlay-editor-DzvkzNgP.js → number-overlay-editor-BFwgibS5.js} +1 -1
  61. package/dist/assets/{outline-panel-C95qN5yF.js → outline-panel-BVLrHsJa.js} +1 -1
  62. package/dist/assets/{packages-panel-sY9qWXae.js → packages-panel-cq-qnvM5.js} +1 -1
  63. package/dist/assets/{panels-CCUm-UiE.js → panels-DwxpnIFf.js} +3 -3
  64. package/dist/assets/{pegDiagram-XKGWAZYB-CciXs9oJ.js → pegDiagram-XKGWAZYB-Cq-QrQFc.js} +1 -1
  65. package/dist/assets/{pieDiagram-E7YTZNPT-BbYR1uGC.js → pieDiagram-E7YTZNPT-DXU0ndOt.js} +1 -1
  66. package/dist/assets/{process-output-CGPaOEF_.js → process-output-B76bPsnA.js} +1 -1
  67. package/dist/assets/{railroadDiagram-O6MQD6OU-CcMt9sHo.js → railroadDiagram-O6MQD6OU-CFI_pgSK.js} +1 -1
  68. package/dist/assets/{requirementDiagram-BXWQKSXE-BCxwwt1G.js → requirementDiagram-BXWQKSXE-DgdygEWz.js} +1 -1
  69. package/dist/assets/{reveal-component-CkEkHMf-.js → reveal-component-BqiZOsW3.js} +1 -1
  70. package/dist/assets/{run-page-DuB25jlR.js → run-page-DVqnr-8x.js} +1 -1
  71. package/dist/assets/{scratchpad-panel-Dotdyqj2.js → scratchpad-panel-BT2lF-Gs.js} +1 -1
  72. package/dist/assets/{secrets-panel-1h46YXtq.js → secrets-panel-CeovmJAu.js} +1 -1
  73. package/dist/assets/{sequenceDiagram-WJ2MYXX4-BDiLUY65.js → sequenceDiagram-WJ2MYXX4-Cq7P3SPg.js} +1 -1
  74. package/dist/assets/{session-panel-C5KxX76R.js → session-panel-CGddxX8c.js} +1 -1
  75. package/dist/assets/{snippets-panel-C4akeu4G.js → snippets-panel-UawnfExC.js} +1 -1
  76. package/dist/assets/{stateDiagram-D77RDMKH-CDTKGawS.js → stateDiagram-D77RDMKH-CO8GuJdh.js} +1 -1
  77. package/dist/assets/{stateDiagram-v2-MP3YSRHH-DoZ64xoP.js → stateDiagram-v2-MP3YSRHH-DA7CflqT.js} +1 -1
  78. package/dist/assets/{swimlanes-42K2YHIH-CTH1Amtr.js → swimlanes-42K2YHIH-Bkf4BWja.js} +1 -1
  79. package/dist/assets/{swimlanesDiagram-VR7AAH4N-BeyRxUpX.js → swimlanesDiagram-VR7AAH4N-Bf0FHwi-.js} +1 -1
  80. package/dist/assets/{swiper-component-CUC6e6Nx.js → swiper-component-Dcb47cI1.js} +1 -1
  81. package/dist/assets/{terminal-C0R4btMV.js → terminal-bvd8BLSi.js} +1 -1
  82. package/dist/assets/{timeline-definition-24CTP7MA-BcRe5OGG.js → timeline-definition-24CTP7MA-CWdT681e.js} +1 -1
  83. package/dist/assets/{tracing-DiHWzXpM.js → tracing-BbV840Cl.js} +1 -1
  84. package/dist/assets/{tracing-panel-DNwBoqbU.js → tracing-panel-AQUl8b58.js} +2 -2
  85. package/dist/assets/{useCellActionButton-CSzUH7xJ.js → useCellActionButton-DIiKKxoN.js} +1 -1
  86. package/dist/assets/{vega-component-C3dqV-HG.js → vega-component-C5LY21OO.js} +1 -1
  87. package/dist/assets/{vega-embed-container-NsunuIaD.js → vega-embed-container-C6Hr9CZj.js} +1 -1
  88. package/dist/assets/{vennDiagram-4TSXK5OY-DT15w8Xq.js → vennDiagram-4TSXK5OY-B3uJF3gV.js} +1 -1
  89. package/dist/assets/{wardleyDiagram-VM6X3IG4-BTCnC8gB.js → wardleyDiagram-VM6X3IG4-DGmcLh5J.js} +1 -1
  90. package/dist/assets/{xychartDiagram-S5SC5T6Z-BtV9PLMA.js → xychartDiagram-S5SC5T6Z-kFxqIAk2.js} +1 -1
  91. package/dist/index.html +4 -4
  92. package/package.json +1 -1
  93. package/src/__mocks__/notebook.ts +1 -0
  94. package/src/components/editor/navigation/clipboard.ts +1 -0
  95. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +37 -0
  96. package/src/core/cells/__tests__/apply-transaction.test.ts +34 -0
  97. package/src/core/cells/__tests__/cells.test.ts +1 -0
  98. package/src/core/cells/__tests__/document-changes.test.ts +39 -1
  99. package/src/core/cells/__tests__/outputs.test.tsx +117 -0
  100. package/src/core/cells/__tests__/session.test.ts +7 -0
  101. package/src/core/cells/cells.ts +6 -1
  102. package/src/core/cells/document-changes.ts +11 -1
  103. package/src/core/cells/outputs.ts +66 -9
  104. package/src/core/cells/session.ts +2 -0
  105. package/src/core/cells/types.ts +2 -0
  106. package/dist/assets/has-Bpddg3XQ.js +0 -1
  107. package/dist/assets/index-BtFkx6qT.js +0 -62
@@ -1,4 +1,4 @@
1
- import{t as e}from"./graphlib-Czf9KyA4.js";import{A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,L as u,M as d,N as f,O as p,P as m,R as h,T as g,U as _,V as ee,W as te,b as v,j as y,k as b,l as x,v as S,w as C,z as w}from"./chunk-75Z2AOVW-DA_lihEi.js";import{u as T}from"./src-BpnPuKEN.js";import{n as E}from"./chunk-Y2CYZVJY-DsF7k-Jl.js";import{t as D}from"./src-Cyu5G-Tr.js";import{a as O,b as k,c as A,rt as ne,s as re,x as ie}from"./chunk-DU6HZSFF-J-califE.js";import{t as ae}from"./channel-ni7ei-yz.js";import"./chunk-P2QGCYS3-DsJshZeL.js";import"./chunk-PWAF6VOD-CrFPAGFi.js";import"./chunk-GMAD6QVW-mXoq4V-T.js";import"./chunk-4HAMMTFA-F3WVmmmo.js";import{i as oe,r as se}from"./chunk-GVQU2GXP-B-87l3Xt.js";import{a as ce,c as le,i as ue,s as de}from"./chunk-OSK3NFVY-PWoOtECb.js";import{t as fe}from"./chunk-5VM5RSS4-ZNzvKenW.js";function pe(e){return Array.isArray(e)}function me(e){if(v(e))return e;let t=s(e);if(!he(e))return{};if(pe(e)){let t=Array.from(e);return e.length>0&&typeof e[0]==`string`&&Object.hasOwn(e,`index`)&&(t.index=e.index,t.input=e.input),t}if(S(e)){let t=e,n=t.constructor;return new n(t.buffer,t.byteOffset,t.length)}if(t===`[object ArrayBuffer]`)return new ArrayBuffer(e.byteLength);if(t===`[object DataView]`){let t=e,n=t.buffer,r=t.byteOffset,i=t.byteLength,a=new ArrayBuffer(i),o=new Uint8Array(n,r,i);return new Uint8Array(a).set(o),new DataView(a)}if(t===`[object Boolean]`||t===`[object Number]`||t===`[object String]`){let n=e.constructor,r=new n(e.valueOf());return t===`[object String]`?_e(r,e):j(r,e),r}if(t===`[object Date]`)return new Date(Number(e));if(t===`[object RegExp]`){let t=e,n=new RegExp(t.source,t.flags);return n.lastIndex=t.lastIndex,n}if(t===`[object Symbol]`)return Object(Symbol.prototype.valueOf.call(e));if(t===`[object Map]`){let t=e,n=new Map;return t.forEach((e,t)=>{n.set(t,e)}),n}if(t===`[object Set]`){let t=e,n=new Set;return t.forEach(e=>{n.add(e)}),n}if(t===`[object Arguments]`){let t=e,n={};return j(n,t),n.length=t.length,n[Symbol.iterator]=t[Symbol.iterator],n}let n={};return ve(n,e),j(n,e),ge(n,e),n}function he(e){switch(s(e)){case r:case g:case C:case i:case a:case p:case b:case t:case f:case y:case d:case m:case o:case l:case u:case h:case w:case n:case _:case te:case ee:case c:return!0;default:return!1}}function j(e,t){for(let n in t)Object.hasOwn(t,n)&&(e[n]=t[n])}function ge(e,t){let n=Object.getOwnPropertySymbols(t);for(let r=0;r<n.length;r++){let i=n[r];Object.prototype.propertyIsEnumerable.call(t,i)&&(e[i]=t[i])}}function _e(e,t){let n=t.valueOf().length;for(let r in t)Object.hasOwn(t,r)&&(Number.isNaN(Number(r))||Number(r)>=n)&&(e[r]=t[r])}function ve(e,t){let n=Object.getPrototypeOf(t);n!==null&&typeof t.constructor==`function`&&Object.setPrototypeOf(e,n)}var M=(function(){var e=E(function(e,t,n,r){for(n||={},r=e.length;r--;n[e[r]]=t);return n},`o`),t=[1,15],n=[1,7],r=[1,13],i=[1,14],a=[1,19],o=[1,16],s=[1,17],c=[1,18],l=[8,30],u=[8,10,21,28,29,30,31,39,43,46],d=[1,23],f=[1,24],p=[8,10,15,16,21,28,29,30,31,39,43,46],m=[8,10,15,16,21,27,28,29,30,31,39,43,46],h=[1,49],g={trace:E(function(){},`trace`),yy:{},symbols_:{error:2,spaceLines:3,SPACELINE:4,NL:5,separator:6,SPACE:7,EOF:8,start:9,BLOCK_DIAGRAM_KEY:10,document:11,stop:12,statement:13,link:14,LINK:15,START_LINK:16,LINK_LABEL:17,STR:18,nodeStatement:19,columnsStatement:20,SPACE_BLOCK:21,blockStatement:22,classDefStatement:23,cssClassStatement:24,styleStatement:25,node:26,SIZE:27,COLUMNS:28,"id-block":29,end:30,NODE_ID:31,nodeShapeNLabel:32,dirList:33,DIR:34,NODE_DSTART:35,NODE_DEND:36,BLOCK_ARROW_START:37,BLOCK_ARROW_END:38,classDef:39,CLASSDEF_ID:40,CLASSDEF_STYLEOPTS:41,DEFAULT:42,class:43,CLASSENTITY_IDS:44,STYLECLASS:45,style:46,STYLE_ENTITY_IDS:47,STYLE_DEFINITION_DATA:48,$accept:0,$end:1},terminals_:{2:`error`,4:`SPACELINE`,5:`NL`,7:`SPACE`,8:`EOF`,10:`BLOCK_DIAGRAM_KEY`,15:`LINK`,16:`START_LINK`,17:`LINK_LABEL`,18:`STR`,21:`SPACE_BLOCK`,27:`SIZE`,28:`COLUMNS`,29:`id-block`,30:`end`,31:`NODE_ID`,34:`DIR`,35:`NODE_DSTART`,36:`NODE_DEND`,37:`BLOCK_ARROW_START`,38:`BLOCK_ARROW_END`,39:`classDef`,40:`CLASSDEF_ID`,41:`CLASSDEF_STYLEOPTS`,42:`DEFAULT`,43:`class`,44:`CLASSENTITY_IDS`,45:`STYLECLASS`,46:`style`,47:`STYLE_ENTITY_IDS`,48:`STYLE_DEFINITION_DATA`},productions_:[0,[3,1],[3,2],[3,2],[6,1],[6,1],[6,1],[9,3],[12,1],[12,1],[12,2],[12,2],[11,1],[11,2],[14,1],[14,4],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[19,3],[19,2],[19,1],[20,1],[22,4],[22,3],[26,1],[26,2],[33,1],[33,2],[32,3],[32,4],[23,3],[23,3],[24,3],[25,3]],performAction:E(function(e,t,n,r,i,a,o){var s=a.length-1;switch(i){case 4:r.getLogger().debug(`Rule: separator (NL) `);break;case 5:r.getLogger().debug(`Rule: separator (Space) `);break;case 6:r.getLogger().debug(`Rule: separator (EOF) `);break;case 7:r.getLogger().debug(`Rule: hierarchy: `,a[s-1]),r.setHierarchy(a[s-1]);break;case 8:r.getLogger().debug(`Stop NL `);break;case 9:r.getLogger().debug(`Stop EOF `);break;case 10:r.getLogger().debug(`Stop NL2 `);break;case 11:r.getLogger().debug(`Stop EOF2 `);break;case 12:r.getLogger().debug(`Rule: statement: `,a[s]),this.$=typeof a[s].length==`number`?a[s]:[a[s]];break;case 13:r.getLogger().debug(`Rule: statement #2: `,a[s-1]),this.$=[a[s-1]].concat(a[s]);break;case 14:r.getLogger().debug(`Rule: link: `,a[s],e),this.$={edgeTypeStr:a[s],label:``};break;case 15:r.getLogger().debug(`Rule: LABEL link: `,a[s-3],a[s-1],a[s]),this.$={edgeTypeStr:a[s],label:a[s-1]};break;case 18:let t=parseInt(a[s]),n=r.generateId();this.$={id:n,type:`space`,label:``,width:t,children:[]};break;case 23:r.getLogger().debug(`Rule: (nodeStatement link node) `,a[s-2],a[s-1],a[s],` typestr: `,a[s-1].edgeTypeStr);let i=r.edgeStrToEdgeData(a[s-1].edgeTypeStr),o=r.edgeStrToEdgeStartData(a[s-1].edgeTypeStr),c=r.edgeStrToThickness(a[s-1].edgeTypeStr),l=r.edgeStrToPattern(a[s-1].edgeTypeStr);this.$=[{id:a[s-2].id,label:a[s-2].label,type:a[s-2].type,directions:a[s-2].directions},{id:a[s-2].id+`-`+a[s].id,start:a[s-2].id,end:a[s].id,label:a[s-1].label,type:`edge`,thickness:c,pattern:l,directions:a[s].directions,arrowTypeEnd:i,arrowTypeStart:o},{id:a[s].id,label:a[s].label,type:r.typeStr2Type(a[s].typeStr),directions:a[s].directions}];break;case 24:r.getLogger().debug(`Rule: nodeStatement (abc88 node size) `,a[s-1],a[s]),this.$={id:a[s-1].id,label:a[s-1].label,type:r.typeStr2Type(a[s-1].typeStr),directions:a[s-1].directions,widthInColumns:parseInt(a[s],10)};break;case 25:r.getLogger().debug(`Rule: nodeStatement (node) `,a[s]),this.$={id:a[s].id,label:a[s].label,type:r.typeStr2Type(a[s].typeStr),directions:a[s].directions,widthInColumns:1};break;case 26:r.getLogger().debug(`APA123`,this?this:`na`),r.getLogger().debug(`COLUMNS: `,a[s]),this.$={type:`column-setting`,columns:a[s]===`auto`?-1:parseInt(a[s])};break;case 27:r.getLogger().debug(`Rule: id-block statement : `,a[s-2],a[s-1]),r.generateId(),this.$={...a[s-2],type:`composite`,children:a[s-1]};break;case 28:r.getLogger().debug(`Rule: blockStatement : `,a[s-2],a[s-1],a[s]);let u=r.generateId();this.$={id:u,type:`composite`,label:``,children:a[s-1]};break;case 29:r.getLogger().debug(`Rule: node (NODE_ID separator): `,a[s]),this.$={id:a[s]};break;case 30:r.getLogger().debug(`Rule: node (NODE_ID nodeShapeNLabel separator): `,a[s-1],a[s]),this.$={id:a[s-1],label:a[s].label,typeStr:a[s].typeStr,directions:a[s].directions};break;case 31:r.getLogger().debug(`Rule: dirList: `,a[s]),this.$=[a[s]];break;case 32:r.getLogger().debug(`Rule: dirList: `,a[s-1],a[s]),this.$=[a[s-1]].concat(a[s]);break;case 33:r.getLogger().debug(`Rule: nodeShapeNLabel: `,a[s-2],a[s-1],a[s]),this.$={typeStr:a[s-2]+a[s],label:a[s-1]};break;case 34:r.getLogger().debug(`Rule: BLOCK_ARROW nodeShapeNLabel: `,a[s-3],a[s-2],` #3:`,a[s-1],a[s]),this.$={typeStr:a[s-3]+a[s],label:a[s-2],directions:a[s-1]};break;case 35:case 36:this.$={type:`classDef`,id:a[s-1].trim(),css:a[s].trim()};break;case 37:this.$={type:`applyClass`,id:a[s-1].trim(),styleClass:a[s].trim()};break;case 38:this.$={type:`applyStyles`,id:a[s-1].trim(),stylesStr:a[s].trim()}}},`anonymous`),table:[{9:1,10:[1,2]},{1:[3]},{10:t,11:3,13:4,19:5,20:6,21:n,22:8,23:9,24:10,25:11,26:12,28:r,29:i,31:a,39:o,43:s,46:c},{8:[1,20]},e(l,[2,12],{13:4,19:5,20:6,22:8,23:9,24:10,25:11,26:12,11:21,10:t,21:n,28:r,29:i,31:a,39:o,43:s,46:c}),e(u,[2,16],{14:22,15:d,16:f}),e(u,[2,17]),e(u,[2,18]),e(u,[2,19]),e(u,[2,20]),e(u,[2,21]),e(u,[2,22]),e(p,[2,25],{27:[1,25]}),e(u,[2,26]),{19:26,26:12,31:a},{10:t,11:27,13:4,19:5,20:6,21:n,22:8,23:9,24:10,25:11,26:12,28:r,29:i,31:a,39:o,43:s,46:c},{40:[1,28],42:[1,29]},{44:[1,30]},{47:[1,31]},e(m,[2,29],{32:32,35:[1,33],37:[1,34]}),{1:[2,7]},e(l,[2,13]),{26:35,31:a},{31:[2,14]},{17:[1,36]},e(p,[2,24]),{10:t,11:37,13:4,14:22,15:d,16:f,19:5,20:6,21:n,22:8,23:9,24:10,25:11,26:12,28:r,29:i,31:a,39:o,43:s,46:c},{30:[1,38]},{41:[1,39]},{41:[1,40]},{45:[1,41]},{48:[1,42]},e(m,[2,30]),{18:[1,43]},{18:[1,44]},e(p,[2,23]),{18:[1,45]},{30:[1,46]},e(u,[2,28]),e(u,[2,35]),e(u,[2,36]),e(u,[2,37]),e(u,[2,38]),{36:[1,47]},{33:48,34:h},{15:[1,50]},e(u,[2,27]),e(m,[2,33]),{38:[1,51]},{33:52,34:h,38:[2,31]},{31:[2,15]},e(m,[2,34]),{38:[2,32]}],defaultActions:{20:[2,7],23:[2,14],50:[2,15],52:[2,32]},parseError:E(function(e,t){if(t.recoverable)this.trace(e);else{var n=Error(e);throw n.hash=t,n}},`parseError`),parse:E(function(e){var t=this,n=[0],r=[],i=[null],a=[],o=this.table,s=``,c=0,l=0,u=0,d=2,f=1,p=a.slice.call(arguments,1),m=Object.create(this.lexer),h={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(h.yy[g]=this.yy[g]);m.setInput(e,h.yy),h.yy.lexer=m,h.yy.parser=this,m.yylloc===void 0&&(m.yylloc={});var _=m.yylloc;a.push(_);var ee=m.options&&m.options.ranges;this.parseError=typeof h.yy.parseError==`function`?h.yy.parseError:Object.getPrototypeOf(this).parseError;function te(e){n.length-=2*e,i.length-=e,a.length-=e}E(te,`popStack`);function v(){var e=r.pop()||m.lex()||f;return typeof e!=`number`&&(e instanceof Array&&(r=e,e=r.pop()),e=t.symbols_[e]||e),e}E(v,`lex`);for(var y,b,x,S,C,w={},T,D,O,k;;){if(x=n[n.length-1],this.defaultActions[x]?S=this.defaultActions[x]:(y??=v(),S=o[x]&&o[x][y]),S===void 0||!S.length||!S[0]){var A=``;for(T in k=[],o[x])this.terminals_[T]&&T>d&&k.push(`'`+this.terminals_[T]+`'`);A=m.showPosition?`Parse error on line `+(c+1)+`:
1
+ import{t as e}from"./graphlib-6_f7N0YM.js";import{A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,L as u,M as d,N as f,O as p,P as m,R as h,T as g,U as _,V as ee,W as te,b as v,j as y,k as b,l as x,v as S,w as C,z as w}from"./chunk-75Z2AOVW-DA_lihEi.js";import{u as T}from"./src-BpnPuKEN.js";import{n as E}from"./chunk-Y2CYZVJY-DsF7k-Jl.js";import{t as D}from"./src-Cyu5G-Tr.js";import{a as O,b as k,c as A,rt as ne,s as re,x as ie}from"./chunk-DU6HZSFF-J-califE.js";import{t as ae}from"./channel-ni7ei-yz.js";import"./chunk-P2QGCYS3-DsJshZeL.js";import"./chunk-PWAF6VOD-CrFPAGFi.js";import"./chunk-GMAD6QVW-mXoq4V-T.js";import"./chunk-4HAMMTFA-F3WVmmmo.js";import{i as oe,r as se}from"./chunk-GVQU2GXP-B-87l3Xt.js";import{a as ce,c as le,i as ue,s as de}from"./chunk-OSK3NFVY-PWoOtECb.js";import{t as fe}from"./chunk-5VM5RSS4-ZNzvKenW.js";function pe(e){return Array.isArray(e)}function me(e){if(v(e))return e;let t=s(e);if(!he(e))return{};if(pe(e)){let t=Array.from(e);return e.length>0&&typeof e[0]==`string`&&Object.hasOwn(e,`index`)&&(t.index=e.index,t.input=e.input),t}if(S(e)){let t=e,n=t.constructor;return new n(t.buffer,t.byteOffset,t.length)}if(t===`[object ArrayBuffer]`)return new ArrayBuffer(e.byteLength);if(t===`[object DataView]`){let t=e,n=t.buffer,r=t.byteOffset,i=t.byteLength,a=new ArrayBuffer(i),o=new Uint8Array(n,r,i);return new Uint8Array(a).set(o),new DataView(a)}if(t===`[object Boolean]`||t===`[object Number]`||t===`[object String]`){let n=e.constructor,r=new n(e.valueOf());return t===`[object String]`?_e(r,e):j(r,e),r}if(t===`[object Date]`)return new Date(Number(e));if(t===`[object RegExp]`){let t=e,n=new RegExp(t.source,t.flags);return n.lastIndex=t.lastIndex,n}if(t===`[object Symbol]`)return Object(Symbol.prototype.valueOf.call(e));if(t===`[object Map]`){let t=e,n=new Map;return t.forEach((e,t)=>{n.set(t,e)}),n}if(t===`[object Set]`){let t=e,n=new Set;return t.forEach(e=>{n.add(e)}),n}if(t===`[object Arguments]`){let t=e,n={};return j(n,t),n.length=t.length,n[Symbol.iterator]=t[Symbol.iterator],n}let n={};return ve(n,e),j(n,e),ge(n,e),n}function he(e){switch(s(e)){case r:case g:case C:case i:case a:case p:case b:case t:case f:case y:case d:case m:case o:case l:case u:case h:case w:case n:case _:case te:case ee:case c:return!0;default:return!1}}function j(e,t){for(let n in t)Object.hasOwn(t,n)&&(e[n]=t[n])}function ge(e,t){let n=Object.getOwnPropertySymbols(t);for(let r=0;r<n.length;r++){let i=n[r];Object.prototype.propertyIsEnumerable.call(t,i)&&(e[i]=t[i])}}function _e(e,t){let n=t.valueOf().length;for(let r in t)Object.hasOwn(t,r)&&(Number.isNaN(Number(r))||Number(r)>=n)&&(e[r]=t[r])}function ve(e,t){let n=Object.getPrototypeOf(t);n!==null&&typeof t.constructor==`function`&&Object.setPrototypeOf(e,n)}var M=(function(){var e=E(function(e,t,n,r){for(n||={},r=e.length;r--;n[e[r]]=t);return n},`o`),t=[1,15],n=[1,7],r=[1,13],i=[1,14],a=[1,19],o=[1,16],s=[1,17],c=[1,18],l=[8,30],u=[8,10,21,28,29,30,31,39,43,46],d=[1,23],f=[1,24],p=[8,10,15,16,21,28,29,30,31,39,43,46],m=[8,10,15,16,21,27,28,29,30,31,39,43,46],h=[1,49],g={trace:E(function(){},`trace`),yy:{},symbols_:{error:2,spaceLines:3,SPACELINE:4,NL:5,separator:6,SPACE:7,EOF:8,start:9,BLOCK_DIAGRAM_KEY:10,document:11,stop:12,statement:13,link:14,LINK:15,START_LINK:16,LINK_LABEL:17,STR:18,nodeStatement:19,columnsStatement:20,SPACE_BLOCK:21,blockStatement:22,classDefStatement:23,cssClassStatement:24,styleStatement:25,node:26,SIZE:27,COLUMNS:28,"id-block":29,end:30,NODE_ID:31,nodeShapeNLabel:32,dirList:33,DIR:34,NODE_DSTART:35,NODE_DEND:36,BLOCK_ARROW_START:37,BLOCK_ARROW_END:38,classDef:39,CLASSDEF_ID:40,CLASSDEF_STYLEOPTS:41,DEFAULT:42,class:43,CLASSENTITY_IDS:44,STYLECLASS:45,style:46,STYLE_ENTITY_IDS:47,STYLE_DEFINITION_DATA:48,$accept:0,$end:1},terminals_:{2:`error`,4:`SPACELINE`,5:`NL`,7:`SPACE`,8:`EOF`,10:`BLOCK_DIAGRAM_KEY`,15:`LINK`,16:`START_LINK`,17:`LINK_LABEL`,18:`STR`,21:`SPACE_BLOCK`,27:`SIZE`,28:`COLUMNS`,29:`id-block`,30:`end`,31:`NODE_ID`,34:`DIR`,35:`NODE_DSTART`,36:`NODE_DEND`,37:`BLOCK_ARROW_START`,38:`BLOCK_ARROW_END`,39:`classDef`,40:`CLASSDEF_ID`,41:`CLASSDEF_STYLEOPTS`,42:`DEFAULT`,43:`class`,44:`CLASSENTITY_IDS`,45:`STYLECLASS`,46:`style`,47:`STYLE_ENTITY_IDS`,48:`STYLE_DEFINITION_DATA`},productions_:[0,[3,1],[3,2],[3,2],[6,1],[6,1],[6,1],[9,3],[12,1],[12,1],[12,2],[12,2],[11,1],[11,2],[14,1],[14,4],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[19,3],[19,2],[19,1],[20,1],[22,4],[22,3],[26,1],[26,2],[33,1],[33,2],[32,3],[32,4],[23,3],[23,3],[24,3],[25,3]],performAction:E(function(e,t,n,r,i,a,o){var s=a.length-1;switch(i){case 4:r.getLogger().debug(`Rule: separator (NL) `);break;case 5:r.getLogger().debug(`Rule: separator (Space) `);break;case 6:r.getLogger().debug(`Rule: separator (EOF) `);break;case 7:r.getLogger().debug(`Rule: hierarchy: `,a[s-1]),r.setHierarchy(a[s-1]);break;case 8:r.getLogger().debug(`Stop NL `);break;case 9:r.getLogger().debug(`Stop EOF `);break;case 10:r.getLogger().debug(`Stop NL2 `);break;case 11:r.getLogger().debug(`Stop EOF2 `);break;case 12:r.getLogger().debug(`Rule: statement: `,a[s]),this.$=typeof a[s].length==`number`?a[s]:[a[s]];break;case 13:r.getLogger().debug(`Rule: statement #2: `,a[s-1]),this.$=[a[s-1]].concat(a[s]);break;case 14:r.getLogger().debug(`Rule: link: `,a[s],e),this.$={edgeTypeStr:a[s],label:``};break;case 15:r.getLogger().debug(`Rule: LABEL link: `,a[s-3],a[s-1],a[s]),this.$={edgeTypeStr:a[s],label:a[s-1]};break;case 18:let t=parseInt(a[s]),n=r.generateId();this.$={id:n,type:`space`,label:``,width:t,children:[]};break;case 23:r.getLogger().debug(`Rule: (nodeStatement link node) `,a[s-2],a[s-1],a[s],` typestr: `,a[s-1].edgeTypeStr);let i=r.edgeStrToEdgeData(a[s-1].edgeTypeStr),o=r.edgeStrToEdgeStartData(a[s-1].edgeTypeStr),c=r.edgeStrToThickness(a[s-1].edgeTypeStr),l=r.edgeStrToPattern(a[s-1].edgeTypeStr);this.$=[{id:a[s-2].id,label:a[s-2].label,type:a[s-2].type,directions:a[s-2].directions},{id:a[s-2].id+`-`+a[s].id,start:a[s-2].id,end:a[s].id,label:a[s-1].label,type:`edge`,thickness:c,pattern:l,directions:a[s].directions,arrowTypeEnd:i,arrowTypeStart:o},{id:a[s].id,label:a[s].label,type:r.typeStr2Type(a[s].typeStr),directions:a[s].directions}];break;case 24:r.getLogger().debug(`Rule: nodeStatement (abc88 node size) `,a[s-1],a[s]),this.$={id:a[s-1].id,label:a[s-1].label,type:r.typeStr2Type(a[s-1].typeStr),directions:a[s-1].directions,widthInColumns:parseInt(a[s],10)};break;case 25:r.getLogger().debug(`Rule: nodeStatement (node) `,a[s]),this.$={id:a[s].id,label:a[s].label,type:r.typeStr2Type(a[s].typeStr),directions:a[s].directions,widthInColumns:1};break;case 26:r.getLogger().debug(`APA123`,this?this:`na`),r.getLogger().debug(`COLUMNS: `,a[s]),this.$={type:`column-setting`,columns:a[s]===`auto`?-1:parseInt(a[s])};break;case 27:r.getLogger().debug(`Rule: id-block statement : `,a[s-2],a[s-1]),r.generateId(),this.$={...a[s-2],type:`composite`,children:a[s-1]};break;case 28:r.getLogger().debug(`Rule: blockStatement : `,a[s-2],a[s-1],a[s]);let u=r.generateId();this.$={id:u,type:`composite`,label:``,children:a[s-1]};break;case 29:r.getLogger().debug(`Rule: node (NODE_ID separator): `,a[s]),this.$={id:a[s]};break;case 30:r.getLogger().debug(`Rule: node (NODE_ID nodeShapeNLabel separator): `,a[s-1],a[s]),this.$={id:a[s-1],label:a[s].label,typeStr:a[s].typeStr,directions:a[s].directions};break;case 31:r.getLogger().debug(`Rule: dirList: `,a[s]),this.$=[a[s]];break;case 32:r.getLogger().debug(`Rule: dirList: `,a[s-1],a[s]),this.$=[a[s-1]].concat(a[s]);break;case 33:r.getLogger().debug(`Rule: nodeShapeNLabel: `,a[s-2],a[s-1],a[s]),this.$={typeStr:a[s-2]+a[s],label:a[s-1]};break;case 34:r.getLogger().debug(`Rule: BLOCK_ARROW nodeShapeNLabel: `,a[s-3],a[s-2],` #3:`,a[s-1],a[s]),this.$={typeStr:a[s-3]+a[s],label:a[s-2],directions:a[s-1]};break;case 35:case 36:this.$={type:`classDef`,id:a[s-1].trim(),css:a[s].trim()};break;case 37:this.$={type:`applyClass`,id:a[s-1].trim(),styleClass:a[s].trim()};break;case 38:this.$={type:`applyStyles`,id:a[s-1].trim(),stylesStr:a[s].trim()}}},`anonymous`),table:[{9:1,10:[1,2]},{1:[3]},{10:t,11:3,13:4,19:5,20:6,21:n,22:8,23:9,24:10,25:11,26:12,28:r,29:i,31:a,39:o,43:s,46:c},{8:[1,20]},e(l,[2,12],{13:4,19:5,20:6,22:8,23:9,24:10,25:11,26:12,11:21,10:t,21:n,28:r,29:i,31:a,39:o,43:s,46:c}),e(u,[2,16],{14:22,15:d,16:f}),e(u,[2,17]),e(u,[2,18]),e(u,[2,19]),e(u,[2,20]),e(u,[2,21]),e(u,[2,22]),e(p,[2,25],{27:[1,25]}),e(u,[2,26]),{19:26,26:12,31:a},{10:t,11:27,13:4,19:5,20:6,21:n,22:8,23:9,24:10,25:11,26:12,28:r,29:i,31:a,39:o,43:s,46:c},{40:[1,28],42:[1,29]},{44:[1,30]},{47:[1,31]},e(m,[2,29],{32:32,35:[1,33],37:[1,34]}),{1:[2,7]},e(l,[2,13]),{26:35,31:a},{31:[2,14]},{17:[1,36]},e(p,[2,24]),{10:t,11:37,13:4,14:22,15:d,16:f,19:5,20:6,21:n,22:8,23:9,24:10,25:11,26:12,28:r,29:i,31:a,39:o,43:s,46:c},{30:[1,38]},{41:[1,39]},{41:[1,40]},{45:[1,41]},{48:[1,42]},e(m,[2,30]),{18:[1,43]},{18:[1,44]},e(p,[2,23]),{18:[1,45]},{30:[1,46]},e(u,[2,28]),e(u,[2,35]),e(u,[2,36]),e(u,[2,37]),e(u,[2,38]),{36:[1,47]},{33:48,34:h},{15:[1,50]},e(u,[2,27]),e(m,[2,33]),{38:[1,51]},{33:52,34:h,38:[2,31]},{31:[2,15]},e(m,[2,34]),{38:[2,32]}],defaultActions:{20:[2,7],23:[2,14],50:[2,15],52:[2,32]},parseError:E(function(e,t){if(t.recoverable)this.trace(e);else{var n=Error(e);throw n.hash=t,n}},`parseError`),parse:E(function(e){var t=this,n=[0],r=[],i=[null],a=[],o=this.table,s=``,c=0,l=0,u=0,d=2,f=1,p=a.slice.call(arguments,1),m=Object.create(this.lexer),h={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(h.yy[g]=this.yy[g]);m.setInput(e,h.yy),h.yy.lexer=m,h.yy.parser=this,m.yylloc===void 0&&(m.yylloc={});var _=m.yylloc;a.push(_);var ee=m.options&&m.options.ranges;this.parseError=typeof h.yy.parseError==`function`?h.yy.parseError:Object.getPrototypeOf(this).parseError;function te(e){n.length-=2*e,i.length-=e,a.length-=e}E(te,`popStack`);function v(){var e=r.pop()||m.lex()||f;return typeof e!=`number`&&(e instanceof Array&&(r=e,e=r.pop()),e=t.symbols_[e]||e),e}E(v,`lex`);for(var y,b,x,S,C,w={},T,D,O,k;;){if(x=n[n.length-1],this.defaultActions[x]?S=this.defaultActions[x]:(y??=v(),S=o[x]&&o[x][y]),S===void 0||!S.length||!S[0]){var A=``;for(T in k=[],o[x])this.terminals_[T]&&T>d&&k.push(`'`+this.terminals_[T]+`'`);A=m.showPosition?`Parse error on line `+(c+1)+`:
2
2
  `+m.showPosition()+`
3
3
  Expecting `+k.join(`, `)+`, got '`+(this.terminals_[y]||y)+`'`:`Parse error on line `+(c+1)+`: Unexpected `+(y==f?`end of input`:`'`+(this.terminals_[y]||y)+`'`),this.parseError(A,{text:m.match,token:this.terminals_[y]||y,line:m.yylineno,loc:_,expected:k})}if(S[0]instanceof Array&&S.length>1)throw Error(`Parse Error: multiple actions possible at state: `+x+`, token: `+y);switch(S[0]){case 1:n.push(y),i.push(m.yytext),a.push(m.yylloc),n.push(S[1]),y=null,b?(y=b,b=null):(l=m.yyleng,s=m.yytext,c=m.yylineno,_=m.yylloc,u>0&&u--);break;case 2:if(D=this.productions_[S[1]][1],w.$=i[i.length-D],w._$={first_line:a[a.length-(D||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(D||1)].first_column,last_column:a[a.length-1].last_column},ee&&(w._$.range=[a[a.length-(D||1)].range[0],a[a.length-1].range[1]]),C=this.performAction.apply(w,[s,l,c,h.yy,S[1],i,a].concat(p)),C!==void 0)return C;D&&(n=n.slice(0,-1*D*2),i=i.slice(0,-1*D),a=a.slice(0,-1*D)),n.push(this.productions_[S[1]][0]),i.push(w.$),a.push(w._$),O=o[n[n.length-2]][n[n.length-1]],n.push(O);break;case 3:return!0}}return!0},`parse`)};g.lexer=(function(){return{EOF:1,parseError:E(function(e,t){if(this.yy.parser)this.yy.parser.parseError(e,t);else throw Error(e)},`parseError`),setInput:E(function(e,t){return this.yy=t||this.yy||{},this._input=e,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match=``,this.conditionStack=[`INITIAL`],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},`setInput`),input:E(function(){var e=this._input[0];return this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e,e.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},`input`),unput:E(function(e){var t=e.length,n=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-t),this.offset-=t;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-t]),this.yyleng=this.yytext.length,this},`unput`),more:E(function(){return this._more=!0,this},`more`),reject:E(function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError(`Lexical error on line `+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
4
4
  `+this.showPosition(),{text:``,token:null,line:this.yylineno});return this},`reject`),less:E(function(e){this.unput(this.match.slice(e))},`less`),pastInput:E(function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(e.length>20?`...`:``)+e.substr(-20).replace(/\n/g,``)},`pastInput`),upcomingInput:E(function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(e.length>20?`...`:``)).replace(/\n/g,``)},`upcomingInput`),showPosition:E(function(){var e=this.pastInput(),t=Array(e.length+1).join(`-`);return e+this.upcomingInput()+`
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{l as t}from"./useEvent-Dc9HkKI2.js";import{t as n}from"./react-CUdNIagt.js";import{t as r}from"./compiler-runtime-BQ9S8nyo.js";import{t as i}from"./cn-ldLVeaqm.js";import{t as a}from"./jsx-runtime-B74pBk57.js";import{a as o,c as s,i as c,l,n as u,o as d,r as f,s as p,t as m,u as h}from"./alert-dialog-CeE3i3Qa.js";import{t as g}from"./button-BoklZTGL.js";import{Q as _}from"./panels-CCUm-UiE.js";import{F as v,I as y}from"./RunButton-DfEJQMZn.js";import{t as b}from"./database-zap-CrkOvbyN.js";import{t as x}from"./trash-2-BJG-7Qob.js";import{t as S}from"./use-toast-CC89xOwH.js";import{r as C}from"./requests-yTHMxhVa.js";import{t as w}from"./context-BFOBKCJB.js";import{i as T}from"./numbers-DsgsDslU.js";import{n as E}from"./useAsyncData-DucTwMkf.js";import{ei as D,pa as O}from"./index-BtFkx6qT.js";import{t as k}from"./empty-state-CzxjZqGW.js";var A=r(),j=e(n(),1),M=a(),N=e=>{let t=(0,A.c)(27),{children:n,title:r,description:i,onConfirm:a,confirmText:g,cancelText:_,destructive:v}=e,y=g===void 0?`Continue`:g,b=_===void 0?`Cancel`:_,x=v!==void 0&&v,[S,C]=j.useState(!1),w;t[0]===a?w=t[1]:(w=()=>{a(),C(!1)},t[0]=a,t[1]=w);let T=w,E=x?d:u,D;t[2]===n?D=t[3]:(D=(0,M.jsx)(h,{asChild:!0,children:n}),t[2]=n,t[3]=D);let O;t[4]===r?O=t[5]:(O=(0,M.jsx)(l,{children:r}),t[4]=r,t[5]=O);let k;t[6]===i?k=t[7]:(k=(0,M.jsx)(o,{children:i}),t[6]=i,t[7]=k);let N;t[8]!==O||t[9]!==k?(N=(0,M.jsxs)(s,{children:[O,k]}),t[8]=O,t[9]=k,t[10]=N):N=t[10];let P;t[11]===b?P=t[12]:(P=(0,M.jsx)(f,{children:b}),t[11]=b,t[12]=P);let F;t[13]!==E||t[14]!==y||t[15]!==T?(F=(0,M.jsx)(E,{onClick:T,children:y}),t[13]=E,t[14]=y,t[15]=T,t[16]=F):F=t[16];let I;t[17]!==F||t[18]!==P?(I=(0,M.jsxs)(p,{children:[P,F]}),t[17]=F,t[18]=P,t[19]=I):I=t[19];let L;t[20]!==I||t[21]!==N?(L=(0,M.jsxs)(c,{children:[N,I]}),t[20]=I,t[21]=N,t[22]=L):L=t[22];let R;return t[23]!==S||t[24]!==L||t[25]!==D?(R=(0,M.jsxs)(m,{open:S,onOpenChange:C,children:[D,L]}),t[23]=S,t[24]=L,t[25]=D,t[26]=R):R=t[26],R},P=()=>{let{clearCache:e,getCacheInfo:n}=C(),r=t(_),[a,o]=(0,j.useState)(!1),{locale:s}=w(),{isPending:c,isFetching:l,refetch:u}=E(async()=>{await n(),await new Promise(e=>setTimeout(e,500))},[]),d=async()=>{try{o(!0),await e(),S({title:`Cache purged`,description:`All cached data has been cleared`}),u()}catch(e){S({title:`Error`,description:e instanceof Error?e.message:`Failed to purge cache`,variant:`danger`})}finally{o(!1)}};if(c&&!r)return(0,M.jsx)(D,{size:`medium`,centered:!0});let f=(0,M.jsxs)(g,{variant:`outline`,size:`sm`,onClick:u,disabled:l,children:[l?(0,M.jsx)(D,{size:`small`,className:`w-4 h-4 mr-2`}):(0,M.jsx)(O,{className:`w-4 h-4 mr-2`}),`Refresh`]});if(!r)return(0,M.jsx)(k,{title:`No cache data`,description:`Cache information is not available.`,icon:(0,M.jsx)(b,{}),action:f});let p=r.hits,m=r.misses,h=r.time,A=r.disk_total,P=r.disk_to_free,I=p+m,L=I>0?p/I*100:0;return I===0?(0,M.jsx)(k,{title:`No cache activity`,description:`The cache has not been used yet. Cached functions will appear here once they are executed.`,icon:(0,M.jsx)(b,{}),action:f}):(0,M.jsx)(`div`,{className:`flex flex-col h-full overflow-auto`,children:(0,M.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 h-full`,children:[(0,M.jsx)(`div`,{className:`flex items-center justify-end`,children:(0,M.jsx)(g,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:u,disabled:l,children:(0,M.jsx)(O,{className:i(`h-4 w-4 text-muted-foreground hover:text-foreground`,l&&`animate-[spin_0.5s]`)})})}),(0,M.jsxs)(`div`,{className:`space-y-3`,children:[(0,M.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Statistics`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,M.jsx)(F,{label:`Time saved`,value:y(h,s),description:`Total execution time saved`}),(0,M.jsx)(F,{label:`Hit rate`,value:I>0?`${T(L,s)}%`:`—`,description:`${T(p,s)} hits / ${T(I,s)} total`}),(0,M.jsx)(F,{label:`Cache hits`,value:T(p,s),description:`Successful cache retrievals`}),(0,M.jsx)(F,{label:`Cache misses`,value:T(m,s),description:`Cache not found`})]})]}),A>0&&(0,M.jsxs)(`div`,{className:`space-y-3 pt-2 border-t`,children:[(0,M.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Storage`}),(0,M.jsx)(`div`,{className:`grid grid-cols-1 gap-3`,children:(0,M.jsx)(F,{label:`Disk usage`,value:v(A,s),description:P>0?`${v(P,s)} can be freed`:`Cache storage on disk`})})]}),(0,M.jsx)(`div`,{className:`my-auto`}),(0,M.jsx)(`div`,{className:`pt-2 border-t`,children:(0,M.jsx)(N,{title:`Purge cache?`,description:`This will permanently delete all cached data. This action cannot be undone.`,confirmText:`Purge`,destructive:!0,onConfirm:d,children:(0,M.jsxs)(g,{variant:`outlineDestructive`,size:`xs`,disabled:a,className:`w-full`,children:[a?(0,M.jsx)(D,{size:`small`,className:`w-3 h-3 mr-2`}):(0,M.jsx)(x,{className:`w-3 h-3 mr-2`}),`Purge Cache`]})})})]})})},F=e=>{let t=(0,A.c)(10),{label:n,value:r,description:i}=e,a;t[0]===n?a=t[1]:(a=(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,M.jsx)(`span`,{className:`text-lg font-semibold`,children:r}),t[2]=r,t[3]=o);let s;t[4]===i?s=t[5]:(s=i&&(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i}),t[4]=i,t[5]=s);let c;return t[6]!==a||t[7]!==o||t[8]!==s?(c=(0,M.jsxs)(`div`,{className:`flex flex-col gap-1 p-3 rounded-lg border bg-card`,children:[a,o,s]}),t[6]=a,t[7]=o,t[8]=s,t[9]=c):c=t[9],c};export{P as default};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{l as t}from"./useEvent-Dc9HkKI2.js";import{t as n}from"./react-CUdNIagt.js";import{t as r}from"./compiler-runtime-BQ9S8nyo.js";import{t as i}from"./cn-ldLVeaqm.js";import{t as a}from"./jsx-runtime-B74pBk57.js";import{a as o,c as s,i as c,l,n as u,o as d,r as f,s as p,t as m,u as h}from"./alert-dialog-CeE3i3Qa.js";import{t as g}from"./button-BoklZTGL.js";import{Q as _}from"./panels-DwxpnIFf.js";import{F as v,I as y}from"./RunButton-IMtEkRXV.js";import{t as b}from"./database-zap-CrkOvbyN.js";import{t as x}from"./trash-2-BJG-7Qob.js";import{t as S}from"./use-toast-CC89xOwH.js";import{r as C}from"./requests-yTHMxhVa.js";import{t as w}from"./context-BFOBKCJB.js";import{i as T}from"./numbers-DsgsDslU.js";import{n as E}from"./useAsyncData-DucTwMkf.js";import{ei as D,pa as O}from"./index-CcaMC2ZX.js";import{t as k}from"./empty-state-CzxjZqGW.js";var A=r(),j=e(n(),1),M=a(),N=e=>{let t=(0,A.c)(27),{children:n,title:r,description:i,onConfirm:a,confirmText:g,cancelText:_,destructive:v}=e,y=g===void 0?`Continue`:g,b=_===void 0?`Cancel`:_,x=v!==void 0&&v,[S,C]=j.useState(!1),w;t[0]===a?w=t[1]:(w=()=>{a(),C(!1)},t[0]=a,t[1]=w);let T=w,E=x?d:u,D;t[2]===n?D=t[3]:(D=(0,M.jsx)(h,{asChild:!0,children:n}),t[2]=n,t[3]=D);let O;t[4]===r?O=t[5]:(O=(0,M.jsx)(l,{children:r}),t[4]=r,t[5]=O);let k;t[6]===i?k=t[7]:(k=(0,M.jsx)(o,{children:i}),t[6]=i,t[7]=k);let N;t[8]!==O||t[9]!==k?(N=(0,M.jsxs)(s,{children:[O,k]}),t[8]=O,t[9]=k,t[10]=N):N=t[10];let P;t[11]===b?P=t[12]:(P=(0,M.jsx)(f,{children:b}),t[11]=b,t[12]=P);let F;t[13]!==E||t[14]!==y||t[15]!==T?(F=(0,M.jsx)(E,{onClick:T,children:y}),t[13]=E,t[14]=y,t[15]=T,t[16]=F):F=t[16];let I;t[17]!==F||t[18]!==P?(I=(0,M.jsxs)(p,{children:[P,F]}),t[17]=F,t[18]=P,t[19]=I):I=t[19];let L;t[20]!==I||t[21]!==N?(L=(0,M.jsxs)(c,{children:[N,I]}),t[20]=I,t[21]=N,t[22]=L):L=t[22];let R;return t[23]!==S||t[24]!==L||t[25]!==D?(R=(0,M.jsxs)(m,{open:S,onOpenChange:C,children:[D,L]}),t[23]=S,t[24]=L,t[25]=D,t[26]=R):R=t[26],R},P=()=>{let{clearCache:e,getCacheInfo:n}=C(),r=t(_),[a,o]=(0,j.useState)(!1),{locale:s}=w(),{isPending:c,isFetching:l,refetch:u}=E(async()=>{await n(),await new Promise(e=>setTimeout(e,500))},[]),d=async()=>{try{o(!0),await e(),S({title:`Cache purged`,description:`All cached data has been cleared`}),u()}catch(e){S({title:`Error`,description:e instanceof Error?e.message:`Failed to purge cache`,variant:`danger`})}finally{o(!1)}};if(c&&!r)return(0,M.jsx)(D,{size:`medium`,centered:!0});let f=(0,M.jsxs)(g,{variant:`outline`,size:`sm`,onClick:u,disabled:l,children:[l?(0,M.jsx)(D,{size:`small`,className:`w-4 h-4 mr-2`}):(0,M.jsx)(O,{className:`w-4 h-4 mr-2`}),`Refresh`]});if(!r)return(0,M.jsx)(k,{title:`No cache data`,description:`Cache information is not available.`,icon:(0,M.jsx)(b,{}),action:f});let p=r.hits,m=r.misses,h=r.time,A=r.disk_total,P=r.disk_to_free,I=p+m,L=I>0?p/I*100:0;return I===0?(0,M.jsx)(k,{title:`No cache activity`,description:`The cache has not been used yet. Cached functions will appear here once they are executed.`,icon:(0,M.jsx)(b,{}),action:f}):(0,M.jsx)(`div`,{className:`flex flex-col h-full overflow-auto`,children:(0,M.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 h-full`,children:[(0,M.jsx)(`div`,{className:`flex items-center justify-end`,children:(0,M.jsx)(g,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:u,disabled:l,children:(0,M.jsx)(O,{className:i(`h-4 w-4 text-muted-foreground hover:text-foreground`,l&&`animate-[spin_0.5s]`)})})}),(0,M.jsxs)(`div`,{className:`space-y-3`,children:[(0,M.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Statistics`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,M.jsx)(F,{label:`Time saved`,value:y(h,s),description:`Total execution time saved`}),(0,M.jsx)(F,{label:`Hit rate`,value:I>0?`${T(L,s)}%`:`—`,description:`${T(p,s)} hits / ${T(I,s)} total`}),(0,M.jsx)(F,{label:`Cache hits`,value:T(p,s),description:`Successful cache retrievals`}),(0,M.jsx)(F,{label:`Cache misses`,value:T(m,s),description:`Cache not found`})]})]}),A>0&&(0,M.jsxs)(`div`,{className:`space-y-3 pt-2 border-t`,children:[(0,M.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Storage`}),(0,M.jsx)(`div`,{className:`grid grid-cols-1 gap-3`,children:(0,M.jsx)(F,{label:`Disk usage`,value:v(A,s),description:P>0?`${v(P,s)} can be freed`:`Cache storage on disk`})})]}),(0,M.jsx)(`div`,{className:`my-auto`}),(0,M.jsx)(`div`,{className:`pt-2 border-t`,children:(0,M.jsx)(N,{title:`Purge cache?`,description:`This will permanently delete all cached data. This action cannot be undone.`,confirmText:`Purge`,destructive:!0,onConfirm:d,children:(0,M.jsxs)(g,{variant:`outlineDestructive`,size:`xs`,disabled:a,className:`w-full`,children:[a?(0,M.jsx)(D,{size:`small`,className:`w-3 h-3 mr-2`}):(0,M.jsx)(x,{className:`w-3 h-3 mr-2`}),`Purge Cache`]})})})]})})},F=e=>{let t=(0,A.c)(10),{label:n,value:r,description:i}=e,a;t[0]===n?a=t[1]:(a=(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,M.jsx)(`span`,{className:`text-lg font-semibold`,children:r}),t[2]=r,t[3]=o);let s;t[4]===i?s=t[5]:(s=i&&(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i}),t[4]=i,t[5]=s);let c;return t[6]!==a||t[7]!==o||t[8]!==s?(c=(0,M.jsxs)(`div`,{className:`flex flex-col gap-1 p-3 rounded-lg border bg-card`,children:[a,o,s]}),t[6]=a,t[7]=o,t[8]=s,t[9]=c):c=t[9],c};export{P as default};
@@ -118,7 +118,7 @@ mark line col
118
118
  `||n===`\r`||n===` `||n===`\b`||n===`\v`){if(r>t){let n=e.slice(t,r),i=this.filterControlChars(n);i.length>0&&this.buffer.writeString(i)}this.buffer.control(n),t=r+1}else if(n<` `){if(r>t){let n=e.slice(t,r);n.length>0&&this.buffer.writeString(n)}t=r+1}}if(t<n){let n=e.slice(t),r=this.filterControlChars(n);r.length>0&&this.buffer.writeString(r)}}filterControlChars(e){let t=!1;for(let n of e)if(n<` `){t=!0;break}if(!t)return e;let n=``;for(let t of e)t>=` `&&(n+=t);return n}},pj=class e{mimetype;channel;timestamp;ansiReducer=new fj;_data;get data(){return this._data}static create(t){let n=new fj;return n.append(t.data),new e(t.mimetype,t.channel,t.timestamp,n)}constructor(e,t,n,r){this.mimetype=e,this.channel=t,this.timestamp=n,this.ansiReducer=r,this._data=this.ansiReducer.render()}appendData(t){return this.ansiReducer.append(t),new e(this.mimetype,this.channel,this.timestamp,this.ansiReducer)}toJSON(){return{mimetype:this.mimetype,channel:this.channel,timestamp:this.timestamp,data:this.data}}};function mj(e,t=5e3){let n=[...e];if(n.length<2)return yj(n.map(gj),t);let r=n[n.length-1],i=n[n.length-2];return hj(r,i)&&(vj(r),vj(i),n[n.length-2]=_j(i,r),n.pop()),yj(n,t)}function hj(e,t){let n=e.mimetype===`text/plain`&&t.mimetype===`text/plain`;if(!n)return!1;let r=e.channel===t.channel,i=e.channel!==`stdin`;return n&&r&&i}function gj(e){return e instanceof pj?e:typeof e.data==`string`?pj.create(e):e}function _j(e,t){return e instanceof pj?e.appendData(t.data):pj.create(e).appendData(t.data)}function vj(e){de(typeof e.data==`string`,`expected string output`)}function yj(e,t){let n=0,r;for(r=e.length-1;r>=0&&n<t;r--){let t=e[r];t.mimetype===`text/plain`?(de(typeof t.data==`string`,`expected string`),n+=t.data.split(`
119
119
  `).length):n++}if(n<t)return e;let i=r+1,a={channel:`stderr`,mimetype:`text/html`,data:`<pre>Streaming output truncated to last ${t} lines.\n</pre>`,timestamp:-1},o=e[i];if(o==null)return[a,...e.slice(i+1)];if(o.mimetype===`text/plain`){de(typeof o.data==`string`,`expected string`);let r=o.data.split(`
120
120
  `),s=t-(n-r.length);return[a,{...o,data:r.slice(-s).join(`
121
- `)},...e.slice(i+1)]}return[a,...e.slice(i+1)]}function bj(e,t){let n={...e};switch(t.status){case`queued`:n.interrupted=!1,n.errored=!1,n.runElapsedTimeMs=null,n.debuggerActive=!1;break;case`running`:n.interrupted=!1,e.stopped&&(n.output=null),n.status===`queued`&&(n.consoleOutputs=[]),n.stopped=!1,n.runStartTimestamp=t.timestamp,n.lastRunStartTimestamp=t.timestamp;break;case`idle`:e.runStartTimestamp&&(n.runElapsedTimeMs=Tv.fromSeconds((t.timestamp??0)-e.runStartTimestamp).toMilliseconds(),n.runStartTimestamp=null,n.staleInputs=!1),!e.lastRunStartTimestamp&&t.timestamp&&(n.lastRunStartTimestamp=t.timestamp),n.debuggerActive=!1;break;case null:break;case`disabled-transitively`:break;case void 0:break;default:Pr(t.status)}n.output=t.output??n.output,n.staleInputs=t.stale_inputs??n.staleInputs,n.status=t.status??n.status,t.serialization!==void 0&&(n.serialization=t.serialization);let r=!1;t.output!=null&&t.output.mimetype===`application/vnd.marimo+error`&&((n.status===`queued`||n.status===`running`)&&(n.status=`idle`),de(Array.isArray(t.output.data),`Expected error output data to be an array`),t.output.data.some(e=>e.type===`interruption`)?(n.interrupted=!0,r=!0):t.output.data.some(e=>e.type.includes(`ancestor`))?n.stopped=!0:n.errored=!0);let i=e.consoleOutputs;(r||t.status===`idle`)&&(n.debuggerActive=!1,i=i.map(e=>e.channel===`stdin`?{channel:e.channel,mimetype:e.mimetype,data:e.data,timestamp:e.timestamp,response:e.response??``}:e));let a=t.console;a!=null&&(i=mj(Array.isArray(a)?a:[...i,a])),n.consoleOutputs=i,n.outline=ij(n.output);let o=[t.console].flat().filter(Boolean).filter(e=>e.channel===`pdb`);return o.length>0&&o.some(e=>e.data===`start`)&&(n.debuggerActive=!0),n}function xj(e){let t={...e};return e.status!==`disabled-transitively`&&(t.status=`queued`),t.interrupted=!1,t.errored=!1,t.runElapsedTimeMs=null,t.debuggerActive=!1,t}function Sj(e){return e===`running`||e===`queued`}function Cj(e,t){let{status:n,output:r,runStartTimestamp:i,interrupted:a,staleInputs:o}=e;if(a)return!1;if(t)return!0;let s=Sj(n),c=n===`running`&&r!==null&&i!==null&&(r.timestamp??0)>i;return s&&!c?!0:o}function wj(e,t){if(!e){B.warn(`getCell: cellId is undefined`);return}let n=t.cellData[e];if(!n){B.warn(`getCell: cell ${e} not found in state`);return}return n}function Tj(e,t){let n=t.cellIds.inOrderIds,r=n.indexOf(e);if(r>0)return{after:n[r-1]};if(r===0&&n.length>1)return{before:n[1]}}function Ej(e){let t=new Map,n=e.cellIds.getColumns();for(let[e,r]of n.entries())for(let n of r.inOrderIds)t.set(n,e);return t}function Dj(e,t){let n=new Set(e.cellIds.inOrderIds),r=[];for(let e of t.cellIds.inOrderIds)if(!n.has(e)){let n=wj(e,t);n&&r.push({type:`create-cell`,cellId:n.id,code:n.code,name:n.name,config:n.config,...Tj(n.id,t)})}return r}function Oj(e,t){let n=new Set(t.cellIds.inOrderIds),r=[];for(let t of e.cellIds.inOrderIds)n.has(t)||r.push({type:`delete-cell`,cellId:t});return r}function kj(e,t){let n=Ej(e),r=Ej(t),i=[];for(let[e,a]of r)if(n.get(e)!==a){let n=wj(e,t);i.push({type:`set-config`,cellId:e,column:a,disabled:n?.config.disabled??!1,hideCode:n?.config.hide_code??!1})}return i.push({type:`reorder-cells`,cellIds:t.cellIds.inOrderIds}),i}function Aj(e,t,n){switch(n.type){case`createNewCell`:return Dj(e,t);case`deleteCell`:return[{type:`delete-cell`,cellId:n.payload.cellId}];case`moveCell`:case`sendToTop`:case`sendToBottom`:{let{cellId:e}=n.payload;return[{type:`move-cell`,cellId:e,...Tj(e,t)}]}case`dropCellOverCell`:case`dropCellOverColumn`:case`moveCellToIndex`:case`moveCellsRelativeTo`:return kj(e,t);case`updateCellCode`:{let e=wj(n.payload.cellId,t);return e?[{type:`set-code`,cellId:e.id,code:e.code}]:[]}case`updateCellName`:{let e=wj(n.payload.cellId,t);return e?[{type:`set-name`,cellId:e.id,name:e.name}]:[]}case`updateCellConfig`:{let{cellId:e}=n.payload,r=wj(e,t);return r?[{type:`set-config`,cellId:e,column:r.config.column??null,disabled:r.config.disabled??!1,hideCode:r.config.hide_code??!1}]:[]}case`dropOverNewColumn`:case`moveColumn`:case`addColumnBreakpoint`:case`deleteColumn`:case`mergeAllColumns`:case`compactColumns`:return kj(e,t);case`addColumn`:return[...Dj(e,t),...kj(e,t)];case`undoDeleteCell`:{let n=Dj(e,t),r=kj(e,t);return n.length===0?r:r.length>1?[...n,...r]:n}case`splitCell`:{let{cellId:r}=n.payload,i=wj(r,t);return i?[{type:`set-code`,cellId:r,code:i.code},...Dj(e,t)]:[]}case`undoSplitCell`:{let{cellId:r}=n.payload,i=wj(r,t);return i?[{type:`set-code`,cellId:r,code:i.code},...Oj(e,t)]:[]}case`moveToNextCell`:return Dj(e,t);case`addSetupCellIfDoesntExist`:return Dj(e,t);case`focusCell`:case`focusTopCell`:case`focusBottomCell`:case`scrollToTarget`:case`showCellIfHidden`:case`markTouched`:case`markUntouched`:return[];case`prepareForRun`:case`handleCellMessage`:case`setCellIds`:case`rebuildCellColumns`:case`setCellCodes`:case`setCells`:case`setStdinResponse`:case`clearSerializedEditorState`:case`clearCellOutput`:case`clearCellConsoleOutput`:case`clearAllCellOutputs`:case`clearLogs`:case`addLogs`:return[];case`foldAll`:case`unfoldAll`:case`collapseCell`:case`expandCell`:case`collapseAllCells`:case`expandAllCells`:return[];default:Fr(n)}}function jj(e){let t=new Set,n=new Set;for(let r of e)r.type===`create-cell`?t.add(r.cellId):r.type===`delete-cell`&&n.add(r.cellId);return t.intersection(n)}function Mj(e,t){let n=[];for(let r of e)switch(r.type){case`create-cell`:{let e=`__end__`,t=!1;r.after?(e=r.after,t=!1):r.before&&(e=r.before,t=!0),n.push({type:`createNewCell`,payload:{cellId:e,before:t,code:r.code,newCellId:r.cellId,autoFocus:!1,hideCode:r.config?.hide_code??!1}}),r.name&&n.push({type:`updateCellName`,payload:{cellId:r.cellId,name:r.name}}),(r.config?.disabled!=null||r.config?.column!=null)&&n.push({type:`updateCellConfig`,payload:{cellId:r.cellId,config:{...r.config.disabled!=null&&{disabled:r.config.disabled},...r.config.column!=null&&{column:r.config.column}}}});break}case`delete-cell`:n.push({type:`deleteCell`,payload:{cellId:r.cellId}});break;case`move-cell`:{let e=[...t()],i=r.cellId,a=e.indexOf(i);if(a<0)break;if(e.splice(a,1),r.after){let t=e.indexOf(r.after);t>=0?e.splice(t+1,0,i):e.push(i)}else if(r.before){let t=e.indexOf(r.before);t>=0?e.splice(t,0,i):e.unshift(i)}else e.push(i);n.push({type:`setCellIds`,payload:{cellIds:e}});break}case`reorder-cells`:n.push({type:`setCellIds`,payload:{cellIds:r.cellIds}});break;case`set-code`:n.push({type:`setCellCodes`,payload:{ids:[r.cellId],codes:[r.code],codeIsStale:!0}});break;case`set-name`:n.push({type:`updateCellName`,payload:{cellId:r.cellId,name:r.name}});break;case`set-config`:n.push({type:`updateCellConfig`,payload:{cellId:r.cellId,config:{column:r.column,disabled:r.disabled,hide_code:r.hideCode}}})}return n}var Nj=new Set([`set-code`,`set-name`,`set-config`]),Pj=new Set([`set-code`,`set-name`,`set-config`,`move-cell`]);function Fj(e){let t=new Set;for(let n of e)n.type===`delete-cell`&&t.add(n.cellId);let n=e.filter(e=>!(Pj.has(e.type)&&`cellId`in e&&t.has(e.cellId))),r=new Map;return n.forEach((e,t)=>{Nj.has(e.type)&&`cellId`in e&&r.set(`${e.type}:${e.cellId}`,t)}),n.filter((e,t)=>Nj.has(e.type)&&`cellId`in e?r.get(`${e.type}:${e.cellId}`)===t:!0)}var Ij=[],Lj=[],Rj=Promise.resolve(),zj=0,Bj=null,Vj={status:`synchronized`};function Hj(){if(Vj.status===`failed`)return;let e=Fj(Ij);Ij=[],e.length>0&&Lj.push(e)}async function Uj(e){if(e===zj){if(Vj.status===`failed`)throw Vj.error;for(;Lj.length>0;){let t=Lj[0];try{await Lr().sendDocumentTransaction({changes:t})}catch(t){if(e!==zj)return;throw Vj={status:`failed`,error:t},Lj=Lj.slice(1),t}if(e!==zj)return;Lj.shift()}}}function Wj(){let e=zj,t=Bj?.promise??Promise.resolve(),n=Promise.all([Rj.catch(()=>void 0),t]).then(()=>Uj(e));return Rj=n,n}var Gj=te(()=>{Hj(),Wj().catch(()=>void 0)},400);async function Kj(){if(Vj.status===`failed`)throw Vj.error;Gj.cancel(),Hj();let e=Wj();for(;;){if(await e,Gj.cancel(),Hj(),Ij.length===0&&Lj.length===0&&Rj===e)return;e=Rj===e?Wj():Rj}}function qj(){if(Vj.status!==`failed`)return null;Gj.cancel();let e=Ij,t=Lj;return Ij=[],Lj=[],{failure:Vj,includedChanges:e,includedTransactions:t}}function Jj(e){e!==null&&Vj===e.failure&&(Ij=[...e.includedChanges,...Ij],Lj=[...e.includedTransactions,...Lj])}async function Yj(e){e!==null&&(await Rj.catch(()=>void 0),Vj===e.failure&&(Vj={status:`synchronized`},Rj=Promise.resolve(),Ij.length>0&&Gj()))}function Xj(e){Bj===e&&(Bj=null),e.resolve()}async function Zj(e){let t=null;try{await Kj()}catch(e){if(t=qj(),t===null)throw e}let n=new ai;Bj=n;try{let r=await e();return Xj(n),await Yj(t),r}catch(e){throw Jj(t),Xj(n),e}}function Qj(e){return`cellId`in e&&e.cellId===`__scratch__`}function $j(e){u.get(fe)||Qj(e)||(Ij.push(e),Vj.status===`synchronized`&&Gj())}function eM(e,t,n){for(let r of Aj(e,t,n))$j(r)}function tM(e,t,n){let r=jj(e),i=[...e.filter(e=>e.type!==`set-config`),...e.filter(e=>e.type===`set-config`)],a=!1,o=null;for(let e of i)if(!(r.size>0&&`cellId`in e&&r.has(e.cellId))){e.type===`set-config`&&(a=!0),e.type===`create-cell`&&e.config?.column!=null&&(a=!0),e.type===`reorder-cells`&&(o=e.cellIds);for(let r of Mj([e],n))t[r.type](r.payload)}a&&t.rebuildCellColumns({cellIds:o??n()})}function nM(e,t){return Mt(e*1e3,t?.in)}var rM=function(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e},iM;(function(e){e[e.EOS=0]=`EOS`,e[e.Text=1]=`Text`,e[e.Incomplete=2]=`Incomplete`,e[e.ESC=3]=`ESC`,e[e.Unknown=4]=`Unknown`,e[e.SGR=5]=`SGR`,e[e.OSCURL=6]=`OSCURL`})(iM||={});var aM=class{constructor(){this.VERSION=`6.0.6`,this.setup_palettes(),this._use_classes=!1,this.bold=!1,this.faint=!1,this.italic=!1,this.underline=!1,this.fg=this.bg=null,this._buffer=``,this._url_allowlist={http:1,https:1},this._escape_html=!0,this.boldStyle=`font-weight:bold`,this.faintStyle=`opacity:0.7`,this.italicStyle=`font-style:italic`,this.underlineStyle=`text-decoration:underline`}set use_classes(e){this._use_classes=e}get use_classes(){return this._use_classes}set url_allowlist(e){this._url_allowlist=e}get url_allowlist(){return this._url_allowlist}set escape_html(e){this._escape_html=e}get escape_html(){return this._escape_html}set boldStyle(e){this._boldStyle=e}get boldStyle(){return this._boldStyle}set faintStyle(e){this._faintStyle=e}get faintStyle(){return this._faintStyle}set italicStyle(e){this._italicStyle=e}get italicStyle(){return this._italicStyle}set underlineStyle(e){this._underlineStyle=e}get underlineStyle(){return this._underlineStyle}setup_palettes(){this.ansi_colors=[[{rgb:[0,0,0],class_name:`ansi-black`},{rgb:[187,0,0],class_name:`ansi-red`},{rgb:[0,187,0],class_name:`ansi-green`},{rgb:[187,187,0],class_name:`ansi-yellow`},{rgb:[0,0,187],class_name:`ansi-blue`},{rgb:[187,0,187],class_name:`ansi-magenta`},{rgb:[0,187,187],class_name:`ansi-cyan`},{rgb:[255,255,255],class_name:`ansi-white`}],[{rgb:[85,85,85],class_name:`ansi-bright-black`},{rgb:[255,85,85],class_name:`ansi-bright-red`},{rgb:[0,255,0],class_name:`ansi-bright-green`},{rgb:[255,255,85],class_name:`ansi-bright-yellow`},{rgb:[85,85,255],class_name:`ansi-bright-blue`},{rgb:[255,85,255],class_name:`ansi-bright-magenta`},{rgb:[85,255,255],class_name:`ansi-bright-cyan`},{rgb:[255,255,255],class_name:`ansi-bright-white`}]],this.palette_256=[],this.ansi_colors.forEach(e=>{e.forEach(e=>{this.palette_256.push(e)})});let e=[0,95,135,175,215,255];for(let t=0;t<6;++t)for(let n=0;n<6;++n)for(let r=0;r<6;++r){let i={rgb:[e[t],e[n],e[r]],class_name:`truecolor`};this.palette_256.push(i)}let t=8;for(let e=0;e<24;++e,t+=10){let e={rgb:[t,t,t],class_name:`truecolor`};this.palette_256.push(e)}}escape_txt_for_html(e){return this._escape_html?e.replace(/[&<>"']/gm,e=>{if(e===`&`)return`&amp;`;if(e===`<`)return`&lt;`;if(e===`>`)return`&gt;`;if(e===`"`)return`&quot;`;if(e===`'`)return`&#x27;`}):e}append_buffer(e){var t=this._buffer+e;this._buffer=t}get_next_packet(){var e={kind:iM.EOS,text:``,url:``},t=this._buffer.length;if(t==0)return e;var n=this._buffer.indexOf(`\x1B`);if(n==-1)return e.kind=iM.Text,e.text=this._buffer,this._buffer=``,e;if(n>0)return e.kind=iM.Text,e.text=this._buffer.slice(0,n),this._buffer=this._buffer.slice(n),e;if(n==0){if(t<3)return e.kind=iM.Incomplete,e;var r=this._buffer.charAt(1);if(r!=`[`&&r!=`]`&&r!=`(`)return e.kind=iM.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;if(r==`[`){this._csi_regex||=oM(cM||=rM([`
121
+ `)},...e.slice(i+1)]}return[a,...e.slice(i+1)]}function bj(e,t){let n={...e};switch(t.status){case`queued`:n.interrupted=!1,n.errored=!1,n.runElapsedTimeMs=null,n.debuggerActive=!1;break;case`running`:n.interrupted=!1,e.stopped&&(n.output=null),n.status===`queued`&&(n.consoleOutputs=[]),n.stopped=!1,n.runStartTimestamp=t.timestamp,n.lastRunStartTimestamp=t.timestamp;break;case`idle`:e.runStartTimestamp&&(n.runElapsedTimeMs=Tv.fromSeconds((t.timestamp??0)-e.runStartTimestamp).toMilliseconds(),n.runStartTimestamp=null,n.staleInputs=!1),!e.lastRunStartTimestamp&&t.timestamp&&(n.lastRunStartTimestamp=t.timestamp),n.debuggerActive=!1;break;case null:break;case`disabled-transitively`:break;case void 0:break;default:Pr(t.status)}n.output=t.output??n.output,n.staleInputs=t.stale_inputs??n.staleInputs,n.status=t.status??n.status,t.serialization!==void 0&&(n.serialization=t.serialization);let r=!1;t.output!=null&&t.output.mimetype===`application/vnd.marimo+error`&&((n.status===`queued`||n.status===`running`)&&(n.status=`idle`),de(Array.isArray(t.output.data),`Expected error output data to be an array`),t.output.data.some(e=>e.type===`interruption`)?(n.interrupted=!0,r=!0):t.output.data.some(e=>e.type.includes(`ancestor`))?n.stopped=!0:n.errored=!0);let i=e.consoleOutputs;(r||t.status===`idle`)&&(n.debuggerActive=!1,i=i.map(e=>e.channel===`stdin`?{channel:e.channel,mimetype:e.mimetype,data:e.data,timestamp:e.timestamp,response:e.response??``}:e));let a=t.console;a!=null&&(i=mj(Array.isArray(a)?a:[...i,a])),n.consoleOutputs=i,n.outline=ij(n.output);let o=[t.console].flat().filter(Boolean).filter(e=>e.channel===`pdb`);return o.length>0&&o.some(e=>e.data===`start`)&&(n.debuggerActive=!0),n}function xj(e){let t={...e};return e.status!==`disabled-transitively`&&(t.status=`queued`),t.interrupted=!1,t.errored=!1,t.runElapsedTimeMs=null,t.debuggerActive=!1,t}function Sj(e){return e===`running`||e===`queued`}function Cj(e,t){let{status:n,output:r,runStartTimestamp:i,interrupted:a,staleInputs:o}=e;if(a)return!1;if(t)return!0;let s=Sj(n),c=n===`running`&&r!==null&&i!==null&&(r.timestamp??0)>i;return s&&!c?!0:o}function wj(e,t){if(!e){B.warn(`getCell: cellId is undefined`);return}let n=t.cellData[e];if(!n){B.warn(`getCell: cell ${e} not found in state`);return}return n}function Tj(e,t){let n=t.cellIds.inOrderIds,r=n.indexOf(e);if(r>0)return{after:n[r-1]};if(r===0&&n.length>1)return{before:n[1]}}function Ej(e){let t=new Map,n=e.cellIds.getColumns();for(let[e,r]of n.entries())for(let n of r.inOrderIds)t.set(n,e);return t}function Dj(e,t){let n=new Set(e.cellIds.inOrderIds),r=[];for(let e of t.cellIds.inOrderIds)if(!n.has(e)){let n=wj(e,t);n&&r.push({type:`create-cell`,cellId:n.id,code:n.code,name:n.name,config:n.config,...Tj(n.id,t)})}return r}function Oj(e,t){let n=new Set(t.cellIds.inOrderIds),r=[];for(let t of e.cellIds.inOrderIds)n.has(t)||r.push({type:`delete-cell`,cellId:t});return r}function kj(e,t){let n=Ej(e),r=Ej(t),i=[];for(let[e,a]of r)if(n.get(e)!==a){let n=wj(e,t);i.push({type:`set-config`,cellId:e,column:a,disabled:n?.config.disabled??!1,hideCode:n?.config.hide_code??!1,expandOutput:n?.config.expand_output??!1})}return i.push({type:`reorder-cells`,cellIds:t.cellIds.inOrderIds}),i}function Aj(e,t,n){switch(n.type){case`createNewCell`:return Dj(e,t);case`deleteCell`:return[{type:`delete-cell`,cellId:n.payload.cellId}];case`moveCell`:case`sendToTop`:case`sendToBottom`:{let{cellId:e}=n.payload;return[{type:`move-cell`,cellId:e,...Tj(e,t)}]}case`dropCellOverCell`:case`dropCellOverColumn`:case`moveCellToIndex`:case`moveCellsRelativeTo`:return kj(e,t);case`updateCellCode`:{let e=wj(n.payload.cellId,t);return e?[{type:`set-code`,cellId:e.id,code:e.code}]:[]}case`updateCellName`:{let e=wj(n.payload.cellId,t);return e?[{type:`set-name`,cellId:e.id,name:e.name}]:[]}case`updateCellConfig`:{let{cellId:e}=n.payload,r=wj(e,t);return r?[{type:`set-config`,cellId:e,column:r.config.column??null,disabled:r.config.disabled??!1,hideCode:r.config.hide_code??!1,expandOutput:r.config.expand_output??!1}]:[]}case`dropOverNewColumn`:case`moveColumn`:case`addColumnBreakpoint`:case`deleteColumn`:case`mergeAllColumns`:case`compactColumns`:return kj(e,t);case`addColumn`:return[...Dj(e,t),...kj(e,t)];case`undoDeleteCell`:{let n=Dj(e,t),r=kj(e,t);return n.length===0?r:r.length>1?[...n,...r]:n}case`splitCell`:{let{cellId:r}=n.payload,i=wj(r,t);return i?[{type:`set-code`,cellId:r,code:i.code},...Dj(e,t)]:[]}case`undoSplitCell`:{let{cellId:r}=n.payload,i=wj(r,t);return i?[{type:`set-code`,cellId:r,code:i.code},...Oj(e,t)]:[]}case`moveToNextCell`:return Dj(e,t);case`addSetupCellIfDoesntExist`:return Dj(e,t);case`focusCell`:case`focusTopCell`:case`focusBottomCell`:case`scrollToTarget`:case`showCellIfHidden`:case`markTouched`:case`markUntouched`:return[];case`prepareForRun`:case`handleCellMessage`:case`setCellIds`:case`rebuildCellColumns`:case`setCellCodes`:case`setCells`:case`setStdinResponse`:case`clearSerializedEditorState`:case`clearCellOutput`:case`clearCellConsoleOutput`:case`clearAllCellOutputs`:case`clearLogs`:case`addLogs`:return[];case`foldAll`:case`unfoldAll`:case`collapseCell`:case`expandCell`:case`collapseAllCells`:case`expandAllCells`:return[];default:Fr(n)}}function jj(e){let t=new Set,n=new Set;for(let r of e)r.type===`create-cell`?t.add(r.cellId):r.type===`delete-cell`&&n.add(r.cellId);return t.intersection(n)}function Mj(e,t){let n=[];for(let r of e)switch(r.type){case`create-cell`:{let e=`__end__`,t=!1;r.after?(e=r.after,t=!1):r.before&&(e=r.before,t=!0),n.push({type:`createNewCell`,payload:{cellId:e,before:t,code:r.code,newCellId:r.cellId,autoFocus:!1,hideCode:r.config?.hide_code??!1}}),r.name&&n.push({type:`updateCellName`,payload:{cellId:r.cellId,name:r.name}}),(r.config?.disabled!=null||r.config?.column!=null||r.config?.expand_output!=null)&&n.push({type:`updateCellConfig`,payload:{cellId:r.cellId,config:{...r.config.disabled!=null&&{disabled:r.config.disabled},...r.config.column!=null&&{column:r.config.column},...r.config.expand_output!=null&&{expand_output:r.config.expand_output}}}});break}case`delete-cell`:n.push({type:`deleteCell`,payload:{cellId:r.cellId}});break;case`move-cell`:{let e=[...t()],i=r.cellId,a=e.indexOf(i);if(a<0)break;if(e.splice(a,1),r.after){let t=e.indexOf(r.after);t>=0?e.splice(t+1,0,i):e.push(i)}else if(r.before){let t=e.indexOf(r.before);t>=0?e.splice(t,0,i):e.unshift(i)}else e.push(i);n.push({type:`setCellIds`,payload:{cellIds:e}});break}case`reorder-cells`:n.push({type:`setCellIds`,payload:{cellIds:r.cellIds}});break;case`set-code`:n.push({type:`setCellCodes`,payload:{ids:[r.cellId],codes:[r.code],codeIsStale:!0}});break;case`set-name`:n.push({type:`updateCellName`,payload:{cellId:r.cellId,name:r.name}});break;case`set-config`:n.push({type:`updateCellConfig`,payload:{cellId:r.cellId,config:{column:r.column,disabled:r.disabled,hide_code:r.hideCode,expand_output:r.expandOutput}}})}return n}var Nj=new Set([`set-code`,`set-name`,`set-config`]),Pj=new Set([`set-code`,`set-name`,`set-config`,`move-cell`]);function Fj(e){let t=new Set;for(let n of e)n.type===`delete-cell`&&t.add(n.cellId);let n=e.filter(e=>!(Pj.has(e.type)&&`cellId`in e&&t.has(e.cellId))),r=new Map;return n.forEach((e,t)=>{Nj.has(e.type)&&`cellId`in e&&r.set(`${e.type}:${e.cellId}`,t)}),n.filter((e,t)=>Nj.has(e.type)&&`cellId`in e?r.get(`${e.type}:${e.cellId}`)===t:!0)}var Ij=[],Lj=[],Rj=Promise.resolve(),zj=0,Bj=null,Vj={status:`synchronized`};function Hj(){if(Vj.status===`failed`)return;let e=Fj(Ij);Ij=[],e.length>0&&Lj.push(e)}async function Uj(e){if(e===zj){if(Vj.status===`failed`)throw Vj.error;for(;Lj.length>0;){let t=Lj[0];try{await Lr().sendDocumentTransaction({changes:t})}catch(t){if(e!==zj)return;throw Vj={status:`failed`,error:t},Lj=Lj.slice(1),t}if(e!==zj)return;Lj.shift()}}}function Wj(){let e=zj,t=Bj?.promise??Promise.resolve(),n=Promise.all([Rj.catch(()=>void 0),t]).then(()=>Uj(e));return Rj=n,n}var Gj=te(()=>{Hj(),Wj().catch(()=>void 0)},400);async function Kj(){if(Vj.status===`failed`)throw Vj.error;Gj.cancel(),Hj();let e=Wj();for(;;){if(await e,Gj.cancel(),Hj(),Ij.length===0&&Lj.length===0&&Rj===e)return;e=Rj===e?Wj():Rj}}function qj(){if(Vj.status!==`failed`)return null;Gj.cancel();let e=Ij,t=Lj;return Ij=[],Lj=[],{failure:Vj,includedChanges:e,includedTransactions:t}}function Jj(e){e!==null&&Vj===e.failure&&(Ij=[...e.includedChanges,...Ij],Lj=[...e.includedTransactions,...Lj])}async function Yj(e){e!==null&&(await Rj.catch(()=>void 0),Vj===e.failure&&(Vj={status:`synchronized`},Rj=Promise.resolve(),Ij.length>0&&Gj()))}function Xj(e){Bj===e&&(Bj=null),e.resolve()}async function Zj(e){let t=null;try{await Kj()}catch(e){if(t=qj(),t===null)throw e}let n=new ai;Bj=n;try{let r=await e();return Xj(n),await Yj(t),r}catch(e){throw Jj(t),Xj(n),e}}function Qj(e){return`cellId`in e&&e.cellId===`__scratch__`}function $j(e){u.get(fe)||Qj(e)||(Ij.push(e),Vj.status===`synchronized`&&Gj())}function eM(e,t,n){for(let r of Aj(e,t,n))$j(r)}function tM(e,t,n){let r=jj(e),i=[...e.filter(e=>e.type!==`set-config`),...e.filter(e=>e.type===`set-config`)],a=!1,o=null;for(let e of i)if(!(r.size>0&&`cellId`in e&&r.has(e.cellId))){e.type===`set-config`&&(a=!0),e.type===`create-cell`&&e.config?.column!=null&&(a=!0),e.type===`reorder-cells`&&(o=e.cellIds);for(let r of Mj([e],n))t[r.type](r.payload)}a&&t.rebuildCellColumns({cellIds:o??n()})}function nM(e,t){return Mt(e*1e3,t?.in)}var rM=function(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e},iM;(function(e){e[e.EOS=0]=`EOS`,e[e.Text=1]=`Text`,e[e.Incomplete=2]=`Incomplete`,e[e.ESC=3]=`ESC`,e[e.Unknown=4]=`Unknown`,e[e.SGR=5]=`SGR`,e[e.OSCURL=6]=`OSCURL`})(iM||={});var aM=class{constructor(){this.VERSION=`6.0.6`,this.setup_palettes(),this._use_classes=!1,this.bold=!1,this.faint=!1,this.italic=!1,this.underline=!1,this.fg=this.bg=null,this._buffer=``,this._url_allowlist={http:1,https:1},this._escape_html=!0,this.boldStyle=`font-weight:bold`,this.faintStyle=`opacity:0.7`,this.italicStyle=`font-style:italic`,this.underlineStyle=`text-decoration:underline`}set use_classes(e){this._use_classes=e}get use_classes(){return this._use_classes}set url_allowlist(e){this._url_allowlist=e}get url_allowlist(){return this._url_allowlist}set escape_html(e){this._escape_html=e}get escape_html(){return this._escape_html}set boldStyle(e){this._boldStyle=e}get boldStyle(){return this._boldStyle}set faintStyle(e){this._faintStyle=e}get faintStyle(){return this._faintStyle}set italicStyle(e){this._italicStyle=e}get italicStyle(){return this._italicStyle}set underlineStyle(e){this._underlineStyle=e}get underlineStyle(){return this._underlineStyle}setup_palettes(){this.ansi_colors=[[{rgb:[0,0,0],class_name:`ansi-black`},{rgb:[187,0,0],class_name:`ansi-red`},{rgb:[0,187,0],class_name:`ansi-green`},{rgb:[187,187,0],class_name:`ansi-yellow`},{rgb:[0,0,187],class_name:`ansi-blue`},{rgb:[187,0,187],class_name:`ansi-magenta`},{rgb:[0,187,187],class_name:`ansi-cyan`},{rgb:[255,255,255],class_name:`ansi-white`}],[{rgb:[85,85,85],class_name:`ansi-bright-black`},{rgb:[255,85,85],class_name:`ansi-bright-red`},{rgb:[0,255,0],class_name:`ansi-bright-green`},{rgb:[255,255,85],class_name:`ansi-bright-yellow`},{rgb:[85,85,255],class_name:`ansi-bright-blue`},{rgb:[255,85,255],class_name:`ansi-bright-magenta`},{rgb:[85,255,255],class_name:`ansi-bright-cyan`},{rgb:[255,255,255],class_name:`ansi-bright-white`}]],this.palette_256=[],this.ansi_colors.forEach(e=>{e.forEach(e=>{this.palette_256.push(e)})});let e=[0,95,135,175,215,255];for(let t=0;t<6;++t)for(let n=0;n<6;++n)for(let r=0;r<6;++r){let i={rgb:[e[t],e[n],e[r]],class_name:`truecolor`};this.palette_256.push(i)}let t=8;for(let e=0;e<24;++e,t+=10){let e={rgb:[t,t,t],class_name:`truecolor`};this.palette_256.push(e)}}escape_txt_for_html(e){return this._escape_html?e.replace(/[&<>"']/gm,e=>{if(e===`&`)return`&amp;`;if(e===`<`)return`&lt;`;if(e===`>`)return`&gt;`;if(e===`"`)return`&quot;`;if(e===`'`)return`&#x27;`}):e}append_buffer(e){var t=this._buffer+e;this._buffer=t}get_next_packet(){var e={kind:iM.EOS,text:``,url:``},t=this._buffer.length;if(t==0)return e;var n=this._buffer.indexOf(`\x1B`);if(n==-1)return e.kind=iM.Text,e.text=this._buffer,this._buffer=``,e;if(n>0)return e.kind=iM.Text,e.text=this._buffer.slice(0,n),this._buffer=this._buffer.slice(n),e;if(n==0){if(t<3)return e.kind=iM.Incomplete,e;var r=this._buffer.charAt(1);if(r!=`[`&&r!=`]`&&r!=`(`)return e.kind=iM.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;if(r==`[`){this._csi_regex||=oM(cM||=rM([`
122
122
  ^ # beginning of line
123
123
  #
124
124
  # First attempt
@@ -217,4 +217,4 @@ mark line col
217
217
  )
218
218
  `]));let n=this._buffer.match(this._osc_regex);if(n===null)return e.kind=iM.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;e.kind=iM.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=iM.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==iM.EOS||n.kind==iM.Incomplete)break;n.kind!=iM.ESC&&n.kind!=iM.Unknown&&(n.kind==iM.Text?t.push(this.transform_to_html(this.with_state(n))):n.kind==iM.SGR?this.process_ansi(n):n.kind==iM.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 oM(e,...t){let n=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,``);return new RegExp(n)}function sM(e,...t){let n=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,``);return new RegExp(n,`g`)}var cM,lM,uM,dM=new aM;function fM(e){try{let t=document.createElement(`div`);return t.innerHTML=e,(t.textContent||t.innerText||``).split(`
219
219
  `).map(e=>e.trimEnd()).join(`
220
- `)}catch(t){return B.error(`Error parsing HTML content:`,t),e}}function pM(e){if(!e)return``;try{return fM(dM.ansi_to_html(e))}catch(t){return B.error(`Error converting ANSI to plain text:`,t),e}}var mM=o(null);function hM(e){return e.type===`cell`?e.cellId:`lsp:${e.name}`}var gM=!1;function _M(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=Ir.asString(r.data),o=i?fM(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(vM.log),n.length===0&&vf(e.output?.mimetype)&&Array.isArray(e.output.data)){e.output.data.forEach(t=>{vM.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(pe)===`read`;if(t.length>0&&!gM&&n){gM=!0;let e=t.find(e=>e.traceback);nn(e?{title:`An internal error occurred`,description:e.msg||`Click 'View' to see traceback`,variant:`danger`,action:G.createElement(pt,{altText:`View traceback`,onClick:()=>{u.set(mM,{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 vM={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`,`[${yM(e.timestamp)}]`,`(${hM(e.source)}) ${e.message}`)}};function yM(e){try{return nM(e).toLocaleTimeString(void 0,{hour12:!0,hour:`numeric`,minute:`numeric`,second:`numeric`})}catch{return``}}function bM(e,t){let n=kN(t);n?n.focus():B.warn(`[CellFocusManager] focusCellEditor: element not found: ${t}`)}function xM(e){let t=document.getElementById(ji.create(e));t?wM(t):B.warn(`[CellFocusManager] focusCell: element not found: ${e}`)}function SM(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}function CM(){return document.activeElement instanceof HTMLElement&&document.activeElement.classList.contains(`marimo-cell`)}function wM(e){try{e.focus()}catch{B.warn(`[CellFocusManager] element may not be focusable`,e)}}function TM(e,t){let{retries:n,delay:r,initialDelay:i=0}=t,a=0,o=()=>{if(a<n){try{if(e())return}catch(e){B.error(`Error executing function on attempt ${a+1}, retrying`,{error:e})}a++,setTimeout(o,r)}};i>0?setTimeout(o,i):o()}function EM({cellId:e,cell:t,isCodeHidden:n,codeFocus:r,variableName:i}){if(!t)return;let a=document.getElementById(ji.create(e));if(!a){B.warn(`scrollCellIntoView: element not found`);return}if(CM()){wM(a);return}if(n)wM(a);else{Zs.promote(e);let n=t.current?.editorView;if(!n){B.warn(`scrollCellIntoView: editor not found`,e);return}if(n.hasFocus||!document.hasFocus())return;if(TM(()=>(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&&K_(n,i)}a.scrollIntoView({behavior:`smooth`,block:`nearest`})}function DM(e){let t=document.getElementById(ji.create(e));if(!t){B.warn(`scrollCellIntoView: element not found`);return}t.classList.add(`focus-outline`),setTimeout(()=>{t.classList.remove(`focus-outline`)},2e3),t.scrollIntoView({behavior:`smooth`,block:`center`})}function OM(){let e=document.getElementById(`App`);e?.scrollTo({top:e.scrollHeight,behavior:`smooth`})}function kM(){document.getElementById(`App`)?.scrollTo({top:0,behavior:`smooth`})}function AM(e){let t=kN(e);if(t?.hasFocus){Mh(t,{behavior:`instant`});return}let n=document.getElementById(ji.create(e));n?n.scrollIntoView({behavior:`instant`,block:`nearest`}):B.warn(`[CellFocusManager] scrollCellIntoView: element not found: ${e}`)}function jM({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 MM(e){return{hide_code:!1,disabled:!1,column:null,...e}}function NM(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 PM(e){let t={column:0,hide_code:!1,disabled:!1};return{...e,cellData:{[ki]:jM({id:ki,config:t}),...e.cellData},cellRuntime:{[ki]:NM(),...e.cellRuntime},cellHandles:{[ki]:(0,G.createRef)(),...e.cellHandles}}}function FM(){return PM({cellIds:Es.from([]),cellData:{},cellRuntime:{},cellHandles:{},history:[],scrollKey:null,cellLogs:[],untouchedNewCells:new Set})}var{reducer:IM,addMiddleware:LM,createActions:RM,useActions:zM,valueAtom:BM}=Er(FM,{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||Ai.create(),h=r?p:p+1;return{...e,cellIds:e.cellIds.insertId(m,f,h),cellData:{...e.cellData,[m]:jM({id:m,code:i,name:a,lastCodeRun:s,config:MM({...o,...d!=null&&{hide_code:d}}),lastExecutionTime:c,edited:!!i&&i!==s})},cellRuntime:{...e.cellRuntime,[m]:NM()},cellHandles:{...e.cellHandles,[m]:(0,G.createRef)()},scrollKey:l?m:null,untouchedNewCells:d&&l?new Set([...e.untouchedNewCells,m]):e.untouchedNewCells}},moveCell:(e,t)=>{let{cellId:n,before:r,direction:i}=t;if(r!==void 0&&i!==void 0&&B.warn(`Both before and direction specified for moveCell. Ignoring one.`),i){let t=e.cellIds.findWithId(n),r=e.cellIds.indexOf(t),a=i===`left`?r-1:r+1,o=e.cellIds.at(a);return o?{...e,cellIds:e.cellIds.moveAcrossColumns(t.id,n,o.id,void 0),scrollKey:n}:e}let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n);return r&&o===0?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,0),scrollKey:n}:!r&&o===a.length-1?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,a.length-1),scrollKey:n}:r?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o-1),scrollKey:n}:{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o+1),scrollKey:n}},moveCellToIndex:(e,t)=>{let{cellId:n,columnId:r,index:i}=t,a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=e.cellIds.get(r);if(!s)return e;let c=Math.max(0,Math.min(i,s.length)),l=a.id===r&&o<c?c-1:c;if(a.id===r&&o===l)return e;let u=e.cellIds.deleteById(n),d=u.get(r);return d?{...e,cellIds:u.insertId(n,r,Math.max(0,Math.min(l,d.length))),scrollKey:null}:e},dropCellOverCell:(e,t)=>{let{cellId:n,overCellId:r}=t,i=e.cellIds.findWithId(n),a=e.cellIds.findWithId(r),o=i.indexOfOrThrow(n),s=a.indexOfOrThrow(r);return i.id===a.id?o===s?e:{...e,cellIds:e.cellIds.moveWithinColumn(i.id,o,s),scrollKey:null}:{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,a.id,r),scrollKey:null}},moveCellsRelativeTo:(e,t)=>{let{cellIds:n,targetCellId:r,position:i,previousPlacements:a}=t;if(n.length===0)return e;let o=e.cellIds.moveCellsRelativeTo(n,r,i),s=a&&a.length===n.length?[...e.history,{type:`move`,cellIds:n,placements:a}]:e.history;return{...e,cellIds:o,history:s,scrollKey:null}},dropCellOverColumn:(e,t)=>{let{cellId:n,columnId:r}=t,i=e.cellIds.findWithId(n);return{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,r,void 0)}},dropOverNewColumn:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.moveToNewColumn(n)}},moveColumn:(e,t)=>t.column===t.overColumn?e:{...e,cellIds:e.cellIds.moveColumn(t.column,t.overColumn)},focusCell:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,where:i}=t,a=n.indexOfOrThrow(r),o;o=i===`before`?xr(a-1,0,n.length-1):i===`after`?xr(a+1,0,n.length-1):a;let s=n.atOrThrow(o);return EM({cellId:s,cell:e.cellHandles[s],isCodeHidden:VM(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 EM({cellId:n,cell:e.cellHandles[n],isCodeHidden:VM(e,n),codeFocus:void 0,variableName:void 0}),kM(),e},focusBottomCell:e=>{let t=e.cellIds.getColumns().at(-1);if(t===void 0||t.length===0)return e;let n=t.last();return EM({cellId:n,cell:e.cellHandles[n],isCodeHidden:VM(e,n),codeFocus:void 0,variableName:void 0}),OM(),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=Ai.create();return{...e,cellIds:e.cellIds.addColumn(t.columnId,[n]),cellData:{...e.cellData,[n]:jM({id:n})},cellRuntime:{...e.cellRuntime,[n]:NM()},cellHandles:{...e.cellHandles,[n]:(0,G.createRef)()},scrollKey:n}},addColumnBreakpoint:(e,t)=>{let{cellId:n}=t;return e.cellIds.getColumns()[0].inOrderIds[0]===n?e:{...e,cellIds:e.cellIds.insertBreakpoint(n)}},deleteColumn:(e,t)=>{let{columnId:n}=t;return{...e,cellIds:e.cellIds.delete(n)}},mergeAllColumns:e=>({...e,cellIds:e.cellIds.mergeAllColumns()}),compactColumns:e=>({...e,cellIds:e.cellIds.compact()}),deleteCell:(e,t)=>{let n=t.cellId;if(e.cellIds.hasOnlyOneId())return e;let r;try{r=e.cellIds.findWithId(n)}catch(t){return B.warn(`Skipping delete for missing cellId`,{cellId:n,error:t}),e}let i=r.indexOfOrThrow(n),a=i===0?1:i-1,o=null;r.length>1&&(o=r.atOrThrow(a));let s=(e.cellHandles[n].current?.editorView)?.state.toJSON({history:$n});s&&(s.doc=e.cellData[n].code),wN(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===W,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?W:Ai.create(),l=jM({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]:NM()},cellHandles:{...e.cellHandles,[c]:(0,G.createRef)()},history:e.history.slice(0,-1),scrollKey:c}},clearSerializedEditorState:(e,t)=>{let{cellId:n}=t;return UM({state:e,cellId:n,cellReducer:e=>({...e,serializedEditorState:null})})},updateCellCode:(e,t)=>{let{cellId:n,code:r,formattingChange:i}=t;return e.cellData[n]?UM({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 UM({state:e,cellId:n,cellReducer:e=>({...e,name:r})})},updateCellConfig:(e,t)=>{let{cellId:n,config:r}=t;return UM({state:e,cellId:n,cellReducer:e=>({...e,config:MM({...e.config,...r})})})},prepareForRun:(e,t)=>UM({state:HM({state:e,cellId:t.cellId,cellReducer:e=>xj(e)}),cellId:t.cellId,cellReducer:e=>({...e,edited:!1,lastCodeRun:e.code.trim()})}),handleCellMessage:(e,t)=>{let n=t.cell_id,r=HM({state:e,cellId:n,cellReducer:e=>bj(e,t)});return t.status===`queued`&&(r=UM({state:r,cellId:n,cellReducer:e=>({...e,lastCodeRun:e.code.trim(),edited:!1})})),{...r,cellLogs:[...r.cellLogs,..._M(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]=jM({id:a})),a in e.cellRuntime||(r[a]=NM()),a in e.cellHandles||(i[a]=(0,G.createRef)());return{...e,cellIds:Es.fromWithPreviousShape(t.cellIds,e.cellIds),cellData:n,cellRuntime:r,cellHandles:i}},rebuildCellColumns:(e,t)=>{let n=Es.fromIdsAndColumns(t.cellIds.map(t=>[t,e.cellData[t]?.config.column??null]));return{...e,cellIds:n}},setCellCodes:(e,t)=>{de(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 jM({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(!cj()||!lj(i)){let e=n.cellHandles[i].current;e?.editorViewOrNull&&YA(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 HM({state:e,cellId:n,cellReducer:e=>{let t=[...e.consoleOutputs],n=t[i];return n==null||n.channel!==`stdin`?(B.warn(`Expected stdin output`),e):(t[i]={channel:`stdin`,mimetype:n.mimetype,data:n.data,timestamp:n.timestamp,response:r},{...e,interrupted:!1,consoleOutputs:t})}})},setCells:(e,t)=>{let n=Object.fromEntries(t.map(e=>[e.id,e])),r=me(),i=t=>{if(!r)return NM();let n=e.cellRuntime[t];return n&&(n.output!=null||n.consoleOutputs.length>0)?n:NM()},a=Object.fromEntries(t.map(e=>[e.id,i(e.id)]));return PM({...e,cellIds:Es.fromIdsAndColumns(t.map(e=>[e.id,e.config.column])),cellData:n,cellRuntime:a,cellHandles:Object.fromEntries(t.map(e=>[e.id,(0,G.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=Ai.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,s),cellData:{...e.cellData,[t]:jM({id:t})},cellRuntime:{...e.cellRuntime,[t]:NM()},cellHandles:{...e.cellHandles,[t]:(0,G.createRef)()},scrollKey:t}}if(l&&!i){let t=Ai.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,0),cellData:{...e.cellData,[t]:jM({id:t})},cellRuntime:{...e.cellRuntime,[t]:NM()},cellHandles:{...e.cellHandles,[t]:(0,G.createRef)()},scrollKey:t}}if((c||l)&&i)return e;if(s>=0&&s<a.length){let t=a.atOrThrow(s);EM({cellId:t,cell:e.cellHandles[t],isCodeHidden:VM(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 EM({cellId:i,cell:e.cellHandles[i],isCodeHidden:VM(e,i),codeFocus:void 0,variableName:void 0}),{...e,scrollKey:null}},foldAll:e=>(Ks(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),unfoldAll:e=>(qs(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=oj(r.indexOfOrThrow(n),i);if(!a)return e;let o=r.atOrThrow(a[1]);return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.collapse(n,o)),scrollKey:n}},expandCell:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.expand(n)),scrollKey:n}},collapseAllCells:e=>({...e,cellIds:e.cellIds.transformAll(t=>{let n=t.topLevelIds.map(t=>e.cellRuntime[t].outline),r=[...t.nodes],i=new Map,a=[],o=r.length-1;for(;o>=0;){let e=oj(o,n);if(e){let n=o,r=e[1],s=i.get(r)??r;i.set(r,n);let c=t.atOrThrow(n),l=t.atOrThrow(s);a.push({id:c,until:l})}else a.push(null);o--}let s=a.toReversed();return t.collapseAll(s)})}),expandAllCells:e=>({...e,cellIds:e.cellIds.transformAll(e=>e.expandAll())}),showCellIfHidden:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r,a=r.findAndExpandDeep(n);return a.equals(i)?e:{...e,cellIds:e.cellIds.transformWithCellId(n,()=>a)}},splitCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.indexOfOrThrow(n),a=e.cellData[n],o=e.cellHandles[n].current;if(o?.editorView==null)return e;let{beforeCursorCode:s,afterCursorCode:c}=XA(o.editorView);YA(o.editorView,s);let l=Ai.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]:jM({id:l,code:c,edited:!!c})},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]},[l]:NM()},cellHandles:{...e.cellHandles,[l]:(0,G.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:(YA(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 HM({state:e,cellId:n,cellReducer:e=>({...e,output:null,consoleOutputs:[]})})},clearCellConsoleOutput:(e,t)=>{let{cellId:n}=t;return HM({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:W}:{...e,cellIds:e.cellIds.insertId(W,e.cellIds.atOrThrow(0).id,0),cellData:{...e.cellData,[W]:jM({id:W,name:W,code:n,edited:!!n})},cellRuntime:{...e.cellRuntime,[W]:NM()},cellHandles:{...e.cellHandles,[W]:(0,G.createRef)()},scrollKey:W}}});LM(eM);function VM(e,t){return!!e.cellData[t].config.hide_code&&!e.untouchedNewCells.has(t)}function HM({state:e,cellId:t,cellReducer:n}){return t in e.cellRuntime?{...e,cellRuntime:{...e.cellRuntime,[t]:n(e.cellRuntime[t])}}:(B.warn(`Cell ${t} not found in state`),e)}function UM({state:e,cellId:t,cellReducer:n}){return t in e.cellData?{...e,cellData:{...e.cellData,[t]:n(e.cellData[t])}}:(B.warn(`Cell ${t} not found in state`),e)}function WM(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 GM=RM(e=>{u.set(BM,t=>IM(t,e))}).addLogs,KM=o(e=>e(BM).cellIds),qM=o(e=>e(KM).hasOnlyOneId()),JM=o(e=>wf(e(BM)).length>0);o(e=>Tf(e(BM)).length>0);var YM=o(e=>Ef(e(BM))),XM=o(e=>Df(e(BM))),ZM=o(e=>xf(e(BM))),QM=o(e=>{let{cellIds:t,cellRuntime:n,cellData:r}=e(BM);return t.inOrderIds.map(e=>{let t=n[e],{name:i}=r[e];if(vf(t.output?.mimetype)){de(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)}),$M=o(e=>{let{cellIds:t,cellRuntime:n}=e(BM);return rj(t.inOrderIds.map(e=>n[e].outline))}),eN=o(e=>e(QM).length),tN=c(o(e=>{let{cellIds:t,cellData:n}=e(BM);return ue.fromEntries(t.inOrderIds.map(e=>[e,n[e]?.name]))})),nN=o(e=>e(BM).scrollKey),rN=()=>s(BM),iN=()=>s(KM),aN=()=>s(tN),oN=()=>s(QM),sN=()=>s(BM).cellLogs,cN=()=>s(nN),lN=()=>u.get(BM),uN=()=>u.get(BM).cellIds,dN=()=>{let{cellIds:e,cellData:t}=u.get(BM);return e.inOrderIds.map(e=>t[e]?.name).filter(Boolean)},fN=$o(Ko(BM,e=>e.cellIds.inOrderIds.map(t=>e.cellData[t]))),pN=()=>a(fN),mN=o(e=>e(BM).cellRuntime),hN=o(e=>yf(e(BM))),gN=o(e=>{let{cellRuntime:t}=e(BM);return Object.entries(t).every(([e,t])=>t.status!==`running`||e===`__scratch__`)}),_N=o(e=>bf(e(BM))),vN=o(e=>e(BM).cellIds.colLength),yN=o(e=>e(BM).cellIds.idLength>0),bN=o(e=>e(BM).cellIds.getColumnIds()),xN=Ho(e=>o(t=>t(BM).cellData[e])),SN=Ho(e=>o(t=>t(BM).cellRuntime[e])),CN=Ho(e=>o(t=>t(BM).cellHandles[e]));function wN(e){xN.remove(e),SN.remove(e),CN.remove(e)}var TN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=xN(e),t[0]=e,t[1]=n),s(n)},EN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=SN(e),t[0]=e,t[1]=n),s(n)},DN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=CN(e),t[0]=e,t[1]=n),s(n)},ON=()=>{let{cellIds:e,cellHandles:t}=u.get(BM);return e.inOrderIds.map(e=>t[e]?.current?.editorViewOrNull).filter(Boolean)},kN=e=>{let{cellHandles:t}=u.get(BM);return t[e].current?.editorView},AN=e=>(Zs.promote(e),kN(e));function jN(e){let{cellIds:t,cellData:n,cellRuntime:r}=e;return t.getColumns().flatMap(e=>e.topLevelIds.map(e=>({...n[e],...r[e]})))}function MN(e){return o(t=>t(BM).untouchedNewCells.has(e))}function NN(e){let t=SN(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(...Ws(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 PN(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),zM(n)}export{tM as $,ko as $a,Ff as $i,$y as $n,Rh as $r,FO as $t,oN as A,Es as Aa,kp as Ai,IT as An,Ti as Ao,T_ as Ar,Hk as At,DM as B,ls as Ba,up as Bi,Pw as Bn,lg as Br,gk as Bt,_N as C,yu as Ca,im as Ci,WD as Cn,Pi as Co,M_ as Cr,pA as Ct,PN as D,Us as Da,jp as Di,vE as Dn,Ni as Do,P_ as Dr,eA as Dt,XM as E,Ws as Ea,Fp as Ei,ZE as En,W as Eo,j_ as Er,tA as Et,EN as F,hs as Fa,Dp as Fi,Kw as Fn,xg as Fr,Tk as Ft,CM as G,zo as Ga,ip as Gi,WC as Gn,qh as Gr,ek as Gt,TM as H,Vo as Ha,Qf as Hi,dw as Hn,ag as Hr,ak as Ht,rN as I,ps as Ia,Sp as Ii,Rw as In,hg as Ir,Ck as It,hM as J,Io as Ja,ep as Ji,KC as Jn,Hh as Jr,qO as Jt,SM as K,Ro as Ka,Yf as Ki,UC as Kn,rg as Kr,XO as Kt,cN as L,us as La,pp as Li,Lw as Ln,ug as Lr,Sk as Lt,iN as M,bs as Ma,wp as Mi,Uw as Mn,bi as Mo,Tg as Mr,Gk as Mt,sN as N,gs as Na,Cp as Ni,Gw as Nn,_i as No,vg as Nr,xk as Nt,TN as O,Bs as Oa,Np as Oi,VE as On,Mi as Oo,g_ as Or,$k as Ot,aN as P,ms as Pa,xp as Pi,Ww as Pn,fi as Po,Cg as Pr,Ek as Pt,aM as Q,Ao as Qa,qf as Qi,eb as Qn,Vh as Qr,NO as Qt,jM as R,cs as Ra,dp as Ri,zw as Rn,cg as Rr,wk as Rt,$M as S,Fd as Sa,rm as Si,cO as Sn,Ai as So,D_ as Sr,dA as St,gN as T,Hs as Ta,Pp as Ti,$E as Tn,ki as To,k_ as Tr,nA as Tt,xM as U,rs as Ua,Xf as Ui,JC as Un,eg as Ur,QO as Ut,AM as V,is as Va,mp as Vi,Mw as Vn,sg as Vr,ik as Vt,bM as W,Ko as Wa,Zf as Wi,HC as Wn,ig as Wr,$O as Wt,pM as X,No as Xa,Jf as Xi,Wb as Xn,Wh as Xr,BO as Xt,mM as Y,Fo as Ya,rp as Yi,ax as Yn,Uh as Yr,MO as Yt,fM as Z,jo as Za,Kf as Zi,nb as Zn,Bh as Zr,VO as Zt,JM as _,cf as _a,_m as _i,gO as _n,zi as _o,Q_ as _r,zA as _t,mN as a,Of as aa,Ch as ai,OO as an,So as ao,my as ar,cj as at,BM as b,qd as ba,Kp as bi,_O as bn,Ri as bo,A_ as br,uA as bt,AN as c,Sf as ca,vh as ci,vO as cn,_o as co,Jv as cr,nj as ct,WM as d,kf as da,gh as di,yO as dn,mo as do,Ev as dr,JA as dt,If as ea,zh as ei,RO as en,Oo as eo,zy as er,Kj as et,kN as f,vf as fa,hh as fi,lO as fn,fo,pv as fr,YA as ft,yN as g,mf as ga,Pm as gi,dO as gn,Na as go,nv as gr,qA as gt,lN as h,hf as ha,rh as hi,mO as hn,ka as ho,hv as hr,BA as ht,KM as i,Tf as ia,kh as ii,DO as in,wo as io,by as ir,lj as it,DN as j,Ss as ja,Ep as ji,rT as jn,yi as jo,kg as jr,Vk as jt,pN as k,zs as ka,Mp as ki,TT as kn,wi as ko,E_ as kr,Kk as kt,jN as l,Nf as la,mh as li,xO as ln,go as lo,Uv as lr,ij as lt,uN as m,_f as ma,oh as mi,pO as mn,lo as mo,ov as mr,WA as mt,xN as n,Mf as na,jh as ni,HO as nn,Eo as no,Iy as nr,Sj as nt,bN as o,Af as oa,xh as oi,TO as on,bo as oo,hy as or,sj as ot,dN as p,gf as pa,_h as pi,uO as pn,uo as po,mv as pr,UA as pt,yM as q,Lo as qa,$f as qi,GC as qn,ng as qr,KO as qt,eN as r,wf as ra,Dh as ri,UO as rn,To as ro,Ly as rr,Cj as rt,MN as s,Cf as sa,yh as si,EO as sn,yo as so,Yv as sr,aj as st,YM as t,jf as ta,Ih as ti,zO as tn,Do as to,Ry as tr,Zj as tt,ON as u,Pf as ua,ph as ui,CO as un,ho as uo,Tv as ur,ZA as ut,qM as v,sf as va,gm as vi,fO as vn,Ii as vo,ev as vr,KA as vt,vN as w,Zs as wa,Xp as wi,QE as wn,ji as wo,N_ as wr,mA as wt,hN as x,Jd as xa,Gp as xi,sO as xn,Fi as xo,O_ as xr,lA as xt,ZM as y,tf as ya,zp as yi,hO as yn,Li as yo,K_ as yr,gA as yt,NM as z,ss as za,fp as zi,Iw as zn,Q as zr,_k as zt};
220
+ `)}catch(t){return B.error(`Error parsing HTML content:`,t),e}}function pM(e){if(!e)return``;try{return fM(dM.ansi_to_html(e))}catch(t){return B.error(`Error converting ANSI to plain text:`,t),e}}var mM=o(null);function hM(e){return e.type===`cell`?e.cellId:`lsp:${e.name}`}var gM=!1;function _M(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=Ir.asString(r.data),o=i?fM(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(vM.log),n.length===0&&vf(e.output?.mimetype)&&Array.isArray(e.output.data)){e.output.data.forEach(t=>{vM.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(pe)===`read`;if(t.length>0&&!gM&&n){gM=!0;let e=t.find(e=>e.traceback);nn(e?{title:`An internal error occurred`,description:e.msg||`Click 'View' to see traceback`,variant:`danger`,action:G.createElement(pt,{altText:`View traceback`,onClick:()=>{u.set(mM,{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 vM={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`,`[${yM(e.timestamp)}]`,`(${hM(e.source)}) ${e.message}`)}};function yM(e){try{return nM(e).toLocaleTimeString(void 0,{hour12:!0,hour:`numeric`,minute:`numeric`,second:`numeric`})}catch{return``}}function bM(e,t){let n=kN(t);n?n.focus():B.warn(`[CellFocusManager] focusCellEditor: element not found: ${t}`)}function xM(e){let t=document.getElementById(ji.create(e));t?wM(t):B.warn(`[CellFocusManager] focusCell: element not found: ${e}`)}function SM(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}function CM(){return document.activeElement instanceof HTMLElement&&document.activeElement.classList.contains(`marimo-cell`)}function wM(e){try{e.focus()}catch{B.warn(`[CellFocusManager] element may not be focusable`,e)}}function TM(e,t){let{retries:n,delay:r,initialDelay:i=0}=t,a=0,o=()=>{if(a<n){try{if(e())return}catch(e){B.error(`Error executing function on attempt ${a+1}, retrying`,{error:e})}a++,setTimeout(o,r)}};i>0?setTimeout(o,i):o()}function EM({cellId:e,cell:t,isCodeHidden:n,codeFocus:r,variableName:i}){if(!t)return;let a=document.getElementById(ji.create(e));if(!a){B.warn(`scrollCellIntoView: element not found`);return}if(CM()){wM(a);return}if(n)wM(a);else{Zs.promote(e);let n=t.current?.editorView;if(!n){B.warn(`scrollCellIntoView: editor not found`,e);return}if(n.hasFocus||!document.hasFocus())return;if(TM(()=>(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&&K_(n,i)}a.scrollIntoView({behavior:`smooth`,block:`nearest`})}function DM(e){let t=document.getElementById(ji.create(e));if(!t){B.warn(`scrollCellIntoView: element not found`);return}t.classList.add(`focus-outline`),setTimeout(()=>{t.classList.remove(`focus-outline`)},2e3),t.scrollIntoView({behavior:`smooth`,block:`center`})}function OM(){let e=document.getElementById(`App`);e?.scrollTo({top:e.scrollHeight,behavior:`smooth`})}function kM(){document.getElementById(`App`)?.scrollTo({top:0,behavior:`smooth`})}function AM(e){let t=kN(e);if(t?.hasFocus){Mh(t,{behavior:`instant`});return}let n=document.getElementById(ji.create(e));n?n.scrollIntoView({behavior:`instant`,block:`nearest`}):B.warn(`[CellFocusManager] scrollCellIntoView: element not found: ${e}`)}function jM({id:e,name:t=`_`,code:n=``,lastCodeRun:r=null,lastExecutionTime:i=null,edited:a=!1,config:o,serializedEditorState:s=null}){return{id:e,config:o||{hide_code:!1,disabled:!1,column:null,expand_output:!1},name:t,code:n,edited:a,lastCodeRun:r,lastExecutionTime:i,serializedEditorState:s}}function MM(e){return{hide_code:!1,disabled:!1,column:null,expand_output:!1,...e}}function NM(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 PM(e){let t={column:0,hide_code:!1,disabled:!1,expand_output:!1};return{...e,cellData:{[ki]:jM({id:ki,config:t}),...e.cellData},cellRuntime:{[ki]:NM(),...e.cellRuntime},cellHandles:{[ki]:(0,G.createRef)(),...e.cellHandles}}}function FM(){return PM({cellIds:Es.from([]),cellData:{},cellRuntime:{},cellHandles:{},history:[],scrollKey:null,cellLogs:[],untouchedNewCells:new Set})}var{reducer:IM,addMiddleware:LM,createActions:RM,useActions:zM,valueAtom:BM}=Er(FM,{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||Ai.create(),h=r?p:p+1;return{...e,cellIds:e.cellIds.insertId(m,f,h),cellData:{...e.cellData,[m]:jM({id:m,code:i,name:a,lastCodeRun:s,config:MM({...o,...d!=null&&{hide_code:d}}),lastExecutionTime:c,edited:!!i&&i!==s})},cellRuntime:{...e.cellRuntime,[m]:NM()},cellHandles:{...e.cellHandles,[m]:(0,G.createRef)()},scrollKey:l?m:null,untouchedNewCells:d&&l?new Set([...e.untouchedNewCells,m]):e.untouchedNewCells}},moveCell:(e,t)=>{let{cellId:n,before:r,direction:i}=t;if(r!==void 0&&i!==void 0&&B.warn(`Both before and direction specified for moveCell. Ignoring one.`),i){let t=e.cellIds.findWithId(n),r=e.cellIds.indexOf(t),a=i===`left`?r-1:r+1,o=e.cellIds.at(a);return o?{...e,cellIds:e.cellIds.moveAcrossColumns(t.id,n,o.id,void 0),scrollKey:n}:e}let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n);return r&&o===0?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,0),scrollKey:n}:!r&&o===a.length-1?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,a.length-1),scrollKey:n}:r?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o-1),scrollKey:n}:{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o+1),scrollKey:n}},moveCellToIndex:(e,t)=>{let{cellId:n,columnId:r,index:i}=t,a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=e.cellIds.get(r);if(!s)return e;let c=Math.max(0,Math.min(i,s.length)),l=a.id===r&&o<c?c-1:c;if(a.id===r&&o===l)return e;let u=e.cellIds.deleteById(n),d=u.get(r);return d?{...e,cellIds:u.insertId(n,r,Math.max(0,Math.min(l,d.length))),scrollKey:null}:e},dropCellOverCell:(e,t)=>{let{cellId:n,overCellId:r}=t,i=e.cellIds.findWithId(n),a=e.cellIds.findWithId(r),o=i.indexOfOrThrow(n),s=a.indexOfOrThrow(r);return i.id===a.id?o===s?e:{...e,cellIds:e.cellIds.moveWithinColumn(i.id,o,s),scrollKey:null}:{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,a.id,r),scrollKey:null}},moveCellsRelativeTo:(e,t)=>{let{cellIds:n,targetCellId:r,position:i,previousPlacements:a}=t;if(n.length===0)return e;let o=e.cellIds.moveCellsRelativeTo(n,r,i),s=a&&a.length===n.length?[...e.history,{type:`move`,cellIds:n,placements:a}]:e.history;return{...e,cellIds:o,history:s,scrollKey:null}},dropCellOverColumn:(e,t)=>{let{cellId:n,columnId:r}=t,i=e.cellIds.findWithId(n);return{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,r,void 0)}},dropOverNewColumn:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.moveToNewColumn(n)}},moveColumn:(e,t)=>t.column===t.overColumn?e:{...e,cellIds:e.cellIds.moveColumn(t.column,t.overColumn)},focusCell:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,where:i}=t,a=n.indexOfOrThrow(r),o;o=i===`before`?xr(a-1,0,n.length-1):i===`after`?xr(a+1,0,n.length-1):a;let s=n.atOrThrow(o);return EM({cellId:s,cell:e.cellHandles[s],isCodeHidden:VM(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 EM({cellId:n,cell:e.cellHandles[n],isCodeHidden:VM(e,n),codeFocus:void 0,variableName:void 0}),kM(),e},focusBottomCell:e=>{let t=e.cellIds.getColumns().at(-1);if(t===void 0||t.length===0)return e;let n=t.last();return EM({cellId:n,cell:e.cellHandles[n],isCodeHidden:VM(e,n),codeFocus:void 0,variableName:void 0}),OM(),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=Ai.create();return{...e,cellIds:e.cellIds.addColumn(t.columnId,[n]),cellData:{...e.cellData,[n]:jM({id:n})},cellRuntime:{...e.cellRuntime,[n]:NM()},cellHandles:{...e.cellHandles,[n]:(0,G.createRef)()},scrollKey:n}},addColumnBreakpoint:(e,t)=>{let{cellId:n}=t;return e.cellIds.getColumns()[0].inOrderIds[0]===n?e:{...e,cellIds:e.cellIds.insertBreakpoint(n)}},deleteColumn:(e,t)=>{let{columnId:n}=t;return{...e,cellIds:e.cellIds.delete(n)}},mergeAllColumns:e=>({...e,cellIds:e.cellIds.mergeAllColumns()}),compactColumns:e=>({...e,cellIds:e.cellIds.compact()}),deleteCell:(e,t)=>{let n=t.cellId;if(e.cellIds.hasOnlyOneId())return e;let r;try{r=e.cellIds.findWithId(n)}catch(t){return B.warn(`Skipping delete for missing cellId`,{cellId:n,error:t}),e}let i=r.indexOfOrThrow(n),a=i===0?1:i-1,o=null;r.length>1&&(o=r.atOrThrow(a));let s=(e.cellHandles[n].current?.editorView)?.state.toJSON({history:$n});s&&(s.doc=e.cellData[n].code),wN(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===W,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?W:Ai.create(),l=jM({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]:NM()},cellHandles:{...e.cellHandles,[c]:(0,G.createRef)()},history:e.history.slice(0,-1),scrollKey:c}},clearSerializedEditorState:(e,t)=>{let{cellId:n}=t;return UM({state:e,cellId:n,cellReducer:e=>({...e,serializedEditorState:null})})},updateCellCode:(e,t)=>{let{cellId:n,code:r,formattingChange:i}=t;return e.cellData[n]?UM({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 UM({state:e,cellId:n,cellReducer:e=>({...e,name:r})})},updateCellConfig:(e,t)=>{let{cellId:n,config:r}=t;return UM({state:e,cellId:n,cellReducer:e=>({...e,config:MM({...e.config,...r})})})},prepareForRun:(e,t)=>UM({state:HM({state:e,cellId:t.cellId,cellReducer:e=>xj(e)}),cellId:t.cellId,cellReducer:e=>({...e,edited:!1,lastCodeRun:e.code.trim()})}),handleCellMessage:(e,t)=>{let n=t.cell_id,r=HM({state:e,cellId:n,cellReducer:e=>bj(e,t)});return t.status===`queued`&&(r=UM({state:r,cellId:n,cellReducer:e=>({...e,lastCodeRun:e.code.trim(),edited:!1})})),{...r,cellLogs:[...r.cellLogs,..._M(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]=jM({id:a})),a in e.cellRuntime||(r[a]=NM()),a in e.cellHandles||(i[a]=(0,G.createRef)());return{...e,cellIds:Es.fromWithPreviousShape(t.cellIds,e.cellIds),cellData:n,cellRuntime:r,cellHandles:i}},rebuildCellColumns:(e,t)=>{let n=Es.fromIdsAndColumns(t.cellIds.map(t=>[t,e.cellData[t]?.config.column??null]));return{...e,cellIds:n}},setCellCodes:(e,t)=>{de(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 jM({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(!cj()||!lj(i)){let e=n.cellHandles[i].current;e?.editorViewOrNull&&YA(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 HM({state:e,cellId:n,cellReducer:e=>{let t=[...e.consoleOutputs],n=t[i];return n==null||n.channel!==`stdin`?(B.warn(`Expected stdin output`),e):(t[i]={channel:`stdin`,mimetype:n.mimetype,data:n.data,timestamp:n.timestamp,response:r},{...e,interrupted:!1,consoleOutputs:t})}})},setCells:(e,t)=>{let n=Object.fromEntries(t.map(e=>[e.id,e])),r=me(),i=t=>{if(!r)return NM();let n=e.cellRuntime[t];return n&&(n.output!=null||n.consoleOutputs.length>0)?n:NM()},a=Object.fromEntries(t.map(e=>[e.id,i(e.id)]));return PM({...e,cellIds:Es.fromIdsAndColumns(t.map(e=>[e.id,e.config.column])),cellData:n,cellRuntime:a,cellHandles:Object.fromEntries(t.map(e=>[e.id,(0,G.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=Ai.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,s),cellData:{...e.cellData,[t]:jM({id:t})},cellRuntime:{...e.cellRuntime,[t]:NM()},cellHandles:{...e.cellHandles,[t]:(0,G.createRef)()},scrollKey:t}}if(l&&!i){let t=Ai.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,0),cellData:{...e.cellData,[t]:jM({id:t})},cellRuntime:{...e.cellRuntime,[t]:NM()},cellHandles:{...e.cellHandles,[t]:(0,G.createRef)()},scrollKey:t}}if((c||l)&&i)return e;if(s>=0&&s<a.length){let t=a.atOrThrow(s);EM({cellId:t,cell:e.cellHandles[t],isCodeHidden:VM(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 EM({cellId:i,cell:e.cellHandles[i],isCodeHidden:VM(e,i),codeFocus:void 0,variableName:void 0}),{...e,scrollKey:null}},foldAll:e=>(Ks(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),unfoldAll:e=>(qs(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=oj(r.indexOfOrThrow(n),i);if(!a)return e;let o=r.atOrThrow(a[1]);return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.collapse(n,o)),scrollKey:n}},expandCell:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.expand(n)),scrollKey:n}},collapseAllCells:e=>({...e,cellIds:e.cellIds.transformAll(t=>{let n=t.topLevelIds.map(t=>e.cellRuntime[t].outline),r=[...t.nodes],i=new Map,a=[],o=r.length-1;for(;o>=0;){let e=oj(o,n);if(e){let n=o,r=e[1],s=i.get(r)??r;i.set(r,n);let c=t.atOrThrow(n),l=t.atOrThrow(s);a.push({id:c,until:l})}else a.push(null);o--}let s=a.toReversed();return t.collapseAll(s)})}),expandAllCells:e=>({...e,cellIds:e.cellIds.transformAll(e=>e.expandAll())}),showCellIfHidden:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r,a=r.findAndExpandDeep(n);return a.equals(i)?e:{...e,cellIds:e.cellIds.transformWithCellId(n,()=>a)}},splitCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.indexOfOrThrow(n),a=e.cellData[n],o=e.cellHandles[n].current;if(o?.editorView==null)return e;let{beforeCursorCode:s,afterCursorCode:c}=XA(o.editorView);YA(o.editorView,s);let l=Ai.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]:jM({id:l,code:c,edited:!!c})},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]},[l]:NM()},cellHandles:{...e.cellHandles,[l]:(0,G.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:(YA(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 HM({state:e,cellId:n,cellReducer:e=>({...e,output:null,consoleOutputs:[]})})},clearCellConsoleOutput:(e,t)=>{let{cellId:n}=t;return HM({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:W}:{...e,cellIds:e.cellIds.insertId(W,e.cellIds.atOrThrow(0).id,0),cellData:{...e.cellData,[W]:jM({id:W,name:W,code:n,edited:!!n})},cellRuntime:{...e.cellRuntime,[W]:NM()},cellHandles:{...e.cellHandles,[W]:(0,G.createRef)()},scrollKey:W}}});LM(eM);function VM(e,t){return!!e.cellData[t].config.hide_code&&!e.untouchedNewCells.has(t)}function HM({state:e,cellId:t,cellReducer:n}){return t in e.cellRuntime?{...e,cellRuntime:{...e.cellRuntime,[t]:n(e.cellRuntime[t])}}:(B.warn(`Cell ${t} not found in state`),e)}function UM({state:e,cellId:t,cellReducer:n}){return t in e.cellData?{...e,cellData:{...e.cellData,[t]:n(e.cellData[t])}}:(B.warn(`Cell ${t} not found in state`),e)}function WM(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 GM=RM(e=>{u.set(BM,t=>IM(t,e))}).addLogs,KM=o(e=>e(BM).cellIds),qM=o(e=>e(KM).hasOnlyOneId()),JM=o(e=>wf(e(BM)).length>0);o(e=>Tf(e(BM)).length>0);var YM=o(e=>Ef(e(BM))),XM=o(e=>Df(e(BM))),ZM=o(e=>xf(e(BM))),QM=o(e=>{let{cellIds:t,cellRuntime:n,cellData:r}=e(BM);return t.inOrderIds.map(e=>{let t=n[e],{name:i}=r[e];if(vf(t.output?.mimetype)){de(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)}),$M=o(e=>{let{cellIds:t,cellRuntime:n}=e(BM);return rj(t.inOrderIds.map(e=>n[e].outline))}),eN=o(e=>e(QM).length),tN=c(o(e=>{let{cellIds:t,cellData:n}=e(BM);return ue.fromEntries(t.inOrderIds.map(e=>[e,n[e]?.name]))})),nN=o(e=>e(BM).scrollKey),rN=()=>s(BM),iN=()=>s(KM),aN=()=>s(tN),oN=()=>s(QM),sN=()=>s(BM).cellLogs,cN=()=>s(nN),lN=()=>u.get(BM),uN=()=>u.get(BM).cellIds,dN=()=>{let{cellIds:e,cellData:t}=u.get(BM);return e.inOrderIds.map(e=>t[e]?.name).filter(Boolean)},fN=$o(Ko(BM,e=>e.cellIds.inOrderIds.map(t=>e.cellData[t]))),pN=()=>a(fN),mN=o(e=>e(BM).cellRuntime),hN=o(e=>yf(e(BM))),gN=o(e=>{let{cellRuntime:t}=e(BM);return Object.entries(t).every(([e,t])=>t.status!==`running`||e===`__scratch__`)}),_N=o(e=>bf(e(BM))),vN=o(e=>e(BM).cellIds.colLength),yN=o(e=>e(BM).cellIds.idLength>0),bN=o(e=>e(BM).cellIds.getColumnIds()),xN=Ho(e=>o(t=>t(BM).cellData[e])),SN=Ho(e=>o(t=>t(BM).cellRuntime[e])),CN=Ho(e=>o(t=>t(BM).cellHandles[e]));function wN(e){xN.remove(e),SN.remove(e),CN.remove(e)}var TN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=xN(e),t[0]=e,t[1]=n),s(n)},EN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=SN(e),t[0]=e,t[1]=n),s(n)},DN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=CN(e),t[0]=e,t[1]=n),s(n)},ON=()=>{let{cellIds:e,cellHandles:t}=u.get(BM);return e.inOrderIds.map(e=>t[e]?.current?.editorViewOrNull).filter(Boolean)},kN=e=>{let{cellHandles:t}=u.get(BM);return t[e].current?.editorView},AN=e=>(Zs.promote(e),kN(e));function jN(e){let{cellIds:t,cellData:n,cellRuntime:r}=e;return t.getColumns().flatMap(e=>e.topLevelIds.map(e=>({...n[e],...r[e]})))}function MN(e){return o(t=>t(BM).untouchedNewCells.has(e))}function NN(e){let t=SN(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(...Ws(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 PN(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),zM(n)}export{tM as $,ko as $a,Ff as $i,$y as $n,Rh as $r,FO as $t,oN as A,Es as Aa,kp as Ai,IT as An,Ti as Ao,T_ as Ar,Hk as At,DM as B,ls as Ba,up as Bi,Pw as Bn,lg as Br,gk as Bt,_N as C,yu as Ca,im as Ci,WD as Cn,Pi as Co,M_ as Cr,pA as Ct,PN as D,Us as Da,jp as Di,vE as Dn,Ni as Do,P_ as Dr,eA as Dt,XM as E,Ws as Ea,Fp as Ei,ZE as En,W as Eo,j_ as Er,tA as Et,EN as F,hs as Fa,Dp as Fi,Kw as Fn,xg as Fr,Tk as Ft,CM as G,zo as Ga,ip as Gi,WC as Gn,qh as Gr,ek as Gt,TM as H,Vo as Ha,Qf as Hi,dw as Hn,ag as Hr,ak as Ht,rN as I,ps as Ia,Sp as Ii,Rw as In,hg as Ir,Ck as It,hM as J,Io as Ja,ep as Ji,KC as Jn,Hh as Jr,qO as Jt,SM as K,Ro as Ka,Yf as Ki,UC as Kn,rg as Kr,XO as Kt,cN as L,us as La,pp as Li,Lw as Ln,ug as Lr,Sk as Lt,iN as M,bs as Ma,wp as Mi,Uw as Mn,bi as Mo,Tg as Mr,Gk as Mt,sN as N,gs as Na,Cp as Ni,Gw as Nn,_i as No,vg as Nr,xk as Nt,TN as O,Bs as Oa,Np as Oi,VE as On,Mi as Oo,g_ as Or,$k as Ot,aN as P,ms as Pa,xp as Pi,Ww as Pn,fi as Po,Cg as Pr,Ek as Pt,aM as Q,Ao as Qa,qf as Qi,eb as Qn,Vh as Qr,NO as Qt,jM as R,cs as Ra,dp as Ri,zw as Rn,cg as Rr,wk as Rt,$M as S,Fd as Sa,rm as Si,cO as Sn,Ai as So,D_ as Sr,dA as St,gN as T,Hs as Ta,Pp as Ti,$E as Tn,ki as To,k_ as Tr,nA as Tt,xM as U,rs as Ua,Xf as Ui,JC as Un,eg as Ur,QO as Ut,AM as V,is as Va,mp as Vi,Mw as Vn,sg as Vr,ik as Vt,bM as W,Ko as Wa,Zf as Wi,HC as Wn,ig as Wr,$O as Wt,pM as X,No as Xa,Jf as Xi,Wb as Xn,Wh as Xr,BO as Xt,mM as Y,Fo as Ya,rp as Yi,ax as Yn,Uh as Yr,MO as Yt,fM as Z,jo as Za,Kf as Zi,nb as Zn,Bh as Zr,VO as Zt,JM as _,cf as _a,_m as _i,gO as _n,zi as _o,Q_ as _r,zA as _t,mN as a,Of as aa,Ch as ai,OO as an,So as ao,my as ar,cj as at,BM as b,qd as ba,Kp as bi,_O as bn,Ri as bo,A_ as br,uA as bt,AN as c,Sf as ca,vh as ci,vO as cn,_o as co,Jv as cr,nj as ct,WM as d,kf as da,gh as di,yO as dn,mo as do,Ev as dr,JA as dt,If as ea,zh as ei,RO as en,Oo as eo,zy as er,Kj as et,kN as f,vf as fa,hh as fi,lO as fn,fo,pv as fr,YA as ft,yN as g,mf as ga,Pm as gi,dO as gn,Na as go,nv as gr,qA as gt,lN as h,hf as ha,rh as hi,mO as hn,ka as ho,hv as hr,BA as ht,KM as i,Tf as ia,kh as ii,DO as in,wo as io,by as ir,lj as it,DN as j,Ss as ja,Ep as ji,rT as jn,yi as jo,kg as jr,Vk as jt,pN as k,zs as ka,Mp as ki,TT as kn,wi as ko,E_ as kr,Kk as kt,jN as l,Nf as la,mh as li,xO as ln,go as lo,Uv as lr,ij as lt,uN as m,_f as ma,oh as mi,pO as mn,lo as mo,ov as mr,WA as mt,xN as n,Mf as na,jh as ni,HO as nn,Eo as no,Iy as nr,Sj as nt,bN as o,Af as oa,xh as oi,TO as on,bo as oo,hy as or,sj as ot,dN as p,gf as pa,_h as pi,uO as pn,uo as po,mv as pr,UA as pt,yM as q,Lo as qa,$f as qi,GC as qn,ng as qr,KO as qt,eN as r,wf as ra,Dh as ri,UO as rn,To as ro,Ly as rr,Cj as rt,MN as s,Cf as sa,yh as si,EO as sn,yo as so,Yv as sr,aj as st,YM as t,jf as ta,Ih as ti,zO as tn,Do as to,Ry as tr,Zj as tt,ON as u,Pf as ua,ph as ui,CO as un,ho as uo,Tv as ur,ZA as ut,qM as v,sf as va,gm as vi,fO as vn,Ii as vo,ev as vr,KA as vt,vN as w,Zs as wa,Xp as wi,QE as wn,ji as wo,N_ as wr,mA as wt,hN as x,Jd as xa,Gp as xi,sO as xn,Fi as xo,O_ as xr,lA as xt,ZM as y,tf as ya,zp as yi,hO as yn,Li as yo,K_ as yr,gA as yt,NM as z,ss as za,fp as zi,Iw as zn,Q as zr,_k as zt};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-CUdNIagt.js";import{ao as n,lo as r}from"./cells-BY2lhea7.js";import{D as i,P as a,S as o,b as s}from"./schemas-BL-NsLlF.js";import{t as c}from"./compiler-runtime-BQ9S8nyo.js";import{t as l}from"./isEmpty-BJso7_X0.js";import{nt as u}from"./ai-model-dropdown-Bq7LNfwO.js";import{g as d}from"./useEventListener-BdZUApHd.js";import{t as f}from"./cn-ldLVeaqm.js";import{t as p}from"./jsx-runtime-B74pBk57.js";import{a as m,i as h,o as g,r as _}from"./config-CMqNngzA.js";import{t as v}from"./button-BoklZTGL.js";import{t as y}from"./createLucideIcon-rHn2EdoM.js";import{r as b}from"./paths-CzfpItSz.js";import{Y as x,p as S,u as C}from"./add-cell-with-ai-CY4gzrAg.js";import{t as w}from"./bot-message-square-BfGaNy9r.js";import{a as T}from"./useNumberFormatter-C4-_TnkF.js";import{i as E}from"./strings-BHZPE0Mc.js";import{Cn as D,Oa as O,Oi as k,_a as A,aa as j}from"./index-BtFkx6qT.js";var M=y(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),N=y(`shield-question-mark`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),P=`user_cancelled`;function F(e){if(e.type===`abort`)return e.reason}function I(e){return e.isAbort?e.streamReason||`user_cancelled`:null}function L(e){switch(e){case P:return`Generation stopped`;case`timeout`:return`Generation stopped: timed out`;default:return`Generation stopped: ${e}`}}var R=c(),z=e(t(),1),B=p(),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)(w,{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)(g,{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 v;t[4]===n?v=t[5]:(v=(0,B.jsx)(h,{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)(D,{content:n})})})}),t[4]=n,t[5]=v);let y;t[6]!==p||t[7]!==v?(y=(0,B.jsxs)(m,{value:`reasoning`,className:`border-0`,children:[p,v]}),t[6]=p,t[7]=v,t[8]=y):y=t[8];let b;return t[9]!==a||t[10]!==l||t[11]!==y?(b=(0,B.jsx)(_,{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=f(`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 p;t[6]===n?p=t[7]:(p=H(n),t[6]=n,t[7]=p);let m;t[8]===p?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:p})]})]}),t[8]=p,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)(v,{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)(v,{size:`xs`,onClick:()=>a({id:i.id,approved:!0}),children:`Approve`}),t[15]=i.id,t[16]=a,t[17]=_):_=t[17];let y;t[18]!==_||t[19]!==g?(y=(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[g,_]}),t[18]=_,t[19]=g,t[20]=y):y=t[20];let b;return t[21]!==s||t[22]!==y||t[23]!==l||t[24]!==m||t[25]!==h?(b=(0,B.jsxs)(`div`,{className:s,role:`alertdialog`,"aria-label":l,children:[m,h,y]}),t[21]=s,t[22]=y,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:i,errorText:a,isLive:o,className:s}=e,[c,l]=z.useState(o),u=z.useRef(o),d,p;t[0]===o?(d=t[1],p=t[2]):(d=()=>{u.current&&!o&&l(!1),u.current=o},p=[o],t[0]=o,t[1]=d,t[2]=p),z.useEffect(d,p);let m;t[3]===s?m=t[4]:(m=f(`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)(r,{className:`h-3.5 w-3.5 shrink-0`}),t[6]=g):g=t[6];let _;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Failed:`}),t[7]=_):_=t[7];let v;t[8]===n?v=t[9]:(v=H(n),t[8]=n,t[9]=v);let y;t[10]===v?y=t[11]:(y=(0,B.jsxs)(`span`,{className:`flex-1 text-left`,children:[_,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:v})]}),t[10]=v,t[11]=y);let b=c&&`rotate-180`,x;t[12]===b?x=t[13]:(x=f(`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)(T,{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 w;t[20]!==a||t[21]!==i||t[22]!==c?(w=c&&(0,B.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t border-(--red-6)/40 pt-3`,children:[(0,B.jsx)(U,{input:i}),a&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-(--red-11) mb-1`,children:`Error`}),(0,B.jsx)(`pre`,{className:`bg-(--red-2) border border-(--red-6) rounded p-2 text-xs text-(--red-11) leading-relaxed overflow-auto scrollbar-thin max-h-64 whitespace-pre-wrap`,children:a})]})]}),t[20]=a,t[21]=i,t[22]=c,t[23]=w):w=t[23];let E;return t[24]!==C||t[25]!==w||t[26]!==m?(E=(0,B.jsxs)(`div`,{className:m,children:[C,w]}),t[24]=C,t[25]=w,t[26]=m,t[27]=E):E=t[27],E};function K(e){return!e}function q(e){return e==null||typeof e==`object`&&l(e)}var J=i({status:a().default(`success`),auth_required:o().default(!1),action_url:s(),next_steps:s(),meta:s(),message:a().nullish()}),Y=e=>{let t=(0,R.c)(12),{data:r}=e,i;if(t[0]!==r){let{status:e,auth_required:a,action_url:o,meta:s,next_steps:c,message:l,...u}=r,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:`Tool Result`}),t[2]=d):d=t[2];let f;t[3]===e?f=t[4]:(f=(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--grass-2) text-(--grass-11) rounded-full font-medium capitalize`,children:e}),t[3]=e,t[4]=f);let p;t[5]===a?p=t[6]:(p=a&&(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--amber-2) text-(--amber-11) rounded-full`,children:`Auth Required`}),t[5]=a,t[6]=p);let m;t[7]!==f||t[8]!==p?(m=(0,B.jsxs)(`div`,{className:`flex items-center justify-between`,children:[d,(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f,p]})]}),t[7]=f,t[8]=p,t[9]=m):m=t[9];let h;t[10]===l?h=t[11]:(h=l&&(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(n,{className:`h-3 w-3 text-(--blue-11) mt-0.5 shrink-0`}),(0,B.jsx)(`div`,{className:`text-xs text-foreground`,children:l})]}),t[10]=l,t[11]=h),i=(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[m,h,u&&(0,B.jsx)(`div`,{className:`space-y-3`,children:Object.entries(u).map(Z)})]}),t[0]=r,t[1]=i}else i=t[1];return i},X=e=>{let t=(0,R.c)(8),{result:n}=e,r;t[0]===n?r=t[1]:(r=J.safeParse(n),t[0]=n,t[1]=r);let i=r;if(i.success){let e;return t[2]===i.data?e=t[3]:(e=(0,B.jsx)(Y,{data:i.data}),t[2]=i.data,t[3]=e),e}let a;t[4]===n?a=t[5]:(a=typeof n==`string`?n:JSON.stringify(n,null,2),t[4]=n,t[5]=a);let o;return t[6]===a?o=t[7]:(o=(0,B.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1 max-h-64 overflow-y-auto scrollbar-thin`,children:a}),t[6]=a,t[7]=o),o};function Z(e){let[t,n]=e;return q(n)?null:(0,B.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:JSON.stringify(n,null,2)})]},t)}var ee={"input-streaming":`Generating`,"input-available":`Running`,"approval-responded":`Awaiting result`,"output-available":`Done`,"output-denied":`Denied`},te=new Set([`input-streaming`,`input-available`,`approval-responded`]),ne=e=>{let t=(0,R.c)(5),{state:n,interrupted:r}=e;if(r){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(M,{className:`h-3 w-3 text-muted-foreground`}),t[0]=e):e=t[0],e}switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(A,{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)(u,{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)(x,{className:`h-3 w-3 text-muted-foreground`}),t[3]=e):e=t[3],e}default:{E(n);let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(j,{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 E(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,p;t[0]!==d||t[1]!==r?(p=!d&&te.has(r),t[0]=d,t[1]=r,t[2]=p):p=t[2];let v=p,y=`tool-${u}`,b;t[3]===c?b=t[4]:(b=f(`w-full`,c),t[3]=c,t[4]=b);let x;t[5]!==v||t[6]!==r?(x=f(`h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline`,v?`text-muted-foreground`:re(r)),t[5]=v,t[6]=r,t[7]=x):x=t[7];let S;t[8]!==v||t[9]!==r?(S=(0,B.jsx)(ne,{state:r,interrupted:v}),t[8]=v,t[9]=r,t[10]=S):S=t[10];let C=v?`Interrupted`:ee[r],w;t[11]===n?w=t[12]:(w=H(n),t[11]=n,t[12]=w);let T;t[13]===w?T=t[14]:(T=(0,B.jsx)(`code`,{className:`font-mono text-xs`,children:w}),t[13]=w,t[14]=T);let E;t[15]!==T||t[16]!==S||t[17]!==C?(E=(0,B.jsxs)(`span`,{className:`flex items-center gap-1`,children:[S,C,`:`,T]}),t[15]=T,t[16]=S,t[17]=C,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==x?(D=(0,B.jsx)(g,{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)(h,{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)(m,{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)(_,{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 E(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 E(r),null}},ae=({message:e,isStreamingReasoning:t,isLast:n,isActive:r,addToolApprovalResponse:i})=>{return(0,B.jsx)(B.Fragment,{children:e.parts.map((e,t)=>a(e,t))});function a(a,o){if(oe(a))return(0,B.jsx)($,{index:o,toolName:a.type,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,className:`my-2`,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);if(se(a))return d.debug(`Found data part`,a),null;switch(a.type){case`text`:return a.text.includes(`<marimo-`)?(0,B.jsx)(z.Fragment,{children:k({html:a.text})},o):(0,B.jsx)(D,{content:a.text},o);case`reasoning`:return(0,B.jsx)(V,{reasoning:a.text,index:o,isStreaming:t&&n&&o===(e.parts.length||0)-1},o);case`file`:return(0,B.jsx)(C,{attachment:a},o);case`reasoning-file`:return(0,B.jsx)(C,{attachment:{type:`file`,mediaType:a.mediaType,url:a.url}},o);case`dynamic-tool`:return(0,B.jsx)($,{toolName:a.toolName,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);case`source-document`:return(0,B.jsx)(S,{icon:(0,B.jsx)(b,{className:`h-3 w-3 shrink-0`}),title:a.title,subtitle:a.filename},o);case`source-url`:return(0,B.jsx)(S,{icon:(0,B.jsx)(O,{className:`h-3 w-3 shrink-0`}),title:a.title??a.url,subtitle:a.title?a.url:void 0,href:a.url},o);case`custom`:return(0,B.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.kind},o);case`step-start`:return null;default:return E(a),null}}};function oe(e){return e.type.startsWith(`tool-`)}function se(e){return e.type.startsWith(`data-`)}export{I as i,L as n,F as r,ae as t};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-CUdNIagt.js";import{ao as n,lo as r}from"./cells-C0itXtA7.js";import{D as i,P as a,S as o,b as s}from"./schemas-BL-NsLlF.js";import{t as c}from"./compiler-runtime-BQ9S8nyo.js";import{t as l}from"./isEmpty-BJso7_X0.js";import{nt as u}from"./ai-model-dropdown-Ct4CTWKe.js";import{g as d}from"./useEventListener-BdZUApHd.js";import{t as f}from"./cn-ldLVeaqm.js";import{t as p}from"./jsx-runtime-B74pBk57.js";import{a as m,i as h,o as g,r as _}from"./config-CMqNngzA.js";import{t as v}from"./button-BoklZTGL.js";import{t as y}from"./createLucideIcon-rHn2EdoM.js";import{r as b}from"./paths-CzfpItSz.js";import{Y as x,p as S,u as C}from"./add-cell-with-ai-CSNC0MIy.js";import{t as w}from"./bot-message-square-BfGaNy9r.js";import{a as T}from"./useNumberFormatter-C4-_TnkF.js";import{i as E}from"./strings-BHZPE0Mc.js";import{Cn as D,Oa as O,Oi as k,_a as A,aa as j}from"./index-CcaMC2ZX.js";var M=y(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),N=y(`shield-question-mark`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),P=`user_cancelled`;function F(e){if(e.type===`abort`)return e.reason}function I(e){return e.isAbort?e.streamReason||`user_cancelled`:null}function L(e){switch(e){case P:return`Generation stopped`;case`timeout`:return`Generation stopped: timed out`;default:return`Generation stopped: ${e}`}}var R=c(),z=e(t(),1),B=p(),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)(w,{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)(g,{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 v;t[4]===n?v=t[5]:(v=(0,B.jsx)(h,{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)(D,{content:n})})})}),t[4]=n,t[5]=v);let y;t[6]!==p||t[7]!==v?(y=(0,B.jsxs)(m,{value:`reasoning`,className:`border-0`,children:[p,v]}),t[6]=p,t[7]=v,t[8]=y):y=t[8];let b;return t[9]!==a||t[10]!==l||t[11]!==y?(b=(0,B.jsx)(_,{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=f(`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 p;t[6]===n?p=t[7]:(p=H(n),t[6]=n,t[7]=p);let m;t[8]===p?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:p})]})]}),t[8]=p,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)(v,{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)(v,{size:`xs`,onClick:()=>a({id:i.id,approved:!0}),children:`Approve`}),t[15]=i.id,t[16]=a,t[17]=_):_=t[17];let y;t[18]!==_||t[19]!==g?(y=(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[g,_]}),t[18]=_,t[19]=g,t[20]=y):y=t[20];let b;return t[21]!==s||t[22]!==y||t[23]!==l||t[24]!==m||t[25]!==h?(b=(0,B.jsxs)(`div`,{className:s,role:`alertdialog`,"aria-label":l,children:[m,h,y]}),t[21]=s,t[22]=y,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:i,errorText:a,isLive:o,className:s}=e,[c,l]=z.useState(o),u=z.useRef(o),d,p;t[0]===o?(d=t[1],p=t[2]):(d=()=>{u.current&&!o&&l(!1),u.current=o},p=[o],t[0]=o,t[1]=d,t[2]=p),z.useEffect(d,p);let m;t[3]===s?m=t[4]:(m=f(`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)(r,{className:`h-3.5 w-3.5 shrink-0`}),t[6]=g):g=t[6];let _;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Failed:`}),t[7]=_):_=t[7];let v;t[8]===n?v=t[9]:(v=H(n),t[8]=n,t[9]=v);let y;t[10]===v?y=t[11]:(y=(0,B.jsxs)(`span`,{className:`flex-1 text-left`,children:[_,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:v})]}),t[10]=v,t[11]=y);let b=c&&`rotate-180`,x;t[12]===b?x=t[13]:(x=f(`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)(T,{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 w;t[20]!==a||t[21]!==i||t[22]!==c?(w=c&&(0,B.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t border-(--red-6)/40 pt-3`,children:[(0,B.jsx)(U,{input:i}),a&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-(--red-11) mb-1`,children:`Error`}),(0,B.jsx)(`pre`,{className:`bg-(--red-2) border border-(--red-6) rounded p-2 text-xs text-(--red-11) leading-relaxed overflow-auto scrollbar-thin max-h-64 whitespace-pre-wrap`,children:a})]})]}),t[20]=a,t[21]=i,t[22]=c,t[23]=w):w=t[23];let E;return t[24]!==C||t[25]!==w||t[26]!==m?(E=(0,B.jsxs)(`div`,{className:m,children:[C,w]}),t[24]=C,t[25]=w,t[26]=m,t[27]=E):E=t[27],E};function K(e){return!e}function q(e){return e==null||typeof e==`object`&&l(e)}var J=i({status:a().default(`success`),auth_required:o().default(!1),action_url:s(),next_steps:s(),meta:s(),message:a().nullish()}),Y=e=>{let t=(0,R.c)(12),{data:r}=e,i;if(t[0]!==r){let{status:e,auth_required:a,action_url:o,meta:s,next_steps:c,message:l,...u}=r,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:`Tool Result`}),t[2]=d):d=t[2];let f;t[3]===e?f=t[4]:(f=(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--grass-2) text-(--grass-11) rounded-full font-medium capitalize`,children:e}),t[3]=e,t[4]=f);let p;t[5]===a?p=t[6]:(p=a&&(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--amber-2) text-(--amber-11) rounded-full`,children:`Auth Required`}),t[5]=a,t[6]=p);let m;t[7]!==f||t[8]!==p?(m=(0,B.jsxs)(`div`,{className:`flex items-center justify-between`,children:[d,(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f,p]})]}),t[7]=f,t[8]=p,t[9]=m):m=t[9];let h;t[10]===l?h=t[11]:(h=l&&(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(n,{className:`h-3 w-3 text-(--blue-11) mt-0.5 shrink-0`}),(0,B.jsx)(`div`,{className:`text-xs text-foreground`,children:l})]}),t[10]=l,t[11]=h),i=(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[m,h,u&&(0,B.jsx)(`div`,{className:`space-y-3`,children:Object.entries(u).map(Z)})]}),t[0]=r,t[1]=i}else i=t[1];return i},X=e=>{let t=(0,R.c)(8),{result:n}=e,r;t[0]===n?r=t[1]:(r=J.safeParse(n),t[0]=n,t[1]=r);let i=r;if(i.success){let e;return t[2]===i.data?e=t[3]:(e=(0,B.jsx)(Y,{data:i.data}),t[2]=i.data,t[3]=e),e}let a;t[4]===n?a=t[5]:(a=typeof n==`string`?n:JSON.stringify(n,null,2),t[4]=n,t[5]=a);let o;return t[6]===a?o=t[7]:(o=(0,B.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1 max-h-64 overflow-y-auto scrollbar-thin`,children:a}),t[6]=a,t[7]=o),o};function Z(e){let[t,n]=e;return q(n)?null:(0,B.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:JSON.stringify(n,null,2)})]},t)}var ee={"input-streaming":`Generating`,"input-available":`Running`,"approval-responded":`Awaiting result`,"output-available":`Done`,"output-denied":`Denied`},te=new Set([`input-streaming`,`input-available`,`approval-responded`]),ne=e=>{let t=(0,R.c)(5),{state:n,interrupted:r}=e;if(r){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(M,{className:`h-3 w-3 text-muted-foreground`}),t[0]=e):e=t[0],e}switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(A,{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)(u,{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)(x,{className:`h-3 w-3 text-muted-foreground`}),t[3]=e):e=t[3],e}default:{E(n);let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(j,{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 E(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,p;t[0]!==d||t[1]!==r?(p=!d&&te.has(r),t[0]=d,t[1]=r,t[2]=p):p=t[2];let v=p,y=`tool-${u}`,b;t[3]===c?b=t[4]:(b=f(`w-full`,c),t[3]=c,t[4]=b);let x;t[5]!==v||t[6]!==r?(x=f(`h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline`,v?`text-muted-foreground`:re(r)),t[5]=v,t[6]=r,t[7]=x):x=t[7];let S;t[8]!==v||t[9]!==r?(S=(0,B.jsx)(ne,{state:r,interrupted:v}),t[8]=v,t[9]=r,t[10]=S):S=t[10];let C=v?`Interrupted`:ee[r],w;t[11]===n?w=t[12]:(w=H(n),t[11]=n,t[12]=w);let T;t[13]===w?T=t[14]:(T=(0,B.jsx)(`code`,{className:`font-mono text-xs`,children:w}),t[13]=w,t[14]=T);let E;t[15]!==T||t[16]!==S||t[17]!==C?(E=(0,B.jsxs)(`span`,{className:`flex items-center gap-1`,children:[S,C,`:`,T]}),t[15]=T,t[16]=S,t[17]=C,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==x?(D=(0,B.jsx)(g,{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)(h,{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)(m,{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)(_,{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 E(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 E(r),null}},ae=({message:e,isStreamingReasoning:t,isLast:n,isActive:r,addToolApprovalResponse:i})=>{return(0,B.jsx)(B.Fragment,{children:e.parts.map((e,t)=>a(e,t))});function a(a,o){if(oe(a))return(0,B.jsx)($,{index:o,toolName:a.type,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,className:`my-2`,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);if(se(a))return d.debug(`Found data part`,a),null;switch(a.type){case`text`:return a.text.includes(`<marimo-`)?(0,B.jsx)(z.Fragment,{children:k({html:a.text})},o):(0,B.jsx)(D,{content:a.text},o);case`reasoning`:return(0,B.jsx)(V,{reasoning:a.text,index:o,isStreaming:t&&n&&o===(e.parts.length||0)-1},o);case`file`:return(0,B.jsx)(C,{attachment:a},o);case`reasoning-file`:return(0,B.jsx)(C,{attachment:{type:`file`,mediaType:a.mediaType,url:a.url}},o);case`dynamic-tool`:return(0,B.jsx)($,{toolName:a.toolName,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);case`source-document`:return(0,B.jsx)(S,{icon:(0,B.jsx)(b,{className:`h-3 w-3 shrink-0`}),title:a.title,subtitle:a.filename},o);case`source-url`:return(0,B.jsx)(S,{icon:(0,B.jsx)(O,{className:`h-3 w-3 shrink-0`}),title:a.title??a.url,subtitle:a.title?a.url:void 0,href:a.url},o);case`custom`:return(0,B.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.kind},o);case`step-start`:return null;default:return E(a),null}}};function oe(e){return e.type.startsWith(`tool-`)}function se(e){return e.type.startsWith(`data-`)}export{I as i,L as n,F as r,ae as t};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,l as r,t as i,u as a}from"./useEvent-Dc9HkKI2.js";import{t as o}from"./react-CUdNIagt.js";import{D as s,Xa as c,Zn as l,br as u,cn as d,co as f,dn as p,un as m}from"./cells-BY2lhea7.js";import{t as h}from"./compiler-runtime-BQ9S8nyo.js";import{a as g,n as _}from"./utils-B3E7otfg.js";import{c as v,j as y,r as b,t as x}from"./ai-model-dropdown-Bq7LNfwO.js";import{g as S,o as C}from"./useEventListener-BdZUApHd.js";import{M as w,o as T}from"./config-CBLBAU5c.js";import{t as E}from"./cn-ldLVeaqm.js";import{t as D}from"./jsx-runtime-B74pBk57.js";import{S as O,T as k,_ as A,w as j,x as M,y as N}from"./fullscreen-BmzAqMKq.js";import{u as P}from"./menu-items-BBdeXCvU.js";import{t as ee}from"./config-CMqNngzA.js";import{a as te,i as F,m as I,n as L,r as ne,s as re,t as ie}from"./select-BplWpfFo.js";import{i as ae,t as R}from"./tooltip-DR2Z2N4w.js";import{t as z}from"./button-BoklZTGL.js";import{t as B}from"./createLucideIcon-rHn2EdoM.js";import{at as oe}from"./panels-CCUm-UiE.js";import{t as se}from"./scroll-to-bottom-button-D4qWtyN8.js";import{B as ce,C as le,D as V,E as ue,N as de,R as fe,S as pe,U as me,_ as he,b as ge,c as H,d as _e,f as ve,g as ye,h as be,k as xe,l as Se,m as Ce,n as we,u as U,v as Te,w as W,x as Ee,y as De,z as Oe}from"./add-cell-with-ai-CY4gzrAg.js";import{t as G}from"./bot-message-square-BfGaNy9r.js";import{i as ke,n as Ae,r as je,t as Me}from"./chat-display-CHx8XIBv.js";import{t as Ne}from"./hat-glasses-DVgK5i5l.js";import{b as Pe,p as Fe}from"./write-secret-modal-CBUZw27N.js";import{t as Ie}from"./plus-gbN72xHe.js";import{Qt as Le,r as Re}from"./input-BDakodZ2.js";import{t as ze}from"./settings-DlKTeV_0.js";import{t as Be}from"./copy-icon-DFhUGBjO.js";import{r as Ve}from"./requests-yTHMxhVa.js";import{t as K}from"./uuid-k9DpjH68.js";import{t as He}from"./context-BFOBKCJB.js";import{Ar as Ue,Dr as We,Fn as Ge,Hn as Ke,Mr as qe,_a as Je,a as Ye,ha as Xe,kr as Ze}from"./index-BtFkx6qT.js";import{t as Qe}from"./empty-state-CzxjZqGW.js";import{g as $e,y as et}from"./edit-page-Bw_9cD6X.js";var q=e(o(),1),J=D();function tt(e,t){return q.useReducer((e,n)=>t[e][n]??e,e)}var nt=`ScrollArea`,[rt,it]=j(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=P(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)(k.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)(k.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)(N,{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)(N,{present:n||s!==`hidden`,children:(0,J.jsx)(ft,{"data-state":s===`hidden`?`hidden`:`visible`,...r,ref:t,onPointerEnter:O(e.onPointerEnter,()=>c(`POINTER_ENTER`)),onPointerLeave:O(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)(N,{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=A(u),S=A(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:A(a),onThumbPointerUp:A(o),onThumbPositionChange:S,onThumbPointerDown:A(s),children:(0,J.jsx)(k.div,{...f,ref:g,style:{position:`absolute`,...f.style},onPointerDown:O(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:O(e.onPointerMove,T),onPointerUp:O(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)(N,{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)(k.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:O(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:O(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)(k.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=I(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=A(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=A(t);M(()=>{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=B(`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=B(`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 ce{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=E(`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=E(`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(Ue),{locale:o}=He(),[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 u=l,h;bb0:{if(!s.trim()){h=u;break bb0}let e;if(t[2]!==u||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=u.filter(n),t[2]=u,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)(p,{asChild:!0,children:(0,J.jsx)(z,{variant:`text`,size:`icon`,children:(0,J.jsx)(f,{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)(Re,{placeholder:`Search chat history...`,value:s,onChange:b,className:`text-xs`})}),t[11]=s,t[12]=x);let S;t[13]===u.length?S=t[14]:(S=u.length===0&&(0,J.jsx)(Qe,{title:`No chats yet`,description:`Start a new chat to get started`,icon:(0,J.jsx)(G,{})}),t[13]=u.length,t[14]=S);let C;t[15]!==u.length||t[16]!==g.length||t[17]!==s?(C=g.length===0&&s&&u.length>0&&(0,J.jsx)(Qe,{title:`No chats found`,description:`No chats match "${s}"`,icon:(0,J.jsx)(Le,{})}),t[15]=u.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:E(`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:Ge(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 D;return t[33]!==T||t[34]!==x?(D=(0,J.jsxs)(d,{children:[y,(0,J.jsxs)(m,{className:`w-[480px] p-0`,align:`start`,side:`right`,children:[x,T]})]}),t[33]=T,t[34]=x,t[35]=D):D=t[35],D};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=E(`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 u;e[3]!==a||e[4]!==o||e[5]!==c?(u=(0,J.jsx)(p,{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]=u):u=e[6];let f;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,J.jsx)(`span`,{className:`text-sm font-semibold`,children:`Web search`}),e[7]=f):f=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:[f,(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Search the web when the model supports it.`,` `,(0,J.jsx)(Fe,{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)(m,{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)(Ye,{id:`web-search-toggle`,"aria-label":`Web search`,size:`sm`,checked:i,onCheckedChange:g})]})}),e[11]=g,e[12]=i,e[13]=_):_=e[13];let v;return e[14]!==u||e[15]!==_?(v=(0,J.jsxs)(d,{children:[u,_]}),e[14]=u,e[15]=_,e[16]=v):v=e[16],v};function qt(){return K()}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-Dc9HkKI2.js";import{t as o}from"./react-CUdNIagt.js";import{D as s,Xa as c,Zn as l,br as u,cn as d,co as f,dn as p,un as m}from"./cells-C0itXtA7.js";import{t as h}from"./compiler-runtime-BQ9S8nyo.js";import{a as g,n as _}from"./utils-B3E7otfg.js";import{c as v,j as y,r as b,t as x}from"./ai-model-dropdown-Ct4CTWKe.js";import{g as S,o as C}from"./useEventListener-BdZUApHd.js";import{M as w,o as T}from"./config-CBLBAU5c.js";import{t as E}from"./cn-ldLVeaqm.js";import{t as D}from"./jsx-runtime-B74pBk57.js";import{S as O,T as k,_ as A,w as j,x as M,y as N}from"./fullscreen-BmzAqMKq.js";import{u as P}from"./menu-items-BBdeXCvU.js";import{t as ee}from"./config-CMqNngzA.js";import{a as te,i as F,m as I,n as L,r as ne,s as re,t as ie}from"./select-BplWpfFo.js";import{i as ae,t as R}from"./tooltip-DR2Z2N4w.js";import{t as z}from"./button-BoklZTGL.js";import{t as B}from"./createLucideIcon-rHn2EdoM.js";import{at as oe}from"./panels-DwxpnIFf.js";import{t as se}from"./scroll-to-bottom-button-D4qWtyN8.js";import{B as ce,C as le,D as V,E as ue,N as de,R as fe,S as pe,U as me,_ as he,b as ge,c as H,d as _e,f as ve,g as ye,h as be,k as xe,l as Se,m as Ce,n as we,u as U,v as Te,w as W,x as Ee,y as De,z as Oe}from"./add-cell-with-ai-CSNC0MIy.js";import{t as G}from"./bot-message-square-BfGaNy9r.js";import{i as ke,n as Ae,r as je,t as Me}from"./chat-display-CHxh_MGC.js";import{t as Ne}from"./hat-glasses-DVgK5i5l.js";import{b as Pe,p as Fe}from"./write-secret-modal-CBUZw27N.js";import{t as Ie}from"./plus-gbN72xHe.js";import{Qt as Le,r as Re}from"./input-BDakodZ2.js";import{t as ze}from"./settings-DlKTeV_0.js";import{t as Be}from"./copy-icon-DFhUGBjO.js";import{r as Ve}from"./requests-yTHMxhVa.js";import{t as K}from"./uuid-k9DpjH68.js";import{t as He}from"./context-BFOBKCJB.js";import{Ar as Ue,Dr as We,Fn as Ge,Hn as Ke,Mr as qe,_a as Je,a as Ye,ha as Xe,kr as Ze}from"./index-CcaMC2ZX.js";import{t as Qe}from"./empty-state-CzxjZqGW.js";import{g as $e,y as et}from"./edit-page-Cw1A5Rhq.js";var q=e(o(),1),J=D();function tt(e,t){return q.useReducer((e,n)=>t[e][n]??e,e)}var nt=`ScrollArea`,[rt,it]=j(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=P(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)(k.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)(k.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)(N,{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)(N,{present:n||s!==`hidden`,children:(0,J.jsx)(ft,{"data-state":s===`hidden`?`hidden`:`visible`,...r,ref:t,onPointerEnter:O(e.onPointerEnter,()=>c(`POINTER_ENTER`)),onPointerLeave:O(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)(N,{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=A(u),S=A(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:A(a),onThumbPointerUp:A(o),onThumbPositionChange:S,onThumbPointerDown:A(s),children:(0,J.jsx)(k.div,{...f,ref:g,style:{position:`absolute`,...f.style},onPointerDown:O(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:O(e.onPointerMove,T),onPointerUp:O(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)(N,{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)(k.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:O(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:O(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)(k.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=I(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=A(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=A(t);M(()=>{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=B(`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=B(`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 ce{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=E(`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=E(`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(Ue),{locale:o}=He(),[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 u=l,h;bb0:{if(!s.trim()){h=u;break bb0}let e;if(t[2]!==u||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=u.filter(n),t[2]=u,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)(p,{asChild:!0,children:(0,J.jsx)(z,{variant:`text`,size:`icon`,children:(0,J.jsx)(f,{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)(Re,{placeholder:`Search chat history...`,value:s,onChange:b,className:`text-xs`})}),t[11]=s,t[12]=x);let S;t[13]===u.length?S=t[14]:(S=u.length===0&&(0,J.jsx)(Qe,{title:`No chats yet`,description:`Start a new chat to get started`,icon:(0,J.jsx)(G,{})}),t[13]=u.length,t[14]=S);let C;t[15]!==u.length||t[16]!==g.length||t[17]!==s?(C=g.length===0&&s&&u.length>0&&(0,J.jsx)(Qe,{title:`No chats found`,description:`No chats match "${s}"`,icon:(0,J.jsx)(Le,{})}),t[15]=u.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:E(`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:Ge(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 D;return t[33]!==T||t[34]!==x?(D=(0,J.jsxs)(d,{children:[y,(0,J.jsxs)(m,{className:`w-[480px] p-0`,align:`start`,side:`right`,children:[x,T]})]}),t[33]=T,t[34]=x,t[35]=D):D=t[35],D};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=E(`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 u;e[3]!==a||e[4]!==o||e[5]!==c?(u=(0,J.jsx)(p,{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]=u):u=e[6];let f;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,J.jsx)(`span`,{className:`text-sm font-semibold`,children:`Web search`}),e[7]=f):f=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:[f,(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Search the web when the model supports it.`,` `,(0,J.jsx)(Fe,{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)(m,{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)(Ye,{id:`web-search-toggle`,"aria-label":`Web search`,size:`sm`,checked:i,onCheckedChange:g})]})}),e[11]=g,e[12]=i,e[13]=_):_=e[13];let v;return e[14]!==u||e[15]!==_?(v=(0,J.jsxs)(d,{children:[u,_]}),e[14]=u,e[15]=_,e[16]=v):v=e[16],v};function qt(){return K()}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)(Je,{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)(Ie,{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)(ze,{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)(we,{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
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)(Be,{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=E(`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:Xe},{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:Ne},{value:`code_mode`,label:`Code Mode (beta)`,subtitle:`AI with access to the notebook's kernel. Potentially destructive.`,Icon:oe}],t[0]=h):h=t[0];let g=h,v=Ce.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)(re,{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)(L,{children:(0,J.jsxs)(ne,{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)(ie,{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)(H,{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)(Se,{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)(ve,{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 R;t[36]!==P||t[37]!==F||t[38]!==I?(R=(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]=R):R=t[39];let z;return t[40]!==N||t[41]!==R?(z=(0,J.jsx)(ae,{children:(0,J.jsxs)(`div`,{className:`px-3 py-2 border-t border-border/20 flex flex-wrap items-center gap-1`,children:[N,R]})}),t[40]=N,t[41]=R,t[42]=z):z=t[42],z});$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=E(`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)(we,{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=()=>W(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)(c,{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)(et,{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)(G,{}),e[2]=r):r=e[2];let i;return e[3]===t?i=e[4]:(i=(0,J.jsx)(Qe,{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(Ue),[r,o]=t(We),[c,d]=t(qe),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(``),[g,v]=(0,q.useState)(!0),{files:y,addFiles:b,clearFiles:x,removeFile:C}=pe(),{messages:w,enqueue:D,flushNext:O,clear:k,hasQueuedRef:A}=le(),j=(0,q.useRef)(null),M=(0,q.useRef)(null),N=(0,q.useRef)(null),P=(0,q.useRef)(null),ee=(0,q.useRef)(null),[te,F]=(0,q.useState)(null),I=i(()=>{ee.current=null,F(null)}),L=T(),{invokeAiTool:ne,sendRun:re}=Ve(),{openModal:ie,closeModal:R}=Pe(),B=r?.id,{chatControllerId:oe,renewDraftChatId:ce}=Jt(B),H=n(),{addStagedCell:ve}=de(),{createNewCell:Se,prepareForRun:Ce}=s(),we={addStagedCell:ve,createNewCell:Se,prepareForRun:Ce,sendRun:re,store:H},{messages:U,sendMessage:W,error:G,status:Me,regenerate:Ne,stop:Fe,addToolOutput:Ie,addToolApprovalResponse:Le,id:Re}=Oe({id:oe,throttle:100,sendAutomaticallyWhen:({messages:e})=>Te(e),messages:r?.messages||[],transport:new zt({api:L.getAiURL(`chat`).toString(),headers:()=>L.headers(),prepareSendMessagesRequest:async e=>{let t=await me({messages:e.messages});t.success||S.debug(`Outgoing chat messages failed AI SDK schema validation`,t.error);let n={uiMessages:e.messages,includeOtherCode:l(``),options:H.get(Ze)},r=H.get(_)?.mode||Yt,i=xe.getToolSchemas(r);return{api:L.getAiURL(`chat`).toString(),body:{tools:i,...e,...n}}}},e=>{let t=je(e);t!==void 0&&(ee.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=ke({isAbort:!0,streamReason:ee.current});if(I(),e!=null){let t=Ae(e);S.debug(`Chat stream aborted`,{reason:e,finishReason:i}),F(t)}}else I();Be(t,{isError:n,isAbort:r})},onToolCall:async({toolCall:e})=>{await he({invokeAiTool:ne,addToolOutput:Ie,toolCall:{toolName:e.toolName,toolCallId:e.toolCallId,input:e.input},toolContext:we})},onError:e=>{S.error(`An error occurred:`,e)}}),ze=i(e=>{I(),W({role:`user`,parts:e})}),Be=i((e,t)=>{A.current&&Ee({isError:t.isError,isAbort:t.isAbort,hasPendingToolCalls:Te(e),hasUnresolvedToolCalls:De(e)})&&O(ze)}),K=Me===`submitted`||Me===`streaming`,He=(0,q.useRef)(K);He.current=K;let Ge=i(e=>{He.current||A.current?D(e):ze(e)}),Ye=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)}),Xe=i((e=!1)=>{let t=N.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?`smooth`:`auto`})}),Qe=K&&U.length>0&&ge(U);(0,q.useEffect)(()=>{v(!0),k(),I()},[B,k,I]),(0,q.useEffect)(()=>{if(!g)return;let e=requestAnimationFrame(()=>{Xe()});return()=>cancelAnimationFrame(e)},[U,w,K,g,Xe]),(0,q.useEffect)(()=>{K||Be(U,{isError:G!=null,isAbort:!1})},[U,K,G,Be]);let et=i(t=>{let n=Date.now(),r={id:Re,title:ye(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)=>{et(e);let n=t&&t.length>0?await be(t):void 0,{contextPart:r,attachments:i}=await V(e);W({role:`user`,parts:[{type:`text`,text:e},...r?[r]:[],...n??[],...i]}),x(),p(``)}),nt=i(()=>{ce(),o(null),p(``),h(``),k(),x()}),rt=i(()=>{ie((0,J.jsx)($e,{onClose:R}))}),it=i(async(e,t)=>{let n=U[e],r=n.parts?.filter(e=>e.type===`file`&&!ue(e))??[],{contextPart:i,attachments:a}=await V(t),o=n.id;W({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&&fe(M.current.view);let n=y?await be(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&&fe(j.current.view),tt(m.trim(),y))}),st=()=>j.current?.editor?.blur(),ct=i(async e=>{B??(et(e),p(m));let{contextPart:t,attachments:n}=await V(e);Ge([{type:`text`,text:e},...t?[t]:[],...n])}),X=U.length===0;(0,q.useEffect)(()=>{if(!c)return;d(null);let{prompt:e,submit:t}=c;t?ct(e):X?(h(e),u(j)):(p(e),u(M))},[c,d,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:K,onStop:Fe,fileInputRef:P,onAddFiles:b,onClose:st},`new-thread-input`):(0,J.jsx)(en,{input:f,setInput:p,onSubmit:at,inputRef:M,isLoading:K,onStop:Fe,onClose:()=>M.current?.editor?.blur(),fileInputRef:P,onAddFiles:b}),lt=y&&y.length>0&&(0,J.jsx)(`div`,{className:E(`flex flex-row gap-1 flex-wrap p-1`,X&&`py-2 px-1`),children:y?.map(e=>(0,J.jsx)(_e,{file:e,onRemove:()=>C(e)},e.name))});return(0,J.jsxs)(`div`,{className:`flex flex-col h-[calc(100%-53px)]`,children:[(0,J.jsx)(ae,{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:Ye,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})]}),U.map((e,t)=>(0,J.jsx)(Qt,{message:e,index:t,onEdit:it,isStreamingReasoning:Qe,isLast:t===U.length-1,isActive:K,addToolApprovalResponse:Le},e.id)),w.map(e=>(0,J.jsx)(Xt,{message:e},e.id)),K&&(0,J.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,J.jsx)(Je,{className:`h-4 w-4 animate-spin`})}),G&&(0,J.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 mb-4`,children:[(0,J.jsx)(Ke,{error:G||Error(`Unknown error`)}),(0,J.jsx)(z,{variant:`outline`,size:`sm`,onClick:Y,children:`Retry`})]}),te&&!K&&!G&&(0,J.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:te})})]}),(0,J.jsx)(se,{isVisible:!g&&(U.length>0||w.length>0),onScrollToBottom:()=>Xe(!0)})]}),K&&(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:Fe,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)(U,{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)(U,{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)(F,{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-CUdNIagt.js";import{Tr as n,cn as r,dn as i,ho as a,un as o}from"./cells-BY2lhea7.js";import{E as s,P as c,S as l,b as u,j as d}from"./schemas-BL-NsLlF.js";import{t as f}from"./compiler-runtime-BQ9S8nyo.js";import{g as p,t as m}from"./useEventListener-BdZUApHd.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-BplWpfFo.js";import{a as y,p as b,r as x,t as S}from"./dropdown-menu-VuyoeQOD.js";import{t as C}from"./tooltip-DR2Z2N4w.js";import{t as w}from"./button-BoklZTGL.js";import{B as ee,H as te,K as ne,h as T,n as E,q as D,v as re,z as ie}from"./add-cell-with-ai-CY4gzrAg.js";import{t as ae}from"./bot-message-square-BfGaNy9r.js";import{r as oe}from"./useNumberFormatter-C4-_TnkF.js";import{u as O}from"./toDate-BbJ1_N2T.js";import{i as se,n as ce,r as le,t as ue}from"./chat-display-CHx8XIBv.js";import{t as de}from"./rotate-cw-BcRERxHa.js";import{o as k,r as A}from"./input-BDakodZ2.js";import{t as j}from"./settings-DlKTeV_0.js";import{t as M}from"./trash-2-BJG-7Qob.js";import{t as N}from"./copy-icon-DFhUGBjO.js";import{t as P}from"./strings-BHZPE0Mc.js";import{t as F}from"./uuid-k9DpjH68.js";import{n as I}from"./useAsyncData-DucTwMkf.js";import{Hn as L,Wr as R,Yr as z,ei as B,ua as V}from"./index-BtFkx6qT.js";var H=f(),U=_(),W=e(t(),1),G=a,fe=d({type:s(`stream_chunk`),message_id:c(),content:u().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,r]=(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),O=()=>{b.current=null,S(null)},{data:k}=I(async()=>(await e.get_chat_history({})).messages,[]),A=e.value.length>0?e.value:k,{messages:j,sendMessage:P,setMessages:z,status:H,stop:G,error:K,regenerate:q,clearError:J,addToolApprovalResponse:Y}=ie({sendAutomaticallyWhen:({messages:e})=>re(e),transport:new ee({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(`
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-CUdNIagt.js";import{Tr as n,cn as r,dn as i,ho as a,un as o}from"./cells-C0itXtA7.js";import{E as s,P as c,S as l,b as u,j as d}from"./schemas-BL-NsLlF.js";import{t as f}from"./compiler-runtime-BQ9S8nyo.js";import{g as p,t as m}from"./useEventListener-BdZUApHd.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-BplWpfFo.js";import{a as y,p as b,r as x,t as S}from"./dropdown-menu-VuyoeQOD.js";import{t as C}from"./tooltip-DR2Z2N4w.js";import{t as w}from"./button-BoklZTGL.js";import{B as ee,H as te,K as ne,h as T,n as E,q as D,v as re,z as ie}from"./add-cell-with-ai-CSNC0MIy.js";import{t as ae}from"./bot-message-square-BfGaNy9r.js";import{r as oe}from"./useNumberFormatter-C4-_TnkF.js";import{u as O}from"./toDate-BbJ1_N2T.js";import{i as se,n as ce,r as le,t as ue}from"./chat-display-CHxh_MGC.js";import{t as de}from"./rotate-cw-BcRERxHa.js";import{o as k,r as A}from"./input-BDakodZ2.js";import{t as j}from"./settings-DlKTeV_0.js";import{t as M}from"./trash-2-BJG-7Qob.js";import{t as N}from"./copy-icon-DFhUGBjO.js";import{t as P}from"./strings-BHZPE0Mc.js";import{t as F}from"./uuid-k9DpjH68.js";import{n as I}from"./useAsyncData-DucTwMkf.js";import{Hn as L,Wr as R,Yr as z,ei as B,ua as V}from"./index-CcaMC2ZX.js";var H=f(),U=_(),W=e(t(),1),G=a,fe=d({type:s(`stream_chunk`),message_id:c(),content:u().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,r]=(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),O=()=>{b.current=null,S(null)},{data:k}=I(async()=>(await e.get_chat_history({})).messages,[]),A=e.value.length>0?e.value:k,{messages:j,sendMessage:P,setMessages:z,status:H,stop:G,error:K,regenerate:q,clearError:J,addToolApprovalResponse:Y}=ie({sendAutomaticallyWhen:({messages:e})=>re(e),transport:new ee({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
2
  `)})),n=F();O();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}),te({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:A,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=se({isAbort:!0,streamReason:b.current});if(O(),e!=null){let t=ce(e);p.debug(`Chat stream aborted`,{reason:e,finishReason:r}),S(t)}}else O();e.setValue(t)},onError:e=>{p.error(`An error occurred:`,e)}});m(e.host,R.TYPE,e=>{let t=fe.safeParse(e.detail.message);if(t.success){if(t.data.content&&t.data.message_id===y.current){let e=le(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=j.findIndex(e=>e.id===t);if(n!==-1){let r=j.filter(e=>e.id!==t);e.delete_chat_message({index:n}),z(r),e.setValue(r),r.length===0&&O()}},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`})},[j.length,h]);let $=f.current?.view,ve=()=>{if($){let e=$.state.doc.length;$.dispatch({changes:{from:0,to:e,insert:``}})}r(``)};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:()=>{z([]),e.setValue([]),e.delete_chat_history({}),J(),O()},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:[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)(ae,{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
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:ue({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)(N,{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)(M,{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)(B,{size:`small`})}),K&&(0,U.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 mb-4`,children:[(0,U.jsx)(L,{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 T(c):void 0;P({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=>{r(e),requestAnimationFrame(()=>{$?.focus(),n($)})}}),(0,U.jsx)(E,{className:`rounded-sm mr-2`,placeholder:Q,value:t,inputRef:f,maxHeight:e.maxHeight?`${e.maxHeight/2}px`:void 0,onChange:r,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
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)(oe,{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)(D,{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)(V,{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)(ne,{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: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)(i,{asChild:!0,children:(0,U.jsx)(w,{variant:`outline`,size:`sm`,className:`border-none shadow-none hover:bg-transparent`,children:(0,U.jsx)(j,{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:[P.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)(k,{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)(o,{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)(r,{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:i}=e,[a,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(``),u;t[0]===i?u=t[1]:(u=e=>{[...e.matchAll(/{{(\w+)}}/g)].length>0?(l(e),s(!0)):i(e)},t[0]=i,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]!==i||t[12]!==c?(g=(0,U.jsx)(o,{side:`right`,align:`end`,className:`min-w-80 px-2`,children:(0,U.jsx)(J,{prompt:c,onClose:h,onSelect:i})}),t[11]=i,t[12]=c,t[13]=g):g=t[13];let _;return t[14]!==a||t[15]!==m||t[16]!==g?(_=(0,U.jsxs)(r,{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)(A,{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};