sliccy 6.180.0 → 6.181.0
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/ui/.vite/manifest.json +217 -189
- package/dist/ui/assets/account-store-0RMtbmqz.js +1 -0
- package/dist/ui/assets/account-store-J3ybiSNw.js +2 -0
- package/dist/ui/assets/adobe-DEXpooxf.js +1 -0
- package/dist/ui/assets/adobe-YOeKKYUk.js +2 -0
- package/dist/ui/assets/{agent-panels-D9q2my7u.js → agent-panels-B4hlhzVG.js} +1 -1
- package/dist/ui/assets/{almost-bash-shell-headless-FNia8qKH.js → almost-bash-shell-headless-BR1Hr6tM.js} +30 -30
- package/dist/ui/assets/{apply-layout-CY0ZMc2P.js → apply-layout-BgFVMSBx.js} +1 -1
- package/dist/ui/assets/{apps-30Hsl8Yx.js → apps-oyrUmtWx.js} +1 -1
- package/dist/ui/assets/{azure-openai-CDmJiho_.js → azure-openai-B6qTFVGv.js} +1 -1
- package/dist/ui/assets/{azure-openai-9tspjkO5.js → azure-openai-Ytc_MWDd.js} +1 -1
- package/dist/ui/assets/{backend-hostfs-Zq8eFtjc.js → backend-hostfs-CEXlx0cW.js} +1 -1
- package/dist/ui/assets/{cdp-C42JpbnT.js → cdp-DVWJozRc.js} +1 -1
- package/dist/ui/assets/{cerebras-CFf6FV04.js → cerebras-BT44OLPt.js} +1 -1
- package/dist/ui/assets/{cerebras-D2OPqUBP.js → cerebras-brHRFUH2.js} +1 -1
- package/dist/ui/assets/{composer-speech-Bi2POadn.js → composer-speech-BZQtz7u1.js} +1 -1
- package/dist/ui/assets/{connect-surface-DQTvGzL6.js → connect-surface-D7cq2QI7.js} +1 -1
- package/dist/ui/assets/core-B3ULTK7V.js +62 -0
- package/dist/ui/assets/core-aQUekdF7.js +36 -0
- package/dist/ui/assets/{directed-approval-DsTXqsDu.js → directed-approval-DvAxEX5J.js} +1 -1
- package/dist/ui/assets/{emscripten-vfs-hook-Bg1EUSS-.js → emscripten-vfs-hook-agmT6Hsz.js} +1 -1
- package/dist/ui/assets/{ensure-speech-assets-0UZlYzUX.js → ensure-speech-assets-CQ05z2Xw.js} +1 -1
- package/dist/ui/assets/feature-flags-BftQitIZ.js +1 -0
- package/dist/ui/assets/feature-flags-ysThCqxC.js +1 -0
- package/dist/ui/assets/{frozen-archive-writer-C0vwpeI6.js → frozen-archive-writer-qxZ9jGOV.js} +1 -1
- package/dist/ui/assets/fs-D6FCLu_F.js +1 -0
- package/dist/ui/assets/fs-Dkh-H6Cd.js +2 -0
- package/dist/ui/assets/{gelatiere-store-6PnudWGB.js → gelatiere-store-ChogqkEu.js} +1 -1
- package/dist/ui/assets/{gelatiere-unit-BguezRYn.js → gelatiere-unit-DxFUh33e.js} +1 -1
- package/dist/ui/assets/{github-CG-b1Yz_.js → github-CrHzeKQ8.js} +1 -1
- package/dist/ui/assets/{github-D7kyOyzh.js → github-D31l6kcK.js} +2 -2
- package/dist/ui/assets/{github-auth-BraqNx1i.js → github-auth-VTbKhlbJ.js} +1 -1
- package/dist/ui/assets/github-copilot-CVwHDKPD.js +2 -0
- package/dist/ui/assets/github-copilot-eUb4Djg_.js +1 -0
- package/dist/ui/assets/{github-install-BpIzczOh.js → github-install-Dkt1u6HU.js} +1 -1
- package/dist/ui/assets/{github-zip-CpV4XMuv.js → github-zip-B6gHXxqd.js} +1 -1
- package/dist/ui/assets/{guest-tool-gate-yzMDXmb7.js → guest-tool-gate-YxkVsl15.js} +1 -1
- package/dist/ui/assets/{hear-D1xfqCRf.js → hear-BKQjhhNP.js} +1 -1
- package/dist/ui/assets/{help-DNjYeiru.js → help-C7WHd3Ia.js} +1 -1
- package/dist/ui/assets/{installer-pNvmgsp2.js → installer-D35TzRKw.js} +1 -1
- package/dist/ui/assets/{interrupted-work-recovery-dk4HMys6.js → interrupted-work-recovery-BK9ZDM7F.js} +1 -1
- package/dist/ui/assets/js-realm-worker-BIVxi3Fa.js +50 -0
- package/dist/ui/assets/{jsh-executor-BuREMqJc.js → jsh-executor-DhdH2_yG.js} +2 -2
- package/dist/ui/assets/{kernel-worker-CMZdB97j.js → kernel-worker-UUfeG-Eg.js} +68 -68
- package/dist/ui/assets/{lick-ws-bridge-CVcgQWV0.js → lick-ws-bridge-DdgwrW91.js} +1 -1
- package/dist/ui/assets/{lick-ws-bridge-nPLmwzQd.js → lick-ws-bridge-DoyPgrSr.js} +1 -1
- package/dist/ui/assets/live-session-curation-6O9TA5qM.js +1 -0
- package/dist/ui/assets/{live-session-snapshot-BSndLrLB.js → live-session-snapshot-D_7T7FHe.js} +1 -1
- package/dist/ui/assets/{local-llm-o-MjgDNe.js → local-llm-BYaSa2xI.js} +1 -1
- package/dist/ui/assets/{local-llm-C4hKvsjN.js → local-llm-TK4oGrWD.js} +1 -1
- package/dist/ui/assets/main-Bgkf5d3Z.js +22 -0
- package/dist/ui/assets/{main-cherry-NHI23XOX.js → main-cherry-BUdIAeG5.js} +1 -1
- package/dist/ui/assets/{memory-curation-seam-CmUEG05f.js → memory-curation-seam-CNOuxuz4.js} +1 -1
- package/dist/ui/assets/{memory-health-DVwJNc8y.js → memory-health-BSo0HKQx.js} +1 -1
- package/dist/ui/assets/memory-v2-flag-CX_dAcAR.js +1 -0
- package/dist/ui/assets/{memory-write-execute-E9mWyIAl.js → memory-write-execute-mQfg-aG4.js} +1 -1
- package/dist/ui/assets/{mount-zxJpqjfc.js → mount-BpcQX-Sq.js} +1 -1
- package/dist/ui/assets/{mount-CkCLiqtz.js → mount-h-dwh5GL.js} +3 -3
- package/dist/ui/assets/new-session-CTx7YRbr.js +2 -0
- package/dist/ui/assets/oauth-bootstrap-B18nfDG4.js +2 -0
- package/dist/ui/assets/{onboarding-orchestrator-NspTxzE-.js → onboarding-orchestrator-Df3UDgbD.js} +1 -1
- package/dist/ui/assets/{openai-codex-CtV9F4YZ.js → openai-codex-Cu1dT_JE.js} +1 -1
- package/dist/ui/assets/{openai-codex-CcVYEGxA.js → openai-codex-DBUtEEk3.js} +1 -1
- package/dist/ui/assets/{openrouter-BNWklYTU.js → openrouter-BwrZKpwu.js} +1 -1
- package/dist/ui/assets/{openrouter-B_ZafRVO.js → openrouter-CrB0BbnV.js} +1 -1
- package/dist/ui/assets/{openrouter-free-BGkRgNKy.js → openrouter-free-B_LRYNX8.js} +1 -1
- package/dist/ui/assets/{openrouter-free-B9EMo-e7.js → openrouter-free-CXqUunRn.js} +1 -1
- package/dist/ui/assets/{openrouter-oauth-CIOPqcnL.js → openrouter-oauth-Bnohq7Ac.js} +1 -1
- package/dist/ui/assets/{openrouter-oauth-DqZoGOX4.js → openrouter-oauth-Bpzo9cvY.js} +1 -1
- package/dist/ui/assets/{opfs-mount-DVnNHDGI.js → opfs-mount-CmDtZOGy.js} +1 -1
- package/dist/ui/assets/panel-rpc-handlers-BFG-ZvfW.js +2 -0
- package/dist/ui/assets/{panelize-shell-6EgwajIj.js → panelize-shell-CLHSr5bz.js} +1 -1
- package/dist/ui/assets/{pi-edit-execution-C2vx7I8W.js → pi-edit-execution-wHbJ4R48.js} +1 -1
- package/dist/ui/assets/{provider-BM8Fl5eb.js → provider-BXK9OD8Z.js} +2 -2
- package/dist/ui/assets/{provider-Do8GE35W.js → provider-DyqdvQeZ.js} +1 -1
- package/dist/ui/assets/{provider-settings-C5-R4CAK.js → provider-settings-BO6Fedc5.js} +1 -1
- package/dist/ui/assets/provider-store-access-BFeKOGcv.js +1 -0
- package/dist/ui/assets/provider-store-access-C2X0AryS.js +1 -0
- package/dist/ui/assets/providers-BvApGkM9.js +2 -0
- package/dist/ui/assets/{providers-1XGnlkRB.js → providers-CAcycJZb.js} +1 -1
- package/dist/ui/assets/{quick-llm-C0JjR1ll.js → quick-llm-BENSRBxD.js} +1 -1
- package/dist/ui/assets/realm-inprocess-BBw2Fa8u.js +30 -0
- package/dist/ui/assets/{recovery-screen-DTnntvly.js → recovery-screen-Tq3wGnmV.js} +1 -1
- package/dist/ui/assets/{remote-terminal-view-Cd-B2Hl9.js → remote-terminal-view-C8LiE7Sl.js} +1 -1
- package/dist/ui/assets/{restore-B5L76uAO.js → restore-DVP0SPlY.js} +1 -1
- package/dist/ui/assets/{run-29F7vZr6.js → run-BGZP3j5p.js} +2 -2
- package/dist/ui/assets/{run-CQO2CvCb.js → run-BV_OY-0v.js} +1 -1
- package/dist/ui/assets/{run-BJ1lweaR.js → run-CPT6_R-_.js} +2 -2
- package/dist/ui/assets/{run-twzOjiSl.js → run-CiUSMP3Y.js} +2 -2
- package/dist/ui/assets/{run-BAVclQ_q.js → run-FyOp8GaC.js} +2 -2
- package/dist/ui/assets/{run-CG0v2Pw6.js → run-zLr2k5ZP.js} +1 -1
- package/dist/ui/assets/{session-command-memory-BBSebn07.js → session-command-memory-HovmIuMP.js} +2 -2
- package/dist/ui/assets/{session-jsonl-Dx1wwk9X.js → session-jsonl-DK-0Hm8U.js} +1 -1
- package/dist/ui/assets/{session-jsonl-__tig_P-.js → session-jsonl-PCOch0_B.js} +1 -1
- package/dist/ui/assets/{session-search-index-DCrprmyT.js → session-search-index-BNvhiRLv.js} +1 -1
- package/dist/ui/assets/setup-feature-flags-remote-2RQqEGaT.js +1 -0
- package/dist/ui/assets/setup-model-catalog-B911rONc.js +1 -0
- package/dist/ui/assets/{signed-fetch-D8kpqzQr.js → signed-fetch-gB25Bw53.js} +1 -1
- package/dist/ui/assets/{silent-renew-backoff-Zis9tJLB.js → silent-renew-backoff-Brcr76an.js} +1 -1
- package/dist/ui/assets/slicc-version-CAje2bW-.js +1 -0
- package/dist/ui/assets/{snapshot-D6x5FQ65.js → snapshot-Ci8jnY_A.js} +1 -1
- package/dist/ui/assets/{snapshot-features-B0z9yqF8.js → snapshot-features-BYEGCVfZ.js} +1 -1
- package/dist/ui/assets/{soundscape-BNuowQ7c.js → soundscape-CdQvLeB0.js} +1 -1
- package/dist/ui/assets/{speak-CM0G-jv2.js → speak-BT4Xdlvj.js} +1 -1
- package/dist/ui/assets/sprinkle-manager-8T1XJmL3.js +1 -0
- package/dist/ui/assets/{sprinkle-renderer-BZ70q8U0.js → sprinkle-renderer-_vOdPt8H.js} +1 -1
- package/dist/ui/assets/{state-CMaAjNLX.js → state-nnDajRje.js} +1 -1
- package/dist/ui/assets/{store-BkgqEymP.js → store-BxxMrsS7.js} +1 -1
- package/dist/ui/assets/{store-DClHiTYa.js → store-D9XL9aIQ.js} +1 -1
- package/dist/ui/assets/{sudo-PCV39MiN.js → sudo-CnXURhFV.js} +1 -1
- package/dist/ui/assets/{supervisor-DtbPDqlw.js → supervisor-fOZGoD0G.js} +1 -1
- package/dist/ui/assets/{sync-dialog-ulF7EhDB.js → sync-dialog-oh_O9Mv5.js} +1 -1
- package/dist/ui/assets/{transformers-env-DA6yIZOQ.js → transformers-env-zmBF2In6.js} +1 -1
- package/dist/ui/assets/{tray-leader-CaNUXMyA.js → tray-leader-Co-1rs4b.js} +1 -1
- package/dist/ui/assets/{tray-leave-runtime-B6H2og7r.js → tray-leave-runtime-PpRt0K76.js} +1 -1
- package/dist/ui/assets/{tray-sidecar-dMsrQrjt.js → tray-sidecar-DYuM8Ifi.js} +1 -1
- package/dist/ui/assets/{turn-journal-DGbDeEVx.js → turn-journal-_Hrn3Aoy.js} +1 -1
- package/dist/ui/assets/{upgrade-detection-B0UzxzJj.js → upgrade-detection-jhAzOLSL.js} +1 -1
- package/dist/ui/assets/{upskill-lick-skip-Dwqx8mXn.js → upskill-lick-skip-D1vFOKgN.js} +1 -1
- package/dist/ui/assets/{voice-reply-DZehR7u8.js → voice-reply--Z1dXvPT.js} +1 -1
- package/dist/ui/assets/wc-attach-BadBFuc7.js +13 -0
- package/dist/ui/assets/{wc-browser-Bn2kzFBz.js → wc-browser-DqUJaWcH.js} +1 -1
- package/dist/ui/assets/{wc-computers-BGpGK_lD.js → wc-computers-CTPf-95b.js} +1 -1
- package/dist/ui/assets/{wc-detached-C2Uoiq-A.js → wc-detached-UIVnUZp5.js} +1 -1
- package/dist/ui/assets/wc-extension-Bxc7adS3.js +2 -0
- package/dist/ui/assets/wc-follower-CcQiy0Ep.js +17 -0
- package/dist/ui/assets/{wc-follower-oauth-d5z3eyJQ.js → wc-follower-oauth-DEBzlhDR.js} +1 -1
- package/dist/ui/assets/wc-gelatiere-B3T_MsYw.js +1 -0
- package/dist/ui/assets/{wc-live-D_nDQ7fc.js → wc-live-B4gJYGS5.js} +8 -8
- package/dist/ui/assets/wc-nav-Cc31eRBb.js +2 -0
- package/dist/ui/assets/{wc-onboarding-zTyXdDGG.js → wc-onboarding-A_43Ieo4.js} +2 -2
- package/dist/ui/assets/{wc-permissions-DE03I9yf.js → wc-permissions-C9woviuI.js} +2 -2
- package/dist/ui/assets/wc-placeholder-t7YMeS_j.js +4 -0
- package/dist/ui/assets/{wc-secret-request-G0Qd5fKh.js → wc-secret-request-Dfm9QvyE.js} +1 -1
- package/dist/ui/assets/{wc-settings-D6ynnLLu.js → wc-settings-BD6JONjg.js} +3 -3
- package/dist/ui/assets/{wc-shell-CRmcNm3q.js → wc-shell-Ba5uNdmF.js} +152 -152
- package/dist/ui/assets/{wc-shortcut-config-BgzkZguq.js → wc-shortcut-config-DeU2Q2BU.js} +1 -1
- package/dist/ui/assets/wc-sprinkles-D4sQVRG5.js +2 -0
- package/dist/ui/assets/wc-transcript-export-CsUhlwMo.js +2 -0
- package/dist/ui/assets/{wc-tray-Dddp-0o-.js → wc-tray-CwvVidS8.js} +4 -4
- package/dist/ui/assets/welcome-detection-CIDbn0ev.js +1 -0
- package/dist/ui/assets/whisper-session-MB0YiZ0q.js +2 -0
- package/dist/ui/assets/xai-grok-0BxCS34q.js +1 -0
- package/dist/ui/assets/xai-grok-rwJAZiuv.js +1 -0
- package/dist/ui/index.html +5 -4
- package/dist/ui/packages/webapp/index.html +5 -4
- package/package.json +1 -1
- package/dist/ui/assets/account-store-C-p1lMw5.js +0 -2
- package/dist/ui/assets/account-store-CQ9VWuvY.js +0 -1
- package/dist/ui/assets/adobe-BUhDM15K.js +0 -2
- package/dist/ui/assets/adobe-CBr4ZN4n.js +0 -1
- package/dist/ui/assets/core-DeN3S2m9.js +0 -62
- package/dist/ui/assets/core-QNbq3R8b.js +0 -36
- package/dist/ui/assets/fs-BtFAX2_M.js +0 -2
- package/dist/ui/assets/fs-DvluRaqj.js +0 -1
- package/dist/ui/assets/github-copilot-CiSp3eBW.js +0 -1
- package/dist/ui/assets/github-copilot-DuD7Lgmt.js +0 -2
- package/dist/ui/assets/js-realm-worker-CkAMvsrT.js +0 -50
- package/dist/ui/assets/live-session-curation-eLY2VPhg.js +0 -1
- package/dist/ui/assets/main-CbW_Za2k.js +0 -22
- package/dist/ui/assets/memory-v2-flag-CnOOdxrM.js +0 -1
- package/dist/ui/assets/new-session-BtrbxZ1f.js +0 -2
- package/dist/ui/assets/oauth-bootstrap-CUEpFgrr.js +0 -2
- package/dist/ui/assets/panel-rpc-handlers-BSCm4kOU.js +0 -2
- package/dist/ui/assets/provider-store-access-CXCNqTez.js +0 -1
- package/dist/ui/assets/provider-store-access-HnHz6M14.js +0 -1
- package/dist/ui/assets/providers-vlrJYxJ5.js +0 -2
- package/dist/ui/assets/realm-inprocess-C6O9qOMR.js +0 -30
- package/dist/ui/assets/setup-feature-flags-remote-05sIbIjy.js +0 -1
- package/dist/ui/assets/slicc-version-yq-tq2SV.js +0 -1
- package/dist/ui/assets/sprinkle-manager-BEv6kGLS.js +0 -1
- package/dist/ui/assets/wc-attach-CM9VDfpp.js +0 -13
- package/dist/ui/assets/wc-extension-Dkkjge5w.js +0 -2
- package/dist/ui/assets/wc-follower-CszcNst7.js +0 -17
- package/dist/ui/assets/wc-gelatiere-CvD4RPku.js +0 -1
- package/dist/ui/assets/wc-nav-DYqaPxPj.js +0 -2
- package/dist/ui/assets/wc-placeholder-CFl99JIA.js +0 -4
- package/dist/ui/assets/wc-sprinkles-BEdhIep-.js +0 -2
- package/dist/ui/assets/wc-transcript-export-CRdtzxLx.js +0 -2
- package/dist/ui/assets/welcome-detection-D-EYPpBI.js +0 -1
- package/dist/ui/assets/whisper-session-BQeRsdCz.js +0 -2
- package/dist/ui/assets/xai-grok-CtZfuLLm.js +0 -1
- package/dist/ui/assets/xai-grok-D2lF8Cx-.js +0 -1
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./logger-LESFN7Hj.js";import{r as n,t as r}from"./base64-BPBW1Gzr.js";import"./proxied-fetch-CNe6icTW.js";import{t as i}from"./runtime-env-DadgceZk.js";import{a,s as o,t as s}from"./api-endpoint-D8lUKmPu.js";import{$ as c,G as l,S as u,U as d,y as f}from"./build-BRNa03GH.js";import"./compat-uEPf6-XW.js";import"./libesm-CTQYxJIv.js";import"./context-compaction-Dpr7xgBZ.js";import{t as p}from"./secrets-bridge-client-kWWipUuL.js";import{r as m,t as h}from"./image-markers-CwM1dvoI.js";import{o as g,s as _}from"./tool-ui-DRnUkp2g.js";function v(e,t){try{return Promise.resolve(t(y))}catch(e){return Promise.reject(e)}}const y={startSpan:v,addEvent:()=>{},setAttributes:()=>{},setStatus:()=>{}};Object.freeze(y);const b=Symbol.for(`yaml.alias`),x=Symbol.for(`yaml.document`),S=Symbol.for(`yaml.map`),C=Symbol.for(`yaml.pair`),ee=Symbol.for(`yaml.scalar`),w=Symbol.for(`yaml.seq`),T=Symbol.for(`yaml.node.type`),E=e=>!!e&&typeof e==`object`&&e[T]===b,D=e=>!!e&&typeof e==`object`&&e[T]===x,te=e=>!!e&&typeof e==`object`&&e[T]===S,O=e=>!!e&&typeof e==`object`&&e[T]===C,k=e=>!!e&&typeof e==`object`&&e[T]===ee,A=e=>!!e&&typeof e==`object`&&e[T]===w;function j(e){if(e&&typeof e==`object`)switch(e[T]){case S:case w:return!0}return!1}function M(e){if(e&&typeof e==`object`)switch(e[T]){case b:case S:case ee:case w:return!0}return!1}const ne=e=>(k(e)||j(e))&&!!e.anchor,N=Symbol(`break visit`),re=Symbol(`skip children`),P=Symbol(`remove node`);function F(e,t){let n=ie(t);D(e)?I(null,e.contents,n,Object.freeze([e]))===P&&(e.contents=null):I(null,e,n,Object.freeze([]))}F.BREAK=N,F.SKIP=re,F.REMOVE=P;function I(e,t,n,r){let i=ae(e,t,n,r);if(M(i)||O(i))return oe(e,r,i),I(e,i,n,r);if(typeof i!=`symbol`){if(j(t)){r=Object.freeze(r.concat(t));for(let e=0;e<t.items.length;++e){let i=I(e,t.items[e],n,r);if(typeof i==`number`)e=i-1;else if(i===N)return N;else i===P&&(t.items.splice(e,1),--e)}}else if(O(t)){r=Object.freeze(r.concat(t));let e=I(`key`,t.key,n,r);if(e===N)return N;e===P&&(t.key=null);let i=I(`value`,t.value,n,r);if(i===N)return N;i===P&&(t.value=null)}}return i}function ie(e){return typeof e==`object`&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function ae(e,t,n,r){if(typeof n==`function`)return n(e,t,r);if(te(t))return n.Map?.(e,t,r);if(A(t))return n.Seq?.(e,t,r);if(O(t))return n.Pair?.(e,t,r);if(k(t))return n.Scalar?.(e,t,r);if(E(t))return n.Alias?.(e,t,r)}function oe(e,t,n){let r=t[t.length-1];if(j(r))r.items[e]=n;else if(O(r))e===`key`?r.key=n:r.value=n;else if(D(r))r.contents=n;else{let e=E(r)?`alias`:`scalar`;throw Error(`Cannot replace node with ${e} parent`)}}function se(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(e)}`;throw Error(t)}return!0}function L(e,t,n,r){if(r&&typeof r==`object`){if(Array.isArray(r))for(let t=0,n=r.length;t<n;++t){let n=r[t],i=L(e,r,String(t),n);i===void 0?delete r[t]:i!==n&&(r[t]=i)}else if(r instanceof Map)for(let t of Array.from(r.keys())){let n=r.get(t),i=L(e,r,t,n);i===void 0?r.delete(t):i!==n&&r.set(t,i)}else if(r instanceof Set)for(let t of Array.from(r)){let n=L(e,r,t,t);n===void 0?r.delete(t):n!==t&&(r.delete(t),r.add(n))}else for(let[t,n]of Object.entries(r)){let i=L(e,r,t,n);i===void 0?delete r[t]:i!==n&&(r[t]=i)}}return e.call(t,n,r)}function R(e,t,n){if(Array.isArray(e))return e.map((e,t)=>R(e,String(t),n));if(e&&typeof e.toJSON==`function`){if(!n||!ne(e))return e.toJSON(t,n);let r={aliasCount:0,count:1,res:void 0};n.anchors.set(e,r),n.onCreate=e=>{r.res=e,delete n.onCreate};let i=e.toJSON(t,n);return n.onCreate&&n.onCreate(i),i}return typeof e==`bigint`&&!n?.keep?Number(e):e}var ce=class{constructor(e){Object.defineProperty(this,T,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:r,reviver:i}={}){if(!D(e))throw TypeError(`A document argument is required`);let a={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof n==`number`?n:100},o=R(this,``,a);if(typeof r==`function`)for(let{count:e,res:t}of a.anchors.values())r(t,e);return typeof i==`function`?L(i,{"":o},``,o):o}},le=class extends ce{constructor(e){super(b),this.source=e,Object.defineProperty(this,"tag",{set(){throw Error(`Alias nodes cannot have tags`)}})}resolve(e,t){if(t?.maxAliasCount===0)throw ReferenceError(`Alias resolution is disabled`);let n;t?.aliasResolveCache?n=t.aliasResolveCache:(n=[],F(e,{Node:(e,t)=>{(E(t)||ne(t))&&n.push(t)}}),t&&(t.aliasResolveCache=n));let r;for(let e of n){if(e===this)break;e.anchor===this.source&&(r=e)}return r}toJSON(e,t){if(!t)return{source:this.source};let{anchors:n,doc:r,maxAliasCount:i}=t,a=this.resolve(r,t);if(!a){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw ReferenceError(e)}let o=n.get(a);if(o||=(R(a,null,t),n.get(a)),o?.res===void 0)throw ReferenceError(`This should not happen: Alias anchor was not resolved?`);if(i>=0&&(o.count+=1,o.aliasCount===0&&(o.aliasCount=z(r,a,n)),o.count*o.aliasCount>i))throw ReferenceError(`Excessive alias count indicates a resource exhaustion attack`);return o.res}toString(e,t,n){let r=`*${this.source}`;if(e){if(se(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw Error(e)}if(e.implicitKey)return`${r} `}return r}};function z(e,t,n){if(E(t)){let r=t.resolve(e),i=n&&r&&n.get(r);return i?i.count*i.aliasCount:0}if(j(t)){let r=0;for(let i of t.items){let t=z(e,i,n);t>r&&(r=t)}return r}if(O(t)){let r=z(e,t.key,n),i=z(e,t.value,n);return Math.max(r,i)}return 1}const ue=e=>!e||typeof e!=`function`&&typeof e!=`object`;var B=class extends ce{constructor(e){super(ee),this.value=e}toJSON(e,t){return t?.keep?this.value:R(this.value,e,t)}toString(){return String(this.value)}};B.BLOCK_FOLDED=`BLOCK_FOLDED`,B.BLOCK_LITERAL=`BLOCK_LITERAL`,B.PLAIN=`PLAIN`,B.QUOTE_DOUBLE=`QUOTE_DOUBLE`,B.QUOTE_SINGLE=`QUOTE_SINGLE`;function de(e,t,n){if(t){let e=n.filter(e=>e.tag===t),r=e.find(e=>!e.format)??e[0];if(!r)throw Error(`Tag ${t} not found`);return r}return n.find(t=>t.identify?.(e)&&!t.format)}function V(e,t,n){if(D(e)&&(e=e.contents),M(e))return e;if(O(e)){let t=n.schema[S].createNode?.(n.schema,null,n);return t.items.push(e),t}(e instanceof String||e instanceof Number||e instanceof Boolean||typeof BigInt<`u`&&e instanceof BigInt)&&(e=e.valueOf());let{aliasDuplicateObjects:r,onAnchor:i,onTagObj:a,schema:o,sourceObjects:s}=n,c;if(r&&e&&typeof e==`object`){if(c=s.get(e),c)return c.anchor??(c.anchor=i(e)),new le(c.anchor);c={anchor:null,node:null},s.set(e,c)}t?.startsWith(`!!`)&&(t=`tag:yaml.org,2002:`+t.slice(2));let l=de(e,t,o.tags);if(!l){if(e&&typeof e.toJSON==`function`&&(e=e.toJSON()),!e||typeof e!=`object`){let t=new B(e);return c&&(c.node=t),t}l=e instanceof Map?o[S]:Symbol.iterator in Object(e)?o[w]:o[S]}a&&(a(l),delete n.onTagObj);let u=l?.createNode?l.createNode(n.schema,e,n):typeof l?.nodeClass?.from==`function`?l.nodeClass.from(n.schema,e,n):new B(e);return t?u.tag=t:l.default||(u.tag=l.tag),c&&(c.node=u),u}function fe(e,t,n){let r=n;for(let e=t.length-1;e>=0;--e){let n=t[e];if(typeof n==`number`&&Number.isInteger(n)&&n>=0){let e=[];e[n]=r,r=e}else r=new Map([[n,r]])}return V(r,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw Error(`This should not happen, please report a bug.`)},schema:e,sourceObjects:new Map})}const pe=e=>e==null||typeof e==`object`&&!!e[Symbol.iterator]().next().done;var me=class extends ce{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(t=>M(t)||O(t)?t.clone(e):t),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(pe(e))this.add(t);else{let[n,...r]=e,i=this.get(n,!0);if(j(i))i.addIn(r,t);else if(i===void 0&&this.schema)this.set(n,fe(this.schema,r,t));else throw Error(`Expected YAML collection at ${n}. Remaining path: ${r}`)}}deleteIn(e){let[t,...n]=e;if(n.length===0)return this.delete(t);let r=this.get(t,!0);if(j(r))return r.deleteIn(n);throw Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){let[n,...r]=e,i=this.get(n,!0);return r.length===0?!t&&k(i)?i.value:i:j(i)?i.getIn(r,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!O(t))return!1;let n=t.value;return n==null||e&&k(n)&&n.value==null&&!n.commentBefore&&!n.comment&&!n.tag})}hasIn(e){let[t,...n]=e;if(n.length===0)return this.has(t);let r=this.get(t,!0);return j(r)?r.hasIn(n):!1}setIn(e,t){let[n,...r]=e;if(r.length===0)this.set(n,t);else{let e=this.get(n,!0);if(j(e))e.setIn(r,t);else if(e===void 0&&this.schema)this.set(n,fe(this.schema,r,t));else throw Error(`Expected YAML collection at ${n}. Remaining path: ${r}`)}}};const he=e=>e.replace(/^(?!$)(?: $)?/gm,`#`);function H(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}const U=(e,t,n)=>e.endsWith(`
|
|
2
|
-
`)?H(n,t):n.includes(`
|
|
3
|
-
`)?`
|
|
4
|
-
`+H(n,t):(e.endsWith(` `)?``:` `)+n,ge=`flow`;function _e(e,t,n=`flow`,{indentAtStart:r,lineWidth:i=80,minContentWidth:a=20,onFold:o,onOverflow:s}={}){if(!i||i<0)return e;i<a&&(a=0);let c=Math.max(1+a,1+i-t.length);if(e.length<=c)return e;let l=[],u={},d=i-t.length;typeof r==`number`&&(r>i-Math.max(2,a)?l.push(0):d=i-r);let f,p,m=!1,h=-1,g=-1,_=-1;n===`block`&&(h=ve(e,h,t.length),h!==-1&&(d=h+c));for(let r;r=e[h+=1];){if(n===`quoted`&&r===`\\`){switch(g=h,e[h+1]){case`x`:h+=3;break;case`u`:h+=5;break;case`U`:h+=9;break;default:h+=1}_=h}if(r===`
|
|
5
|
-
`)n===`block`&&(h=ve(e,h,t.length)),d=h+t.length+c,f=void 0;else{if(r===` `&&p&&p!==` `&&p!==`
|
|
6
|
-
`&&p!==` `){let t=e[h+1];t&&t!==` `&&t!==`
|
|
7
|
-
`&&t!==` `&&(f=h)}if(h>=d){if(f)l.push(f),d=f+c,f=void 0;else if(n===`quoted`){for(;p===` `||p===` `;)p=r,r=e[h+=1],m=!0;let t=h>_+1?h-2:g-1;if(u[t])return e;l.push(t),u[t]=!0,d=t+c,f=void 0}else m=!0}}p=r}if(m&&s&&s(),l.length===0)return e;o&&o();let v=e.slice(0,l[0]);for(let r=0;r<l.length;++r){let i=l[r],a=l[r+1]||e.length;i===0?v=`\n${t}${e.slice(0,a)}`:(n===`quoted`&&u[i]&&(v+=`${e[i]}\\`),v+=`\n${t}${e.slice(i+1,a)}`)}return v}function ve(e,t,n){let r=t,i=t+1,a=e[i];for(;a===` `||a===` `;)if(t<i+n)a=e[++t];else{do a=e[++t];while(a&&a!==`
|
|
8
|
-
`);r=t,i=t+1,a=e[i]}return r}const ye=(e,t)=>({indentAtStart:t?e.indent.length:e.indentAtStart,lineWidth:e.options.lineWidth,minContentWidth:e.options.minContentWidth}),be=e=>/^(%|---|\.\.\.)/m.test(e);function xe(e,t,n){if(!t||t<0)return!1;let r=t-n,i=e.length;if(i<=r)return!1;for(let t=0,n=0;t<i;++t)if(e[t]===`
|
|
9
|
-
`){if(t-n>r)return!0;if(n=t+1,i-n<=r)return!1}return!0}function W(e,t){let n=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return n;let{implicitKey:r}=t,i=t.options.doubleQuotedMinMultiLineLength,a=t.indent||(be(e)?` `:``),o=``,s=0;for(let e=0,t=n[e];t;t=n[++e])if(t===` `&&n[e+1]===`\\`&&n[e+2]===`n`&&(o+=n.slice(s,e)+`\\ `,e+=1,s=e,t=`\\`),t===`\\`)switch(n[e+1]){case`u`:{o+=n.slice(s,e);let t=n.substr(e+2,4);switch(t){case`0000`:o+=`\\0`;break;case`0007`:o+=`\\a`;break;case`000b`:o+=`\\v`;break;case`001b`:o+=`\\e`;break;case`0085`:o+=`\\N`;break;case`00a0`:o+=`\\_`;break;case`2028`:o+=`\\L`;break;case`2029`:o+=`\\P`;break;default:t.substr(0,2)===`00`?o+=`\\x`+t.substr(2):o+=n.substr(e,6)}e+=5,s=e+1}break;case`n`:if(r||n[e+2]===`"`||n.length<i)e+=1;else{for(o+=n.slice(s,e)+`
|
|
10
|
-
|
|
11
|
-
`;n[e+2]===`\\`&&n[e+3]===`n`&&n[e+4]!==`"`;)o+=`
|
|
12
|
-
`,e+=2;o+=a,n[e+2]===` `&&(o+=`\\`),e+=1,s=e+1}break;default:e+=1}return o=s?o+n.slice(s):n,r?o:_e(o,a,`quoted`,ye(t,!1))}function Se(e,t){if(t.options.singleQuote===!1||t.implicitKey&&e.includes(`
|
|
13
|
-
`)||/[ \t]\n|\n[ \t]/.test(e))return W(e,t);let n=t.indent||(be(e)?` `:``),r=`'`+e.replace(/'/g,`''`).replace(/\n+/g,`$&\n${n}`)+`'`;return t.implicitKey?r:_e(r,n,ge,ye(t,!1))}function G(e,t){let{singleQuote:n}=t.options,r;if(n===!1)r=W;else{let t=e.includes(`"`),i=e.includes(`'`);r=t&&!i?Se:i&&!t?W:n?Se:W}return r(e,t)}let Ce;try{Ce=RegExp(`(^|(?<!
|
|
14
|
-
))
|
|
15
|
-
+(?!
|
|
16
|
-
|$)`,`g`)}catch{Ce=/\n+(?!\n|$)/g}function we({comment:e,type:t,value:n},r,i,a){let{blockQuote:o,commentString:s,lineWidth:c}=r.options;if(!o||/\n[\t ]+$/.test(n))return G(n,r);let l=r.indent||(r.forceBlockIndent||be(n)?` `:``),u=o===`literal`?!0:o===`folded`||t===B.BLOCK_FOLDED?!1:t===B.BLOCK_LITERAL||!xe(n,c,l.length);if(!n)return u?`|
|
|
17
|
-
`:`>
|
|
18
|
-
`;let d,f;for(f=n.length;f>0;--f){let e=n[f-1];if(e!==`
|
|
19
|
-
`&&e!==` `&&e!==` `)break}let p=n.substring(f),m=p.indexOf(`
|
|
20
|
-
`);m===-1?d=`-`:n===p||m!==p.length-1?(d=`+`,a&&a()):d=``,p&&=(n=n.slice(0,-p.length),p[p.length-1]===`
|
|
21
|
-
`&&(p=p.slice(0,-1)),p.replace(Ce,`$&${l}`));let h=!1,g,_=-1;for(g=0;g<n.length;++g){let e=n[g];if(e===` `)h=!0;else if(e===`
|
|
22
|
-
`)_=g;else break}let v=n.substring(0,_<g?_+1:g);v&&=(n=n.substring(v.length),v.replace(/\n+/g,`$&${l}`));let y=(h?l?`2`:`1`:``)+d;if(e&&(y+=` `+s(e.replace(/ ?[\r\n]+/g,` `)),i&&i()),!u){let e=n.replace(/\n+/g,`
|
|
23
|
-
$&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\n+/g,`$&${l}`),i=!1,a=ye(r,!0);o!==`folded`&&t!==B.BLOCK_FOLDED&&(a.onOverflow=()=>{i=!0});let s=_e(`${v}${e}${p}`,l,`block`,a);if(!i)return`>${y}\n${l}${s}`}return n=n.replace(/\n+/g,`$&${l}`),`|${y}\n${l}${v}${n}${p}`}function Te(e,t,n,r){let{type:i,value:a}=e,{actualString:o,implicitKey:s,indent:c,indentStep:l,inFlow:u}=t;if(s&&a.includes(`
|
|
24
|
-
`)||u&&/[[\]{},]/.test(a))return G(a,t);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(a))return s||u||!a.includes(`
|
|
25
|
-
`)?G(a,t):we(e,t,n,r);if(!s&&!u&&i!==B.PLAIN&&a.includes(`
|
|
26
|
-
`))return we(e,t,n,r);if(be(a)){if(c===``)return t.forceBlockIndent=!0,we(e,t,n,r);if(s&&c===l)return G(a,t)}let d=a.replace(/\n+/g,`$&\n${c}`);if(o){let e=e=>e.default&&e.tag!==`tag:yaml.org,2002:str`&&e.test?.test(d),{compat:n,tags:r}=t.doc.schema;if(r.some(e)||n?.some(e))return G(a,t)}return s?d:_e(d,c,ge,ye(t,!1))}function Ee(e,t,n,r){let{implicitKey:i,inFlow:a}=t,o=typeof e.value==`string`?e:Object.assign({},e,{value:String(e.value)}),{type:s}=e;s!==B.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(o.value)&&(s=B.QUOTE_DOUBLE);let c=e=>{switch(e){case B.BLOCK_FOLDED:case B.BLOCK_LITERAL:return i||a?G(o.value,t):we(o,t,n,r);case B.QUOTE_DOUBLE:return W(o.value,t);case B.QUOTE_SINGLE:return Se(o.value,t);case B.PLAIN:return Te(o,t,n,r);default:return null}},l=c(s);if(l===null){let{defaultKeyType:e,defaultStringType:n}=t.options,r=i&&e||n;if(l=c(r),l===null)throw Error(`Unsupported default string type ${r}`)}return l}function De(e,t){let n=Object.assign({blockQuote:!0,commentString:he,defaultKeyType:null,defaultStringType:`PLAIN`,directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:`false`,flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:`null`,simpleKeys:!1,singleQuote:null,trailingComma:!1,trueStr:`true`,verifyAliasOrder:!0},e.schema.toStringOptions,t),r;switch(n.collectionStyle){case`block`:r=!1;break;case`flow`:r=!0;break;default:r=null}return{anchors:new Set,doc:e,flowCollectionPadding:n.flowCollectionPadding?` `:``,indent:``,indentStep:typeof n.indent==`number`?` `.repeat(n.indent):` `,inFlow:r,options:n}}function Oe(e,t){if(t.tag){let n=e.filter(e=>e.tag===t.tag);if(n.length>0)return n.find(e=>e.format===t.format)??n[0]}let n,r;if(k(t)){r=t.value;let i=e.filter(e=>e.identify?.(r));if(i.length>1){let e=i.filter(e=>e.test);e.length>0&&(i=e)}n=i.find(e=>e.format===t.format)??i.find(e=>!e.format)}else r=t,n=e.find(e=>e.nodeClass&&r instanceof e.nodeClass);if(!n){let e=r?.constructor?.name??(r===null?`null`:typeof r);throw Error(`Tag not resolved for ${e} value`)}return n}function ke(e,t,{anchors:n,doc:r}){if(!r.directives)return``;let i=[],a=(k(e)||j(e))&&e.anchor;a&&se(a)&&(n.add(a),i.push(`&${a}`));let o=e.tag??(t.default?null:t.tag);return o&&i.push(r.directives.tagString(o)),i.join(` `)}function K(e,t,n,r){if(O(e))return e.toString(t,n,r);if(E(e)){if(t.doc.directives)return e.toString(t);if(t.resolvedAliases?.has(e))throw TypeError(`Cannot stringify circular structure without alias nodes`);t.resolvedAliases?t.resolvedAliases.add(e):t.resolvedAliases=new Set([e]),e=e.resolve(t.doc)}let i,a=M(e)?e:t.doc.createNode(e,{onTagObj:e=>i=e});i??=Oe(t.doc.schema.tags,a);let o=ke(a,i,t);o.length>0&&(t.indentAtStart=(t.indentAtStart??0)+o.length+1);let s=typeof i.stringify==`function`?i.stringify(a,t,n,r):k(a)?Ee(a,t,n,r):a.toString(t,n,r);return o?k(a)||s[0]===`{`||s[0]===`[`?`${o} ${s}`:`${o}\n${t.indent}${s}`:s}function Ae({key:e,value:t},n,r,i){let{allNullValues:a,doc:o,indent:s,indentStep:c,options:{commentString:l,indentSeq:u,simpleKeys:d}}=n,f=M(e)&&e.comment||null;if(d){if(f)throw Error(`With simple keys, key nodes cannot have comments`);if(j(e)||!M(e)&&typeof e==`object`)throw Error(`With simple keys, collection cannot be used as a key value`)}let p=!d&&(!e||f&&t==null&&!n.inFlow||j(e)||(k(e)?e.type===B.BLOCK_FOLDED||e.type===B.BLOCK_LITERAL:typeof e==`object`));n=Object.assign({},n,{allNullValues:!1,implicitKey:!p&&(d||!a),indent:s+c});let m=!1,h=!1,g=K(e,n,()=>m=!0,()=>h=!0);if(!p&&!n.inFlow&&g.length>1024){if(d)throw Error(`With simple keys, single line scalar must not span more than 1024 characters`);p=!0}if(n.inFlow){if(a||t==null)return m&&r&&r(),g===``?`?`:p?`? ${g}`:g}else if(a&&!d||t==null&&p)return g=`? ${g}`,f&&!m?g+=U(g,n.indent,l(f)):h&&i&&i(),g;m&&(f=null),p?(f&&(g+=U(g,n.indent,l(f))),g=`? ${g}\n${s}:`):(g=`${g}:`,f&&(g+=U(g,n.indent,l(f))));let _,v,y;M(t)?(_=!!t.spaceBefore,v=t.commentBefore,y=t.comment):(_=!1,v=null,y=null,t&&typeof t==`object`&&(t=o.createNode(t))),n.implicitKey=!1,!p&&!f&&k(t)&&(n.indentAtStart=g.length+1),h=!1,!u&&c.length>=2&&!n.inFlow&&!p&&A(t)&&!t.flow&&!t.tag&&!t.anchor&&(n.indent=n.indent.substring(2));let b=!1,x=K(t,n,()=>b=!0,()=>h=!0),S=` `;if(f||_||v){if(S=_?`
|
|
27
|
-
`:``,v){let e=l(v);S+=`\n${H(e,n.indent)}`}x===``&&!n.inFlow?S===`
|
|
28
|
-
`&&y&&(S=`
|
|
29
|
-
|
|
30
|
-
`):S+=`\n${n.indent}`}else if(!p&&j(t)){let e=x[0],r=x.indexOf(`
|
|
31
|
-
`),i=r!==-1,a=n.inFlow??t.flow??t.items.length===0;if(i||!a){let t=!1;if(i&&(e===`&`||e===`!`)){let n=x.indexOf(` `);e===`&`&&n!==-1&&n<r&&x[n+1]===`!`&&(n=x.indexOf(` `,n+1)),(n===-1||r<n)&&(t=!0)}t||(S=`\n${n.indent}`)}}else(x===``||x[0]===`
|
|
32
|
-
`)&&(S=``);return g+=S+x,n.inFlow?b&&r&&r():y&&!b?g+=U(g,n.indent,l(y)):h&&i&&i(),g}function je(e,t){(e===`debug`||e===`warn`)&&console.warn(t)}const Me={identify:e=>e===`<<`||typeof e==`symbol`&&e.description===`<<`,default:`key`,tag:`tag:yaml.org,2002:merge`,test:/^<<$/,resolve:()=>Object.assign(new B(Symbol(`<<`)),{addToJSMap:Pe}),stringify:()=>`<<`},Ne=(e,t)=>(Me.identify(t)||k(t)&&(!t.type||t.type===B.PLAIN)&&Me.identify(t.value))&&e?.doc.schema.tags.some(e=>e.tag===Me.tag&&e.default);function Pe(e,t,n){let r=Ie(e,n);if(A(r))for(let n of r.items)Fe(e,t,n);else if(Array.isArray(r))for(let n of r)Fe(e,t,n);else Fe(e,t,r)}function Fe(e,t,n){let r=Ie(e,n);if(!te(r))throw Error(`Merge sources must be maps or map aliases`);let i=r.toJSON(null,e,Map);for(let[e,n]of i)t instanceof Map?t.has(e)||t.set(e,n):t instanceof Set?t.add(e):Object.prototype.hasOwnProperty.call(t,e)||Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0});return t}function Ie(e,t){return e&&E(t)?t.resolve(e.doc,e):t}function Le(e,t,{key:n,value:r}){if(M(n)&&n.addToJSMap)n.addToJSMap(e,t,r);else if(Ne(e,n))Pe(e,t,r);else{let i=R(n,``,e);if(t instanceof Map)t.set(i,R(r,i,e));else if(t instanceof Set)t.add(i);else{let a=Re(n,i,e),o=R(r,a,e);a in t?Object.defineProperty(t,a,{value:o,writable:!0,enumerable:!0,configurable:!0}):t[a]=o}}return t}function Re(e,t,n){if(t===null)return``;if(typeof t!=`object`)return String(t);if(M(e)&&n?.doc){let t=De(n.doc,{});t.anchors=new Set;for(let e of n.anchors.keys())t.anchors.add(e.anchor);t.inFlow=!0,t.inStringifyKey=!0;let r=e.toString(t);if(!n.mapKeyWarned){let e=JSON.stringify(r);e.length>40&&(e=e.substring(0,36)+`..."`),je(n.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${e}. Set mapAsMap: true to use object keys.`),n.mapKeyWarned=!0}return r}return JSON.stringify(t)}function ze(e,t,n){return new q(V(e,void 0,n),V(t,void 0,n))}var q=class e{constructor(e,t=null){Object.defineProperty(this,T,{value:C}),this.key=e,this.value=t}clone(t){let{key:n,value:r}=this;return M(n)&&(n=n.clone(t)),M(r)&&(r=r.clone(t)),new e(n,r)}toJSON(e,t){return Le(t,t?.mapAsMap?new Map:{},this)}toString(e,t,n){return e?.doc?Ae(this,e,t,n):JSON.stringify(this)}};function Be(e,t,n){return(t.inFlow??e.flow?He:Ve)(e,t,n)}function Ve({comment:e,items:t},n,{blockItemPrefix:r,flowChars:i,itemIndent:a,onChompKeep:o,onComment:s}){let{indent:c,options:{commentString:l}}=n,u=Object.assign({},n,{indent:a,type:null}),d=!1,f=[];for(let e=0;e<t.length;++e){let i=t[e],o=null;if(M(i))!d&&i.spaceBefore&&f.push(``),Ue(n,f,i.commentBefore,d),i.comment&&(o=i.comment);else if(O(i)){let e=M(i.key)?i.key:null;e&&(!d&&e.spaceBefore&&f.push(``),Ue(n,f,e.commentBefore,d))}d=!1;let s=K(i,u,()=>o=null,()=>d=!0);o&&(s+=U(s,a,l(o))),d&&o&&(d=!1),f.push(r+s)}let p;if(f.length===0)p=i.start+i.end;else{p=f[0];for(let e=1;e<f.length;++e){let t=f[e];p+=t?`\n${c}${t}`:`
|
|
33
|
-
`}}return e?(p+=`
|
|
34
|
-
`+H(l(e),c),s&&s()):d&&o&&o(),p}function He({items:e},t,{flowChars:n,itemIndent:r}){let{indent:i,indentStep:a,flowCollectionPadding:o,options:{commentString:s}}=t;r+=a;let c=Object.assign({},t,{indent:r,inFlow:!0,type:null}),l=!1,u=0,d=[];for(let n=0;n<e.length;++n){let i=e[n],a=null;if(M(i))i.spaceBefore&&d.push(``),Ue(t,d,i.commentBefore,!1),i.comment&&(a=i.comment);else if(O(i)){let e=M(i.key)?i.key:null;e&&(e.spaceBefore&&d.push(``),Ue(t,d,e.commentBefore,!1),e.comment&&(l=!0));let n=M(i.value)?i.value:null;n?(n.comment&&(a=n.comment),n.commentBefore&&(l=!0)):i.value==null&&e?.comment&&(a=e.comment)}a&&(l=!0);let o=K(i,c,()=>a=null);l||=d.length>u||o.includes(`
|
|
35
|
-
`),n<e.length-1?o+=`,`:t.options.trailingComma&&(t.options.lineWidth>0&&(l||=d.reduce((e,t)=>e+t.length+2,2)+(o.length+2)>t.options.lineWidth),l&&(o+=`,`)),a&&(o+=U(o,r,s(a))),d.push(o),u=d.length}let{start:f,end:p}=n;if(d.length===0)return f+p;if(!l){let e=d.reduce((e,t)=>e+t.length+2,2);l=t.options.lineWidth>0&&e>t.options.lineWidth}if(l){let e=f;for(let t of d)e+=t?`\n${a}${i}${t}`:`
|
|
36
|
-
`;return`${e}\n${i}${p}`}return`${f}${o}${d.join(` `)}${o}${p}`}function Ue({indent:e,options:{commentString:t}},n,r,i){if(r&&i&&(r=r.replace(/^\n+/,``)),r){let i=H(t(r),e);n.push(i.trimStart())}}function J(e,t){let n=k(t)?t.value:t;for(let r of e)if(O(r)&&(r.key===t||r.key===n||k(r.key)&&r.key.value===n))return r}var Y=class extends me{static get tagName(){return`tag:yaml.org,2002:map`}constructor(e){super(S,e),this.items=[]}static from(e,t,n){let{keepUndefined:r,replacer:i}=n,a=new this(e),o=(e,o)=>{if(typeof i==`function`)o=i.call(t,e,o);else if(Array.isArray(i)&&!i.includes(e))return;(o!==void 0||r)&&a.items.push(ze(e,o,n))};if(t instanceof Map)for(let[e,n]of t)o(e,n);else if(t&&typeof t==`object`)for(let e of Object.keys(t))o(e,t[e]);return typeof e.sortMapEntries==`function`&&a.items.sort(e.sortMapEntries),a}add(e,t){let n;n=O(e)?e:!e||typeof e!=`object`||!(`key`in e)?new q(e,e?.value):new q(e.key,e.value);let r=J(this.items,n.key),i=this.schema?.sortMapEntries;if(r){if(!t)throw Error(`Key ${n.key} already set`);k(r.value)&&ue(n.value)?r.value.value=n.value:r.value=n.value}else if(i){let e=this.items.findIndex(e=>i(n,e)<0);e===-1?this.items.push(n):this.items.splice(e,0,n)}else this.items.push(n)}delete(e){let t=J(this.items,e);return t?this.items.splice(this.items.indexOf(t),1).length>0:!1}get(e,t){let n=J(this.items,e)?.value;return(!t&&k(n)?n.value:n)??void 0}has(e){return!!J(this.items,e)}set(e,t){this.add(new q(e,t),!0)}toJSON(e,t,n){let r=n?new n:t?.mapAsMap?new Map:{};t?.onCreate&&t.onCreate(r);for(let e of this.items)Le(t,r,e);return r}toString(e,t,n){if(!e)return JSON.stringify(this);for(let e of this.items)if(!O(e))throw Error(`Map items must all be pairs; found ${JSON.stringify(e)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),Be(this,e,{blockItemPrefix:``,flowChars:{start:`{`,end:`}`},itemIndent:e.indent||``,onChompKeep:n,onComment:t})}};const We={collection:`map`,default:!0,nodeClass:Y,tag:`tag:yaml.org,2002:map`,resolve(e,t){return te(e)||t(`Expected a mapping for this tag`),e},createNode:(e,t,n)=>Y.from(e,t,n)};var Ge=class extends me{static get tagName(){return`tag:yaml.org,2002:seq`}constructor(e){super(w,e),this.items=[]}add(e){this.items.push(e)}delete(e){let t=Ke(e);return typeof t==`number`&&this.items.splice(t,1).length>0}get(e,t){let n=Ke(e);if(typeof n!=`number`)return;let r=this.items[n];return!t&&k(r)?r.value:r}has(e){let t=Ke(e);return typeof t==`number`&&t<this.items.length}set(e,t){let n=Ke(e);if(typeof n!=`number`)throw Error(`Expected a valid index, not ${e}.`);let r=this.items[n];k(r)&&ue(t)?r.value=t:this.items[n]=t}toJSON(e,t){let n=[];t?.onCreate&&t.onCreate(n);let r=0;for(let e of this.items)n.push(R(e,String(r++),t));return n}toString(e,t,n){return e?Be(this,e,{blockItemPrefix:`- `,flowChars:{start:`[`,end:`]`},itemIndent:(e.indent||``)+` `,onChompKeep:n,onComment:t}):JSON.stringify(this)}static from(e,t,n){let{replacer:r}=n,i=new this(e);if(t&&Symbol.iterator in Object(t)){let e=0;for(let a of t){if(typeof r==`function`){let n=t instanceof Set?a:String(e++);a=r.call(t,n,a)}i.items.push(V(a,void 0,n))}}return i}};function Ke(e){let t=k(e)?e.value:e;return t&&typeof t==`string`&&(t=Number(t)),typeof t==`number`&&Number.isInteger(t)&&t>=0?t:null}const qe={collection:`seq`,default:!0,nodeClass:Ge,tag:`tag:yaml.org,2002:seq`,resolve(e,t){return A(e)||t(`Expected a sequence for this tag`),e},createNode:(e,t,n)=>Ge.from(e,t,n)};function Je(e){return typeof e==`bigint`||Number.isInteger(e)}const Ye=({value:e})=>JSON.stringify(e),Xe=[{identify:e=>typeof e==`string`,default:!0,tag:`tag:yaml.org,2002:str`,resolve:e=>e,stringify:Ye},{identify:e=>e==null,createNode:()=>new B(null),default:!0,tag:`tag:yaml.org,2002:null`,test:/^null$/,resolve:()=>null,stringify:Ye},{identify:e=>typeof e==`boolean`,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^true$|^false$/,resolve:e=>e===`true`,stringify:Ye},{identify:Je,default:!0,tag:`tag:yaml.org,2002:int`,test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(e,t,{intAsBigInt:n})=>n?BigInt(e):parseInt(e,10),stringify:({value:e})=>Je(e)?e.toString():JSON.stringify(e)},{identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:e=>parseFloat(e),stringify:Ye}];[We,qe].concat(Xe,{default:!0,tag:``,test:/^/,resolve(e,t){return t(`Unresolved plain scalar ${JSON.stringify(e)}`),e}});function Ze(e,t,n){let{replacer:r}=n,i=new Ge(e);i.tag=`tag:yaml.org,2002:pairs`;let a=0;if(t&&Symbol.iterator in Object(t))for(let e of t){typeof r==`function`&&(e=r.call(t,String(a++),e));let o,s;if(Array.isArray(e)){if(e.length===2)o=e[0],s=e[1];else throw TypeError(`Expected [key, value] tuple: ${e}`)}else if(e&&e instanceof Object){let t=Object.keys(e);if(t.length===1)o=t[0],s=e[o];else throw TypeError(`Expected tuple with one key, not ${t.length} keys`)}else o=e;i.items.push(ze(o,s,n))}return i}var Qe=class e extends Ge{constructor(){super(),this.add=Y.prototype.add.bind(this),this.delete=Y.prototype.delete.bind(this),this.get=Y.prototype.get.bind(this),this.has=Y.prototype.has.bind(this),this.set=Y.prototype.set.bind(this),this.tag=e.tag}toJSON(e,t){if(!t)return super.toJSON(e);let n=new Map;t?.onCreate&&t.onCreate(n);for(let e of this.items){let r,i;if(O(e)?(r=R(e.key,``,t),i=R(e.value,r,t)):r=R(e,``,t),n.has(r))throw Error(`Ordered maps must not include duplicate keys`);n.set(r,i)}return n}static from(e,t,n){let r=Ze(e,t,n),i=new this;return i.items=r.items,i}};Qe.tag=`tag:yaml.org,2002:omap`;var $e=class e extends Y{constructor(t){super(t),this.tag=e.tag}add(e){let t;t=O(e)?e:e&&typeof e==`object`&&`key`in e&&`value`in e&&e.value===null?new q(e.key,null):new q(e,null),J(this.items,t.key)||this.items.push(t)}get(e,t){let n=J(this.items,e);return!t&&O(n)?k(n.key)?n.key.value:n.key:n}set(e,t){if(typeof t!=`boolean`)throw Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);let n=J(this.items,e);n&&!t?this.items.splice(this.items.indexOf(n),1):!n&&t&&this.items.push(new q(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,n){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,n);throw Error(`Set items must all have null values`)}static from(e,t,n){let{replacer:r}=n,i=new this(e);if(t&&Symbol.iterator in Object(t))for(let e of t)typeof r==`function`&&(e=r.call(t,e,e)),i.items.push(ze(e,null,n));return i}};$e.tag=`tag:yaml.org,2002:set`;const et=Symbol(`break visit`),tt=Symbol(`skip children`),nt=Symbol(`remove item`);function X(e,t){`type`in e&&e.type===`document`&&(e={start:e.start,value:e.value}),rt(Object.freeze([]),e,t)}X.BREAK=et,X.SKIP=tt,X.REMOVE=nt,X.itemAtPath=(e,t)=>{let n=e;for(let[e,r]of t){let t=n?.[e];if(t&&`items`in t)n=t.items[r];else return}return n},X.parentCollection=(e,t)=>{let n=X.itemAtPath(e,t.slice(0,-1)),r=t[t.length-1][0],i=n?.[r];if(i&&`items`in i)return i;throw Error(`Parent collection not found`)};function rt(e,t,n){let r=n(t,e);if(typeof r==`symbol`)return r;for(let i of[`key`,`value`]){let a=t[i];if(a&&`items`in a){for(let t=0;t<a.items.length;++t){let r=rt(Object.freeze(e.concat([[i,t]])),a.items[t],n);if(typeof r==`number`)t=r-1;else if(r===et)return et;else r===nt&&(a.items.splice(t,1),--t)}typeof r==`function`&&i===`key`&&(r=r(t,e))}}return typeof r==`function`?r(t,e):r}e(((e,t)=>{function n(e){return Array.isArray(e)?e:[e]}let r=/^\s+$/,i=/(?:[^\\]|^)\\$/,a=/^\\!/,o=/^\\#/,s=/\r?\n/g,c=/^\.{0,2}\/|^\.{1,2}$/,l=/\/$/,u=`node-ignore`;typeof Symbol<`u`&&(u=Symbol.for(`node-ignore`));let d=u,f=(e,t,n)=>(Object.defineProperty(e,t,{value:n}),n),p=/([0-z])-([0-z])/g,m=()=>!1,h=e=>e.replace(p,(e,t,n)=>t.charCodeAt(0)<=n.charCodeAt(0)?e:``),g=e=>{let{length:t}=e;return e.slice(0,t-t%2)},_=[[/^\uFEFF/,()=>``],[/((?:\\\\)*?)(\\?\s+)$/,(e,t,n)=>t+(n.indexOf(`\\`)===0?` `:``)],[/(\\+?)\s/g,(e,t)=>{let{length:n}=t;return t.slice(0,n-n%2)+` `}],[/[\\$.|*+(){^]/g,e=>`\\${e}`],[/(?!\\)\?/g,()=>`[^/]`],[/^\//,()=>`^`],[/\//g,()=>`\\/`],[/^\^*\\\*\\\*\\\//,()=>`^(?:.*\\/)?`],[/^(?=[^^])/,function(){return/\/(?!$)/.test(this)?`^`:`(?:^|\\/)`}],[/\\\/\\\*\\\*(?=\\\/|$)/g,(e,t,n)=>t+6<n.length?`(?:\\/[^\\/]+)*`:`\\/.+`],[/(^|[^\\]+)(\\\*)+(?=.+)/g,(e,t,n)=>t+n.replace(/\\\*/g,`[^\\/]*`)],[/\\\\\\(?=[$.|*+(){^])/g,()=>`\\`],[/\\\\/g,()=>`\\`],[/(\\)?\[([^\]/]*?)(\\*)($|\])/g,(e,t,n,r,i)=>t===`\\`?`\\[${n}${g(r)}${i}`:i===`]`&&r.length%2==0?`[${h(n)}${r}]`:`[]`],[/(?:[^*])$/,e=>/\/$/.test(e)?`${e}$`:`${e}(?=$|\\/$)`]],v=/(^|\\\/)?\\\*$/,y=`regex`,b=`checkRegex`,x={[y](e,t){return`${t?`${t}[^/]+`:`[^/]*`}(?=$|\\/$)`},[b](e,t){return`${t?`${t}[^/]*`:`[^/]*`}(?=$|\\/$)`}},S=e=>_.reduce((t,[n,r])=>t.replace(n,r.bind(e)),e),C=e=>typeof e==`string`,ee=e=>e&&C(e)&&!r.test(e)&&!i.test(e)&&e.indexOf(`#`)!==0,w=e=>e.split(s).filter(Boolean);var T=class{constructor(e,t,n,r,i,a){this.pattern=e,this.mark=t,this.negative=i,f(this,`body`,n),f(this,`ignoreCase`,r),f(this,`regexPrefix`,a)}get regex(){let e=`_regex`;return this[e]?this[e]:this._make(y,e)}get checkRegex(){let e=`_checkRegex`;return this[e]?this[e]:this._make(b,e)}_make(e,t){let n=this.regexPrefix.replace(v,x[e]),r=this.ignoreCase?new RegExp(n,`i`):new RegExp(n);return f(this,t,r)}};let E=({pattern:e,mark:t},n)=>{let r=!1,i=e;i.indexOf(`!`)===0&&(r=!0,i=i.substr(1)),i=i.replace(a,`!`).replace(o,`#`);let s=S(i);return new T(e,t,i,n,r,s)};var D=class{constructor(e){this._ignoreCase=e,this._rules=[]}_add(e){if(e&&e[d]){this._rules=this._rules.concat(e._rules._rules),this._added=!0;return}if(C(e)&&(e={pattern:e}),ee(e.pattern)){let t=E(e,this._ignoreCase);this._added=!0,this._rules.push(t)}}add(e){return this._added=!1,n(C(e)?w(e):e).forEach(this._add,this),this._added}test(e,t,n){let r=!1,i=!1,a;this._rules.forEach(o=>{let{negative:s}=o;i===s&&r!==i||s&&!r&&!i&&!t||o[n].test(e)&&(r=!s,i=s,a=s?void 0:o)});let o={ignored:r,unignored:i};return a&&(o.rule=a),o}};let te=(e,t)=>{throw new t(e)},O=(e,t,n)=>C(e)?e?!O.isNotRelative(e)||n(`path should be a \`path.relative()\`d string, but got "${t}"`,RangeError):n(`path must not be empty`,TypeError):n(`path must be a string, but got \`${t}\``,TypeError),k=e=>c.test(e);O.isNotRelative=k,O.convert=e=>e;var A=class{constructor({ignorecase:e=!0,ignoreCase:t=e,allowRelativePaths:n=!1}={}){f(this,d,!0),this._rules=new D(t),this._strictPathCheck=!n,this._initCache()}_initCache(){this._ignoreCache=Object.create(null),this._testCache=Object.create(null)}add(e){return this._rules.add(e)&&this._initCache(),this}addPattern(e){return this.add(e)}_test(e,t,n,r){let i=e&&O.convert(e);return O(i,e,this._strictPathCheck?te:m),this._t(i,t,n,r)}checkIgnore(e){if(!l.test(e))return this.test(e);let t=e.split(`/`).filter(Boolean);if(t.pop(),t.length){let e=this._t(t.join(`/`)+`/`,this._testCache,!0,t);if(e.ignored)return e}return this._rules.test(e,!1,b)}_t(e,t,n,r){if(e in t)return t[e];if(r||=e.split(`/`).filter(Boolean),r.pop(),!r.length)return t[e]=this._rules.test(e,n,y);let i=this._t(r.join(`/`)+`/`,t,n,r);return t[e]=i.ignored?i:this._rules.test(e,n,y)}ignores(e){return this._test(e,this._ignoreCache,!1).ignored}createFilter(){return e=>!this.ignores(e)}filter(e){return n(e).filter(this.createFilter())}test(e){return this._test(e,this._testCache,!0)}};let j=e=>new A(e),M=e=>O(e&&O.convert(e),e,m),ne=()=>{O.convert=e=>/^\\\\\?\\/.test(e)||/["<>|\u0000-\u001F]+/u.test(e)?e:e.replace(/\\/g,`/`);let e=/^[a-z]:\//i;O.isNotRelative=t=>e.test(t)||k(t)};typeof process<`u`&&process.platform===`win32`&&ne(),t.exports=j,j.default=j,t.exports.isPathValid=M,f(t.exports,Symbol.for(`setupWindows`),ne)}))();const it={"pi.session.id":{type:`string`,required:!0,cardinality:`high`,description:`Session id`},"pi.lane.name":{type:`string`,required:!0,cardinality:`high`,description:`Lane name`},"pi.operation.id":{type:`string`,required:!0,cardinality:`high`,description:`Durable operation id`},"pi.operation.recovery":{type:`boolean`,required:!0,description:`Whether this invocation resumes durable work`}},at={"pi.error.code":{type:`string`,cardinality:`low`,description:`Stable operation error code`},"pi.error.type":{type:`string`,cardinality:`low`,description:`Low-cardinality operation error class`}};({...it}),{...at},{...it},{...at},{...it},{...at},globalThis.Buffer,d({command:f({description:`Bash command to execute`}),timeout:l(u({description:`Timeout in seconds (optional, no default timeout)`}))});const ot=d({oldText:f({description:`Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.`}),newText:f({description:`Replacement text for this targeted edit.`})},{});d({path:f({description:`Path to the file to edit (relative or absolute)`}),edits:c(ot,{description:`One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.`})},{}),d({path:f({description:`Path to the file to read (relative or absolute)`}),offset:l(u({description:`Line number to start reading from (1-indexed)`})),limit:l(u({description:`Maximum number of lines to read`}))}),d({path:f({description:`Path to the file to write (relative or absolute)`}),content:f({description:`Content to write to the file`})});function st(){return i()?`extension-direct`:a()?`extension-delegate`:globalThis.__slicc_connect_mode?`connect`:`node-rest`}function ct(){return st()===`node-rest`}const Z=t(`secret-scrub`),Q=`[tool output withheld: secret scrub unavailable]`,lt=async e=>e;function ut(){let e=st();return e===`extension-direct`?async e=>{if(!e)return e;try{let t=await new Promise(t=>{chrome.runtime.sendMessage({type:`secrets.scrub-tool-result`,text:e},e=>t(e??{}))});return t.error?(Z.debug(`SW scrub-tool-result returned error`),Q):typeof t.text==`string`?t.text:Q}catch{return Z.debug(`SW scrub-tool-result failed`),Q}}:e===`extension-delegate`?async e=>{if(!e)return e;try{let t=await p(`secrets.scrub-tool-result`,{text:e});return t?.error?(Z.debug(`Bridge scrub-tool-result returned error`),Q):typeof t?.text==`string`?t.text:Q}catch{return Z.debug(`Bridge scrub-tool-result failed`),Q}}:e===`connect`?lt:async e=>{if(!e)return e;try{let t=await fetch(o(`/api/secrets/scrub`),{method:`POST`,headers:s({"content-type":`application/json`}),body:JSON.stringify({text:e})});if(!t.ok)return Z.debug(`Server scrub-tool-result returned non-ok`,{status:t.status}),e;let n=await t.json();return typeof n.text==`string`?n.text:e}catch(t){return Z.debug(`Server scrub-tool-result failed`,{error:t instanceof Error?t.message:String(t)}),e}}}const $=t(`image-processor`),dt=3932160;function ft(e){let t=e.replace(/[\t\n\f\r ]/g,``),n=t.length%4;return n===2?`${t}==`:n===3?`${t}=`:t}function pt(e,t){let n=r(ft(e.slice(0,t)));return new DataView(n.buffer,n.byteOffset,n.byteLength)}function mt(e,t){return e>0&&t>0?{width:e,height:t}:null}function ht(e){if(e.length<32)return null;let t=pt(e,32);return mt(t.getUint32(16,!1),t.getUint32(20,!1))}function gt(e){if(e.length<16)return null;let t=pt(e,16);return mt(t.getUint16(6,!0),t.getUint16(8,!0))}function _t(e){let t=pt(e,Math.min(87384,e.length));for(let e=0;e<t.byteLength-8;e++){if(t.getUint8(e)!==255)continue;let n=t.getUint8(e+1);if(n===192||n===194)return mt(t.getUint16(e+7,!1),t.getUint16(e+5,!1))}return null}function vt(e,t){try{let n=ft(e);if(t===`image/png`)return ht(n);if(t===`image/gif`)return gt(n);if(t===`image/jpeg`)return _t(n)}catch{}return null}async function yt(e){if(!m(e.mimeType))return $.warn(`Unsupported image format`,{mimeType:e.mimeType}),{type:`text`,text:`[Image removed: unsupported format "${e.mimeType}". Supported: JPEG, PNG, GIF, WebP]`};let t=e.data.length,i=vt(e.data,e.mimeType);if(!(t>5242880||i!==null&&(i.width>8e3||i.height>8e3)||i!==null&&Math.max(i.width,i.height)>1568))return e;$.info(`Image needs processing`,{base64Size:t,dimensions:i?`${i.width}x${i.height}`:`unknown`,reason:t>5242880?`size`:`dimensions`});let a,o;try{let e=await import(`./magick-wasm-DCNZhAyd.js`).then(e=>e.r);a=e.getMagick,o=e.MIME_TO_MAGICK_FORMAT}catch(e){return $.error(`ImageMagick WASM module unavailable`,{error:e instanceof Error?e.message:String(e)}),{type:`text`,text:`[Image removed: resize service unavailable (ImageMagick WASM could not be loaded)]`}}let s;try{s=await a()}catch(e){return $.error(`ImageMagick WASM initialization failed`,{error:e instanceof Error?e.message:String(e)}),{type:`text`,text:`[Image removed: resize service unavailable (WASM init failed)]`}}try{let i=r(ft(e.data)),a={data:null,mime:e.mimeType};if(await s.ImageMagick.read(i,async t=>{let n=t.width,r=t.height,i=Math.max(n,r);if(i>1568){let e=1568/i,a=Math.round(n*e),o=Math.round(r*e);t.resize(a,o),$.info(`Resized image`,{from:`${n}x${r}`,to:`${a}x${o}`})}let s=o[e.mimeType]||`JPEG`;t.write(s,e=>{a.data=new Uint8Array(e)}),a.data&&a.data.length>dt&&s!==`JPEG`?($.info(`Still over 5MB, compressing to JPEG q80`),t.quality=80,t.write(`JPEG`,e=>{a.data=new Uint8Array(e)}),a.mime=`image/jpeg`):a.data&&a.data.length>dt&&($.info(`Still over 5MB as JPEG, reducing quality to 60`),t.quality=60,t.write(`JPEG`,e=>{a.data=new Uint8Array(e)}))}),!a.data)return $.warn(`ImageMagick produced no output`),{type:`text`,text:`[Image removed: could not be processed (empty output from resize)]`};if(a.data.length>dt)return $.warn(`Image still over 5MB after resize+compress`,{size:a.data.length}),{type:`text`,text:`[Image removed: still ${Math.round(a.data.length/1024/1024*10)/10}MB after resize and compression, exceeds 5MB API limit]`};let c=n(a.data);return $.info(`Image processed successfully`,{originalBase64:t,newBase64:c.length,mimeType:a.mime}),{type:`image`,data:c,mimeType:a.mime}}catch(n){return $.error(`Image data processing failed (corrupt or unreadable)`,{mimeType:e.mimeType,estimatedBytes:t,error:n instanceof Error?n.message:String(n)}),{type:`text`,text:`[Image removed: image data could not be processed (${n instanceof Error?n.message:`corrupt or unreadable`})]`}}}const bt=t(`tool-adapter`);function xt(e){let t=[],n=0;for(let r of h(e)){if(r.kind===`inert`||!r.parsed)continue;let i=e.slice(n,r.index);i.trim()&&t.push({type:`text`,text:i.trimEnd()}),t.push({type:`image`,mimeType:r.parsed.mimeType,data:r.parsed.data}),n=r.index+r.marker.length}let r=e.slice(n);return(r.trim()||t.length===0)&&t.push({type:`text`,text:r||e}),t}async function St(e){let t=xt(e),n=[];for(let e of t)e.type===`image`?n.push(await yt(e)):n.push(e);return n}function Ct(e,t,n,r){if(!r)return{tracked:null,effectiveSignal:n};let i=r.processManager.spawn({kind:`tool`,argv:[e.name,...At(t)],owner:r.owner,ppid:r.getParentPid?.()});n?.aborted?r.processManager.signal(i.pid,`SIGINT`):n&&n.addEventListener(`abort`,()=>r.processManager.signal(i.pid,`SIGINT`),{once:!0});let a=r.processManager.onSignal((e,t)=>{e.pid===i.pid&&t===`SIGKILL`&&r.processManager.exit(i.pid,null)});return{tracked:{record:i,manager:r.processManager,unsubscribeKill:a},effectiveSignal:i.abort.signal}}function wt(e,t){e&&e.manager.exit(e.record.pid,t)}async function Tt(e,t,n){if(!n||typeof e!=`string`||e.length===0)return e;try{return await n.scrubToolResult(e)}catch(n){return bt.warn(`Tool-result scrub failed, falling back to unscrubbed content`,{tool:t,error:n instanceof Error?n.message:String(n)}),e}}async function Et(e,t){try{return await St(e)}catch(n){return bt.warn(`Image processing failed, falling back to raw content`,{tool:t,error:n instanceof Error?n.message:String(n)}),xt(e)}}async function Dt(e,t,n,r){let i=n?.currentGate();if(!i)return!0;if(r?.aborted)return!1;try{return await i.approve(e.name,t)&&r?.aborted!==!0}catch(t){return bt.warn(`Tool-call gate threw — refusing the call`,{tool:e.name,error:t instanceof Error?t.message:String(t)}),!1}}function Ot(e,t,n,r){return{name:e.name,label:e.name,description:e.description,parameters:e.inputSchema,prepareArguments:e.prepareArguments,async execute(i,a,o,s){let c;if(s&&(c=_({onUpdate:s,toolName:e.name,toolCallId:i})),!await Dt(e,a,r,o))return c&&g(c),{content:[{type:`text`,text:`${e.name}: not approved (guest-caused turn).`}],details:{isError:!0}};let l=Ct(e,a,o,t);try{let t=await e.execute(a??{},l.effectiveSignal),r=await Et(await Tt(t.content,e.name,n),e.name);return wt(l.tracked,+!!t.isError),{content:r,details:{isError:t.isError}}}catch(e){throw wt(l.tracked,l.tracked?.record.abort.signal.aborted?null:1),e}finally{c&&g(c),l.tracked?.unsubscribeKill()}}}}function kt(e,t,n,r){return e.map(e=>Ot(e,t,n,r))}function At(e){if(typeof e!=`object`||!e)return[];let t=e;for(let e of[`command`,`file_path`,`path`,`pattern`,`url`,`key`,`name`,`query`,`message`]){let n=t[e];if(typeof n==`string`&&n.length>0)return[n]}for(let e of Object.values(t))if(typeof e==`string`&&e.length>0)return[e];return[]}export{st as a,ct as i,At as n,ut as r,kt as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-b828m-Si.js","assets/rolldown-runtime-Dd_uD5pT.js","assets/buffer-DvhmllZ2.js","assets/opfs-mount-DVnNHDGI.js","assets/backend-hostfs-Zq8eFtjc.js","assets/api-endpoint-DuEQRZ4g.js","assets/runtime-env-Dlaokqg1.js","assets/types-D8gIX-W-.js","assets/remote-cache-3KNT1gsp.js","assets/mount-CkCLiqtz.js","assets/preload-helper-Czpn1I53.js","assets/mime-types-D0xZwlMO.js","assets/base64-ELzoYfwP.js","assets/mount-table-store-dY2IfQ5S.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{n as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./preload-helper-Czpn1I53.js";import{t as n}from"./logger-DDBAeTLF.js";import{n as r,t as i}from"./types-D8gIX-W-.js";import{a,i as o,n as s,r as c,t as l}from"./path-utils-DNJG-zQf.js";import{r as u,t as d}from"./bounded-walk-BjxKWNqp.js";import{n as ee,t as te}from"./virtual-device-paths-D45tpPP6.js";import{t as f}from"./same-file-identity-DuEcSmPX.js";import{a as ne,i as re,n as ie,t as p}from"./mount-table-store-dY2IfQ5S.js";var m=n(`fs-watcher`),ae=0;function oe(e,t){return t===`/`||e===t||e.startsWith(t+`/`)}var h=class{registrations=new Map;watch(e,t,n){let r=`fsw-${++ae}`;return this.registrations.set(r,{id:r,basePath:e,filter:t,callback:n}),m.debug(`Watch registered`,{id:r,basePath:e}),()=>{this.registrations.delete(r),m.debug(`Watch unregistered`,{id:r})}}notify(e){if(e.length!==0)for(let[,t]of this.registrations){let n=e.filter(e=>oe(e.path,t.basePath)&&t.filter(e.path));if(n.length>0)try{t.callback(n)}catch(e){m.error(`Watch callback error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}}}dispose(){this.registrations.clear(),m.debug(`All watchers disposed`)}get size(){return this.registrations.size}},g=n(`mount-index`),se=400,ce=2e6,le=`SLICC_MOUNT_INDEX_MAX_DEPTH`,ue=`SLICC_MOUNT_INDEX_MAX_ENTRIES`,_=256,v=class extends Error{cause;constructor(e,t){super(e),this.name=`MountIndexAbortError`,this.cause=t}};function de(e){let t=e.map(([e,t])=>`${e}\u0000${t.kind}`).sort(),n=t.length>_?t.slice(0,_):t;return`${t.length}\u0001${n.join(``)}`}async function fe(e,t){let n=e.isSameEntry;if(typeof n!=`function`)return!1;try{return await n.call(e,t)}catch{return!1}}function pe(e,t){return e instanceof Map?e.get(t):e[t]}function me(e){let t=e.trim();if(t===``)return;let n=Number(t);if(!(!Number.isInteger(n)||n<=0))return n}function y(e,t,n){let r=pe(e,t);if(r===void 0||r.trim()===``)return n;let i=me(r);return i===void 0?(g.warn(`Ignoring invalid ${t}; expected a positive integer, using default`,{value:r,fallback:n}),n):i}function b(e){return{maxDepth:y(e,le,se),maxEntries:y(e,ue,ce),skipNoiseDirs:!0}}var x=class{mounts=new Map;listeners=new Set;registerMount(e,t,n=b({})){this.mounts.get(e)?.abortController?.abort();let r=new AbortController,i={handle:t,state:{status:`pending`,indexed:0},files:new Set,directories:new Set,childrenByDirectory:new Map,abortController:r,limits:n};this.mounts.set(e,i),this.notifyListeners(),this.indexMount(e,i,r.signal)}unregisterMount(e){let t=this.mounts.get(e);t&&(t.abortController?.abort(),this.mounts.delete(e),this.notifyListeners())}async refreshMount(e,t){let n=this.mounts.get(e);if(!n)throw Error(`No mount at ${e}`);n.abortController?.abort();let r=new AbortController;n.abortController=r,n.state={status:`pending`,indexed:0},n.files.clear(),n.directories.clear(),n.childrenByDirectory.clear(),t&&(n.limits=t),this.notifyListeners(),await this.indexMount(e,n,r.signal)}isReady(e){return this.mounts.get(e)?.state.status===`ready`}isAnyIndexing(){for(let e of this.mounts.values())if(e.state.status===`indexing`||e.state.status===`pending`)return!0;return!1}dispose(){for(let e of this.mounts.values())e.abortController?.abort();this.mounts.clear(),this.listeners.clear()}getState(e){return this.mounts.get(e)?.state}getFiles(e,t){let n=this.mounts.get(e);if(n?.state.status!==`ready`)return;if(!t)return[...n.files];let r=[];for(let e of n.files)t(e)&&r.push(e);return r}getDirectoryEntries(e,t){let n=this.mounts.get(e);if(n?.state.status!==`ready`)return;let r=n.childrenByDirectory.get(t);if(r)return[...r].map(([e,t])=>({name:e,type:t}))}hasPath(e,t){let n=this.mounts.get(e);if(n?.state.status===`ready`)return n.files.has(t)||n.directories.has(t)}notifyWrite(e){let t=this.findMountForPath(e);if(!t)return;let n=this.mounts.get(t);if(n?.state.status!==`ready`||this.isSkippedNoisePath(t,e,n,`file`))return;n.files.add(e),this.addPathToChildIndex(n,e,`file`);let r=this.parentPath(e);for(;(r===t||r.startsWith(`${t}/`))&&(n.directories.add(r),this.ensureDirectoryChildren(n,r),r!==t);)this.addPathToChildIndex(n,r,`directory`),r=this.parentPath(r)}notifyDelete(e){let t=this.findMountForPath(e);if(!t)return;let n=this.mounts.get(t);if(n?.state.status!==`ready`||this.isSkippedNoisePath(t,e,n,`unknown`))return;n.files.delete(e),n.directories.delete(e);let r=e+`/`;for(let e of n.files)e.startsWith(r)&&n.files.delete(e);for(let e of n.directories)e.startsWith(r)&&n.directories.delete(e);this.removePathFromChildIndex(n,e);for(let t of n.childrenByDirectory.keys())(t===e||t.startsWith(r))&&n.childrenByDirectory.delete(t)}notifyRename(e,t){let n=this.findMountForPath(e);if(!n)return;let r=this.mounts.get(n);if(r?.state.status!==`ready`)return;let i=r.files.has(e)?`file`:r.directories.has(e)?`directory`:`unknown`;if(i===`unknown`||this.isSkippedNoisePath(n,e,r,i))return;if(this.isSkippedNoisePath(n,t,r,i)){this.notifyDelete(e);return}if(i===`file`){r.files.delete(e),r.files.add(t),this.removePathFromChildIndex(r,e),this.addPathToChildIndex(r,t,`file`);return}r.directories.delete(e),r.directories.add(t);let a=e+`/`,o=t+`/`;for(let e of[...r.files])e.startsWith(a)&&(r.files.delete(e),r.files.add(o+e.slice(a.length)));for(let e of[...r.directories])e.startsWith(a)&&(r.directories.delete(e),r.directories.add(o+e.slice(a.length)));this.removePathFromChildIndex(r,e),this.addPathToChildIndex(r,t,`directory`);let s=[...r.childrenByDirectory.entries()].filter(([t])=>t===e||t.startsWith(a));for(let[e]of s)r.childrenByDirectory.delete(e);for(let[n,i]of s){let s=n===e?t:o+n.slice(a.length);r.childrenByDirectory.set(s,i)}}ensureDirectoryChildren(e,t){let n=e.childrenByDirectory.get(t);return n||(n=new Map,e.childrenByDirectory.set(t,n)),n}addPathToChildIndex(e,t,n){let r=t.slice(t.lastIndexOf(`/`)+1);r&&(this.ensureDirectoryChildren(e,this.parentPath(t)).set(r,n),n===`directory`&&this.ensureDirectoryChildren(e,t))}removePathFromChildIndex(e,t){let n=t.slice(t.lastIndexOf(`/`)+1);e.childrenByDirectory.get(this.parentPath(t))?.delete(n)}parentPath(e){let t=e.lastIndexOf(`/`);return t<=0?`/`:e.slice(0,t)}isSkippedNoisePath(e,t,n,r){if(!n.limits.skipNoiseDirs||!t.startsWith(`${e}/`))return!1;let i=t.slice(e.length+1).split(`/`),a=r===`unknown`?n.files.has(t)?`file`:n.directories.has(t)?`directory`:`unknown`:r;for(let e=0;e<i.length;e++){let t=e===i.length-1;if(!(t&&a===`file`)&&!(t&&a===`unknown`&&!d(i[e]))&&d(i[e]))return!0}return!1}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}findMountForPath(e){let t;for(let n of this.mounts.keys())(e===n||e.startsWith(n+`/`))&&(!t||n.length>t.length)&&(t=n);return t}notifyListeners(){for(let e of this.listeners)try{e()}catch{}}async indexMount(e,t,n){t.state={status:`indexing`,indexed:0},this.notifyListeners();try{if(await this.walkHandle(e,t.handle,t,n),n.aborted)return;t.state={status:`ready`,indexed:t.files.size+t.directories.size,total:t.files.size+t.directories.size},t.abortController=null,g.info(`Mount indexed`,{path:e,files:t.files.size,directories:t.directories.size})}catch(r){if(n.aborted)return;let i=r instanceof Error?r.message:String(r),a=r instanceof v?r.cause:`indexing-error`;t.state={status:`error`,indexed:0,error:i,abortCause:a},g.error(`Mount indexing failed`,{path:e,error:i,abortCause:a})}this.notifyListeners()}async walkHandle(e,t,n,r,i=0,a=new Map){if(r.aborted)return;this.enforceWalkBounds(i,n),n.directories.add(e),this.ensureDirectoryChildren(n,e);let o=await this.readChildren(t,r,n);if(r.aborted)return;let s=await this.confirmNoCycle(e,t,o,a),c=this.pushAncestor(a,s,e,t);try{await this.walkChildren(e,o,n,r,i,a)}finally{this.popAncestor(a,s,c)}}enforceWalkBounds(e,t){if(e>t.limits.maxDepth)throw new v(`mount indexing aborted: directory nesting exceeded ${t.limits.maxDepth} levels`,`depth-exceeded`);if(t.directories.size+t.files.size>=t.limits.maxEntries)throw new v(`mount indexing aborted: exceeded ${t.limits.maxEntries} entries`,`entries-exceeded`)}async readChildren(e,t,n){let r=e,i=[];for await(let e of r){if(t.aborted)break;if(n.directories.size+n.files.size+i.length>=n.limits.maxEntries)throw new v(`mount indexing aborted: exceeded ${n.limits.maxEntries} entries`,`entries-exceeded`);i.push(e)}return i}async confirmNoCycle(e,t,n,r){let i=de(n),a=r.get(i);if(a){for(let n of a)if(await fe(n.handle,t))throw new v(`mount indexing aborted: self-referential mount cycle detected at ${e} (re-exposes ${n.path})`,`cycle-detected`)}return i}pushAncestor(e,t,n,r){let i=e.get(t);return i||(i=[],e.set(t,i)),i.push({path:n,handle:r,signature:t}),i}popAncestor(e,t,n){n.pop(),n.length===0&&e.delete(t)}async walkChildren(e,t,n,r,i,a){for(let[o,s]of t){if(r.aborted)return;let t=e===`/`?`/${o}`:`${e}/${o}`;if(s.kind===`file`)n.files.add(t),this.addPathToChildIndex(n,t,`file`),n.state.indexed++;else if(s.kind===`directory`){if(n.limits.skipNoiseDirs&&d(o))continue;this.addPathToChildIndex(n,t,`directory`),await this.walkHandle(t,s,n,r,i+1,a)}n.state.indexed%500==0&&(this.notifyListeners(),await new Promise(e=>setTimeout(e,0)))}}},S=new TextEncoder,C=new TextDecoder(`utf-8`,{fatal:!1}),w=class{entries=new Map;static handles(e){return ee(s(e))}has(e){return this.entries.has(s(e))}write(e,t){let n=s(e),r=typeof t==`string`?S.encode(t):new Uint8Array(t),i=Date.now(),a=this.entries.get(n);this.entries.set(n,{bytes:r,mtime:i,ctime:a?.ctime??i})}append(e,t){let n=this.entries.get(s(e))?.bytes??new Uint8Array,r=typeof t==`string`?S.encode(t):t,i=new Uint8Array(n.length+r.length);i.set(n),i.set(r,n.length),this.write(e,i)}read(e,t){let n=this.require(e);return(t?.encoding??`utf-8`)===`utf-8`?C.decode(n.bytes):new Uint8Array(n.bytes)}readText(e){return C.decode(this.require(e).bytes)}stat(e){let t=this.require(e);return{type:`file`,size:t.bytes.length,mtime:t.mtime,ctime:t.ctime}}remove(e){return this.entries.delete(s(e))}require(e){let t=s(e),n=this.entries.get(t);if(!n)throw new i(`ENOENT`,`no such file or directory`,t);return n}},T={[te]:{stat:()=>({type:`file`,size:0,mtime:0,ctime:0}),read:e=>(e?.encoding??`utf-8`)===`utf-8`?``:new Uint8Array,readText:()=>``,write:()=>{}}},E=[`/tmp/`],D=class{ephemeralFds=new w;vfs;allowedPrefixes;readOnlyPrefixes;readGrantPatterns=[];writeEnforcement;includeMounts;constructor(e,t,n=[],r=`hard`,i={}){this.vfs=e;let a=e=>{let t=s(e);return t.endsWith(`/`)?t:t+`/`};this.allowedPrefixes=t.map(a),this.readOnlyPrefixes=n.map(a),this.writeEnforcement=r,this.includeMounts=i.includeMounts!==!1}getAllPrefixes(){let e=this.includeMounts?this.vfs.listMounts().map(e=>e.endsWith(`/`)?e:e+`/`):[];return[...this.allowedPrefixes,...this.readOnlyPrefixes,...e,...E]}setReadGrants(e){this.readGrantPatterns=[];for(let t of new Set(e))this.addReadGrant(t)}addReadGrant(e){let t=e.split(`/`),n=[];for(let e=1;e<t.length;e++)n.push(c(t.slice(0,e).join(`/`)||`/`));this.readGrantPatterns.push({pattern:e,regex:c(e),ancestorRegexes:n})}matchesReadGrant(e){return this.readGrantPatterns.some(t=>t.regex.test(e))}leadsToReadGrant(e){return this.readGrantPatterns.some(t=>t.ancestorRegexes.some(t=>t.test(e)))}isAllowed(e){let t=s(e),n=this.getAllPrefixes();return this.matchesReadGrant(t)||this.leadsToReadGrant(t)||n.some(e=>t===e.slice(0,-1)||t.startsWith(e)||t===`/`||e.startsWith(t+`/`))}isAllowedStrict(e){let t=s(e),n=this.getAllPrefixes();return this.matchesReadGrant(t)||n.some(e=>t===e.slice(0,-1)||t.startsWith(e))}isWritable(e){let t=s(e);return[...this.allowedPrefixes,...E].some(e=>t===e.slice(0,-1)||t.startsWith(e))}canWrite(e){return w.handles(e)||this.isWritable(e)}checkWrite(e){if(this.writeEnforcement!==`sudo-delegated`&&!this.isWritable(e))throw new i(`EACCES`,`permission denied`,s(e))}async resolveAndCheckRead(e){try{let t=await this.vfs.realpath(e);if(!this.isAllowedStrict(t))throw new i(`ENOENT`,`no such file or directory`,s(e));return t}catch(t){throw t instanceof i?t:new i(`ENOENT`,`no such file or directory`,s(e))}}async resolveAndCheckWrite(e){try{let t=await this.vfs.realpath(e);if(!this.isWritable(t)&&!this.isSymlinkEscapeAllowed(t))throw new i(`EACCES`,`permission denied`,s(e));return t}catch(t){throw t instanceof i?t:new i(`EACCES`,`permission denied`,s(e))}}isSymlinkEscapeAllowed(e){return!1}async checkParentRealpathEscape(e){let t=this.vfs.dirname(e),n=this.vfs.basename(e),r;try{r=await this.vfs.realpath(t)}catch(e){if(e instanceof i&&e.code===`EACCES`)throw e;return}let a=r+`/`+n;if(this.isWritable(a))return;let o=s(r)!==s(t);if(!(this.writeEnforcement===`sudo-delegated`&&!o))throw new i(`EACCES`,`permission denied`,s(e))}getUnderlyingFS(){return this.vfs}invalidatePaths(e){this.vfs.invalidatePaths(e)}async forgetSidecarConsistency(){await this.vfs.forgetSidecarConsistency()}async flush(){await this.vfs.flush()}isPathUnderMount(e){return this.vfs.isPathUnderMount(e)}async readFile(e,t){let n=T[s(e)];if(n)return n.read(t);if(w.handles(e))return this.ephemeralFds.read(e,t);if(!this.isAllowedStrict(e))throw new i(`ENOENT`,`no such file or directory`,s(e));let r=await this.resolveAndCheckRead(e);return this.vfs.readFile(r,t)}async readFileRange(e,t,n){if(!this.isAllowedStrict(e))throw new i(`ENOENT`,`no such file or directory`,s(e));let r=await this.resolveAndCheckRead(e);return this.vfs.readFileRange(r,t,n)}async getNativeFile(e){if(T[s(e)]||w.handles(e)||!this.isAllowedStrict(e))return null;try{let t=await this.resolveAndCheckRead(e);return await this.vfs.getNativeFile(t)}catch{return null}}async readDir(e,t){if(!this.isAllowed(e))return[];let n=e;if(this.isAllowedStrict(e))try{n=await this.resolveAndCheckRead(e)}catch{return[]}let r=await this.vfs.readDir(n,t);if(!this.isAllowedStrict(e)){let t=s(e);return r.filter(e=>{let n=t===`/`?`/${e.name}`:`${t}/${e.name}`;return this.isAllowed(n)})}return r}async stat(e){let t=T[s(e)];if(t)return t.stat();if(w.handles(e))return this.ephemeralFds.stat(e);if(!this.isAllowed(e))throw new i(`ENOENT`,`no such file or directory`,s(e));if(this.isAllowedStrict(e)){let t=await this.resolveAndCheckRead(e);return this.vfs.stat(t)}return this.vfs.stat(e)}scanPathForSymlinks(e,t){let n=s(e);if(n===`/`)return!1;let r=n.slice(1).split(`/`),i=t?r.length:r.length-1,a=``;for(let e=0;e<i;e++){a=a+`/`+r[e];let t=this.vfs.lstatSync(a);if(t===null)return null;if(t.type===`symlink`)return!0}return!1}statSync(e){let t=T[s(e)];return t?t.stat():w.handles(e)?this.ephemeralFds.has(e)?this.ephemeralFds.stat(e):null:!this.isAllowedStrict(e)||this.scanPathForSymlinks(e,!0)!==!1?null:this.vfs.statSync(e)}lstatSync(e){let t=T[s(e)];return t?t.stat():w.handles(e)?this.ephemeralFds.has(e)?this.ephemeralFds.stat(e):null:!this.isAllowed(e)||this.scanPathForSymlinks(e,!1)!==!1?null:this.vfs.lstatSync(e)}readDirSync(e){if(!this.isAllowed(e)||this.scanPathForSymlinks(e,!0)!==!1)return null;let t=this.vfs.readDirSync(e);if(t===null)return null;if(this.isAllowedStrict(e))return t;let n=s(e);return t.filter(e=>{let t=n===`/`?`/${e.name}`:`${n}/${e.name}`;return this.isAllowed(t)})}async realpath(e){if(w.handles(e)){let t=s(e);if(!this.ephemeralFds.has(t))throw new i(`ENOENT`,`no such file or directory`,t);return t}let t;try{t=await this.vfs.realpath(e)}catch(t){throw t instanceof i?t:new i(`ENOENT`,`no such file or directory`,s(e))}if(!this.isAllowedStrict(t))throw new i(`ENOENT`,`no such file or directory`,s(e));return t}async exists(e){if(T[s(e)])return!0;if(w.handles(e))return this.ephemeralFds.has(e);if(!this.isAllowed(e))return!1;if(this.isAllowedStrict(e))try{await this.resolveAndCheckRead(e)}catch{return!1}return this.vfs.exists(e)}async readTextFile(e){let t=T[s(e)];if(t)return t.readText();if(w.handles(e))return this.ephemeralFds.readText(e);if(!this.isAllowedStrict(e))throw new i(`ENOENT`,`no such file or directory`,s(e));let n=await this.resolveAndCheckRead(e);return this.vfs.readTextFile(n)}async*walk(e){if(!this.isAllowed(e))return;let t=e;if(this.isAllowedStrict(e))try{t=await this.resolveAndCheckRead(e)}catch{return}for await(let e of this.vfs.walk(t))this.isAllowed(e)&&(yield e)}async writeFile(e,t,n){let r=T[s(e)];if(r){r.write(t);return}if(w.handles(e)){this.ephemeralFds.write(e,t);return}return await this.checkContentWrite(e),this.vfs.writeFile(e,t,n)}async appendFile(e,t){let n=T[s(e)];if(n){n.write(t);return}if(w.handles(e)){this.ephemeralFds.append(e,t);return}return await this.checkContentWrite(e),this.vfs.appendFile(e,t)}async chmod(e,t){return this.refuseDescriptorTreeOp(e),await this.checkContentWrite(e),this.vfs.chmod(e,t)}async utimes(e,t,n){return this.refuseDescriptorTreeOp(e),await this.checkContentWrite(e),this.vfs.utimes(e,t,n)}async checkContentWrite(e){this.checkWrite(e),await this.checkParentRealpathEscape(e);try{(await this.vfs.lstat(e)).type===`symlink`&&await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof i&&e.code===`EACCES`)throw e}}refuseDescriptorTreeOp(e){if(w.handles(e))throw new i(`EACCES`,`permission denied`,s(e))}async mkdir(e,t){return this.refuseDescriptorTreeOp(e),this.checkWrite(e),await this.checkParentRealpathEscape(e),this.vfs.mkdir(e,t)}async rm(e,t){if(w.handles(e)){if(!this.ephemeralFds.remove(e))throw new i(`ENOENT`,`no such file or directory`,s(e));return}this.checkWrite(e);try{(await this.vfs.lstat(e)).type===`symlink`||await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof i&&e.code===`EACCES`)throw e}return this.vfs.rm(e,t)}async rename(e,t){return this.refuseDescriptorTreeOp(e),this.refuseDescriptorTreeOp(t),this.checkWrite(e),this.checkWrite(t),await this.resolveAndCheckWrite(e),await this.checkParentRealpathEscape(t),this.vfs.rename(e,t)}async copyFile(e,t){if(w.handles(e)){let n=this.ephemeralFds.read(e,{encoding:`binary`});await this.writeFile(t,n);return}if(w.handles(t)){if(!this.isAllowed(e))throw new i(`ENOENT`,`no such file or directory`,s(e));let n=await this.resolveAndCheckRead(e);this.ephemeralFds.write(t,await this.vfs.readFile(n,{encoding:`binary`}));return}if(!this.isAllowed(e))throw new i(`ENOENT`,`no such file or directory`,s(e));this.checkWrite(t);let n=await this.resolveAndCheckRead(e);await this.checkParentRealpathEscape(t);try{(await this.vfs.lstat(t)).type===`symlink`&&await this.resolveAndCheckWrite(t)}catch(e){if(e instanceof i&&e.code===`EACCES`)throw e}return this.vfs.copyFile(n,t)}async symlink(e,t){return this.refuseDescriptorTreeOp(t),this.checkWrite(t),await this.checkParentRealpathEscape(t),this.vfs.symlink(e,t)}async readlink(e){if(!this.isAllowedStrict(e))throw new i(`ENOENT`,`no such file or directory`,s(e));let t=await this.vfs.readlink(e),n;if(t.startsWith(`/`))n=s(t);else{let r=this.vfs.dirname(e);n=s(r+`/`+t)}if(!this.isAllowedStrict(n))throw new i(`ENOENT`,`no such file or directory`,s(e));return t}async lstat(e){let t=T[s(e)];if(t)return t.stat();if(w.handles(e))return this.ephemeralFds.stat(e);if(!this.isAllowed(e))throw new i(`ENOENT`,`no such file or directory`,s(e));let n=s(e),r=this.vfs.dirname(n),a=this.vfs.basename(n),o;if(r===n)o=r;else try{o=await this.vfs.realpath(r)}catch{throw new i(`ENOENT`,`no such file or directory`,n)}let c=o===`/`?`/${a}`:`${o}/${a}`;if(!this.isAllowed(c))throw new i(`ENOENT`,`no such file or directory`,n);return this.vfs.lstat(c)}watch(e,t,n){if(!this.isAllowed(e))throw new i(`EACCES`,`permission denied`,s(e));let r=this.vfs.getWatcher();if(!r)throw new i(`EINVAL`,`no watcher configured`);return r.watch(s(e),t,n)}dirname(e){return this.vfs.dirname(e)}basename(e){return this.vfs.basename(e)}async mount(e,t,n){return this.refuseDescriptorTreeOp(e),this.checkWrite(e),await this.checkParentRealpathEscape(e),this.vfs.mount(e,t,n)}async unmount(e){return this.refuseDescriptorTreeOp(e),this.checkWrite(e),await this.checkParentRealpathEscape(e),this.vfs.unmount(e)}listMounts(){let e=this.vfs.listMounts();return this.includeMounts?e:e.filter(e=>this.isAllowedStrict(e))}getMountIndex(){return this.vfs.getMountIndex()}async refreshMount(e,t){return this.refuseDescriptorTreeOp(e),this.checkWrite(e),this.vfs.refreshMount(e,t)}async dispose(){await this.vfs.dispose()}};function O(e,t){if(e instanceof i){let n=`${e.code}: `,r=e.message;throw r.startsWith(n)&&(r=r.slice(n.length)),e.path&&r.endsWith(` '${e.path}'`)&&(r=r.slice(0,r.length-` '${e.path}'`.length)),new i(e.code,r,t)}throw e}var he=[`ENOENT`,`EEXIST`,`ENOTDIR`,`EISDIR`,`ENOTEMPTY`,`EINVAL`,`EACCES`,`ELOOP`,`EBUSY`,`EFBIG`,`EBADF`,`ENOSYS`,`EOPNOTSUPP`,`EXDEV`,`EIO`];function k(e,t){if(e instanceof i)return e;{let n=e instanceof Error?e.message:String(e);if(n.includes(`maximum size exceeded`)||n.includes(`call stack size exceeded`))return new i(`EIO`,`internal overflow, not storage: ${n} — reload the session`,t)}let n=e?.code;if(typeof n==`string`){let r=n;if(he.includes(r)){let n=e instanceof Error?e.message:String(e);return n.startsWith(`${r}: `)&&(n=n.slice(r.length+2),n=n.replace(/, undefined( '[^']*')?$/,``).replace(/ '[^']*'$/,``)),new i(r,n||r,t)}}let r=e instanceof Error?e.message:String(e);return r.includes(`ENOENT`)?new i(`ENOENT`,`no such file or directory`,t):r.includes(`EEXIST`)?new i(`EEXIST`,`file already exists`,t):r.includes(`ENOTDIR`)?new i(`ENOTDIR`,`not a directory`,t):r.includes(`EISDIR`)?new i(`EISDIR`,`is a directory`,t):r.includes(`ENOTEMPTY`)?new i(`ENOTEMPTY`,`directory not empty`,t):r.includes(`ELOOP`)?new i(`ELOOP`,`too many levels of symbolic links`,t):r.includes(`EOPNOTSUPP`)||r.includes(`ENOTSUP`)?new i(`EOPNOTSUPP`,`operation not supported`,t):r.includes(`EXDEV`)?new i(`EXDEV`,`cross-device link`,t):new i(`EINVAL`,r,t)}var ge=61440,_e=16384;function A(e){return e===void 0?`absent`:(e&ge)===_e?`directory`:`file`}function j(e,t){return t===`absent`?!1:e.kind===`missing`||e.kind!==t}function M(e){let t=e?.mode;return typeof t==`number`?t:void 0}function ve(e,t,n,r=new Set){let i=new Set(n);if(r.size>0){for(let t of Object.keys(e.entries??{}))for(let e of r)if(t===e||t.startsWith(`${e}/`)){i.add(t);break}}let a=[];for(let n of i){let r=e.entries?.[n],i=t.entries?.[n];if(!r||!i)continue;let o=A(M(r));o!==A(M(i))&&a.push({path:n,ownIsDirectory:o===`directory`})}return a}var N=512,P=class e{kind=`local`;listingStatsMatchStat=!0;source=void 0;profile=void 0;mountId;handle;dirCacheMax;dirCache=new Map;closed=!1;constructor(e,t){this.handle=e,this.mountId=t.mountId,this.dirCacheMax=t.dirCacheMax??N}static fromHandle(t,n){return new e(t,n)}getHandle(){return this.handle}assertOpen(e){if(this.closed)throw new i(`EBADF`,`mount closed`,e)}splitPath(e){return e.replace(/^\/+/,``).replace(/\/+$/,``).split(`/`).filter(e=>e.length>0)}cacheGet(e){let t=this.dirCache.get(e);if(t!==void 0)return this.dirCache.delete(e),this.dirCache.set(e,t),t}cacheSet(e,t){for(this.dirCache.has(e)&&this.dirCache.delete(e),this.dirCache.set(e,t);this.dirCache.size>this.dirCacheMax;){let e=this.dirCache.keys().next();if(e.done)break;this.dirCache.delete(e.value)}}invalidate(e){if(e===``){this.dirCache.clear();return}let t=`${e}/`;for(let n of[...this.dirCache.keys()])(n===e||n.startsWith(t))&&this.dirCache.delete(n)}getDirCacheSize(){return this.dirCache.size}async resolveDirFrom(e,t,n,r=!0){let i=this.handle,a=``,o=0;if(r)for(let t=e.length;t>0;t--){let n=e.slice(0,t).join(`/`),r=this.cacheGet(n);if(r){i=r,a=n,o=t;break}}let s=a;for(;o<e.length;o++){let r=e[o];try{i=await i.getDirectoryHandle(r,{create:n})}catch(r){if(n&&s!==``)return this.invalidate(s),this.resolveDirFrom(e,t,n,!1);throw this.toFsError(r,t)}a=a===``?r:`${a}/${r}`,this.cacheSet(a,i)}return i}async resolveDir(e,t=!1){return this.resolveDirFrom(this.splitPath(e),e,t)}async resolveParent(e,t){let n=this.splitPath(e);if(n.length===0)throw new i(`EISDIR`,`is a directory`,e);let r=n.pop();return{parent:await this.resolveDirFrom(n,e,t),name:r}}async resolveFile(e,t=!1){let{parent:n,name:r}=await this.resolveParent(e,t);try{return await n.getFileHandle(r,{create:t})}catch(t){throw this.toFsError(t,e)}}toFsError(e,t){if(e instanceof i)return e;if(e instanceof DOMException){if(e.name===`NotFoundError`)return new i(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatchError`)return new i(`ENOTDIR`,`not a directory`,t);if(e.name===`NotAllowedError`)return new i(`EACCES`,`permission denied`,t);if(e.name===`InvalidModificationError`)return new i(`ENOTEMPTY`,`directory not empty`,t)}if(e instanceof Error){if(e.name===`NotFound`||e.name===`NotFoundError`)return new i(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatch`||e.name===`TypeMismatchError`)return new i(`ENOTDIR`,`not a directory`,t);if(e.name===`InvalidModification`||e.name===`InvalidModificationError`)return new i(`ENOTEMPTY`,`directory not empty`,t)}return new i(`EINVAL`,e instanceof Error?e.message:String(e),t)}async readDir(e,t){this.assertOpen(e);let n=await this.resolveDir(e),r=[];for await(let[e,i]of n){if(i.kind!==`file`){r.push({name:e,kind:`directory`});continue}if(!t?.includeStats){r.push({name:e,kind:`file`});continue}let n=await i.getFile();r.push({name:e,kind:`file`,size:n.size,lastModified:n.lastModified})}return r}async readFile(e){this.assertOpen(e);let t=await(await this.resolveFile(e)).getFile();return new Uint8Array(await t.arrayBuffer())}async getNativeFile(e){this.assertOpen(e);try{return await(await this.resolveFile(e)).getFile()}catch{return null}}async writeFile(e,t){this.assertOpen(e);let n=await(await this.resolveFile(e,!0)).createWritable();await n.write(t),await n.close()}async stat(e){this.assertOpen(e);let t=this.splitPath(e);if(t.length===0)return{kind:`directory`,size:0,mtime:0};let n=t.pop(),r=await this.resolveDirFrom(t,e,!1);try{let e=await(await r.getFileHandle(n)).getFile();return{kind:`file`,size:e.size,mtime:e.lastModified}}catch(t){let n=this.toFsError(t,e);if(n.code!==`ENOENT`&&n.code!==`ENOTDIR`)throw n}try{let e=await r.getDirectoryHandle(n);this.cacheSet(t.length===0?n:`${t.join(`/`)}/${n}`,e)}catch(t){throw this.toFsError(t,e)}return{kind:`directory`,size:0,mtime:0}}async mkdir(e){this.assertOpen(e),await this.resolveDir(e,!0)}async remove(e,t){this.assertOpen(e);let n=this.splitPath(e);if(n.length===0)throw new i(`EINVAL`,`cannot remove mount root`,e);let r=n.pop(),a=await this.resolveDirFrom(n,e,!1);try{await a.removeEntry(r,{recursive:t?.recursive??!1})}catch(t){throw this.toFsError(t,e)}this.invalidate(n.length===0?r:`${n.join(`/`)}/${r}`)}async refresh(){return this.assertOpen(`/`),this.dirCache.clear(),{added:[],removed:[],changed:[],unchanged:0,errors:[]}}describe(){return{displayName:this.handle.name}}async close(){this.closed=!0,this.dirCache.clear()}};async function F(e,t){let n=t.split(`/`).filter(Boolean),r=n.pop();if(r===void 0)return null;try{let t=e;for(let e of n)t=await t.getDirectoryHandle(e);return await(await t.getFileHandle(r)).getFile()}catch{return null}}function I(e,t){return e===t||e.startsWith(t===`/`?`/`:`${t}/`)}var ye=`/.metadata.json`,L=`.metadata.consistent.json`,R=`/${L}`;function z(e){return e.entries&&(delete e.entries[ye],delete e.entries[R]),e}function be(e,t,n){let r=t.entries??{},i={...e.entries??{}};`/`in r&&(i[`/`]=r[`/`]);for(let e of n.paths)e in r?i[e]=r[e]:delete i[e];for(let e of n.prefixes){for(let t of Object.keys(i))I(t,e)&&delete i[t];for(let t of Object.keys(r))I(t,e)&&(i[t]=r[t])}let{entries:a,...o}=t;return z({...o,entries:i})}var B=1;async function xe(e,t,n){let r=Math.max(1,Math.trunc(e)||1),i=Array(t.length),a=0,o=async()=>{for(;a<t.length;){let e=a;if(a+=1,e>=t.length)return;i[e]=await n(t[e],e)}},s=[],c=Math.min(r,t.length);for(let e=0;e<c;e+=1)s.push(o());return await Promise.all(s),i}async function V(e){let t=e;if(typeof t.createSyncAccessHandle==`function`)try{let e=await t.createSyncAccessHandle();try{return e.getSize()}finally{try{await e.close()}catch{}}}catch{}return(await e.getFile()).size}async function H(e){let t;for(let n=0;n<3;n+=1)try{return await(await e.getFile()).text()}catch(e){if(e?.name!==`NotReadableError`)throw e;t=e}throw t}function Se(e){if(!e||typeof e!=`object`)return!1;let t=e.entries;return!!t&&typeof t==`object`}async function Ce(e){try{let t=await H(await e.getFileHandle(`.metadata.json`)),n=JSON.parse(t);return Se(n)?{text:t,doc:n}:null}catch{return null}}async function we(e,t){let n=await(await e.getFileHandle(`.metadata.json`,{create:!0})).createWritable();await n.write(t),await n.close()}async function U(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e)),n=new Uint8Array(t),r=``;for(let e of n)r+=e.toString(16).padStart(2,`0`);return r}async function W(e,t){try{let n=await e.getFileHandle(L),r=JSON.parse(await H(n));if(!r||typeof r!=`object`)return!1;let i=r;return i.v!==B||typeof i.hash!=`string`?!1:i.hash===await U(t)}catch{return!1}}async function Te(e,t){let n={v:B,hash:await U(t)},r=await(await e.getFileHandle(L,{create:!0})).createWritable();await r.write(JSON.stringify(n)),await r.close()}async function Ee(e){try{await e.removeEntry(L)}catch(e){if(e?.name===`NotFoundError`)return;throw e}}async function De(e,t,n){let r=e,i=``,a=0;for(let e=n.length;e>0;--e){let o=n.slice(0,e).join(`/`),s=t.get(o);if(s){r=s,i=o,a=e;break}}for(let e=a;e<n.length;e+=1){let a=n[e];try{r=await r.getDirectoryHandle(a)}catch{return null}i=i?`${i}/${a}`:a,t.set(i,r)}return r}async function Oe(e,t,n,r,i,a){let o=async()=>{try{let n=await e.getDirectoryHandle(t);return i.set(a?`${a}/${t}`:t,n),{kind:`directory`}}catch{return null}},s=async()=>{try{let n=await e.getFileHandle(t);return r?{kind:`file`,size:await V(n)}:{kind:`file`,size:0}}catch{return null}};return n===`directory`?await o()??await s()??{kind:`missing`}:await s()??await o()??{kind:`missing`}}function G(e,t){let n=t?.includeSize!==!1,r=new Map;return async(t,i)=>{let a=t.split(`/`).filter(Boolean),o=await De(e,r,a.slice(0,-1));if(!o)return{kind:`missing`};let s=a[a.length-1];if(s===void 0)return{kind:`directory`};let c=a.slice(0,-1).join(`/`);return Oe(o,s,i,n,r,c)}}async function ke(e){let t=new Map;for await(let[n,r]of e.entries())t.set(n,r);return t}function Ae(e){return e.kind===`directory`?`directory`:e.kind===`file`?`file`:`other`}function je(e){if(typeof e.entries!=`function`)return G(e);let t=new Map,n=(e,n)=>{let r=t.get(n);if(r)return r;let i=ke(e).catch(e=>{throw t.delete(n),e});return t.set(n,i),i};return async t=>{let r=t.split(`/`).filter(Boolean),i=e,a=``;for(let e=0;e<r.length;e+=1){let t=r[e],o=(await n(i,a)).get(t);if(!o)return{kind:`missing`};let s=Ae(o);if(e!==r.length-1){if(s!==`directory`)return{kind:`missing`};i=o,a=`${a}/${t}`;continue}return s===`directory`?{kind:`directory`}:s===`file`?{kind:`file`,size:await V(o)}:{kind:`missing`}}return{kind:`directory`}}}var Me=61440,K=16384,q=32768,Ne=40960;async function Pe(e,t,n,r=16){let i=J(),a=e.entries??{},o=[];for(let[e,t]of Object.entries(a)){let r=Fe(e,t,a,i);r?o.push(r):n?.()}return Ie(o,await xe(r,o,async e=>{n?.();let r=e.fmt===K?`directory`:`file`;return t(e.path,r)}),a,i),Le(a,i),i}function J(){return{kindFixed:[],sizesFixed:0,dropped:0,selfEntryDropped:!1,inosReassigned:0,nlinksFixed:0,changed:!1}}function Fe(e,t,n,r){if(e===`/`||typeof t!=`object`||!t)return null;if(e===`/.metadata.json`||e===R)return delete n[e],e===`/.metadata.json`&&(r.selfEntryDropped=!0),r.changed=!0,null;let i=t,a=(i.mode??0)&Me;return a===Ne?(Y(i,r),null):{path:e,entry:i,fmt:a}}function Ie(e,t,n,r){for(let i=0;i<e.length;i+=1){let a=e[i],o=t[i];if(o.kind===`missing`){delete n[a.path],r.dropped+=1,r.changed=!0;continue}Y(a.entry,r),Re(a.path,a.entry,a.fmt,o,r)}}function Le(e,t){let n=0;for(let t of Object.values(e)){let e=t;typeof e?.ino==`number`&&(n=Math.max(n,e.ino)),typeof e?.data==`number`&&(n=Math.max(n,e.data))}let r=n+1,i=new Set;for(let[n,a]of Object.entries(e)){if(typeof a!=`object`||!a)continue;let e=a;if(n===`/`){typeof e.ino==`number`&&i.add(e.ino);continue}let o=e.ino;if(typeof o==`number`&&o!==0&&!i.has(o)){i.add(o);continue}e.ino=r,e.data=r+1,i.add(r),r+=2,t.inosReassigned+=1,t.changed=!0}}function Y(e,t){e.nlink||(e.nlink=1,t.nlinksFixed+=1,t.changed=!0)}function Re(e,t,n,r,i){if(n===q&&r.kind===`directory`){t.mode=((t.mode??0)&511||493)|K,i.kindFixed.push(`${e} file→dir`),i.changed=!0;return}if(n===K&&r.kind===`file`){t.mode=((t.mode??0)&511||420)|q,t.size=r.size,i.kindFixed.push(`${e} dir→file`),i.changed=!0;return}n===q&&r.kind===`file`&&typeof t.size==`number`&&t.size!==r.size&&(t.size=r.size,i.sizesFixed+=1,i.changed=!0)}async function ze(e,t,n){try{return await e()}catch(r){let i=null;try{i=await t()}catch{}if(!i?.changed)throw r;return n(i),await e()}}async function Be(e,t){let n=await Ce(e);if(!n)return null;if(await W(e,n.text))return J();let r=await Pe(n.doc,je(e),t),i=r.changed?JSON.stringify(n.doc):n.text;r.changed&&await we(e,i);try{await Te(e,i)}catch{}return r}function X(e,t,n=0){if(!(!Number.isSafeInteger(t)||(t??0)<=0||!Number.isSafeInteger(n)||n<0))return JSON.stringify([e,n,t])}async function Ve(e,t,n,r){try{return await e.lstat(t)}catch(e){let t=k(e,r);if(t.code===`ENOENT`&&n)return null;throw t}}async function He(e,t,n){let r;try{r=await e.readlink(t)}catch(e){throw k(e,n)}return r.startsWith(`/`)?s(r):s(l(a(t).dir,r))}async function Ue(e,t,n,r,a,o){let s=t===`/`?`/${n}`:`${t}/${n}`;for(;;){let t=await Ve(e,s,r,a);if(t===null||!t.isSymbolicLink())return{resolved:s,hops:o};if(++o>10)throw new i(`ELOOP`,`too many symbolic links encountered`,a);s=await He(e,s,a)}}async function Z(e,t,n){let r=s(n);if(t(r))return r;let i=r.split(`/`).filter(Boolean),a=`/`,o=0;for(let t=0;t<i.length;t++){let n=await Ue(e,a,i[t],t===i.length-1,r,o);a=n.resolved,o=n.hops}return a}async function We(e,t,n){return t(n)?n:Z(e,t,n)}function Q(){try{if(typeof globalThis.navigator?.storage?.getDirectory==`function`)return`opfs`}catch{}return`memory`}function Ge(e,t){let n=e.kind===`directory`?`directory`:`file`;return t?{name:e.name,type:n,...e.size===void 0?{}:{size:e.size},...e.lastModified===void 0?{}:{mtime:e.lastModified},...e.ctime===void 0?{}:{ctime:e.ctime},...e.ino===void 0?{}:{ino:e.ino},...e.identity===void 0?{}:{identity:e.identity},...e.dev===void 0?{}:{dev:e.dev},...e.uid===void 0?{}:{uid:e.uid},...e.gid===void 0?{}:{gid:e.gid},...e.mode===void 0?{}:{mode:e.mode}}:{name:e.name,type:n}}function Ke(e,t){switch(e.kind){case`local`:case`proc`:return{kind:`local`,mountId:e.mountId,idbHandleKey:t};case`hostfs`:return{kind:`hostfs`,mountId:e.mountId,hostPath:e.getHostPath()};default:return{kind:e.kind===`s3`?`s3`:e.kind===`aem`?`aem`:`da`,mountId:e.mountId,source:e.source,profile:e.profile??`default`}}}var $=class e{lfs;lfsSync;rawLfs=null;rawLfsSync=null;_ready;_readyResolved=!1;backend;mountPoints=new Map;opfsBackendFs=null;opfsHandle=null;mountRoot=``;internalMounts=new Set;watcher=null;dbName;mountSyncChannel=null;mountIndex=new x;static writeChains=new Map;onRepairProgress;constructor(t,n,r,i,a,o){if(this.dbName=t,this.onRepairProgress=a,this.backend=r===`opfs`?`opfs`:`memory`,this.lfs=this.makeDeferredLfs(),this.lfsSync=this.makeDeferredLfsSync(),this._ready=this.backend===`opfs`?e.initOpfsBackend(this,i,n===!0,o):e.initMemoryBackend(this,t,n===!0),this._ready.then(()=>{this._readyResolved=!0},()=>{}),typeof BroadcastChannel<`u`)try{this.mountSyncChannel=new BroadcastChannel(`vfs-mount-sync:${t}`),this.mountSyncChannel.onmessage=e=>{let{type:t,path:n,descriptor:r}=e.data??{};if(t===`mount`&&typeof n==`string`&&r)this.reconstructBackendFromDescriptor(r,n).then(e=>{this.mountPoints.set(n,e),e.kind===`local`&&this.mountIndex.registerMount(n,e.getHandle()),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}])}).catch(()=>{});else if(t===`unmount`&&typeof n==`string`){let e=this.mountPoints.get(n);this.mountPoints.delete(n),this.mountIndex.unregisterMount(n),e?.close(),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}])}}}catch{}}static opfsInitChains=new Map;static async initOpfsBackend(t,n,r,i){let a=(e.opfsInitChains.get(t.dbName)??Promise.resolve()).catch(()=>{}).then(()=>e.resolveOpfsBackend(t,n,r,i));e.opfsInitChains.set(t.dbName,a);try{await a}finally{e.opfsInitChains.get(t.dbName)===a&&e.opfsInitChains.delete(t.dbName)}}static async resolveOpfsBackend(n,r,a,o){let s=e.opfsBackends.get(n.dbName);if(s&&a)throw new i(`EBUSY`,`Cannot wipe an OPFS backend with live holders`,n.dbName);if(s&&o!==void 0&&s.asyncCache!==o)throw new i(`EBUSY`,`OPFS async cache setting conflicts with the live backend`,n.dbName);let c=r??await e.acquireOpfsHandle(n.dbName,a);await n.withWriteLock(()=>e.seedOpfsMetadataSidecarIfMissing(c));let l=await t(()=>import(`./dist-b828m-Si.js`),__vite__mapDeps([0,1,2]));await e.ensureRootMount(l);let u=`/__opfs__/${n.dbName}`,d=e.opfsBackends.get(n.dbName);if(!d){let{resolveOpfsMount:r}=await t(async()=>{let{resolveOpfsMount:e}=await import(`./opfs-mount-DVnNHDGI.js`);return{resolveOpfsMount:e}},__vite__mapDeps([3,0,1,2])),i=await r({handle:c,dbName:n.dbName,asyncCache:o,onRepairProgress:n.onRepairProgress,withWriteLock:e=>n.withWriteLock(e)});try{l.mount(u,i)}catch{}d={backendFs:i,refs:0,asyncCache:o!==!1,sidecarDirty:{paths:new Set,prefixes:new Set}},e.opfsBackends.set(n.dbName,d)}d.refs+=1,n.opfsBackendFs=d.backendFs.index?d.backendFs:null,n.opfsHandle=c,n.mountRoot=u,n.rawLfs=l.promises,n.rawLfsSync=l}static async initMemoryBackend(n,r,i){let a=await t(()=>import(`./dist-b828m-Si.js`),__vite__mapDeps([0,1,2]));await e.ensureRootMount(a);let o=`/__zenfs__/${r}`,s=e.memoryBackends.get(r);if(s&&i){try{a.umount(o)}catch{}e.memoryBackends.delete(r),s=void 0}s||(s={store:a.InMemory.create({label:r}),refs:0},e.memoryBackends.set(r,s)),s.refs+=1;try{a.mount(o,s.store)}catch{}n.mountRoot=o,n.rawLfs=a.promises,n.rawLfsSync=a,n.opfsBackendFs=null,n.opfsHandle=null}static rootMountReady=null;static memoryBackends=new Map;static opfsBackends=new Map;static async ensureRootMount(t){return e.rootMountReady===null&&(e.rootMountReady=(async()=>{await t.configureSingle({backend:t.InMemory,label:`__vfs_root__`})})()),e.rootMountReady}prefix(e){return this.mountRoot?e===`/`?this.mountRoot:this.mountRoot+e:e}unprefix(e){return!this.mountRoot||!e.startsWith(this.mountRoot)?e:e.slice(this.mountRoot.length)||`/`}makeDeferredLfs(){let e=e=>this.prefix(e),t=e=>this.unprefix(e),n=()=>{if(!this.rawLfs)throw Error(`VirtualFS used before init resolved`);return this.rawLfs};return{readFile:(t,r)=>this._readyResolved?n().readFile(e(t),r):this._ready.then(()=>n().readFile(e(t),r)),writeFile:(t,r,i)=>this._readyResolved?n().writeFile(e(t),r,i):this._ready.then(()=>n().writeFile(e(t),r,i)),appendFile:async(t,r)=>{this._readyResolved||await this._ready,await n().appendFile(e(t),r)},chmod:async(t,r)=>{this._readyResolved||await this._ready,await n().chmod(e(t),r)},utimes:async(t,r,i)=>{this._readyResolved||await this._ready,await n().utimes(e(t),r,i)},readdir:t=>this._readyResolved?n().readdir(e(t)):this._ready.then(()=>n().readdir(e(t))),mkdir:(t,r)=>this._readyResolved?n().mkdir(e(t),r):this._ready.then(()=>n().mkdir(e(t),r)),rmdir:t=>this._readyResolved?n().rmdir(e(t)):this._ready.then(()=>n().rmdir(e(t))),unlink:t=>this._readyResolved?n().unlink(e(t)):this._ready.then(()=>n().unlink(e(t))),rename:(t,r)=>this._readyResolved?n().rename(e(t),e(r)):this._ready.then(()=>n().rename(e(t),e(r))),stat:t=>this._readyResolved?n().stat(e(t)):this._ready.then(()=>n().stat(e(t))),lstat:t=>this._readyResolved?n().lstat(e(t)):this._ready.then(()=>n().lstat(e(t))),symlink:(t,r)=>{let i=t.startsWith(`/`)?e(t):t;return this._readyResolved?n().symlink(i,e(r)):this._ready.then(()=>n().symlink(i,e(r)))},readlink:async r=>(this._readyResolved||await this._ready,t(await n().readlink(e(r)))),truncate:async(t,r)=>{this._readyResolved||await this._ready;let i=n();typeof i.truncate==`function`&&await i.truncate(e(t),r)},realpath:async r=>{this._readyResolved||await this._ready;let i=n();return typeof i.realpath==`function`?t(await i.realpath(e(r))):e(r)}}}makeDeferredLfsSync(){let e=e=>this.prefix(e),t=e=>this.unprefix(e);return{readdirSync:t=>{let n=this.rawLfsSync;return n?.readdirSync?n.readdirSync(e(t)):void 0},statSync:t=>{let n=this.rawLfsSync;return n?.statSync?n.statSync(e(t)):void 0},lstatSync:t=>{let n=this.rawLfsSync;return n?.lstatSync?n.lstatSync(e(t)):void 0},readlinkSync:n=>{let r=this.rawLfsSync;return r?.readlinkSync?t(r.readlinkSync(e(n))):void 0}}}static async seedOpfsMetadataSidecarIfMissing(t){let n=`.metadata.json`;try{let r=await t.getFileHandle(n);if(e.isUsableMetadataDocument(await e.readSidecarText(r)))return;console.warn(`[virtual-fs] metadata sidecar is unparseable (torn write?); reseeding an empty index`)}catch(e){if(e?.name!==`NotFoundError`)throw e}let r=await(await t.getFileHandle(n,{create:!0})).createWritable(),i=JSON.stringify({version:1,maxSize:4294967295,entries:{}});await r.write(i),await r.close()}static async readSidecarText(e){let t;for(let n=0;n<3;n++)try{return await(await e.getFile()).text()}catch(e){if(e?.name!==`NotReadableError`)throw e;t=e}throw t}static isUsableMetadataDocument(e){let t;try{t=JSON.parse(e)}catch{return!1}if(!t||typeof t!=`object`)return!1;let n=t.entries;return!!n&&typeof n==`object`}static async acquireOpfsHandle(e,t){let n=navigator.storage;if(!n?.getDirectory)throw new i(`EINVAL`,`OPFS is not available in this environment`);let r=await n.getDirectory();if(t)try{await r.removeEntry(e,{recursive:!0})}catch{}return r.getDirectoryHandle(e,{create:!0})}static _createSyncForTests(t){return new e(t)}static async create(t){let n=t?.dbName??`browser-fs`,r=t?.wipe===!0,i=t?.backend??Q(),a=new e(n,r,i,void 0,t?.onRepairProgress,t?.opfsAsyncCache);try{await a._ready}catch(e){throw a.mountSyncChannel?.close(),e}return r&&await p().catch(()=>{}),a}async flush(){await this.writeOpfsMetadataSidecar()}async writeOpfsMetadataSidecar(){this.backend===`opfs`&&await this.withWriteLock(()=>this.writeOpfsMetadataSidecarUnlocked())}async writeOpfsMetadataSidecarUnlocked(){if(this.backend!==`opfs`)return;let t=this.opfsBackendFs,n=this.opfsHandle;if(!t||!n)return;let r=t.index.toJSON(),i=e.opfsBackends.get(this.dbName)?.sidecarDirty,a=r;if(i){let e=null;try{let t=await n.getFileHandle(`.metadata.json`),r=JSON.parse(await(await t.getFile()).text());r&&typeof r==`object`&&r.entries&&(e=r)}catch{}e&&(await this.auditDirtyKindFlips(r,e,i,n),a=be(e,r,i))}let o=JSON.stringify(z(a)),s=await(await n.getFileHandle(`.metadata.json`,{create:!0})).createWritable();await s.write(o),await s.close(),i&&(i.paths.clear(),i.prefixes.clear())}async auditDirtyKindFlips(e,t,n,r){let i=ve(e,t,n.paths,n.prefixes);if(i.length===0)return;let a=G(r),o=this.opfsBackendFs;for(let n of i){let r=await a(n.path).catch(()=>null);if(r!==null&&r.kind!==`missing`&&r.kind===`directory`===n.ownIsDirectory)continue;let i=t.entries?.[n.path];e.entries&&i!==void 0&&(e.entries[n.path]=i);let s=r!==null&&r.kind!==`missing`;s&&(o?.index?.delete(n.path),o?._handles?.delete(n.path)),console.warn(`[virtual-fs] refused to flush in-memory kind flip over sidecar record (#2006)`,{path:n.path,reality:r?.kind??`unverifiable`,evicted:s})}}markSidecarDirty(t,n=`path`){if(this.backend!==`opfs`)return;let r=e.opfsBackends.get(this.dbName)?.sidecarDirty;if(!r)return;let i=s(t);(n===`prefix`?r.prefixes:r.paths).add(i);let{dir:o}=a(i);for(;o!==`/`;)r.paths.add(o),o=a(o).dir}async forgetSidecarConsistency(){await this.dropSidecarConsistency()}sidecarConsistencyDrop=null;dropSidecarConsistency(){if(this.backend!==`opfs`||!this.opfsHandle)return Promise.resolve();if(!this.sidecarConsistencyDrop){let e=this.opfsHandle;this.sidecarConsistencyDrop=Ee(e).catch(e=>{throw this.sidecarConsistencyDrop=null,e})}return this.sidecarConsistencyDrop}invalidatePaths(e){if(this.backend!==`opfs`||!this.opfsBackendFs)return;e.length>0&&this.dropSidecarConsistency().catch(()=>void 0);let t=this.opfsBackendFs;for(let n of e){let e=s(n);t.index.delete(e),t._handles?.delete(e),this.markSidecarDirty(e)}}async withKindMismatchRetry(e,t){return this.withKindMismatchRetryPaths([e],t)}async withKindMismatchRetryPaths(e,t){try{return await t()}catch(n){let r=n?.code;if(r!==`EISDIR`&&r!==`ENOTDIR`&&r!==`EINVAL`)throw n;for(let n of e)if(await this.reconcileKindMismatch(n).catch(()=>!1))return await t();throw n}}async reconcileKindMismatch(e){if(this.backend!==`opfs`)return!1;let t=this.opfsBackendFs,n=this.opfsHandle;if(!t?.index||!n)return!1;let r=s(e),i=r;try{i=await this.resolveSymlinks(r)}catch{}let a=await G(n)(i),o=A(t.index.get(i)?.mode),c=t._handles?.get(i),l=c?.kind===`directory`?`directory`:c?.kind===`file`?`file`:`absent`,u=j(a,o),d=j(a,l);if(!u&&!d)return!1;if(t.index.delete(i),t._handles?.delete(i),o===`directory`||l===`directory`){let e=`${i}/`;for(let n of[...t.index.keys()])n.startsWith(e)&&t.index.delete(n);if(t._handles)for(let n of[...t._handles.keys()])n.startsWith(e)&&t._handles.delete(n)}return this.markSidecarDirty(i),console.warn(`[virtual-fs] reconciled in-memory kind mismatch (#2006)`,{path:i,reality:a.kind,indexHeld:o,handleHeld:l}),!0}localIdentity(e){return X(`zenfs:${this.backend}:${this.dbName}`,e)}canWrite(e){return!0}setWatcher(e){this.watcher=e}getWatcher(){return this.watcher}async watch(e,t){let n=this.watcher;if(!n)throw new i(`ENOSYS`,`no FsWatcher attached to this VirtualFS`);let r=e.map(e=>n.watch(e,()=>!0,t));return()=>{for(let e of r)e()}}async dispose(){if(this.mountSyncChannel?.close(),this.mountSyncChannel=null,this.watcher?.dispose(),this.watcher=null,this.mountIndex.dispose(),await this.writeOpfsMetadataSidecar(),this.mountRoot){let n=this.backend===`opfs`?e.opfsBackends:e.memoryBackends,r=n.get(this.dbName);if(r&&(--r.refs,r.refs<=0)){n.delete(this.dbName);try{(await t(()=>import(`./dist-b828m-Si.js`),__vite__mapDeps([0,1,2]))).umount(this.mountRoot)}catch{}}}}readDirSync(e){let t=s(e);if(this.findMount(t))return null;let n=this.lfsSync;if(typeof n.readdirSync!=`function`||typeof n.lstatSync!=`function`)return null;try{let e=n.readdirSync(t),r=[];for(let i of e){let e=t===`/`?`/${i}`:`${t}/${i}`;try{let t=n.lstatSync(e),a=t.isSymbolicLink()?`symlink`:t.isDirectory()?`directory`:`file`;r.push(a===`symlink`?{name:i,type:a}:{name:i,type:a,size:t.size,mtime:t.mtimeMs,ctime:t.ctimeMs,...t.ino===void 0?{}:{ino:t.ino,identity:this.localIdentity(t.ino),dev:t.dev},...t.uid===void 0?{}:{uid:t.uid},...t.gid===void 0?{}:{gid:t.gid},mode:t.mode})}catch{}}return r}catch{return null}}statSync(e){let t=s(e);if(this.findMount(t))return null;let n=this.lfsSync;if(typeof n.statSync!=`function`||typeof n.lstatSync!=`function`||typeof n.readlinkSync!=`function`)return null;if(t===`/`)try{let e=n.statSync(t);return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev,mode:e.mode}}catch{return null}let r=t;for(let e=0;e<=10;e++){let e;try{e=n.lstatSync(r)}catch{return null}if(!e.isSymbolicLink())return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev,mode:e.mode};let t;try{t=n.readlinkSync(r)}catch{return null}r=t.startsWith(`/`)?s(t):s(l(a(r).dir,t))}return null}lstatSync(e){let t=s(e);if(this.findMount(t))return null;let n=this.lfsSync;if(typeof n.lstatSync!=`function`)return null;if(t===`/`)return this.statSync(t);try{let e=n.lstatSync(t);if(e.isSymbolicLink()){let r=n.readlinkSync?n.readlinkSync(t):``;return{type:`symlink`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,isSymlink:!0,symlinkTarget:r,ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev,mode:e.mode}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev,mode:e.mode}}catch{return null}}async mount(e,t,n){let r=s(e);if(this.mountPoints.has(r))throw new i(`EEXIST`,`mount point is already mounted`,r);try{if((await this.lstat(r)).type!==`directory`)throw new i(`ENOTDIR`,`mount point must be a directory`,r);if((await this.readDir(r)).length>0)throw new i(`ENOTEMPTY`,`mount point must be empty to avoid shadowing existing files`,r)}catch(e){if(!(e instanceof i)||e.code!==`ENOENT`)throw e}let{dir:o}=a(r);o!==`/`&&await this.mkdir(o,{recursive:!0}),await this.dropSidecarConsistency();try{await this.lfs.mkdir(r)}catch{}if(this.mountPoints.set(r,t),t.kind===`local`){let e=n?.limits??b(n?.env??{});this.mountIndex.registerMount(r,t.getHandle(),e)}let c=Ke(t,r);try{this.mountSyncChannel?.postMessage({type:`mount`,path:r,descriptor:c})}catch{}if(this.watcher?.notify([{type:`modify`,path:r,entryType:`directory`}]),t.kind!==`hostfs`)try{let e={targetPath:r,descriptor:c,createdAt:Date.now()},n=t.kind===`local`?t.getHandle():void 0;await ne(e,n)}catch{}}async unmount(e){let t=s(e),n=this.mountPoints.get(t);this.mountPoints.delete(t),this.mountIndex.unregisterMount(t);try{this.mountSyncChannel?.postMessage({type:`unmount`,path:t})}catch{}this.watcher?.notify([{type:`modify`,path:t,entryType:`directory`}]),await n?.close();try{await re(t)}catch{}}async reconstructBackendFromDescriptor(e,n){switch(e.kind){case`local`:{let t=await ie(e.idbHandleKey);if(!t)throw Error(`no handle stored for ${e.idbHandleKey}`);return P.fromHandle(t,{mountId:e.mountId})}case`hostfs`:{let{HostFsMountBackend:r}=await t(async()=>{let{HostFsMountBackend:e}=await import(`./backend-hostfs-Zq8eFtjc.js`);return{HostFsMountBackend:e}},__vite__mapDeps([4,5,6,7,8]));return new r({targetPath:n,hostPath:e.hostPath,mountId:e.mountId})}case`s3`:{let{S3MountBackend:n,RemoteMountCache:r,makeSignedFetchS3:i}=await t(async()=>{let{S3MountBackend:e,RemoteMountCache:t,makeSignedFetchS3:n}=await import(`./mount-CkCLiqtz.js`);return{S3MountBackend:e,RemoteMountCache:t,makeSignedFetchS3:n}},__vite__mapDeps([9,10,11,12,7,13,1,8])),a=new r({mountId:e.mountId,ttlMs:3e4});return new n({source:e.source,profile:e.profile,cache:a,mountId:e.mountId,signedFetch:i(e.profile)})}case`da`:{let{DaMountBackend:n,RemoteMountCache:r,makeSignedFetchDa:i}=await t(async()=>{let{DaMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}=await import(`./mount-CkCLiqtz.js`);return{DaMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}},__vite__mapDeps([9,10,11,12,7,13,1,8])),a=new r({mountId:e.mountId,ttlMs:3e4});return new n({source:e.source,profile:e.profile,cache:a,mountId:e.mountId,signedFetch:i()})}case`aem`:{let{AemMountBackend:n,RemoteMountCache:r,makeSignedFetchDa:i}=await t(async()=>{let{AemMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}=await import(`./mount-CkCLiqtz.js`);return{AemMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}},__vite__mapDeps([9,10,11,12,7,13,1,8])),a=new r({mountId:e.mountId,ttlMs:3e4});return new n({source:e.source,profile:e.profile,cache:a,mountId:e.mountId,signedFetch:i()})}}}listMounts(){let e=[];for(let t of this.mountPoints.keys())this.internalMounts.has(t)||e.push(t);return e}listInternalMounts(){return[...this.internalMounts]}listMountPoints(){let e=[];for(let[t,n]of this.mountPoints)this.internalMounts.has(t)||e.push({path:t,kind:n.kind});return e}getMountBackend(e){let t=s(e);return this.mountPoints.get(t)??null}async mountInternal(e,t){let n=s(e);if(this.mountPoints.has(n))throw new i(`EEXIST`,`mount point is already mounted`,n);let{dir:r}=a(n);r!==`/`&&await this.mkdir(r,{recursive:!0}),await this.dropSidecarConsistency();try{await this.lfs.mkdir(n)}catch{}this.mountPoints.set(n,t),this.internalMounts.add(n),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}])}async unmountInternal(e){let t=s(e);if(!this.internalMounts.has(t))throw new i(`ENOENT`,`not an internal mount point`,t);let n=this.mountPoints.get(t);this.mountPoints.delete(t),this.internalMounts.delete(t),this.watcher?.notify([{type:`modify`,path:t,entryType:`directory`}]),await n?.close()}getMountIndex(){return this.mountIndex}async refreshMount(e,t){let n=s(e),r=this.mountPoints.get(n);if(!r)throw new i(`ENOENT`,`not a mount point`,n);let a=await r.refresh(t);return r.kind===`local`&&await this.mountIndex.refreshMount(n,b(t?.env??{})),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}]),a}isPathUnderMount(e){for(let t of this.mountPoints.keys())if(e===t||e.startsWith(t+`/`))return!0;return!1}findMount(e){let t=null;for(let[n,r]of this.mountPoints)(e===n||e.startsWith(n+`/`))&&(!t||n.length>t.mountPath.length)&&(t={mountPath:n,backend:r});return t?e===t.mountPath?{path:t.mountPath,backend:t.backend,relParts:[]}:{path:t.mountPath,backend:t.backend,relParts:e.slice(t.mountPath.length+1).split(`/`).filter(Boolean)}:null}async readFile(e,t){return this.withKindMismatchRetry(e,()=>this.readFileInner(e,t))}async readFileInner(e,t){let n=s(e),r=this.findMount(n);if(r){if(r.relParts.length===0)throw new i(`EISDIR`,`is a directory`,n);let e=r.relParts.join(`/`);try{let n=await r.backend.readFile(e);return(t?.encoding??`utf-8`)===`utf-8`?new TextDecoder(`utf-8`).decode(n):n}catch(e){O(e,n)}}let a=await this.resolveSymlinks(n);try{return(t?.encoding??`utf-8`)===`utf-8`?await this.lfs.readFile(a,{encoding:`utf8`}):await this.lfs.readFile(a)}catch(e){throw k(e,n)}}async readFileRange(e,t,n){let r=s(e);if(!Number.isInteger(t)||!Number.isInteger(n)||t<0||n<t)throw new i(`EINVAL`,`invalid byte range ${t}-${n}`,r);if(t===n)return new Uint8Array;let a=this.findMount(r),o=a?.backend.readFileRange;if(a&&o){if(a.relParts.length===0)throw new i(`EISDIR`,`is a directory`,r);try{return await o.call(a.backend,a.relParts.join(`/`),t,n)}catch(e){O(e,r)}}let c=await this.sliceNativeFile(r,t,n);if(c)return c;let l=await this.readFile(r,{encoding:`binary`});return new Uint8Array(l.subarray(t,Math.min(n,l.byteLength)))}async sliceNativeFile(e,t,n){try{let r=await this.getNativeFile(e);if(!r)return null;let i=r.slice(t,Math.min(n,r.size));return new Uint8Array(await i.arrayBuffer())}catch{return null}}async getNativeFile(e){let t=s(e),n=this.findMount(t);if(n){let e=n.backend.getNativeFile;if(!e||n.relParts.length===0)return null;try{return await e.call(n.backend,n.relParts.join(`/`))}catch{return null}}let r=this.opfsHandle;if(!r)return null;try{return await F(r,await this.resolveSymlinks(t))}catch{return null}}async writeFile(e,t,n){return this.withKindMismatchRetry(e,()=>this.writeFileInner(e,t,n))}async writeFileInner(e,t,n){let r=s(e),o=this.findMount(r);if(o){if(o.relParts.length===0)throw new i(`EISDIR`,`is a directory`,r);let e=o.relParts.join(`/`),n=!1;try{await this.stat(r),n=!0}catch{}let a=typeof t==`string`?new TextEncoder().encode(t):t instanceof Uint8Array?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t);try{await o.backend.writeFile(e,a)}catch(e){O(e,r)}this.watcher?.notify([{type:n?`modify`:`create`,path:r,entryType:`file`}]),this.mountIndex.notifyWrite(r);return}let c;try{c=await this.resolveSymlinks(r)}catch{c=r}let l=!1;try{await this.lfs.stat(c),l=!0}catch{}let{dir:u}=a(c);await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),this.markSidecarDirty(c),u!==`/`&&await this.mkdirRecursiveUnlocked(u);let e=typeof t==`string`?new TextEncoder().encode(t).byteLength:(t instanceof Uint8Array,t.byteLength);try{await this.lfs.writeFile(c,t)}catch(e){if(u!==`/`&&e instanceof Error&&e.message.includes(`ENOENT`)){await this.mkdirRecursiveUnlocked(u);try{await this.lfs.writeFile(c,t)}catch(e){throw k(e,r)}}else throw k(e,r)}try{await this.lfs.truncate?.(c,e)}catch(e){throw k(e,r)}}),this.watcher?.notify([{type:l?`modify`:`create`,path:c,entryType:`file`}])}async appendFile(e,t){let n=s(e);await this.withKindMismatchRetry(n,()=>this.withWriteLock(async()=>{if(this.findMount(n)){await this.appendMounted(n,t);return}await this.dropSidecarConsistency();let e=n,r=!1;try{if(e=await this.resolveSymlinks(n),(await this.lfs.stat(e)).isDirectory())throw new i(`EISDIR`,`is a directory`,n);r=!0}catch(e){let t=k(e,n);if(t.code!==`ENOENT`)throw t}this.markSidecarDirty(e);let{dir:o}=a(e);await this.mkdirRecursiveUnlocked(o);try{await this.lfs.appendFile(e,t)}catch(e){throw k(e,n)}this.watcher?.notify([{type:r?`modify`:`create`,path:e,entryType:`file`}])}))}async appendMounted(e,t){let n=new Uint8Array;try{let t=await this.readFileInner(e,{encoding:`binary`});n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t)}catch(t){let n=k(t,e);if(n.code!==`ENOENT`)throw n}let r=typeof t==`string`?new TextEncoder().encode(t):t,i=new Uint8Array(n.length+r.length);i.set(n),i.set(r,n.length),await this.writeFileInner(e,i)}async chmod(e,t){if(!Number.isInteger(t)||t<0||t>4095)throw new i(`EINVAL`,`invalid file mode`,s(e));await this.changeMetadata(e,e=>this.lfs.chmod(e,t))}async utimes(e,t,n){if(!Number.isFinite(t.getTime())||!Number.isFinite(n.getTime()))throw new i(`EINVAL`,`invalid file time`,s(e));await this.changeMetadata(e,e=>this.lfs.utimes(e,t,n))}async changeMetadata(e,t){let n=s(e);if(this.findMount(n))throw await this.stat(n),new i(`ENOSYS`,`metadata changes are not supported by this mount`,n);await this.withKindMismatchRetry(n,()=>this.withWriteLock(async()=>{await this.dropSidecarConsistency();let e=await this.resolveSymlinks(n);try{let n=await this.lfs.stat(e);this.markSidecarDirty(e),await t(e),await this.writeOpfsMetadataSidecarUnlocked(),this.watcher?.notify([{type:`modify`,path:e,entryType:n.isDirectory()?`directory`:`file`}])}catch(e){throw k(e,n)}}))}async readDir(e,t){let n=s(e),r=this.findMount(n);return r?this.readDirMounted(n,r,t):this.readDirLocal(n)}async readDirMounted(e,t,n){let r=n?.includeStats===!0?void 0:this.mountIndex.getDirectoryEntries(t.path,e);if(r!==void 0){let t=new Map;for(let e of r)t.set(e.name,{name:e.name,type:e.type});return this.addNestedMountEntries(t,e),[...t.values()]}let i=t.relParts.join(`/`)||`/`,a;try{a=await t.backend.readDir(i,n)}catch(t){O(t,e)}let o=new Map,s=t.backend.listingStatsMatchStat===!0;for(let e of a)o.set(e.name,Ge(e,s));return this.addNestedMountEntries(o,e),[...o.values()]}async readDirLocal(e){return this.withKindMismatchRetry(e,()=>this.readDirLocalInner(e))}async readDirLocalInner(e){let t=await this.resolveSymlinks(e);try{let e=await this.lfs.readdir(t),n=[];for(let r of e){let e=await this.statDirEntry(t,r);e&&n.push(e)}return n}catch(t){throw k(t,e)}}async statDirEntry(e,t){let n=e===`/`?`/${t}`:`${e}/${t}`;try{let e=await this.lfs.lstat(n);return e.isSymbolicLink()?{name:t,type:`symlink`}:{name:t,type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,...e.ino===void 0?{}:{ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev},...e.uid===void 0?{}:{uid:e.uid},...e.gid===void 0?{}:{gid:e.gid},mode:e.mode}}catch{return null}}addNestedMountEntries(e,t){let n=t===`/`?`/`:`${t}/`;for(let r of this.mountPoints.keys()){if(r===t||!r.startsWith(n))continue;let i=r.slice(n.length);!i||i.includes(`/`)||e.has(i)||e.set(i,{name:i,type:`directory`})}}async withWriteLock(t){let n=this.dbName,r,i=new Promise(e=>{r=e}),a=e.writeChains.get(n)??Promise.resolve();e.writeChains.set(n,i),await a;try{let e=globalThis.navigator?.locks;return this.backend!==`opfs`||typeof e?.request!=`function`?await t():await e.request(`slicc-vfs:${n}`,()=>t())}finally{r(),e.writeChains.get(n)===i&&e.writeChains.delete(n)}}async mkdirRecursiveUnlocked(e){let t=e.split(`/`).filter(Boolean),n=[],r=``;for(let e of t){r+=`/`+e;try{await this.lfs.mkdir(r),n.push(r)}catch(e){if(e instanceof Error&&!e.message.includes(`EEXIST`))throw k(e,r);try{let e=await this.lfs.lstat(r);if(!e.isDirectory()&&!e.isSymbolicLink())throw new i(`ENOTDIR`,`not a directory`,r)}catch(e){if(e instanceof i&&e.code===`ENOTDIR`)throw e}}}return n}async mkdir(e,t){let n=s(e);if(n===`/`)return;let r=this.findMount(n);if(r){if(r.relParts.length===0)return;let e=r.relParts.join(`/`),t=await this.exists(n);try{await r.backend.mkdir(e)}catch(e){O(e,n)}t||this.watcher?.notify([{type:`create`,path:n,entryType:`directory`}]);return}if(t?.recursive){let e=await this.withWriteLock(async()=>(await this.dropSidecarConsistency(),this.markSidecarDirty(n),this.mkdirRecursiveUnlocked(n)));e.length>0&&this.watcher?.notify(e.map(e=>({type:`create`,path:e,entryType:`directory`})))}else await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),this.markSidecarDirty(n);try{await this.lfs.mkdir(n)}catch(e){throw k(e,n)}}),this.watcher?.notify([{type:`create`,path:n,entryType:`directory`}])}async rm(e,t){return this.withKindMismatchRetry(s(e),()=>this.rmInner(e,t))}async rmInner(e,t){let n=s(e),r=this.findMount(n);if(r){if(r.relParts.length===0)throw new i(`EINVAL`,`cannot remove a mount point — use unmount`,n);let e;try{e=(await this.stat(n)).type}catch{}let a=r.relParts.join(`/`);try{await r.backend.remove(a,{recursive:t?.recursive})}catch(e){O(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:e}]),this.mountIndex.notifyDelete(n);return}try{let e=await this.lfs.lstat(n);await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),e.isSymbolicLink()?await this.lfs.unlink(n):e.isDirectory()?t?.recursive?await this.rmRecursiveUnlocked(n):await this.lfs.rmdir(n):await this.lfs.unlink(n),this.markSidecarDirty(n,`prefix`),await this.writeOpfsMetadataSidecarUnlocked()})}catch(e){throw k(e,n)}this.watcher?.notify([{type:`delete`,path:n}])}async rmRecursiveUnlocked(e){let t=await this.lfs.readdir(e);for(let n of t){let t=e===`/`?`/${n}`:`${e}/${n}`,r=await this.lfs.lstat(t);r.isSymbolicLink()?await this.lfs.unlink(t):r.isDirectory()?await this.rmRecursiveUnlocked(t):await this.lfs.unlink(t)}await this.lfs.rmdir(e)}async stat(e){return this.withKindMismatchRetry(e,()=>this.statInner(e))}async statInner(e){let t=s(e),n=this.findMount(t);if(n){if(n.relParts.length===0)try{let e=await this.lfs.stat(t);return{type:`directory`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch{return{type:`directory`,size:0,mtime:Date.now(),ctime:Date.now()}}let e=n.relParts.join(`/`);try{let t=await n.backend.stat(e);return{type:t.kind===`directory`?`directory`:`file`,size:t.size,mtime:t.mtime,ctime:t.ctime??t.mtime,...t.ino===void 0?{}:{ino:t.ino},...t.identity===void 0?{}:{identity:t.identity},...t.dev===void 0?{}:{dev:t.dev},...t.uid===void 0?{}:{uid:t.uid},...t.gid===void 0?{}:{gid:t.gid},...t.mode===void 0?{}:{mode:t.mode}}}catch(e){O(e,t)}}let r=await this.resolveSymlinks(t);try{let e=await this.lfs.stat(r);return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,dev:e.dev,identity:this.localIdentity(e.ino),uid:e.uid,gid:e.gid,mode:e.mode}}catch(e){throw k(e,t)}}async exists(e){let t=s(e),n=this.findMount(t);if(n){if(n.relParts.length===0)return!0;try{return await this.stat(t),!0}catch{return!1}}try{return await this.stat(t),!0}catch{try{return await this.lfs.lstat(t),!0}catch{return!1}}}async rename(e,t){return this.withKindMismatchRetryPaths([s(e),s(t)],()=>this.renameInner(e,t))}async renameInner(e,t){let n=s(e),r=s(t);if(n===r)return;let i;try{i=await this.lstat(n)}catch{}let a=i?.type,o=this.findMount(n);if(o?.backend.rename){let e=this.findMount(r);if(e&&e.backend===o.backend){let t=!1;try{t=(await o.backend.rename(o.relParts.join(`/`),e.relParts.join(`/`)))?.noop===!0}catch(e){O(e,n)}t||(this.watcher?.notify([{type:`delete`,path:n,entryType:a},{type:`create`,path:r,entryType:a}]),this.mountIndex.notifyRename(n,r));return}}if(i)try{let e=await this.lstat(r);if(f(i,e))return}catch{}try{await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),this.markSidecarDirty(n,`prefix`),this.markSidecarDirty(r,`prefix`),await this.lfs.rename(n,r),await this.writeOpfsMetadataSidecarUnlocked()})}catch(e){throw k(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:a},{type:`create`,path:r,entryType:a}]),this.mountIndex.notifyRename(n,r)}async readTextFile(e){return await this.readFile(e,{encoding:`utf-8`})}async*walk(e,t,n=0){yield*u({mountPoints:this.mountPoints,mountIndex:this.mountIndex,realpath:e=>this.realpath(e),readDir:e=>this.readDir(e),stat:e=>this.stat(e)},e,t,n)}async copyFile(e,t){let n=await this.stat(e);if(n.type===`directory`)throw new i(`EISDIR`,`is a directory`,e);try{let e=await this.stat(t);if(f(n,e))return}catch{}let r=await this.readFile(e,{encoding:`binary`});await this.writeFile(t,r)}dirname(e){return a(s(e)).dir}basename(e){return a(s(e)).base}resolveSymlinkTargetPath(e,t){return e.startsWith(`/`)?s(e):s(l(a(t).dir,e))}assertSymlinkCreateAllowed(e,t){if(this.findMount(t))throw new i(`EINVAL`,`symlinks not supported on mounted filesystems`,t);let n=this.resolveSymlinkTargetPath(e,t);if(this.findMount(n))throw new i(`EXDEV`,`cannot create a symlink across a mount boundary to '${n}'`,t)}async symlink(e,t){let n=s(t);this.assertSymlinkCreateAllowed(e,n);let{dir:r}=a(n);await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),r!==`/`&&await this.mkdirRecursiveUnlocked(r);try{await this.lfs.symlink(e,n)}catch(t){if(r!==`/`&&t instanceof Error&&t.message.includes(`ENOENT`)){await this.mkdirRecursiveUnlocked(r);try{await this.lfs.symlink(e,n)}catch(e){throw k(e,n)}}else throw k(t,n)}this.markSidecarDirty(n),await this.writeOpfsMetadataSidecarUnlocked()}),this.watcher?.notify([{type:`create`,path:n,entryType:`symlink`}])}async readlink(e){let t=s(e);try{return await this.lfs.readlink(t)}catch(e){throw k(e,t)}}async lstat(e){let t=s(e);if(this.findMount(t)||t===`/`)return this.stat(t);try{let e=await this.lfs.lstat(t);if(e.isSymbolicLink()){let n=await this.lfs.readlink(t);return{type:`symlink`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,isSymlink:!0,symlinkTarget:n,ino:e.ino,dev:e.dev,identity:this.localIdentity(e.ino),uid:e.uid,gid:e.gid,mode:e.mode}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,dev:e.dev,identity:this.localIdentity(e.ino),uid:e.uid,gid:e.gid,mode:e.mode}}catch(e){throw k(e,t)}}async realpath(e){return Z(this.lfs,e=>this.findMount(e)!==null,e)}resolveSymlinks(e){return We(this.lfs,e=>this.findMount(e)!==null,e)}},qe=e({FsError:()=>i,FsWatcher:()=>h,MountIndex:()=>x,RestrictedFS:()=>D,VirtualFS:()=>$,joinPath:()=>l,normalizePath:()=>s,pathSegments:()=>o,resolveVfsBackendFromEnv:()=>Q,sameFileIdentity:()=>f,splitPath:()=>a,statsFromDirEntry:()=>r});export{i as FsError,h as FsWatcher,x as MountIndex,D as RestrictedFS,$ as VirtualFS,P as a,ze as i,l as joinPath,X as n,s as normalizePath,o as pathSegments,Be as r,Q as resolveVfsBackendFromEnv,f as sameFileIdentity,a as splitPath,r as statsFromDirEntry,qe as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./logger-LESFN7Hj.js";import{a as n,i as r,n as i,r as a,t as o}from"./path-utils-DNJG-zQf.js";import{n as s,t as c}from"./types-D8gIX-W-.js";import{i as l,r as u,t as d}from"./mount-index-CQfmUPuZ.js";import{a as f,i as p,n as m,t as h}from"./mount-table-store-DrF_Ifaz.js";import{n as g,t as _}from"./virtual-device-paths-CS5o4QVz.js";import{t as v}from"./same-file-identity-DuEcSmPX.js";import{a as y,i as b,o as x,r as S}from"./sidecar-repair-BTU4PjlG.js";import{t as C}from"./stat-identity-BaU9yoai.js";function w(e,t,n){return e.size===0||!e.has(n)||!t.isReady(n)?!1:!Array.from(e.keys()).some(e=>e!==n&&e.startsWith(n+`/`))}async function T(e,t){try{return await e(t)}catch{return t}}async function*E(e,t,n,r=0){let a=i(t);if(w(e.mountPoints,e.mountIndex,a)){let t=e.mountIndex.getFiles(a);if(t){for(let e of t)yield e;return}}let o=n??new Set;if(r>64||o.size>=1e5)return;let s=await T(t=>e.realpath(t),a);if(o.has(s))return;o.add(s);let c=await e.readDir(a);for(let t of c)yield*D(e,t,a===`/`?`/${t.name}`:`${a}/${t.name}`,o,r+1)}async function*D(e,t,n,r,i){if(t.type===`file`){yield n;return}if(t.type===`symlink`){yield*O(e,n,r,i);return}yield*E(e,n,r,i)}async function*O(e,t,n,r){try{let i=await e.stat(t);i.type===`file`?yield t:i.type===`directory`&&(yield*E(e,t,n,r))}catch{}}const k=t(`fs-watcher`);let A=0;function ee(e,t){return t===`/`||e===t||e.startsWith(t+`/`)}var j=class{registrations=new Map;watch(e,t,n){let r=`fsw-${++A}`;return this.registrations.set(r,{id:r,basePath:e,filter:t,callback:n}),k.debug(`Watch registered`,{id:r,basePath:e}),()=>{this.registrations.delete(r),k.debug(`Watch unregistered`,{id:r})}}notify(e){if(e.length!==0)for(let[,t]of this.registrations){let n=e.filter(e=>ee(e.path,t.basePath)&&t.filter(e.path));if(n.length>0)try{t.callback(n)}catch(e){k.error(`Watch callback error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}}}dispose(){this.registrations.clear(),k.debug(`All watchers disposed`)}get size(){return this.registrations.size}};const M=new TextEncoder,N=new TextDecoder(`utf-8`,{fatal:!1});var P=class{entries=new Map;static handles(e){return g(i(e))}has(e){return this.entries.has(i(e))}write(e,t){let n=i(e),r=typeof t==`string`?M.encode(t):new Uint8Array(t),a=Date.now(),o=this.entries.get(n);this.entries.set(n,{bytes:r,mtime:a,ctime:o?.ctime??a})}append(e,t){let n=this.entries.get(i(e))?.bytes??new Uint8Array,r=typeof t==`string`?M.encode(t):t,a=new Uint8Array(n.length+r.length);a.set(n),a.set(r,n.length),this.write(e,a)}read(e,t){let n=this.require(e);return(t?.encoding??`utf-8`)===`utf-8`?N.decode(n.bytes):new Uint8Array(n.bytes)}readText(e){return N.decode(this.require(e).bytes)}stat(e){let t=this.require(e);return{type:`file`,size:t.bytes.length,mtime:t.mtime,ctime:t.ctime}}remove(e){return this.entries.delete(i(e))}require(e){let t=i(e),n=this.entries.get(t);if(!n)throw new c(`ENOENT`,`no such file or directory`,t);return n}};const F={[_]:{stat:()=>({type:`file`,size:0,mtime:0,ctime:0}),read:e=>(e?.encoding??`utf-8`)===`utf-8`?``:new Uint8Array,readText:()=>``,write:()=>{}}},I=[`/tmp/`];var L=class{ephemeralFds=new P;vfs;allowedPrefixes;readOnlyPrefixes;readGrantPatterns=[];writeEnforcement;includeMounts;constructor(e,t,n=[],r=`hard`,a={}){this.vfs=e;let o=e=>{let t=i(e);return t.endsWith(`/`)?t:t+`/`};this.allowedPrefixes=t.map(o),this.readOnlyPrefixes=n.map(o),this.writeEnforcement=r,this.includeMounts=a.includeMounts!==!1}getAllPrefixes(){let e=this.includeMounts?this.vfs.listMounts().map(e=>e.endsWith(`/`)?e:e+`/`):[];return[...this.allowedPrefixes,...this.readOnlyPrefixes,...e,...I]}setReadGrants(e){this.readGrantPatterns=[];for(let t of new Set(e))this.addReadGrant(t)}addReadGrant(e){let t=e.split(`/`),n=[];for(let e=1;e<t.length;e++)n.push(a(t.slice(0,e).join(`/`)||`/`));this.readGrantPatterns.push({pattern:e,regex:a(e),ancestorRegexes:n})}matchesReadGrant(e){return this.readGrantPatterns.some(t=>t.regex.test(e))}leadsToReadGrant(e){return this.readGrantPatterns.some(t=>t.ancestorRegexes.some(t=>t.test(e)))}isAllowed(e){let t=i(e),n=this.getAllPrefixes();return this.matchesReadGrant(t)||this.leadsToReadGrant(t)||n.some(e=>t===e.slice(0,-1)||t.startsWith(e)||t===`/`||e.startsWith(t+`/`))}isAllowedStrict(e){let t=i(e),n=this.getAllPrefixes();return this.matchesReadGrant(t)||n.some(e=>t===e.slice(0,-1)||t.startsWith(e))}isWritable(e){let t=i(e);return[...this.allowedPrefixes,...I].some(e=>t===e.slice(0,-1)||t.startsWith(e))}canWrite(e){return P.handles(e)||this.isWritable(e)}checkWrite(e){if(this.writeEnforcement!==`sudo-delegated`&&!this.isWritable(e))throw new c(`EACCES`,`permission denied`,i(e))}async resolveAndCheckRead(e){try{let t=await this.vfs.realpath(e);if(!this.isAllowedStrict(t))throw new c(`ENOENT`,`no such file or directory`,i(e));return t}catch(t){throw t instanceof c?t:new c(`ENOENT`,`no such file or directory`,i(e))}}async resolveAndCheckWrite(e){try{let t=await this.vfs.realpath(e);if(!this.isWritable(t)&&!this.isSymlinkEscapeAllowed(t))throw new c(`EACCES`,`permission denied`,i(e));return t}catch(t){throw t instanceof c?t:new c(`EACCES`,`permission denied`,i(e))}}isSymlinkEscapeAllowed(e){return!1}async checkParentRealpathEscape(e){let t=this.vfs.dirname(e),n=this.vfs.basename(e),r;try{r=await this.vfs.realpath(t)}catch(e){if(e instanceof c&&e.code===`EACCES`)throw e;return}let a=r+`/`+n;if(this.isWritable(a))return;let o=i(r)!==i(t);if(!(this.writeEnforcement===`sudo-delegated`&&!o))throw new c(`EACCES`,`permission denied`,i(e))}getUnderlyingFS(){return this.vfs}invalidatePaths(e){this.vfs.invalidatePaths(e)}async forgetSidecarConsistency(){await this.vfs.forgetSidecarConsistency()}async flush(){await this.vfs.flush()}isPathUnderMount(e){return this.vfs.isPathUnderMount(e)}async readFile(e,t){let n=F[i(e)];if(n)return n.read(t);if(P.handles(e))return this.ephemeralFds.read(e,t);if(!this.isAllowedStrict(e))throw new c(`ENOENT`,`no such file or directory`,i(e));let r=await this.resolveAndCheckRead(e);return this.vfs.readFile(r,t)}async readFileRange(e,t,n){if(!this.isAllowedStrict(e))throw new c(`ENOENT`,`no such file or directory`,i(e));let r=await this.resolveAndCheckRead(e);return this.vfs.readFileRange(r,t,n)}async getNativeFile(e){if(F[i(e)]||P.handles(e)||!this.isAllowedStrict(e))return null;try{let t=await this.resolveAndCheckRead(e);return await this.vfs.getNativeFile(t)}catch{return null}}async readDir(e,t){if(!this.isAllowed(e))return[];let n=e;if(this.isAllowedStrict(e))try{n=await this.resolveAndCheckRead(e)}catch{return[]}let r=await this.vfs.readDir(n,t);if(!this.isAllowedStrict(e)){let t=i(e);return r.filter(e=>{let n=t===`/`?`/${e.name}`:`${t}/${e.name}`;return this.isAllowed(n)})}return r}async stat(e){let t=F[i(e)];if(t)return t.stat();if(P.handles(e))return this.ephemeralFds.stat(e);if(!this.isAllowed(e))throw new c(`ENOENT`,`no such file or directory`,i(e));if(this.isAllowedStrict(e)){let t=await this.resolveAndCheckRead(e);return this.vfs.stat(t)}return this.vfs.stat(e)}scanPathForSymlinks(e,t){let n=i(e);if(n===`/`)return!1;let r=n.slice(1).split(`/`),a=t?r.length:r.length-1,o=``;for(let e=0;e<a;e++){o=o+`/`+r[e];let t=this.vfs.lstatSync(o);if(t===null)return null;if(t.type===`symlink`)return!0}return!1}statSync(e){let t=F[i(e)];return t?t.stat():P.handles(e)?this.ephemeralFds.has(e)?this.ephemeralFds.stat(e):null:!this.isAllowedStrict(e)||this.scanPathForSymlinks(e,!0)!==!1?null:this.vfs.statSync(e)}lstatSync(e){let t=F[i(e)];return t?t.stat():P.handles(e)?this.ephemeralFds.has(e)?this.ephemeralFds.stat(e):null:!this.isAllowed(e)||this.scanPathForSymlinks(e,!1)!==!1?null:this.vfs.lstatSync(e)}readDirSync(e){if(!this.isAllowed(e)||this.scanPathForSymlinks(e,!0)!==!1)return null;let t=this.vfs.readDirSync(e);if(t===null)return null;if(this.isAllowedStrict(e))return t;let n=i(e);return t.filter(e=>{let t=n===`/`?`/${e.name}`:`${n}/${e.name}`;return this.isAllowed(t)})}async realpath(e){if(P.handles(e)){let t=i(e);if(!this.ephemeralFds.has(t))throw new c(`ENOENT`,`no such file or directory`,t);return t}let t;try{t=await this.vfs.realpath(e)}catch(t){throw t instanceof c?t:new c(`ENOENT`,`no such file or directory`,i(e))}if(!this.isAllowedStrict(t))throw new c(`ENOENT`,`no such file or directory`,i(e));return t}async exists(e){if(F[i(e)])return!0;if(P.handles(e))return this.ephemeralFds.has(e);if(!this.isAllowed(e))return!1;if(this.isAllowedStrict(e))try{await this.resolveAndCheckRead(e)}catch{return!1}return this.vfs.exists(e)}async readTextFile(e){let t=F[i(e)];if(t)return t.readText();if(P.handles(e))return this.ephemeralFds.readText(e);if(!this.isAllowedStrict(e))throw new c(`ENOENT`,`no such file or directory`,i(e));let n=await this.resolveAndCheckRead(e);return this.vfs.readTextFile(n)}async*walk(e){if(!this.isAllowed(e))return;let t=e;if(this.isAllowedStrict(e))try{t=await this.resolveAndCheckRead(e)}catch{return}for await(let e of this.vfs.walk(t))this.isAllowed(e)&&(yield e)}async writeFile(e,t,n){let r=F[i(e)];if(r){r.write(t);return}if(P.handles(e)){this.ephemeralFds.write(e,t);return}return await this.checkContentWrite(e),this.vfs.writeFile(e,t,n)}async appendFile(e,t){let n=F[i(e)];if(n){n.write(t);return}if(P.handles(e)){this.ephemeralFds.append(e,t);return}return await this.checkContentWrite(e),this.vfs.appendFile(e,t)}async chmod(e,t){return this.refuseDescriptorTreeOp(e),await this.checkContentWrite(e),this.vfs.chmod(e,t)}async utimes(e,t,n){return this.refuseDescriptorTreeOp(e),await this.checkContentWrite(e),this.vfs.utimes(e,t,n)}async checkContentWrite(e){this.checkWrite(e),await this.checkParentRealpathEscape(e);try{(await this.vfs.lstat(e)).type===`symlink`&&await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof c&&e.code===`EACCES`)throw e}}refuseDescriptorTreeOp(e){if(P.handles(e))throw new c(`EACCES`,`permission denied`,i(e))}async mkdir(e,t){return this.refuseDescriptorTreeOp(e),this.checkWrite(e),await this.checkParentRealpathEscape(e),this.vfs.mkdir(e,t)}async rm(e,t){if(P.handles(e)){if(!this.ephemeralFds.remove(e))throw new c(`ENOENT`,`no such file or directory`,i(e));return}this.checkWrite(e);try{(await this.vfs.lstat(e)).type===`symlink`||await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof c&&e.code===`EACCES`)throw e}return this.vfs.rm(e,t)}async rename(e,t){return this.refuseDescriptorTreeOp(e),this.refuseDescriptorTreeOp(t),this.checkWrite(e),this.checkWrite(t),await this.resolveAndCheckWrite(e),await this.checkParentRealpathEscape(t),this.vfs.rename(e,t)}async copyFile(e,t){if(P.handles(e)){let n=this.ephemeralFds.read(e,{encoding:`binary`});await this.writeFile(t,n);return}if(P.handles(t)){if(!this.isAllowed(e))throw new c(`ENOENT`,`no such file or directory`,i(e));let n=await this.resolveAndCheckRead(e);this.ephemeralFds.write(t,await this.vfs.readFile(n,{encoding:`binary`}));return}if(!this.isAllowed(e))throw new c(`ENOENT`,`no such file or directory`,i(e));this.checkWrite(t);let n=await this.resolveAndCheckRead(e);await this.checkParentRealpathEscape(t);try{(await this.vfs.lstat(t)).type===`symlink`&&await this.resolveAndCheckWrite(t)}catch(e){if(e instanceof c&&e.code===`EACCES`)throw e}return this.vfs.copyFile(n,t)}async symlink(e,t){return this.refuseDescriptorTreeOp(t),this.checkWrite(t),await this.checkParentRealpathEscape(t),this.vfs.symlink(e,t)}async readlink(e){if(!this.isAllowedStrict(e))throw new c(`ENOENT`,`no such file or directory`,i(e));let t=await this.vfs.readlink(e),n;if(t.startsWith(`/`))n=i(t);else{let r=this.vfs.dirname(e);n=i(r+`/`+t)}if(!this.isAllowedStrict(n))throw new c(`ENOENT`,`no such file or directory`,i(e));return t}async lstat(e){let t=F[i(e)];if(t)return t.stat();if(P.handles(e))return this.ephemeralFds.stat(e);if(!this.isAllowed(e))throw new c(`ENOENT`,`no such file or directory`,i(e));let n=i(e),r=this.vfs.dirname(n),a=this.vfs.basename(n),o;if(r===n)o=r;else try{o=await this.vfs.realpath(r)}catch{throw new c(`ENOENT`,`no such file or directory`,n)}let s=o===`/`?`/${a}`:`${o}/${a}`;if(!this.isAllowed(s))throw new c(`ENOENT`,`no such file or directory`,n);return this.vfs.lstat(s)}watch(e,t,n){if(!this.isAllowed(e))throw new c(`EACCES`,`permission denied`,i(e));let r=this.vfs.getWatcher();if(!r)throw new c(`EINVAL`,`no watcher configured`);return r.watch(i(e),t,n)}dirname(e){return this.vfs.dirname(e)}basename(e){return this.vfs.basename(e)}async mount(e,t,n){return this.refuseDescriptorTreeOp(e),this.checkWrite(e),await this.checkParentRealpathEscape(e),this.vfs.mount(e,t,n)}async unmount(e){return this.refuseDescriptorTreeOp(e),this.checkWrite(e),await this.checkParentRealpathEscape(e),this.vfs.unmount(e)}listMounts(){let e=this.vfs.listMounts();return this.includeMounts?e:e.filter(e=>this.isAllowedStrict(e))}getMountIndex(){return this.vfs.getMountIndex()}async refreshMount(e,t){return this.refuseDescriptorTreeOp(e),this.checkWrite(e),this.vfs.refreshMount(e,t)}async dispose(){await this.vfs.dispose()}};function R(e,t){if(e instanceof c){let n=`${e.code}: `,r=e.message;throw r.startsWith(n)&&(r=r.slice(n.length)),e.path&&r.endsWith(` '${e.path}'`)&&(r=r.slice(0,r.length-` '${e.path}'`.length)),new c(e.code,r,t)}throw e}const z=[`ENOENT`,`EEXIST`,`ENOTDIR`,`EISDIR`,`ENOTEMPTY`,`EINVAL`,`EACCES`,`ELOOP`,`EBUSY`,`EFBIG`,`EBADF`,`ENOSYS`,`EOPNOTSUPP`,`EXDEV`,`EIO`];function B(e,t){if(e instanceof c)return e;{let n=e instanceof Error?e.message:String(e);if(n.includes(`maximum size exceeded`)||n.includes(`call stack size exceeded`))return new c(`EIO`,`internal overflow, not storage: ${n} — reload the session`,t)}let n=e?.code;if(typeof n==`string`){let r=n;if(z.includes(r)){let n=e instanceof Error?e.message:String(e);return n.startsWith(`${r}: `)&&(n=n.slice(r.length+2),n=n.replace(/, undefined( '[^']*')?$/,``).replace(/ '[^']*'$/,``)),new c(r,n||r,t)}}let r=e instanceof Error?e.message:String(e);return r.includes(`ENOENT`)?new c(`ENOENT`,`no such file or directory`,t):r.includes(`EEXIST`)?new c(`EEXIST`,`file already exists`,t):r.includes(`ENOTDIR`)?new c(`ENOTDIR`,`not a directory`,t):r.includes(`EISDIR`)?new c(`EISDIR`,`is a directory`,t):r.includes(`ENOTEMPTY`)?new c(`ENOTEMPTY`,`directory not empty`,t):r.includes(`ELOOP`)?new c(`ELOOP`,`too many levels of symbolic links`,t):r.includes(`EOPNOTSUPP`)||r.includes(`ENOTSUP`)?new c(`EOPNOTSUPP`,`operation not supported`,t):r.includes(`EXDEV`)?new c(`EXDEV`,`cross-device link`,t):new c(`EINVAL`,r,t)}function V(e){return e===void 0?`absent`:(e&61440)==16384?`directory`:`file`}function H(e,t){return t===`absent`?!1:e.kind===`missing`||e.kind!==t}function U(e){let t=e?.mode;return typeof t==`number`?t:void 0}function W(e,t,n,r=new Set){let i=new Set(n);if(r.size>0){for(let t of Object.keys(e.entries??{}))for(let e of r)if(t===e||t.startsWith(`${e}/`)){i.add(t);break}}let a=[];for(let n of i){let r=e.entries?.[n],i=t.entries?.[n];if(!r||!i)continue;let o=V(U(r));o!==V(U(i))&&a.push({path:n,ownIsDirectory:o===`directory`})}return a}async function G(e,t){let n=t.split(`/`).filter(Boolean),r=n.pop();if(r===void 0)return null;try{let t=e;for(let e of n)t=await t.getDirectoryHandle(e);return await(await t.getFileHandle(r)).getFile()}catch{return null}}async function K(e,t,n,r){try{return await e.lstat(t)}catch(e){let t=B(e,r);if(t.code===`ENOENT`&&n)return null;throw t}}async function q(e,t,r){let a;try{a=await e.readlink(t)}catch(e){throw B(e,r)}return a.startsWith(`/`)?i(a):i(o(n(t).dir,a))}async function J(e,t,n,r,i,a){let o=t===`/`?`/${n}`:`${t}/${n}`;for(;;){let t=await K(e,o,r,i);if(t===null||!t.isSymbolicLink())return{resolved:o,hops:a};if(++a>10)throw new c(`ELOOP`,`too many symbolic links encountered`,i);o=await q(e,o,i)}}async function Y(e,t,n){let r=i(n);if(t(r))return r;let a=r.split(`/`).filter(Boolean),o=`/`,s=0;for(let t=0;t<a.length;t++){let n=await J(e,o,a[t],t===a.length-1,r,s);o=n.resolved,s=n.hops}return o}async function X(e,t,n){return t(n)?n:Y(e,t,n)}function Z(){try{if(typeof globalThis.navigator?.storage?.getDirectory==`function`)return`opfs`}catch{}return`memory`}function Q(e,t){let n=e.kind===`directory`?`directory`:`file`;return t?{name:e.name,type:n,...e.size===void 0?{}:{size:e.size},...e.lastModified===void 0?{}:{mtime:e.lastModified},...e.ctime===void 0?{}:{ctime:e.ctime},...e.ino===void 0?{}:{ino:e.ino},...e.identity===void 0?{}:{identity:e.identity},...e.dev===void 0?{}:{dev:e.dev},...e.uid===void 0?{}:{uid:e.uid},...e.gid===void 0?{}:{gid:e.gid},...e.mode===void 0?{}:{mode:e.mode}}:{name:e.name,type:n}}function te(e,t){switch(e.kind){case`local`:case`proc`:return{kind:`local`,mountId:e.mountId,idbHandleKey:t};case`hostfs`:return{kind:`hostfs`,mountId:e.mountId,hostPath:e.getHostPath()};default:return{kind:e.kind===`s3`?`s3`:e.kind===`aem`?`aem`:`da`,mountId:e.mountId,source:e.source,profile:e.profile??`default`}}}var $=class e{lfs;lfsSync;rawLfs=null;rawLfsSync=null;_ready;_readyResolved=!1;backend;mountPoints=new Map;opfsBackendFs=null;opfsHandle=null;mountRoot=``;internalMounts=new Set;watcher=null;dbName;mountSyncChannel=null;mountIndex=new d;static writeChains=new Map;onRepairProgress;constructor(t,n,r,i,a,o){if(this.dbName=t,this.onRepairProgress=a,this.backend=r===`opfs`?`opfs`:`memory`,this.lfs=this.makeDeferredLfs(),this.lfsSync=this.makeDeferredLfsSync(),this._ready=this.backend===`opfs`?e.initOpfsBackend(this,i,n===!0,o):e.initMemoryBackend(this,t,n===!0),this._ready.then(()=>{this._readyResolved=!0},()=>{}),typeof BroadcastChannel<`u`)try{this.mountSyncChannel=new BroadcastChannel(`vfs-mount-sync:${t}`),this.mountSyncChannel.onmessage=e=>{let{type:t,path:n,descriptor:r}=e.data??{};if(t===`mount`&&typeof n==`string`&&r)this.reconstructBackendFromDescriptor(r,n).then(e=>{this.mountPoints.set(n,e),e.kind===`local`&&this.mountIndex.registerMount(n,e.getHandle()),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}])}).catch(()=>{});else if(t===`unmount`&&typeof n==`string`){let e=this.mountPoints.get(n);this.mountPoints.delete(n),this.mountIndex.unregisterMount(n),e?.close(),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}])}}}catch{}}static opfsInitChains=new Map;static async initOpfsBackend(t,n,r,i){let a=(e.opfsInitChains.get(t.dbName)??Promise.resolve()).catch(()=>{}).then(()=>e.resolveOpfsBackend(t,n,r,i));e.opfsInitChains.set(t.dbName,a);try{await a}finally{e.opfsInitChains.get(t.dbName)===a&&e.opfsInitChains.delete(t.dbName)}}static async resolveOpfsBackend(t,n,r,i){let a=e.opfsBackends.get(t.dbName);if(a&&r)throw new c(`EBUSY`,`Cannot wipe an OPFS backend with live holders`,t.dbName);if(a&&i!==void 0&&a.asyncCache!==i)throw new c(`EBUSY`,`OPFS async cache setting conflicts with the live backend`,t.dbName);let o=n??await e.acquireOpfsHandle(t.dbName,r);await t.withWriteLock(()=>e.seedOpfsMetadataSidecarIfMissing(o));let s=await import(`./dist-TdFroLO3.js`);await e.ensureRootMount(s);let l=`/__opfs__/${t.dbName}`,u=e.opfsBackends.get(t.dbName);if(!u){let{resolveOpfsMount:n}=await import(`./opfs-mount-DF49ioKQ.js`),r=await n({handle:o,dbName:t.dbName,asyncCache:i,onRepairProgress:t.onRepairProgress,withWriteLock:e=>t.withWriteLock(e)});try{s.mount(l,r)}catch{}u={backendFs:r,refs:0,asyncCache:i!==!1,sidecarDirty:{paths:new Set,prefixes:new Set}},e.opfsBackends.set(t.dbName,u)}u.refs+=1,t.opfsBackendFs=u.backendFs.index?u.backendFs:null,t.opfsHandle=o,t.mountRoot=l,t.rawLfs=s.promises,t.rawLfsSync=s}static async initMemoryBackend(t,n,r){let i=await import(`./dist-TdFroLO3.js`);await e.ensureRootMount(i);let a=`/__zenfs__/${n}`,o=e.memoryBackends.get(n);if(o&&r){try{i.umount(a)}catch{}e.memoryBackends.delete(n),o=void 0}o||(o={store:i.InMemory.create({label:n}),refs:0},e.memoryBackends.set(n,o)),o.refs+=1;try{i.mount(a,o.store)}catch{}t.mountRoot=a,t.rawLfs=i.promises,t.rawLfsSync=i,t.opfsBackendFs=null,t.opfsHandle=null}static rootMountReady=null;static memoryBackends=new Map;static opfsBackends=new Map;static async ensureRootMount(t){return e.rootMountReady===null&&(e.rootMountReady=(async()=>{await t.configureSingle({backend:t.InMemory,label:`__vfs_root__`})})()),e.rootMountReady}prefix(e){return this.mountRoot?e===`/`?this.mountRoot:this.mountRoot+e:e}unprefix(e){return!this.mountRoot||!e.startsWith(this.mountRoot)?e:e.slice(this.mountRoot.length)||`/`}makeDeferredLfs(){let e=e=>this.prefix(e),t=e=>this.unprefix(e),n=()=>{if(!this.rawLfs)throw Error(`VirtualFS used before init resolved`);return this.rawLfs};return{readFile:(t,r)=>this._readyResolved?n().readFile(e(t),r):this._ready.then(()=>n().readFile(e(t),r)),writeFile:(t,r,i)=>this._readyResolved?n().writeFile(e(t),r,i):this._ready.then(()=>n().writeFile(e(t),r,i)),appendFile:async(t,r)=>{this._readyResolved||await this._ready,await n().appendFile(e(t),r)},chmod:async(t,r)=>{this._readyResolved||await this._ready,await n().chmod(e(t),r)},utimes:async(t,r,i)=>{this._readyResolved||await this._ready,await n().utimes(e(t),r,i)},readdir:t=>this._readyResolved?n().readdir(e(t)):this._ready.then(()=>n().readdir(e(t))),mkdir:(t,r)=>this._readyResolved?n().mkdir(e(t),r):this._ready.then(()=>n().mkdir(e(t),r)),rmdir:t=>this._readyResolved?n().rmdir(e(t)):this._ready.then(()=>n().rmdir(e(t))),unlink:t=>this._readyResolved?n().unlink(e(t)):this._ready.then(()=>n().unlink(e(t))),rename:(t,r)=>this._readyResolved?n().rename(e(t),e(r)):this._ready.then(()=>n().rename(e(t),e(r))),stat:t=>this._readyResolved?n().stat(e(t)):this._ready.then(()=>n().stat(e(t))),lstat:t=>this._readyResolved?n().lstat(e(t)):this._ready.then(()=>n().lstat(e(t))),symlink:(t,r)=>{let i=t.startsWith(`/`)?e(t):t;return this._readyResolved?n().symlink(i,e(r)):this._ready.then(()=>n().symlink(i,e(r)))},readlink:async r=>(this._readyResolved||await this._ready,t(await n().readlink(e(r)))),truncate:async(t,r)=>{this._readyResolved||await this._ready;let i=n();typeof i.truncate==`function`&&await i.truncate(e(t),r)},realpath:async r=>{this._readyResolved||await this._ready;let i=n();return typeof i.realpath==`function`?t(await i.realpath(e(r))):e(r)}}}makeDeferredLfsSync(){let e=e=>this.prefix(e),t=e=>this.unprefix(e);return{readdirSync:t=>{let n=this.rawLfsSync;return n?.readdirSync?n.readdirSync(e(t)):void 0},statSync:t=>{let n=this.rawLfsSync;return n?.statSync?n.statSync(e(t)):void 0},lstatSync:t=>{let n=this.rawLfsSync;return n?.lstatSync?n.lstatSync(e(t)):void 0},readlinkSync:n=>{let r=this.rawLfsSync;return r?.readlinkSync?t(r.readlinkSync(e(n))):void 0}}}static async seedOpfsMetadataSidecarIfMissing(t){let n=`.metadata.json`;try{let r=await t.getFileHandle(n);if(e.isUsableMetadataDocument(await e.readSidecarText(r)))return;console.warn(`[virtual-fs] metadata sidecar is unparseable (torn write?); reseeding an empty index`)}catch(e){if(e?.name!==`NotFoundError`)throw e}let r=await(await t.getFileHandle(n,{create:!0})).createWritable(),i=JSON.stringify({version:1,maxSize:4294967295,entries:{}});await r.write(i),await r.close()}static async readSidecarText(e){let t;for(let n=0;n<3;n++)try{return await(await e.getFile()).text()}catch(e){if(e?.name!==`NotReadableError`)throw e;t=e}throw t}static isUsableMetadataDocument(e){let t;try{t=JSON.parse(e)}catch{return!1}if(!t||typeof t!=`object`)return!1;let n=t.entries;return!!n&&typeof n==`object`}static async acquireOpfsHandle(e,t){let n=navigator.storage;if(!n?.getDirectory)throw new c(`EINVAL`,`OPFS is not available in this environment`);let r=await n.getDirectory();if(t)try{await r.removeEntry(e,{recursive:!0})}catch{}return r.getDirectoryHandle(e,{create:!0})}static _createSyncForTests(t){return new e(t)}static async create(t){let n=t?.dbName??`browser-fs`,r=t?.wipe===!0,i=t?.backend??Z(),a=new e(n,r,i,void 0,t?.onRepairProgress,t?.opfsAsyncCache);try{await a._ready}catch(e){throw a.mountSyncChannel?.close(),e}return r&&await h().catch(()=>{}),a}async flush(){await this.writeOpfsMetadataSidecar()}async writeOpfsMetadataSidecar(){this.backend===`opfs`&&await this.withWriteLock(()=>this.writeOpfsMetadataSidecarUnlocked())}async writeOpfsMetadataSidecarUnlocked(){if(this.backend!==`opfs`)return;let t=this.opfsBackendFs,n=this.opfsHandle;if(!t||!n)return;let r=t.index.toJSON(),i=e.opfsBackends.get(this.dbName)?.sidecarDirty,a=r;if(i){let e=null;try{let t=await n.getFileHandle(`.metadata.json`),r=JSON.parse(await(await t.getFile()).text());r&&typeof r==`object`&&r.entries&&(e=r)}catch{}e&&(await this.auditDirtyKindFlips(r,e,i,n),a=y(e,r,i))}let o=JSON.stringify(x(a)),s=await(await n.getFileHandle(`.metadata.json`,{create:!0})).createWritable();await s.write(o),await s.close(),i&&(i.paths.clear(),i.prefixes.clear())}async auditDirtyKindFlips(e,t,n,r){let i=W(e,t,n.paths,n.prefixes);if(i.length===0)return;let a=b(r),o=this.opfsBackendFs;for(let n of i){let r=await a(n.path).catch(()=>null);if(r!==null&&r.kind!==`missing`&&r.kind===`directory`===n.ownIsDirectory)continue;let i=t.entries?.[n.path];e.entries&&i!==void 0&&(e.entries[n.path]=i);let s=r!==null&&r.kind!==`missing`;s&&(o?.index?.delete(n.path),o?._handles?.delete(n.path)),console.warn(`[virtual-fs] refused to flush in-memory kind flip over sidecar record (#2006)`,{path:n.path,reality:r?.kind??`unverifiable`,evicted:s})}}markSidecarDirty(t,r=`path`){if(this.backend!==`opfs`)return;let a=e.opfsBackends.get(this.dbName)?.sidecarDirty;if(!a)return;let o=i(t);(r===`prefix`?a.prefixes:a.paths).add(o);let{dir:s}=n(o);for(;s!==`/`;)a.paths.add(s),s=n(s).dir}async forgetSidecarConsistency(){await this.dropSidecarConsistency()}sidecarConsistencyDrop=null;dropSidecarConsistency(){if(this.backend!==`opfs`||!this.opfsHandle)return Promise.resolve();if(!this.sidecarConsistencyDrop){let e=this.opfsHandle;this.sidecarConsistencyDrop=S(e).catch(e=>{throw this.sidecarConsistencyDrop=null,e})}return this.sidecarConsistencyDrop}invalidatePaths(e){if(this.backend!==`opfs`||!this.opfsBackendFs)return;e.length>0&&this.dropSidecarConsistency().catch(()=>void 0);let t=this.opfsBackendFs;for(let n of e){let e=i(n);t.index.delete(e),t._handles?.delete(e),this.markSidecarDirty(e)}}async withKindMismatchRetry(e,t){return this.withKindMismatchRetryPaths([e],t)}async withKindMismatchRetryPaths(e,t){try{return await t()}catch(n){let r=n?.code;if(r!==`EISDIR`&&r!==`ENOTDIR`&&r!==`EINVAL`)throw n;for(let n of e)if(await this.reconcileKindMismatch(n).catch(()=>!1))return await t();throw n}}async reconcileKindMismatch(e){if(this.backend!==`opfs`)return!1;let t=this.opfsBackendFs,n=this.opfsHandle;if(!t?.index||!n)return!1;let r=i(e),a=r;try{a=await this.resolveSymlinks(r)}catch{}let o=await b(n)(a),s=V(t.index.get(a)?.mode),c=t._handles?.get(a),l=c?.kind===`directory`?`directory`:c?.kind===`file`?`file`:`absent`,u=H(o,s),d=H(o,l);if(!u&&!d)return!1;if(t.index.delete(a),t._handles?.delete(a),s===`directory`||l===`directory`){let e=`${a}/`;for(let n of[...t.index.keys()])n.startsWith(e)&&t.index.delete(n);if(t._handles)for(let n of[...t._handles.keys()])n.startsWith(e)&&t._handles.delete(n)}return this.markSidecarDirty(a),console.warn(`[virtual-fs] reconciled in-memory kind mismatch (#2006)`,{path:a,reality:o.kind,indexHeld:s,handleHeld:l}),!0}localIdentity(e){return C(`zenfs:${this.backend}:${this.dbName}`,e)}canWrite(e){return!0}setWatcher(e){this.watcher=e}getWatcher(){return this.watcher}async watch(e,t){let n=this.watcher;if(!n)throw new c(`ENOSYS`,`no FsWatcher attached to this VirtualFS`);let r=e.map(e=>n.watch(e,()=>!0,t));return()=>{for(let e of r)e()}}async dispose(){if(this.mountSyncChannel?.close(),this.mountSyncChannel=null,this.watcher?.dispose(),this.watcher=null,this.mountIndex.dispose(),await this.writeOpfsMetadataSidecar(),this.mountRoot){let t=this.backend===`opfs`?e.opfsBackends:e.memoryBackends,n=t.get(this.dbName);if(n&&(--n.refs,n.refs<=0)){t.delete(this.dbName);try{(await import(`./dist-TdFroLO3.js`)).umount(this.mountRoot)}catch{}}}}readDirSync(e){let t=i(e);if(this.findMount(t))return null;let n=this.lfsSync;if(typeof n.readdirSync!=`function`||typeof n.lstatSync!=`function`)return null;try{let e=n.readdirSync(t),r=[];for(let i of e){let e=t===`/`?`/${i}`:`${t}/${i}`;try{let t=n.lstatSync(e),a=t.isSymbolicLink()?`symlink`:t.isDirectory()?`directory`:`file`;r.push(a===`symlink`?{name:i,type:a}:{name:i,type:a,size:t.size,mtime:t.mtimeMs,ctime:t.ctimeMs,...t.ino===void 0?{}:{ino:t.ino,identity:this.localIdentity(t.ino),dev:t.dev},...t.uid===void 0?{}:{uid:t.uid},...t.gid===void 0?{}:{gid:t.gid},mode:t.mode})}catch{}}return r}catch{return null}}statSync(e){let t=i(e);if(this.findMount(t))return null;let r=this.lfsSync;if(typeof r.statSync!=`function`||typeof r.lstatSync!=`function`||typeof r.readlinkSync!=`function`)return null;if(t===`/`)try{let e=r.statSync(t);return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev,mode:e.mode}}catch{return null}let a=t;for(let e=0;e<=10;e++){let e;try{e=r.lstatSync(a)}catch{return null}if(!e.isSymbolicLink())return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev,mode:e.mode};let t;try{t=r.readlinkSync(a)}catch{return null}a=t.startsWith(`/`)?i(t):i(o(n(a).dir,t))}return null}lstatSync(e){let t=i(e);if(this.findMount(t))return null;let n=this.lfsSync;if(typeof n.lstatSync!=`function`)return null;if(t===`/`)return this.statSync(t);try{let e=n.lstatSync(t);if(e.isSymbolicLink()){let r=n.readlinkSync?n.readlinkSync(t):``;return{type:`symlink`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,isSymlink:!0,symlinkTarget:r,ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev,mode:e.mode}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev,mode:e.mode}}catch{return null}}async mount(e,t,r){let a=i(e);if(this.mountPoints.has(a))throw new c(`EEXIST`,`mount point is already mounted`,a);try{if((await this.lstat(a)).type!==`directory`)throw new c(`ENOTDIR`,`mount point must be a directory`,a);if((await this.readDir(a)).length>0)throw new c(`ENOTEMPTY`,`mount point must be empty to avoid shadowing existing files`,a)}catch(e){if(!(e instanceof c)||e.code!==`ENOENT`)throw e}let{dir:o}=n(a);o!==`/`&&await this.mkdir(o,{recursive:!0}),await this.dropSidecarConsistency();try{await this.lfs.mkdir(a)}catch{}if(this.mountPoints.set(a,t),t.kind===`local`){let e=r?.limits??u(r?.env??{});this.mountIndex.registerMount(a,t.getHandle(),e)}let s=te(t,a);try{this.mountSyncChannel?.postMessage({type:`mount`,path:a,descriptor:s})}catch{}if(this.watcher?.notify([{type:`modify`,path:a,entryType:`directory`}]),t.kind!==`hostfs`)try{let e={targetPath:a,descriptor:s,createdAt:Date.now()},n=t.kind===`local`?t.getHandle():void 0;await f(e,n)}catch{}}async unmount(e){let t=i(e),n=this.mountPoints.get(t);this.mountPoints.delete(t),this.mountIndex.unregisterMount(t);try{this.mountSyncChannel?.postMessage({type:`unmount`,path:t})}catch{}this.watcher?.notify([{type:`modify`,path:t,entryType:`directory`}]),await n?.close();try{await p(t)}catch{}}async reconstructBackendFromDescriptor(e,t){switch(e.kind){case`local`:{let t=await m(e.idbHandleKey);if(!t)throw Error(`no handle stored for ${e.idbHandleKey}`);return l.fromHandle(t,{mountId:e.mountId})}case`hostfs`:{let{HostFsMountBackend:n}=await import(`./backend-hostfs-CMj5JyW-.js`);return new n({targetPath:t,hostPath:e.hostPath,mountId:e.mountId})}case`s3`:{let{S3MountBackend:t,RemoteMountCache:n,makeSignedFetchS3:r}=await import(`./mount-zxJpqjfc.js`).then(e=>e.t),i=new n({mountId:e.mountId,ttlMs:3e4});return new t({source:e.source,profile:e.profile,cache:i,mountId:e.mountId,signedFetch:r(e.profile)})}case`da`:{let{DaMountBackend:t,RemoteMountCache:n,makeSignedFetchDa:r}=await import(`./mount-zxJpqjfc.js`).then(e=>e.t),i=new n({mountId:e.mountId,ttlMs:3e4});return new t({source:e.source,profile:e.profile,cache:i,mountId:e.mountId,signedFetch:r()})}case`aem`:{let{AemMountBackend:t,RemoteMountCache:n,makeSignedFetchDa:r}=await import(`./mount-zxJpqjfc.js`).then(e=>e.t),i=new n({mountId:e.mountId,ttlMs:3e4});return new t({source:e.source,profile:e.profile,cache:i,mountId:e.mountId,signedFetch:r()})}}}listMounts(){let e=[];for(let t of this.mountPoints.keys())this.internalMounts.has(t)||e.push(t);return e}listInternalMounts(){return[...this.internalMounts]}listMountPoints(){let e=[];for(let[t,n]of this.mountPoints)this.internalMounts.has(t)||e.push({path:t,kind:n.kind});return e}getMountBackend(e){let t=i(e);return this.mountPoints.get(t)??null}async mountInternal(e,t){let r=i(e);if(this.mountPoints.has(r))throw new c(`EEXIST`,`mount point is already mounted`,r);let{dir:a}=n(r);a!==`/`&&await this.mkdir(a,{recursive:!0}),await this.dropSidecarConsistency();try{await this.lfs.mkdir(r)}catch{}this.mountPoints.set(r,t),this.internalMounts.add(r),this.watcher?.notify([{type:`modify`,path:r,entryType:`directory`}])}async unmountInternal(e){let t=i(e);if(!this.internalMounts.has(t))throw new c(`ENOENT`,`not an internal mount point`,t);let n=this.mountPoints.get(t);this.mountPoints.delete(t),this.internalMounts.delete(t),this.watcher?.notify([{type:`modify`,path:t,entryType:`directory`}]),await n?.close()}getMountIndex(){return this.mountIndex}async refreshMount(e,t){let n=i(e),r=this.mountPoints.get(n);if(!r)throw new c(`ENOENT`,`not a mount point`,n);let a=await r.refresh(t);return r.kind===`local`&&await this.mountIndex.refreshMount(n,u(t?.env??{})),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}]),a}isPathUnderMount(e){for(let t of this.mountPoints.keys())if(e===t||e.startsWith(t+`/`))return!0;return!1}findMount(e){let t=null;for(let[n,r]of this.mountPoints)(e===n||e.startsWith(n+`/`))&&(!t||n.length>t.mountPath.length)&&(t={mountPath:n,backend:r});return t?e===t.mountPath?{path:t.mountPath,backend:t.backend,relParts:[]}:{path:t.mountPath,backend:t.backend,relParts:e.slice(t.mountPath.length+1).split(`/`).filter(Boolean)}:null}async readFile(e,t){return this.withKindMismatchRetry(e,()=>this.readFileInner(e,t))}async readFileInner(e,t){let n=i(e),r=this.findMount(n);if(r){if(r.relParts.length===0)throw new c(`EISDIR`,`is a directory`,n);let e=r.relParts.join(`/`);try{let n=await r.backend.readFile(e);return(t?.encoding??`utf-8`)===`utf-8`?new TextDecoder(`utf-8`).decode(n):n}catch(e){R(e,n)}}let a=await this.resolveSymlinks(n);try{return(t?.encoding??`utf-8`)===`utf-8`?await this.lfs.readFile(a,{encoding:`utf8`}):await this.lfs.readFile(a)}catch(e){throw B(e,n)}}async readFileRange(e,t,n){let r=i(e);if(!Number.isInteger(t)||!Number.isInteger(n)||t<0||n<t)throw new c(`EINVAL`,`invalid byte range ${t}-${n}`,r);if(t===n)return new Uint8Array;let a=this.findMount(r),o=a?.backend.readFileRange;if(a&&o){if(a.relParts.length===0)throw new c(`EISDIR`,`is a directory`,r);try{return await o.call(a.backend,a.relParts.join(`/`),t,n)}catch(e){R(e,r)}}let s=await this.sliceNativeFile(r,t,n);if(s)return s;let l=await this.readFile(r,{encoding:`binary`});return new Uint8Array(l.subarray(t,Math.min(n,l.byteLength)))}async sliceNativeFile(e,t,n){try{let r=await this.getNativeFile(e);if(!r)return null;let i=r.slice(t,Math.min(n,r.size));return new Uint8Array(await i.arrayBuffer())}catch{return null}}async getNativeFile(e){let t=i(e),n=this.findMount(t);if(n){let e=n.backend.getNativeFile;if(!e||n.relParts.length===0)return null;try{return await e.call(n.backend,n.relParts.join(`/`))}catch{return null}}let r=this.opfsHandle;if(!r)return null;try{return await G(r,await this.resolveSymlinks(t))}catch{return null}}async writeFile(e,t,n){return this.withKindMismatchRetry(e,()=>this.writeFileInner(e,t,n))}async writeFileInner(e,t,r){let a=i(e),o=this.findMount(a);if(o){if(o.relParts.length===0)throw new c(`EISDIR`,`is a directory`,a);let e=o.relParts.join(`/`),n=!1;try{await this.stat(a),n=!0}catch{}let r=typeof t==`string`?new TextEncoder().encode(t):t instanceof Uint8Array?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t);try{await o.backend.writeFile(e,r)}catch(e){R(e,a)}this.watcher?.notify([{type:n?`modify`:`create`,path:a,entryType:`file`}]),this.mountIndex.notifyWrite(a);return}let s;try{s=await this.resolveSymlinks(a)}catch{s=a}let l=!1;try{await this.lfs.stat(s),l=!0}catch{}let{dir:u}=n(s);await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),this.markSidecarDirty(s),u!==`/`&&await this.mkdirRecursiveUnlocked(u);let e=typeof t==`string`?new TextEncoder().encode(t).byteLength:(t instanceof Uint8Array,t.byteLength);try{await this.lfs.writeFile(s,t)}catch(e){if(u!==`/`&&e instanceof Error&&e.message.includes(`ENOENT`)){await this.mkdirRecursiveUnlocked(u);try{await this.lfs.writeFile(s,t)}catch(e){throw B(e,a)}}else throw B(e,a)}try{await this.lfs.truncate?.(s,e)}catch(e){throw B(e,a)}}),this.watcher?.notify([{type:l?`modify`:`create`,path:s,entryType:`file`}])}async appendFile(e,t){let r=i(e);await this.withKindMismatchRetry(r,()=>this.withWriteLock(async()=>{if(this.findMount(r)){await this.appendMounted(r,t);return}await this.dropSidecarConsistency();let e=r,i=!1;try{if(e=await this.resolveSymlinks(r),(await this.lfs.stat(e)).isDirectory())throw new c(`EISDIR`,`is a directory`,r);i=!0}catch(e){let t=B(e,r);if(t.code!==`ENOENT`)throw t}this.markSidecarDirty(e);let{dir:a}=n(e);await this.mkdirRecursiveUnlocked(a);try{await this.lfs.appendFile(e,t)}catch(e){throw B(e,r)}this.watcher?.notify([{type:i?`modify`:`create`,path:e,entryType:`file`}])}))}async appendMounted(e,t){let n=new Uint8Array;try{let t=await this.readFileInner(e,{encoding:`binary`});n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t)}catch(t){let n=B(t,e);if(n.code!==`ENOENT`)throw n}let r=typeof t==`string`?new TextEncoder().encode(t):t,i=new Uint8Array(n.length+r.length);i.set(n),i.set(r,n.length),await this.writeFileInner(e,i)}async chmod(e,t){if(!Number.isInteger(t)||t<0||t>4095)throw new c(`EINVAL`,`invalid file mode`,i(e));await this.changeMetadata(e,e=>this.lfs.chmod(e,t))}async utimes(e,t,n){if(!Number.isFinite(t.getTime())||!Number.isFinite(n.getTime()))throw new c(`EINVAL`,`invalid file time`,i(e));await this.changeMetadata(e,e=>this.lfs.utimes(e,t,n))}async changeMetadata(e,t){let n=i(e);if(this.findMount(n))throw await this.stat(n),new c(`ENOSYS`,`metadata changes are not supported by this mount`,n);await this.withKindMismatchRetry(n,()=>this.withWriteLock(async()=>{await this.dropSidecarConsistency();let e=await this.resolveSymlinks(n);try{let n=await this.lfs.stat(e);this.markSidecarDirty(e),await t(e),await this.writeOpfsMetadataSidecarUnlocked(),this.watcher?.notify([{type:`modify`,path:e,entryType:n.isDirectory()?`directory`:`file`}])}catch(e){throw B(e,n)}}))}async readDir(e,t){let n=i(e),r=this.findMount(n);return r?this.readDirMounted(n,r,t):this.readDirLocal(n)}async readDirMounted(e,t,n){let r=n?.includeStats===!0?void 0:this.mountIndex.getDirectoryEntries(t.path,e);if(r!==void 0){let t=new Map;for(let e of r)t.set(e.name,{name:e.name,type:e.type});return this.addNestedMountEntries(t,e),[...t.values()]}let i=t.relParts.join(`/`)||`/`,a;try{a=await t.backend.readDir(i,n)}catch(t){R(t,e)}let o=new Map,s=t.backend.listingStatsMatchStat===!0;for(let e of a)o.set(e.name,Q(e,s));return this.addNestedMountEntries(o,e),[...o.values()]}async readDirLocal(e){return this.withKindMismatchRetry(e,()=>this.readDirLocalInner(e))}async readDirLocalInner(e){let t=await this.resolveSymlinks(e);try{let e=await this.lfs.readdir(t),n=[];for(let r of e){let e=await this.statDirEntry(t,r);e&&n.push(e)}return n}catch(t){throw B(t,e)}}async statDirEntry(e,t){let n=e===`/`?`/${t}`:`${e}/${t}`;try{let e=await this.lfs.lstat(n);return e.isSymbolicLink()?{name:t,type:`symlink`}:{name:t,type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,...e.ino===void 0?{}:{ino:e.ino,identity:this.localIdentity(e.ino),dev:e.dev},...e.uid===void 0?{}:{uid:e.uid},...e.gid===void 0?{}:{gid:e.gid},mode:e.mode}}catch{return null}}addNestedMountEntries(e,t){let n=t===`/`?`/`:`${t}/`;for(let r of this.mountPoints.keys()){if(r===t||!r.startsWith(n))continue;let i=r.slice(n.length);!i||i.includes(`/`)||e.has(i)||e.set(i,{name:i,type:`directory`})}}async withWriteLock(t){let n=this.dbName,r,i=new Promise(e=>{r=e}),a=e.writeChains.get(n)??Promise.resolve();e.writeChains.set(n,i),await a;try{let e=globalThis.navigator?.locks;return this.backend!==`opfs`||typeof e?.request!=`function`?await t():await e.request(`slicc-vfs:${n}`,()=>t())}finally{r(),e.writeChains.get(n)===i&&e.writeChains.delete(n)}}async mkdirRecursiveUnlocked(e){let t=e.split(`/`).filter(Boolean),n=[],r=``;for(let e of t){r+=`/`+e;try{await this.lfs.mkdir(r),n.push(r)}catch(e){if(e instanceof Error&&!e.message.includes(`EEXIST`))throw B(e,r);try{let e=await this.lfs.lstat(r);if(!e.isDirectory()&&!e.isSymbolicLink())throw new c(`ENOTDIR`,`not a directory`,r)}catch(e){if(e instanceof c&&e.code===`ENOTDIR`)throw e}}}return n}async mkdir(e,t){let n=i(e);if(n===`/`)return;let r=this.findMount(n);if(r){if(r.relParts.length===0)return;let e=r.relParts.join(`/`),t=await this.exists(n);try{await r.backend.mkdir(e)}catch(e){R(e,n)}t||this.watcher?.notify([{type:`create`,path:n,entryType:`directory`}]);return}if(t?.recursive){let e=await this.withWriteLock(async()=>(await this.dropSidecarConsistency(),this.markSidecarDirty(n),this.mkdirRecursiveUnlocked(n)));e.length>0&&this.watcher?.notify(e.map(e=>({type:`create`,path:e,entryType:`directory`})))}else await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),this.markSidecarDirty(n);try{await this.lfs.mkdir(n)}catch(e){throw B(e,n)}}),this.watcher?.notify([{type:`create`,path:n,entryType:`directory`}])}async rm(e,t){return this.withKindMismatchRetry(i(e),()=>this.rmInner(e,t))}async rmInner(e,t){let n=i(e),r=this.findMount(n);if(r){if(r.relParts.length===0)throw new c(`EINVAL`,`cannot remove a mount point — use unmount`,n);let e;try{e=(await this.stat(n)).type}catch{}let i=r.relParts.join(`/`);try{await r.backend.remove(i,{recursive:t?.recursive})}catch(e){R(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:e}]),this.mountIndex.notifyDelete(n);return}try{let e=await this.lfs.lstat(n);await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),e.isSymbolicLink()?await this.lfs.unlink(n):e.isDirectory()?t?.recursive?await this.rmRecursiveUnlocked(n):await this.lfs.rmdir(n):await this.lfs.unlink(n),this.markSidecarDirty(n,`prefix`),await this.writeOpfsMetadataSidecarUnlocked()})}catch(e){throw B(e,n)}this.watcher?.notify([{type:`delete`,path:n}])}async rmRecursiveUnlocked(e){let t=await this.lfs.readdir(e);for(let n of t){let t=e===`/`?`/${n}`:`${e}/${n}`,r=await this.lfs.lstat(t);r.isSymbolicLink()?await this.lfs.unlink(t):r.isDirectory()?await this.rmRecursiveUnlocked(t):await this.lfs.unlink(t)}await this.lfs.rmdir(e)}async stat(e){return this.withKindMismatchRetry(e,()=>this.statInner(e))}async statInner(e){let t=i(e),n=this.findMount(t);if(n){if(n.relParts.length===0)try{let e=await this.lfs.stat(t);return{type:`directory`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch{return{type:`directory`,size:0,mtime:Date.now(),ctime:Date.now()}}let e=n.relParts.join(`/`);try{let t=await n.backend.stat(e);return{type:t.kind===`directory`?`directory`:`file`,size:t.size,mtime:t.mtime,ctime:t.ctime??t.mtime,...t.ino===void 0?{}:{ino:t.ino},...t.identity===void 0?{}:{identity:t.identity},...t.dev===void 0?{}:{dev:t.dev},...t.uid===void 0?{}:{uid:t.uid},...t.gid===void 0?{}:{gid:t.gid},...t.mode===void 0?{}:{mode:t.mode}}}catch(e){R(e,t)}}let r=await this.resolveSymlinks(t);try{let e=await this.lfs.stat(r);return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,dev:e.dev,identity:this.localIdentity(e.ino),uid:e.uid,gid:e.gid,mode:e.mode}}catch(e){throw B(e,t)}}async exists(e){let t=i(e),n=this.findMount(t);if(n){if(n.relParts.length===0)return!0;try{return await this.stat(t),!0}catch{return!1}}try{return await this.stat(t),!0}catch{try{return await this.lfs.lstat(t),!0}catch{return!1}}}async rename(e,t){return this.withKindMismatchRetryPaths([i(e),i(t)],()=>this.renameInner(e,t))}async renameInner(e,t){let n=i(e),r=i(t);if(n===r)return;let a;try{a=await this.lstat(n)}catch{}let o=a?.type,s=this.findMount(n);if(s?.backend.rename){let e=this.findMount(r);if(e&&e.backend===s.backend){let t=!1;try{t=(await s.backend.rename(s.relParts.join(`/`),e.relParts.join(`/`)))?.noop===!0}catch(e){R(e,n)}t||(this.watcher?.notify([{type:`delete`,path:n,entryType:o},{type:`create`,path:r,entryType:o}]),this.mountIndex.notifyRename(n,r));return}}if(a)try{let e=await this.lstat(r);if(v(a,e))return}catch{}try{await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),this.markSidecarDirty(n,`prefix`),this.markSidecarDirty(r,`prefix`),await this.lfs.rename(n,r),await this.writeOpfsMetadataSidecarUnlocked()})}catch(e){throw B(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:o},{type:`create`,path:r,entryType:o}]),this.mountIndex.notifyRename(n,r)}async readTextFile(e){return await this.readFile(e,{encoding:`utf-8`})}async*walk(e,t,n=0){yield*E({mountPoints:this.mountPoints,mountIndex:this.mountIndex,realpath:e=>this.realpath(e),readDir:e=>this.readDir(e),stat:e=>this.stat(e)},e,t,n)}async copyFile(e,t){let n=await this.stat(e);if(n.type===`directory`)throw new c(`EISDIR`,`is a directory`,e);try{let e=await this.stat(t);if(v(n,e))return}catch{}let r=await this.readFile(e,{encoding:`binary`});await this.writeFile(t,r)}dirname(e){return n(i(e)).dir}basename(e){return n(i(e)).base}resolveSymlinkTargetPath(e,t){return e.startsWith(`/`)?i(e):i(o(n(t).dir,e))}assertSymlinkCreateAllowed(e,t){if(this.findMount(t))throw new c(`EINVAL`,`symlinks not supported on mounted filesystems`,t);let n=this.resolveSymlinkTargetPath(e,t);if(this.findMount(n))throw new c(`EXDEV`,`cannot create a symlink across a mount boundary to '${n}'`,t)}async symlink(e,t){let r=i(t);this.assertSymlinkCreateAllowed(e,r);let{dir:a}=n(r);await this.withWriteLock(async()=>{await this.dropSidecarConsistency(),a!==`/`&&await this.mkdirRecursiveUnlocked(a);try{await this.lfs.symlink(e,r)}catch(t){if(a!==`/`&&t instanceof Error&&t.message.includes(`ENOENT`)){await this.mkdirRecursiveUnlocked(a);try{await this.lfs.symlink(e,r)}catch(e){throw B(e,r)}}else throw B(t,r)}this.markSidecarDirty(r),await this.writeOpfsMetadataSidecarUnlocked()}),this.watcher?.notify([{type:`create`,path:r,entryType:`symlink`}])}async readlink(e){let t=i(e);try{return await this.lfs.readlink(t)}catch(e){throw B(e,t)}}async lstat(e){let t=i(e);if(this.findMount(t)||t===`/`)return this.stat(t);try{let e=await this.lfs.lstat(t);if(e.isSymbolicLink()){let n=await this.lfs.readlink(t);return{type:`symlink`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,isSymlink:!0,symlinkTarget:n,ino:e.ino,dev:e.dev,identity:this.localIdentity(e.ino),uid:e.uid,gid:e.gid,mode:e.mode}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino,dev:e.dev,identity:this.localIdentity(e.ino),uid:e.uid,gid:e.gid,mode:e.mode}}catch(e){throw B(e,t)}}async realpath(e){return Y(this.lfs,e=>this.findMount(e)!==null,e)}resolveSymlinks(e){return X(this.lfs,e=>this.findMount(e)!==null,e)}},ne=e({FsError:()=>c,FsWatcher:()=>j,MountIndex:()=>d,RestrictedFS:()=>L,VirtualFS:()=>$,joinPath:()=>o,normalizePath:()=>i,pathSegments:()=>r,resolveVfsBackendFromEnv:()=>Z,sameFileIdentity:()=>v,splitPath:()=>n,statsFromDirEntry:()=>s});export{j as i,$ as n,L as r,ne as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e,r as t}from"./account-store-CQ9VWuvY.js";import{a as n}from"./diagnostics-DN_idNHx.js";import{a as r,n as i,r as a}from"./compat-uEPf6-XW.js";import{a as o,c as s,i as c,r as l,s as u,t as d}from"./legacy-api-aliases-jKEvBgOL.js";import"./provider-settings-C5-R4CAK.js";function f(e){if(!e||typeof e!=`object`)return null;let t=e.quota_snapshots?.premium_interactions;return!t||t.unlimited||typeof t.percent_remaining!=`number`?null:{percent:Math.max(0,100-t.percent_remaining),status:t.percent_remaining<=0&&t.overage_permitted!==!0?`rate-limited`:`ok`,window:`monthly`,resetsAt:e.quota_reset_date_utc}}async function p(e,t,n={}){let r=typeof AbortController==`function`?new AbortController:null,i=r?setTimeout(()=>r.abort(),n.timeoutMs??8e3):null;try{let i=await t(`https://api.github.com/copilot_internal/user`,{headers:{...n.headers,Authorization:`Bearer ${e}`},...r?{signal:r.signal}:{}});if(i.status===404||i.status===501)return null;if(!i.ok)throw Error(`GitHub Copilot /copilot_internal/user returned ${i.status}`);return f(await i.json())}finally{i&&clearTimeout(i)}}const m=`github-copilot`,h=atob(`SXYxLmI1MDdhMDhjODdlY2ZlOTg=`),g={Accept:`application/json`,"Editor-Version":`vscode/1.107.0`,"Editor-Plugin-Version":`copilot-chat/0.35.0`,"Copilot-Integration-Id":`vscode-chat`},_={Accept:`application/json`,"Content-Type":`application/x-www-form-urlencoded`};function v(){return t().find(e=>e.providerId===m)}async function y(){let e=await fetch(`https://github.com/login/device/code`,{method:`POST`,headers:_,body:new URLSearchParams({client_id:h,scope:`read:user`})});if(!e.ok)throw Error(`GitHub device-code request failed: ${e.status} ${e.statusText} — ${await e.text().catch(()=>``)}`);let t=await e.json();if(typeof t.device_code!=`string`||typeof t.user_code!=`string`||typeof t.verification_uri!=`string`||typeof t.expires_in!=`number`||typeof t.interval!=`number`)throw Error(`GitHub device-code response had an unexpected shape`);return t}async function b(e,t){let n=Date.now()+e.expires_in*1e3,r=Math.max(1e3,Math.floor(e.interval*1e3)),i=1.2;for(;Date.now()<n;){if(t.aborted)throw Error(`Copilot login cancelled`);await x(Math.ceil(r*i),t);let n=await fetch(`https://github.com/login/oauth/access_token`,{method:`POST`,headers:_,body:new URLSearchParams({client_id:h,device_code:e.device_code,grant_type:`urn:ietf:params:oauth:grant-type:device_code`})});if(!n.ok)throw Error(`GitHub token poll failed: ${n.status} ${n.statusText} — ${await n.text().catch(()=>``)}`);let a=await n.json();if(typeof a.access_token==`string`&&a.access_token.length>0)return a.access_token;if(a.error!==`authorization_pending`){if(a.error===`slow_down`){r=typeof a.interval==`number`?a.interval*1e3:r+5e3,i=1.4;continue}if(a.error){let e=a.error_description?`: ${a.error_description}`:``;throw Error(`Device flow failed (${a.error})${e}`)}}}throw Error(`Copilot device flow timed out (device code expired)`)}function x(e,t){return new Promise((n,r)=>{if(t.aborted){r(Error(`Copilot login cancelled`));return}let i=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(i),r(Error(`Copilot login cancelled`))},{once:!0})})}function S(e){let t=e.match(/proxy-ep=([^;]+)/);return t?`https://${t[1].replace(/^proxy\./,`api.`)}`:null}async function C(e){let t=await fetch(`https://api.github.com/copilot_internal/v2/token`,{headers:{...g,Authorization:`Bearer ${e}`}});if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`Copilot token exchange failed: ${t.status} ${t.statusText} — ${e.slice(0,300)}`)}let n=await t.json();if(typeof n.token!=`string`||typeof n.expires_at!=`number`)throw Error(`Copilot token exchange returned an unexpected payload`);if(n.chat_enabled===!1)throw Error(`GitHub Copilot Chat is disabled for this account (no chat features granted)`);return{copilotToken:n.token,expiresAtMs:n.expires_at*1e3-3e5,apiBaseUrl:S(n.token)??`https://api.individual.githubcopilot.com`,githubAccessToken:e}}const w=`github-copilot.models.v1`;function T(e){let t=e.supported_endpoints??[],n=(e.vendor??``).toLowerCase(),r=e.id;return n===`anthropic`&&t.includes(`/v1/messages`)?`anthropic-messages`:n===`openai`&&(/^gpt-5/i.test(r)||/codex/i.test(r)||/^o\d/i.test(r))?`openai-responses`:`openai-completions`}function E(e){if(!e||typeof e!=`object`)return[];let t=e.data;if(!Array.isArray(t))return[];let n=[];for(let e of t)e.capabilities?.type&&e.capabilities.type!==`chat`||e.model_picker_enabled!==!1&&e.id&&n.push({id:e.id,name:e.name??e.id,vendor:e.vendor??``,api:T(e),contextWindow:e.capabilities?.limits?.max_context_window_tokens??e.capabilities?.limits?.max_prompt_tokens??128e3,maxTokens:e.capabilities?.limits?.max_output_tokens??8192,supportsTools:e.capabilities?.supports?.tool_calls===!0,supportsStreaming:e.capabilities?.supports?.streaming!==!1,supportsVision:e.capabilities?.supports?.vision===!0,supportsReasoning:e.capabilities?.supports?.adaptive_thinking===!0||Array.isArray(e.capabilities?.supports?.reasoning_effort),policyState:e.policy?.state??`enabled`});return n}async function D(e){let t=await fetch(`${e.apiBaseUrl}/models`,{headers:{...g,Authorization:`Bearer ${e.copilotToken}`,Accept:`application/json`}});if(!t.ok)throw Error(`Copilot /models returned ${t.status} ${t.statusText}`);return E(await t.json())}function O(){if(typeof localStorage>`u`)return[];try{let e=localStorage.getItem(w);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function k(e){if(!(typeof localStorage>`u`))try{localStorage.setItem(w,JSON.stringify(e))}catch{}}function A(e){return O().find(t=>t.id===e)??null}async function j(e){let t;try{t=await D(e)}catch(e){console.warn(`[github-copilot] Catalog refresh failed; keeping previous cache.`,e instanceof Error?e.message:String(e));return}k(t),await Promise.all(t.filter(e=>e.policyState===`disabled`).map(async t=>{let n=`${e.apiBaseUrl}/models/${encodeURIComponent(t.id)}/policy`;try{let r=await fetch(n,{method:`POST`,headers:{...g,"Content-Type":`application/json`,Authorization:`Bearer ${e.copilotToken}`,"openai-intent":`chat-policy`,"x-interaction-type":`chat-policy`},body:JSON.stringify({state:`enabled`})});r.ok?t.policyState=`enabled`:r.status!==404&&r.status!==400&&console.warn(`[github-copilot] enable policy for ${t.id} returned ${r.status} ${r.statusText}`)}catch(e){console.warn(`[github-copilot] enable policy for ${t.id} failed:`,e instanceof Error?e.message:String(e))}})),k(t)}async function M(t,n){await e({providerId:m,accessToken:t.copilotToken,refreshToken:t.githubAccessToken,tokenExpiresAt:t.expiresAtMs,baseUrl:t.apiBaseUrl,userName:n})}async function N(){let e=v();if(!e?.accessToken||!e.refreshToken)throw Error(`Not logged in to GitHub Copilot — click "Login" in the provider settings`);let t=e.tokenExpiresAt??0;if(Date.now()<t-6e4)return e.accessToken;let n=await C(e.refreshToken);return await M(n,e.userName),n.copilotToken}const P=[`mini`,`nano`,`flash`,`haiku`,`lite`,`embedding`];function F(e){let t=[e.id,e.name??``].flatMap(e=>{let t=e.toLowerCase();return[t,t.replace(/[\s_.:]+/g,`-`)]});return!P.some(e=>t.some(t=>t.includes(e)))}function I(){if(!v()?.accessToken)return[];let e=O();if(e.length>0)return e.filter(e=>!e.policyState.startsWith(`unavailable:`)).filter(e=>F(e)).map(e=>({id:e.id,name:e.name,api:e.api===`anthropic-messages`?`anthropic`:`openai`,context_window:e.contextWindow,max_tokens:e.maxTokens,reasoning:e.supportsReasoning,input:e.supportsVision?[`text`,`image`]:[`text`]}));let t;try{t=a(`github-copilot`)}catch{return[]}return t.filter(e=>F({id:e.id,name:e.name})).map(e=>({id:e.id,name:e.name??e.id,api:e.api===`anthropic-messages`?`anthropic`:`openai`,context_window:e.contextWindow,max_tokens:e.maxTokens,reasoning:e.reasoning,input:e.input}))}function L(e,t){return{type:`error`,reason:`error`,error:{role:`assistant`,content:[],api:e.api,provider:m,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`error`,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()}}}const R={"User-Agent":`GitHubCopilotChat/0.35.0`,"Editor-Version":`vscode/1.107.0`,"Editor-Plugin-Version":`copilot-chat/0.35.0`,"Copilot-Integration-Id":`vscode-chat`};function z(e){let t=v(),n=t?.baseUrl??`https://api.individual.githubcopilot.com`,r=A(e);if(r)return{api:r.api,baseUrl:n,headers:{...R}};try{let n=i(`github-copilot`,e);return{api:n.api,baseUrl:t?.baseUrl??n.baseUrl,headers:{...n.headers??{},...R}}}catch{return null}}function B(e,t){let n=O(),r=n.findIndex(t=>t.id===e);r<0||(n[r]={...n[r],policyState:`unavailable:${t}`},k(n))}function V(e,t){return`GitHub Copilot rejected "${e}" with model_not_supported. This usually means the model isn't included in your Copilot plan (Opus and other premium models require Copilot Pro / Pro+ / Business / Enterprise). Try Claude Sonnet 4.6 or another model that appears in the picker after a fresh login. Original error: ${t}`}function H(e){if(!e||typeof e!=`object`)return null;let t=e;if(t.type!==`error`)return null;if(t.error&&typeof t.error==`object`){let e=t.error.errorMessage;if(typeof e==`string`)return e}return typeof t.errorMessage==`string`?t.errorMessage:null}function U(e,t){return e===`anthropic-messages`?t?o:d:e===`openai-responses`?t?s:c:t?u:l}function W(e,t,n){let r=H(n);if(r&&/model_not_supported/i.test(r)){B(t.id,`model_not_supported`);let n=V(t.id,r);return console.error(`[github-copilot] Plan-gated model rejection:`,n),e.push(L(t,Error(n))),e.end(),!0}return e.push(n),!1}function G(e,t,n){let r=n instanceof Error?n.message:String(n),i=n;/model_not_supported/i.test(r)&&(B(t.id,`model_not_supported`),i=Error(V(t.id,r))),console.error(`[github-copilot] Stream error:`,i instanceof Error?i.message:String(i)),e.push(L(t,i)),e.end()}async function K(e,t,n,r,i){try{let a=await N(),o=z(t.id);if(!o)throw Error(`GitHub Copilot does not recognize "${t.id}" — open the picker (the model list refreshes on login) and pick a current model.`);let s={...t,api:o.api,baseUrl:o.baseUrl,headers:o.headers,provider:`github-copilot`},c={...r,apiKey:a},l=U(o.api,i)(s,n,c);for await(let n of l)if(W(e,t,n))return;e.end()}catch(n){G(e,t,n)}}function q(e){return(t,r,i={})=>{let a=n();return K(a,t,r,i,e),a}}const J=q(!1),Y=q(!0),X=({userCode:e,verificationUrl:t})=>typeof document>`u`?(console.info(`[github-copilot] Device verification code: ${e} — open ${t} in a browser to authorize.`),Promise.resolve(`continue`)):new Promise(t=>{let n=document.createElement(`div`);n.setAttribute(`data-slicc-overlay`,`github-copilot-device`),n.style.cssText=[`position:fixed`,`top:24px`,`right:24px`,`z-index:2147483647`,`background:#0d1117`,`color:#e6edf3`,`border:1px solid #30363d`,`border-radius:10px`,`padding:16px 18px`,`box-shadow:0 8px 32px rgba(0,0,0,0.45)`,`font:13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,`min-width:260px`,`max-width:340px`].join(`;`);let r=document.createElement(`div`);r.textContent=`GitHub Copilot — verification code`,r.style.cssText=`font-weight:600;margin-bottom:8px;color:#7ee787`;let i=document.createElement(`div`);i.textContent=e,i.style.cssText=[`font:600 22px ui-monospace, SFMono-Regular, Menlo, monospace`,`letter-spacing:2px`,`background:#161b22`,`border:1px solid #30363d`,`border-radius:6px`,`padding:10px 12px`,`text-align:center`,`margin-bottom:10px`,`user-select:all`,`cursor:text`].join(`;`);let a=document.createElement(`div`);a.style.cssText=`color:#8b949e;font-size:12px;line-height:1.5`,a.textContent=`Copy the code, then click Continue to open the GitHub authorization page in a new tab.`;let o=document.createElement(`div`);o.style.cssText=`display:flex;gap:8px;margin-top:12px;justify-content:flex-end`;let s=document.createElement(`button`);s.type=`button`,s.textContent=`Cancel`,s.style.cssText=[`background:transparent`,`color:#e6edf3`,`border:1px solid #30363d`,`border-radius:6px`,`padding:6px 12px`,`font:600 12px inherit`,`cursor:pointer`].join(`;`);let c=document.createElement(`button`);c.type=`button`,c.textContent=`Copy & Continue`,c.style.cssText=[`background:#238636`,`color:#fff`,`border:0`,`border-radius:6px`,`padding:6px 12px`,`font:600 12px inherit`,`cursor:pointer`].join(`;`);let l=()=>{try{n.remove()}catch{}};s.addEventListener(`click`,()=>{l(),t(`cancel`)}),c.addEventListener(`click`,()=>{(async()=>{try{let{copyTextToClipboard:t}=await import(`./provider-settings-C5-R4CAK.js`).then(e=>e.t);await t(e)}catch{}l(),t(`continue`)})()}),o.appendChild(s),o.appendChild(c),n.appendChild(r),n.appendChild(i),n.appendChild(a),n.appendChild(o),document.body.appendChild(n)});async function Z(){let e=v();return e?.refreshToken?p(e.refreshToken,fetch,{headers:g}):null}const Q={id:m,name:`GitHub Copilot`,description:`Use your GitHub Copilot subscription to access Claude, GPT-5, Codex, Gemini, and Grok models. Sign in with the GitHub device-code flow.`,requiresApiKey:!1,requiresBaseUrl:!1,isOAuth:!0,defaultModelId:`claude-sonnet-4.6`,oauthTokenDomains:[`*.githubcopilot.com`,`api.individual.githubcopilot.com`,`api.business.githubcopilot.com`,`api.enterprise.githubcopilot.com`],getModelIds:I,getBudgetUsage:Z,onOAuthLoginIntercepted:async(e,t,n)=>{let r=await y(),i=new URL(r.verification_uri);if(i.searchParams.set(`user_code`,r.user_code),await(n?.presentDeviceCode??X)({userCode:r.user_code,verificationUrl:i.toString(),expiresInSeconds:r.expires_in})===`cancel`)throw Error(`GitHub Copilot login cancelled`);let a=new AbortController,o=e({authorizeUrl:i.toString(),redirectUriPattern:`https://github.com/login/device/success*`,onCapture:`close`,timeoutMs:r.expires_in*1e3}).catch(e=>(console.warn(`[github-copilot] Launcher failed:`,e instanceof Error?e.message:String(e)),null)),s;try{s=await b(r,a.signal)}catch(e){throw a.abort(),await o,e}await o;let c=await C(s),l;try{let e=await fetch(`https://api.github.com/user`,{headers:{Authorization:`Bearer ${s}`,Accept:`application/json`}});if(e.ok){let t=await e.json();l=t.name||t.login}}catch{}await M(c,l),await j(c),t()},onOAuthLogout:async()=>{await e({providerId:m,accessToken:``})},onSilentRenew:async()=>{let e=v();if(!e?.refreshToken)return null;try{let t=await C(e.refreshToken);return await M(t,e.userName),await j(t),t.copilotToken}catch(e){return console.warn(`[github-copilot] Silent renew failed:`,e instanceof Error?e.message:String(e)),null}}};function $(){r({api:`github-copilot-anthropic`,stream:J,streamSimple:Y}),r({api:`github-copilot-openai`,stream:J,streamSimple:Y})}export{Q as config,F as isCopilotConeCompatible,$ as register};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/clipboard-eqmn97SP.js","assets/rolldown-runtime-Dd_uD5pT.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e}from"./diagnostics-DN_idNHx.js";import{t}from"./preload-helper-Czpn1I53.js";import{a as n,n as r,r as i}from"./compat-qQM4gjF_.js";import{a,c as o,i as s,r as c,s as l,t as u}from"./legacy-api-aliases-DtQJ5I7w.js";import{G as d,f as ee}from"./account-store-C-p1lMw5.js";import"./main-CbW_Za2k.js";var te=`https://api.github.com/copilot_internal/user`,f=8e3;function p(e){if(!e||typeof e!=`object`)return null;let t=e.quota_snapshots?.premium_interactions;return!t||t.unlimited||typeof t.percent_remaining!=`number`?null:{percent:Math.max(0,100-t.percent_remaining),status:t.percent_remaining<=0&&t.overage_permitted!==!0?`rate-limited`:`ok`,window:`monthly`,resetsAt:e.quota_reset_date_utc}}async function m(e,t,n={}){let r=typeof AbortController==`function`?new AbortController:null,i=r?setTimeout(()=>r.abort(),n.timeoutMs??f):null;try{let i=await t(te,{headers:{...n.headers,Authorization:`Bearer ${e}`},...r?{signal:r.signal}:{}});if(i.status===404||i.status===501)return null;if(!i.ok)throw Error(`GitHub Copilot /copilot_internal/user returned ${i.status}`);return p(await i.json())}finally{i&&clearTimeout(i)}}var h=`github-copilot`,g=atob(`SXYxLmI1MDdhMDhjODdlY2ZlOTg=`),_=`https://github.com/login/device/code`,v=`https://github.com/login/oauth/access_token`,y=`https://api.github.com/copilot_internal/v2/token`,b={Accept:`application/json`,"Editor-Version":`vscode/1.107.0`,"Editor-Plugin-Version":`copilot-chat/0.35.0`,"Copilot-Integration-Id":`vscode-chat`},x={Accept:`application/json`,"Content-Type":`application/x-www-form-urlencoded`},S=`https://github.com/login/device/success*`;function C(){return ee().find(e=>e.providerId===h)}async function w(){let e=await fetch(_,{method:`POST`,headers:x,body:new URLSearchParams({client_id:g,scope:`read:user`})});if(!e.ok)throw Error(`GitHub device-code request failed: ${e.status} ${e.statusText} — ${await e.text().catch(()=>``)}`);let t=await e.json();if(typeof t.device_code!=`string`||typeof t.user_code!=`string`||typeof t.verification_uri!=`string`||typeof t.expires_in!=`number`||typeof t.interval!=`number`)throw Error(`GitHub device-code response had an unexpected shape`);return t}async function T(e,t){let n=Date.now()+e.expires_in*1e3,r=Math.max(1e3,Math.floor(e.interval*1e3)),i=1.2;for(;Date.now()<n;){if(t.aborted)throw Error(`Copilot login cancelled`);await E(Math.ceil(r*i),t);let n=await fetch(v,{method:`POST`,headers:x,body:new URLSearchParams({client_id:g,device_code:e.device_code,grant_type:`urn:ietf:params:oauth:grant-type:device_code`})});if(!n.ok)throw Error(`GitHub token poll failed: ${n.status} ${n.statusText} — ${await n.text().catch(()=>``)}`);let a=await n.json();if(typeof a.access_token==`string`&&a.access_token.length>0)return a.access_token;if(a.error!==`authorization_pending`){if(a.error===`slow_down`){r=typeof a.interval==`number`?a.interval*1e3:r+5e3,i=1.4;continue}if(a.error){let e=a.error_description?`: ${a.error_description}`:``;throw Error(`Device flow failed (${a.error})${e}`)}}}throw Error(`Copilot device flow timed out (device code expired)`)}function E(e,t){return new Promise((n,r)=>{if(t.aborted){r(Error(`Copilot login cancelled`));return}let i=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(i),r(Error(`Copilot login cancelled`))},{once:!0})})}function ne(e){let t=e.match(/proxy-ep=([^;]+)/);return t?`https://${t[1].replace(/^proxy\./,`api.`)}`:null}async function D(e){let t=await fetch(y,{headers:{...b,Authorization:`Bearer ${e}`}});if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`Copilot token exchange failed: ${t.status} ${t.statusText} — ${e.slice(0,300)}`)}let n=await t.json();if(typeof n.token!=`string`||typeof n.expires_at!=`number`)throw Error(`Copilot token exchange returned an unexpected payload`);if(n.chat_enabled===!1)throw Error(`GitHub Copilot Chat is disabled for this account (no chat features granted)`);return{copilotToken:n.token,expiresAtMs:n.expires_at*1e3-3e5,apiBaseUrl:ne(n.token)??`https://api.individual.githubcopilot.com`,githubAccessToken:e}}var O=`github-copilot.models.v1`;function k(e){let t=e.supported_endpoints??[],n=(e.vendor??``).toLowerCase(),r=e.id;return n===`anthropic`&&t.includes(`/v1/messages`)?`anthropic-messages`:n===`openai`&&(/^gpt-5/i.test(r)||/codex/i.test(r)||/^o\d/i.test(r))?`openai-responses`:`openai-completions`}function A(e){if(!e||typeof e!=`object`)return[];let t=e.data;if(!Array.isArray(t))return[];let n=[];for(let e of t)e.capabilities?.type&&e.capabilities.type!==`chat`||e.model_picker_enabled!==!1&&e.id&&n.push({id:e.id,name:e.name??e.id,vendor:e.vendor??``,api:k(e),contextWindow:e.capabilities?.limits?.max_context_window_tokens??e.capabilities?.limits?.max_prompt_tokens??128e3,maxTokens:e.capabilities?.limits?.max_output_tokens??8192,supportsTools:e.capabilities?.supports?.tool_calls===!0,supportsStreaming:e.capabilities?.supports?.streaming!==!1,supportsVision:e.capabilities?.supports?.vision===!0,supportsReasoning:e.capabilities?.supports?.adaptive_thinking===!0||Array.isArray(e.capabilities?.supports?.reasoning_effort),policyState:e.policy?.state??`enabled`});return n}async function j(e){let t=await fetch(`${e.apiBaseUrl}/models`,{headers:{...b,Authorization:`Bearer ${e.copilotToken}`,Accept:`application/json`}});if(!t.ok)throw Error(`Copilot /models returned ${t.status} ${t.statusText}`);return A(await t.json())}function M(){if(typeof localStorage>`u`)return[];try{let e=localStorage.getItem(O);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function N(e){if(!(typeof localStorage>`u`))try{localStorage.setItem(O,JSON.stringify(e))}catch{}}function P(e){return M().find(t=>t.id===e)??null}async function F(e){let t;try{t=await j(e)}catch(e){console.warn(`[github-copilot] Catalog refresh failed; keeping previous cache.`,e instanceof Error?e.message:String(e));return}N(t),await Promise.all(t.filter(e=>e.policyState===`disabled`).map(async t=>{let n=`${e.apiBaseUrl}/models/${encodeURIComponent(t.id)}/policy`;try{let r=await fetch(n,{method:`POST`,headers:{...b,"Content-Type":`application/json`,Authorization:`Bearer ${e.copilotToken}`,"openai-intent":`chat-policy`,"x-interaction-type":`chat-policy`},body:JSON.stringify({state:`enabled`})});r.ok?t.policyState=`enabled`:r.status!==404&&r.status!==400&&console.warn(`[github-copilot] enable policy for ${t.id} returned ${r.status} ${r.statusText}`)}catch(e){console.warn(`[github-copilot] enable policy for ${t.id} failed:`,e instanceof Error?e.message:String(e))}})),N(t)}async function I(e,t){await d({providerId:h,accessToken:e.copilotToken,refreshToken:e.githubAccessToken,tokenExpiresAt:e.expiresAtMs,baseUrl:e.apiBaseUrl,userName:t})}async function L(){let e=C();if(!e?.accessToken||!e.refreshToken)throw Error(`Not logged in to GitHub Copilot — click "Login" in the provider settings`);let t=e.tokenExpiresAt??0;if(Date.now()<t-6e4)return e.accessToken;let n=await D(e.refreshToken);return await I(n,e.userName),n.copilotToken}var R=[`mini`,`nano`,`flash`,`haiku`,`lite`,`embedding`];function z(e){let t=[e.id,e.name??``].flatMap(e=>{let t=e.toLowerCase();return[t,t.replace(/[\s_.:]+/g,`-`)]});return!R.some(e=>t.some(t=>t.includes(e)))}function B(){if(!C()?.accessToken)return[];let e=M();if(e.length>0)return e.filter(e=>!e.policyState.startsWith(`unavailable:`)).filter(e=>z(e)).map(e=>({id:e.id,name:e.name,api:e.api===`anthropic-messages`?`anthropic`:`openai`,context_window:e.contextWindow,max_tokens:e.maxTokens,reasoning:e.supportsReasoning,input:e.supportsVision?[`text`,`image`]:[`text`]}));let t;try{t=i(`github-copilot`)}catch{return[]}return t.filter(e=>z({id:e.id,name:e.name})).map(e=>({id:e.id,name:e.name??e.id,api:e.api===`anthropic-messages`?`anthropic`:`openai`,context_window:e.contextWindow,max_tokens:e.maxTokens,reasoning:e.reasoning,input:e.input}))}function V(e,t){return{type:`error`,reason:`error`,error:{role:`assistant`,content:[],api:e.api,provider:h,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`error`,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()}}}var H={"User-Agent":`GitHubCopilotChat/0.35.0`,"Editor-Version":`vscode/1.107.0`,"Editor-Plugin-Version":`copilot-chat/0.35.0`,"Copilot-Integration-Id":`vscode-chat`};function U(e){let t=C(),n=t?.baseUrl??`https://api.individual.githubcopilot.com`,i=P(e);if(i)return{api:i.api,baseUrl:n,headers:{...H}};try{let n=r(`github-copilot`,e);return{api:n.api,baseUrl:t?.baseUrl??n.baseUrl,headers:{...n.headers??{},...H}}}catch{return null}}function W(e,t){let n=M(),r=n.findIndex(t=>t.id===e);r<0||(n[r]={...n[r],policyState:`unavailable:${t}`},N(n))}function G(e,t){return`GitHub Copilot rejected "${e}" with model_not_supported. This usually means the model isn't included in your Copilot plan (Opus and other premium models require Copilot Pro / Pro+ / Business / Enterprise). Try Claude Sonnet 4.6 or another model that appears in the picker after a fresh login. Original error: ${t}`}function K(e){if(!e||typeof e!=`object`)return null;let t=e;if(t.type!==`error`)return null;if(t.error&&typeof t.error==`object`){let e=t.error.errorMessage;if(typeof e==`string`)return e}return typeof t.errorMessage==`string`?t.errorMessage:null}function q(e,t){return e===`anthropic-messages`?t?a:u:e===`openai-responses`?t?o:s:t?l:c}function J(e,t,n){let r=K(n);if(r&&/model_not_supported/i.test(r)){W(t.id,`model_not_supported`);let n=G(t.id,r);return console.error(`[github-copilot] Plan-gated model rejection:`,n),e.push(V(t,Error(n))),e.end(),!0}return e.push(n),!1}function Y(e,t,n){let r=n instanceof Error?n.message:String(n),i=n;/model_not_supported/i.test(r)&&(W(t.id,`model_not_supported`),i=Error(G(t.id,r))),console.error(`[github-copilot] Stream error:`,i instanceof Error?i.message:String(i)),e.push(V(t,i)),e.end()}async function X(e,t,n,r,i){try{let a=await L(),o=U(t.id);if(!o)throw Error(`GitHub Copilot does not recognize "${t.id}" — open the picker (the model list refreshes on login) and pick a current model.`);let s={...t,api:o.api,baseUrl:o.baseUrl,headers:o.headers,provider:`github-copilot`},c={...r,apiKey:a},l=q(o.api,i)(s,n,c);for await(let n of l)if(J(e,t,n))return;e.end()}catch(n){Y(e,t,n)}}function Z(t){return(n,r,i={})=>{let a=e();return X(a,n,r,i,t),a}}var Q=Z(!1),$=Z(!0),re=({userCode:e,verificationUrl:n})=>typeof document>`u`?(console.info(`[github-copilot] Device verification code: ${e} — open ${n} in a browser to authorize.`),Promise.resolve(`continue`)):new Promise(n=>{let r=document.createElement(`div`);r.setAttribute(`data-slicc-overlay`,`github-copilot-device`),r.style.cssText=[`position:fixed`,`top:24px`,`right:24px`,`z-index:2147483647`,`background:#0d1117`,`color:#e6edf3`,`border:1px solid #30363d`,`border-radius:10px`,`padding:16px 18px`,`box-shadow:0 8px 32px rgba(0,0,0,0.45)`,`font:13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,`min-width:260px`,`max-width:340px`].join(`;`);let i=document.createElement(`div`);i.textContent=`GitHub Copilot — verification code`,i.style.cssText=`font-weight:600;margin-bottom:8px;color:#7ee787`;let a=document.createElement(`div`);a.textContent=e,a.style.cssText=[`font:600 22px ui-monospace, SFMono-Regular, Menlo, monospace`,`letter-spacing:2px`,`background:#161b22`,`border:1px solid #30363d`,`border-radius:6px`,`padding:10px 12px`,`text-align:center`,`margin-bottom:10px`,`user-select:all`,`cursor:text`].join(`;`);let o=document.createElement(`div`);o.style.cssText=`color:#8b949e;font-size:12px;line-height:1.5`,o.textContent=`Copy the code, then click Continue to open the GitHub authorization page in a new tab.`;let s=document.createElement(`div`);s.style.cssText=`display:flex;gap:8px;margin-top:12px;justify-content:flex-end`;let c=document.createElement(`button`);c.type=`button`,c.textContent=`Cancel`,c.style.cssText=[`background:transparent`,`color:#e6edf3`,`border:1px solid #30363d`,`border-radius:6px`,`padding:6px 12px`,`font:600 12px inherit`,`cursor:pointer`].join(`;`);let l=document.createElement(`button`);l.type=`button`,l.textContent=`Copy & Continue`,l.style.cssText=[`background:#238636`,`color:#fff`,`border:0`,`border-radius:6px`,`padding:6px 12px`,`font:600 12px inherit`,`cursor:pointer`].join(`;`);let u=()=>{try{r.remove()}catch{}};c.addEventListener(`click`,()=>{u(),n(`cancel`)}),l.addEventListener(`click`,()=>{(async()=>{try{let{copyTextToClipboard:n}=await t(async()=>{let{copyTextToClipboard:e}=await import(`./clipboard-eqmn97SP.js`).then(e=>e.t);return{copyTextToClipboard:e}},__vite__mapDeps([0,1]));await n(e)}catch{}u(),n(`continue`)})()}),s.appendChild(c),s.appendChild(l),r.appendChild(i),r.appendChild(a),r.appendChild(o),r.appendChild(s),document.body.appendChild(r)});async function ie(){let e=C();return e?.refreshToken?m(e.refreshToken,fetch,{headers:b}):null}var ae={id:h,name:`GitHub Copilot`,description:`Use your GitHub Copilot subscription to access Claude, GPT-5, Codex, Gemini, and Grok models. Sign in with the GitHub device-code flow.`,requiresApiKey:!1,requiresBaseUrl:!1,isOAuth:!0,defaultModelId:`claude-sonnet-4.6`,oauthTokenDomains:[`*.githubcopilot.com`,`api.individual.githubcopilot.com`,`api.business.githubcopilot.com`,`api.enterprise.githubcopilot.com`],getModelIds:B,getBudgetUsage:ie,onOAuthLoginIntercepted:async(e,t,n)=>{let r=await w(),i=new URL(r.verification_uri);if(i.searchParams.set(`user_code`,r.user_code),await(n?.presentDeviceCode??re)({userCode:r.user_code,verificationUrl:i.toString(),expiresInSeconds:r.expires_in})===`cancel`)throw Error(`GitHub Copilot login cancelled`);let a=new AbortController,o=e({authorizeUrl:i.toString(),redirectUriPattern:S,onCapture:`close`,timeoutMs:r.expires_in*1e3}).catch(e=>(console.warn(`[github-copilot] Launcher failed:`,e instanceof Error?e.message:String(e)),null)),s;try{s=await T(r,a.signal)}catch(e){throw a.abort(),await o,e}await o;let c=await D(s),l;try{let e=await fetch(`https://api.github.com/user`,{headers:{Authorization:`Bearer ${s}`,Accept:`application/json`}});if(e.ok){let t=await e.json();l=t.name||t.login}}catch{}await I(c,l),await F(c),t()},onOAuthLogout:async()=>{await d({providerId:h,accessToken:``})},onSilentRenew:async()=>{let e=C();if(!e?.refreshToken)return null;try{let t=await D(e.refreshToken);return await I(t,e.userName),await F(t),t.copilotToken}catch(e){return console.warn(`[github-copilot] Silent renew failed:`,e instanceof Error?e.message:String(e)),null}}};function oe(){n({api:`github-copilot-anthropic`,stream:Q,streamSimple:$}),n({api:`github-copilot-openai`,stream:Q,streamSimple:$})}export{ae as config,z as isCopilotConeCompatible,oe as register};
|