@marimo-team/frontend 0.24.3-dev4 → 0.24.3-dev9
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-0QNZS4By.js → CellStatus-DXkwkuL9.js} +1 -1
- package/dist/assets/{ConnectedDataExplorerComponent-DW6cJ-Lr.js → ConnectedDataExplorerComponent-DiXd-oqU.js} +1 -1
- package/dist/assets/{JsonOutput-D2ZWLZs4.js → JsonOutput-izmGhjov.js} +9 -9
- package/dist/assets/LazyAnyLanguageCodeMirror-C_cwGmDg.js +2 -0
- package/dist/assets/{MarimoErrorOutput-BlmIJ9WY.js → MarimoErrorOutput-CdmP3ZHL.js} +2 -2
- package/dist/assets/{RenderHTML-DnPB4qpJ.js → RenderHTML-DlYXvh8D.js} +1 -1
- package/dist/assets/{RunButton-C7TxE07w.js → RunButton-Bieadi9w.js} +1 -1
- package/dist/assets/add-cell-with-ai-ZpV9L4qe.js +76 -0
- package/dist/assets/{add-connection-dialog-MTOC2ycO.js → add-connection-dialog-a8mkIeXa.js} +3 -3
- package/dist/assets/agent-panel-rVtDSi07.js +286 -0
- package/dist/assets/{ai-model-dropdown-CmJEEhSC.js → ai-model-dropdown-C8IztRe2.js} +3 -3
- package/dist/assets/{any-language-editor-DflLjPSQ.js → any-language-editor-pGZDaSqz.js} +1 -1
- package/dist/assets/{app-config-button-W8Pytgb5.js → app-config-button-DLr-6jwI.js} +1 -1
- package/dist/assets/{blob-BrVH7IJp.js → blob-B2Qs47Zi.js} +1 -1
- package/dist/assets/{cell-editor-C7IiingQ.js → cell-editor-3VpJI5EQ.js} +9 -9
- package/dist/assets/cell-link-DEXHmwy1.js +1 -0
- package/dist/assets/{cells-BBhW3FXj.js → cells--Hh9voS5.js} +25 -25
- package/dist/assets/chat-display-DtQ0tOGK.js +1 -0
- package/dist/assets/{chat-panel-CK3X_KPy.js → chat-panel-DLgUUTdo.js} +1 -1
- package/dist/assets/{chat-ui-BJwtx1SR.js → chat-ui-DIXDoCsM.js} +3 -3
- package/dist/assets/{column-preview-Coa5PyHk.js → column-preview-H8rmRiii.js} +1 -1
- package/dist/assets/{command-palette-_xpwMniA.js → command-palette-Pmg3QxZ0.js} +1 -1
- package/dist/assets/{common-KqtqJsml.js → common-CrhvbKbI.js} +1 -1
- package/dist/assets/components-DWwMSfV5.js +1 -0
- package/dist/assets/components-rCVlCccf.js +1 -0
- package/dist/assets/{config-BlNM0caL.js → config-BuGkUPaK.js} +1 -1
- package/dist/assets/{copy-icon-z8fuTE3w.js → copy-icon-BUOcnUgJ.js} +1 -1
- package/dist/assets/{datasource-B3qF2oaW.js → datasource-DgkQfSw3.js} +2 -2
- package/dist/assets/{dependency-graph-panel-Av1CMZ61.js → dependency-graph-panel-D1BZdQJH.js} +1 -1
- package/dist/assets/dist-0lSCnrrf.js +1 -0
- package/dist/assets/dist-CLXTUtr2.js +1 -0
- package/dist/assets/{documentation-panel-BEz3Hjfu.js → documentation-panel-DzNGB1Zx.js} +1 -1
- package/dist/assets/{download-BgO9EN-W.js → download-DtQweFN1.js} +1 -1
- package/dist/assets/dropdown-menu-DnvwbPho.js +1 -0
- package/dist/assets/edit-page-fb5fV9UA.js +9 -0
- package/dist/assets/error-entries-CMsalXvZ.js +5 -0
- package/dist/assets/{error-panel-BtLTJDUq.js → error-panel-D6kqFA9f.js} +1 -1
- package/dist/assets/file-explorer-panel-D3APtOiy.js +1 -0
- package/dist/assets/file-icons-wArFRwmS.js +1 -0
- package/dist/assets/{file-name-input-CH-hNP6F.js → file-name-input-CdDGwb85.js} +3 -3
- package/dist/assets/{floating-outline-Cmk3XDJi.js → floating-outline-D2WpILR-.js} +1 -1
- package/dist/assets/gallery-page-B39w2KuX.js +1 -0
- package/dist/assets/{glide-data-editor-sICUMEhk.js → glide-data-editor-BufxOYjB.js} +1 -1
- package/dist/assets/home-page-BXgJYrZ5.js +4 -0
- package/dist/assets/index-B4Fq20-p.js +29 -0
- package/dist/assets/{kiosk-mode-mxgb5lWf.js → kiosk-mode-m6yKu6eh.js} +1 -1
- package/dist/assets/{layout-CsLuqwD3.js → layout-VgriO3Ll.js} +4 -4
- package/dist/assets/logs-panel-DsbX3K3h.js +1 -0
- package/dist/assets/{markdown-renderer-751VNlrQ.js → markdown-renderer-DD7ui8RW.js} +1 -1
- package/dist/assets/{name-cell-input-DexJ7ZIH.js → name-cell-input-EjA-eGvA.js} +1 -1
- package/dist/assets/{outline-panel-QU3nj1VW.js → outline-panel-DeDFCw9s.js} +1 -1
- package/dist/assets/{packages-panel-D7oDuI6v.js → packages-panel-B__MaP9u.js} +1 -1
- package/dist/assets/{pair-with-agent-modal-CbUFKJHP.js → pair-with-agent-modal-DYvcjx3q.js} +1 -1
- package/dist/assets/{panel-accordion-state-Dl0VcB79.js → panel-accordion-state-CwLKISCL.js} +1 -1
- package/dist/assets/panels-c3iYYVuV.js +4 -0
- package/dist/assets/{pathUtils-Cryrlpma.js → pathUtils-D7lk2rYQ.js} +1 -1
- package/dist/assets/paths-ClYq6Exe.js +1 -0
- package/dist/assets/{process-output-CPUOlFhp.js → process-output-DQoLxPra.js} +1 -1
- package/dist/assets/{readonly-code-display-DP7DxRA1.js → readonly-code-display-DuFy8860.js} +1 -1
- package/dist/assets/{readonly-python-code-CAYyabaV.js → readonly-python-code-yR65TOiM.js} +1 -1
- package/dist/assets/{renderShortcut-X-CJUSM8.js → renderShortcut-BE8QI9Yi.js} +1 -1
- package/dist/assets/{reveal-component-D9DygPds.js → reveal-component-CgskYNVn.js} +2 -2
- package/dist/assets/run-page-C_mciAdT.js +1 -0
- package/dist/assets/{scratchpad-panel-7YBL6E95.js → scratchpad-panel-Bj4yxnuS.js} +1 -1
- package/dist/assets/{secrets-panel-D3BpDIgg.js → secrets-panel-Cf-U5wY0.js} +1 -1
- package/dist/assets/select-C1IYgK48.js +1 -0
- package/dist/assets/session-panel-NQyDQouJ.js +1 -0
- package/dist/assets/{skeleton-CM7HxSva.js → skeleton-CUFHwpIk.js} +1 -1
- package/dist/assets/{snippets-panel-AdjuR23O.js → snippets-panel-Bx2wFck8.js} +1 -1
- package/dist/assets/{state-DOrY1Jyf.js → state-CdjswcRf.js} +1 -1
- package/dist/assets/{state-DQHafeTV.js → state-CiPrV156.js} +3 -3
- package/dist/assets/switch-DhPDzMo3.js +1 -0
- package/dist/assets/{terminal-CQAFGBfN.js → terminal-DH54UV0y.js} +2 -2
- package/dist/assets/tooltip-BvU0ko_d.js +1 -0
- package/dist/assets/tracing-Qjfb3Qm1.js +1 -0
- package/dist/assets/tracing-panel-Cj_-LD2X.js +2 -0
- package/dist/assets/{tree-actions-mfuAcK1x.js → tree-actions-CmY9PFuu.js} +1 -1
- package/dist/assets/{useAddCell-BR8kYnb6.js → useAddCell-Bvb-C_H5.js} +1 -1
- package/dist/assets/{useBoolean-BXC4CItZ.js → useBoolean-zcg-oxnj.js} +1 -1
- package/dist/assets/useCellActionButton-Df4qSnWR.js +1 -0
- package/dist/assets/{useDeleteCell-DwaN6KAw.js → useDeleteCell-eNMTvg8D.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-I-7B78cW.js → useDependencyPanelTab-BusYWoB8.js} +1 -1
- package/dist/assets/{useInstallPackage-IUt497GC.js → useInstallPackage-ClaR_nYb.js} +1 -1
- package/dist/assets/useNotebookActions-bWJW4dS_.js +10 -0
- package/dist/assets/{useRunCells-BMQuitYY.js → useRunCells-D8B7UNsg.js} +1 -1
- package/dist/assets/{useSplitCell-B7AvHoya.js → useSplitCell-Cy7fCcQW.js} +1 -1
- package/dist/assets/{vega-component-C7TCzyaU.js → vega-component-Z8mt9AUF.js} +1 -1
- package/dist/assets/{write-secret-modal-D6zoZgLY.js → write-secret-modal-CSWlDX_Z.js} +1 -1
- package/dist/index.html +34 -33
- package/package.json +1 -1
- package/src/components/data-table/column-visibility-dropdown.tsx +9 -3
- package/src/components/datasources/components.tsx +4 -2
- package/src/components/home/components.tsx +17 -0
- package/src/components/pages/gallery-page.tsx +2 -4
- package/src/components/pages/home-page.tsx +2 -4
- package/src/components/terminal/terminal.tsx +4 -4
- package/src/core/islands/__tests__/parse.test.ts +140 -7
- package/src/core/islands/parse.ts +20 -0
- package/src/core/runtime/__tests__/runtime.test.ts +11 -0
- package/src/core/runtime/runtime.ts +7 -2
- package/dist/assets/LazyAnyLanguageCodeMirror-LboTfNDv.js +0 -2
- package/dist/assets/add-cell-with-ai-OQ4sSXg4.js +0 -76
- package/dist/assets/agent-panel-BdEDIHdc.js +0 -286
- package/dist/assets/cell-link-CbHXmrt8.js +0 -1
- package/dist/assets/chat-display-CIpYPLlF.js +0 -1
- package/dist/assets/components-Cpv2z-yV.js +0 -1
- package/dist/assets/dist-DzCQtGkt.js +0 -1
- package/dist/assets/dropdown-menu-C40jM9o4.js +0 -1
- package/dist/assets/edit-page-DslcxB67.js +0 -9
- package/dist/assets/error-entries-BFzSRy80.js +0 -5
- package/dist/assets/file-explorer-panel-DEyChgqS.js +0 -1
- package/dist/assets/file-icons-BhotQqrU.js +0 -1
- package/dist/assets/gallery-page-C3pBpHlY.js +0 -1
- package/dist/assets/home-page-CUBuu5Go.js +0 -4
- package/dist/assets/index-C5h1aWhw.js +0 -29
- package/dist/assets/logs-panel-BV4VZ_uH.js +0 -1
- package/dist/assets/panels-nM4QKfEI.js +0 -4
- package/dist/assets/paths-zcL04qUW.js +0 -1
- package/dist/assets/run-page-CzO-uMUn.js +0 -1
- package/dist/assets/select-nLt2y0Sw.js +0 -1
- package/dist/assets/session-panel-hnFaUP0Y.js +0 -1
- package/dist/assets/switch-DjXr9Y9D.js +0 -1
- package/dist/assets/tooltip-BUtPzKB4.js +0 -1
- package/dist/assets/tracing-CUlvXr_H.js +0 -1
- package/dist/assets/tracing-panel-CjyayE-l.js +0 -2
- package/dist/assets/useCellActionButton-BhREXvvn.js +0 -1
- package/dist/assets/useNotebookActions-D5_YLR42.js +0 -10
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./loro_wasm_bg-BzjWitFM.js","./loro_wasm_bg-BRA1AbB3.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-xfs0Sn4r.js";import{t as u}from"./react-CBDbhulC.js";import{
|
|
3
|
-
`).length-1}},Aa=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){this.cache.set(e,{result:t,timestamp:Date.now()})}},ja=(e,t)=>$n.fromClass(class{abortController=null;cache;constructor(){this.cache=new Aa(t.cacheTimeout??1e3)}async update(n){if(!n.docChanged||t.events?.beforeSuggestionFetch?.(n.view)===!1)return;this.abortController?.abort(),this.abortController=new AbortController;let r=n.state.doc,i=r.toString(),a=this.cache.get(i);if(a){n.view.dispatch({effects:Da.of({text:a,doc:r})});return}try{let a=await e(n.state,this.abortController.signal,n.view);if(this.abortController.signal.aborted||t.events?.shouldShowSuggestion?.(n.view,a)===!1)return;this.cache.set(i,a),n.view.dispatch({effects:Da.of({text:a,doc:r})})}catch(e){e instanceof Error&&e.name!==`AbortError`&&console.error(`Suggestion fetch error:`,e)}}destroy(){this.abortController?.abort()}}),Ma=$n.fromClass(class{decorations;constructor(){this.decorations=L.none}update(e){let t=e.state.field(Ea)?.suggestion;if(!t){this.decorations=L.none;return}this.decorations=Oa(e.view,t)}},{decorations:e=>e.decorations});function Na(e,t,n,r){return{...e.changeByRange(i=>{if(i===e.selection.main)return{changes:{from:n,to:r,insert:t},range:zn.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:zn.cursor(i.from-a+t.length)}}),userEvent:`input.complete`}}var Pa=e=>{let t=e.state.field(Ea)?.suggestion;if(!t)return!1;let n=e.state.facet(La);return e.dispatch({...Na(e.state,t,e.state.selection.main.head,e.state.selection.main.head)}),n.events?.onSuggestionAccepted?.(e,t),!0},Fa=e=>{let t=e.state.field(Ea)?.suggestion;if(!t)return!1;let n=e.state.facet(La);return e.dispatch({effects:Da.of({text:null,doc:e.state.doc})}),n.events?.onSuggestionRejected?.(e,t),!0},Ia=Rn.of([{key:`Tab`,run:Pa},{key:`Escape`,run:Fa}]),La=kn.define({combine:e=>e.at(-1)});function Ra(e){let{delay:t=500,includeKeymap:n=!0}=e,r=Ta(e.fetchFn,t);return[Ea,La.of(e),ja(r,e),Ma,n?Ia:[]]}var za=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`}});function Ba(e){let t=e.state.facet(ca),n={...oa,...t.keymaps},r=e.state.facet(Va),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=wa(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 Va=kn.define({combine(e){return Qn(e,{render:Ba,hideOnBlur:!1,label:`Edit with AI`})}}),Ha=$n.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(Va);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(Va).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()}}),Ua=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 Wa(){return[Ha,Ua]}var Ga=class extends Wn{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">${wa(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">${wa(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}},Ka=class extends Wn{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 qa(e){if(!e.prompt)throw Error(`prompt function is required`);let t={...oa,...e.keymaps};return[ca.of(e),ua,pa,ha,_a,Wa(),za,Rn.of([{key:t.showInput,run:ya}]),Zn.highest([Rn.of([{key:t.acceptEdit,run:ba},{key:t.rejectEdit,run:xa}])]),Ja,Ya,Xa,Za]}var Ja=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})]})}),Ya=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}),Xa=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 Ka(n.prompt),side:-1}).range(a))}}return L.set(r)}),Za=Fn.define({create(e){return L.none},update(e,t){let n=t.state.field(ha);return n?L.set([L.widget({widget:new Ga(n.oldCode),block:!0}).range(n.from)]):L.none},provide:e=>R.decorations.from(e)}),V=Ot(),H=e(u(),1),Qa=()=>({entries:new Map}),{valueAtom:$a,useActions:eo}=mr(Qa,{submit:(e,t)=>{let{cellIds:n,deleteCell:r,deleteManyCells:i,store:a}=t,o=a.get(Ce),s=a.get(De),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)}),Qa()):{...e,entries:l}},clear:()=>Qa()});function to(){let e=n(),{submit:t,clear:r}=eo(),{entries:a}=i($a),o=si(),s=oi();return(0,H.useMemo)(()=>({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}}),[e,t,r,a,o,s])}function no(e){let t=(0,V.c)(16),n=i($a),r=eo(),a=oi(),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(ro)}),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 ro(e){return e.cellId}async function io(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 zr({stream:Nr({stream:e.body,schema:Br}).pipeThrough(new TransformStream({transform(e){if(!e.success)throw e.error;let r=e.value;if(Fr(r)&&r.type===Mr)t=Pr.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 ao(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-xfs0Sn4r.js";import{t as u}from"./react-CBDbhulC.js";import{Aa as d,Ai as f,Ar as p,Bn as m,Br as h,Cn as g,Ct as _,D as v,Di as y,Dt as b,Ei as x,Gr as S,H as C,Hr as w,I as T,Jn as E,K as D,Ka as ee,Ko as O,Kr as k,No as te,Oi as A,Pr as ne,Qa as j,Ra as M,Rr as re,So as ie,St as N,Tn as ae,Tr as oe,Tt as P,U as se,Ui as ce,Ur as le,V as F,Vr as ue,W as de,Wr as fe,Wt as pe,Xr as me,Za as he,Zr as ge,_i as _e,_n as ve,b as ye,bi as be,bt as xe,ci as Se,cr as Ce,ct as we,d as Te,dt as Ee,eo as De,fi as Oe,fr as ke,ft as Ae,gi as je,go as Me,gr as Ne,h as Pe,ha as Fe,hi as Ie,hn as Le,hr as Re,i as ze,ir as Be,ji as Ve,jo as He,ka as Ue,ki as We,li as Ge,lr as Ke,mi as qe,mr as Je,nr as Ye,pr as Xe,pt as Ze,qa as Qe,qn as $e,qr as et,qt as tt,to as nt,u as rt,ua as it,ui as at,ur as ot,vt as st,wi as ct,wn as lt,wt as ut,xn as dt,xt as ft,yi as pt,yn as mt,yo as ht,yt as gt,za as _t}from"./cells--Hh9voS5.js";import{t as vt}from"./react-dom-BQrReHnR.js";import{Cn as yt,In as bt,Jn as xt,Sn as St,Tt as Ct,kt as wt,ln as Tt,xt as Et}from"./schemas-aTUejmFi.js";import{t as Dt}from"./compiler-runtime-CYIjoINj.js";import{t as Ot}from"./debounce-aFmHgJZY.js";import{D as kt,_ as At,c as jt,g as Mt,l as Nt,v as Pt}from"./utils-D5Ywm7-q.js";import{D as Ft,O as It,b as Lt,g as Rt,h as zt,m as Bt,t as Vt,w as Ht}from"./ai-model-dropdown-C8IztRe2.js";import{_ as Ut,c as Wt,g as Gt,m as Kt,t as qt}from"./useEventListener-92uWqz-P.js";import{t as Jt}from"./invariant-Ci2dTZ72.js";import{E as Yt,N as Xt,O as Zt,S as Qt,T as $t,m as en,o as tn,r as nn,v as rn}from"./config-BuGkUPaK.js";import{n as an,t as on}from"./switch-DhPDzMo3.js";import{f as sn,n as cn,r as ln,y as un}from"./readonly-python-code-yR65TOiM.js";import{t as dn}from"./ErrorBoundary-CDVGFYfr.js";import{t as fn}from"./cn-ldLVeaqm.js";import{t as pn}from"./jsx-runtime-B74pBk57.js";import{d as mn}from"./select-C1IYgK48.js";import{Q as hn,Z as gn}from"./JsonOutput-izmGhjov.js";import{n as _n}from"./download-DtQweFN1.js";import{t as vn}from"./tooltip-BvU0ko_d.js";import{r as yn,t as bn}from"./button-Dh8EwhsF.js";import{At as xn,Bt as Sn,Ct as Cn,Dt as wn,E as Tn,Et as En,Ft as Dn,Gt as On,H as kn,Ht as An,I as jn,P as Mn,Pt as Nn,Qt as Pn,Rt as Fn,St as In,Tt as Ln,Ut as Rn,V as zn,Wt as Bn,Yt as Vn,Zt as I,_ as Hn,at as L,dt as Un,en as Wn,gt as Gn,ht as Kn,lt as qn,m as Jn,ot as Yn,qt as Xn,rn as Zn,st as R,ut as Qn,w as $n,xt as er}from"./dist-BtC9ym6k.js";import{C as tr,E as nr,I as rr,O as ir,S as ar,a as or,c as sr,n as cr,r as lr,w as ur}from"./dist-CZNULd6Z.js";import{o as dr}from"./arrays-BqUx5USx.js";import{n as fr}from"./once-Haz_uxEL.js";import{t as pr}from"./createReducer-B_XmHROl.js";import{a as mr,c as hr,f as gr,h as _r,i as vr,l as yr,n as br,o as xr,t as Sr}from"./dist-DiYjQAhI.js";import{r as Cr}from"./strings-CReV1AYG.js";import{r as wr,t as Tr}from"./requests-C6_IaFh7.js";import{t as Er}from"./createLucideIcon-B7HeEoG2.js";import{i as Dr,n as Or}from"./paths-ClYq6Exe.js";import{r as kr}from"./layout-VgriO3Ll.js";import{r as Ar}from"./useNumberFormatter-DHJ9s6Vk.js";import{t as jr}from"./circle-check-CUWv70QX.js";import{B as Mr,F as Nr,G as Pr,I as Fr,L as Ir,M as Lr,R as Rr,T as zr,V as Br,W as Vr,c as Hr,f as Ur,i as Wr,n as Gr,o as Kr,r as qr,s as Jr,w as Yr,z as Xr}from"./add-cell-with-ai-ZpV9L4qe.js";import{t as Zr}from"./database-zap-CloO6gbw.js";import{r as Qr,t as $r}from"./file-icons-wArFRwmS.js";import{t as ei}from"./components-DUYCXngU.js";import{D as ti,E as ni,T as ri,b as ii,j as ai}from"./write-secret-modal-CSWlDX_Z.js";import{n as oi}from"./spinner-Ck-Hgfvj.js";import{n as si,t as ci}from"./useDeleteCell-eNMTvg8D.js";import{t as li}from"./save-BybsbOKz.js";import{I as ui,Mt as di,P as fi}from"./input-DEbY281O.js";import{t as pi}from"./badge-BSgtkC2e.js";import{t as mi}from"./preload-helper-HclGiUj8.js";import{a as hi}from"./dist-CKUpxYGQ.js";import{t as gi}from"./use-toast-DpWHUGuF.js";import{t as _i}from"./session-Sz5nSFku.js";import{r as vi}from"./useTheme-C-ri8BtY.js";import{t as yi}from"./context-Do8M9TDF.js";import{i as bi}from"./numbers-Bc-r3jsC.js";import{n as xi}from"./useAsyncData-Buhk-UgR.js";import{n as Si}from"./copy-DlEomWzI.js";import{a as Ci}from"./useRunCells-D8B7UNsg.js";import{c as wi}from"./useInstallPackage-ClaR_nYb.js";import{a as Ti}from"./errors-DzO-nXy-.js";import{t as z}from"./extends-CvVTau-c.js";import{i as Ei,n as Di}from"./esm-BHMOvJzM.js";import{t as Oi}from"./kbd-Cwh96ZBE.js";import{a as ki,n as Ai}from"./state-CdjswcRf.js";import{a as ji,o as Mi}from"./cell-link-DEXHmwy1.js";import{a as Ni}from"./renderShortcut-BE8QI9Yi.js";import{n as Pi,t as Fi}from"./icons-CjLa9BiH.js";import{t as Ii}from"./dist-wY2yia-1.js";import{t as Li}from"./requests-S_7PqcSt.js";import{n as Ri}from"./formatting-BWZH2nBg.js";import{t as zi}from"./useSplitCell-Cy7fCcQW.js";import{n as Bi,r as Vi,t as Hi}from"./panel-accordion-state-CwLKISCL.js";import{co as Ui,do as Wi,fo as Gi,ft as Ki,go as qi,ho as Ji,lo as Yi,mo as Xi,oo as Zi,po as Qi,so as $i,uo as ea}from"./loro_wasm_bg-BRA1AbB3.js";import{t as ta}from"./ws-DLVysDhS.js";import{t as na}from"./Inputs-E85rt2lh.js";import{r as ra,t as ia}from"./skeleton-CUFHwpIk.js";var aa=Er(`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=On.define({combine:e=>Zn(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=Pn.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=Pn.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=Pn.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=Pn.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:Rn.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={mac:`⌘`,windows:`Ctrl`,default:`Ctrl`};function Ca(){return navigator.platform.startsWith(`Mac`)?Sa.mac:navigator.platform.startsWith(`Win`)?Sa.windows:Sa.default}function wa(e){return e.replace(`Mod`,Ca()).replace(`-`,` `).toUpperCase()}function B(e,t){let n=document.createElement(e);return n.className=t,n}function Ta(e,t,n=void 0){let r=()=>{};return(...i)=>(r(),new Promise((a,o)=>{let s=setTimeout(()=>a(e(...i)),t);r=()=>{clearTimeout(s),n!==void 0&&o(n)}}))}var Ea=Pn.define({create(){return{suggestion:null}},update(e,t){let n=t.effects.find(e=>e.is(Da));return!t.docChanged&&!n&&!t.selection?e:n&&t.state.doc===n.value.doc?{suggestion:n.value.text}:{suggestion:null}}}),Da=I.define();function Oa(e,t){let n=e.state.selection.main.head,r=[],i=L.widget({widget:new ka(t),side:1});return r.push(i.range(n)),L.set(r)}var ka=class extends Un{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}},Aa=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){this.cache.set(e,{result:t,timestamp:Date.now()})}},ja=(e,t)=>Qn.fromClass(class{abortController=null;cache;constructor(){this.cache=new Aa(t.cacheTimeout??1e3)}async update(n){if(!n.docChanged||t.events?.beforeSuggestionFetch?.(n.view)===!1)return;this.abortController?.abort(),this.abortController=new AbortController;let r=n.state.doc,i=r.toString(),a=this.cache.get(i);if(a){n.view.dispatch({effects:Da.of({text:a,doc:r})});return}try{let a=await e(n.state,this.abortController.signal,n.view);if(this.abortController.signal.aborted||t.events?.shouldShowSuggestion?.(n.view,a)===!1)return;this.cache.set(i,a),n.view.dispatch({effects:Da.of({text:a,doc:r})})}catch(e){e instanceof Error&&e.name!==`AbortError`&&console.error(`Suggestion fetch error:`,e)}}destroy(){this.abortController?.abort()}}),Ma=Qn.fromClass(class{decorations;constructor(){this.decorations=L.none}update(e){let t=e.state.field(Ea)?.suggestion;if(!t){this.decorations=L.none;return}this.decorations=Oa(e.view,t)}},{decorations:e=>e.decorations});function Na(e,t,n,r){return{...e.changeByRange(i=>{if(i===e.selection.main)return{changes:{from:n,to:r,insert:t},range:Rn.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:Rn.cursor(i.from-a+t.length)}}),userEvent:`input.complete`}}var Pa=e=>{let t=e.state.field(Ea)?.suggestion;if(!t)return!1;let n=e.state.facet(La);return e.dispatch({...Na(e.state,t,e.state.selection.main.head,e.state.selection.main.head)}),n.events?.onSuggestionAccepted?.(e,t),!0},Fa=e=>{let t=e.state.field(Ea)?.suggestion;if(!t)return!1;let n=e.state.facet(La);return e.dispatch({effects:Da.of({text:null,doc:e.state.doc})}),n.events?.onSuggestionRejected?.(e,t),!0},Ia=Ln.of([{key:`Tab`,run:Pa},{key:`Escape`,run:Fa}]),La=On.define({combine:e=>e.at(-1)});function Ra(e){let{delay:t=500,includeKeymap:n=!0}=e,r=Ta(e.fetchFn,t);return[Ea,La.of(e),ja(r,e),Ma,n?Ia:[]]}var za=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`}});function Ba(e){let t=e.state.facet(ca),n={...oa,...t.keymaps},r=e.state.facet(Va),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=wa(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 Va=On.define({combine(e){return Zn(e,{render:Ba,hideOnBlur:!1,label:`Edit with AI`})}}),Ha=Qn.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(Va);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(Va).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()}}),Ua=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 Wa(){return[Ha,Ua]}var Ga=class extends Un{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">${wa(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">${wa(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}},Ka=class extends Un{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 qa(e){if(!e.prompt)throw Error(`prompt function is required`);let t={...oa,...e.keymaps};return[ca.of(e),ua,pa,ha,_a,Wa(),za,Ln.of([{key:t.showInput,run:ya}]),Xn.highest([Ln.of([{key:t.acceptEdit,run:ba},{key:t.rejectEdit,run:xa}])]),Ja,Ya,Xa,Za]}var Ja=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})]})}),Ya=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}),Xa=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 Ka(n.prompt),side:-1}).range(a))}}return L.set(r)}),Za=Pn.define({create(e){return L.none},update(e,t){let n=t.state.field(ha);return n?L.set([L.widget({widget:new Ga(n.oldCode),block:!0}).range(n.from)]):L.none},provide:e=>R.decorations.from(e)}),V=Dt(),H=e(u(),1),Qa=()=>({entries:new Map}),{valueAtom:$a,useActions:eo}=pr(Qa,{submit:(e,t)=>{let{cellIds:n,deleteCell:r,deleteManyCells:i,store:a}=t,o=a.get(ye),s=a.get(Se),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)}),Qa()):{...e,entries:l}},clear:()=>Qa()});function to(){let e=n(),{submit:t,clear:r}=eo(),{entries:a}=i($a),o=ci(),s=si();return(0,H.useMemo)(()=>({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}}),[e,t,r,a,o,s])}function no(e){let t=(0,V.c)(16),n=i($a),r=eo(),a=si(),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(ro)}),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 ro(e){return e.cellId}async function io(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 Br({stream:Pr({stream:e.body,schema:Vr}).pipeThrough(new TransformStream({transform(e){if(!e.success)throw e.error;let r=e.value;if(Ir(r)&&r.type===Nr)t=Fr.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 ao(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=rn();await $t();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 io(r);return a.startsWith(i)||(a=i+a),a}function oo(e){switch(e){case`table`:case`connection`:ye(`variables`),Hi(Vi,`datasources`);return;case`bucket`:ye(`files`),Hi(Bi,`remote-storage`);return;case`cache`:ye(`cache`);return;default:wr(e)}}function so(e){let{state:t,names:n}=e;if(n.size===0)return[];let r=An(t);if(!r||P(r))return[];let i=new Map,a=e=>{if(e.name===O.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===O.TupleExpression||e.name===O.ArrayExpression||e.name===O.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===O.AssignOp&&(t=n.from);if(t!==-1)for(let n=e.firstChild;n&&n.from<t;n=n.nextSibling)a(n)},s=e=>{if(!nt.has(e.name)){if(e.name===O.AssignStatement){o(e);return}for(let t=e.firstChild;t;t=t.nextSibling)s(t)}};return s(r.topNode),[...i.values()]}var co=/\bmo\.(?:persistent_cache|cache)\b/g;function lo(e){let t=e.match(/^[A-Za-z]*("""|'''|"|')([\s\S]*)\1$/);return t?t[2]:e}function uo(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===O.VariableName&&t(i)===`name`&&i.nextSibling?.name===O.AssignOp)){let e=i.nextSibling.nextSibling;if(e?.name===O.String&&n(e.nextSibling))return lo(t(e))}return r&&r.name===O.String&&n(r.nextSibling)?lo(t(r)):null}function fo(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===O.CallExpression){l=e;break}if(l){c=l.to,s=l.getChild(O.ArgList);let e=l.parent;if(e?.name===O.AssignStatement){let t=e.getChild(O.VariableName);o=t&&t.from<l.from?i(t):null}else if(e?.name===O.WithStatement){let t=e.firstChild;for(;t;){if(t.from<l.to||t.name===w.As){t=t.nextSibling;continue}t.name===O.VariableName&&(o=i(t));break}}}else if(a.parent?.name===O.Decorator){let e=a.parent,t=e.getChild(O.ArgList);t?.from===r&&(s=t,c=t.to);let n=(e.parent?.getChild(O.FunctionDefinition))?.getChild(O.VariableName);o=n?i(n):null}let u=uo(s,i);return{from:n,to:c,boundName:o,cacheName:u}}function po(e,t,n){let r=t.resolveInner(n,1);return!pe.has(r.name)&&r.name===O.VariableName&&e.doc.sliceString(r.from,r.to)===`mo`}function mo(e){let t=An(e);return!t||P(t)?[]:[...e.doc.toString().matchAll(co)].filter(n=>po(e,t,n.index??0)).map(n=>{let r=n.index??0;return fo(e,t,r,r+n[0].length)})}function ho(e,t,n){let r=e.get(t);r!==void 0&&r!==n&&Kt.error(`[code-lens] "${t}" is claimed by both a ${r} and a ${n} entity; keeping ${n}`),e.set(t,n)}var go=r(e=>{let t=new Map;for(let n of e(ht))n.variable_name&&ho(t,n.variable_name,`table`);for(let n of e(Je).keys())A.has(n)||ho(t,n,`connection`);for(let n of e(b))ho(t,n.name,`bucket`);return t}),_o=r(e=>{let t=e(go),n=e(De),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 vo(e){let{byCell:t,pending:n}=o.get(_o),r=new Map(t.get(e));for(let[e,t]of n)r.has(e)||r.set(e,t);return r}var yo=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>`,bo={table:yo(`<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:yo(`<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:yo(`<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:yo(`<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"/>`)},xo={table:`Open in data sources`,connection:`Open in data sources`,bucket:`Open in remote storage`,cache:`Open cache panel`},So=e(yt(),1),Co=e(ge(),1),U=mn();function wo(e,t){let n=(0,Co.createRoot)(e);return(0,So.flushSync)(()=>{n.render((0,U.jsx)(s,{store:o,children:(0,U.jsx)(To,{spec:t})}))}),()=>queueMicrotask(()=>n.unmount())}var To=e=>{let t=(0,V.c)(9),{spec:n}=e;switch(n.kind){case`table`:{let e;return t[0]===n.name?e=t[1]:(e=(0,U.jsx)(Eo,{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)(Do,{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)(Oo,{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)(No,{boundName:e,cacheName:r}),t[6]=e,t[7]=r,t[8]=i):i=t[8],i}default:wr(n.kind)}},Eo=e=>{let t=(0,V.c)(5),{name:n}=e,r=i(ht),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?We(i):d(`table`),t[0]=n,t[1]=r,t[2]=a}else a=t[2];return a},Do=e=>{let t=(0,V.c)(5),{name:n}=e,r=i(Je),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=d(`database`),t[4]=e):e=t[4],o=e;break bb0}a=Ge(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},Oo=e=>{let t=(0,V.c)(27),{name:n}=e,r=i(b),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:x,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)($r,{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)(fi,{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)(re,{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)(y,{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)(y,{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)(y,{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:x,children:[l,m]}),t[24]=l,t[25]=m,t[26]=h):h=t[26],h},ko=/\bhits=(\d+) misses=(\d+)/,Ao=null,jo=5e3;function Mo(){let e=Date.now();Ao!=null&&e-Ao<jo||(Ao=e,Er().getCacheInfo().catch(()=>{Ao=null}))}var No=e=>{let t=(0,V.c)(16),{boundName:n,cacheName:r}=e,{locale:a}=yi(),o=i(De),s=i(Li),c=n?o[n]:void 0,l;t[0]===c?l=t[1]:(l=c?.dataType?.startsWith(`_cache_call`)?c.value?.match(ko):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||Mo()},p=[d],t[2]=d,t[3]=f,t[4]=p),(0,H.useEffect)(f,p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,U.jsx)(Xr,{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)(re,{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)(y,{label:`Hits`,value:(0,U.jsx)(`span`,{className:`font-medium`,children:bi(Number(u[1]),a)})}),(0,U.jsx)(y,{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)(y,{label:`Hits`,value:bi(s.hits,a)}),(0,U.jsx)(y,{label:`Misses`,value:bi(s.misses,a)}),(0,U.jsx)(y,{label:`Time saved`,value:Ri(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 b;return t[13]!==g||t[14]!==_?(b=(0,U.jsxs)(`div`,{className:x,children:[g,_,v]}),t[13]=g,t[14]=_,t[15]=b):b=t[15],b},Po=I.define(),Fo=I.define();function Io(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 Lo=class{view;showTimer;hideTimer;constructor(e){this.view=e}enterLens(e,t){this.clearTimers(),zo(this.view,t);let n=this.view.state.field(Ho,!1);n&&Io(n.spec,e)||(this.showTimer=window.setTimeout(()=>{this.showTimer=void 0,this.view.dispatch({effects:Fo.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(Ho,!1)&&this.view.dispatch({effects:Fo.of(null)})}destroy(){this.clearTimers()}clearTimers(){window.clearTimeout(this.showTimer),window.clearTimeout(this.hideTimer),this.showTimer=void 0,this.hideTimer=void 0}},Ro=$n.define(e=>new Lo(e));function zo(e,t){e.dom.dispatchEvent(new MouseEvent(`mouseleave`,{relatedTarget:t}))}var Bo=class extends Wn{spec;constructor(e){super(),this.spec=e}eq(e){return Io(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`,xo[t.kind]),n.innerHTML=bo[t.kind];let r=()=>e.plugin(Ro),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(),oo(t.kind)},n.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),i(),oo(t.kind))},n}ignoreEvent(){return!0}};function Vo(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(Ro)?.enterPopover(),n.onmouseleave=()=>t.plugin(Ro)?.leave(),{dom:n,resize:!1,destroy:wo(n,e)}}}}}var Ho=Fn.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(Fo))return n.value?Vo(n.value):null;if(n.is(Po)&&e)return n.value.some(t=>Io(t,e.spec))?e:null}return t.docChanged?null:e},provide:e=>Pn.from(e,e=>e?.tooltip??null)}),Uo=Fn.define({create(){return L.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(Po)&&(e=L.set(n.value.map(e=>L.widget({widget:new Bo(e),side:1}).range(e.pos)),!0));return e},provide:e=>R.decorations.from(e)}),Wo=class{view;cellId;includeCache;unsubscribes;debounceMs=300;scheduleUpdate;constructor(e,t,n){this.view=e,this.cellId=t,this.includeCache=n,this.scheduleUpdate=kt(()=>this.run(),this.debounceMs);let r=()=>this.scheduleUpdate();this.unsubscribes=[o.sub(ht,r),o.sub(Je,r),o.sub(b,r),o.sub(De,r)],this.scheduleUpdate()}update(e){let t=e.startState.field(M,!1)?.type!==e.state.field(M,!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(M,!1)?.type;if(n==null||n===`python`){let n=vo(this.cellId),r=so({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 mo(e))t.push({pos:n.to,kind:`cache`,name:`cache:${n.from}`,cache:{boundName:n.boundName,cacheName:n.cacheName}})}queueMicrotask(()=>{this.view.dispatch({effects:Po.of(t)})})}},Go=`3px`,Ko=R.baseTheme({".mo-code-lens":{display:`inline-flex`,verticalAlign:`baseline`,transform:`translateY(1.5px)`,padding:Go,margin:`-${Go} 0 -${Go} calc(0.3em - ${Go})`,cursor:`pointer`,opacity:`0.5`},".mo-code-lens:hover":{opacity:`1`}});function qo(e,t=!0){return t?[Uo,Ho,Ro,$n.define(t=>new Wo(t,e,Me(`cache_panel`))),Ko]:[]}var Jo=[`%alias`,`%cd`,`%clear`,`%debug`,`%env`,`%load`,`%load_ext`,`%lsmagic`,`%matplotlib`,`%pwd`,`%who_ls`,`%system`,`%%time`,`%%timeit`,`%%writefile`,`%%capture`,`%%html`,`%%latex`],Yo;function Xo(){let e=async e=>{let t=o.get(At),{saveUserConfig:n}=Er();await n({config:{runtime:{auto_reload:e}}}).then(()=>o.set(At,{...t,runtime:{...t.runtime,auto_reload:e}}))},t=[{match:`!pip install`,onMatch:()=>{o.set(_e,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(_e,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(_e,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.`]})},...Jo.map(e=>({match:e,onMatch:()=>{},title:(0,U.jsx)(Oi,{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(),Yo?Yo.upsert({title:o.title,description:o.description}):Yo=hi({title:o.title,description:o.description}))}})}var Zo=new Set([`Escape`,"Alt-`"]);function Qo(e,t=Zo){return e.filter(e=>![e.key,e.mac,e.linux,e.win].some(e=>t.has(e)))}function $o(e=!0){let t=new Set(Zo);e||t.add(`Enter`);let n=Qo(gr,t);return Zn.highest(Rn.of([...n,{key:`Ctrl-y`,run:e=>f(e)?xr(e):!1},{key:`Ctrl-n`,run:e=>f(e)?_r(!0)(e):!1},{key:`Ctrl-p`,run:e=>f(e)?_r(!1)(e):!1}]))}var es=I.define(),ts=I.define(),ns=I.define();function W(e,t){if(!e)throw Error(t)}var rs=34028234663852886e22,is=-34028234663852886e22,as=4294967295,os=2147483647,ss=-2147483648;function cs(e){if(typeof e!=`number`)throw Error(`invalid int 32: `+typeof e);if(!Number.isInteger(e)||e>os||e<ss)throw Error(`invalid int 32: `+e)}function ls(e){if(typeof e!=`number`)throw Error(`invalid uint 32: `+typeof e);if(!Number.isInteger(e)||e>as||e<0)throw Error(`invalid uint 32: `+e)}function us(e){if(typeof e!=`number`)throw Error(`invalid float 32: `+typeof e);if(Number.isFinite(e)&&(e>rs||e<is))throw Error(`invalid float 32: `+e)}var ds=Symbol(`@bufbuild/protobuf/enum-type`);function fs(e){let t=e[ds];return W(t,`missing enum type on enum object`),t}function ps(e,t,n,r){e[ds]=ms(t,n.map(t=>({no:t.no,name:t.name,localName:e[t.no]})),r)}function ms(e,t,n){let r=Object.create(null),i=Object.create(null),a=[];for(let e of t){let t=gs(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 hs(e,t,n){let r={};for(let e of t){let t=gs(e);r[t.localName]=t.no,r[t.no]=t.localName}return ps(r,e,t,n),r}function gs(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 _s(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 vs(){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 ys(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 bs=4294967296;function xs(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>=bs&&(i+=r/bs|0,r%=bs)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?Es(r,i):Ts(r,i)}function Ss(e,t){let n=Ts(e,t),r=n.hi&2147483648;r&&(n=Es(n.lo,n.hi));let i=Cs(n.lo,n.hi);return r?`-`+i:i}function Cs(e,t){if({lo:e,hi:t}=ws(e,t),t<=2097151)return String(bs*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()+Ds(o)+Ds(a)}function ws(e,t){return{lo:e>>>0,hi:t>>>0}}function Ts(e,t){return{lo:e|0,hi:t|0}}function Es(e,t){return t=~t,e?e=~e+1:t+=1,Ts(e,t)}var Ds=e=>{let t=String(e);return`0000000`.slice(t.length)+t};function Os(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 ks(){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 As(){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),xs(e)},uEnc(e){return typeof e!=`string`&&(e=e.toString()),n(e),xs(e)},dec(e,t){return Ss(e,t)},uDec(e,t){return Cs(e,t)}}}var K=As(),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 js;(function(e){e[e.BIGINT=0]=`BIGINT`,e[e.STRING=1]=`STRING`})(js||={});function Ms(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 Ns(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 Ps(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 Fs=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(ls(e);e>127;)this.buf.push(e&127|128),e>>>=7;return this.buf.push(e),this}int32(e){return cs(e),Os(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){us(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){ls(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){cs(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return cs(e),e=(e<<1^e>>31)>>>0,Os(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 ys(t.lo,t.hi,this.buf),this}sint64(e){let t=K.enc(e),n=t.hi>>31;return ys(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=K.uEnc(e);return ys(t.lo,t.hi,this.buf),this}},Is=class{constructor(e,t){this.varint64=vs,this.uint32=ks,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 Ls(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 Rs(e){let t=e.field.localName,n=Object.create(null);return n[t]=zs(e),[n,()=>n[t]]}function zs(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 Ns(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 Bs(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 Vs=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),Hs=[];for(let e=0;e<Vs.length;e++)Hs[Vs[e].charCodeAt(0)]=e;Hs[45]=Vs.indexOf(`+`),Hs[95]=Vs.indexOf(`/`);var Us={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=Hs[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+=Vs[r>>2],i=(r&3)<<4,n=1;break;case 1:t+=Vs[i|r>>4],i=(r&15)<<2,n=2;break;case 2:t+=Vs[i|r>>6],t+=Vs[r&63],n=0}return n&&(t+=Vs[i],t+=`=`,n==1&&(t+=`=`)),t}};function Ws(e,t,n){qs(t,e);let r=t.runtime.bin.makeReadOptions(n),i=Bs(e.getType().runtime.bin.listUnknownFields(e),t.field),[a,o]=Rs(t);for(let e of i)t.runtime.bin.readField(a,r.readerFactory(e.data),t.field,e.wireType,r);return o()}function Gs(e,t,n,r){qs(t,e);let i=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(Ks(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 Ks(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 qs(e,t){W(e.extendee.typeName==t.getType().typeName,`extension ${e.typeName} can only be applied to message ${e.extendee.typeName}`)}function Js(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:!Ps(e.T,t[n]);case`message`:return t[n]!==void 0;case`map`:return Object.keys(t[n]).length>0}}function Ys(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?Ns(e.T,e.L):void 0;break;case`message`:t[n]=void 0}}function Xs(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 Zs(e,t){return Xs(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 Qs={ignoreUnknownFields:!1},$s={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function ec(e){return e?Object.assign(Object.assign({},Qs),e):Qs}function tc(e){return e?Object.assign(Object.assign({},$s),e):$s}var nc=Symbol(),rc=Symbol();function ic(){return{makeReadOptions:ec,makeWriteOptions:tc,readMessage(e,t,n,r){if(t==null||Array.isArray(t)||typeof t!=`object`)throw Error(`cannot decode message ${e.typeName} from JSON: ${ac(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)}oc(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]=Rs(i);oc(e,s,i.field,n,i),Gs(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(!Js(i,e)){if(i.req)throw`required field not set`;if(!t.emitDefaultValues||!uc(i))continue}let n=i.oneof?e[i.oneof.localName].value:e[i.localName],a=dc(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&&Ks(e,o)){let n=Ws(e,o,t),i=dc(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 cc(e,t,n??js.BIGINT,!0)},writeScalar(e,t,n){if(t!==void 0&&(n||Ps(e,t)))return pc(e,t)},debug:ac}}function ac(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 oc(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: ${ac(t)}`);let o=e[a];for(let e of t){if(e===null)throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${ac(e)}`);switch(n.kind){case`message`:o.push(n.T.fromJson(e,r));break;case`enum`:let t=lc(n.T,e,r.ignoreUnknownFields,!0);t!==rc&&o.push(t);break;case`scalar`:try{o.push(cc(n.T,e,n.L,!0))}catch(t){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${ac(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: ${ac(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=sc(n.K,e)}catch(e){let r=`cannot decode map key for field ${i.typeName}.${n.name} from JSON: ${ac(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=lc(n.V.T,a,r.ignoreUnknownFields,!0);e!==rc&&(o[s]=e);break;case`scalar`:try{o[s]=cc(n.V.T,a,js.BIGINT,!0)}catch(e){let r=`cannot decode map value for field ${i.typeName}.${n.name} from JSON: ${ac(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];Xs(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=lc(n.T,t,r.ignoreUnknownFields,!1);switch(c){case nc:Ys(n,e);break;case rc:break;default:e[a]=c}break;case`scalar`:try{let r=cc(n.T,t,n.L,!1);switch(r){case nc:Ys(n,e);break;default:e[a]=r}}catch(e){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${ac(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}}}function sc(e,t){if(e===q.BOOL)switch(t){case`true`:t=!0;break;case`false`:t=!1}return cc(e,t,js.BIGINT,!0).toString()}function cc(e,t,n,r){if(t===null)return r?Ns(e,n):nc;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&&us(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?ls(i):cs(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 Us.dec(t)}throw Error()}function lc(e,t,n,r){if(t===null)return e.typeName==`google.protobuf.NullValue`?0:r?e.values[0].no:nc;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 rc}throw Error(`cannot decode enum ${e.typeName} from JSON: ${ac(t)}`)}function uc(e){return e.repeated||e.kind==`map`?!0:!(e.oneof||e.kind==`message`||e.opt||e.req)}function dc(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()]=pc(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()]=fc(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(pc(e.T,t[n]));break;case`enum`:for(let i=0;i<t.length;i++)r.push(fc(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 pc(e.T,t);case`enum`:return fc(e.T,t,n.enumAsInteger);case`message`:return Zs(e.T,t).toJson(n)}}function fc(e,t,n){return W(typeof t==`number`),e.typeName==`google.protobuf.NullValue`?null:n?t:e.findNumber(t)?.name??t}function pc(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),Us.enc(t)}}var mc=Symbol(`@bufbuild/protobuf/unknown-fields`),hc={readUnknownFields:!0,readerFactory:e=>new Is(e)},gc={writeUnknownFields:!0,writerFactory:()=>new Fs};function _c(e){return e?Object.assign(Object.assign({},hc),e):hc}function vc(e){return e?Object.assign(Object.assign({},gc),e):gc}function yc(){return{makeReadOptions:_c,makeWriteOptions:vc,listUnknownFields(e){return e[mc]??[]},discardUnknownFields(e){delete e[mc]},writeUnknownFields(e,t){let n=e[mc];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[mc])||(i[mc]=[]),i[mc].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}bc(e,t,n,c,r)}if(i&&(c!=J.EndGroup||s!==n))throw Error(`invalid end group tag`)},readField:bc,writeMessage(e,t,n){let r=e.getType();for(let i of r.fields.byNumber()){if(!Js(i,e)){if(i.req)throw Error(`cannot encode field ${r.typeName}.${i.name} to binary: required field not set`);continue}Tc(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&&Tc(e,t,n,r)}}}function bc(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=wc;if(n.kind==`scalar`&&n.L>0&&(c=Cc),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(xc(t,new l,i,n)):Xs(e[o])?xc(t,e[o],i,n):(e[o]=xc(t,new l,i,n),l.fieldWrapper&&!n.oneof&&!n.repeated&&(e[o]=l.fieldWrapper.unwrapField(e[o])));break;case`map`:let[u,d]=Sc(n,t,i);e[o][u]=d}}function xc(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 Sc(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=wc(t,e.K);break;case 2:switch(e.V.kind){case`scalar`:o=wc(t,e.V.T);break;case`enum`:o=t.int32();break;case`message`:o=xc(t,new e.V.T,n,void 0)}}}if(a===void 0&&(a=Ns(e.K,js.BIGINT)),typeof a!=`string`&&typeof a!=`number`&&(a=a.toString()),o===void 0)switch(e.V.kind){case`scalar`:o=Ns(e.V.T,js.BIGINT);break;case`enum`:o=e.V.T.values[0].no;break;case`message`:o=new e.V.T}return[a,o]}function Cc(e,t){let n=wc(e,t);return typeof n==`bigint`?n.toString():n}function wc(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 Tc(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)kc(n,a,e.no,t);else for(let r of t)Oc(n,a,e.no,r)}else Oc(n,a,e.no,t);break;case`message`:if(i){W(Array.isArray(t));for(let i of t)Dc(n,r,e,i)}else Dc(n,r,e,t);break;case`map`:W(typeof t==`object`&&!!t);for(let[i,a]of Object.entries(t))Ec(n,r,e,i,a)}}function Ec(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(Oc(e,n.K,1,a),n.V.kind){case`scalar`:Oc(e,n.V.T,2,i);break;case`enum`:Oc(e,q.INT32,2,i);break;case`message`:W(i!==void 0),e.tag(2,J.LengthDelimited).bytes(i.toBinary(t))}e.join()}function Dc(e,t,n,r){let i=Zs(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 Oc(e,t,n,r){W(r!==void 0);let[i,a]=Ac(t);e.tag(n,i)[a](r)}function kc(e,t,n,r){if(!r.length)return;e.tag(n,J.LengthDelimited).fork();let[,i]=Ac(t);for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}function Ac(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 jc(){return{setEnumType:ps,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`&&!Xs(o,t.T)?o=new t.T(o):t&&t.kind===`scalar`&&t.T===q.BYTES&&(o=Nc(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(Nc):Nc(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]=Nc(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=>Xs(e,c)?e:new c(e));else{let e=a[n];i[n]=c.fieldWrapper?c.typeName===`google.protobuf.BytesValue`?Nc(e):e:Xs(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)=>Ms(e.T,t,i[n]));case`enum`:return r.every((e,t)=>Ms(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&&!Xs(t)&&(t=e.T.fieldWrapper.wrapField(t)),n!==void 0&&!Xs(n)&&(n=e.T.fieldWrapper.wrapField(n))),e.T.equals(t,n);case`enum`:return Ms(q.INT32,r,i);case`scalar`:return Ms(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 Ms(q.INT32,r.value,i.value);case`scalar`:return Ms(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=>Ms(q.INT32,r[e],i[e]));case`scalar`:let n=e.V.T;return o.every(e=>Ms(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(Mc);else if(n.kind==`map`){i=r[n.localName];for(let[e,n]of Object.entries(t))i[e]=Mc(n)}else i=n.kind==`oneof`?n.findField(t.case)?{case:t.case,value:Mc(t.value)}:{case:void 0}:Mc(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 Mc(e){if(e===void 0)return e;if(Xs(e))return e.clone();if(e instanceof Uint8Array){let t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function Nc(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Pc(e,t,n){return{syntax:e,json:ic(),bin:yc(),util:Object.assign(Object.assign({},jc()),{newFieldList:t,initFields:n}),makeMessageType(e,t,n){return _s(this,e,t,n)},makeEnum:hs,makeEnumType:ms,getEnumType:fs,makeExtension(e,t,n){return Ls(this,e,t,n)}}}var Fc=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 Ic(e,t){let n=zc(e);return t?n:Wc(Uc(n))}function Lc(e){return Ic(e,!1)}var Rc=zc;function zc(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 Bc=new Set([`constructor`,`toString`,`toJSON`,`valueOf`]),Vc=new Set([`getType`,`clone`,`equals`,`fromBinary`,`fromJson`,`fromJsonString`,`toBinary`,`toJson`,`toJsonString`,`toObject`]),Hc=e=>`${e}$`,Uc=e=>Vc.has(e)?Hc(e):e,Wc=e=>Bc.has(e)?Hc(e):e,Gc=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=Lc(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 Kc(e,t){let n=[],r;for(let i of typeof e==`function`?e():e){let e=i;if(e.localName=Ic(i.name,i.oneof!==void 0),e.jsonName=i.jsonName??Rc(i.name),e.repeated=i.repeated??!1,i.kind==`scalar`&&(e.L=i.L??js.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 Gc(t)),e.oneof=r,r.addField(e)}n.push(e)}return n}var Y=Pc(`proto3`,e=>new Fc(e,e=>Kc(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]=Ns(t.T,t.L)}}}),qc;(function(e){e[e.Unary=0]=`Unary`,e[e.ServerStreaming=1]=`ServerStreaming`,e[e.ClientStreaming=2]=`ClientStreaming`,e[e.BiDiStreaming=3]=`BiDiStreaming`})(qc||={});var Jc;(function(e){e[e.NoSideEffects=1]=`NoSideEffects`,e[e.Idempotent=2]=`Idempotent`})(Jc||={});var Yc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.JUPYTER_FORMAT=77]=`JUPYTER_FORMAT`})(Yc||={}),Y.util.setEnumType(Yc,`exa.codeium_common_pb.ExperimentKey`,[{no:0,name:`UNSPECIFIED`},{no:77,name:`JUPYTER_FORMAT`}]);var Xc;(function(e){e[e.CODEIUM=0]=`CODEIUM`})(Xc||={}),Y.util.setEnumType(Xc,`exa.codeium_common_pb.AuthSource`,[{no:0,name:`AUTH_SOURCE_CODEIUM`}]);var Zc;(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`})(Zc||={}),Y.util.setEnumType(Zc,`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 Qc;(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`})(Qc||={}),Y.util.setEnumType(Qc,`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 $c;(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`})($c||={}),Y.util.setEnumType($c,`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 el=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)}},tl=class e extends G{ideName=``;ideVersion=``;extensionName=``;extensionVersion=``;apiKey=``;locale=``;sessionId=``;requestId=K.zero;userAgent=``;url=``;authSource=Xc.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(Xc)}]);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)}},nl=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=Zc.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(Zc)},{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 rl=class extends Wn{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}},il=kn.define({combine(e){return Qn(e,{language:$c.TYPESCRIPT,timeout:150,widgetClass:rl,alwaysOn:!0},{})}}),al=kn.define({combine(e){return Qn(e,{override:()=>[]},{})}}),ol=L.mark({class:`cm-ghostText`}),sl=Fn.define({create(e){return null},update(e,t){let n=t.state.facet(il);for(let e of t.effects){if(e.is(es)){let{changeSpecs:t,index:r}=e.value,i=t[r].map(e=>ol.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(ts)||e.is(ns))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)}),cl=In.define(),ll=In.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 ul(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 dl;function fl(e){if(!dl){dl={};for(let e of Object.values(X))typeof e!=`string`&&(dl[ul(e)]=e)}return dl[e]}var Z=class e extends Error{constructor(e,t=X.Unknown,n,r,i){super(pl(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 pl(e,t){return e.length?`[${ul(t)}] ${e}`:`[${ul(t)}]`}function ml(...e){let t=new Headers;for(let n of e)n.forEach((e,n)=>{t.append(n,e)});return t}function hl(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 gl(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 _l(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 vl=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)}},yl=function(e){return this instanceof yl?(this.v=e,this):new yl(e)},bl=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 yl?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])}},xl=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:yl(e[r](t)),done:!1}:i?i(t):t}:i}};function Sl(e){return bl(this,arguments,function*(){yield yl(yield*xl(vl(e)))})}var Cl=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)}},wl=function(e){return this instanceof wl?(this.v=e,this):new wl(e)},Tl=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:wl(e[r](t)),done:!1}:i?i(t):t}:i}},El=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 wl?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 Dl(e,t){return hl(e,n=>{switch(n.kind){case qc.Unary:return kl(t,e,n);case qc.ServerStreaming:return Al(t,e,n);case qc.ClientStreaming:return jl(t,e,n);case qc.BiDiStreaming:return Ml(t,e,n);default:return null}})}function Ol(e,t){return Dl(e,t)}function kl(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 Al(e,t,n){return function(r,i){return Nl(e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,Sl([r]),i?.contextValues),i)}}function jl(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=Cl(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 Ml(e,t,n){return function(r,i){return Nl(e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,r,i?.contextValues),i)}}function Nl(e,t){let n=(function(){return El(this,arguments,function*(){var n,r;let i=yield wl(e);(n=t?.onHeader)==null||n.call(t,i.header),yield wl(yield*Tl(Cl(i.message))),(r=t?.onTrailer)==null||r.call(t,i.trailer)})})()[Symbol.asyncIterator]();return{[Symbol.asyncIterator]:()=>({next:()=>n.next()})}}function Pl(...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(Il(this));for(let e of n)e.removeEventListener(`abort`,r)}return t}function Fl(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 Il(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 Ll(){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 Rl(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 zl(e,t){return t instanceof e?t:new e(t)}function Bl(e,t){function n(t){return t.done===!0?t:{done:t.done,value:zl(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 Vl(e,t){return t?.concat().reverse().reduce((e,t)=>t(e),e)??e}function Hl(e){let t=Object.assign({},e);return t.ignoreUnknownFields??=!0,t}function Ul(e,t,n,r){let i=t?Wl(e.I,r):Gl(e.I,n);return{parse:(t?Wl(e.O,r):Gl(e.O,n)).parse,serialize:i.serialize}}function Wl(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 Gl(e,t){let n=t?.textEncoder??new TextEncoder,r=t?.textDecoder??new TextDecoder,i=Hl(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 Kl=/^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$/i,ql=`application/proto`,Jl=`application/json`,Yl=`application/connect+proto`,Xl=`application/connect+json`;function Zl(e){let t=e?.match(Kl);if(t)return{stream:!!t[1],binary:!!t[3]}}function Ql(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=fl(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:Us.dec(t.value),debug:t.debug})}catch{throw n}}return a}function $l(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?Ql(n.error,r,t):void 0}}var eu=`Content-Type`,tu=`Content-Length`,nu=`Content-Encoding`,ru=`Accept-Encoding`,iu=`Connect-Timeout-Ms`,au=`Connect-Protocol-Version`,ou=`User-Agent`;function su(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 cu(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 lu(e,t,n,r,i){let a=new Headers(r??{});return n!==void 0&&a.set(iu,`${n}`),a.set(eu,e==qc.Unary?t?ql:Jl:t?Yl:Xl),a.set(au,`1`),i&&a.set(ou,`connect-es/1.6.1`),a}function uu(e,t,n,r){let i=r.get(eu),a=Zl(i);if(n!==200){let t=new Z(`HTTP ${n}`,su(n),r);if(e==qc.Unary&&a&&!a.binary)return{isUnaryError:!0,unaryError:t};throw t}let o={binary:t,stream:e!==qc.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 du=`application/`;function fu(e,t){return t?Us.enc(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``):encodeURIComponent(new TextDecoder().decode(e))}function pu(e,t,n){let r=`?connect=v1`,i=e.header.get(eu);i?.indexOf(du)===0&&(r+=`&encoding=`+encodeURIComponent(i.slice(12)));let a=e.header.get(nu);a!==null&&a!==`identity`&&(r+=`&compression=`+encodeURIComponent(a),n=!0),n&&(r+=`&base64=1`),r+=`&message=`+fu(t,n);let o=e.url+r,s=new Headers(e.header);return[au,eu,tu,nu,ru].forEach(e=>s.delete(e)),Object.assign(Object.assign({},e),{init:Object.assign(Object.assign({},e.init),{method:`GET`}),url:o,header:s})}function mu(e){let t=Vl(e.next,e.interceptors),[n,r,i]=gu(e);return t(Object.assign(Object.assign({},e.req),{message:zl(e.req.method.I,e.req.message),signal:n})).then(e=>(i(),e),r)}function hu(e){let t=Vl(e.next,e.interceptors),[n,r,i]=gu(e),a=Object.assign(Object.assign({},e.req),{message:Bl(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 gu(e){let{signal:t,cleanup:n}=Fl(e.timeoutMs),r=Pl(e.signal,t);return[r.signal,function(e){let i=Z.from(t.aborted?Il(t):e);return r.abort(i),n(),Promise.reject(i)},function(){n(),r.abort()}]}var _u;(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`})(_u||={}),Y.util.setEnumType(_u,`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 vu;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.SINGLE=1]=`SINGLE`,e[e.MULTI=2]=`MULTI`})(vu||={}),Y.util.setEnumType(vu,`exa.language_server_pb.LineType`,[{no:0,name:`LINE_TYPE_UNSPECIFIED`},{no:1,name:`LINE_TYPE_SINGLE`},{no:2,name:`LINE_TYPE_MULTI`}]);var yu;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.INLINE=1]=`INLINE`,e[e.BLOCK=2]=`BLOCK`,e[e.INLINE_MASK=3]=`INLINE_MASK`})(yu||={}),Y.util.setEnumType(yu,`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 bu=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)}},xu=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:tl},{no:2,name:`document`,kind:`message`,T:Ou},{no:3,name:`editor_options`,kind:`message`,T:nl},{no:5,name:`other_documents`,kind:`message`,T:Ou,repeated:!0},{no:7,name:`experiment_config`,kind:`message`,T:ku},{no:10,name:`model_name`,kind:`scalar`,T:9},{no:13,name:`multiline_config`,kind:`message`,T:bu}]);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{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:Au},{no:2,name:`completion_items`,kind:`message`,T:Pu,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)}},Cu=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:tl},{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)}},wu=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)}},Tu=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)}},Eu=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)}},Du=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)}},Ou=class e extends G{absolutePath=``;relativePath=``;text=``;editorLanguage=``;language=$c.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($c)},{no:6,name:`cursor_offset`,kind:`scalar`,T:4},{no:8,name:`cursor_position`,kind:`message`,T:Du},{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)}},ku=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(Yc),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)}},Au=class e extends G{state=_u.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(_u)},{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)}},ju=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:Du},{no:4,name:`end_position`,kind:`message`,T:Du}]);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=``;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)}},Nu=class e extends G{text=``;offset=K.zero;type=yu.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(yu)},{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)}},Pu=class e extends G{completion;suffix;range;source=Qc.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:el},{no:5,name:`suffix`,kind:`message`,T:Mu},{no:2,name:`range`,kind:`message`,T:ju},{no:3,name:`source`,kind:`enum`,T:Y.getEnumType(Qc)},{no:8,name:`completion_parts`,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)}},Fu={typeName:`exa.language_server_pb.LanguageServerService`,methods:{getCompletions:{name:`GetCompletions`,I:xu,O:Su,kind:qc.Unary},acceptCompletion:{name:`AcceptCompletion`,I:Cu,O:wu,kind:qc.Unary},getAuthToken:{name:`GetAuthToken`,I:Tu,O:Eu,kind:qc.Unary}}};function Iu(){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 Lu=function(e){return this instanceof Lu?(this.v=e,this):new Lu(e)},Ru=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 Lu?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 zu(e){Iu();let t=e.useBinaryFormat??!1;return{async unary(n,r,i,a,o,s,c){let{serialize:l,parse:u}=Ul(r,t,e.jsonOptions,e.binaryOptions);return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await mu({interceptors:e.interceptors,signal:i,timeoutMs:a,req:{stream:!1,service:n,method:r,url:Rl(e.baseUrl,n,r),init:{method:`POST`,credentials:e.credentials??`same-origin`,redirect:`error`,mode:`cors`},header:lu(r.kind,t,a,o,!1),contextValues:c??Ll(),message:s},next:async i=>{let a=e.useHttpGet===!0&&r.idempotency===Jc.NoSideEffects,o=null;a?i=pu(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}=uu(r.kind,t,s.status,s.headers);if(c)throw Ql(await s.json(),ml(...cu(s.headers)),d);let[f,p]=cu(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(),Hl(e.jsonOptions)),trailer:p}}})},async stream(n,r,i,a,o,s,c){let{serialize:l,parse:u}=Ul(r,t,e.jsonOptions,e.binaryOptions);function d(e,t,n,r){return Ru(this,arguments,function*(){let i=gl(e).getReader(),a=!1;for(;;){let e=yield Lu(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=$l(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 Lu(u(o))}if(`throwIfAborted`in r&&r.throwIfAborted(),!a)throw`missing EndStreamResponse`})}async function f(e){if(r.kind!=qc.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 _l(0,l(t.value))}return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await hu({interceptors:e.interceptors,timeoutMs:a,signal:i,req:{stream:!0,service:n,method:r,url:Rl(e.baseUrl,n,r),init:{method:`POST`,credentials:e.credentials??`same-origin`,redirect:`error`,mode:`cors`},header:lu(r.kind,t,a,o,!1),contextValues:c??Ll(),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(uu(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 Bu=Ol(Fu,zu({baseUrl:`https://web-backend.codeium.com`,useBinaryFormat:!0})),Vu;try{Vu=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))}Vu=e()}async function Hu({text:e,cursorOffset:t,config:n,otherDocuments:r}){return await Bu.getCompletions({metadata:{ideName:`web`,ideVersion:`0.0.5`,extensionName:`@valtown/codemirror-codeium`,extensionVersion:`1.0.0`,apiKey:n.apiKey,sessionId:Vu,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}-${Vu}`}})}function Uu(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 Wu(e,t){let n=e.state.facet(il),{override:r}=e.state.facet(al),i=await r(),a=e.state,o=a.selection.main.head,s=a.doc.toString();try{let r=await Hu({text:s,cursorOffset:o,config:n,otherDocuments:i});if(!r||r.completionItems.length===0||!((t===void 0||o===t)&&
|
|
9
|
+
`.trim(),n=nn();await Qt();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 io(r);return a.startsWith(i)||(a=i+a),a}function oo(e){switch(e){case`table`:case`connection`:ge(`variables`),Hi(Vi,`datasources`);return;case`bucket`:ge(`files`),Hi(Bi,`remote-storage`);return;case`cache`:ge(`cache`);return;default:Cr(e)}}function so(e){let{state:t,names:n}=e;if(n.size===0)return[];let r=kn(t);if(!r||le(r))return[];let i=new Map,a=e=>{if(e.name===k.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===k.TupleExpression||e.name===k.ArrayExpression||e.name===k.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===k.AssignOp&&(t=n.from);if(t!==-1)for(let n=e.firstChild;n&&n.from<t;n=n.nextSibling)a(n)},s=e=>{if(!et.has(e.name)){if(e.name===k.AssignStatement){o(e);return}for(let t=e.firstChild;t;t=t.nextSibling)s(t)}};return s(r.topNode),[...i.values()]}var co=/\bmo\.(?:persistent_cache|cache)\b/g;function lo(e){let t=e.match(/^[A-Za-z]*("""|'''|"|')([\s\S]*)\1$/);return t?t[2]:e}function uo(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===k.VariableName&&t(i)===`name`&&i.nextSibling?.name===k.AssignOp)){let e=i.nextSibling.nextSibling;if(e?.name===k.String&&n(e.nextSibling))return lo(t(e))}return r&&r.name===k.String&&n(r.nextSibling)?lo(t(r)):null}function fo(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===k.CallExpression){l=e;break}if(l){c=l.to,s=l.getChild(k.ArgList);let e=l.parent;if(e?.name===k.AssignStatement){let t=e.getChild(k.VariableName);o=t&&t.from<l.from?i(t):null}else if(e?.name===k.WithStatement){let t=e.firstChild;for(;t;){if(t.from<l.to||t.name===S.As){t=t.nextSibling;continue}t.name===k.VariableName&&(o=i(t));break}}}else if(a.parent?.name===k.Decorator){let e=a.parent,t=e.getChild(k.ArgList);t?.from===r&&(s=t,c=t.to);let n=(e.parent?.getChild(k.FunctionDefinition))?.getChild(k.VariableName);o=n?i(n):null}let u=uo(s,i);return{from:n,to:c,boundName:o,cacheName:u}}function po(e,t,n){let r=t.resolveInner(n,1);return!fe.has(r.name)&&r.name===k.VariableName&&e.doc.sliceString(r.from,r.to)===`mo`}function mo(e){let t=kn(e);return!t||le(t)?[]:[...e.doc.toString().matchAll(co)].filter(n=>po(e,t,n.index??0)).map(n=>{let r=n.index??0;return fo(e,t,r,r+n[0].length)})}function ho(e,t,n){let r=e.get(t);r!==void 0&&r!==n&&Gt.error(`[code-lens] "${t}" is claimed by both a ${r} and a ${n} entity; keeping ${n}`),e.set(t,n)}var go=r(e=>{let t=new Map;for(let n of e(Fe))n.variable_name&&ho(t,n.variable_name,`table`);for(let n of e(it).keys())Ue.has(n)||ho(t,n,`connection`);for(let n of e(b))ho(t,n.name,`bucket`);return t}),_o=r(e=>{let t=e(go),n=e(Se),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 vo(e){let{byCell:t,pending:n}=o.get(_o),r=new Map(t.get(e));for(let[e,t]of n)r.has(e)||r.set(e,t);return r}var yo=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>`,bo={table:yo(`<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:yo(`<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:yo(`<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:yo(`<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"/>`)},xo={table:`Open in data sources`,connection:`Open in data sources`,bucket:`Open in remote storage`,cache:`Open cache panel`},So=e(vt(),1),Co=e(O(),1),U=pn();function wo(e,t){let n=(0,Co.createRoot)(e);return(0,So.flushSync)(()=>{n.render((0,U.jsx)(s,{store:o,children:(0,U.jsx)(To,{spec:t})}))}),()=>queueMicrotask(()=>n.unmount())}var To=e=>{let t=(0,V.c)(9),{spec:n}=e;switch(n.kind){case`table`:{let e;return t[0]===n.name?e=t[1]:(e=(0,U.jsx)(Eo,{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)(Do,{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)(Oo,{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)(No,{boundName:e,cacheName:r}),t[6]=e,t[7]=r,t[8]=i):i=t[8],i}default:Cr(n.kind)}},Eo=e=>{let t=(0,V.c)(5),{name:n}=e,r=i(Fe),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?Ve(i):f(`table`),t[0]=n,t[1]=r,t[2]=a}else a=t[2];return a},Do=e=>{let t=(0,V.c)(5),{name:n}=e,r=i(it),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=f(`database`),t[4]=e):e=t[4],o=e;break bb0}a=We(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},Oo=e=>{let t=(0,V.c)(27),{name:n}=e,r=i(b),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:x,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)(ei,{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)(pi,{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)(A,{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)(y,{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)(y,{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)(y,{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:x,children:[l,m]}),t[24]=l,t[25]=m,t[26]=h):h=t[26],h},ko=/\bhits=(\d+) misses=(\d+)/,Ao=null,jo=5e3;function Mo(){let e=Date.now();Ao!=null&&e-Ao<jo||(Ao=e,Tr().getCacheInfo().catch(()=>{Ao=null}))}var No=e=>{let t=(0,V.c)(16),{boundName:n,cacheName:r}=e,{locale:a}=yi(),o=i(Se),s=i(Li),c=n?o[n]:void 0,l;t[0]===c?l=t[1]:(l=c?.dataType?.startsWith(`_cache_call`)?c.value?.match(ko):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||Mo()},p=[d],t[2]=d,t[3]=f,t[4]=p),(0,H.useEffect)(f,p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,U.jsx)(Zr,{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)(A,{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)(y,{label:`Hits`,value:(0,U.jsx)(`span`,{className:`font-medium`,children:bi(Number(u[1]),a)})}),(0,U.jsx)(y,{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)(y,{label:`Hits`,value:bi(s.hits,a)}),(0,U.jsx)(y,{label:`Misses`,value:bi(s.misses,a)}),(0,U.jsx)(y,{label:`Time saved`,value:Ri(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 b;return t[13]!==g||t[14]!==_?(b=(0,U.jsxs)(`div`,{className:x,children:[g,_,v]}),t[13]=g,t[14]=_,t[15]=b):b=t[15],b},Po=I.define(),Fo=I.define();function Io(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 Lo=class{view;showTimer;hideTimer;constructor(e){this.view=e}enterLens(e,t){this.clearTimers(),zo(this.view,t);let n=this.view.state.field(Ho,!1);n&&Io(n.spec,e)||(this.showTimer=window.setTimeout(()=>{this.showTimer=void 0,this.view.dispatch({effects:Fo.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(Ho,!1)&&this.view.dispatch({effects:Fo.of(null)})}destroy(){this.clearTimers()}clearTimers(){window.clearTimeout(this.showTimer),window.clearTimeout(this.hideTimer),this.showTimer=void 0,this.hideTimer=void 0}},Ro=Qn.define(e=>new Lo(e));function zo(e,t){e.dom.dispatchEvent(new MouseEvent(`mouseleave`,{relatedTarget:t}))}var Bo=class extends Un{spec;constructor(e){super(),this.spec=e}eq(e){return Io(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`,xo[t.kind]),n.innerHTML=bo[t.kind];let r=()=>e.plugin(Ro),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(),oo(t.kind)},n.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),i(),oo(t.kind))},n}ignoreEvent(){return!0}};function Vo(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(Ro)?.enterPopover(),n.onmouseleave=()=>t.plugin(Ro)?.leave(),{dom:n,resize:!1,destroy:wo(n,e)}}}}}var Ho=Pn.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(Fo))return n.value?Vo(n.value):null;if(n.is(Po)&&e)return n.value.some(t=>Io(t,e.spec))?e:null}return t.docChanged?null:e},provide:e=>Nn.from(e,e=>e?.tooltip??null)}),Uo=Pn.define({create(){return L.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(Po)&&(e=L.set(n.value.map(e=>L.widget({widget:new Bo(e),side:1}).range(e.pos)),!0));return e},provide:e=>R.decorations.from(e)}),Wo=class{view;cellId;includeCache;unsubscribes;debounceMs=300;scheduleUpdate;constructor(e,t,n){this.view=e,this.cellId=t,this.includeCache=n,this.scheduleUpdate=Ot(()=>this.run(),this.debounceMs);let r=()=>this.scheduleUpdate();this.unsubscribes=[o.sub(Fe,r),o.sub(it,r),o.sub(b,r),o.sub(Se,r)],this.scheduleUpdate()}update(e){let t=e.startState.field(N,!1)?.type!==e.state.field(N,!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(N,!1)?.type;if(n==null||n===`python`){let n=vo(this.cellId),r=so({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 mo(e))t.push({pos:n.to,kind:`cache`,name:`cache:${n.from}`,cache:{boundName:n.boundName,cacheName:n.cacheName}})}queueMicrotask(()=>{this.view.dispatch({effects:Po.of(t)})})}},Go=`3px`,Ko=R.baseTheme({".mo-code-lens":{display:`inline-flex`,verticalAlign:`baseline`,transform:`translateY(1.5px)`,padding:Go,margin:`-${Go} 0 -${Go} calc(0.3em - ${Go})`,cursor:`pointer`,opacity:`0.5`},".mo-code-lens:hover":{opacity:`1`}});function qo(e,t=!0){return t?[Uo,Ho,Ro,Qn.define(t=>new Wo(t,e,Oe(`cache_panel`))),Ko]:[]}var Jo=[`%alias`,`%cd`,`%clear`,`%debug`,`%env`,`%load`,`%load_ext`,`%lsmagic`,`%matplotlib`,`%pwd`,`%who_ls`,`%system`,`%%time`,`%%timeit`,`%%writefile`,`%%capture`,`%%html`,`%%latex`],Yo;function Xo(){let e=async e=>{let t=o.get(kt),{saveUserConfig:n}=Tr();await n({config:{runtime:{auto_reload:e}}}).then(()=>o.set(kt,{...t,runtime:{...t.runtime,auto_reload:e}}))},t=[{match:`!pip install`,onMatch:()=>{o.set(me,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(me,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(me,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.`]})},...Jo.map(e=>({match:e,onMatch:()=>{},title:(0,U.jsx)(Oi,{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(),Yo?Yo.upsert({title:o.title,description:o.description}):Yo=gi({title:o.title,description:o.description}))}})}var Zo=new Set([`Escape`,"Alt-`"]);function Qo(e,t=Zo){return e.filter(e=>![e.key,e.mac,e.linux,e.win].some(e=>t.has(e)))}function $o(e=!0){let t=new Set(Zo);e||t.add(`Enter`);let n=Qo(hr,t);return Xn.highest(Ln.of([...n,{key:`Ctrl-y`,run:e=>p(e)?br(e):!1},{key:`Ctrl-n`,run:e=>p(e)?gr(!0)(e):!1},{key:`Ctrl-p`,run:e=>p(e)?gr(!1)(e):!1}]))}var es=I.define(),ts=I.define(),ns=I.define();function W(e,t){if(!e)throw Error(t)}var rs=34028234663852886e22,is=-34028234663852886e22,as=4294967295,os=2147483647,ss=-2147483648;function cs(e){if(typeof e!=`number`)throw Error(`invalid int 32: `+typeof e);if(!Number.isInteger(e)||e>os||e<ss)throw Error(`invalid int 32: `+e)}function ls(e){if(typeof e!=`number`)throw Error(`invalid uint 32: `+typeof e);if(!Number.isInteger(e)||e>as||e<0)throw Error(`invalid uint 32: `+e)}function us(e){if(typeof e!=`number`)throw Error(`invalid float 32: `+typeof e);if(Number.isFinite(e)&&(e>rs||e<is))throw Error(`invalid float 32: `+e)}var ds=Symbol(`@bufbuild/protobuf/enum-type`);function fs(e){let t=e[ds];return W(t,`missing enum type on enum object`),t}function ps(e,t,n,r){e[ds]=ms(t,n.map(t=>({no:t.no,name:t.name,localName:e[t.no]})),r)}function ms(e,t,n){let r=Object.create(null),i=Object.create(null),a=[];for(let e of t){let t=gs(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 hs(e,t,n){let r={};for(let e of t){let t=gs(e);r[t.localName]=t.no,r[t.no]=t.localName}return ps(r,e,t,n),r}function gs(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 _s(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 vs(){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 ys(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 bs=4294967296;function xs(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>=bs&&(i+=r/bs|0,r%=bs)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?Es(r,i):Ts(r,i)}function Ss(e,t){let n=Ts(e,t),r=n.hi&2147483648;r&&(n=Es(n.lo,n.hi));let i=Cs(n.lo,n.hi);return r?`-`+i:i}function Cs(e,t){if({lo:e,hi:t}=ws(e,t),t<=2097151)return String(bs*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()+Ds(o)+Ds(a)}function ws(e,t){return{lo:e>>>0,hi:t>>>0}}function Ts(e,t){return{lo:e|0,hi:t|0}}function Es(e,t){return t=~t,e?e=~e+1:t+=1,Ts(e,t)}var Ds=e=>{let t=String(e);return`0000000`.slice(t.length)+t};function Os(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 ks(){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 As(){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),xs(e)},uEnc(e){return typeof e!=`string`&&(e=e.toString()),n(e),xs(e)},dec(e,t){return Ss(e,t)},uDec(e,t){return Cs(e,t)}}}var K=As(),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 js;(function(e){e[e.BIGINT=0]=`BIGINT`,e[e.STRING=1]=`STRING`})(js||={});function Ms(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 Ns(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 Ps(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 Fs=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(ls(e);e>127;)this.buf.push(e&127|128),e>>>=7;return this.buf.push(e),this}int32(e){return cs(e),Os(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){us(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){ls(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){cs(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return cs(e),e=(e<<1^e>>31)>>>0,Os(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 ys(t.lo,t.hi,this.buf),this}sint64(e){let t=K.enc(e),n=t.hi>>31;return ys(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=K.uEnc(e);return ys(t.lo,t.hi,this.buf),this}},Is=class{constructor(e,t){this.varint64=vs,this.uint32=ks,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 Ls(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 Rs(e){let t=e.field.localName,n=Object.create(null);return n[t]=zs(e),[n,()=>n[t]]}function zs(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 Ns(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 Bs(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 Vs=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),Hs=[];for(let e=0;e<Vs.length;e++)Hs[Vs[e].charCodeAt(0)]=e;Hs[45]=Vs.indexOf(`+`),Hs[95]=Vs.indexOf(`/`);var Us={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=Hs[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+=Vs[r>>2],i=(r&3)<<4,n=1;break;case 1:t+=Vs[i|r>>4],i=(r&15)<<2,n=2;break;case 2:t+=Vs[i|r>>6],t+=Vs[r&63],n=0}return n&&(t+=Vs[i],t+=`=`,n==1&&(t+=`=`)),t}};function Ws(e,t,n){qs(t,e);let r=t.runtime.bin.makeReadOptions(n),i=Bs(e.getType().runtime.bin.listUnknownFields(e),t.field),[a,o]=Rs(t);for(let e of i)t.runtime.bin.readField(a,r.readerFactory(e.data),t.field,e.wireType,r);return o()}function Gs(e,t,n,r){qs(t,e);let i=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(Ks(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 Ks(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 qs(e,t){W(e.extendee.typeName==t.getType().typeName,`extension ${e.typeName} can only be applied to message ${e.extendee.typeName}`)}function Js(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:!Ps(e.T,t[n]);case`message`:return t[n]!==void 0;case`map`:return Object.keys(t[n]).length>0}}function Ys(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?Ns(e.T,e.L):void 0;break;case`message`:t[n]=void 0}}function Xs(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 Zs(e,t){return Xs(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 Qs={ignoreUnknownFields:!1},$s={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function ec(e){return e?Object.assign(Object.assign({},Qs),e):Qs}function tc(e){return e?Object.assign(Object.assign({},$s),e):$s}var nc=Symbol(),rc=Symbol();function ic(){return{makeReadOptions:ec,makeWriteOptions:tc,readMessage(e,t,n,r){if(t==null||Array.isArray(t)||typeof t!=`object`)throw Error(`cannot decode message ${e.typeName} from JSON: ${ac(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)}oc(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]=Rs(i);oc(e,s,i.field,n,i),Gs(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(!Js(i,e)){if(i.req)throw`required field not set`;if(!t.emitDefaultValues||!uc(i))continue}let n=i.oneof?e[i.oneof.localName].value:e[i.localName],a=dc(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&&Ks(e,o)){let n=Ws(e,o,t),i=dc(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 cc(e,t,n??js.BIGINT,!0)},writeScalar(e,t,n){if(t!==void 0&&(n||Ps(e,t)))return pc(e,t)},debug:ac}}function ac(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 oc(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: ${ac(t)}`);let o=e[a];for(let e of t){if(e===null)throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${ac(e)}`);switch(n.kind){case`message`:o.push(n.T.fromJson(e,r));break;case`enum`:let t=lc(n.T,e,r.ignoreUnknownFields,!0);t!==rc&&o.push(t);break;case`scalar`:try{o.push(cc(n.T,e,n.L,!0))}catch(t){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${ac(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: ${ac(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=sc(n.K,e)}catch(e){let r=`cannot decode map key for field ${i.typeName}.${n.name} from JSON: ${ac(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=lc(n.V.T,a,r.ignoreUnknownFields,!0);e!==rc&&(o[s]=e);break;case`scalar`:try{o[s]=cc(n.V.T,a,js.BIGINT,!0)}catch(e){let r=`cannot decode map value for field ${i.typeName}.${n.name} from JSON: ${ac(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];Xs(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=lc(n.T,t,r.ignoreUnknownFields,!1);switch(c){case nc:Ys(n,e);break;case rc:break;default:e[a]=c}break;case`scalar`:try{let r=cc(n.T,t,n.L,!1);switch(r){case nc:Ys(n,e);break;default:e[a]=r}}catch(e){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${ac(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}}}function sc(e,t){if(e===q.BOOL)switch(t){case`true`:t=!0;break;case`false`:t=!1}return cc(e,t,js.BIGINT,!0).toString()}function cc(e,t,n,r){if(t===null)return r?Ns(e,n):nc;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&&us(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?ls(i):cs(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 Us.dec(t)}throw Error()}function lc(e,t,n,r){if(t===null)return e.typeName==`google.protobuf.NullValue`?0:r?e.values[0].no:nc;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 rc}throw Error(`cannot decode enum ${e.typeName} from JSON: ${ac(t)}`)}function uc(e){return e.repeated||e.kind==`map`?!0:!(e.oneof||e.kind==`message`||e.opt||e.req)}function dc(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()]=pc(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()]=fc(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(pc(e.T,t[n]));break;case`enum`:for(let i=0;i<t.length;i++)r.push(fc(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 pc(e.T,t);case`enum`:return fc(e.T,t,n.enumAsInteger);case`message`:return Zs(e.T,t).toJson(n)}}function fc(e,t,n){return W(typeof t==`number`),e.typeName==`google.protobuf.NullValue`?null:n?t:e.findNumber(t)?.name??t}function pc(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),Us.enc(t)}}var mc=Symbol(`@bufbuild/protobuf/unknown-fields`),hc={readUnknownFields:!0,readerFactory:e=>new Is(e)},gc={writeUnknownFields:!0,writerFactory:()=>new Fs};function _c(e){return e?Object.assign(Object.assign({},hc),e):hc}function vc(e){return e?Object.assign(Object.assign({},gc),e):gc}function yc(){return{makeReadOptions:_c,makeWriteOptions:vc,listUnknownFields(e){return e[mc]??[]},discardUnknownFields(e){delete e[mc]},writeUnknownFields(e,t){let n=e[mc];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[mc])||(i[mc]=[]),i[mc].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}bc(e,t,n,c,r)}if(i&&(c!=J.EndGroup||s!==n))throw Error(`invalid end group tag`)},readField:bc,writeMessage(e,t,n){let r=e.getType();for(let i of r.fields.byNumber()){if(!Js(i,e)){if(i.req)throw Error(`cannot encode field ${r.typeName}.${i.name} to binary: required field not set`);continue}Tc(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&&Tc(e,t,n,r)}}}function bc(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=wc;if(n.kind==`scalar`&&n.L>0&&(c=Cc),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(xc(t,new l,i,n)):Xs(e[o])?xc(t,e[o],i,n):(e[o]=xc(t,new l,i,n),l.fieldWrapper&&!n.oneof&&!n.repeated&&(e[o]=l.fieldWrapper.unwrapField(e[o])));break;case`map`:let[u,d]=Sc(n,t,i);e[o][u]=d}}function xc(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 Sc(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=wc(t,e.K);break;case 2:switch(e.V.kind){case`scalar`:o=wc(t,e.V.T);break;case`enum`:o=t.int32();break;case`message`:o=xc(t,new e.V.T,n,void 0)}}}if(a===void 0&&(a=Ns(e.K,js.BIGINT)),typeof a!=`string`&&typeof a!=`number`&&(a=a.toString()),o===void 0)switch(e.V.kind){case`scalar`:o=Ns(e.V.T,js.BIGINT);break;case`enum`:o=e.V.T.values[0].no;break;case`message`:o=new e.V.T}return[a,o]}function Cc(e,t){let n=wc(e,t);return typeof n==`bigint`?n.toString():n}function wc(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 Tc(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)kc(n,a,e.no,t);else for(let r of t)Oc(n,a,e.no,r)}else Oc(n,a,e.no,t);break;case`message`:if(i){W(Array.isArray(t));for(let i of t)Dc(n,r,e,i)}else Dc(n,r,e,t);break;case`map`:W(typeof t==`object`&&!!t);for(let[i,a]of Object.entries(t))Ec(n,r,e,i,a)}}function Ec(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(Oc(e,n.K,1,a),n.V.kind){case`scalar`:Oc(e,n.V.T,2,i);break;case`enum`:Oc(e,q.INT32,2,i);break;case`message`:W(i!==void 0),e.tag(2,J.LengthDelimited).bytes(i.toBinary(t))}e.join()}function Dc(e,t,n,r){let i=Zs(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 Oc(e,t,n,r){W(r!==void 0);let[i,a]=Ac(t);e.tag(n,i)[a](r)}function kc(e,t,n,r){if(!r.length)return;e.tag(n,J.LengthDelimited).fork();let[,i]=Ac(t);for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}function Ac(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 jc(){return{setEnumType:ps,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`&&!Xs(o,t.T)?o=new t.T(o):t&&t.kind===`scalar`&&t.T===q.BYTES&&(o=Nc(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(Nc):Nc(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]=Nc(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=>Xs(e,c)?e:new c(e));else{let e=a[n];i[n]=c.fieldWrapper?c.typeName===`google.protobuf.BytesValue`?Nc(e):e:Xs(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)=>Ms(e.T,t,i[n]));case`enum`:return r.every((e,t)=>Ms(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&&!Xs(t)&&(t=e.T.fieldWrapper.wrapField(t)),n!==void 0&&!Xs(n)&&(n=e.T.fieldWrapper.wrapField(n))),e.T.equals(t,n);case`enum`:return Ms(q.INT32,r,i);case`scalar`:return Ms(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 Ms(q.INT32,r.value,i.value);case`scalar`:return Ms(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=>Ms(q.INT32,r[e],i[e]));case`scalar`:let n=e.V.T;return o.every(e=>Ms(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(Mc);else if(n.kind==`map`){i=r[n.localName];for(let[e,n]of Object.entries(t))i[e]=Mc(n)}else i=n.kind==`oneof`?n.findField(t.case)?{case:t.case,value:Mc(t.value)}:{case:void 0}:Mc(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 Mc(e){if(e===void 0)return e;if(Xs(e))return e.clone();if(e instanceof Uint8Array){let t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function Nc(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Pc(e,t,n){return{syntax:e,json:ic(),bin:yc(),util:Object.assign(Object.assign({},jc()),{newFieldList:t,initFields:n}),makeMessageType(e,t,n){return _s(this,e,t,n)},makeEnum:hs,makeEnumType:ms,getEnumType:fs,makeExtension(e,t,n){return Ls(this,e,t,n)}}}var Fc=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 Ic(e,t){let n=zc(e);return t?n:Wc(Uc(n))}function Lc(e){return Ic(e,!1)}var Rc=zc;function zc(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 Bc=new Set([`constructor`,`toString`,`toJSON`,`valueOf`]),Vc=new Set([`getType`,`clone`,`equals`,`fromBinary`,`fromJson`,`fromJsonString`,`toBinary`,`toJson`,`toJsonString`,`toObject`]),Hc=e=>`${e}$`,Uc=e=>Vc.has(e)?Hc(e):e,Wc=e=>Bc.has(e)?Hc(e):e,Gc=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=Lc(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 Kc(e,t){let n=[],r;for(let i of typeof e==`function`?e():e){let e=i;if(e.localName=Ic(i.name,i.oneof!==void 0),e.jsonName=i.jsonName??Rc(i.name),e.repeated=i.repeated??!1,i.kind==`scalar`&&(e.L=i.L??js.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 Gc(t)),e.oneof=r,r.addField(e)}n.push(e)}return n}var Y=Pc(`proto3`,e=>new Fc(e,e=>Kc(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]=Ns(t.T,t.L)}}}),qc;(function(e){e[e.Unary=0]=`Unary`,e[e.ServerStreaming=1]=`ServerStreaming`,e[e.ClientStreaming=2]=`ClientStreaming`,e[e.BiDiStreaming=3]=`BiDiStreaming`})(qc||={});var Jc;(function(e){e[e.NoSideEffects=1]=`NoSideEffects`,e[e.Idempotent=2]=`Idempotent`})(Jc||={});var Yc;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.JUPYTER_FORMAT=77]=`JUPYTER_FORMAT`})(Yc||={}),Y.util.setEnumType(Yc,`exa.codeium_common_pb.ExperimentKey`,[{no:0,name:`UNSPECIFIED`},{no:77,name:`JUPYTER_FORMAT`}]);var Xc;(function(e){e[e.CODEIUM=0]=`CODEIUM`})(Xc||={}),Y.util.setEnumType(Xc,`exa.codeium_common_pb.AuthSource`,[{no:0,name:`AUTH_SOURCE_CODEIUM`}]);var Zc;(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`})(Zc||={}),Y.util.setEnumType(Zc,`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 Qc;(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`})(Qc||={}),Y.util.setEnumType(Qc,`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 $c;(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`})($c||={}),Y.util.setEnumType($c,`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 el=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)}},tl=class e extends G{ideName=``;ideVersion=``;extensionName=``;extensionVersion=``;apiKey=``;locale=``;sessionId=``;requestId=K.zero;userAgent=``;url=``;authSource=Xc.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(Xc)}]);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)}},nl=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=Zc.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(Zc)},{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 rl=class extends Un{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}},il=On.define({combine(e){return Zn(e,{language:$c.TYPESCRIPT,timeout:150,widgetClass:rl,alwaysOn:!0},{})}}),al=On.define({combine(e){return Zn(e,{override:()=>[]},{})}}),ol=L.mark({class:`cm-ghostText`}),sl=Pn.define({create(e){return null},update(e,t){let n=t.state.facet(il);for(let e of t.effects){if(e.is(es)){let{changeSpecs:t,index:r}=e.value,i=t[r].map(e=>ol.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(ts)||e.is(ns))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)}),cl=Fn.define(),ll=Fn.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 ul(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 dl;function fl(e){if(!dl){dl={};for(let e of Object.values(X))typeof e!=`string`&&(dl[ul(e)]=e)}return dl[e]}var Z=class e extends Error{constructor(e,t=X.Unknown,n,r,i){super(pl(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 pl(e,t){return e.length?`[${ul(t)}] ${e}`:`[${ul(t)}]`}function ml(...e){let t=new Headers;for(let n of e)n.forEach((e,n)=>{t.append(n,e)});return t}function hl(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 gl(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 _l(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 vl=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)}},yl=function(e){return this instanceof yl?(this.v=e,this):new yl(e)},bl=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 yl?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])}},xl=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:yl(e[r](t)),done:!1}:i?i(t):t}:i}};function Sl(e){return bl(this,arguments,function*(){yield yl(yield*xl(vl(e)))})}var Cl=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)}},wl=function(e){return this instanceof wl?(this.v=e,this):new wl(e)},Tl=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:wl(e[r](t)),done:!1}:i?i(t):t}:i}},El=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 wl?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 Dl(e,t){return hl(e,n=>{switch(n.kind){case qc.Unary:return kl(t,e,n);case qc.ServerStreaming:return Al(t,e,n);case qc.ClientStreaming:return jl(t,e,n);case qc.BiDiStreaming:return Ml(t,e,n);default:return null}})}function Ol(e,t){return Dl(e,t)}function kl(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 Al(e,t,n){return function(r,i){return Nl(e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,Sl([r]),i?.contextValues),i)}}function jl(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=Cl(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 Ml(e,t,n){return function(r,i){return Nl(e.stream(t,n,i?.signal,i?.timeoutMs,i?.headers,r,i?.contextValues),i)}}function Nl(e,t){let n=(function(){return El(this,arguments,function*(){var n,r;let i=yield wl(e);(n=t?.onHeader)==null||n.call(t,i.header),yield wl(yield*Tl(Cl(i.message))),(r=t?.onTrailer)==null||r.call(t,i.trailer)})})()[Symbol.asyncIterator]();return{[Symbol.asyncIterator]:()=>({next:()=>n.next()})}}function Pl(...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(Il(this));for(let e of n)e.removeEventListener(`abort`,r)}return t}function Fl(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 Il(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 Ll(){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 Rl(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 zl(e,t){return t instanceof e?t:new e(t)}function Bl(e,t){function n(t){return t.done===!0?t:{done:t.done,value:zl(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 Vl(e,t){return t?.concat().reverse().reduce((e,t)=>t(e),e)??e}function Hl(e){let t=Object.assign({},e);return t.ignoreUnknownFields??=!0,t}function Ul(e,t,n,r){let i=t?Wl(e.I,r):Gl(e.I,n);return{parse:(t?Wl(e.O,r):Gl(e.O,n)).parse,serialize:i.serialize}}function Wl(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 Gl(e,t){let n=t?.textEncoder??new TextEncoder,r=t?.textDecoder??new TextDecoder,i=Hl(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 Kl=/^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$/i,ql=`application/proto`,Jl=`application/json`,Yl=`application/connect+proto`,Xl=`application/connect+json`;function Zl(e){let t=e?.match(Kl);if(t)return{stream:!!t[1],binary:!!t[3]}}function Ql(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=fl(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:Us.dec(t.value),debug:t.debug})}catch{throw n}}return a}function $l(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?Ql(n.error,r,t):void 0}}var eu=`Content-Type`,tu=`Content-Length`,nu=`Content-Encoding`,ru=`Accept-Encoding`,iu=`Connect-Timeout-Ms`,au=`Connect-Protocol-Version`,ou=`User-Agent`;function su(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 cu(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 lu(e,t,n,r,i){let a=new Headers(r??{});return n!==void 0&&a.set(iu,`${n}`),a.set(eu,e==qc.Unary?t?ql:Jl:t?Yl:Xl),a.set(au,`1`),i&&a.set(ou,`connect-es/1.6.1`),a}function uu(e,t,n,r){let i=r.get(eu),a=Zl(i);if(n!==200){let t=new Z(`HTTP ${n}`,su(n),r);if(e==qc.Unary&&a&&!a.binary)return{isUnaryError:!0,unaryError:t};throw t}let o={binary:t,stream:e!==qc.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 du=`application/`;function fu(e,t){return t?Us.enc(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``):encodeURIComponent(new TextDecoder().decode(e))}function pu(e,t,n){let r=`?connect=v1`,i=e.header.get(eu);i?.indexOf(du)===0&&(r+=`&encoding=`+encodeURIComponent(i.slice(12)));let a=e.header.get(nu);a!==null&&a!==`identity`&&(r+=`&compression=`+encodeURIComponent(a),n=!0),n&&(r+=`&base64=1`),r+=`&message=`+fu(t,n);let o=e.url+r,s=new Headers(e.header);return[au,eu,tu,nu,ru].forEach(e=>s.delete(e)),Object.assign(Object.assign({},e),{init:Object.assign(Object.assign({},e.init),{method:`GET`}),url:o,header:s})}function mu(e){let t=Vl(e.next,e.interceptors),[n,r,i]=gu(e);return t(Object.assign(Object.assign({},e.req),{message:zl(e.req.method.I,e.req.message),signal:n})).then(e=>(i(),e),r)}function hu(e){let t=Vl(e.next,e.interceptors),[n,r,i]=gu(e),a=Object.assign(Object.assign({},e.req),{message:Bl(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 gu(e){let{signal:t,cleanup:n}=Fl(e.timeoutMs),r=Pl(e.signal,t);return[r.signal,function(e){let i=Z.from(t.aborted?Il(t):e);return r.abort(i),n(),Promise.reject(i)},function(){n(),r.abort()}]}var _u;(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`})(_u||={}),Y.util.setEnumType(_u,`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 vu;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.SINGLE=1]=`SINGLE`,e[e.MULTI=2]=`MULTI`})(vu||={}),Y.util.setEnumType(vu,`exa.language_server_pb.LineType`,[{no:0,name:`LINE_TYPE_UNSPECIFIED`},{no:1,name:`LINE_TYPE_SINGLE`},{no:2,name:`LINE_TYPE_MULTI`}]);var yu;(function(e){e[e.UNSPECIFIED=0]=`UNSPECIFIED`,e[e.INLINE=1]=`INLINE`,e[e.BLOCK=2]=`BLOCK`,e[e.INLINE_MASK=3]=`INLINE_MASK`})(yu||={}),Y.util.setEnumType(yu,`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 bu=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)}},xu=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:tl},{no:2,name:`document`,kind:`message`,T:Ou},{no:3,name:`editor_options`,kind:`message`,T:nl},{no:5,name:`other_documents`,kind:`message`,T:Ou,repeated:!0},{no:7,name:`experiment_config`,kind:`message`,T:ku},{no:10,name:`model_name`,kind:`scalar`,T:9},{no:13,name:`multiline_config`,kind:`message`,T:bu}]);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{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:Au},{no:2,name:`completion_items`,kind:`message`,T:Pu,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)}},Cu=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:tl},{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)}},wu=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)}},Tu=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)}},Eu=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)}},Du=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)}},Ou=class e extends G{absolutePath=``;relativePath=``;text=``;editorLanguage=``;language=$c.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($c)},{no:6,name:`cursor_offset`,kind:`scalar`,T:4},{no:8,name:`cursor_position`,kind:`message`,T:Du},{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)}},ku=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(Yc),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)}},Au=class e extends G{state=_u.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(_u)},{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)}},ju=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:Du},{no:4,name:`end_position`,kind:`message`,T:Du}]);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=``;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)}},Nu=class e extends G{text=``;offset=K.zero;type=yu.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(yu)},{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)}},Pu=class e extends G{completion;suffix;range;source=Qc.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:el},{no:5,name:`suffix`,kind:`message`,T:Mu},{no:2,name:`range`,kind:`message`,T:ju},{no:3,name:`source`,kind:`enum`,T:Y.getEnumType(Qc)},{no:8,name:`completion_parts`,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)}},Fu={typeName:`exa.language_server_pb.LanguageServerService`,methods:{getCompletions:{name:`GetCompletions`,I:xu,O:Su,kind:qc.Unary},acceptCompletion:{name:`AcceptCompletion`,I:Cu,O:wu,kind:qc.Unary},getAuthToken:{name:`GetAuthToken`,I:Tu,O:Eu,kind:qc.Unary}}};function Iu(){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 Lu=function(e){return this instanceof Lu?(this.v=e,this):new Lu(e)},Ru=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 Lu?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 zu(e){Iu();let t=e.useBinaryFormat??!1;return{async unary(n,r,i,a,o,s,c){let{serialize:l,parse:u}=Ul(r,t,e.jsonOptions,e.binaryOptions);return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await mu({interceptors:e.interceptors,signal:i,timeoutMs:a,req:{stream:!1,service:n,method:r,url:Rl(e.baseUrl,n,r),init:{method:`POST`,credentials:e.credentials??`same-origin`,redirect:`error`,mode:`cors`},header:lu(r.kind,t,a,o,!1),contextValues:c??Ll(),message:s},next:async i=>{let a=e.useHttpGet===!0&&r.idempotency===Jc.NoSideEffects,o=null;a?i=pu(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}=uu(r.kind,t,s.status,s.headers);if(c)throw Ql(await s.json(),ml(...cu(s.headers)),d);let[f,p]=cu(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(),Hl(e.jsonOptions)),trailer:p}}})},async stream(n,r,i,a,o,s,c){let{serialize:l,parse:u}=Ul(r,t,e.jsonOptions,e.binaryOptions);function d(e,t,n,r){return Ru(this,arguments,function*(){let i=gl(e).getReader(),a=!1;for(;;){let e=yield Lu(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=$l(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 Lu(u(o))}if(`throwIfAborted`in r&&r.throwIfAborted(),!a)throw`missing EndStreamResponse`})}async function f(e){if(r.kind!=qc.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 _l(0,l(t.value))}return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await hu({interceptors:e.interceptors,timeoutMs:a,signal:i,req:{stream:!0,service:n,method:r,url:Rl(e.baseUrl,n,r),init:{method:`POST`,credentials:e.credentials??`same-origin`,redirect:`error`,mode:`cors`},header:lu(r.kind,t,a,o,!1),contextValues:c??Ll(),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(uu(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 Bu=Ol(Fu,zu({baseUrl:`https://web-backend.codeium.com`,useBinaryFormat:!0})),Vu;try{Vu=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))}Vu=e()}async function Hu({text:e,cursorOffset:t,config:n,otherDocuments:r}){return await Bu.getCompletions({metadata:{ideName:`web`,ideVersion:`0.0.5`,extensionName:`@valtown/codemirror-codeium`,extensionVersion:`1.0.0`,apiKey:n.apiKey,sessionId:Vu,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}-${Vu}`}})}function Uu(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 Wu(e,t){let n=e.state.facet(il),{override:r}=e.state.facet(al),i=await r(),a=e.state,o=a.selection.main.head,s=a.doc.toString();try{let r=await Hu({text:s,cursorOffset:o,config:n,otherDocuments:i});if(!r||r.completionItems.length===0||!((t===void 0||o===t)&&yr(e.state)!==`active`&&e.hasFocus))return;let c=Uu(r),l=c.at(0);if(!l)return;let u=Sn.of(l,a.doc.length),d=u.invert(a.doc);e.dispatch({changes:u,effects:es.of({index:0,reverseChangeSet:d,changeSpecs:c}),annotations:[ll.of(null),cl.of(null),Wn.addToHistory.of(!1)]})}catch(e){console.warn(`copilot completion failed`,e),await new Promise(e=>setTimeout(e,300))}}function Gu(e){return e.docChanged&&!e.transactions.some(e=>e.effects.some(e=>e.is(ts)||e.is(ns)))}function Ku(e){if(!e.view.hasFocus||e.state.field(sl)||yr(e.state)===`active`)return!0;for(let t of e.transactions)if(t.annotation(cl)!==void 0)return!0}function qu(){let e=null,t=0;return R.updateListener.of(n=>{let r=n.view.state.facet(il);if(!r.alwaysOn||!Gu(n)||(e&&clearTimeout(e),Ku(n)))return;let i=n.state.selection.main.head;r.shouldComplete&&!r.shouldComplete(new Sr(n.view.state,i,!1))||(e=setTimeout(async()=>{i===t&&await Wu(n.view,t)},r.timeout),t=i)})}function Ju(e){let t=e.state.field(sl);if(!t)return!1;let n=t.reverseChangeSet?.invert(e.state.doc);e.dispatch({changes:t.reverseChangeSet,effects:ts.of(null),annotations:[ll.of(null),cl.of(null),Wn.addToHistory.of(!1)]});let r=0;return n?.iterChangedRanges((e,t,n,i)=>{r=i}),e.dispatch({changes:n,selection:Rn.cursor(r),annotations:[cl.of(null),Wn.addToHistory.of(!0)]}),!0}var Yu=e=>{let{state:t}=e,n=t.field(sl);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=Sn.of(n.reverseChangeSet,t.doc.length).compose(Sn.of(a,o.length)),c=Sn.of(a,o.length).invert(o);return e.dispatch({changes:s,effects:es.of({index:i,reverseChangeSet:c,changeSpecs:r}),annotations:[ll.of(null),cl.of(null),Wn.addToHistory.of(!1)]}),!0};function Xu(e){let t=e.state.field(sl);return t&&e.dispatch({changes:t.reverseChangeSet,effects:ns.of(null),annotations:[ll.of(null),cl.of(null),Wn.addToHistory.of(!1)]}),!1}function Zu(e,t){return e.state.field(sl)?t===`Tab`?Ju(e):Xu(e):!1}function Qu(e){let t=!1,n=e.state.selection.asSingle().ranges.at(0)?.head,r=e.state.field(sl);return n!==void 0&&r?(r.decorations?.between(n,n,()=>{t=!0}),t):!1}function $u(){return R.domEventHandlers({keydown(e,t){return e.key===`]`&&e.ctrlKey?!1:e.key!==`Shift`&&e.key!==`Control`&&e.key!==`Alt`&&e.key!==`Meta`&&Zu(t,e.key)},mouseup(e,t){let n=e.target;return n.nodeName===`BUTTON`&&n.dataset.action===`codeium-cycle`?(Yu(t),e.stopPropagation(),e.preventDefault(),!0):Qu(t)?Ju(t):Xu(t)}})}function ed(){return Ln.of([{key:`Ctrl-]`,run:Yu}])}function td(){return R.updateListener.of(e=>{e.focusChanged&&Xu(e.view)})}function nd(e){return[il.of(e),sl,Xn.highest(ed()),Xn.highest(td()),Xn.high($u()),qu()]}var rd=De();function id({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 ad=new An,od=Gt.get(`@github/copilot-language-server`),sd={delay:300,includeKeymap:!0,events:{shouldShowSuggestion:e=>e.hasFocus,beforeSuggestionFetch:e=>e.hasFocus}},cd=e=>{let t=[];return e.copilot===`codeium`&&e.codeium_api_key&&t.push(nd({apiKey:e.codeium_api_key,language:$c.PYTHON}),al.of({override:async()=>[{text:Be(``),language:$c.PYTHON,editorLanguage:`python`}]})),e.copilot===`github`&&t.push(Ra({...sd,fetchFn:async(e,t,n)=>{let r=e.selection.main.head;if(!Lt()||!n.hasFocus||e.doc.length===0)return``;await new Promise(e=>setTimeout(e,20));let i=e.doc.toString(),a=ld(e,Be(i)),o=await Rt().getCompletion(a);return r===n.state.selection.main.head?ud(o,a.position,e):(Gt.debug(`ignoring response because of new position`),``)}})),e.copilot===`custom`&&t.push(Ra({...sd,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(N).type,s=await an.post(`/ai/inline_completion`,{prefix:i,suffix:a,language:o});return r===n.state.selection.main.head?(s=id({response:s,prefix:i,suffix:a}),s):(Gt.debug(`ignoring response because of new position`),``)}})),[...t,Xn.highest(Ln.of([{key:`Escape`,run:e=>{let t=Fa(e);return!p(e)&&t}}])),ad.of(zt())]};function ld(e,t){let n=e.doc.toString(),r=t.split(`
|
|
12
12
|
`).length-n.split(`
|
|
13
|
-
`).length,i=dd(e.doc,e.selection.main.head);return i.line+=r,{textDocument:{uri:`file://${
|
|
13
|
+
`).length,i=dd(e.doc,e.selection.main.head);return i.line+=r,{textDocument:{uri:`file://${Bt}`,version:`replace_me`},position:i,context:{triggerKind:rd.InlineCompletionTriggerKind.Automatic},formattingOptions:{tabSize:e.tabSize,insertSpaces:!0}}}function ud(e,t,n){if(!e)return od.debug(`No response from copilot`),``;let r=Array.isArray(e)?e[0]:e.items[0];if(!r)return od.debug(`No response from copilot`),``;let{insertText:i,range:a}=r,o=String(i);if(!a)return od.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 dd(e,t){let n=e.lineAt(t);return{line:n.number-1,character:t-n.from}}function fd(e){return Jt(`create`in e,`Expected query to have a "create" method`),e}var pd=ht({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 md(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(pd,{type:`setFind`,find:n}),o.set(pd,{type:`setCurrentView`,view:e,range:{from:t.from,to:t.to}})):o.set(pd,{type:`setCurrentView`,view:e,range:{from:0,to:0}})}return o.get(pd).isOpen?(o.set(pd,{type:`setIsOpen`,isOpen:!1}),requestAnimationFrame(()=>{o.set(pd,{type:`setIsOpen`,isOpen:!0})}),!0):(o.set(pd,{type:`setIsOpen`,isOpen:!0}),!0)}function hd(){return o.get(pd).isOpen?(o.set(pd,{type:`setIsOpen`,isOpen:!1}),!0):!1}var gd=I.define();function _d(){let e=o.get(pd),t=rt();for(let n of t)n.state.readOnly||n.dispatch({effects:gd.of(new cr({search:e.findText,caseSensitive:e.caseSensitive,regexp:e.regexp,replace:e.replaceText,wholeWord:e.wholeWord}))})}function vd(){let e=rt();for(let t of e)t.state.readOnly||t.dispatch({effects:gd.of(new cr({search:``}))})}var yd=Pn.define({create(){let e=o.get(pd);return fd(new cr({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(gd)&&(e=fd(n.value).create());return e}}),bd=L.mark({class:`cm-searchMatch`}),xd=L.mark({class:`cm-searchMatch cm-searchMatch-selected`}),Sd=Qn.fromClass(class{decorations;view;constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(yd))}update(e){let t=e.state.field(yd);(t!==e.startState.field(yd)||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 Vn,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?xd:bd)})}return n.finish()}},{decorations:e=>e.decorations}),Cd=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 wd(e){return[Ln.of([{key:`Escape`,preventDefault:!1,run:hd},{key:e.getHotkey(`cell.selectNextOccurrence`).key,preventDefault:!0,run:or},{key:e.getHotkey(`cell.findAndReplace`).key,preventDefault:!0,run:md}]),lr(),Sd,yd,Cd]}var Td=L.mark({class:`underline`}),Ed=I.define(),Dd=I.define(),Od=I.define(),kd=Pn.define({create(){return L.none},update(e,t){let n=e.map(t.changes);for(let r of t.effects)r.is(Ed)?n=e.update({add:[Td.range(r.value.from,r.value.to)]}):r.is(Dd)?n=e.update({add:[h.range(r.value.from,r.value.to)]}):r.is(Od)&&(n=L.none);return n},provide:e=>R.decorations.from(e)}),Ad=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(w,!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:Dd.of(this.hoveredRange)});return}let r=kn(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:Ed.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:Od.of(null)}),null)}},jd=e=>Qn.define(t=>new Ad(t,e));function Md(){return[kd,jd(e=>{oe(e)}),R.baseTheme({".underline":{textDecoration:`underline`,cursor:`pointer`,color:`var(--link)`}})]}function Nd(){return[R.domEventHandlers({drop:(e,t)=>{let n=e.dataTransfer?.files[0];if(n?.type.startsWith(`text/`))return e.preventDefault(),Xe(t,n),!0;if(n?.type.startsWith(`image/`))return e.preventDefault(),ke(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 Pd(){return[R.domEventHandlers({paste:(e,t)=>{let n=e.clipboardData?.getData(`text/plain`);if(!n||!Fd(n))return!1;let{setup:r,cells:i}=Id(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 Fd(e){return/@app\.cell|@app\.function|\bapp\.setup\b/.test(e)}function Id(e){if(!Fd(e))return{setup:null,cells:[]};let t=[],n=[],r=hi.parse(e),i=(t,n)=>{let r=e.lastIndexOf(`
|
|
14
14
|
`,t-1)+1;return Ld(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 Ld(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 Rd(e,t,n,r){return r!==`{`||t!==n||!An(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 zd(){return R.inputHandler.of(Rd)}function Bd(e){let{showPlaceholder:t,enableAI:n}=e;return t?`marimo-import`:n?`ai`:`none`}var Vd=`cm-tooltip-portal`;function Hd(e){if(e==null)return document.querySelector(`#App`)??void 0;let t=document.querySelector(e);if(t==null)return;let n=t.querySelector(`:scope > .${Vd}`);if(n!=null)return n;let r=document.createElement(`div`);return r.className=`${Vd} not-prose contents`,t.append(r),r}var Ud=e=>{let{cellId:t,keymapConfig:n,hotkeys:r,enableAI:i,cellActions:a,completionConfig:o,lspConfig:s,diagnosticsConfig:c,displayConfig:l,inlineAiTooltip:u}=e,d=Bd(e);return[It(n,r),Nd(),Pd(),Xo(),ve({cellId:t,completionConfig:o,hotkeys:r,placeholderType:d,lspConfig:s,diagnosticsConfig:c}),Ie({cellId:t,hotkeys:r,cellActions:a,keymapConfig:n}),Gd(e),Md(),c?.enabled?cr():[],i&&u?[qa({prompt:e=>ao({prompt:e.prompt,selection:e.selection,codeBefore:e.codeBefore,codeAfter:e.codeAfter,language:st(e.editorView)})}),Va.of({hideOnBlur:!0})]:[],fe(t,l.reference_highlighting??!0),qo(t,l.code_lens??!0)]},Wd=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()!==``&&vr(e)},Gd=e=>{let{theme:t,hotkeys:n,completionConfig:r,acceptCompletionOnEnter:i,cellId:a,lspConfig:o,diagnosticsConfig:s,tooltipParentSelector:c}=e,l=Bd(e),u=r.auto_close_pairs!==!1;return[R.lineWrapping,qn(),Kn(),tr(),Ln(),wn(),Tn(),Sn(),On({position:`fixed`,parent:Hd(c)}),Ke(),t===`dark`?un:ln,ae(o),cd(r),er(),zd(),u?yr():[],$o(i),u?Zn.high(Rn.of(hr)):[],Yn(),Nn(),Mn.of(` `),Bn(Un,{fallback:!0}),Rn.of(En),Ee({placeholderType:l,completionConfig:r,hotkeys:n,cellId:a,lspConfig:{...o,diagnostics:s}}),he.of(or()),Vn.allowMultipleSelections.of(!0),wd(n),Rn.of([{key:`Tab`,run:e=>xr(e)||Wd(e)||rr(e),preventDefault:!0},{key:n.getHotkey(`completion.moveDown`).key,run:e=>br(e.state)!==null&&(_r(!0)(e),!0),preventDefault:!0},{key:n.getHotkey(`completion.moveUp`).key,run:e=>br(e.state)!==null&&(_r(!1)(e),!0),preventDefault:!0}]),Rn.of([...dr,ar])]},Kd=(e=>!e||e instanceof WebAssembly.Module?e:typeof e==`object`&&`default`in e?e.default??e:e)(Ki),qd=e=>{Qi(e),typeof Xi==`function`&&Xi(),Jd(qi)};function Jd(e){typeof e.__wbindgen_start==`function`&&e.__wbindgen_start()}if(Kd&&Kd.__wbindgen_start)qd(Kd);else if(`Bun`in globalThis){let e;if(Kd instanceof WebAssembly.Module)({instance:e}=await WebAssembly.instantiate(Kd,{"./loro_wasm_bg.js":qi}));else{let t=Bun.pathToFileURL(Kd);({instance:e}=await WebAssembly.instantiateStreaming(fetch(t),{"./loro_wasm_bg.js":qi}))}qd(e.exports)}else{let e=Kd instanceof WebAssembly.Module?Kd:await pi(()=>import(`./loro_wasm_bg-BzjWitFM.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);qd(n.exports??n)}var Yd=[`Map`,`Text`,`List`,`Tree`,`MovableList`,`Counter`];function Xd(e){return e.startsWith(`cid:`)}function Zd(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return typeof t!=`object`||!t||typeof t.kind!=`function`?!1:Yd.includes(e.kind())}var Qd=class{constructor(e,t=3e4){this.listeners=new Set,this.inner=new Zi(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))}};Yi.prototype.toJsonWithReplacer=function(e){let t=new Set,n=this,r=(r,a)=>{if(typeof a==`string`&&Xd(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(Zd(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(Zd(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 $d=Symbol(`loro.callPendingEventsWrapped`);function ef(e,t){let n=Object.getOwnPropertyDescriptor(e,t);if(!n||typeof n.value!=`function`)return;let r=n.value;if(r[$d])return;let i=function(...e){let t;try{return t=r.apply(this,e),t}finally{t&&typeof t.then==`function`?t.finally(()=>{Ji()}):Ji()}};i[$d]=!0,Object.defineProperty(e,t,{...n,value:i})}function tf(e,t){for(let n of t)ef(e,n)}tf(Yi.prototype,[`setDetachedEditing`,`attach`,`detach`,`fork`,`forkAt`,`checkoutToLatest`,`checkout`,`commit`,`getCursorPos`,`revertTo`,`export`,`exportJsonUpdates`,`exportJsonInIdSpan`,`importJsonUpdates`,`import`,`importUpdateBatch`,`importBatch`,`travelChangeAncestors`,`getChangedContainersIn`,`diff`,`applyDiff`,`setPeerId`]),tf(Ui.prototype,[`set`,`delete`,`apply`,`removeOutdated`]),tf(Gi.prototype,[`undo`,`redo`]);var nf=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`}});In.define();var rf=I.define(),af=Fn.define({create(){return{remoteCursors:new Map,isCheckout:!1}},update(e,t){for(let n of t.effects)if(n.is(rf))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}}),of=e=>{let t=e.transactions.flatMap(e=>e.effects).filter(e=>e.is(rf));return e.docChanged||e.viewportChanged||t.length>0},sf=()=>Dn({above:!0,class:`loro-cursor-layer`,update:of,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(af);return n?[]:[...t.values()].flatMap(t=>{let n=zn.cursor(t.cursor.anchor);return lf.createCursor(e,n,t.user?.name||`unknown`,t.user?.colorClassName||``)})}}),cf=()=>Dn({above:!1,class:`loro-selection-layer`,update:of,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(af);return n?[]:[...t.entries()].filter(([,e])=>e.cursor.head!==void 0&&e.cursor.anchor!==e.cursor.head).flatMap(([,t])=>{let n=zn.range(t.cursor.anchor,t.cursor.head);return Jn.forRange(e,`loro-selection ${t.user?.colorClassName||``}`,n)})}}),lf=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===Xn.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)}},uf=(e,t,n,r)=>{let i=[],{updated:a,added:o}=n;for(let n of[...a,...o]){let a=df(e,t,n,r);a&&i.push(a)}return i},df=(e,t,n,r)=>{let i=t.getAllStates()[n];if(!i||n===e.peerIdStr||i.scopeId!==r)return;if(i.type===`delete`)return rf.of({type:`delete`,peer:i.uid,scopeId:i.scopeId});let a=$i.decode(i.cursor.anchor),o=e.getCursorPos(a)?.offset??0,s=o;if(i.cursor.head){let t=$i.decode(i.cursor.head);s=e.getCursorPos(t)?.offset??0}return rf.of({type:`update`,peer:i.uid,scopeId:i.scopeId,cursor:{anchor:o,head:s},user:i.user})},ff=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=df(this.doc,this.awareness,t,this.scopeId);n&&e.push(n)}this.view.dispatch({effects:e})}else e.by===`checkout`&&this.view.dispatch({effects:[rf.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=mf({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})}},pf=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:uf(this.doc,this.awareness,e,this.scopeId)})};this._awarenessListener=i,this.awareness.addListener(i)}destroy(){this._awarenessListener&&this.awareness.removeListener(this._awarenessListener)}},mf=({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}},hf=[`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)`],gf=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 hf[Math.abs(t)%hf.length]}return hf[e%hf.length]},Q=Kt.get(`rtc`),_f=Q.get(`awareness`).disabled(),vf=`awareness:`;function yf(e,t){let n=new TextEncoder().encode(e);return new Uint8Array([...n,...t])}function bf(e,t){return new TextDecoder().decode(e.slice(0,t.length))===t}function xf(e,t){return e.slice(t.length)}var Sf=r(void 0),$=new Yi,Cf=new Qd($.peerIdStr),wf=pr(()=>{Q.debug(`creating websocket`);let e=rn().getWsSyncURL(_i()).toString(),t=new ta(e,void 0,{maxRetries:10,debug:!1,startClosed:!0,connectionTimeout:1e4});return Promise.resolve().then(async()=>{await $t(),Xt()===`edit`&&t.reconnect()}),t.addEventListener(`message`,async e=>{let t=await e.data.arrayBuffer(),n=new Uint8Array(t);if(bf(n,vf)){let e=xf(n,vf);Cf.apply(e),_f.debug(`applied awareness update`);return}$.import(n),Q.debug(`imported doc change. new doc:`,$.toJSON()),o.get(Sf)!==$&&o.set(Sf,$)}),t.addEventListener(`open`,()=>{Q.debug(`websocket open`)}),t.addEventListener(`close`,e=>{Q.warn(`websocket close`,e),o.get(Sf)===$&&o.set(Sf,void 0)}),t});Pe()&&wf(),$.subscribeLocalUpdates(e=>{Q.debug(`local update, sending to server`),wf().send(e)}),Cf.addListener((e,t)=>{let n=[...e.added,...e.removed,...e.updated];t===`local`&&(_f.debug(`awareness changes`,n),wf().send(yf(vf,Cf.encode(n))))});function Tf(e,t,n=``){if(Zt())return{extension:[],code:n};let r=$.getByPath(`codes/${e}`)!==void 0,i=$.getMap(`codes`).getOrCreateContainer(e,new Wi);return r||(Q.log(`initializing code for new cell`,n),i.insert(0,n)),{code:n.toString(),extension:[Ef(e),Df(e),Of($,Cf,{get name(){return o.get(et)||`Anonymous`},get colorClassName(){return gf(this.name)}},()=>i,e),Re($,[`codes`,e],()=>i)]}}function Ef(e){let t=(e,t)=>{let n=e.state.field(M).type,r=t.toString();r&&r!==n&&(Q.debug(`[incoming] setting language type: ${n} -> ${r}`),N(e,{language:r,keepCodeAsIs:!0}))},n=(e,t)=>{let n=e.state.field(Oe),r=t.toJSON();a(n,r)||e.dispatch({effects:[ct.of(r)],annotations:[Ye.of(!0)]})};return $n.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}Yt(a instanceof Wi,`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}Yt(o instanceof ea,`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 Df(e){let t=$.getMap(`languages`).getOrCreateContainer(e,new Wi),n=$.getMap(`language_metadata`).getOrCreateContainer(e,new ea);return R.updateListener.of(e=>{let r=t.toString()!==``;if(!e.docChanged&&r)return;if(!r){let r=mt(e.state).type;N(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(Oe));let i=e.state.field(Oe);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(Ye)){for(let e of r.effects)if(e.is(ft)&&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(ct)||e.is(qe)){let t=e.value;e.is(qe)?(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 Of(e,t,n,r,i,a){let o=`loro:cell:${i}`;return[af,sf(),cf(),$n.define(i=>new ff(i,e,n,t,r,o,a)),$n.define(n=>new pf(n,e,t,o)),nf]}var kf=S,Af=e=>{let t=(0,V.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}=Tr(),[f,p]=(0,H.useState)(l),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=[],t[0]=m):m=t[0];let[g,_]=(0,H.useState)(m),[v,y]=(0,H.useState)(!1),b=(0,H.useRef)(null),x=(0,H.useRef)(!1),S,C;t[1]===l?(S=t[2],C=t[3]):(S=()=>{p(l)},C=[l],t[1]=l,t[2]=S,t[3]=C),(0,H.useEffect)(S,C);let w;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(w=()=>{y(!0)},t[4]=w):w=t[4];let ee=w,T;t[5]!==l||t[6]!==c?(T=e=>{e.relatedTarget?.closest(`.filename-input`)||(y(!1),c&&p(l))},t[5]=l,t[6]=c,t[7]=T):T=t[7];let te=T,E;t[8]===f?E=t[9]:(E=gi.dirname(f||``),t[8]=f,t[9]=E);let ne=E,D=gi.basename(f||``),O=g.filter(e=>gi.basename(e.path).startsWith(D)),k;t[10]!==ne||t[11]!==v||t[12]!==d?(k=async()=>{if(!v){_([]);return}let e=await d({path:ne});_(e.files)},t[10]=ne,t[11]=v,t[12]=d,t[13]=k):k=t[13];let A;t[14]!==ne||t[15]!==v?(A=[ne,v],t[14]=ne,t[15]=v,t[16]=A):A=t[16];let{isPending:re}=xi(k,A),j=jf(f,g,l),ie=(j||O.length>0)&&(0,U.jsxs)(oe,{className:`font-mono`,children:[!re&&(0,U.jsx)(pt,{children:`No files`}),j&&(0,U.jsxs)(dt,{variant:`success`,className:`py-2 px-3`,onSelect:()=>{j&&(x.current=!0,o(j),b.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:gi.basename(j)})]})]},`_rename_`),O.map(e=>{let t=e.isDirectory?`directory`:Zr(e.path),n=Qr[t];return(0,U.jsxs)(dt,{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`}),` `,gi.basename(e.path)]},e.path)})]}),ae=Math.max(20,f?.length||r?.length||0)*10,M=v?f||``:l||``,se;t[17]!==u||t[18]!==ae?(se=u?{maxWidth:ae}:void 0,t[17]=u,t[18]=ae,t[19]=se):se=t[19];let N;t[20]===s?N=t[21]:(N=pn(s,`w-full px-4 py-1 my-1 h-9 font-mono text-foreground/60`),t[20]=s,t[21]=N);let ce;t[22]!==r||t[23]!==M||t[24]!==se||t[25]!==N?(ce=(0,U.jsx)(kf,{children:(0,U.jsx)(h,{"data-testid":`dir-completion-input`,tabIndex:-1,rootClassName:`border-none justify-center px-1`,spellCheck:`false`,value:M,onKeyDown:Mf,icon:null,ref:b,onValueChange:p,placeholder:r,autoComplete:`off`,style:se,className:N})}),t[22]=r,t[23]=M,t[24]=se,t[25]=N,t[26]=ce):ce=t[26];let le=ie&&`group-focus-within:block`,ue;t[27]===le?ue=t[28]:(ue=pn(`p-0 w-full min-w-80 max-w-80vw hidden`,le),t[27]=le,t[28]=ue);let P;t[29]!==ie||t[30]!==ue?(P=(0,U.jsx)(xe,{side:`bottom`,className:ue,portal:!1,children:ie}),t[29]=ie,t[30]=ue,t[31]=P):P=t[31];let de;t[32]!==ce||t[33]!==P?(de=(0,U.jsxs)(oe,{children:[ce,P]}),t[32]=ce,t[33]=P,t[34]=de):de=t[34];let fe;t[35]!==te||t[36]!==de?(fe=(0,U.jsx)(_t,{onFocus:ee,onBlur:te,shouldFilter:!1,id:`filename-input`,className:`bg-transparent group filename-input`,children:de}),t[35]=te,t[36]=de,t[37]=fe):fe=t[37];let F;return t[38]!==v||t[39]!==fe?(F=(0,U.jsx)(fn,{children:(0,U.jsx)(ze,{open:v,modal:!1,children:fe})}),t[38]=v,t[39]=fe,t[40]=F):F=t[40],F};function jf(e,t,n){if(e&&!e.endsWith(`/`)&&((Me(`markdown`)?new Set([`py`,`md`,`markdown`,`qmd`]):new Set([`py`])).has(gi.extension(e))||(e=e.endsWith(`.`)?`${e}py`:e.endsWith(`.p`)?`${e}y`:`${e}.py`),!t.some(t=>t.path===e||gi.basename(t.path)===e)&&!(n&&(n===e||gi.basename(n)===e))))return e}function Mf(e){e.key===`Escape`&&e.currentTarget.blur()}var Nf=e=>{let t=(0,V.c)(33),n=()=>{vn(new Blob([r()],{type:`text/plain`}),`${e.proposedName}.json`)},r=c(If),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)(ii,{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)(ti,{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)(xn,{"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)(xn,{"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)(ei,{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)(ni,{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},Pf=e=>{let t=(0,V.c)(12),{filename:n,needsSave:r}=e,{openModal:i,closeModal:a}=ri(),o;t[0]===n?o=t[1]:(o=n===null?`app`:gi.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)(Nf,{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;Ut(`global.save`,l);let u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=Ni(`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)(ci,{strokeWidth:1.5,size:18}),t[8]=f):f=t[8];let p;return t[9]!==l||t[10]!==d?(p=(0,U.jsx)(yn,{content:u,children:(0,U.jsx)(na,{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 Ff(e){return{id:e.id,name:e.name,code:e.code,code_hash:null,config:{column:0,...e.config}}}function If(){let e=Le(),t=le(e),n={version:`1`,metadata:{marimo_version:dn()},cells:t.map(Ff)};return JSON.stringify(n,null,2)}var Lf=r(void 0),Rf=r(e=>{let t=e(Lf);return zf({state:e(Ce),layout:e(cn),lastSavedNotebook:t})});function zf({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!fr(s,n.codes)||!fr(l,n.names)||!a(c,n.configs)||!a(t.selectedLayout,n.layout.selectedLayout)||!a(t.layoutData,n.layout.layoutData)}function Bf(e){let t=(0,V.c)(21),{codes:n,cellConfigs:r,config:i,connStatus:a,cellNames:o,needsSave:s,kioskMode:c,onSave:l}=e,u=(0,H.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(Vf).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===en.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,H.useEffect)(_,v)}function Vf(e){return JSON.stringify(e)}var Hf=Promise.resolve();function Uf(e){let t=Hf.then(e);return Hf=t.then(()=>void 0,()=>void 0),t}var Wf=e=>{let t=(0,V.c)(15),{kioskMode:n}=e,r=ji(),a=i(Rf),o=i(an).state===en.CLOSED,{saveOrNameNotebook:s,saveIfNotebookIsPersistent:c}=Gf(),l;t[0]!==n||t[1]!==c?(l={onSave:c,kioskMode:n},t[0]=n,t[1]=c,t[2]=l):l=t[2],Xf(l),ra();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),Jt(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(Ut(`global.save`,s),o){let e;return t[7]!==r||t[8]!==a?(e=(0,U.jsx)(Pf,{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=Ni(`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)(ci,{strokeWidth:1.5,size:18}),t[11]=h):h=t[11];let g;return t[12]!==f||t[13]!==m?(g=(0,U.jsx)(yn,{content:p,children:(0,U.jsx)(na,{"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 Gf(){let e=(0,V.c)(21),{sendSave:t}=Tr(),{openModal:r,closeModal:i,openAlert:a}=ri(),o=l(Lf),s=Mi(),u=n(),d;e[0]!==a||e[1]!==t||e[2]!==o||e[3]!==u?(d=(e,n)=>Uf(async()=>{let r=u.get(an),i=u.get(Pt);if(u.get(Qt))return;if(r.state!==en.OPEN){a(`Failed to save notebook: not connected to a kernel.`);return}if(Kt.log(`saving to `,e),n&&i.format_on_save&&(Kt.log(`formatting notebook (onSave)`),await ut()),le(Le()).length===0)return;let s=await ke(async()=>{let n=Le(),r=le(n),i=r.map(Jf),a=r.map(qf),o=r.map(Kf),s=Ae(n),c=u.get(cn);return await t({cellIds:i,codes:a,names:o,filename:e,configs:s,layout:Or(),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(Te),r=u.get(an);Yf(n)&&r.state===en.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(Te),t=u.get(an);m(!0),!Yf(e)&&t.state!==en.CLOSED&&r((0,U.jsx)($f,{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 Kf(e){return e.name}function qf(e){return e.code}function Jf(e){return e.id}function Yf(e){return e!==null&&!e.startsWith(`/tmp/`)&&!e.startsWith(`/var/folders`)&&!e.includes(`AppData\\Local\\Temp`)}function Xf(e){let n=(0,V.c)(14),r=i(Pt),a=E(),[o]=t(an),s=i(Rf),c,l;if(n[0]!==a){let e=le(a);c=e.map(Qf),l=e.map(Zf),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=Ae(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],Bf(p)}function Zf(e){return e.name}function Qf(e){return e.code}var $f=e=>{let t=(0,V.c)(17),{onClose:n,onSave:r}=e,[i,a]=(0,H.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)(ii,{children:`Save notebook`}),t[3]=c):c=t[3];let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,U.jsx)(hn,{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)(Af,{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)(xn,{"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)(xn,{"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)(ei,{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)(ni,{children:[c,u,m]}),t[14]=u,t[15]=m,t[16]=h):h=t[16],h};function ep(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var tp={modified:{doc:``},original:{doc:``}},np=(0,H.createContext)(tp);function rp(e,t){return z({},e,t,{modified:z({},e.modified,t.modified),original:z({},e.original,t.original)})}var ip=()=>(0,H.useContext)(np),ap=e=>{var{children:t,theme:n}=e,[r,i]=(0,H.useReducer)(rp,z({},tp,{theme:n}));return(0,H.useEffect)(()=>i({theme:n}),[n]),(0,U.jsx)(np.Provider,{value:z({},r,{dispatch:i}),children:t})},op=[`extensions`,`value`,`selection`,`onChange`],sp=e=>{var{extensions:t=[],value:n,selection:r,onChange:i}=e,a=Ei(e,op),{theme:o,dispatch:s}=ip(),c=Di(z({},a,{theme:o}));return(0,H.useEffect)(()=>s({original:{doc:n,selection:r,extensions:[...c,...t]},originalExtension:{onChange:i,option:a,extension:[t]}}),[e]),null};sp.displayName=`CodeMirrorMerge.Original`;var cp=[`extensions`,`value`,`selection`,`onChange`],lp=e=>{var{extensions:t=[],value:n,selection:r,onChange:i}=e,a=Ei(e,cp),{theme:o,dispatch:s}=ip(),c=Di(z({},a,{theme:o}));return(0,H.useEffect)(()=>{s({modified:{doc:n,selection:r,extensions:[...c,...t]},modifiedExtension:{onChange:i,option:a,extension:[t]}})},[e]),null};lp.displayName=`CodeMirrorMerge.Modified`;var up=[`className`,`children`,`orientation`,`revertControls`,`highlightChanges`,`gutter`,`collapseUnchanged`,`destroyRerender`,`renderRevertControl`,`diffConfig`,`root`],dp=[`modified`,`modifiedExtension`,`original`,`originalExtension`,`theme`,`dispatch`],fp=H.forwardRef((e,t)=>{var{className:n,children:r,orientation:i,revertControls:a,highlightChanges:o,gutter:s,collapseUnchanged:c,destroyRerender:l=!0,renderRevertControl:u,diffConfig:d,root:f}=e,p=Ei(e,up),m=ip(),{modified:h,modifiedExtension:g,original:_,originalExtension:v,theme:y,dispatch:b}=m,x=Ei(m,dp),S=(0,H.useRef)(null),C=(0,H.useRef)(),w={orientation:i,revertControls:a,highlightChanges:o,gutter:s,collapseUnchanged:c,renderRevertControl:u,diffConfig:d,root:f};(0,H.useImperativeHandle)(t,()=>({container:S.current,view:C.current,modified:h,original:_,config:z({a:_,b:h,parent:S.current},w)}),[S,C,h,_,w]);var ee=R.updateListener.of(e=>{if(e.docChanged&&typeof v?.onChange==`function`){var t=e.state.doc.toString();v?.onChange(t,e)}}),T=R.updateListener.of(e=>{if(e.docChanged&&typeof g?.onChange==`function`){var t=e.state.doc.toString();g?.onChange(t,e)}});return(0,H.useEffect)(()=>{!C.current&&S.current&&v&&g&&(C.current=new Ii(z({a:z({},_,{extensions:[...v?.extension||[],...Di(z({},v?.option,{theme:y})),ee]}),b:z({},h,{extensions:[...g?.extension||[],...Di(z({},g?.option,{theme:y})),T]}),parent:S.current},w)),b({view:C.current}))},[C,S,v,g]),(0,H.useEffect)(()=>{if(_&&_.doc&&C.current){var e=C.current?.a.state.doc.toString();if(e!==_.doc){var t;(t=C.current)==null||t.a.dispatch({changes:{from:0,to:e.length,insert:_.doc||``}})}}if(h&&h.doc&&C.current){var n=C.current?.b.state.doc.toString();if(n!==h.doc){var r;(r=C.current)==null||r.b.dispatch({changes:{from:0,to:n.length,insert:h.doc||``}})}}if(l&&C.current){var i=C.current.a.state.selection.ranges[0].from,a=C.current.b.state.selection.ranges[0].from;C.current.destroy(),C.current=new Ii(z({a:z({},_,{extensions:[...v?.extension||[],...Di(z({},v?.option,{theme:y}))]}),b:z({},h,{extensions:[...g?.extension||[],...Di(z({},g?.option,{theme:y}))]}),parent:S.current},w)),i&&(C.current.a.focus(),C.current.a.dispatch({selection:{anchor:i,head:i}})),a&&(C.current.b.focus(),C.current.b.dispatch({selection:{anchor:a,head:a}}))}},[C,y,S.current,_,h,v,g,l]),(0,H.useEffect)(()=>()=>C.current&&C.current.destroy(),[]),(0,H.useEffect)(()=>{if(C.current){var e={};x.orientation!==i&&(e.orientation=i),x.revertControls!==a&&(e.revertControls=a),x.highlightChanges!==o&&(e.highlightChanges=o),x.gutter!==s&&(e.gutter=s),x.collapseUnchanged!==c&&(e.collapseUnchanged=c),x.renderRevertControl!==u&&(e.collapseUnchanged=c),Object.keys(e).length&&b&&C.current&&(C.current.reconfigure(z({},e)),b(z({},e)))}},[b,C,i,a,o,s,c,u]),(0,U.jsx)(`div`,z({ref:S,className:`cm-merge-theme`+(n?` `+n:``)},p,{children:r}))});fp.displayName=`CodeMirrorMerge.Internal`;var pp=[`theme`],mp=H.forwardRef((e,t)=>{var{theme:n}=e,r=Ei(e,pp);return(0,U.jsx)(ap,{theme:n,children:(0,U.jsx)(fp,z({},r,{ref:t}))})});mp.Original=sp,mp.Modified=lp,mp.displayName=`CodeMirrorMerge`;var hp=mp.Original,gp=mp.Modified,_p=[Qe(),R.lineWrapping],vp=({cellId:e,aiCompletionCell:n,className:r,onChange:i,currentLanguageAdapter:a,currentCode:o,declineChange:s,acceptChange:c,runCell:l,outputArea:u,children:d})=>{let[f,p]=(0,H.useState)(!1),[m,h]=t(ki),g=(0,H.useId)(),_=nn(),{initialPrompt:v,triggerImmediately:y,cellId:b}=n??{},x=b===e,S=Ir(e),C;S?.type===`update_cell`&&(C=S.previousCode);let[w,T]=(0,H.useState)(``),[te,E]=(0,H.useState)(v??``),ne=H.useMemo(()=>new jr({api:_.getAiURL(`completion`).toString(),headers:()=>_.headers(),prepareSendMessagesRequest:({body:e})=>({body:e??{}})}),[_]),{sendMessage:D,stop:O,status:k}=Yr({throttle:100,transport:ne,onData:e=>{if(e.type===Mr){let t=Pr.parse(e.data);T(t.code.trimEnd())}},onError:e=>{T(``),hi({title:`Completion failed`,description:Ti(e)})},onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{(e||t||n||r!==`stop`)&&T(``)}}),A=k===`submitted`||k===`streaming`,re=(0,H.useCallback)(()=>{T(``),O()},[O]),j=(0,H.useCallback)(async e=>{await O(),T(``);let t={...Rr({input:e}),prompt:e,includeOtherCode:m?Ue(o):``,code:o,language:a??`python`};await D({text:e},{body:t})},[o,a,m,D,O]),ae=(0,H.useCallback)(()=>{j(te)},[j,te]),M=H.useRef(null),oe=(0,H.useCallback)(()=>{y&&!A&&v&&j(v)},[y]);(0,H.useEffect)(()=>{x&&(ee(()=>{let e=M.current;return e?.view?(e.view.focus(),oe(),!0):!1},{retries:3,delay:100,initialDelay:100}),ie(M.current?.view))},[x,oe]),(0,H.useEffect)(()=>{x&&E(v||``)},[x,v,E]);let{theme:se}=vi(),N=()=>{c(w),T(``)},ce=()=>{re(),p(!0),M.current?.view?.focus()},le=x&&y&&(w||A);u??=`below`;let P=x&&(!y||f),de=(0,U.jsx)(`div`,{className:pn(`w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden`,le?`max-h-20 opacity-100 translate-y-0`:`max-h-0 opacity-0 -translate-y-2`),children:(0,U.jsx)(yp,{status:A?`loading`:`generated`,onAccept:N,onReject:ce,showInputPrompt:f,setShowInputPrompt:p,runCell:l,className:`mt-4 mb-3 w-lg`})}),fe=(e,t)=>(0,U.jsxs)(mp,{className:`cm`,theme:se,children:[(0,U.jsx)(hp,{onChange:i,value:e,extensions:_p}),(0,U.jsx)(gp,{value:t,editable:!1,readOnly:!0,extensions:_p})]}),F=()=>{if(w&&x)return fe(o,w);if(!w&&C)return fe(C,o)},pe=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Ur,{isLoading:A,onAccept:N,size:`xs`,multipleCompletions:!1,label:Kr.accept,acceptShortcut:`Mod-↵`,runCell:l}),(0,U.jsx)(Gr,{onDecline:ce,size:`xs`,multipleCompletions:!1,label:Kr.decline,declineShortcut:`Shift-Mod-Delete`})]});return(0,U.jsxs)(`div`,{"data-ai-input-open":P,className:pn(`flex flex-col w-full rounded-[inherit]`,r),children:[(0,U.jsx)(`div`,{className:pn(`flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300`,P&&`max-h-[400px] border-b min-h-11 visible`,!P&&`max-h-0 min-h-0 invisible`),children:x&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(ue,{className:`text-(--blue-10) shrink-0`,size:16}),(0,U.jsx)(Wr,{inputRef:M,className:`h-full my-0 py-2 flex items-center`,onClose:()=>{re(),s()},value:te,onChange:E,onSubmit:()=>{A||(M.current?.view&&Lr(M.current.view),ae())},onKeyDown:qr({handleAcceptCompletion:N,handleDeclineCompletion:ce,isLoading:A,hasCompletion:w.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)(Hr,{isLoading:A,onStop:re,onSendClick:ae,isEmpty:!te.trim(),showStopLabel:!0}),(0,U.jsx)(Vr,{handleAddContext:()=>Jr(M),isLoading:A}),(0,U.jsx)(Ht,{triggerClassName:`h-7 text-xs`,iconSize:`small`,forRole:`edit`,displayIconOnly:!0,placeholder:`Edit model`})]}),w&&(0,U.jsx)(`div`,{className:`mt-1 flex items-center gap-1`,children:pe})]}),(0,U.jsx)(`div`,{className:`h-full w-px bg-border mx-2`}),(0,U.jsx)(yn,{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)(tt,{"data-testid":`include-other-cells-checkbox`,id:g,checked:m,onCheckedChange:e=>h(!!e)}),(0,U.jsx)(hn,{htmlFor:g,className:`text-muted-foreground text-xs whitespace-nowrap ellipsis`,children:`All code`})]})}),(0,U.jsx)(xn,{"data-testid":`decline-completion-button`,variant:`text`,size:`icon`,disabled:A,onClick:()=>{re(),s()},children:(0,U.jsx)(kr,{className:`text-(--red-10)`,size:16})})]})}),u===`above`&&de,F(),(!w||!x)&&!C&&d,u===`below`&&de]})},yp=e=>{let t=(0,V.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=pn(`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)(ai,{className:`animate-spin text-blue-600 mb-px`,size:15,strokeWidth:2,"aria-label":`Generating fix`}):(0,U.jsx)(Ar,{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)(hn,{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)(Ur,{isLoading:l,onAccept:r,size:`xs`,label:Kr.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)(Gr,{onDecline:i,size:`xs`,label:Kr.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},bp=`web application/x-marimo-cell`,xp=bt({cells:wt(bt({code:xt(),name:xt().optional(),config:bt({column:St([Ct(),Dt()]).optional(),disabled:Tt().optional(),hide_code:Tt().optional()}).optional()})),version:Et(`1.0`)});function Sp(e){return e.map(e=>e.code).join(`
|
|
18
|
+
`).trim()}function Rd(e,t,n,r){return r!==`{`||t!==n||!kn(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 zd(){return R.inputHandler.of(Rd)}function Bd(e){let{showPlaceholder:t,enableAI:n}=e;return t?`marimo-import`:n?`ai`:`none`}var Vd=`cm-tooltip-portal`;function Hd(e){if(e==null)return document.querySelector(`#App`)??void 0;let t=document.querySelector(e);if(t==null)return;let n=t.querySelector(`:scope > .${Vd}`);if(n!=null)return n;let r=document.createElement(`div`);return r.className=`${Vd} not-prose contents`,t.append(r),r}var Ud=e=>{let{cellId:t,keymapConfig:n,hotkeys:r,enableAI:i,cellActions:a,completionConfig:o,lspConfig:s,diagnosticsConfig:c,displayConfig:l,inlineAiTooltip:u}=e,d=Bd(e);return[Ft(n,r),Nd(),Pd(),Xo(),Qe({cellId:t,completionConfig:o,hotkeys:r,placeholderType:d,lspConfig:s,diagnosticsConfig:c}),Ne({cellId:t,hotkeys:r,cellActions:a,keymapConfig:n}),Gd(e),Md(),c?.enabled?sr():[],i&&u?[qa({prompt:e=>ao({prompt:e.prompt,selection:e.selection,codeBefore:e.codeBefore,codeAfter:e.codeAfter,language:at(e.editorView)})}),Va.of({hideOnBlur:!0})]:[],ue(t,l.reference_highlighting??!0),qo(t,l.code_lens??!0)]},Wd=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()!==``&&_r(e)},Gd=e=>{let{theme:t,hotkeys:n,completionConfig:r,acceptCompletionOnEnter:i,cellId:a,lspConfig:o,diagnosticsConfig:s,tooltipParentSelector:c}=e,l=Bd(e),u=r.auto_close_pairs!==!1;return[R.lineWrapping,Kn(),Gn(),er(),In(),Cn(),wn(),xn(),Dn({position:`fixed`,parent:Hd(c)}),Ge(),t===`dark`?ln:cn,re(o),cd(r),$n(),zd(),u?vr():[],$o(i),u?Xn.high(Ln.of(mr)):[],Jn(),Mn(),jn.of(` `),zn(Hn,{fallback:!0}),Ln.of(Tn),xe({placeholderType:l,completionConfig:r,hotkeys:n,cellId:a,lspConfig:{...o,diagnostics:s}}),ee.of(ar()),Bn.allowMultipleSelections.of(!0),wd(n),Ln.of([{key:`Tab`,run:e=>br(e)||Wd(e)||nr(e),preventDefault:!0},{key:n.getHotkey(`completion.moveDown`).key,run:e=>yr(e.state)!==null&&(gr(!0)(e),!0),preventDefault:!0},{key:n.getHotkey(`completion.moveUp`).key,run:e=>yr(e.state)!==null&&(gr(!1)(e),!0),preventDefault:!0}]),Ln.of([...ur,ir])]},Kd=(e=>!e||e instanceof WebAssembly.Module?e:typeof e==`object`&&`default`in e?e.default??e:e)(Ki),qd=e=>{Qi(e),typeof Xi==`function`&&Xi(),Jd(qi)};function Jd(e){typeof e.__wbindgen_start==`function`&&e.__wbindgen_start()}if(Kd&&Kd.__wbindgen_start)qd(Kd);else if(`Bun`in globalThis){let e;if(Kd instanceof WebAssembly.Module)({instance:e}=await WebAssembly.instantiate(Kd,{"./loro_wasm_bg.js":qi}));else{let t=Bun.pathToFileURL(Kd);({instance:e}=await WebAssembly.instantiateStreaming(fetch(t),{"./loro_wasm_bg.js":qi}))}qd(e.exports)}else{let e=Kd instanceof WebAssembly.Module?Kd:await mi(()=>import(`./loro_wasm_bg-BzjWitFM.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);qd(n.exports??n)}var Yd=[`Map`,`Text`,`List`,`Tree`,`MovableList`,`Counter`];function Xd(e){return e.startsWith(`cid:`)}function Zd(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return typeof t!=`object`||!t||typeof t.kind!=`function`?!1:Yd.includes(e.kind())}var Qd=class{constructor(e,t=3e4){this.listeners=new Set,this.inner=new Zi(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))}};Yi.prototype.toJsonWithReplacer=function(e){let t=new Set,n=this,r=(r,a)=>{if(typeof a==`string`&&Xd(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(Zd(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(Zd(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 $d=Symbol(`loro.callPendingEventsWrapped`);function ef(e,t){let n=Object.getOwnPropertyDescriptor(e,t);if(!n||typeof n.value!=`function`)return;let r=n.value;if(r[$d])return;let i=function(...e){let t;try{return t=r.apply(this,e),t}finally{t&&typeof t.then==`function`?t.finally(()=>{Ji()}):Ji()}};i[$d]=!0,Object.defineProperty(e,t,{...n,value:i})}function tf(e,t){for(let n of t)ef(e,n)}tf(Yi.prototype,[`setDetachedEditing`,`attach`,`detach`,`fork`,`forkAt`,`checkoutToLatest`,`checkout`,`commit`,`getCursorPos`,`revertTo`,`export`,`exportJsonUpdates`,`exportJsonInIdSpan`,`importJsonUpdates`,`import`,`importUpdateBatch`,`importBatch`,`travelChangeAncestors`,`getChangedContainersIn`,`diff`,`applyDiff`,`setPeerId`]),tf(Ui.prototype,[`set`,`delete`,`apply`,`removeOutdated`]),tf(Gi.prototype,[`undo`,`redo`]);var nf=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`}});Fn.define();var rf=I.define(),af=Pn.define({create(){return{remoteCursors:new Map,isCheckout:!1}},update(e,t){for(let n of t.effects)if(n.is(rf))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}}),of=e=>{let t=e.transactions.flatMap(e=>e.effects).filter(e=>e.is(rf));return e.docChanged||e.viewportChanged||t.length>0},sf=()=>En({above:!0,class:`loro-cursor-layer`,update:of,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(af);return n?[]:[...t.values()].flatMap(t=>{let n=Rn.cursor(t.cursor.anchor);return lf.createCursor(e,n,t.user?.name||`unknown`,t.user?.colorClassName||``)})}}),cf=()=>En({above:!1,class:`loro-selection-layer`,update:of,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(af);return n?[]:[...t.entries()].filter(([,e])=>e.cursor.head!==void 0&&e.cursor.anchor!==e.cursor.head).flatMap(([,t])=>{let n=Rn.range(t.cursor.anchor,t.cursor.head);return qn.forRange(e,`loro-selection ${t.user?.colorClassName||``}`,n)})}}),lf=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===Yn.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)}},uf=(e,t,n,r)=>{let i=[],{updated:a,added:o}=n;for(let n of[...a,...o]){let a=df(e,t,n,r);a&&i.push(a)}return i},df=(e,t,n,r)=>{let i=t.getAllStates()[n];if(!i||n===e.peerIdStr||i.scopeId!==r)return;if(i.type===`delete`)return rf.of({type:`delete`,peer:i.uid,scopeId:i.scopeId});let a=$i.decode(i.cursor.anchor),o=e.getCursorPos(a)?.offset??0,s=o;if(i.cursor.head){let t=$i.decode(i.cursor.head);s=e.getCursorPos(t)?.offset??0}return rf.of({type:`update`,peer:i.uid,scopeId:i.scopeId,cursor:{anchor:o,head:s},user:i.user})},ff=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=df(this.doc,this.awareness,t,this.scopeId);n&&e.push(n)}this.view.dispatch({effects:e})}else e.by===`checkout`&&this.view.dispatch({effects:[rf.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=mf({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})}},pf=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:uf(this.doc,this.awareness,e,this.scopeId)})};this._awarenessListener=i,this.awareness.addListener(i)}destroy(){this._awarenessListener&&this.awareness.removeListener(this._awarenessListener)}},mf=({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}},hf=[`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)`],gf=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 hf[Math.abs(t)%hf.length]}return hf[e%hf.length]},Q=Gt.get(`rtc`),_f=Q.get(`awareness`).disabled(),vf=`awareness:`;function yf(e,t){let n=new TextEncoder().encode(e);return new Uint8Array([...n,...t])}function bf(e,t){return new TextDecoder().decode(e.slice(0,t.length))===t}function xf(e,t){return e.slice(t.length)}var Sf=r(void 0),$=new Yi,Cf=new Qd($.peerIdStr),wf=fr(()=>{Q.debug(`creating websocket`);let e=nn().getWsSyncURL(_i()).toString(),t=new ta(e,void 0,{maxRetries:10,debug:!1,startClosed:!0,connectionTimeout:1e4});return Promise.resolve().then(async()=>{await Qt(),Yt()===`edit`&&t.reconnect()}),t.addEventListener(`message`,async e=>{let t=await e.data.arrayBuffer(),n=new Uint8Array(t);if(bf(n,vf)){let e=xf(n,vf);Cf.apply(e),_f.debug(`applied awareness update`);return}$.import(n),Q.debug(`imported doc change. new doc:`,$.toJSON()),o.get(Sf)!==$&&o.set(Sf,$)}),t.addEventListener(`open`,()=>{Q.debug(`websocket open`)}),t.addEventListener(`close`,e=>{Q.warn(`websocket close`,e),o.get(Sf)===$&&o.set(Sf,void 0)}),t});Ae()&&wf(),$.subscribeLocalUpdates(e=>{Q.debug(`local update, sending to server`),wf().send(e)}),Cf.addListener((e,t)=>{let n=[...e.added,...e.removed,...e.updated];t===`local`&&(_f.debug(`awareness changes`,n),wf().send(yf(vf,Cf.encode(n))))});function Tf(e,t,n=``){if(Xt())return{extension:[],code:n};let r=$.getByPath(`codes/${e}`)!==void 0,i=$.getMap(`codes`).getOrCreateContainer(e,new Wi);return r||(Q.log(`initializing code for new cell`,n),i.insert(0,n)),{code:n.toString(),extension:[Ef(e),Df(e),Of($,Cf,{get name(){return o.get(Ze)||`Anonymous`},get colorClassName(){return gf(this.name)}},()=>i,e),Ie($,[`codes`,e],()=>i)]}}function Ef(e){let t=(e,t)=>{let n=e.state.field(N).type,r=t.toString();r&&r!==n&&(Q.debug(`[incoming] setting language type: ${n} -> ${r}`),P(e,{language:r,keepCodeAsIs:!0}))},n=(e,t)=>{let n=e.state.field(Ce),r=t.toJSON();a(n,r)||e.dispatch({effects:[ot.of(r)],annotations:[qe.of(!0)]})};return Qn.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}Jt(a instanceof Wi,`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}Jt(o instanceof ea,`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 Df(e){let t=$.getMap(`languages`).getOrCreateContainer(e,new Wi),n=$.getMap(`language_metadata`).getOrCreateContainer(e,new ea);return R.updateListener.of(e=>{let r=t.toString()!==``;if(!e.docChanged&&r)return;if(!r){let r=ft(e.state).type;P(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(Ce));let i=e.state.field(Ce);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(qe)){for(let e of r.effects)if(e.is(ut)&&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(ot)||e.is(Ke)){let t=e.value;e.is(Ke)?(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 Of(e,t,n,r,i,a){let o=`loro:cell:${i}`;return[af,sf(),cf(),Qn.define(i=>new ff(i,e,n,t,r,o,a)),Qn.define(n=>new pf(n,e,t,o)),nf]}var kf=ie,Af=e=>{let t=(0,V.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}=wr(),[f,p]=(0,H.useState)(l),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=[],t[0]=m):m=t[0];let[h,_]=(0,H.useState)(m),[v,y]=(0,H.useState)(!1),b=(0,H.useRef)(null),x=(0,H.useRef)(!1),S,C;t[1]===l?(S=t[2],C=t[3]):(S=()=>{p(l)},C=[l],t[1]=l,t[2]=S,t[3]=C),(0,H.useEffect)(S,C);let w;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(w=()=>{y(!0)},t[4]=w):w=t[4];let T=w,E;t[5]!==l||t[6]!==c?(E=e=>{e.relatedTarget?.closest(`.filename-input`)||(y(!1),c&&p(l))},t[5]=l,t[6]=c,t[7]=E):E=t[7];let D=E,ee;t[8]===f?ee=t[9]:(ee=Or.dirname(f||``),t[8]=f,t[9]=ee);let O=ee,k=Or.basename(f||``),te=h.filter(e=>Or.basename(e.path).startsWith(k)),A;t[10]!==O||t[11]!==v||t[12]!==d?(A=async()=>{if(!v){_([]);return}let e=await d({path:O});_(e.files)},t[10]=O,t[11]=v,t[12]=d,t[13]=A):A=t[13];let ne;t[14]!==O||t[15]!==v?(ne=[O,v],t[14]=O,t[15]=v,t[16]=ne):ne=t[16];let{isPending:j}=xi(A,ne),M=jf(f,h,l),re=(M||te.length>0)&&(0,U.jsxs)(ae,{className:`font-mono`,children:[!j&&(0,U.jsx)(dt,{children:`No files`}),M&&(0,U.jsxs)(lt,{variant:`success`,className:`py-2 px-3`,onSelect:()=>{M&&(x.current=!0,o(M),b.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:Or.basename(M)})]})]},`_rename_`),te.map(e=>{let t=e.isDirectory?`directory`:Qr(e.path),n=$r[t];return(0,U.jsxs)(lt,{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`}),` `,Or.basename(e.path)]},e.path)})]}),ie=Math.max(20,f?.length||r?.length||0)*10,N=v?f||``:l||``,oe;t[17]!==u||t[18]!==ie?(oe=u?{maxWidth:ie}:void 0,t[17]=u,t[18]=ie,t[19]=oe):oe=t[19];let P;t[20]===s?P=t[21]:(P=fn(s,`w-full px-4 py-1 my-1 h-9 font-mono text-foreground/60`),t[20]=s,t[21]=P);let se;t[22]!==r||t[23]!==N||t[24]!==oe||t[25]!==P?(se=(0,U.jsx)(kf,{children:(0,U.jsx)(g,{"data-testid":`dir-completion-input`,tabIndex:-1,rootClassName:`border-none justify-center px-1`,spellCheck:`false`,value:N,onKeyDown:Mf,icon:null,ref:b,onValueChange:p,placeholder:r,autoComplete:`off`,style:oe,className:P})}),t[22]=r,t[23]=N,t[24]=oe,t[25]=P,t[26]=se):se=t[26];let ce=re&&`group-focus-within:block`,le;t[27]===ce?le=t[28]:(le=fn(`p-0 w-full min-w-80 max-w-80vw hidden`,ce),t[27]=ce,t[28]=le);let F;t[29]!==re||t[30]!==le?(F=(0,U.jsx)(ve,{side:`bottom`,className:le,portal:!1,children:re}),t[29]=re,t[30]=le,t[31]=F):F=t[31];let ue;t[32]!==se||t[33]!==F?(ue=(0,U.jsxs)(ae,{children:[se,F]}),t[32]=se,t[33]=F,t[34]=ue):ue=t[34];let de;t[35]!==D||t[36]!==ue?(de=(0,U.jsx)(mt,{onFocus:T,onBlur:D,shouldFilter:!1,id:`filename-input`,className:`bg-transparent group filename-input`,children:ue}),t[35]=D,t[36]=ue,t[37]=de):de=t[37];let fe;return t[38]!==v||t[39]!==de?(fe=(0,U.jsx)(dn,{children:(0,U.jsx)(Le,{open:v,modal:!1,children:de})}),t[38]=v,t[39]=de,t[40]=fe):fe=t[40],fe};function jf(e,t,n){if(e&&!e.endsWith(`/`)&&((Oe(`markdown`)?new Set([`py`,`md`,`markdown`,`qmd`]):new Set([`py`])).has(Or.extension(e))||(e=e.endsWith(`.`)?`${e}py`:e.endsWith(`.p`)?`${e}y`:`${e}.py`),!t.some(t=>t.path===e||Or.basename(t.path)===e)&&!(n&&(n===e||Or.basename(n)===e))))return e}function Mf(e){e.key===`Escape`&&e.currentTarget.blur()}var Nf=e=>{let t=(0,V.c)(33),n=()=>{_n(new Blob([r()],{type:`text/plain`}),`${e.proposedName}.json`)},r=c(If),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)(ai,{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)(ni,{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)(bn,{"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)(bn,{"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)(ti,{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)(ri,{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},Pf=e=>{let t=(0,V.c)(12),{filename:n,needsSave:r}=e,{openModal:i,closeModal:a}=ii(),o;t[0]===n?o=t[1]:(o=n===null?`app`:Or.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)(Nf,{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;Ht(`global.save`,l);let u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=Ni(`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)(li,{strokeWidth:1.5,size:18}),t[8]=f):f=t[8];let p;return t[9]!==l||t[10]!==d?(p=(0,U.jsx)(vn,{content:u,children:(0,U.jsx)(na,{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 Ff(e){return{id:e.id,name:e.name,code:e.code,code_hash:null,config:{column:0,...e.config}}}function If(){let e=Pe(),t=_t(e),n={version:`1`,metadata:{marimo_version:un()},cells:t.map(Ff)};return JSON.stringify(n,null,2)}var Lf=r(void 0),Rf=r(e=>{let t=e(Lf);return zf({state:e(ye),layout:e(sn),lastSavedNotebook:t})});function zf({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!dr(s,n.codes)||!dr(l,n.names)||!a(c,n.configs)||!a(t.selectedLayout,n.layout.selectedLayout)||!a(t.layoutData,n.layout.layoutData)}function Bf(e){let t=(0,V.c)(21),{codes:n,cellConfigs:r,config:i,connStatus:a,cellNames:o,needsSave:s,kioskMode:c,onSave:l}=e,u=(0,H.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(Vf).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===$t.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,H.useEffect)(_,v)}function Vf(e){return JSON.stringify(e)}var Hf=Promise.resolve();function Uf(e){let t=Hf.then(e);return Hf=t.then(()=>void 0,()=>void 0),t}var Wf=e=>{let t=(0,V.c)(15),{kioskMode:n}=e,r=ji(),a=i(Rf),o=i(rn).state===$t.CLOSED,{saveOrNameNotebook:s,saveIfNotebookIsPersistent:c}=Gf(),l;t[0]!==n||t[1]!==c?(l={onSave:c,kioskMode:n},t[0]=n,t[1]=c,t[2]=l):l=t[2],Xf(l),ra();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),qt(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(Ht(`global.save`,s),o){let e;return t[7]!==r||t[8]!==a?(e=(0,U.jsx)(Pf,{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=Ni(`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)(li,{strokeWidth:1.5,size:18}),t[11]=h):h=t[11];let g;return t[12]!==f||t[13]!==m?(g=(0,U.jsx)(vn,{content:p,children:(0,U.jsx)(na,{"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 Gf(){let e=(0,V.c)(21),{sendSave:t}=wr(),{openModal:r,closeModal:i,openAlert:a}=ii(),o=l(Lf),s=Mi(),u=n(),d;e[0]!==a||e[1]!==t||e[2]!==o||e[3]!==u?(d=(e,n)=>Uf(async()=>{let r=u.get(rn),i=u.get(Nt);if(u.get(Zt))return;if(r.state!==$t.OPEN){a(`Failed to save notebook: not connected to a kernel.`);return}if(Gt.log(`saving to `,e),n&&i.format_on_save&&(Gt.log(`formatting notebook (onSave)`),await ct()),_t(Pe()).length===0)return;let s=await we(async()=>{let n=Pe(),r=_t(n),i=r.map(Jf),a=r.map(qf),o=r.map(Kf),s=Te(n),c=u.get(sn);return await t({cellIds:i,codes:a,names:o,filename:e,configs:s,layout:kr(),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(Me),r=u.get(rn);Yf(n)&&r.state===$t.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(Me),t=u.get(rn);m(!0),!Yf(e)&&t.state!==$t.CLOSED&&r((0,U.jsx)($f,{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 Kf(e){return e.name}function qf(e){return e.code}function Jf(e){return e.id}function Yf(e){return e!==null&&!e.startsWith(`/tmp/`)&&!e.startsWith(`/var/folders`)&&!e.includes(`AppData\\Local\\Temp`)}function Xf(e){let n=(0,V.c)(14),r=i(Nt),a=T(),[o]=t(rn),s=i(Rf),c,l;if(n[0]!==a){let e=_t(a);c=e.map(Qf),l=e.map(Zf),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=Te(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],Bf(p)}function Zf(e){return e.name}function Qf(e){return e.code}var $f=e=>{let t=(0,V.c)(17),{onClose:n,onSave:r}=e,[i,a]=(0,H.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)(ai,{children:`Save notebook`}),t[3]=c):c=t[3];let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,U.jsx)(mn,{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)(Af,{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)(bn,{"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)(bn,{"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)(ti,{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)(ri,{children:[c,u,m]}),t[14]=u,t[15]=m,t[16]=h):h=t[16],h};function ep(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var tp={modified:{doc:``},original:{doc:``}},np=(0,H.createContext)(tp);function rp(e,t){return z({},e,t,{modified:z({},e.modified,t.modified),original:z({},e.original,t.original)})}var ip=()=>(0,H.useContext)(np),ap=e=>{var{children:t,theme:n}=e,[r,i]=(0,H.useReducer)(rp,z({},tp,{theme:n}));return(0,H.useEffect)(()=>i({theme:n}),[n]),(0,U.jsx)(np.Provider,{value:z({},r,{dispatch:i}),children:t})},op=[`extensions`,`value`,`selection`,`onChange`],sp=e=>{var{extensions:t=[],value:n,selection:r,onChange:i}=e,a=Ei(e,op),{theme:o,dispatch:s}=ip(),c=Di(z({},a,{theme:o}));return(0,H.useEffect)(()=>s({original:{doc:n,selection:r,extensions:[...c,...t]},originalExtension:{onChange:i,option:a,extension:[t]}}),[e]),null};sp.displayName=`CodeMirrorMerge.Original`;var cp=[`extensions`,`value`,`selection`,`onChange`],lp=e=>{var{extensions:t=[],value:n,selection:r,onChange:i}=e,a=Ei(e,cp),{theme:o,dispatch:s}=ip(),c=Di(z({},a,{theme:o}));return(0,H.useEffect)(()=>{s({modified:{doc:n,selection:r,extensions:[...c,...t]},modifiedExtension:{onChange:i,option:a,extension:[t]}})},[e]),null};lp.displayName=`CodeMirrorMerge.Modified`;var up=[`className`,`children`,`orientation`,`revertControls`,`highlightChanges`,`gutter`,`collapseUnchanged`,`destroyRerender`,`renderRevertControl`,`diffConfig`,`root`],dp=[`modified`,`modifiedExtension`,`original`,`originalExtension`,`theme`,`dispatch`],fp=H.forwardRef((e,t)=>{var{className:n,children:r,orientation:i,revertControls:a,highlightChanges:o,gutter:s,collapseUnchanged:c,destroyRerender:l=!0,renderRevertControl:u,diffConfig:d,root:f}=e,p=Ei(e,up),m=ip(),{modified:h,modifiedExtension:g,original:_,originalExtension:v,theme:y,dispatch:b}=m,x=Ei(m,dp),S=(0,H.useRef)(null),C=(0,H.useRef)(),w={orientation:i,revertControls:a,highlightChanges:o,gutter:s,collapseUnchanged:c,renderRevertControl:u,diffConfig:d,root:f};(0,H.useImperativeHandle)(t,()=>({container:S.current,view:C.current,modified:h,original:_,config:z({a:_,b:h,parent:S.current},w)}),[S,C,h,_,w]);var T=R.updateListener.of(e=>{if(e.docChanged&&typeof v?.onChange==`function`){var t=e.state.doc.toString();v?.onChange(t,e)}}),E=R.updateListener.of(e=>{if(e.docChanged&&typeof g?.onChange==`function`){var t=e.state.doc.toString();g?.onChange(t,e)}});return(0,H.useEffect)(()=>{!C.current&&S.current&&v&&g&&(C.current=new Ii(z({a:z({},_,{extensions:[...v?.extension||[],...Di(z({},v?.option,{theme:y})),T]}),b:z({},h,{extensions:[...g?.extension||[],...Di(z({},g?.option,{theme:y})),E]}),parent:S.current},w)),b({view:C.current}))},[C,S,v,g]),(0,H.useEffect)(()=>{if(_&&_.doc&&C.current){var e=C.current?.a.state.doc.toString();if(e!==_.doc){var t;(t=C.current)==null||t.a.dispatch({changes:{from:0,to:e.length,insert:_.doc||``}})}}if(h&&h.doc&&C.current){var n=C.current?.b.state.doc.toString();if(n!==h.doc){var r;(r=C.current)==null||r.b.dispatch({changes:{from:0,to:n.length,insert:h.doc||``}})}}if(l&&C.current){var i=C.current.a.state.selection.ranges[0].from,a=C.current.b.state.selection.ranges[0].from;C.current.destroy(),C.current=new Ii(z({a:z({},_,{extensions:[...v?.extension||[],...Di(z({},v?.option,{theme:y}))]}),b:z({},h,{extensions:[...g?.extension||[],...Di(z({},g?.option,{theme:y}))]}),parent:S.current},w)),i&&(C.current.a.focus(),C.current.a.dispatch({selection:{anchor:i,head:i}})),a&&(C.current.b.focus(),C.current.b.dispatch({selection:{anchor:a,head:a}}))}},[C,y,S.current,_,h,v,g,l]),(0,H.useEffect)(()=>()=>C.current&&C.current.destroy(),[]),(0,H.useEffect)(()=>{if(C.current){var e={};x.orientation!==i&&(e.orientation=i),x.revertControls!==a&&(e.revertControls=a),x.highlightChanges!==o&&(e.highlightChanges=o),x.gutter!==s&&(e.gutter=s),x.collapseUnchanged!==c&&(e.collapseUnchanged=c),x.renderRevertControl!==u&&(e.collapseUnchanged=c),Object.keys(e).length&&b&&C.current&&(C.current.reconfigure(z({},e)),b(z({},e)))}},[b,C,i,a,o,s,c,u]),(0,U.jsx)(`div`,z({ref:S,className:`cm-merge-theme`+(n?` `+n:``)},p,{children:r}))});fp.displayName=`CodeMirrorMerge.Internal`;var pp=[`theme`],mp=H.forwardRef((e,t)=>{var{theme:n}=e,r=Ei(e,pp);return(0,U.jsx)(ap,{theme:n,children:(0,U.jsx)(fp,z({},r,{ref:t}))})});mp.Original=sp,mp.Modified=lp,mp.displayName=`CodeMirrorMerge`;var hp=mp.Original,gp=mp.Modified,_p=[Ye(),R.lineWrapping],vp=({cellId:e,aiCompletionCell:n,className:r,onChange:i,currentLanguageAdapter:a,currentCode:o,declineChange:s,acceptChange:c,runCell:l,outputArea:u,children:d})=>{let[f,p]=(0,H.useState)(!1),[m,h]=t(ki),g=(0,H.useId)(),_=tn(),{initialPrompt:v,triggerImmediately:y,cellId:b}=n??{},x=b===e,S=Lr(e),w;S?.type===`update_cell`&&(w=S.previousCode);let[T,E]=(0,H.useState)(``),[D,ee]=(0,H.useState)(v??``),O=H.useMemo(()=>new Mr({api:_.getAiURL(`completion`).toString(),headers:()=>_.headers(),prepareSendMessagesRequest:({body:e})=>({body:e??{}})}),[_]),{sendMessage:k,stop:te,status:A}=Xr({throttle:100,transport:O,onData:e=>{if(e.type===Nr){let t=Fr.parse(e.data);E(t.code.trimEnd())}},onError:e=>{E(``),gi({title:`Completion failed`,description:Ti(e)})},onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{(e||t||n||r!==`stop`)&&E(``)}}),j=A===`submitted`||A===`streaming`,M=(0,H.useCallback)(()=>{E(``),te()},[te]),re=(0,H.useCallback)(async e=>{await te(),E(``);let t={...zr({input:e}),prompt:e,includeOtherCode:m?Be(o):``,code:o,language:a??`python`};await k({text:e},{body:t})},[o,a,m,k,te]),ie=(0,H.useCallback)(()=>{re(D)},[re,D]),N=H.useRef(null),ae=(0,H.useCallback)(()=>{y&&!j&&v&&re(v)},[y]);(0,H.useEffect)(()=>{x&&(C(()=>{let e=N.current;return e?.view?(e.view.focus(),ae(),!0):!1},{retries:3,delay:100,initialDelay:100}),ne(N.current?.view))},[x,ae]),(0,H.useEffect)(()=>{x&&ee(v||``)},[x,v,ee]);let{theme:oe}=vi(),P=()=>{c(T),E(``)},se=()=>{M(),p(!0),N.current?.view?.focus()},le=x&&y&&(T||j);u??=`below`;let F=x&&(!y||f),ue=(0,U.jsx)(`div`,{className:fn(`w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden`,le?`max-h-20 opacity-100 translate-y-0`:`max-h-0 opacity-0 -translate-y-2`),children:(0,U.jsx)(yp,{status:j?`loading`:`generated`,onAccept:P,onReject:se,showInputPrompt:f,setShowInputPrompt:p,runCell:l,className:`mt-4 mb-3 w-lg`})}),de=(e,t)=>(0,U.jsxs)(mp,{className:`cm`,theme:oe,children:[(0,U.jsx)(hp,{onChange:i,value:e,extensions:_p}),(0,U.jsx)(gp,{value:t,editable:!1,readOnly:!0,extensions:_p})]}),fe=()=>{if(T&&x)return de(o,T);if(!T&&w)return de(w,o)},pe=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Wr,{isLoading:j,onAccept:P,size:`xs`,multipleCompletions:!1,label:qr.accept,acceptShortcut:`Mod-↵`,runCell:l}),(0,U.jsx)(Kr,{onDecline:se,size:`xs`,multipleCompletions:!1,label:qr.decline,declineShortcut:`Shift-Mod-Delete`})]});return(0,U.jsxs)(`div`,{"data-ai-input-open":F,className:fn(`flex flex-col w-full rounded-[inherit]`,r),children:[(0,U.jsx)(`div`,{className:fn(`flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300`,F&&`max-h-[400px] border-b min-h-11 visible`,!F&&`max-h-0 min-h-0 invisible`),children:x&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(ce,{className:`text-(--blue-10) shrink-0`,size:16}),(0,U.jsx)(Gr,{inputRef:N,className:`h-full my-0 py-2 flex items-center`,onClose:()=>{M(),s()},value:D,onChange:ee,onSubmit:()=>{j||(N.current?.view&&Rr(N.current.view),ie())},onKeyDown:Jr({handleAcceptCompletion:P,handleDeclineCompletion:se,isLoading:j,hasCompletion:T.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)(Ur,{isLoading:j,onStop:M,onSendClick:ie,isEmpty:!D.trim(),showStopLabel:!0}),(0,U.jsx)(Hr,{handleAddContext:()=>Yr(N),isLoading:j}),(0,U.jsx)(Vt,{triggerClassName:`h-7 text-xs`,iconSize:`small`,forRole:`edit`,displayIconOnly:!0,placeholder:`Edit model`})]}),T&&(0,U.jsx)(`div`,{className:`mt-1 flex items-center gap-1`,children:pe})]}),(0,U.jsx)(`div`,{className:`h-full w-px bg-border mx-2`}),(0,U.jsx)(vn,{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)($e,{"data-testid":`include-other-cells-checkbox`,id:g,checked:m,onCheckedChange:e=>h(!!e)}),(0,U.jsx)(mn,{htmlFor:g,className:`text-muted-foreground text-xs whitespace-nowrap ellipsis`,children:`All code`})]})}),(0,U.jsx)(bn,{"data-testid":`decline-completion-button`,variant:`text`,size:`icon`,disabled:j,onClick:()=>{M(),s()},children:(0,U.jsx)(Ar,{className:`text-(--red-10)`,size:16})})]})}),u===`above`&&ue,fe(),(!T||!x)&&!w&&d,u===`below`&&ue]})},yp=e=>{let t=(0,V.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=fn(`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)(oi,{className:`animate-spin text-blue-600 mb-px`,size:15,strokeWidth:2,"aria-label":`Generating fix`}):(0,U.jsx)(jr,{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)(mn,{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)(Wr,{isLoading:l,onAccept:r,size:`xs`,label:qr.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)(Kr,{onDecline:i,size:`xs`,label:qr.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},bp=`web application/x-marimo-cell`,xp=yt({cells:Ct(yt({code:bt(),name:bt().optional(),config:yt({column:xt([St(),Et()]).optional(),disabled:wt().optional(),hide_code:wt().optional()}).optional()})),version:Tt(`1.0`)});function Sp(e){return e.map(e=>e.code).join(`
|
|
19
19
|
|
|
20
|
-
`)}async function Cp(e){let t={cells:e.map(e=>({code:e.code,name:e.name,config:e.config})),version:`1.0`},n=new kp().add(bp,t).add(`text/plain`,Sp(e)).build();await navigator.clipboard.write([n])}function wp(){let e=(0,V.c)(13),t=v(),n=gt(),r=we(),i;e[0]===n?i=e[1]:(i=async e=>{let t=Le(),r=e.map(e=>t.cellData[e]).filter(Boolean);if(r.length!==0)try{await Cp(r),n.clear(),Tp(r.length)}catch(e){let t=e;Kt.error(`Failed to copy cells to clipboard`,t);try{await Si(Sp(r)),n.clear(),Tp(r.length)}catch{Ep()}}},e[0]=n,e[1]=i);let a=c(i),o;e[2]===n?o=e[3]:(o=async e=>{let t=Le(),r=e.filter(e=>t.cellData[e]),i=r.map(e=>t.cellData[e]);if(i.length!==0)try{await Cp(i),n.markForCut({cellIds:r})}catch(e){let t=e;Kt.error(`Failed to cut cells to clipboard`,t);try{await Si(Sp(i)),n.markForCut({cellIds:r})}catch{Ep()}}},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=Le(),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(bp)){let n=await(await r.getType(bp)).text();try{let r=xp.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;Kt.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}):Dp()}catch(e){let t=e;Kt.error(`Failed to paste from clipboard`,t),Op()}},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 Tp=e=>{let t=e===1?`Cell`:`${e} cells`;hi({title:`${t} copied`,description:`${t} ${e===1?`has`:`have`} been copied to clipboard.`})},Ep=()=>{hi({title:`Copy failed`,description:`Failed to copy cells to clipboard.`,variant:`danger`})},Dp=()=>{hi({title:`Nothing to paste`,description:`No cell or text found in clipboard.`,variant:`danger`})},Op=()=>{hi({title:`Paste failed`,description:`Failed to read from clipboard`,variant:`danger`})},kp=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):(Kt.warn(`ClipboardItem does not support ${e}`),this)}build(){return new ClipboardItem(this.items)}};function Ap(){return{selectionStart:null,selectionEnd:null,selected:new Set}}var{reducer:jp,createActions:Mp,valueAtom:Np,useActions:Pp}=mr(Ap,{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:Ap()}),Fp=()=>i(Np);function Ip(e){let t=(0,V.c)(2),n;return t[0]===e?n=t[1]:(n=r(t=>t(Np).selected.has(e)),t[0]=e,t[1]=n),i(n)}function Lp(){return Pp()}function Rp(e){return e.get(Np).selected}var{valueAtom:zp,useActions:Bp}=mr(()=>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),D(()=>{let e=document.activeElement;if(!e)return;let t=C.findElementThroughShadowDOMs(e);t&&de(C.parse(t.id))}),n}}),Vp=e=>r(t=>t(zp).has(e));function Hp(e){let t=(0,V.c)(2),n;return t[0]===e?n=t[1]:(n=Vp(e),t[0]=e,t[1]=n),i(n)}var Up=new WeakMap,Wp=500;function Gp(e){if(e.ctrlKey||e.metaKey||e.altKey)return``;let t=e.key.toLowerCase();return e.shiftKey?`shift+${t}`:t}function Kp(e,t){let n=Gp(e),r=e.target;if(!n||!r)return!1;let i=Up.get(r),a=n;i?.timeout&&clearTimeout(i.timeout),i&&(a=`${i.sequence} ${n}`);let o=t[a];if(o)return Up.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(()=>{Up.delete(r)},Wp);return Up.set(r,{sequence:a,timeout:e}),!0}return Up.delete(r),!1}function qp(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 Jp(e){return{handle:t=>e([t]),bulkHandle:t=>e(t)}}function Yp(e,t){let n=(0,V.c)(12),r=me(),i=v(),a=Bp(),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=>{Xp(n.relatedTarget)||Xp(n.target)||Zp(n.relatedTarget)!==e&&Zp(n.relatedTarget?.closest(`[data-for-cell-id]`))!==e&&(a.remove(e),i.markTouched({cellId:e}),r.blurCell(),t.current&&nm(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}=di(c);return l}function Xp(e){return e?e instanceof HTMLElement&&e.closest(`.cm-vim-panel`)!==null:!1}function Zp(e){return e&&e.getAttribute(p)||null}function Qp(e,t){let r=(0,V.c)(34),{canMoveX:a,editorView:o,cellActionDropdownRef:s}=t,{saveOrNameNotebook:c}=Gf(),{saveCellConfig:u}=Tr(),d=l(Ai),f=v(),p=n(),m=Bp(),h=Ci(),g=i(Ft),{copyCells:_,pasteAtCell:y,cutCells:b}=wp(),x=Lp(),S=Ip(e),C=to(),w=oi(),ee=i(At),T;r[0]===ee?T=r[1]:(T=jt(ee),r[0]=ee,r[1]=T);let te=T,E;r[2]!==C||r[3]!==x?(E={clear:()=>{C.clear(),x.clear()},extend:e=>{C.clear(),x.extend(e)},select:e=>{C.clear(),x.select(e)}},r[2]=C,r[3]=x,r[4]=E):E=r[4];let D=E,O=i(Nt),k;r[5]===O?k=r[6]:(k=(e,t)=>qt(O.getHotkey(e).key)(t.nativeEvent||t),r[5]=O,r[6]=k);let A=k,re=Yp(e,o),j;r[7]!==f||r[8]!==te||r[9]!==a||r[10]!==s||r[11]!==e||r[12]!==_||r[13]!==b||r[14]!==w||r[15]!==o||r[16]!==S||r[17]!==A||r[18]!==g||r[19]!==y||r[20]!==C||r[21]!==h||r[22]!==u||r[23]!==c||r[24]!==D||r[25]!==d||r[26]!==p||r[27]!==m||r[28]!==ee?(j={onKeyDown:t=>{if(bn.fromInput(t)){t.continuePropagation();return}let n={"Mod+ArrowUp":()=>(f.focusTopCell(),D.clear(),!0),"Mod+ArrowDown":()=>(f.focusBottomCell(),D.clear(),!0),ArrowUp:()=>(f.focusCell({cellId:e,where:`before`}),D.clear(),!0),ArrowDown:()=>(f.focusCell({cellId:e,where:`after`}),D.clear(),!0),ArrowLeft:()=>{if(a){let t=p.get(Ce),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r-1);if(i&&i.length>0){let t=tm(e,i);return f.focusCell({cellId:t,where:`exact`}),D.clear(),!0}}return!1},ArrowRight:()=>{if(a){let t=p.get(Ce),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r+1);if(i&&i.length>0){let t=tm(e,i);return f.focusCell({cellId:t,where:`exact`}),D.clear(),!0}}return!1},"Shift+ArrowUp":()=>{let t=p.get(Ve);D.extend({cellId:e,allCellIds:t});let n=t.findWithId(e).before(e);return n&&D.extend({cellId:n,allCellIds:t}),f.focusCell({cellId:e,where:`before`}),!0},"Shift+ArrowDown":()=>{let t=p.get(Ve);D.extend({cellId:e,allCellIds:t});let n=t.findWithId(e).after(e);return n&&D.extend({cellId:n,allCellIds:t}),f.focusCell({cellId:e,where:`after`}),!0},Escape:()=>p.get(be).size>0?(p.set(Fe),!0):S?(D.clear(),!0):!1,Enter:()=>(m.add(e),F(p,e),D.clear(),!0),s:()=>(c(),!0)};for(let[e,r]of Object.entries(n))if(qt(e)(t)&&r()){t.preventDefault();return}let r={"cell.run":Jp(e=>(h(e),!0)),"cell.runAndNewBelow":Jp(e=>{h(e);let t=e[e.length-1];return f.moveToNextCell({cellId:t,before:!1}),!0}),"cell.runAndNewAbove":Jp(e=>{h(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":Jp(e=>{let t=e[0];return p.get(Ce).cellIds.findWithId(t).first()!==t&&(e.forEach(e=>{f.moveCell({cellId:e,before:!0})}),!0)}),"cell.moveDown":Jp(e=>{let t=e[e.length-1];return p.get(Ce).cellIds.findWithId(t).last()!==t&&(e.toReversed().forEach(e=>{f.moveCell({cellId:e,before:!1})}),!0)}),"cell.moveLeft":qp(e=>a?(f.moveCell({cellId:e,direction:`left`}),!0):!1),"cell.moveRight":qp(e=>a?(f.moveCell({cellId:e,direction:`right`}),!0):!1),"cell.hideCode":Jp(e=>{let t=!e.map(e=>p.get(Ce).cellData[e]?.config||null).every($p);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(),ce(n)):F(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":Jp(e=>(e.forEach(e=>{f.sendToBottom({cellId:e})}),!0)),"cell.sendToTop":Jp(e=>(e.toReversed().forEach(e=>{f.sendToTop({cellId:e})}),!0)),"cell.aiCompletion":e=>{if(!te)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":Jp(e=>(_(e),!0)),"command.cutCell":Jp(e=>(b(e),!0)),"command.pasteCell":e=>(y(e),!0),"command.createCellBefore":e=>!bn.hasModifier(t)&&(f.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),"command.createCellAfter":e=>!bn.hasModifier(t)&&(f.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"command.createSqlCellAfter":e=>!bn.hasModifier(t)&&(rt({autoInstantiate:!0,createNewCell:f.createNewCell,fromCellId:e,before:!0}),f.createNewCell({cellId:e,before:!1,autoFocus:!0,code:ne.sql.defaultCode}),!0),"cell.delete":()=>{if(!ee.keymap.destructive_delete)return!1;let t=i.size>=2?[...i]:[e],n=p.get(Ce);return t.some(e=>{let{status:t}=n.cellRuntime[e];return t===`running`||t===`queued`})?!1:C.idle?(C.submit(t),!0):(w({cellIds:t}),C.clear(),!0)}},i=Rp(p);if(g===`vim`&&Kp(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":()=>(_(i.size>=2?[...i]:[e]),!0),p:()=>(y(e,{before:!1}),!0),"shift+p":()=>(y(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(A(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]=te,r[9]=a,r[10]=s,r[11]=e,r[12]=_,r[13]=b,r[14]=w,r[15]=o,r[16]=S,r[17]=A,r[18]=g,r[19]=y,r[20]=C,r[21]=h,r[22]=u,r[23]=c,r[24]=D,r[25]=d,r[26]=p,r[27]=m,r[28]=ee,r[29]=j):j=r[29];let{keyboardProps:ie}=li(j),ae;return r[30]!==re||r[31]!==S||r[32]!==ie?(ae=ui(re,ie,{"data-selected":S,className:`data-[selected=true]:ring-1 data-[selected=true]:ring-(--blue-8) data-[selected=true]:ring-offset-1`}),r[30]=re,r[31]=S,r[32]=ie,r[33]=ae):ae=r[33],ae}function $p(e){return e?.hide_code}function em(e,t){let n=(0,V.c)(12),r=Bp(),a=i(Ft),o=i(Nt),s;if(n[0]!==o){let e=o.getHotkey(`command.vimEnterCommandMode`);s=qt(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),ce(e),D(()=>{de(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(ir(e))return;let r=!!n.field(Ze,!1)||!!n.field(Be,!1),i=br(n)!==null;r&&nm(e),i&&Sr(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}=li(p);return m}function tm(e,t){let n=document.getElementById(C.create(e));if(!n)return t.first();let r=n.getBoundingClientRect();for(let e of t.topLevelIds){let t=document.getElementById(C.create(e));if(t){let n=t.getBoundingClientRect();if(r.top<=n.bottom&&r.bottom>=n.top)return e}}return t.last()}function nm(e){e.state.field(Ze,!1)&&e.dispatch({effects:at.of(null)}),Xe(e)}var rm=50,im=4,am=60;function om(e){return Math.min(am,Math.max(im,e))}var sm=e=>{let t=(0,V.c)(13),{code:n,className:r}=e,i,a,o,s;if(t[0]!==r||t[1]!==n){let e=n.split(`
|
|
21
|
-
`,rm);t[6]===r?i=t[7]:(i=
|
|
20
|
+
`)}async function Cp(e){let t={cells:e.map(e=>({code:e.code,name:e.name,config:e.config})),version:`1.0`},n=new kp().add(bp,t).add(`text/plain`,Sp(e)).build();await navigator.clipboard.write([n])}function wp(){let e=(0,V.c)(13),t=v(),n=pt(),r=be(),i;e[0]===n?i=e[1]:(i=async e=>{let t=Pe(),r=e.map(e=>t.cellData[e]).filter(Boolean);if(r.length!==0)try{await Cp(r),n.clear(),Tp(r.length)}catch(e){let t=e;Gt.error(`Failed to copy cells to clipboard`,t);try{await Si(Sp(r)),n.clear(),Tp(r.length)}catch{Ep()}}},e[0]=n,e[1]=i);let a=c(i),o;e[2]===n?o=e[3]:(o=async e=>{let t=Pe(),r=e.filter(e=>t.cellData[e]),i=r.map(e=>t.cellData[e]);if(i.length!==0)try{await Cp(i),n.markForCut({cellIds:r})}catch(e){let t=e;Gt.error(`Failed to cut cells to clipboard`,t);try{await Si(Sp(i)),n.markForCut({cellIds:r})}catch{Ep()}}},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=Pe(),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(bp)){let n=await(await r.getType(bp)).text();try{let r=xp.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;Gt.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}):Dp()}catch(e){let t=e;Gt.error(`Failed to paste from clipboard`,t),Op()}},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 Tp=e=>{let t=e===1?`Cell`:`${e} cells`;gi({title:`${t} copied`,description:`${t} ${e===1?`has`:`have`} been copied to clipboard.`})},Ep=()=>{gi({title:`Copy failed`,description:`Failed to copy cells to clipboard.`,variant:`danger`})},Dp=()=>{gi({title:`Nothing to paste`,description:`No cell or text found in clipboard.`,variant:`danger`})},Op=()=>{gi({title:`Paste failed`,description:`Failed to read from clipboard`,variant:`danger`})},kp=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):(Gt.warn(`ClipboardItem does not support ${e}`),this)}build(){return new ClipboardItem(this.items)}};function Ap(){return{selectionStart:null,selectionEnd:null,selected:new Set}}var{reducer:jp,createActions:Mp,valueAtom:Np,useActions:Pp}=pr(Ap,{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:Ap()}),Fp=()=>i(Np);function Ip(e){let t=(0,V.c)(2),n;return t[0]===e?n=t[1]:(n=r(t=>t(Np).selected.has(e)),t[0]=e,t[1]=n),i(n)}function Lp(){return Pp()}function Rp(e){return e.get(Np).selected}var{valueAtom:zp,useActions:Bp}=pr(()=>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),D(()=>{let e=document.activeElement;if(!e)return;let t=He.findElementThroughShadowDOMs(e);t&&F(He.parse(t.id))}),n}}),Vp=e=>r(t=>t(zp).has(e));function Hp(e){let t=(0,V.c)(2),n;return t[0]===e?n=t[1]:(n=Vp(e),t[0]=e,t[1]=n),i(n)}var Up=new WeakMap,Wp=500;function Gp(e){if(e.ctrlKey||e.metaKey||e.altKey)return``;let t=e.key.toLowerCase();return e.shiftKey?`shift+${t}`:t}function Kp(e,t){let n=Gp(e),r=e.target;if(!n||!r)return!1;let i=Up.get(r),a=n;i?.timeout&&clearTimeout(i.timeout),i&&(a=`${i.sequence} ${n}`);let o=t[a];if(o)return Up.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(()=>{Up.delete(r)},Wp);return Up.set(r,{sequence:a,timeout:e}),!0}return Up.delete(r),!1}function qp(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 Jp(e){return{handle:t=>e([t]),bulkHandle:t=>e(t)}}function Yp(e,t){let n=(0,V.c)(12),r=pe(),i=v(),a=Bp(),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=>{Xp(n.relatedTarget)||Xp(n.target)||Zp(n.relatedTarget)!==e&&Zp(n.relatedTarget?.closest(`[data-for-cell-id]`))!==e&&(a.remove(e),i.markTouched({cellId:e}),r.blurCell(),t.current&&nm(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}=fi(c);return l}function Xp(e){return e?e instanceof HTMLElement&&e.closest(`.cm-vim-panel`)!==null:!1}function Zp(e){return e&&e.getAttribute(m)||null}function Qp(e,t){let r=(0,V.c)(34),{canMoveX:a,editorView:o,cellActionDropdownRef:s}=t,{saveOrNameNotebook:c}=Gf(),{saveCellConfig:u}=wr(),d=l(Ai),f=v(),p=n(),m=Bp(),h=Ci(),g=i(Pt),{copyCells:_,pasteAtCell:y,cutCells:b}=wp(),x=Lp(),S=Ip(e),C=to(),w=si(),T=i(kt),D;r[0]===T?D=r[1]:(D=At(T),r[0]=T,r[1]=D);let ee=D,O;r[2]!==C||r[3]!==x?(O={clear:()=>{C.clear(),x.clear()},extend:e=>{C.clear(),x.extend(e)},select:e=>{C.clear(),x.select(e)}},r[2]=C,r[3]=x,r[4]=O):O=r[4];let k=O,te=i(Mt),A;r[5]===te?A=r[6]:(A=(e,t)=>Kt(te.getHotkey(e).key)(t.nativeEvent||t),r[5]=te,r[6]=A);let ne=A,j=Yp(e,o),M;r[7]!==f||r[8]!==ee||r[9]!==a||r[10]!==s||r[11]!==e||r[12]!==_||r[13]!==b||r[14]!==w||r[15]!==o||r[16]!==S||r[17]!==ne||r[18]!==g||r[19]!==y||r[20]!==C||r[21]!==h||r[22]!==u||r[23]!==c||r[24]!==k||r[25]!==d||r[26]!==p||r[27]!==m||r[28]!==T?(M={onKeyDown:t=>{if(yn.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(ye),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r-1);if(i&&i.length>0){let t=tm(e,i);return f.focusCell({cellId:t,where:`exact`}),k.clear(),!0}}return!1},ArrowRight:()=>{if(a){let t=p.get(ye),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r+1);if(i&&i.length>0){let t=tm(e,i);return f.focusCell({cellId:t,where:`exact`}),k.clear(),!0}}return!1},"Shift+ArrowUp":()=>{let t=p.get(ze);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(ze);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(_e).size>0?(p.set(je),!0):S?(k.clear(),!0):!1,Enter:()=>(m.add(e),de(p,e),k.clear(),!0),s:()=>(c(),!0)};for(let[e,r]of Object.entries(n))if(Kt(e)(t)&&r()){t.preventDefault();return}let r={"cell.run":Jp(e=>(h(e),!0)),"cell.runAndNewBelow":Jp(e=>{h(e);let t=e[e.length-1];return f.moveToNextCell({cellId:t,before:!1}),!0}),"cell.runAndNewAbove":Jp(e=>{h(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":Jp(e=>{let t=e[0];return p.get(ye).cellIds.findWithId(t).first()!==t&&(e.forEach(e=>{f.moveCell({cellId:e,before:!0})}),!0)}),"cell.moveDown":Jp(e=>{let t=e[e.length-1];return p.get(ye).cellIds.findWithId(t).last()!==t&&(e.toReversed().forEach(e=>{f.moveCell({cellId:e,before:!1})}),!0)}),"cell.moveLeft":qp(e=>a?(f.moveCell({cellId:e,direction:`left`}),!0):!1),"cell.moveRight":qp(e=>a?(f.moveCell({cellId:e,direction:`right`}),!0):!1),"cell.hideCode":Jp(e=>{let t=!e.map(e=>p.get(ye).cellData[e]?.config||null).every($p);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(),se(n)):de(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":Jp(e=>(e.forEach(e=>{f.sendToBottom({cellId:e})}),!0)),"cell.sendToTop":Jp(e=>(e.toReversed().forEach(e=>{f.sendToTop({cellId:e})}),!0)),"cell.aiCompletion":e=>{if(!ee)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":Jp(e=>(_(e),!0)),"command.cutCell":Jp(e=>(b(e),!0)),"command.pasteCell":e=>(y(e),!0),"command.createCellBefore":e=>!yn.hasModifier(t)&&(f.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),"command.createCellAfter":e=>!yn.hasModifier(t)&&(f.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"command.createSqlCellAfter":e=>!yn.hasModifier(t)&&(tt({autoInstantiate:!0,createNewCell:f.createNewCell,fromCellId:e,before:!0}),f.createNewCell({cellId:e,before:!1,autoFocus:!0,code:E.sql.defaultCode}),!0),"cell.delete":()=>{if(!T.keymap.destructive_delete)return!1;let t=i.size>=2?[...i]:[e],n=p.get(ye);return t.some(e=>{let{status:t}=n.cellRuntime[e];return t===`running`||t===`queued`})?!1:C.idle?(C.submit(t),!0):(w({cellIds:t}),C.clear(),!0)}},i=Rp(p);if(g===`vim`&&Kp(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":()=>(_(i.size>=2?[...i]:[e]),!0),p:()=>(y(e,{before:!1}),!0),"shift+p":()=>(y(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(ne(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]=ee,r[9]=a,r[10]=s,r[11]=e,r[12]=_,r[13]=b,r[14]=w,r[15]=o,r[16]=S,r[17]=ne,r[18]=g,r[19]=y,r[20]=C,r[21]=h,r[22]=u,r[23]=c,r[24]=k,r[25]=d,r[26]=p,r[27]=m,r[28]=T,r[29]=M):M=r[29];let{keyboardProps:re}=ui(M),ie;return r[30]!==j||r[31]!==S||r[32]!==re?(ie=di(j,re,{"data-selected":S,className:`data-[selected=true]:ring-1 data-[selected=true]:ring-(--blue-8) data-[selected=true]:ring-offset-1`}),r[30]=j,r[31]=S,r[32]=re,r[33]=ie):ie=r[33],ie}function $p(e){return e?.hide_code}function em(e,t){let n=(0,V.c)(12),r=Bp(),a=i(Pt),o=i(Mt),s;if(n[0]!==o){let e=o.getHotkey(`command.vimEnterCommandMode`);s=Kt(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),se(e),D(()=>{F(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(rr(e))return;let r=!!n.field(j,!1)||!!n.field(Re,!1),i=yr(n)!==null;r&&nm(e),i&&xr(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}=ui(p);return m}function tm(e,t){let n=document.getElementById(He.create(e));if(!n)return t.first();let r=n.getBoundingClientRect();for(let e of t.topLevelIds){let t=document.getElementById(He.create(e));if(t){let n=t.getBoundingClientRect();if(r.top<=n.bottom&&r.bottom>=n.top)return e}}return t.last()}function nm(e){e.state.field(j,!1)&&e.dispatch({effects:he.of(null)}),Je(e)}var rm=50,im=4,am=60;function om(e){return Math.min(am,Math.max(im,e))}var sm=e=>{let t=(0,V.c)(13),{code:n,className:r}=e,i,a,o,s;if(t[0]!==r||t[1]!==n){let e=n.split(`
|
|
21
|
+
`,rm);t[6]===r?i=t[7]:(i=fn(`cm`,`mo-code-placeholder`,r),t[6]=r,t[7]=i),a=`cell-editor-placeholder`,o=!0,s=e.map(cm),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 cm(e,t){let n=e.trimEnd().length;return(0,U.jsx)(`div`,{className:`mo-code-placeholder-line`,children:n>0&&(0,U.jsx)(ia,{className:`mo-code-placeholder-bar`,style:{width:`${om(n)}ch`}})},t)}var lm=e=>{let t=(0,V.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=E.markdown.isSupported(r)||r.trim()===``,t[0]=r,t[1]=c);let l=c,u;t[2]===r?u=t[3]:(u=E.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)(Dr,{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)(um,{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)(Fi,{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)(um,{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)(Pi,{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)(um,{editorView:n,currentLanguageAdapter:i,canSwitchToLanguage:!0,icon:_,toType:`python`,displayName:`Python`,onAfterToggle:Ut.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},um=e=>{let t=(0,V.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&&(P(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)(bn,{"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)(vn,{content:d,children:f}),t[7]=d,t[8]=f,t[9]=p):p=t[9],p},dm=({theme:e,showPlaceholder:n,id:r,config:a,code:o,status:s,serializedEditorState:l,setEditorView:u,runCell:d,userConfig:f,editorViewRef:p,editorViewParentRef:m,hidden:h,hasOutput:g,showHiddenCode:y,languageAdapter:b,setLanguageAdapter:x,showLanguageToggles:S=!0,inlineAiTooltip:C,outputArea:w,tooltipParentSelector:T})=>{let[E,D]=t(Ai),ee=ci(),{saveOrNameNotebook:O}=Gf(),k=to(),{saveCellConfig:A}=wr(),ne=s===`running`||s===`queued`,j=v(),re=zi(),ie=b===`markdown`,ae=c(()=>ne?!1:k.idle&&f.keymap.destructive_delete?(k.submit([r]),!0):(ee({cellId:r}),!0)),oe=c(()=>!ne&&(d(),p.current&&nm(p.current),!0)),se=c(()=>{let e=!a.hide_code;return A({configs:{[r]:{hide_code:e}}}),j.updateCellConfig({cellId:r,config:{hide_code:e}}),e}),ce=i(jt),le=i(It),F=c(()=>{tt({autoInstantiate:ce,createNewCell:j.createNewCell}),a.hide_code||(A({configs:{[r]:{hide_code:!0}}}),j.updateCellConfig({cellId:r,config:{hide_code:!0}}),j.markUntouched({cellId:r}))}),ue=c(()=>{tt({autoInstantiate:ce,createNewCell:j.createNewCell})}),de=At(f),fe=(0,H.useMemo)(()=>{let t=Ud({cellId:r,showPlaceholder:n,enableAI:de,cellActions:{...j,afterToggleMarkdown:F,afterToggleSQL:ue,onRun:oe,deleteCell:ae,saveNotebook:O,createManyBelow:e=>{for(let t of e.toReversed())j.createNewCell({code:t,before:!1,cellId:r,skipIfCodeExists:!0})},addOrAppendSetupCell:e=>{let t=Pe();if(!t.cellIds.setupCellExists()){j.addSetupCellIfDoesntExist({code:e});return}let n=M(t)[te],r=n?st(n):t.cellData[te].code,i=r.trim()?`${r.trimEnd()}\n\n${e}`:e;n&>(n,i),j.updateCellCode({cellId:te,code:i,formattingChange:!1})},splitCell:re,toggleHideCode:se,aiCellCompletion:()=>{if(!de)return!1;let e=!1;return D(t=>t?.cellId===r?(e=!0,null):{cellId:r}),e}},completionConfig:f.completion,acceptCompletionOnEnter:le,keymapConfig:f.keymap,lspConfig:f.language_servers,theme:e,hotkeys:new Wt(f.keymap.overrides??{}),diagnosticsConfig:f.diagnostics,displayConfig:f.display,inlineAiTooltip:C??f.ai?.inline_tooltip??!1,tooltipParentSelector:T});return t.push(Qn.define(e=>(x(e.state.field(N).type),{update(e){x(e.state.field(N).type)}})),R.updateListener.of(e=>{e.selectionSet&&e.state.selection.ranges.some(e=>e.from!==e.to)&&y({focus:!1})}),R.domEventHandlers({focus:()=>{y({focus:!1})}})),t},[r,le,f.keymap,f.completion,f.language_servers,f.display,f.diagnostics,f.ai?.inline_tooltip,C,T,de,e,n,j,re,se,ae,oe,D,F,ue,x,y,O]),pe=Ae()&&Ee(r),me=c(()=>{if(pe){let e=Tf(r,e=>{j.updateCellCode({cellId:r,code:e,formattingChange:!0})},o);fe.push(e.extension),o=e.code}let e=new R({state:Bn.create({doc:o,extensions:fe})});u(e),pe||P(e,{language:ft(e.state).type})}),he=c(()=>{if(Jt(p.current!==null,`Editor view is not initialized`),pe){let e=Tf(r,e=>{j.updateCellCode({cellId:r,code:e,formattingChange:!0})});fe.push(e.extension)}p.current.dispatch({effects:[I.reconfigure.of([fe]),_(p.current,{completionConfig:f.completion,hotkeysProvider:new Wt(f.keymap.overrides??{}),lspConfig:{...f.language_servers,diagnostics:f.diagnostics}})]})}),ge=c(()=>{if(Jt(l,`Editor view is not initialized`),pe){let e=Tf(r,e=>{j.updateCellCode({cellId:r,code:e,formattingChange:!0})},o);fe.push(e.extension),o=e.code}let e=new R({state:Bn.fromJSON(l,{doc:o,extensions:fe},{history:tr})});pe||P(e,{language:ft(e.state).type}),u(e),j.clearSerializedEditorState({cellId:r})}),[_e,ve]=(0,H.useState)(l!==null);(0,H.useEffect)(()=>{if(p.current!==null){ve(!0);return}if(ve(!1),l!==null){ge(),ve(!0);return}return nt.request(r,()=>{p.current===null&&(me(),ve(!0))}),()=>nt.cancel(r)},[r,p,ge,me,l]),(0,H.useEffect)(()=>{p.current!==null&&he()},[he,fe,p]),(0,H.useEffect)(()=>()=>{p.current?.destroy(),p.current=null},[p]);let[ye,be]=hn({rootMargin:`300px 0px`,threshold:0});(0,H.useEffect)(()=>{_e||(be?.isIntersecting?nt.prioritize(r):nt.deprioritize(r))},[_e,be?.isIntersecting,r]);let xe=em(r,p),Se=``;return ie&&h&&g?Se=`h-0 overflow-hidden`:h&&(Se=`opacity-20 h-8 [&>div.cm-editor]:h-full [&>div.cm-editor]:overflow-hidden [&_.cm-panels]:hidden`),(0,U.jsx)(vp,{cellId:r,aiCompletionCell:E,currentCode:p.current?.state.doc.toString()??o,currentLanguageAdapter:b,declineChange:c(()=>{D(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(),D(null)}),runCell:oe,outputArea:w,children:(0,U.jsxs)(`div`,{className:`relative w-full`,ref:ye,...xe,children:[_e?(0,U.jsx)(fm,{className:Se,editorView:p.current,ref:m,hidden:h,showHiddenCode:y}):(0,U.jsx)(sm,{code:o,className:Se}),!h&&S&&(0,U.jsx)(`div`,{className:`absolute top-1 right-5`,children:(0,U.jsx)(lm,{code:o,editorView:p.current,currentLanguageAdapter:b,onAfterToggle:F})})]})})},fm=H.forwardRef((e,t)=>{let n=(0,V.c)(14),{className:r,editorView:i,hidden:a,showHiddenCode:o}=e,s=(0,H.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,H.useEffect)(c,l);let u;n[3]===r?u=n[4]:(u=fn(`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?ep(t,s)(e):ep(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,V.c)(5),a=i(rn),[o,s]=t(Sf);if(Ae()&&Ee(n.id)&&(en(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)(gn,{milliseconds:1e3,fallback:null,children:[e,(0,U.jsx)(bn,{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=Ae()?pm((0,H.memo)(dm)):(0,H.memo)(dm);export{md as _,Bp as a,to as b,ep as c,Lf as d,Af as f,pd as g,_d as h,Hp as i,Wf as l,vd as m,lm as n,Lp as o,Sf as p,Qp as r,Fp as s,mm as t,Gf as u,fd as v,no as y};
|