@marimo-team/frontend 0.25.3-dev141 → 0.25.3-dev16
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.
- package/dist/assets/{CellStatus-BP2mavAq.js → CellStatus-DVOHpdeJ.js} +1 -1
- package/dist/assets/{ConnectedDataExplorerComponent-t8fH_TNc.js → ConnectedDataExplorerComponent-TprnxZeJ.js} +1 -1
- package/dist/assets/{ErrorBoundary-Gl5nCA8C.js → ErrorBoundary-CM13wrd8.js} +2 -2
- package/dist/assets/JsonOutput-Cx1iyibB.js +11 -0
- package/dist/assets/{LazyAnyLanguageCodeMirror-CKcCbG2G.js → LazyAnyLanguageCodeMirror-B4fCknq1.js} +2 -2
- package/dist/assets/MarimoErrorOutput-s_5GOX8k.js +10 -0
- package/dist/assets/{RenderHTML-BbOqmHy3.js → RenderHTML-DX6i99Op.js} +1 -1
- package/dist/assets/{RunButton-CK3LhnP5.js → RunButton-BKoh0zYG.js} +1 -1
- package/dist/assets/{add-cell-with-ai-8UBC0xwR.js → add-cell-with-ai-BpD_790A.js} +11 -11
- package/dist/assets/{add-connection-dialog-DXQnd6eB.js → add-connection-dialog-B1BXCjex.js} +2 -2
- package/dist/assets/{agent-panel-D7kMZLG-.js → agent-panel-CDFUc1uu.js} +5 -5
- package/dist/assets/ai-model-dropdown-i1vfGeVi.js +13 -0
- package/dist/assets/{any-language-editor-BLCAD3yx.js → any-language-editor-BdTWdMCI.js} +1 -1
- package/dist/assets/{app-config-button-BKEG4x9u.js → app-config-button-AdV-QDD7.js} +1 -1
- package/dist/assets/{blob-D5nfNHOo.js → blob-BG8yoQmx.js} +1 -1
- package/dist/assets/{cell-editor-ADVfycpN.js → cell-editor-BKJ06H5F.js} +9 -9
- package/dist/assets/cell-link-8Auigi8P.js +1 -0
- package/dist/assets/{cells-BRkCaSsh.js → cells-C6YGYGdi.js} +56 -56
- package/dist/assets/{chat-display-Dnagy4Nv.js → chat-display-DhgI2MS9.js} +1 -1
- package/dist/assets/{chat-panel-DQ6HkWEF.js → chat-panel-Cau71Ygr.js} +2 -2
- package/dist/assets/{chat-ui-Df8Vcj6n.js → chat-ui-C5ql1Up-.js} +1 -1
- package/dist/assets/code-visibility-BJImdpDi.js +1 -0
- package/dist/assets/coerce-DWjFeXOY.js +1 -0
- package/dist/assets/{column-preview-Cm2D6vyX.js → column-preview-BZ_iNhtJ.js} +1 -1
- package/dist/assets/{command-palette-DTSQ7gOC.js → command-palette-DDC3kBet.js} +1 -1
- package/dist/assets/{common-Cu6CDbuw.js → common-Sl3uthjg.js} +1 -1
- package/dist/assets/{components-CGw16R_N.js → components-3cou6Mka.js} +1 -1
- package/dist/assets/{components-CP_UoFtT.js → components-CskjK6xZ.js} +1 -1
- package/dist/assets/{components-CXfO-F47.js → components-YBmtV0p6.js} +1 -1
- package/dist/assets/{config-VPSq73n8.js → config-CA1V-wjh.js} +1 -1
- package/dist/assets/config-DRIpOKqh.js +1 -0
- package/dist/assets/config-Dy28fDwn.js +1 -0
- package/dist/assets/{datasource-Cq6x_5ML.js → datasource-DfbNb83e.js} +1 -1
- package/dist/assets/{dates-BbFQ2oE4.js → dates-CfmdTL6B.js} +1 -1
- package/dist/assets/{dependency-graph-panel--Kgtktcw.js → dependency-graph-panel-L5cBE5sl.js} +1 -1
- package/dist/assets/{documentation-panel-BHmbeznw.js → documentation-panel-D7S8JIc2.js} +1 -1
- package/dist/assets/{download-DCJXy66H.js → download-C03FOElq.js} +1 -1
- package/dist/assets/edit-page-D_Rg0gQO.js +9 -0
- package/dist/assets/{error-banner-Cd69vvyX.js → error-banner-COZ7SfYV.js} +1 -1
- package/dist/assets/{error-entries-Dk3VZ-OK.js → error-entries-CLnPDv7b.js} +1 -1
- package/dist/assets/{error-panel-BPRYmC5J.js → error-panel-D2xrYLue.js} +1 -1
- package/dist/assets/{errors-DCrsa1nH.js → errors-CNsgAw6m.js} +1 -1
- package/dist/assets/{feedback-button-Bik2-e33.js → feedback-button-DzPunIqU.js} +2 -2
- package/dist/assets/feedback-button-Kla7i5RT.js +1 -0
- package/dist/assets/{file-explorer-panel-BEEK5lcl.js → file-explorer-panel-Uk4_QIJQ.js} +1 -1
- package/dist/assets/{file-name-input-Cdc-TVqO.js → file-name-input-B4fRaQkI.js} +1 -1
- package/dist/assets/{floating-outline-XD9FAV-f.js → floating-outline-B5MaM1JS.js} +1 -1
- package/dist/assets/{gallery-page-Dm6mGwBi.js → gallery-page-BefvdsM7.js} +1 -1
- package/dist/assets/{glide-data-editor-J9CAb70d.js → glide-data-editor-C3eaYlXg.js} +1 -1
- package/dist/assets/{home-page-DMHnsRxm.js → home-page-hmvKlc1w.js} +1 -1
- package/dist/assets/{hooks-93IwHd2u.js → hooks-DzML9nez.js} +1 -1
- package/dist/assets/index-6b4mf8Ai.css +2 -0
- package/dist/assets/index-ptK1gxmo.js +30 -0
- package/dist/assets/{layout-DmcNEu3P.js → layout-Ck1RoL1B.js} +5 -5
- package/dist/assets/{logs-panel-ABM16htT.js → logs-panel-BRytaWaO.js} +1 -1
- package/dist/assets/{markdown-renderer-BG3sp2rs.js → markdown-renderer-DX0Xrrfy.js} +1 -1
- package/dist/assets/{mermaid-a3xYymTy.js → mermaid-C4EiVqcd.js} +1 -1
- package/dist/assets/{name-cell-input-BgEBmqyL.js → name-cell-input-DlpTvPLa.js} +1 -1
- package/dist/assets/{outline-panel-DCXQ3_F6.js → outline-panel-B2WIpz-1.js} +1 -1
- package/dist/assets/{packages-panel-BMGOmZkR.js → packages-panel-CI5ff9b-.js} +1 -1
- package/dist/assets/{panel-accordion-state-C1sdPp0m.js → panel-accordion-state-BqSH5ttk.js} +1 -1
- package/dist/assets/panels-BCcZ_yLK.js +107 -0
- package/dist/assets/{process-output-D0KGq04R.js → process-output-f3C3PD0Z.js} +1 -1
- package/dist/assets/{readonly-code-display-Do50PHI8.js → readonly-code-display-MnMEoYW5.js} +1 -1
- package/dist/assets/{readonly-python-code-DCSMIsTX.js → readonly-python-code-ggs4hAzC.js} +1 -1
- package/dist/assets/{renderShortcut-BkVJQ_Zh.js → renderShortcut-C1JwYcqW.js} +1 -1
- package/dist/assets/{reveal-component-ltaepAqw.js → reveal-component-PiV1eQk9.js} +1 -1
- package/dist/assets/run-page-AfZhtEh1.js +1 -0
- package/dist/assets/{runtime-details-state-CSPobEdR.js → runtime-details-state-CoL-p0MC.js} +1 -1
- package/dist/assets/{schemas-Dv42wLFq.js → schemas-ChRqMOTL.js} +1 -1
- package/dist/assets/{scratchpad-panel-Dwd6W5PE.js → scratchpad-panel-D2rWg4k8.js} +1 -1
- package/dist/assets/{secrets-panel-Bctbtkrp.js → secrets-panel-D7KN4tVs.js} +1 -1
- package/dist/assets/session-panel-CnANhcTo.js +1 -0
- package/dist/assets/{snippets-panel-Bh1oTw4m.js → snippets-panel-ClGHtEKQ.js} +1 -1
- package/dist/assets/state-CbjBtkdd.js +3 -0
- package/dist/assets/{state-XsPO8hNi.js → state-DtGB7xeJ.js} +1 -1
- package/dist/assets/{terminal-Ck_vK-34.js → terminal-wnSHYT8N.js} +1 -1
- package/dist/assets/{tracing-Di6pUmX8.js → tracing-Dz2rYOFL.js} +1 -1
- package/dist/assets/{tracing-panel-PeRXHD8_.js → tracing-panel-DqQY9V91.js} +2 -2
- package/dist/assets/{tree-actions-GM5E_bUs.js → tree-actions-DnUokmva.js} +1 -1
- package/dist/assets/{useAddCell-GR7eEQrT.js → useAddCell-IN24thff.js} +1 -1
- package/dist/assets/{useBoolean-BDD6_xQQ.js → useBoolean-d0Tty94N.js} +1 -1
- package/dist/assets/{useCellActionButton-B-9eG5z_.js → useCellActionButton-DmaFZ4oF.js} +1 -1
- package/dist/assets/{useDeleteCell-2_bMClHd.js → useDeleteCell-fQlM46Y2.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-k3C3M18S.js → useDependencyPanelTab-ImXYINm_.js} +1 -1
- package/dist/assets/{useInstallPackage-iX1eufdl.js → useInstallPackage-BW06eter.js} +1 -1
- package/dist/assets/{useNotebookActions-NHN6A-cN.js → useNotebookActions-DHt3s-ia.js} +1 -1
- package/dist/assets/{useRunCells-B2vUhREg.js → useRunCells-DSJPXE-j.js} +1 -1
- package/dist/assets/{useSplitCell-DEb03htp.js → useSplitCell-DQyMF5gd.js} +1 -1
- package/dist/assets/{useTheme-COhSHkCj.js → useTheme-n8Dj1zH7.js} +1 -1
- package/dist/assets/{vega-component-CnadTgoE.js → vega-component-IouMe13t.js} +1 -1
- package/dist/index.html +34 -35
- package/package.json +5 -2
- package/src/__tests__/fixtures/{pair-preview.ts → pair-config.ts} +3 -2
- package/src/__tests__/host-imports.test.ts +100 -0
- package/src/__tests__/mount.test.ts +28 -8
- package/src/components/data-table/__tests__/context-menu.test.ts +176 -0
- package/src/components/data-table/__tests__/date-filter-inputs.test.tsx +24 -1
- package/src/components/data-table/__tests__/export-actions.test.tsx +329 -6
- package/src/components/data-table/context-menu.tsx +125 -26
- package/src/components/data-table/date-filter-inputs.tsx +15 -42
- package/src/components/data-table/export-actions.tsx +192 -116
- package/src/components/data-table/schemas.ts +14 -36
- package/src/components/data-table/utils.ts +18 -0
- package/src/components/editor/Output.tsx +9 -2
- package/src/components/editor/actions/__tests__/pair-with-agent-commands.test.ts +80 -252
- package/src/components/editor/actions/__tests__/pair-with-agent-modal.test.tsx +186 -34
- package/src/components/editor/actions/pair-with-agent-commands.ts +42 -51
- package/src/components/editor/actions/pair-with-agent-modal.tsx +96 -36
- package/src/components/editor/chrome/panels/error-panel.tsx +1 -0
- package/src/components/editor/chrome/wrapper/__tests__/attachment-status.test.tsx +372 -0
- package/src/components/editor/chrome/wrapper/footer-item.tsx +32 -24
- package/src/components/editor/chrome/wrapper/footer-items/attachment-status.tsx +237 -0
- package/src/components/editor/chrome/wrapper/footer.tsx +2 -0
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +548 -0
- package/src/components/editor/errors/send-error-report-button.tsx +69 -0
- package/src/components/editor/output/MarimoErrorOutput.tsx +21 -5
- package/src/components/editor/output/MarimoTracebackOutput.tsx +35 -20
- package/src/components/editor/output/__tests__/ansi-reduce.test.ts +18 -0
- package/src/components/editor/output/ansi-reduce.ts +6 -0
- package/src/core/attachments/__tests__/toast.test.tsx +58 -0
- package/src/core/attachments/state.ts +21 -0
- package/src/core/attachments/toast.ts +15 -0
- package/src/core/cells/__tests__/cells.test.ts +52 -0
- package/src/core/cells/__tests__/error-report.test.ts +139 -0
- package/src/core/cells/__tests__/session.test.ts +50 -1
- package/src/core/cells/error-report.ts +63 -0
- package/src/core/cells/session.ts +28 -1
- package/src/core/config/pair.ts +5 -3
- package/src/core/edit-app.tsx +2 -2
- package/src/core/host/AGENTS.md +6 -0
- package/src/core/host/__tests__/events.test.ts +46 -0
- package/src/core/host/__tests__/notebook-client.test.ts +191 -0
- package/src/core/host/__tests__/protocol.test.ts +214 -0
- package/src/core/host/connection.ts +81 -0
- package/src/core/host/events.ts +60 -0
- package/src/core/host/notebook-client.ts +226 -0
- package/src/core/host/protocol.ts +1943 -0
- package/src/core/islands/__tests__/bootstrap.test.ts +26 -0
- package/src/core/islands/bootstrap.ts +1 -0
- package/src/core/run-app.tsx +2 -2
- package/src/core/runtime/__tests__/runtime.test.ts +55 -11
- package/src/core/runtime/runtime.ts +14 -1
- package/src/core/runtime/types.ts +2 -0
- package/src/core/websocket/__tests__/{useMarimoKernelConnection.test.ts → connection-state.test.ts} +15 -17
- package/src/core/websocket/__tests__/{useWebSocket.test.ts → createConnectionTransport.test.ts} +1 -1
- package/src/core/websocket/__tests__/useNotebookClient.hook.test.tsx +140 -0
- package/src/core/websocket/__tests__/{useMarimoKernelConnection.hook.test.tsx → useNotebookSession.hook.test.tsx} +352 -65
- package/src/core/websocket/connection-state.ts +70 -0
- package/src/core/websocket/transports/__tests__/sse.test.ts +1 -4
- package/src/core/websocket/transports/create.ts +31 -0
- package/src/core/websocket/transports/transport.ts +12 -23
- package/src/core/websocket/types.ts +9 -39
- package/src/core/websocket/useNotebookClient.ts +80 -0
- package/src/core/websocket/{useMarimoKernelConnection.tsx → useNotebookSession.tsx} +67 -225
- package/src/mount.tsx +7 -3
- package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +84 -0
- package/src/utils/__tests__/dates.test.ts +116 -0
- package/src/utils/dates.ts +94 -0
- package/dist/assets/JsonOutput-D6HIIsCb.js +0 -11
- package/dist/assets/MarimoErrorOutput-D60XkCny.js +0 -6
- package/dist/assets/ai-model-dropdown-B0z6-zhp.js +0 -5
- package/dist/assets/api-BeC_VSGv.js +0 -1
- package/dist/assets/cell-link-LSth_8hT.js +0 -1
- package/dist/assets/code-visibility-B-_GvwR5.js +0 -1
- package/dist/assets/coerce-CpE6kUdX.js +0 -1
- package/dist/assets/config-BOKzA3tF.js +0 -1
- package/dist/assets/config-DX8Y2WbJ.js +0 -1
- package/dist/assets/edit-page-ChcSgpke.js +0 -9
- package/dist/assets/feedback-button-B2gKC5cn.js +0 -1
- package/dist/assets/index-Bcdzex-3.css +0 -2
- package/dist/assets/index-s-M1OXjs.js +0 -29
- package/dist/assets/pair-CaQyK6En.js +0 -1
- package/dist/assets/panels-CxVG8-v2.js +0 -4
- package/dist/assets/run-page-DF3c5cDk.js +0 -1
- package/dist/assets/session-panel-VdDhEBa-.js +0 -1
- package/dist/assets/state-_Qai_QyX.js +0 -3
- package/src/core/websocket/useWebSocket.tsx +0 -88
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./loro_wasm_bg-C2Fqi8D-.js","./loro_wasm_bg-Ctp2cNI9.js","./rolldown-runtime-B0Z9INg1.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,f as r,l as i,o as a,r as o,s,t as c,u as l}from"./useEvent-Dfcbgjhg.js";import{t as u}from"./react-DVplv7_D.js";import{$i as d,Bn as f,Br as p,Bt as m,Ca as h,Ci as g,Co as _,Cr as v,D as y,Dr as b,Fr as x,H as S,I as C,Ir as w,K as T,Lr as E,Lt as D,Ni as O,Nn as ee,Nr as k,Pr as te,Qi as ne,Ri as re,Rr as A,Si as j,U as ie,Ur as M,V as N,Vn as P,W as ae,Wr as oe,Yn as se,Zn as ce,_i as le,_n as ue,_t as de,ai as fe,ar as pe,at as me,b as he,ba as ge,bi as _e,bt as ve,ca as ye,ci as be,cn as xe,cr as Se,d as Ce,dt as we,fi as Te,fn as Ee,fo as De,ft as Oe,ga as ke,gn as Ae,gt as je,h as Me,ha as Ne,ht as Pe,i as Fe,it as Ie,jo as Le,jr as Re,li as ze,lr as Be,mn as Ve,mt as He,ni as Ue,nr as We,or as Ge,ot as Ke,pi as qe,pt as Je,qa as Ye,ri as Xe,rr as Ze,sa as Qe,si as $e,sr as et,ti as tt,tr as nt,tt as rt,u as it,ui as at,un as ot,vn as st,vr as ct,vt as lt,wa as ut,wi as dt,xa as ft,xi as pt,xo as mt,yi as ht,za as gt,zr as F}from"./cells-
|
|
3
|
-
`).length-1}},Ea=class{cache=new Map;timeout;constructor(e){this.timeout=e}get(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>this.timeout?(this.cache.delete(e),null):t.result:null}set(e,t){if(t){for(let[e,t]of this.cache)Date.now()-t.timestamp>this.timeout&&this.cache.delete(e);if(this.cache.delete(e),this.cache.set(e,{result:t,timestamp:Date.now()}),this.cache.size>20){let e=this.cache.keys().next().value;e!==void 0&&this.cache.delete(e)}}}},Da=(e,t)=>Vr.fromClass(class{abortController=null;timer=null;cache;constructor(){this.cache=new Ea(t.cacheTimeout??1e3)}cancel(){this.timer!==null&&clearTimeout(this.timer),this.timer=null,this.abortController?.abort(),this.abortController=null}update(n){let r=n.transactions.some(e=>e.effects.some(e=>e.is(Ca)&&e.value.text===null));if(!n.docChanged&&!n.selectionSet&&!r&&!(n.focusChanged&&!n.view.hasFocus)||(this.cancel(),!n.docChanged||n.state.field(Sa).suggestion||!n.state.selection.main.empty||n.state.selection.ranges.length!==1||t.events?.beforeSuggestionFetch?.(n.view)===!1))return;let i=new AbortController;this.abortController=i;let a=n.state.doc,o=n.state.selection.main.head,s=JSON.stringify([a.toString(),o]),c=this.cache.get(s),l=async()=>{if(!i.signal.aborted)try{let r=c??await e(n.state,i.signal,n.view);if(i.signal.aborted||n.view.state.doc!==a||n.view.state.selection.main.head!==o||t.events?.shouldShowSuggestion?.(n.view,r)===!1)return;this.cache.set(s,r),n.view.dispatch({effects:Ca.of({text:r,doc:a,pos:o})})}catch(e){!i.signal.aborted&&e instanceof Error&&e.name!==`AbortError`&&console.error(`Suggestion fetch error:`,e)}};this.timer=setTimeout(l,c?0:t.delay??500)}destroy(){this.cancel()}}),Oa=Vr.fromClass(class{decorations;constructor(){this.decorations=L.none}update(e){let t=e.state.field(Sa)?.suggestion;if(!t){this.decorations=L.none;return}this.decorations=wa(e.view,t)}},{decorations:e=>e.decorations});function ka(e,t,n,r){return{...e.changeByRange(i=>{if(i===e.selection.main)return{changes:{from:n,to:r,insert:t},range:kr.cursor(n+t.length)};let a=r-n;return!i.empty||a&&e.sliceDoc(i.from-a,i.from)!==e.sliceDoc(n,r)?{range:i}:{changes:{from:i.from-a,to:i.from,insert:t},range:kr.cursor(i.from-a+t.length)}}),userEvent:`input.complete`}}var Aa=e=>{let t=e.state.field(Sa)?.suggestion;if(!t)return!1;let n=e.state.facet(Na);return e.dispatch({...ka(e.state,t,e.state.selection.main.head,e.state.selection.main.head)}),n.events?.onSuggestionAccepted?.(e,t),!0},ja=e=>{let t=e.state.field(Sa)?.suggestion;if(!t)return!1;let n=e.state.facet(Na);return e.dispatch({effects:Ca.of({text:null,doc:e.state.doc,pos:e.state.selection.main.head})}),n.events?.onSuggestionRejected?.(e,t),!0},Ma=hr.of([{key:`Tab`,run:Aa},{key:`Escape`,run:ja}]),Na=Sr.define({combine:e=>e.at(-1)});function Pa(e){let{includeKeymap:t=!0}=e;return[Sa,Na.of(e),Da(e.fetchFn,e),Oa,t?Ma:[]]}var Fa=R.baseTheme({".cm-ai-input-container":{display:`flex`,flexDirection:`column`,gap:`4px`,width:`min(calc(100% + 7px), 500px)`,padding:`5px 5px`,margin:`0 -6px`,backgroundColor:`light-dark(rgb(241, 243, 245), rgb(40, 40, 40))`},".cm-ai-input":{display:`block`,width:`100%`,padding:`3px 8px`,border:`2px solid rgb(51, 154, 240)`,borderRadius:`5px`,fontSize:`12px`},".cm-ai-help-info-button":{fontSize:`10px`,paddingLeft:`10px`,height:`18px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,display:`block`,marginRight:`auto`},".cm-ai-help-info-button:hover":{color:`light-dark(rgb(89, 97, 105), rgb(190, 190, 190))`},".cm-ai-generate-button":{background:`#0E639C`,border:`none`,padding:`2px 6px`,color:`#ffffff`,cursor:`pointer`,font:`inherit`,borderRadius:`4px`,"&:hover":{backgroundColor:`#1177bb`}},".cm-line.cm-ai-selection, .cm-line.cm-ai-selection.cm-active-line":{backgroundColor:`light-dark(color-mix(in srgb, rgb(223, 227, 232) 50%, transparent), color-mix(in srgb, rgb(50, 50, 50) 50%, transparent)) !important`},".cm-line:has(.cm-new-code-line)":{backgroundColor:`light-dark(color-mix(in srgb, rgb(183, 235, 143) 50%, transparent), color-mix(in srgb, rgb(40, 100, 40) 50%, transparent)) !important`},".cm-old-code-container":{backgroundColor:`light-dark(rgb(255, 205, 205), rgb(100, 40, 40))`,position:`relative`,display:`flex`,paddingTop:`0`,width:`100%`,alignItems:`center`},".cm-code-button":{position:`absolute`,right:`5px`,top:`50%`,transform:`translateY(-50%)`,background:`none`,border:`none`,cursor:`pointer`,fontSize:`16px`},".cm-floating-buttons":{fontFamily:`sans-serif`,position:`absolute`,top:`-20px`,left:`5px`,display:`flex`},".cm-floating-button":{fontFamily:`sans-serif`,padding:`2px 5px`,fontSize:`10px`,cursor:`pointer`,fontWeight:`700`},".cm-floating-accept":{backgroundColor:`light-dark(rgb(55, 125, 34), rgb(40, 80, 25))`,borderTopLeftRadius:`5px`,borderBottomLeftRadius:`5px`,color:`white`,filter:`brightness(90%)`,"&:hover":{filter:`brightness(100%)`}},".cm-floating-reject":{backgroundColor:`light-dark(rgb(220, 53, 69), rgb(180, 40, 50))`,color:`white`,borderTopRightRadius:`5px`,borderBottomRightRadius:`5px`,filter:`brightness(90%)`,"&:hover":{filter:`brightness(100%)`}},".hotkey":{display:`inline-block`,padding:`0 4px`,borderRadius:`3px`,backgroundColor:`rgba(255, 255, 255, 0.1)`,fontSize:`90%`},".cm-ai-loading-indicator":{fontStyle:`italic`,fontSize:`10px`,paddingLeft:`12px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,opacity:`0`,transition:`opacity 0.3s ease-in-out`,"&::after":{content:`""`,display:`inline-block`,animation:`ellipsis-pulse 1.5s steps(4, end) infinite`},"&:not(:empty)":{opacity:`1`}},".cm-ai-input:disabled":{opacity:`0.5`},"@keyframes ellipsis-pulse":{"0%":{content:`'.'`},"25%":{content:`'..'`},"50%":{content:`'...'`},"75%":{content:`''`}},".cm-ai-loading-container":{display:`flex`,alignItems:`center`,padding:`0 8px`},".cm-ai-cancel-button":{padding:`2px 8px`,fontSize:`10px`,borderRadius:`4px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,cursor:`pointer`,"&:hover":{background:`light-dark(rgb(223, 227, 232), rgb(50, 50, 50))`}},".hidden":{display:`none`}}),Ia={mac:`⌘`,windows:`Ctrl`,default:`Ctrl`};function La(){return navigator.platform.startsWith(`Mac`)?Ia.mac:navigator.platform.startsWith(`Win`)?Ia.windows:Ia.default}function Ra(e){return e.replace(`Mod`,La()).replace(`-`,` `).toUpperCase()}function B(e,t){let n=document.createElement(e);return n.className=t,n}function za(e){let t=e.state.facet(ca),n={...oa,...t.keymaps},r=e.state.facet(Ba),i=B(`div`,`cm-ai-tooltip`).appendChild(B(`div`,`cm-ai-tooltip-button`)),a=i.appendChild(document.createElement(`span`));a.textContent=`${r.label} `;let o=a.appendChild(document.createElement(`span`));return o.className=`hotkey`,o.textContent=Ra(n.showInput),i.querySelector(`span`)?.addEventListener(`mousedown`,e=>{e.stopPropagation(),e.button===0&&e.preventDefault()}),i.querySelector(`span`)?.addEventListener(`click`,t=>{t.preventDefault(),ya(e)}),i}var Ba=Sr.define({combine(e){return Fr(e,{render:za,hideOnBlur:!1,label:`Edit with AI`})}}),Va=Vr.fromClass(class{view;suppress;dom;mousedown=()=>{this.suppress=!0};mouseup=()=>{this.suppress=!1,this.display(this.view)};scroll=()=>{this.display(this.view)};windowScroll=()=>{this.display(this.view)};constructor(e){this.view=e;let t=e.state.facet(Ba);this.suppress=!1,document.addEventListener(`mousedown`,this.mousedown),document.addEventListener(`mouseup`,this.mouseup),e.scrollDOM.addEventListener(`scroll`,this.scroll),window.addEventListener(`scroll`,this.windowScroll,!0);let n=t.render(e);e.dom.appendChild(n),this.dom=n}update(e){this.display(e.view)}docViewUpdate(e){this.display(e)}display(e){if(e.state.field(ua).show){this.dom.style.display=`none`;return}if(e.state.facet(Ba).hideOnBlur&&!e.hasFocus){this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`);return}e.requestMeasure({read:this.#e})}#e=e=>{let t=e.state.selection.ranges.find(e=>!e.empty);if(t&&!this.suppress){let n=e.coordsAtPos(t.from),r=e.coordsAtPos(t.to);if(!n||!r)return;let i=e.dom.getBoundingClientRect(),a=e.dom.parentElement?.getBoundingClientRect(),o=e=>e.top>=i.top&&e.top<=i.bottom&&e.left>=i.left&&e.left<=i.right,s=e=>!a||e.top>=a.top&&e.top<=a.bottom&&e.left>=a.left&&e.left<=a.right,c=o(n)||o(r),l=s(n)||s(r);if(!c||!l){this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`);return}this.dom.style.display=`flex`,this.dom.setAttribute(`aria-hidden`,`false`);let u=this.dom.getBoundingClientRect(),d=o(n)?n:r,f=i.right-u.width,p=Math.min(d.left,f),m=d.top-u.height,h=a?a.y:-1/0;m<h&&(m=r.bottom),this.dom.style.left=`${p}px`,this.dom.style.top=`${m}px`,requestAnimationFrame(()=>{this.dom&&this.dom.setAttribute(`aria-hidden`,`false`)})}else this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`)};destroy(){document.removeEventListener(`mousedown`,this.mousedown),document.removeEventListener(`mouseup`,this.mouseup),this.view.scrollDOM.removeEventListener(`scroll`,this.scroll),window.removeEventListener(`scroll`,this.windowScroll,!0),this.dom.remove()}}),Ha=R.baseTheme({".cm-ai-tooltip-button":{userSelect:`none`,fontFamily:`system-ui, -apple-system, sans-serif`,position:`fixed`,display:`flex`,boxSizing:`border-box`,padding:`2px 6px`,borderRadius:`4px`,fontSize:`12px`,backgroundColor:`#0E639C`,color:`#ffffff`,border:`1px solid transparent`,boxShadow:`0 2px 4px rgba(0,0,0,0.1)`,zIndex:`999`,transition:`opacity 0.5s`,"&[aria-hidden='true']":{opacity:`0`},"&[aria-hidden='false']":{opacity:`1`},"& > span":{pointerEvents:`auto`,cursor:`pointer`,display:`inline-block`,padding:`2px`},"&:hover":{backgroundColor:`#1177bb`}}});function Ua(){return[Va,Ha]}var Wa=class extends Mr{oldCode;constructor(e){super(),this.oldCode=e}toDOM(e){let t=B(`div`,`cm-old-code-container`);t.setAttribute(`role`,`region`),t.setAttribute(`aria-label`,`Previous code version`);let n=B(`div`,`cm-old-code cm-line`);n.textContent=this.oldCode;let r=B(`div`,`cm-floating-buttons`),i=e.state.facet(ca),a={...oa,...i.keymaps},o=B(`button`,`cm-floating-button cm-floating-accept`);o.innerHTML=`<span class="hotkey">${Ra(a.acceptEdit)}</span> Accept`,o.setAttribute(`aria-label`,`Accept changes`),o.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e.focus(),ba(e)});let s=B(`button`,`cm-floating-button cm-floating-reject`);return s.innerHTML=`<span class="hotkey">${Ra(a.rejectEdit)}</span> Reject`,s.setAttribute(`aria-label`,`Reject changes`),s.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e.focus(),xa(e)}),r.append(o,s),t.append(n,r),t}updateDOM(e,t){return!0}},Ga=class extends Mr{complete;abortController=null;dom=null;input=null;loadingContainer=null;helpInfo=null;inputContainer=null;form=null;view=null;constructor(e){super(),this.complete=e}toDOM(e){if(this.dom)return this.dom;this.view=e;let t=e.state.field(pa),n=e.state.field(_a),r=B(`div`,`cm-ai-input-container`);this.inputContainer=r,this.dom=r;let i=B(`form`,`cm-ai-input-form`);this.form=i,i.setAttribute(`role`,`search`),i.setAttribute(`aria-label`,`AI editing instructions`),i.addEventListener(`submit`,e=>e.preventDefault());let a=B(`input`,`cm-ai-input`);this.input=a,i.append(a),a.placeholder=`Editing instructions...`,a.setAttribute(`aria-label`,`AI editing instructions`),a.setAttribute(`autocomplete`,`off`),a.setAttribute(`spellcheck`,`true`),a.value=t.inputValue;let o=B(`div`,`cm-ai-loading-container`);this.loadingContainer=o;let s=B(`div`,`cm-ai-loading-indicator`);s.setAttribute(`role`,`status`),s.setAttribute(`aria-live`,`polite`),s.textContent=`Generating`;let c=B(`button`,`cm-ai-cancel-button`);c.textContent=`Cancel`,c.setAttribute(`aria-label`,`Cancel code generation`),c.addEventListener(`click`,this.onCancel),o.append(c,s);let l=B(`div`,`cm-ai-help-info`);this.helpInfo=l;let u=l.appendChild(document.createElement(`button`));u.className=`cm-ai-help-info-button`,u.textContent=`Esc to close`,u.addEventListener(`click`,this.onCancel);let d=B(`button`,`cm-ai-generate-button`);d.textContent=`⏎ Generate`,d.setAttribute(`aria-label`,`Generate code`),d.addEventListener(`click`,this.handleSubmit),this.toggleLoading(n),t.shouldFocus&&requestAnimationFrame(()=>{a.value=t.inputValue,a.focus(),e.dispatch({effects:fa.of(!1)})}),f(a.value),a.addEventListener(`input`,m),a.addEventListener(`keydown`,this.onKeyDown);function f(e){l.replaceChildren(e?d:u)}let p=``;function m(){e.dispatch({effects:da.of(a.value)});let t=a.value.trim();t!==p&&(p=t,f(t))}return r}toggleLoading(e){this.inputContainer&&this.form&&this.loadingContainer&&this.helpInfo&&this.inputContainer?.replaceChildren(this.form,e?this.loadingContainer:this.helpInfo)}onKeyDown=async e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),await this.handleSubmit()):e.key===`Escape`&&this.onCancel()};onCancel=()=>{this.cleanup();let e=this.view;e&&(e.dispatch({effects:[la.of({show:!1,lineFrom:0,lineTo:0}),ga.of(!1)]}),e.focus())};handleSubmit=async e=>{let t=this.view;if(!t)return;let n=t.state.facet(ca);e?.stopPropagation();let r=t.state.field(ua),{input:i}=this;if(!i)return;let a=i.value.trim();if(!r.show||!a)return;let o=t.state.doc.line(r.lineFrom),s=t.state.doc.line(r.lineTo),c=o.from,l=s.to,u=t.state.sliceDoc(c,l),d=t.state.sliceDoc(0,c),f=t.state.sliceDoc(l);this.abortController=new AbortController,t.dispatch({effects:ga.of(!0)}),this.toggleLoading(!0);try{let e=await this.complete({prompt:a,selection:u,codeBefore:d,codeAfter:f,editorView:t,signal:this.abortController.signal});if(!t.state.field(ua).show)return;if(!e||typeof e!=`string`)throw Error(`Invalid completion result`);t.dispatch({changes:{from:c,to:l,insert:e},effects:[la.of({show:!1,lineFrom:0,lineTo:0}),ma.of({from:c,to:c+e.length,oldCode:u,newCode:e}),ga.of(!1)]})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;n.onError?.(e)}finally{this.cleanup(),this.toggleLoading(!1),t.focus()}};updateDOM(e,t){return this.dom=e,this.input=e.querySelector(`.cm-ai-input`),!0}cleanup(){this.abortController?.abort(),this.abortController=null,this.dom?.remove(),this.input?.remove(),this.dom=null,this.input=null}destroy(){this.cleanup()}};function Ka(e){if(!e.prompt)throw Error(`prompt function is required`);let t={...oa,...e.keymaps};return[ca.of(e),ua,pa,ha,_a,Ua(),Fa,hr.of([{key:t.showInput,run:ya}]),xr.highest([hr.of([{key:t.acceptEdit,run:ba},{key:t.rejectEdit,run:xa}])]),qa,Ja,Ya,Xa]}var qa=R.updateListener.of(e=>{let t=e.state.field(ua);if(!t.show||!e.docChanged)return;let{lineFrom:n,lineTo:r}=t,i=!1;e.changes.iterChanges((t,a,o,s)=>{let c=e.state.doc.lineAt(t).number;if(c<n){let t=e.state.doc.lineAt(s).number-e.state.doc.lineAt(o).number;n+=t,r+=t,i=!0}else if(c<=r){let t=e.state.doc.lineAt(s).number-e.state.doc.lineAt(o).number;r+=t,i=!0}}),i&&e.view.dispatch({effects:[la.of({show:!0,lineFrom:n,lineTo:r})]})}),Ja=R.decorations.of(e=>{let t=e.state.field(ha);return t?L.set([L.mark({class:`cm-new-code-line`}).range(t.from,t.to)]):L.none}),Ya=R.decorations.compute([ua],e=>{let t=e.field(ua),n=e.facet(ca),r=[];if(t.show){let i=t.lineFrom,a=t.lineTo;for(let t=i;t<=a;t++){let a=e.doc.line(t).from;r.push(L.line({class:`cm-ai-selection`}).range(a)),t===i&&r.push(L.widget({widget:new Ga(n.prompt),side:-1}).range(a))}}return L.set(r)}),Xa=dr.define({create(e){return L.none},update(e,t){let n=t.state.field(ha);return n?L.set([L.widget({widget:new Wa(n.oldCode),block:!0}).range(n.from)]):L.none},provide:e=>R.decorations.from(e)}),V=e(u(),1),H=Et(),Za=()=>({entries:new Map}),{valueAtom:Qa,useActions:$a}=ri(Za,{submit:(e,t)=>{let{cellIds:n,deleteCell:r,deleteManyCells:i,store:a}=t,o=a.get(he),s=a.get(tt),c=new Set(o.cellIds.inOrderIds.filter(e=>o.cellData[e].code.trim()===``)),l=new Map;for(let e of n){if(c.has(e)){l.set(e,{cellId:e,type:`simple`});continue}let t=o.cellRuntime[e],n=new Map;for(let t of Object.values(s)){let r=t.declaredBy.includes(e),i=t.usedBy.some(e=>!c.has(e));r&&i&&n.set(t.name,t.usedBy)}let r;t?.runElapsedTimeMs&&t.runElapsedTimeMs>2e3&&(r=t.runElapsedTimeMs),n.size===0&&r===void 0?l.set(e,{cellId:e,type:`simple`}):l.set(e,{cellId:e,type:`expensive`,executionDurationMs:r,defs:n})}let u=[...l.values()].every(e=>e.type===`simple`);return l.size>0&&u?(l.size===1?r({cellId:[...l.values()][0].cellId}):i({cellIds:[...l.values()].map(e=>e.cellId)}),Za()):{...e,entries:l}},clear:()=>Za()});function eo(){let e=n(),{submit:t,clear:r}=$a(),{entries:a}=i(Qa),o=$n(),s=Qn();return{submit:n=>{t({cellIds:n,deleteCell:o,deleteManyCells:s,store:e})},clear:r,get idle(){return a.size===0},get shouldConfirmDelete(){return a.size>1}}}function to(e){let t=(0,H.c)(16),n=i(Qa),r=$a(),a=Qn(),o;t[0]!==e||t[1]!==n.entries?(o=n.entries.get(e),t[0]=e,t[1]=n.entries,t[2]=o):o=t[2];let s=o;if(!s){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e={isPending:!1},t[3]=e):e=t[3],e}if(n.entries.size!==1){let e;return t[4]===s?e=t[5]:(e={isPending:!0,shouldConfirmDelete:!1,...s},t[4]=s,t[5]=e),e}let c;t[6]!==r||t[7]!==a||t[8]!==n.entries?(c=()=>{a({cellIds:[...n.entries.values()].map(no)}),r.clear()},t[6]=r,t[7]=a,t[8]=n.entries,t[9]=c):c=t[9];let l;t[10]===r?l=t[11]:(l=()=>r.clear(),t[10]=r,t[11]=l);let u;return t[12]!==s||t[13]!==c||t[14]!==l?(u={isPending:!0,...s,shouldConfirmDelete:!0,confirm:c,cancel:l},t[12]=s,t[13]=c,t[14]=l,t[15]=u):u=t[15],u}function no(e){return e.cellId}async function ro(e){if(!e.ok)throw Error(await e.text());if(!e.body)throw Error(`Failed to get response body`);let t=null,n=!1;if(await Mn({stream:En({stream:e.body,schema:Nn}).pipeThrough(new TransformStream({transform(e){if(!e.success)throw e.error;let r=e.value;if(On(r)&&r.type===Tn)t=Dn.parse(r.data).code;else if(r.type===`error`)throw Error(r.errorText);else r.type===`finish`&&(n=r.finishReason===`stop`)}})),onError:e=>{throw e}}),!n)throw Error(`AI completion ended before final validation`);if(t===null)throw Error(`AI completion returned no cell code`);return t}async function io(e){let t=`
|
|
2
|
+
import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,f as r,l as i,o as a,r as o,s,t as c,u as l}from"./useEvent-Dfcbgjhg.js";import{t as u}from"./react-DVplv7_D.js";import{$i as d,Bn as f,Br as p,Bt as m,Ca as h,Ci as g,Co as _,Cr as v,D as y,Dr as b,Fr as x,H as S,I as C,Ir as w,K as T,Lr as E,Lt as D,Ni as O,Nn as ee,Nr as k,Pr as te,Qi as ne,Ri as re,Rr as A,Si as j,U as ie,Ur as M,V as N,Vn as P,W as ae,Wr as oe,Yn as se,Zn as ce,_i as le,_n as ue,_t as de,ai as fe,ar as pe,at as me,b as he,ba as ge,bi as _e,bt as ve,ca as ye,ci as be,cn as xe,cr as Se,d as Ce,dt as we,fi as Te,fn as Ee,fo as De,ft as Oe,ga as ke,gn as Ae,gt as je,h as Me,ha as Ne,ht as Pe,i as Fe,it as Ie,jo as Le,jr as Re,li as ze,lr as Be,mn as Ve,mt as He,ni as Ue,nr as We,or as Ge,ot as Ke,pi as qe,pt as Je,qa as Ye,ri as Xe,rr as Ze,sa as Qe,si as $e,sr as et,ti as tt,tr as nt,tt as rt,u as it,ui as at,un as ot,vn as st,vr as ct,vt as lt,wa as ut,wi as dt,xa as ft,xi as pt,xo as mt,yi as ht,za as gt,zr as F}from"./cells-C6YGYGdi.js";import{t as _t}from"./react-dom-_LrxgvjW.js";import{C as vt,I as yt,M as bt,N as xt,O as St,R as Ct,S as wt,b as Tt}from"./schemas-ChRqMOTL.js";import{t as Et}from"./compiler-runtime-BrajqUja.js";import{t as Dt}from"./debounce-aFmHgJZY.js";import{E as Ot,_ as kt,c as At,g as jt,h as Mt,s as Nt}from"./config-CA1V-wjh.js";import{_ as Pt,c as Ft,g as It,m as Lt,t as Rt}from"./useEventListener-D9cftcHj.js";import{t as zt}from"./invariant-Ci2dTZ72.js";import{s as Bt}from"./config-DRIpOKqh.js";import{d as Vt,m as Ht,t as Ut}from"./session-DqoWmb7X.js";import{N as Wt,O as Gt,S as Kt,T as qt,_ as Jt,o as Yt,p as Xt,r as Zt}from"./config-Dy28fDwn.js";import{c as Qt}from"./state-C3oDoyFe.js";import{t as $t}from"./ErrorBoundary-CM13wrd8.js";import{t as en}from"./cn-ldLVeaqm.js";import{t as tn}from"./jsx-runtime-B74pBk57.js";import{Q as nn,Z as rn}from"./JsonOutput-Cx1iyibB.js";import{d as an}from"./select-DTBn5eTb.js";import{n as on}from"./download-C03FOElq.js";import{t as sn}from"./switch-CTaiAjrz.js";import{t as cn}from"./tooltip-C9TuY18o.js";import{r as ln,t as un}from"./button-COI-NGrx.js";import{t as dn}from"./createLucideIcon-DfJ2oMlA.js";import{i as fn,n as pn}from"./paths-bkIFVj8h.js";import{r as mn}from"./layout-Ck1RoL1B.js";import{A as hn,C as gn,D as _n,_ as vn,j as yn,t as bn,v as xn,y as Sn}from"./ai-model-dropdown-i1vfGeVi.js";import{r as Cn}from"./useNumberFormatter-D7O_26UI.js";import{t as wn}from"./circle-check-BCurAHEb.js";import{B as Tn,F as En,G as Dn,I as On,L as kn,M as An,R as jn,T as Mn,V as Nn,W as Pn,c as Fn,f as In,i as Ln,n as Rn,o as zn,r as Bn,s as Vn,w as Hn,z as Un}from"./add-cell-with-ai-BpD_790A.js";import{t as Wn}from"./database-zap-B_PMVg8T.js";import{r as Gn,t as Kn}from"./file-icons-CdJgUy-I.js";import{t as qn}from"./components-CskjK6xZ.js";import{b as Jn}from"./write-secret-modal-DzKAInL2.js";import{n as Yn}from"./spinner-DyNE-o8o.js";import{n as Xn,o as Zn,r as Qn}from"./readonly-python-code-ggs4hAzC.js";import{n as $n,t as er}from"./useDeleteCell-fQlM46Y2.js";import{t as tr}from"./save-Dgoim6QF.js";import{G as nr,I as rr,Ut as ir,Xt as ar,Yt as or,Zt as sr,tn as cr}from"./input-BoBxR50a.js";import{n as lr}from"./copy-D8O_CYCG.js";import{t as ur}from"./use-toast-Wu434mLr.js";import{t as dr}from"./preload-helper-uBIymjUX.js";import{$t as fr,Ct as pr,Dt as mr,E as hr,Et as gr,Ft as _r,Gt as vr,H as yr,I as br,It as xr,Jt as Sr,Kt as Cr,Ot as wr,P as Tr,Qt as I,St as Er,Ut as Dr,V as Or,Vt as kr,Wt as Ar,Xt as jr,_ as Mr,at as L,dt as Nr,gt as Pr,ht as Fr,in as Ir,jt as Lr,lt as Rr,m as zr,ot as Br,st as R,tn as Vr,ut as Hr,w as Ur,wt as Wr,zt as Gr}from"./dist-Cny7_yZb.js";import{C as Kr,E as qr,I as Jr,O as Yr,S as Xr,a as Zr,c as Qr,n as $r,r as ei,w as ti}from"./dist-DBMV4gqt.js";import{o as ni}from"./arrays-BqUx5USx.js";import{n as ri}from"./once-Haz_uxEL.js";import{t as ii}from"./createReducer-DgRODTW6.js";import{a as ai,c as oi,f as si,h as ci,i as li,l as ui,n as di,o as fi,t as pi}from"./dist-qhAY4L2r.js";import{r as mi}from"./strings-B2vv-ENv.js";import{r as hi,t as gi}from"./requests-lt0JK8Jt.js";import{t as _i}from"./badge-crT3E0Rm.js";import{a as vi}from"./dist-DusFODSa.js";import{r as yi}from"./useTheme-n8Dj1zH7.js";import{t as bi}from"./I18nProvider-Cg2I_s1_.js";import{i as xi}from"./numbers-Mk3-CcoU.js";import{n as Si}from"./useAsyncData-C7aJJz0Y.js";import{a as Ci}from"./useRunCells-DSJPXE-j.js";import{l as wi}from"./useInstallPackage-BW06eter.js";import{a as Ti}from"./errors-CNsgAw6m.js";import{t as z}from"./extends-CvVTau-c.js";import{t as Ei}from"./objectWithoutPropertiesLoose-Do6ywDBO.js";import{t as Di}from"./kbd-pdKBv96t.js";import{a as Oi,n as ki}from"./state-DtGB7xeJ.js";import{a as Ai,o as ji}from"./cell-link-8Auigi8P.js";import{a as Mi}from"./renderShortcut-C1JwYcqW.js";import{n as Ni,t as Pi}from"./icons-CiZ_8zS-.js";import{n as Fi}from"./esm-CI_o7NhW.js";import{t as Ii}from"./dist-AelfNxj6.js";import{t as Li}from"./skeleton-Cqh4O9g1.js";import{t as Ri}from"./requests-CgSY1X4a.js";import{n as zi}from"./formatting-BqrP-n49.js";import{t as Bi}from"./useSplitCell-DQyMF5gd.js";import{n as Vi,r as Hi,t as Ui}from"./panel-accordion-state-BqSH5ttk.js";import{Bo as Wi,Fo as Gi,Ho as Ki,Io as qi,Lo as Ji,No as Yi,Po as Xi,Ro as Zi,Uo as Qi,Vo as $i,ut as ea,zo as ta}from"./loro_wasm_bg-Ctp2cNI9.js";import{t as na}from"./ws-BXWY541V.js";import{t as ra}from"./Inputs-BsQm29hD.js";import{n as ia}from"./hooks-DzML9nez.js";var aa=dn(`file-pen`,[[`path`,{d:`M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34`,key:`o6klzx`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z`,key:`zhnas1`}]]),oa={showInput:`Mod-l`,acceptEdit:`Mod-y`,rejectEdit:`Mod-u`},sa=300,ca=Cr.define({combine:e=>Ir(e,{onError:console.error,inputDebounceTime:sa,keymaps:oa},{onError:(e,t)=>e&&t,inputDebounceTime:(e,t)=>e&&t,keymaps:(e,t)=>e&&t})}),la=I.define(),ua=fr.define({create(){return{show:!1,lineFrom:0,lineTo:0}},update(e,t){for(let e of t.effects)if(e.is(la))return e.value;return e}}),da=I.define(),fa=I.define(),pa=fr.define({create(){return{shouldFocus:!1,inputValue:``}},update(e,t){let n=e;for(let e of t.effects)e.is(da)&&(n={...n,inputValue:e.value}),e.is(fa)&&(n={...n,shouldFocus:e.value});return n}}),ma=I.define(),ha=fr.define({create(){return null},update(e,t){for(let e of t.effects)if(e.is(ma))return e.value;return e}}),ga=I.define(),_a=fr.define({create(){return!1},update(e,t){for(let e of t.effects)if(e.is(ga))return e.value;return e}}),va=1,ya=e=>{let{state:t}=e,n=t.selection.main;if(n.empty)return!1;let r=t.doc,i=r.lineAt(n.from),a=r.lineAt(n.to);if(t.sliceDoc(i.from,a.to).trim().length<va)return!1;let o=Math.max(1,Math.min(i.number,r.lines)),s=Math.max(1,Math.min(a.number,r.lines));return e.dispatch({effects:[la.of({show:!0,lineFrom:o,lineTo:s}),fa.of(!0),da.of(``)],selection:Ar.cursor(i.from)}),!0},ba=e=>e.state.field(ha)?(e.dispatch({effects:[ma.of(null),la.of({show:!1,lineFrom:0,lineTo:0}),fa.of(!1),da.of(``),ga.of(!1)]}),!0):!1,xa=e=>{let t=e.state.field(ha);return t?(e.dispatch({changes:{from:t.from,to:t.to,insert:t.oldCode},effects:[ma.of(null),la.of({show:!1,lineFrom:0,lineTo:0}),fa.of(!1),da.of(``),ga.of(!1)]}),!0):!1},Sa=fr.define({create(){return{suggestion:null}},update(e,t){let n=t.effects.find(e=>e.is(Ca));if(!t.docChanged&&!n&&!t.selection)return e;if(n&&t.state.doc===n.value.doc&&t.state.selection.main.head===n.value.pos)return{suggestion:n.value.text};if(e.suggestion&&t.docChanged&&t.startState.selection.ranges.length===1&&t.startState.selection.main.empty&&t.state.selection.ranges.length===1&&t.state.selection.main.empty){let n=t.startState.selection.main.head,r=``,i=0,a=!0;if(t.changes.iterChanges((e,t,o,s,c)=>{i++,a&&=e===n&&t===n,r=c.toString()}),a&&i===1&&r&&e.suggestion.startsWith(r)&&t.state.selection.main.head===n+r.length)return{suggestion:e.suggestion.slice(r.length)||null}}return{suggestion:null}}}),Ca=I.define();function wa(e,t){let n=e.state.selection.main.head,r=[],i=L.widget({widget:new Ta(t),side:1});return r.push(i.range(n)),L.set(r)}var Ta=class extends Nr{suggestion;constructor(e){super(),this.suggestion=e}toDOM(){let e=document.createElement(`span`);return e.style.opacity=`0.4`,e.className=`cm-inline-suggestion`,e.textContent=this.suggestion,e.setAttribute(`role`,`suggestion`),e.setAttribute(`aria-label`,`Suggestion: ${this.suggestion}`),e}get lineBreaks(){return this.suggestion.split(`
|
|
3
|
+
`).length-1}},Ea=class{cache=new Map;timeout;constructor(e){this.timeout=e}get(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>this.timeout?(this.cache.delete(e),null):t.result:null}set(e,t){if(t){for(let[e,t]of this.cache)Date.now()-t.timestamp>this.timeout&&this.cache.delete(e);if(this.cache.delete(e),this.cache.set(e,{result:t,timestamp:Date.now()}),this.cache.size>20){let e=this.cache.keys().next().value;e!==void 0&&this.cache.delete(e)}}}},Da=(e,t)=>Hr.fromClass(class{abortController=null;timer=null;cache;constructor(){this.cache=new Ea(t.cacheTimeout??1e3)}cancel(){this.timer!==null&&clearTimeout(this.timer),this.timer=null,this.abortController?.abort(),this.abortController=null}update(n){let r=n.transactions.some(e=>e.effects.some(e=>e.is(Ca)&&e.value.text===null));if(!n.docChanged&&!n.selectionSet&&!r&&!(n.focusChanged&&!n.view.hasFocus)||(this.cancel(),!n.docChanged||n.state.field(Sa).suggestion||!n.state.selection.main.empty||n.state.selection.ranges.length!==1||t.events?.beforeSuggestionFetch?.(n.view)===!1))return;let i=new AbortController;this.abortController=i;let a=n.state.doc,o=n.state.selection.main.head,s=JSON.stringify([a.toString(),o]),c=this.cache.get(s),l=async()=>{if(!i.signal.aborted)try{let r=c??await e(n.state,i.signal,n.view);if(i.signal.aborted||n.view.state.doc!==a||n.view.state.selection.main.head!==o||t.events?.shouldShowSuggestion?.(n.view,r)===!1)return;this.cache.set(s,r),n.view.dispatch({effects:Ca.of({text:r,doc:a,pos:o})})}catch(e){!i.signal.aborted&&e instanceof Error&&e.name!==`AbortError`&&console.error(`Suggestion fetch error:`,e)}};this.timer=setTimeout(l,c?0:t.delay??500)}destroy(){this.cancel()}}),Oa=Hr.fromClass(class{decorations;constructor(){this.decorations=L.none}update(e){let t=e.state.field(Sa)?.suggestion;if(!t){this.decorations=L.none;return}this.decorations=wa(e.view,t)}},{decorations:e=>e.decorations});function ka(e,t,n,r){return{...e.changeByRange(i=>{if(i===e.selection.main)return{changes:{from:n,to:r,insert:t},range:Ar.cursor(n+t.length)};let a=r-n;return!i.empty||a&&e.sliceDoc(i.from-a,i.from)!==e.sliceDoc(n,r)?{range:i}:{changes:{from:i.from-a,to:i.from,insert:t},range:Ar.cursor(i.from-a+t.length)}}),userEvent:`input.complete`}}var Aa=e=>{let t=e.state.field(Sa)?.suggestion;if(!t)return!1;let n=e.state.facet(Na);return e.dispatch({...ka(e.state,t,e.state.selection.main.head,e.state.selection.main.head)}),n.events?.onSuggestionAccepted?.(e,t),!0},ja=e=>{let t=e.state.field(Sa)?.suggestion;if(!t)return!1;let n=e.state.facet(Na);return e.dispatch({effects:Ca.of({text:null,doc:e.state.doc,pos:e.state.selection.main.head})}),n.events?.onSuggestionRejected?.(e,t),!0},Ma=gr.of([{key:`Tab`,run:Aa},{key:`Escape`,run:ja}]),Na=Cr.define({combine:e=>e.at(-1)});function Pa(e){let{includeKeymap:t=!0}=e;return[Sa,Na.of(e),Da(e.fetchFn,e),Oa,t?Ma:[]]}var Fa=R.baseTheme({".cm-ai-input-container":{display:`flex`,flexDirection:`column`,gap:`4px`,width:`min(calc(100% + 7px), 500px)`,padding:`5px 5px`,margin:`0 -6px`,backgroundColor:`light-dark(rgb(241, 243, 245), rgb(40, 40, 40))`},".cm-ai-input":{display:`block`,width:`100%`,padding:`3px 8px`,border:`2px solid rgb(51, 154, 240)`,borderRadius:`5px`,fontSize:`12px`},".cm-ai-help-info-button":{fontSize:`10px`,paddingLeft:`10px`,height:`18px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,display:`block`,marginRight:`auto`},".cm-ai-help-info-button:hover":{color:`light-dark(rgb(89, 97, 105), rgb(190, 190, 190))`},".cm-ai-generate-button":{background:`#0E639C`,border:`none`,padding:`2px 6px`,color:`#ffffff`,cursor:`pointer`,font:`inherit`,borderRadius:`4px`,"&:hover":{backgroundColor:`#1177bb`}},".cm-line.cm-ai-selection, .cm-line.cm-ai-selection.cm-active-line":{backgroundColor:`light-dark(color-mix(in srgb, rgb(223, 227, 232) 50%, transparent), color-mix(in srgb, rgb(50, 50, 50) 50%, transparent)) !important`},".cm-line:has(.cm-new-code-line)":{backgroundColor:`light-dark(color-mix(in srgb, rgb(183, 235, 143) 50%, transparent), color-mix(in srgb, rgb(40, 100, 40) 50%, transparent)) !important`},".cm-old-code-container":{backgroundColor:`light-dark(rgb(255, 205, 205), rgb(100, 40, 40))`,position:`relative`,display:`flex`,paddingTop:`0`,width:`100%`,alignItems:`center`},".cm-code-button":{position:`absolute`,right:`5px`,top:`50%`,transform:`translateY(-50%)`,background:`none`,border:`none`,cursor:`pointer`,fontSize:`16px`},".cm-floating-buttons":{fontFamily:`sans-serif`,position:`absolute`,top:`-20px`,left:`5px`,display:`flex`},".cm-floating-button":{fontFamily:`sans-serif`,padding:`2px 5px`,fontSize:`10px`,cursor:`pointer`,fontWeight:`700`},".cm-floating-accept":{backgroundColor:`light-dark(rgb(55, 125, 34), rgb(40, 80, 25))`,borderTopLeftRadius:`5px`,borderBottomLeftRadius:`5px`,color:`white`,filter:`brightness(90%)`,"&:hover":{filter:`brightness(100%)`}},".cm-floating-reject":{backgroundColor:`light-dark(rgb(220, 53, 69), rgb(180, 40, 50))`,color:`white`,borderTopRightRadius:`5px`,borderBottomRightRadius:`5px`,filter:`brightness(90%)`,"&:hover":{filter:`brightness(100%)`}},".hotkey":{display:`inline-block`,padding:`0 4px`,borderRadius:`3px`,backgroundColor:`rgba(255, 255, 255, 0.1)`,fontSize:`90%`},".cm-ai-loading-indicator":{fontStyle:`italic`,fontSize:`10px`,paddingLeft:`12px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,opacity:`0`,transition:`opacity 0.3s ease-in-out`,"&::after":{content:`""`,display:`inline-block`,animation:`ellipsis-pulse 1.5s steps(4, end) infinite`},"&:not(:empty)":{opacity:`1`}},".cm-ai-input:disabled":{opacity:`0.5`},"@keyframes ellipsis-pulse":{"0%":{content:`'.'`},"25%":{content:`'..'`},"50%":{content:`'...'`},"75%":{content:`''`}},".cm-ai-loading-container":{display:`flex`,alignItems:`center`,padding:`0 8px`},".cm-ai-cancel-button":{padding:`2px 8px`,fontSize:`10px`,borderRadius:`4px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,cursor:`pointer`,"&:hover":{background:`light-dark(rgb(223, 227, 232), rgb(50, 50, 50))`}},".hidden":{display:`none`}}),Ia={mac:`⌘`,windows:`Ctrl`,default:`Ctrl`};function La(){return navigator.platform.startsWith(`Mac`)?Ia.mac:navigator.platform.startsWith(`Win`)?Ia.windows:Ia.default}function Ra(e){return e.replace(`Mod`,La()).replace(`-`,` `).toUpperCase()}function B(e,t){let n=document.createElement(e);return n.className=t,n}function za(e){let t=e.state.facet(ca),n={...oa,...t.keymaps},r=e.state.facet(Ba),i=B(`div`,`cm-ai-tooltip`).appendChild(B(`div`,`cm-ai-tooltip-button`)),a=i.appendChild(document.createElement(`span`));a.textContent=`${r.label} `;let o=a.appendChild(document.createElement(`span`));return o.className=`hotkey`,o.textContent=Ra(n.showInput),i.querySelector(`span`)?.addEventListener(`mousedown`,e=>{e.stopPropagation(),e.button===0&&e.preventDefault()}),i.querySelector(`span`)?.addEventListener(`click`,t=>{t.preventDefault(),ya(e)}),i}var Ba=Cr.define({combine(e){return Ir(e,{render:za,hideOnBlur:!1,label:`Edit with AI`})}}),Va=Hr.fromClass(class{view;suppress;dom;mousedown=()=>{this.suppress=!0};mouseup=()=>{this.suppress=!1,this.display(this.view)};scroll=()=>{this.display(this.view)};windowScroll=()=>{this.display(this.view)};constructor(e){this.view=e;let t=e.state.facet(Ba);this.suppress=!1,document.addEventListener(`mousedown`,this.mousedown),document.addEventListener(`mouseup`,this.mouseup),e.scrollDOM.addEventListener(`scroll`,this.scroll),window.addEventListener(`scroll`,this.windowScroll,!0);let n=t.render(e);e.dom.appendChild(n),this.dom=n}update(e){this.display(e.view)}docViewUpdate(e){this.display(e)}display(e){if(e.state.field(ua).show){this.dom.style.display=`none`;return}if(e.state.facet(Ba).hideOnBlur&&!e.hasFocus){this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`);return}e.requestMeasure({read:this.#e})}#e=e=>{let t=e.state.selection.ranges.find(e=>!e.empty);if(t&&!this.suppress){let n=e.coordsAtPos(t.from),r=e.coordsAtPos(t.to);if(!n||!r)return;let i=e.dom.getBoundingClientRect(),a=e.dom.parentElement?.getBoundingClientRect(),o=e=>e.top>=i.top&&e.top<=i.bottom&&e.left>=i.left&&e.left<=i.right,s=e=>!a||e.top>=a.top&&e.top<=a.bottom&&e.left>=a.left&&e.left<=a.right,c=o(n)||o(r),l=s(n)||s(r);if(!c||!l){this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`);return}this.dom.style.display=`flex`,this.dom.setAttribute(`aria-hidden`,`false`);let u=this.dom.getBoundingClientRect(),d=o(n)?n:r,f=i.right-u.width,p=Math.min(d.left,f),m=d.top-u.height,h=a?a.y:-1/0;m<h&&(m=r.bottom),this.dom.style.left=`${p}px`,this.dom.style.top=`${m}px`,requestAnimationFrame(()=>{this.dom&&this.dom.setAttribute(`aria-hidden`,`false`)})}else this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`)};destroy(){document.removeEventListener(`mousedown`,this.mousedown),document.removeEventListener(`mouseup`,this.mouseup),this.view.scrollDOM.removeEventListener(`scroll`,this.scroll),window.removeEventListener(`scroll`,this.windowScroll,!0),this.dom.remove()}}),Ha=R.baseTheme({".cm-ai-tooltip-button":{userSelect:`none`,fontFamily:`system-ui, -apple-system, sans-serif`,position:`fixed`,display:`flex`,boxSizing:`border-box`,padding:`2px 6px`,borderRadius:`4px`,fontSize:`12px`,backgroundColor:`#0E639C`,color:`#ffffff`,border:`1px solid transparent`,boxShadow:`0 2px 4px rgba(0,0,0,0.1)`,zIndex:`999`,transition:`opacity 0.5s`,"&[aria-hidden='true']":{opacity:`0`},"&[aria-hidden='false']":{opacity:`1`},"& > span":{pointerEvents:`auto`,cursor:`pointer`,display:`inline-block`,padding:`2px`},"&:hover":{backgroundColor:`#1177bb`}}});function Ua(){return[Va,Ha]}var Wa=class extends Nr{oldCode;constructor(e){super(),this.oldCode=e}toDOM(e){let t=B(`div`,`cm-old-code-container`);t.setAttribute(`role`,`region`),t.setAttribute(`aria-label`,`Previous code version`);let n=B(`div`,`cm-old-code cm-line`);n.textContent=this.oldCode;let r=B(`div`,`cm-floating-buttons`),i=e.state.facet(ca),a={...oa,...i.keymaps},o=B(`button`,`cm-floating-button cm-floating-accept`);o.innerHTML=`<span class="hotkey">${Ra(a.acceptEdit)}</span> Accept`,o.setAttribute(`aria-label`,`Accept changes`),o.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e.focus(),ba(e)});let s=B(`button`,`cm-floating-button cm-floating-reject`);return s.innerHTML=`<span class="hotkey">${Ra(a.rejectEdit)}</span> Reject`,s.setAttribute(`aria-label`,`Reject changes`),s.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e.focus(),xa(e)}),r.append(o,s),t.append(n,r),t}updateDOM(e,t){return!0}},Ga=class extends Nr{complete;abortController=null;dom=null;input=null;loadingContainer=null;helpInfo=null;inputContainer=null;form=null;view=null;constructor(e){super(),this.complete=e}toDOM(e){if(this.dom)return this.dom;this.view=e;let t=e.state.field(pa),n=e.state.field(_a),r=B(`div`,`cm-ai-input-container`);this.inputContainer=r,this.dom=r;let i=B(`form`,`cm-ai-input-form`);this.form=i,i.setAttribute(`role`,`search`),i.setAttribute(`aria-label`,`AI editing instructions`),i.addEventListener(`submit`,e=>e.preventDefault());let a=B(`input`,`cm-ai-input`);this.input=a,i.append(a),a.placeholder=`Editing instructions...`,a.setAttribute(`aria-label`,`AI editing instructions`),a.setAttribute(`autocomplete`,`off`),a.setAttribute(`spellcheck`,`true`),a.value=t.inputValue;let o=B(`div`,`cm-ai-loading-container`);this.loadingContainer=o;let s=B(`div`,`cm-ai-loading-indicator`);s.setAttribute(`role`,`status`),s.setAttribute(`aria-live`,`polite`),s.textContent=`Generating`;let c=B(`button`,`cm-ai-cancel-button`);c.textContent=`Cancel`,c.setAttribute(`aria-label`,`Cancel code generation`),c.addEventListener(`click`,this.onCancel),o.append(c,s);let l=B(`div`,`cm-ai-help-info`);this.helpInfo=l;let u=l.appendChild(document.createElement(`button`));u.className=`cm-ai-help-info-button`,u.textContent=`Esc to close`,u.addEventListener(`click`,this.onCancel);let d=B(`button`,`cm-ai-generate-button`);d.textContent=`⏎ Generate`,d.setAttribute(`aria-label`,`Generate code`),d.addEventListener(`click`,this.handleSubmit),this.toggleLoading(n),t.shouldFocus&&requestAnimationFrame(()=>{a.value=t.inputValue,a.focus(),e.dispatch({effects:fa.of(!1)})}),f(a.value),a.addEventListener(`input`,m),a.addEventListener(`keydown`,this.onKeyDown);function f(e){l.replaceChildren(e?d:u)}let p=``;function m(){e.dispatch({effects:da.of(a.value)});let t=a.value.trim();t!==p&&(p=t,f(t))}return r}toggleLoading(e){this.inputContainer&&this.form&&this.loadingContainer&&this.helpInfo&&this.inputContainer?.replaceChildren(this.form,e?this.loadingContainer:this.helpInfo)}onKeyDown=async e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),await this.handleSubmit()):e.key===`Escape`&&this.onCancel()};onCancel=()=>{this.cleanup();let e=this.view;e&&(e.dispatch({effects:[la.of({show:!1,lineFrom:0,lineTo:0}),ga.of(!1)]}),e.focus())};handleSubmit=async e=>{let t=this.view;if(!t)return;let n=t.state.facet(ca);e?.stopPropagation();let r=t.state.field(ua),{input:i}=this;if(!i)return;let a=i.value.trim();if(!r.show||!a)return;let o=t.state.doc.line(r.lineFrom),s=t.state.doc.line(r.lineTo),c=o.from,l=s.to,u=t.state.sliceDoc(c,l),d=t.state.sliceDoc(0,c),f=t.state.sliceDoc(l);this.abortController=new AbortController,t.dispatch({effects:ga.of(!0)}),this.toggleLoading(!0);try{let e=await this.complete({prompt:a,selection:u,codeBefore:d,codeAfter:f,editorView:t,signal:this.abortController.signal});if(!t.state.field(ua).show)return;if(!e||typeof e!=`string`)throw Error(`Invalid completion result`);t.dispatch({changes:{from:c,to:l,insert:e},effects:[la.of({show:!1,lineFrom:0,lineTo:0}),ma.of({from:c,to:c+e.length,oldCode:u,newCode:e}),ga.of(!1)]})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;n.onError?.(e)}finally{this.cleanup(),this.toggleLoading(!1),t.focus()}};updateDOM(e,t){return this.dom=e,this.input=e.querySelector(`.cm-ai-input`),!0}cleanup(){this.abortController?.abort(),this.abortController=null,this.dom?.remove(),this.input?.remove(),this.dom=null,this.input=null}destroy(){this.cleanup()}};function Ka(e){if(!e.prompt)throw Error(`prompt function is required`);let t={...oa,...e.keymaps};return[ca.of(e),ua,pa,ha,_a,Ua(),Fa,gr.of([{key:t.showInput,run:ya}]),Sr.highest([gr.of([{key:t.acceptEdit,run:ba},{key:t.rejectEdit,run:xa}])]),qa,Ja,Ya,Xa]}var qa=R.updateListener.of(e=>{let t=e.state.field(ua);if(!t.show||!e.docChanged)return;let{lineFrom:n,lineTo:r}=t,i=!1;e.changes.iterChanges((t,a,o,s)=>{let c=e.state.doc.lineAt(t).number;if(c<n){let t=e.state.doc.lineAt(s).number-e.state.doc.lineAt(o).number;n+=t,r+=t,i=!0}else if(c<=r){let t=e.state.doc.lineAt(s).number-e.state.doc.lineAt(o).number;r+=t,i=!0}}),i&&e.view.dispatch({effects:[la.of({show:!0,lineFrom:n,lineTo:r})]})}),Ja=R.decorations.of(e=>{let t=e.state.field(ha);return t?L.set([L.mark({class:`cm-new-code-line`}).range(t.from,t.to)]):L.none}),Ya=R.decorations.compute([ua],e=>{let t=e.field(ua),n=e.facet(ca),r=[];if(t.show){let i=t.lineFrom,a=t.lineTo;for(let t=i;t<=a;t++){let a=e.doc.line(t).from;r.push(L.line({class:`cm-ai-selection`}).range(a)),t===i&&r.push(L.widget({widget:new Ga(n.prompt),side:-1}).range(a))}}return L.set(r)}),Xa=fr.define({create(e){return L.none},update(e,t){let n=t.state.field(ha);return n?L.set([L.widget({widget:new Wa(n.oldCode),block:!0}).range(n.from)]):L.none},provide:e=>R.decorations.from(e)}),V=e(u(),1),H=Et(),Za=()=>({entries:new Map}),{valueAtom:Qa,useActions:$a}=ii(Za,{submit:(e,t)=>{let{cellIds:n,deleteCell:r,deleteManyCells:i,store:a}=t,o=a.get(he),s=a.get(tt),c=new Set(o.cellIds.inOrderIds.filter(e=>o.cellData[e].code.trim()===``)),l=new Map;for(let e of n){if(c.has(e)){l.set(e,{cellId:e,type:`simple`});continue}let t=o.cellRuntime[e],n=new Map;for(let t of Object.values(s)){let r=t.declaredBy.includes(e),i=t.usedBy.some(e=>!c.has(e));r&&i&&n.set(t.name,t.usedBy)}let r;t?.runElapsedTimeMs&&t.runElapsedTimeMs>2e3&&(r=t.runElapsedTimeMs),n.size===0&&r===void 0?l.set(e,{cellId:e,type:`simple`}):l.set(e,{cellId:e,type:`expensive`,executionDurationMs:r,defs:n})}let u=[...l.values()].every(e=>e.type===`simple`);return l.size>0&&u?(l.size===1?r({cellId:[...l.values()][0].cellId}):i({cellIds:[...l.values()].map(e=>e.cellId)}),Za()):{...e,entries:l}},clear:()=>Za()});function eo(){let e=n(),{submit:t,clear:r}=$a(),{entries:a}=i(Qa),o=er(),s=$n();return{submit:n=>{t({cellIds:n,deleteCell:o,deleteManyCells:s,store:e})},clear:r,get idle(){return a.size===0},get shouldConfirmDelete(){return a.size>1}}}function to(e){let t=(0,H.c)(16),n=i(Qa),r=$a(),a=$n(),o;t[0]!==e||t[1]!==n.entries?(o=n.entries.get(e),t[0]=e,t[1]=n.entries,t[2]=o):o=t[2];let s=o;if(!s){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e={isPending:!1},t[3]=e):e=t[3],e}if(n.entries.size!==1){let e;return t[4]===s?e=t[5]:(e={isPending:!0,shouldConfirmDelete:!1,...s},t[4]=s,t[5]=e),e}let c;t[6]!==r||t[7]!==a||t[8]!==n.entries?(c=()=>{a({cellIds:[...n.entries.values()].map(no)}),r.clear()},t[6]=r,t[7]=a,t[8]=n.entries,t[9]=c):c=t[9];let l;t[10]===r?l=t[11]:(l=()=>r.clear(),t[10]=r,t[11]=l);let u;return t[12]!==s||t[13]!==c||t[14]!==l?(u={isPending:!0,...s,shouldConfirmDelete:!0,confirm:c,cancel:l},t[12]=s,t[13]=c,t[14]=l,t[15]=u):u=t[15],u}function no(e){return e.cellId}async function ro(e){if(!e.ok)throw Error(await e.text());if(!e.body)throw Error(`Failed to get response body`);let t=null,n=!1;if(await Nn({stream:Dn({stream:e.body,schema:Pn}).pipeThrough(new TransformStream({transform(e){if(!e.success)throw e.error;let r=e.value;if(kn(r)&&r.type===En)t=On.parse(r.data).code;else if(r.type===`error`)throw Error(r.errorText);else r.type===`finish`&&(n=r.finishReason===`stop`)}})),onError:e=>{throw e}}),!n)throw Error(`AI completion ended before final validation`);if(t===null)throw Error(`AI completion returned no cell code`);return t}async function io(e){let t=`
|
|
4
4
|
${e.codeBefore}
|
|
5
5
|
<rewrite_this>
|
|
6
6
|
${e.selection}
|
|
7
7
|
</rewrite_this>
|
|
8
8
|
${e.codeAfter}
|
|
9
|
-
`.trim(),n=Yt();await Gt();let r=await fetch(n.getAiURL(`completion`).toString(),{method:`POST`,headers:n.headers(),body:JSON.stringify({prompt:e.prompt,code:t,selectedText:e.selection,includeOtherCode:``,language:e.language})}),i=e.selection.match(/^\s*/)?.[0]||``,a=await ro(r);return a.startsWith(i)||(a=i+a),a}function ao(e){switch(e){case`table`:case`connection`:oe(`variables`),Ui(Hi,`datasources`);return;case`bucket`:oe(`files`),Ui(Vi,`remote-storage`);return;case`cache`:oe(`cache`);return;default:pi(e)}}function oo(e){let{state:t,names:n}=e;if(n.size===0)return[];let r=vr(t);if(!r||w(r))return[];let i=new Map,a=e=>{if(e.name===F.VariableName){let r=t.doc.sliceString(e.from,e.to);n.has(r)&&!i.has(r)&&i.set(r,{from:e.from,to:e.to,name:r});return}if(e.name===F.TupleExpression||e.name===F.ArrayExpression||e.name===F.ParenthesizedExpression)for(let t=e.firstChild;t;t=t.nextSibling)a(t)},o=e=>{let t=-1;for(let n=e.firstChild;n;n=n.nextSibling)n.name===F.AssignOp&&(t=n.from);if(t!==-1)for(let n=e.firstChild;n&&n.from<t;n=n.nextSibling)a(n)},s=e=>{if(!p.has(e.name)){if(e.name===F.AssignStatement){o(e);return}for(let t=e.firstChild;t;t=t.nextSibling)s(t)}};return s(r.topNode),[...i.values()]}var so=/\bmo\.(?:persistent_cache|cache)\b/g;function co(e){let t=e.match(/^[A-Za-z]*("""|'''|"|')([\s\S]*)\1$/);return t?t[2]:e}function lo(e,t){if(!e)return null;let n=e=>e?.name===`,`||e?.name===`)`,r=null;for(let i=e.firstChild;i;i=i.nextSibling)if(i.name!==`(`&&i.name!==`)`&&i.name!==`,`&&(r??=i,i.name===F.VariableName&&t(i)===`name`&&i.nextSibling?.name===F.AssignOp)){let e=i.nextSibling.nextSibling;if(e?.name===F.String&&n(e.nextSibling))return co(t(e))}return r&&r.name===F.String&&n(r.nextSibling)?co(t(r)):null}function uo(e,t,n,r){let i=t=>e.doc.sliceString(t.from,t.to),a=t.resolveInner(n,1),o=null,s=null,c=r,l=null;for(let e=a.parent;e&&e.from===n;e=e.parent)if(e.name===F.CallExpression){l=e;break}if(l){c=l.to,s=l.getChild(F.ArgList);let e=l.parent;if(e?.name===F.AssignStatement){let t=e.getChild(F.VariableName);o=t&&t.from<l.from?i(t):null}else if(e?.name===F.WithStatement){let t=e.firstChild;for(;t;){if(t.from<l.to||t.name===A.As){t=t.nextSibling;continue}t.name===F.VariableName&&(o=i(t));break}}}else if(a.parent?.name===F.Decorator){let e=a.parent,t=e.getChild(F.ArgList);t?.from===r&&(s=t,c=t.to);let n=(e.parent?.getChild(F.FunctionDefinition))?.getChild(F.VariableName);o=n?i(n):null}let u=lo(s,i);return{from:n,to:c,boundName:o,cacheName:u}}function fo(e,t,n){let r=t.resolveInner(n,1);return!E.has(r.name)&&r.name===F.VariableName&&e.doc.sliceString(r.from,r.to)===`mo`}function po(e){let t=vr(e);return!t||w(t)?[]:[...e.doc.toString().matchAll(so)].filter(n=>fo(e,t,n.index??0)).map(n=>{let r=n.index??0;return uo(e,t,r,r+n[0].length)})}function mo(e,t,n){let r=e.get(t);r!==void 0&&r!==n&&It.error(`[code-lens] "${t}" is claimed by both a ${r} and a ${n} entity; keeping ${n}`),e.set(t,n)}var ho=r(e=>{let t=new Map;for(let n of e(re))n.variable_name&&mo(t,n.variable_name,`table`);for(let n of e(O).keys())ne.has(n)||mo(t,n,`connection`);for(let n of e(ve))mo(t,n.name,`bucket`);return t}),go=r(e=>{let t=e(ho),n=e(tt),r=new Map,i=new Map;for(let[e,a]of t){let t=n[e];if(t==null){i.set(e,a);continue}for(let n of t.declaredBy){let t=r.get(n);t||(t=new Map,r.set(n,t)),t.set(e,a)}}return{byCell:r,pending:i}});function _o(e){let{byCell:t,pending:n}=o.get(go),r=new Map(t.get(e));for(let[e,t]of n)r.has(e)||r.set(e,t);return r}var vo=e=>`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${e}</svg>`,yo={table:vo(`<path d="M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18"/>`),connection:vo(`<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 21 19V5"/><path d="M3 12A9 3 0 0 0 21 12"/>`),bucket:vo(`<line x1="22" x2="2" y1="12" y2="12"/><path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/><line x1="6" x2="6.01" y1="16" y2="16"/><line x1="10" x2="10.01" y1="16" y2="16"/>`),cache:vo(`<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 15 21.84"/><path d="M21 5V8"/><path d="M21 12L18 17H22L19 22"/><path d="M3 12A9 3 0 0 0 14.59 14.87"/>`)},bo={table:`Open in data sources`,connection:`Open in data sources`,bucket:`Open in remote storage`,cache:`Open cache panel`},xo=e(_t(),1),So=e(Le(),1),U=en();function Co(e,t){let n=(0,So.createRoot)(e);return(0,xo.flushSync)(()=>{n.render((0,U.jsx)(s,{store:o,children:(0,U.jsx)(wo,{spec:t})}))}),()=>queueMicrotask(()=>n.unmount())}var wo=e=>{let t=(0,H.c)(9),{spec:n}=e;switch(n.kind){case`table`:{let e;return t[0]===n.name?e=t[1]:(e=(0,U.jsx)(To,{name:n.name}),t[0]=n.name,t[1]=e),e}case`connection`:{let e;return t[2]===n.name?e=t[3]:(e=(0,U.jsx)(Eo,{name:n.name}),t[2]=n.name,t[3]=e),e}case`bucket`:{let e;return t[4]===n.name?e=t[5]:(e=(0,U.jsx)(Do,{name:n.name}),t[4]=n.name,t[5]=e),e}case`cache`:{let e=n.cache?.boundName??null,r=n.cache?.cacheName??null,i;return t[6]!==e||t[7]!==r?(i=(0,U.jsx)(Mo,{boundName:e,cacheName:r}),t[6]=e,t[7]=r,t[8]=i):i=t[8],i}default:pi(n.kind)}},To=e=>{let t=(0,H.c)(5),{name:n}=e,r=i(re),a;if(t[0]!==n||t[1]!==r){let e;t[3]===n?e=t[4]:(e=e=>e.variable_name===n,t[3]=n,t[4]=e);let i=r.find(e);a=i?dt(i):g(`table`),t[0]=n,t[1]=r,t[2]=a}else a=t[2];return a},Eo=e=>{let t=(0,H.c)(5),{name:n}=e,r=i(O),a,o;if(t[0]!==r||t[1]!==n){o=Symbol.for(`react.early_return_sentinel`);bb0:{let e=r.get(n);if(!e){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=g(`database`),t[4]=e):e=t[4],o=e;break bb0}a=j(e)}t[0]=r,t[1]=n,t[2]=a,t[3]=o}else a=t[2],o=t[3];return o===Symbol.for(`react.early_return_sentinel`)?a:o},Do=e=>{let t=(0,H.c)(27),{name:n}=e,r=i(ve),a;if(t[0]!==n||t[1]!==r){let e;t[3]===n?e=t[4]:(e=e=>e.name===n,t[3]=n,t[4]=e),a=r.find(e),t[0]=n,t[1]=r,t[2]=a}else a=t[2];let o=a;if(!o){let e;return t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,U.jsx)(`div`,{className:ht,children:(0,U.jsx)(`span`,{className:`text-xs text-(--slate-11)`,children:`No storage information available.`})}),t[5]=e):e=t[5],e}let s;t[6]===o.protocol?s=t[7]:(s=(0,U.jsx)(Kn,{protocol:o.protocol,className:`w-4 h-4`}),t[6]=o.protocol,t[7]=s);let c;t[8]===o.protocol?c=t[9]:(c=(0,U.jsx)(gi,{variant:`outline`,className:`text-xs`,children:o.protocol}),t[8]=o.protocol,t[9]=c);let l;t[10]!==o.displayName||t[11]!==s||t[12]!==c?(l=(0,U.jsx)(pt,{icon:s,title:o.displayName,badge:c}),t[10]=o.displayName,t[11]=s,t[12]=c,t[13]=l):l=t[13];let u;t[14]===o.name?u=t[15]:(u=(0,U.jsx)(_e,{label:`Variable`,value:(0,U.jsx)(`code`,{className:`text-xs bg-(--slate-4) px-1 rounded`,children:o.name})}),t[14]=o.name,t[15]=u);let d=o.rootPath||`(root)`,f;t[16]===d?f=t[17]:(f=(0,U.jsx)(_e,{label:`Root`,value:(0,U.jsx)(`code`,{className:`text-xs bg-(--slate-4) px-1 rounded`,children:d})}),t[16]=d,t[17]=f);let p;t[18]===o.backendType?p=t[19]:(p=(0,U.jsx)(_e,{label:`Backend`,value:(0,U.jsx)(`span`,{className:`font-medium`,children:o.backendType})}),t[18]=o.backendType,t[19]=p);let m;t[20]!==u||t[21]!==f||t[22]!==p?(m=(0,U.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[u,f,p]}),t[20]=u,t[21]=f,t[22]=p,t[23]=m):m=t[23];let h;return t[24]!==l||t[25]!==m?(h=(0,U.jsxs)(`div`,{className:ht,children:[l,m]}),t[24]=l,t[25]=m,t[26]=h):h=t[26],h},Oo=/\bhits=(\d+) misses=(\d+)/,ko=null,Ao=5e3;function jo(){let e=Date.now();ko!=null&&e-ko<Ao||(ko=e,hi().getCacheInfo().catch(()=>{ko=null}))}var Mo=e=>{let t=(0,H.c)(16),{boundName:n,cacheName:r}=e,{locale:a}=yi(),o=i(tt),s=i(Ri),c=n?o[n]:void 0,l;t[0]===c?l=t[1]:(l=c?.dataType?.startsWith(`_cache_call`)?c.value?.match(Oo):void 0,t[0]=c,t[1]=l);let u=l,d=!!u,f,p;t[2]===d?(f=t[3],p=t[4]):(f=()=>{d||jo()},p=[d],t[2]=d,t[3]=f,t[4]=p),(0,V.useEffect)(f,p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,U.jsx)(Un,{className:`w-4 h-4 text-(--amber-9)`}),t[5]=m):m=t[5];let h=r??n??`Cache`,g;t[6]===h?g=t[7]:(g=(0,U.jsx)(pt,{icon:m,title:h}),t[6]=h,t[7]=g);let _;t[8]!==s||t[9]!==a||t[10]!==u?(_=u?(0,U.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,U.jsx)(_e,{label:`Hits`,value:(0,U.jsx)(`span`,{className:`font-medium`,children:bi(Number(u[1]),a)})}),(0,U.jsx)(_e,{label:`Misses`,value:(0,U.jsx)(`span`,{className:`font-medium`,children:bi(Number(u[2]),a)})})]}):s&&(0,U.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,U.jsx)(`span`,{className:`text-xs font-medium text-(--slate-11)`,children:`Notebook-wide`}),(0,U.jsx)(_e,{label:`Hits`,value:bi(s.hits,a)}),(0,U.jsx)(_e,{label:`Misses`,value:bi(s.misses,a)}),(0,U.jsx)(_e,{label:`Time saved`,value:zi(s.time,a)})]}),t[8]=s,t[9]=a,t[10]=u,t[11]=_):_=t[11];let v;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,U.jsx)(`div`,{className:`pt-2 text-xs text-(--slate-10)`,children:`Click to open the cache panel`}),t[12]=v):v=t[12];let y;return t[13]!==g||t[14]!==_?(y=(0,U.jsxs)(`div`,{className:ht,children:[g,_,v]}),t[13]=g,t[14]=_,t[15]=y):y=t[15],y},No=I.define(),Po=I.define();function Fo(e,t){return e.pos===t.pos&&e.kind===t.kind&&e.name===t.name&&e.cache?.boundName===t.cache?.boundName&&e.cache?.cacheName===t.cache?.cacheName}var Io=class{view;showTimer;hideTimer;constructor(e){this.view=e}enterLens(e,t){this.clearTimers(),Ro(this.view,t);let n=this.view.state.field(Vo,!1);n&&Fo(n.spec,e)||(this.showTimer=window.setTimeout(()=>{this.showTimer=void 0,this.view.dispatch({effects:Po.of(e)})},400))}leave(){this.clearTimers(),this.hideTimer=window.setTimeout(()=>{this.hideTimer=void 0,this.hide()},200)}enterPopover(){window.clearTimeout(this.hideTimer),this.hideTimer=void 0}hide(){this.clearTimers(),this.view.state.field(Vo,!1)&&this.view.dispatch({effects:Po.of(null)})}destroy(){this.clearTimers()}clearTimers(){window.clearTimeout(this.showTimer),window.clearTimeout(this.hideTimer),this.showTimer=void 0,this.hideTimer=void 0}},Lo=Vr.define(e=>new Io(e));function Ro(e,t){e.dom.dispatchEvent(new MouseEvent(`mouseleave`,{relatedTarget:t}))}var zo=class extends Mr{spec;constructor(e){super(),this.spec=e}eq(e){return Fo(this.spec,e.spec)}toDOM(e){let{spec:t}=this,n=document.createElement(`span`);n.className=`mo-code-lens`,n.setAttribute(`role`,`button`),n.tabIndex=0,n.setAttribute(`aria-label`,bo[t.kind]),n.innerHTML=yo[t.kind];let r=()=>e.plugin(Lo),i=()=>r()?.hide();return n.onmouseenter=()=>r()?.enterLens(t,n),n.onmouseleave=()=>r()?.leave(),n.onmousemove=e=>{e.stopPropagation()},n.onmousedown=e=>{e.preventDefault(),e.stopPropagation()},n.onclick=e=>{e.preventDefault(),e.stopPropagation(),i(),ao(t.kind)},n.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),i(),ao(t.kind))},n}ignoreEvent(){return!0}};function Bo(e){return{spec:e,tooltip:{pos:e.pos,above:!0,create:t=>{let n=document.createElement(`div`);return n.classList.add(`mo-cm-tooltip`,`docs-documentation`),n.onmouseenter=()=>t.plugin(Lo)?.enterPopover(),n.onmouseleave=()=>t.plugin(Lo)?.leave(),{dom:n,resize:!1,destroy:Co(n,e)}}}}}var Vo=dr.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(Po))return n.value?Bo(n.value):null;if(n.is(No)&&e)return n.value.some(t=>Fo(t,e.spec))?e:null}return t.docChanged?null:e},provide:e=>gr.from(e,e=>e?.tooltip??null)}),Ho=dr.define({create(){return L.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(No)&&(e=L.set(n.value.map(e=>L.widget({widget:new zo(e),side:1}).range(e.pos)),!0));return e},provide:e=>R.decorations.from(e)}),Uo=class{view;cellId;includeCache;unsubscribes;debounceMs=300;scheduleUpdate;constructor(e,t,n){this.view=e,this.cellId=t,this.includeCache=n,this.scheduleUpdate=Dt(()=>this.run(),this.debounceMs);let r=()=>this.scheduleUpdate();this.unsubscribes=[o.sub(re,r),o.sub(O,r),o.sub(ve,r),o.sub(tt,r)],this.scheduleUpdate()}update(e){let t=e.startState.field(Pe,!1)?.type!==e.state.field(Pe,!1)?.type;(e.docChanged||t)&&this.scheduleUpdate()}destroy(){this.scheduleUpdate.cancel();for(let e of this.unsubscribes)e()}run(){let{state:e}=this.view,t=[],n=e.field(Pe,!1)?.type;if(n==null||n===`python`){let n=_o(this.cellId),r=oo({state:e,names:new Set(n.keys())});for(let e of r){let r=n.get(e.name);r&&t.push({pos:e.to,kind:r,name:e.name})}if(this.includeCache)for(let n of po(e))t.push({pos:n.to,kind:`cache`,name:`cache:${n.from}`,cache:{boundName:n.boundName,cacheName:n.cacheName}})}queueMicrotask(()=>{this.view.dispatch({effects:No.of(t)})})}},Wo=`3px`,Go=R.baseTheme({".mo-code-lens":{display:`inline-flex`,verticalAlign:`baseline`,transform:`translateY(1.5px)`,padding:Wo,margin:`-${Wo} 0 -${Wo} calc(0.3em - ${Wo})`,cursor:`pointer`,opacity:`0.5`},".mo-code-lens:hover":{opacity:`1`}});function Ko(e,t=!0){return t?[Ho,Vo,Lo,Vr.define(t=>new Uo(t,e,fe(`cache_panel`))),Go]:[]}var qo=[`%alias`,`%cd`,`%clear`,`%debug`,`%env`,`%load`,`%load_ext`,`%lsmagic`,`%matplotlib`,`%pwd`,`%who_ls`,`%system`,`%%time`,`%%timeit`,`%%writefile`,`%%capture`,`%%html`,`%%latex`],Jo;function Yo(){let e=async e=>{let t=o.get(Ot),{saveUserConfig:n}=hi();await n({config:{runtime:{auto_reload:e}}}).then(()=>o.set(Ot,{...t,runtime:{...t.runtime,auto_reload:e}}))},t=[{match:`!pip install`,onMatch:()=>{o.set(M,e=>({...e,isSidebarOpen:!0,selectedPanel:`packages`})),Ci()},title:`Package Installation`,description:(0,U.jsxs)(U.Fragment,{children:[`The package manager sidebar has been opened.`,(0,U.jsx)(`br`,{}),`Install packages directly from there instead.`]})},{match:`!uv pip install`,onMatch:()=>{o.set(M,e=>({...e,isSidebarOpen:!0,selectedPanel:`packages`})),Ci()},title:`Package Installation`,description:(0,U.jsxs)(U.Fragment,{children:[`The package manager sidebar has been opened.`,(0,U.jsx)(`br`,{}),`Install packages directly from there instead.`]})},{match:`!uv add`,onMatch:()=>{o.set(M,e=>({...e,isSidebarOpen:!0,selectedPanel:`packages`})),Ci()},title:`Package Installation`,description:(0,U.jsxs)(U.Fragment,{children:[`The package manager sidebar has been opened.`,(0,U.jsx)(`br`,{}),`Install packages directly from there instead.`]})},{match:`%autoreload 2`,onMatch:async()=>{await e(`autorun`)},title:`Module reload`,description:(0,U.jsxs)(U.Fragment,{children:[`Module reload mode set to `,(0,U.jsx)(`b`,{children:`autorun`}),` - module changes will re-run the cells that import them.`]})},{match:`%autoreload 1`,onMatch:async()=>{await e(`lazy`)},title:`Module reload`,description:(0,U.jsxs)(U.Fragment,{children:[`Module reload mode set to `,(0,U.jsx)(`b`,{children:`lazy`}),` - module changes will mark the cells that import them as stale.`]})},{match:`%autoreload 0`,onMatch:async()=>{await e(`off`)},title:`Module reload`,description:(0,U.jsx)(U.Fragment,{children:`Module reload disabled - module changes will not be detected.`})},{match:`!ls`,onMatch:()=>{},title:`Listing files`,description:(0,U.jsxs)(U.Fragment,{children:[`Shell commands are not directly supported.`,(0,U.jsx)(`br`,{}),`Use `,(0,U.jsx)(`code`,{children:`import subprocess; subprocess.run(['ls'])`}),` instead.`]})},...qo.map(e=>({match:e,onMatch:()=>{},title:(0,U.jsx)(Di,{className:`inline`,children:e}),description:(0,U.jsxs)(U.Fragment,{children:[`Magic commands are not supported in marimo. Read more about replacements in the`,` `,(0,U.jsx)(`a`,{href:`https://docs.marimo.io/guides/coming_from/jupyter/#adapting-to-the-absence-of-magic-commands`,target:`_blank`,className:`text-link underline cursor-pointer`,rel:`noopener noreferrer`,children:`documentation`}),`.`]})}))],n=new Map(t.map(e=>[e.match,e]));return R.updateListener.of(e=>{if(e.docChanged){let t=e.state.selection.main,r=e.state.doc,i=r.lineAt(t.head),a=r.sliceString(i.from,t.anchor).trim(),o=n.get(a);o&&(o.onMatch(),Jo?Jo.upsert({title:o.title,description:o.description}):Jo=lr({title:o.title,description:o.description}))}})}var Xo=new Set([`Escape`,"Alt-`"]);function Zo(e,t=Xo){return e.filter(e=>![e.key,e.mac,e.linux,e.win].some(e=>t.has(e)))}function Qo(e=!0){let t=new Set(Xo);e||t.add(`Enter`);let n=Zo(ai,t);return xr.highest(hr.of([...n,{key:`Ctrl-y`,run:e=>v(e)?ui(e):!1},{key:`Ctrl-n`,run:e=>v(e)?oi(!0)(e):!1},{key:`Ctrl-p`,run:e=>v(e)?oi(!1)(e):!1}]))}var $o=I.define(),es=I.define(),ts=I.define();function W(e,t){if(!e)throw Error(t)}var ns=34028234663852886e22,rs=-34028234663852886e22,is=4294967295,as=2147483647,os=-2147483648;function ss(e){if(typeof e!=`number`)throw Error(`invalid int 32: `+typeof e);if(!Number.isInteger(e)||e>as||e<os)throw Error(`invalid int 32: `+e)}function cs(e){if(typeof e!=`number`)throw Error(`invalid uint 32: `+typeof e);if(!Number.isInteger(e)||e>is||e<0)throw Error(`invalid uint 32: `+e)}function ls(e){if(typeof e!=`number`)throw Error(`invalid float 32: `+typeof e);if(Number.isFinite(e)&&(e>ns||e<rs))throw Error(`invalid float 32: `+e)}var us=Symbol(`@bufbuild/protobuf/enum-type`);function ds(e){let t=e[us];return W(t,`missing enum type on enum object`),t}function fs(e,t,n,r){e[us]=ps(t,n.map(t=>({no:t.no,name:t.name,localName:e[t.no]})),r)}function ps(e,t,n){let r=Object.create(null),i=Object.create(null),a=[];for(let e of t){let t=hs(e);a.push(t),r[e.name]=t,i[e.no]=t}return{typeName:e,values:a,findName(e){return r[e]},findNumber(e){return i[e]}}}function ms(e,t,n){let r={};for(let e of t){let t=hs(e);r[t.localName]=t.no,r[t.no]=t.localName}return fs(r,e,t,n),r}function hs(e){return`localName`in e?e:Object.assign(Object.assign({},e),{localName:e.name})}var G=class{equals(e){return this.getType().runtime.util.equals(this.getType(),this,e)}clone(){return this.getType().runtime.util.clone(this)}fromBinary(e,t){let n=this.getType().runtime.bin,r=n.makeReadOptions(t);return n.readMessage(this,r.readerFactory(e),e.byteLength,r),this}fromJson(e,t){let n=this.getType(),r=n.runtime.json,i=r.makeReadOptions(t);return r.readMessage(n,e,i,this),this}fromJsonString(e,t){let n;try{n=JSON.parse(e)}catch(e){throw Error(`cannot decode ${this.getType().typeName} from JSON: ${e instanceof Error?e.message:String(e)}`)}return this.fromJson(n,t)}toBinary(e){let t=this.getType().runtime.bin,n=t.makeWriteOptions(e),r=n.writerFactory();return t.writeMessage(this,r,n),r.finish()}toJson(e){let t=this.getType().runtime.json,n=t.makeWriteOptions(e);return t.writeMessage(this,n)}toJsonString(e){let t=this.toJson(e);return JSON.stringify(t,null,e?.prettySpaces??0)}toJSON(){return this.toJson({emitDefaultValues:!0})}getType(){return Object.getPrototypeOf(this).constructor}};function gs(e,t,n,r){let i=r?.localName??t.substring(t.lastIndexOf(`.`)+1),a={[i]:function(t){e.util.initFields(this),e.util.initPartial(t,this)}}[i];return Object.setPrototypeOf(a.prototype,new G),Object.assign(a,{runtime:e,typeName:t,fields:e.util.newFieldList(n),fromBinary(e,t){return new a().fromBinary(e,t)},fromJson(e,t){return new a().fromJson(e,t)},fromJsonString(e,t){return new a().fromJsonString(e,t)},equals(t,n){return e.util.equals(a,t,n)}}),a}function _s(){let e=0,t=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<n,!(r&128))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(n&15)<<28,t=(n&112)>>4,!(n&128))return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(t|=(r&127)<<n,!(r&128))return this.assertBounds(),[e,t]}throw Error(`invalid varint`)}function vs(e,t,n){for(let r=0;r<28;r+=7){let i=e>>>r,a=!(!(i>>>7)&&t==0),o=(a?i|128:i)&255;if(n.push(o),!a)return}let r=e>>>28&15|(t&7)<<4,i=!!(t>>3);if(n.push((i?r|128:r)&255),i){for(let e=3;e<31;e+=7){let r=t>>>e,i=!!(r>>>7),a=(i?r|128:r)&255;if(n.push(a),!i)return}n.push(t>>>31&1)}}var ys=4294967296;function bs(e){let t=e[0]===`-`;t&&(e=e.slice(1));let n=1e6,r=0,i=0;function a(t,a){let o=Number(e.slice(t,a));i*=n,r=r*n+o,r>=ys&&(i+=r/ys|0,r%=ys)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?Ts(r,i):ws(r,i)}function xs(e,t){let n=ws(e,t),r=n.hi&2147483648;r&&(n=Ts(n.lo,n.hi));let i=Ss(n.lo,n.hi);return r?`-`+i:i}function Ss(e,t){if({lo:e,hi:t}=Cs(e,t),t<=2097151)return String(ys*t+e);let n=e&16777215,r=(e>>>24|t<<8)&16777215,i=t>>16&65535,a=n+r*6777216+i*6710656,o=r+i*8147497,s=i*2,c=1e7;return a>=c&&(o+=Math.floor(a/c),a%=c),o>=c&&(s+=Math.floor(o/c),o%=c),s.toString()+Es(o)+Es(a)}function Cs(e,t){return{lo:e>>>0,hi:t>>>0}}function ws(e,t){return{lo:e|0,hi:t|0}}function Ts(e,t){return t=~t,e?e=~e+1:t+=1,ws(e,t)}var Es=e=>{let t=String(e);return`0000000`.slice(t.length)+t};function Ds(e,t){if(e>=0){for(;e>127;)t.push(e&127|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(e&127|128),e>>=7;t.push(1)}}function Os(){let e=this.buf[this.pos++],t=e&127;if(!(e&128)||(e=this.buf[this.pos++],t|=(e&127)<<7,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<14,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<21,!(e&128)))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let t=5;e&128&&t<10;t++)e=this.buf[this.pos++];if(e&128)throw Error(`invalid varint`);return this.assertBounds(),t>>>0}function ks(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt==`function`&&typeof e.getBigInt64==`function`&&typeof e.getBigUint64==`function`&&typeof e.setBigInt64==`function`&&typeof e.setBigUint64==`function`&&(typeof process!=`object`||{}.BUF_BIGINT_DISABLE!==`1`)){let t=BigInt(`-9223372036854775808`),n=BigInt(`9223372036854775807`),r=BigInt(`0`),i=BigInt(`18446744073709551615`);return{zero:BigInt(0),supported:!0,parse(e){let r=typeof e==`bigint`?e:BigInt(e);if(r>n||r<t)throw Error(`int64 invalid: ${e}`);return r},uParse(e){let t=typeof e==`bigint`?e:BigInt(e);if(t>i||t<r)throw Error(`uint64 invalid: ${e}`);return t},enc(t){return e.setBigInt64(0,this.parse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(t){return e.setBigInt64(0,this.uParse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigInt64(0,!0)},uDec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigUint64(0,!0)}}}let t=e=>W(/^-?[0-9]+$/.test(e),`int64 invalid: ${e}`),n=e=>W(/^[0-9]+$/.test(e),`uint64 invalid: ${e}`);return{zero:`0`,supported:!1,parse(e){return typeof e!=`string`&&(e=e.toString()),t(e),e},uParse(e){return typeof e!=`string`&&(e=e.toString()),n(e),e},enc(e){return typeof e!=`string`&&(e=e.toString()),t(e),bs(e)},uEnc(e){return typeof e!=`string`&&(e=e.toString()),n(e),bs(e)},dec(e,t){return xs(e,t)},uDec(e,t){return Ss(e,t)}}}var K=ks(),q;(function(e){e[e.DOUBLE=1]=`DOUBLE`,e[e.FLOAT=2]=`FLOAT`,e[e.INT64=3]=`INT64`,e[e.UINT64=4]=`UINT64`,e[e.INT32=5]=`INT32`,e[e.FIXED64=6]=`FIXED64`,e[e.FIXED32=7]=`FIXED32`,e[e.BOOL=8]=`BOOL`,e[e.STRING=9]=`STRING`,e[e.BYTES=12]=`BYTES`,e[e.UINT32=13]=`UINT32`,e[e.SFIXED32=15]=`SFIXED32`,e[e.SFIXED64=16]=`SFIXED64`,e[e.SINT32=17]=`SINT32`,e[e.SINT64=18]=`SINT64`})(q||={});var As;(function(e){e[e.BIGINT=0]=`BIGINT`,e[e.STRING=1]=`STRING`})(As||={});function js(e,t,n){if(t===n)return!0;if(e==q.BYTES){if(!(t instanceof Uint8Array)||!(n instanceof Uint8Array)||t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}switch(e){case q.UINT64:case q.FIXED64:case q.INT64:case q.SFIXED64:case q.SINT64:return t==n}return!1}function Ms(e,t){switch(e){case q.BOOL:return!1;case q.UINT64:case q.FIXED64:case q.INT64:case q.SFIXED64:case q.SINT64:return t==0?K.zero:`0`;case q.DOUBLE:case q.FLOAT:return 0;case q.BYTES:return new Uint8Array;case q.STRING:return``;default:return 0}}function Ns(e,t){switch(e){case q.BOOL:return t===!1;case q.STRING:return t===``;case q.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return t==0}}var J;(function(e){e[e.Varint=0]=`Varint`,e[e.Bit64=1]=`Bit64`,e[e.LengthDelimited=2]=`LengthDelimited`,e[e.StartGroup=3]=`StartGroup`,e[e.EndGroup=4]=`EndGroup`,e[e.Bit32=5]=`Bit32`})(J||={});var Ps=class{constructor(e){this.stack=[],this.textEncoder=e??new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let t=0;t<this.chunks.length;t++)e+=this.chunks[t].length;let t=new Uint8Array(e),n=0;for(let e=0;e<this.chunks.length;e++)t.set(this.chunks[e],n),n+=this.chunks[e].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw Error(`invalid state, fork stack empty`);return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(cs(e);e>127;)this.buf.push(e&127|128),e>>>=7;return this.buf.push(e),this}int32(e){return ss(e),Ds(e,this.buf),this}bool(e){return this.buf.push(+!!e),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){ls(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){cs(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){ss(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return ss(e),e=(e<<1^e>>31)>>>0,Ds(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=K.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=K.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=K.enc(e);return vs(t.lo,t.hi,this.buf),this}sint64(e){let t=K.enc(e),n=t.hi>>31;return vs(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=K.uEnc(e);return vs(t.lo,t.hi,this.buf),this}},Fs=class{constructor(e,t){this.varint64=_s,this.uint32=Os,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t??new TextDecoder}tag(){let e=this.uint32(),t=e>>>3,n=e&7;if(t<=0||n<0||n>5)throw Error(`illegal tag: field no `+t+` wire type `+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case J.Varint:for(;this.buf[this.pos++]&128;);break;case J.Bit64:this.pos+=4;case J.Bit32:this.pos+=4;break;case J.LengthDelimited:let n=this.uint32();this.pos+=n;break;case J.StartGroup:for(;;){let[e,n]=this.tag();if(n===J.EndGroup){if(t!==void 0&&e!==t)throw Error(`invalid end group tag`);break}this.skip(n,e)}break;default:throw Error(`cant skip wire type `+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw RangeError(`premature EOF`)}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return K.dec(...this.varint64())}uint64(){return K.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,K.dec(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return K.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return K.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}};function Is(e,t,n,r){let i;return{typeName:t,extendee:n,get field(){if(!i){let n=typeof r==`function`?r():r;n.name=t.split(`.`).pop(),n.jsonName=`[${t}]`,i=e.util.newFieldList([n]).list()[0]}return i},runtime:e}}function Ls(e){let t=e.field.localName,n=Object.create(null);return n[t]=Rs(e),[n,()=>n[t]]}function Rs(e){let t=e.field;if(t.repeated)return[];if(t.default!==void 0)return t.default;switch(t.kind){case`enum`:return t.T.values[0].no;case`scalar`:return Ms(t.T,t.L);case`message`:let e=t.T,n=new e;return e.fieldWrapper?e.fieldWrapper.unwrapField(n):n;case`map`:throw`map fields are not allowed to be extensions`}}function zs(e,t){if(!t.repeated&&(t.kind==`enum`||t.kind==`scalar`)){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.no)return[e[n]];return[]}return e.filter(e=>e.no===t.no)}var Bs=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),Vs=[];for(let e=0;e<Bs.length;e++)Vs[Bs[e].charCodeAt(0)]=e;Vs[45]=Bs.indexOf(`+`),Vs[95]=Bs.indexOf(`/`);var Hs={dec(e){let t=e.length*3/4;e[e.length-2]==`=`?t-=2:e[e.length-1]==`=`&&--t;let n=new Uint8Array(t),r=0,i=0,a,o=0;for(let t=0;t<e.length;t++){if(a=Vs[e.charCodeAt(t)],a===void 0)switch(e[t]){case`=`:i=0;case`
|
|
10
|
-
`:case`\r`:case` `:case` `:continue;default:throw Error(`invalid base64 string.`)}switch(i){case 0:o=a,i=1;break;case 1:n[r++]=o<<2|(a&48)>>4,o=a,i=2;break;case 2:n[r++]=(o&15)<<4|(a&60)>>2,o=a,i=3;break;case 3:n[r++]=(o&3)<<6|a,i=0}}if(i==1)throw Error(`invalid base64 string.`);return n.subarray(0,r)},enc(e){let t=``,n=0,r,i=0;for(let a=0;a<e.length;a++)switch(r=e[a],n){case 0:t+=Bs[r>>2],i=(r&3)<<4,n=1;break;case 1:t+=Bs[i|r>>4],i=(r&15)<<2,n=2;break;case 2:t+=Bs[i|r>>6],t+=Bs[r&63],n=0}return n&&(t+=Bs[i],t+=`=`,n==1&&(t+=`=`)),t}};function Us(e,t,n){Ks(t,e);let r=t.runtime.bin.makeReadOptions(n),i=zs(e.getType().runtime.bin.listUnknownFields(e),t.field),[a,o]=Ls(t);for(let e of i)t.runtime.bin.readField(a,r.readerFactory(e.data),t.field,e.wireType,r);return o()}function Ws(e,t,n,r){Ks(t,e);let i=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(Gs(e,t)){let n=e.getType().runtime.bin.listUnknownFields(e).filter(e=>e.no!=t.field.no);e.getType().runtime.bin.discardUnknownFields(e);for(let t of n)e.getType().runtime.bin.onUnknownField(e,t.no,t.wireType,t.data)}let o=a.writerFactory(),s=t.field;!s.opt&&!s.repeated&&(s.kind==`enum`||s.kind==`scalar`)&&(s=Object.assign(Object.assign({},t.field),{opt:!0})),t.runtime.bin.writeField(s,n,o,a);let c=i.readerFactory(o.finish());for(;c.pos<c.len;){let[t,n]=c.tag(),r=c.skip(n,t);e.getType().runtime.bin.onUnknownField(e,t,n,r)}}function Gs(e,t){let n=e.getType();return t.extendee.typeName===n.typeName&&!!n.runtime.bin.listUnknownFields(e).find(e=>e.no==t.field.no)}function Ks(e,t){W(e.extendee.typeName==t.getType().typeName,`extension ${e.typeName} can only be applied to message ${e.extendee.typeName}`)}function qs(e,t){let n=e.localName;if(e.repeated)return t[n].length>0;if(e.oneof)return t[e.oneof.localName].case===n;switch(e.kind){case`enum`:case`scalar`:return e.opt||e.req?t[n]!==void 0:e.kind==`enum`?t[n]!==e.T.values[0].no:!Ns(e.T,t[n]);case`message`:return t[n]!==void 0;case`map`:return Object.keys(t[n]).length>0}}function Js(e,t){let n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case`map`:t[n]={};break;case`enum`:t[n]=r?e.T.values[0].no:void 0;break;case`scalar`:t[n]=r?Ms(e.T,e.L):void 0;break;case`message`:t[n]=void 0}}function Ys(e,t){if(typeof e!=`object`||!e||!Object.getOwnPropertyNames(G.prototype).every(t=>t in e&&typeof e[t]==`function`))return!1;let n=e.getType();return n===null||typeof n!=`function`||!(`typeName`in n)||typeof n.typeName!=`string`?!1:t===void 0||n.typeName==t.typeName}function Xs(e,t){return Ys(t)||!e.fieldWrapper?t:e.fieldWrapper.wrapField(t)}q.DOUBLE,q.FLOAT,q.INT64,q.UINT64,q.INT32,q.UINT32,q.BOOL,q.STRING,q.BYTES;var Zs={ignoreUnknownFields:!1},Qs={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function $s(e){return e?Object.assign(Object.assign({},Zs),e):Zs}function ec(e){return e?Object.assign(Object.assign({},Qs),e):Qs}var tc=Symbol(),nc=Symbol();function rc(){return{makeReadOptions:$s,makeWriteOptions:ec,readMessage(e,t,n,r){if(t==null||Array.isArray(t)||typeof t!=`object`)throw Error(`cannot decode message ${e.typeName} from JSON: ${ic(t)}`);r??=new e;let i=new Map,a=n.typeRegistry;for(let[o,s]of Object.entries(t)){let t=e.fields.findJsonName(o);if(t){if(t.oneof){if(s===null&&t.kind==`scalar`)continue;let n=i.get(t.oneof);if(n!==void 0)throw Error(`cannot decode message ${e.typeName} from JSON: multiple keys for oneof "${t.oneof.name}" present: "${n}", "${o}"`);i.set(t.oneof,o)}ac(r,s,t,n,e)}else{let t=!1;if(a?.findExtension&&o.startsWith(`[`)&&o.endsWith(`]`)){let i=a.findExtension(o.substring(1,o.length-1));if(i&&i.extendee.typeName==e.typeName){t=!0;let[e,a]=Ls(i);ac(e,s,i.field,n,i),Ws(r,i,a(),n)}}if(!t&&!n.ignoreUnknownFields)throw Error(`cannot decode message ${e.typeName} from JSON: key "${o}" is unknown`)}}return r},writeMessage(e,t){let n=e.getType(),r={},i;try{for(i of n.fields.byNumber()){if(!qs(i,e)){if(i.req)throw`required field not set`;if(!t.emitDefaultValues||!lc(i))continue}let n=i.oneof?e[i.oneof.localName].value:e[i.localName],a=uc(i,n,t);a!==void 0&&(r[t.useProtoFieldName?i.name:i.jsonName]=a)}let a=t.typeRegistry;if(a?.findExtensionFor)for(let i of n.runtime.bin.listUnknownFields(e)){let o=a.findExtensionFor(n.typeName,i.no);if(o&&Gs(e,o)){let n=Us(e,o,t),i=uc(o.field,n,t);i!==void 0&&(r[o.field.jsonName]=i)}}}catch(e){let t=i?`cannot encode field ${n.typeName}.${i.name} to JSON`:`cannot encode message ${n.typeName} to JSON`,r=e instanceof Error?e.message:String(e);throw Error(t+(r.length>0?`: ${r}`:``))}return r},readScalar(e,t,n){return sc(e,t,n??As.BIGINT,!0)},writeScalar(e,t,n){if(t!==void 0&&(n||Ns(e,t)))return fc(e,t)},debug:ic}}function ic(e){if(e===null)return`null`;switch(typeof e){case`object`:return Array.isArray(e)?`array`:`object`;case`string`:return e.length>100?`string`:`"${e.split(`"`).join(`\\"`)}"`;default:return String(e)}}function ac(e,t,n,r,i){let a=n.localName;if(n.repeated){if(W(n.kind!=`map`),t===null)return;if(!Array.isArray(t))throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(t)}`);let o=e[a];for(let e of t){if(e===null)throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(e)}`);switch(n.kind){case`message`:o.push(n.T.fromJson(e,r));break;case`enum`:let t=cc(n.T,e,r.ignoreUnknownFields,!0);t!==nc&&o.push(t);break;case`scalar`:try{o.push(sc(n.T,e,n.L,!0))}catch(t){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(e)}`;throw t instanceof Error&&t.message.length>0&&(r+=`: ${t.message}`),Error(r)}}}}else if(n.kind==`map`){if(t===null)return;if(typeof t!=`object`||Array.isArray(t))throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(t)}`);let o=e[a];for(let[e,a]of Object.entries(t)){if(a===null)throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: map value null`);let s;try{s=oc(n.K,e)}catch(e){let r=`cannot decode map key for field ${i.typeName}.${n.name} from JSON: ${ic(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}switch(n.V.kind){case`message`:o[s]=n.V.T.fromJson(a,r);break;case`enum`:let e=cc(n.V.T,a,r.ignoreUnknownFields,!0);e!==nc&&(o[s]=e);break;case`scalar`:try{o[s]=sc(n.V.T,a,As.BIGINT,!0)}catch(e){let r=`cannot decode map value for field ${i.typeName}.${n.name} from JSON: ${ic(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}}}}else switch(n.oneof&&(e=e[n.oneof.localName]={case:a},a=`value`),n.kind){case`message`:let o=n.T;if(t===null&&o.typeName!=`google.protobuf.Value`)return;let s=e[a];Ys(s)?s.fromJson(t,r):(e[a]=s=o.fromJson(t,r),o.fieldWrapper&&!n.oneof&&(e[a]=o.fieldWrapper.unwrapField(s)));break;case`enum`:let c=cc(n.T,t,r.ignoreUnknownFields,!1);switch(c){case tc:Js(n,e);break;case nc:break;default:e[a]=c}break;case`scalar`:try{let r=sc(n.T,t,n.L,!1);switch(r){case tc:Js(n,e);break;default:e[a]=r}}catch(e){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}}}function oc(e,t){if(e===q.BOOL)switch(t){case`true`:t=!0;break;case`false`:t=!1}return sc(e,t,As.BIGINT,!0).toString()}function sc(e,t,n,r){if(t===null)return r?Ms(e,n):tc;switch(e){case q.DOUBLE:case q.FLOAT:if(t===`NaN`)return NaN;if(t===`Infinity`)return 1/0;if(t===`-Infinity`)return-1/0;if(t===``||typeof t==`string`&&t.trim().length!==t.length||typeof t!=`string`&&typeof t!=`number`)break;let r=Number(t);if(Number.isNaN(r)||!Number.isFinite(r))break;return e==q.FLOAT&&ls(r),r;case q.INT32:case q.FIXED32:case q.SFIXED32:case q.SINT32:case q.UINT32:let i;if(typeof t==`number`?i=t:typeof t==`string`&&t.length>0&&t.trim().length===t.length&&(i=Number(t)),i===void 0)break;return e==q.UINT32||e==q.FIXED32?cs(i):ss(i),i;case q.INT64:case q.SFIXED64:case q.SINT64:if(typeof t!=`number`&&typeof t!=`string`)break;let a=K.parse(t);return n?a.toString():a;case q.FIXED64:case q.UINT64:if(typeof t!=`number`&&typeof t!=`string`)break;let o=K.uParse(t);return n?o.toString():o;case q.BOOL:if(typeof t!=`boolean`)break;return t;case q.STRING:if(typeof t!=`string`)break;return t;case q.BYTES:if(t===``)return new Uint8Array;if(typeof t!=`string`)break;return Hs.dec(t)}throw Error()}function cc(e,t,n,r){if(t===null)return e.typeName==`google.protobuf.NullValue`?0:r?e.values[0].no:tc;switch(typeof t){case`number`:if(Number.isInteger(t))return t;break;case`string`:let r=e.findName(t);if(r!==void 0)return r.no;if(n)return nc}throw Error(`cannot decode enum ${e.typeName} from JSON: ${ic(t)}`)}function lc(e){return e.repeated||e.kind==`map`?!0:!(e.oneof||e.kind==`message`||e.opt||e.req)}function uc(e,t,n){if(e.kind==`map`){W(typeof t==`object`&&!!t);let r={},i=Object.entries(t);switch(e.V.kind){case`scalar`:for(let[t,n]of i)r[t.toString()]=fc(e.V.T,n);break;case`message`:for(let[e,t]of i)r[e.toString()]=t.toJson(n);break;case`enum`:let t=e.V.T;for(let[e,a]of i)r[e.toString()]=dc(t,a,n.enumAsInteger)}return n.emitDefaultValues||i.length>0?r:void 0}if(e.repeated){W(Array.isArray(t));let r=[];switch(e.kind){case`scalar`:for(let n=0;n<t.length;n++)r.push(fc(e.T,t[n]));break;case`enum`:for(let i=0;i<t.length;i++)r.push(dc(e.T,t[i],n.enumAsInteger));break;case`message`:for(let e=0;e<t.length;e++)r.push(t[e].toJson(n))}return n.emitDefaultValues||r.length>0?r:void 0}switch(e.kind){case`scalar`:return fc(e.T,t);case`enum`:return dc(e.T,t,n.enumAsInteger);case`message`:return Xs(e.T,t).toJson(n)}}function dc(e,t,n){return W(typeof t==`number`),e.typeName==`google.protobuf.NullValue`?null:n?t:e.findNumber(t)?.name??t}function fc(e,t){switch(e){case q.INT32:case q.SFIXED32:case q.SINT32:case q.FIXED32:case q.UINT32:return W(typeof t==`number`),t;case q.FLOAT:case q.DOUBLE:return W(typeof t==`number`),Number.isNaN(t)?`NaN`:t===1/0?`Infinity`:t===-1/0?`-Infinity`:t;case q.STRING:return W(typeof t==`string`),t;case q.BOOL:return W(typeof t==`boolean`),t;case q.UINT64:case q.FIXED64:case q.INT64:case q.SFIXED64:case q.SINT64:return W(typeof t==`bigint`||typeof t==`string`||typeof t==`number`),t.toString();case q.BYTES:return W(t instanceof Uint8Array),Hs.enc(t)}}var pc=Symbol(`@bufbuild/protobuf/unknown-fields`),mc={readUnknownFields:!0,readerFactory:e=>new Fs(e)},hc={writeUnknownFields:!0,writerFactory:()=>new Ps};function gc(e){return e?Object.assign(Object.assign({},mc),e):mc}function _c(e){return e?Object.assign(Object.assign({},hc),e):hc}function vc(){return{makeReadOptions:gc,makeWriteOptions:_c,listUnknownFields(e){return e[pc]??[]},discardUnknownFields(e){delete e[pc]},writeUnknownFields(e,t){let n=e[pc];if(n)for(let e of n)t.tag(e.no,e.wireType).raw(e.data)},onUnknownField(e,t,n,r){let i=e;Array.isArray(i[pc])||(i[pc]=[]),i[pc].push({no:t,wireType:n,data:r})},readMessage(e,t,n,r,i){let a=e.getType(),o=i?t.len:t.pos+n,s,c;for(;t.pos<o&&([s,c]=t.tag(),i!==!0||c!=J.EndGroup);){let n=a.fields.find(s);if(!n){let n=t.skip(c,s);r.readUnknownFields&&this.onUnknownField(e,s,c,n);continue}yc(e,t,n,c,r)}if(i&&(c!=J.EndGroup||s!==n))throw Error(`invalid end group tag`)},readField:yc,writeMessage(e,t,n){let r=e.getType();for(let i of r.fields.byNumber()){if(!qs(i,e)){if(i.req)throw Error(`cannot encode field ${r.typeName}.${i.name} to binary: required field not set`);continue}wc(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t,n)}return n.writeUnknownFields&&this.writeUnknownFields(e,t),t},writeField(e,t,n,r){t!==void 0&&wc(e,t,n,r)}}}function yc(e,t,n,r,i){let{repeated:a,localName:o}=n;switch(n.oneof&&(e=e[n.oneof.localName],e.case!=o&&delete e.value,e.case=o,o=`value`),n.kind){case`scalar`:case`enum`:let s=n.kind==`enum`?q.INT32:n.T,c=Cc;if(n.kind==`scalar`&&n.L>0&&(c=Sc),a){let n=e[o];if(r==J.LengthDelimited&&s!=q.STRING&&s!=q.BYTES){let e=t.uint32()+t.pos;for(;t.pos<e;)n.push(c(t,s))}else n.push(c(t,s))}else e[o]=c(t,s);break;case`message`:let l=n.T;a?e[o].push(bc(t,new l,i,n)):Ys(e[o])?bc(t,e[o],i,n):(e[o]=bc(t,new l,i,n),l.fieldWrapper&&!n.oneof&&!n.repeated&&(e[o]=l.fieldWrapper.unwrapField(e[o])));break;case`map`:let[u,d]=xc(n,t,i);e[o][u]=d}}function bc(e,t,n,r){let i=t.getType().runtime.bin,a=r?.delimited;return i.readMessage(t,e,a?r.no:e.uint32(),n,a),t}function xc(e,t,n){let r=t.uint32(),i=t.pos+r,a,o;for(;t.pos<i;){let[r]=t.tag();switch(r){case 1:a=Cc(t,e.K);break;case 2:switch(e.V.kind){case`scalar`:o=Cc(t,e.V.T);break;case`enum`:o=t.int32();break;case`message`:o=bc(t,new e.V.T,n,void 0)}}}if(a===void 0&&(a=Ms(e.K,As.BIGINT)),typeof a!=`string`&&typeof a!=`number`&&(a=a.toString()),o===void 0)switch(e.V.kind){case`scalar`:o=Ms(e.V.T,As.BIGINT);break;case`enum`:o=e.V.T.values[0].no;break;case`message`:o=new e.V.T}return[a,o]}function Sc(e,t){let n=Cc(e,t);return typeof n==`bigint`?n.toString():n}function Cc(e,t){switch(t){case q.STRING:return e.string();case q.BOOL:return e.bool();case q.DOUBLE:return e.double();case q.FLOAT:return e.float();case q.INT32:return e.int32();case q.INT64:return e.int64();case q.UINT64:return e.uint64();case q.FIXED64:return e.fixed64();case q.BYTES:return e.bytes();case q.FIXED32:return e.fixed32();case q.SFIXED32:return e.sfixed32();case q.SFIXED64:return e.sfixed64();case q.SINT64:return e.sint64();case q.UINT32:return e.uint32();case q.SINT32:return e.sint32()}}function wc(e,t,n,r){W(t!==void 0);let i=e.repeated;switch(e.kind){case`scalar`:case`enum`:let a=e.kind==`enum`?q.INT32:e.T;if(i){if(W(Array.isArray(t)),e.packed)Oc(n,a,e.no,t);else for(let r of t)Dc(n,a,e.no,r)}else Dc(n,a,e.no,t);break;case`message`:if(i){W(Array.isArray(t));for(let i of t)Ec(n,r,e,i)}else Ec(n,r,e,t);break;case`map`:W(typeof t==`object`&&!!t);for(let[i,a]of Object.entries(t))Tc(n,r,e,i,a)}}function Tc(e,t,n,r,i){e.tag(n.no,J.LengthDelimited),e.fork();let a=r;switch(n.K){case q.INT32:case q.FIXED32:case q.UINT32:case q.SFIXED32:case q.SINT32:a=Number.parseInt(r);break;case q.BOOL:W(r==`true`||r==`false`),a=r==`true`}switch(Dc(e,n.K,1,a),n.V.kind){case`scalar`:Dc(e,n.V.T,2,i);break;case`enum`:Dc(e,q.INT32,2,i);break;case`message`:W(i!==void 0),e.tag(2,J.LengthDelimited).bytes(i.toBinary(t))}e.join()}function Ec(e,t,n,r){let i=Xs(n.T,r);n.delimited?e.tag(n.no,J.StartGroup).raw(i.toBinary(t)).tag(n.no,J.EndGroup):e.tag(n.no,J.LengthDelimited).bytes(i.toBinary(t))}function Dc(e,t,n,r){W(r!==void 0);let[i,a]=kc(t);e.tag(n,i)[a](r)}function Oc(e,t,n,r){if(!r.length)return;e.tag(n,J.LengthDelimited).fork();let[,i]=kc(t);for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}function kc(e){let t=J.Varint;switch(e){case q.BYTES:case q.STRING:t=J.LengthDelimited;break;case q.DOUBLE:case q.FIXED64:case q.SFIXED64:t=J.Bit64;break;case q.FIXED32:case q.SFIXED32:case q.FLOAT:t=J.Bit32}let n=q[e].toLowerCase();return[t,n]}function Ac(){return{setEnumType:fs,initPartial(e,t){if(e===void 0)return;let n=t.getType();for(let r of n.fields.byMember()){let n=r.localName,i=t,a=e;if(a[n]!=null)switch(r.kind){case`oneof`:let e=a[n].case;if(e===void 0)continue;let t=r.findField(e),o=a[n].value;t&&t.kind==`message`&&!Ys(o,t.T)?o=new t.T(o):t&&t.kind===`scalar`&&t.T===q.BYTES&&(o=Mc(o)),i[n]={case:e,value:o};break;case`scalar`:case`enum`:let s=a[n];r.T===q.BYTES&&(s=r.repeated?s.map(Mc):Mc(s)),i[n]=s;break;case`map`:switch(r.V.kind){case`scalar`:case`enum`:if(r.V.T===q.BYTES)for(let[e,t]of Object.entries(a[n]))i[n][e]=Mc(t);else Object.assign(i[n],a[n]);break;case`message`:let e=r.V.T;for(let t of Object.keys(a[n])){let r=a[n][t];e.fieldWrapper||(r=new e(r)),i[n][t]=r}}break;case`message`:let c=r.T;if(r.repeated)i[n]=a[n].map(e=>Ys(e,c)?e:new c(e));else{let e=a[n];i[n]=c.fieldWrapper?c.typeName===`google.protobuf.BytesValue`?Mc(e):e:Ys(e,c)?e:new c(e)}}}},equals(e,t,n){return t===n?!0:!t||!n?!1:e.fields.byMember().every(e=>{let r=t[e.localName],i=n[e.localName];if(e.repeated){if(r.length!==i.length)return!1;switch(e.kind){case`message`:return r.every((t,n)=>e.T.equals(t,i[n]));case`scalar`:return r.every((t,n)=>js(e.T,t,i[n]));case`enum`:return r.every((e,t)=>js(q.INT32,e,i[t]))}throw Error(`repeated cannot contain ${e.kind}`)}switch(e.kind){case`message`:let t=r,n=i;return e.T.fieldWrapper&&(t!==void 0&&!Ys(t)&&(t=e.T.fieldWrapper.wrapField(t)),n!==void 0&&!Ys(n)&&(n=e.T.fieldWrapper.wrapField(n))),e.T.equals(t,n);case`enum`:return js(q.INT32,r,i);case`scalar`:return js(e.T,r,i);case`oneof`:if(r.case!==i.case)return!1;let a=e.findField(r.case);if(a===void 0)return!0;switch(a.kind){case`message`:return a.T.equals(r.value,i.value);case`enum`:return js(q.INT32,r.value,i.value);case`scalar`:return js(a.T,r.value,i.value)}throw Error(`oneof cannot contain ${a.kind}`);case`map`:let o=Object.keys(r).concat(Object.keys(i));switch(e.V.kind){case`message`:let t=e.V.T;return o.every(e=>t.equals(r[e],i[e]));case`enum`:return o.every(e=>js(q.INT32,r[e],i[e]));case`scalar`:let n=e.V.T;return o.every(e=>js(n,r[e],i[e]))}}})},clone(e){let t=e.getType(),n=new t,r=n;for(let n of t.fields.byMember()){let t=e[n.localName],i;if(n.repeated)i=t.map(jc);else if(n.kind==`map`){i=r[n.localName];for(let[e,n]of Object.entries(t))i[e]=jc(n)}else i=n.kind==`oneof`?n.findField(t.case)?{case:t.case,value:jc(t.value)}:{case:void 0}:jc(t);r[n.localName]=i}for(let n of t.runtime.bin.listUnknownFields(e))t.runtime.bin.onUnknownField(r,n.no,n.wireType,n.data);return n}}}function jc(e){if(e===void 0)return e;if(Ys(e))return e.clone();if(e instanceof Uint8Array){let t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function Mc(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Nc(e,t,n){return{syntax:e,json:rc(),bin:vc(),util:Object.assign(Object.assign({},Ac()),{newFieldList:t,initFields:n}),makeMessageType(e,t,n){return gs(this,e,t,n)},makeEnum:ms,makeEnumType:ps,getEnumType:ds,makeExtension(e,t,n){return Is(this,e,t,n)}}}var Pc=class{constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){let e={};for(let t of this.list())e[t.jsonName]=e[t.name]=t;this.jsonNames=e}return this.jsonNames[e]}find(e){if(!this.numbers){let e={};for(let t of this.list())e[t.no]=t;this.numbers=e}return this.numbers[e]}list(){return this.all||=this._normalizer(this._fields),this.all}byNumber(){return this.numbersAsc||=this.list().concat().sort((e,t)=>e.no-t.no),this.numbersAsc}byMember(){if(!this.members){this.members=[];let e=this.members,t;for(let n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}};function Fc(e,t){let n=Rc(e);return t?n:Uc(Hc(n))}function Ic(e){return Fc(e,!1)}var Lc=Rc;function Rc(e){let t=!1,n=[];for(let r=0;r<e.length;r++){let i=e.charAt(r);switch(i){case`_`:t=!0;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n.push(i),t=!1;break;default:t&&(t=!1,i=i.toUpperCase()),n.push(i)}}return n.join(``)}var zc=new Set([`constructor`,`toString`,`toJSON`,`valueOf`]),Bc=new Set([`getType`,`clone`,`equals`,`fromBinary`,`fromJson`,`fromJsonString`,`toBinary`,`toJson`,`toJsonString`,`toObject`]),Vc=e=>`${e}$`,Hc=e=>Bc.has(e)?Vc(e):e,Uc=e=>zc.has(e)?Vc(e):e,Wc=class{constructor(e){this.kind=`oneof`,this.repeated=!1,this.packed=!1,this.opt=!1,this.req=!1,this.default=void 0,this.fields=[],this.name=e,this.localName=Ic(e)}addField(e){W(e.oneof===this,`field ${e.name} not one of ${this.name}`),this.fields.push(e)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let e=0;e<this.fields.length;e++)this._lookup[this.fields[e].localName]=this.fields[e]}return this._lookup[e]}};function Gc(e,t){let n=[],r;for(let i of typeof e==`function`?e():e){let e=i;if(e.localName=Fc(i.name,i.oneof!==void 0),e.jsonName=i.jsonName??Lc(i.name),e.repeated=i.repeated??!1,i.kind==`scalar`&&(e.L=i.L??As.BIGINT),e.delimited=i.delimited??!1,e.req=i.req??!1,e.opt=i.opt??!1,i.packed===void 0&&(e.packed=t?i.kind==`enum`||i.kind==`scalar`&&i.T!=q.BYTES&&i.T!=q.STRING:!1),i.oneof!==void 0){let t=typeof i.oneof==`string`?i.oneof:i.oneof.name;(!r||r.name!=t)&&(r=new Wc(t)),e.oneof=r,r.addField(e)}n.push(e)}return n}var Y=Nc(`proto3`,e=>new Pc(e,e=>Gc(e,!0)),e=>{for(let t of e.getType().fields.byMember()){if(t.opt)continue;let n=t.localName,r=e;if(t.repeated){r[n]=[];continue}switch(t.kind){case`oneof`:r[n]={case:void 0};break;case`enum`:r[n]=0;break;case`map`:r[n]={};break;case`scalar`:r[n]=Ms(t.T,t.L)}}}),Kc;(function(e){e[e.Unary=0]=`Unary`,e[e.ServerStreaming=1]=`ServerStreaming`,e[e.ClientStreaming=2]=`ClientStreaming`,e[e.BiDiStreaming=3]=`BiDiStreaming`})(Kc||={});var qc;(function(e){e[e.NoSideEffects=1]=`NoSideEffects`,e[e.Idempotent=2]=`Idempotent`})(qc||={});var Jc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.JUPYTER_FORMAT=77]=`JUPYTER_FORMAT`})(Jc||={}),Y.util.setEnumType(Jc,`exa.codeium_common_pb.ExperimentKey`,[{no:0,name:`UNSPECIFIED`},{no:77,name:`JUPYTER_FORMAT`}]);var Yc;(function(e){e[e.CODEIUM=0]=`CODEIUM`})(Yc||={}),Y.util.setEnumType(Yc,`exa.codeium_common_pb.AuthSource`,[{no:0,name:`AUTH_SOURCE_CODEIUM`}]);var Xc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.ENABLE_CODEIUM=1]=`ENABLE_CODEIUM`,e[e.DISABLE_CODEIUM=2]=`DISABLE_CODEIUM`,e[e.SHOW_PREVIOUS_COMPLETION=3]=`SHOW_PREVIOUS_COMPLETION`,e[e.SHOW_NEXT_COMPLETION=4]=`SHOW_NEXT_COMPLETION`})(Xc||={}),Y.util.setEnumType(Xc,`exa.codeium_common_pb.EventType`,[{no:0,name:`EVENT_TYPE_UNSPECIFIED`},{no:1,name:`EVENT_TYPE_ENABLE_CODEIUM`},{no:2,name:`EVENT_TYPE_DISABLE_CODEIUM`},{no:3,name:`EVENT_TYPE_SHOW_PREVIOUS_COMPLETION`},{no:4,name:`EVENT_TYPE_SHOW_NEXT_COMPLETION`}]);var Zc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.TYPING_AS_SUGGESTED=1]=`TYPING_AS_SUGGESTED`,e[e.CACHE=2]=`CACHE`,e[e.NETWORK=3]=`NETWORK`})(Zc||={}),Y.util.setEnumType(Zc,`exa.codeium_common_pb.CompletionSource`,[{no:0,name:`COMPLETION_SOURCE_UNSPECIFIED`},{no:1,name:`COMPLETION_SOURCE_TYPING_AS_SUGGESTED`},{no:2,name:`COMPLETION_SOURCE_CACHE`},{no:3,name:`COMPLETION_SOURCE_NETWORK`}]);var Qc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.C=1]=`C`,e[e.CLOJURE=2]=`CLOJURE`,e[e.COFFEESCRIPT=3]=`COFFEESCRIPT`,e[e.CPP=4]=`CPP`,e[e.CSHARP=5]=`CSHARP`,e[e.CSS=6]=`CSS`,e[e.CUDACPP=7]=`CUDACPP`,e[e.DOCKERFILE=8]=`DOCKERFILE`,e[e.GO=9]=`GO`,e[e.GROOVY=10]=`GROOVY`,e[e.HANDLEBARS=11]=`HANDLEBARS`,e[e.HASKELL=12]=`HASKELL`,e[e.HCL=13]=`HCL`,e[e.HTML=14]=`HTML`,e[e.INI=15]=`INI`,e[e.JAVA=16]=`JAVA`,e[e.JAVASCRIPT=17]=`JAVASCRIPT`,e[e.JSON=18]=`JSON`,e[e.JULIA=19]=`JULIA`,e[e.KOTLIN=20]=`KOTLIN`,e[e.LATEX=21]=`LATEX`,e[e.LESS=22]=`LESS`,e[e.LUA=23]=`LUA`,e[e.MAKEFILE=24]=`MAKEFILE`,e[e.MARKDOWN=25]=`MARKDOWN`,e[e.OBJECTIVEC=26]=`OBJECTIVEC`,e[e.OBJECTIVECPP=27]=`OBJECTIVECPP`,e[e.PERL=28]=`PERL`,e[e.PHP=29]=`PHP`,e[e.PLAINTEXT=30]=`PLAINTEXT`,e[e.PROTOBUF=31]=`PROTOBUF`,e[e.PBTXT=32]=`PBTXT`,e[e.PYTHON=33]=`PYTHON`,e[e.R=34]=`R`,e[e.RUBY=35]=`RUBY`,e[e.RUST=36]=`RUST`,e[e.SASS=37]=`SASS`,e[e.SCALA=38]=`SCALA`,e[e.SCSS=39]=`SCSS`,e[e.SHELL=40]=`SHELL`,e[e.SQL=41]=`SQL`,e[e.STARLARK=42]=`STARLARK`,e[e.SWIFT=43]=`SWIFT`,e[e.TSX=44]=`TSX`,e[e.TYPESCRIPT=45]=`TYPESCRIPT`,e[e.VISUALBASIC=46]=`VISUALBASIC`,e[e.VUE=47]=`VUE`,e[e.XML=48]=`XML`,e[e.XSL=49]=`XSL`,e[e.YAML=50]=`YAML`,e[e.SVELTE=51]=`SVELTE`,e[e.TOML=52]=`TOML`,e[e.DART=53]=`DART`,e[e.RST=54]=`RST`,e[e.OCAML=55]=`OCAML`,e[e.CMAKE=56]=`CMAKE`,e[e.PASCAL=57]=`PASCAL`,e[e.ELIXIR=58]=`ELIXIR`,e[e.FSHARP=59]=`FSHARP`,e[e.LISP=60]=`LISP`,e[e.MATLAB=61]=`MATLAB`,e[e.POWERSHELL=62]=`POWERSHELL`,e[e.SOLIDITY=63]=`SOLIDITY`,e[e.ADA=64]=`ADA`,e[e.OCAML_INTERFACE=65]=`OCAML_INTERFACE`})(Qc||={}),Y.util.setEnumType(Qc,`exa.codeium_common_pb.Language`,[{no:0,name:`LANGUAGE_UNSPECIFIED`},{no:1,name:`LANGUAGE_C`},{no:2,name:`LANGUAGE_CLOJURE`},{no:3,name:`LANGUAGE_COFFEESCRIPT`},{no:4,name:`LANGUAGE_CPP`},{no:5,name:`LANGUAGE_CSHARP`},{no:6,name:`LANGUAGE_CSS`},{no:7,name:`LANGUAGE_CUDACPP`},{no:8,name:`LANGUAGE_DOCKERFILE`},{no:9,name:`LANGUAGE_GO`},{no:10,name:`LANGUAGE_GROOVY`},{no:11,name:`LANGUAGE_HANDLEBARS`},{no:12,name:`LANGUAGE_HASKELL`},{no:13,name:`LANGUAGE_HCL`},{no:14,name:`LANGUAGE_HTML`},{no:15,name:`LANGUAGE_INI`},{no:16,name:`LANGUAGE_JAVA`},{no:17,name:`LANGUAGE_JAVASCRIPT`},{no:18,name:`LANGUAGE_JSON`},{no:19,name:`LANGUAGE_JULIA`},{no:20,name:`LANGUAGE_KOTLIN`},{no:21,name:`LANGUAGE_LATEX`},{no:22,name:`LANGUAGE_LESS`},{no:23,name:`LANGUAGE_LUA`},{no:24,name:`LANGUAGE_MAKEFILE`},{no:25,name:`LANGUAGE_MARKDOWN`},{no:26,name:`LANGUAGE_OBJECTIVEC`},{no:27,name:`LANGUAGE_OBJECTIVECPP`},{no:28,name:`LANGUAGE_PERL`},{no:29,name:`LANGUAGE_PHP`},{no:30,name:`LANGUAGE_PLAINTEXT`},{no:31,name:`LANGUAGE_PROTOBUF`},{no:32,name:`LANGUAGE_PBTXT`},{no:33,name:`LANGUAGE_PYTHON`},{no:34,name:`LANGUAGE_R`},{no:35,name:`LANGUAGE_RUBY`},{no:36,name:`LANGUAGE_RUST`},{no:37,name:`LANGUAGE_SASS`},{no:38,name:`LANGUAGE_SCALA`},{no:39,name:`LANGUAGE_SCSS`},{no:40,name:`LANGUAGE_SHELL`},{no:41,name:`LANGUAGE_SQL`},{no:42,name:`LANGUAGE_STARLARK`},{no:43,name:`LANGUAGE_SWIFT`},{no:44,name:`LANGUAGE_TSX`},{no:45,name:`LANGUAGE_TYPESCRIPT`},{no:46,name:`LANGUAGE_VISUALBASIC`},{no:47,name:`LANGUAGE_VUE`},{no:48,name:`LANGUAGE_XML`},{no:49,name:`LANGUAGE_XSL`},{no:50,name:`LANGUAGE_YAML`},{no:51,name:`LANGUAGE_SVELTE`},{no:52,name:`LANGUAGE_TOML`},{no:53,name:`LANGUAGE_DART`},{no:54,name:`LANGUAGE_RST`},{no:55,name:`LANGUAGE_OCAML`},{no:56,name:`LANGUAGE_CMAKE`},{no:57,name:`LANGUAGE_PASCAL`},{no:58,name:`LANGUAGE_ELIXIR`},{no:59,name:`LANGUAGE_FSHARP`},{no:60,name:`LANGUAGE_LISP`},{no:61,name:`LANGUAGE_MATLAB`},{no:62,name:`LANGUAGE_POWERSHELL`},{no:63,name:`LANGUAGE_SOLIDITY`},{no:64,name:`LANGUAGE_ADA`},{no:65,name:`LANGUAGE_OCAML_INTERFACE`}]);var $c=class e extends G{completionId=``;text=``;prefix=``;stop=``;score=0;tokens=[];decodedTokens=[];probabilities=[];adjustedProbabilities=[];generatedLength=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.codeium_common_pb.Completion`;static fields=Y.util.newFieldList(()=>[{no:1,name:`completion_id`,kind:`scalar`,T:9},{no:2,name:`text`,kind:`scalar`,T:9},{no:3,name:`prefix`,kind:`scalar`,T:9},{no:4,name:`stop`,kind:`scalar`,T:9},{no:5,name:`score`,kind:`scalar`,T:1},{no:6,name:`tokens`,kind:`scalar`,T:4,repeated:!0},{no:7,name:`decoded_tokens`,kind:`scalar`,T:9,repeated:!0},{no:8,name:`probabilities`,kind:`scalar`,T:1,repeated:!0},{no:9,name:`adjusted_probabilities`,kind:`scalar`,T:1,repeated:!0},{no:10,name:`generated_length`,kind:`scalar`,T:4}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},el=class e extends G{ideName=``;ideVersion=``;extensionName=``;extensionVersion=``;apiKey=``;locale=``;sessionId=``;requestId=K.zero;userAgent=``;url=``;authSource=Yc.CODEIUM;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.codeium_common_pb.Metadata`;static fields=Y.util.newFieldList(()=>[{no:1,name:`ide_name`,kind:`scalar`,T:9},{no:7,name:`ide_version`,kind:`scalar`,T:9},{no:12,name:`extension_name`,kind:`scalar`,T:9},{no:2,name:`extension_version`,kind:`scalar`,T:9},{no:3,name:`api_key`,kind:`scalar`,T:9},{no:4,name:`locale`,kind:`scalar`,T:9},{no:10,name:`session_id`,kind:`scalar`,T:9},{no:9,name:`request_id`,kind:`scalar`,T:4},{no:13,name:`user_agent`,kind:`scalar`,T:9},{no:14,name:`url`,kind:`scalar`,T:9},{no:15,name:`auth_source`,kind:`enum`,T:Y.getEnumType(Yc)}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},tl=class e extends G{tabSize=K.zero;insertSpaces=!1;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.codeium_common_pb.EditorOptions`;static fields=Y.util.newFieldList(()=>[{no:1,name:`tab_size`,kind:`scalar`,T:4},{no:2,name:`insert_spaces`,kind:`scalar`,T:8}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}};(class e extends G{eventType=Xc.UNSPECIFIED;eventJson=``;timestampUnixMs=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.codeium_common_pb.Event`;static fields=Y.util.newFieldList(()=>[{no:1,name:`event_type`,kind:`enum`,T:Y.getEnumType(Xc)},{no:2,name:`event_json`,kind:`scalar`,T:9},{no:3,name:`timestamp_unix_ms`,kind:`scalar`,T:3}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}});var nl=class extends Mr{index;total;constructor(e,t){super(),this.index=e,this.total=t}toDOM(){let e=document.createElement(`span`);e.setAttribute(`aria-hidden`,`true`),e.className=`cm-codeium-cycle`;let t=e.appendChild(document.createElement(`span`));t.className=`cm-codeium-cycle-explanation`,t.innerText=`${this.index+1}/${this.total}`;let n=e.appendChild(document.createElement(`button`));return n.className=`cm-codeium-cycle-key`,n.innerText=`→ (Ctrl ])`,n.dataset.action=`codeium-cycle`,e}ignoreEvent(){return!1}},rl=Sr.define({combine(e){return Fr(e,{language:Qc.TYPESCRIPT,timeout:150,widgetClass:nl,alwaysOn:!0},{})}}),il=Sr.define({combine(e){return Fr(e,{override:()=>[]},{})}}),al=L.mark({class:`cm-ghostText`}),ol=dr.define({create(e){return null},update(e,t){let n=t.state.facet(rl);for(let e of t.effects){if(e.is($o)){let{changeSpecs:t,index:r}=e.value,i=t[r].map(e=>al.range(e.absoluteStartPos,e.absoluteEndPos)),a=i.at(-1)?.to;return{index:r,decorations:L.set([...i,...a!==void 0&&t.length>1&&n.widgetClass?[L.widget({widget:new n.widgetClass(r,t.length),side:1}).range(a)]:[]]),changeSpecs:t,reverseChangeSet:e.value.reverseChangeSet}}if(e.is(es)||e.is(ts))return null}return e&&{...e,decorations:e.decorations.map(t.changes),reverseChangeSet:e.reverseChangeSet.map(t.changes)}},provide:e=>R.decorations.from(e,e=>e?.decorations||L.none)}),sl=Wr.define(),cl=Wr.define(),X;(function(e){e[e.Canceled=1]=`Canceled`,e[e.Unknown=2]=`Unknown`,e[e.InvalidArgument=3]=`InvalidArgument`,e[e.DeadlineExceeded=4]=`DeadlineExceeded`,e[e.NotFound=5]=`NotFound`,e[e.AlreadyExists=6]=`AlreadyExists`,e[e.PermissionDenied=7]=`PermissionDenied`,e[e.ResourceExhausted=8]=`ResourceExhausted`,e[e.FailedPrecondition=9]=`FailedPrecondition`,e[e.Aborted=10]=`Aborted`,e[e.OutOfRange=11]=`OutOfRange`,e[e.Unimplemented=12]=`Unimplemented`,e[e.Internal=13]=`Internal`,e[e.Unavailable=14]=`Unavailable`,e[e.DataLoss=15]=`DataLoss`,e[e.Unauthenticated=16]=`Unauthenticated`})(X||={});function ll(e){let t=X[e];return typeof t==`string`?t[0].toLowerCase()+t.substring(1).replace(/[A-Z]/g,e=>`_`+e.toLowerCase()):e.toString()}var ul;function dl(e){if(!ul){ul={};for(let e of Object.values(X))typeof e!=`string`&&(ul[ll(e)]=e)}return ul[e]}var Z=class e extends Error{constructor(e,t=X.Unknown,n,r,i){super(fl(e,t)),this.name=`ConnectError`,Object.setPrototypeOf(this,new.target.prototype),this.rawMessage=e,this.code=t,this.metadata=new Headers(n??{}),this.details=r??[],this.cause=i}static from(t,n=X.Unknown){return t instanceof e?t:t instanceof Error?t.name==`AbortError`?new e(t.message,X.Canceled):new e(t.message,n,void 0,void 0,t):new e(String(t),n,void 0,void 0,t)}static[Symbol.hasInstance](t){return t instanceof Error?Object.getPrototypeOf(t)===e.prototype||t.name===`ConnectError`&&`code`in t&&typeof t.code==`number`&&`metadata`in t&&`details`in t&&Array.isArray(t.details)&&`rawMessage`in t&&typeof t.rawMessage==`string`&&`cause`in t:!1}findDetails(e){let t=`typeName`in e?{findMessage:t=>t===e.typeName?e:void 0}:e,n=[];for(let e of this.details){if(`getType`in e){t.findMessage(e.getType().typeName)&&n.push(e);continue}let r=t.findMessage(e.type);if(r)try{n.push(r.fromBinary(e.value))}catch{}}return n}};function fl(e,t){return e.length?`[${ll(t)}] ${e}`:`[${ll(t)}]`}function pl(...e){let t=new Headers;for(let n of e)n.forEach((e,n)=>{t.append(n,e)});return t}function ml(e,t){let n={};for(let[r,i]of Object.entries(e.methods)){let a=t(Object.assign(Object.assign({},i),{localName:r,service:e}));a!=null&&(n[r]=a)}return n}function hl(e){let t,n=new Uint8Array;function r(e){let t=new Uint8Array(n.length+e.length);t.set(n),t.set(e,n.length),n=t}return new ReadableStream({start(){t=e.getReader()},async pull(e){let i;for(;;){if(i===void 0&&n.byteLength>=5){let e=0;for(let t=1;t<5;t++)e=(e<<8)+n[t];i={flags:n[0],length:e}}if(i!==void 0&&n.byteLength>=i.length+5)break;let e=await t.read();if(e.done)break;r(e.value)}if(i===void 0){if(n.byteLength==0){e.close();return}e.error(new Z(`premature end of stream`,X.DataLoss));return}let a=n.subarray(5,5+i.length);n=n.subarray(5+i.length),e.enqueue({flags:i.flags,data:a})}})}function gl(e,t){let n=new Uint8Array(t.length+5);n.set(t,5);let r=new DataView(n.buffer,n.byteOffset,n.byteLength);return r.setUint8(0,e),r.setUint32(1,t.length),n}var _l=function(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values==`function`?__values(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}},vl=function(e){return this instanceof vl?(this.v=e,this):new vl(e)},yl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i={},s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof vl?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}},bl=function(e){var t,n;return t={},r(`next`),r(`throw`,function(e){throw e}),r(`return`),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:vl(e[r](t)),done:!1}:i?i(t):t}:i}};function xl(e){return yl(this,arguments,function*(){yield vl(yield*bl(_l(e)))})}var Sl=function(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values==`function`?__values(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}},Cl=function(e){return this instanceof Cl?(this.v=e,this):new Cl(e)},wl=function(e){var t,n;return t={},r(`next`),r(`throw`,function(e){throw e}),r(`return`),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:Cl(e[r](t)),done:!1}:i?i(t):t}:i}},Tl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i={},s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof Cl?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}};function El(e,t){return ml(e,n=>{switch(n.kind){case Kc.Unary:return Ol(t,e,n);case Kc.ServerStreaming:return kl(t,e,n);case Kc.ClientStreaming:return Al(t,e,n);case Kc.BiDiStreaming:return jl(t,e,n);default:return null}})}function Dl(e,t){return El(e,t)}function Ol(e,t,n){return async function(r,i){var a,o;let s=await e.unary(t,n,i?.signal,i?.timeoutMs,i?.headers,r,i?.contextValues);return(a=i?.onHeader)==null||a.call(i,s.header),(o=i?.onTrailer)==null||o.call(i,s.trailer),s.message}}function kl(e,t,n){return function(r,i){return Ml(e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,xl([r]),i?.contextValues),i)}}function Al(e,t,n){return async function(r,i){var a,o,s,c,l,u;let d=await e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,r,i?.contextValues);(l=i?.onHeader)==null||l.call(i,d.header);let f,p=0;try{for(var m=!0,h=Sl(d.message),g;g=await h.next(),a=g.done,!a;m=!0)c=g.value,m=!1,f=c,p++}catch(e){o={error:e}}finally{try{!m&&!a&&(s=h.return)&&await s.call(h)}finally{if(o)throw o.error}}if(!f)throw new Z(`protocol error: missing response message`,X.Unimplemented);if(p>1)throw new Z(`protocol error: received extra messages for client streaming method`,X.Unimplemented);return(u=i?.onTrailer)==null||u.call(i,d.trailer),f}}function jl(e,t,n){return function(r,i){return Ml(e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,r,i?.contextValues),i)}}function Ml(e,t){let n=(function(){return Tl(this,arguments,function*(){var n,r;let i=yield Cl(e);(n=t?.onHeader)==null||n.call(t,i.header),yield Cl(yield*wl(Sl(i.message))),(r=t?.onTrailer)==null||r.call(t,i.trailer)})})()[Symbol.asyncIterator]();return{[Symbol.asyncIterator]:()=>({next:()=>n.next()})}}function Nl(...e){let t=new AbortController,n=e.filter(e=>e!==void 0).concat(t.signal);for(let e of n){if(e.aborted){r.apply(e);break}e.addEventListener(`abort`,r)}function r(){t.signal.aborted||t.abort(Fl(this));for(let e of n)e.removeEventListener(`abort`,r)}return t}function Pl(e){let t=new AbortController,n=()=>{t.abort(new Z(`the operation timed out`,X.DeadlineExceeded))},r;return e!==void 0&&(e<=0?n():r=setTimeout(n,e)),{signal:t.signal,cleanup:()=>clearTimeout(r)}}function Fl(e){if(!e.aborted)return;if(e.reason!==void 0)return e.reason;let t=Error(`This operation was aborted`);return t.name=`AbortError`,t}function Il(){return{get(e){return e.id in this?this[e.id]:e.defaultValue},set(e,t){return this[e.id]=t,this},delete(e){return delete this[e.id],this}}}function Ll(e,t,n){let r=typeof t==`string`?t:t.typeName,i=typeof n==`string`?n:n.name;return e.toString().replace(/\/?$/,`/${r}/${i}`)}function Rl(e,t){return t instanceof e?t:new e(t)}function zl(e,t){function n(t){return t.done===!0?t:{done:t.done,value:Rl(e,t.value)}}return{[Symbol.asyncIterator](){let e=t[Symbol.asyncIterator](),r={next:()=>e.next().then(n)};return e.throw!==void 0&&(r.throw=t=>e.throw(t).then(n)),e.return!==void 0&&(r.return=t=>e.return(t).then(n)),r}}}function Bl(e,t){return t?.concat().reverse().reduce((e,t)=>t(e),e)??e}function Vl(e){let t=Object.assign({},e);return t.ignoreUnknownFields??=!0,t}function Hl(e,t,n,r){let i=t?Ul(e.I,r):Wl(e.I,n);return{parse:(t?Ul(e.O,r):Wl(e.O,n)).parse,serialize:i.serialize}}function Ul(e,t){return{parse(n){try{return e.fromBinary(n,t)}catch(e){throw new Z(`parse binary: ${e instanceof Error?e.message:String(e)}`,X.Internal)}},serialize(e){try{return e.toBinary(t)}catch(e){throw new Z(`serialize binary: ${e instanceof Error?e.message:String(e)}`,X.Internal)}}}}function Wl(e,t){let n=t?.textEncoder??new TextEncoder,r=t?.textDecoder??new TextDecoder,i=Vl(t);return{parse(t){try{let n=r.decode(t);return e.fromJsonString(n,i)}catch(e){throw Z.from(e,X.InvalidArgument)}},serialize(e){try{let t=e.toJsonString(i);return n.encode(t)}catch(e){throw Z.from(e,X.Internal)}}}}var Gl=/^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$/i,Kl=`application/proto`,ql=`application/json`,Jl=`application/connect+proto`,Yl=`application/connect+json`;function Xl(e){let t=e?.match(Gl);if(t)return{stream:!!t[1],binary:!!t[3]}}function Zl(e,t,n){if(t&&new Headers(t).forEach((e,t)=>n.metadata.append(t,e)),typeof e!=`object`||!e||Array.isArray(e))throw n;let r=n.code;`code`in e&&typeof e.code==`string`&&(r=dl(e.code)??r);let i=e.message;if(i!=null&&typeof i!=`string`)throw n;let a=new Z(i??``,r,t);if(`details`in e&&Array.isArray(e.details))for(let t of e.details){if(typeof t!=`object`||!t||Array.isArray(t)||typeof t.type!=`string`||typeof t.value!=`string`)throw n;try{a.details.push({type:t.type,value:Hs.dec(t.value),debug:t.debug})}catch{throw n}}return a}function Ql(e){let t=new Z(`invalid end stream`,X.Unknown),n;try{n=JSON.parse(typeof e==`string`?e:new TextDecoder().decode(e))}catch{throw t}if(typeof n!=`object`||!n||Array.isArray(n))throw t;let r=new Headers;if(`metadata`in n){if(typeof n.metadata!=`object`||n.metadata==null||Array.isArray(n.metadata))throw t;for(let[e,i]of Object.entries(n.metadata)){if(!Array.isArray(i)||i.some(e=>typeof e!=`string`))throw t;for(let t of i)r.append(e,t)}}return{metadata:r,error:`error`in n&&n.error!=null?Zl(n.error,r,t):void 0}}var $l=`Content-Type`,eu=`Content-Length`,tu=`Content-Encoding`,nu=`Accept-Encoding`,ru=`Connect-Timeout-Ms`,iu=`Connect-Protocol-Version`,au=`User-Agent`;function ou(e){switch(e){case 400:return X.Internal;case 401:return X.Unauthenticated;case 403:return X.PermissionDenied;case 404:return X.Unimplemented;case 429:return X.Unavailable;case 502:return X.Unavailable;case 503:return X.Unavailable;case 504:return X.Unavailable;default:return X.Unknown}}function su(e){let t=new Headers,n=new Headers;return e.forEach((e,r)=>{r.toLowerCase().startsWith(`trailer-`)?n.append(r.substring(8),e):t.append(r,e)}),[t,n]}function cu(e,t,n,r,i){let a=new Headers(r??{});return n!==void 0&&a.set(ru,`${n}`),a.set($l,e==Kc.Unary?t?Kl:ql:t?Jl:Yl),a.set(iu,`1`),i&&a.set(au,`connect-es/1.6.1`),a}function lu(e,t,n,r){let i=r.get($l),a=Xl(i);if(n!==200){let t=new Z(`HTTP ${n}`,ou(n),r);if(e==Kc.Unary&&a&&!a.binary)return{isUnaryError:!0,unaryError:t};throw t}let o={binary:t,stream:e!==Kc.Unary};if(a?.binary!==o.binary||a.stream!==o.stream)throw new Z(`unsupported content type ${i}`,a===void 0?X.Unknown:X.Internal,r);return{isUnaryError:!1}}var uu=`application/`;function du(e,t){return t?Hs.enc(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``):encodeURIComponent(new TextDecoder().decode(e))}function fu(e,t,n){let r=`?connect=v1`,i=e.header.get($l);i?.indexOf(uu)===0&&(r+=`&encoding=`+encodeURIComponent(i.slice(12)));let a=e.header.get(tu);a!==null&&a!==`identity`&&(r+=`&compression=`+encodeURIComponent(a),n=!0),n&&(r+=`&base64=1`),r+=`&message=`+du(t,n);let o=e.url+r,s=new Headers(e.header);return[iu,$l,eu,tu,nu].forEach(e=>s.delete(e)),Object.assign(Object.assign({},e),{init:Object.assign(Object.assign({},e.init),{method:`GET`}),url:o,header:s})}function pu(e){let t=Bl(e.next,e.interceptors),[n,r,i]=hu(e);return t(Object.assign(Object.assign({},e.req),{message:Rl(e.req.method.I,e.req.message),signal:n})).then(e=>(i(),e),r)}function mu(e){let t=Bl(e.next,e.interceptors),[n,r,i]=hu(e),a=Object.assign(Object.assign({},e.req),{message:zl(e.req.method.I,e.req.message),signal:n}),o=!1;return n.addEventListener(`abort`,function(){var t,n;let r=e.req.message[Symbol.asyncIterator]();o||(t=r.throw)==null||t.call(r,this.reason).catch(()=>{}),(n=r.return)==null||n.call(r).catch(()=>{})}),t(a).then(e=>Object.assign(Object.assign({},e),{message:{[Symbol.asyncIterator](){let t=e.message[Symbol.asyncIterator]();return{next(){return t.next().then(e=>(e.done==1&&(o=!0,i()),e),r)}}}}}),r)}function hu(e){let{signal:t,cleanup:n}=Pl(e.timeoutMs),r=Nl(e.signal,t);return[r.signal,function(e){let i=Z.from(t.aborted?Fl(t):e);return r.abort(i),n(),Promise.reject(i)},function(){n(),r.abort()}]}var gu;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.INACTIVE=1]=`INACTIVE`,e[e.PROCESSING=2]=`PROCESSING`,e[e.SUCCESS=3]=`SUCCESS`,e[e.WARNING=4]=`WARNING`,e[e.ERROR=5]=`ERROR`})(gu||={}),Y.util.setEnumType(gu,`exa.language_server_pb.CodeiumState`,[{no:0,name:`CODEIUM_STATE_UNSPECIFIED`},{no:1,name:`CODEIUM_STATE_INACTIVE`},{no:2,name:`CODEIUM_STATE_PROCESSING`},{no:3,name:`CODEIUM_STATE_SUCCESS`},{no:4,name:`CODEIUM_STATE_WARNING`},{no:5,name:`CODEIUM_STATE_ERROR`}]);var _u;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.SINGLE=1]=`SINGLE`,e[e.MULTI=2]=`MULTI`})(_u||={}),Y.util.setEnumType(_u,`exa.language_server_pb.LineType`,[{no:0,name:`LINE_TYPE_UNSPECIFIED`},{no:1,name:`LINE_TYPE_SINGLE`},{no:2,name:`LINE_TYPE_MULTI`}]);var vu;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.INLINE=1]=`INLINE`,e[e.BLOCK=2]=`BLOCK`,e[e.INLINE_MASK=3]=`INLINE_MASK`})(vu||={}),Y.util.setEnumType(vu,`exa.language_server_pb.CompletionPartType`,[{no:0,name:`COMPLETION_PART_TYPE_UNSPECIFIED`},{no:1,name:`COMPLETION_PART_TYPE_INLINE`},{no:2,name:`COMPLETION_PART_TYPE_BLOCK`},{no:3,name:`COMPLETION_PART_TYPE_INLINE_MASK`}]);var yu=class e extends G{threshold=0;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.MultilineConfig`;static fields=Y.util.newFieldList(()=>[{no:1,name:`threshold`,kind:`scalar`,T:2}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},bu=class e extends G{metadata;document;editorOptions;otherDocuments=[];experimentConfig;modelName=``;multilineConfig;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.GetCompletionsRequest`;static fields=Y.util.newFieldList(()=>[{no:1,name:`metadata`,kind:`message`,T:el},{no:2,name:`document`,kind:`message`,T:Du},{no:3,name:`editor_options`,kind:`message`,T:tl},{no:5,name:`other_documents`,kind:`message`,T:Du,repeated:!0},{no:7,name:`experiment_config`,kind:`message`,T:Ou},{no:10,name:`model_name`,kind:`scalar`,T:9},{no:13,name:`multiline_config`,kind:`message`,T:yu}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},xu=class e extends G{state;completionItems=[];constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.GetCompletionsResponse`;static fields=Y.util.newFieldList(()=>[{no:1,name:`state`,kind:`message`,T:ku},{no:2,name:`completion_items`,kind:`message`,T:Nu,repeated:!0}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Su=class e extends G{metadata;completionId=``;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.AcceptCompletionRequest`;static fields=Y.util.newFieldList(()=>[{no:1,name:`metadata`,kind:`message`,T:el},{no:2,name:`completion_id`,kind:`scalar`,T:9}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Cu=class e extends G{constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.AcceptCompletionResponse`;static fields=Y.util.newFieldList(()=>[]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},wu=class e extends G{constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.GetAuthTokenRequest`;static fields=Y.util.newFieldList(()=>[]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Tu=class e extends G{authToken=``;uuid=``;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.GetAuthTokenResponse`;static fields=Y.util.newFieldList(()=>[{no:1,name:`auth_token`,kind:`scalar`,T:9},{no:2,name:`uuid`,kind:`scalar`,T:9}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Eu=class e extends G{row=K.zero;col=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.DocumentPosition`;static fields=Y.util.newFieldList(()=>[{no:1,name:`row`,kind:`scalar`,T:4},{no:2,name:`col`,kind:`scalar`,T:4}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Du=class e extends G{absolutePath=``;relativePath=``;text=``;editorLanguage=``;language=Qc.UNSPECIFIED;cursorOffset=K.zero;cursorPosition;lineEnding=``;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.Document`;static fields=Y.util.newFieldList(()=>[{no:1,name:`absolute_path`,kind:`scalar`,T:9},{no:2,name:`relative_path`,kind:`scalar`,T:9},{no:3,name:`text`,kind:`scalar`,T:9},{no:4,name:`editor_language`,kind:`scalar`,T:9},{no:5,name:`language`,kind:`enum`,T:Y.getEnumType(Qc)},{no:6,name:`cursor_offset`,kind:`scalar`,T:4},{no:8,name:`cursor_position`,kind:`message`,T:Eu},{no:7,name:`line_ending`,kind:`scalar`,T:9}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Ou=class e extends G{forceEnableExperiments=[];constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.ExperimentConfig`;static fields=Y.util.newFieldList(()=>[{no:1,name:`force_enable_experiments`,kind:`enum`,T:Y.getEnumType(Jc),repeated:!0}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},ku=class e extends G{state=gu.UNSPECIFIED;message=``;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.State`;static fields=Y.util.newFieldList(()=>[{no:1,name:`state`,kind:`enum`,T:Y.getEnumType(gu)},{no:2,name:`message`,kind:`scalar`,T:9}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Au=class e extends G{startOffset=K.zero;endOffset=K.zero;startPosition;endPosition;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.Range`;static fields=Y.util.newFieldList(()=>[{no:1,name:`start_offset`,kind:`scalar`,T:4},{no:2,name:`end_offset`,kind:`scalar`,T:4},{no:3,name:`start_position`,kind:`message`,T:Eu},{no:4,name:`end_position`,kind:`message`,T:Eu}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},ju=class e extends G{text=``;deltaCursorOffset=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.Suffix`;static fields=Y.util.newFieldList(()=>[{no:1,name:`text`,kind:`scalar`,T:9},{no:2,name:`delta_cursor_offset`,kind:`scalar`,T:3}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Mu=class e extends G{text=``;offset=K.zero;type=vu.UNSPECIFIED;prefix=``;line=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.CompletionPart`;static fields=Y.util.newFieldList(()=>[{no:1,name:`text`,kind:`scalar`,T:9},{no:2,name:`offset`,kind:`scalar`,T:4},{no:3,name:`type`,kind:`enum`,T:Y.getEnumType(vu)},{no:4,name:`prefix`,kind:`scalar`,T:9},{no:5,name:`line`,kind:`scalar`,T:4}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Nu=class e extends G{completion;suffix;range;source=Zc.UNSPECIFIED;completionParts=[];constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.CompletionItem`;static fields=Y.util.newFieldList(()=>[{no:1,name:`completion`,kind:`message`,T:$c},{no:5,name:`suffix`,kind:`message`,T:ju},{no:2,name:`range`,kind:`message`,T:Au},{no:3,name:`source`,kind:`enum`,T:Y.getEnumType(Zc)},{no:8,name:`completion_parts`,kind:`message`,T:Mu,repeated:!0}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Pu={typeName:`exa.language_server_pb.LanguageServerService`,methods:{getCompletions:{name:`GetCompletions`,I:bu,O:xu,kind:Kc.Unary},acceptCompletion:{name:`AcceptCompletion`,I:Su,O:Cu,kind:Kc.Unary},getAuthToken:{name:`GetAuthToken`,I:wu,O:Tu,kind:Kc.Unary}}};function Fu(){try{new Headers}catch{throw Error(`connect-web requires the fetch API. Are you running on an old version of Node.js? Node.js is not supported in Connect for Web - please stay tuned for Connect for Node.`)}}var Iu=function(e){return this instanceof Iu?(this.v=e,this):new Iu(e)},Lu=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i={},s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof Iu?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}};function Ru(e){Fu();let t=e.useBinaryFormat??!1;return{async unary(n,r,i,a,o,s,c){let{serialize:l,parse:u}=Hl(r,t,e.jsonOptions,e.binaryOptions);return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await pu({interceptors:e.interceptors,signal:i,timeoutMs:a,req:{stream:!1,service:n,method:r,url:Ll(e.baseUrl,n,r),init:{method:`POST`,credentials:e.credentials??`same-origin`,redirect:`error`,mode:`cors`},header:cu(r.kind,t,a,o,!1),contextValues:c??Il(),message:s},next:async i=>{let a=e.useHttpGet===!0&&r.idempotency===qc.NoSideEffects,o=null;a?i=fu(i,l(i.message),t):o=l(i.message);let s=await(e.fetch??globalThis.fetch)(i.url,Object.assign(Object.assign({},i.init),{headers:i.header,signal:i.signal,body:o})),{isUnaryError:c,unaryError:d}=lu(r.kind,t,s.status,s.headers);if(c)throw Zl(await s.json(),pl(...su(s.headers)),d);let[f,p]=su(s.headers);return{stream:!1,service:n,method:r,header:f,message:t?u(new Uint8Array(await s.arrayBuffer())):r.O.fromJson(await s.json(),Vl(e.jsonOptions)),trailer:p}}})},async stream(n,r,i,a,o,s,c){let{serialize:l,parse:u}=Hl(r,t,e.jsonOptions,e.binaryOptions);function d(e,t,n,r){return Lu(this,arguments,function*(){let i=hl(e).getReader(),a=!1;for(;;){let e=yield Iu(i.read());if(e.done)break;let{flags:r,data:o}=e.value;if((r&1)==1)throw new Z(`protocol error: received unsupported compressed output`,X.Internal);if((r&2)==2){a=!0;let e=Ql(o);if(e.error){let t=e.error;throw n.forEach((e,n)=>{t.metadata.append(n,e)}),t}e.metadata.forEach((e,n)=>t.set(n,e));continue}yield yield Iu(u(o))}if(`throwIfAborted`in r&&r.throwIfAborted(),!a)throw`missing EndStreamResponse`})}async function f(e){if(r.kind!=Kc.ServerStreaming)throw`The fetch API does not support streaming request bodies`;let t=await e[Symbol.asyncIterator]().next();if(t.done==1)throw`missing request message`;return gl(0,l(t.value))}return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await mu({interceptors:e.interceptors,timeoutMs:a,signal:i,req:{stream:!0,service:n,method:r,url:Ll(e.baseUrl,n,r),init:{method:`POST`,credentials:e.credentials??`same-origin`,redirect:`error`,mode:`cors`},header:cu(r.kind,t,a,o,!1),contextValues:c??Il(),message:s},next:async n=>{let i=await(e.fetch??globalThis.fetch)(n.url,Object.assign(Object.assign({},n.init),{headers:n.header,signal:n.signal,body:await f(n.message)}));if(lu(r.kind,t,i.status,i.headers),i.body===null)throw`missing response body`;let a=new Headers;return Object.assign(Object.assign({},n),{header:i.headers,trailer:a,message:d(i.body,a,i.headers,n.signal)})}})}}}var zu=Dl(Pu,Ru({baseUrl:`https://web-backend.codeium.com`,useBinaryFormat:!0})),Bu;try{Bu=crypto.randomUUID()}catch{function e(){return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(+e^(crypto.getRandomValues(new Uint8Array(1))[0]??0)&15>>e/4).toString(16))}Bu=e()}async function Vu({text:e,cursorOffset:t,config:n,otherDocuments:r}){return await zu.getCompletions({metadata:{ideName:`web`,ideVersion:`0.0.5`,extensionName:`@valtown/codemirror-codeium`,extensionVersion:`1.0.0`,apiKey:n.apiKey,sessionId:Bu,authSource:n.authSource},document:{text:e,cursorOffset:BigInt(t),language:n.language,editorLanguage:`typescript`,lineEnding:`
|
|
11
|
-
`},editorOptions:{tabSize:2n,insertSpaces:!0},otherDocuments:r,multilineConfig:void 0},{headers:{Authorization:`Basic ${n.apiKey}-${Bu}`}})}function Hu(e){return e.completionItems.map(e=>{let t=0;return e.completionParts.filter(e=>e.type!==3).map(e=>{let n=Number(e.offset),r=e.type===2?`\n${e.text}`:e.text,i={absoluteStartPos:t+n,absoluteEndPos:t+n+r.length,from:n,to:n,insert:r};return t+=r.length,i})})}async function Uu(e,t){let n=e.state.facet(rl),{override:r}=e.state.facet(il),i=await r(),a=e.state,o=a.selection.main.head,s=a.doc.toString();try{let r=await Vu({text:s,cursorOffset:o,config:n,otherDocuments:i});if(!r||r.completionItems.length===0||!((t===void 0||o===t)&&
|
|
9
|
+
`.trim(),n=Zt();await Kt();let r=await fetch(n.getAiURL(`completion`).toString(),{method:`POST`,headers:n.headers(),body:JSON.stringify({prompt:e.prompt,code:t,selectedText:e.selection,includeOtherCode:``,language:e.language})}),i=e.selection.match(/^\s*/)?.[0]||``,a=await ro(r);return a.startsWith(i)||(a=i+a),a}function ao(e){switch(e){case`table`:case`connection`:oe(`variables`),Ui(Hi,`datasources`);return;case`bucket`:oe(`files`),Ui(Vi,`remote-storage`);return;case`cache`:oe(`cache`);return;default:mi(e)}}function oo(e){let{state:t,names:n}=e;if(n.size===0)return[];let r=yr(t);if(!r||w(r))return[];let i=new Map,a=e=>{if(e.name===F.VariableName){let r=t.doc.sliceString(e.from,e.to);n.has(r)&&!i.has(r)&&i.set(r,{from:e.from,to:e.to,name:r});return}if(e.name===F.TupleExpression||e.name===F.ArrayExpression||e.name===F.ParenthesizedExpression)for(let t=e.firstChild;t;t=t.nextSibling)a(t)},o=e=>{let t=-1;for(let n=e.firstChild;n;n=n.nextSibling)n.name===F.AssignOp&&(t=n.from);if(t!==-1)for(let n=e.firstChild;n&&n.from<t;n=n.nextSibling)a(n)},s=e=>{if(!p.has(e.name)){if(e.name===F.AssignStatement){o(e);return}for(let t=e.firstChild;t;t=t.nextSibling)s(t)}};return s(r.topNode),[...i.values()]}var so=/\bmo\.(?:persistent_cache|cache)\b/g;function co(e){let t=e.match(/^[A-Za-z]*("""|'''|"|')([\s\S]*)\1$/);return t?t[2]:e}function lo(e,t){if(!e)return null;let n=e=>e?.name===`,`||e?.name===`)`,r=null;for(let i=e.firstChild;i;i=i.nextSibling)if(i.name!==`(`&&i.name!==`)`&&i.name!==`,`&&(r??=i,i.name===F.VariableName&&t(i)===`name`&&i.nextSibling?.name===F.AssignOp)){let e=i.nextSibling.nextSibling;if(e?.name===F.String&&n(e.nextSibling))return co(t(e))}return r&&r.name===F.String&&n(r.nextSibling)?co(t(r)):null}function uo(e,t,n,r){let i=t=>e.doc.sliceString(t.from,t.to),a=t.resolveInner(n,1),o=null,s=null,c=r,l=null;for(let e=a.parent;e&&e.from===n;e=e.parent)if(e.name===F.CallExpression){l=e;break}if(l){c=l.to,s=l.getChild(F.ArgList);let e=l.parent;if(e?.name===F.AssignStatement){let t=e.getChild(F.VariableName);o=t&&t.from<l.from?i(t):null}else if(e?.name===F.WithStatement){let t=e.firstChild;for(;t;){if(t.from<l.to||t.name===A.As){t=t.nextSibling;continue}t.name===F.VariableName&&(o=i(t));break}}}else if(a.parent?.name===F.Decorator){let e=a.parent,t=e.getChild(F.ArgList);t?.from===r&&(s=t,c=t.to);let n=(e.parent?.getChild(F.FunctionDefinition))?.getChild(F.VariableName);o=n?i(n):null}let u=lo(s,i);return{from:n,to:c,boundName:o,cacheName:u}}function fo(e,t,n){let r=t.resolveInner(n,1);return!E.has(r.name)&&r.name===F.VariableName&&e.doc.sliceString(r.from,r.to)===`mo`}function po(e){let t=yr(e);return!t||w(t)?[]:[...e.doc.toString().matchAll(so)].filter(n=>fo(e,t,n.index??0)).map(n=>{let r=n.index??0;return uo(e,t,r,r+n[0].length)})}function mo(e,t,n){let r=e.get(t);r!==void 0&&r!==n&&It.error(`[code-lens] "${t}" is claimed by both a ${r} and a ${n} entity; keeping ${n}`),e.set(t,n)}var ho=r(e=>{let t=new Map;for(let n of e(re))n.variable_name&&mo(t,n.variable_name,`table`);for(let n of e(O).keys())ne.has(n)||mo(t,n,`connection`);for(let n of e(ve))mo(t,n.name,`bucket`);return t}),go=r(e=>{let t=e(ho),n=e(tt),r=new Map,i=new Map;for(let[e,a]of t){let t=n[e];if(t==null){i.set(e,a);continue}for(let n of t.declaredBy){let t=r.get(n);t||(t=new Map,r.set(n,t)),t.set(e,a)}}return{byCell:r,pending:i}});function _o(e){let{byCell:t,pending:n}=o.get(go),r=new Map(t.get(e));for(let[e,t]of n)r.has(e)||r.set(e,t);return r}var vo=e=>`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${e}</svg>`,yo={table:vo(`<path d="M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18"/>`),connection:vo(`<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 21 19V5"/><path d="M3 12A9 3 0 0 0 21 12"/>`),bucket:vo(`<line x1="22" x2="2" y1="12" y2="12"/><path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/><line x1="6" x2="6.01" y1="16" y2="16"/><line x1="10" x2="10.01" y1="16" y2="16"/>`),cache:vo(`<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 15 21.84"/><path d="M21 5V8"/><path d="M21 12L18 17H22L19 22"/><path d="M3 12A9 3 0 0 0 14.59 14.87"/>`)},bo={table:`Open in data sources`,connection:`Open in data sources`,bucket:`Open in remote storage`,cache:`Open cache panel`},xo=e(_t(),1),So=e(Le(),1),U=tn();function Co(e,t){let n=(0,So.createRoot)(e);return(0,xo.flushSync)(()=>{n.render((0,U.jsx)(s,{store:o,children:(0,U.jsx)(wo,{spec:t})}))}),()=>queueMicrotask(()=>n.unmount())}var wo=e=>{let t=(0,H.c)(9),{spec:n}=e;switch(n.kind){case`table`:{let e;return t[0]===n.name?e=t[1]:(e=(0,U.jsx)(To,{name:n.name}),t[0]=n.name,t[1]=e),e}case`connection`:{let e;return t[2]===n.name?e=t[3]:(e=(0,U.jsx)(Eo,{name:n.name}),t[2]=n.name,t[3]=e),e}case`bucket`:{let e;return t[4]===n.name?e=t[5]:(e=(0,U.jsx)(Do,{name:n.name}),t[4]=n.name,t[5]=e),e}case`cache`:{let e=n.cache?.boundName??null,r=n.cache?.cacheName??null,i;return t[6]!==e||t[7]!==r?(i=(0,U.jsx)(Mo,{boundName:e,cacheName:r}),t[6]=e,t[7]=r,t[8]=i):i=t[8],i}default:mi(n.kind)}},To=e=>{let t=(0,H.c)(5),{name:n}=e,r=i(re),a;if(t[0]!==n||t[1]!==r){let e;t[3]===n?e=t[4]:(e=e=>e.variable_name===n,t[3]=n,t[4]=e);let i=r.find(e);a=i?dt(i):g(`table`),t[0]=n,t[1]=r,t[2]=a}else a=t[2];return a},Eo=e=>{let t=(0,H.c)(5),{name:n}=e,r=i(O),a,o;if(t[0]!==r||t[1]!==n){o=Symbol.for(`react.early_return_sentinel`);bb0:{let e=r.get(n);if(!e){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=g(`database`),t[4]=e):e=t[4],o=e;break bb0}a=j(e)}t[0]=r,t[1]=n,t[2]=a,t[3]=o}else a=t[2],o=t[3];return o===Symbol.for(`react.early_return_sentinel`)?a:o},Do=e=>{let t=(0,H.c)(27),{name:n}=e,r=i(ve),a;if(t[0]!==n||t[1]!==r){let e;t[3]===n?e=t[4]:(e=e=>e.name===n,t[3]=n,t[4]=e),a=r.find(e),t[0]=n,t[1]=r,t[2]=a}else a=t[2];let o=a;if(!o){let e;return t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,U.jsx)(`div`,{className:ht,children:(0,U.jsx)(`span`,{className:`text-xs text-(--slate-11)`,children:`No storage information available.`})}),t[5]=e):e=t[5],e}let s;t[6]===o.protocol?s=t[7]:(s=(0,U.jsx)(qn,{protocol:o.protocol,className:`w-4 h-4`}),t[6]=o.protocol,t[7]=s);let c;t[8]===o.protocol?c=t[9]:(c=(0,U.jsx)(_i,{variant:`outline`,className:`text-xs`,children:o.protocol}),t[8]=o.protocol,t[9]=c);let l;t[10]!==o.displayName||t[11]!==s||t[12]!==c?(l=(0,U.jsx)(pt,{icon:s,title:o.displayName,badge:c}),t[10]=o.displayName,t[11]=s,t[12]=c,t[13]=l):l=t[13];let u;t[14]===o.name?u=t[15]:(u=(0,U.jsx)(_e,{label:`Variable`,value:(0,U.jsx)(`code`,{className:`text-xs bg-(--slate-4) px-1 rounded`,children:o.name})}),t[14]=o.name,t[15]=u);let d=o.rootPath||`(root)`,f;t[16]===d?f=t[17]:(f=(0,U.jsx)(_e,{label:`Root`,value:(0,U.jsx)(`code`,{className:`text-xs bg-(--slate-4) px-1 rounded`,children:d})}),t[16]=d,t[17]=f);let p;t[18]===o.backendType?p=t[19]:(p=(0,U.jsx)(_e,{label:`Backend`,value:(0,U.jsx)(`span`,{className:`font-medium`,children:o.backendType})}),t[18]=o.backendType,t[19]=p);let m;t[20]!==u||t[21]!==f||t[22]!==p?(m=(0,U.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[u,f,p]}),t[20]=u,t[21]=f,t[22]=p,t[23]=m):m=t[23];let h;return t[24]!==l||t[25]!==m?(h=(0,U.jsxs)(`div`,{className:ht,children:[l,m]}),t[24]=l,t[25]=m,t[26]=h):h=t[26],h},Oo=/\bhits=(\d+) misses=(\d+)/,ko=null,Ao=5e3;function jo(){let e=Date.now();ko!=null&&e-ko<Ao||(ko=e,gi().getCacheInfo().catch(()=>{ko=null}))}var Mo=e=>{let t=(0,H.c)(16),{boundName:n,cacheName:r}=e,{locale:a}=bi(),o=i(tt),s=i(Ri),c=n?o[n]:void 0,l;t[0]===c?l=t[1]:(l=c?.dataType?.startsWith(`_cache_call`)?c.value?.match(Oo):void 0,t[0]=c,t[1]=l);let u=l,d=!!u,f,p;t[2]===d?(f=t[3],p=t[4]):(f=()=>{d||jo()},p=[d],t[2]=d,t[3]=f,t[4]=p),(0,V.useEffect)(f,p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,U.jsx)(Wn,{className:`w-4 h-4 text-(--amber-9)`}),t[5]=m):m=t[5];let h=r??n??`Cache`,g;t[6]===h?g=t[7]:(g=(0,U.jsx)(pt,{icon:m,title:h}),t[6]=h,t[7]=g);let _;t[8]!==s||t[9]!==a||t[10]!==u?(_=u?(0,U.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,U.jsx)(_e,{label:`Hits`,value:(0,U.jsx)(`span`,{className:`font-medium`,children:xi(Number(u[1]),a)})}),(0,U.jsx)(_e,{label:`Misses`,value:(0,U.jsx)(`span`,{className:`font-medium`,children:xi(Number(u[2]),a)})})]}):s&&(0,U.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,U.jsx)(`span`,{className:`text-xs font-medium text-(--slate-11)`,children:`Notebook-wide`}),(0,U.jsx)(_e,{label:`Hits`,value:xi(s.hits,a)}),(0,U.jsx)(_e,{label:`Misses`,value:xi(s.misses,a)}),(0,U.jsx)(_e,{label:`Time saved`,value:zi(s.time,a)})]}),t[8]=s,t[9]=a,t[10]=u,t[11]=_):_=t[11];let v;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,U.jsx)(`div`,{className:`pt-2 text-xs text-(--slate-10)`,children:`Click to open the cache panel`}),t[12]=v):v=t[12];let y;return t[13]!==g||t[14]!==_?(y=(0,U.jsxs)(`div`,{className:ht,children:[g,_,v]}),t[13]=g,t[14]=_,t[15]=y):y=t[15],y},No=I.define(),Po=I.define();function Fo(e,t){return e.pos===t.pos&&e.kind===t.kind&&e.name===t.name&&e.cache?.boundName===t.cache?.boundName&&e.cache?.cacheName===t.cache?.cacheName}var Io=class{view;showTimer;hideTimer;constructor(e){this.view=e}enterLens(e,t){this.clearTimers(),Ro(this.view,t);let n=this.view.state.field(Vo,!1);n&&Fo(n.spec,e)||(this.showTimer=window.setTimeout(()=>{this.showTimer=void 0,this.view.dispatch({effects:Po.of(e)})},400))}leave(){this.clearTimers(),this.hideTimer=window.setTimeout(()=>{this.hideTimer=void 0,this.hide()},200)}enterPopover(){window.clearTimeout(this.hideTimer),this.hideTimer=void 0}hide(){this.clearTimers(),this.view.state.field(Vo,!1)&&this.view.dispatch({effects:Po.of(null)})}destroy(){this.clearTimers()}clearTimers(){window.clearTimeout(this.showTimer),window.clearTimeout(this.hideTimer),this.showTimer=void 0,this.hideTimer=void 0}},Lo=Hr.define(e=>new Io(e));function Ro(e,t){e.dom.dispatchEvent(new MouseEvent(`mouseleave`,{relatedTarget:t}))}var zo=class extends Nr{spec;constructor(e){super(),this.spec=e}eq(e){return Fo(this.spec,e.spec)}toDOM(e){let{spec:t}=this,n=document.createElement(`span`);n.className=`mo-code-lens`,n.setAttribute(`role`,`button`),n.tabIndex=0,n.setAttribute(`aria-label`,bo[t.kind]),n.innerHTML=yo[t.kind];let r=()=>e.plugin(Lo),i=()=>r()?.hide();return n.onmouseenter=()=>r()?.enterLens(t,n),n.onmouseleave=()=>r()?.leave(),n.onmousemove=e=>{e.stopPropagation()},n.onmousedown=e=>{e.preventDefault(),e.stopPropagation()},n.onclick=e=>{e.preventDefault(),e.stopPropagation(),i(),ao(t.kind)},n.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),i(),ao(t.kind))},n}ignoreEvent(){return!0}};function Bo(e){return{spec:e,tooltip:{pos:e.pos,above:!0,create:t=>{let n=document.createElement(`div`);return n.classList.add(`mo-cm-tooltip`,`docs-documentation`),n.onmouseenter=()=>t.plugin(Lo)?.enterPopover(),n.onmouseleave=()=>t.plugin(Lo)?.leave(),{dom:n,resize:!1,destroy:Co(n,e)}}}}}var Vo=fr.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(Po))return n.value?Bo(n.value):null;if(n.is(No)&&e)return n.value.some(t=>Fo(t,e.spec))?e:null}return t.docChanged?null:e},provide:e=>_r.from(e,e=>e?.tooltip??null)}),Ho=fr.define({create(){return L.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(No)&&(e=L.set(n.value.map(e=>L.widget({widget:new zo(e),side:1}).range(e.pos)),!0));return e},provide:e=>R.decorations.from(e)}),Uo=class{view;cellId;includeCache;unsubscribes;debounceMs=300;scheduleUpdate;constructor(e,t,n){this.view=e,this.cellId=t,this.includeCache=n,this.scheduleUpdate=Dt(()=>this.run(),this.debounceMs);let r=()=>this.scheduleUpdate();this.unsubscribes=[o.sub(re,r),o.sub(O,r),o.sub(ve,r),o.sub(tt,r)],this.scheduleUpdate()}update(e){let t=e.startState.field(Pe,!1)?.type!==e.state.field(Pe,!1)?.type;(e.docChanged||t)&&this.scheduleUpdate()}destroy(){this.scheduleUpdate.cancel();for(let e of this.unsubscribes)e()}run(){let{state:e}=this.view,t=[],n=e.field(Pe,!1)?.type;if(n==null||n===`python`){let n=_o(this.cellId),r=oo({state:e,names:new Set(n.keys())});for(let e of r){let r=n.get(e.name);r&&t.push({pos:e.to,kind:r,name:e.name})}if(this.includeCache)for(let n of po(e))t.push({pos:n.to,kind:`cache`,name:`cache:${n.from}`,cache:{boundName:n.boundName,cacheName:n.cacheName}})}queueMicrotask(()=>{this.view.dispatch({effects:No.of(t)})})}},Wo=`3px`,Go=R.baseTheme({".mo-code-lens":{display:`inline-flex`,verticalAlign:`baseline`,transform:`translateY(1.5px)`,padding:Wo,margin:`-${Wo} 0 -${Wo} calc(0.3em - ${Wo})`,cursor:`pointer`,opacity:`0.5`},".mo-code-lens:hover":{opacity:`1`}});function Ko(e,t=!0){return t?[Ho,Vo,Lo,Hr.define(t=>new Uo(t,e,fe(`cache_panel`))),Go]:[]}var qo=[`%alias`,`%cd`,`%clear`,`%debug`,`%env`,`%load`,`%load_ext`,`%lsmagic`,`%matplotlib`,`%pwd`,`%who_ls`,`%system`,`%%time`,`%%timeit`,`%%writefile`,`%%capture`,`%%html`,`%%latex`],Jo;function Yo(){let e=async e=>{let t=o.get(Ot),{saveUserConfig:n}=gi();await n({config:{runtime:{auto_reload:e}}}).then(()=>o.set(Ot,{...t,runtime:{...t.runtime,auto_reload:e}}))},t=[{match:`!pip install`,onMatch:()=>{o.set(M,e=>({...e,isSidebarOpen:!0,selectedPanel:`packages`})),wi()},title:`Package Installation`,description:(0,U.jsxs)(U.Fragment,{children:[`The package manager sidebar has been opened.`,(0,U.jsx)(`br`,{}),`Install packages directly from there instead.`]})},{match:`!uv pip install`,onMatch:()=>{o.set(M,e=>({...e,isSidebarOpen:!0,selectedPanel:`packages`})),wi()},title:`Package Installation`,description:(0,U.jsxs)(U.Fragment,{children:[`The package manager sidebar has been opened.`,(0,U.jsx)(`br`,{}),`Install packages directly from there instead.`]})},{match:`!uv add`,onMatch:()=>{o.set(M,e=>({...e,isSidebarOpen:!0,selectedPanel:`packages`})),wi()},title:`Package Installation`,description:(0,U.jsxs)(U.Fragment,{children:[`The package manager sidebar has been opened.`,(0,U.jsx)(`br`,{}),`Install packages directly from there instead.`]})},{match:`%autoreload 2`,onMatch:async()=>{await e(`autorun`)},title:`Module reload`,description:(0,U.jsxs)(U.Fragment,{children:[`Module reload mode set to `,(0,U.jsx)(`b`,{children:`autorun`}),` - module changes will re-run the cells that import them.`]})},{match:`%autoreload 1`,onMatch:async()=>{await e(`lazy`)},title:`Module reload`,description:(0,U.jsxs)(U.Fragment,{children:[`Module reload mode set to `,(0,U.jsx)(`b`,{children:`lazy`}),` - module changes will mark the cells that import them as stale.`]})},{match:`%autoreload 0`,onMatch:async()=>{await e(`off`)},title:`Module reload`,description:(0,U.jsx)(U.Fragment,{children:`Module reload disabled - module changes will not be detected.`})},{match:`!ls`,onMatch:()=>{},title:`Listing files`,description:(0,U.jsxs)(U.Fragment,{children:[`Shell commands are not directly supported.`,(0,U.jsx)(`br`,{}),`Use `,(0,U.jsx)(`code`,{children:`import subprocess; subprocess.run(['ls'])`}),` instead.`]})},...qo.map(e=>({match:e,onMatch:()=>{},title:(0,U.jsx)(Di,{className:`inline`,children:e}),description:(0,U.jsxs)(U.Fragment,{children:[`Magic commands are not supported in marimo. Read more about replacements in the`,` `,(0,U.jsx)(`a`,{href:`https://docs.marimo.io/guides/coming_from/jupyter/#adapting-to-the-absence-of-magic-commands`,target:`_blank`,className:`text-link underline cursor-pointer`,rel:`noopener noreferrer`,children:`documentation`}),`.`]})}))],n=new Map(t.map(e=>[e.match,e]));return R.updateListener.of(e=>{if(e.docChanged){let t=e.state.selection.main,r=e.state.doc,i=r.lineAt(t.head),a=r.sliceString(i.from,t.anchor).trim(),o=n.get(a);o&&(o.onMatch(),Jo?Jo.upsert({title:o.title,description:o.description}):Jo=ur({title:o.title,description:o.description}))}})}var Xo=new Set([`Escape`,"Alt-`"]);function Zo(e,t=Xo){return e.filter(e=>![e.key,e.mac,e.linux,e.win].some(e=>t.has(e)))}function Qo(e=!0){let t=new Set(Xo);e||t.add(`Enter`);let n=Zo(oi,t);return Sr.highest(gr.of([...n,{key:`Ctrl-y`,run:e=>v(e)?di(e):!1},{key:`Ctrl-n`,run:e=>v(e)?si(!0)(e):!1},{key:`Ctrl-p`,run:e=>v(e)?si(!1)(e):!1}]))}var $o=I.define(),es=I.define(),ts=I.define();function W(e,t){if(!e)throw Error(t)}var ns=34028234663852886e22,rs=-34028234663852886e22,is=4294967295,as=2147483647,os=-2147483648;function ss(e){if(typeof e!=`number`)throw Error(`invalid int 32: `+typeof e);if(!Number.isInteger(e)||e>as||e<os)throw Error(`invalid int 32: `+e)}function cs(e){if(typeof e!=`number`)throw Error(`invalid uint 32: `+typeof e);if(!Number.isInteger(e)||e>is||e<0)throw Error(`invalid uint 32: `+e)}function ls(e){if(typeof e!=`number`)throw Error(`invalid float 32: `+typeof e);if(Number.isFinite(e)&&(e>ns||e<rs))throw Error(`invalid float 32: `+e)}var us=Symbol(`@bufbuild/protobuf/enum-type`);function ds(e){let t=e[us];return W(t,`missing enum type on enum object`),t}function fs(e,t,n,r){e[us]=ps(t,n.map(t=>({no:t.no,name:t.name,localName:e[t.no]})),r)}function ps(e,t,n){let r=Object.create(null),i=Object.create(null),a=[];for(let e of t){let t=hs(e);a.push(t),r[e.name]=t,i[e.no]=t}return{typeName:e,values:a,findName(e){return r[e]},findNumber(e){return i[e]}}}function ms(e,t,n){let r={};for(let e of t){let t=hs(e);r[t.localName]=t.no,r[t.no]=t.localName}return fs(r,e,t,n),r}function hs(e){return`localName`in e?e:Object.assign(Object.assign({},e),{localName:e.name})}var G=class{equals(e){return this.getType().runtime.util.equals(this.getType(),this,e)}clone(){return this.getType().runtime.util.clone(this)}fromBinary(e,t){let n=this.getType().runtime.bin,r=n.makeReadOptions(t);return n.readMessage(this,r.readerFactory(e),e.byteLength,r),this}fromJson(e,t){let n=this.getType(),r=n.runtime.json,i=r.makeReadOptions(t);return r.readMessage(n,e,i,this),this}fromJsonString(e,t){let n;try{n=JSON.parse(e)}catch(e){throw Error(`cannot decode ${this.getType().typeName} from JSON: ${e instanceof Error?e.message:String(e)}`)}return this.fromJson(n,t)}toBinary(e){let t=this.getType().runtime.bin,n=t.makeWriteOptions(e),r=n.writerFactory();return t.writeMessage(this,r,n),r.finish()}toJson(e){let t=this.getType().runtime.json,n=t.makeWriteOptions(e);return t.writeMessage(this,n)}toJsonString(e){let t=this.toJson(e);return JSON.stringify(t,null,e?.prettySpaces??0)}toJSON(){return this.toJson({emitDefaultValues:!0})}getType(){return Object.getPrototypeOf(this).constructor}};function gs(e,t,n,r){let i=r?.localName??t.substring(t.lastIndexOf(`.`)+1),a={[i]:function(t){e.util.initFields(this),e.util.initPartial(t,this)}}[i];return Object.setPrototypeOf(a.prototype,new G),Object.assign(a,{runtime:e,typeName:t,fields:e.util.newFieldList(n),fromBinary(e,t){return new a().fromBinary(e,t)},fromJson(e,t){return new a().fromJson(e,t)},fromJsonString(e,t){return new a().fromJsonString(e,t)},equals(t,n){return e.util.equals(a,t,n)}}),a}function _s(){let e=0,t=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<n,!(r&128))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(n&15)<<28,t=(n&112)>>4,!(n&128))return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(t|=(r&127)<<n,!(r&128))return this.assertBounds(),[e,t]}throw Error(`invalid varint`)}function vs(e,t,n){for(let r=0;r<28;r+=7){let i=e>>>r,a=!(!(i>>>7)&&t==0),o=(a?i|128:i)&255;if(n.push(o),!a)return}let r=e>>>28&15|(t&7)<<4,i=!!(t>>3);if(n.push((i?r|128:r)&255),i){for(let e=3;e<31;e+=7){let r=t>>>e,i=!!(r>>>7),a=(i?r|128:r)&255;if(n.push(a),!i)return}n.push(t>>>31&1)}}var ys=4294967296;function bs(e){let t=e[0]===`-`;t&&(e=e.slice(1));let n=1e6,r=0,i=0;function a(t,a){let o=Number(e.slice(t,a));i*=n,r=r*n+o,r>=ys&&(i+=r/ys|0,r%=ys)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?Ts(r,i):ws(r,i)}function xs(e,t){let n=ws(e,t),r=n.hi&2147483648;r&&(n=Ts(n.lo,n.hi));let i=Ss(n.lo,n.hi);return r?`-`+i:i}function Ss(e,t){if({lo:e,hi:t}=Cs(e,t),t<=2097151)return String(ys*t+e);let n=e&16777215,r=(e>>>24|t<<8)&16777215,i=t>>16&65535,a=n+r*6777216+i*6710656,o=r+i*8147497,s=i*2,c=1e7;return a>=c&&(o+=Math.floor(a/c),a%=c),o>=c&&(s+=Math.floor(o/c),o%=c),s.toString()+Es(o)+Es(a)}function Cs(e,t){return{lo:e>>>0,hi:t>>>0}}function ws(e,t){return{lo:e|0,hi:t|0}}function Ts(e,t){return t=~t,e?e=~e+1:t+=1,ws(e,t)}var Es=e=>{let t=String(e);return`0000000`.slice(t.length)+t};function Ds(e,t){if(e>=0){for(;e>127;)t.push(e&127|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(e&127|128),e>>=7;t.push(1)}}function Os(){let e=this.buf[this.pos++],t=e&127;if(!(e&128)||(e=this.buf[this.pos++],t|=(e&127)<<7,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<14,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<21,!(e&128)))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let t=5;e&128&&t<10;t++)e=this.buf[this.pos++];if(e&128)throw Error(`invalid varint`);return this.assertBounds(),t>>>0}function ks(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt==`function`&&typeof e.getBigInt64==`function`&&typeof e.getBigUint64==`function`&&typeof e.setBigInt64==`function`&&typeof e.setBigUint64==`function`&&(typeof process!=`object`||{}.BUF_BIGINT_DISABLE!==`1`)){let t=BigInt(`-9223372036854775808`),n=BigInt(`9223372036854775807`),r=BigInt(`0`),i=BigInt(`18446744073709551615`);return{zero:BigInt(0),supported:!0,parse(e){let r=typeof e==`bigint`?e:BigInt(e);if(r>n||r<t)throw Error(`int64 invalid: ${e}`);return r},uParse(e){let t=typeof e==`bigint`?e:BigInt(e);if(t>i||t<r)throw Error(`uint64 invalid: ${e}`);return t},enc(t){return e.setBigInt64(0,this.parse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(t){return e.setBigInt64(0,this.uParse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigInt64(0,!0)},uDec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigUint64(0,!0)}}}let t=e=>W(/^-?[0-9]+$/.test(e),`int64 invalid: ${e}`),n=e=>W(/^[0-9]+$/.test(e),`uint64 invalid: ${e}`);return{zero:`0`,supported:!1,parse(e){return typeof e!=`string`&&(e=e.toString()),t(e),e},uParse(e){return typeof e!=`string`&&(e=e.toString()),n(e),e},enc(e){return typeof e!=`string`&&(e=e.toString()),t(e),bs(e)},uEnc(e){return typeof e!=`string`&&(e=e.toString()),n(e),bs(e)},dec(e,t){return xs(e,t)},uDec(e,t){return Ss(e,t)}}}var K=ks(),q;(function(e){e[e.DOUBLE=1]=`DOUBLE`,e[e.FLOAT=2]=`FLOAT`,e[e.INT64=3]=`INT64`,e[e.UINT64=4]=`UINT64`,e[e.INT32=5]=`INT32`,e[e.FIXED64=6]=`FIXED64`,e[e.FIXED32=7]=`FIXED32`,e[e.BOOL=8]=`BOOL`,e[e.STRING=9]=`STRING`,e[e.BYTES=12]=`BYTES`,e[e.UINT32=13]=`UINT32`,e[e.SFIXED32=15]=`SFIXED32`,e[e.SFIXED64=16]=`SFIXED64`,e[e.SINT32=17]=`SINT32`,e[e.SINT64=18]=`SINT64`})(q||={});var As;(function(e){e[e.BIGINT=0]=`BIGINT`,e[e.STRING=1]=`STRING`})(As||={});function js(e,t,n){if(t===n)return!0;if(e==q.BYTES){if(!(t instanceof Uint8Array)||!(n instanceof Uint8Array)||t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}switch(e){case q.UINT64:case q.FIXED64:case q.INT64:case q.SFIXED64:case q.SINT64:return t==n}return!1}function Ms(e,t){switch(e){case q.BOOL:return!1;case q.UINT64:case q.FIXED64:case q.INT64:case q.SFIXED64:case q.SINT64:return t==0?K.zero:`0`;case q.DOUBLE:case q.FLOAT:return 0;case q.BYTES:return new Uint8Array;case q.STRING:return``;default:return 0}}function Ns(e,t){switch(e){case q.BOOL:return t===!1;case q.STRING:return t===``;case q.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return t==0}}var J;(function(e){e[e.Varint=0]=`Varint`,e[e.Bit64=1]=`Bit64`,e[e.LengthDelimited=2]=`LengthDelimited`,e[e.StartGroup=3]=`StartGroup`,e[e.EndGroup=4]=`EndGroup`,e[e.Bit32=5]=`Bit32`})(J||={});var Ps=class{constructor(e){this.stack=[],this.textEncoder=e??new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let t=0;t<this.chunks.length;t++)e+=this.chunks[t].length;let t=new Uint8Array(e),n=0;for(let e=0;e<this.chunks.length;e++)t.set(this.chunks[e],n),n+=this.chunks[e].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw Error(`invalid state, fork stack empty`);return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(cs(e);e>127;)this.buf.push(e&127|128),e>>>=7;return this.buf.push(e),this}int32(e){return ss(e),Ds(e,this.buf),this}bool(e){return this.buf.push(+!!e),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){ls(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){cs(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){ss(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return ss(e),e=(e<<1^e>>31)>>>0,Ds(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=K.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=K.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=K.enc(e);return vs(t.lo,t.hi,this.buf),this}sint64(e){let t=K.enc(e),n=t.hi>>31;return vs(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=K.uEnc(e);return vs(t.lo,t.hi,this.buf),this}},Fs=class{constructor(e,t){this.varint64=_s,this.uint32=Os,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t??new TextDecoder}tag(){let e=this.uint32(),t=e>>>3,n=e&7;if(t<=0||n<0||n>5)throw Error(`illegal tag: field no `+t+` wire type `+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case J.Varint:for(;this.buf[this.pos++]&128;);break;case J.Bit64:this.pos+=4;case J.Bit32:this.pos+=4;break;case J.LengthDelimited:let n=this.uint32();this.pos+=n;break;case J.StartGroup:for(;;){let[e,n]=this.tag();if(n===J.EndGroup){if(t!==void 0&&e!==t)throw Error(`invalid end group tag`);break}this.skip(n,e)}break;default:throw Error(`cant skip wire type `+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw RangeError(`premature EOF`)}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return K.dec(...this.varint64())}uint64(){return K.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,K.dec(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return K.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return K.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}};function Is(e,t,n,r){let i;return{typeName:t,extendee:n,get field(){if(!i){let n=typeof r==`function`?r():r;n.name=t.split(`.`).pop(),n.jsonName=`[${t}]`,i=e.util.newFieldList([n]).list()[0]}return i},runtime:e}}function Ls(e){let t=e.field.localName,n=Object.create(null);return n[t]=Rs(e),[n,()=>n[t]]}function Rs(e){let t=e.field;if(t.repeated)return[];if(t.default!==void 0)return t.default;switch(t.kind){case`enum`:return t.T.values[0].no;case`scalar`:return Ms(t.T,t.L);case`message`:let e=t.T,n=new e;return e.fieldWrapper?e.fieldWrapper.unwrapField(n):n;case`map`:throw`map fields are not allowed to be extensions`}}function zs(e,t){if(!t.repeated&&(t.kind==`enum`||t.kind==`scalar`)){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.no)return[e[n]];return[]}return e.filter(e=>e.no===t.no)}var Bs=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),Vs=[];for(let e=0;e<Bs.length;e++)Vs[Bs[e].charCodeAt(0)]=e;Vs[45]=Bs.indexOf(`+`),Vs[95]=Bs.indexOf(`/`);var Hs={dec(e){let t=e.length*3/4;e[e.length-2]==`=`?t-=2:e[e.length-1]==`=`&&--t;let n=new Uint8Array(t),r=0,i=0,a,o=0;for(let t=0;t<e.length;t++){if(a=Vs[e.charCodeAt(t)],a===void 0)switch(e[t]){case`=`:i=0;case`
|
|
10
|
+
`:case`\r`:case` `:case` `:continue;default:throw Error(`invalid base64 string.`)}switch(i){case 0:o=a,i=1;break;case 1:n[r++]=o<<2|(a&48)>>4,o=a,i=2;break;case 2:n[r++]=(o&15)<<4|(a&60)>>2,o=a,i=3;break;case 3:n[r++]=(o&3)<<6|a,i=0}}if(i==1)throw Error(`invalid base64 string.`);return n.subarray(0,r)},enc(e){let t=``,n=0,r,i=0;for(let a=0;a<e.length;a++)switch(r=e[a],n){case 0:t+=Bs[r>>2],i=(r&3)<<4,n=1;break;case 1:t+=Bs[i|r>>4],i=(r&15)<<2,n=2;break;case 2:t+=Bs[i|r>>6],t+=Bs[r&63],n=0}return n&&(t+=Bs[i],t+=`=`,n==1&&(t+=`=`)),t}};function Us(e,t,n){Ks(t,e);let r=t.runtime.bin.makeReadOptions(n),i=zs(e.getType().runtime.bin.listUnknownFields(e),t.field),[a,o]=Ls(t);for(let e of i)t.runtime.bin.readField(a,r.readerFactory(e.data),t.field,e.wireType,r);return o()}function Ws(e,t,n,r){Ks(t,e);let i=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(Gs(e,t)){let n=e.getType().runtime.bin.listUnknownFields(e).filter(e=>e.no!=t.field.no);e.getType().runtime.bin.discardUnknownFields(e);for(let t of n)e.getType().runtime.bin.onUnknownField(e,t.no,t.wireType,t.data)}let o=a.writerFactory(),s=t.field;!s.opt&&!s.repeated&&(s.kind==`enum`||s.kind==`scalar`)&&(s=Object.assign(Object.assign({},t.field),{opt:!0})),t.runtime.bin.writeField(s,n,o,a);let c=i.readerFactory(o.finish());for(;c.pos<c.len;){let[t,n]=c.tag(),r=c.skip(n,t);e.getType().runtime.bin.onUnknownField(e,t,n,r)}}function Gs(e,t){let n=e.getType();return t.extendee.typeName===n.typeName&&!!n.runtime.bin.listUnknownFields(e).find(e=>e.no==t.field.no)}function Ks(e,t){W(e.extendee.typeName==t.getType().typeName,`extension ${e.typeName} can only be applied to message ${e.extendee.typeName}`)}function qs(e,t){let n=e.localName;if(e.repeated)return t[n].length>0;if(e.oneof)return t[e.oneof.localName].case===n;switch(e.kind){case`enum`:case`scalar`:return e.opt||e.req?t[n]!==void 0:e.kind==`enum`?t[n]!==e.T.values[0].no:!Ns(e.T,t[n]);case`message`:return t[n]!==void 0;case`map`:return Object.keys(t[n]).length>0}}function Js(e,t){let n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case`map`:t[n]={};break;case`enum`:t[n]=r?e.T.values[0].no:void 0;break;case`scalar`:t[n]=r?Ms(e.T,e.L):void 0;break;case`message`:t[n]=void 0}}function Ys(e,t){if(typeof e!=`object`||!e||!Object.getOwnPropertyNames(G.prototype).every(t=>t in e&&typeof e[t]==`function`))return!1;let n=e.getType();return n===null||typeof n!=`function`||!(`typeName`in n)||typeof n.typeName!=`string`?!1:t===void 0||n.typeName==t.typeName}function Xs(e,t){return Ys(t)||!e.fieldWrapper?t:e.fieldWrapper.wrapField(t)}q.DOUBLE,q.FLOAT,q.INT64,q.UINT64,q.INT32,q.UINT32,q.BOOL,q.STRING,q.BYTES;var Zs={ignoreUnknownFields:!1},Qs={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function $s(e){return e?Object.assign(Object.assign({},Zs),e):Zs}function ec(e){return e?Object.assign(Object.assign({},Qs),e):Qs}var tc=Symbol(),nc=Symbol();function rc(){return{makeReadOptions:$s,makeWriteOptions:ec,readMessage(e,t,n,r){if(t==null||Array.isArray(t)||typeof t!=`object`)throw Error(`cannot decode message ${e.typeName} from JSON: ${ic(t)}`);r??=new e;let i=new Map,a=n.typeRegistry;for(let[o,s]of Object.entries(t)){let t=e.fields.findJsonName(o);if(t){if(t.oneof){if(s===null&&t.kind==`scalar`)continue;let n=i.get(t.oneof);if(n!==void 0)throw Error(`cannot decode message ${e.typeName} from JSON: multiple keys for oneof "${t.oneof.name}" present: "${n}", "${o}"`);i.set(t.oneof,o)}ac(r,s,t,n,e)}else{let t=!1;if(a?.findExtension&&o.startsWith(`[`)&&o.endsWith(`]`)){let i=a.findExtension(o.substring(1,o.length-1));if(i&&i.extendee.typeName==e.typeName){t=!0;let[e,a]=Ls(i);ac(e,s,i.field,n,i),Ws(r,i,a(),n)}}if(!t&&!n.ignoreUnknownFields)throw Error(`cannot decode message ${e.typeName} from JSON: key "${o}" is unknown`)}}return r},writeMessage(e,t){let n=e.getType(),r={},i;try{for(i of n.fields.byNumber()){if(!qs(i,e)){if(i.req)throw`required field not set`;if(!t.emitDefaultValues||!lc(i))continue}let n=i.oneof?e[i.oneof.localName].value:e[i.localName],a=uc(i,n,t);a!==void 0&&(r[t.useProtoFieldName?i.name:i.jsonName]=a)}let a=t.typeRegistry;if(a?.findExtensionFor)for(let i of n.runtime.bin.listUnknownFields(e)){let o=a.findExtensionFor(n.typeName,i.no);if(o&&Gs(e,o)){let n=Us(e,o,t),i=uc(o.field,n,t);i!==void 0&&(r[o.field.jsonName]=i)}}}catch(e){let t=i?`cannot encode field ${n.typeName}.${i.name} to JSON`:`cannot encode message ${n.typeName} to JSON`,r=e instanceof Error?e.message:String(e);throw Error(t+(r.length>0?`: ${r}`:``))}return r},readScalar(e,t,n){return sc(e,t,n??As.BIGINT,!0)},writeScalar(e,t,n){if(t!==void 0&&(n||Ns(e,t)))return fc(e,t)},debug:ic}}function ic(e){if(e===null)return`null`;switch(typeof e){case`object`:return Array.isArray(e)?`array`:`object`;case`string`:return e.length>100?`string`:`"${e.split(`"`).join(`\\"`)}"`;default:return String(e)}}function ac(e,t,n,r,i){let a=n.localName;if(n.repeated){if(W(n.kind!=`map`),t===null)return;if(!Array.isArray(t))throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(t)}`);let o=e[a];for(let e of t){if(e===null)throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(e)}`);switch(n.kind){case`message`:o.push(n.T.fromJson(e,r));break;case`enum`:let t=cc(n.T,e,r.ignoreUnknownFields,!0);t!==nc&&o.push(t);break;case`scalar`:try{o.push(sc(n.T,e,n.L,!0))}catch(t){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(e)}`;throw t instanceof Error&&t.message.length>0&&(r+=`: ${t.message}`),Error(r)}}}}else if(n.kind==`map`){if(t===null)return;if(typeof t!=`object`||Array.isArray(t))throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(t)}`);let o=e[a];for(let[e,a]of Object.entries(t)){if(a===null)throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: map value null`);let s;try{s=oc(n.K,e)}catch(e){let r=`cannot decode map key for field ${i.typeName}.${n.name} from JSON: ${ic(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}switch(n.V.kind){case`message`:o[s]=n.V.T.fromJson(a,r);break;case`enum`:let e=cc(n.V.T,a,r.ignoreUnknownFields,!0);e!==nc&&(o[s]=e);break;case`scalar`:try{o[s]=sc(n.V.T,a,As.BIGINT,!0)}catch(e){let r=`cannot decode map value for field ${i.typeName}.${n.name} from JSON: ${ic(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}}}}else switch(n.oneof&&(e=e[n.oneof.localName]={case:a},a=`value`),n.kind){case`message`:let o=n.T;if(t===null&&o.typeName!=`google.protobuf.Value`)return;let s=e[a];Ys(s)?s.fromJson(t,r):(e[a]=s=o.fromJson(t,r),o.fieldWrapper&&!n.oneof&&(e[a]=o.fieldWrapper.unwrapField(s)));break;case`enum`:let c=cc(n.T,t,r.ignoreUnknownFields,!1);switch(c){case tc:Js(n,e);break;case nc:break;default:e[a]=c}break;case`scalar`:try{let r=sc(n.T,t,n.L,!1);switch(r){case tc:Js(n,e);break;default:e[a]=r}}catch(e){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${ic(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}}}function oc(e,t){if(e===q.BOOL)switch(t){case`true`:t=!0;break;case`false`:t=!1}return sc(e,t,As.BIGINT,!0).toString()}function sc(e,t,n,r){if(t===null)return r?Ms(e,n):tc;switch(e){case q.DOUBLE:case q.FLOAT:if(t===`NaN`)return NaN;if(t===`Infinity`)return 1/0;if(t===`-Infinity`)return-1/0;if(t===``||typeof t==`string`&&t.trim().length!==t.length||typeof t!=`string`&&typeof t!=`number`)break;let r=Number(t);if(Number.isNaN(r)||!Number.isFinite(r))break;return e==q.FLOAT&&ls(r),r;case q.INT32:case q.FIXED32:case q.SFIXED32:case q.SINT32:case q.UINT32:let i;if(typeof t==`number`?i=t:typeof t==`string`&&t.length>0&&t.trim().length===t.length&&(i=Number(t)),i===void 0)break;return e==q.UINT32||e==q.FIXED32?cs(i):ss(i),i;case q.INT64:case q.SFIXED64:case q.SINT64:if(typeof t!=`number`&&typeof t!=`string`)break;let a=K.parse(t);return n?a.toString():a;case q.FIXED64:case q.UINT64:if(typeof t!=`number`&&typeof t!=`string`)break;let o=K.uParse(t);return n?o.toString():o;case q.BOOL:if(typeof t!=`boolean`)break;return t;case q.STRING:if(typeof t!=`string`)break;return t;case q.BYTES:if(t===``)return new Uint8Array;if(typeof t!=`string`)break;return Hs.dec(t)}throw Error()}function cc(e,t,n,r){if(t===null)return e.typeName==`google.protobuf.NullValue`?0:r?e.values[0].no:tc;switch(typeof t){case`number`:if(Number.isInteger(t))return t;break;case`string`:let r=e.findName(t);if(r!==void 0)return r.no;if(n)return nc}throw Error(`cannot decode enum ${e.typeName} from JSON: ${ic(t)}`)}function lc(e){return e.repeated||e.kind==`map`?!0:!(e.oneof||e.kind==`message`||e.opt||e.req)}function uc(e,t,n){if(e.kind==`map`){W(typeof t==`object`&&!!t);let r={},i=Object.entries(t);switch(e.V.kind){case`scalar`:for(let[t,n]of i)r[t.toString()]=fc(e.V.T,n);break;case`message`:for(let[e,t]of i)r[e.toString()]=t.toJson(n);break;case`enum`:let t=e.V.T;for(let[e,a]of i)r[e.toString()]=dc(t,a,n.enumAsInteger)}return n.emitDefaultValues||i.length>0?r:void 0}if(e.repeated){W(Array.isArray(t));let r=[];switch(e.kind){case`scalar`:for(let n=0;n<t.length;n++)r.push(fc(e.T,t[n]));break;case`enum`:for(let i=0;i<t.length;i++)r.push(dc(e.T,t[i],n.enumAsInteger));break;case`message`:for(let e=0;e<t.length;e++)r.push(t[e].toJson(n))}return n.emitDefaultValues||r.length>0?r:void 0}switch(e.kind){case`scalar`:return fc(e.T,t);case`enum`:return dc(e.T,t,n.enumAsInteger);case`message`:return Xs(e.T,t).toJson(n)}}function dc(e,t,n){return W(typeof t==`number`),e.typeName==`google.protobuf.NullValue`?null:n?t:e.findNumber(t)?.name??t}function fc(e,t){switch(e){case q.INT32:case q.SFIXED32:case q.SINT32:case q.FIXED32:case q.UINT32:return W(typeof t==`number`),t;case q.FLOAT:case q.DOUBLE:return W(typeof t==`number`),Number.isNaN(t)?`NaN`:t===1/0?`Infinity`:t===-1/0?`-Infinity`:t;case q.STRING:return W(typeof t==`string`),t;case q.BOOL:return W(typeof t==`boolean`),t;case q.UINT64:case q.FIXED64:case q.INT64:case q.SFIXED64:case q.SINT64:return W(typeof t==`bigint`||typeof t==`string`||typeof t==`number`),t.toString();case q.BYTES:return W(t instanceof Uint8Array),Hs.enc(t)}}var pc=Symbol(`@bufbuild/protobuf/unknown-fields`),mc={readUnknownFields:!0,readerFactory:e=>new Fs(e)},hc={writeUnknownFields:!0,writerFactory:()=>new Ps};function gc(e){return e?Object.assign(Object.assign({},mc),e):mc}function _c(e){return e?Object.assign(Object.assign({},hc),e):hc}function vc(){return{makeReadOptions:gc,makeWriteOptions:_c,listUnknownFields(e){return e[pc]??[]},discardUnknownFields(e){delete e[pc]},writeUnknownFields(e,t){let n=e[pc];if(n)for(let e of n)t.tag(e.no,e.wireType).raw(e.data)},onUnknownField(e,t,n,r){let i=e;Array.isArray(i[pc])||(i[pc]=[]),i[pc].push({no:t,wireType:n,data:r})},readMessage(e,t,n,r,i){let a=e.getType(),o=i?t.len:t.pos+n,s,c;for(;t.pos<o&&([s,c]=t.tag(),i!==!0||c!=J.EndGroup);){let n=a.fields.find(s);if(!n){let n=t.skip(c,s);r.readUnknownFields&&this.onUnknownField(e,s,c,n);continue}yc(e,t,n,c,r)}if(i&&(c!=J.EndGroup||s!==n))throw Error(`invalid end group tag`)},readField:yc,writeMessage(e,t,n){let r=e.getType();for(let i of r.fields.byNumber()){if(!qs(i,e)){if(i.req)throw Error(`cannot encode field ${r.typeName}.${i.name} to binary: required field not set`);continue}wc(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t,n)}return n.writeUnknownFields&&this.writeUnknownFields(e,t),t},writeField(e,t,n,r){t!==void 0&&wc(e,t,n,r)}}}function yc(e,t,n,r,i){let{repeated:a,localName:o}=n;switch(n.oneof&&(e=e[n.oneof.localName],e.case!=o&&delete e.value,e.case=o,o=`value`),n.kind){case`scalar`:case`enum`:let s=n.kind==`enum`?q.INT32:n.T,c=Cc;if(n.kind==`scalar`&&n.L>0&&(c=Sc),a){let n=e[o];if(r==J.LengthDelimited&&s!=q.STRING&&s!=q.BYTES){let e=t.uint32()+t.pos;for(;t.pos<e;)n.push(c(t,s))}else n.push(c(t,s))}else e[o]=c(t,s);break;case`message`:let l=n.T;a?e[o].push(bc(t,new l,i,n)):Ys(e[o])?bc(t,e[o],i,n):(e[o]=bc(t,new l,i,n),l.fieldWrapper&&!n.oneof&&!n.repeated&&(e[o]=l.fieldWrapper.unwrapField(e[o])));break;case`map`:let[u,d]=xc(n,t,i);e[o][u]=d}}function bc(e,t,n,r){let i=t.getType().runtime.bin,a=r?.delimited;return i.readMessage(t,e,a?r.no:e.uint32(),n,a),t}function xc(e,t,n){let r=t.uint32(),i=t.pos+r,a,o;for(;t.pos<i;){let[r]=t.tag();switch(r){case 1:a=Cc(t,e.K);break;case 2:switch(e.V.kind){case`scalar`:o=Cc(t,e.V.T);break;case`enum`:o=t.int32();break;case`message`:o=bc(t,new e.V.T,n,void 0)}}}if(a===void 0&&(a=Ms(e.K,As.BIGINT)),typeof a!=`string`&&typeof a!=`number`&&(a=a.toString()),o===void 0)switch(e.V.kind){case`scalar`:o=Ms(e.V.T,As.BIGINT);break;case`enum`:o=e.V.T.values[0].no;break;case`message`:o=new e.V.T}return[a,o]}function Sc(e,t){let n=Cc(e,t);return typeof n==`bigint`?n.toString():n}function Cc(e,t){switch(t){case q.STRING:return e.string();case q.BOOL:return e.bool();case q.DOUBLE:return e.double();case q.FLOAT:return e.float();case q.INT32:return e.int32();case q.INT64:return e.int64();case q.UINT64:return e.uint64();case q.FIXED64:return e.fixed64();case q.BYTES:return e.bytes();case q.FIXED32:return e.fixed32();case q.SFIXED32:return e.sfixed32();case q.SFIXED64:return e.sfixed64();case q.SINT64:return e.sint64();case q.UINT32:return e.uint32();case q.SINT32:return e.sint32()}}function wc(e,t,n,r){W(t!==void 0);let i=e.repeated;switch(e.kind){case`scalar`:case`enum`:let a=e.kind==`enum`?q.INT32:e.T;if(i){if(W(Array.isArray(t)),e.packed)Oc(n,a,e.no,t);else for(let r of t)Dc(n,a,e.no,r)}else Dc(n,a,e.no,t);break;case`message`:if(i){W(Array.isArray(t));for(let i of t)Ec(n,r,e,i)}else Ec(n,r,e,t);break;case`map`:W(typeof t==`object`&&!!t);for(let[i,a]of Object.entries(t))Tc(n,r,e,i,a)}}function Tc(e,t,n,r,i){e.tag(n.no,J.LengthDelimited),e.fork();let a=r;switch(n.K){case q.INT32:case q.FIXED32:case q.UINT32:case q.SFIXED32:case q.SINT32:a=Number.parseInt(r);break;case q.BOOL:W(r==`true`||r==`false`),a=r==`true`}switch(Dc(e,n.K,1,a),n.V.kind){case`scalar`:Dc(e,n.V.T,2,i);break;case`enum`:Dc(e,q.INT32,2,i);break;case`message`:W(i!==void 0),e.tag(2,J.LengthDelimited).bytes(i.toBinary(t))}e.join()}function Ec(e,t,n,r){let i=Xs(n.T,r);n.delimited?e.tag(n.no,J.StartGroup).raw(i.toBinary(t)).tag(n.no,J.EndGroup):e.tag(n.no,J.LengthDelimited).bytes(i.toBinary(t))}function Dc(e,t,n,r){W(r!==void 0);let[i,a]=kc(t);e.tag(n,i)[a](r)}function Oc(e,t,n,r){if(!r.length)return;e.tag(n,J.LengthDelimited).fork();let[,i]=kc(t);for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}function kc(e){let t=J.Varint;switch(e){case q.BYTES:case q.STRING:t=J.LengthDelimited;break;case q.DOUBLE:case q.FIXED64:case q.SFIXED64:t=J.Bit64;break;case q.FIXED32:case q.SFIXED32:case q.FLOAT:t=J.Bit32}let n=q[e].toLowerCase();return[t,n]}function Ac(){return{setEnumType:fs,initPartial(e,t){if(e===void 0)return;let n=t.getType();for(let r of n.fields.byMember()){let n=r.localName,i=t,a=e;if(a[n]!=null)switch(r.kind){case`oneof`:let e=a[n].case;if(e===void 0)continue;let t=r.findField(e),o=a[n].value;t&&t.kind==`message`&&!Ys(o,t.T)?o=new t.T(o):t&&t.kind===`scalar`&&t.T===q.BYTES&&(o=Mc(o)),i[n]={case:e,value:o};break;case`scalar`:case`enum`:let s=a[n];r.T===q.BYTES&&(s=r.repeated?s.map(Mc):Mc(s)),i[n]=s;break;case`map`:switch(r.V.kind){case`scalar`:case`enum`:if(r.V.T===q.BYTES)for(let[e,t]of Object.entries(a[n]))i[n][e]=Mc(t);else Object.assign(i[n],a[n]);break;case`message`:let e=r.V.T;for(let t of Object.keys(a[n])){let r=a[n][t];e.fieldWrapper||(r=new e(r)),i[n][t]=r}}break;case`message`:let c=r.T;if(r.repeated)i[n]=a[n].map(e=>Ys(e,c)?e:new c(e));else{let e=a[n];i[n]=c.fieldWrapper?c.typeName===`google.protobuf.BytesValue`?Mc(e):e:Ys(e,c)?e:new c(e)}}}},equals(e,t,n){return t===n?!0:!t||!n?!1:e.fields.byMember().every(e=>{let r=t[e.localName],i=n[e.localName];if(e.repeated){if(r.length!==i.length)return!1;switch(e.kind){case`message`:return r.every((t,n)=>e.T.equals(t,i[n]));case`scalar`:return r.every((t,n)=>js(e.T,t,i[n]));case`enum`:return r.every((e,t)=>js(q.INT32,e,i[t]))}throw Error(`repeated cannot contain ${e.kind}`)}switch(e.kind){case`message`:let t=r,n=i;return e.T.fieldWrapper&&(t!==void 0&&!Ys(t)&&(t=e.T.fieldWrapper.wrapField(t)),n!==void 0&&!Ys(n)&&(n=e.T.fieldWrapper.wrapField(n))),e.T.equals(t,n);case`enum`:return js(q.INT32,r,i);case`scalar`:return js(e.T,r,i);case`oneof`:if(r.case!==i.case)return!1;let a=e.findField(r.case);if(a===void 0)return!0;switch(a.kind){case`message`:return a.T.equals(r.value,i.value);case`enum`:return js(q.INT32,r.value,i.value);case`scalar`:return js(a.T,r.value,i.value)}throw Error(`oneof cannot contain ${a.kind}`);case`map`:let o=Object.keys(r).concat(Object.keys(i));switch(e.V.kind){case`message`:let t=e.V.T;return o.every(e=>t.equals(r[e],i[e]));case`enum`:return o.every(e=>js(q.INT32,r[e],i[e]));case`scalar`:let n=e.V.T;return o.every(e=>js(n,r[e],i[e]))}}})},clone(e){let t=e.getType(),n=new t,r=n;for(let n of t.fields.byMember()){let t=e[n.localName],i;if(n.repeated)i=t.map(jc);else if(n.kind==`map`){i=r[n.localName];for(let[e,n]of Object.entries(t))i[e]=jc(n)}else i=n.kind==`oneof`?n.findField(t.case)?{case:t.case,value:jc(t.value)}:{case:void 0}:jc(t);r[n.localName]=i}for(let n of t.runtime.bin.listUnknownFields(e))t.runtime.bin.onUnknownField(r,n.no,n.wireType,n.data);return n}}}function jc(e){if(e===void 0)return e;if(Ys(e))return e.clone();if(e instanceof Uint8Array){let t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function Mc(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Nc(e,t,n){return{syntax:e,json:rc(),bin:vc(),util:Object.assign(Object.assign({},Ac()),{newFieldList:t,initFields:n}),makeMessageType(e,t,n){return gs(this,e,t,n)},makeEnum:ms,makeEnumType:ps,getEnumType:ds,makeExtension(e,t,n){return Is(this,e,t,n)}}}var Pc=class{constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){let e={};for(let t of this.list())e[t.jsonName]=e[t.name]=t;this.jsonNames=e}return this.jsonNames[e]}find(e){if(!this.numbers){let e={};for(let t of this.list())e[t.no]=t;this.numbers=e}return this.numbers[e]}list(){return this.all||=this._normalizer(this._fields),this.all}byNumber(){return this.numbersAsc||=this.list().concat().sort((e,t)=>e.no-t.no),this.numbersAsc}byMember(){if(!this.members){this.members=[];let e=this.members,t;for(let n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}};function Fc(e,t){let n=Rc(e);return t?n:Uc(Hc(n))}function Ic(e){return Fc(e,!1)}var Lc=Rc;function Rc(e){let t=!1,n=[];for(let r=0;r<e.length;r++){let i=e.charAt(r);switch(i){case`_`:t=!0;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n.push(i),t=!1;break;default:t&&(t=!1,i=i.toUpperCase()),n.push(i)}}return n.join(``)}var zc=new Set([`constructor`,`toString`,`toJSON`,`valueOf`]),Bc=new Set([`getType`,`clone`,`equals`,`fromBinary`,`fromJson`,`fromJsonString`,`toBinary`,`toJson`,`toJsonString`,`toObject`]),Vc=e=>`${e}$`,Hc=e=>Bc.has(e)?Vc(e):e,Uc=e=>zc.has(e)?Vc(e):e,Wc=class{constructor(e){this.kind=`oneof`,this.repeated=!1,this.packed=!1,this.opt=!1,this.req=!1,this.default=void 0,this.fields=[],this.name=e,this.localName=Ic(e)}addField(e){W(e.oneof===this,`field ${e.name} not one of ${this.name}`),this.fields.push(e)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let e=0;e<this.fields.length;e++)this._lookup[this.fields[e].localName]=this.fields[e]}return this._lookup[e]}};function Gc(e,t){let n=[],r;for(let i of typeof e==`function`?e():e){let e=i;if(e.localName=Fc(i.name,i.oneof!==void 0),e.jsonName=i.jsonName??Lc(i.name),e.repeated=i.repeated??!1,i.kind==`scalar`&&(e.L=i.L??As.BIGINT),e.delimited=i.delimited??!1,e.req=i.req??!1,e.opt=i.opt??!1,i.packed===void 0&&(e.packed=t?i.kind==`enum`||i.kind==`scalar`&&i.T!=q.BYTES&&i.T!=q.STRING:!1),i.oneof!==void 0){let t=typeof i.oneof==`string`?i.oneof:i.oneof.name;(!r||r.name!=t)&&(r=new Wc(t)),e.oneof=r,r.addField(e)}n.push(e)}return n}var Y=Nc(`proto3`,e=>new Pc(e,e=>Gc(e,!0)),e=>{for(let t of e.getType().fields.byMember()){if(t.opt)continue;let n=t.localName,r=e;if(t.repeated){r[n]=[];continue}switch(t.kind){case`oneof`:r[n]={case:void 0};break;case`enum`:r[n]=0;break;case`map`:r[n]={};break;case`scalar`:r[n]=Ms(t.T,t.L)}}}),Kc;(function(e){e[e.Unary=0]=`Unary`,e[e.ServerStreaming=1]=`ServerStreaming`,e[e.ClientStreaming=2]=`ClientStreaming`,e[e.BiDiStreaming=3]=`BiDiStreaming`})(Kc||={});var qc;(function(e){e[e.NoSideEffects=1]=`NoSideEffects`,e[e.Idempotent=2]=`Idempotent`})(qc||={});var Jc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.JUPYTER_FORMAT=77]=`JUPYTER_FORMAT`})(Jc||={}),Y.util.setEnumType(Jc,`exa.codeium_common_pb.ExperimentKey`,[{no:0,name:`UNSPECIFIED`},{no:77,name:`JUPYTER_FORMAT`}]);var Yc;(function(e){e[e.CODEIUM=0]=`CODEIUM`})(Yc||={}),Y.util.setEnumType(Yc,`exa.codeium_common_pb.AuthSource`,[{no:0,name:`AUTH_SOURCE_CODEIUM`}]);var Xc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.ENABLE_CODEIUM=1]=`ENABLE_CODEIUM`,e[e.DISABLE_CODEIUM=2]=`DISABLE_CODEIUM`,e[e.SHOW_PREVIOUS_COMPLETION=3]=`SHOW_PREVIOUS_COMPLETION`,e[e.SHOW_NEXT_COMPLETION=4]=`SHOW_NEXT_COMPLETION`})(Xc||={}),Y.util.setEnumType(Xc,`exa.codeium_common_pb.EventType`,[{no:0,name:`EVENT_TYPE_UNSPECIFIED`},{no:1,name:`EVENT_TYPE_ENABLE_CODEIUM`},{no:2,name:`EVENT_TYPE_DISABLE_CODEIUM`},{no:3,name:`EVENT_TYPE_SHOW_PREVIOUS_COMPLETION`},{no:4,name:`EVENT_TYPE_SHOW_NEXT_COMPLETION`}]);var Zc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.TYPING_AS_SUGGESTED=1]=`TYPING_AS_SUGGESTED`,e[e.CACHE=2]=`CACHE`,e[e.NETWORK=3]=`NETWORK`})(Zc||={}),Y.util.setEnumType(Zc,`exa.codeium_common_pb.CompletionSource`,[{no:0,name:`COMPLETION_SOURCE_UNSPECIFIED`},{no:1,name:`COMPLETION_SOURCE_TYPING_AS_SUGGESTED`},{no:2,name:`COMPLETION_SOURCE_CACHE`},{no:3,name:`COMPLETION_SOURCE_NETWORK`}]);var Qc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.C=1]=`C`,e[e.CLOJURE=2]=`CLOJURE`,e[e.COFFEESCRIPT=3]=`COFFEESCRIPT`,e[e.CPP=4]=`CPP`,e[e.CSHARP=5]=`CSHARP`,e[e.CSS=6]=`CSS`,e[e.CUDACPP=7]=`CUDACPP`,e[e.DOCKERFILE=8]=`DOCKERFILE`,e[e.GO=9]=`GO`,e[e.GROOVY=10]=`GROOVY`,e[e.HANDLEBARS=11]=`HANDLEBARS`,e[e.HASKELL=12]=`HASKELL`,e[e.HCL=13]=`HCL`,e[e.HTML=14]=`HTML`,e[e.INI=15]=`INI`,e[e.JAVA=16]=`JAVA`,e[e.JAVASCRIPT=17]=`JAVASCRIPT`,e[e.JSON=18]=`JSON`,e[e.JULIA=19]=`JULIA`,e[e.KOTLIN=20]=`KOTLIN`,e[e.LATEX=21]=`LATEX`,e[e.LESS=22]=`LESS`,e[e.LUA=23]=`LUA`,e[e.MAKEFILE=24]=`MAKEFILE`,e[e.MARKDOWN=25]=`MARKDOWN`,e[e.OBJECTIVEC=26]=`OBJECTIVEC`,e[e.OBJECTIVECPP=27]=`OBJECTIVECPP`,e[e.PERL=28]=`PERL`,e[e.PHP=29]=`PHP`,e[e.PLAINTEXT=30]=`PLAINTEXT`,e[e.PROTOBUF=31]=`PROTOBUF`,e[e.PBTXT=32]=`PBTXT`,e[e.PYTHON=33]=`PYTHON`,e[e.R=34]=`R`,e[e.RUBY=35]=`RUBY`,e[e.RUST=36]=`RUST`,e[e.SASS=37]=`SASS`,e[e.SCALA=38]=`SCALA`,e[e.SCSS=39]=`SCSS`,e[e.SHELL=40]=`SHELL`,e[e.SQL=41]=`SQL`,e[e.STARLARK=42]=`STARLARK`,e[e.SWIFT=43]=`SWIFT`,e[e.TSX=44]=`TSX`,e[e.TYPESCRIPT=45]=`TYPESCRIPT`,e[e.VISUALBASIC=46]=`VISUALBASIC`,e[e.VUE=47]=`VUE`,e[e.XML=48]=`XML`,e[e.XSL=49]=`XSL`,e[e.YAML=50]=`YAML`,e[e.SVELTE=51]=`SVELTE`,e[e.TOML=52]=`TOML`,e[e.DART=53]=`DART`,e[e.RST=54]=`RST`,e[e.OCAML=55]=`OCAML`,e[e.CMAKE=56]=`CMAKE`,e[e.PASCAL=57]=`PASCAL`,e[e.ELIXIR=58]=`ELIXIR`,e[e.FSHARP=59]=`FSHARP`,e[e.LISP=60]=`LISP`,e[e.MATLAB=61]=`MATLAB`,e[e.POWERSHELL=62]=`POWERSHELL`,e[e.SOLIDITY=63]=`SOLIDITY`,e[e.ADA=64]=`ADA`,e[e.OCAML_INTERFACE=65]=`OCAML_INTERFACE`})(Qc||={}),Y.util.setEnumType(Qc,`exa.codeium_common_pb.Language`,[{no:0,name:`LANGUAGE_UNSPECIFIED`},{no:1,name:`LANGUAGE_C`},{no:2,name:`LANGUAGE_CLOJURE`},{no:3,name:`LANGUAGE_COFFEESCRIPT`},{no:4,name:`LANGUAGE_CPP`},{no:5,name:`LANGUAGE_CSHARP`},{no:6,name:`LANGUAGE_CSS`},{no:7,name:`LANGUAGE_CUDACPP`},{no:8,name:`LANGUAGE_DOCKERFILE`},{no:9,name:`LANGUAGE_GO`},{no:10,name:`LANGUAGE_GROOVY`},{no:11,name:`LANGUAGE_HANDLEBARS`},{no:12,name:`LANGUAGE_HASKELL`},{no:13,name:`LANGUAGE_HCL`},{no:14,name:`LANGUAGE_HTML`},{no:15,name:`LANGUAGE_INI`},{no:16,name:`LANGUAGE_JAVA`},{no:17,name:`LANGUAGE_JAVASCRIPT`},{no:18,name:`LANGUAGE_JSON`},{no:19,name:`LANGUAGE_JULIA`},{no:20,name:`LANGUAGE_KOTLIN`},{no:21,name:`LANGUAGE_LATEX`},{no:22,name:`LANGUAGE_LESS`},{no:23,name:`LANGUAGE_LUA`},{no:24,name:`LANGUAGE_MAKEFILE`},{no:25,name:`LANGUAGE_MARKDOWN`},{no:26,name:`LANGUAGE_OBJECTIVEC`},{no:27,name:`LANGUAGE_OBJECTIVECPP`},{no:28,name:`LANGUAGE_PERL`},{no:29,name:`LANGUAGE_PHP`},{no:30,name:`LANGUAGE_PLAINTEXT`},{no:31,name:`LANGUAGE_PROTOBUF`},{no:32,name:`LANGUAGE_PBTXT`},{no:33,name:`LANGUAGE_PYTHON`},{no:34,name:`LANGUAGE_R`},{no:35,name:`LANGUAGE_RUBY`},{no:36,name:`LANGUAGE_RUST`},{no:37,name:`LANGUAGE_SASS`},{no:38,name:`LANGUAGE_SCALA`},{no:39,name:`LANGUAGE_SCSS`},{no:40,name:`LANGUAGE_SHELL`},{no:41,name:`LANGUAGE_SQL`},{no:42,name:`LANGUAGE_STARLARK`},{no:43,name:`LANGUAGE_SWIFT`},{no:44,name:`LANGUAGE_TSX`},{no:45,name:`LANGUAGE_TYPESCRIPT`},{no:46,name:`LANGUAGE_VISUALBASIC`},{no:47,name:`LANGUAGE_VUE`},{no:48,name:`LANGUAGE_XML`},{no:49,name:`LANGUAGE_XSL`},{no:50,name:`LANGUAGE_YAML`},{no:51,name:`LANGUAGE_SVELTE`},{no:52,name:`LANGUAGE_TOML`},{no:53,name:`LANGUAGE_DART`},{no:54,name:`LANGUAGE_RST`},{no:55,name:`LANGUAGE_OCAML`},{no:56,name:`LANGUAGE_CMAKE`},{no:57,name:`LANGUAGE_PASCAL`},{no:58,name:`LANGUAGE_ELIXIR`},{no:59,name:`LANGUAGE_FSHARP`},{no:60,name:`LANGUAGE_LISP`},{no:61,name:`LANGUAGE_MATLAB`},{no:62,name:`LANGUAGE_POWERSHELL`},{no:63,name:`LANGUAGE_SOLIDITY`},{no:64,name:`LANGUAGE_ADA`},{no:65,name:`LANGUAGE_OCAML_INTERFACE`}]);var $c=class e extends G{completionId=``;text=``;prefix=``;stop=``;score=0;tokens=[];decodedTokens=[];probabilities=[];adjustedProbabilities=[];generatedLength=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.codeium_common_pb.Completion`;static fields=Y.util.newFieldList(()=>[{no:1,name:`completion_id`,kind:`scalar`,T:9},{no:2,name:`text`,kind:`scalar`,T:9},{no:3,name:`prefix`,kind:`scalar`,T:9},{no:4,name:`stop`,kind:`scalar`,T:9},{no:5,name:`score`,kind:`scalar`,T:1},{no:6,name:`tokens`,kind:`scalar`,T:4,repeated:!0},{no:7,name:`decoded_tokens`,kind:`scalar`,T:9,repeated:!0},{no:8,name:`probabilities`,kind:`scalar`,T:1,repeated:!0},{no:9,name:`adjusted_probabilities`,kind:`scalar`,T:1,repeated:!0},{no:10,name:`generated_length`,kind:`scalar`,T:4}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},el=class e extends G{ideName=``;ideVersion=``;extensionName=``;extensionVersion=``;apiKey=``;locale=``;sessionId=``;requestId=K.zero;userAgent=``;url=``;authSource=Yc.CODEIUM;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.codeium_common_pb.Metadata`;static fields=Y.util.newFieldList(()=>[{no:1,name:`ide_name`,kind:`scalar`,T:9},{no:7,name:`ide_version`,kind:`scalar`,T:9},{no:12,name:`extension_name`,kind:`scalar`,T:9},{no:2,name:`extension_version`,kind:`scalar`,T:9},{no:3,name:`api_key`,kind:`scalar`,T:9},{no:4,name:`locale`,kind:`scalar`,T:9},{no:10,name:`session_id`,kind:`scalar`,T:9},{no:9,name:`request_id`,kind:`scalar`,T:4},{no:13,name:`user_agent`,kind:`scalar`,T:9},{no:14,name:`url`,kind:`scalar`,T:9},{no:15,name:`auth_source`,kind:`enum`,T:Y.getEnumType(Yc)}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},tl=class e extends G{tabSize=K.zero;insertSpaces=!1;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.codeium_common_pb.EditorOptions`;static fields=Y.util.newFieldList(()=>[{no:1,name:`tab_size`,kind:`scalar`,T:4},{no:2,name:`insert_spaces`,kind:`scalar`,T:8}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}};(class e extends G{eventType=Xc.UNSPECIFIED;eventJson=``;timestampUnixMs=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.codeium_common_pb.Event`;static fields=Y.util.newFieldList(()=>[{no:1,name:`event_type`,kind:`enum`,T:Y.getEnumType(Xc)},{no:2,name:`event_json`,kind:`scalar`,T:9},{no:3,name:`timestamp_unix_ms`,kind:`scalar`,T:3}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}});var nl=class extends Nr{index;total;constructor(e,t){super(),this.index=e,this.total=t}toDOM(){let e=document.createElement(`span`);e.setAttribute(`aria-hidden`,`true`),e.className=`cm-codeium-cycle`;let t=e.appendChild(document.createElement(`span`));t.className=`cm-codeium-cycle-explanation`,t.innerText=`${this.index+1}/${this.total}`;let n=e.appendChild(document.createElement(`button`));return n.className=`cm-codeium-cycle-key`,n.innerText=`→ (Ctrl ])`,n.dataset.action=`codeium-cycle`,e}ignoreEvent(){return!1}},rl=Cr.define({combine(e){return Ir(e,{language:Qc.TYPESCRIPT,timeout:150,widgetClass:nl,alwaysOn:!0},{})}}),il=Cr.define({combine(e){return Ir(e,{override:()=>[]},{})}}),al=L.mark({class:`cm-ghostText`}),ol=fr.define({create(e){return null},update(e,t){let n=t.state.facet(rl);for(let e of t.effects){if(e.is($o)){let{changeSpecs:t,index:r}=e.value,i=t[r].map(e=>al.range(e.absoluteStartPos,e.absoluteEndPos)),a=i.at(-1)?.to;return{index:r,decorations:L.set([...i,...a!==void 0&&t.length>1&&n.widgetClass?[L.widget({widget:new n.widgetClass(r,t.length),side:1}).range(a)]:[]]),changeSpecs:t,reverseChangeSet:e.value.reverseChangeSet}}if(e.is(es)||e.is(ts))return null}return e&&{...e,decorations:e.decorations.map(t.changes),reverseChangeSet:e.reverseChangeSet.map(t.changes)}},provide:e=>R.decorations.from(e,e=>e?.decorations||L.none)}),sl=Gr.define(),cl=Gr.define(),X;(function(e){e[e.Canceled=1]=`Canceled`,e[e.Unknown=2]=`Unknown`,e[e.InvalidArgument=3]=`InvalidArgument`,e[e.DeadlineExceeded=4]=`DeadlineExceeded`,e[e.NotFound=5]=`NotFound`,e[e.AlreadyExists=6]=`AlreadyExists`,e[e.PermissionDenied=7]=`PermissionDenied`,e[e.ResourceExhausted=8]=`ResourceExhausted`,e[e.FailedPrecondition=9]=`FailedPrecondition`,e[e.Aborted=10]=`Aborted`,e[e.OutOfRange=11]=`OutOfRange`,e[e.Unimplemented=12]=`Unimplemented`,e[e.Internal=13]=`Internal`,e[e.Unavailable=14]=`Unavailable`,e[e.DataLoss=15]=`DataLoss`,e[e.Unauthenticated=16]=`Unauthenticated`})(X||={});function ll(e){let t=X[e];return typeof t==`string`?t[0].toLowerCase()+t.substring(1).replace(/[A-Z]/g,e=>`_`+e.toLowerCase()):e.toString()}var ul;function dl(e){if(!ul){ul={};for(let e of Object.values(X))typeof e!=`string`&&(ul[ll(e)]=e)}return ul[e]}var Z=class e extends Error{constructor(e,t=X.Unknown,n,r,i){super(fl(e,t)),this.name=`ConnectError`,Object.setPrototypeOf(this,new.target.prototype),this.rawMessage=e,this.code=t,this.metadata=new Headers(n??{}),this.details=r??[],this.cause=i}static from(t,n=X.Unknown){return t instanceof e?t:t instanceof Error?t.name==`AbortError`?new e(t.message,X.Canceled):new e(t.message,n,void 0,void 0,t):new e(String(t),n,void 0,void 0,t)}static[Symbol.hasInstance](t){return t instanceof Error?Object.getPrototypeOf(t)===e.prototype||t.name===`ConnectError`&&`code`in t&&typeof t.code==`number`&&`metadata`in t&&`details`in t&&Array.isArray(t.details)&&`rawMessage`in t&&typeof t.rawMessage==`string`&&`cause`in t:!1}findDetails(e){let t=`typeName`in e?{findMessage:t=>t===e.typeName?e:void 0}:e,n=[];for(let e of this.details){if(`getType`in e){t.findMessage(e.getType().typeName)&&n.push(e);continue}let r=t.findMessage(e.type);if(r)try{n.push(r.fromBinary(e.value))}catch{}}return n}};function fl(e,t){return e.length?`[${ll(t)}] ${e}`:`[${ll(t)}]`}function pl(...e){let t=new Headers;for(let n of e)n.forEach((e,n)=>{t.append(n,e)});return t}function ml(e,t){let n={};for(let[r,i]of Object.entries(e.methods)){let a=t(Object.assign(Object.assign({},i),{localName:r,service:e}));a!=null&&(n[r]=a)}return n}function hl(e){let t,n=new Uint8Array;function r(e){let t=new Uint8Array(n.length+e.length);t.set(n),t.set(e,n.length),n=t}return new ReadableStream({start(){t=e.getReader()},async pull(e){let i;for(;;){if(i===void 0&&n.byteLength>=5){let e=0;for(let t=1;t<5;t++)e=(e<<8)+n[t];i={flags:n[0],length:e}}if(i!==void 0&&n.byteLength>=i.length+5)break;let e=await t.read();if(e.done)break;r(e.value)}if(i===void 0){if(n.byteLength==0){e.close();return}e.error(new Z(`premature end of stream`,X.DataLoss));return}let a=n.subarray(5,5+i.length);n=n.subarray(5+i.length),e.enqueue({flags:i.flags,data:a})}})}function gl(e,t){let n=new Uint8Array(t.length+5);n.set(t,5);let r=new DataView(n.buffer,n.byteOffset,n.byteLength);return r.setUint8(0,e),r.setUint32(1,t.length),n}var _l=function(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values==`function`?__values(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}},vl=function(e){return this instanceof vl?(this.v=e,this):new vl(e)},yl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i={},s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof vl?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}},bl=function(e){var t,n;return t={},r(`next`),r(`throw`,function(e){throw e}),r(`return`),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:vl(e[r](t)),done:!1}:i?i(t):t}:i}};function xl(e){return yl(this,arguments,function*(){yield vl(yield*bl(_l(e)))})}var Sl=function(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values==`function`?__values(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}},Cl=function(e){return this instanceof Cl?(this.v=e,this):new Cl(e)},wl=function(e){var t,n;return t={},r(`next`),r(`throw`,function(e){throw e}),r(`return`),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:Cl(e[r](t)),done:!1}:i?i(t):t}:i}},Tl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i={},s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof Cl?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}};function El(e,t){return ml(e,n=>{switch(n.kind){case Kc.Unary:return Ol(t,e,n);case Kc.ServerStreaming:return kl(t,e,n);case Kc.ClientStreaming:return Al(t,e,n);case Kc.BiDiStreaming:return jl(t,e,n);default:return null}})}function Dl(e,t){return El(e,t)}function Ol(e,t,n){return async function(r,i){var a,o;let s=await e.unary(t,n,i?.signal,i?.timeoutMs,i?.headers,r,i?.contextValues);return(a=i?.onHeader)==null||a.call(i,s.header),(o=i?.onTrailer)==null||o.call(i,s.trailer),s.message}}function kl(e,t,n){return function(r,i){return Ml(e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,xl([r]),i?.contextValues),i)}}function Al(e,t,n){return async function(r,i){var a,o,s,c,l,u;let d=await e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,r,i?.contextValues);(l=i?.onHeader)==null||l.call(i,d.header);let f,p=0;try{for(var m=!0,h=Sl(d.message),g;g=await h.next(),a=g.done,!a;m=!0)c=g.value,m=!1,f=c,p++}catch(e){o={error:e}}finally{try{!m&&!a&&(s=h.return)&&await s.call(h)}finally{if(o)throw o.error}}if(!f)throw new Z(`protocol error: missing response message`,X.Unimplemented);if(p>1)throw new Z(`protocol error: received extra messages for client streaming method`,X.Unimplemented);return(u=i?.onTrailer)==null||u.call(i,d.trailer),f}}function jl(e,t,n){return function(r,i){return Ml(e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,r,i?.contextValues),i)}}function Ml(e,t){let n=(function(){return Tl(this,arguments,function*(){var n,r;let i=yield Cl(e);(n=t?.onHeader)==null||n.call(t,i.header),yield Cl(yield*wl(Sl(i.message))),(r=t?.onTrailer)==null||r.call(t,i.trailer)})})()[Symbol.asyncIterator]();return{[Symbol.asyncIterator]:()=>({next:()=>n.next()})}}function Nl(...e){let t=new AbortController,n=e.filter(e=>e!==void 0).concat(t.signal);for(let e of n){if(e.aborted){r.apply(e);break}e.addEventListener(`abort`,r)}function r(){t.signal.aborted||t.abort(Fl(this));for(let e of n)e.removeEventListener(`abort`,r)}return t}function Pl(e){let t=new AbortController,n=()=>{t.abort(new Z(`the operation timed out`,X.DeadlineExceeded))},r;return e!==void 0&&(e<=0?n():r=setTimeout(n,e)),{signal:t.signal,cleanup:()=>clearTimeout(r)}}function Fl(e){if(!e.aborted)return;if(e.reason!==void 0)return e.reason;let t=Error(`This operation was aborted`);return t.name=`AbortError`,t}function Il(){return{get(e){return e.id in this?this[e.id]:e.defaultValue},set(e,t){return this[e.id]=t,this},delete(e){return delete this[e.id],this}}}function Ll(e,t,n){let r=typeof t==`string`?t:t.typeName,i=typeof n==`string`?n:n.name;return e.toString().replace(/\/?$/,`/${r}/${i}`)}function Rl(e,t){return t instanceof e?t:new e(t)}function zl(e,t){function n(t){return t.done===!0?t:{done:t.done,value:Rl(e,t.value)}}return{[Symbol.asyncIterator](){let e=t[Symbol.asyncIterator](),r={next:()=>e.next().then(n)};return e.throw!==void 0&&(r.throw=t=>e.throw(t).then(n)),e.return!==void 0&&(r.return=t=>e.return(t).then(n)),r}}}function Bl(e,t){return t?.concat().reverse().reduce((e,t)=>t(e),e)??e}function Vl(e){let t=Object.assign({},e);return t.ignoreUnknownFields??=!0,t}function Hl(e,t,n,r){let i=t?Ul(e.I,r):Wl(e.I,n);return{parse:(t?Ul(e.O,r):Wl(e.O,n)).parse,serialize:i.serialize}}function Ul(e,t){return{parse(n){try{return e.fromBinary(n,t)}catch(e){throw new Z(`parse binary: ${e instanceof Error?e.message:String(e)}`,X.Internal)}},serialize(e){try{return e.toBinary(t)}catch(e){throw new Z(`serialize binary: ${e instanceof Error?e.message:String(e)}`,X.Internal)}}}}function Wl(e,t){let n=t?.textEncoder??new TextEncoder,r=t?.textDecoder??new TextDecoder,i=Vl(t);return{parse(t){try{let n=r.decode(t);return e.fromJsonString(n,i)}catch(e){throw Z.from(e,X.InvalidArgument)}},serialize(e){try{let t=e.toJsonString(i);return n.encode(t)}catch(e){throw Z.from(e,X.Internal)}}}}var Gl=/^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$/i,Kl=`application/proto`,ql=`application/json`,Jl=`application/connect+proto`,Yl=`application/connect+json`;function Xl(e){let t=e?.match(Gl);if(t)return{stream:!!t[1],binary:!!t[3]}}function Zl(e,t,n){if(t&&new Headers(t).forEach((e,t)=>n.metadata.append(t,e)),typeof e!=`object`||!e||Array.isArray(e))throw n;let r=n.code;`code`in e&&typeof e.code==`string`&&(r=dl(e.code)??r);let i=e.message;if(i!=null&&typeof i!=`string`)throw n;let a=new Z(i??``,r,t);if(`details`in e&&Array.isArray(e.details))for(let t of e.details){if(typeof t!=`object`||!t||Array.isArray(t)||typeof t.type!=`string`||typeof t.value!=`string`)throw n;try{a.details.push({type:t.type,value:Hs.dec(t.value),debug:t.debug})}catch{throw n}}return a}function Ql(e){let t=new Z(`invalid end stream`,X.Unknown),n;try{n=JSON.parse(typeof e==`string`?e:new TextDecoder().decode(e))}catch{throw t}if(typeof n!=`object`||!n||Array.isArray(n))throw t;let r=new Headers;if(`metadata`in n){if(typeof n.metadata!=`object`||n.metadata==null||Array.isArray(n.metadata))throw t;for(let[e,i]of Object.entries(n.metadata)){if(!Array.isArray(i)||i.some(e=>typeof e!=`string`))throw t;for(let t of i)r.append(e,t)}}return{metadata:r,error:`error`in n&&n.error!=null?Zl(n.error,r,t):void 0}}var $l=`Content-Type`,eu=`Content-Length`,tu=`Content-Encoding`,nu=`Accept-Encoding`,ru=`Connect-Timeout-Ms`,iu=`Connect-Protocol-Version`,au=`User-Agent`;function ou(e){switch(e){case 400:return X.Internal;case 401:return X.Unauthenticated;case 403:return X.PermissionDenied;case 404:return X.Unimplemented;case 429:return X.Unavailable;case 502:return X.Unavailable;case 503:return X.Unavailable;case 504:return X.Unavailable;default:return X.Unknown}}function su(e){let t=new Headers,n=new Headers;return e.forEach((e,r)=>{r.toLowerCase().startsWith(`trailer-`)?n.append(r.substring(8),e):t.append(r,e)}),[t,n]}function cu(e,t,n,r,i){let a=new Headers(r??{});return n!==void 0&&a.set(ru,`${n}`),a.set($l,e==Kc.Unary?t?Kl:ql:t?Jl:Yl),a.set(iu,`1`),i&&a.set(au,`connect-es/1.6.1`),a}function lu(e,t,n,r){let i=r.get($l),a=Xl(i);if(n!==200){let t=new Z(`HTTP ${n}`,ou(n),r);if(e==Kc.Unary&&a&&!a.binary)return{isUnaryError:!0,unaryError:t};throw t}let o={binary:t,stream:e!==Kc.Unary};if(a?.binary!==o.binary||a.stream!==o.stream)throw new Z(`unsupported content type ${i}`,a===void 0?X.Unknown:X.Internal,r);return{isUnaryError:!1}}var uu=`application/`;function du(e,t){return t?Hs.enc(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``):encodeURIComponent(new TextDecoder().decode(e))}function fu(e,t,n){let r=`?connect=v1`,i=e.header.get($l);i?.indexOf(uu)===0&&(r+=`&encoding=`+encodeURIComponent(i.slice(12)));let a=e.header.get(tu);a!==null&&a!==`identity`&&(r+=`&compression=`+encodeURIComponent(a),n=!0),n&&(r+=`&base64=1`),r+=`&message=`+du(t,n);let o=e.url+r,s=new Headers(e.header);return[iu,$l,eu,tu,nu].forEach(e=>s.delete(e)),Object.assign(Object.assign({},e),{init:Object.assign(Object.assign({},e.init),{method:`GET`}),url:o,header:s})}function pu(e){let t=Bl(e.next,e.interceptors),[n,r,i]=hu(e);return t(Object.assign(Object.assign({},e.req),{message:Rl(e.req.method.I,e.req.message),signal:n})).then(e=>(i(),e),r)}function mu(e){let t=Bl(e.next,e.interceptors),[n,r,i]=hu(e),a=Object.assign(Object.assign({},e.req),{message:zl(e.req.method.I,e.req.message),signal:n}),o=!1;return n.addEventListener(`abort`,function(){var t,n;let r=e.req.message[Symbol.asyncIterator]();o||(t=r.throw)==null||t.call(r,this.reason).catch(()=>{}),(n=r.return)==null||n.call(r).catch(()=>{})}),t(a).then(e=>Object.assign(Object.assign({},e),{message:{[Symbol.asyncIterator](){let t=e.message[Symbol.asyncIterator]();return{next(){return t.next().then(e=>(e.done==1&&(o=!0,i()),e),r)}}}}}),r)}function hu(e){let{signal:t,cleanup:n}=Pl(e.timeoutMs),r=Nl(e.signal,t);return[r.signal,function(e){let i=Z.from(t.aborted?Fl(t):e);return r.abort(i),n(),Promise.reject(i)},function(){n(),r.abort()}]}var gu;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.INACTIVE=1]=`INACTIVE`,e[e.PROCESSING=2]=`PROCESSING`,e[e.SUCCESS=3]=`SUCCESS`,e[e.WARNING=4]=`WARNING`,e[e.ERROR=5]=`ERROR`})(gu||={}),Y.util.setEnumType(gu,`exa.language_server_pb.CodeiumState`,[{no:0,name:`CODEIUM_STATE_UNSPECIFIED`},{no:1,name:`CODEIUM_STATE_INACTIVE`},{no:2,name:`CODEIUM_STATE_PROCESSING`},{no:3,name:`CODEIUM_STATE_SUCCESS`},{no:4,name:`CODEIUM_STATE_WARNING`},{no:5,name:`CODEIUM_STATE_ERROR`}]);var _u;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.SINGLE=1]=`SINGLE`,e[e.MULTI=2]=`MULTI`})(_u||={}),Y.util.setEnumType(_u,`exa.language_server_pb.LineType`,[{no:0,name:`LINE_TYPE_UNSPECIFIED`},{no:1,name:`LINE_TYPE_SINGLE`},{no:2,name:`LINE_TYPE_MULTI`}]);var vu;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.INLINE=1]=`INLINE`,e[e.BLOCK=2]=`BLOCK`,e[e.INLINE_MASK=3]=`INLINE_MASK`})(vu||={}),Y.util.setEnumType(vu,`exa.language_server_pb.CompletionPartType`,[{no:0,name:`COMPLETION_PART_TYPE_UNSPECIFIED`},{no:1,name:`COMPLETION_PART_TYPE_INLINE`},{no:2,name:`COMPLETION_PART_TYPE_BLOCK`},{no:3,name:`COMPLETION_PART_TYPE_INLINE_MASK`}]);var yu=class e extends G{threshold=0;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.MultilineConfig`;static fields=Y.util.newFieldList(()=>[{no:1,name:`threshold`,kind:`scalar`,T:2}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},bu=class e extends G{metadata;document;editorOptions;otherDocuments=[];experimentConfig;modelName=``;multilineConfig;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.GetCompletionsRequest`;static fields=Y.util.newFieldList(()=>[{no:1,name:`metadata`,kind:`message`,T:el},{no:2,name:`document`,kind:`message`,T:Du},{no:3,name:`editor_options`,kind:`message`,T:tl},{no:5,name:`other_documents`,kind:`message`,T:Du,repeated:!0},{no:7,name:`experiment_config`,kind:`message`,T:Ou},{no:10,name:`model_name`,kind:`scalar`,T:9},{no:13,name:`multiline_config`,kind:`message`,T:yu}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},xu=class e extends G{state;completionItems=[];constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.GetCompletionsResponse`;static fields=Y.util.newFieldList(()=>[{no:1,name:`state`,kind:`message`,T:ku},{no:2,name:`completion_items`,kind:`message`,T:Nu,repeated:!0}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Su=class e extends G{metadata;completionId=``;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.AcceptCompletionRequest`;static fields=Y.util.newFieldList(()=>[{no:1,name:`metadata`,kind:`message`,T:el},{no:2,name:`completion_id`,kind:`scalar`,T:9}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Cu=class e extends G{constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.AcceptCompletionResponse`;static fields=Y.util.newFieldList(()=>[]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},wu=class e extends G{constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.GetAuthTokenRequest`;static fields=Y.util.newFieldList(()=>[]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Tu=class e extends G{authToken=``;uuid=``;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.GetAuthTokenResponse`;static fields=Y.util.newFieldList(()=>[{no:1,name:`auth_token`,kind:`scalar`,T:9},{no:2,name:`uuid`,kind:`scalar`,T:9}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Eu=class e extends G{row=K.zero;col=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.DocumentPosition`;static fields=Y.util.newFieldList(()=>[{no:1,name:`row`,kind:`scalar`,T:4},{no:2,name:`col`,kind:`scalar`,T:4}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Du=class e extends G{absolutePath=``;relativePath=``;text=``;editorLanguage=``;language=Qc.UNSPECIFIED;cursorOffset=K.zero;cursorPosition;lineEnding=``;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.Document`;static fields=Y.util.newFieldList(()=>[{no:1,name:`absolute_path`,kind:`scalar`,T:9},{no:2,name:`relative_path`,kind:`scalar`,T:9},{no:3,name:`text`,kind:`scalar`,T:9},{no:4,name:`editor_language`,kind:`scalar`,T:9},{no:5,name:`language`,kind:`enum`,T:Y.getEnumType(Qc)},{no:6,name:`cursor_offset`,kind:`scalar`,T:4},{no:8,name:`cursor_position`,kind:`message`,T:Eu},{no:7,name:`line_ending`,kind:`scalar`,T:9}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Ou=class e extends G{forceEnableExperiments=[];constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.ExperimentConfig`;static fields=Y.util.newFieldList(()=>[{no:1,name:`force_enable_experiments`,kind:`enum`,T:Y.getEnumType(Jc),repeated:!0}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},ku=class e extends G{state=gu.UNSPECIFIED;message=``;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.State`;static fields=Y.util.newFieldList(()=>[{no:1,name:`state`,kind:`enum`,T:Y.getEnumType(gu)},{no:2,name:`message`,kind:`scalar`,T:9}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Au=class e extends G{startOffset=K.zero;endOffset=K.zero;startPosition;endPosition;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.Range`;static fields=Y.util.newFieldList(()=>[{no:1,name:`start_offset`,kind:`scalar`,T:4},{no:2,name:`end_offset`,kind:`scalar`,T:4},{no:3,name:`start_position`,kind:`message`,T:Eu},{no:4,name:`end_position`,kind:`message`,T:Eu}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},ju=class e extends G{text=``;deltaCursorOffset=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.Suffix`;static fields=Y.util.newFieldList(()=>[{no:1,name:`text`,kind:`scalar`,T:9},{no:2,name:`delta_cursor_offset`,kind:`scalar`,T:3}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Mu=class e extends G{text=``;offset=K.zero;type=vu.UNSPECIFIED;prefix=``;line=K.zero;constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.CompletionPart`;static fields=Y.util.newFieldList(()=>[{no:1,name:`text`,kind:`scalar`,T:9},{no:2,name:`offset`,kind:`scalar`,T:4},{no:3,name:`type`,kind:`enum`,T:Y.getEnumType(vu)},{no:4,name:`prefix`,kind:`scalar`,T:9},{no:5,name:`line`,kind:`scalar`,T:4}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Nu=class e extends G{completion;suffix;range;source=Zc.UNSPECIFIED;completionParts=[];constructor(e){super(),Y.util.initPartial(e,this)}static runtime=Y;static typeName=`exa.language_server_pb.CompletionItem`;static fields=Y.util.newFieldList(()=>[{no:1,name:`completion`,kind:`message`,T:$c},{no:5,name:`suffix`,kind:`message`,T:ju},{no:2,name:`range`,kind:`message`,T:Au},{no:3,name:`source`,kind:`enum`,T:Y.getEnumType(Zc)},{no:8,name:`completion_parts`,kind:`message`,T:Mu,repeated:!0}]);static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return Y.util.equals(e,t,n)}},Pu={typeName:`exa.language_server_pb.LanguageServerService`,methods:{getCompletions:{name:`GetCompletions`,I:bu,O:xu,kind:Kc.Unary},acceptCompletion:{name:`AcceptCompletion`,I:Su,O:Cu,kind:Kc.Unary},getAuthToken:{name:`GetAuthToken`,I:wu,O:Tu,kind:Kc.Unary}}};function Fu(){try{new Headers}catch{throw Error(`connect-web requires the fetch API. Are you running on an old version of Node.js? Node.js is not supported in Connect for Web - please stay tuned for Connect for Node.`)}}var Iu=function(e){return this instanceof Iu?(this.v=e,this):new Iu(e)},Lu=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i={},s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof Iu?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}};function Ru(e){Fu();let t=e.useBinaryFormat??!1;return{async unary(n,r,i,a,o,s,c){let{serialize:l,parse:u}=Hl(r,t,e.jsonOptions,e.binaryOptions);return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await pu({interceptors:e.interceptors,signal:i,timeoutMs:a,req:{stream:!1,service:n,method:r,url:Ll(e.baseUrl,n,r),init:{method:`POST`,credentials:e.credentials??`same-origin`,redirect:`error`,mode:`cors`},header:cu(r.kind,t,a,o,!1),contextValues:c??Il(),message:s},next:async i=>{let a=e.useHttpGet===!0&&r.idempotency===qc.NoSideEffects,o=null;a?i=fu(i,l(i.message),t):o=l(i.message);let s=await(e.fetch??globalThis.fetch)(i.url,Object.assign(Object.assign({},i.init),{headers:i.header,signal:i.signal,body:o})),{isUnaryError:c,unaryError:d}=lu(r.kind,t,s.status,s.headers);if(c)throw Zl(await s.json(),pl(...su(s.headers)),d);let[f,p]=su(s.headers);return{stream:!1,service:n,method:r,header:f,message:t?u(new Uint8Array(await s.arrayBuffer())):r.O.fromJson(await s.json(),Vl(e.jsonOptions)),trailer:p}}})},async stream(n,r,i,a,o,s,c){let{serialize:l,parse:u}=Hl(r,t,e.jsonOptions,e.binaryOptions);function d(e,t,n,r){return Lu(this,arguments,function*(){let i=hl(e).getReader(),a=!1;for(;;){let e=yield Iu(i.read());if(e.done)break;let{flags:r,data:o}=e.value;if((r&1)==1)throw new Z(`protocol error: received unsupported compressed output`,X.Internal);if((r&2)==2){a=!0;let e=Ql(o);if(e.error){let t=e.error;throw n.forEach((e,n)=>{t.metadata.append(n,e)}),t}e.metadata.forEach((e,n)=>t.set(n,e));continue}yield yield Iu(u(o))}if(`throwIfAborted`in r&&r.throwIfAborted(),!a)throw`missing EndStreamResponse`})}async function f(e){if(r.kind!=Kc.ServerStreaming)throw`The fetch API does not support streaming request bodies`;let t=await e[Symbol.asyncIterator]().next();if(t.done==1)throw`missing request message`;return gl(0,l(t.value))}return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await mu({interceptors:e.interceptors,timeoutMs:a,signal:i,req:{stream:!0,service:n,method:r,url:Ll(e.baseUrl,n,r),init:{method:`POST`,credentials:e.credentials??`same-origin`,redirect:`error`,mode:`cors`},header:cu(r.kind,t,a,o,!1),contextValues:c??Il(),message:s},next:async n=>{let i=await(e.fetch??globalThis.fetch)(n.url,Object.assign(Object.assign({},n.init),{headers:n.header,signal:n.signal,body:await f(n.message)}));if(lu(r.kind,t,i.status,i.headers),i.body===null)throw`missing response body`;let a=new Headers;return Object.assign(Object.assign({},n),{header:i.headers,trailer:a,message:d(i.body,a,i.headers,n.signal)})}})}}}var zu=Dl(Pu,Ru({baseUrl:`https://web-backend.codeium.com`,useBinaryFormat:!0})),Bu;try{Bu=crypto.randomUUID()}catch{function e(){return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(+e^(crypto.getRandomValues(new Uint8Array(1))[0]??0)&15>>e/4).toString(16))}Bu=e()}async function Vu({text:e,cursorOffset:t,config:n,otherDocuments:r}){return await zu.getCompletions({metadata:{ideName:`web`,ideVersion:`0.0.5`,extensionName:`@valtown/codemirror-codeium`,extensionVersion:`1.0.0`,apiKey:n.apiKey,sessionId:Bu,authSource:n.authSource},document:{text:e,cursorOffset:BigInt(t),language:n.language,editorLanguage:`typescript`,lineEnding:`
|
|
11
|
+
`},editorOptions:{tabSize:2n,insertSpaces:!0},otherDocuments:r,multilineConfig:void 0},{headers:{Authorization:`Basic ${n.apiKey}-${Bu}`}})}function Hu(e){return e.completionItems.map(e=>{let t=0;return e.completionParts.filter(e=>e.type!==3).map(e=>{let n=Number(e.offset),r=e.type===2?`\n${e.text}`:e.text,i={absoluteStartPos:t+n,absoluteEndPos:t+n+r.length,from:n,to:n,insert:r};return t+=r.length,i})})}async function Uu(e,t){let n=e.state.facet(rl),{override:r}=e.state.facet(il),i=await r(),a=e.state,o=a.selection.main.head,s=a.doc.toString();try{let r=await Vu({text:s,cursorOffset:o,config:n,otherDocuments:i});if(!r||r.completionItems.length===0||!((t===void 0||o===t)&&ui(e.state)!==`active`&&e.hasFocus))return;let c=Hu(r),l=c.at(0);if(!l)return;let u=kr.of(l,a.doc.length),d=u.invert(a.doc);e.dispatch({changes:u,effects:$o.of({index:0,reverseChangeSet:d,changeSpecs:c}),annotations:[cl.of(null),sl.of(null),Vr.addToHistory.of(!1)]})}catch(e){console.warn(`copilot completion failed`,e),await new Promise(e=>setTimeout(e,300))}}function Wu(e){return e.docChanged&&!e.transactions.some(e=>e.effects.some(e=>e.is(es)||e.is(ts)))}function Gu(e){if(!e.view.hasFocus||e.state.field(ol)||ui(e.state)===`active`)return!0;for(let t of e.transactions)if(t.annotation(sl)!==void 0)return!0}function Ku(){let e=null,t=0;return R.updateListener.of(n=>{let r=n.view.state.facet(rl);if(!r.alwaysOn||!Wu(n)||(e&&clearTimeout(e),Gu(n)))return;let i=n.state.selection.main.head;r.shouldComplete&&!r.shouldComplete(new pi(n.view.state,i,!1))||(e=setTimeout(async()=>{i===t&&await Uu(n.view,t)},r.timeout),t=i)})}function qu(e){let t=e.state.field(ol);if(!t)return!1;let n=t.reverseChangeSet?.invert(e.state.doc);e.dispatch({changes:t.reverseChangeSet,effects:es.of(null),annotations:[cl.of(null),sl.of(null),Vr.addToHistory.of(!1)]});let r=0;return n?.iterChangedRanges((e,t,n,i)=>{r=i}),e.dispatch({changes:n,selection:Ar.cursor(r),annotations:[sl.of(null),Vr.addToHistory.of(!0)]}),!0}var Ju=e=>{let{state:t}=e,n=t.field(ol);if(!n)return!1;let{changeSpecs:r}=n;if(r.length<2)return!1;let i=(n.index+1)%r.length,a=r.at(i);if(!a)return!1;let o=n.reverseChangeSet.apply(t.doc),s=kr.of(n.reverseChangeSet,t.doc.length).compose(kr.of(a,o.length)),c=kr.of(a,o.length).invert(o);return e.dispatch({changes:s,effects:$o.of({index:i,reverseChangeSet:c,changeSpecs:r}),annotations:[cl.of(null),sl.of(null),Vr.addToHistory.of(!1)]}),!0};function Yu(e){let t=e.state.field(ol);return t&&e.dispatch({changes:t.reverseChangeSet,effects:ts.of(null),annotations:[cl.of(null),sl.of(null),Vr.addToHistory.of(!1)]}),!1}function Xu(e,t){return e.state.field(ol)?t===`Tab`?qu(e):Yu(e):!1}function Zu(e){let t=!1,n=e.state.selection.asSingle().ranges.at(0)?.head,r=e.state.field(ol);return n!==void 0&&r?(r.decorations?.between(n,n,()=>{t=!0}),t):!1}function Qu(){return R.domEventHandlers({keydown(e,t){return e.key===`]`&&e.ctrlKey?!1:e.key!==`Shift`&&e.key!==`Control`&&e.key!==`Alt`&&e.key!==`Meta`&&Xu(t,e.key)},mouseup(e,t){let n=e.target;return n.nodeName===`BUTTON`&&n.dataset.action===`codeium-cycle`?(Ju(t),e.stopPropagation(),e.preventDefault(),!0):Zu(t)?qu(t):Yu(t)}})}function $u(){return gr.of([{key:`Ctrl-]`,run:Ju}])}function ed(){return R.updateListener.of(e=>{e.focusChanged&&Yu(e.view)})}function td(e){return[rl.of(e),ol,Sr.highest($u()),Sr.highest(ed()),Sr.high(Qu()),Ku()]}var nd=h();function rd({response:e,prefix:t,suffix:n}){if(!e)return e;let r=e;return t&&r.startsWith(t)&&(r=r.slice(t.length)),n&&r.endsWith(n)&&(r=r.slice(0,-n.length)),r}var id=new Dr,ad=It.get(`@github/copilot-language-server`),od={delay:150,includeKeymap:!0,events:{shouldShowSuggestion:e=>e.hasFocus,beforeSuggestionFetch:e=>e.hasFocus}},sd=e=>{let t=[];return e.copilot===`codeium`&&e.codeium_api_key&&t.push(td({apiKey:e.codeium_api_key,language:Qc.PYTHON}),il.of({override:async()=>[{text:ce(``),language:Qc.PYTHON,editorLanguage:`python`}]})),e.copilot===`github`&&t.push(Pa({...od,fetchFn:async(e,t,n)=>{let r=e.selection.main.head;if(!gn()||!n.hasFocus||e.doc.length===0)return``;let i=Sn(),a=await i.flushDocumentChanges(e.doc.toString());if(t.aborted||e.doc!==n.state.doc)return``;let o=cd(e,a),s=await i.getCompletion(o,t);return t.aborted||e.doc!==n.state.doc||r!==n.state.selection.main.head?(It.debug(`ignoring response because of new position`),``):ld(s,o.position,e)}})),e.copilot===`custom`&&t.push(Pa({...od,fetchFn:async(e,t,n)=>{let r=e.selection.main.head;if(e.doc.length===0||!n.hasFocus)return``;let i=e.doc.sliceString(0,e.selection.main.head),a=e.doc.sliceString(e.selection.main.head,e.doc.length);if(i.length===0)return``;let o=e.field(Pe).type,s=await Bt.post(`/ai/inline_completion`,{prefix:i,suffix:a,language:o},{signal:t});return t.aborted||e.doc!==n.state.doc||r!==n.state.selection.main.head?(It.debug(`ignoring response because of new position`),``):(s=rd({response:s,prefix:i,suffix:a}),s)}})),[...t,Sr.highest(gr.of([{key:`Escape`,run:e=>{let t=ja(e);return!v(e)&&t}}])),id.of(xn())]};function cd(e,t){let n=e.doc.toString(),r=t.split(`
|
|
12
12
|
`).length-n.split(`
|
|
13
|
-
`).length,i=ud(e.doc,e.selection.main.head);return i.line+=r,{textDocument:{uri:`file://${
|
|
13
|
+
`).length,i=ud(e.doc,e.selection.main.head);return i.line+=r,{textDocument:{uri:`file://${vn}`,version:`replace_me`},position:i,context:{triggerKind:nd.InlineCompletionTriggerKind.Automatic},formattingOptions:{tabSize:e.tabSize,insertSpaces:!0}}}function ld(e,t,n){if(!e)return ad.debug(`No response from copilot`),``;let r=Array.isArray(e)?e[0]:e.items[0];if(!r)return ad.debug(`No response from copilot`),``;let{insertText:i,range:a}=r,o=String(i);if(!a)return ad.error(`No range from copilot`),o;let s=a.start.character-t.character,c=s<0?o.slice(-s):o,l=n.doc.sliceString(n.selection.main.head,n.doc.length);for(let e=0;e<c.length;e++){let t=c.slice(e);if(l.startsWith(t))return c.slice(0,e)}return c}function ud(e,t){let n=e.lineAt(t);return{line:n.number-1,character:t-n.from}}function dd(e){return zt(`create`in e,`Expected query to have a "create" method`),e}var fd=Gt({findText:``,replaceText:``,caseSensitive:!1,wholeWord:!1,regexp:!1,isOpen:!1,currentView:void 0},(e,t)=>{if(t===void 0)return e;switch(t.type){case`setFind`:return{...e,findText:t.find};case`setReplace`:return{...e,replaceText:t.replace};case`setCaseSensitive`:return{...e,caseSensitive:t.caseSensitive};case`setWholeWord`:return{...e,wholeWord:t.wholeWord};case`setRegex`:return{...e,regexp:t.regexp};case`setIsOpen`:return{...e,isOpen:t.isOpen};case`setCurrentView`:return{...e,currentView:{view:t.view,range:t.range}};case`clearCurrentView`:return{...e,currentView:void 0}}});function pd(e){if([...document.querySelectorAll(`[role="dialog"][data-state="open"]`)].some(e=>e instanceof HTMLElement&&e.childNodes.length>0))return!1;if(e){let t=e.state.selection.main,n=e.state.sliceDoc(t.from,t.to);n?(o.set(fd,{type:`setFind`,find:n}),o.set(fd,{type:`setCurrentView`,view:e,range:{from:t.from,to:t.to}})):o.set(fd,{type:`setCurrentView`,view:e,range:{from:0,to:0}})}return o.get(fd).isOpen?(o.set(fd,{type:`setIsOpen`,isOpen:!1}),requestAnimationFrame(()=>{o.set(fd,{type:`setIsOpen`,isOpen:!0})}),!0):(o.set(fd,{type:`setIsOpen`,isOpen:!0}),!0)}function md(){return o.get(fd).isOpen?(o.set(fd,{type:`setIsOpen`,isOpen:!1}),!0):!1}var hd=I.define();function gd(){let e=o.get(fd),t=it();for(let n of t)n.state.readOnly||n.dispatch({effects:hd.of(new $r({search:e.findText,caseSensitive:e.caseSensitive,regexp:e.regexp,replace:e.replaceText,wholeWord:e.wholeWord}))})}function _d(){let e=it();for(let t of e)t.state.readOnly||t.dispatch({effects:hd.of(new $r({search:``}))})}var vd=fr.define({create(){let e=o.get(fd);return dd(new $r({search:e.findText,caseSensitive:e.caseSensitive,regexp:e.regexp,replace:e.replaceText,wholeWord:e.wholeWord})).create()},update(e,t){for(let n of t.effects)n.is(hd)&&(e=dd(n.value).create());return e}}),yd=L.mark({class:`cm-searchMatch`}),bd=L.mark({class:`cm-searchMatch cm-searchMatch-selected`}),xd=Hr.fromClass(class{decorations;view;constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(vd))}update(e){let t=e.state.field(vd);(t!==e.startState.field(vd)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight(e){if(!e.spec.valid)return L.none;let{view:t}=this,n=new jr,r=t.visibleRanges,i=r.length;for(let a=0;a<i;a++){let{to:o}=r[a],{from:s}=r[a];for(;a<i-1&&o>r[a+1].from-500;)o=r[++a].to;e.highlight(t.state,s,o,(e,r)=>{let i=t.state.selection.ranges.some(t=>t.from===e&&t.to===r);n.add(e,r,i?bd:yd)})}return n.finish()}},{decorations:e=>e.decorations}),Sd=R.baseTheme({"&light .cm-searchMatch":{backgroundColor:`var(--cm-search-match-background-light)`},"&dark .cm-searchMatch":{backgroundColor:`var(--cm-search-match-background-dark)`},"&light .cm-searchMatch-selected":{backgroundColor:`transparent`},"&dark .cm-searchMatch.cm-searchMatch-selected":{backgroundColor:`var(--cm-search-match-selected-background-dark) !important`}});function Cd(e){return[gr.of([{key:`Escape`,preventDefault:!1,run:md},{key:e.getHotkey(`cell.selectNextOccurrence`).key,preventDefault:!0,run:Zr},{key:e.getHotkey(`cell.findAndReplace`).key,preventDefault:!0,run:pd}]),ei(),xd,vd,Sd]}var wd=L.mark({class:`underline`}),Td=I.define(),Ed=I.define(),Dd=I.define(),Od=fr.define({create(){return L.none},update(e,t){let n=e.map(t.changes);for(let r of t.effects)r.is(Td)?n=e.update({add:[wd.range(r.value.from,r.value.to)]}):r.is(Ed)?n=e.update({add:[k.range(r.value.from,r.value.to)]}):r.is(Dd)&&(n=L.none);return n},provide:e=>R.decorations.from(e)}),kd=class{view;commandClickMode;hoveredRange;onClick;constructor(e,t){this.view=e,this.commandClickMode=!1,this.hoveredRange=null,this.onClick=t,window.addEventListener(`keydown`,this.keydown),window.addEventListener(`keyup`,this.keyup),window.addEventListener(`blur`,this.windowBlur),window.addEventListener(`mouseleave`,this.windowBlur)}update(e){}destroy(){window.removeEventListener(`keydown`,this.keydown),window.removeEventListener(`keyup`,this.keyup),window.removeEventListener(`blur`,this.windowBlur),window.removeEventListener(`mouseleave`,this.windowBlur),this.view.dom.removeEventListener(`mousemove`,this.mousemove),this.view.dom.removeEventListener(`click`,this.click)}keydown=e=>{(e.key===`Meta`||e.key===`Control`)&&(this.commandClickMode=!0,this.view.dom.addEventListener(`mousemove`,this.mousemove),this.view.dom.addEventListener(`click`,this.click))};keyup=e=>{(e.key===`Meta`||e.key===`Control`)&&this.exitCommandClickMode()};windowBlur=()=>{this.commandClickMode&&this.exitCommandClickMode()};exitCommandClickMode(){this.commandClickMode=!1,this.view.dom.removeEventListener(`mousemove`,this.mousemove),this.view.dom.removeEventListener(`click`,this.click),this.clearUnderline()}mousemove=e=>{if(!e.metaKey&&!e.ctrlKey){this.exitCommandClickMode();return}if(!this.commandClickMode){this.clearUnderline();return}let t=this.view.posAtCoords({x:e.clientX,y:e.clientY});if(t==null){this.clearUnderline();return}let n=this.view.state.field(x,!1)?.ranges.find(e=>t>=e.from&&t<=e.to);if(n){let{from:e,to:r}=n;if(this.hoveredRange&&this.hoveredRange.from===e&&this.hoveredRange.to===r)return;this.clearUnderline(),this.hoveredRange={from:e,to:r,position:t},this.view.dispatch({effects:Ed.of(this.hoveredRange)});return}let r=yr(this.view.state).cursorAt(t);if(r.name===`VariableName`){let{from:e,to:n}=r;if(this.hoveredRange&&this.hoveredRange.from===e&&this.hoveredRange.to===n)return;this.clearUnderline(),this.hoveredRange={from:e,to:n,position:t},this.view.dispatch({effects:Td.of(this.hoveredRange)})}else this.clearUnderline()};click=e=>{this.hoveredRange&&(e.preventDefault(),e.stopPropagation(),this.view.dispatch({selection:{head:this.hoveredRange.position,anchor:this.hoveredRange.position}}),this.onClick(this.view))};clearUnderline(){this.hoveredRange&&=(this.view.dispatch({effects:Dd.of(null)}),null)}},Ad=e=>Hr.define(t=>new kd(t,e));function jd(){return[Od,Ad(e=>{ct(e)}),R.baseTheme({".underline":{textDecoration:`underline`,cursor:`pointer`,color:`var(--link)`}})]}function Md(){return[R.domEventHandlers({drop:(e,t)=>{let n=e.dataTransfer?.files[0];if(n?.type.startsWith(`text/`))return e.preventDefault(),Ge(t,n),!0;if(n?.type.startsWith(`image/`))return e.preventDefault(),pe(t,n),!0;let r=e.dataTransfer?.getData(`text/plain`);if(r){e.preventDefault();let n=t.posAtCoords({x:e.clientX,y:e.clientY});return n!==null&&t.dispatch({changes:{from:n,to:n,insert:r},scrollIntoView:!0}),!0}return!1},dragover:e=>{e.preventDefault()}})]}function Nd(){return[R.domEventHandlers({paste:(e,t)=>{let n=e.clipboardData?.getData(`text/plain`);if(!n||!Pd(n))return!1;let{setup:r,cells:i}=Fd(n);if(r===null&&i.length===0)return!1;let a=t.state.facet(d);return r!==null&&a.addOrAppendSetupCell(r),i.length>0&&a.createManyBelow(i),!0}})]}function Pd(e){return/@app\.cell|@app\.function|\bapp\.setup\b/.test(e)}function Fd(e){if(!Pd(e))return{setup:null,cells:[]};let t=[],n=[],r=vi.parse(e),i=(t,n)=>{let r=e.lastIndexOf(`
|
|
14
14
|
`,t-1)+1;return Id(e.slice(r,n))},a=(e,n)=>{let r=i(e,n);r.trim()&&t.push(r)},o=(e,t)=>{let n=[];for(let t=e.firstChild;t;t=t.nextSibling)t.name!==`:`&&n.push(t);t&&n.at(-1)?.name===`ReturnStatement`&&n.pop();let r=n[0],a=n.at(-1);if(!r||!a)return null;let o=i(r.from,a.to);return o.trim()?o:null};return r.iterate({enter:r=>{if(r.name===`WithStatement`){let t=r.node.getChild(`Body`);if(t&&e.slice(r.from,t.from).includes(`app.setup`)){let e=o(t,!1);e!==null&&n.push(e)}return!1}if(r.name!==`DecoratedStatement`)return!0;let i=r.node.getChild(`Decorator`),s=r.node.getChild(`FunctionDefinition`);if(!i||!s)return!1;let c=e.slice(i.from,i.to).trim();if(c.startsWith(`@app.cell`)){let e=s.getChild(`Body`);if(e){let n=o(e,!0);n!==null&&t.push(n)}return!1}return c.startsWith(`@app.function`)&&a(s.from,s.to),!1}}),{setup:n.length>0?n.join(`
|
|
15
15
|
|
|
16
16
|
`):null,cells:t}}function Id(e){let t=e.split(`
|
|
17
17
|
`);if(t.length===0)return``;let n=t.filter(e=>e.trim().length>0);if(n.length===0)return``;let r=/^\s*/,i=Math.min(...n.map(e=>e.match(r)?.[0].length??1/0));return i===0?e.trim():t.map(e=>e.slice(i)).join(`
|
|
18
|
-
`).trim()}function Ld(e,t,n,r){return r!==`{`||t!==n||!vr(e.state).resolveInner(t,-1)?.type.name.includes(`String`)?!1:(e.dispatch({changes:{from:t,to:n,insert:`{}`},selection:{anchor:t+1},userEvent:`input.type`}),!0)}function Rd(){return R.inputHandler.of(Ld)}function zd(e){let{showPlaceholder:t,enableAI:n}=e;return t?`marimo-import`:n?`ai`:`none`}var Bd=`cm-tooltip-portal`;function Vd(e){if(e==null)return document.querySelector(`#App`)??void 0;let t=document.querySelector(e);if(t==null)return;let n=t.querySelector(`:scope > .${Bd}`);if(n!=null)return n;let r=document.createElement(`div`);return r.className=`${Bd} not-prose contents`,t.append(r),r}var Hd=e=>{let{cellId:t,keymapConfig:n,hotkeys:r,enableAI:i,cellActions:a,completionConfig:o,lspConfig:s,diagnosticsConfig:c,displayConfig:l,inlineAiTooltip:u}=e,d=zd(e);return[mn(n,r),Md(),Nd(),Yo(),ke({cellId:t,completionConfig:o,hotkeys:r,placeholderType:d,lspConfig:s,diagnosticsConfig:c}),Be({cellId:t,hotkeys:r,cellActions:a,keymapConfig:n}),Wd(e),jd(),c?.enabled?Zr():[],i&&u?[Ka({prompt:e=>io({prompt:e.prompt,selection:e.selection,codeBefore:e.codeBefore,codeAfter:e.codeAfter,language:Xe(e.editorView)})}),Ba.of({hideOnBlur:!0})]:[],te(t,l.reference_highlighting??!0),Ko(t,l.code_lens??!0)]},Ud=e=>{let{from:t,to:n}=e.state.selection.main;if(t!==n)return!1;let r=e.state.doc.lineAt(n);return r.text.slice(0,n-r.from).trim()!==``&&si(e)},Wd=e=>{let{theme:t,hotkeys:n,completionConfig:r,acceptCompletionOnEnter:i,cellId:a,lspConfig:o,diagnosticsConfig:s,tooltipParentSelector:c}=e,l=zd(e),u=r.auto_close_pairs!==!1;return[R.lineWrapping,Pr(),Nr(),Tr(),fr(),Ur(),Cr(),Ir(),br({position:`fixed`,parent:Vd(c)}),Ue(),t===`dark`?Zn:Yn,Re(o),sd(r),Hr(),Rd(),u?ci():[],Qo(i),u?xr.high(hr.of(ii)):[],Rr(),wr(),yr.of(` `),Dr(jr,{fallback:!0}),hr.of(mr),Je({placeholderType:l,completionConfig:r,hotkeys:n,cellId:a,lspConfig:{...o,diagnostics:s}}),Ne.of(Yr()),_r.allowMultipleSelections.of(!0),Cd(n),hr.of([{key:`Tab`,run:e=>ui(e)||Ud(e)||Kr(e),preventDefault:!0},{key:n.getHotkey(`completion.moveDown`).key,run:e=>li(e.state)!==null&&(oi(!0)(e),!0),preventDefault:!0},{key:n.getHotkey(`completion.moveUp`).key,run:e=>li(e.state)!==null&&(oi(!1)(e),!0),preventDefault:!0}]),hr.of([...ei,Jr])]},Gd=(e=>!e||e instanceof WebAssembly.Module?e:typeof e==`object`&&`default`in e?e.default??e:e)(ea),Kd=e=>{Wi(e),qd(e)};function qd(e){typeof e.__wbindgen_start==`function`&&e.__wbindgen_start()}if(Gd&&Gd.__wbindgen_start)Kd(Gd);else if(`Bun`in globalThis){let e;if(Gd instanceof WebAssembly.Module)({instance:e}=await WebAssembly.instantiate(Gd,{"./loro_wasm_bg.js":Qi}));else{let t=Bun.pathToFileURL(Gd);({instance:e}=await WebAssembly.instantiateStreaming(fetch(t),{"./loro_wasm_bg.js":Qi}))}Kd(e.exports)}else{let e=Gd instanceof WebAssembly.Module?Gd:await ur(()=>import(`./loro_wasm_bg-C2Fqi8D-.js`),__vite__mapDeps([0,1,2]),import.meta.url),t=e instanceof WebAssembly.Module?e:e&&e.default||e,n;if(t instanceof WebAssembly.Instance)n=t;else if(t instanceof WebAssembly.Module)n=await WebAssembly.instantiate(t,{"./loro_wasm_bg.js":Qi});else if(t instanceof ArrayBuffer||ArrayBuffer.isView(t)){let{instance:e}=await WebAssembly.instantiate(t,{"./loro_wasm_bg.js":Qi});n=e}else if(typeof t==`string`||t instanceof URL){let e=await fetch(t),{instance:r}=await WebAssembly.instantiateStreaming(e,{"./loro_wasm_bg.js":Qi});n=r}else throw console.error(`Unsupported wasm import type:`,t),Error(`Unsupported wasm import type: `+typeof t);Kd(n.exports??n)}var Jd=[`Map`,`Text`,`List`,`Tree`,`MovableList`,`Counter`];function Yd(e){return Ki(e)}function Xd(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return typeof t!=`object`||!t||typeof t.kind!=`function`?!1:Jd.includes(e.kind())}var Zd=class{constructor(e,t=3e4){this.listeners=new Set,this.inner=new Yi(e,t),this.peer=e,this.timeout=t}apply(e,t=`remote`){let{updated:n,added:r}=this.inner.apply(e);this.listeners.forEach(e=>{e({updated:n,added:r,removed:[]},t)}),this.startTimerIfNotEmpty()}setLocalState(e){let t=this.inner.getState(this.peer)==null;this.inner.setLocalState(e),t?this.listeners.forEach(e=>{e({updated:[],added:[this.inner.peer()],removed:[]},`local`)}):this.listeners.forEach(e=>{e({updated:[this.inner.peer()],added:[],removed:[]},`local`)}),this.startTimerIfNotEmpty()}getLocalState(){return this.inner.getState(this.peer)}getAllStates(){return this.inner.getAllStates()}encode(e){return this.inner.encode(e)}encodeAll(){return this.inner.encodeAll()}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}peers(){return this.inner.peers()}destroy(){clearInterval(this.timer),this.listeners.clear()}startTimerIfNotEmpty(){this.inner.isEmpty()||this.timer!=null||(this.timer=setInterval(()=>{let e=this.inner.removeOutdated();e.length>0&&this.listeners.forEach(t=>{t({updated:[],added:[],removed:e},`timeout`)}),this.inner.isEmpty()&&(clearInterval(this.timer),this.timer=void 0)},this.timeout/2))}};qi.prototype.toJsonWithReplacer=function(e){let t=new Set,n=this,r=(r,a)=>{if(typeof a==`string`&&Yd(a)&&!t.has(a)){t.add(a);let o=n.getContainerById(a);if(o==null)throw Error(`ContainerID not found: ${a}`);let s=e(r,o);if(s===o){let e=o.getShallowValue();return typeof e==`object`?i(e):e}if(Xd(s))throw Error(`Using new container is not allowed in toJsonWithReplacer`);return typeof s==`object`&&s?i(s):s}if(typeof a==`object`&&a)return i(a);let o=e(r,a);if(Xd(o))throw Error(`Using new container is not allowed in toJsonWithReplacer`);return o},i=e=>{if(Array.isArray(e))return e.map((e,t)=>r(t,e)).filter(e=>e!==void 0);let t={};for(let[n,i]of Object.entries(e)){let e=r(n,i);e!==void 0&&(t[n]=e)}return t};return i(n.getShallowValue())};var Qd=Symbol(`loro.callPendingEventsWrapped`);function $d(e,t){let n=Object.getOwnPropertyDescriptor(e,t);if(!n||typeof n.value!=`function`)return;let r=n.value;if(r[Qd])return;let i=function(...e){let t;try{return t=r.apply(this,e),t}finally{t&&typeof t.then==`function`?t.finally(()=>{$i()}):$i()}};i[Qd]=!0,Object.defineProperty(e,t,{...n,value:i})}function ef(e,t){for(let n of t)$d(e,n)}ef(qi.prototype,[`setDetachedEditing`,`attach`,`detach`,`fork`,`forkAt`,`checkoutToLatest`,`checkout`,`commit`,`getCursorPos`,`revertTo`,`export`,`exportJsonUpdates`,`exportJsonInIdSpan`,`importJsonUpdates`,`import`,`importUpdateBatch`,`importBatch`,`travelChangeAncestors`,`getChangedContainersIn`,`diff`,`applyDiff`,`setPeerId`]),ef(Gi.prototype,[`set`,`delete`,`apply`,`removeOutdated`]),ef(ta.prototype,[`undo`,`redo`]);var tf=R.baseTheme({".loro-cursor":{position:`absolute`,width:`2px`,display:`inline-block`,height:`1.2em`},".loro-cursor::before":{position:`absolute`,top:`1.3em`,left:`0`,content:`var(--rtc-name)`,padding:`2px 6px`,fontSize:`12px`,borderRadius:`3px`,whiteSpace:`nowrap`,userSelect:`none`,backgroundColor:`inherit`,opacity:`0.7`},".loro-selection":{opacity:`0.5`}});Wr.define();var nf=I.define(),rf=dr.define({create(){return{remoteCursors:new Map,isCheckout:!1}},update(e,t){for(let n of t.effects)if(n.is(nf))switch(n.value.type){case`update`:{let{peer:t,user:r,cursor:i}=n.value;e.remoteCursors.set(t,{uid:t,cursor:i,user:r});break}case`delete`:e.remoteCursors.delete(n.value.peer);break;case`checkout`:e.isCheckout=n.value.checkout}return e}}),af=e=>{let t=e.transactions.flatMap(e=>e.effects).filter(e=>e.is(nf));return e.docChanged||e.viewportChanged||t.length>0},of=()=>pr({above:!0,class:`loro-cursor-layer`,update:af,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(rf);return n?[]:[...t.values()].flatMap(t=>{let n=kr.cursor(t.cursor.anchor);return cf.createCursor(e,n,t.user?.name||`unknown`,t.user?.colorClassName||``)})}}),sf=()=>pr({above:!1,class:`loro-selection-layer`,update:af,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(rf);return n?[]:[...t.entries()].filter(([,e])=>e.cursor.head!==void 0&&e.cursor.anchor!==e.cursor.head).flatMap(([,t])=>{let n=kr.range(t.cursor.anchor,t.cursor.head);return Lr.forRange(e,`loro-selection ${t.user?.colorClassName||``}`,n)})}}),cf=class e{left;top;height;name;colorClassName;constructor(e,t,n,r,i){this.left=e,this.top=t,this.height=n,this.name=r,this.colorClassName=i}draw(){let e=document.createElement(`div`);return this.adjust(e),e}update(e){return this.adjust(e),!0}adjust(e){e.style.left=`${this.left}px`,e.style.top=`${this.top}px`,e.style.height=`${this.height}px`,e.className=`loro-cursor ${this.colorClassName}`,e.style.setProperty(`--rtc-name`,`"${this.name}"`)}eq(e){return this.left===e.left&&this.top===e.top&&this.height===e.height&&this.name===e.name}static createCursor(t,n,r,i){let a=e.calculateAbsoluteCursorPosition(n,t);if(!a)return[];let o=t.scrollDOM.getBoundingClientRect(),s=(t.textDirection===zr.LTR?o.left:o.right-t.scrollDOM.clientWidth)-t.scrollDOM.scrollLeft,c=o.top-t.scrollDOM.scrollTop;return[new e(a.left-s,a.top-c,a.bottom-a.top,r,i)]}static calculateAbsoluteCursorPosition(e,t){let n=Math.max(0,Math.min(t.state.doc.length,e.anchor));return t.coordsAtPos(n,e.assoc||1)}},lf=(e,t,n,r)=>{let i=[],{updated:a,added:o}=n;for(let n of[...a,...o]){let a=uf(e,t,n,r);a&&i.push(a)}return i},uf=(e,t,n,r)=>{let i=t.getAllStates()[n];if(!i||n===e.peerIdStr||i.scopeId!==r)return;if(i.type===`delete`)return nf.of({type:`delete`,peer:i.uid,scopeId:i.scopeId});let a=Xi.decode(i.cursor.anchor),o=e.getCursorPos(a)?.offset??0,s=o;if(i.cursor.head){let t=Xi.decode(i.cursor.head);s=e.getCursorPos(t)?.offset??0}return nf.of({type:`update`,peer:i.uid,scopeId:i.scopeId,cursor:{anchor:o,head:s},user:i.user})},df=class{sub;view;doc;user;awareness;getTextFromDoc;scopeId;getUserId;constructor(e,t,n,r,i,a,o){this.view=e,this.doc=t,this.user=n,this.awareness=r,this.getTextFromDoc=i,this.scopeId=a,this.getUserId=o,this.sub=this.doc.subscribe(e=>{if(e.by===`local`){let e=[];for(let t of this.awareness.peers()){let n=uf(this.doc,this.awareness,t,this.scopeId);n&&e.push(n)}this.view.dispatch({effects:e})}else e.by===`checkout`&&this.view.dispatch({effects:[nf.of({type:`checkout`,checkout:this.doc.isDetached()})]})})}update(e){if(!e.selectionSet&&!e.focusChanged&&!e.docChanged)return;let t=e.state.selection.main;if(this.view.hasFocus&&!this.doc.isDetached()){let e=pf({doc:this.doc,getTextFromDoc:this.getTextFromDoc,anchor:t.anchor,head:t.head});this.awareness.setLocalState({type:`update`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId,cursor:e,user:this.user})}else this.awareness.setLocalState({type:`delete`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}destroy(){this.sub?.(),this.awareness.setLocalState({type:`delete`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}},ff=class{_awarenessListener;view;doc;awareness;scopeId;constructor(e,t,n,r){this.view=e,this.doc=t,this.awareness=n,this.scopeId=r;let i=async(e,t)=>{t!==`local`&&this.view.dispatch({effects:lf(this.doc,this.awareness,e,this.scopeId)})};this._awarenessListener=i,this.awareness.addListener(i)}destroy(){this._awarenessListener&&this.awareness.removeListener(this._awarenessListener)}},pf=({doc:e,getTextFromDoc:t,anchor:n,head:r})=>{n===r&&(r=void 0);let i=t(e).getCursor(n)?.encode();if(!i)throw Error(`cursor head not found`);let a;return r!==void 0&&(a=t(e).getCursor(r)?.encode()),{anchor:i,head:a}},mf=[`bg-(--amber-6)`,`bg-(--blue-6)`,`bg-(--crimson-6)`,`bg-(--cyan-6)`,`bg-(--grass-6)`,`bg-(--gray-6)`,`bg-(--green-6)`,`bg-(--lime-6)`,`bg-(--orange-6)`,`bg-(--purple-6)`,`bg-(--red-6)`,`bg-(--sage-6)`,`bg-(--sky-6)`,`bg-(--slate-6)`],hf=e=>{if(typeof e==`string`){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t=Math.trunc(t);return mf[Math.abs(t)%mf.length]}return mf[e%mf.length]},Q=It.get(`rtc`),gf=Q.get(`awareness`).disabled(),_f=`awareness:`;function vf(e,t){let n=new TextEncoder().encode(e);return new Uint8Array([...n,...t])}function yf(e,t){return new TextDecoder().decode(e.slice(0,t.length))===t}function bf(e,t){return e.slice(t.length)}var xf=r(void 0),$=new qi,Sf=new Zd($.peerIdStr),Cf=ni(()=>{Q.debug(`creating websocket`);let e=Yt().getWsSyncURL(Ht()).toString(),t=new na(e,void 0,{maxRetries:10,debug:!1,startClosed:!0,connectionTimeout:1e4});return Promise.resolve().then(async()=>{await Gt(),Bt()===`edit`&&t.reconnect()}),t.addEventListener(`message`,async e=>{let t=await e.data.arrayBuffer(),n=new Uint8Array(t);if(yf(n,_f)){let e=bf(n,_f);Sf.apply(e),gf.debug(`applied awareness update`);return}$.import(n),Q.debug(`imported doc change. new doc:`,$.toJSON()),o.get(xf)!==$&&o.set(xf,$)}),t.addEventListener(`open`,()=>{Q.debug(`websocket open`)}),t.addEventListener(`close`,e=>{Q.warn(`websocket close`,e),o.get(xf)===$&&o.set(xf,void 0)}),t});me()&&Cf(),$.subscribeLocalUpdates(e=>{Q.debug(`local update, sending to server`),Cf().send(new Uint8Array(e))}),Sf.addListener((e,t)=>{let n=[...e.added,...e.removed,...e.updated];t===`local`&&(gf.debug(`awareness changes`,n),Cf().send(vf(_f,Sf.encode(n))))});function wf(e,t,n=``){if(Wt())return{extension:[],code:n};let r=$.getByPath(`codes/${e}`)!==void 0,i=$.getMap(`codes`).getOrCreateContainer(e,new Zi);return r||(Q.log(`initializing code for new cell`,n),i.insert(0,n)),{code:n.toString(),extension:[Tf(e),Ef(e),Df($,Sf,{get name(){return o.get(Ke)||`Anonymous`},get colorClassName(){return hf(this.name)}},()=>i,e),be($,[`codes`,e],()=>i)]}}function Tf(e){let t=(e,t)=>{let n=e.state.field(Pe).type,r=t.toString();r&&r!==n&&(Q.debug(`[incoming] setting language type: ${n} -> ${r}`),lt(e,{language:r,keepCodeAsIs:!0}))},n=(e,t)=>{let n=e.state.field(nt),r=t.toJSON();a(n,r)||e.dispatch({effects:[Ze.of(r)],annotations:[$e.of(!0)]})};return Vr.define(r=>{let i;return Promise.resolve().then(()=>{let a=$.getByPath(`languages/${e}`);if(!a){Q.error(`no language container found for cell`,e);return}zt(a instanceof Zi,`language type is not a LoroText`);let o=$.getByPath(`language_metadata/${e}`);if(!o){Q.error(`no language metadata container found for cell`,e);return}zt(o instanceof Ji,`language metadata is not a LoroMap`),t(r,a),n(r,o),i=$.subscribe(e=>{if(e.origin===`local`)return;let i=e.events.some(e=>e.target===a.id),s=e.events.some(e=>e.target===o.id);i&&t(r,a),s&&n(r,o)})}),{destroy(){i()}}})}function Ef(e){let t=$.getMap(`languages`).getOrCreateContainer(e,new Zi),n=$.getMap(`language_metadata`).getOrCreateContainer(e,new Ji);return R.updateListener.of(e=>{let r=t.toString()!==``;if(!e.docChanged&&r)return;if(!r){let r=He(e.state).type;lt(e.view,{language:r}),Q.debug(`no initial language, setting default to`,r),t.delete(0,t.length),t.insert(0,r),Q.debug(`no initial language metadata, setting default to`,e.state.field(nt));let i=e.state.field(nt);for(let e of Object.keys(i))n.set(e,i[e]);$.commit();return}let i=!1;for(let r of e.transactions)if(!r.annotation($e)){for(let e of r.effects)if(e.is(de)&&t.toString()!==e.value.type&&(Q.debug(`[outgoing] language change: ${t} -> ${e.value.type}`),t.delete(0,t.length),t.insert(0,e.value.type),i=!0),e.is(Ze)||e.is(We)){let t=e.value;e.is(We)?(Q.debug(`[outgoing] setting language metadata: `,t),n.clear()):Q.debug(`[outgoing] updating language metadata: `,t);for(let e of Object.keys(t))n.set(e,t[e]);i=!0}}i&&$.commit()})}function Df(e,t,n,r,i,a){let o=`loro:cell:${i}`;return[rf,of(),sf(),Vr.define(i=>new df(i,e,n,t,r,o,a)),Vr.define(n=>new ff(n,e,t,o)),tf]}var Of=De,kf=e=>{let t=(0,H.c)(41),{resetOnBlur:n,placeholderText:r,initialValue:i,flexibleWidth:a,onNameChange:o,className:s}=e,c=n!==void 0&&n,l=i===void 0?null:i,u=a!==void 0&&a,{sendListFiles:d}=mi(),[f,p]=(0,V.useState)(l),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=[],t[0]=m):m=t[0];let[h,g]=(0,V.useState)(m),[_,v]=(0,V.useState)(!1),y=(0,V.useRef)(null),b=(0,V.useRef)(!1),x,S;t[1]===l?(x=t[2],S=t[3]):(x=()=>{p(l)},S=[l],t[1]=l,t[2]=x,t[3]=S),(0,V.useEffect)(x,S);let C;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{v(!0)},t[4]=C):C=t[4];let w=C,T;t[5]!==l||t[6]!==c?(T=e=>{e.relatedTarget?.closest(`.filename-input`)||(v(!1),c&&p(l))},t[5]=l,t[6]=c,t[7]=T):T=t[7];let E=T,D;t[8]===f?D=t[9]:(D=fn.dirname(f||``),t[8]=f,t[9]=D);let O=D,ee=fn.basename(f||``),k=h.filter(e=>fn.basename(e.path).startsWith(ee)),te;t[10]!==O||t[11]!==_||t[12]!==d?(te=async()=>{if(!_){g([]);return}let e=await d({path:O});g(e.files)},t[10]=O,t[11]=_,t[12]=d,t[13]=te):te=t[13];let ne;t[14]!==O||t[15]!==_?(ne=[O,_],t[14]=O,t[15]=_,t[16]=ne):ne=t[16];let{isPending:re}=xi(te,ne),A=Af(f,h,l),j=(A||k.length>0)&&(0,U.jsxs)(st,{className:`font-mono`,children:[!re&&(0,U.jsx)(Ve,{children:`No files`}),A&&(0,U.jsxs)(ue,{variant:`success`,className:`py-2 px-3`,onSelect:()=>{A&&(b.current=!0,o(A),y.current?.blur())},children:[(0,U.jsx)(aa,{className:`w-4 h-4 mr-2`}),` `,(0,U.jsxs)(`span`,{className:`text-sm`,children:[l?`Rename to: `:`Save as: `,(0,U.jsx)(`span`,{className:`font-medium text-sm`,children:fn.basename(A)})]})]},`_rename_`),k.map(e=>{let t=e.isDirectory?`directory`:Wn(e.path),n=Gn[t];return(0,U.jsxs)(ue,{variant:e.isDirectory?`default`:`muted`,className:`py-2 px-3`,onSelect:()=>{e.isDirectory?p(`${e.path}/`):p(e.path)},children:[(0,U.jsx)(n,{className:`w-4 h-4 mr-2`}),` `,fn.basename(e.path)]},e.path)})]}),ie=Math.max(20,f?.length||r?.length||0)*10,M=_?f||``:l||``,N;t[17]!==u||t[18]!==ie?(N=u?{maxWidth:ie}:void 0,t[17]=u,t[18]=ie,t[19]=N):N=t[19];let P;t[20]===s?P=t[21]:(P=$t(s,`w-full px-4 py-1 my-1 h-9 font-mono text-foreground/60`),t[20]=s,t[21]=P);let ae;t[22]!==r||t[23]!==M||t[24]!==N||t[25]!==P?(ae=(0,U.jsx)(Of,{children:(0,U.jsx)(Ae,{"data-testid":`dir-completion-input`,tabIndex:-1,rootClassName:`border-none justify-center px-1`,spellCheck:`false`,value:M,onKeyDown:jf,icon:null,ref:y,onValueChange:p,placeholder:r,autoComplete:`off`,style:N,className:P})}),t[22]=r,t[23]=M,t[24]=N,t[25]=P,t[26]=ae):ae=t[26];let oe=j&&`group-focus-within:block`,se;t[27]===oe?se=t[28]:(se=$t(`p-0 w-full min-w-80 max-w-80vw hidden`,oe),t[27]=oe,t[28]=se);let ce;t[29]!==j||t[30]!==se?(ce=(0,U.jsx)(ot,{side:`bottom`,className:se,portal:!1,children:j}),t[29]=j,t[30]=se,t[31]=ce):ce=t[31];let le;t[32]!==ae||t[33]!==ce?(le=(0,U.jsxs)(st,{children:[ae,ce]}),t[32]=ae,t[33]=ce,t[34]=le):le=t[34];let de;t[35]!==E||t[36]!==le?(de=(0,U.jsx)(Ee,{onFocus:w,onBlur:E,shouldFilter:!1,id:`filename-input`,className:`bg-transparent group filename-input`,children:le}),t[35]=E,t[36]=le,t[37]=de):de=t[37];let fe;return t[38]!==_||t[39]!==de?(fe=(0,U.jsx)(Qt,{children:(0,U.jsx)(xe,{open:_,modal:!1,children:de})}),t[38]=_,t[39]=de,t[40]=fe):fe=t[40],fe};function Af(e,t,n){if(e&&!e.endsWith(`/`)&&((fe(`markdown`)?new Set([`py`,`md`,`markdown`,`qmd`]):new Set([`py`])).has(fn.extension(e))||(e=e.endsWith(`.`)?`${e}py`:e.endsWith(`.p`)?`${e}y`:`${e}.py`),!t.some(t=>t.path===e||fn.basename(t.path)===e)&&!(n&&(n===e||fn.basename(n)===e))))return e}function jf(e){e.key===`Escape`&&e.currentTarget.blur()}var Mf=e=>{let t=(0,H.c)(33),n=()=>{an(new Blob([r()],{type:`text/plain`}),`${e.proposedName}.json`)},r=c(Ff),i;t[0]!==n||t[1]!==e?(i=t=>{t.preventDefault(),n(),e.closeModal()},t[0]=n,t[1]=e,t[2]=i):i=t[2];let a;t[3]===e?a=t[4]:(a=t=>{t.key===`Escape`&&e.closeModal()},t[3]=e,t[4]=a);let o;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,U.jsx)(sr,{className:`text-accent-foreground mb-6`,children:`Download unsaved changes?`}),t[5]=o):o=t[5];let s;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(s={wordBreak:`break-word`},t[6]=s):s=t[6];let l,u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,U.jsx)(`p`,{children:`This app has unsaved changes. To recover:`}),u={paddingBottom:`10px`},t[7]=l,t[8]=u):(l=t[7],u=t[8]);let d;t[9]===e.proposedName?d=t[10]:(d=(0,U.jsxs)(`li`,{style:u,children:[`Click the "Download" button. This will download a file called\xA0`,(0,U.jsxs)(`code`,{children:[e.proposedName,`.json`]}),`. This file contains your code.`]}),t[9]=e.proposedName,t[10]=d);let f;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(f={paddingBottom:`10px`},t[11]=f):f=t[11];let p;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(p={display:`block`,padding:`10px`},t[12]=p):p=t[12];let m;t[13]===e.proposedName?m=t[14]:(m=(0,U.jsxs)(`code`,{style:p,children:[`marimo recover `,e.proposedName,`.json `,`>`,` `,e.proposedName,`.py`]}),t[13]=e.proposedName,t[14]=m);let h;t[15]===e.proposedName?h=t[16]:(h=(0,U.jsxs)(`code`,{children:[e.proposedName,`.py`]}),t[15]=e.proposedName,t[16]=h);let g;t[17]!==h||t[18]!==m?(g=(0,U.jsxs)(`li`,{style:f,children:[`In your terminal, type`,m,`to overwrite `,h,` with the recovered changes.`]}),t[17]=h,t[18]=m,t[19]=g):g=t[19];let _;t[20]!==g||t[21]!==d?(_=(0,U.jsx)(ir,{className:`markdown wrap-break-word`,style:s,children:(0,U.jsxs)(`div`,{className:`prose dark:prose-invert`,children:[l,(0,U.jsxs)(`ol`,{children:[d,g]})]})}),t[20]=g,t[21]=d,t[22]=_):_=t[22];let v;t[23]===e.closeModal?v=t[24]:(v=(0,U.jsx)(ln,{"aria-label":`Cancel`,variant:`secondary`,"data-testid":`cancel-recovery-button`,onClick:e.closeModal,children:`Cancel`}),t[23]=e.closeModal,t[24]=v);let y;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,U.jsx)(ln,{"data-testid":`download-recovery-button`,"aria-label":`Download`,variant:`default`,type:`submit`,children:`Download`}),t[25]=y):y=t[25];let b;t[26]===v?b=t[27]:(b=(0,U.jsxs)(or,{children:[v,y]}),t[26]=v,t[27]=b);let x;return t[28]!==i||t[29]!==a||t[30]!==_||t[31]!==b?(x=(0,U.jsx)(ar,{className:`w-fit`,children:(0,U.jsxs)(`form`,{onSubmit:i,onKeyDown:a,children:[o,_,b]})}),t[28]=i,t[29]=a,t[30]=_,t[31]=b,t[32]=x):x=t[32],x},Nf=e=>{let t=(0,H.c)(12),{filename:n,needsSave:r}=e,{openModal:i,closeModal:a}=qn(),o;t[0]===n?o=t[1]:(o=n===null?`app`:fn.basename(n).split(`.`)[0],t[0]=n,t[1]=o);let s=o,c;t[2]!==a||t[3]!==r||t[4]!==i||t[5]!==s?(c=()=>{r&&i((0,U.jsx)(Mf,{proposedName:s,closeModal:a}))},t[2]=a,t[3]=r,t[4]=i,t[5]=s,t[6]=c):c=t[6];let l=c;gn(`global.save`,l);let u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=Mi(`global.save`),t[7]=u):u=t[7];let d=r?`yellow`:`gray`,f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,U.jsx)(er,{strokeWidth:1.5,size:18}),t[8]=f):f=t[8];let p;return t[9]!==l||t[10]!==d?(p=(0,U.jsx)(sn,{content:u,children:(0,U.jsx)(ra,{onClick:l,id:`save-button`,"aria-label":`Save`,className:`rectangle`,color:d,children:f})}),t[9]=l,t[10]=d,t[11]=p):p=t[11],p};function Pf(e){return{id:e.id,name:e.name,code:e.code,code_hash:null,config:{column:0,...e.config}}}function Ff(){let e=Me(),t=ye(e),n={version:`1`,metadata:{marimo_version:Zt()},cells:t.map(Pf)};return JSON.stringify(n,null,2)}var If=r(void 0),Lf=r(e=>{let t=e(If);return Rf({state:e(he),layout:e(Xn),lastSavedNotebook:t})});function Rf({state:e,layout:t,lastSavedNotebook:n}){if(!n)return!1;let{cellIds:r,cellData:i}=e,o=r.inOrderIds.map(e=>i[e]),s=o.map(e=>e.code),c=o.map(e=>e.config),l=o.map(e=>e.name);return!ti(s,n.codes)||!ti(l,n.names)||!a(c,n.configs)||!a(t.selectedLayout,n.layout.selectedLayout)||!a(t.layoutData,n.layout.layoutData)}function zf(e){let t=(0,H.c)(21),{codes:n,cellConfigs:r,config:i,connStatus:a,cellNames:o,needsSave:s,kioskMode:c,onSave:l}=e,u=(0,V.useRef)(null),d;t[0]===n?d=t[1]:(d=n.join(`:`),t[0]=n,t[1]=d);let f=d,p;t[2]===r?p=t[3]:(p=r.map(Bf).join(`:`),t[2]=r,t[3]=p);let m=p,h;t[4]===o?h=t[5]:(h=o.join(`:`),t[4]=o,t[5]=h);let g=h,_;t[6]!==i||t[7]!==a.state||t[8]!==c||t[9]!==s||t[10]!==l?(_=()=>{if(!c)return i.autosave===`after_delay`&&(u.current!==null&&clearTimeout(u.current),s&&a.state===Xt.OPEN&&(u.current=setTimeout(l,i.autosave_delay))),()=>{u.current!==null&&clearTimeout(u.current)}},t[6]=i,t[7]=a.state,t[8]=c,t[9]=s,t[10]=l,t[11]=_):_=t[11];let v;t[12]!==m||t[13]!==g||t[14]!==f||t[15]!==i||t[16]!==a.state||t[17]!==c||t[18]!==s||t[19]!==l?(v=[f,m,g,i,a.state,l,c,s],t[12]=m,t[13]=g,t[14]=f,t[15]=i,t[16]=a.state,t[17]=c,t[18]=s,t[19]=l,t[20]=v):v=t[20],(0,V.useEffect)(_,v)}function Bf(e){return JSON.stringify(e)}var Vf=Promise.resolve();function Hf(e){let t=Vf.then(e);return Vf=t.then(()=>void 0,()=>void 0),t}var Uf=e=>{let t=(0,H.c)(15),{kioskMode:n}=e,r=Ai(),a=i(Lf),o=i(Kt).state===Xt.CLOSED,{saveOrNameNotebook:s,saveIfNotebookIsPersistent:c}=Wf(),l;t[0]!==n||t[1]!==c?(l={onSave:c,kioskMode:n},t[0]=n,t[1]=c,t[2]=l):l=t[2],Yf(l),ia();let u;t[3]===a?u=t[4]:(u=e=>{if(a)return e.preventDefault(),e.returnValue=`You have unsaved changes. Are you sure you want to leave?`,e.returnValue},t[3]=a,t[4]=u),Rt(window,`beforeunload`,u);let d;t[5]===s?d=t[6]:(d=e=>{e.preventDefault(),e.stopPropagation(),s()},t[5]=s,t[6]=d);let f=d;if(gn(`global.save`,s),o){let e;return t[7]!==r||t[8]!==a?(e=(0,U.jsx)(Nf,{filename:r,needsSave:a}),t[7]=r,t[8]=a,t[9]=e):e=t[9],e}let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=Mi(`global.save`),t[10]=p):p=t[10];let m=a?`yellow`:`hint-green`,h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(er,{strokeWidth:1.5,size:18}),t[11]=h):h=t[11];let g;return t[12]!==f||t[13]!==m?(g=(0,U.jsx)(sn,{content:p,children:(0,U.jsx)(ra,{"data-testid":`save-button`,id:`save-button`,shape:`rectangle`,color:m,onClick:f,children:h})}),t[12]=f,t[13]=m,t[14]=g):g=t[14],g};function Wf(){let e=(0,H.c)(21),{sendSave:t}=mi(),{openModal:r,closeModal:i,openAlert:a}=qn(),o=l(If),s=ji(),u=n(),d;e[0]!==a||e[1]!==t||e[2]!==o||e[3]!==u?(d=(e,n)=>Hf(async()=>{let r=u.get(Kt),i=u.get(At);if(u.get(Vt))return;if(r.state!==Xt.OPEN){a(`Failed to save notebook: not connected to a kernel.`);return}if(It.log(`saving to `,e),n&&i.format_on_save&&(It.log(`formatting notebook (onSave)`),await le()),ye(Me()).length===0)return;let s=await rt(async()=>{let n=Me(),r=ye(n),i=r.map(qf),a=r.map(Kf),o=r.map(Gf),s=Ce(n),c=u.get(Xn);return await t({cellIds:i,codes:a,names:o,filename:e,configs:s,layout:pn(),persist:!0}),{names:o,codes:a,configs:s,layout:c}});o(s)}),e[0]=a,e[1]=t,e[2]=o,e[3]=u,e[4]=d):d=e[4];let f=c(d),p;e[5]!==f||e[6]!==u?(p=e=>{let t=e!==void 0&&e,n=u.get(gt),r=u.get(Kt);Jf(n)&&r.state===Xt.OPEN&&f(n,t)},e[5]=f,e[6]=u,e[7]=p):p=e[7];let m=c(p),h;e[8]!==f||e[9]!==s?(h=e=>{s(e).then(e=>{e!==null&&f(e,!0)})},e[8]=f,e[9]=s,e[10]=h):h=e[10];let g=h,_;e[11]!==i||e[12]!==g||e[13]!==r||e[14]!==m||e[15]!==u?(_=()=>{let e=u.get(gt),t=u.get(Kt);m(!0),!Jf(e)&&t.state!==Xt.CLOSED&&r((0,U.jsx)(Qf,{onClose:i,onSave:g}))},e[11]=i,e[12]=g,e[13]=r,e[14]=m,e[15]=u,e[16]=_):_=e[16];let v=c(_),y;return e[17]!==m||e[18]!==f||e[19]!==v?(y={saveOrNameNotebook:v,saveIfNotebookIsPersistent:m,saveNotebook:f},e[17]=m,e[18]=f,e[19]=v,e[20]=y):y=e[20],y}function Gf(e){return e.name}function Kf(e){return e.code}function qf(e){return e.id}function Jf(e){return e!==null&&!e.startsWith(`/tmp/`)&&!e.startsWith(`/var/folders`)&&!e.includes(`AppData\\Local\\Temp`)}function Yf(e){let n=(0,H.c)(14),r=i(At),a=C(),[o]=t(Kt),s=i(Lf),c,l;if(n[0]!==a){let e=ye(a);c=e.map(Zf),l=e.map(Xf),n[0]=a,n[1]=c,n[2]=l}else c=n[1],l=n[2];let u=l,d;n[3]===a?d=n[4]:(d=Ce(a),n[3]=a,n[4]=d);let f=d,p;n[5]!==r||n[6]!==u||n[7]!==c||n[8]!==f||n[9]!==o||n[10]!==s||n[11]!==e.kioskMode||n[12]!==e.onSave?(p={onSave:e.onSave,needsSave:s,codes:c,cellConfigs:f,cellNames:u,connStatus:o,config:r,kioskMode:e.kioskMode},n[5]=r,n[6]=u,n[7]=c,n[8]=f,n[9]=o,n[10]=s,n[11]=e.kioskMode,n[12]=e.onSave,n[13]=p):p=n[13],zf(p)}function Xf(e){return e.name}function Zf(e){return e.code}var Qf=e=>{let t=(0,H.c)(17),{onClose:n,onSave:r}=e,[i,a]=(0,V.useState)(),o;t[0]!==n||t[1]!==r?(o=e=>{a(e),e.trim()&&(r(e),n())},t[0]=n,t[1]=r,t[2]=o):o=t[2];let s=o,c;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,U.jsx)(sr,{children:`Save notebook`}),t[3]=c):c=t[3];let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,U.jsx)(rn,{className:`text-md pt-6 px-1`,children:`Save as`}),t[4]=l):l=t[4];let u;t[5]===s?u=t[6]:(u=(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[l,(0,U.jsx)(kf,{onNameChange:s,placeholderText:`filename`,className:`missing-filename`})]}),t[5]=s,t[6]=u);let d;t[7]===n?d=t[8]:(d=(0,U.jsx)(ln,{"data-testid":`cancel-save-dialog-button`,"aria-label":`Cancel`,variant:`secondary`,onClick:n,children:`Cancel`}),t[7]=n,t[8]=d);let f=!i,p;t[9]===f?p=t[10]:(p=(0,U.jsx)(ln,{"data-testid":`submit-save-dialog-button`,"aria-label":`Save`,variant:`default`,disabled:f,type:`submit`,children:`Save`}),t[9]=f,t[10]=p);let m;t[11]!==d||t[12]!==p?(m=(0,U.jsxs)(or,{children:[d,p]}),t[11]=d,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==u||t[15]!==m?(h=(0,U.jsxs)(ar,{children:[c,u,m]}),t[14]=u,t[15]=m,t[16]=h):h=t[16],h};function $f(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var ep={modified:{doc:``},original:{doc:``}},tp=(0,V.createContext)(ep);function np(e,t){return z({},e,t,{modified:z({},e.modified,t.modified),original:z({},e.original,t.original)})}var rp=()=>(0,V.useContext)(tp),ip=e=>{var t=e.children,n=e.theme,r=(0,V.useReducer)(np,z({},ep,{theme:n})),i=r[0],a=r[1];return(0,V.useEffect)(()=>a({theme:n}),[n]),(0,U.jsx)(tp.Provider,{value:z({},i,{dispatch:a}),children:t})},ap=[`extensions`,`value`,`selection`,`onChange`],op=e=>{var t=e.extensions,n=t===void 0?[]:t,r=e.value,i=e.selection,a=e.onChange,o=Ei(e,ap),s=rp(),c=s.theme,l=s.dispatch,u=Fi(z({},o,{theme:c}));return(0,V.useEffect)(()=>l({original:{doc:r,selection:i,extensions:[...u,...n]},originalExtension:{onChange:a,option:o,extension:[n]}}),[e]),null};op.displayName=`CodeMirrorMerge.Original`;var sp=[`extensions`,`value`,`selection`,`onChange`],cp=e=>{var t=e.extensions,n=t===void 0?[]:t,r=e.value,i=e.selection,a=e.onChange,o=Ei(e,sp),s=rp(),c=s.theme,l=s.dispatch,u=Fi(z({},o,{theme:c}));return(0,V.useEffect)(()=>{l({modified:{doc:r,selection:i,extensions:[...u,...n]},modifiedExtension:{onChange:a,option:o,extension:[n]}})},[e]),null};cp.displayName=`CodeMirrorMerge.Modified`;var lp=[`className`,`children`,`orientation`,`revertControls`,`highlightChanges`,`gutter`,`collapseUnchanged`,`destroyRerender`,`renderRevertControl`,`diffConfig`,`root`],up=[`modified`,`modifiedExtension`,`original`,`originalExtension`,`theme`,`dispatch`],dp=V.forwardRef((e,t)=>{var n=e.className,r=e.children,i=e.orientation,a=e.revertControls,o=e.highlightChanges,s=e.gutter,c=e.collapseUnchanged,l=e.destroyRerender,u=l===void 0||l,d=e.renderRevertControl,f=e.diffConfig,p=e.root,m=Ei(e,lp),h=rp(),g=h.modified,_=h.modifiedExtension,v=h.original,y=h.originalExtension,b=h.theme,x=h.dispatch,S=Ei(h,up),C=(0,V.useRef)(null),w=(0,V.useRef)(),T={orientation:i,revertControls:a,highlightChanges:o,gutter:s,collapseUnchanged:c,renderRevertControl:d,diffConfig:f,root:p};(0,V.useImperativeHandle)(t,()=>({container:C.current,view:w.current,modified:g,original:v,config:z({a:v,b:g,parent:C.current},T)}),[C,w,g,v,T]);var E=R.updateListener.of(e=>{if(e.docChanged&&typeof y?.onChange==`function`){var t=e.state.doc.toString();y?.onChange(t,e)}}),D=R.updateListener.of(e=>{if(e.docChanged&&typeof _?.onChange==`function`){var t=e.state.doc.toString();_?.onChange(t,e)}});return(0,V.useEffect)(()=>{!w.current&&C.current&&y&&_&&(w.current=new Ii(z({a:z({},v,{extensions:[...y?.extension||[],...Fi(z({},y?.option,{theme:b})),E]}),b:z({},g,{extensions:[..._?.extension||[],...Fi(z({},_?.option,{theme:b})),D]}),parent:C.current},T)),x({view:w.current}))},[w,C,y,_]),(0,V.useEffect)(()=>{if(v&&v.doc&&w.current){var e=w.current?.a.state.doc.toString();if(e!==v.doc){var t;(t=w.current)==null||t.a.dispatch({changes:{from:0,to:e.length,insert:v.doc||``}})}}if(g&&g.doc&&w.current){var n=w.current?.b.state.doc.toString();if(n!==g.doc){var r;(r=w.current)==null||r.b.dispatch({changes:{from:0,to:n.length,insert:g.doc||``}})}}if(u&&w.current){var i=w.current.a.state.selection.ranges[0].from,a=w.current.b.state.selection.ranges[0].from;w.current.destroy(),w.current=new Ii(z({a:z({},v,{extensions:[...y?.extension||[],...Fi(z({},y?.option,{theme:b}))]}),b:z({},g,{extensions:[..._?.extension||[],...Fi(z({},_?.option,{theme:b}))]}),parent:C.current},T)),i&&(w.current.a.focus(),w.current.a.dispatch({selection:{anchor:i,head:i}})),a&&(w.current.b.focus(),w.current.b.dispatch({selection:{anchor:a,head:a}}))}},[w,b,C.current,v,g,y,_,u]),(0,V.useEffect)(()=>()=>w.current&&w.current.destroy(),[]),(0,V.useEffect)(()=>{if(w.current){var e={};S.orientation!==i&&(e.orientation=i),S.revertControls!==a&&(e.revertControls=a),S.highlightChanges!==o&&(e.highlightChanges=o),S.gutter!==s&&(e.gutter=s),S.collapseUnchanged!==c&&(e.collapseUnchanged=c),S.renderRevertControl!==d&&(e.collapseUnchanged=c),Object.keys(e).length&&x&&w.current&&(w.current.reconfigure(z({},e)),x(z({},e)))}},[x,w,i,a,o,s,c,d]),(0,U.jsx)(`div`,z({ref:C,className:`cm-merge-theme`+(n?` `+n:``)},m,{children:r}))});dp.displayName=`CodeMirrorMerge.Internal`;var fp=[`theme`],pp=V.forwardRef((e,t)=>{var n=e.theme,r=Ei(e,fp);return(0,U.jsx)(ip,{theme:n,children:(0,U.jsx)(dp,z({},r,{ref:t}))})});pp.Original=op,pp.Modified=cp,pp.displayName=`CodeMirrorMerge`;var mp=pp.Original,hp=pp.Modified,gp=[se(),R.lineWrapping],_p=({cellId:e,aiCompletionCell:n,className:r,onChange:i,currentLanguageAdapter:a,currentCode:o,declineChange:s,acceptChange:c,runCell:l,outputArea:u,children:d})=>{let[p,m]=(0,V.useState)(!1),[h,g]=t(Oi),_=(0,V.useId)(),v=qt(),{initialPrompt:y,triggerImmediately:x,cellId:C}=n??{},w=C===e,T=kn(e),E;T?.type===`update_cell`&&(E=T.previousCode);let[D,O]=(0,V.useState)(``),[ee,k]=(0,V.useState)(y??``),te=V.useMemo(()=>new wn({api:v.getAiURL(`completion`).toString(),headers:()=>v.headers(),prepareSendMessagesRequest:({body:e,id:t})=>({body:{...e,id:t}})}),[v]),{sendMessage:ne,stop:re,status:A}=Hn({throttle:100,transport:te,onData:e=>{if(e.type===Tn){let t=Dn.parse(e.data);O(t.code.trimEnd())}},onError:e=>{O(``),lr({title:`Completion failed`,description:Ti(e)})},onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{(e||t||n||r!==`stop`)&&O(``)}}),j=A===`submitted`||A===`streaming`,ie=(0,V.useCallback)(()=>{O(``),re()},[re]),M=(0,V.useCallback)(async e=>{await re(),O(``);let t={...jn({input:e}),prompt:e,includeOtherCode:h?ce(o):``,code:o,language:a??`python`};await ne({text:e},{body:t})},[o,a,h,ne,re]),N=(0,V.useCallback)(()=>{M(ee)},[M,ee]),P=V.useRef(null),ae=(0,V.useCallback)(()=>{x&&!j&&y&&M(y)},[x]);(0,V.useEffect)(()=>{w&&(S(()=>{let e=P.current;return e?.view?(e.view.focus(),ae(),!0):!1},{retries:3,delay:100,initialDelay:100}),b(P.current?.view))},[w,ae]),(0,V.useEffect)(()=>{w&&k(y||``)},[w,y,k]);let{theme:oe}=vi(),se=()=>{c(D),O(``)},le=()=>{ie(),m(!0),P.current?.view?.focus()},ue=w&&x&&(D||j);u??=`below`;let de=w&&(!x||p),fe=(0,U.jsx)(`div`,{className:$t(`w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden`,ue?`max-h-20 opacity-100 translate-y-0`:`max-h-0 opacity-0 -translate-y-2`),children:(0,U.jsx)(vp,{status:j?`loading`:`generated`,onAccept:se,onReject:le,showInputPrompt:p,setShowInputPrompt:m,runCell:l,className:`mt-4 mb-3 w-lg`})}),pe=(e,t)=>(0,U.jsxs)(pp,{className:`cm`,theme:oe,children:[(0,U.jsx)(mp,{onChange:i,value:e,extensions:gp}),(0,U.jsx)(hp,{value:t,editable:!1,readOnly:!0,extensions:gp})]}),me=()=>{if(D&&w)return pe(o,D);if(!D&&E)return pe(E,o)},he=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(In,{isLoading:j,onAccept:se,size:`xs`,multipleCompletions:!1,label:zn.accept,acceptShortcut:`Mod-↵`,runCell:l}),(0,U.jsx)(Rn,{onDecline:le,size:`xs`,multipleCompletions:!1,label:zn.decline,declineShortcut:`Shift-Mod-Delete`})]});return(0,U.jsxs)(`div`,{"data-ai-input-open":de,className:$t(`flex flex-col w-full rounded-[inherit]`,r),children:[(0,U.jsx)(`div`,{className:$t(`flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300`,de&&`max-h-[400px] border-b min-h-11 visible`,!de&&`max-h-0 min-h-0 invisible`),children:w&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Ye,{className:`text-(--blue-10) shrink-0`,size:16}),(0,U.jsx)(Ln,{inputRef:P,className:`h-full my-0 py-2 flex items-center`,onClose:()=>{ie(),s()},value:ee,onChange:k,onSubmit:()=>{j||(P.current?.view&&An(P.current.view),N())},onKeyDown:Bn({handleAcceptCompletion:se,handleDeclineCompletion:le,isLoading:j,hasCompletion:D.trim().length>0})}),(0,U.jsxs)(`div`,{className:`-mr-1.5 py-1.5`,children:[(0,U.jsxs)(`div`,{className:`flex flex-row items-center justify-end gap-0.5`,children:[(0,U.jsx)(Fn,{isLoading:j,onStop:ie,onSendClick:N,isEmpty:!ee.trim(),showStopLabel:!0}),(0,U.jsx)(Pn,{handleAddContext:()=>Vn(P),isLoading:j}),(0,U.jsx)(yn,{triggerClassName:`h-7 text-xs`,iconSize:`small`,forRole:`edit`,displayIconOnly:!0,placeholder:`Edit model`})]}),D&&(0,U.jsx)(`div`,{className:`mt-1 flex items-center gap-1`,children:he})]}),(0,U.jsx)(`div`,{className:`h-full w-px bg-border mx-2`}),(0,U.jsx)(sn,{content:`Include code from other cells`,children:(0,U.jsxs)(`div`,{className:`flex flex-row items-start gap-1 overflow-hidden`,children:[(0,U.jsx)(f,{"data-testid":`include-other-cells-checkbox`,id:_,checked:h,onCheckedChange:e=>g(!!e)}),(0,U.jsx)(rn,{htmlFor:_,className:`text-muted-foreground text-xs whitespace-nowrap ellipsis`,children:`All code`})]})}),(0,U.jsx)(ln,{"data-testid":`decline-completion-button`,variant:`text`,size:`icon`,disabled:j,onClick:()=>{ie(),s()},children:(0,U.jsx)(Sn,{className:`text-(--red-10)`,size:16})})]})}),u===`above`&&fe,me(),(!D||!w)&&!E&&d,u===`below`&&fe]})},vp=e=>{let t=(0,H.c)(27),{status:n,onAccept:r,onReject:i,className:a,showInputPrompt:o,setShowInputPrompt:s,runCell:c}=e,l=n===`loading`,u;t[0]===a?u=t[1]:(u=$t(`flex flex-row items-center gap-6 rounded-md py-2 px-2.5 text-sm border border-border bg-(--gray-2) dark:bg-(--gray-3)`,a),t[0]=a,t[1]=u);let d;t[2]===l?d=t[3]:(d=l?(0,U.jsx)(Jn,{className:`animate-spin text-blue-600 mb-px`,size:15,strokeWidth:2,"aria-label":`Generating fix`}):(0,U.jsx)(Cn,{className:`text-green-600 mb-px`,size:15,strokeWidth:2,"aria-label":`Fix generated`}),t[2]=l,t[3]=d);let f=l?`Generating fix...`:`Showing fix`,p;t[4]===f?p=t[5]:(p=(0,U.jsx)(`p`,{className:`transition-opacity duration-200 text-muted-foreground`,children:f}),t[4]=f,t[5]=p);let m;t[6]!==d||t[7]!==p?(m=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-2`,children:[d,p]}),t[6]=d,t[7]=p,t[8]=m):m=t[8];let h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(rn,{htmlFor:`show-input-prompt`,className:`text-muted-foreground text-xs whitespace-nowrap ellipsis`,children:`Show prompt`}),t[9]=h):h=t[9];let g;t[10]!==s||t[11]!==o?(g=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-1`,children:[h,(0,U.jsx)(on,{checked:o,onCheckedChange:s,size:`xs`})]}),t[10]=s,t[11]=o,t[12]=g):g=t[12];let _;t[13]!==l||t[14]!==r||t[15]!==c?(_=(0,U.jsx)(In,{isLoading:l,onAccept:r,size:`xs`,label:zn.accept,runCell:c}),t[13]=l,t[14]=r,t[15]=c,t[16]=_):_=t[16];let v;t[17]===i?v=t[18]:(v=(0,U.jsx)(Rn,{onDecline:i,size:`xs`,label:zn.decline}),t[17]=i,t[18]=v);let y;t[19]!==_||t[20]!==v?(y=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-2 ml-auto`,children:[_,v]}),t[19]=_,t[20]=v,t[21]=y):y=t[21];let b;return t[22]!==u||t[23]!==y||t[24]!==m||t[25]!==g?(b=(0,U.jsxs)(`div`,{className:u,children:[m,g,y]}),t[22]=u,t[23]=y,t[24]=m,t[25]=g,t[26]=b):b=t[26],b},yp=`web application/x-marimo-cell`,bp=Ct({cells:wt(Ct({code:xt(),name:xt().optional(),config:Ct({column:bt([vt(),Tt()]).optional(),disabled:St().optional(),hide_code:St().optional(),expand_output:St().optional()}).optional()})),version:yt(`1.0`)});function xp(e){return e.map(e=>e.code).join(`
|
|
18
|
+
`).trim()}function Ld(e,t,n,r){return r!==`{`||t!==n||!yr(e.state).resolveInner(t,-1)?.type.name.includes(`String`)?!1:(e.dispatch({changes:{from:t,to:n,insert:`{}`},selection:{anchor:t+1},userEvent:`input.type`}),!0)}function Rd(){return R.inputHandler.of(Ld)}function zd(e){let{showPlaceholder:t,enableAI:n}=e;return t?`marimo-import`:n?`ai`:`none`}var Bd=`cm-tooltip-portal`;function Vd(e){if(e==null)return document.querySelector(`#App`)??void 0;let t=document.querySelector(e);if(t==null)return;let n=t.querySelector(`:scope > .${Bd}`);if(n!=null)return n;let r=document.createElement(`div`);return r.className=`${Bd} not-prose contents`,t.append(r),r}var Hd=e=>{let{cellId:t,keymapConfig:n,hotkeys:r,enableAI:i,cellActions:a,completionConfig:o,lspConfig:s,diagnosticsConfig:c,displayConfig:l,inlineAiTooltip:u}=e,d=zd(e);return[hn(n,r),Md(),Nd(),Yo(),ke({cellId:t,completionConfig:o,hotkeys:r,placeholderType:d,lspConfig:s,diagnosticsConfig:c}),Be({cellId:t,hotkeys:r,cellActions:a,keymapConfig:n}),Wd(e),jd(),c?.enabled?Qr():[],i&&u?[Ka({prompt:e=>io({prompt:e.prompt,selection:e.selection,codeBefore:e.codeBefore,codeAfter:e.codeAfter,language:Xe(e.editorView)})}),Ba.of({hideOnBlur:!0})]:[],te(t,l.reference_highlighting??!0),Ko(t,l.code_lens??!0)]},Ud=e=>{let{from:t,to:n}=e.state.selection.main;if(t!==n)return!1;let r=e.state.doc.lineAt(n);return r.text.slice(0,n-r.from).trim()!==``&&ci(e)},Wd=e=>{let{theme:t,hotkeys:n,completionConfig:r,acceptCompletionOnEnter:i,cellId:a,lspConfig:o,diagnosticsConfig:s,tooltipParentSelector:c}=e,l=zd(e),u=r.auto_close_pairs!==!1;return[R.lineWrapping,Fr(),Pr(),Er(),pr(),Wr(),wr(),Lr(),xr({position:`fixed`,parent:Vd(c)}),Ue(),t===`dark`?Qn:Xn,Re(o),sd(r),Ur(),Rd(),u?li():[],Qo(i),u?Sr.high(gr.of(ai)):[],zr(),Tr(),br.of(` `),Or(Mr,{fallback:!0}),gr.of(hr),Je({placeholderType:l,completionConfig:r,hotkeys:n,cellId:a,lspConfig:{...o,diagnostics:s}}),Ne.of(Xr()),vr.allowMultipleSelections.of(!0),Cd(n),gr.of([{key:`Tab`,run:e=>di(e)||Ud(e)||qr(e),preventDefault:!0},{key:n.getHotkey(`completion.moveDown`).key,run:e=>ui(e.state)!==null&&(si(!0)(e),!0),preventDefault:!0},{key:n.getHotkey(`completion.moveUp`).key,run:e=>ui(e.state)!==null&&(si(!1)(e),!0),preventDefault:!0}]),gr.of([...ti,Yr])]},Gd=(e=>!e||e instanceof WebAssembly.Module?e:typeof e==`object`&&`default`in e?e.default??e:e)(ea),Kd=e=>{Wi(e),qd(e)};function qd(e){typeof e.__wbindgen_start==`function`&&e.__wbindgen_start()}if(Gd&&Gd.__wbindgen_start)Kd(Gd);else if(`Bun`in globalThis){let e;if(Gd instanceof WebAssembly.Module)({instance:e}=await WebAssembly.instantiate(Gd,{"./loro_wasm_bg.js":Qi}));else{let t=Bun.pathToFileURL(Gd);({instance:e}=await WebAssembly.instantiateStreaming(fetch(t),{"./loro_wasm_bg.js":Qi}))}Kd(e.exports)}else{let e=Gd instanceof WebAssembly.Module?Gd:await dr(()=>import(`./loro_wasm_bg-C2Fqi8D-.js`),__vite__mapDeps([0,1,2]),import.meta.url),t=e instanceof WebAssembly.Module?e:e&&e.default||e,n;if(t instanceof WebAssembly.Instance)n=t;else if(t instanceof WebAssembly.Module)n=await WebAssembly.instantiate(t,{"./loro_wasm_bg.js":Qi});else if(t instanceof ArrayBuffer||ArrayBuffer.isView(t)){let{instance:e}=await WebAssembly.instantiate(t,{"./loro_wasm_bg.js":Qi});n=e}else if(typeof t==`string`||t instanceof URL){let e=await fetch(t),{instance:r}=await WebAssembly.instantiateStreaming(e,{"./loro_wasm_bg.js":Qi});n=r}else throw console.error(`Unsupported wasm import type:`,t),Error(`Unsupported wasm import type: `+typeof t);Kd(n.exports??n)}var Jd=[`Map`,`Text`,`List`,`Tree`,`MovableList`,`Counter`];function Yd(e){return Ki(e)}function Xd(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return typeof t!=`object`||!t||typeof t.kind!=`function`?!1:Jd.includes(e.kind())}var Zd=class{constructor(e,t=3e4){this.listeners=new Set,this.inner=new Yi(e,t),this.peer=e,this.timeout=t}apply(e,t=`remote`){let{updated:n,added:r}=this.inner.apply(e);this.listeners.forEach(e=>{e({updated:n,added:r,removed:[]},t)}),this.startTimerIfNotEmpty()}setLocalState(e){let t=this.inner.getState(this.peer)==null;this.inner.setLocalState(e),t?this.listeners.forEach(e=>{e({updated:[],added:[this.inner.peer()],removed:[]},`local`)}):this.listeners.forEach(e=>{e({updated:[this.inner.peer()],added:[],removed:[]},`local`)}),this.startTimerIfNotEmpty()}getLocalState(){return this.inner.getState(this.peer)}getAllStates(){return this.inner.getAllStates()}encode(e){return this.inner.encode(e)}encodeAll(){return this.inner.encodeAll()}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}peers(){return this.inner.peers()}destroy(){clearInterval(this.timer),this.listeners.clear()}startTimerIfNotEmpty(){this.inner.isEmpty()||this.timer!=null||(this.timer=setInterval(()=>{let e=this.inner.removeOutdated();e.length>0&&this.listeners.forEach(t=>{t({updated:[],added:[],removed:e},`timeout`)}),this.inner.isEmpty()&&(clearInterval(this.timer),this.timer=void 0)},this.timeout/2))}};qi.prototype.toJsonWithReplacer=function(e){let t=new Set,n=this,r=(r,a)=>{if(typeof a==`string`&&Yd(a)&&!t.has(a)){t.add(a);let o=n.getContainerById(a);if(o==null)throw Error(`ContainerID not found: ${a}`);let s=e(r,o);if(s===o){let e=o.getShallowValue();return typeof e==`object`?i(e):e}if(Xd(s))throw Error(`Using new container is not allowed in toJsonWithReplacer`);return typeof s==`object`&&s?i(s):s}if(typeof a==`object`&&a)return i(a);let o=e(r,a);if(Xd(o))throw Error(`Using new container is not allowed in toJsonWithReplacer`);return o},i=e=>{if(Array.isArray(e))return e.map((e,t)=>r(t,e)).filter(e=>e!==void 0);let t={};for(let[n,i]of Object.entries(e)){let e=r(n,i);e!==void 0&&(t[n]=e)}return t};return i(n.getShallowValue())};var Qd=Symbol(`loro.callPendingEventsWrapped`);function $d(e,t){let n=Object.getOwnPropertyDescriptor(e,t);if(!n||typeof n.value!=`function`)return;let r=n.value;if(r[Qd])return;let i=function(...e){let t;try{return t=r.apply(this,e),t}finally{t&&typeof t.then==`function`?t.finally(()=>{$i()}):$i()}};i[Qd]=!0,Object.defineProperty(e,t,{...n,value:i})}function ef(e,t){for(let n of t)$d(e,n)}ef(qi.prototype,[`setDetachedEditing`,`attach`,`detach`,`fork`,`forkAt`,`checkoutToLatest`,`checkout`,`commit`,`getCursorPos`,`revertTo`,`export`,`exportJsonUpdates`,`exportJsonInIdSpan`,`importJsonUpdates`,`import`,`importUpdateBatch`,`importBatch`,`travelChangeAncestors`,`getChangedContainersIn`,`diff`,`applyDiff`,`setPeerId`]),ef(Gi.prototype,[`set`,`delete`,`apply`,`removeOutdated`]),ef(ta.prototype,[`undo`,`redo`]);var tf=R.baseTheme({".loro-cursor":{position:`absolute`,width:`2px`,display:`inline-block`,height:`1.2em`},".loro-cursor::before":{position:`absolute`,top:`1.3em`,left:`0`,content:`var(--rtc-name)`,padding:`2px 6px`,fontSize:`12px`,borderRadius:`3px`,whiteSpace:`nowrap`,userSelect:`none`,backgroundColor:`inherit`,opacity:`0.7`},".loro-selection":{opacity:`0.5`}});Gr.define();var nf=I.define(),rf=fr.define({create(){return{remoteCursors:new Map,isCheckout:!1}},update(e,t){for(let n of t.effects)if(n.is(nf))switch(n.value.type){case`update`:{let{peer:t,user:r,cursor:i}=n.value;e.remoteCursors.set(t,{uid:t,cursor:i,user:r});break}case`delete`:e.remoteCursors.delete(n.value.peer);break;case`checkout`:e.isCheckout=n.value.checkout}return e}}),af=e=>{let t=e.transactions.flatMap(e=>e.effects).filter(e=>e.is(nf));return e.docChanged||e.viewportChanged||t.length>0},of=()=>mr({above:!0,class:`loro-cursor-layer`,update:af,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(rf);return n?[]:[...t.values()].flatMap(t=>{let n=Ar.cursor(t.cursor.anchor);return cf.createCursor(e,n,t.user?.name||`unknown`,t.user?.colorClassName||``)})}}),sf=()=>mr({above:!1,class:`loro-selection-layer`,update:af,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(rf);return n?[]:[...t.entries()].filter(([,e])=>e.cursor.head!==void 0&&e.cursor.anchor!==e.cursor.head).flatMap(([,t])=>{let n=Ar.range(t.cursor.anchor,t.cursor.head);return Rr.forRange(e,`loro-selection ${t.user?.colorClassName||``}`,n)})}}),cf=class e{left;top;height;name;colorClassName;constructor(e,t,n,r,i){this.left=e,this.top=t,this.height=n,this.name=r,this.colorClassName=i}draw(){let e=document.createElement(`div`);return this.adjust(e),e}update(e){return this.adjust(e),!0}adjust(e){e.style.left=`${this.left}px`,e.style.top=`${this.top}px`,e.style.height=`${this.height}px`,e.className=`loro-cursor ${this.colorClassName}`,e.style.setProperty(`--rtc-name`,`"${this.name}"`)}eq(e){return this.left===e.left&&this.top===e.top&&this.height===e.height&&this.name===e.name}static createCursor(t,n,r,i){let a=e.calculateAbsoluteCursorPosition(n,t);if(!a)return[];let o=t.scrollDOM.getBoundingClientRect(),s=(t.textDirection===Br.LTR?o.left:o.right-t.scrollDOM.clientWidth)-t.scrollDOM.scrollLeft,c=o.top-t.scrollDOM.scrollTop;return[new e(a.left-s,a.top-c,a.bottom-a.top,r,i)]}static calculateAbsoluteCursorPosition(e,t){let n=Math.max(0,Math.min(t.state.doc.length,e.anchor));return t.coordsAtPos(n,e.assoc||1)}},lf=(e,t,n,r)=>{let i=[],{updated:a,added:o}=n;for(let n of[...a,...o]){let a=uf(e,t,n,r);a&&i.push(a)}return i},uf=(e,t,n,r)=>{let i=t.getAllStates()[n];if(!i||n===e.peerIdStr||i.scopeId!==r)return;if(i.type===`delete`)return nf.of({type:`delete`,peer:i.uid,scopeId:i.scopeId});let a=Xi.decode(i.cursor.anchor),o=e.getCursorPos(a)?.offset??0,s=o;if(i.cursor.head){let t=Xi.decode(i.cursor.head);s=e.getCursorPos(t)?.offset??0}return nf.of({type:`update`,peer:i.uid,scopeId:i.scopeId,cursor:{anchor:o,head:s},user:i.user})},df=class{sub;view;doc;user;awareness;getTextFromDoc;scopeId;getUserId;constructor(e,t,n,r,i,a,o){this.view=e,this.doc=t,this.user=n,this.awareness=r,this.getTextFromDoc=i,this.scopeId=a,this.getUserId=o,this.sub=this.doc.subscribe(e=>{if(e.by===`local`){let e=[];for(let t of this.awareness.peers()){let n=uf(this.doc,this.awareness,t,this.scopeId);n&&e.push(n)}this.view.dispatch({effects:e})}else e.by===`checkout`&&this.view.dispatch({effects:[nf.of({type:`checkout`,checkout:this.doc.isDetached()})]})})}update(e){if(!e.selectionSet&&!e.focusChanged&&!e.docChanged)return;let t=e.state.selection.main;if(this.view.hasFocus&&!this.doc.isDetached()){let e=pf({doc:this.doc,getTextFromDoc:this.getTextFromDoc,anchor:t.anchor,head:t.head});this.awareness.setLocalState({type:`update`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId,cursor:e,user:this.user})}else this.awareness.setLocalState({type:`delete`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}destroy(){this.sub?.(),this.awareness.setLocalState({type:`delete`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}},ff=class{_awarenessListener;view;doc;awareness;scopeId;constructor(e,t,n,r){this.view=e,this.doc=t,this.awareness=n,this.scopeId=r;let i=async(e,t)=>{t!==`local`&&this.view.dispatch({effects:lf(this.doc,this.awareness,e,this.scopeId)})};this._awarenessListener=i,this.awareness.addListener(i)}destroy(){this._awarenessListener&&this.awareness.removeListener(this._awarenessListener)}},pf=({doc:e,getTextFromDoc:t,anchor:n,head:r})=>{n===r&&(r=void 0);let i=t(e).getCursor(n)?.encode();if(!i)throw Error(`cursor head not found`);let a;return r!==void 0&&(a=t(e).getCursor(r)?.encode()),{anchor:i,head:a}},mf=[`bg-(--amber-6)`,`bg-(--blue-6)`,`bg-(--crimson-6)`,`bg-(--cyan-6)`,`bg-(--grass-6)`,`bg-(--gray-6)`,`bg-(--green-6)`,`bg-(--lime-6)`,`bg-(--orange-6)`,`bg-(--purple-6)`,`bg-(--red-6)`,`bg-(--sage-6)`,`bg-(--sky-6)`,`bg-(--slate-6)`],hf=e=>{if(typeof e==`string`){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t=Math.trunc(t);return mf[Math.abs(t)%mf.length]}return mf[e%mf.length]},Q=It.get(`rtc`),gf=Q.get(`awareness`).disabled(),_f=`awareness:`;function vf(e,t){let n=new TextEncoder().encode(e);return new Uint8Array([...n,...t])}function yf(e,t){return new TextDecoder().decode(e.slice(0,t.length))===t}function bf(e,t){return e.slice(t.length)}var xf=r(void 0),$=new qi,Sf=new Zd($.peerIdStr),Cf=ri(()=>{Q.debug(`creating websocket`);let e=Zt().getWsSyncURL(Ut()).toString(),t=new na(e,void 0,{maxRetries:10,debug:!1,startClosed:!0,connectionTimeout:1e4});return Promise.resolve().then(async()=>{await Kt(),Vt()===`edit`&&t.reconnect()}),t.addEventListener(`message`,async e=>{let t=await e.data.arrayBuffer(),n=new Uint8Array(t);if(yf(n,_f)){let e=bf(n,_f);Sf.apply(e),gf.debug(`applied awareness update`);return}$.import(n),Q.debug(`imported doc change. new doc:`,$.toJSON()),o.get(xf)!==$&&o.set(xf,$)}),t.addEventListener(`open`,()=>{Q.debug(`websocket open`)}),t.addEventListener(`close`,e=>{Q.warn(`websocket close`,e),o.get(xf)===$&&o.set(xf,void 0)}),t});me()&&Cf(),$.subscribeLocalUpdates(e=>{Q.debug(`local update, sending to server`),Cf().send(new Uint8Array(e))}),Sf.addListener((e,t)=>{let n=[...e.added,...e.removed,...e.updated];t===`local`&&(gf.debug(`awareness changes`,n),Cf().send(vf(_f,Sf.encode(n))))});function wf(e,t,n=``){if(Wt())return{extension:[],code:n};let r=$.getByPath(`codes/${e}`)!==void 0,i=$.getMap(`codes`).getOrCreateContainer(e,new Zi);return r||(Q.log(`initializing code for new cell`,n),i.insert(0,n)),{code:n.toString(),extension:[Tf(e),Ef(e),Df($,Sf,{get name(){return o.get(Ke)||`Anonymous`},get colorClassName(){return hf(this.name)}},()=>i,e),be($,[`codes`,e],()=>i)]}}function Tf(e){let t=(e,t)=>{let n=e.state.field(Pe).type,r=t.toString();r&&r!==n&&(Q.debug(`[incoming] setting language type: ${n} -> ${r}`),lt(e,{language:r,keepCodeAsIs:!0}))},n=(e,t)=>{let n=e.state.field(nt),r=t.toJSON();a(n,r)||e.dispatch({effects:[Ze.of(r)],annotations:[$e.of(!0)]})};return Hr.define(r=>{let i;return Promise.resolve().then(()=>{let a=$.getByPath(`languages/${e}`);if(!a){Q.error(`no language container found for cell`,e);return}zt(a instanceof Zi,`language type is not a LoroText`);let o=$.getByPath(`language_metadata/${e}`);if(!o){Q.error(`no language metadata container found for cell`,e);return}zt(o instanceof Ji,`language metadata is not a LoroMap`),t(r,a),n(r,o),i=$.subscribe(e=>{if(e.origin===`local`)return;let i=e.events.some(e=>e.target===a.id),s=e.events.some(e=>e.target===o.id);i&&t(r,a),s&&n(r,o)})}),{destroy(){i()}}})}function Ef(e){let t=$.getMap(`languages`).getOrCreateContainer(e,new Zi),n=$.getMap(`language_metadata`).getOrCreateContainer(e,new Ji);return R.updateListener.of(e=>{let r=t.toString()!==``;if(!e.docChanged&&r)return;if(!r){let r=He(e.state).type;lt(e.view,{language:r}),Q.debug(`no initial language, setting default to`,r),t.delete(0,t.length),t.insert(0,r),Q.debug(`no initial language metadata, setting default to`,e.state.field(nt));let i=e.state.field(nt);for(let e of Object.keys(i))n.set(e,i[e]);$.commit();return}let i=!1;for(let r of e.transactions)if(!r.annotation($e)){for(let e of r.effects)if(e.is(de)&&t.toString()!==e.value.type&&(Q.debug(`[outgoing] language change: ${t} -> ${e.value.type}`),t.delete(0,t.length),t.insert(0,e.value.type),i=!0),e.is(Ze)||e.is(We)){let t=e.value;e.is(We)?(Q.debug(`[outgoing] setting language metadata: `,t),n.clear()):Q.debug(`[outgoing] updating language metadata: `,t);for(let e of Object.keys(t))n.set(e,t[e]);i=!0}}i&&$.commit()})}function Df(e,t,n,r,i,a){let o=`loro:cell:${i}`;return[rf,of(),sf(),Hr.define(i=>new df(i,e,n,t,r,o,a)),Hr.define(n=>new ff(n,e,t,o)),tf]}var Of=De,kf=e=>{let t=(0,H.c)(41),{resetOnBlur:n,placeholderText:r,initialValue:i,flexibleWidth:a,onNameChange:o,className:s}=e,c=n!==void 0&&n,l=i===void 0?null:i,u=a!==void 0&&a,{sendListFiles:d}=hi(),[f,p]=(0,V.useState)(l),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=[],t[0]=m):m=t[0];let[h,g]=(0,V.useState)(m),[_,v]=(0,V.useState)(!1),y=(0,V.useRef)(null),b=(0,V.useRef)(!1),x,S;t[1]===l?(x=t[2],S=t[3]):(x=()=>{p(l)},S=[l],t[1]=l,t[2]=x,t[3]=S),(0,V.useEffect)(x,S);let C;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{v(!0)},t[4]=C):C=t[4];let w=C,T;t[5]!==l||t[6]!==c?(T=e=>{e.relatedTarget?.closest(`.filename-input`)||(v(!1),c&&p(l))},t[5]=l,t[6]=c,t[7]=T):T=t[7];let E=T,D;t[8]===f?D=t[9]:(D=pn.dirname(f||``),t[8]=f,t[9]=D);let O=D,ee=pn.basename(f||``),k=h.filter(e=>pn.basename(e.path).startsWith(ee)),te;t[10]!==O||t[11]!==_||t[12]!==d?(te=async()=>{if(!_){g([]);return}let e=await d({path:O});g(e.files)},t[10]=O,t[11]=_,t[12]=d,t[13]=te):te=t[13];let ne;t[14]!==O||t[15]!==_?(ne=[O,_],t[14]=O,t[15]=_,t[16]=ne):ne=t[16];let{isPending:re}=Si(te,ne),A=Af(f,h,l),j=(A||k.length>0)&&(0,U.jsxs)(st,{className:`font-mono`,children:[!re&&(0,U.jsx)(Ve,{children:`No files`}),A&&(0,U.jsxs)(ue,{variant:`success`,className:`py-2 px-3`,onSelect:()=>{A&&(b.current=!0,o(A),y.current?.blur())},children:[(0,U.jsx)(aa,{className:`w-4 h-4 mr-2`}),` `,(0,U.jsxs)(`span`,{className:`text-sm`,children:[l?`Rename to: `:`Save as: `,(0,U.jsx)(`span`,{className:`font-medium text-sm`,children:pn.basename(A)})]})]},`_rename_`),k.map(e=>{let t=e.isDirectory?`directory`:Gn(e.path),n=Kn[t];return(0,U.jsxs)(ue,{variant:e.isDirectory?`default`:`muted`,className:`py-2 px-3`,onSelect:()=>{e.isDirectory?p(`${e.path}/`):p(e.path)},children:[(0,U.jsx)(n,{className:`w-4 h-4 mr-2`}),` `,pn.basename(e.path)]},e.path)})]}),ie=Math.max(20,f?.length||r?.length||0)*10,M=_?f||``:l||``,N;t[17]!==u||t[18]!==ie?(N=u?{maxWidth:ie}:void 0,t[17]=u,t[18]=ie,t[19]=N):N=t[19];let P;t[20]===s?P=t[21]:(P=en(s,`w-full px-4 py-1 my-1 h-9 font-mono text-foreground/60`),t[20]=s,t[21]=P);let ae;t[22]!==r||t[23]!==M||t[24]!==N||t[25]!==P?(ae=(0,U.jsx)(Of,{children:(0,U.jsx)(Ae,{"data-testid":`dir-completion-input`,tabIndex:-1,rootClassName:`border-none justify-center px-1`,spellCheck:`false`,value:M,onKeyDown:jf,icon:null,ref:y,onValueChange:p,placeholder:r,autoComplete:`off`,style:N,className:P})}),t[22]=r,t[23]=M,t[24]=N,t[25]=P,t[26]=ae):ae=t[26];let oe=j&&`group-focus-within:block`,se;t[27]===oe?se=t[28]:(se=en(`p-0 w-full min-w-80 max-w-80vw hidden`,oe),t[27]=oe,t[28]=se);let ce;t[29]!==j||t[30]!==se?(ce=(0,U.jsx)(ot,{side:`bottom`,className:se,portal:!1,children:j}),t[29]=j,t[30]=se,t[31]=ce):ce=t[31];let le;t[32]!==ae||t[33]!==ce?(le=(0,U.jsxs)(st,{children:[ae,ce]}),t[32]=ae,t[33]=ce,t[34]=le):le=t[34];let de;t[35]!==E||t[36]!==le?(de=(0,U.jsx)(Ee,{onFocus:w,onBlur:E,shouldFilter:!1,id:`filename-input`,className:`bg-transparent group filename-input`,children:le}),t[35]=E,t[36]=le,t[37]=de):de=t[37];let fe;return t[38]!==_||t[39]!==de?(fe=(0,U.jsx)($t,{children:(0,U.jsx)(xe,{open:_,modal:!1,children:de})}),t[38]=_,t[39]=de,t[40]=fe):fe=t[40],fe};function Af(e,t,n){if(e&&!e.endsWith(`/`)&&((fe(`markdown`)?new Set([`py`,`md`,`markdown`,`qmd`]):new Set([`py`])).has(pn.extension(e))||(e=e.endsWith(`.`)?`${e}py`:e.endsWith(`.p`)?`${e}y`:`${e}.py`),!t.some(t=>t.path===e||pn.basename(t.path)===e)&&!(n&&(n===e||pn.basename(n)===e))))return e}function jf(e){e.key===`Escape`&&e.currentTarget.blur()}var Mf=e=>{let t=(0,H.c)(33),n=()=>{on(new Blob([r()],{type:`text/plain`}),`${e.proposedName}.json`)},r=c(Ff),i;t[0]!==n||t[1]!==e?(i=t=>{t.preventDefault(),n(),e.closeModal()},t[0]=n,t[1]=e,t[2]=i):i=t[2];let a;t[3]===e?a=t[4]:(a=t=>{t.key===`Escape`&&e.closeModal()},t[3]=e,t[4]=a);let o;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,U.jsx)(cr,{className:`text-accent-foreground mb-6`,children:`Download unsaved changes?`}),t[5]=o):o=t[5];let s;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(s={wordBreak:`break-word`},t[6]=s):s=t[6];let l,u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,U.jsx)(`p`,{children:`This app has unsaved changes. To recover:`}),u={paddingBottom:`10px`},t[7]=l,t[8]=u):(l=t[7],u=t[8]);let d;t[9]===e.proposedName?d=t[10]:(d=(0,U.jsxs)(`li`,{style:u,children:[`Click the "Download" button. This will download a file called\xA0`,(0,U.jsxs)(`code`,{children:[e.proposedName,`.json`]}),`. This file contains your code.`]}),t[9]=e.proposedName,t[10]=d);let f;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(f={paddingBottom:`10px`},t[11]=f):f=t[11];let p;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(p={display:`block`,padding:`10px`},t[12]=p):p=t[12];let m;t[13]===e.proposedName?m=t[14]:(m=(0,U.jsxs)(`code`,{style:p,children:[`marimo recover `,e.proposedName,`.json `,`>`,` `,e.proposedName,`.py`]}),t[13]=e.proposedName,t[14]=m);let h;t[15]===e.proposedName?h=t[16]:(h=(0,U.jsxs)(`code`,{children:[e.proposedName,`.py`]}),t[15]=e.proposedName,t[16]=h);let g;t[17]!==h||t[18]!==m?(g=(0,U.jsxs)(`li`,{style:f,children:[`In your terminal, type`,m,`to overwrite `,h,` with the recovered changes.`]}),t[17]=h,t[18]=m,t[19]=g):g=t[19];let _;t[20]!==g||t[21]!==d?(_=(0,U.jsx)(ar,{className:`markdown wrap-break-word`,style:s,children:(0,U.jsxs)(`div`,{className:`prose dark:prose-invert`,children:[l,(0,U.jsxs)(`ol`,{children:[d,g]})]})}),t[20]=g,t[21]=d,t[22]=_):_=t[22];let v;t[23]===e.closeModal?v=t[24]:(v=(0,U.jsx)(un,{"aria-label":`Cancel`,variant:`secondary`,"data-testid":`cancel-recovery-button`,onClick:e.closeModal,children:`Cancel`}),t[23]=e.closeModal,t[24]=v);let y;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,U.jsx)(un,{"data-testid":`download-recovery-button`,"aria-label":`Download`,variant:`default`,type:`submit`,children:`Download`}),t[25]=y):y=t[25];let b;t[26]===v?b=t[27]:(b=(0,U.jsxs)(sr,{children:[v,y]}),t[26]=v,t[27]=b);let x;return t[28]!==i||t[29]!==a||t[30]!==_||t[31]!==b?(x=(0,U.jsx)(or,{className:`w-fit`,children:(0,U.jsxs)(`form`,{onSubmit:i,onKeyDown:a,children:[o,_,b]})}),t[28]=i,t[29]=a,t[30]=_,t[31]=b,t[32]=x):x=t[32],x},Nf=e=>{let t=(0,H.c)(12),{filename:n,needsSave:r}=e,{openModal:i,closeModal:a}=Jn(),o;t[0]===n?o=t[1]:(o=n===null?`app`:pn.basename(n).split(`.`)[0],t[0]=n,t[1]=o);let s=o,c;t[2]!==a||t[3]!==r||t[4]!==i||t[5]!==s?(c=()=>{r&&i((0,U.jsx)(Mf,{proposedName:s,closeModal:a}))},t[2]=a,t[3]=r,t[4]=i,t[5]=s,t[6]=c):c=t[6];let l=c;_n(`global.save`,l);let u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=Mi(`global.save`),t[7]=u):u=t[7];let d=r?`yellow`:`gray`,f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,U.jsx)(tr,{strokeWidth:1.5,size:18}),t[8]=f):f=t[8];let p;return t[9]!==l||t[10]!==d?(p=(0,U.jsx)(cn,{content:u,children:(0,U.jsx)(ra,{onClick:l,id:`save-button`,"aria-label":`Save`,className:`rectangle`,color:d,children:f})}),t[9]=l,t[10]=d,t[11]=p):p=t[11],p};function Pf(e){return{id:e.id,name:e.name,code:e.code,code_hash:null,config:{column:0,...e.config}}}function Ff(){let e=Me(),t=ye(e),n={version:`1`,metadata:{marimo_version:Qt()},cells:t.map(Pf)};return JSON.stringify(n,null,2)}var If=r(void 0),Lf=r(e=>{let t=e(If);return Rf({state:e(he),layout:e(Zn),lastSavedNotebook:t})});function Rf({state:e,layout:t,lastSavedNotebook:n}){if(!n)return!1;let{cellIds:r,cellData:i}=e,o=r.inOrderIds.map(e=>i[e]),s=o.map(e=>e.code),c=o.map(e=>e.config),l=o.map(e=>e.name);return!ni(s,n.codes)||!ni(l,n.names)||!a(c,n.configs)||!a(t.selectedLayout,n.layout.selectedLayout)||!a(t.layoutData,n.layout.layoutData)}function zf(e){let t=(0,H.c)(21),{codes:n,cellConfigs:r,config:i,connStatus:a,cellNames:o,needsSave:s,kioskMode:c,onSave:l}=e,u=(0,V.useRef)(null),d;t[0]===n?d=t[1]:(d=n.join(`:`),t[0]=n,t[1]=d);let f=d,p;t[2]===r?p=t[3]:(p=r.map(Bf).join(`:`),t[2]=r,t[3]=p);let m=p,h;t[4]===o?h=t[5]:(h=o.join(`:`),t[4]=o,t[5]=h);let g=h,_;t[6]!==i||t[7]!==a.state||t[8]!==c||t[9]!==s||t[10]!==l?(_=()=>{if(!c)return i.autosave===`after_delay`&&(u.current!==null&&clearTimeout(u.current),s&&a.state===qt.OPEN&&(u.current=setTimeout(l,i.autosave_delay))),()=>{u.current!==null&&clearTimeout(u.current)}},t[6]=i,t[7]=a.state,t[8]=c,t[9]=s,t[10]=l,t[11]=_):_=t[11];let v;t[12]!==m||t[13]!==g||t[14]!==f||t[15]!==i||t[16]!==a.state||t[17]!==c||t[18]!==s||t[19]!==l?(v=[f,m,g,i,a.state,l,c,s],t[12]=m,t[13]=g,t[14]=f,t[15]=i,t[16]=a.state,t[17]=c,t[18]=s,t[19]=l,t[20]=v):v=t[20],(0,V.useEffect)(_,v)}function Bf(e){return JSON.stringify(e)}var Vf=Promise.resolve();function Hf(e){let t=Vf.then(e);return Vf=t.then(()=>void 0,()=>void 0),t}var Uf=e=>{let t=(0,H.c)(15),{kioskMode:n}=e,r=Ai(),a=i(Lf),o=i(Jt).state===qt.CLOSED,{saveOrNameNotebook:s,saveIfNotebookIsPersistent:c}=Wf(),l;t[0]!==n||t[1]!==c?(l={onSave:c,kioskMode:n},t[0]=n,t[1]=c,t[2]=l):l=t[2],Yf(l),ia();let u;t[3]===a?u=t[4]:(u=e=>{if(a)return e.preventDefault(),e.returnValue=`You have unsaved changes. Are you sure you want to leave?`,e.returnValue},t[3]=a,t[4]=u),Rt(window,`beforeunload`,u);let d;t[5]===s?d=t[6]:(d=e=>{e.preventDefault(),e.stopPropagation(),s()},t[5]=s,t[6]=d);let f=d;if(_n(`global.save`,s),o){let e;return t[7]!==r||t[8]!==a?(e=(0,U.jsx)(Nf,{filename:r,needsSave:a}),t[7]=r,t[8]=a,t[9]=e):e=t[9],e}let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=Mi(`global.save`),t[10]=p):p=t[10];let m=a?`yellow`:`hint-green`,h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(tr,{strokeWidth:1.5,size:18}),t[11]=h):h=t[11];let g;return t[12]!==f||t[13]!==m?(g=(0,U.jsx)(cn,{content:p,children:(0,U.jsx)(ra,{"data-testid":`save-button`,id:`save-button`,shape:`rectangle`,color:m,onClick:f,children:h})}),t[12]=f,t[13]=m,t[14]=g):g=t[14],g};function Wf(){let e=(0,H.c)(21),{sendSave:t}=hi(),{openModal:r,closeModal:i,openAlert:a}=Jn(),o=l(If),s=ji(),u=n(),d;e[0]!==a||e[1]!==t||e[2]!==o||e[3]!==u?(d=(e,n)=>Hf(async()=>{let r=u.get(Jt),i=u.get(At);if(u.get(Ht))return;if(r.state!==qt.OPEN){a(`Failed to save notebook: not connected to a kernel.`);return}if(It.log(`saving to `,e),n&&i.format_on_save&&(It.log(`formatting notebook (onSave)`),await le()),ye(Me()).length===0)return;let s=await rt(async()=>{let n=Me(),r=ye(n),i=r.map(qf),a=r.map(Kf),o=r.map(Gf),s=Ce(n),c=u.get(Zn);return await t({cellIds:i,codes:a,names:o,filename:e,configs:s,layout:mn(),persist:!0}),{names:o,codes:a,configs:s,layout:c}});o(s)}),e[0]=a,e[1]=t,e[2]=o,e[3]=u,e[4]=d):d=e[4];let f=c(d),p;e[5]!==f||e[6]!==u?(p=e=>{let t=e!==void 0&&e,n=u.get(gt),r=u.get(Jt);Jf(n)&&r.state===qt.OPEN&&f(n,t)},e[5]=f,e[6]=u,e[7]=p):p=e[7];let m=c(p),h;e[8]!==f||e[9]!==s?(h=e=>{s(e).then(e=>{e!==null&&f(e,!0)})},e[8]=f,e[9]=s,e[10]=h):h=e[10];let g=h,_;e[11]!==i||e[12]!==g||e[13]!==r||e[14]!==m||e[15]!==u?(_=()=>{let e=u.get(gt),t=u.get(Jt);m(!0),!Jf(e)&&t.state!==qt.CLOSED&&r((0,U.jsx)(Qf,{onClose:i,onSave:g}))},e[11]=i,e[12]=g,e[13]=r,e[14]=m,e[15]=u,e[16]=_):_=e[16];let v=c(_),y;return e[17]!==m||e[18]!==f||e[19]!==v?(y={saveOrNameNotebook:v,saveIfNotebookIsPersistent:m,saveNotebook:f},e[17]=m,e[18]=f,e[19]=v,e[20]=y):y=e[20],y}function Gf(e){return e.name}function Kf(e){return e.code}function qf(e){return e.id}function Jf(e){return e!==null&&!e.startsWith(`/tmp/`)&&!e.startsWith(`/var/folders`)&&!e.includes(`AppData\\Local\\Temp`)}function Yf(e){let n=(0,H.c)(14),r=i(At),a=C(),[o]=t(Jt),s=i(Lf),c,l;if(n[0]!==a){let e=ye(a);c=e.map(Zf),l=e.map(Xf),n[0]=a,n[1]=c,n[2]=l}else c=n[1],l=n[2];let u=l,d;n[3]===a?d=n[4]:(d=Ce(a),n[3]=a,n[4]=d);let f=d,p;n[5]!==r||n[6]!==u||n[7]!==c||n[8]!==f||n[9]!==o||n[10]!==s||n[11]!==e.kioskMode||n[12]!==e.onSave?(p={onSave:e.onSave,needsSave:s,codes:c,cellConfigs:f,cellNames:u,connStatus:o,config:r,kioskMode:e.kioskMode},n[5]=r,n[6]=u,n[7]=c,n[8]=f,n[9]=o,n[10]=s,n[11]=e.kioskMode,n[12]=e.onSave,n[13]=p):p=n[13],zf(p)}function Xf(e){return e.name}function Zf(e){return e.code}var Qf=e=>{let t=(0,H.c)(17),{onClose:n,onSave:r}=e,[i,a]=(0,V.useState)(),o;t[0]!==n||t[1]!==r?(o=e=>{a(e),e.trim()&&(r(e),n())},t[0]=n,t[1]=r,t[2]=o):o=t[2];let s=o,c;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,U.jsx)(cr,{children:`Save notebook`}),t[3]=c):c=t[3];let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,U.jsx)(an,{className:`text-md pt-6 px-1`,children:`Save as`}),t[4]=l):l=t[4];let u;t[5]===s?u=t[6]:(u=(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[l,(0,U.jsx)(kf,{onNameChange:s,placeholderText:`filename`,className:`missing-filename`})]}),t[5]=s,t[6]=u);let d;t[7]===n?d=t[8]:(d=(0,U.jsx)(un,{"data-testid":`cancel-save-dialog-button`,"aria-label":`Cancel`,variant:`secondary`,onClick:n,children:`Cancel`}),t[7]=n,t[8]=d);let f=!i,p;t[9]===f?p=t[10]:(p=(0,U.jsx)(un,{"data-testid":`submit-save-dialog-button`,"aria-label":`Save`,variant:`default`,disabled:f,type:`submit`,children:`Save`}),t[9]=f,t[10]=p);let m;t[11]!==d||t[12]!==p?(m=(0,U.jsxs)(sr,{children:[d,p]}),t[11]=d,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==u||t[15]!==m?(h=(0,U.jsxs)(or,{children:[c,u,m]}),t[14]=u,t[15]=m,t[16]=h):h=t[16],h};function $f(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var ep={modified:{doc:``},original:{doc:``}},tp=(0,V.createContext)(ep);function np(e,t){return z({},e,t,{modified:z({},e.modified,t.modified),original:z({},e.original,t.original)})}var rp=()=>(0,V.useContext)(tp),ip=e=>{var t=e.children,n=e.theme,r=(0,V.useReducer)(np,z({},ep,{theme:n})),i=r[0],a=r[1];return(0,V.useEffect)(()=>a({theme:n}),[n]),(0,U.jsx)(tp.Provider,{value:z({},i,{dispatch:a}),children:t})},ap=[`extensions`,`value`,`selection`,`onChange`],op=e=>{var t=e.extensions,n=t===void 0?[]:t,r=e.value,i=e.selection,a=e.onChange,o=Ei(e,ap),s=rp(),c=s.theme,l=s.dispatch,u=Fi(z({},o,{theme:c}));return(0,V.useEffect)(()=>l({original:{doc:r,selection:i,extensions:[...u,...n]},originalExtension:{onChange:a,option:o,extension:[n]}}),[e]),null};op.displayName=`CodeMirrorMerge.Original`;var sp=[`extensions`,`value`,`selection`,`onChange`],cp=e=>{var t=e.extensions,n=t===void 0?[]:t,r=e.value,i=e.selection,a=e.onChange,o=Ei(e,sp),s=rp(),c=s.theme,l=s.dispatch,u=Fi(z({},o,{theme:c}));return(0,V.useEffect)(()=>{l({modified:{doc:r,selection:i,extensions:[...u,...n]},modifiedExtension:{onChange:a,option:o,extension:[n]}})},[e]),null};cp.displayName=`CodeMirrorMerge.Modified`;var lp=[`className`,`children`,`orientation`,`revertControls`,`highlightChanges`,`gutter`,`collapseUnchanged`,`destroyRerender`,`renderRevertControl`,`diffConfig`,`root`],up=[`modified`,`modifiedExtension`,`original`,`originalExtension`,`theme`,`dispatch`],dp=V.forwardRef((e,t)=>{var n=e.className,r=e.children,i=e.orientation,a=e.revertControls,o=e.highlightChanges,s=e.gutter,c=e.collapseUnchanged,l=e.destroyRerender,u=l===void 0||l,d=e.renderRevertControl,f=e.diffConfig,p=e.root,m=Ei(e,lp),h=rp(),g=h.modified,_=h.modifiedExtension,v=h.original,y=h.originalExtension,b=h.theme,x=h.dispatch,S=Ei(h,up),C=(0,V.useRef)(null),w=(0,V.useRef)(),T={orientation:i,revertControls:a,highlightChanges:o,gutter:s,collapseUnchanged:c,renderRevertControl:d,diffConfig:f,root:p};(0,V.useImperativeHandle)(t,()=>({container:C.current,view:w.current,modified:g,original:v,config:z({a:v,b:g,parent:C.current},T)}),[C,w,g,v,T]);var E=R.updateListener.of(e=>{if(e.docChanged&&typeof y?.onChange==`function`){var t=e.state.doc.toString();y?.onChange(t,e)}}),D=R.updateListener.of(e=>{if(e.docChanged&&typeof _?.onChange==`function`){var t=e.state.doc.toString();_?.onChange(t,e)}});return(0,V.useEffect)(()=>{!w.current&&C.current&&y&&_&&(w.current=new Ii(z({a:z({},v,{extensions:[...y?.extension||[],...Fi(z({},y?.option,{theme:b})),E]}),b:z({},g,{extensions:[..._?.extension||[],...Fi(z({},_?.option,{theme:b})),D]}),parent:C.current},T)),x({view:w.current}))},[w,C,y,_]),(0,V.useEffect)(()=>{if(v&&v.doc&&w.current){var e=w.current?.a.state.doc.toString();if(e!==v.doc){var t;(t=w.current)==null||t.a.dispatch({changes:{from:0,to:e.length,insert:v.doc||``}})}}if(g&&g.doc&&w.current){var n=w.current?.b.state.doc.toString();if(n!==g.doc){var r;(r=w.current)==null||r.b.dispatch({changes:{from:0,to:n.length,insert:g.doc||``}})}}if(u&&w.current){var i=w.current.a.state.selection.ranges[0].from,a=w.current.b.state.selection.ranges[0].from;w.current.destroy(),w.current=new Ii(z({a:z({},v,{extensions:[...y?.extension||[],...Fi(z({},y?.option,{theme:b}))]}),b:z({},g,{extensions:[..._?.extension||[],...Fi(z({},_?.option,{theme:b}))]}),parent:C.current},T)),i&&(w.current.a.focus(),w.current.a.dispatch({selection:{anchor:i,head:i}})),a&&(w.current.b.focus(),w.current.b.dispatch({selection:{anchor:a,head:a}}))}},[w,b,C.current,v,g,y,_,u]),(0,V.useEffect)(()=>()=>w.current&&w.current.destroy(),[]),(0,V.useEffect)(()=>{if(w.current){var e={};S.orientation!==i&&(e.orientation=i),S.revertControls!==a&&(e.revertControls=a),S.highlightChanges!==o&&(e.highlightChanges=o),S.gutter!==s&&(e.gutter=s),S.collapseUnchanged!==c&&(e.collapseUnchanged=c),S.renderRevertControl!==d&&(e.collapseUnchanged=c),Object.keys(e).length&&x&&w.current&&(w.current.reconfigure(z({},e)),x(z({},e)))}},[x,w,i,a,o,s,c,d]),(0,U.jsx)(`div`,z({ref:C,className:`cm-merge-theme`+(n?` `+n:``)},m,{children:r}))});dp.displayName=`CodeMirrorMerge.Internal`;var fp=[`theme`],pp=V.forwardRef((e,t)=>{var n=e.theme,r=Ei(e,fp);return(0,U.jsx)(ip,{theme:n,children:(0,U.jsx)(dp,z({},r,{ref:t}))})});pp.Original=op,pp.Modified=cp,pp.displayName=`CodeMirrorMerge`;var mp=pp.Original,hp=pp.Modified,gp=[se(),R.lineWrapping],_p=({cellId:e,aiCompletionCell:n,className:r,onChange:i,currentLanguageAdapter:a,currentCode:o,declineChange:s,acceptChange:c,runCell:l,outputArea:u,children:d})=>{let[p,m]=(0,V.useState)(!1),[h,g]=t(Oi),_=(0,V.useId)(),v=Yt(),{initialPrompt:y,triggerImmediately:x,cellId:C}=n??{},w=C===e,T=An(e),E;T?.type===`update_cell`&&(E=T.previousCode);let[D,O]=(0,V.useState)(``),[ee,k]=(0,V.useState)(y??``),te=V.useMemo(()=>new Tn({api:v.getAiURL(`completion`).toString(),headers:()=>v.headers(),prepareSendMessagesRequest:({body:e,id:t})=>({body:{...e,id:t}})}),[v]),{sendMessage:ne,stop:re,status:A}=Un({throttle:100,transport:te,onData:e=>{if(e.type===En){let t=On.parse(e.data);O(t.code.trimEnd())}},onError:e=>{O(``),ur({title:`Completion failed`,description:Ti(e)})},onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{(e||t||n||r!==`stop`)&&O(``)}}),j=A===`submitted`||A===`streaming`,ie=(0,V.useCallback)(()=>{O(``),re()},[re]),M=(0,V.useCallback)(async e=>{await re(),O(``);let t={...Mn({input:e}),prompt:e,includeOtherCode:h?ce(o):``,code:o,language:a??`python`};await ne({text:e},{body:t})},[o,a,h,ne,re]),N=(0,V.useCallback)(()=>{M(ee)},[M,ee]),P=V.useRef(null),ae=(0,V.useCallback)(()=>{x&&!j&&y&&M(y)},[x]);(0,V.useEffect)(()=>{w&&(S(()=>{let e=P.current;return e?.view?(e.view.focus(),ae(),!0):!1},{retries:3,delay:100,initialDelay:100}),b(P.current?.view))},[w,ae]),(0,V.useEffect)(()=>{w&&k(y||``)},[w,y,k]);let{theme:oe}=yi(),se=()=>{c(D),O(``)},le=()=>{ie(),m(!0),P.current?.view?.focus()},ue=w&&x&&(D||j);u??=`below`;let de=w&&(!x||p),fe=(0,U.jsx)(`div`,{className:en(`w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden`,ue?`max-h-20 opacity-100 translate-y-0`:`max-h-0 opacity-0 -translate-y-2`),children:(0,U.jsx)(vp,{status:j?`loading`:`generated`,onAccept:se,onReject:le,showInputPrompt:p,setShowInputPrompt:m,runCell:l,className:`mt-4 mb-3 w-lg`})}),pe=(e,t)=>(0,U.jsxs)(pp,{className:`cm`,theme:oe,children:[(0,U.jsx)(mp,{onChange:i,value:e,extensions:gp}),(0,U.jsx)(hp,{value:t,editable:!1,readOnly:!0,extensions:gp})]}),me=()=>{if(D&&w)return pe(o,D);if(!D&&E)return pe(E,o)},he=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Ln,{isLoading:j,onAccept:se,size:`xs`,multipleCompletions:!1,label:Bn.accept,acceptShortcut:`Mod-↵`,runCell:l}),(0,U.jsx)(zn,{onDecline:le,size:`xs`,multipleCompletions:!1,label:Bn.decline,declineShortcut:`Shift-Mod-Delete`})]});return(0,U.jsxs)(`div`,{"data-ai-input-open":de,className:en(`flex flex-col w-full rounded-[inherit]`,r),children:[(0,U.jsx)(`div`,{className:en(`flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300`,de&&`max-h-[400px] border-b min-h-11 visible`,!de&&`max-h-0 min-h-0 invisible`),children:w&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Ye,{className:`text-(--blue-10) shrink-0`,size:16}),(0,U.jsx)(Rn,{inputRef:P,className:`h-full my-0 py-2 flex items-center`,onClose:()=>{ie(),s()},value:ee,onChange:k,onSubmit:()=>{j||(P.current?.view&&jn(P.current.view),N())},onKeyDown:Vn({handleAcceptCompletion:se,handleDeclineCompletion:le,isLoading:j,hasCompletion:D.trim().length>0})}),(0,U.jsxs)(`div`,{className:`-mr-1.5 py-1.5`,children:[(0,U.jsxs)(`div`,{className:`flex flex-row items-center justify-end gap-0.5`,children:[(0,U.jsx)(In,{isLoading:j,onStop:ie,onSendClick:N,isEmpty:!ee.trim(),showStopLabel:!0}),(0,U.jsx)(Fn,{handleAddContext:()=>Hn(P),isLoading:j}),(0,U.jsx)(bn,{triggerClassName:`h-7 text-xs`,iconSize:`small`,forRole:`edit`,displayIconOnly:!0,placeholder:`Edit model`})]}),D&&(0,U.jsx)(`div`,{className:`mt-1 flex items-center gap-1`,children:he})]}),(0,U.jsx)(`div`,{className:`h-full w-px bg-border mx-2`}),(0,U.jsx)(cn,{content:`Include code from other cells`,children:(0,U.jsxs)(`div`,{className:`flex flex-row items-start gap-1 overflow-hidden`,children:[(0,U.jsx)(f,{"data-testid":`include-other-cells-checkbox`,id:_,checked:h,onCheckedChange:e=>g(!!e)}),(0,U.jsx)(an,{htmlFor:_,className:`text-muted-foreground text-xs whitespace-nowrap ellipsis`,children:`All code`})]})}),(0,U.jsx)(un,{"data-testid":`decline-completion-button`,variant:`text`,size:`icon`,disabled:j,onClick:()=>{ie(),s()},children:(0,U.jsx)(Cn,{className:`text-(--red-10)`,size:16})})]})}),u===`above`&&fe,me(),(!D||!w)&&!E&&d,u===`below`&&fe]})},vp=e=>{let t=(0,H.c)(27),{status:n,onAccept:r,onReject:i,className:a,showInputPrompt:o,setShowInputPrompt:s,runCell:c}=e,l=n===`loading`,u;t[0]===a?u=t[1]:(u=en(`flex flex-row items-center gap-6 rounded-md py-2 px-2.5 text-sm border border-border bg-(--gray-2) dark:bg-(--gray-3)`,a),t[0]=a,t[1]=u);let d;t[2]===l?d=t[3]:(d=l?(0,U.jsx)(Yn,{className:`animate-spin text-blue-600 mb-px`,size:15,strokeWidth:2,"aria-label":`Generating fix`}):(0,U.jsx)(wn,{className:`text-green-600 mb-px`,size:15,strokeWidth:2,"aria-label":`Fix generated`}),t[2]=l,t[3]=d);let f=l?`Generating fix...`:`Showing fix`,p;t[4]===f?p=t[5]:(p=(0,U.jsx)(`p`,{className:`transition-opacity duration-200 text-muted-foreground`,children:f}),t[4]=f,t[5]=p);let m;t[6]!==d||t[7]!==p?(m=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-2`,children:[d,p]}),t[6]=d,t[7]=p,t[8]=m):m=t[8];let h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(an,{htmlFor:`show-input-prompt`,className:`text-muted-foreground text-xs whitespace-nowrap ellipsis`,children:`Show prompt`}),t[9]=h):h=t[9];let g;t[10]!==s||t[11]!==o?(g=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-1`,children:[h,(0,U.jsx)(sn,{checked:o,onCheckedChange:s,size:`xs`})]}),t[10]=s,t[11]=o,t[12]=g):g=t[12];let _;t[13]!==l||t[14]!==r||t[15]!==c?(_=(0,U.jsx)(Ln,{isLoading:l,onAccept:r,size:`xs`,label:Bn.accept,runCell:c}),t[13]=l,t[14]=r,t[15]=c,t[16]=_):_=t[16];let v;t[17]===i?v=t[18]:(v=(0,U.jsx)(zn,{onDecline:i,size:`xs`,label:Bn.decline}),t[17]=i,t[18]=v);let y;t[19]!==_||t[20]!==v?(y=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-2 ml-auto`,children:[_,v]}),t[19]=_,t[20]=v,t[21]=y):y=t[21];let b;return t[22]!==u||t[23]!==y||t[24]!==m||t[25]!==g?(b=(0,U.jsxs)(`div`,{className:u,children:[m,g,y]}),t[22]=u,t[23]=y,t[24]=m,t[25]=g,t[26]=b):b=t[26],b},yp=`web application/x-marimo-cell`,bp=xt({cells:wt(xt({code:yt(),name:yt().optional(),config:xt({column:Ct([bt(),Tt()]).optional(),disabled:vt().optional(),hide_code:vt().optional(),expand_output:vt().optional()}).optional()})),version:St(`1.0`)});function xp(e){return e.map(e=>e.code).join(`
|
|
19
19
|
|
|
20
|
-
`)}async function Sp(e){let t={cells:e.map(e=>({code:e.code,name:e.name,config:e.config})),version:`1.0`},n=new Op().add(yp,t).add(`text/plain`,xp(e)).build();await navigator.clipboard.write([n])}function Cp(){let e=(0,H.c)(13),t=y(),n=Te(),r=qe(),i;e[0]===n?i=e[1]:(i=async e=>{let t=Me(),r=e.map(e=>t.cellData[e]).filter(Boolean);if(r.length!==0)try{await Sp(r),n.clear(),wp(r.length)}catch(e){let t=e;It.error(`Failed to copy cells to clipboard`,t);try{await cr(xp(r)),n.clear(),wp(r.length)}catch{Tp()}}},e[0]=n,e[1]=i);let a=c(i),o;e[2]===n?o=e[3]:(o=async e=>{let t=Me(),r=e.filter(e=>t.cellData[e]),i=r.map(e=>t.cellData[e]);if(i.length!==0)try{await Sp(i),n.markForCut({cellIds:r})}catch(e){let t=e;It.error(`Failed to cut cells to clipboard`,t);try{await cr(xp(i)),n.markForCut({cellIds:r})}catch{Tp()}}},e[2]=n,e[3]=o);let s=c(o),l;e[4]!==t||e[5]!==n||e[6]!==r.cellIds?(l=async(e,i)=>{let{before:a}=i??{},o=a!==void 0&&a;if(r.cellIds.size>0){let i=[...r.cellIds],a=Me(),s=i.map(e=>{let t=a.cellIds.findWithId(e);return{columnId:t.id,index:t.indexOfOrThrow(e)}});t.moveCellsRelativeTo({cellIds:i,targetCellId:e,position:o?`before`:`after`,previousPlacements:s}),n.clear();return}try{let n=await navigator.clipboard.read();for(let r of n)if(r.types.includes(yp)){let n=await(await r.getType(yp)).text();try{let r=bp.parse(JSON.parse(n));if(r.cells.length===0)break;let i=e,a=r.cells.toReversed();for(let e of a)t.createNewCell({cellId:i,before:o,code:e.code,name:e.name,config:e.config,hideCode:e.config?.hide_code,autoFocus:!0});return}catch(e){let t=e;It.warn(`Failed to parse clipboard cell data`,t)}}let r=await navigator.clipboard.readText();r.trim()?t.createNewCell({cellId:e,before:o,code:r,autoFocus:!0}):Ep()}catch(e){let t=e;It.error(`Failed to paste from clipboard`,t),Dp()}},e[4]=t,e[5]=n,e[6]=r.cellIds,e[7]=l):l=e[7];let u=c(l),d;return e[8]!==a||e[9]!==s||e[10]!==u||e[11]!==n.clear?(d={copyCells:a,cutCells:s,pasteAtCell:u,clearPendingCut:n.clear},e[8]=a,e[9]=s,e[10]=u,e[11]=n.clear,e[12]=d):d=e[12],d}var wp=e=>{let t=e===1?`Cell`:`${e} cells`;lr({title:`${t} copied`,description:`${t} ${e===1?`has`:`have`} been copied to clipboard.`})},Tp=()=>{lr({title:`Copy failed`,description:`Failed to copy cells to clipboard.`,variant:`danger`})},Ep=()=>{lr({title:`Nothing to paste`,description:`No cell or text found in clipboard.`,variant:`danger`})},Dp=()=>{lr({title:`Paste failed`,description:`Failed to read from clipboard`,variant:`danger`})},Op=class{items={};add(e,t){return ClipboardItem.supports(e)?typeof t==`string`?(this.items[e]=new Blob([t],{type:e}),this):(this.items[e]=new Blob([JSON.stringify(t)],{type:e}),this):(It.warn(`ClipboardItem does not support ${e}`),this)}build(){return new ClipboardItem(this.items)}};function kp(){return{selectionStart:null,selectionEnd:null,selected:new Set}}var{reducer:Ap,createActions:jp,valueAtom:Mp,useActions:Np}=ri(kp,{select:(e,t)=>({selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])}),extend:(e,t)=>{if(!e.selectionStart)return{selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])};let{cellId:n,allCellIds:r}=t;try{let t=r.findWithId(e.selectionStart),i=t.indexOfOrThrow(e.selectionStart),a=t.indexOfOrThrow(n),[o,s]=i<a?[i,a]:[a,i],c=t.slice(o,s+1);return{selectionStart:e.selectionStart,selectionEnd:n,selected:new Set(c)}}catch{return{selectionStart:n,selectionEnd:n,selected:new Set([n])}}},clear:e=>e.selected.size===0?e:kp()}),Pp=()=>i(Mp);function Fp(e){let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=r(t=>t(Mp).selected.has(e)),t[0]=e,t[1]=n),i(n)}function Ip(){return Np()}function Lp(e){return e.get(Mp).selected}var{valueAtom:Rp,useActions:zp}=ri(()=>new Set,{add:(e,t)=>{if(e.has(t))return e;let n=new Set(e);return n.add(t),n},remove:(e,t)=>{if(!e.has(t))return e;let n=new Set(e);return n.delete(t),T(()=>{let e=document.activeElement;if(!e)return;let t=mt.findElementThroughShadowDOMs(e);t&&N(mt.parse(t.id))}),n}}),Bp=e=>r(t=>t(Rp).has(e));function Vp(e){let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=Bp(e),t[0]=e,t[1]=n),i(n)}var Hp=new WeakMap,Up=500;function Wp(e){if(e.ctrlKey||e.metaKey||e.altKey)return``;let t=e.key.toLowerCase();return e.shiftKey?`shift+${t}`:t}function Gp(e,t){let n=Wp(e),r=e.target;if(!n||!r)return!1;let i=Hp.get(r),a=n;i?.timeout&&clearTimeout(i.timeout),i&&(a=`${i.sequence} ${n}`);let o=t[a];if(o)return Hp.delete(r),o();if(!i){let e=t[n];if(e)return e()}if(Object.keys(t).some(e=>e.startsWith(`${a} `))){let e=window.setTimeout(()=>{Hp.delete(r)},Up);return Hp.set(r,{sequence:a,timeout:e}),!0}return Hp.delete(r),!1}function Kp(e){return{handle:t=>e(t),bulkHandle:t=>{let n=!0;try{for(let r of t)n&&=e(r);return n}catch{return!1}}}}function qp(e){return{handle:t=>e([t]),bulkHandle:t=>e(t)}}function Jp(e,t){let n=(0,H.c)(12),r=D(),i=y(),a=zp(),o;n[0]!==e||n[1]!==r?(o=()=>{r.focusCell({cellId:e})},n[0]=e,n[1]=r,n[2]=o):o=n[2];let s;n[3]!==i||n[4]!==e||n[5]!==t||n[6]!==r||n[7]!==a?(s=n=>{Yp(n.relatedTarget)||Yp(n.target)||Xp(n.relatedTarget)!==e&&Xp(n.relatedTarget?.closest(`[data-for-cell-id]`))!==e&&(a.remove(e),i.markTouched({cellId:e}),r.blurCell(),t.current&&tm(t.current))},n[3]=i,n[4]=e,n[5]=t,n[6]=r,n[7]=a,n[8]=s):s=n[8];let c;n[9]!==o||n[10]!==s?(c={onFocusWithin:o,onBlurWithin:s},n[9]=o,n[10]=s,n[11]=c):c=n[11];let{focusWithinProps:l}=nr(c);return l}function Yp(e){return e?e instanceof HTMLElement&&e.closest(`.cm-vim-panel`)!==null:!1}function Xp(e){return e&&e.getAttribute(ee)||null}function Zp(e,t){let r=(0,H.c)(34),{canMoveX:a,editorView:o,cellActionDropdownRef:s}=t,{saveOrNameNotebook:c}=Wf(),{saveCellConfig:u}=mi(),d=l(ki),f=y(),p=n(),h=zp(),g=Si(),_=i(kt),{copyCells:v,pasteAtCell:b,cutCells:x}=Cp(),S=Ip(),C=Fp(e),w=eo(),T=Qn(),E=i(Ot),D;r[0]===E?D=r[1]:(D=jt(E),r[0]=E,r[1]=D);let O=D,ee;r[2]!==w||r[3]!==S?(ee={clear:()=>{w.clear(),S.clear()},extend:e=>{w.clear(),S.extend(e)},select:e=>{w.clear(),S.select(e)}},r[2]=w,r[3]=S,r[4]=ee):ee=r[4];let k=ee,te=i(Mt),ne;r[5]===te?ne=r[6]:(ne=(e,t)=>Lt(te.getHotkey(e).key)(t.nativeEvent||t),r[5]=te,r[6]=ne);let re=ne,A=Jp(e,o),j;r[7]!==f||r[8]!==O||r[9]!==a||r[10]!==s||r[11]!==e||r[12]!==v||r[13]!==x||r[14]!==T||r[15]!==o||r[16]!==C||r[17]!==re||r[18]!==_||r[19]!==b||r[20]!==w||r[21]!==g||r[22]!==u||r[23]!==c||r[24]!==k||r[25]!==d||r[26]!==p||r[27]!==h||r[28]!==E?(j={onKeyDown:t=>{if(cn.fromInput(t)){t.continuePropagation();return}let n={"Mod+ArrowUp":()=>(f.focusTopCell(),k.clear(),!0),"Mod+ArrowDown":()=>(f.focusBottomCell(),k.clear(),!0),ArrowUp:()=>(f.focusCell({cellId:e,where:`before`}),k.clear(),!0),ArrowDown:()=>(f.focusCell({cellId:e,where:`after`}),k.clear(),!0),ArrowLeft:()=>{if(a){let t=p.get(he),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r-1);if(i&&i.length>0){let t=em(e,i);return f.focusCell({cellId:t,where:`exact`}),k.clear(),!0}}return!1},ArrowRight:()=>{if(a){let t=p.get(he),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r+1);if(i&&i.length>0){let t=em(e,i);return f.focusCell({cellId:t,where:`exact`}),k.clear(),!0}}return!1},"Shift+ArrowUp":()=>{let t=p.get(Fe);k.extend({cellId:e,allCellIds:t});let n=t.findWithId(e).before(e);return n&&k.extend({cellId:n,allCellIds:t}),f.focusCell({cellId:e,where:`before`}),!0},"Shift+ArrowDown":()=>{let t=p.get(Fe);k.extend({cellId:e,allCellIds:t});let n=t.findWithId(e).after(e);return n&&k.extend({cellId:n,allCellIds:t}),f.focusCell({cellId:e,where:`after`}),!0},Escape:()=>p.get(at).size>0?(p.set(ze),!0):C?(k.clear(),!0):!1,Enter:()=>(h.add(e),ae(p,e),k.clear(),!0),s:()=>(c(),!0)};for(let[e,r]of Object.entries(n))if(Lt(e)(t)&&r()){t.preventDefault();return}let r={"cell.run":qp(e=>(g(e),!0)),"cell.runAndNewBelow":qp(e=>{g(e);let t=e[e.length-1];return f.moveToNextCell({cellId:t,before:!1}),!0}),"cell.runAndNewAbove":qp(e=>{g(e);let t=e[0];return f.moveToNextCell({cellId:t,before:!0}),!0}),"cell.createAbove":e=>(f.createNewCell({cellId:e,before:!0}),!0),"cell.createBelow":e=>(f.createNewCell({cellId:e,before:!1}),!0),"cell.moveUp":qp(e=>{let t=e[0];return p.get(he).cellIds.findWithId(t).first()!==t&&(e.forEach(e=>{f.moveCell({cellId:e,before:!0})}),!0)}),"cell.moveDown":qp(e=>{let t=e[e.length-1];return p.get(he).cellIds.findWithId(t).last()!==t&&(e.toReversed().forEach(e=>{f.moveCell({cellId:e,before:!1})}),!0)}),"cell.moveLeft":Kp(e=>a?(f.moveCell({cellId:e,direction:`left`}),!0):!1),"cell.moveRight":Kp(e=>a?(f.moveCell({cellId:e,direction:`right`}),!0):!1),"cell.hideCode":qp(e=>{let t=!e.map(e=>p.get(he).cellData[e]?.config||null).every(Qp);u({configs:Object.fromEntries(e.map(e=>[e,{hide_code:t}]))});for(let n of e)f.updateCellConfig({cellId:n,config:{hide_code:t}});if(e.length===1){let n=e[0];f.focusCell({cellId:n,where:`after`}),t?(o.current?.contentDOM.blur(),ie(n)):ae(p,n)}return!0}),"cell.focusDown":e=>(f.focusCell({cellId:e,where:`after`}),!0),"cell.focusUp":e=>(f.focusCell({cellId:e,where:`before`}),!0),"cell.sendToBottom":qp(e=>(e.forEach(e=>{f.sendToBottom({cellId:e})}),!0)),"cell.sendToTop":qp(e=>(e.toReversed().forEach(e=>{f.sendToTop({cellId:e})}),!0)),"cell.aiCompletion":e=>{if(!O)return!1;let t=!1;return d(n=>n?.cellId===e?(t=!0,null):{cellId:e}),t&&o.current?.focus(),!0},"cell.cellActions":()=>(s.current?.toggle(),!0),"command.copyCell":qp(e=>(v(e),!0)),"command.cutCell":qp(e=>(x(e),!0)),"command.pasteCell":e=>(b(e),!0),"command.createCellBefore":e=>!cn.hasModifier(t)&&(f.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),"command.createCellAfter":e=>!cn.hasModifier(t)&&(f.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"command.createSqlCellAfter":e=>!cn.hasModifier(t)&&(m({autoInstantiate:!0,createNewCell:f.createNewCell,fromCellId:e,before:!0}),f.createNewCell({cellId:e,before:!1,autoFocus:!0,code:P.sql.defaultCode}),!0),"cell.delete":()=>{if(!E.keymap.destructive_delete)return!1;let t=i.size>=2?[...i]:[e],n=p.get(he);return t.some(e=>{let{status:t}=n.cellRuntime[e];return t===`running`||t===`queued`})?!1:w.idle?(w.submit(t),!0):(T({cellIds:t}),w.clear(),!0)}},i=Lp(p);if(_===`vim`&&Gp(t.nativeEvent||t,{j:n.ArrowDown,k:n.ArrowUp,h:n.ArrowLeft,l:n.ArrowRight,i:n.Enter,"shift+j":n[`Shift+ArrowDown`],"shift+k":n[`Shift+ArrowUp`],"g g":n[`Mod+ArrowUp`],"shift+g":n[`Mod+ArrowDown`],"d d":()=>r[`cell.delete`](),"y y":()=>(v(i.size>=2?[...i]:[e]),!0),p:()=>(b(e,{before:!1}),!0),"shift+p":()=>(b(e,{before:!0}),!0),o:()=>(f.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"shift+o":()=>(f.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),u:()=>(f.undoDeleteCell(),!0)})){t.preventDefault();return}for(let[n,a]of Object.entries(r))if(re(n,t)){if(typeof a==`function`){if(a(e)){t.preventDefault();return}}else if(i.size>=2?a.bulkHandle([...i]):a.handle(e)){t.preventDefault();return}return}t.continuePropagation()}},r[7]=f,r[8]=O,r[9]=a,r[10]=s,r[11]=e,r[12]=v,r[13]=x,r[14]=T,r[15]=o,r[16]=C,r[17]=re,r[18]=_,r[19]=b,r[20]=w,r[21]=g,r[22]=u,r[23]=c,r[24]=k,r[25]=d,r[26]=p,r[27]=h,r[28]=E,r[29]=j):j=r[29];let{keyboardProps:M}=tr(j),N;return r[30]!==A||r[31]!==C||r[32]!==M?(N=rr(A,M,{"data-selected":C,className:`data-[selected=true]:ring-1 data-[selected=true]:ring-(--blue-8) data-[selected=true]:ring-offset-1`}),r[30]=A,r[31]=C,r[32]=M,r[33]=N):N=r[33],N}function Qp(e){return e?.hide_code}function $p(e,t){let n=(0,H.c)(12),r=zp(),a=i(kt),o=i(Mt),s;if(n[0]!==o){let e=o.getHotkey(`command.vimEnterCommandMode`);s=Lt(e.key),n[0]=o,n[1]=s}else s=n[1];let c=s,l;n[2]!==e||n[3]!==r?(l=()=>{r.remove(e),ie(e),T(()=>{N(e)})},n[2]=e,n[3]=r,n[4]=l):l=n[4];let u=l,d;n[5]!==t||n[6]!==u?(d=()=>{if(!t.current){u();return}let e=t.current,n=e.state;if(qr(e))return;let r=!!n.field(ft,!1)||!!n.field(Se,!1),i=li(n)!==null;r&&tm(e),i&&di(e),!(r||i)&&u()},n[5]=t,n[6]=u,n[7]=d):d=n[7];let f=d,p;n[8]!==f||n[9]!==a||n[10]!==c?(p={onKeyDown:e=>{a===`vim`?c(e)&&f():e.key===`Escape`&&f(),e.continuePropagation()}},n[8]=f,n[9]=a,n[10]=c,n[11]=p):p=n[11];let{keyboardProps:m}=tr(p);return m}function em(e,t){let n=document.getElementById(mt.create(e));if(!n)return t.first();let r=n.getBoundingClientRect();for(let e of t.topLevelIds){let t=document.getElementById(mt.create(e));if(t){let n=t.getBoundingClientRect();if(r.top<=n.bottom&&r.bottom>=n.top)return e}}return t.last()}function tm(e){e.state.field(ft,!1)&&e.dispatch({effects:ge.of(null)}),et(e)}var nm=50,rm=4,im=60;function am(e){return Math.min(im,Math.max(rm,e))}var om=e=>{let t=(0,H.c)(13),{code:n,className:r}=e,i,a,o,s;if(t[0]!==r||t[1]!==n){let e=n.split(`
|
|
21
|
-
`,nm);t[6]===r?i=t[7]:(i
|
|
20
|
+
`)}async function Sp(e){let t={cells:e.map(e=>({code:e.code,name:e.name,config:e.config})),version:`1.0`},n=new Op().add(yp,t).add(`text/plain`,xp(e)).build();await navigator.clipboard.write([n])}function Cp(){let e=(0,H.c)(13),t=y(),n=Te(),r=qe(),i;e[0]===n?i=e[1]:(i=async e=>{let t=Me(),r=e.map(e=>t.cellData[e]).filter(Boolean);if(r.length!==0)try{await Sp(r),n.clear(),wp(r.length)}catch(e){let t=e;It.error(`Failed to copy cells to clipboard`,t);try{await lr(xp(r)),n.clear(),wp(r.length)}catch{Tp()}}},e[0]=n,e[1]=i);let a=c(i),o;e[2]===n?o=e[3]:(o=async e=>{let t=Me(),r=e.filter(e=>t.cellData[e]),i=r.map(e=>t.cellData[e]);if(i.length!==0)try{await Sp(i),n.markForCut({cellIds:r})}catch(e){let t=e;It.error(`Failed to cut cells to clipboard`,t);try{await lr(xp(i)),n.markForCut({cellIds:r})}catch{Tp()}}},e[2]=n,e[3]=o);let s=c(o),l;e[4]!==t||e[5]!==n||e[6]!==r.cellIds?(l=async(e,i)=>{let{before:a}=i??{},o=a!==void 0&&a;if(r.cellIds.size>0){let i=[...r.cellIds],a=Me(),s=i.map(e=>{let t=a.cellIds.findWithId(e);return{columnId:t.id,index:t.indexOfOrThrow(e)}});t.moveCellsRelativeTo({cellIds:i,targetCellId:e,position:o?`before`:`after`,previousPlacements:s}),n.clear();return}try{let n=await navigator.clipboard.read();for(let r of n)if(r.types.includes(yp)){let n=await(await r.getType(yp)).text();try{let r=bp.parse(JSON.parse(n));if(r.cells.length===0)break;let i=e,a=r.cells.toReversed();for(let e of a)t.createNewCell({cellId:i,before:o,code:e.code,name:e.name,config:e.config,hideCode:e.config?.hide_code,autoFocus:!0});return}catch(e){let t=e;It.warn(`Failed to parse clipboard cell data`,t)}}let r=await navigator.clipboard.readText();r.trim()?t.createNewCell({cellId:e,before:o,code:r,autoFocus:!0}):Ep()}catch(e){let t=e;It.error(`Failed to paste from clipboard`,t),Dp()}},e[4]=t,e[5]=n,e[6]=r.cellIds,e[7]=l):l=e[7];let u=c(l),d;return e[8]!==a||e[9]!==s||e[10]!==u||e[11]!==n.clear?(d={copyCells:a,cutCells:s,pasteAtCell:u,clearPendingCut:n.clear},e[8]=a,e[9]=s,e[10]=u,e[11]=n.clear,e[12]=d):d=e[12],d}var wp=e=>{let t=e===1?`Cell`:`${e} cells`;ur({title:`${t} copied`,description:`${t} ${e===1?`has`:`have`} been copied to clipboard.`})},Tp=()=>{ur({title:`Copy failed`,description:`Failed to copy cells to clipboard.`,variant:`danger`})},Ep=()=>{ur({title:`Nothing to paste`,description:`No cell or text found in clipboard.`,variant:`danger`})},Dp=()=>{ur({title:`Paste failed`,description:`Failed to read from clipboard`,variant:`danger`})},Op=class{items={};add(e,t){return ClipboardItem.supports(e)?typeof t==`string`?(this.items[e]=new Blob([t],{type:e}),this):(this.items[e]=new Blob([JSON.stringify(t)],{type:e}),this):(It.warn(`ClipboardItem does not support ${e}`),this)}build(){return new ClipboardItem(this.items)}};function kp(){return{selectionStart:null,selectionEnd:null,selected:new Set}}var{reducer:Ap,createActions:jp,valueAtom:Mp,useActions:Np}=ii(kp,{select:(e,t)=>({selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])}),extend:(e,t)=>{if(!e.selectionStart)return{selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])};let{cellId:n,allCellIds:r}=t;try{let t=r.findWithId(e.selectionStart),i=t.indexOfOrThrow(e.selectionStart),a=t.indexOfOrThrow(n),[o,s]=i<a?[i,a]:[a,i],c=t.slice(o,s+1);return{selectionStart:e.selectionStart,selectionEnd:n,selected:new Set(c)}}catch{return{selectionStart:n,selectionEnd:n,selected:new Set([n])}}},clear:e=>e.selected.size===0?e:kp()}),Pp=()=>i(Mp);function Fp(e){let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=r(t=>t(Mp).selected.has(e)),t[0]=e,t[1]=n),i(n)}function Ip(){return Np()}function Lp(e){return e.get(Mp).selected}var{valueAtom:Rp,useActions:zp}=ii(()=>new Set,{add:(e,t)=>{if(e.has(t))return e;let n=new Set(e);return n.add(t),n},remove:(e,t)=>{if(!e.has(t))return e;let n=new Set(e);return n.delete(t),T(()=>{let e=document.activeElement;if(!e)return;let t=mt.findElementThroughShadowDOMs(e);t&&N(mt.parse(t.id))}),n}}),Bp=e=>r(t=>t(Rp).has(e));function Vp(e){let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=Bp(e),t[0]=e,t[1]=n),i(n)}var Hp=new WeakMap,Up=500;function Wp(e){if(e.ctrlKey||e.metaKey||e.altKey)return``;let t=e.key.toLowerCase();return e.shiftKey?`shift+${t}`:t}function Gp(e,t){let n=Wp(e),r=e.target;if(!n||!r)return!1;let i=Hp.get(r),a=n;i?.timeout&&clearTimeout(i.timeout),i&&(a=`${i.sequence} ${n}`);let o=t[a];if(o)return Hp.delete(r),o();if(!i){let e=t[n];if(e)return e()}if(Object.keys(t).some(e=>e.startsWith(`${a} `))){let e=window.setTimeout(()=>{Hp.delete(r)},Up);return Hp.set(r,{sequence:a,timeout:e}),!0}return Hp.delete(r),!1}function Kp(e){return{handle:t=>e(t),bulkHandle:t=>{let n=!0;try{for(let r of t)n&&=e(r);return n}catch{return!1}}}}function qp(e){return{handle:t=>e([t]),bulkHandle:t=>e(t)}}function Jp(e,t){let n=(0,H.c)(12),r=D(),i=y(),a=zp(),o;n[0]!==e||n[1]!==r?(o=()=>{r.focusCell({cellId:e})},n[0]=e,n[1]=r,n[2]=o):o=n[2];let s;n[3]!==i||n[4]!==e||n[5]!==t||n[6]!==r||n[7]!==a?(s=n=>{Yp(n.relatedTarget)||Yp(n.target)||Xp(n.relatedTarget)!==e&&Xp(n.relatedTarget?.closest(`[data-for-cell-id]`))!==e&&(a.remove(e),i.markTouched({cellId:e}),r.blurCell(),t.current&&tm(t.current))},n[3]=i,n[4]=e,n[5]=t,n[6]=r,n[7]=a,n[8]=s):s=n[8];let c;n[9]!==o||n[10]!==s?(c={onFocusWithin:o,onBlurWithin:s},n[9]=o,n[10]=s,n[11]=c):c=n[11];let{focusWithinProps:l}=rr(c);return l}function Yp(e){return e?e instanceof HTMLElement&&e.closest(`.cm-vim-panel`)!==null:!1}function Xp(e){return e&&e.getAttribute(ee)||null}function Zp(e,t){let r=(0,H.c)(34),{canMoveX:a,editorView:o,cellActionDropdownRef:s}=t,{saveOrNameNotebook:c}=Wf(),{saveCellConfig:u}=hi(),d=l(ki),f=y(),p=n(),h=zp(),g=Ci(),_=i(kt),{copyCells:v,pasteAtCell:b,cutCells:x}=Cp(),S=Ip(),C=Fp(e),w=eo(),T=$n(),E=i(Ot),D;r[0]===E?D=r[1]:(D=jt(E),r[0]=E,r[1]=D);let O=D,ee;r[2]!==w||r[3]!==S?(ee={clear:()=>{w.clear(),S.clear()},extend:e=>{w.clear(),S.extend(e)},select:e=>{w.clear(),S.select(e)}},r[2]=w,r[3]=S,r[4]=ee):ee=r[4];let k=ee,te=i(Mt),ne;r[5]===te?ne=r[6]:(ne=(e,t)=>Lt(te.getHotkey(e).key)(t.nativeEvent||t),r[5]=te,r[6]=ne);let re=ne,A=Jp(e,o),j;r[7]!==f||r[8]!==O||r[9]!==a||r[10]!==s||r[11]!==e||r[12]!==v||r[13]!==x||r[14]!==T||r[15]!==o||r[16]!==C||r[17]!==re||r[18]!==_||r[19]!==b||r[20]!==w||r[21]!==g||r[22]!==u||r[23]!==c||r[24]!==k||r[25]!==d||r[26]!==p||r[27]!==h||r[28]!==E?(j={onKeyDown:t=>{if(ln.fromInput(t)){t.continuePropagation();return}let n={"Mod+ArrowUp":()=>(f.focusTopCell(),k.clear(),!0),"Mod+ArrowDown":()=>(f.focusBottomCell(),k.clear(),!0),ArrowUp:()=>(f.focusCell({cellId:e,where:`before`}),k.clear(),!0),ArrowDown:()=>(f.focusCell({cellId:e,where:`after`}),k.clear(),!0),ArrowLeft:()=>{if(a){let t=p.get(he),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r-1);if(i&&i.length>0){let t=em(e,i);return f.focusCell({cellId:t,where:`exact`}),k.clear(),!0}}return!1},ArrowRight:()=>{if(a){let t=p.get(he),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r+1);if(i&&i.length>0){let t=em(e,i);return f.focusCell({cellId:t,where:`exact`}),k.clear(),!0}}return!1},"Shift+ArrowUp":()=>{let t=p.get(Fe);k.extend({cellId:e,allCellIds:t});let n=t.findWithId(e).before(e);return n&&k.extend({cellId:n,allCellIds:t}),f.focusCell({cellId:e,where:`before`}),!0},"Shift+ArrowDown":()=>{let t=p.get(Fe);k.extend({cellId:e,allCellIds:t});let n=t.findWithId(e).after(e);return n&&k.extend({cellId:n,allCellIds:t}),f.focusCell({cellId:e,where:`after`}),!0},Escape:()=>p.get(at).size>0?(p.set(ze),!0):C?(k.clear(),!0):!1,Enter:()=>(h.add(e),ae(p,e),k.clear(),!0),s:()=>(c(),!0)};for(let[e,r]of Object.entries(n))if(Lt(e)(t)&&r()){t.preventDefault();return}let r={"cell.run":qp(e=>(g(e),!0)),"cell.runAndNewBelow":qp(e=>{g(e);let t=e[e.length-1];return f.moveToNextCell({cellId:t,before:!1}),!0}),"cell.runAndNewAbove":qp(e=>{g(e);let t=e[0];return f.moveToNextCell({cellId:t,before:!0}),!0}),"cell.createAbove":e=>(f.createNewCell({cellId:e,before:!0}),!0),"cell.createBelow":e=>(f.createNewCell({cellId:e,before:!1}),!0),"cell.moveUp":qp(e=>{let t=e[0];return p.get(he).cellIds.findWithId(t).first()!==t&&(e.forEach(e=>{f.moveCell({cellId:e,before:!0})}),!0)}),"cell.moveDown":qp(e=>{let t=e[e.length-1];return p.get(he).cellIds.findWithId(t).last()!==t&&(e.toReversed().forEach(e=>{f.moveCell({cellId:e,before:!1})}),!0)}),"cell.moveLeft":Kp(e=>a?(f.moveCell({cellId:e,direction:`left`}),!0):!1),"cell.moveRight":Kp(e=>a?(f.moveCell({cellId:e,direction:`right`}),!0):!1),"cell.hideCode":qp(e=>{let t=!e.map(e=>p.get(he).cellData[e]?.config||null).every(Qp);u({configs:Object.fromEntries(e.map(e=>[e,{hide_code:t}]))});for(let n of e)f.updateCellConfig({cellId:n,config:{hide_code:t}});if(e.length===1){let n=e[0];f.focusCell({cellId:n,where:`after`}),t?(o.current?.contentDOM.blur(),ie(n)):ae(p,n)}return!0}),"cell.focusDown":e=>(f.focusCell({cellId:e,where:`after`}),!0),"cell.focusUp":e=>(f.focusCell({cellId:e,where:`before`}),!0),"cell.sendToBottom":qp(e=>(e.forEach(e=>{f.sendToBottom({cellId:e})}),!0)),"cell.sendToTop":qp(e=>(e.toReversed().forEach(e=>{f.sendToTop({cellId:e})}),!0)),"cell.aiCompletion":e=>{if(!O)return!1;let t=!1;return d(n=>n?.cellId===e?(t=!0,null):{cellId:e}),t&&o.current?.focus(),!0},"cell.cellActions":()=>(s.current?.toggle(),!0),"command.copyCell":qp(e=>(v(e),!0)),"command.cutCell":qp(e=>(x(e),!0)),"command.pasteCell":e=>(b(e),!0),"command.createCellBefore":e=>!ln.hasModifier(t)&&(f.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),"command.createCellAfter":e=>!ln.hasModifier(t)&&(f.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"command.createSqlCellAfter":e=>!ln.hasModifier(t)&&(m({autoInstantiate:!0,createNewCell:f.createNewCell,fromCellId:e,before:!0}),f.createNewCell({cellId:e,before:!1,autoFocus:!0,code:P.sql.defaultCode}),!0),"cell.delete":()=>{if(!E.keymap.destructive_delete)return!1;let t=i.size>=2?[...i]:[e],n=p.get(he);return t.some(e=>{let{status:t}=n.cellRuntime[e];return t===`running`||t===`queued`})?!1:w.idle?(w.submit(t),!0):(T({cellIds:t}),w.clear(),!0)}},i=Lp(p);if(_===`vim`&&Gp(t.nativeEvent||t,{j:n.ArrowDown,k:n.ArrowUp,h:n.ArrowLeft,l:n.ArrowRight,i:n.Enter,"shift+j":n[`Shift+ArrowDown`],"shift+k":n[`Shift+ArrowUp`],"g g":n[`Mod+ArrowUp`],"shift+g":n[`Mod+ArrowDown`],"d d":()=>r[`cell.delete`](),"y y":()=>(v(i.size>=2?[...i]:[e]),!0),p:()=>(b(e,{before:!1}),!0),"shift+p":()=>(b(e,{before:!0}),!0),o:()=>(f.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"shift+o":()=>(f.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),u:()=>(f.undoDeleteCell(),!0)})){t.preventDefault();return}for(let[n,a]of Object.entries(r))if(re(n,t)){if(typeof a==`function`){if(a(e)){t.preventDefault();return}}else if(i.size>=2?a.bulkHandle([...i]):a.handle(e)){t.preventDefault();return}return}t.continuePropagation()}},r[7]=f,r[8]=O,r[9]=a,r[10]=s,r[11]=e,r[12]=v,r[13]=x,r[14]=T,r[15]=o,r[16]=C,r[17]=re,r[18]=_,r[19]=b,r[20]=w,r[21]=g,r[22]=u,r[23]=c,r[24]=k,r[25]=d,r[26]=p,r[27]=h,r[28]=E,r[29]=j):j=r[29];let{keyboardProps:M}=nr(j),N;return r[30]!==A||r[31]!==C||r[32]!==M?(N=ir(A,M,{"data-selected":C,className:`data-[selected=true]:ring-1 data-[selected=true]:ring-(--blue-8) data-[selected=true]:ring-offset-1`}),r[30]=A,r[31]=C,r[32]=M,r[33]=N):N=r[33],N}function Qp(e){return e?.hide_code}function $p(e,t){let n=(0,H.c)(12),r=zp(),a=i(kt),o=i(Mt),s;if(n[0]!==o){let e=o.getHotkey(`command.vimEnterCommandMode`);s=Lt(e.key),n[0]=o,n[1]=s}else s=n[1];let c=s,l;n[2]!==e||n[3]!==r?(l=()=>{r.remove(e),ie(e),T(()=>{N(e)})},n[2]=e,n[3]=r,n[4]=l):l=n[4];let u=l,d;n[5]!==t||n[6]!==u?(d=()=>{if(!t.current){u();return}let e=t.current,n=e.state;if(Jr(e))return;let r=!!n.field(ft,!1)||!!n.field(Se,!1),i=ui(n)!==null;r&&tm(e),i&&fi(e),!(r||i)&&u()},n[5]=t,n[6]=u,n[7]=d):d=n[7];let f=d,p;n[8]!==f||n[9]!==a||n[10]!==c?(p={onKeyDown:e=>{a===`vim`?c(e)&&f():e.key===`Escape`&&f(),e.continuePropagation()}},n[8]=f,n[9]=a,n[10]=c,n[11]=p):p=n[11];let{keyboardProps:m}=nr(p);return m}function em(e,t){let n=document.getElementById(mt.create(e));if(!n)return t.first();let r=n.getBoundingClientRect();for(let e of t.topLevelIds){let t=document.getElementById(mt.create(e));if(t){let n=t.getBoundingClientRect();if(r.top<=n.bottom&&r.bottom>=n.top)return e}}return t.last()}function tm(e){e.state.field(ft,!1)&&e.dispatch({effects:ge.of(null)}),et(e)}var nm=50,rm=4,im=60;function am(e){return Math.min(im,Math.max(rm,e))}var om=e=>{let t=(0,H.c)(13),{code:n,className:r}=e,i,a,o,s;if(t[0]!==r||t[1]!==n){let e=n.split(`
|
|
21
|
+
`,nm);t[6]===r?i=t[7]:(i=en(`cm`,`mo-code-placeholder`,r),t[6]=r,t[7]=i),a=`cell-editor-placeholder`,o=!0,s=e.map(sm),t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s}else i=t[2],a=t[3],o=t[4],s=t[5];let c;return t[8]!==i||t[9]!==a||t[10]!==o||t[11]!==s?(c=(0,U.jsx)(`div`,{className:i,"data-testid":a,"aria-hidden":o,children:s}),t[8]=i,t[9]=a,t[10]=o,t[11]=s,t[12]=c):c=t[12],c};function sm(e,t){let n=e.trimEnd().length;return(0,U.jsx)(`div`,{className:`mo-code-placeholder-line`,children:n>0&&(0,U.jsx)(Li,{className:`mo-code-placeholder-bar`,style:{width:`${am(n)}ch`}})},t)}var cm=e=>{let t=(0,H.c)(25),{editorView:n,code:r,currentLanguageAdapter:i,onAfterToggle:a,className:o}=e,s=o===void 0?`absolute right-3 top-2 z-20 flex hover-action gap-1`:o,c;t[0]===r?c=t[1]:(c=P.markdown.isSupported(r)||r.trim()===``,t[0]=r,t[1]=c);let l=c,u;t[2]===r?u=t[3]:(u=P.sql.isSupported(r)||r.trim()===``,t[2]=r,t[3]=u);let d=u&&i===`python`,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,U.jsx)(fn,{color:`var(--sky-11)`,strokeWidth:2.5,className:`w-4 h-4`}),t[4]=f):f=t[4];let p;t[5]!==i||t[6]!==n||t[7]!==a||t[8]!==d?(p=(0,U.jsx)(lm,{editorView:n,currentLanguageAdapter:i,canSwitchToLanguage:d,icon:f,toType:`sql`,displayName:`SQL`,onAfterToggle:a}),t[5]=i,t[6]=n,t[7]=a,t[8]=d,t[9]=p):p=t[9];let m=l&&i===`python`,h;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(Pi,{fill:`var(--sky-11)`,color:`black`,className:`w-4 h-4`}),t[10]=h):h=t[10];let g;t[11]!==i||t[12]!==n||t[13]!==a||t[14]!==m?(g=(0,U.jsx)(lm,{editorView:n,currentLanguageAdapter:i,canSwitchToLanguage:m,icon:h,toType:`markdown`,displayName:`Markdown`,onAfterToggle:a}),t[11]=i,t[12]=n,t[13]=a,t[14]=m,t[15]=g):g=t[15];let _;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,U.jsx)(Ni,{fill:`var(--sky-11)`,color:`black`,className:`w-4 h-4`}),t[16]=_):_=t[16];let v;t[17]!==i||t[18]!==n?(v=(0,U.jsx)(lm,{editorView:n,currentLanguageAdapter:i,canSwitchToLanguage:!0,icon:_,toType:`python`,displayName:`Python`,onAfterToggle:Pt.NOOP}),t[17]=i,t[18]=n,t[19]=v):v=t[19];let y;return t[20]!==s||t[21]!==v||t[22]!==p||t[23]!==g?(y=(0,U.jsxs)(`div`,{className:s,children:[p,g,v]}),t[20]=s,t[21]=v,t[22]=p,t[23]=g,t[24]=y):y=t[24],y},lm=e=>{let t=(0,H.c)(10),{editorView:n,currentLanguageAdapter:r,canSwitchToLanguage:i,icon:a,toType:o,displayName:s,onAfterToggle:c}=e,l;t[0]!==n||t[1]!==c||t[2]!==o?(l=()=>{n&&(lt(n,{language:o}),c())},t[0]=n,t[1]=c,t[2]=o,t[3]=l):l=t[3];let u=l;if(!i||r===o)return null;let d=`View as ${s}`,f;t[4]!==u||t[5]!==a?(f=(0,U.jsx)(un,{"data-testid":`language-toggle-button`,variant:`text`,size:`xs`,className:`opacity-80 px-1`,onClick:u,children:a}),t[4]=u,t[5]=a,t[6]=f):f=t[6];let p;return t[7]!==d||t[8]!==f?(p=(0,U.jsx)(cn,{content:d,children:f}),t[7]=d,t[8]=f,t[9]=p):p=t[9],p};function um(e,t,n){return n?{code:n.code,extensions:[...t,n.extension]}:{code:e,extensions:t}}var dm=({theme:e,showPlaceholder:n,id:r,config:a,code:o,status:s,serializedEditorState:l,setEditorView:u,runCell:d,userConfig:f,editorViewRef:p,editorViewParentRef:h,hidden:g,hasOutput:v,showHiddenCode:b,languageAdapter:x,setLanguageAdapter:S,showLanguageToggles:C=!0,inlineAiTooltip:w,outputArea:T,tooltipParentSelector:E})=>{let[D,O]=t(ki),ee=er(),{saveOrNameNotebook:k}=Wf(),te=eo(),{saveCellConfig:ne}=hi(),re=s===`running`||s===`queued`,A=y(),j=Bi(),ie=x===`markdown`,M=c(()=>re?!1:te.idle&&f.keymap.destructive_delete?(te.submit([r]),!0):(ee({cellId:r}),!0)),N=c(()=>!re&&(d(),p.current&&tm(p.current),!0)),P=c(()=>{let e=!a.hide_code;return ne({configs:{[r]:{hide_code:e}}}),A.updateCellConfig({cellId:r,config:{hide_code:e}}),e}),ae=i(Nt),oe=i(yn),se=c(()=>{m({autoInstantiate:ae,createNewCell:A.createNewCell}),a.hide_code||(ne({configs:{[r]:{hide_code:!0}}}),A.updateCellConfig({cellId:r,config:{hide_code:!0}}),A.markUntouched({cellId:r}))}),ce=c(()=>{m({autoInstantiate:ae,createNewCell:A.createNewCell})}),le=jt(f),ue=(0,V.useMemo)(()=>{let t=Hd({cellId:r,showPlaceholder:n,enableAI:le,cellActions:{...A,afterToggleMarkdown:se,afterToggleSQL:ce,onRun:N,deleteCell:M,saveNotebook:k,createManyBelow:e=>{for(let t of e.toReversed())A.createNewCell({code:t,before:!1,cellId:r,skipIfCodeExists:!0})},addOrAppendSetupCell:e=>{let t=Me();if(!t.cellIds.setupCellExists()){A.addSetupCellIfDoesntExist({code:e});return}let n=Qe(t)[_],r=n?we(n):t.cellData[_].code,i=r.trim()?`${r.trimEnd()}\n\n${e}`:e;n&&Oe(n,i),A.updateCellCode({cellId:_,code:i,formattingChange:!1})},splitCell:j,toggleHideCode:P,aiCellCompletion:()=>{if(!le)return!1;let e=!1;return O(t=>t?.cellId===r?(e=!0,null):{cellId:r}),e}},completionConfig:f.completion,acceptCompletionOnEnter:oe,keymapConfig:f.keymap,lspConfig:f.language_servers,theme:e,hotkeys:new Ft(f.keymap.overrides??{}),diagnosticsConfig:f.diagnostics,displayConfig:f.display,inlineAiTooltip:w??f.ai?.inline_tooltip??!1,tooltipParentSelector:E});return t.push(Hr.define(e=>(S(e.state.field(Pe).type),{update(e){S(e.state.field(Pe).type)}})),R.updateListener.of(e=>{e.selectionSet&&e.state.selection.ranges.some(e=>e.from!==e.to)&&b({focus:!1})}),R.domEventHandlers({focus:()=>{b({focus:!1})}})),t},[r,oe,f.keymap,f.completion,f.language_servers,f.display,f.diagnostics,f.ai?.inline_tooltip,w,E,le,e,n,A,j,P,M,N,O,se,ce,S,b,k]),de=me()&&Ie(r),fe=e=>{if(!de)return um(o,ue,void 0);let t=wf(r,e=>{A.updateCellCode({cellId:r,code:e,formattingChange:!0})},e);return um(o,ue,t)},pe=c(()=>{let e=fe(o),t=new R({state:vr.create({doc:e.code,extensions:e.extensions})});u(t),de||lt(t,{language:He(t.state).type})}),he=c(()=>{zt(p.current!==null,`Editor view is not initialized`);let e=fe();p.current.dispatch({effects:[I.reconfigure.of([e.extensions]),je(p.current,{completionConfig:f.completion,hotkeysProvider:new Ft(f.keymap.overrides??{}),lspConfig:{...f.language_servers,diagnostics:f.diagnostics}})]})}),ge=c(()=>{zt(l,`Editor view is not initialized`);let e=fe(o),t=new R({state:vr.fromJSON(l,{doc:e.code,extensions:e.extensions},{history:Kr})});de||lt(t,{language:He(t.state).type}),u(t),A.clearSerializedEditorState({cellId:r})}),[_e,ve]=(0,V.useState)(l!==null);(0,V.useEffect)(()=>{if(p.current!==null){ve(!0);return}if(ve(!1),l!==null){ge(),ve(!0);return}return ut.request(r,()=>{p.current===null&&(pe(),ve(!0))}),()=>ut.cancel(r)},[r,p,ge,pe,l]),(0,V.useEffect)(()=>{p.current!==null&&he()},[he,ue,p]),(0,V.useEffect)(()=>()=>{p.current?.destroy(),p.current=null},[p]);let[ye,be]=nn({rootMargin:`300px 0px`,threshold:0});(0,V.useEffect)(()=>{_e||(be?.isIntersecting?ut.prioritize(r):ut.deprioritize(r))},[_e,be?.isIntersecting,r]);let xe=$p(r,p),Se=``;return ie&&g&&v?Se=`h-0 overflow-hidden`:g&&(Se=`opacity-20 h-8 [&>div.cm-editor]:h-full [&>div.cm-editor]:overflow-hidden [&_.cm-panels]:hidden`),(0,U.jsx)(_p,{cellId:r,aiCompletionCell:D,currentCode:p.current?.state.doc.toString()??o,currentLanguageAdapter:x,declineChange:c(()=>{O(null),p.current?.focus()}),onChange:c(e=>{p.current?.dispatch({changes:{from:0,to:p.current.state.doc.length,insert:e}})}),acceptChange:c(e=>{p.current?.dispatch({changes:{from:0,to:p.current.state.doc.length,insert:e}}),p.current?.focus(),O(null)}),runCell:N,outputArea:T,children:(0,U.jsxs)(`div`,{className:`relative w-full`,ref:ye,...xe,children:[_e?(0,U.jsx)(fm,{className:Se,editorView:p.current,ref:h,hidden:g,showHiddenCode:b}):(0,U.jsx)(om,{code:o,className:Se}),!g&&C&&(0,U.jsx)(`div`,{className:`absolute top-1 right-5`,children:(0,U.jsx)(cm,{code:o,editorView:p.current,currentLanguageAdapter:x,onAfterToggle:se})})]})})},fm=V.forwardRef((e,t)=>{let n=(0,H.c)(14),{className:r,editorView:i,hidden:a,showHiddenCode:o}=e,s=(0,V.useRef)(null),c,l;n[0]===i?(c=n[1],l=n[2]):(c=()=>{i!==null&&s.current!==null&&s.current.children.length===0&&s.current.append(i.dom)},l=[i,s],n[0]=i,n[1]=c,n[2]=l),(0,V.useEffect)(c,l);let u;n[3]===r?u=n[4]:(u=en(`cm mathjax_ignore`,r),n[3]=r,n[4]=u);let d;n[5]!==a||n[6]!==o?(d=e=>{a&&o&&(e.stopPropagation(),o({focus:!0}))},n[5]=a,n[6]=o,n[7]=d):d=n[7];let f;n[8]===t?f=n[9]:(f=e=>{t?$f(t,s)(e):$f(s)(e)},n[8]=t,n[9]=f);let p;return n[10]!==u||n[11]!==d||n[12]!==f?(p=(0,U.jsx)(`div`,{className:u,onDoubleClick:d,ref:f,"data-testid":`cell-editor`}),n[10]=u,n[11]=d,n[12]=f,n[13]=p):p=n[13],p});fm.displayName=`CellCodeMirrorEditor`;function pm(e){let n=n=>{let r=(0,H.c)(5),a=i(Jt),[o,s]=t(xf);if(me()&&Ie(n.id)&&(Xt(a.state)||o===void 0)){let e;r[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,U.jsx)(`span`,{children:`Waiting for real-time collaboration connection...`}),r[0]=e):e=r[0];let t;return r[1]===s?t=r[2]:(t=(0,U.jsx)(`div`,{className:`flex h-full w-full items-baseline p-4`,children:(0,U.jsxs)(rn,{milliseconds:1e3,fallback:null,children:[e,(0,U.jsx)(un,{variant:`link`,onClick:()=>{s(`disabled`)},children:`Turn off real-time collaboration`})]})}),r[1]=s,r[2]=t),t}let c;return r[3]===n?c=r[4]:(c=(0,U.jsx)(e,{...n}),r[3]=n,r[4]=c),c};return n.displayName=`WithWaitUntilConnected(${e.displayName})`,n}var mm=me()?pm((0,V.memo)(dm)):(0,V.memo)(dm);export{pd as _,zp as a,eo as b,$f as c,If as d,kf as f,fd as g,gd as h,Vp as i,Uf as l,_d as m,cm as n,Ip as o,xf as p,Zp as r,Pp as s,mm as t,Wf as u,dd as v,to as y};
|