sliccy 6.136.0 → 6.136.1
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 +140 -139
- package/dist/ui/assets/{SKILL-CLNwFz3P.js → SKILL-Dkk5iZlJ.js} +1 -1
- package/dist/ui/assets/{account-store-CG9Pz134.js → account-store-BzCpAbzU.js} +1 -1
- package/dist/ui/assets/{account-store-B8IgsGFb.js → account-store-IBc-Swl2.js} +1 -1
- package/dist/ui/assets/{adobe-BgPcRuIn.js → adobe-BlUDEEVT.js} +1 -1
- package/dist/ui/assets/{adobe-DJimoIir.js → adobe-xtVVXp2q.js} +1 -1
- package/dist/ui/assets/{agent-bridge-WC9o6r65.js → agent-bridge-Bgb7xaDh.js} +1 -1
- package/dist/ui/assets/{apply-layout-Dv1RaUFe.js → apply-layout-l78p8Bos.js} +1 -1
- package/dist/ui/assets/{apps-BOBYtKMD.js → apps-DDo9wnih.js} +1 -1
- package/dist/ui/assets/{azure-openai-CSeH1BDL.js → azure-openai-CRb9ZtBO.js} +1 -1
- package/dist/ui/assets/{azure-openai-C1v6YymB.js → azure-openai-zWPF524s.js} +1 -1
- package/dist/ui/assets/{cdp-0LZ0nstT.js → cdp-DKhmYptD.js} +1 -1
- package/dist/ui/assets/{cerebras-BUohc5O0.js → cerebras-COu_QlOd.js} +1 -1
- package/dist/ui/assets/{cerebras-C4a_X7D8.js → cerebras-DtLUDEbM.js} +1 -1
- package/dist/ui/assets/{connect-surface-D2e8Twf-.js → connect-surface-B4G8l--y.js} +1 -1
- package/dist/ui/assets/{dip-DjZvvl_D.js → dip-DySyh98z.js} +4 -4
- package/dist/ui/assets/{directed-approval-rMofdevJ.js → directed-approval-CZK0YFwX.js} +1 -1
- package/dist/ui/assets/{fs-DX7ZCHzZ.js → fs-BXsWV91k.js} +2 -2
- package/dist/ui/assets/{fs-Brsg4Rlu.js → fs-D5rn9Yg2.js} +1 -1
- package/dist/ui/assets/{github-D0j7COIL.js → github-CJd5WOrc.js} +1 -1
- package/dist/ui/assets/{github-BsDD6b6E.js → github-DzUDXVwm.js} +2 -2
- package/dist/ui/assets/{github-copilot-DmmtmUPS.js → github-copilot-CPDNi2pJ.js} +1 -1
- package/dist/ui/assets/{github-copilot-DJnyx6Kk.js → github-copilot-OMKzjJ2o.js} +1 -1
- package/dist/ui/assets/{github-install-DHWvp_ed.js → github-install-DY3uazWz.js} +1 -1
- package/dist/ui/assets/{github-zip-C7RqBdik.js → github-zip-BGeyA2Li.js} +1 -1
- package/dist/ui/assets/{help-Db3oErKr.js → help-CjuK8HDa.js} +1 -1
- package/dist/ui/assets/{js-realm-worker-7yCsdyVv.js → js-realm-worker-Ca9s6UEK.js} +1 -1
- package/dist/ui/assets/{kernel-worker-B28ddZ6G.js → kernel-worker-CC7asGg9.js} +31 -31
- package/dist/ui/assets/{local-llm-jlZx1MJC.js → local-llm-C4lmoelF.js} +1 -1
- package/dist/ui/assets/{local-llm-Xuq1mj9S.js → local-llm-DZ9jctP2.js} +1 -1
- package/dist/ui/assets/{main-DtQE8ZJN.js → main-CcfFeq6P.js} +3 -3
- package/dist/ui/assets/{main-cherry-BRvnemBM.js → main-cherry-Ibu56rin.js} +1 -1
- package/dist/ui/assets/{mount-CSNG1HDe.js → mount-DbUK_ouC.js} +3 -3
- package/dist/ui/assets/{mount-recovery-DG2kvUyT.js → mount-recovery-Dzskgqa7.js} +1 -1
- package/dist/ui/assets/{mount-dY50JDIC.js → mount-vbEbpo4N.js} +1 -1
- package/dist/ui/assets/{new-session-Ba4480Kn.js → new-session-BscrQvQH.js} +2 -2
- package/dist/ui/assets/{oauth-bootstrap-CSqwVxsH.js → oauth-bootstrap-CCnmEqBW.js} +2 -2
- package/dist/ui/assets/{openai-codex-uDeSXi0c.js → openai-codex-B-7bpkdM.js} +1 -1
- package/dist/ui/assets/{openai-codex-D0gE5hCX.js → openai-codex-BO7ubdvf.js} +1 -1
- package/dist/ui/assets/{openrouter-KPrk7aTG.js → openrouter-C2yH1Eg2.js} +1 -1
- package/dist/ui/assets/{openrouter-CELFnxj8.js → openrouter-c4UnAH0g.js} +1 -1
- package/dist/ui/assets/{openrouter-oauth-CRIb5OcK.js → openrouter-oauth-DOOgBCk9.js} +1 -1
- package/dist/ui/assets/{openrouter-oauth-C9851OCp.js → openrouter-oauth-SIQYiorE.js} +1 -1
- package/dist/ui/assets/{panel-rpc-handlers-zoyvF7_M.js → panel-rpc-handlers-DAdmCiAM.js} +2 -2
- package/dist/ui/assets/{provider-BuVKaW63.js → provider-DHmZizbV.js} +1 -1
- package/dist/ui/assets/{provider-DXM2_o56.js → provider-DSOEMASd.js} +2 -2
- package/dist/ui/assets/provider-settings-BS8lFD1q.js +1 -0
- package/dist/ui/assets/{provider-settings-BusT_5Y1.js → provider-settings-CGwq2ZSe.js} +1 -1
- package/dist/ui/assets/{provider-store-access-BJulUz_a.js → provider-store-access-CMRf7M8N.js} +2 -2
- package/dist/ui/assets/provider-store-access-CVOw7bhE.js +1 -0
- package/dist/ui/assets/{providers-CxGK6Fqy.js → providers-DEZ_uN7Q.js} +2 -2
- package/dist/ui/assets/{providers-IZ5cNVfA.js → providers-DfgkYKp3.js} +1 -1
- package/dist/ui/assets/{quick-llm-DBwEP6q1.js → quick-llm-CTm8kfpN.js} +1 -1
- package/dist/ui/assets/{recovery-screen-D1reb-pz.js → recovery-screen-D7czDrGy.js} +1 -1
- package/dist/ui/assets/{run-jqtaDwYu.js → run-BbwmmE0l.js} +1 -1
- package/dist/ui/assets/{run-Bo2fK4R4.js → run-CMPmBjRA.js} +1 -1
- package/dist/ui/assets/{run-BjclDk0Z.js → run-kHiTfPA_.js} +2 -2
- package/dist/ui/assets/{session-freezer-kUAj24xS.js → session-freezer-C7H1VByB.js} +3 -3
- package/dist/ui/assets/{setup-feature-flags-remote-CkzzcYU8.js → setup-feature-flags-remote-J95n02lO.js} +1 -1
- package/dist/ui/assets/{setup-standalone-prelude-C4d7EdCJ.js → setup-standalone-prelude-L6dqa7or.js} +2 -2
- package/dist/ui/assets/{setup-sudo-Fk7Y7Qt-.js → setup-sudo-DXCFEDCh.js} +2 -2
- package/dist/ui/assets/{skills-BAQj3H1g.js → skills-DLlIa_OZ.js} +1 -1
- package/dist/ui/assets/slicc-version-C8iZhVsg.js +1 -0
- package/dist/ui/assets/{snapshot-Cfd5BBqA.js → snapshot-BWdwScwG.js} +1 -1
- package/dist/ui/assets/{snapshot-features-Bluz5JNp.js → snapshot-features-CHwnS5pR.js} +1 -1
- package/dist/ui/assets/sprinkle-bridge-CeRz-DjR.js +2 -0
- package/dist/ui/assets/{sprinkle-manager-CtUCzppZ.js → sprinkle-manager-jHNM2oxy.js} +1 -1
- package/dist/ui/assets/{sprinkle-renderer-DJyQFvKt.js → sprinkle-renderer-Ce6YjEek.js} +72 -13
- package/dist/ui/assets/{state-99acinkj.js → state-BaXCc20k.js} +1 -1
- package/dist/ui/assets/{store-D48jOp3G.js → store-BDD3IHgP.js} +1 -1
- package/dist/ui/assets/{store-GRTMEtdq.js → store-Ca4Dnbdu.js} +1 -1
- package/dist/ui/assets/{sudo-BMl-vlg6.js → sudo-CA0RFOLj.js} +1 -1
- package/dist/ui/assets/{upgrade-detection-DH1eohPP.js → upgrade-detection-C145Khtm.js} +1 -1
- package/dist/ui/assets/{wc-extension-CY666K0U.js → wc-extension-Bi0TRT8Q.js} +2 -2
- package/dist/ui/assets/{wc-follower-BWQOhNee.js → wc-follower-Bo_J3jq5.js} +3 -3
- package/dist/ui/assets/{wc-follower-oauth-ClOA_w6r.js → wc-follower-oauth-DCz20htV.js} +1 -1
- package/dist/ui/assets/{wc-live-B1dex7oL.js → wc-live-NRwfoCVf.js} +3 -3
- package/dist/ui/assets/{wc-nav-DVdmQDvN.js → wc-nav-DrHMR3BW.js} +2 -2
- package/dist/ui/assets/{wc-onboarding-NYG1uBXD.js → wc-onboarding-De4Igl1i.js} +2 -2
- package/dist/ui/assets/{wc-placeholder-MzB6mEv3.js → wc-placeholder-DPzXeItf.js} +2 -2
- package/dist/ui/assets/{wc-settings-DyL5gfGi.js → wc-settings-CVX_pOD-.js} +2 -2
- package/dist/ui/assets/{wc-shell-DchXcP-_.js → wc-shell-DgmtA7sH.js} +2 -2
- package/dist/ui/assets/{wc-sprinkles-DtoxWB3_.js → wc-sprinkles-FfifZkuL.js} +2 -2
- package/dist/ui/assets/{wc-tray-DWjggXZK.js → wc-tray-DJF61Czu.js} +4 -4
- package/dist/ui/assets/{xai-grok-BnXKBV79.js → xai-grok-9c2GZFuB.js} +1 -1
- package/dist/ui/assets/{xai-grok-BTJ50D3E.js → xai-grok-DrI5c3BY.js} +1 -1
- package/dist/ui/index.html +6 -6
- package/dist/ui/packages/webapp/index.html +6 -6
- package/package.json +1 -1
- package/dist/ui/assets/provider-settings-CHgRgntH.js +0 -1
- package/dist/ui/assets/provider-store-access-BSv6hr_9.js +0 -1
- package/dist/ui/assets/slicc-version-C3ORozzC.js +0 -1
- package/dist/ui/assets/sprinkle-bridge-B8DKuaxn.js +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{_ as e,x as t}from"./account-store-
|
|
1
|
+
import{_ as e,x as t}from"./account-store-BzCpAbzU.js";import{a as n}from"./diagnostics-DN_idNHx.js";import{t as r}from"./models-BSkXF4T6.js";import{u as i}from"./claude-model-version-BJLrDjmH.js";import{r as a,t as o}from"./transform-messages-BsQjTIEJ.js";function s(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n}function c(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)}var l=function(){let{crypto:e}=globalThis;if(e?.randomUUID)return l=e.randomUUID.bind(e),e.randomUUID();let t=new Uint8Array(1),n=e?()=>e.getRandomValues(t)[0]:()=>Math.random()*255&255;return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^n()&15>>e/4).toString(16))};function u(e){return typeof e==`object`&&!!e&&(`name`in e&&e.name===`AbortError`||`message`in e&&String(e.message).includes(`FetchRequestCanceledException`))}var d=e=>{if(e instanceof Error)return e;if(typeof e==`object`&&e){try{if(Object.prototype.toString.call(e)===`[object Error]`){let t=Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch{}try{return Error(JSON.stringify(e))}catch{}}return Error(e)},f=class extends Error{},p=class e extends f{constructor(t,n,r,i){super(`${e.makeMessage(t,n,r)}`),this.status=t,this.headers=i,this.requestID=i?.get(`x-request-id`),this.error=n;let a=n;this.code=a?.code,this.param=a?.param,this.type=a?.type}static makeMessage(e,t,n){let r=t?.message?typeof t.message==`string`?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||`(no status code or body)`}static generate(t,n,r,i){if(!t||!i)return new h({message:r,cause:d(n)});let a=n?.error;return t===400?new _(t,a,r,i):t===401?new v(t,a,r,i):t===403?new y(t,a,r,i):t===404?new b(t,a,r,i):t===409?new x(t,a,r,i):t===422?new ee(t,a,r,i):t===429?new te(t,a,r,i):t>=500?new ne(t,a,r,i):new e(t,a,r,i)}},m=class extends p{constructor({message:e}={}){super(void 0,void 0,e||`Request was aborted.`,void 0)}},h=class extends p{constructor({message:e,cause:t}){super(void 0,void 0,e||`Connection error.`,void 0),t&&(this.cause=t)}},g=class extends h{constructor({message:e}={}){super({message:e??`Request timed out.`})}},_=class extends p{},v=class extends p{},y=class extends p{},b=class extends p{},x=class extends p{},ee=class extends p{},te=class extends p{},ne=class extends p{},re=class extends f{constructor(){super(`Could not parse response content as the length limit was reached`)}},ie=class extends f{constructor(){super(`Could not parse response content as the request was rejected by the content filter`)}},ae=class extends Error{constructor(e){super(e)}},oe=class extends p{constructor(e,t,n){let r=`OAuth2 authentication error`,i;if(t&&typeof t==`object`){let e=t;i=e.error;let n=e.error_description;n&&typeof n==`string`?r=n:i&&(r=i)}super(e,t,r,n),this.error_code=i}},se=class extends f{constructor(e,t,n){super(e),this.provider=t,this.cause=n}},ce=/^[a-z][a-z0-9+.-]*:/i,le=e=>ce.test(e),S=e=>(S=Array.isArray,S(e)),ue=S;function de(e){return typeof e==`object`?e??{}:{}}function fe(e){if(!e)return!0;for(let t in e)return!1;return!0}function pe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function C(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var me=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t))throw new f(`${e} must be an integer`);if(t<0)throw new f(`${e} must be a positive integer`);return t},he=e=>{try{return JSON.parse(e)}catch{return}},ge=e=>new Promise(t=>setTimeout(t,e));function _e(){if(typeof fetch<`u`)return fetch;throw Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function ve(...e){let t=globalThis.ReadableStream;if(t===void 0)throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function ye(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return ve({start(){},async pull(e){let{done:n,value:r}=await t.next();n?e.close():e.enqueue(r)},async cancel(){await t.return?.()}})}function be(e){if(e[Symbol.asyncIterator])return e;let t=e.getReader();return{async next(){try{let e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){let e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function xe(e){if(typeof e!=`object`||!e)return;if(e[Symbol.asyncIterator]){await e[Symbol.asyncIterator]().return?.();return}let t=e.getReader(),n=t.cancel();t.releaseLock(),await n}var Se;function w(e){let t;return(Se??=(t=new globalThis.TextEncoder,t.encode.bind(t)))(e)}var Ce;function we(e){let t;return(Ce??=(t=new globalThis.TextDecoder,t.decode.bind(t)))(e)}var Te,T,E,D,O,Ee,De,Oe=65536,ke=class{constructor(){Te.add(this),T.set(this,void 0),E.set(this,void 0),D.set(this,void 0),O.set(this,void 0),Ee.set(this,void 0),s(this,T,new Uint8Array,`f`),s(this,E,0,`f`),s(this,D,0,`f`),s(this,O,0,`f`),s(this,Ee,!1,`f`)}decode(e){if(e==null)return[];let t;if(t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`string`?w(e):e,t.length===0||c(this,Ee,`f`)&&(s(this,Ee,!1,`f`),t[0]===10&&(t=t.subarray(1)),t.length===0))return[];c(this,Te,`m`,De).call(this,t);let n=[],r;for(;(r=Ae(c(this,T,`f`),c(this,O,`f`),c(this,D,`f`)))!=null;){let e=we(c(this,T,`f`).subarray(c(this,E,`f`),r.preceding));n.push(e),s(this,E,r.index,`f`),r.carriage&&(c(this,E,`f`)<c(this,D,`f`)&&c(this,T,`f`)[c(this,E,`f`)]===10?s(this,E,c(this,E,`f`)+1,`f`):c(this,E,`f`)===c(this,D,`f`)&&s(this,Ee,!0,`f`)),s(this,O,c(this,E,`f`),`f`)}if(s(this,O,c(this,D,`f`),`f`),c(this,E,`f`)===c(this,D,`f`))s(this,E,0,`f`),s(this,D,0,`f`),s(this,O,0,`f`),c(this,T,`f`).length>Oe&&s(this,T,new Uint8Array,`f`);else if(n.length>0&&c(this,T,`f`).length>Oe){let e=c(this,D,`f`)-c(this,E,`f`);if(e<=Oe||c(this,T,`f`).length>e*4){let t=e<=Oe?Math.min(Math.max(e*2,256),Oe):e*2,n=new Uint8Array(t);n.set(c(this,T,`f`).subarray(c(this,E,`f`),c(this,D,`f`))),s(this,T,n,`f`),s(this,E,0,`f`),s(this,D,e,`f`),s(this,O,e,`f`)}}return n}flush(){return s(this,Ee,!1,`f`),c(this,E,`f`)===c(this,D,`f`)?[]:this.decode(`
|
|
2
2
|
`)}};T=new WeakMap,E=new WeakMap,D=new WeakMap,O=new WeakMap,Ee=new WeakMap,Te=new WeakSet,De=function(e){if(c(this,D,`f`)+e.length>c(this,T,`f`).length){let t=c(this,D,`f`)-c(this,E,`f`);if(c(this,E,`f`)>=c(this,T,`f`).length/2&&t+e.length<=c(this,T,`f`).length)c(this,T,`f`).copyWithin(0,c(this,E,`f`),c(this,D,`f`));else{let n=Math.max(c(this,T,`f`).length*2,t+e.length,256),r=new Uint8Array(n);r.set(c(this,T,`f`).subarray(c(this,E,`f`),c(this,D,`f`))),s(this,T,r,`f`)}s(this,O,c(this,O,`f`)-c(this,E,`f`),`f`),s(this,D,t,`f`),s(this,E,0,`f`)}c(this,T,`f`).set(e,c(this,D,`f`)),s(this,D,c(this,D,`f`)+e.length,`f`)},ke.NEWLINE_CHARS=new Set([`
|
|
3
3
|
`,`\r`]),ke.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Ae(e,t,n){for(let r=t;r<n;r++){if(e[r]===10)return{preceding:r,index:r+1,carriage:!1};if(e[r]===13)return{preceding:r,index:r+1,carriage:!0}}return null}function je(e){for(let t=0;t<e.length-1;t++){let n=Me(e,t);if(n>0){let r=t+n,i=Me(e,r);if(i>0)return r+i}}return-1}function Me(e,t){return e[t]===10?1:e[t]===13?e[t+1]===10?2:1:0}var Ne={off:0,error:200,warn:300,info:400,debug:500},Pe=(e,t,n)=>{if(e){if(pe(Ne,e))return e;k(n).warn(`${t} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(Ne))}`)}};function Fe(){}function Ie(e,t,n){return!t||Ne[e]>Ne[n]?Fe:t[e].bind(t)}var Le={error:Fe,warn:Fe,info:Fe,debug:Fe},Re=new WeakMap;function k(e){let t=e.logger,n=e.logLevel??`off`;if(!t)return Le;let r=Re.get(t);if(r&&r[0]===n)return r[1];let i={error:Ie(`error`,t,n),warn:Ie(`warn`,t,n),info:Ie(`info`,t,n),debug:Ie(`debug`,t,n)};return Re.set(t,[n,i]),i}var ze=e=>(e.options&&(e.options={...e.options},delete e.options.headers),e.headers&&=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([e,t])=>[e,e.toLowerCase()===`authorization`||e.toLowerCase()===`api-key`||e.toLowerCase()===`x-api-key`||e.toLowerCase()===`x-amz-security-token`||e.toLowerCase()===`cookie`||e.toLowerCase()===`set-cookie`?`***`:t])),`retryOfRequestLogID`in e&&(e.retryOfRequestLogID&&(e.retryOf=e.retryOfRequestLogID),delete e.retryOfRequestLogID),e),Be,Ve=class e{constructor(e,t,n){Be.set(this,void 0),this.iterator=e,this.controller=t,s(this,Be,n,`f`)}static fromSSEResponse(t,n,r,i){let a=!1,o=r?k(r):console;async function*s(){if(a)throw new f("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");a=!0;let e=!1,r=!1;try{for await(let e of He(t,n)){if(e.data.startsWith(`[DONE]`)){r=!0;break}if(e.event===null||!e.event.startsWith(`thread.`)){let n;try{n=JSON.parse(e.data)}catch(t){throw o.error(`Could not parse message into JSON:`,e.data),o.error(`From chunk:`,e.raw),t}if(n&&n.error)throw new p(void 0,n.error,void 0,t.headers);yield i?{event:e.event,data:n}:n}else{let t;try{t=JSON.parse(e.data)}catch(t){throw console.error(`Could not parse message into JSON:`,e.data),console.error(`From chunk:`,e.raw),t}if(e.event===`error`)throw new p(void 0,t.error,t.message,void 0);yield{event:e.event,data:t}}}e=!0}catch(e){if(r||u(e)||n.signal.aborted&&e===n.signal.reason)return;throw e}finally{e||n.abort()}}return new e(s,n,r)}static fromReadableStream(t,n,r){let i=!1;async function*a(){let e=new ke,r=t.getReader(),i=!1,a,o=()=>{a??=r.cancel(),a.catch(()=>void 0)};n.signal.addEventListener(`abort`,o,{once:!0});try{if(n.signal.aborted){o();return}for(;;){let{value:t,done:a}=await r.read();if(a){i=!0;break}if(n.signal.aborted)return;for(let r of e.decode(t)){if(n.signal.aborted)return;yield r}}if(n.signal.aborted)return;for(let t of e.flush()){if(n.signal.aborted)return;yield t}}finally{n.signal.removeEventListener(`abort`,o),i||o(),r.releaseLock()}}async function*o(){if(i)throw new f("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let e=!1;try{for await(let t of a())e||t&&(yield JSON.parse(t));e=!0}catch(e){if(n.signal.aborted||u(e))return;throw e}finally{e||n.abort()}}return new e(o,n,r)}[(Be=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){let t=[],n=[],r=this.iterator(),i=e=>({next:()=>{if(e.length===0){let e=r.next();t.push(e),n.push(e)}return e.shift()}});return[new e(()=>i(t),this.controller,c(this,Be,`f`)),new e(()=>i(n),this.controller,c(this,Be,`f`))]}toReadableStream(){let e;return ve({start:async()=>{e=this[Symbol.asyncIterator]()},async pull(t){try{let{value:n,done:r}=await e.next();if(r)return t.close();let i=w(JSON.stringify(n)+`
|
|
4
4
|
`);t.enqueue(i)}catch(e){t.error(e)}},async cancel(){await e.return?.()}})}};async function*He(e,t){if(!e.body)throw t.abort(),globalThis.navigator!==void 0&&globalThis.navigator.product===`ReactNative`?new f(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`):new f(`Attempted to iterate over a response with no body`);let n=new Ge,r=new ke,i=be(e.body);for await(let e of We(i))for(let t of r.decode(e)){let e=n.decode(t);e&&(yield e)}for(let e of r.flush()){let t=n.decode(e);t&&(yield t)}}var Ue=3;async function*We(e){let t=new Uint8Array,n=0,r=0,i=0;for await(let a of e){if(a==null)continue;let e;if(e=a instanceof ArrayBuffer?new Uint8Array(a):typeof a==`string`?w(a):a,r+e.length>t.length){let a=r-n;if(n>=t.length/2&&a+e.length<=t.length)t.copyWithin(0,n,r);else{let i=new Uint8Array(Math.max(t.length*2,a+e.length));i.set(t.subarray(n,r)),t=i}i-=n,n=0,r=a}t.set(e,r),r+=e.length;let o;for(;(o=je(t.subarray(i,r)))!==-1;)o+=i,yield t.slice(n,o),n=o,i=n;i=Math.max(n,r-Ue)}r>n&&(yield t.slice(n,r))}var Ge=class{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith(`\r`)&&(e=e.slice(0,-1)),!e){if(!this.event&&!this.data.length)return null;let e={event:this.event,data:this.data.join(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./logger-DDBAeTLF.js";import"./navigation-watcher-C8xRyQBd.js";import"./wc-follower-oauth-
|
|
1
|
+
import{t as e}from"./logger-DDBAeTLF.js";import"./navigation-watcher-C8xRyQBd.js";import"./wc-follower-oauth-DCz20htV.js";import{n as t,t as n}from"./pending-request-table-Dgn6qYdL.js";var r=e(`cdp`),i=4001,a=class{ws=null;nextId=1;_superseded=!1;pending=new n;listeners=new Map;_state=`disconnected`;get state(){return this._state}get superseded(){return this._superseded}async connect(e){if(this._state!==`disconnected`)throw Error(`Cannot connect: state is ${this._state}`);if(!e?.url)throw Error(`CDPClient.connect() requires a WebSocket URL`);let{url:t,timeout:n=5e3,protocols:i}=e;return this._state=`connecting`,new Promise((e,a)=>{let o=setTimeout(()=>{this.cleanup(),a(Error(`CDP connection timed out after ${n}ms`))},n);try{this.ws=i===void 0?new WebSocket(t):new WebSocket(t,i)}catch(e){clearTimeout(o),this._state=`disconnected`,a(e);return}this.ws.onopen=()=>{clearTimeout(o),this._state=`connected`,this._superseded=!1,r.info(`Connected`,{url:t}),e()},this.ws.onerror=e=>{clearTimeout(o),this._state===`connecting`&&(r.error(`Connection failed`,{url:t}),this.cleanup(),a(Error(`CDP WebSocket connection failed`)))},this.ws.onmessage=e=>{this.handleMessage(e.data)},this.ws.onclose=e=>{this.handleClose(e?.code)}})}disconnect(){this.ws&&(this.ws.onclose=null,this.ws.close()),this._superseded=!1,this.cleanup(),r.info(`Disconnected`)}async send(e,t,n,i=3e4){if(this._state!==`connected`||!this.ws)throw Error(`CDP client is not connected`);let a=this.nextId++,o={id:a,method:e};t&&(o.params=t),n&&(o.sessionId=n),r.debug(`Send`,{method:e,id:a,sessionId:n});let s=this.pending.issue(a,i,`CDP command timed out after ${i}ms: ${e}`);return this.ws.send(JSON.stringify(o)),s}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){let n=this.listeners.get(e);n&&(n.delete(t),n.size===0&&this.listeners.delete(e))}once(e,n=3e4){return t(t=>(this.on(e,t),()=>this.off(e,t)),n,`Timed out waiting for event: ${e}`)}handleMessage(e){let t;try{t=JSON.parse(e)}catch{return}if(`id`in t&&typeof t.id==`number`){let e=t;r.debug(`Response`,{id:e.id,hasError:!!e.error}),e.error?(r.error(`Command error`,{id:e.id,code:e.error.code,message:e.error.message}),this.pending.reject(e.id,Error(`CDP error: ${e.error.message} (${e.error.code})`))):this.pending.resolve(e.id,e.result??{});return}if(`method`in t){let e=t;r.debug(`Event`,{method:e.method,sessionId:e.sessionId});let n=this.listeners.get(e.method);if(n){let t=e.sessionId?{...e.params,sessionId:e.sessionId}:e.params??{};for(let e of n)try{e(t)}catch{}}}}handleClose(e){let t=e===i;t?(this._superseded=!0,r.warn(`CDP slot superseded by another SLICC tab/window on this instance`,{code:e})):r.error(`Connection closed unexpectedly`,{pendingCommands:this.pending.size});let n=t?`CDP connection superseded by another SLICC tab/window on this instance`:`CDP connection closed`;this.pending.rejectAll(n),this.cleanup()}cleanup(){this.ws=null,this._state=`disconnected`,this.pending.rejectAll(`CDP client disconnected`)}},o=e(`har-recorder`),s=class{recordings=new Map;client;fs;eventCleanup=new Map;constructor(e,t){this.client=e,this.fs=t}async startRecording(e,t,n){let r=`rec-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await this.client.send(`Network.enable`,{},t),await this.client.send(`Page.enable`,{},t);let i=(await this.client.send(`Runtime.evaluate`,{expression:`location.href`,returnByValue:!0},t)).result?.value??`about:blank`,a={id:r,targetId:e,sessionId:t,filterCode:n,pendingRequests:new Map,entries:[],startTime:Date.now(),currentUrl:i,snapshotCount:0};return this.recordings.set(r,a),this.setupEventListeners(a),await this.ensureDir(`/recordings/${r}`),o.debug(`Started recording`,{recordingId:r,targetId:e,currentUrl:i}),r}setupEventListeners(e){let{sessionId:t,id:n}=e,r=n=>{let r=n;r.sessionId===t&&this.handleRequestWillBeSent(e,r)},i=n=>{let r=n;r.sessionId===t&&this.handleResponseReceived(e,r)},a=r=>{let i=r;i.sessionId===t&&this.handleLoadingFinished(e,i).catch(e=>{o.error(`Failed to process loadingFinished event`,{recordingId:n,requestId:i.requestId,error:e instanceof Error?e.message:String(e)})})},s=n=>{let r=n;r.sessionId===t&&this.handleLoadingFailed(e,r)},c=r=>{let i=r;if(i.sessionId!==t)return;let a=i.frame;if(!a?.parentId&&a?.url){let t=[...e.entries],r=e.currentUrl;e.currentUrl=a.url,e.entries=[],e.pendingRequests.clear(),this.saveSnapshotWithEntries(e,`navigation`,t,r).catch(e=>{o.error(`Failed to save navigation snapshot`,{recordingId:n,error:e instanceof Error?e.message:String(e)})})}};this.client.on(`Network.requestWillBeSent`,r),this.client.on(`Network.responseReceived`,i),this.client.on(`Network.loadingFinished`,a),this.client.on(`Network.loadingFailed`,s),this.client.on(`Page.frameNavigated`,c),this.eventCleanup.set(n,()=>{this.client.off(`Network.requestWillBeSent`,r),this.client.off(`Network.responseReceived`,i),this.client.off(`Network.loadingFinished`,a),this.client.off(`Network.loadingFailed`,s),this.client.off(`Page.frameNavigated`,c)})}handleRequestWillBeSent(e,t){let{requestId:n,request:r,timestamp:i}=t;!n||!r||i==null||e.pendingRequests.set(n,{requestId:n,startTime:i*1e3,request:{method:r.method,url:r.url,headers:r.headers,postData:r.postData}})}handleResponseReceived(e,t){let{requestId:n,response:r}=t;if(!n||!r)return;let i=e.pendingRequests.get(n);i&&(i.response={status:r.status,statusText:r.statusText,headers:r.headers,mimeType:r.mimeType},i.timing=r.timing)}async handleLoadingFinished(e,t){let{requestId:n,timestamp:r}=t;if(!n||r==null)return;let i=e.pendingRequests.get(n);if(!i)return;i.endTime=r*1e3;try{let t=await this.client.send(`Network.getResponseBody`,{requestId:n},e.sessionId);i.responseBody=t.body,i.responseBodyBase64=t.base64Encoded===!0}catch{}let a=this.buildHarEntry(i);a&&e.entries.push(a),e.pendingRequests.delete(n)}handleLoadingFailed(e,t){let{requestId:n}=t;n&&e.pendingRequests.delete(n)}buildHarEntry(e){if(!e.response)return null;let{request:t,response:n,timing:r,startTime:i,endTime:a,responseBody:o,responseBodyBase64:s}=e,c=a?a-i:0,l=[];try{let e=new URL(t.url);l=Array.from(e.searchParams.entries()).map(([e,t])=>({name:e,value:t}))}catch{}let u=r?(()=>{let e=(e,t)=>{if(e==null||t==null||e<0||t<0)return-1;let n=t-e;return n>=0?n:-1},t=r.dnsStart>=0?r.dnsStart:r.connectStart>=0?r.connectStart:0;return{blocked:t>0?t:-1,dns:e(r.dnsStart,r.dnsEnd),connect:e(r.connectStart,r.connectEnd),ssl:e(r.sslStart,r.sslEnd),send:e(r.sendStart,r.sendEnd),wait:e(r.sendEnd,r.receiveHeadersStart),receive:e(r.receiveHeadersStart,r.receiveHeadersEnd)}})():{blocked:-1,dns:-1,connect:-1,ssl:-1,send:0,wait:c,receive:0},d={size:o?.length??0,mimeType:n.mimeType??`application/octet-stream`};o&&(d.text=o,s&&(d.encoding=`base64`));let f;return t.postData&&(f={mimeType:t.headers[`content-type`]??t.headers[`Content-Type`]??`text/plain`,text:t.postData}),{startedDateTime:new Date(i).toISOString(),time:c,request:{method:t.method,url:t.url,httpVersion:`HTTP/1.1`,cookies:[],headers:Object.entries(t.headers).map(([e,t])=>({name:e,value:t})),queryString:l,postData:f,headersSize:-1,bodySize:t.postData?.length??0},response:{status:n.status,statusText:n.statusText,httpVersion:`HTTP/1.1`,cookies:[],headers:Object.entries(n.headers).map(([e,t])=>({name:e,value:t})),content:d,redirectURL:n.headers.location??n.headers.Location??``,headersSize:-1,bodySize:d.size},cache:{},timings:u}}async saveSnapshot(e,t){return this.saveSnapshotWithEntries(e,t,e.entries,e.currentUrl)}async applyFilter(e,t){return c(e,t)}async saveSnapshotWithEntries(e,t,n,r){if(n.length===0)return o.debug(`No entries to save`,{recordingId:e.id,trigger:t}),null;let i=e.filterCode?await this.applyFilter(n,e.filterCode):n;if(i.length===0)return o.debug(`All entries filtered out`,{recordingId:e.id,trigger:t}),null;e.snapshotCount++;let a=new Date().toISOString().replace(/[:.]/g,`-`),s=this.urlToSlug(r),c=`${e.snapshotCount.toString().padStart(3,`0`)}-${a}-${t}-${s}.har`,l=`/recordings/${e.id}/${c}`,u={log:{version:`1.2`,creator:{name:`SLICC HAR Recorder`,version:`1.0.0`},entries:i}};return await this.fs.writeFile(l,JSON.stringify(u,null,2)),o.debug(`Saved HAR snapshot`,{recordingId:e.id,path:l,entryCount:i.length}),l}urlToSlug(e){try{let t=new URL(e);return`${t.hostname}${t.pathname}`.replace(/[^a-zA-Z0-9]/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,50)||`page`}catch{return`page`}}async stopRecording(e){let t=this.recordings.get(e);if(!t)throw Error(`Recording not found: ${e}`);await this.saveSnapshot(t,`close`);let n=this.eventCleanup.get(e);n&&(n(),this.eventCleanup.delete(e));try{await this.client.send(`Network.disable`,{},t.sessionId)}catch{}this.recordings.delete(e);let r=`/recordings/${e}`;return o.debug(`Stopped recording`,{recordingId:e,snapshotCount:t.snapshotCount}),r}getRecording(e){return this.recordings.get(e)}getRecordingByTarget(e){for(let[t,n]of this.recordings)if(n.targetId===e)return t}async ensureDir(e){await this.fs.mkdir(e,{recursive:!0})}};function c(e,t){try{let n=Function(`entry`,`return (${t})(entry);`),r=[];for(let t of e)try{let e=n(t);if(e===!1)continue;typeof e==`object`&&e?r.push(e):r.push(t)}catch(e){o.error(`Filter function error on entry, keeping it`,{error:e instanceof Error?e.message:String(e)}),r.push(t)}return r}catch(t){return o.error(`Failed to compile filter, returning unfiltered`,{error:t instanceof Error?t.message:String(t)}),e}}var l=`(function() {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
// ===== DOM Utilities =====
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as e}from"./account-store-
|
|
1
|
+
import{g as e}from"./account-store-BzCpAbzU.js";import{a as t}from"./diagnostics-DN_idNHx.js";import{u as n}from"./claude-model-version-BJLrDjmH.js";import{r,s as i}from"./legacy-api-aliases-45zvHmpJ.js";var a=`cerebras`,o=`https://api.cerebras.ai/v1`,s=`openai-completions`,c=`${a}-openai`,l=`slicc-cerebras-models`,u=[],d=[{id:`gpt-oss-120b`,name:`GPT OSS 120B`,api:`openai`,reasoning:!0,input:[`text`],context_window:131072,max_tokens:40960},{id:`gemma-4-31b`,name:`Gemma 4 31B`,api:`openai`,reasoning:!1,input:[`text`,`image`],context_window:131072,max_tokens:40960},{id:`zai-glm-4.7`,name:`Z.AI GLM-4.7`,api:`openai`,reasoning:!1,input:[`text`],context_window:131072,max_tokens:40960}];function f(e){try{localStorage.setItem(l,JSON.stringify(e))}catch{}}function p(){try{let e=localStorage.getItem(l);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)&&t.length>0?t:[]}catch{return[]}}function m(e){let t=e.id??``,n=d.find(e=>e.id===t);return{id:t,name:e.name??n?.name??t,api:`openai`,reasoning:e.capabilities?.reasoning??n?.reasoning??!1,input:e.capabilities?.vision?[`text`,`image`]:n?.input??[`text`],context_window:e.limits?.max_context_length??n?.context_window??8192,max_tokens:e.limits?.max_completion_tokens??n?.max_tokens??4096}}async function h(e){let t=await fetch(`${o}/models`,{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw Error(`GET /v1/models → ${t.status} ${t.statusText}`);let n=((await t.json()).data??[]).map(m).filter(e=>e.id.length>0);n.length>0&&(u=n,f(n))}function g(e,t){return{type:`error`,reason:`error`,error:{role:`assistant`,content:[],api:c,provider:a,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()}}}function _(e){console.error(`[cerebras] Stream error:`,e instanceof Error?e.message:String(e))}var v=(e,n,r={})=>{let i=t();return y(i,e,n,r).catch(_),i};async function y(e,t,n,i){try{let a={...t,baseUrl:o,api:s},c=r(a,n,i);for await(let t of c)e.push(t);e.end()}catch(n){_(n),e.push(g(t,n)),e.end()}}var b=(e,n,r)=>{let i=t();return x(i,e,n,r).catch(_),i};async function x(e,t,n,r){try{let a={...t,baseUrl:o,api:s},c=i(a,n,r);for await(let t of c)e.push(t);e.end()}catch(n){_(n),e.push(g(t,n)),e.end()}}var S={id:a,name:`Cerebras`,description:`Ultra-fast inference on Cerebras hardware. Get an API key at cloud.cerebras.ai.`,requiresApiKey:!0,requiresBaseUrl:!1,getModelIds:()=>{if(u.length>0)return u;let e=p();return e.length>0?e:d},refreshModels:async t=>{let n=t??e(a)??``;if(n)try{await h(n)}catch(e){console.warn(`[cerebras] Failed to refresh model list:`,e instanceof Error?e.message:String(e))}}};function C(){n({api:c,stream:v,streamSimple:b})}export{S as config,C as register};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./account-store-
|
|
1
|
+
import{a as e}from"./account-store-IBc-Swl2.js";import{a as t}from"./diagnostics-DN_idNHx.js";import{a as n}from"./compat-uEPf6-XW.js";import{r,s as i}from"./legacy-api-aliases-jKEvBgOL.js";const a=`cerebras`,o=`https://api.cerebras.ai/v1`,s=`openai-completions`,c=`${a}-openai`,l=`slicc-cerebras-models`;let u=[];const d=[{id:`gpt-oss-120b`,name:`GPT OSS 120B`,api:`openai`,reasoning:!0,input:[`text`],context_window:131072,max_tokens:40960},{id:`gemma-4-31b`,name:`Gemma 4 31B`,api:`openai`,reasoning:!1,input:[`text`,`image`],context_window:131072,max_tokens:40960},{id:`zai-glm-4.7`,name:`Z.AI GLM-4.7`,api:`openai`,reasoning:!1,input:[`text`],context_window:131072,max_tokens:40960}];function f(e){try{localStorage.setItem(l,JSON.stringify(e))}catch{}}function p(){try{let e=localStorage.getItem(l);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)&&t.length>0?t:[]}catch{return[]}}function m(e){let t=e.id??``,n=d.find(e=>e.id===t);return{id:t,name:e.name??n?.name??t,api:`openai`,reasoning:e.capabilities?.reasoning??n?.reasoning??!1,input:e.capabilities?.vision?[`text`,`image`]:n?.input??[`text`],context_window:e.limits?.max_context_length??n?.context_window??8192,max_tokens:e.limits?.max_completion_tokens??n?.max_tokens??4096}}async function h(e){let t=await fetch(`${o}/models`,{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw Error(`GET /v1/models → ${t.status} ${t.statusText}`);let n=((await t.json()).data??[]).map(m).filter(e=>e.id.length>0);n.length>0&&(u=n,f(n))}function g(e,t){return{type:`error`,reason:`error`,error:{role:`assistant`,content:[],api:c,provider:a,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()}}}function _(e){console.error(`[cerebras] Stream error:`,e instanceof Error?e.message:String(e))}const v=(e,n,r={})=>{let i=t();return y(i,e,n,r).catch(_),i};async function y(e,t,n,i){try{let a={...t,baseUrl:o,api:s},c=r(a,n,i);for await(let t of c)e.push(t);e.end()}catch(n){_(n),e.push(g(t,n)),e.end()}}const b=(e,n,r)=>{let i=t();return x(i,e,n,r).catch(_),i};async function x(e,t,n,r){try{let a={...t,baseUrl:o,api:s},c=i(a,n,r);for await(let t of c)e.push(t);e.end()}catch(n){_(n),e.push(g(t,n)),e.end()}}const S={id:a,name:`Cerebras`,description:`Ultra-fast inference on Cerebras hardware. Get an API key at cloud.cerebras.ai.`,requiresApiKey:!0,requiresBaseUrl:!1,getModelIds:()=>{if(u.length>0)return u;let e=p();return e.length>0?e:d},refreshModels:async t=>{let n=t??e(a)??``;if(n)try{await h(n)}catch(e){console.warn(`[cerebras] Failed to refresh model list:`,e instanceof Error?e.message:String(e))}}};function C(){n({api:c,stream:v,streamSimple:b})}export{S as config,C as register};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{R as e,f as t,p as n,w as r}from"./account-store-
|
|
1
|
+
import{R as e,f as t,p as n,w as r}from"./account-store-BzCpAbzU.js";import{n as i}from"./provider-settings-CGwq2ZSe.js";var a=`slicc_cloud_model_catalog`,o=`adobe`;function s(e){if(e===o)return!1;let t=r(e);return!(t.hidden||t.onOAuthLoginIntercepted)}function c(){try{let e=n().map(e=>({providerId:e.providerId,providerName:e.providerName,models:e.models.map(e=>({id:e.id,name:e.name}))}));localStorage.setItem(a,JSON.stringify(e))}catch{}}async function l(n){for(;n.firstChild;)n.removeChild(n.firstChild);n.className=`connect-surface`;let a=document.createElement(`h1`);a.className=`connect-surface__title`,a.textContent=`Connect providers`,n.appendChild(a);let l=document.createElement(`p`);l.className=`connect-surface__desc`,l.textContent=`Log in or add API keys for the providers your cone should use, then click Done to return to the dashboard.`,n.appendChild(l);let u=document.createElement(`div`);u.className=`connect-surface__accounts`,n.appendChild(u);function d(){for(;u.firstChild;)u.removeChild(u.firstChild);let n=t().filter(e=>e.providerId!==o);if(n.length===0){let e=document.createElement(`div`);e.className=`connect-surface__empty`,e.textContent=`No providers connected yet.`,u.appendChild(e)}else{let t=document.createElement(`div`);t.className=`connect-surface__accounts-list`;for(let i of n){let n=r(i.providerId),a=document.createElement(`div`);a.className=`connect-surface__account-row`;let o=document.createElement(`div`);o.className=`connect-surface__account-info`;let s=document.createElement(`div`);s.className=`connect-surface__account-name`,s.textContent=n.name,o.appendChild(s);let l=document.createElement(`div`);l.className=`connect-surface__account-detail`,l.textContent=i.userName?i.userName:i.accessToken?`Logged in`:i.apiKey?`API key set`:`No credentials`,o.appendChild(l),a.appendChild(o);let u=document.createElement(`button`);u.className=`connect-surface__remove-btn`,u.textContent=`Remove`,u.onclick=async()=>{await e(i.providerId),c(),d()},a.appendChild(u),t.appendChild(a)}u.appendChild(t)}let a=document.createElement(`button`);a.className=`connect-surface__add-btn`,a.textContent=n.length===0?`Add provider`:`Manage providers`,a.onclick=async()=>{await i({startInAddAccount:!0,providerFilter:s})&&(c(),d())},u.appendChild(a)}d(),c();let f=document.createElement(`div`);f.className=`connect-surface__footer`;let p=document.createElement(`button`);if(p.className=`connect-surface__done-btn`,p.textContent=`Done — return to dashboard`,p.onclick=()=>{c(),window.close()},f.appendChild(p),n.appendChild(f),!document.getElementById(`connect-surface-style`)){let e=document.createElement(`style`);e.id=`connect-surface-style`,e.textContent=`
|
|
2
2
|
.connect-surface {
|
|
3
3
|
padding: 2rem;
|
|
4
4
|
max-width: 560px;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mount-picker-popup--ijSfN8u.js","assets/logger-DDBAeTLF.js","assets/picker-popup-sQtXmfAo.js","assets/runtime-env-Dlaokqg1.js","assets/usb-picker-Cbm0jfjl.js","assets/serial-picker-BQF_Eitc.js","assets/hid-picker-sFJ8vzUj.js","assets/usb-device-registry-DmUBqrA-.js","assets/rolldown-runtime-Dd_uD5pT.js","assets/serial-port-registry-CCqklAEr.js","assets/hid-device-registry-B2R-0rNt.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{
|
|
2
|
+
import{n as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./preload-helper-Czpn1I53.js";import{a as n,i as r,n as i}from"./sprinkle-renderer-Ce6YjEek.js";import{n as a}from"./runtime-env-Dlaokqg1.js";import{t as o}from"./permissions-surface-registry-CilCRwhh.js";import{n as s,r as c}from"./hid-device-registry-B2R-0rNt.js";import{a as l,i as u}from"./serial-port-registry-CCqklAEr.js";import{A as d,C as f,D as ee,O as te,S as p,T as m,_ as ne,b as re,c as ie,g as ae,h as oe,o as se,r as ce,s as le,u as ue,v as h,w as de}from"./usb-operations-BsAiCAWF.js";import{i as fe,r as g}from"./usb-device-registry-DmUBqrA-.js";import{n as pe}from"./sprinkle-bridge-CeRz-DjR.js";import{a as _,n as v,r as y}from"./theme-CXRqxpw6.js";var me=e({broadcastToDips:()=>L,disposeDips:()=>X,handleDipPickerAction:()=>Z,hydrateDips:()=>Y,mountDip:()=>K,setDipExecHandler:()=>_e}),b=a();function he(e){if(typeof e!=`object`||!e||Array.isArray(e))return[];let t=e.filters;return Array.isArray(t)?t:[]}async function x(e,t){if(t?.aborted)throw new DOMException(`aborted`,`AbortError`);let n=await C(e,!0,t);if(t?.aborted)throw new DOMException(`aborted`,`AbortError`);if(n===null)throw Error(`VFS read failed: ${e}`);return typeof n==`string`?n:new TextDecoder().decode(n)}var S=null;function ge(){if(S)return S;if(typeof BroadcastChannel>`u`)return null;try{S=new BroadcastChannel(`preview-vfs`)}catch{return null}return S}async function C(e,t,n){let r=ge();if(!r)return null;let i=`dip-${Date.now()}-${Math.random().toString(36).slice(2)}`;return new Promise(a=>{let o=!1,s=()=>{r.removeEventListener(`message`,c),n?.removeEventListener(`abort`,l)},c=e=>{if(!o&&e.data?.type===`preview-vfs-response`&&e.data.id===i){if(o=!0,s(),e.data.error){a(null);return}a(e.data.content??null)}},l=()=>{o||(o=!0,s(),a(null))};r.addEventListener(`message`,c),n?.addEventListener(`abort`,l),setTimeout(()=>{o||(o=!0,s(),a(null))},5e3),r.postMessage({type:`preview-vfs-read`,id:i,path:e,asText:t})})}var w=[`/shared/sprinkles/`,`/workspace/skills/sprinkles/`,`/workspace/sprinkles/`],T=[`/shared/`,`/workspace/skills/sprinkles/`,`/workspace/sprinkles/`];function E(e){return w.some(t=>e.startsWith(t))}function D(e){return typeof e!=`string`||!e.startsWith(`/`)||e.includes(`..`)?!1:T.some(t=>e.startsWith(t))}var O=new WeakSet,k=`,
|
|
3
3
|
exec: Object.assign(function(cmd) {
|
|
4
4
|
return _vfsCall('dip-exec', { cmd: cmd }, function(m) { return m.result; });
|
|
5
5
|
}, { spawn: function(argv) {
|
|
@@ -218,10 +218,10 @@ mark{background:color-mix(in srgb,var(--s2-accent) 25%,transparent);color:inheri
|
|
|
218
218
|
try { window.lucide.createIcons(); } catch(ex){}
|
|
219
219
|
}
|
|
220
220
|
});
|
|
221
|
-
})();`;function F(e,t,n=!1){let i
|
|
221
|
+
})();`;function F(e,t,n=!1){let r=i(),a=v()?` class="theme-light"`:``,o=t||e.includes(`<slicc-editor`),s=t||e.includes(`<slicc-diff`),c=t?`<script>${P}<\/script>`:``;return`<!DOCTYPE html>
|
|
222
222
|
<html${a}><head>
|
|
223
223
|
<meta charset="utf-8">
|
|
224
|
-
<style>${
|
|
224
|
+
<style>${r}</style>
|
|
225
225
|
<style>${N}</style>
|
|
226
226
|
<script>${M(n&&!t)}<\/script>
|
|
227
227
|
${c}
|
|
@@ -230,4 +230,4 @@ ${s?`<script src="/slicc-diff.js"><\/script>`:``}
|
|
|
230
230
|
<script src="/lucide-icons.js"><\/script>
|
|
231
231
|
</head>
|
|
232
232
|
<body class="sprinkle-inline">${e}</body></html>`}var I=new Set;function L(e){if(typeof e?.type!=`string`||e.type.indexOf(`slicc-`)!==0)throw Error(`broadcastToDips: payload.type must start with 'slicc-'`);for(let t of I)try{t.postMessage(e,`*`)}catch{}}var R;function _e(e){R=e}function z(e){return e.length===0?`''`:`'${e.replace(/'/g,`'\\''`)}'`}function ve(e,t){let n=t?.cwd??`.`,r=t?.allowedCommands??`*`,i=[`agent`];return t?.model&&i.push(`--model`,z(t.model)),t?.thinking&&i.push(`--thinking`,z(t.thinking)),t?.readOnly&&i.push(`--read-only`,z(t.readOnly)),i.push(z(n),z(r),z(e)),i.join(` `)}async function B(e){if(!R)return{stdout:``,stderr:`exec: shell bridge not available
|
|
233
|
-
`,exitCode:127};try{return await R(e)}catch(e){return{stdout:``,stderr:`exec: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}async function ye(e,t){let n=await B(ve(e,t));return{stdout:n.stdout||n.stderr,exitCode:n.exitCode}}async function be(e,t){let n=await pe(B,e,t);if(e===`fetch`){let e=n,t=atob(e.bodyBase64),r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);return{...e,body:new TextDecoder(`utf-8`).decode(r)}}return n}var V=new WeakMap;function H(e,t){try{e.postMessage({type:`dip-device-event`,channel:`hid:inputreport`,payload:t},`*`)}catch{}}async function xe(e,t){let n=V.get(e);if(n||(n=new Map,V.set(e,n)),n.has(t))return;let r=await f(c(),t,n=>{let r=n.bytes instanceof Uint8Array?n.bytes:new Uint8Array(n.bytes);H(e,{handle:t,reportId:n.reportId,data:r})});n.set(t,r)}async function Se(e,t){let n=V.get(e);if(!n)return;let r=n.get(t);if(r){n.delete(t);try{await Promise.resolve(r())}catch{}}n.size===0&&V.delete(e)}function U(e){let t=V.get(e);if(t){for(let e of t.values())try{Promise.resolve(e()).catch(()=>{})}catch{}V.delete(e)}}function Ce(e){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e)){let t=e;return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}if(Array.isArray(e))return new Uint8Array(e);throw Error(`expected Uint8Array, ArrayBuffer, or number[]`)}async function we(e,t,n){let r=c();switch(t){case`list`:{let e=s();if(!e)throw Error(`WebHID is unavailable in this browser`);return ne(r,e)}case`request`:{let e=s();if(!e)throw Error(`WebHID is unavailable in this browser`);return re(r,e,n[0]??[])}case`info`:return ae(r,n[0]);case`open`:{let t=n[0];return await h(r,t),await xe(e,t),{ok:!0}}case`close`:{let t=n[0];return await Se(e,t),await oe(r,t),{ok:!0}}case`sendReport`:{let e=n[0],t=n[1],i=Ce(n[2]),a=i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength);return await p(r,e,t,a),{ok:!0}}default:throw Error(`hid: unknown op '${t}'`)}}async function Te(e,t){let n=l();switch(e){case`list`:{let e=u();if(!e)throw Error(`Web Serial is unavailable in this browser`);return ee(n,e)}case`request`:{let e=u();if(!e)throw Error(`Web Serial is unavailable in this browser`);return d(n,e,t[0]??[])}case`info`:return m(n,t[0]);case`open`:{let e=t[0],r=t[1]??{baudRate:9600};return await te(n,e,r),{ok:!0}}case`close`:return await de(n,t[0]),{ok:!0};default:throw Error(`serial: unknown op '${e}'`)}}async function Ee(e,t){let n=fe();switch(e){case`list`:{let e=g();if(!e)throw Error(`WebUSB is unavailable in this browser`);return le(n,e)}case`request`:{let e=g();if(!e)throw Error(`WebUSB is unavailable in this browser`);return ue(n,e,t[0]??[])}case`info`:return se(n,t[0]);case`open`:return await ie(n,t[0]),{ok:!0};case`close`:return await ce(n,t[0]),{ok:!0};default:throw Error(`usb: unknown op '${e}'`)}}async function De(e,t,n,r){switch(t){case`hid`:return we(e,n,r);case`serial`:return Te(n,r);case`usb`:return Ee(n,r);default:throw Error(`unknown device channel '${t}'`)}}async function W(e,t){if(!e||typeof t.id!=`number`)return!1;let n=n=>{try{e.postMessage({...n,id:t.id},`*`)}catch{}};if(!O.has(e))return n({type:`dip-device-op-response`,error:`device access not allowed for this dip`}),!0;let r=t.channel;if(r!==`hid`&&r!==`serial`&&r!==`usb`)return n({type:`dip-device-op-response`,error:`unknown device channel '${r}'`}),!0;try{n({type:`dip-device-op-response`,result:await De(e,r,typeof t.op==`string`?t.op:``,Array.isArray(t.args)?t.args:[])})}catch(e){n({type:`dip-device-op-response`,error:e instanceof Error?e.message:String(e)})}return!0}async function G(e,t){if(!e||typeof t.id!=`number`)return!1;let n=n=>{try{e.postMessage({...n,id:t.id},`*`)}catch{}};if(!O.has(e))return n({type:`${t.type}-response`,error:`exec not allowed for this dip`}),!0;if(t.type===`dip-exec`)return n({type:`dip-exec-response`,result:await B(typeof t.cmd==`string`?t.cmd:``)}),!0;if(t.type===`dip-agent`)return n({type:`dip-agent-response`,result:await ye(typeof t.prompt==`string`?t.prompt:``,t.opts)}),!0;if(t.type===`dip-jsh`){try{n({type:`dip-jsh-response`,result:await be(typeof t.op==`string`?t.op:``,Array.isArray(t.args)?t.args:[])})}catch(e){n({type:`dip-jsh-response`,error:e instanceof Error?e.message:String(e)})}return!0}return!1}function K(e,t,r,a=!1){let o=F(t,!1,a);if(b)return Ne(e,o,r,a);let s=document.createElement(`iframe`);s.setAttribute(`sandbox`,`allow-scripts allow-same-origin`),s.style.cssText=`width:100%;border:none;overflow:hidden;display:block;`,s.srcdoc=o,e.appendChild(s),s.contentWindow&&(y(s.contentWindow),I.add(s.contentWindow),a&&O.add(s.contentWindow)),s.addEventListener(`load`,()=>{y(s.contentWindow),s.contentWindow&&(I.add(s.contentWindow),a&&O.add(s.contentWindow)),i()&&n(s)},{once:!0});let c=e=>{if(e.source!==s.contentWindow)return;let t=e.data;t?.type&&(t.type===`dip-lick`?r(t.action,t.data):t.type===`dip-height`?s.style.height=t.height+`px`:t.type===`dip-open-link`?J(t.url):t.type===`dip-picker-action`?Z(t,r):t.type===`dip-readfile`||t.type===`dip-exists`||t.type===`dip-stat`?q(s.contentWindow,t):t.type===`dip-exec`||t.type===`dip-agent`||t.type===`dip-jsh`?G(s.contentWindow,t):t.type===`dip-device-op`&&W(s.contentWindow,t))};window.addEventListener(`message`,c);let l=null;if(i()&&typeof IntersectionObserver<`u`){let e=!1,t=new IntersectionObserver(r=>{if(r[r.length-1].isIntersecting){if(e){e=!1;return}t.unobserve(s),n(s,()=>{e=!0,t.observe(s)})}});l=t,t.observe(s)}return{dispose(){l?.disconnect(),window.removeEventListener(`message`,c),_(s.contentWindow),s.contentWindow&&(I.delete(s.contentWindow),O.delete(s.contentWindow),U(s.contentWindow)),s.remove()}}}async function q(e,t){if(!e||typeof t.id!=`number`)return!1;let n=typeof t.path==`string`?t.path:``,r=n=>{try{e.postMessage({...n,id:t.id},`*`)}catch{}};if(!O.has(e))return r({type:`${t.type}-response`,error:`VFS access not allowed for this dip`}),!0;if(!D(n))return r({type:`${t.type}-response`,error:`VFS path not allowed: ${n}`}),!0;if(t.type===`dip-readfile`){let e=await C(n,!0);return e===null?(r({type:`dip-readfile-response`,error:`Read failed`}),!0):(r({type:`dip-readfile-response`,content:typeof e==`string`?e:new TextDecoder().decode(e)}),!0)}if(t.type===`dip-exists`)return r({type:`dip-exists-response`,exists:await C(n,!0)!==null}),!0;if(t.type===`dip-stat`){let e=await C(n,!1);return e===null?(r({type:`dip-stat-response`,error:`Stat failed`}),!0):(r({type:`dip-stat-response`,stat:{isFile:!0,isDirectory:!1,size:typeof e==`string`?e.length:e.byteLength,mtimeMs:0}}),!0)}return!1}function J(e){if(!(typeof e!=`string`||!e)&&/^(https?:|mailto:)/i.test(e))try{window.open(e,`_blank`,`noopener,noreferrer`)}catch{}}function Y(e,t){let n=[],r=e.querySelectorAll(`pre > code.language-shtml`);for(let e of r){let r=e.parentElement,i=e.textContent??``,a=document.createElement(`div`);a.className=`msg__dip`,r.replaceWith(a),n.push(K(a,i,t,!1))}let i=e.querySelectorAll(`img[src$=".shtml"]`);for(let e of i){let r=e.getAttribute(`src`);if(!r)continue;let i=document.createElement(`div`);i.className=`msg__dip`,e.alt&&i.setAttribute(`title`,e.alt),e.replaceWith(i);let a=new AbortController,o=null,s=!1;n.push({dispose(){s=!0,a.abort(),o&&=(o.dispose(),null)}});let c=r.startsWith(`/`),l=typeof navigator<`u`&&!!navigator.serviceWorker?.controller,u=c?`/preview${r}`:r,d=async()=>{if(c&&!l)return x(r,a.signal);let e;try{e=await fetch(u,{signal:a.signal})}catch(e){if(e?.name===`AbortError`)throw e;if(c)return x(r,a.signal);throw e}if(e.ok)return e.text();if(c)return x(r,a.signal);throw Error(`HTTP ${e.status}`)},f=c&&E(r);d().then(e=>{s||!i.isConnected||(o=K(i,e,t,f))}).catch(e=>{s||e?.name===`AbortError`||(i.textContent=`Failed to load dip: ${r}`,i.style.cssText=`padding:8px;font-size:12px;color:var(--s2-negative);font-family:var(--s2-font-mono)`)})}return n}function X(e){for(let t of e)try{t.dispose()}catch{}e.length=0}async function Z(e,t){let n=he(e.data);if(b){await Oe(e.picker,e.action,n,t);return}switch(e.picker){case`directory`:await ke(e.action,t);return;case`usb-device`:await Ae(e.action,n,t);return;case`serial-port`:await je(e.action,n,t);return;case`hid-device`:await Me(e.action,n,t);return;default:t(e.action,e.data);return}}async function Oe(e,n,r,i){try{switch(e){case`directory`:{let{openMountPickerPopup:e}=await t(async()=>{let{openMountPickerPopup:e}=await import(`./mount-picker-popup--ijSfN8u.js`);return{openMountPickerPopup:e}},__vite__mapDeps([0,1,2,3])),r=await e();r.cancelled?i(n,{cancelled:!0}):r.error?i(n,{error:r.error}):r.idbKey?i(n,{handleInIdb:!0,idbKey:r.idbKey,dirName:r.dirName??``}):i(n,{error:`mount picker returned no handle key`});return}case`usb-device`:{let{openUsbPickerPopup:e}=await t(async()=>{let{openUsbPickerPopup:e}=await import(`./usb-picker-Cbm0jfjl.js`);return{openUsbPickerPopup:e}},__vite__mapDeps([4,2,3])),a=await e(r);`cancelled`in a?i(n,{cancelled:!0}):`error`in a?i(n,{error:a.error}):i(n,{granted:!0,info:a.info});return}case`serial-port`:{let{openSerialPickerPopup:e}=await t(async()=>{let{openSerialPickerPopup:e}=await import(`./serial-picker-BQF_Eitc.js`);return{openSerialPickerPopup:e}},__vite__mapDeps([5,2,3])),a=await e(r);`cancelled`in a?i(n,{cancelled:!0}):`error`in a?i(n,{error:a.error}):i(n,{granted:!0,info:a.info});return}case`hid-device`:{let{openHidPickerPopup:e}=await t(async()=>{let{openHidPickerPopup:e}=await import(`./hid-picker-sFJ8vzUj.js`);return{openHidPickerPopup:e}},__vite__mapDeps([6,2,3])),a=await e(r);`cancelled`in a?i(n,{cancelled:!0}):`error`in a?i(n,{error:a.error}):i(n,{granted:!0,info:a.info});return}default:i(n,{error:`unknown picker kind: ${e??`(none)`}`});return}}catch(e){i(n,{error:e instanceof Error?e.message:String(e)})}}async function Q(e,t){let n=o();if(!n)return null;let r={current:null},i=t=>{let n=t.detail;n.kind===e&&(r.current=n)};n.addEventListener(`slicc-permission-deny`,i);try{let i=await n.request(e,t);if(i)return{ok:!0,grant:i};let a=r.current;return{ok:!1,reason:a?.reason??`error`,...a?.message?{message:a.message}:{}}}finally{n.removeEventListener(`slicc-permission-deny`,i)}}function $(e,t,n,r){if(t.reason===`cancelled`){r(e,{cancelled:!0});return}if(t.reason===`unavailable`){r(e,{error:n});return}r(e,{error:t.message??`unknown error`})}async function ke(e,n){let r=await Q(`filesystem`);if(!r){n(e,{error:`File System Access API not available`});return}if(!r.ok){$(e,r,`File System Access API not available`,n);return}let i=r.grant.handle,a=`pendingMount:dip-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;try{let{storePendingHandle:e}=await t(async()=>{let{storePendingHandle:e}=await import(`./mount-picker-popup--ijSfN8u.js`);return{storePendingHandle:e}},__vite__mapDeps([0,1,2,3]));await e(a,i)}catch(t){n(e,{error:`failed to store directory handle: ${t instanceof Error?t.message:String(t)}`});return}n(e,{handleInIdb:!0,idbKey:a,dirName:i.name})}async function Ae(e,n,r){let i=await Q(`usb`,{filters:n});if(!i){r(e,{error:`WebUSB is not available`});return}if(!i.ok){$(e,i,`WebUSB is not available`,r);return}let a=i.grant,{getSharedUsbRegistry:o,deviceToInfo:s}=await t(async()=>{let{getSharedUsbRegistry:e,deviceToInfo:t}=await import(`./usb-device-registry-DmUBqrA-.js`).then(e=>e.a);return{getSharedUsbRegistry:e,deviceToInfo:t}},__vite__mapDeps([7,8])),c=o().register(a.device);r(e,{granted:!0,handle:c,info:s(c,a.device)})}async function je(e,n,r){let i=await Q(`serial`,n.length?{filters:n}:void 0);if(!i){r(e,{error:`Web Serial is not available`});return}if(!i.ok){$(e,i,`Web Serial is not available`,r);return}let a=i.grant,o=await t(()=>import(`./serial-port-registry-CCqklAEr.js`).then(e=>e.o),__vite__mapDeps([9,8])),s=o.getSharedSerialRegistry(),c=s.register(a.port),l=s.get(c);r(e,{granted:!0,handle:c,info:l?o.deviceToInfo(c,l):{handle:c}})}async function Me(e,n,r){let i=await Q(`hid`,{filters:n});if(!i){r(e,{error:`WebHID is not available`});return}if(!i.ok){$(e,i,`WebHID is not available`,r);return}let a=i.grant,{getSharedHidRegistry:o,hidDeviceToInfo:s}=await t(async()=>{let{getSharedHidRegistry:e,hidDeviceToInfo:t}=await import(`./hid-device-registry-B2R-0rNt.js`).then(e=>e.a);return{getSharedHidRegistry:e,hidDeviceToInfo:t}},__vite__mapDeps([10,8])),c=o(),l=a.devices.map(e=>{let t=c.register(e);return s(t,e)}),u=l[0];r(e,{granted:!0,handle:u.handle,info:u,devices:l})}function Ne(e,t,n,r=!1){let i=document.createElement(`iframe`);i.src=chrome.runtime.getURL(`sprinkle-sandbox.html`),i.style.cssText=`width:100%;border:none;overflow:hidden;display:block;`,e.appendChild(i);let a=e=>{if(e.source!==i.contentWindow)return;let t=e.data;t?.type&&(t.type===`dip-lick`?n(t.action,t.data):t.type===`dip-height`?i.style.height=t.height+`px`:t.type===`dip-open-link`?J(t.url):t.type===`dip-readfile`||t.type===`dip-exists`||t.type===`dip-stat`?q(i.contentWindow,t):t.type===`dip-exec`||t.type===`dip-agent`||t.type===`dip-jsh`?G(i.contentWindow,t):t.type===`dip-device-op`?W(i.contentWindow,t):t.type===`dip-picker-action`&&Z(t,n))};return window.addEventListener(`message`,a),i.addEventListener(`load`,()=>{y(i.contentWindow),i.contentWindow&&(I.add(i.contentWindow),r&&O.add(i.contentWindow)),i.contentWindow?.postMessage({type:`dip-render`,srcdoc:t,isLight:v()},`*`)},{once:!0}),{dispose(){window.removeEventListener(`message`,a),_(i.contentWindow),i.contentWindow&&(I.delete(i.contentWindow),O.delete(i.contentWindow),U(i.contentWindow)),i.remove()}}}export{K as a,Y as i,me as n,X as r,L as t};
|
|
233
|
+
`,exitCode:127};try{return await R(e)}catch(e){return{stdout:``,stderr:`exec: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}async function ye(e,t){let n=await B(ve(e,t));return{stdout:n.stdout||n.stderr,exitCode:n.exitCode}}async function be(e,t){let n=await pe(B,e,t);if(e===`fetch`){let e=n,t=atob(e.bodyBase64),r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);return{...e,body:new TextDecoder(`utf-8`).decode(r)}}return n}var V=new WeakMap;function H(e,t){try{e.postMessage({type:`dip-device-event`,channel:`hid:inputreport`,payload:t},`*`)}catch{}}async function xe(e,t){let n=V.get(e);if(n||(n=new Map,V.set(e,n)),n.has(t))return;let r=await f(c(),t,n=>{let r=n.bytes instanceof Uint8Array?n.bytes:new Uint8Array(n.bytes);H(e,{handle:t,reportId:n.reportId,data:r})});n.set(t,r)}async function Se(e,t){let n=V.get(e);if(!n)return;let r=n.get(t);if(r){n.delete(t);try{await Promise.resolve(r())}catch{}}n.size===0&&V.delete(e)}function U(e){let t=V.get(e);if(t){for(let e of t.values())try{Promise.resolve(e()).catch(()=>{})}catch{}V.delete(e)}}function Ce(e){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e)){let t=e;return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}if(Array.isArray(e))return new Uint8Array(e);throw Error(`expected Uint8Array, ArrayBuffer, or number[]`)}async function we(e,t,n){let r=c();switch(t){case`list`:{let e=s();if(!e)throw Error(`WebHID is unavailable in this browser`);return ne(r,e)}case`request`:{let e=s();if(!e)throw Error(`WebHID is unavailable in this browser`);return re(r,e,n[0]??[])}case`info`:return ae(r,n[0]);case`open`:{let t=n[0];return await h(r,t),await xe(e,t),{ok:!0}}case`close`:{let t=n[0];return await Se(e,t),await oe(r,t),{ok:!0}}case`sendReport`:{let e=n[0],t=n[1],i=Ce(n[2]),a=i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength);return await p(r,e,t,a),{ok:!0}}default:throw Error(`hid: unknown op '${t}'`)}}async function Te(e,t){let n=l();switch(e){case`list`:{let e=u();if(!e)throw Error(`Web Serial is unavailable in this browser`);return ee(n,e)}case`request`:{let e=u();if(!e)throw Error(`Web Serial is unavailable in this browser`);return d(n,e,t[0]??[])}case`info`:return m(n,t[0]);case`open`:{let e=t[0],r=t[1]??{baudRate:9600};return await te(n,e,r),{ok:!0}}case`close`:return await de(n,t[0]),{ok:!0};default:throw Error(`serial: unknown op '${e}'`)}}async function Ee(e,t){let n=fe();switch(e){case`list`:{let e=g();if(!e)throw Error(`WebUSB is unavailable in this browser`);return le(n,e)}case`request`:{let e=g();if(!e)throw Error(`WebUSB is unavailable in this browser`);return ue(n,e,t[0]??[])}case`info`:return se(n,t[0]);case`open`:return await ie(n,t[0]),{ok:!0};case`close`:return await ce(n,t[0]),{ok:!0};default:throw Error(`usb: unknown op '${e}'`)}}async function De(e,t,n,r){switch(t){case`hid`:return we(e,n,r);case`serial`:return Te(n,r);case`usb`:return Ee(n,r);default:throw Error(`unknown device channel '${t}'`)}}async function W(e,t){if(!e||typeof t.id!=`number`)return!1;let n=n=>{try{e.postMessage({...n,id:t.id},`*`)}catch{}};if(!O.has(e))return n({type:`dip-device-op-response`,error:`device access not allowed for this dip`}),!0;let r=t.channel;if(r!==`hid`&&r!==`serial`&&r!==`usb`)return n({type:`dip-device-op-response`,error:`unknown device channel '${r}'`}),!0;try{n({type:`dip-device-op-response`,result:await De(e,r,typeof t.op==`string`?t.op:``,Array.isArray(t.args)?t.args:[])})}catch(e){n({type:`dip-device-op-response`,error:e instanceof Error?e.message:String(e)})}return!0}async function G(e,t){if(!e||typeof t.id!=`number`)return!1;let n=n=>{try{e.postMessage({...n,id:t.id},`*`)}catch{}};if(!O.has(e))return n({type:`${t.type}-response`,error:`exec not allowed for this dip`}),!0;if(t.type===`dip-exec`)return n({type:`dip-exec-response`,result:await B(typeof t.cmd==`string`?t.cmd:``)}),!0;if(t.type===`dip-agent`)return n({type:`dip-agent-response`,result:await ye(typeof t.prompt==`string`?t.prompt:``,t.opts)}),!0;if(t.type===`dip-jsh`){try{n({type:`dip-jsh-response`,result:await be(typeof t.op==`string`?t.op:``,Array.isArray(t.args)?t.args:[])})}catch(e){n({type:`dip-jsh-response`,error:e instanceof Error?e.message:String(e)})}return!0}return!1}function K(e,t,i,a=!1){let o=F(t,!1,a);if(b)return Ne(e,o,i,a);let s=document.createElement(`iframe`);s.setAttribute(`sandbox`,`allow-scripts allow-same-origin`),s.style.cssText=`width:100%;border:none;overflow:hidden;display:block;`,s.srcdoc=o,e.appendChild(s),s.contentWindow&&(y(s.contentWindow),I.add(s.contentWindow),a&&O.add(s.contentWindow)),s.addEventListener(`load`,()=>{y(s.contentWindow),s.contentWindow&&(I.add(s.contentWindow),a&&O.add(s.contentWindow)),r()&&n(s)},{once:!0});let c=e=>{if(e.source!==s.contentWindow)return;let t=e.data;t?.type&&(t.type===`dip-lick`?i(t.action,t.data):t.type===`dip-height`?s.style.height=t.height+`px`:t.type===`dip-open-link`?J(t.url):t.type===`dip-picker-action`?Z(t,i):t.type===`dip-readfile`||t.type===`dip-exists`||t.type===`dip-stat`?q(s.contentWindow,t):t.type===`dip-exec`||t.type===`dip-agent`||t.type===`dip-jsh`?G(s.contentWindow,t):t.type===`dip-device-op`&&W(s.contentWindow,t))};window.addEventListener(`message`,c);let l=null;if(r()&&typeof IntersectionObserver<`u`){let e=!1,t=new IntersectionObserver(r=>{if(r[r.length-1].isIntersecting){if(e){e=!1;return}t.unobserve(s),n(s,()=>{e=!0,t.observe(s)})}});l=t,t.observe(s)}return{dispose(){l?.disconnect(),window.removeEventListener(`message`,c),_(s.contentWindow),s.contentWindow&&(I.delete(s.contentWindow),O.delete(s.contentWindow),U(s.contentWindow)),s.remove()}}}async function q(e,t){if(!e||typeof t.id!=`number`)return!1;let n=typeof t.path==`string`?t.path:``,r=n=>{try{e.postMessage({...n,id:t.id},`*`)}catch{}};if(!O.has(e))return r({type:`${t.type}-response`,error:`VFS access not allowed for this dip`}),!0;if(!D(n))return r({type:`${t.type}-response`,error:`VFS path not allowed: ${n}`}),!0;if(t.type===`dip-readfile`){let e=await C(n,!0);return e===null?(r({type:`dip-readfile-response`,error:`Read failed`}),!0):(r({type:`dip-readfile-response`,content:typeof e==`string`?e:new TextDecoder().decode(e)}),!0)}if(t.type===`dip-exists`)return r({type:`dip-exists-response`,exists:await C(n,!0)!==null}),!0;if(t.type===`dip-stat`){let e=await C(n,!1);return e===null?(r({type:`dip-stat-response`,error:`Stat failed`}),!0):(r({type:`dip-stat-response`,stat:{isFile:!0,isDirectory:!1,size:typeof e==`string`?e.length:e.byteLength,mtimeMs:0}}),!0)}return!1}function J(e){if(!(typeof e!=`string`||!e)&&/^(https?:|mailto:)/i.test(e))try{window.open(e,`_blank`,`noopener,noreferrer`)}catch{}}function Y(e,t){let n=[],r=e.querySelectorAll(`pre > code.language-shtml`);for(let e of r){let r=e.parentElement,i=e.textContent??``,a=document.createElement(`div`);a.className=`msg__dip`,r.replaceWith(a),n.push(K(a,i,t,!1))}let i=e.querySelectorAll(`img[src$=".shtml"]`);for(let e of i){let r=e.getAttribute(`src`);if(!r)continue;let i=document.createElement(`div`);i.className=`msg__dip`,e.alt&&i.setAttribute(`title`,e.alt),e.replaceWith(i);let a=new AbortController,o=null,s=!1;n.push({dispose(){s=!0,a.abort(),o&&=(o.dispose(),null)}});let c=r.startsWith(`/`),l=typeof navigator<`u`&&!!navigator.serviceWorker?.controller,u=c?`/preview${r}`:r,d=async()=>{if(c&&!l)return x(r,a.signal);let e;try{e=await fetch(u,{signal:a.signal})}catch(e){if(e?.name===`AbortError`)throw e;if(c)return x(r,a.signal);throw e}if(e.ok)return e.text();if(c)return x(r,a.signal);throw Error(`HTTP ${e.status}`)},f=c&&E(r);d().then(e=>{s||!i.isConnected||(o=K(i,e,t,f))}).catch(e=>{s||e?.name===`AbortError`||(i.textContent=`Failed to load dip: ${r}`,i.style.cssText=`padding:8px;font-size:12px;color:var(--s2-negative);font-family:var(--s2-font-mono)`)})}return n}function X(e){for(let t of e)try{t.dispose()}catch{}e.length=0}async function Z(e,t){let n=he(e.data);if(b){await Oe(e.picker,e.action,n,t);return}switch(e.picker){case`directory`:await ke(e.action,t);return;case`usb-device`:await Ae(e.action,n,t);return;case`serial-port`:await je(e.action,n,t);return;case`hid-device`:await Me(e.action,n,t);return;default:t(e.action,e.data);return}}async function Oe(e,n,r,i){try{switch(e){case`directory`:{let{openMountPickerPopup:e}=await t(async()=>{let{openMountPickerPopup:e}=await import(`./mount-picker-popup--ijSfN8u.js`);return{openMountPickerPopup:e}},__vite__mapDeps([0,1,2,3])),r=await e();r.cancelled?i(n,{cancelled:!0}):r.error?i(n,{error:r.error}):r.idbKey?i(n,{handleInIdb:!0,idbKey:r.idbKey,dirName:r.dirName??``}):i(n,{error:`mount picker returned no handle key`});return}case`usb-device`:{let{openUsbPickerPopup:e}=await t(async()=>{let{openUsbPickerPopup:e}=await import(`./usb-picker-Cbm0jfjl.js`);return{openUsbPickerPopup:e}},__vite__mapDeps([4,2,3])),a=await e(r);`cancelled`in a?i(n,{cancelled:!0}):`error`in a?i(n,{error:a.error}):i(n,{granted:!0,info:a.info});return}case`serial-port`:{let{openSerialPickerPopup:e}=await t(async()=>{let{openSerialPickerPopup:e}=await import(`./serial-picker-BQF_Eitc.js`);return{openSerialPickerPopup:e}},__vite__mapDeps([5,2,3])),a=await e(r);`cancelled`in a?i(n,{cancelled:!0}):`error`in a?i(n,{error:a.error}):i(n,{granted:!0,info:a.info});return}case`hid-device`:{let{openHidPickerPopup:e}=await t(async()=>{let{openHidPickerPopup:e}=await import(`./hid-picker-sFJ8vzUj.js`);return{openHidPickerPopup:e}},__vite__mapDeps([6,2,3])),a=await e(r);`cancelled`in a?i(n,{cancelled:!0}):`error`in a?i(n,{error:a.error}):i(n,{granted:!0,info:a.info});return}default:i(n,{error:`unknown picker kind: ${e??`(none)`}`});return}}catch(e){i(n,{error:e instanceof Error?e.message:String(e)})}}async function Q(e,t){let n=o();if(!n)return null;let r={current:null},i=t=>{let n=t.detail;n.kind===e&&(r.current=n)};n.addEventListener(`slicc-permission-deny`,i);try{let i=await n.request(e,t);if(i)return{ok:!0,grant:i};let a=r.current;return{ok:!1,reason:a?.reason??`error`,...a?.message?{message:a.message}:{}}}finally{n.removeEventListener(`slicc-permission-deny`,i)}}function $(e,t,n,r){if(t.reason===`cancelled`){r(e,{cancelled:!0});return}if(t.reason===`unavailable`){r(e,{error:n});return}r(e,{error:t.message??`unknown error`})}async function ke(e,n){let r=await Q(`filesystem`);if(!r){n(e,{error:`File System Access API not available`});return}if(!r.ok){$(e,r,`File System Access API not available`,n);return}let i=r.grant.handle,a=`pendingMount:dip-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;try{let{storePendingHandle:e}=await t(async()=>{let{storePendingHandle:e}=await import(`./mount-picker-popup--ijSfN8u.js`);return{storePendingHandle:e}},__vite__mapDeps([0,1,2,3]));await e(a,i)}catch(t){n(e,{error:`failed to store directory handle: ${t instanceof Error?t.message:String(t)}`});return}n(e,{handleInIdb:!0,idbKey:a,dirName:i.name})}async function Ae(e,n,r){let i=await Q(`usb`,{filters:n});if(!i){r(e,{error:`WebUSB is not available`});return}if(!i.ok){$(e,i,`WebUSB is not available`,r);return}let a=i.grant,{getSharedUsbRegistry:o,deviceToInfo:s}=await t(async()=>{let{getSharedUsbRegistry:e,deviceToInfo:t}=await import(`./usb-device-registry-DmUBqrA-.js`).then(e=>e.a);return{getSharedUsbRegistry:e,deviceToInfo:t}},__vite__mapDeps([7,8])),c=o().register(a.device);r(e,{granted:!0,handle:c,info:s(c,a.device)})}async function je(e,n,r){let i=await Q(`serial`,n.length?{filters:n}:void 0);if(!i){r(e,{error:`Web Serial is not available`});return}if(!i.ok){$(e,i,`Web Serial is not available`,r);return}let a=i.grant,o=await t(()=>import(`./serial-port-registry-CCqklAEr.js`).then(e=>e.o),__vite__mapDeps([9,8])),s=o.getSharedSerialRegistry(),c=s.register(a.port),l=s.get(c);r(e,{granted:!0,handle:c,info:l?o.deviceToInfo(c,l):{handle:c}})}async function Me(e,n,r){let i=await Q(`hid`,{filters:n});if(!i){r(e,{error:`WebHID is not available`});return}if(!i.ok){$(e,i,`WebHID is not available`,r);return}let a=i.grant,{getSharedHidRegistry:o,hidDeviceToInfo:s}=await t(async()=>{let{getSharedHidRegistry:e,hidDeviceToInfo:t}=await import(`./hid-device-registry-B2R-0rNt.js`).then(e=>e.a);return{getSharedHidRegistry:e,hidDeviceToInfo:t}},__vite__mapDeps([10,8])),c=o(),l=a.devices.map(e=>{let t=c.register(e);return s(t,e)}),u=l[0];r(e,{granted:!0,handle:u.handle,info:u,devices:l})}function Ne(e,t,n,r=!1){let i=document.createElement(`iframe`);i.src=chrome.runtime.getURL(`sprinkle-sandbox.html`),i.style.cssText=`width:100%;border:none;overflow:hidden;display:block;`,e.appendChild(i);let a=e=>{if(e.source!==i.contentWindow)return;let t=e.data;t?.type&&(t.type===`dip-lick`?n(t.action,t.data):t.type===`dip-height`?i.style.height=t.height+`px`:t.type===`dip-open-link`?J(t.url):t.type===`dip-readfile`||t.type===`dip-exists`||t.type===`dip-stat`?q(i.contentWindow,t):t.type===`dip-exec`||t.type===`dip-agent`||t.type===`dip-jsh`?G(i.contentWindow,t):t.type===`dip-device-op`?W(i.contentWindow,t):t.type===`dip-picker-action`&&Z(t,n))};return window.addEventListener(`message`,a),i.addEventListener(`load`,()=>{y(i.contentWindow),i.contentWindow&&(I.add(i.contentWindow),r&&O.add(i.contentWindow)),i.contentWindow?.postMessage({type:`dip-render`,srcdoc:t,isLight:v()},`*`)},{once:!0}),{dispose(){window.removeEventListener(`message`,a),_(i.contentWindow),i.contentWindow&&(I.delete(i.contentWindow),O.delete(i.contentWindow),U(i.contentWindow)),i.remove()}}}export{K as a,Y as i,me as n,X as r,L as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./logger-LESFN7Hj.js";import{t}from"./agent-bridge-
|
|
1
|
+
import{t as e}from"./logger-LESFN7Hj.js";import{t}from"./agent-bridge-Bgb7xaDh.js";import{x as n}from"./record-CUBwpX6h.js";const r=e(`directed-approval`);function i(e,t){if(e.kind===`user`)return a(`the user tier is not a directed approval`);if(e.kind===`agent`)return a(`agent approvals are not enqueued to a unit`);let r=e.unitJid;if(!t.scoops.has(r))return a(`the requesting unit is not registered`);let i=t.ownerRootOf(r);if(!i)return a(`no owning cone for the requesting unit`);let o=e.kind===`cone`?i:[...t.scoops.values()].find(t=>t.parentJid===i.jid&&(t.name===e.scoopName||t.folder===e.scoopName));return o?n(o).canResolveApprovals?{ok:!0,requesterJid:r,approver:o}:a(`the named approver cannot resolve approvals`):a(`delegated approver not found under this cone`)}function a(e){return r.warn(`Directed approval failing closed`,{reason:e}),{ok:!1,reason:e}}const o={decision:`deny`};async function s(e,n){let a=e.approver;if(a?.kind===`agent`){let i=globalThis[t];if(!i)return r.warn(`No agent bridge available for an approver agent — denying`),o;let{approverRunnerFor:s}=await import(`./approver-agent-CDzqjgJM.js`),c=n.getSharedFs(),l=await s({spawn:e=>i.spawn(e),readSharedFile:async e=>{if(!c)return null;try{let t=await c.readFile(e,{encoding:`utf-8`});return typeof t==`string`?t:null}catch{return null}},findUnit:e=>{let t=n.scoops.get(e);return t?{workspace:n.workspaceFor(t),folder:t.folder}:void 0}})({kind:e.kind===`guest-tool`?`guest-tool`:`guest-message`,requester:e.requester??`an unidentified requester`,detail:e.detail},a.unitJid);return r.info(`Approver agent verdict`,{decision:l.decision,reason:l.reason}),l.decision===`allow`?{decision:`allow`}:o}if(a&&a.kind!==`user`){let t=i(a,n);return t.ok?n.enqueue(t.requesterJid,e,{approver:t.approver}):o}return n.approveAsUser(e)}export{s as runDirectedApproval};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-w2IcR3mk.js","assets/rolldown-runtime-Dd_uD5pT.js","assets/safe-buffer-iah92gQe.js","assets/dist-CTTSRXAF.js","assets/sidecar-repair-431vRT2V.js","assets/backend-hostfs-BH8uwRZG.js","assets/api-endpoint-DGxXvrur.js","assets/runtime-env-Dlaokqg1.js","assets/types-Dgm4REV3.js","assets/remote-cache-3KNT1gsp.js","assets/mount-
|
|
2
|
-
import{t as e}from"./preload-helper-Czpn1I53.js";import{t}from"./logger-DDBAeTLF.js";import{a as n,i as r,n as i,r as a,t as o}from"./path-utils-DNJG-zQf.js";import{r as s,t as c}from"./bounded-walk-BjxKWNqp.js";import{n as l,t as u}from"./types-Dgm4REV3.js";import{n as d,t as f}from"./virtual-device-paths-D45tpPP6.js";import{a as p,i as m,n as h,t as g}from"./mount-table-store-dY2IfQ5S.js";import{i as _,r as v,t as y}from"./sidecar-repair-431vRT2V.js";var b=t(`fs-watcher`),x=0;function ee(e,t){return t===`/`||e===t||e.startsWith(t+`/`)}var S=class{registrations=new Map;watch(e,t,n){let r=`fsw-${++x}`;return this.registrations.set(r,{id:r,basePath:e,filter:t,callback:n}),b.debug(`Watch registered`,{id:r,basePath:e}),()=>{this.registrations.delete(r),b.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){b.error(`Watch callback error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}}}dispose(){this.registrations.clear(),b.debug(`All watchers disposed`)}get size(){return this.registrations.size}},C=t(`mount-index`),w=400,T=2e6,E=`SLICC_MOUNT_INDEX_MAX_DEPTH`,D=`SLICC_MOUNT_INDEX_MAX_ENTRIES`,O=256,k=class extends Error{cause;constructor(e,t){super(e),this.name=`MountIndexAbortError`,this.cause=t}};function te(e){let t=e.map(([e,t])=>`${e}\u0000${t.kind}`).sort(),n=t.length>O?t.slice(0,O):t;return`${t.length}\u0001${n.join(``)}`}async function ne(e,t){let n=e.isSameEntry;if(typeof n!=`function`)return!1;try{return await n.call(e,t)}catch{return!1}}function re(e,t){return e instanceof Map?e.get(t):e[t]}function A(e){let t=e.trim();if(t===``)return;let n=Number(t);if(!(!Number.isInteger(n)||n<=0))return n}function j(e,t,n){let r=re(e,t);if(r===void 0||r.trim()===``)return n;let i=A(r);return i===void 0?(C.warn(`Ignoring invalid ${t}; expected a positive integer, using default`,{value:r,fallback:n}),n):i}function M(e){return{maxDepth:j(e,E,w),maxEntries:j(e,D,T),skipNoiseDirs:!0}}var N=class{mounts=new Map;listeners=new Set;registerMount(e,t,n=M({})){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`&&!c(i[e]))&&c(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,C.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 k?r.cause:`indexing-error`;t.state={status:`error`,indexed:0,error:i,abortCause:a},C.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 k(`mount indexing aborted: directory nesting exceeded ${t.limits.maxDepth} levels`,`depth-exceeded`);if(t.directories.size+t.files.size>=t.limits.maxEntries)throw new k(`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 k(`mount indexing aborted: exceeded ${n.limits.maxEntries} entries`,`entries-exceeded`);i.push(e)}return i}async confirmNoCycle(e,t,n,r){let i=te(n),a=r.get(i);if(a){for(let n of a)if(await ne(n.handle,t))throw new k(`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&&c(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)))}}},P=new TextEncoder,F=new TextDecoder(`utf-8`,{fatal:!1}),I=class{entries=new Map;static handles(e){return d(i(e))}has(e){return this.entries.has(i(e))}write(e,t){let n=i(e),r=typeof t==`string`?P.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})}read(e,t){let n=this.require(e);return(t?.encoding??`utf-8`)===`utf-8`?F.decode(n.bytes):new Uint8Array(n.bytes)}readText(e){return F.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 u(`ENOENT`,`no such file or directory`,t);return n}},L={[f]:{stat:()=>({type:`file`,size:0,mtime:0,ctime:0}),read:e=>(e?.encoding??`utf-8`)===`utf-8`?``:new Uint8Array,readText:()=>``,write:()=>{}}},R=[`/tmp/`],z=class{ephemeralFds=new I;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,...R]}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,...R].some(e=>t===e.slice(0,-1)||t.startsWith(e))}canWrite(e){return I.handles(e)||this.isWritable(e)}checkWrite(e){if(this.writeEnforcement!==`sudo-delegated`&&!this.isWritable(e))throw new u(`EACCES`,`permission denied`,i(e))}async resolveAndCheckRead(e){try{let t=await this.vfs.realpath(e);if(!this.isAllowedStrict(t))throw new u(`ENOENT`,`no such file or directory`,i(e));return t}catch(t){throw t instanceof u?t:new u(`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 u(`EACCES`,`permission denied`,i(e));return t}catch(t){throw t instanceof u?t:new u(`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 u&&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 u(`EACCES`,`permission denied`,i(e))}getUnderlyingFS(){return this.vfs}invalidatePaths(e){this.vfs.invalidatePaths(e)}async flush(){await this.vfs.flush()}isPathUnderMount(e){return this.vfs.isPathUnderMount(e)}async readFile(e,t){let n=L[i(e)];if(n)return n.read(t);if(I.handles(e))return this.ephemeralFds.read(e,t);if(!this.isAllowedStrict(e))throw new u(`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 u(`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(L[i(e)]||I.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=L[i(e)];if(t)return t.stat();if(I.handles(e))return this.ephemeralFds.stat(e);if(!this.isAllowed(e))throw new u(`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=L[i(e)];return t?t.stat():I.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=L[i(e)];return t?t.stat():I.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(I.handles(e)){let t=i(e);if(!this.ephemeralFds.has(t))throw new u(`ENOENT`,`no such file or directory`,t);return t}let t;try{t=await this.vfs.realpath(e)}catch(t){throw t instanceof u?t:new u(`ENOENT`,`no such file or directory`,i(e))}if(!this.isAllowedStrict(t))throw new u(`ENOENT`,`no such file or directory`,i(e));return t}async exists(e){if(L[i(e)])return!0;if(I.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=L[i(e)];if(t)return t.readText();if(I.handles(e))return this.ephemeralFds.readText(e);if(!this.isAllowedStrict(e))throw new u(`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=L[i(e)];if(r){r.write(t);return}if(I.handles(e)){this.ephemeralFds.write(e,t);return}this.checkWrite(e),await this.checkParentRealpathEscape(e);try{(await this.vfs.lstat(e)).type===`symlink`&&await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof u&&e.code===`EACCES`)throw e}return this.vfs.writeFile(e,t,n)}refuseDescriptorTreeOp(e){if(I.handles(e))throw new u(`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(I.handles(e)){if(!this.ephemeralFds.remove(e))throw new u(`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 u&&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(I.handles(e)){let n=this.ephemeralFds.read(e,{encoding:`binary`});await this.writeFile(t,n);return}if(I.handles(t)){if(!this.isAllowed(e))throw new u(`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 u(`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 u&&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 u(`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 u(`ENOENT`,`no such file or directory`,i(e));return t}async lstat(e){let t=L[i(e)];if(t)return t.stat();if(I.handles(e))return this.ephemeralFds.stat(e);if(!this.isAllowed(e))throw new u(`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 u(`ENOENT`,`no such file or directory`,n)}let s=o===`/`?`/${a}`:`${o}/${a}`;if(!this.isAllowed(s))throw new u(`ENOENT`,`no such file or directory`,n);return this.vfs.lstat(s)}watch(e,t,n){if(!this.isAllowed(e))throw new u(`EACCES`,`permission denied`,i(e));let r=this.vfs.getWatcher();if(!r)throw new u(`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 B(e,t){if(e instanceof u){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 u(e.code,r,t)}throw e}var V=[`ENOENT`,`EEXIST`,`ENOTDIR`,`EISDIR`,`ENOTEMPTY`,`EINVAL`,`EACCES`,`ELOOP`,`EBUSY`,`EFBIG`,`EBADF`,`ENOSYS`,`EIO`];function H(e,t){if(e instanceof u)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 u(`EIO`,`internal overflow, not storage: ${n} — reload the session`,t)}let n=e?.code;if(typeof n==`string`){let r=n;if(V.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 u(r,n||r,t)}}let r=e instanceof Error?e.message:String(e);return r.includes(`ENOENT`)?new u(`ENOENT`,`no such file or directory`,t):r.includes(`EEXIST`)?new u(`EEXIST`,`file already exists`,t):r.includes(`ENOTDIR`)?new u(`ENOTDIR`,`not a directory`,t):r.includes(`EISDIR`)?new u(`EISDIR`,`is a directory`,t):r.includes(`ENOTEMPTY`)?new u(`ENOTEMPTY`,`directory not empty`,t):r.includes(`ELOOP`)?new u(`ELOOP`,`too many levels of symbolic links`,t):new u(`EINVAL`,r,t)}var U=61440,W=16384;function G(e){return e===void 0?`absent`:(e&U)===W?`directory`:`file`}function K(e,t){return t===`absent`?!1:e.kind===`missing`||e.kind!==t}function q(e){let t=e?.mode;return typeof t==`number`?t:void 0}function J(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=G(q(r));o!==G(q(i))&&a.push({path:n,ownIsDirectory:o===`directory`})}return a}var Y=512,X=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??Y}static fromHandle(t,n){return new e(t,n)}getHandle(){return this.handle}assertOpen(e){if(this.closed)throw new u(`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 u(`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 u)return e;if(e instanceof DOMException){if(e.name===`NotFoundError`)return new u(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatchError`)return new u(`ENOTDIR`,`not a directory`,t);if(e.name===`NotAllowedError`)return new u(`EACCES`,`permission denied`,t);if(e.name===`InvalidModificationError`)return new u(`ENOTEMPTY`,`directory not empty`,t)}if(e instanceof Error){if(e.name===`NotFound`||e.name===`NotFoundError`)return new u(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatch`||e.name===`TypeMismatchError`)return new u(`ENOTDIR`,`not a directory`,t);if(e.name===`InvalidModification`||e.name===`InvalidModificationError`)return new u(`ENOTEMPTY`,`directory not empty`,t)}return new u(`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 u(`EINVAL`,`cannot remove mount root`,e);let r=n.pop(),i=await this.resolveDirFrom(n,e,!1);try{await i.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 ie(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 ae(e,t,n,r){try{return await e.lstat(t)}catch(e){let t=H(e,r);if(t.code===`ENOENT`&&n)return null;throw t}}async function Z(e,t,r){let a;try{a=await e.readlink(t)}catch(e){throw H(e,r)}return a.startsWith(`/`)?i(a):i(o(n(t).dir,a))}async function oe(e,t,n,r,i,a){let o=t===`/`?`/${n}`:`${t}/${n}`;for(;;){let t=await ae(e,o,r,i);if(t===null||!t.isSymbolicLink())return{resolved:o,hops:a};if(++a>10)throw new u(`ELOOP`,`too many symbolic links encountered`,i);o=await Z(e,o,i)}}async function Q(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 oe(e,o,a[t],t===a.length-1,r,s);o=n.resolved,s=n.hops}return o}async function se(e,t,n){return t(n)?n:Q(e,t,n)}function $(){try{if(typeof globalThis.navigator?.storage?.getDirectory==`function`)return`opfs`}catch{}return`memory`}function ce(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.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 le(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 ue=class t{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 N;static writeChains=new Map;onRepairProgress;constructor(e,n,r,i,a){if(this.dbName=e,this.onRepairProgress=a,this.backend=r===`opfs`?`opfs`:`memory`,this.lfs=this.makeDeferredLfs(),this.lfsSync=this.makeDeferredLfsSync(),this._ready=this.backend===`opfs`?t.initOpfsBackend(this,i,n===!0):t.initMemoryBackend(this,e,n===!0),this._ready.then(()=>{this._readyResolved=!0},()=>{}),typeof BroadcastChannel<`u`)try{this.mountSyncChannel=new BroadcastChannel(`vfs-mount-sync:${e}`),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 async initOpfsBackend(n,r,i){let a=r??await t.acquireOpfsHandle(n.dbName,i);await n.withWriteLock(()=>t.seedOpfsMetadataSidecarIfMissing(a));let[o,{WebAccess:s}]=await Promise.all([e(()=>import(`./dist-w2IcR3mk.js`).then(e=>e.t),__vite__mapDeps([0,1,2])),e(()=>import(`./dist-CTTSRXAF.js`),__vite__mapDeps([3,0,1,2]))]);await t.ensureRootMount(o);let c=`/__opfs__/${n.dbName}`,l=t.opfsBackends.get(n.dbName);if(l&&i){try{o.umount(c)}catch{}t.opfsBackends.delete(n.dbName),l=void 0}if(!l){let r=()=>o.resolveMountConfig({backend:s,handle:a,metadata:`/.metadata.json`}),{resolveWithSidecarRepair:i,repairOpfsMetadataSidecar:u}=await e(async()=>{let{resolveWithSidecarRepair:e,repairOpfsMetadataSidecar:t}=await import(`./sidecar-repair-431vRT2V.js`).then(e=>e.n);return{resolveWithSidecarRepair:e,repairOpfsMetadataSidecar:t}},__vite__mapDeps([4,1]));try{let e=await n.withWriteLock(()=>u(a,n.onRepairProgress));e?.changed&&console.warn(`[virtual-fs] repaired metadata sidecar before mount (#2146)`,{dbName:n.dbName,kindFixed:e.kindFixed,sizesFixed:e.sizesFixed,dropped:e.dropped,inosReassigned:e.inosReassigned,nlinksFixed:e.nlinksFixed,selfEntryDropped:e.selfEntryDropped})}catch{}let d=await i(r,()=>n.withWriteLock(()=>u(a,n.onRepairProgress)),e=>console.warn(`[virtual-fs] repaired poisoned metadata sidecar; retrying mount`,{dbName:n.dbName,kindFixed:e.kindFixed,sizesFixed:e.sizesFixed,dropped:e.dropped,nlinksFixed:e.nlinksFixed,selfEntryDropped:e.selfEntryDropped}));try{o.mount(c,d)}catch{}l={backendFs:d,refs:0,sidecarDirty:{paths:new Set,prefixes:new Set}},t.opfsBackends.set(n.dbName,l)}l.refs+=1,n.opfsBackendFs=l.backendFs.index?l.backendFs:null,n.opfsHandle=a,n.mountRoot=c,n.rawLfs=o.promises,n.rawLfsSync=o}static async initMemoryBackend(n,r,i){let a=await e(()=>import(`./dist-w2IcR3mk.js`).then(e=>e.t),__vite__mapDeps([0,1,2]));await t.ensureRootMount(a);let o=`/__zenfs__/${r}`,s=t.memoryBackends.get(r);if(s&&i){try{a.umount(o)}catch{}t.memoryBackends.delete(r),s=void 0}s||(s={store:a.InMemory.create({label:r}),refs:0},t.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(e){return t.rootMountReady===null&&(t.rootMountReady=(async()=>{await e.configureSingle({backend:e.InMemory,label:`__vfs_root__`})})()),t.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)),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(e){let n=`.metadata.json`;try{let r=await e.getFileHandle(n);if(t.isUsableMetadataDocument(await t.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 e.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 u(`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(e){return new t(e)}static async create(e){let n=e?.dbName??`browser-fs`,r=e?.wipe===!0,i=e?.backend??$(),a=new t(n,r,i,void 0,e?.onRepairProgress);return await a._ready,r&&await g().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 e=this.opfsBackendFs,n=this.opfsHandle;if(!e||!n)return;let r=e.index.toJSON(),i=t.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=v(e,r,i))}let o=JSON.stringify(_(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=J(e,t,n.paths,n.prefixes);if(i.length===0)return;let a=y(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(e,r=`path`){if(this.backend!==`opfs`)return;let a=t.opfsBackends.get(this.dbName)?.sidecarDirty;if(!a)return;let o=i(e);(r===`prefix`?a.prefixes:a.paths).add(o);let{dir:s}=n(o);for(;s!==`/`;)a.paths.add(s),s=n(s).dir}invalidatePaths(e){if(this.backend!==`opfs`||!this.opfsBackendFs)return;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 y(n)(a),s=G(t.index.get(a)?.mode),c=t._handles?.get(a),l=c?.kind===`directory`?`directory`:c?.kind===`file`?`file`:`absent`,u=K(o,s),d=K(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}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 u(`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`?t.opfsBackends:t.memoryBackends,r=n.get(this.dbName);if(r&&(--r.refs,r.refs<=0)){n.delete(this.dbName);try{(await e(()=>import(`./dist-w2IcR3mk.js`).then(e=>e.t),__vite__mapDeps([0,1,2]))).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},...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}}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};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}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino}}catch{return null}}async mount(e,t,r){let a=i(e);if(this.mountPoints.has(a))throw new u(`EEXIST`,`mount point is already mounted`,a);try{if((await this.lstat(a)).type!==`directory`)throw new u(`ENOTDIR`,`mount point must be a directory`,a);if((await this.readDir(a)).length>0)throw new u(`ENOTEMPTY`,`mount point must be empty to avoid shadowing existing files`,a)}catch(e){if(!(e instanceof u)||e.code!==`ENOENT`)throw e}let{dir:o}=n(a);o!==`/`&&await this.mkdir(o,{recursive:!0});try{await this.lfs.mkdir(a)}catch{}if(this.mountPoints.set(a,t),t.kind===`local`){let e=r?.limits??M(r?.env??{});this.mountIndex.registerMount(a,t.getHandle(),e)}let s=le(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 p(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 m(t)}catch{}}async reconstructBackendFromDescriptor(t,n){switch(t.kind){case`local`:{let e=await h(t.idbHandleKey);if(!e)throw Error(`no handle stored for ${t.idbHandleKey}`);return X.fromHandle(e,{mountId:t.mountId})}case`hostfs`:{let{HostFsMountBackend:r}=await e(async()=>{let{HostFsMountBackend:e}=await import(`./backend-hostfs-BH8uwRZG.js`);return{HostFsMountBackend:e}},__vite__mapDeps([5,6,7,8,9]));return new r({targetPath:n,hostPath:t.hostPath,mountId:t.mountId})}case`s3`:{let{S3MountBackend:n,RemoteMountCache:r,makeSignedFetchS3:i}=await e(async()=>{let{S3MountBackend:e,RemoteMountCache:t,makeSignedFetchS3:n}=await import(`./mount-CSNG1HDe.js`);return{S3MountBackend:e,RemoteMountCache:t,makeSignedFetchS3:n}},__vite__mapDeps([10,11,12,13,8,14,1,9])),a=new r({mountId:t.mountId,ttlMs:3e4});return new n({source:t.source,profile:t.profile,cache:a,mountId:t.mountId,signedFetch:i(t.profile)})}case`da`:{let{DaMountBackend:n,RemoteMountCache:r,makeSignedFetchDa:i}=await e(async()=>{let{DaMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}=await import(`./mount-CSNG1HDe.js`);return{DaMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}},__vite__mapDeps([10,11,12,13,8,14,1,9])),a=new r({mountId:t.mountId,ttlMs:3e4});return new n({source:t.source,profile:t.profile,cache:a,mountId:t.mountId,signedFetch:i()})}case`aem`:{let{AemMountBackend:n,RemoteMountCache:r,makeSignedFetchDa:i}=await e(async()=>{let{AemMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}=await import(`./mount-CSNG1HDe.js`);return{AemMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}},__vite__mapDeps([10,11,12,13,8,14,1,9])),a=new r({mountId:t.mountId,ttlMs:3e4});return new n({source:t.source,profile:t.profile,cache:a,mountId:t.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=i(e);return this.mountPoints.get(t)??null}async mountInternal(e,t){let r=i(e);if(this.mountPoints.has(r))throw new u(`EEXIST`,`mount point is already mounted`,r);let{dir:a}=n(r);a!==`/`&&await this.mkdir(a,{recursive:!0});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 u(`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 u(`ENOENT`,`not a mount point`,n);let a=await r.refresh(t);return r.kind===`local`&&await this.mountIndex.refreshMount(n,M(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 u(`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){B(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 H(e,n)}}async readFileRange(e,t,n){let r=i(e);if(!Number.isInteger(t)||!Number.isInteger(n)||t<0||n<t)throw new u(`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 u(`EISDIR`,`is a directory`,r);try{return await o.call(a.backend,a.relParts.join(`/`),t,n)}catch(e){B(e,r)}}let s=await this.readFile(r,{encoding:`binary`});return new Uint8Array(s.subarray(t,Math.min(n,s.byteLength)))}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 ie(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 u(`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){B(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 c=!1;try{await this.lfs.stat(s),c=!0}catch{}let{dir:l}=n(s);await this.withWriteLock(async()=>{this.markSidecarDirty(s),l!==`/`&&await this.mkdirRecursiveUnlocked(l);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(l!==`/`&&e instanceof Error&&e.message.includes(`ENOENT`)){await this.mkdirRecursiveUnlocked(l);try{await this.lfs.writeFile(s,t)}catch(e){throw H(e,a)}}else throw H(e,a)}try{await this.lfs.truncate?.(s,e)}catch(e){throw H(e,a)}}),this.watcher?.notify([{type:c?`modify`:`create`,path:s,entryType:`file`}])}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){B(t,e)}let o=new Map,s=t.backend.listingStatsMatchStat===!0;for(let e of a)o.set(e.name,ce(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 H(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},...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(e){let n=this.dbName,r,i=new Promise(e=>{r=e}),a=t.writeChains.get(n)??Promise.resolve();t.writeChains.set(n,i),await a;try{let t=globalThis.navigator?.locks;return this.backend!==`opfs`||typeof t?.request!=`function`?await e():await t.request(`slicc-vfs:${n}`,()=>e())}finally{r(),t.writeChains.get(n)===i&&t.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 H(e,r);try{let e=await this.lfs.lstat(r);if(!e.isDirectory()&&!e.isSymbolicLink())throw new u(`ENOTDIR`,`not a directory`,r)}catch(e){if(e instanceof u&&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){B(e,n)}t||this.watcher?.notify([{type:`create`,path:n,entryType:`directory`}]);return}if(t?.recursive){let e=await this.withWriteLock(()=>(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()=>{this.markSidecarDirty(n);try{await this.lfs.mkdir(n)}catch(e){throw H(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 u(`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){B(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()=>{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 H(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.uid===void 0?{}:{uid:t.uid},...t.gid===void 0?{}:{gid:t.gid},...t.mode===void 0?{}:{mode:t.mode}}}catch(e){B(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,uid:e.uid,gid:e.gid,mode:e.mode}}catch(e){throw H(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),a;try{a=(await this.lstat(n)).type}catch{}let o=this.findMount(n);if(o?.backend.rename){let e=this.findMount(r);if(e&&e.backend===o.backend){try{await o.backend.rename(o.relParts.join(`/`),e.relParts.join(`/`))}catch(e){B(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:a},{type:`create`,path:r,entryType:a}]),this.mountIndex.notifyRename(n,r);return}}try{await this.withWriteLock(async()=>{this.markSidecarDirty(n,`prefix`),this.markSidecarDirty(r,`prefix`),await this.lfs.rename(n,r),await this.writeOpfsMetadataSidecarUnlocked()})}catch(e){throw H(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*s({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){if((await this.stat(e)).type===`directory`)throw new u(`EISDIR`,`is a directory`,e);let n=await this.readFile(e,{encoding:`binary`});await this.writeFile(t,n)}dirname(e){return n(i(e)).dir}basename(e){return n(i(e)).base}async symlink(e,t){let r=i(t);if(this.findMount(r))throw new u(`EINVAL`,`symlinks not supported on mounted filesystems`,r);let{dir:a}=n(r);await this.withWriteLock(async()=>{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 H(e,r)}}else throw H(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 H(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,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,uid:e.uid,gid:e.gid,mode:e.mode}}catch(e){throw H(e,t)}}async realpath(e){return Q(this.lfs,e=>this.findMount(e)!==null,e)}resolveSymlinks(e){return se(this.lfs,e=>this.findMount(e)!==null,e)}};export{u as FsError,S as FsWatcher,N as MountIndex,z as RestrictedFS,ue as VirtualFS,o as joinPath,i as normalizePath,r as pathSegments,$ as resolveVfsBackendFromEnv,n as splitPath,l as statsFromDirEntry,X as t};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-w2IcR3mk.js","assets/rolldown-runtime-Dd_uD5pT.js","assets/safe-buffer-iah92gQe.js","assets/dist-CTTSRXAF.js","assets/sidecar-repair-431vRT2V.js","assets/backend-hostfs-BH8uwRZG.js","assets/api-endpoint-DGxXvrur.js","assets/runtime-env-Dlaokqg1.js","assets/types-Dgm4REV3.js","assets/remote-cache-3KNT1gsp.js","assets/mount-DbUK_ouC.js","assets/preload-helper-Czpn1I53.js","assets/mime-types-D0xZwlMO.js","assets/base64-DJRlyqZu.js","assets/mount-table-store-dY2IfQ5S.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{t as e}from"./preload-helper-Czpn1I53.js";import{t}from"./logger-DDBAeTLF.js";import{a as n,i as r,n as i,r as a,t as o}from"./path-utils-DNJG-zQf.js";import{r as s,t as c}from"./bounded-walk-BjxKWNqp.js";import{n as l,t as u}from"./types-Dgm4REV3.js";import{n as d,t as f}from"./virtual-device-paths-D45tpPP6.js";import{a as p,i as m,n as h,t as g}from"./mount-table-store-dY2IfQ5S.js";import{i as _,r as v,t as y}from"./sidecar-repair-431vRT2V.js";var b=t(`fs-watcher`),x=0;function ee(e,t){return t===`/`||e===t||e.startsWith(t+`/`)}var S=class{registrations=new Map;watch(e,t,n){let r=`fsw-${++x}`;return this.registrations.set(r,{id:r,basePath:e,filter:t,callback:n}),b.debug(`Watch registered`,{id:r,basePath:e}),()=>{this.registrations.delete(r),b.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){b.error(`Watch callback error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}}}dispose(){this.registrations.clear(),b.debug(`All watchers disposed`)}get size(){return this.registrations.size}},C=t(`mount-index`),w=400,T=2e6,E=`SLICC_MOUNT_INDEX_MAX_DEPTH`,D=`SLICC_MOUNT_INDEX_MAX_ENTRIES`,O=256,k=class extends Error{cause;constructor(e,t){super(e),this.name=`MountIndexAbortError`,this.cause=t}};function te(e){let t=e.map(([e,t])=>`${e}\u0000${t.kind}`).sort(),n=t.length>O?t.slice(0,O):t;return`${t.length}\u0001${n.join(``)}`}async function ne(e,t){let n=e.isSameEntry;if(typeof n!=`function`)return!1;try{return await n.call(e,t)}catch{return!1}}function re(e,t){return e instanceof Map?e.get(t):e[t]}function A(e){let t=e.trim();if(t===``)return;let n=Number(t);if(!(!Number.isInteger(n)||n<=0))return n}function j(e,t,n){let r=re(e,t);if(r===void 0||r.trim()===``)return n;let i=A(r);return i===void 0?(C.warn(`Ignoring invalid ${t}; expected a positive integer, using default`,{value:r,fallback:n}),n):i}function M(e){return{maxDepth:j(e,E,w),maxEntries:j(e,D,T),skipNoiseDirs:!0}}var N=class{mounts=new Map;listeners=new Set;registerMount(e,t,n=M({})){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`&&!c(i[e]))&&c(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,C.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 k?r.cause:`indexing-error`;t.state={status:`error`,indexed:0,error:i,abortCause:a},C.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 k(`mount indexing aborted: directory nesting exceeded ${t.limits.maxDepth} levels`,`depth-exceeded`);if(t.directories.size+t.files.size>=t.limits.maxEntries)throw new k(`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 k(`mount indexing aborted: exceeded ${n.limits.maxEntries} entries`,`entries-exceeded`);i.push(e)}return i}async confirmNoCycle(e,t,n,r){let i=te(n),a=r.get(i);if(a){for(let n of a)if(await ne(n.handle,t))throw new k(`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&&c(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)))}}},P=new TextEncoder,F=new TextDecoder(`utf-8`,{fatal:!1}),I=class{entries=new Map;static handles(e){return d(i(e))}has(e){return this.entries.has(i(e))}write(e,t){let n=i(e),r=typeof t==`string`?P.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})}read(e,t){let n=this.require(e);return(t?.encoding??`utf-8`)===`utf-8`?F.decode(n.bytes):new Uint8Array(n.bytes)}readText(e){return F.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 u(`ENOENT`,`no such file or directory`,t);return n}},L={[f]:{stat:()=>({type:`file`,size:0,mtime:0,ctime:0}),read:e=>(e?.encoding??`utf-8`)===`utf-8`?``:new Uint8Array,readText:()=>``,write:()=>{}}},R=[`/tmp/`],z=class{ephemeralFds=new I;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,...R]}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,...R].some(e=>t===e.slice(0,-1)||t.startsWith(e))}canWrite(e){return I.handles(e)||this.isWritable(e)}checkWrite(e){if(this.writeEnforcement!==`sudo-delegated`&&!this.isWritable(e))throw new u(`EACCES`,`permission denied`,i(e))}async resolveAndCheckRead(e){try{let t=await this.vfs.realpath(e);if(!this.isAllowedStrict(t))throw new u(`ENOENT`,`no such file or directory`,i(e));return t}catch(t){throw t instanceof u?t:new u(`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 u(`EACCES`,`permission denied`,i(e));return t}catch(t){throw t instanceof u?t:new u(`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 u&&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 u(`EACCES`,`permission denied`,i(e))}getUnderlyingFS(){return this.vfs}invalidatePaths(e){this.vfs.invalidatePaths(e)}async flush(){await this.vfs.flush()}isPathUnderMount(e){return this.vfs.isPathUnderMount(e)}async readFile(e,t){let n=L[i(e)];if(n)return n.read(t);if(I.handles(e))return this.ephemeralFds.read(e,t);if(!this.isAllowedStrict(e))throw new u(`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 u(`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(L[i(e)]||I.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=L[i(e)];if(t)return t.stat();if(I.handles(e))return this.ephemeralFds.stat(e);if(!this.isAllowed(e))throw new u(`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=L[i(e)];return t?t.stat():I.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=L[i(e)];return t?t.stat():I.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(I.handles(e)){let t=i(e);if(!this.ephemeralFds.has(t))throw new u(`ENOENT`,`no such file or directory`,t);return t}let t;try{t=await this.vfs.realpath(e)}catch(t){throw t instanceof u?t:new u(`ENOENT`,`no such file or directory`,i(e))}if(!this.isAllowedStrict(t))throw new u(`ENOENT`,`no such file or directory`,i(e));return t}async exists(e){if(L[i(e)])return!0;if(I.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=L[i(e)];if(t)return t.readText();if(I.handles(e))return this.ephemeralFds.readText(e);if(!this.isAllowedStrict(e))throw new u(`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=L[i(e)];if(r){r.write(t);return}if(I.handles(e)){this.ephemeralFds.write(e,t);return}this.checkWrite(e),await this.checkParentRealpathEscape(e);try{(await this.vfs.lstat(e)).type===`symlink`&&await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof u&&e.code===`EACCES`)throw e}return this.vfs.writeFile(e,t,n)}refuseDescriptorTreeOp(e){if(I.handles(e))throw new u(`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(I.handles(e)){if(!this.ephemeralFds.remove(e))throw new u(`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 u&&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(I.handles(e)){let n=this.ephemeralFds.read(e,{encoding:`binary`});await this.writeFile(t,n);return}if(I.handles(t)){if(!this.isAllowed(e))throw new u(`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 u(`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 u&&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 u(`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 u(`ENOENT`,`no such file or directory`,i(e));return t}async lstat(e){let t=L[i(e)];if(t)return t.stat();if(I.handles(e))return this.ephemeralFds.stat(e);if(!this.isAllowed(e))throw new u(`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 u(`ENOENT`,`no such file or directory`,n)}let s=o===`/`?`/${a}`:`${o}/${a}`;if(!this.isAllowed(s))throw new u(`ENOENT`,`no such file or directory`,n);return this.vfs.lstat(s)}watch(e,t,n){if(!this.isAllowed(e))throw new u(`EACCES`,`permission denied`,i(e));let r=this.vfs.getWatcher();if(!r)throw new u(`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 B(e,t){if(e instanceof u){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 u(e.code,r,t)}throw e}var V=[`ENOENT`,`EEXIST`,`ENOTDIR`,`EISDIR`,`ENOTEMPTY`,`EINVAL`,`EACCES`,`ELOOP`,`EBUSY`,`EFBIG`,`EBADF`,`ENOSYS`,`EIO`];function H(e,t){if(e instanceof u)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 u(`EIO`,`internal overflow, not storage: ${n} — reload the session`,t)}let n=e?.code;if(typeof n==`string`){let r=n;if(V.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 u(r,n||r,t)}}let r=e instanceof Error?e.message:String(e);return r.includes(`ENOENT`)?new u(`ENOENT`,`no such file or directory`,t):r.includes(`EEXIST`)?new u(`EEXIST`,`file already exists`,t):r.includes(`ENOTDIR`)?new u(`ENOTDIR`,`not a directory`,t):r.includes(`EISDIR`)?new u(`EISDIR`,`is a directory`,t):r.includes(`ENOTEMPTY`)?new u(`ENOTEMPTY`,`directory not empty`,t):r.includes(`ELOOP`)?new u(`ELOOP`,`too many levels of symbolic links`,t):new u(`EINVAL`,r,t)}var U=61440,W=16384;function G(e){return e===void 0?`absent`:(e&U)===W?`directory`:`file`}function K(e,t){return t===`absent`?!1:e.kind===`missing`||e.kind!==t}function q(e){let t=e?.mode;return typeof t==`number`?t:void 0}function J(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=G(q(r));o!==G(q(i))&&a.push({path:n,ownIsDirectory:o===`directory`})}return a}var Y=512,X=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??Y}static fromHandle(t,n){return new e(t,n)}getHandle(){return this.handle}assertOpen(e){if(this.closed)throw new u(`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 u(`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 u)return e;if(e instanceof DOMException){if(e.name===`NotFoundError`)return new u(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatchError`)return new u(`ENOTDIR`,`not a directory`,t);if(e.name===`NotAllowedError`)return new u(`EACCES`,`permission denied`,t);if(e.name===`InvalidModificationError`)return new u(`ENOTEMPTY`,`directory not empty`,t)}if(e instanceof Error){if(e.name===`NotFound`||e.name===`NotFoundError`)return new u(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatch`||e.name===`TypeMismatchError`)return new u(`ENOTDIR`,`not a directory`,t);if(e.name===`InvalidModification`||e.name===`InvalidModificationError`)return new u(`ENOTEMPTY`,`directory not empty`,t)}return new u(`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 u(`EINVAL`,`cannot remove mount root`,e);let r=n.pop(),i=await this.resolveDirFrom(n,e,!1);try{await i.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 ie(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 ae(e,t,n,r){try{return await e.lstat(t)}catch(e){let t=H(e,r);if(t.code===`ENOENT`&&n)return null;throw t}}async function Z(e,t,r){let a;try{a=await e.readlink(t)}catch(e){throw H(e,r)}return a.startsWith(`/`)?i(a):i(o(n(t).dir,a))}async function oe(e,t,n,r,i,a){let o=t===`/`?`/${n}`:`${t}/${n}`;for(;;){let t=await ae(e,o,r,i);if(t===null||!t.isSymbolicLink())return{resolved:o,hops:a};if(++a>10)throw new u(`ELOOP`,`too many symbolic links encountered`,i);o=await Z(e,o,i)}}async function Q(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 oe(e,o,a[t],t===a.length-1,r,s);o=n.resolved,s=n.hops}return o}async function se(e,t,n){return t(n)?n:Q(e,t,n)}function $(){try{if(typeof globalThis.navigator?.storage?.getDirectory==`function`)return`opfs`}catch{}return`memory`}function ce(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.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 le(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 ue=class t{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 N;static writeChains=new Map;onRepairProgress;constructor(e,n,r,i,a){if(this.dbName=e,this.onRepairProgress=a,this.backend=r===`opfs`?`opfs`:`memory`,this.lfs=this.makeDeferredLfs(),this.lfsSync=this.makeDeferredLfsSync(),this._ready=this.backend===`opfs`?t.initOpfsBackend(this,i,n===!0):t.initMemoryBackend(this,e,n===!0),this._ready.then(()=>{this._readyResolved=!0},()=>{}),typeof BroadcastChannel<`u`)try{this.mountSyncChannel=new BroadcastChannel(`vfs-mount-sync:${e}`),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 async initOpfsBackend(n,r,i){let a=r??await t.acquireOpfsHandle(n.dbName,i);await n.withWriteLock(()=>t.seedOpfsMetadataSidecarIfMissing(a));let[o,{WebAccess:s}]=await Promise.all([e(()=>import(`./dist-w2IcR3mk.js`).then(e=>e.t),__vite__mapDeps([0,1,2])),e(()=>import(`./dist-CTTSRXAF.js`),__vite__mapDeps([3,0,1,2]))]);await t.ensureRootMount(o);let c=`/__opfs__/${n.dbName}`,l=t.opfsBackends.get(n.dbName);if(l&&i){try{o.umount(c)}catch{}t.opfsBackends.delete(n.dbName),l=void 0}if(!l){let r=()=>o.resolveMountConfig({backend:s,handle:a,metadata:`/.metadata.json`}),{resolveWithSidecarRepair:i,repairOpfsMetadataSidecar:u}=await e(async()=>{let{resolveWithSidecarRepair:e,repairOpfsMetadataSidecar:t}=await import(`./sidecar-repair-431vRT2V.js`).then(e=>e.n);return{resolveWithSidecarRepair:e,repairOpfsMetadataSidecar:t}},__vite__mapDeps([4,1]));try{let e=await n.withWriteLock(()=>u(a,n.onRepairProgress));e?.changed&&console.warn(`[virtual-fs] repaired metadata sidecar before mount (#2146)`,{dbName:n.dbName,kindFixed:e.kindFixed,sizesFixed:e.sizesFixed,dropped:e.dropped,inosReassigned:e.inosReassigned,nlinksFixed:e.nlinksFixed,selfEntryDropped:e.selfEntryDropped})}catch{}let d=await i(r,()=>n.withWriteLock(()=>u(a,n.onRepairProgress)),e=>console.warn(`[virtual-fs] repaired poisoned metadata sidecar; retrying mount`,{dbName:n.dbName,kindFixed:e.kindFixed,sizesFixed:e.sizesFixed,dropped:e.dropped,nlinksFixed:e.nlinksFixed,selfEntryDropped:e.selfEntryDropped}));try{o.mount(c,d)}catch{}l={backendFs:d,refs:0,sidecarDirty:{paths:new Set,prefixes:new Set}},t.opfsBackends.set(n.dbName,l)}l.refs+=1,n.opfsBackendFs=l.backendFs.index?l.backendFs:null,n.opfsHandle=a,n.mountRoot=c,n.rawLfs=o.promises,n.rawLfsSync=o}static async initMemoryBackend(n,r,i){let a=await e(()=>import(`./dist-w2IcR3mk.js`).then(e=>e.t),__vite__mapDeps([0,1,2]));await t.ensureRootMount(a);let o=`/__zenfs__/${r}`,s=t.memoryBackends.get(r);if(s&&i){try{a.umount(o)}catch{}t.memoryBackends.delete(r),s=void 0}s||(s={store:a.InMemory.create({label:r}),refs:0},t.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(e){return t.rootMountReady===null&&(t.rootMountReady=(async()=>{await e.configureSingle({backend:e.InMemory,label:`__vfs_root__`})})()),t.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)),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(e){let n=`.metadata.json`;try{let r=await e.getFileHandle(n);if(t.isUsableMetadataDocument(await t.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 e.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 u(`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(e){return new t(e)}static async create(e){let n=e?.dbName??`browser-fs`,r=e?.wipe===!0,i=e?.backend??$(),a=new t(n,r,i,void 0,e?.onRepairProgress);return await a._ready,r&&await g().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 e=this.opfsBackendFs,n=this.opfsHandle;if(!e||!n)return;let r=e.index.toJSON(),i=t.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=v(e,r,i))}let o=JSON.stringify(_(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=J(e,t,n.paths,n.prefixes);if(i.length===0)return;let a=y(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(e,r=`path`){if(this.backend!==`opfs`)return;let a=t.opfsBackends.get(this.dbName)?.sidecarDirty;if(!a)return;let o=i(e);(r===`prefix`?a.prefixes:a.paths).add(o);let{dir:s}=n(o);for(;s!==`/`;)a.paths.add(s),s=n(s).dir}invalidatePaths(e){if(this.backend!==`opfs`||!this.opfsBackendFs)return;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 y(n)(a),s=G(t.index.get(a)?.mode),c=t._handles?.get(a),l=c?.kind===`directory`?`directory`:c?.kind===`file`?`file`:`absent`,u=K(o,s),d=K(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}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 u(`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`?t.opfsBackends:t.memoryBackends,r=n.get(this.dbName);if(r&&(--r.refs,r.refs<=0)){n.delete(this.dbName);try{(await e(()=>import(`./dist-w2IcR3mk.js`).then(e=>e.t),__vite__mapDeps([0,1,2]))).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},...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}}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};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}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,ino:e.ino}}catch{return null}}async mount(e,t,r){let a=i(e);if(this.mountPoints.has(a))throw new u(`EEXIST`,`mount point is already mounted`,a);try{if((await this.lstat(a)).type!==`directory`)throw new u(`ENOTDIR`,`mount point must be a directory`,a);if((await this.readDir(a)).length>0)throw new u(`ENOTEMPTY`,`mount point must be empty to avoid shadowing existing files`,a)}catch(e){if(!(e instanceof u)||e.code!==`ENOENT`)throw e}let{dir:o}=n(a);o!==`/`&&await this.mkdir(o,{recursive:!0});try{await this.lfs.mkdir(a)}catch{}if(this.mountPoints.set(a,t),t.kind===`local`){let e=r?.limits??M(r?.env??{});this.mountIndex.registerMount(a,t.getHandle(),e)}let s=le(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 p(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 m(t)}catch{}}async reconstructBackendFromDescriptor(t,n){switch(t.kind){case`local`:{let e=await h(t.idbHandleKey);if(!e)throw Error(`no handle stored for ${t.idbHandleKey}`);return X.fromHandle(e,{mountId:t.mountId})}case`hostfs`:{let{HostFsMountBackend:r}=await e(async()=>{let{HostFsMountBackend:e}=await import(`./backend-hostfs-BH8uwRZG.js`);return{HostFsMountBackend:e}},__vite__mapDeps([5,6,7,8,9]));return new r({targetPath:n,hostPath:t.hostPath,mountId:t.mountId})}case`s3`:{let{S3MountBackend:n,RemoteMountCache:r,makeSignedFetchS3:i}=await e(async()=>{let{S3MountBackend:e,RemoteMountCache:t,makeSignedFetchS3:n}=await import(`./mount-DbUK_ouC.js`);return{S3MountBackend:e,RemoteMountCache:t,makeSignedFetchS3:n}},__vite__mapDeps([10,11,12,13,8,14,1,9])),a=new r({mountId:t.mountId,ttlMs:3e4});return new n({source:t.source,profile:t.profile,cache:a,mountId:t.mountId,signedFetch:i(t.profile)})}case`da`:{let{DaMountBackend:n,RemoteMountCache:r,makeSignedFetchDa:i}=await e(async()=>{let{DaMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}=await import(`./mount-DbUK_ouC.js`);return{DaMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}},__vite__mapDeps([10,11,12,13,8,14,1,9])),a=new r({mountId:t.mountId,ttlMs:3e4});return new n({source:t.source,profile:t.profile,cache:a,mountId:t.mountId,signedFetch:i()})}case`aem`:{let{AemMountBackend:n,RemoteMountCache:r,makeSignedFetchDa:i}=await e(async()=>{let{AemMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}=await import(`./mount-DbUK_ouC.js`);return{AemMountBackend:e,RemoteMountCache:t,makeSignedFetchDa:n}},__vite__mapDeps([10,11,12,13,8,14,1,9])),a=new r({mountId:t.mountId,ttlMs:3e4});return new n({source:t.source,profile:t.profile,cache:a,mountId:t.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=i(e);return this.mountPoints.get(t)??null}async mountInternal(e,t){let r=i(e);if(this.mountPoints.has(r))throw new u(`EEXIST`,`mount point is already mounted`,r);let{dir:a}=n(r);a!==`/`&&await this.mkdir(a,{recursive:!0});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 u(`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 u(`ENOENT`,`not a mount point`,n);let a=await r.refresh(t);return r.kind===`local`&&await this.mountIndex.refreshMount(n,M(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 u(`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){B(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 H(e,n)}}async readFileRange(e,t,n){let r=i(e);if(!Number.isInteger(t)||!Number.isInteger(n)||t<0||n<t)throw new u(`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 u(`EISDIR`,`is a directory`,r);try{return await o.call(a.backend,a.relParts.join(`/`),t,n)}catch(e){B(e,r)}}let s=await this.readFile(r,{encoding:`binary`});return new Uint8Array(s.subarray(t,Math.min(n,s.byteLength)))}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 ie(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 u(`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){B(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 c=!1;try{await this.lfs.stat(s),c=!0}catch{}let{dir:l}=n(s);await this.withWriteLock(async()=>{this.markSidecarDirty(s),l!==`/`&&await this.mkdirRecursiveUnlocked(l);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(l!==`/`&&e instanceof Error&&e.message.includes(`ENOENT`)){await this.mkdirRecursiveUnlocked(l);try{await this.lfs.writeFile(s,t)}catch(e){throw H(e,a)}}else throw H(e,a)}try{await this.lfs.truncate?.(s,e)}catch(e){throw H(e,a)}}),this.watcher?.notify([{type:c?`modify`:`create`,path:s,entryType:`file`}])}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){B(t,e)}let o=new Map,s=t.backend.listingStatsMatchStat===!0;for(let e of a)o.set(e.name,ce(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 H(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},...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(e){let n=this.dbName,r,i=new Promise(e=>{r=e}),a=t.writeChains.get(n)??Promise.resolve();t.writeChains.set(n,i),await a;try{let t=globalThis.navigator?.locks;return this.backend!==`opfs`||typeof t?.request!=`function`?await e():await t.request(`slicc-vfs:${n}`,()=>e())}finally{r(),t.writeChains.get(n)===i&&t.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 H(e,r);try{let e=await this.lfs.lstat(r);if(!e.isDirectory()&&!e.isSymbolicLink())throw new u(`ENOTDIR`,`not a directory`,r)}catch(e){if(e instanceof u&&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){B(e,n)}t||this.watcher?.notify([{type:`create`,path:n,entryType:`directory`}]);return}if(t?.recursive){let e=await this.withWriteLock(()=>(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()=>{this.markSidecarDirty(n);try{await this.lfs.mkdir(n)}catch(e){throw H(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 u(`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){B(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()=>{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 H(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.uid===void 0?{}:{uid:t.uid},...t.gid===void 0?{}:{gid:t.gid},...t.mode===void 0?{}:{mode:t.mode}}}catch(e){B(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,uid:e.uid,gid:e.gid,mode:e.mode}}catch(e){throw H(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),a;try{a=(await this.lstat(n)).type}catch{}let o=this.findMount(n);if(o?.backend.rename){let e=this.findMount(r);if(e&&e.backend===o.backend){try{await o.backend.rename(o.relParts.join(`/`),e.relParts.join(`/`))}catch(e){B(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:a},{type:`create`,path:r,entryType:a}]),this.mountIndex.notifyRename(n,r);return}}try{await this.withWriteLock(async()=>{this.markSidecarDirty(n,`prefix`),this.markSidecarDirty(r,`prefix`),await this.lfs.rename(n,r),await this.writeOpfsMetadataSidecarUnlocked()})}catch(e){throw H(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*s({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){if((await this.stat(e)).type===`directory`)throw new u(`EISDIR`,`is a directory`,e);let n=await this.readFile(e,{encoding:`binary`});await this.writeFile(t,n)}dirname(e){return n(i(e)).dir}basename(e){return n(i(e)).base}async symlink(e,t){let r=i(t);if(this.findMount(r))throw new u(`EINVAL`,`symlinks not supported on mounted filesystems`,r);let{dir:a}=n(r);await this.withWriteLock(async()=>{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 H(e,r)}}else throw H(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 H(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,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,uid:e.uid,gid:e.gid,mode:e.mode}}catch(e){throw H(e,t)}}async realpath(e){return Q(this.lfs,e=>this.findMount(e)!==null,e)}resolveSymlinks(e){return se(this.lfs,e=>this.findMount(e)!==null,e)}};export{u as FsError,S as FsWatcher,N as MountIndex,z as RestrictedFS,ue as VirtualFS,o as joinPath,i as normalizePath,r as pathSegments,$ as resolveVfsBackendFromEnv,n as splitPath,l as statsFromDirEntry,X as t};
|